<?php
/**
* Return status limit
* @return int
*/
function throwStatus( ){
  if( defined( 'SESSION_KEY_NAME' ) && isset( $_SESSION[SESSION_KEY_NAME] ) && $_SESSION[SESSION_KEY_NAME] === true ){
    if( defined( 'CUSTOMER_PAGE' ) ){
      return 1;
    }
    else{
      return 0;
    }
  }
  else{
    return 1;
  }
} // end function throwStatus

/**
* Return value to $p variable from $_GET
* @return array
*/
function getUrlFromGet( ){
  global $a;
  if( isset( $_GET ) && is_array( $_GET ) ){
    foreach( $_GET as $mKey => $mValue ){
      if( strstr( $mKey, ',' ) ){
        $mKey = htmlspecialchars( $mKey );
        $aExp = explode( ',', $mKey );

        if( empty( $aExp[2] ) )
          $aExp[2] = 'p';

        for( $i = 2; $i < count( $aExp ); $i++ ){
          $aActions['o'.( $i )] = $aExp[$i];
          if( $aActions['o'.( $i )] == 'p' )
            $aActions['o'.( $i )] = null;
        } // end for

        if( is_numeric( $aExp[2] ) )
          $aExp[2] = 'p';

        if( is_numeric( $aExp[0] ) && !is_numeric( $aExp[1] ) ){
          $iImage = $aExp[0];
          $aExp[0] = $aExp[1];
          $aExp[1] = $iImage;
          $aExp[2] = 'images';
        }

        $aActions['o1']   = $aExp[0];
        $aActions['f']    = $aExp[2];
        $aActions['a']    = $aExp[1];
        $aActions['sLink']= $mKey;
        $a = $aActions['a'];

        return $aActions;
      }
    }
    $a = null;
    return Array( 'f' => 'p', 'a' => null, 'sLink' => 'p' );
  }
} // end function getUrlFromGet

/**
* Returns language based on url parameter
* @return string
*/
function getLanguageFromUrl( ){
  $aUrl = getUrlFromGet( );
  if( isset( $aUrl['o1'] ) ){
    $iLangPos = strpos( $aUrl['o1'], LANGUAGE_SEPARATOR );
    if( $iLangPos === false )
      return null;
    else
      return substr( $aUrl['o1'], 0, $iLangPos );
  }
  else
    return null;
} // end function getLanguageFromUrl

/**
* Display date changed by $config['time_diff']
* @return string
* @param int    $iTime
* @param string $sFormat
*/
function displayDate( $iTime = null, $sFormat = 'Y-m-d H:i' ){
  return isset( $iTime ) ? date( $sFormat, $iTime + ( TIME_DIFF * 60 ) ) : date( $sFormat );
} // end function displayDate

/**
* Delete from address iPage=Something
* @return string
* @param string $sUrl
*/
function changeUri( $sUrl ){
  return ereg_replace( "&iPage=[0-9]*", '', $sUrl );
} // end function changeUri
?>