diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php old mode 100755 new mode 100644 index 1f979e6a7..57a512acc --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -30,50 +30,47 @@ class G { - /** * is_https * @return void */ - function is_https() - { - if(isset($_SERVER['HTTPS'])) + function is_https() { - if($_SERVER['HTTPS']=='on') - return true; - else - return false; - } - else - return false; - } - - /** - * Fill array values (recursive) - * @author maborak - * @access public - * @param Array $arr - * @param Void $value - * @param Boolean $recursive - * @return Array - */ - function array_fill_value($arr = Array(),$value = '',$recursive = false) - { - if(is_array($arr)) { - foreach($arr as $key=>$val) { - if(is_array($arr[$key])) { - $arr[$key] = ($recursive===true)?G::array_fill_value($arr[$key],$value,true):$val; + if(isset($_SERVER['HTTPS'])) + { + if($_SERVER['HTTPS']=='on') + return true; + else + return false; + } else { + return false; } - else { - $arr[$key] = $value; - } - } + } + /** + * Fill array values (recursive) + * + * @author maborak + * @access public + * @param Array $arr + * @param Void $value + * @param Boolean $recursive + * @return Array + */ + function array_fill_value ($arr = Array(), $value = '', $recursive = false) + { + if (is_array( $arr )) { + foreach ($arr as $key => $val) { + if (is_array( $arr[$key] )) { + $arr[$key] = ($recursive === true) ? G::array_fill_value( $arr[$key], $value, true ) : $val; + } else { + $arr[$key] = $value; + } + } + } else { + $arr = Array (); + } + return $arr; } - else { - $arr = Array(); - } - return $arr; - } /** * Generate Password Random @@ -82,44 +79,43 @@ class G * @param Int * @return String */ - function generate_password($length = 8) - { - $password = ""; - $possible = "0123456789bcdfghjkmnpqrstvwxyz"; - $i = 0; - while($i<$length) { - $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); - if(!strstr($password, $char)) { - $password .= $char; - $i++; - } - } - return $password; - } - - /** - * Array concat - * array_concat(ArrayToConcat,ArrayOriginal); - * @author maborak - * @access public - * @param Array - * @return Array - */ - function array_concat() - { - $nums = func_num_args(); - $vars = func_get_args(); - $ret = Array(); - for($i = 0;$i < $nums; $i++) + function generate_password($length = 8) { - if(is_array($vars[$i])) { - foreach($vars[$i] as $key=>$value) { - $ret[$key] = $value; + $password = ""; + $possible = "0123456789bcdfghjkmnpqrstvwxyz"; + $i = 0; + while($i<$length) { + $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); + if(!strstr($password, $char)) { + $password .= $char; + $i++; + } } - } + return $password; + } + /** + * Array concat + * array_concat(ArrayToConcat,ArrayOriginal); + * + * @author maborak + * @access public + * @param Array + * @return Array + */ + function array_concat () + { + $nums = func_num_args(); + $vars = func_get_args(); + $ret = Array (); + for ($i = 0; $i < $nums; $i ++) { + if (is_array( $vars[$i] )) { + foreach ($vars[$i] as $key => $value) { + $ret[$key] = $value; + } + } + } + return $ret; } - return $ret; - } /** * Compare Variables @@ -130,19 +126,21 @@ class G * @param void $var1-N * @return Boolean */ - function var_compare($value=true,$varN) - { - $nums = func_num_args(); - if($nums<2){return true;} - $vars = func_get_args(); - $ret = Array(); - for($i=1;$i<$nums;$i++) { - if($vars[$i]!==$value) { - return false; - } + function var_compare ($value = true, $varN) + { + $nums = func_num_args(); + if ($nums < 2) { + return true; + } + $vars = func_get_args(); + $ret = Array (); + for ($i = 1; $i < $nums; $i ++) { + if ($vars[$i] !== $value) { + return false; + } + } + return true; } - return true; - } /** * Emulate variable selector * @author maborak @@ -150,1041 +148,1038 @@ class G * @param void * @return void */ - function var_probe() - { - //return (!$variable)? - $nums = func_num_args(); - $vars = func_get_args(); - for($i=0;$i<$nums;$i++) { - if($vars[$i]) { - return $vars[$i]; - } + function var_probe () + { + //return (!$variable)? + $nums = func_num_args(); + $vars = func_get_args(); + for ($i = 0; $i < $nums; $i ++) { + if ($vars[$i]) { + return $vars[$i]; + } + } + return 1; + } + + /** + * Get the current version of gulliver classes + * + * @author Fernando Ontiveros Lira + * @access public + * @return string + */ + function &getVersion () + { + //majorVersion.minorVersion-SvnRevision + return '3.0-1'; } - return 1; - } - - /** - * Get the current version of gulliver classes - * @author Fernando Ontiveros Lira - * @access public - * @return string - */ - function &getVersion( ) - { - //majorVersion.minorVersion-SvnRevision - return '3.0-1'; - } /** * getIpAddress * @return string $ip */ - function getIpAddress () - { - if (getenv('HTTP_CLIENT_IP')) { - $ip = getenv('HTTP_CLIENT_IP'); - } - elseif(getenv('HTTP_X_FORWARDED_FOR')) { - $ip = getenv('HTTP_X_FORWARDED_FOR'); - } - else { - $ip = getenv('REMOTE_ADDR'); - } - return $ip; - } - - /** - * getMacAddress - * @return string $mac - */ - function getMacAddress() - { - if ( strstr ( getenv ( 'OS' ), 'Windows' ) ) { - $ipconfig = `ipconfig /all`; - preg_match('/[\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}/i',$ipconfig,$mac); - } else { - $ifconfig = `/sbin/ifconfig`; - preg_match('/[\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}/i',$ifconfig,$mac); - } - return isset($mac[0])? $mac[0]:'00:00:00:00:00:00'; - } - - /** - * microtime_float - * @return array_sum(explode(' ',microtime())) - */ - /*public static*/ function microtime_float() { - return array_sum(explode(' ',microtime())); - } - /* custom error functions */ - - /** - * &setFatalErrorHandler - * - * @param string $newFatalErrorHandler default value null - * - * @return boolean true - */ + function getIpAddress () + { + if (getenv( 'HTTP_CLIENT_IP' )) { + $ip = getenv( 'HTTP_CLIENT_IP' ); + } elseif (getenv( 'HTTP_X_FORWARDED_FOR' )) { + $ip = getenv( 'HTTP_X_FORWARDED_FOR' ); + } else { + $ip = getenv( 'REMOTE_ADDR' ); + } + return $ip; + } + + /** + * getMacAddress + * + * @return string $mac + */ + function getMacAddress () + { + if (strstr( getenv( 'OS' ), 'Windows' )) { + $ipconfig = `ipconfig /all`; + preg_match( '/[\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}/i', $ipconfig, $mac ); + } else { + $ifconfig = `/sbin/ifconfig`; + preg_match( '/[\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}/i', $ifconfig, $mac ); + } + return isset( $mac[0] ) ? $mac[0] : '00:00:00:00:00:00'; + } + + /** + * microtime_float + * + * @return array_sum(explode(' ',microtime())) + */ + /*public static*/ + function microtime_float () + { + return array_sum( explode( ' ', microtime() ) ); + } + /* custom error functions */ + + /** + * &setFatalErrorHandler + * + * @param string $newFatalErrorHandler default value null + * + * @return boolean true + */ /*public static*/ - function &setFatalErrorHandler( $newFatalErrorHandler = null ) - { - if ( isset ( $newFatalErrorHandler ) ) { - set_error_handler( $newFatalErrorHandler ); - } - else { - ob_start( array ( 'G', 'fatalErrorHandler' ) ); - } - return true; - } - - /** - * setErrorHandler - * @param string setErrorHandler - * @param object $newCustomErrorHandler - * - * @return boolean true - */ - /*public static*/ - function setErrorHandler( $newCustomErrorHandler = null ) - { - if ( isset ( $newCustomErrorHandler ) ) { - set_error_handler( $newCustomErrorHandler ); - } - else { - set_error_handler( array("G", "customErrorHandler")); - } - return true; - } - - /** - * fatalErrorHandler - * - * @param string $buffer - * - * @return string $errorBox or $buffer - */ - /*public static*/ function fatalErrorHandler($buffer) { - // The ereg function has been DEPRECATED as of PHP 5.3.0. - // if (ereg("(error:)(.+)(:)(.+)(/","",$regs[2]); - G::customErrorLog('FATAL', $err, '', 0, ''); - $ip_addr = G::getIpAddress(); - $errorBox = "
" . - "" . - "" . - " " . - "
ERROR CAUGHT check log file
IP address: $ip_addr
"; - return $errorBox; - } - return $buffer; - } - - /** - * customErrorHandler - * - * @param string $errno - * @param string $msg - * @param string $file - * @param string $line - * @param string $context - * - * @return void - */ - /*public static*/ - function customErrorHandler ( $errno, $msg, $file, $line, $context) { - switch ($errno) { - case E_ERROR: - case E_USER_ERROR: - $type = "FATAL"; - G::customErrorLog ($type, $msg, $file, $line); - G::verboseError ($type, $errno, $msg, $file, $line, $context); - if (defined ("ERROR_SHOW_SOURCE_CODE") && ERROR_SHOW_SOURCE_CODE) - G::showErrorSource ($type, $msg, $file, $line, "#c00000"); - die (); - break; - case E_WARNING: - case E_USER_WARNING: - $type = "WARNING"; - G::customErrorLog ($type, $msg, $file, $line); - break; - case E_NOTICE: - case E_USER_NOTICE: - $type = "NOTICE"; - if (defined ("ERROR_LOG_NOTICE_ERROR") && ERROR_LOG_NOTICE_ERROR) - G::customErrorLog ($type, $msg, $file, $line); - break; - case E_STRICT: - $type = "STRICT"; //dont show STRICT Errors - //if (defined ("ERROR_LOG_NOTICE_ERROR") && ERROR_LOG_NOTICE_ERROR) - // G::customErrorLog ($type, $msg, $file, $line); - break; - default: - $type = "ERROR ($errno)"; - G::customErrorLog ($type, $msg, $file, $line); - break; - } - - if (defined ("ERROR_SHOW_SOURCE_CODE") && ERROR_SHOW_SOURCE_CODE && $errno <> E_STRICT ) - G::showErrorSource ($type, $msg, $file, $line); - } - - /** - * Function showErrorSource - * @author David S. Callizaya S. - * @access public - * @parameter string type - * @parameter string msg - * @parameter string file - * @parameter string line - * @return string - */ - function showErrorSource($type, $msg, $file, $line) - { - global $__src_array; - $line_offset = 3; - - if (! isset ($__src_array[$file])) - $__src_array[$file] = @file ($file); - - if (!$__src_array[$file]) - return; - - if ($line - $line_offset < 1) - $start = 1; - else - $start = $line - $line_offset; - - if ($line + $line_offset > count ($__src_array[$file])) - $end = count ($__src_array[$file]); - else - $end = $line + $line_offset; - - print ""; + for ($i = $start; $i <= $end; $i ++) { + $str = @highlight_string( "", true ); + + $pos1 = strpos( $str, "<?" ); + $pos2 = strrpos( $str, "?>" ); + + $str = substr( $str, 0, $pos1 ) . substr( $str, $pos1 + 5, $pos2 - ($pos1 + 5) ) . substr( $str, $pos2 + 5 ); + + ($i == $line) ? $bgcolor = "bgcolor=#ffccaa" : $bgcolor = "bgcolor=#ffffff"; + print " + "; + } + + print "
"; - print ""; - print " + function &setFatalErrorHandler ($newFatalErrorHandler = null) + { + if (isset( $newFatalErrorHandler )) { + set_error_handler( $newFatalErrorHandler ); + } else { + ob_start( array ('G','fatalErrorHandler' + ) ); + } + return true; + } + + /** + * setErrorHandler + * + * @param string setErrorHandler + * @param object $newCustomErrorHandler + * + * @return boolean true + */ + /*public static*/ + function setErrorHandler ($newCustomErrorHandler = null) + { + if (isset( $newCustomErrorHandler )) { + set_error_handler( $newCustomErrorHandler ); + } else { + set_error_handler( array ("G","customErrorHandler") ); + } + return true; + } + + /** + * fatalErrorHandler + * + * @param string $buffer + * + * @return string $errorBox or $buffer + */ + /*public static*/ + function fatalErrorHandler ($buffer) + { + // The ereg function has been DEPRECATED as of PHP 5.3.0. + // if (ereg("(error:)(.+)(:)(.+)(/", "", $regs[2] ); + G::customErrorLog( 'FATAL', $err, '', 0, '' ); + $ip_addr = G::getIpAddress(); + $errorBox = "
" . "" . "" . " " . "
ERROR CAUGHT check log file
IP address: $ip_addr
"; + return $errorBox; + } + return $buffer; + } + /** + * customErrorHandler + * + * @param string $errno + * @param string $msg + * @param string $file + * @param string $line + * @param string $context + * + * @return void + */ + /*public static*/ + function customErrorHandler ($errno, $msg, $file, $line, $context) + { + switch ($errno) { + case E_ERROR: + case E_USER_ERROR: + $type = "FATAL"; + G::customErrorLog( $type, $msg, $file, $line ); + G::verboseError( $type, $errno, $msg, $file, $line, $context ); + if (defined( "ERROR_SHOW_SOURCE_CODE" ) && ERROR_SHOW_SOURCE_CODE) + G::showErrorSource( $type, $msg, $file, $line, "#c00000" ); + die(); + break; + case E_WARNING: + case E_USER_WARNING: + $type = "WARNING"; + G::customErrorLog( $type, $msg, $file, $line ); + break; + case E_NOTICE: + case E_USER_NOTICE: + $type = "NOTICE"; + if (defined( "ERROR_LOG_NOTICE_ERROR" ) && ERROR_LOG_NOTICE_ERROR) + G::customErrorLog( $type, $msg, $file, $line ); + break; + case E_STRICT: + $type = "STRICT"; //dont show STRICT Errors + //if (defined ("ERROR_LOG_NOTICE_ERROR") && ERROR_LOG_NOTICE_ERROR) + // G::customErrorLog ($type, $msg, $file, $line); + break; + default: + $type = "ERROR ($errno)"; + G::customErrorLog( $type, $msg, $file, $line ); + break; + } + if (defined( "ERROR_SHOW_SOURCE_CODE" ) && ERROR_SHOW_SOURCE_CODE && $errno != E_STRICT) + G::showErrorSource( $type, $msg, $file, $line ); + } + + /** + * Function showErrorSource + * + * @author David S. Callizaya S. + * @access public + * @param eter string type + * @param eter string msg + * @param eter string file + * @param eter string line + * @return string + */ + function showErrorSource ($type, $msg, $file, $line) + { + global $__src_array; + $line_offset = 3; + + if (! isset( $__src_array[$file] )) + $__src_array[$file] = @file( $file ); + + if (! $__src_array[$file]) + return; + + if ($line - $line_offset < 1) + $start = 1; + else + $start = $line - $line_offset; + + if ($line + $line_offset > count( $__src_array[$file] )) + $end = count( $__src_array[$file] ); + else + $end = $line + $line_offset; + + print "
"; + print ""; + print " - - "; - for ($i = $start; $i <= $end; $i++) { - $str = @highlight_string ("", TRUE); - - $pos1 = strpos ($str,"<?"); - $pos2 = strrpos ($str,"?>"); - - $str = substr ($str, 0, $pos1) . - substr ($str, $pos1+5, $pos2-($pos1+5)) . - substr ($str, $pos2+5); - - ($i == $line) ? $bgcolor = "bgcolor=#ffccaa" : $bgcolor = "bgcolor=#ffffff"; - print " - "; - } - - print "
$type: $msg
File: $file
$i$str

"; - } - - /** - * customErrorLog - * - * @param string $type - * @param string $msg - * @param string $file - * @param string $line - * - * @return void - */ - /*public static*/ - function customErrorLog ($type, $msg, $file, $line) - { - global $HTTP_X_FORWARDED_FOR, $REMOTE_ADDR, $HTTP_USER_AGENT, $REQUEST_URI; - - $ip_addr = G::getIpAddress(); - - if (defined ('APPLICATION_CODE')) - $name = APPLICATION_CODE; - else - $name = "php"; - - if ( $file != '') - $msg .= " in $file:$line "; - - $date = date ( 'Y-m-d H:i:s'); - $REQUEST_URI = getenv ( 'REQUEST_URI' ); - $HTTP_USER_AGENT = getenv ( 'HTTP_USER_AGENT' ); - error_log ("[$date] [$ip_addr] [$name] $type: $msg [$HTTP_USER_AGENT] URI: $REQUEST_URI", 0); - } - - /** - * verboseError - * - * @param string $type - * @param string $errno - * @param string $msg - * @param string $file - * @param string $line - * @param string $context - * - * @return void - */ - /*public static*/ function verboseError ($type, $errno, $msg, $file, $line, $context) { - global $SERVER_ADMIN; - - print "

Error!

"; - print "An error occurred while executing this script. Please +
File: $file
$i$str

"; + } + + /** + * customErrorLog + * + * @param string $type + * @param string $msg + * @param string $file + * @param string $line + * + * @return void + */ + /*public static*/ + function customErrorLog ($type, $msg, $file, $line) + { + global $HTTP_X_FORWARDED_FOR, $REMOTE_ADDR, $HTTP_USER_AGENT, $REQUEST_URI; + + $ip_addr = G::getIpAddress(); + + if (defined( 'APPLICATION_CODE' )) + $name = APPLICATION_CODE; + else + $name = "php"; + + if ($file != '') + $msg .= " in $file:$line "; + + $date = date( 'Y-m-d H:i:s' ); + $REQUEST_URI = getenv( 'REQUEST_URI' ); + $HTTP_USER_AGENT = getenv( 'HTTP_USER_AGENT' ); + error_log( "[$date] [$ip_addr] [$name] $type: $msg [$HTTP_USER_AGENT] URI: $REQUEST_URI", 0 ); + } + + /** + * verboseError + * + * @param string $type + * @param string $errno + * @param string $msg + * @param string $file + * @param string $line + * @param string $context + * + * @return void + */ + /*public static*/ + function verboseError ($type, $errno, $msg, $file, $line, $context) + { + global $SERVER_ADMIN; + + print "

Error!

"; + print "An error occurred while executing this script. Please contact the $SERVER_ADMIN to - report this error."; - print "

"; - print "Here is the information provided by the script:"; - print "


";
-    print "Error type: $type (code: $errno)
"; - print "Error message: $msg
"; - print "Script name and line number of error: $file:$line
"; - print "Variable context when error occurred:
"; - print_r ($context); - print "

"; - } - - /*** Encrypt and decrypt functions ****/ - /** - * Encrypt string - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $string - * @param string $key - * @return string - */ - function encrypt($string, $key) - { - //print $string; - // if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) { - if (strpos($string, '|', 0) !== false) return $string; - $result = ''; - for($i = 0; $i'; - $result = base64_encode($result); - $result = str_replace ( '/' , '°' , $result); - $result = str_replace ( '=' , '' , $result); - // } - // else - // $result = $string; - - return $result; - } - - /** - * Decrypt string - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $string - * @param string $key - * @return string - */ - function decrypt($string, $key) { - - // if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) { - - //if (strpos($string, '|', 0) !== false) return $string; - $result = ''; - $string = str_replace ( '°', '/' , $string); - $string_jhl = explode("?",$string); - $string = base64_decode($string); - $string = base64_decode($string_jhl[0]); - - for($i=0; $i - * @access public - * @param string $target - * @return void - */ - function lookup($target) - { - //if( eregi("[a-zA-Z]", $target) ) - if( preg_match("[a-zA-Z]", $target) )//Made compatible to PHP 5.3 - $ntarget = gethostbyname($target); - else - $ntarget = gethostbyaddr($target); - return($ntarget); - } - - /*************** path functions *****************/ - - function mk_dir( $strPath, $rights = 0777) - { - $folder_path = array($strPath); - $oldumask = umask(0); - while(!@is_dir(dirname(end($folder_path))) - && dirname(end($folder_path)) != '/' - && dirname(end($folder_path)) != '.' - && dirname(end($folder_path)) != '') - array_push($folder_path, dirname(end($folder_path))); //var_dump($folder_path); die; - - while($parent_folder_path = array_pop($folder_path)) - if(!@is_dir($parent_folder_path)) - if(!@mkdir($parent_folder_path, $rights)) - //trigger_error ("Can't create folder \"$parent_folder_path\".", E_USER_WARNING); - umask($oldumask); - } - - /** - * rm_dir - * - * @param string $dirName - * - * @return void - */ - function rm_dir($dirName) - { - if (!is_writable($dirName)) { - return false; - } - - if (is_dir($dirName)) { - foreach(glob($dirName . '/{,.}*', GLOB_BRACE) as $file) { - if ( $file == $dirName . '/.' || $file == $dirName . '/..') { - continue; - } - if(is_dir($file)) { - G::rm_dir($file); - - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $dirNameWin = str_replace('/','\\' ,$dirName); - exec('DEL /F /S /Q ' . $dirNameWin . '', $res); - exec('RD /S /Q ' . $dirNameWin . '', $res); - } else { - @rmdir($file); - } - - } - else { - @unlink($file); - } - } - } - else { - @unlink($dirName); - } - } - - /** - * verify path - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $strPath path - * @param boolean $createPath if true this function will create the path - * @return boolean - */ - function verifyPath( $strPath , $createPath = false ) - { - $folder_path = strstr($strPath, '.') ? dirname($strPath) : $strPath; - - if ( file_exists($strPath ) || @is_dir( $strPath )) { - return true; - } - else { - if ( $createPath ) { - //TODO:: Define Environment constants: Devel (0777), Production (0770), ... - G::mk_dir ( $strPath , 0777 ); - } - else - return false; - } - return false; - } - - /** - * Expand the path using the path constants - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $strPath - * @return string - */ - function expandPath( $strPath = '' ) - { - $res = ""; - $res = PATH_CORE; - if( $strPath != "" ) - { - $res .= $strPath . "/"; - } - return $res; - } - - /** - * Load Gulliver Classes - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $strClass - * @return void - */ - function LoadSystem( $strClass ) - { - require_once( PATH_GULLIVER . 'class.' . $strClass . '.php' ); - } - - function LoadSystemExist($strClass) - { - if (file_exists (PATH_GULLIVER . 'class.' . $strClass . '.php') ) - return true; - else - return false; - } - - /** - * Render Page - * - * @author Fernando Ontiveros Lira - * @access public - * @param object $objContent - * @param string $strTemplate - * @param string $strSkin - * @return void - */ - function RenderPage( $strTemplate = "default", $strSkin = SYS_SKIN , $objContent = NULL, $layout='') - { - global $G_CONTENT; - global $G_TEMPLATE; - global $G_SKIN; - global $G_PUBLISH; - - $G_CONTENT = $objContent; - $G_TEMPLATE = $strTemplate; - $G_SKIN = $strSkin; - - try { - $file = G::ExpandPath('skinEngine') . 'skinEngine.php'; - include $file; - $skinEngine = new SkinEngine($G_TEMPLATE, $G_SKIN, $G_CONTENT); - $skinEngine->setLayout($layout); - $skinEngine->dispatch(); - } catch (Exception $e) { - global $G_PUBLISH; - if (is_null($G_PUBLISH)) { - $G_PUBLISH = new Publisher(); - } - if (count($G_PUBLISH->Parts) == 1) { - array_shift($G_PUBLISH->Parts); - } - global $oHeadPublisher; - $leimnudInitString = $oHeadPublisher->leimnudInitString; - $oHeadPublisher->clearScripts(); - $oHeadPublisher->leimnudInitString = $leimnudInitString; - $oHeadPublisher->addScriptFile('/js/maborak/core/maborak.js'); - $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', null, array('MESSAGE' => $e->getMessage())); - if (class_exists('SkinEngine')) { - $skinEngine = new SkinEngine('publish', 'blank', ''); - $skinEngine->dispatch(); - } else { - die($e->getMessage()); - } - } - } - - /** - * Load a skin - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $strSkinName - * @return void - */ - function LoadSkin( $strSkinName ) - { - //print $strSkinName; - //now, we are using the skin, a skin is a file in engine/skin directory - $file = G::ExpandPath( "skins" ) . $strSkinName. ".php"; - //G::pr($file); - if (file_exists ($file) ) { - require_once( $file ); - return; - } - else { - if (file_exists ( PATH_HTML . 'errors/error703.php') ) { - header ( 'location: /errors/error703.php' ); - die; - } - else { - $text = "The Skin $file does not exist, please review the Skin Definition"; - throw ( new Exception ( $text) ); - } - } - - } - - /** - * Include javascript files - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $strInclude - * @return void - */ - function LoadInclude( $strInclude ) - { - $incfile = G::ExpandPath( "includes" ) . 'inc.' . $strInclude . '.php'; - if ( !file_exists( $incfile )) { - $incfile = PATH_GULLIVER_HOME . 'includes' . PATH_SEP . 'inc.' . $strInclude . '.php'; - } - - if ( file_exists( $incfile )) { - require_once( $incfile ); - return true; - } - else { - return false; - } - } - - /** - * Include all model files - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $strInclude - * @return void - */ - function LoadAllModelClasses( ) - { - $baseDir = PATH_CORE . 'classes' . PATH_SEP . 'model'; - if ($handle = opendir( $baseDir )) { - while ( false !== ($file = readdir($handle))) { - if ( strpos($file, '.php',1) && !strpos($file, 'Peer.php',1) ) { - require_once ( $baseDir . PATH_SEP . $file ); - } - } - } - } - - /** - * Include all model plugin files - * - * LoadAllPluginModelClasses - * @author Hugo Loza - * @access public - * @return void - */ - function LoadAllPluginModelClasses(){ - //Get the current Include path, where the plugins directories should be - if ( !defined('PATH_SEPARATOR') ) { - define('PATH_SEPARATOR', ( substr(PHP_OS, 0, 3) == 'WIN' ) ? ';' : ':'); - } - $path=explode(PATH_SEPARATOR,get_include_path()); - - - foreach($path as $possiblePath){ - if(strstr($possiblePath,"plugins")){ - $baseDir = $possiblePath . 'classes' . PATH_SEP . 'model'; - if(file_exists($baseDir)){ - if ($handle = opendir( $baseDir )) { - while ( false !== ($file = readdir($handle))) { - if ( strpos($file, '.php',1) && !strpos($file, 'Peer.php',1) ) { - require_once ( $baseDir . PATH_SEP . $file ); - } - } - } - //Include also the extendGulliverClass that could have some new definitions for fields - if(file_exists($possiblePath . 'classes' . PATH_SEP.'class.extendGulliver.php')){ - include_once $possiblePath . 'classes' . PATH_SEP.'class.extendGulliver.php'; - } - } - } - } - } - - /** - * Load a template - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $strTemplateName - * @return void - */ - function LoadTemplate( $strTemplateName ) - { - if ( $strTemplateName == '' ) return; - $temp = $strTemplateName . ".php"; - $file = G::ExpandPath( 'templates' ) . $temp; - // Check if its a user template - if ( file_exists($file) ) { - //require_once( $file ); - include( $file ); - } else { - // Try to get the global system template - $file = PATH_TEMPLATE . PATH_SEP . $temp; - //require_once( $file ); - if ( file_exists($file) ) - include( $file ); - } - } - - /** - * Function LoadClassRBAC - * @author David S. Callizaya S. - * @access public - * @parameter string strClass - * @return string - */ - function LoadClassRBAC( $strClass ) - { - $classfile = PATH_RBAC . "class.$strClass" . '.php'; - require_once( $classfile ); - } - /** - * If the class is not defined by the aplication, it - * attempt to load the class from gulliver.system - * - * @author Fernando Ontiveros Lira , David S. Callizaya - * @access public - * @param string $strClass - * @return void - */ - function LoadClass( $strClass ) - { - $classfile = G::ExpandPath( "classes" ) . 'class.' . $strClass . '.php'; - if (!file_exists( $classfile )) { - if (file_exists( PATH_GULLIVER . 'class.' . $strClass . '.php' )) - return require_once( PATH_GULLIVER . 'class.' . $strClass . '.php' ); - else - return false; - } else { - return require_once( $classfile ); - } - } - - /** - * Loads a Class. If the class is not defined by the aplication, it - * attempt to load the class from gulliver.system - * - * @author Fernando Ontiveros Lira , David S. Callizaya - * @access public - * @param string $strClass - * @return void - */ - function LoadThirdParty( $sPath , $sFile ) - { - $classfile = PATH_THIRDPARTY . $sPath .'/'. $sFile . - ( (substr($sFile,0,-4)!=='.php')? '.php': '' ); - return require_once( $classfile ); - } - - /** - * Encrypt URL - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $urlLink - * @return string - */ - function encryptlink($url) - { - if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) - return urlencode( G::encrypt( $url ,URL_KEY ) ); - else - return $url; - } - - /** - * Parsing the URI - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $urlLink - * @return string - */ - static function parseURI($uri, $isRestRequest = false) - { - //*** process the $_POST with magic_quotes enabled - // The magic_quotes_gpc feature has been DEPRECATED as of PHP 5.3.0. - if (get_magic_quotes_gpc() === 1) { - $_POST = G::strip_slashes($_POST); - } - - $aRequestUri = explode('/', $uri ); - if ($isRestRequest) { - $args = self::parseRestUri($aRequestUri); - } else { - $args = self::parseNormalUri($aRequestUri); - } - - define("SYS_LANG", $args['SYS_LANG']); - define("SYS_SKIN", $args['SYS_SKIN']); - define('SYS_COLLECTION', $args['SYS_COLLECTION']); - define('SYS_TARGET', $args['SYS_TARGET']); - - if ( $args['SYS_COLLECTION'] == 'js2' ) { - print "ERROR"; die; - } - } - - public function parseNormalUri($aRequestUri) - { - if (substr($aRequestUri[1], 0, 3) == 'sys') { - define('SYS_TEMP', substr($aRequestUri[1], 3)); - } else { - define("ENABLE_ENCRYPT", 'yes'); - define('SYS_TEMP', $aRequestUri[1]); - $plain = '/sys' . SYS_TEMP; - - for ($i = 2; $i < count($aRequestUri); $i++) { - $decoded = G::decrypt(urldecode($aRequestUri[$i]), URL_KEY); - if ( $decoded == 'sWì›' ) { - $decoded = $VARS[$i]; //this is for the string "../" - } - $plain .= '/' . $decoded; - } - $_SERVER["REQUEST_URI"] = $plain; - } - - $work = explode('?', $_SERVER["REQUEST_URI"]); - - if (count($work) > 1) { - define('SYS_CURRENT_PARMS', $work[1]); - } else { - define('SYS_CURRENT_PARMS', ''); - } - - define('SYS_CURRENT_URI', $work[0]); - - if (!defined('SYS_CURRENT_PARMS')) { - define('SYS_CURRENT_PARMS', $work[1]); - } - - $preArray = explode('&', SYS_CURRENT_PARMS); - $buffer = explode('.', $work[0]); - - if (count($buffer) == 1) { - $buffer[1]=''; - } - - //request type - define('REQUEST_TYPE', ($buffer[1] != "" ?$buffer[1] : 'html')); - - $toparse = substr($buffer[0], 1, strlen($buffer[0]) - 1); - $uriVars = explode('/', $toparse); - - unset($work); - unset($buffer); - unset($toparse); - array_shift($uriVars); - - $args = array(); - $args['SYS_LANG'] = array_shift($uriVars); - $args['SYS_SKIN'] = array_shift($uriVars); - $args['SYS_COLLECTION'] = array_shift($uriVars); - $args['SYS_TARGET'] = array_shift($uriVars); - - //to enable more than 2 directories...in the methods structure - while (count($uriVars) > 0) { - $args['SYS_TARGET'] .= '/' . array_shift($uriVars); - } - - /* Fix to prevent use uxs skin outside siplified interface, - because that skin is not compatible with others interfaces*/ - if ($args['SYS_SKIN'] == 'uxs' && $args['SYS_COLLECTION'] != 'home' && $args['SYS_COLLECTION'] != 'cases') { - $config = System::getSystemConfiguration(); - $args['SYS_SKIN'] = $config['default_skin']; - } - - return $args; - } - - public function parseRestUri($requestUri) - { - $args = array(); - //$args['SYS_TEMP'] = $requestUri[1]; - define('SYS_TEMP', $requestUri[2]); - $restUri = ''; - - for ($i=3; $i < count($requestUri); $i++) { - $restUri .= '/' . $requestUri[$i]; - } - - $args['SYS_LANG'] = 'en'; // TODO, this can be set from http header - $args['SYS_SKIN'] = ''; - $args['SYS_COLLECTION'] = ''; - $args['SYS_TARGET'] = $restUri; - - return $args; - } - - function strip_slashes($vVar) { - if (is_array($vVar)) { - foreach($vVar as $sKey => $vValue) { - if (is_array($vValue)) { - G::strip_slashes($vVar[$sKey]); - } - else { - $vVar[$sKey] = stripslashes($vVar[$sKey]); - } - } - } - else { - $vVar = stripslashes($vVar); - } - - return $vVar; - } - - /** - * function to calculate the time used to render a page - */ - function logTimeByPage() - { - if (!defined(PATH_DATA)) { - return false; - } - - $serverAddr = $_SERVER['SERVER_ADDR']; - global $startingTime; - $endTime = microtime(true); - $time = $endTime - $startingTime; - $fpt= fopen ( PATH_DATA . 'log/time.log', 'a' ); - fwrite( $fpt, sprintf ( "%s.%03d %15s %s %5.3f %s\n", date('Y-m-d H:i:s'), $time, getenv('REMOTE_ADDR'), substr($serverAddr,-4), $time, $_SERVER['REQUEST_URI'] )); - fclose( $fpt); - } - - /** - * streaming a big JS file with small js files - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $file - * @return string - */ - function streamCSSBigFile( $filename ) - { - header('Content-Type: text/css'); - - //First get Skin info - $filenameParts = explode("-",$filename); - $skinName = $filenameParts[0]; - $skinVariant = "skin"; - - if(isset($filenameParts[1])) { - $skinVariant = strtolower($filenameParts[1]); - } - - if ($skinName == "jscolors") $skinName = "classic"; - if ($skinName == "xmlcolors") $skinName = "classic"; - if ($skinName=="classic") { - $configurationFile = G::ExpandPath( "skinEngine" ).'base'.PATH_SEP.'config.xml'; - } - else { - $configurationFile = PATH_CUSTOM_SKINS . $skinName . PATH_SEP . 'config.xml'; - - if (!is_file($configurationFile)) { - $configurationFile = G::ExpandPath( "skinEngine" ) . $skinName . PATH_SEP . 'config.xml'; - } - } - - //Read Configuration File - $xmlConfiguration = file_get_contents ( $configurationFile ); - $xmlConfigurationObj=G::xmlParser($xmlConfiguration); - $baseSkinDirectory=dirname($configurationFile); - $directorySize=G::getDirectorySize($baseSkinDirectory); - $mtime=$directorySize['maxmtime']; - - - - //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. - //$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); - - $gmt_mtime = gmdate("D, d M Y H:i:s", $mtime ) . " GMT"; - header('Pragma: cache'); - header('ETag: "' . md5 ($mtime . $filename ) . '"' ); - header("Last-Modified: " . $gmt_mtime ); - header('Cache-Control: public'); - header("Expires: " . gmdate("D, d M Y H:i:s", time () + 30*60*60*24 ) . " GMT"); //1 month - //header("Expires: " . gmdate("D, d M Y H:i:s", time () + 60*60*24 ) . " GMT"); //1 day - tempor - if( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ) { - if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) { - header('HTTP/1.1 304 Not Modified'); - exit(); - } - } - - if ( isset($_SERVER['HTTP_IF_NONE_MATCH'])) { - if ( str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == md5( $mtime . $filename)) { - header("HTTP/1.1 304 Not Modified"); - exit(); - } - } - - $outputHeader = "/* Autogenerated CSS file by gulliver framework \n"; - $outputHeader .=" Skin: $filename\n"; - $outputHeader .=" Configuration: $configurationFile\n"; - $mtimeNow = date('U'); - $gmt_mtimeNow = gmdate("D, d M Y H:i:s", $mtimeNow ) . " GMT"; - $outputHeader .=" Date: $gmt_mtimeNow*/\n"; - $output =""; - //Base files - switch(strtolower($skinVariant)){ - case "extjs": - //Base - $baseCSSPath=PATH_SKIN_ENGINE."base". PATH_SEP."baseCss". PATH_SEP; - $output .= file_get_contents ( $baseCSSPath . 'ext-all-notheme.css' ); - //$output .= file_get_contents ( $publicExtPath . 'ext-all.css' ); - - //Classic Skin - $extJsSkin = 'xtheme-gray'; - /*$publicExtPath = PATH_SKIN_ENGINE."base". PATH_SEP."css". PATH_SEP; + report this error."; + print "

"; + print "Here is the information provided by the script:"; + print "


";
+        print "Error type: $type (code: $errno)
"; + print "Error message: $msg
"; + print "Script name and line number of error: $file:$line
"; + print "Variable context when error occurred:
"; + print_r( $context ); + print "

"; + } + + /** + * * Encrypt and decrypt functions *** + */ + /** + * Encrypt string + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $string + * @param string $key + * @return string + */ + function encrypt ($string, $key) + { + //print $string; + // if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) { + if (strpos( $string, '|', 0 ) !== false) + return $string; + $result = ''; + for ($i = 0; $i < strlen( $string ); $i ++) { + $char = substr( $string, $i, 1 ); + $keychar = substr( $key, ($i % strlen( $key )) - 1, 1 ); + $char = chr( ord( $char ) + ord( $keychar ) ); + $result .= $char; + } + //echo $result . '
'; + $result = base64_encode( $result ); + $result = str_replace( '/', '°', $result ); + $result = str_replace( '=', '', $result ); + // } + // else + // $result = $string; + return $result; + } + + /** + * Decrypt string + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $string + * @param string $key + * @return string + */ + function decrypt ($string, $key) + { + // if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) { + //if (strpos($string, '|', 0) !== false) return $string; + $result = ''; + $string = str_replace( '°', '/', $string ); + $string_jhl = explode( "?", $string ); + $string = base64_decode( $string ); + $string = base64_decode( $string_jhl[0] ); + + for ($i = 0; $i < strlen( $string ); $i ++) { + $char = substr( $string, $i, 1 ); + $keychar = substr( $key, ($i % strlen( $key )) - 1, 1 ); + $char = chr( ord( $char ) - ord( $keychar ) ); + $result .= $char; + } + if (! empty( $string_jhl[1] )) + $result .= '?' . $string_jhl[1]; + // } + // else + // $result = $string; + return $result; + } + + /** + * Look up an IP address direction + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $target + * @return void + */ + function lookup ($target) + { + //if( eregi("[a-zA-Z]", $target) ) + if (preg_match( "[a-zA-Z]", $target )) //Made compatible to PHP 5.3 + $ntarget = gethostbyname( $target ); + else + $ntarget = gethostbyaddr( $target ); + return ($ntarget); + } + + /** + * ************* path functions **************** + */ + function mk_dir ($strPath, $rights = 0777) + { + $folder_path = array ($strPath + ); + $oldumask = umask( 0 ); + while (! @is_dir( dirname( end( $folder_path ) ) ) && dirname( end( $folder_path ) ) != '/' && dirname( end( $folder_path ) ) != '.' && dirname( end( $folder_path ) ) != '') + array_push( $folder_path, dirname( end( $folder_path ) ) ); //var_dump($folder_path); die; + + + while ($parent_folder_path = array_pop( $folder_path )) + if (! @is_dir( $parent_folder_path )) + if (! @mkdir( $parent_folder_path, $rights )) + //trigger_error ("Can't create folder \"$parent_folder_path\".", E_USER_WARNING); + umask( $oldumask ); + } + /** + * rm_dir + * + * @param string $dirName + * + * @return void + */ + function rm_dir ($dirName) + { + if (! is_writable( $dirName )) { + return false; + } + + if (is_dir( $dirName )) { + foreach (glob( $dirName . '/{,.}*', GLOB_BRACE ) as $file) { + if ($file == $dirName . '/.' || $file == $dirName . '/..') { + continue; + } + if (is_dir( $file )) { + G::rm_dir( $file ); + + if (strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN') { + $dirNameWin = str_replace( '/', '\\', $dirName ); + exec( 'DEL /F /S /Q ' . $dirNameWin . '', $res ); + exec( 'RD /S /Q ' . $dirNameWin . '', $res ); + } else { + @rmdir( $file ); + } + + } else { + @unlink( $file ); + } + } + } else { + @unlink( $dirName ); + } + } + + /** + * verify path + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $strPath path + * @param boolean $createPath if true this function will create the path + * @return boolean + */ + function verifyPath ($strPath, $createPath = false) + { + $folder_path = strstr( $strPath, '.' ) ? dirname( $strPath ) : $strPath; + + if (file_exists( $strPath ) || @is_dir( $strPath )) { + return true; + } else { + if ($createPath) { + //TODO:: Define Environment constants: Devel (0777), Production (0770), ... + G::mk_dir( $strPath, 0777 ); + } else + return false; + } + return false; + } + + /** + * Expand the path using the path constants + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $strPath + * @return string + */ + function expandPath ($strPath = '') + { + $res = ""; + $res = PATH_CORE; + if ($strPath != "") { + $res .= $strPath . "/"; + } + return $res; + } + + /** + * Load Gulliver Classes + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $strClass + * @return void + */ + function LoadSystem ($strClass) + { + require_once (PATH_GULLIVER . 'class.' . $strClass . '.php'); + } + + function LoadSystemExist ($strClass) + { + if (file_exists( PATH_GULLIVER . 'class.' . $strClass . '.php' )) + return true; + else + return false; + } + + /** + * Render Page + * + * @author Fernando Ontiveros Lira + * @access public + * @param object $objContent + * @param string $strTemplate + * @param string $strSkin + * @return void + */ + function RenderPage ($strTemplate = "default", $strSkin = SYS_SKIN, $objContent = NULL, $layout = '') + { + global $G_CONTENT; + global $G_TEMPLATE; + global $G_SKIN; + global $G_PUBLISH; + + $G_CONTENT = $objContent; + $G_TEMPLATE = $strTemplate; + $G_SKIN = $strSkin; + + try { + $file = G::ExpandPath( 'skinEngine' ) . 'skinEngine.php'; + include $file; + $skinEngine = new SkinEngine( $G_TEMPLATE, $G_SKIN, $G_CONTENT ); + $skinEngine->setLayout( $layout ); + $skinEngine->dispatch(); + } catch (Exception $e) { + global $G_PUBLISH; + if (is_null( $G_PUBLISH )) { + $G_PUBLISH = new Publisher(); + } + if (count( $G_PUBLISH->Parts ) == 1) { + array_shift( $G_PUBLISH->Parts ); + } + global $oHeadPublisher; + $leimnudInitString = $oHeadPublisher->leimnudInitString; + $oHeadPublisher->clearScripts(); + $oHeadPublisher->leimnudInitString = $leimnudInitString; + $oHeadPublisher->addScriptFile( '/js/maborak/core/maborak.js' ); + $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', null, array ('MESSAGE' => $e->getMessage() + ) ); + if (class_exists( 'SkinEngine' )) { + $skinEngine = new SkinEngine( 'publish', 'blank', '' ); + $skinEngine->dispatch(); + } else { + die( $e->getMessage() ); + } + } + } + + /** + * Load a skin + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $strSkinName + * @return void + */ + function LoadSkin ($strSkinName) + { + //print $strSkinName; + //now, we are using the skin, a skin is a file in engine/skin directory + $file = G::ExpandPath( "skins" ) . $strSkinName . ".php"; + //G::pr($file); + if (file_exists( $file )) { + require_once ($file); + return; + } else { + if (file_exists( PATH_HTML . 'errors/error703.php' )) { + header( 'location: /errors/error703.php' ); + die(); + } else { + $text = "The Skin $file does not exist, please review the Skin Definition"; + throw (new Exception( $text )); + } + } + + } + + /** + * Include javascript files + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $strInclude + * @return void + */ + function LoadInclude ($strInclude) + { + $incfile = G::ExpandPath( "includes" ) . 'inc.' . $strInclude . '.php'; + if (! file_exists( $incfile )) { + $incfile = PATH_GULLIVER_HOME . 'includes' . PATH_SEP . 'inc.' . $strInclude . '.php'; + } + + if (file_exists( $incfile )) { + require_once ($incfile); + return true; + } else { + return false; + } + } + + /** + * Include all model files + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $strInclude + * @return void + */ + function LoadAllModelClasses () + { + $baseDir = PATH_CORE . 'classes' . PATH_SEP . 'model'; + if ($handle = opendir( $baseDir )) { + while (false !== ($file = readdir( $handle ))) { + if (strpos( $file, '.php', 1 ) && ! strpos( $file, 'Peer.php', 1 )) { + require_once ($baseDir . PATH_SEP . $file); + } + } + } + } + + /** + * Include all model plugin files + * + * LoadAllPluginModelClasses + * + * @author Hugo Loza + * @access public + * @return void + */ + function LoadAllPluginModelClasses () + { + //Get the current Include path, where the plugins directories should be + if (! defined( 'PATH_SEPARATOR' )) { + define( 'PATH_SEPARATOR', (substr( PHP_OS, 0, 3 ) == 'WIN') ? ';' : ':' ); + } + $path = explode( PATH_SEPARATOR, get_include_path() ); + + foreach ($path as $possiblePath) { + if (strstr( $possiblePath, "plugins" )) { + $baseDir = $possiblePath . 'classes' . PATH_SEP . 'model'; + if (file_exists( $baseDir )) { + if ($handle = opendir( $baseDir )) { + while (false !== ($file = readdir( $handle ))) { + if (strpos( $file, '.php', 1 ) && ! strpos( $file, 'Peer.php', 1 )) { + require_once ($baseDir . PATH_SEP . $file); + } + } + } + //Include also the extendGulliverClass that could have some new definitions for fields + if (file_exists( $possiblePath . 'classes' . PATH_SEP . 'class.extendGulliver.php' )) { + include_once $possiblePath . 'classes' . PATH_SEP . 'class.extendGulliver.php'; + } + } + } + } + } + + /** + * Load a template + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $strTemplateName + * @return void + */ + function LoadTemplate ($strTemplateName) + { + if ($strTemplateName == '') + return; + $temp = $strTemplateName . ".php"; + $file = G::ExpandPath( 'templates' ) . $temp; + // Check if its a user template + if (file_exists( $file )) { + //require_once( $file ); + include ($file); + } else { + // Try to get the global system template + $file = PATH_TEMPLATE . PATH_SEP . $temp; + //require_once( $file ); + if (file_exists( $file )) + include ($file); + } + } + + /** + * Function LoadClassRBAC + * + * @author David S. Callizaya S. + * @access public + * @param eter string strClass + * @return string + */ + function LoadClassRBAC ($strClass) + { + $classfile = PATH_RBAC . "class.$strClass" . '.php'; + require_once ($classfile); + } + + /** + * If the class is not defined by the aplication, it + * attempt to load the class from gulliver.system + * + * @author Fernando Ontiveros Lira , David S. Callizaya + * @access public + * @param string $strClass + * @return void + */ + function LoadClass ($strClass) + { + $classfile = G::ExpandPath( "classes" ) . 'class.' . $strClass . '.php'; + if (! file_exists( $classfile )) { + if (file_exists( PATH_GULLIVER . 'class.' . $strClass . '.php' )) + return require_once (PATH_GULLIVER . 'class.' . $strClass . '.php'); + else + return false; + } else { + return require_once ($classfile); + } + } + + /** + * Loads a Class. + * If the class is not defined by the aplication, it + * attempt to load the class from gulliver.system + * + * @author Fernando Ontiveros Lira , David S. Callizaya + * @access public + * @param string $strClass + * @return void + */ + function LoadThirdParty ($sPath, $sFile) + { + $classfile = PATH_THIRDPARTY . $sPath . '/' . $sFile . ((substr( $sFile, 0, - 4 ) !== '.php') ? '.php' : ''); + return require_once ($classfile); + } + + /** + * Encrypt URL + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $urlLink + * @return string + */ + function encryptlink ($url) + { + if (defined( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes') + return urlencode( G::encrypt( $url, URL_KEY ) ); + else + return $url; + } + + /** + * Parsing the URI + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $urlLink + * @return string + */ + static function parseURI ($uri, $isRestRequest = false) + { + //*** process the $_POST with magic_quotes enabled + // The magic_quotes_gpc feature has been DEPRECATED as of PHP 5.3.0. + if (get_magic_quotes_gpc() === 1) { + $_POST = G::strip_slashes( $_POST ); + } + + $aRequestUri = explode( '/', $uri ); + if ($isRestRequest) { + $args = self::parseRestUri( $aRequestUri ); + } else { + $args = self::parseNormalUri( $aRequestUri ); + } + + define( "SYS_LANG", $args['SYS_LANG'] ); + define( "SYS_SKIN", $args['SYS_SKIN'] ); + define( 'SYS_COLLECTION', $args['SYS_COLLECTION'] ); + define( 'SYS_TARGET', $args['SYS_TARGET'] ); + + if ($args['SYS_COLLECTION'] == 'js2') { + print "ERROR"; + die(); + } + } + + public function parseNormalUri ($aRequestUri) + { + if (substr( $aRequestUri[1], 0, 3 ) == 'sys') { + define( 'SYS_TEMP', substr( $aRequestUri[1], 3 ) ); + } else { + define( "ENABLE_ENCRYPT", 'yes' ); + define( 'SYS_TEMP', $aRequestUri[1] ); + $plain = '/sys' . SYS_TEMP; + + for ($i = 2; $i < count( $aRequestUri ); $i ++) { + $decoded = G::decrypt( urldecode( $aRequestUri[$i] ), URL_KEY ); + if ($decoded == 'sWì›') { + $decoded = $VARS[$i]; //this is for the string "../" + } + $plain .= '/' . $decoded; + } + $_SERVER["REQUEST_URI"] = $plain; + } + + $work = explode( '?', $_SERVER["REQUEST_URI"] ); + + if (count( $work ) > 1) { + define( 'SYS_CURRENT_PARMS', $work[1] ); + } else { + define( 'SYS_CURRENT_PARMS', '' ); + } + + define( 'SYS_CURRENT_URI', $work[0] ); + + if (! defined( 'SYS_CURRENT_PARMS' )) { + define( 'SYS_CURRENT_PARMS', $work[1] ); + } + + $preArray = explode( '&', SYS_CURRENT_PARMS ); + $buffer = explode( '.', $work[0] ); + + if (count( $buffer ) == 1) { + $buffer[1] = ''; + } + + //request type + define( 'REQUEST_TYPE', ($buffer[1] != "" ? $buffer[1] : 'html') ); + + $toparse = substr( $buffer[0], 1, strlen( $buffer[0] ) - 1 ); + $uriVars = explode( '/', $toparse ); + + unset( $work ); + unset( $buffer ); + unset( $toparse ); + array_shift( $uriVars ); + + $args = array (); + $args['SYS_LANG'] = array_shift( $uriVars ); + $args['SYS_SKIN'] = array_shift( $uriVars ); + $args['SYS_COLLECTION'] = array_shift( $uriVars ); + $args['SYS_TARGET'] = array_shift( $uriVars ); + + //to enable more than 2 directories...in the methods structure + while (count( $uriVars ) > 0) { + $args['SYS_TARGET'] .= '/' . array_shift( $uriVars ); + } + + /* Fix to prevent use uxs skin outside siplified interface, + because that skin is not compatible with others interfaces*/ + if ($args['SYS_SKIN'] == 'uxs' && $args['SYS_COLLECTION'] != 'home' && $args['SYS_COLLECTION'] != 'cases') { + $config = System::getSystemConfiguration(); + $args['SYS_SKIN'] = $config['default_skin']; + } + + return $args; + } + + public function parseRestUri ($requestUri) + { + $args = array (); + //$args['SYS_TEMP'] = $requestUri[1]; + define( 'SYS_TEMP', $requestUri[2] ); + $restUri = ''; + + for ($i = 3; $i < count( $requestUri ); $i ++) { + $restUri .= '/' . $requestUri[$i]; + } + + $args['SYS_LANG'] = 'en'; // TODO, this can be set from http header + $args['SYS_SKIN'] = ''; + $args['SYS_COLLECTION'] = ''; + $args['SYS_TARGET'] = $restUri; + + return $args; + } + + function strip_slashes ($vVar) + { + if (is_array( $vVar )) { + foreach ($vVar as $sKey => $vValue) { + if (is_array( $vValue )) { + G::strip_slashes( $vVar[$sKey] ); + } else { + $vVar[$sKey] = stripslashes( $vVar[$sKey] ); + } + } + } else { + $vVar = stripslashes( $vVar ); + } + + return $vVar; + } + + /** + * function to calculate the time used to render a page + */ + function logTimeByPage () + { + if (! defined( PATH_DATA )) { + return false; + } + + $serverAddr = $_SERVER['SERVER_ADDR']; + global $startingTime; + $endTime = microtime( true ); + $time = $endTime - $startingTime; + $fpt = fopen( PATH_DATA . 'log/time.log', 'a' ); + fwrite( $fpt, sprintf( "%s.%03d %15s %s %5.3f %s\n", date( 'Y-m-d H:i:s' ), $time, getenv( 'REMOTE_ADDR' ), substr( $serverAddr, - 4 ), $time, $_SERVER['REQUEST_URI'] ) ); + fclose( $fpt ); + } + + /** + * streaming a big JS file with small js files + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $file + * @return string + */ + function streamCSSBigFile ($filename) + { + header( 'Content-Type: text/css' ); + + //First get Skin info + $filenameParts = explode( "-", $filename ); + $skinName = $filenameParts[0]; + $skinVariant = "skin"; + + if (isset( $filenameParts[1] )) { + $skinVariant = strtolower( $filenameParts[1] ); + } + + if ($skinName == "jscolors") + $skinName = "classic"; + if ($skinName == "xmlcolors") + $skinName = "classic"; + if ($skinName == "classic") { + $configurationFile = G::ExpandPath( "skinEngine" ) . 'base' . PATH_SEP . 'config.xml'; + } else { + $configurationFile = PATH_CUSTOM_SKINS . $skinName . PATH_SEP . 'config.xml'; + + if (! is_file( $configurationFile )) { + $configurationFile = G::ExpandPath( "skinEngine" ) . $skinName . PATH_SEP . 'config.xml'; + } + } + + //Read Configuration File + $xmlConfiguration = file_get_contents( $configurationFile ); + $xmlConfigurationObj = G::xmlParser( $xmlConfiguration ); + $baseSkinDirectory = dirname( $configurationFile ); + $directorySize = G::getDirectorySize( $baseSkinDirectory ); + $mtime = $directorySize['maxmtime']; + + //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. + //$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); + + + $gmt_mtime = gmdate( "D, d M Y H:i:s", $mtime ) . " GMT"; + header( 'Pragma: cache' ); + header( 'ETag: "' . md5( $mtime . $filename ) . '"' ); + header( "Last-Modified: " . $gmt_mtime ); + header( 'Cache-Control: public' ); + header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + 30 * 60 * 60 * 24 ) . " GMT" ); //1 month + //header("Expires: " . gmdate("D, d M Y H:i:s", time () + 60*60*24 ) . " GMT"); //1 day - tempor + if (isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] )) { + if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) { + header( 'HTTP/1.1 304 Not Modified' ); + exit(); + } + } + + if (isset( $_SERVER['HTTP_IF_NONE_MATCH'] )) { + if (str_replace( '"', '', stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) == md5( $mtime . $filename )) { + header( "HTTP/1.1 304 Not Modified" ); + exit(); + } + } + + $outputHeader = "/* Autogenerated CSS file by gulliver framework \n"; + $outputHeader .= " Skin: $filename\n"; + $outputHeader .= " Configuration: $configurationFile\n"; + $mtimeNow = date( 'U' ); + $gmt_mtimeNow = gmdate( "D, d M Y H:i:s", $mtimeNow ) . " GMT"; + $outputHeader .= " Date: $gmt_mtimeNow*/\n"; + $output = ""; + //Base files + switch (strtolower( $skinVariant )) { + case "extjs": + //Base + $baseCSSPath = PATH_SKIN_ENGINE . "base" . PATH_SEP . "baseCss" . PATH_SEP; + $output .= file_get_contents( $baseCSSPath . 'ext-all-notheme.css' ); + //$output .= file_get_contents ( $publicExtPath . 'ext-all.css' ); + + + //Classic Skin + $extJsSkin = 'xtheme-gray'; + /*$publicExtPath = PATH_SKIN_ENGINE."base". PATH_SEP."css". PATH_SEP; $output .= file_get_contents ( $publicExtPath . $extJsSkin . '.css' ); $output .= file_get_contents ( $publicExtPath . 'pmos-' . $extJsSkin . '.css' ); - */ - //adding the extend css for extjs-pmos - //TODO: move this files to pmos-xthem.. - //$cssThemeExtensions = glob(PATH_TPL . "*/css/extjs-extend/{$extJsSkin}.css"); - //foreach($cssThemeExtensions as $cssThemeExtensionFile) - //$helper->addFile($cssThemeExtensionFile); - //$output .= file_get_contents ( $cssThemeExtensionFile ); - // $classicCSSPath=PATH_SKIN_ENGINE."base". PATH_SEP."css". PATH_SEP; - // $output .= file_get_contents ( $classicCSSPath . 'sprite.css' ); - //$output .= file_get_contents ( $classicCSSPath . 'sprite_ie.css' ); - - - break; - default: - - break; - - } - - - - //Get Browser Info - $infoBrowser=G::browser_detection( 'full_assoc'); - $browserName=$infoBrowser['browser_working']; - if(isset($infoBrowser[$browserName.'_data'])){ - if($infoBrowser[$browserName.'_data'][0]!=""){ - $browserName=$infoBrowser[$browserName.'_data'][0]; - } - } + */ + //adding the extend css for extjs-pmos + //TODO: move this files to pmos-xthem.. + //$cssThemeExtensions = glob(PATH_TPL . "*/css/extjs-extend/{$extJsSkin}.css"); + //foreach($cssThemeExtensions as $cssThemeExtensionFile) + //$helper->addFile($cssThemeExtensionFile); + //$output .= file_get_contents ( $cssThemeExtensionFile ); + // $classicCSSPath=PATH_SKIN_ENGINE."base". PATH_SEP."css". PATH_SEP; + // $output .= file_get_contents ( $classicCSSPath . 'sprite.css' ); + //$output .= file_get_contents ( $classicCSSPath . 'sprite_ie.css' ); + + + break; + default: + + break; + + } + + //Get Browser Info + $infoBrowser = G::browser_detection( 'full_assoc' ); + $browserName = $infoBrowser['browser_working']; + if (isset( $infoBrowser[$browserName . '_data'] )) { + if ($infoBrowser[$browserName . '_data'][0] != "") { + $browserName = $infoBrowser[$browserName . '_data'][0]; + } + } //print "

$browserName

"; //G::pr($infoBrowser); @@ -1225,281 +1220,282 @@ class G $output .= file_get_contents ( $baseSkinDirectory . PATH_SEP.'css'.PATH_SEP.$cssFileInfo['__ATTRIBUTES__']['file'] ); } } - } - //Remove comments.. - $regex = array( -"`^([\t\s]+)`ism"=>'', -"`^\/\*(.+?)\*\/`ism"=>"", -"`([\n\A;]+)\/\*(.+?)\*\/`ism"=>"$1", -"`([\n\A;\s]+)//(.+?)[\n\r]`ism"=>"$1\n", -"`(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+`ism"=>"\n" -); -$output = preg_replace(array_keys($regex),$regex,$output); -$output = $outputHeader.$output; - - return $output; - } - - /** - * streaming a big JS file with small js files - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $file - * @param boolean $download - * @param string $downloadFileName - * @return string - */ - function streamJSTranslationFile( $filename, $locale = 'en' ) - { - header('Content-Type: text/javascript'); - - if (!G::LoadTranslationObject($locale)) { - header('Cache-Control: no-cache'); - header('Pragma: no-cache'); - return; - } - - global $translation; - - //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. - $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); - if ( file_exists($filename) ) - $mtime = filemtime($filename); - else - $mtime = date('U'); - $gmt_mtime = gmdate("D, d M Y H:i:s", $mtime ) . " GMT"; - header('Pragma: cache'); - header('ETag: "' . md5 ($mtime . $filename ) . '"' ); - header("Last-Modified: " . $gmt_mtime ); - header('Cache-Control: public'); - header("Expires: " . gmdate("D, d M Y H:i:s", time () + 30*60*60*24 ) . " GMT"); //1 month - if( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ) { - if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) { - header('HTTP/1.1 304 Not Modified'); - exit(); - } - } - - if ( isset($_SERVER['HTTP_IF_NONE_MATCH'])) { - if ( str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == md5( $mtime . $filename)) { - header("HTTP/1.1 304 Not Modified"); - exit(); - } - } - - return JSMin::minify ( 'var TRANSLATIONS = ' . G::json_encode($translation) . ';' ); - } - - /** - * streaming a file - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $file - * @param boolean $download - * @param string $downloadFileName - * @return string - */ - function streamFile( $file, $download = false, $downloadFileName = '' ) - { - require_once (PATH_THIRDPARTY . 'jsmin/jsmin.php'); - $folderarray = explode ( '/', $file ); - $typearray = explode ( '.', basename( $file) ); - $typefile = $typearray[ count($typearray) -1 ]; - $filename = $file; - - //trick to generate the translation.language.js file , merging two files and then minified the content. - if ( strtolower ($typefile ) == 'js' && $typearray[0] == 'translation' ) { - $output = G::streamJSTranslationFile ($filename, $typearray[1]); - print $output; - return; - } - - //trick to generate the big css file for ext style . - if ( strtolower ($typefile ) == 'css' && $folderarray[count($folderarray)-2] == 'css' ) { - $output = G::streamCSSBigFile( $typearray[0] ); - print $output; - return; - } - - if ( file_exists ( $filename ) ) { - switch ( strtolower ($typefile ) ) { - case 'swf' : - G::sendHeaders ( $filename , 'application/x-shockwave-flash', $download, $downloadFileName ); break; - case 'js' : - G::sendHeaders ( $filename , 'text/javascript', $download, $downloadFileName ); break; - case 'htm' : - case 'html' : - G::sendHeaders ( $filename , 'text/html', $download, $downloadFileName ); break; - case 'htc' : - G::sendHeaders ( $filename , 'text/plain', $download, $downloadFileName ); break; - case 'json' : - G::sendHeaders ( $filename , 'text/plain', $download, $downloadFileName ); break; - case 'gif' : - G::sendHeaders ( $filename , 'image/gif', $download, $downloadFileName ); break; - case 'png' : - G::sendHeaders ( $filename , 'image/png', $download, $downloadFileName ); break; - case 'jpg' : - G::sendHeaders ( $filename , 'image/jpg', $download, $downloadFileName ); break; - case 'css' : - G::sendHeaders ( $filename , 'text/css', $download, $downloadFileName ); break; - case 'css' : - G::sendHeaders ( $filename , 'text/css', $download, $downloadFileName ); break; - case 'xml' : - G::sendHeaders ( $filename , 'text/xml', $download, $downloadFileName ); break; - case 'txt' : - G::sendHeaders ( $filename , 'text/html', $download, $downloadFileName ); break; - case 'doc' : - case 'pdf' : - case 'pm' : - case 'po' : - G::sendHeaders ( $filename , 'application/octet-stream', $download, $downloadFileName ); break; - case 'php' : - if ($download) { - G::sendHeaders ( $filename , 'text/plain', $download, $downloadFileName ); - } - else { - require_once( $filename ); - return; - } - break; - case 'tar': - G::sendHeaders ( $filename , 'application/x-tar', $download, $downloadFileName ); break; - default : - //throw new Exception ( "Unknown type of file '$file'. " ); - G::sendHeaders ( $filename , 'application/octet-stream', $download, $downloadFileName ); break; - break; - } - } - else { - if( strpos($file, 'gulliver') !== false ){ - list($path, $filename) = explode('gulliver', $file); - } - - $_SESSION['phpFileNotFound'] = $file; - G::header("location: /errors/error404.php?l=".$_SERVER['REQUEST_URI']); - } - - switch ( strtolower($typefile ) ) { - case "js" : - $paths = explode ( '/', $filename); - $jsName = $paths[ count ($paths) -1 ]; - $output = ''; - $pathJs = PATH_GULLIVER_HOME . PATH_SEP . 'js' . PATH_SEP; - switch ( $jsName ) { - case 'draw2d.js' : - $cachePath = PATH_C . 'ExtJs' . PATH_SEP; - $checksum = G::getCheckSum(array( - $pathJs . 'ext/wz_jsgraphics.js', - $pathJs . 'ext/mootools.js', - $pathJs . 'ext/moocanvas.js' - )); - - $cf = $cachePath . "ext-draw2d-cache.$checksum.js"; - $cfStored = G::getCacheFileNameByPattern($cachePath, 'ext-draw2d-cache.*.js'); - //error_log("draw2d.js ".$checksum ."==". $cfStored['checksum']); - if(is_file($cfStored['filename']) && $checksum == $cfStored['checksum']) { - $output = file_get_contents($cf); - } else { - if (is_file($cfStored['filename'])) - @unlink($cfStored['filename']); - - $output .= JSMin::minify ( file_get_contents ( $pathJs . 'ext/wz_jsgraphics.js' ) ); - $output .= JSMin::minify ( file_get_contents ( $pathJs . 'ext/mootools.js' ) ); - $output .= JSMin::minify ( file_get_contents ( $pathJs . 'ext/moocanvas.js' ) ); - $output .= file_get_contents ($pathJs . 'ext/draw2d.js'); //already minified - file_put_contents($cf, $output); - //error_log("draw2d.js writting ".$cf); - } - break; - case 'ext-all.js' : - $cachePath = PATH_C . 'ExtJs' . PATH_SEP; - $checksum = G::getCheckSum(array( - $pathJs . 'ext/pmos-common.js', - $pathJs . 'ext/ux/miframe.js', - $pathJs . 'ext/ux.locationbar/Ext.ux.LocationBar.js', - $pathJs . 'ext/ux.statusbar/ext-statusbar.js', - $pathJs . 'ext/ux.treefilterx/Ext.ux.tree.TreeFilterX.js' - )); - - $cfStored = G::getCacheFileNameByPattern($cachePath, 'ext-all-cache.*.js'); - $cf = PATH_C . 'ExtJs' . PATH_SEP . "ext-all-cache.$checksum.js"; - if(is_file($cfStored['filename']) && $checksum == $cfStored['checksum']) { - $output = file_get_contents($cf); - } else { - if (is_file($cfStored['filename'])) - @unlink($cfStored['filename']); - - $output .= file_get_contents ( $pathJs . 'ext/ext-all.js' ); //already minified - $output .= file_get_contents ( $pathJs . 'ext/ux/ux-all.js' ); //already minified - $output .= JSMin::minify ( file_get_contents ( $pathJs . 'ext/pmos-common.js' ) ); - $output .= JSMin::minify ( file_get_contents ( $pathJs . 'ext/ux/miframe.js' ) ); - $output .= JSMin::minify ( file_get_contents ( $pathJs . 'ext/ux.locationbar/Ext.ux.LocationBar.js' ) ); - $output .= JSMin::minify ( file_get_contents ( $pathJs . 'ext/ux.statusbar/ext-statusbar.js' ) ); - $output .= JSMin::minify ( file_get_contents ( $pathJs . 'ext/ux.treefilterx/Ext.ux.tree.TreeFilterX.js' ) ); - - file_put_contents($cf, $output); - } - break; - - case 'maborak.js' : - $oHeadPublisher =& headPublisher::getSingleton(); - foreach ( $oHeadPublisher->maborakFiles as $fileJS ) { - $output .= JSMin::minify ( file_get_contents ( $fileJS ) ); - //$output .= G::trimSourceCodeFile ($fileJS ); - } - break; - case 'maborak.loader.js': - $oHeadPublisher =& headPublisher::getSingleton(); - foreach ( $oHeadPublisher->maborakLoaderFiles as $fileJS ) { - $output .= JSMin::minify ( file_get_contents ( $fileJS ) ); - //$output .= G::trimSourceCodeFile ($fileJS ); - } - break; - default : - //$output = file_get_contents ( $filename ) ; - $output = JSMin::minify ( file_get_contents ( $filename ) ); - //$output = G::trimSourceCodeFile ($filename ); - } - print $output; - break; - case 'css' : - //$output = JSMin::minify ( file_get_contents ( $filename) ); - print G::trimSourceCodeFile ($filename ); - break; - default : - @readfile($filename); - } - } - - /** - * trimSourceCodeFile - * - * @param string $filename - * - * @return string $output - */ - function trimSourceCodeFile ( $filename ) { - $handle = fopen ($filename, "r"); - $lastChar = ''; - $firstChar = ''; - $content = ''; - $line = ''; - - //no optimizing code - if ($handle) { - while (!feof($handle)) { - //$line = trim( fgets($handle, 16096) ) . "\n" ; - $line = fgets($handle, 16096); - $content .= $line; - } - fclose($handle); - } - return $content; - //end NO optimizing code - //begin optimizing code - /* + } + //Remove comments.. + $regex = array ("`^([\t\s]+)`ism" => '',"`^\/\*(.+?)\*\/`ism" => "","`([\n\A;]+)\/\*(.+?)\*\/`ism" => "$1","`([\n\A;\s]+)//(.+?)[\n\r]`ism" => "$1\n","`(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+`ism" => "\n" + ); + $output = preg_replace( array_keys( $regex ), $regex, $output ); + $output = $outputHeader . $output; + + return $output; + } + + /** + * streaming a big JS file with small js files + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $file + * @param boolean $download + * @param string $downloadFileName + * @return string + */ + function streamJSTranslationFile ($filename, $locale = 'en') + { + header( 'Content-Type: text/javascript' ); + + if (! G::LoadTranslationObject( $locale )) { + header( 'Cache-Control: no-cache' ); + header( 'Pragma: no-cache' ); + return; + } + + global $translation; + + //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. + $userAgent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); + if (file_exists( $filename )) + $mtime = filemtime( $filename ); + else + $mtime = date( 'U' ); + $gmt_mtime = gmdate( "D, d M Y H:i:s", $mtime ) . " GMT"; + header( 'Pragma: cache' ); + header( 'ETag: "' . md5( $mtime . $filename ) . '"' ); + header( "Last-Modified: " . $gmt_mtime ); + header( 'Cache-Control: public' ); + header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + 30 * 60 * 60 * 24 ) . " GMT" ); //1 month + if (isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] )) { + if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) { + header( 'HTTP/1.1 304 Not Modified' ); + exit(); + } + } + + if (isset( $_SERVER['HTTP_IF_NONE_MATCH'] )) { + if (str_replace( '"', '', stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) == md5( $mtime . $filename )) { + header( "HTTP/1.1 304 Not Modified" ); + exit(); + } + } + + return JSMin::minify( 'var TRANSLATIONS = ' . G::json_encode( $translation ) . ';' ); + } + + /** + * streaming a file + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $file + * @param boolean $download + * @param string $downloadFileName + * @return string + */ + function streamFile ($file, $download = false, $downloadFileName = '') + { + require_once (PATH_THIRDPARTY . 'jsmin/jsmin.php'); + $folderarray = explode( '/', $file ); + $typearray = explode( '.', basename( $file ) ); + $typefile = $typearray[count( $typearray ) - 1]; + $filename = $file; + + //trick to generate the translation.language.js file , merging two files and then minified the content. + if (strtolower( $typefile ) == 'js' && $typearray[0] == 'translation') { + $output = G::streamJSTranslationFile( $filename, $typearray[1] ); + print $output; + return; + } + + //trick to generate the big css file for ext style . + if (strtolower( $typefile ) == 'css' && $folderarray[count( $folderarray ) - 2] == 'css') { + $output = G::streamCSSBigFile( $typearray[0] ); + print $output; + return; + } + + if (file_exists( $filename )) { + switch (strtolower( $typefile )) { + case 'swf': + G::sendHeaders( $filename, 'application/x-shockwave-flash', $download, $downloadFileName ); + break; + case 'js': + G::sendHeaders( $filename, 'text/javascript', $download, $downloadFileName ); + break; + case 'htm': + case 'html': + G::sendHeaders( $filename, 'text/html', $download, $downloadFileName ); + break; + case 'htc': + G::sendHeaders( $filename, 'text/plain', $download, $downloadFileName ); + break; + case 'json': + G::sendHeaders( $filename, 'text/plain', $download, $downloadFileName ); + break; + case 'gif': + G::sendHeaders( $filename, 'image/gif', $download, $downloadFileName ); + break; + case 'png': + G::sendHeaders( $filename, 'image/png', $download, $downloadFileName ); + break; + case 'jpg': + G::sendHeaders( $filename, 'image/jpg', $download, $downloadFileName ); + break; + case 'css': + G::sendHeaders( $filename, 'text/css', $download, $downloadFileName ); + break; + case 'css': + G::sendHeaders( $filename, 'text/css', $download, $downloadFileName ); + break; + case 'xml': + G::sendHeaders( $filename, 'text/xml', $download, $downloadFileName ); + break; + case 'txt': + G::sendHeaders( $filename, 'text/html', $download, $downloadFileName ); + break; + case 'doc': + case 'pdf': + case 'pm': + case 'po': + G::sendHeaders( $filename, 'application/octet-stream', $download, $downloadFileName ); + break; + case 'php': + if ($download) { + G::sendHeaders( $filename, 'text/plain', $download, $downloadFileName ); + } else { + require_once ($filename); + return; + } + break; + case 'tar': + G::sendHeaders( $filename, 'application/x-tar', $download, $downloadFileName ); + break; + default: + //throw new Exception ( "Unknown type of file '$file'. " ); + G::sendHeaders( $filename, 'application/octet-stream', $download, $downloadFileName ); + break; + break; + } + } else { + if (strpos( $file, 'gulliver' ) !== false) { + list ($path, $filename) = explode( 'gulliver', $file ); + } + + $_SESSION['phpFileNotFound'] = $file; + G::header( "location: /errors/error404.php?l=" . $_SERVER['REQUEST_URI'] ); + } + + switch (strtolower( $typefile )) { + case "js": + $paths = explode( '/', $filename ); + $jsName = $paths[count( $paths ) - 1]; + $output = ''; + $pathJs = PATH_GULLIVER_HOME . PATH_SEP . 'js' . PATH_SEP; + switch ($jsName) { + case 'draw2d.js': + $cachePath = PATH_C . 'ExtJs' . PATH_SEP; + $checksum = G::getCheckSum( array ($pathJs . 'ext/wz_jsgraphics.js',$pathJs . 'ext/mootools.js',$pathJs . 'ext/moocanvas.js' + ) ); + + $cf = $cachePath . "ext-draw2d-cache.$checksum.js"; + $cfStored = G::getCacheFileNameByPattern( $cachePath, 'ext-draw2d-cache.*.js' ); + //error_log("draw2d.js ".$checksum ."==". $cfStored['checksum']); + if (is_file( $cfStored['filename'] ) && $checksum == $cfStored['checksum']) { + $output = file_get_contents( $cf ); + } else { + if (is_file( $cfStored['filename'] )) + @unlink( $cfStored['filename'] ); + + $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/wz_jsgraphics.js' ) ); + $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/mootools.js' ) ); + $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/moocanvas.js' ) ); + $output .= file_get_contents( $pathJs . 'ext/draw2d.js' ); //already minified + file_put_contents( $cf, $output ); + //error_log("draw2d.js writting ".$cf); + } + break; + case 'ext-all.js': + $cachePath = PATH_C . 'ExtJs' . PATH_SEP; + $checksum = G::getCheckSum( array ($pathJs . 'ext/pmos-common.js',$pathJs . 'ext/ux/miframe.js',$pathJs . 'ext/ux.locationbar/Ext.ux.LocationBar.js',$pathJs . 'ext/ux.statusbar/ext-statusbar.js',$pathJs . 'ext/ux.treefilterx/Ext.ux.tree.TreeFilterX.js' + ) ); + + $cfStored = G::getCacheFileNameByPattern( $cachePath, 'ext-all-cache.*.js' ); + $cf = PATH_C . 'ExtJs' . PATH_SEP . "ext-all-cache.$checksum.js"; + if (is_file( $cfStored['filename'] ) && $checksum == $cfStored['checksum']) { + $output = file_get_contents( $cf ); + } else { + if (is_file( $cfStored['filename'] )) + @unlink( $cfStored['filename'] ); + + $output .= file_get_contents( $pathJs . 'ext/ext-all.js' ); //already minified + $output .= file_get_contents( $pathJs . 'ext/ux/ux-all.js' ); //already minified + $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/pmos-common.js' ) ); + $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/ux/miframe.js' ) ); + $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/ux.locationbar/Ext.ux.LocationBar.js' ) ); + $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/ux.statusbar/ext-statusbar.js' ) ); + $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/ux.treefilterx/Ext.ux.tree.TreeFilterX.js' ) ); + + file_put_contents( $cf, $output ); + } + break; + + case 'maborak.js': + $oHeadPublisher = & headPublisher::getSingleton(); + foreach ($oHeadPublisher->maborakFiles as $fileJS) { + $output .= JSMin::minify( file_get_contents( $fileJS ) ); + //$output .= G::trimSourceCodeFile ($fileJS ); + } + break; + case 'maborak.loader.js': + $oHeadPublisher = & headPublisher::getSingleton(); + foreach ($oHeadPublisher->maborakLoaderFiles as $fileJS) { + $output .= JSMin::minify( file_get_contents( $fileJS ) ); + //$output .= G::trimSourceCodeFile ($fileJS ); + } + break; + default: + //$output = file_get_contents ( $filename ) ; + $output = JSMin::minify( file_get_contents( $filename ) ); + //$output = G::trimSourceCodeFile ($filename ); + } + print $output; + break; + case 'css': + //$output = JSMin::minify ( file_get_contents ( $filename) ); + print G::trimSourceCodeFile( $filename ); + break; + default: + @readfile( $filename ); + } + } + + /** + * trimSourceCodeFile + * + * @param string $filename + * + * @return string $output + */ + function trimSourceCodeFile ($filename) + { + $handle = fopen( $filename, "r" ); + $lastChar = ''; + $firstChar = ''; + $content = ''; + $line = ''; + + //no optimizing code + if ($handle) { + while (! feof( $handle )) { + //$line = trim( fgets($handle, 16096) ) . "\n" ; + $line = fgets( $handle, 16096 ); + $content .= $line; + } + fclose( $handle ); + } + return $content; + //end NO optimizing code + //begin optimizing code + /* if ($handle) { while (!feof($handle)) { $lastChar = ( strlen ( $line ) > 5 ) ? $line[strlen($line)-1] : ''; @@ -1517,465 +1513,493 @@ $output = $outputHeader.$output; } fclose($handle); } - */ - //end optimizing code - - $index = 0; - $output = ''; - while ( $index < strlen ($content) ) { - $car = $content[$index]; - $index++; - if ( $car == '/' && isset($content[$index]) && $content[$index] == '*' ) { - $endComment = false; - $index ++; - while ( $endComment == false && $index < strlen ($content) ) { - if ($content[$index] == '*' && isset($content[$index+1]) && $content[$index+1] == '/' ) { - $endComment = true; $index ++; - } - $index ++; - } - $car = ''; - } - $output .= $car; - } - return $output; - } - - /** - * sendHeaders - * - * @param string $filename - * @param string $contentType default value '' - * @param boolean $download default value false - * @param string $downloadFileName default value '' - * - * @return void - */ - function sendHeaders ( $filename , $contentType = '', $download = false, $downloadFileName = '' ) - { - if ($download) { - if ($downloadFileName == '') { - $aAux = explode('/', $filename); - $downloadFileName = $aAux[count($aAux) - 1]; - } - header('Content-Disposition: attachment; filename="' . $downloadFileName . '"'); - } - header('Content-Type: ' . $contentType); - - //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. - $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); - if ( preg_match("/msie/i", $userAgent)) { - //if ( ereg("msie", $userAgent)) { - header('Pragma: cache'); - - $mtime = filemtime($filename); - $gmt_mtime = gmdate("D, d M Y H:i:s", $mtime ) . " GMT"; - header('ETag: "' . md5 ($mtime . $filename ) . '"' ); - header("Last-Modified: " . $gmt_mtime ); - header('Cache-Control: public'); - header("Expires: " . gmdate("D, d M Y H:i:s", time () + 60*10 ) . " GMT"); //ten minutes - return; - } - - if (!$download) { - - header('Pragma: cache'); - - if ( file_exists($filename) ) - $mtime = filemtime($filename); - else - $mtime = date('U'); - $gmt_mtime = gmdate("D, d M Y H:i:s", $mtime ) . " GMT"; - header('ETag: "' . md5 ($mtime . $filename ) . '"' ); - header("Last-Modified: " . $gmt_mtime ); - header('Cache-Control: public'); - header("Expires: " . gmdate("D, d M Y H:i:s", time () + 90*60*60*24 ) . " GMT"); - if( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ) { - if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) { - header('HTTP/1.1 304 Not Modified'); - exit(); - } - } - - if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { - if ( str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == md5( $mtime . $filename)) { - header("HTTP/1.1 304 Not Modified"); - exit(); - } - } - } - } - - /** - * Transform a public URL into a local path. - * - * @author David S. Callizaya S. - * @access public - * @param string $url - * @param string $corvertionTable - * @param string $realPath = local path - * @return boolean - */ - function virtualURI( $url , $convertionTable , &$realPath ) - { - foreach($convertionTable as $urlPattern => $localPath ) { - // $urlPattern = addcslashes( $urlPattern , '/'); - $urlPattern = addcslashes( $urlPattern , './'); - $urlPattern = '/^' . str_replace( - array('*','?'), - array('.*','.?'), - $urlPattern) . '$/'; - if (preg_match($urlPattern , $url, $match)) { - if ($localPath === FALSE) { - $realPath = $url; - return false; - } - if ( $localPath != 'jsMethod' ) - $realPath = $localPath . $match[1]; - else - $realPath = $localPath; - return true; - } - } - $realPath = $url; - return false; - } - - /** - * Create an encrypted unique identifier based on $id and the selected scope id. - * - * @author David S. Callizaya S. - * @access public - * @param string $scope - * @param string $id - * @return string - */ - function createUID( $scope, $id ) - { - $e = $scope . $id; - $e=G::encrypt( $e , URL_KEY ); - $e=str_replace(array('+','/','='),array('__','_','___'),base64_encode($e)); - return $e; - } - - /** - * (Create an encrypted unique identificator based on $id and the selected scope id.) ^-1 - * getUIDName - * - * @author David S. Callizaya S. - * @access public - * @param string $id - * @param string $scope - * @return string - */ - function getUIDName( $uid , $scope = '' ) - { - $e=str_replace(array('=','+','/'),array('___','__','_'),$uid); - $e=base64_decode($e); - $e=G::decrypt( $e , URL_KEY ); - $e=substr( $e , strlen($scope) ); - return $e; - } - - /* formatNumber + */ + //end optimizing code + + + $index = 0; + $output = ''; + while ($index < strlen( $content )) { + $car = $content[$index]; + $index ++; + if ($car == '/' && isset( $content[$index] ) && $content[$index] == '*') { + $endComment = false; + $index ++; + while ($endComment == false && $index < strlen( $content )) { + if ($content[$index] == '*' && isset( $content[$index + 1] ) && $content[$index + 1] == '/') { + $endComment = true; + $index ++; + } + $index ++; + } + $car = ''; + } + $output .= $car; + } + return $output; + } + + /** + * sendHeaders + * + * @param string $filename + * @param string $contentType default value '' + * @param boolean $download default value false + * @param string $downloadFileName default value '' + * + * @return void + */ + function sendHeaders ($filename, $contentType = '', $download = false, $downloadFileName = '') + { + if ($download) { + if ($downloadFileName == '') { + $aAux = explode( '/', $filename ); + $downloadFileName = $aAux[count( $aAux ) - 1]; + } + header( 'Content-Disposition: attachment; filename="' . $downloadFileName . '"' ); + } + header( 'Content-Type: ' . $contentType ); + + //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. + $userAgent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); + if (preg_match( "/msie/i", $userAgent )) { + //if ( ereg("msie", $userAgent)) { + header( 'Pragma: cache' ); + + $mtime = filemtime( $filename ); + $gmt_mtime = gmdate( "D, d M Y H:i:s", $mtime ) . " GMT"; + header( 'ETag: "' . md5( $mtime . $filename ) . '"' ); + header( "Last-Modified: " . $gmt_mtime ); + header( 'Cache-Control: public' ); + header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + 60 * 10 ) . " GMT" ); //ten minutes + return; + } + + if (! $download) { + + header( 'Pragma: cache' ); + + if (file_exists( $filename )) + $mtime = filemtime( $filename ); + else + $mtime = date( 'U' ); + $gmt_mtime = gmdate( "D, d M Y H:i:s", $mtime ) . " GMT"; + header( 'ETag: "' . md5( $mtime . $filename ) . '"' ); + header( "Last-Modified: " . $gmt_mtime ); + header( 'Cache-Control: public' ); + header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + 90 * 60 * 60 * 24 ) . " GMT" ); + if (isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] )) { + if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) { + header( 'HTTP/1.1 304 Not Modified' ); + exit(); + } + } + + if (isset( $_SERVER['HTTP_IF_NONE_MATCH'] )) { + if (str_replace( '"', '', stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) == md5( $mtime . $filename )) { + header( "HTTP/1.1 304 Not Modified" ); + exit(); + } + } + } + } + + /** + * Transform a public URL into a local path. + * + * @author David S. Callizaya S. + * @access public + * @param string $url + * @param string $corvertionTable + * @param string $realPath = local path + * @return boolean + */ + function virtualURI ($url, $convertionTable, &$realPath) + { + foreach ($convertionTable as $urlPattern => $localPath) { + // $urlPattern = addcslashes( $urlPattern , '/'); + $urlPattern = addcslashes( $urlPattern, './' ); + $urlPattern = '/^' . str_replace( array ('*','?' + ), array ('.*','.?' + ), $urlPattern ) . '$/'; + if (preg_match( $urlPattern, $url, $match )) { + if ($localPath === FALSE) { + $realPath = $url; + return false; + } + if ($localPath != 'jsMethod') + $realPath = $localPath . $match[1]; + else + $realPath = $localPath; + return true; + } + } + $realPath = $url; + return false; + } + + /** + * Create an encrypted unique identifier based on $id and the selected scope id. + * + * @author David S. Callizaya S. + * @access public + * @param string $scope + * @param string $id + * @return string + */ + function createUID ($scope, $id) + { + $e = $scope . $id; + $e = G::encrypt( $e, URL_KEY ); + $e = str_replace( array ('+','/','=' + ), array ('__','_','___' + ), base64_encode( $e ) ); + return $e; + } + + /** + * (Create an encrypted unique identificator based on $id and the selected scope id.) ^-1 + * getUIDName + * + * @author David S. Callizaya S. + * @access public + * @param string $id + * @param string $scope + * @return string + */ + function getUIDName ($uid, $scope = '') + { + $e = str_replace( array ('=','+','/' + ), array ('___','__','_' + ), $uid ); + $e = base64_decode( $e ); + $e = G::decrypt( $e, URL_KEY ); + $e = substr( $e, strlen( $scope ) ); + return $e; + } + + /* formatNumber * * @author David Callizaya * @param int/string $num * @return string number - */ - function formatNumber($num, $language='latin') - { - switch($language) - { - default: - $snum=$num; - } - return $snum; - } - - /* Returns a date formatted according to the given format string + */ + function formatNumber ($num, $language = 'latin') + { + switch ($language) { + default: + $snum = $num; + } + return $snum; + } + + /* Returns a date formatted according to the given format string * @author David Callizaya * @param string $format The format of the outputted date string * @param string $datetime Date in the format YYYY-MM-DD HH:MM:SS - */ - function formatDate($datetime, $format='Y-m-d', $lang='') - { - if ($lang==='') $lang=defined(SYS_LANG)?SYS_LANG:'en'; - $aux = explode (' ', $datetime); //para dividir la fecha del dia - $date = explode ('-', isset ( $aux[0] ) ? $aux[0] : '00-00-00' ); //para obtener los dias, el mes, y el año. - $time = explode (':', isset ( $aux[1] ) ? $aux[1] : '00:00:00' ); //para obtener las horas, minutos, segundos. - $date[0] = (int)((isset($date[0]))?$date[0]:'0'); - $date[1] = (int)((isset($date[1]))?$date[1]:'0'); - $date[2] = (int)((isset($date[2]))?$date[2]:'0'); - $time[0] = (int)((isset($time[0]))?$time[0]:'0'); - $time[1] = (int)((isset($time[1]))?$time[1]:'0'); - $time[2] = (int)((isset($time[2]))?$time[2]:'0'); - // Spanish months - $ARR_MONTHS['es'] = array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"); - // English months - $ARR_MONTHS['en'] = array("January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"); - - - // Spanish days - $ARR_WEEKDAYS['es'] = array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"); - // English days - $ARR_WEEKDAYS['en'] = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); - - - - if ($lang=='fa') - $number='persian'; - else - $number='latin'; - $d = '0'.$date[2];$d=G::formatNumber(substr($d,strlen($d)-2,2),$number); - $j = G::formatNumber($date[2],$number); - $F = isset ( $ARR_MONTHS[$lang][$date[1]-1] ) ? $ARR_MONTHS[$lang][$date[1]-1] : ''; - $m = '0'.$date[1];$m=G::formatNumber(substr($m,strlen($m)-2,2),$number); - $n = G::formatNumber($date[1],$number); - $y = G::formatNumber(substr($date[0],strlen($date[0])-2,2),$number); - $Y = '0000'.$date[0];$Y=G::formatNumber(substr($Y,strlen($Y)-4,4),$number); - $g = ($time[0] % 12);if ($g===0)$g=12; - $G = $time[0]; - $h = '0'.$g;$h=G::formatNumber(substr($h,strlen($h)-2,2),$number); - $H = '0'.$G;$H=G::formatNumber(substr($H,strlen($H)-2,2),$number); - $i = '0'.$time[1];$i=G::formatNumber(substr($i,strlen($i)-2,2),$number); - $s = '0'.$time[2];$s=G::formatNumber(substr($s,strlen($s)-2,2),$number); - $names=array('d','j','F','m','n','y','Y','g','G','h','H','i','s'); - $values=array($d, $j, $F, $m, $n, $y, $Y, $g, $G, $h, $H, $i, $s); - $_formatedDate = str_replace( $names, $values, $format ); - return $_formatedDate; - } - - /** - * getformatedDate - * - * @param date $date - * @param string $format default value 'yyyy-mm-dd', - * @param string $lang default value '' - * - * @return string $ret - */ - function getformatedDate($date, $format = 'yyyy-mm-dd', $lang = '') - { - /******************************************************************************************************** - * if the year is 2008 and the format is yy then -> 08 - * if the year is 2008 and the format is yyyy then -> 2008 - * - * if the month is 05 and the format is mm then -> 05 - * if the month is 05 and the format is m and the month is less than 10 then -> 5 else digit normal - * if the month is 05 and the format is MM or M then -> May - * - * if the day is 5 and the format is dd then -> 05 - * if the day is 5 and the format is d and the day is less than 10 then -> 5 else digit normal - * if the day is 5 and the format is DD or D then -> five - *********************************************************************************************************/ - - //scape the literal - switch($lang) { - case 'es': - $format = str_replace(' de ', '[of]', $format); - break; - } - - //first we must formatted the string - $format = str_replace('yyyy', '{YEAR}', $format); - $format = str_replace('yy', '{year}', $format); - - $format = str_replace('mm', '{YONTH}', $format); - $format = str_replace('m', '{month}', $format); - $format = str_replace('M', '{XONTH}', $format); - - $format = str_replace('dd', '{DAY}', $format); - $format = str_replace('d', '{day}', $format); - - $format = str_replace('h', '{h}', $format); - $format = str_replace('i', '{i}', $format); - $format = str_replace('s', '{s}', $format); - - - if ($lang==='') $lang=defined(SYS_LANG)?SYS_LANG:'en'; - - $aux = explode (' ', $date); //para dividir la fecha del dia - $date = explode ('-', isset ( $aux[0] ) ? $aux[0] : '00-00-00' ); //para obtener los dias, el mes, y el año. - $time = explode (':', isset ( $aux[1] ) ? $aux[1] : '00:00:00' ); //para obtener las horas, minutos, segundos. - - $year = (int)((isset($date[0]))?$date[0]:'0'); //year - $month = (int)((isset($date[1]))?$date[1]:'0'); //month - $day = (int)((isset($date[2]))?$date[2]:'0'); //day - - $h = isset($time[0])? $time[0]: '00'; //hour - $i = isset($time[1])? $time[1]: '00'; //minute - $s = isset($time[2])? $time[2]: '00'; //second - - $MONTHS = Array(); - for($i=1; $i<=12; $i++){ - $MONTHS[$i] = G::LoadTranslation("ID_MONTH_$i", $lang); - } - - $d = (int)$day; - $dd = G::complete_field($day, 2, 1); - - //missing D - - $M = $MONTHS[$month]; - $m = (int)$month; - $mm = G::complete_field($month, 2, 1); - - $yy = substr($year,strlen($year)-2,2); - $yyyy = $year; - - $names = array('{day}', '{DAY}', '{month}', '{YONTH}', '{XONTH}', '{year}', '{YEAR}', '{h}', '{i}', '{s}'); - $values = array($d, $dd, $m, $mm, $M, $yy, $yyyy, $h, $i, $s); - - $ret = str_replace( $names, $values, $format ); - - //recovering the original literal - switch($lang){ - case 'es': - $ret = str_replace('[of]', ' de ', $ret); - break; - } - - return $ret; - } - - /** - * By - * Here's a little wrapper for array_diff - I found myself needing - * to iterate through the edited array, and I didn't need to original keys for anything. - */ - function arrayDiff($array1, $array2) { - if (!is_array($array1)) { - $array1 = (array) $array1; - } - - if (!is_array($array2)) { - $array2 = (array) $array2; - } - - // This wrapper for array_diff rekeys the array returned - $valid_array = array_diff($array1,$array2); - - // reinstantiate $array1 variable - $array1 = array(); - - // loop through the validated array and move elements to $array1 - // this is necessary because the array_diff function returns arrays that retain their original keys - foreach ($valid_array as $valid){ - $array1[] = $valid; - } - return $array1; - } - - /** - * @author Erik Amaru Ortiz - * @name complete_field($string, $lenght, $type={1:number/2:string/3:float}) - */ - function complete_field($campo, $long, $tipo) - { - $campo = trim($campo); - switch($tipo) - { - case 1: //number - $long = $long-strlen($campo); - for($i=1; $i<=$long; $i++) { - $campo = "0".$campo; - } - break; - - case 2: //string - $long = $long-strlen($campo); - for($i=1; $i<=$long; $i++) { - $campo = " ".$campo; - } - break; - - case 3: //float - if($campo!="0") { - $vals = explode(".",$long); - $ints = $vals[0]; - - $decs = $vals[1]; - - $valscampo = explode(".",$campo); - - $intscampo = $valscampo[0]; - $decscampo = $valscampo[1]; - - $ints = $ints - strlen($intscampo); - - for($i=1; $i<=$ints; $i++) { - $intscampo = "0".$intscampo; - } - - //los decimales pueden ser 0 uno o dos - $decs = $decs - strlen($decscampo); - for($i=1; $i<=$decs; $i++) { - $decscampo = $decscampo."0"; - } - - $campo = $intscampo.".".$decscampo; - } else { - $vals = explode(".",$long); - $ints = $vals[0]; - $decs = $vals[1]; - - $campo = ""; - for($i=1; $i<=$ints; $i++) { - $campo = "0".$campo; - } - $campod = ""; - for($i=1; $i<=$decs; $i++) { - $campod = "0".$campod; - } - - $campo = $campo.".".$campod; - } - break; - } - return $campo; - } - - /* Escapes special characters in a string for use in a SQL statement + */ + function formatDate ($datetime, $format = 'Y-m-d', $lang = '') + { + if ($lang === '') + $lang = defined( SYS_LANG ) ? SYS_LANG : 'en'; + $aux = explode( ' ', $datetime ); //para dividir la fecha del dia + $date = explode( '-', isset( $aux[0] ) ? $aux[0] : '00-00-00' ); //para obtener los dias, el mes, y el año. + $time = explode( ':', isset( $aux[1] ) ? $aux[1] : '00:00:00' ); //para obtener las horas, minutos, segundos. + $date[0] = (int) ((isset( $date[0] )) ? $date[0] : '0'); + $date[1] = (int) ((isset( $date[1] )) ? $date[1] : '0'); + $date[2] = (int) ((isset( $date[2] )) ? $date[2] : '0'); + $time[0] = (int) ((isset( $time[0] )) ? $time[0] : '0'); + $time[1] = (int) ((isset( $time[1] )) ? $time[1] : '0'); + $time[2] = (int) ((isset( $time[2] )) ? $time[2] : '0'); + // Spanish months + $ARR_MONTHS['es'] = array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre" + ); + // English months + $ARR_MONTHS['en'] = array ("January","February","March","April","May","June","July","August","September","October","November","December" + ); + + // Spanish days + $ARR_WEEKDAYS['es'] = array ("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado" + ); + // English days + $ARR_WEEKDAYS['en'] = array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" + ); + + if ($lang == 'fa') + $number = 'persian'; + else + $number = 'latin'; + $d = '0' . $date[2]; + $d = G::formatNumber( substr( $d, strlen( $d ) - 2, 2 ), $number ); + $j = G::formatNumber( $date[2], $number ); + $F = isset( $ARR_MONTHS[$lang][$date[1] - 1] ) ? $ARR_MONTHS[$lang][$date[1] - 1] : ''; + $m = '0' . $date[1]; + $m = G::formatNumber( substr( $m, strlen( $m ) - 2, 2 ), $number ); + $n = G::formatNumber( $date[1], $number ); + $y = G::formatNumber( substr( $date[0], strlen( $date[0] ) - 2, 2 ), $number ); + $Y = '0000' . $date[0]; + $Y = G::formatNumber( substr( $Y, strlen( $Y ) - 4, 4 ), $number ); + $g = ($time[0] % 12); + if ($g === 0) + $g = 12; + $G = $time[0]; + $h = '0' . $g; + $h = G::formatNumber( substr( $h, strlen( $h ) - 2, 2 ), $number ); + $H = '0' . $G; + $H = G::formatNumber( substr( $H, strlen( $H ) - 2, 2 ), $number ); + $i = '0' . $time[1]; + $i = G::formatNumber( substr( $i, strlen( $i ) - 2, 2 ), $number ); + $s = '0' . $time[2]; + $s = G::formatNumber( substr( $s, strlen( $s ) - 2, 2 ), $number ); + $names = array ('d','j','F','m','n','y','Y','g','G','h','H','i','s' + ); + $values = array ($d,$j,$F,$m,$n,$y,$Y,$g,$G,$h,$H,$i,$s + ); + $_formatedDate = str_replace( $names, $values, $format ); + return $_formatedDate; + } + + /** + * getformatedDate + * + * @param date $date + * @param string $format default value 'yyyy-mm-dd', + * @param string $lang default value '' + * + * @return string $ret + */ + function getformatedDate ($date, $format = 'yyyy-mm-dd', $lang = '') + { + /** + * ****************************************************************************************************** + * if the year is 2008 and the format is yy then -> 08 + * if the year is 2008 and the format is yyyy then -> 2008 + * + * if the month is 05 and the format is mm then -> 05 + * if the month is 05 and the format is m and the month is less than 10 then -> 5 else digit normal + * if the month is 05 and the format is MM or M then -> May + * + * if the day is 5 and the format is dd then -> 05 + * if the day is 5 and the format is d and the day is less than 10 then -> 5 else digit normal + * if the day is 5 and the format is DD or D then -> five + * ******************************************************************************************************* + */ + + //scape the literal + switch ($lang) { + case 'es': + $format = str_replace( ' de ', '[of]', $format ); + break; + } + + //first we must formatted the string + $format = str_replace( 'yyyy', '{YEAR}', $format ); + $format = str_replace( 'yy', '{year}', $format ); + + $format = str_replace( 'mm', '{YONTH}', $format ); + $format = str_replace( 'm', '{month}', $format ); + $format = str_replace( 'M', '{XONTH}', $format ); + + $format = str_replace( 'dd', '{DAY}', $format ); + $format = str_replace( 'd', '{day}', $format ); + + $format = str_replace( 'h', '{h}', $format ); + $format = str_replace( 'i', '{i}', $format ); + $format = str_replace( 's', '{s}', $format ); + + if ($lang === '') + $lang = defined( SYS_LANG ) ? SYS_LANG : 'en'; + + $aux = explode( ' ', $date ); //para dividir la fecha del dia + $date = explode( '-', isset( $aux[0] ) ? $aux[0] : '00-00-00' ); //para obtener los dias, el mes, y el año. + $time = explode( ':', isset( $aux[1] ) ? $aux[1] : '00:00:00' ); //para obtener las horas, minutos, segundos. + + + $year = (int) ((isset( $date[0] )) ? $date[0] : '0'); //year + $month = (int) ((isset( $date[1] )) ? $date[1] : '0'); //month + $day = (int) ((isset( $date[2] )) ? $date[2] : '0'); //day + + + $h = isset( $time[0] ) ? $time[0] : '00'; //hour + $i = isset( $time[1] ) ? $time[1] : '00'; //minute + $s = isset( $time[2] ) ? $time[2] : '00'; //second + + + $MONTHS = Array (); + for ($i = 1; $i <= 12; $i ++) { + $MONTHS[$i] = G::LoadTranslation( "ID_MONTH_$i", $lang ); + } + + $d = (int) $day; + $dd = G::complete_field( $day, 2, 1 ); + + //missing D + + + $M = $MONTHS[$month]; + $m = (int) $month; + $mm = G::complete_field( $month, 2, 1 ); + + $yy = substr( $year, strlen( $year ) - 2, 2 ); + $yyyy = $year; + + $names = array ('{day}','{DAY}','{month}','{YONTH}','{XONTH}','{year}','{YEAR}','{h}','{i}','{s}' + ); + $values = array ($d,$dd,$m,$mm,$M,$yy,$yyyy,$h,$i,$s + ); + + $ret = str_replace( $names, $values, $format ); + + //recovering the original literal + switch ($lang) { + case 'es': + $ret = str_replace( '[of]', ' de ', $ret ); + break; + } + + return $ret; + } + + /** + * By + * Here's a little wrapper for array_diff - I found myself needing + * to iterate through the edited array, and I didn't need to original keys for anything. + */ + function arrayDiff ($array1, $array2) + { + if (! is_array( $array1 )) { + $array1 = (array) $array1; + } + + if (! is_array( $array2 )) { + $array2 = (array) $array2; + } + + // This wrapper for array_diff rekeys the array returned + $valid_array = array_diff( $array1, $array2 ); + + // reinstantiate $array1 variable + $array1 = array (); + + // loop through the validated array and move elements to $array1 + // this is necessary because the array_diff function returns arrays that retain their original keys + foreach ($valid_array as $valid) { + $array1[] = $valid; + } + return $array1; + } + + /** + * + * @author Erik Amaru Ortiz + * @name complete_field($string, $lenght, $type={1:number/2:string/3:float}) + */ + function complete_field ($campo, $long, $tipo) + { + $campo = trim( $campo ); + switch ($tipo) { + case 1: //number + $long = $long - strlen( $campo ); + for ($i = 1; $i <= $long; $i ++) { + $campo = "0" . $campo; + } + break; + + case 2: //string + $long = $long - strlen( $campo ); + for ($i = 1; $i <= $long; $i ++) { + $campo = " " . $campo; + } + break; + + case 3: //float + if ($campo != "0") { + $vals = explode( ".", $long ); + $ints = $vals[0]; + + $decs = $vals[1]; + + $valscampo = explode( ".", $campo ); + + $intscampo = $valscampo[0]; + $decscampo = $valscampo[1]; + + $ints = $ints - strlen( $intscampo ); + + for ($i = 1; $i <= $ints; $i ++) { + $intscampo = "0" . $intscampo; + } + + //los decimales pueden ser 0 uno o dos + $decs = $decs - strlen( $decscampo ); + for ($i = 1; $i <= $decs; $i ++) { + $decscampo = $decscampo . "0"; + } + + $campo = $intscampo . "." . $decscampo; + } else { + $vals = explode( ".", $long ); + $ints = $vals[0]; + $decs = $vals[1]; + + $campo = ""; + for ($i = 1; $i <= $ints; $i ++) { + $campo = "0" . $campo; + } + $campod = ""; + for ($i = 1; $i <= $decs; $i ++) { + $campod = "0" . $campod; + } + + $campo = $campo . "." . $campod; + } + break; + } + return $campo; + } + + /* Escapes special characters in a string for use in a SQL statement * @author David Callizaya * @param string $sqlString The string to be escaped * @param string $DBEngine Target DBMS - */ - function sqlEscape( $sqlString, $DBEngine = DB_ADAPTER ) - { - $DBEngine = DB_ADAPTER; - switch($DBEngine){ - case 'mysql': - $con = Propel::getConnection('workflow') ; - return mysql_real_escape_string(stripslashes($sqlString), $con->getResource() ); - case 'myxml': - $sqlString = str_replace('"', '""', $sqlString); - return str_replace("'", "''", $sqlString); - //return str_replace(array('"',"'"),array('""',"''"),stripslashes($sqlString)); - default: - return addslashes(stripslashes($sqlString)); - } - } - - /** - * Function MySQLSintaxis - * @access public - * @return Boolean - **/ - function MySQLSintaxis() - { - $DBEngine = DB_ADAPTER; - switch($DBEngine){ - case 'mysql' : - return TRUE; - break; - case 'mssql' : - default: - return FALSE; - break; - } - } - /* Returns a sql string with @@parameters replaced with its values defined + */ + function sqlEscape ($sqlString, $DBEngine = DB_ADAPTER) + { + $DBEngine = DB_ADAPTER; + switch ($DBEngine) { + case 'mysql': + $con = Propel::getConnection( 'workflow' ); + return mysql_real_escape_string( stripslashes( $sqlString ), $con->getResource() ); + case 'myxml': + $sqlString = str_replace( '"', '""', $sqlString ); + return str_replace( "'", "''", $sqlString ); + //return str_replace(array('"',"'"),array('""',"''"),stripslashes($sqlString)); + default: + return addslashes( stripslashes( $sqlString ) ); + } + } + + /** + * Function MySQLSintaxis + * + * @access public + * @return Boolean + * + */ + function MySQLSintaxis () + { + $DBEngine = DB_ADAPTER; + switch ($DBEngine) { + case 'mysql': + return TRUE; + break; + case 'mssql': + default: + return FALSE; + break; + } + } + /* Returns a sql string with @@parameters replaced with its values defined * in array $result using the next notation: * NOTATION: * @@ Quoted parameter acording to the SYSTEM's Database @@ -1986,28 +2010,29 @@ $output = $outputHeader.$output; * @! Evaluate string : Replace the parameters in value and then in the sql string * @fn() Evaluate string with the function "fn" * @author David Callizaya - */ - function replaceDataField( $sqlString, $result, $DBEngine = 'mysql' ) - { - if (!is_array($result)) { - $result = array(); - } - $result = $result + G::getSystemConstants(); - $__textoEval = ""; - $u = 0; - //$count=preg_match_all('/\@(?:([\@\%\#\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))/',$sqlString,$match,PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); - $count = preg_match_all('/\@(?:([\@\%\#\=\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*?)*)\))/',$sqlString,$match,PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); - if ($count) { - for($r=0;$r<$count;$r++) { - if (!isset($result[$match[2][$r][0]])) - $result[$match[2][$r][0]] = ''; - if (!is_array($result[$match[2][$r][0]])) { - $__textoEval.=substr($sqlString,$u,$match[0][$r][1]-$u); - $u = $match[0][$r][1]+strlen($match[0][$r][0]); - //Mysql quotes scape - if (($match[1][$r][0]=='@')&&(isset($result[$match[2][$r][0]]))) { - $__textoEval.="\"". G::sqlEscape($result[$match[2][$r][0]],$DBEngine) ."\"";continue; - } + */ + function replaceDataField ($sqlString, $result, $DBEngine = 'mysql') + { + if (! is_array( $result )) { + $result = array (); + } + $result = $result + G::getSystemConstants(); + $__textoEval = ""; + $u = 0; + //$count=preg_match_all('/\@(?:([\@\%\#\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))/',$sqlString,$match,PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); + $count = preg_match_all( '/\@(?:([\@\%\#\=\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*?)*)\))/', $sqlString, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); + if ($count) { + for ($r = 0; $r < $count; $r ++) { + if (! isset( $result[$match[2][$r][0]] )) + $result[$match[2][$r][0]] = ''; + if (! is_array( $result[$match[2][$r][0]] )) { + $__textoEval .= substr( $sqlString, $u, $match[0][$r][1] - $u ); + $u = $match[0][$r][1] + strlen( $match[0][$r][0] ); + //Mysql quotes scape + if (($match[1][$r][0] == '@') && (isset( $result[$match[2][$r][0]] ))) { + $__textoEval .= "\"" . G::sqlEscape( $result[$match[2][$r][0]], $DBEngine ) . "\""; + continue; + } //URL encode if (($match[1][$r][0]=='%')&&(isset($result[$match[2][$r][0]]))) { $__textoEval.=urlencode($result[$match[2][$r][0]]);continue; @@ -2112,849 +2137,862 @@ $output = $outputHeader.$output; $sContent = G::replaceDataField($sContent, $aFields); return $sContent; - } - - - /* Load strings from a XMLFile. + } + + /* Load strings from a XMLFile. * @author David Callizaya * @parameter $languageFile An xml language file. * @parameter $languageId (es|en|...). * @parameter $forceParse Force to read and parse the xml file. - */ - function loadLanguageFile ( $filename , $languageId = '', $forceParse = false ) - { - global $arrayXmlMessages; - if ($languageId==='') $languageId = defined('SYS_LANG') ? SYS_LANG : 'en'; - $languageFile = basename( $filename , '.xml' ); - $cacheFile = substr( $filename , 0 ,-3 ) . $languageId; - if (($forceParse) || (!file_exists($cacheFile)) || - ( filemtime($filename) > filemtime($cacheFile)) - //|| ( filemtime(__FILE__) > filemtime($cacheFile)) - ) { - $languageDocument = new Xml_document(); - $languageDocument->parseXmlFile( $filename ); - if (!is_array($arrayXmlMessages)) $arrayXmlMessages = array(); - $arrayXmlMessages[ $languageFile ] = array(); - for($r=0 ; $r < sizeof($languageDocument->children[0]->children) ; $r++ ) { - $n = $languageDocument->children[0]->children[$r]->findNode($languageId); - if ($n) { - $k = $languageDocument->children[0]->children[$r]->name; - $arrayXmlMessages[ $languageFile ][ $k ] = $n->value; - } - } - $f = fopen( $cacheFile , 'w'); - fwrite( $f , "" ); - fclose( $f ); - } else { - require( $cacheFile ); - } - } - /* Funcion auxiliar Temporal: + */ + function loadLanguageFile ($filename, $languageId = '', $forceParse = false) + { + global $arrayXmlMessages; + if ($languageId === '') + $languageId = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; + $languageFile = basename( $filename, '.xml' ); + $cacheFile = substr( $filename, 0, - 3 ) . $languageId; + if (($forceParse) || (! file_exists( $cacheFile )) || (filemtime( $filename ) > filemtime( $cacheFile ))) + //|| ( filemtime(__FILE__) > filemtime($cacheFile)) + { + $languageDocument = new Xml_document(); + $languageDocument->parseXmlFile( $filename ); + if (! is_array( $arrayXmlMessages )) + $arrayXmlMessages = array (); + $arrayXmlMessages[$languageFile] = array (); + for ($r = 0; $r < sizeof( $languageDocument->children[0]->children ); $r ++) { + $n = $languageDocument->children[0]->children[$r]->findNode( $languageId ); + if ($n) { + $k = $languageDocument->children[0]->children[$r]->name; + $arrayXmlMessages[$languageFile][$k] = $n->value; + } + } + $f = fopen( $cacheFile, 'w' ); + fwrite( $f, "" ); + fclose( $f ); + } else { + require ($cacheFile); + } + } + /* Funcion auxiliar Temporal: * Registra en la base de datos los labels xml usados en el sistema * @author David Callizaya - */ - function registerLabel( $id , $label ) - { - return 1; - $dbc = new DBConnection(); - $ses = new DBSession($dbc); - $ses->Execute(G::replaceDataField( - 'REPLACE INTO `TRANSLATION` (`TRN_CATEGORY`, `TRN_ID`, `TRN_LANG`, `TRN_VALUE`) VALUES - ("LABEL", @@ID, "'.SYS_LANG.'", @@LABEL);',array('ID'=>$id,'LABEL'=>($label !== null ? $label : '')))); - } - /** - * Function LoadMenuXml - * @author David S. Callizaya S. - * @access public - * @parameter string msgID - * @return string - */ - function LoadMenuXml( $msgID ) - { - global $arrayXmlMessages; - if (!isset($arrayXmlMessages['menus'])) - G::loadLanguageFile( G::ExpandPath('content') . 'languages/menus.xml' ); - G::registerLabel($msgID,$arrayXmlMessages['menus'][$msgID]); - return $arrayXmlMessages['menus'][$msgID]; - } - /** - * Function SendMessageXml - * @author David S. Callizaya S. - * @access public - * @parameter string msgID - * @parameter string strType - * @parameter string file - * @return string - */ - function SendMessageXml( $msgID, $strType , $file="labels") - { - global $arrayXmlMessages; - if (!isset($arrayXmlMessages[$file])) - G::loadLanguageFile( G::ExpandPath('content') . 'languages/' . $file . '.xml' ); - $_SESSION['G_MESSAGE_TYPE'] = $strType; - G::registerLabel($msgID,$arrayXmlMessages[$file][$msgID]); - $_SESSION['G_MESSAGE'] = nl2br ($arrayXmlMessages[$file][$msgID]); - } - - /** - * SendTemporalMessage - * - * @param string $msgID - * @param string $strType - * @param string $sType default value 'LABEL' - * @param date $time default value null - * @param integer $width default value null - * @param string $customLabels default value null - * - * @return void - */ - function SendTemporalMessage($msgID, $strType, $sType='LABEL', $time=null, $width=null, $customLabels= null) - { - if( isset($width) ){ - $_SESSION['G_MESSAGE_WIDTH'] = $width; - } - if( isset($time) ){ - $_SESSION['G_MESSAGE_TIME'] = $time; - } - switch(strtolower($sType)){ - case 'label': - case 'labels': - $_SESSION['G_MESSAGE_TYPE'] = $strType; - $_SESSION['G_MESSAGE'] = nl2br(G::LoadTranslation($msgID)); - break; - case 'string': - $_SESSION['G_MESSAGE_TYPE'] = $strType; - $_SESSION['G_MESSAGE'] = nl2br($msgID); - break; - } - if ( $customLabels != null ) { - $message = $_SESSION['G_MESSAGE']; - foreach ( $customLabels as $key=>$val ) { - $message = str_replace ( '{' . nl2br($key) . '}' , nl2br($val), $message ); - } - $_SESSION['G_MESSAGE'] = $message; - } - } - - /** - * SendMessage - * - * @param string $msgID - * @param string $strType - * @param string $file default value "labels" - * - * @return void - */ - function SendMessage( $msgID, $strType , $file="labels") - { - global $arrayXmlMessages; - $_SESSION['G_MESSAGE_TYPE'] = $strType; - $_SESSION['G_MESSAGE'] = nl2br (G::LoadTranslation($msgID)); - } - - /** - * SendMessageText - * Just put the $text in the message text - * - * @param string $text - * @param string $strType - * - * @return void - */ - function SendMessageText( $text, $strType) - { - global $arrayXmlMessages; - $_SESSION['G_MESSAGE_TYPE'] = $strType; - $_SESSION['G_MESSAGE'] = nl2br ( $text ); - } - - /** - * Render message from XML file - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $msgID - * @return void - */ - function LoadMessage( $msgID, $file = "messages" ) - { - global $_SESSION; - global $arrayXmlMessages; - - if ( !is_array ($arrayXmlMessages) ) - $arrayXmlMessages = G::LoadArrayFile( G::ExpandPath( 'content' ) . $file . "." . SYS_LANG ); - - $aux = $arrayXmlMessages[$msgID]; - $msg = ""; - for ($i = 0; $i < strlen($aux); $i++) { - if ( $aux[$i] == "$") { - $token = ""; $i++; - while ($i < strlen ($aux) && $aux[$i]!=" " && $aux[$i]!="." && $aux[$i]!="'" && $aux[$i]!='"') - $token.= $aux[$i++]; - eval ( "\$msg.= \$_SESSION['".$token."'] ; "); - $msg .= $aux[$i]; - } - else - $msg = $msg . $aux[$i]; - } - return $msg; - } - /** - * Function LoadXmlLabel - * @author David S. Callizaya S. - * @access public - * @parameter string file - * @parameter string msgID - * @return string - */ - function LoadXmlLabel( $msgID , $file = 'labels' ) - { - return 'xxxxxx'; - global $arrayXmlMessages; - if (!isset($arrayXmlMessages[$file])) - G::loadLanguageFile( G::ExpandPath('content') . 'languages/' . $file . '.xml' ); - G::registerLabel($msgID,$arrayXmlMessages[$file][$msgID]); - return $arrayXmlMessages[$file][$msgID]; - } - /** - * Function LoadMessageXml - * @author David S. Callizaya S. - * @access public - * @parameter string msgID - * @parameter string file - * @return string - */ - function LoadMessageXml( $msgID , $file ='labels' ) - { - global $arrayXmlMessages; - if ( !isset($arrayXmlMessages[$file]) ) - G::loadLanguageFile( G::ExpandPath('content') . 'languages/' . $file . '.xml' ); - if ( isset($arrayXmlMessages[$file][$msgID]) ) { - G::registerLabel( $msgID, $arrayXmlMessages[$file][$msgID] ); - return $arrayXmlMessages[$file][$msgID]; - } - else { - G::registerLabel($msgID,''); - return NULL; - } - } - /** - * Function LoadTranslationObject - * It generates a global Translation variable that will be used in all the system. Per script - * @author Hugo Loza. - * @access public - * @parameter string lang - * @return void - */ - function LoadTranslationObject($lang = SYS_LANG){ - $defaultTranslations = Array(); - $foreignTranslations = Array(); - - //if the default translations table doesn't exist we can't proceed - if( ! is_file(PATH_LANGUAGECONT . 'translation.en') ) - return NULL; - - //load the translations table - require_once ( PATH_LANGUAGECONT . 'translation.en' ); - $defaultTranslations = $translation; - - //if some foreign language was requested and its translation file exists - if( $lang != 'en' && file_exists(PATH_LANGUAGECONT . 'translation.' . $lang) ){ - require_once ( PATH_LANGUAGECONT . 'translation.' . $lang ); //load the foreign translations table - $foreignTranslations = $translation; - } - - global $translation; - if( defined("SHOW_UNTRANSLATED_AS_TAG") && SHOW_UNTRANSLATED_AS_TAG != 0 ) - $translation = $foreignTranslations; - else - $translation = array_merge($defaultTranslations, $foreignTranslations); - - return true; - } - - /** - * Function LoadTranslation - * @author Aldo Mauricio Veliz Valenzuela. - * @access public - * @parameter string msgID - * @parameter string file - * @parameter array data // erik: associative array within data input to replace for formatted string i.e "any messsage {replaced_label} that contains a replace label" - * @return string - */ - function LoadTranslation($msgID, $lang = SYS_LANG, $data = null) - { - global $translation; - - // if the second parameter $lang is an array does mean it was especified to use as data - if (is_array($lang)) { - $data = $lang; - $lang = SYS_LANG; - } - - if ( isset ( $translation[$msgID] ) ){ - $translationString = preg_replace("[\n|\r|\n\r]", ' ', $translation[$msgID]); - - if( isset($data) && is_array($data) ) { - foreach($data as $label=>$value) { - $translationString = str_replace('{'.$label.'}', $value, $translationString); - } - } - - return $translationString; - } else { - if( defined("UNTRANSLATED_MARK") ) { - $untranslatedMark = strip_tags(UNTRANSLATED_MARK); - } else { - $untranslatedMark = "**"; - } - return $untranslatedMark . $msgID . $untranslatedMark; - } - - } - - /** - * Function getTranslations - * @author Erik Amaru O. - * @access public - * @parameter array msgIDs - * @parameter string file - * @return string - */ - function getTranslations($msgIDs , $lang = SYS_LANG) - { - if ( ! is_array($msgIDs) ) return null; - - $translations = Array(); - foreach( $msgIDs as $mID ) { - $translations[$mID] = self::LoadTranslation($mID , $lang); - } - - return $translations; - } - /** - * Load an array File Content - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $strFile - * @return void - */ - function LoadArrayFile( $strFile = '' ) - { - $res = NULL; - if ( $strFile != '' ) - { - $src = file( $strFile ); - if( is_array( $src ) ) - { - foreach( $src as $key => $val ) - { - $res[$key] = trim( $val ); - } - } - } - unset( $src ); - return $res; - } - - /** - * Expand an uri based in the current URI - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $methodPage the method directory and the page - * @return the expanded uri, later, will encryt the uri... - */ - function expandUri ( $methodPage ) { - $uri = explode ( '/', getenv ( 'REQUEST_URI' ) ); - $sw = 0; - $newUri = ''; - if ( !defined ( 'SYS_SKIN' ) ) { - for ( $i = 0; $i < count( $uri) ; $i++ ) { - if ( $sw == 0 ) $newUri .= $uri[ $i ] . PATH_SEP ; - if ( $uri[ $i ] == SYS_SKIN ) $sw = 1; - } - } - else { - for ( $i =0; $i < 4 ; $i++ ) { - if ( $sw == 0 ) $newUri .= $uri[ $i ] . PATH_SEP ; - if ( $uri[ $i ] == SYS_SKIN ) $sw = 1; - } - } - $newUri .= $methodPage; - return $newUri; - } - - /** - * Forces login for generic applications - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $userid - * @param string $permission - * @param string $urlNoAccess - * @return void - */ - function genericForceLogin( $permission , $urlNoAccess, $urlLogin = 'login/login' ) { - global $RBAC; - - //the session is expired, go to login page, - //the login page is login/login.html - if ( ! isset ( $_SESSION ) ) { - header ( 'location: ' . G::expandUri ( $urlLogin ) ); - die (); - } - - //$permission is an array, we'll verify all permission to allow access. - if ( is_array($permission) ) - $aux = $permission; - else - $aux[0] = $permission; - - $sw = 0; - for ($i = 0; $i < count ($aux); $i++ ) { - $res = $RBAC->userCanAccess($aux[$i]); - if ($res == 1) $sw = 1; - } - - //you don't have access to this page - if ($sw == 0) { - header ( 'location: ' . G::expandUri ( $urlNoAccess ) ); - die; - } - } - - /** - * capitalize - * - * @param string $string - * - * @return string $string - */ - function capitalize($string) - { - return ucfirst($string); - } - - /** - * toUpper - * - * @param string $sText - * - * @return string strtoupper($sText) - */ - function toUpper($sText) - { - return strtoupper($sText); - } - - /** - * toLower - * - * @param string $sText - * @return string strtolower($sText) - */ - function toLower($sText) - { - return strtolower($sText); - } - - /** - * http_build_query - * - * @param string $formdata, - * @param string $numeric_prefix default value null, - * @param string $key default value null - * - * @return array $res - */ - function http_build_query( $formdata, $numeric_prefix = null, $key = null ) - { - $res = array(); - foreach ((array)$formdata as $k=>$v) { - $tmp_key = rawurlencode(is_int($k) ? $numeric_prefix.$k : $k); - if ($key) $tmp_key = $key.'['.$tmp_key.']'; - if ( is_array($v) || is_object($v) ) { - $res[] = G::http_build_query($v, null /* or $numeric_prefix if you want to add numeric_prefix to all indexes in array*/, $tmp_key); - } else { - $res[] = $tmp_key."=".rawurlencode($v); - } - /* + */ + function registerLabel ($id, $label) + { + return 1; + $dbc = new DBConnection(); + $ses = new DBSession( $dbc ); + $ses->Execute( G::replaceDataField( 'REPLACE INTO `TRANSLATION` (`TRN_CATEGORY`, `TRN_ID`, `TRN_LANG`, `TRN_VALUE`) VALUES + ("LABEL", @@ID, "' . SYS_LANG . '", @@LABEL);', array ('ID' => $id,'LABEL' => ($label !== null ? $label : '') + ) ) ); + } + + /** + * Function LoadMenuXml + * + * @author David S. Callizaya S. + * @access public + * @param eter string msgID + * @return string + */ + function LoadMenuXml ($msgID) + { + global $arrayXmlMessages; + if (! isset( $arrayXmlMessages['menus'] )) + G::loadLanguageFile( G::ExpandPath( 'content' ) . 'languages/menus.xml' ); + G::registerLabel( $msgID, $arrayXmlMessages['menus'][$msgID] ); + return $arrayXmlMessages['menus'][$msgID]; + } + + /** + * Function SendMessageXml + * + * @author David S. Callizaya S. + * @access public + * @param eter string msgID + * @param eter string strType + * @param eter string file + * @return string + */ + function SendMessageXml ($msgID, $strType, $file = "labels") + { + global $arrayXmlMessages; + if (! isset( $arrayXmlMessages[$file] )) + G::loadLanguageFile( G::ExpandPath( 'content' ) . 'languages/' . $file . '.xml' ); + $_SESSION['G_MESSAGE_TYPE'] = $strType; + G::registerLabel( $msgID, $arrayXmlMessages[$file][$msgID] ); + $_SESSION['G_MESSAGE'] = nl2br( $arrayXmlMessages[$file][$msgID] ); + } + + /** + * SendTemporalMessage + * + * @param string $msgID + * @param string $strType + * @param string $sType default value 'LABEL' + * @param date $time default value null + * @param integer $width default value null + * @param string $customLabels default value null + * + * @return void + */ + function SendTemporalMessage ($msgID, $strType, $sType = 'LABEL', $time = null, $width = null, $customLabels = null) + { + if (isset( $width )) { + $_SESSION['G_MESSAGE_WIDTH'] = $width; + } + if (isset( $time )) { + $_SESSION['G_MESSAGE_TIME'] = $time; + } + switch (strtolower( $sType )) { + case 'label': + case 'labels': + $_SESSION['G_MESSAGE_TYPE'] = $strType; + $_SESSION['G_MESSAGE'] = nl2br( G::LoadTranslation( $msgID ) ); + break; + case 'string': + $_SESSION['G_MESSAGE_TYPE'] = $strType; + $_SESSION['G_MESSAGE'] = nl2br( $msgID ); + break; + } + if ($customLabels != null) { + $message = $_SESSION['G_MESSAGE']; + foreach ($customLabels as $key => $val) { + $message = str_replace( '{' . nl2br( $key ) . '}', nl2br( $val ), $message ); + } + $_SESSION['G_MESSAGE'] = $message; + } + } + + /** + * SendMessage + * + * @param string $msgID + * @param string $strType + * @param string $file default value "labels" + * + * @return void + */ + function SendMessage ($msgID, $strType, $file = "labels") + { + global $arrayXmlMessages; + $_SESSION['G_MESSAGE_TYPE'] = $strType; + $_SESSION['G_MESSAGE'] = nl2br( G::LoadTranslation( $msgID ) ); + } + + /** + * SendMessageText + * Just put the $text in the message text + * + * @param string $text + * @param string $strType + * + * @return void + */ + function SendMessageText ($text, $strType) + { + global $arrayXmlMessages; + $_SESSION['G_MESSAGE_TYPE'] = $strType; + $_SESSION['G_MESSAGE'] = nl2br( $text ); + } + + /** + * Render message from XML file + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $msgID + * @return void + */ + function LoadMessage ($msgID, $file = "messages") + { + global $_SESSION; + global $arrayXmlMessages; + + if (! is_array( $arrayXmlMessages )) + $arrayXmlMessages = G::LoadArrayFile( G::ExpandPath( 'content' ) . $file . "." . SYS_LANG ); + + $aux = $arrayXmlMessages[$msgID]; + $msg = ""; + for ($i = 0; $i < strlen( $aux ); $i ++) { + if ($aux[$i] == "$") { + $token = ""; + $i ++; + while ($i < strlen( $aux ) && $aux[$i] != " " && $aux[$i] != "." && $aux[$i] != "'" && $aux[$i] != '"') + $token .= $aux[$i ++]; + eval( "\$msg.= \$_SESSION['" . $token . "'] ; " ); + $msg .= $aux[$i]; + } else + $msg = $msg . $aux[$i]; + } + return $msg; + } + + /** + * Function LoadXmlLabel + * + * @author David S. Callizaya S. + * @access public + * @param eter string file + * @param eter string msgID + * @return string + */ + function LoadXmlLabel ($msgID, $file = 'labels') + { + return 'xxxxxx'; + global $arrayXmlMessages; + if (! isset( $arrayXmlMessages[$file] )) + G::loadLanguageFile( G::ExpandPath( 'content' ) . 'languages/' . $file . '.xml' ); + G::registerLabel( $msgID, $arrayXmlMessages[$file][$msgID] ); + return $arrayXmlMessages[$file][$msgID]; + } + + /** + * Function LoadMessageXml + * + * @author David S. Callizaya S. + * @access public + * @param eter string msgID + * @param eter string file + * @return string + */ + function LoadMessageXml ($msgID, $file = 'labels') + { + global $arrayXmlMessages; + if (! isset( $arrayXmlMessages[$file] )) + G::loadLanguageFile( G::ExpandPath( 'content' ) . 'languages/' . $file . '.xml' ); + if (isset( $arrayXmlMessages[$file][$msgID] )) { + G::registerLabel( $msgID, $arrayXmlMessages[$file][$msgID] ); + return $arrayXmlMessages[$file][$msgID]; + } else { + G::registerLabel( $msgID, '' ); + return NULL; + } + } + + /** + * Function LoadTranslationObject + * It generates a global Translation variable that will be used in all the system. + * Per script + * + * @author Hugo Loza. + * @access public + * @param eter string lang + * @return void + */ + function LoadTranslationObject ($lang = SYS_LANG) + { + $defaultTranslations = Array (); + $foreignTranslations = Array (); + + //if the default translations table doesn't exist we can't proceed + if (! is_file( PATH_LANGUAGECONT . 'translation.en' )) + return NULL; + + //load the translations table + require_once (PATH_LANGUAGECONT . 'translation.en'); + $defaultTranslations = $translation; + + //if some foreign language was requested and its translation file exists + if ($lang != 'en' && file_exists( PATH_LANGUAGECONT . 'translation.' . $lang )) { + require_once (PATH_LANGUAGECONT . 'translation.' . $lang); //load the foreign translations table + $foreignTranslations = $translation; + } + + global $translation; + if (defined( "SHOW_UNTRANSLATED_AS_TAG" ) && SHOW_UNTRANSLATED_AS_TAG != 0) + $translation = $foreignTranslations; + else + $translation = array_merge( $defaultTranslations, $foreignTranslations ); + + return true; + } + + /** + * Function LoadTranslation + * + * @author Aldo Mauricio Veliz Valenzuela. + * @access public + * @param eter string msgID + * @param eter string file + * @param eter array data // erik: associative array within data input to replace for formatted string i.e "any messsage {replaced_label} that contains a replace label" + * @return string + */ + function LoadTranslation ($msgID, $lang = SYS_LANG, $data = null) + { + global $translation; + + // if the second parameter $lang is an array does mean it was especified to use as data + if (is_array( $lang )) { + $data = $lang; + $lang = SYS_LANG; + } + + if (isset( $translation[$msgID] )) { + $translationString = preg_replace( "[\n|\r|\n\r]", ' ', $translation[$msgID] ); + + if (isset( $data ) && is_array( $data )) { + foreach ($data as $label => $value) { + $translationString = str_replace( '{' . $label . '}', $value, $translationString ); + } + } + + return $translationString; + } else { + if (defined( "UNTRANSLATED_MARK" )) { + $untranslatedMark = strip_tags( UNTRANSLATED_MARK ); + } else { + $untranslatedMark = "**"; + } + return $untranslatedMark . $msgID . $untranslatedMark; + } + + } + + /** + * Function getTranslations + * + * @author Erik Amaru O. + * @access public + * @param eter array msgIDs + * @param eter string file + * @return string + */ + function getTranslations ($msgIDs, $lang = SYS_LANG) + { + if (! is_array( $msgIDs )) + return null; + + $translations = Array (); + foreach ($msgIDs as $mID) { + $translations[$mID] = self::LoadTranslation( $mID, $lang ); + } + + return $translations; + } + + /** + * Load an array File Content + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $strFile + * @return void + */ + function LoadArrayFile ($strFile = '') + { + $res = NULL; + if ($strFile != '') { + $src = file( $strFile ); + if (is_array( $src )) { + foreach ($src as $key => $val) { + $res[$key] = trim( $val ); + } + } + } + unset( $src ); + return $res; + } + + /** + * Expand an uri based in the current URI + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $methodPage the method directory and the page + * @return the expanded uri, later, will encryt the uri... + */ + function expandUri ($methodPage) + { + $uri = explode( '/', getenv( 'REQUEST_URI' ) ); + $sw = 0; + $newUri = ''; + if (! defined( 'SYS_SKIN' )) { + for ($i = 0; $i < count( $uri ); $i ++) { + if ($sw == 0) + $newUri .= $uri[$i] . PATH_SEP; + if ($uri[$i] == SYS_SKIN) + $sw = 1; + } + } else { + for ($i = 0; $i < 4; $i ++) { + if ($sw == 0) + $newUri .= $uri[$i] . PATH_SEP; + if ($uri[$i] == SYS_SKIN) + $sw = 1; + } + } + $newUri .= $methodPage; + return $newUri; + } + + /** + * Forces login for generic applications + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $userid + * @param string $permission + * @param string $urlNoAccess + * @return void + */ + function genericForceLogin ($permission, $urlNoAccess, $urlLogin = 'login/login') + { + global $RBAC; + + //the session is expired, go to login page, + //the login page is login/login.html + if (! isset( $_SESSION )) { + header( 'location: ' . G::expandUri( $urlLogin ) ); + die(); + } + + //$permission is an array, we'll verify all permission to allow access. + if (is_array( $permission )) + $aux = $permission; + else + $aux[0] = $permission; + + $sw = 0; + for ($i = 0; $i < count( $aux ); $i ++) { + $res = $RBAC->userCanAccess( $aux[$i] ); + if ($res == 1) + $sw = 1; + } + + //you don't have access to this page + if ($sw == 0) { + header( 'location: ' . G::expandUri( $urlNoAccess ) ); + die(); + } + } + + /** + * capitalize + * + * @param string $string + * + * @return string $string + */ + function capitalize ($string) + { + return ucfirst( $string ); + } + + /** + * toUpper + * + * @param string $sText + * + * @return string strtoupper($sText) + */ + function toUpper ($sText) + { + return strtoupper( $sText ); + } + + /** + * toLower + * + * @param string $sText + * @return string strtolower($sText) + */ + function toLower ($sText) + { + return strtolower( $sText ); + } + + /** + * http_build_query + * + * @param string $formdata, + * @param string $numeric_prefix default value null, + * @param string $key default value null + * + * @return array $res + */ + function http_build_query ($formdata, $numeric_prefix = null, $key = null) + { + $res = array (); + foreach ((array) $formdata as $k => $v) { + $tmp_key = rawurlencode( is_int( $k ) ? $numeric_prefix . $k : $k ); + if ($key) + $tmp_key = $key . '[' . $tmp_key . ']'; + if (is_array( $v ) || is_object( $v )) { + $res[] = G::http_build_query( $v, null /* or $numeric_prefix if you want to add numeric_prefix to all indexes in array*/, $tmp_key ); + } else { + $res[] = $tmp_key . "=" . rawurlencode( $v ); + } + /* If you want, you can write this as one string: $res[] = ( ( is_array($v) || is_object($v) ) ? G::http_build_query($v, null, $tmp_key) : $tmp_key."=".urlencode($v) ); - */ + */ + } + $separator = ini_get( 'arg_separator.output' ); + return implode( $separator, $res ); + } + + /** + * Redirect URL + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $parameter + * @return string + */ + function header ($parameter) + { + if (defined( 'ENABLE_ENCRYPT' ) && (ENABLE_ENCRYPT == 'yes') && (substr( $parameter, 0, 9 ) == 'location:')) { + $url = G::encryptUrl( substr( $parameter, 10 ), URL_KEY ); + header( 'location:' . $url ); + } else + header( $parameter ); + return; + } + + /** + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $permission + * @param string $urlNoAccess + * @return void + */ + function forceLogin ($permission = "", $urlNoAccess = "") + { + global $RBAC; + + if (isset( $_SESSION['USER_LOGGED'] ) && $_SESSION['USER_LOGGED'] == '') { + $sys = (ENABLE_ENCRYPT == 'yes' ? SYS_SYS : "sys" . SYS_SYS); + $lang = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( SYS_LANG ), URL_KEY ) : SYS_LANG); + $skin = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( SYS_SKIN ), URL_KEY ) : SYS_SKIN); + $login = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( 'login' ), URL_KEY ) : 'login'); + $loginhtml = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( 'login.html' ), URL_KEY ) : 'login.html'); + $direction = "/$sys/$lang/$skin/$login/$loginhtml"; + die(); + header( "location: $direction" ); + die(); + return; + } + + $Connection = new DBConnection(); + $ses = new DBSession( $Connection ); + $stQry = "SELECT LOG_STATUS FROM LOGIN WHERE LOG_SID = '" . session_id() . "'"; + $dset = $ses->Execute( $stQry ); + $row = $dset->read(); + $sessionPc = defined( 'SESSION_PC' ) ? SESSION_PC : ''; + $sessionBrowser = defined( 'SESSION_BROWSER' ) ? SESSION_BROWSER : ''; + if (($sessionPc == "1") or ($sessionBrowser == "1")) + if ($row['LOG_STATUS'] == 'X') { + $sys = (ENABLE_ENCRYPT == 'yes' ? SYS_SYS : "sys" . SYS_SYS); + $lang = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( SYS_LANG ), URL_KEY ) : SYS_LANG); + $skin = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( SYS_SKIN ), URL_KEY ) : SYS_SKIN); + $login = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( 'login' ), URL_KEY ) : 'login'); + $loginhtml = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( 'login.html' ), URL_KEY ) : 'login.html'); + $direction = "/$sys/$lang/$skin/$login/$loginhtml"; + G::SendMessageXml( 'ID_CLOSE_SESSION', "warning" ); + header( "location: $direction" ); + die(); + return; + } + + if (defined( 'SIN_COMPATIBILIDAD_RBAC' ) and SIN_COMPATIBILIDAD_RBAC == 1) + return; + + if ($permission == "") { + return; + } + + if (is_array( $permission )) + $aux = $permission; + else + $aux[0] = $permission; + + $sw = 0; + for ($i = 0; $i < count( $aux ); $i ++) { + $res = $RBAC->userCanAccess( $aux[$i] ); + if ($res == 1) + $sw = 1; + //print " $aux[$i] $res $sw
"; + } + + if ($sw == 0 && $urlNoAccess != "") { + $aux = explode( '/', $urlNoAccess ); + $sys = (ENABLE_ENCRYPT == 'yes' ? SYS_SYS : "/sys" . SYS_LANG); + $lang = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( SYS_LANG ), URL_KEY ) : SYS_LANG); + $skin = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( SYS_SKIN ), URL_KEY ) : SYS_SKIN); + $login = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( $aux[0] ), URL_KEY ) : $aux[0]); + $loginhtml = (ENABLE_ENCRYPT == 'yes' ? G::encrypt( urldecode( $aux[1] ), URL_KEY ) : $aux[1]); + //header ("location: /$sys/$lang/$skin/$login/$loginhtml"); + header( "location: /fluid/mNE/o9A/mNGm1aLiop3V4qU/dtij4J°gmaLPwKDU3qNn2qXanw" ); + die(); + } + + if ($sw == 0) { + header( "location: /fluid/mNE/o9A/mNGm1aLiop3V4qU/dtij4J°gmaLPwKDU3qNn2qXanw" ); + //header ( "location: /sys/" . SYS_LANG . "/" . SYS_SKIN . "/login/noViewPage.html" ); + die(); + } + } + + /** + * Add slashes to a string + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $val_old + * @return string + */ + function add_slashes ($val_old) + { + + if (! is_string( $val_old )) + $val_old = "$val_old"; + + $tamano_cadena = strlen( $val_old ); + $contador_cadena = 0; + $new_val = ""; + + for ($contador_cadena = 0; $contador_cadena < $tamano_cadena; $contador_cadena ++) { + $car = $val_old[$contador_cadena]; + + if ($car != chr( 34 ) && $car != chr( 39 ) && $car != chr( 92 )) { + $new_val .= $car; + } else { + if ($car2 != chr( 92 )) { + //print " xmlvar: $new_val -- $car -- $car2
"; + $new_val .= chr( 92 ) . $car; + } else + $new_val .= $car; + } + } + return $new_val; + } + + /** + * Upload a file and then copy to path+ nameToSave + * + * @author Mauricio Veliz + * @access public + * @param string $file + * @param string $path + * @param string $nameToSave + * @param integer $permission + * @return void + */ + function uploadFile ($file, $path, $nameToSave, $permission = 0666) + { + try { + if ($file == '') { + throw new Exception( 'The filename is empty!' ); + } + if (filesize( $file ) > ((((ini_get( 'upload_max_filesize' ) + 0)) * 1024) * 1024)) { + throw new Exception( 'The size of upload file exceeds the allowed by the server!' ); + } + $oldumask = umask( 0 ); + if (! is_dir( $path )) { + G::verifyPath( $path, true ); + } + move_uploaded_file( $file, $path . "/" . $nameToSave ); + chmod( $path . "/" . $nameToSave, $permission ); + umask( $oldumask ); + } catch (Exception $oException) { + throw $oException; + } + } + + /** + * resizeImage + * + * @param string $path, + * @param string $resWidth + * @param string $resHeight + * @param string $saveTo default value null + * + * @return void + */ + function resizeImage ($path, $resWidth, $resHeight, $saveTo = null) + { + $imageInfo = @getimagesize( $path ); + + if (! $imageInfo) + throw new Exception( "Could not get image information" ); + + list ($width, $height) = $imageInfo; + $percentHeight = $resHeight / $height; + $percentWidth = $resWidth / $width; + $percent = ($percentWidth < $percentHeight) ? $percentWidth : $percentHeight; + $resWidth = $width * $percent; + $resHeight = $height * $percent; + + // Resample + $image_p = imagecreatetruecolor( $resWidth, $resHeight ); + imagealphablending( $image_p, false ); + imagesavealpha( $image_p, true ); + + $background = imagecolorallocate( $image_p, 0, 0, 0 ); + ImageColorTransparent( $image_p, $background ); // make the new temp image all transparent + + + //Assume 3 channels if we can't find that information + if (! array_key_exists( "channels", $imageInfo )) + $imageInfo["channels"] = 3; + $memoryNeeded = Round( ($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] + Pow( 2, 16 )) * 1.95 ) / (1024 * 1024); + if ($memoryNeeded < 80) + $memoryNeeded = 80; + ini_set( 'memory_limit', intval( $memoryNeeded ) . 'M' ); + + $functions = array (IMAGETYPE_GIF => array ('imagecreatefromgif','imagegif' + ),IMAGETYPE_JPEG => array ('imagecreatefromjpeg','imagejpeg'),IMAGETYPE_PNG => array ('imagecreatefrompng','imagepng')); + + if (! array_key_exists( $imageInfo[2], $functions )) + throw new Exception( "Image format not supported" ); + + list ($inputFn, $outputFn) = $functions[$imageInfo[2]]; + + $image = $inputFn( $path ); + imagecopyresampled( $image_p, $image, 0, 0, 0, 0, $resWidth, $resHeight, $width, $height ); + $outputFn( $image_p, $saveTo ); + + chmod( $saveTo, 0666 ); + } + + /** + * Merge 2 arrays + * + * @author Fernando Ontiveros Lira + * @access public + * @return array + */ + function array_merges () + { + $array = array (); + $arrays = & func_get_args(); + foreach ($arrays as $array_i) { + if (is_array( $array_i )) { + G::array_merge_2( $array, $array_i ); + } + } + return $array; + } + + /** + * Merge 2 arrays + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $array + * @param string $array_i + * @return array + */ + function array_merge_2 (&$array, &$array_i) + { + foreach ($array_i as $k => $v) { + if (is_array( $v )) { + if (! isset( $array[$k] )) { + $array[$k] = array (); + } + G::array_merge_2( $array[$k], $v ); + } else { + if (isset( $array[$k] ) && is_array( $array[$k] )) { + $array[$k][0] = $v; + } else { + if (isset( $array ) && ! is_array( $array )) { + $temp = $array; + $array = array (); + $array[0] = $temp; + } + $array[$k] = $v; + } + } + } + } + + /** + * Generate random number + * + * @author Fernando Ontiveros Lira + * @access public + * @return int + */ + function generateUniqueID () + { + do { + $sUID = str_replace( '.', '0', uniqid( rand( 0, 999999999 ), true ) ); + } while (strlen( $sUID ) != 32); + return $sUID; + //return strtoupper(substr(uniqid(rand(0, 9), false),0,14)); + } + + /** + * Generate a numeric or alphanumeric code + * + * @author Julio Cesar Laura Avendaힼjuliocesar@colosa.com> + * @access public + * @return string + */ + function generateCode ($iDigits = 4, $sType = 'NUMERIC') + { + if (($iDigits < 4) || ($iDigits > 50)) { + $iDigits = 4; + } + if (($sType != 'NUMERIC') && ($sType != 'ALPHA') && ($sType != 'ALPHANUMERIC')) { + $sType = 'NUMERIC'; + } + $aValidCharacters = array ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' + ); + switch ($sType) { + case 'NUMERIC': + $iMin = 0; + $iMax = 9; + break; + case 'ALPHA': + $iMin = 10; + $iMax = 35; + break; + case 'ALPHANUMERIC': + $iMin = 0; + $iMax = 35; + break; + } + $sCode = ''; + for ($i = 0; $i < $iDigits; $i ++) { + $sCode .= $aValidCharacters[rand( $iMin, $iMax )]; + } + return $sCode; + } + + /** + * Verify if the input string is a valid UID + * + * @author David Callizaya + * @access public + * @return int + */ + function verifyUniqueID ($uid) + { + return (bool) preg_match( '/^[0-9A-Za-z]{14,}/', $uid ); + } + + /** + * is_utf8 + * + * @param string $string + * + * @return string utf8_encode() + */ + function is_utf8 ($string) + { + if (is_array( $string )) { + $enc = implode( '', $string ); + return @! ((ord( $enc[0] ) != 239) && (ord( $enc[1] ) != 187) && (ord( $enc[2] ) != 191)); + } else { + return (utf8_encode( utf8_decode( $string ) ) == $string); + } } - $separator = ini_get('arg_separator.output'); - return implode($separator, $res); - } - /** - * Redirect URL - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $parameter - * @return string - */ - function header( $parameter ) { - if ( defined ('ENABLE_ENCRYPT' ) && (ENABLE_ENCRYPT == 'yes') && (substr ( $parameter, 0, 9) == 'location:')) { - $url = G::encryptUrl ( substr( $parameter, 10) , URL_KEY ); - header ( 'location:' . $url ); - } - else - header ( $parameter ); - return ; - } - - /** - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $permission - * @param string $urlNoAccess - * @return void - */ - function forceLogin( $permission = "", $urlNoAccess = "" ) { - global $RBAC; - - if ( isset( $_SESSION['USER_LOGGED'] ) && $_SESSION['USER_LOGGED'] == '' ) { - $sys = (ENABLE_ENCRYPT=='yes'?SYS_SYS :"sys".SYS_SYS); - $lang = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode(SYS_LANG) , URL_KEY ):SYS_LANG); - $skin = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode(SYS_SKIN) , URL_KEY ):SYS_SKIN); - $login = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode('login') , URL_KEY ):'login'); - $loginhtml = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode('login.html') , URL_KEY ):'login.html'); - $direction = "/$sys/$lang/$skin/$login/$loginhtml"; - die; - header ("location: $direction"); - die; - return; - } - - $Connection = new DBConnection; - $ses = new DBSession($Connection); - $stQry = "SELECT LOG_STATUS FROM LOGIN WHERE LOG_SID = '" . session_id() . "'"; - $dset = $ses->Execute ( $stQry ); - $row = $dset->read(); - $sessionPc = defined ( 'SESSION_PC' ) ? SESSION_PC : '' ; - $sessionBrowser = defined ( 'SESSION_BROWSER' ) ? SESSION_BROWSER : '' ; - if (($sessionPc == "1" ) or ( $sessionBrowser == "1")) - if($row['LOG_STATUS'] == 'X'){ - $sys = (ENABLE_ENCRYPT=='yes'?SYS_SYS :"sys".SYS_SYS); - $lang = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode(SYS_LANG) , URL_KEY ):SYS_LANG); - $skin = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode(SYS_SKIN) , URL_KEY ):SYS_SKIN); - $login = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode('login') , URL_KEY ):'login'); - $loginhtml = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode('login.html') , URL_KEY ):'login.html'); - $direction = "/$sys/$lang/$skin/$login/$loginhtml"; - G::SendMessageXml ('ID_CLOSE_SESSION', "warning"); - header ("location: $direction"); - die; - return; - } - - if ( defined( 'SIN_COMPATIBILIDAD_RBAC') and SIN_COMPATIBILIDAD_RBAC == 1 ) - return; - - if ( $permission == "" ) { - return; - } - - if ( is_array($permission) ) - $aux = $permission; - else - $aux[0] = $permission; - - - $sw = 0; - for ($i = 0; $i < count ($aux); $i++ ) { - $res = $RBAC->userCanAccess($aux[$i]); - if ($res == 1) $sw = 1; - //print " $aux[$i] $res $sw
"; - } - - if ($sw == 0 && $urlNoAccess != "") { - $aux = explode ( '/', $urlNoAccess ); - $sys = (ENABLE_ENCRYPT=='yes'?SYS_SYS :"/sys".SYS_LANG); - $lang = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode(SYS_LANG) , URL_KEY ):SYS_LANG); - $skin = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode(SYS_SKIN) , URL_KEY ):SYS_SKIN); - $login = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode($aux[0]) , URL_KEY ):$aux[0]); - $loginhtml = (ENABLE_ENCRYPT=='yes'?G::encrypt ( urldecode($aux[1]) , URL_KEY ):$aux[1]); - //header ("location: /$sys/$lang/$skin/$login/$loginhtml"); - header ("location: /fluid/mNE/o9A/mNGm1aLiop3V4qU/dtij4J°gmaLPwKDU3qNn2qXanw"); - die; - } - - - if ($sw == 0) { - header ("location: /fluid/mNE/o9A/mNGm1aLiop3V4qU/dtij4J°gmaLPwKDU3qNn2qXanw"); - //header ( "location: /sys/" . SYS_LANG . "/" . SYS_SKIN . "/login/noViewPage.html" ); - die; - } - } - /** - * Add slashes to a string - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $val_old - * @return string - */ - function add_slashes($val_old) { - - if (!is_string ($val_old)) $val_old ="$val_old"; - - $tamano_cadena = strlen ($val_old); - $contador_cadena = 0; - $new_val = ""; - - for ($contador_cadena=0; $contador_cadena< $tamano_cadena; $contador_cadena ++) - { - $car = $val_old[$contador_cadena]; - - if ( $car != chr(34) && $car != chr(39) && $car != chr(92)) - { - $new_val .= $car; - } - else - { - if ($car2 != chr (92) ) - { - //print " xmlvar: $new_val -- $car -- $car2
"; - $new_val .= chr(92) . $car; - } - else - $new_val .= $car; - } - } - return $new_val; - } - /** - * Upload a file and then copy to path+ nameToSave - * - * @author Mauricio Veliz - * @access public - * @param string $file - * @param string $path - * @param string $nameToSave - * @param integer $permission - * @return void - */ - function uploadFile($file, $path ,$nameToSave, $permission = 0666) - { - try { - if ($file == '') { - throw new Exception('The filename is empty!'); - } - if (filesize($file) > ((((ini_get('upload_max_filesize') + 0)) * 1024) * 1024)) { - throw new Exception('The size of upload file exceeds the allowed by the server!'); - } - $oldumask = umask(0); - if (!is_dir($path)) { - G::verifyPath($path, true); - } - move_uploaded_file($file , $path . "/" . $nameToSave); - chmod($path . "/" . $nameToSave , $permission); - umask($oldumask); - } - catch (Exception $oException) { - throw $oException; - } - } - - /** - * resizeImage - * - * @param string $path, - * @param string $resWidth - * @param string $resHeight - * @param string $saveTo default value null - * - * @return void - */ - function resizeImage($path, $resWidth, $resHeight, $saveTo=null) - { - $imageInfo = @getimagesize($path); - - if (!$imageInfo) - throw new Exception("Could not get image information"); - - list($width, $height) = $imageInfo; - $percentHeight = $resHeight / $height; - $percentWidth = $resWidth / $width; - $percent = ($percentWidth < $percentHeight) ? $percentWidth : $percentHeight; - $resWidth = $width * $percent; - $resHeight = $height * $percent; - - // Resample - $image_p = imagecreatetruecolor($resWidth, $resHeight); - imagealphablending($image_p, false); - imagesavealpha($image_p, true); - - $background = imagecolorallocate($image_p, 0, 0, 0); - ImageColorTransparent($image_p, $background); // make the new temp image all transparent - - //Assume 3 channels if we can't find that information - if (!array_key_exists("channels", $imageInfo)) - $imageInfo["channels"] = 3; - $memoryNeeded = Round( ($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] + Pow(2, 16)) * 1.95) / (1024*1024); - if ( $memoryNeeded < 80 ) $memoryNeeded = 80; - ini_set('memory_limit', intval($memoryNeeded) . 'M'); - - $functions = array( - IMAGETYPE_GIF => array('imagecreatefromgif', 'imagegif'), - IMAGETYPE_JPEG => array('imagecreatefromjpeg', 'imagejpeg'), - IMAGETYPE_PNG => array('imagecreatefrompng', 'imagepng'), - ); - - if (!array_key_exists($imageInfo[2], $functions)) - throw new Exception("Image format not supported"); - - list($inputFn, $outputFn) = $functions[$imageInfo[2]]; - - $image = $inputFn($path); - imagecopyresampled($image_p, $image, 0, 0, 0, 0, $resWidth, $resHeight, $width, $height); - $outputFn($image_p, $saveTo); - - chmod($saveTo, 0666); - } - - /** - * Merge 2 arrays - * - * @author Fernando Ontiveros Lira - * @access public - * @return array - */ - function array_merges() { - $array = array(); - $arrays =& func_get_args(); - foreach ($arrays as $array_i) { - if (is_array($array_i)) { - G::array_merge_2($array, $array_i); - } - } - return $array; - } - - /** - * Merge 2 arrays - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $array - * @param string $array_i - * @return array - */ - function array_merge_2(&$array, &$array_i) { - foreach ($array_i as $k => $v) { - if (is_array($v)) { - if (!isset($array[$k])) { - $array[$k] = array(); - } - G::array_merge_2($array[$k], $v); - } else { - if (isset($array[$k]) && is_array($array[$k])) { - $array[$k][0] = $v; - } else { - if (isset($array) && !is_array($array)) { - $temp = $array; - $array = array(); - $array[0] = $temp; - } - $array[$k] = $v; - } - } - } - } - - /** - * Generate random number - * - * @author Fernando Ontiveros Lira - * @access public - * @return int - */ - function generateUniqueID() { - do { - $sUID = str_replace('.', '0', uniqid(rand(0, 999999999), true)); - } while (strlen($sUID) != 32); - return $sUID; - //return strtoupper(substr(uniqid(rand(0, 9), false),0,14)); - } - - - /** - * Generate a numeric or alphanumeric code - * - * @author Julio Cesar Laura Avendaힼjuliocesar@colosa.com> - * @access public - * @return string - */ - function generateCode($iDigits = 4, $sType = 'NUMERIC') { - if (($iDigits < 4) || ($iDigits > 50)) { - $iDigits = 4; - } - if (($sType != 'NUMERIC') && ($sType != 'ALPHA') && ($sType != 'ALPHANUMERIC')) { - $sType = 'NUMERIC'; - } - $aValidCharacters = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', - 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', 'W', 'X', 'Y', 'Z'); - switch ($sType) { - case 'NUMERIC': - $iMin = 0; - $iMax = 9; - break; - case 'ALPHA': - $iMin = 10; - $iMax = 35; - break; - case 'ALPHANUMERIC': - $iMin = 0; - $iMax = 35; - break; - } - $sCode = ''; - for ($i = 0; $i < $iDigits; $i++) { - $sCode .= $aValidCharacters[rand($iMin, $iMax)]; - } - return $sCode; - } - - /** - * Verify if the input string is a valid UID - * - * @author David Callizaya - * @access public - * @return int - */ - function verifyUniqueID( $uid ) { - return (bool) preg_match('/^[0-9A-Za-z]{14,}/',$uid); - } - - /** - * is_utf8 - * - * @param string $string - * - * @return string utf8_encode() - */ - function is_utf8($string) - { - if (is_array($string)) - { - $enc = implode('', $string); - return @!((ord($enc[0]) != 239) && (ord($enc[1]) != 187) && (ord($enc[2]) != 191)); - } - else - { - return (utf8_encode(utf8_decode($string)) == $string); - } - } /** @@ -3041,335 +3079,345 @@ $output = $outputHeader.$output; function capitalizeWords( $text ) { return ucwords($text); - } - - /** - * unhtmlentities - * - * @param string $string - * - * @return string substring - */ - function unhtmlentities ($string) - { - $trans_tbl = get_html_translation_table (HTML_ENTITIES); - foreach($trans_tbl as $k => $v) - { - $ttr[$v] = utf8_encode($k); - } - return strtr ($string, $ttr); - } - - /*************************************** init ********************************************** + } + + /** + * unhtmlentities + * + * @param string $string + * + * @return string substring + */ + function unhtmlentities ($string) + { + $trans_tbl = get_html_translation_table( HTML_ENTITIES ); + foreach ($trans_tbl as $k => $v) { + $ttr[$v] = utf8_encode( $k ); + } + return strtr( $string, $ttr ); + } + + /** + * ************************************* init ********************************************** + * Xml parse collection functions + * Returns a associative array within the xml structure and data + * + * @author Erik Amaru Ortiz + */ + function xmlParser (&$string) + { + $parser = xml_parser_create(); + xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 ); + xml_parse_into_struct( $parser, $string, $vals, $index ); + + $mnary = array (); + $ary = &$mnary; + foreach ($vals as $r) { + $t = $r['tag']; + if ($r['type'] == 'open') { + if (isset( $ary[$t] )) { + if (isset( $ary[$t][0] )) + $ary[$t][] = array (); + else + $ary[$t] = array ($ary[$t],array () + ); + $cv = &$ary[$t][count( $ary[$t] ) - 1]; + } else + $cv = &$ary[$t]; + if (isset( $r['attributes'] )) { + foreach ($r['attributes'] as $k => $v) + $cv['__ATTRIBUTES__'][$k] = $v; + } + // note by gustavo cruz gustavo[at]colosa[dot]com + // minor adjustments to validate if an open node have a value attribute. + // for example a dropdown has many childs, but also can have a value attribute. + if (isset( $r['value'] ) && trim( $r['value'] ) != '') { + $cv['__VALUE__'] = $r['value']; + } + // end added code + $cv['__CONTENT__'] = array (); + $cv['__CONTENT__']['_p'] = &$ary; + $ary = &$cv['__CONTENT__']; + + } elseif ($r['type'] == 'complete') { + if (isset( $ary[$t] )) { // same as open + if (isset( $ary[$t][0] )) + $ary[$t][] = array (); + else + $ary[$t] = array ($ary[$t],array () + ); + $cv = &$ary[$t][count( $ary[$t] ) - 1]; + } else + $cv = &$ary[$t]; + if (isset( $r['attributes'] )) { + foreach ($r['attributes'] as $k => $v) + $cv['__ATTRIBUTES__'][$k] = $v; + } + $cv['__VALUE__'] = (isset( $r['value'] ) ? $r['value'] : ''); + + } elseif ($r['type'] == 'close') { + $ary = &$ary['_p']; + } + } + + self::_del_p( $mnary ); + + $obj_resp->code = xml_get_error_code( $parser ); + $obj_resp->message = xml_error_string( $obj_resp->code ); + $obj_resp->result = $mnary; + xml_parser_free( $parser ); + + return $obj_resp; + } + + /** + * _del_p + * + * @param string &$ary + * + * @return void + */ + // _Internal: Remove recursion in result array + function _del_p (&$ary) + { + foreach ($ary as $k => $v) { + if ($k === '_p') + unset( $ary[$k] ); + elseif (is_array( $ary[$k] )) + self::_del_p( $ary[$k] ); + } + } + + /** + * ary2xml + * + * Array to XML + * + * @param string $cary + * @param string $d=0 + * @param string $forcetag default value '' + * + * @return void + */ + // Array to XML + function ary2xml ($cary, $d = 0, $forcetag = '') + { + $res = array (); + foreach ($cary as $tag => $r) { + if (isset( $r[0] )) { + $res[] = self::ary2xml( $r, $d, $tag ); + } else { + if ($forcetag) + $tag = $forcetag; + $sp = str_repeat( "\t", $d ); + $res[] = "$sp<$tag"; + if (isset( $r['_a'] )) { + foreach ($r['_a'] as $at => $av) + $res[] = " $at=\"$av\""; + } + $res[] = ">" . ((isset( $r['_c'] )) ? "\n" : ''); + if (isset( $r['_c'] )) + $res[] = ary2xml( $r['_c'], $d + 1 ); + elseif (isset( $r['_v'] )) + $res[] = $r['_v']; + $res[] = (isset( $r['_c'] ) ? $sp : '') . "\n"; + } + + } + return implode( '', $res ); + } + + /** + * ins2ary + * + * Insert element into array + * + * @param string &$ary + * @param string $element + * @param string $pos + * + * @return void + */ + // Insert element into array + function ins2ary (&$ary, $element, $pos) + { + $ar1 = array_slice( $ary, 0, $pos ); + $ar1[] = $element; + $ary = array_merge( $ar1, array_slice( $ary, $pos ) ); + } + + /* * Xml parse collection functions - * Returns a associative array within the xml structure and data - * - * @author Erik Amaru Ortiz - */ - function xmlParser(&$string) { - $parser = xml_parser_create(); - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); - xml_parse_into_struct($parser, $string, $vals, $index); - - $mnary = array(); - $ary =&$mnary; - foreach ($vals as $r) { - $t=$r['tag']; - if ($r['type']=='open') { - if (isset($ary[$t])) { - if (isset($ary[$t][0])) - $ary[$t][]=array(); - else - $ary[$t]=array($ary[$t], array()); - $cv=&$ary[$t][count($ary[$t])-1]; - } else $cv=&$ary[$t]; - if (isset($r['attributes'])) { - foreach ($r['attributes'] as $k=>$v) $cv['__ATTRIBUTES__'][$k]=$v; - } - // note by gustavo cruz gustavo[at]colosa[dot]com - // minor adjustments to validate if an open node have a value attribute. - // for example a dropdown has many childs, but also can have a value attribute. - if (isset($r['value']) && trim($r['value'])!=''){ - $cv['__VALUE__'] = $r['value']; - } - // end added code - $cv['__CONTENT__'] = array(); - $cv['__CONTENT__']['_p'] =&$ary; - $ary =&$cv['__CONTENT__']; - - } elseif ($r['type']=='complete') { - if (isset($ary[$t])) { // same as open - if (isset($ary[$t][0])) $ary[$t][]=array(); - else $ary[$t]=array($ary[$t], array()); - $cv=&$ary[$t][count($ary[$t])-1]; - } else $cv=&$ary[$t]; - if (isset($r['attributes'])) { - foreach ($r['attributes'] as $k=>$v) $cv['__ATTRIBUTES__'][$k]=$v; - } - $cv['__VALUE__']=(isset($r['value']) ? $r['value'] : ''); - - } elseif ($r['type']=='close') { - $ary=&$ary['_p']; - } + *************************************** end **********************************************/ + + /** + * evalJScript + * + * @param string $c + * + * @return void + */ + function evalJScript ($c) + { + print ("") ; + } + + /** + * Inflects a string with accented characters and other characteres not suitable for file names, by defaul replace with undescore + * + * @author Erik Amaru Ortiz + * @param (string) string to convert + * @param (string) character for replace + * @param (array) additional characteres map + * + */ + function inflect ($string, $replacement = '_', $map = array()) + { + if (is_array( $replacement )) { + $map = $replacement; + $replacement = '_'; + } + + $quotedReplacement = preg_quote( $replacement, '/' ); + + $default = array ('/à|á|å|â/' => 'a','/è|é|ê|ẽ|ë/' => 'e','/ì|í|î/' => 'i','/ò|ó|ô|ø/' => 'o','/ù|ú|ů|û/' => 'u','/ç/' => 'c','/ñ/' => 'n','/ä|æ/' => 'ae','/ö/' => 'oe','/ü/' => 'ue','/Ä/' => 'Ae','/Ü/' => 'Ue','/Ö/' => 'Oe','/ß/' => 'ss','/\.|\,|\:|\-|\\|\//' => " ",'/\\s+/' => $replacement + ); + + $map = array_merge( $default, $map ); + return preg_replace( array_keys( $map ), array_values( $map ), $string ); + } + + /** + * pr + * + * @param string $var + * + * @return void + */ + function pr ($var) + { + print ("
") ;
+        print_r( $var );
+        print ("
") ; + } + + /** + * dump + * + * @param string $var + * + * @return void + */ + function dump ($var) + { + print ("
") ;
+        var_dump( $var );
+        print ("
") ; + } + + /** + * stripCDATA + * + * @param string $string + * + * @return string str_replace + */ + function stripCDATA ($string) + { + preg_match_all( '//is', $string, $matches ); + return str_replace( $matches[0], $matches[1], $string ); + } + + /** + * Get the temporal directory path on differents O.S. + * i.e. /temp -> linux, C:/Temp -> win + * + * @author + */ + function sys_get_temp_dir () + { + if (! function_exists( 'sys_get_temp_dir' )) { + // Based on http://www.phpit.net/ + // article/creating-zip-tar-archives-dynamically-php/2/ + // Try to get from environment variable + if (! empty( $_ENV['TMP'] )) { + return realpath( $_ENV['TMP'] ); + } else if (! empty( $_ENV['TMPDIR'] )) { + return realpath( $_ENV['TMPDIR'] ); + } else if (! empty( $_ENV['TEMP'] )) { + return realpath( $_ENV['TEMP'] ); + } else { // Detect by creating a temporary file + // Try to use system's temporary directory + // as random name shouldn't exist + $temp_file = tempnam( md5( uniqid( rand(), TRUE ) ), '' ); + if ($temp_file) { + $temp_dir = realpath( dirname( $temp_file ) ); + unlink( $temp_file ); + return $temp_dir; + } else { + return FALSE; + } + } + } else { + return sys_get_temp_dir(); + } + } + + /** + * Get the content of a compose pmos web service response + * Returns an array when has a valid reponse, if the response is invalid returns an object containing a status_code and message properties. + * + * @author + */ + function PMWSCompositeResponse ($oResp, $prop) + { + $Resp = new stdClass(); + + if (is_object( $oResp ) && isset( $oResp->{$prop} )) { + $list = $oResp->{$prop}; + + if (is_object( $list )) { + $aList[0] = $list; + } else { + $aList = $list; + } + + $result = true; + if (is_array( $aList )) { + foreach ($aList as $item) { + if (! isset( $item->guid )) { + $result = false; + break; + } + } + } else { + $Resp->status_code = - 1; + $Resp->message = "Bad respose type for ({$prop})"; + } + + if ($result) { + //verifing if the response has a composite response into a guid value of the first row. + $tmp = explode( ' ', trim( $aList[0]->guid ) ); + if (sizeof( $tmp ) >= 2) { //the guid can't has a space, so this should be a ws response + $Resp->status_code = $tmp[0]; + $Resp->message = substr( $aList[0]->guid, strpos( $aList[0]->guid, ' ' ) + 1 ); + } else { + return $aList; + } + + } else { + $Resp->status_code = - 2; + $Resp->message = "Bad respose, the response has not a uniform struct."; + } + } else if (is_object( $oResp )) { + return Array (); + } else { + $Resp->status_code = - 1; + $Resp->message = "1 Bad respose type for ({$prop})"; + } + return $Resp; } - self::_del_p($mnary); - - $obj_resp->code = xml_get_error_code($parser); - $obj_resp->message = xml_error_string($obj_resp->code); - $obj_resp->result = $mnary; - xml_parser_free($parser); - - return $obj_resp; - } - - /** - * _del_p - * - * @param string &$ary - * - * @return void - */ - // _Internal: Remove recursion in result array - function _del_p(&$ary) { - foreach ($ary as $k=>$v) { - if ($k==='_p') unset($ary[$k]); - elseif (is_array($ary[$k])) self::_del_p($ary[$k]); - } - } - - /** - * ary2xml - * - * Array to XML - * - * @param string $cary - * @param string $d=0 - * @param string $forcetag default value '' - * - * @return void - */ - // Array to XML - function ary2xml($cary, $d=0, $forcetag='') { - $res = array(); - foreach ($cary as $tag=>$r) { - if (isset($r[0])) { - $res[]=self::ary2xml($r, $d, $tag); - } else { - if ($forcetag) $tag=$forcetag; - $sp = str_repeat("\t", $d); - $res[] = "$sp<$tag"; - if (isset($r['_a'])) {foreach ($r['_a'] as $at=>$av) $res[]=" $at=\"$av\"";} - $res[] = ">".((isset($r['_c'])) ? "\n" : ''); - if (isset($r['_c'])) $res[]=ary2xml($r['_c'], $d+1); - elseif (isset($r['_v'])) $res[]=$r['_v']; - $res[] = (isset($r['_c']) ? $sp : '')."\n"; - } - - } - return implode('', $res); - } - - /** - * ins2ary - * - * Insert element into array - * - * @param string &$ary - * @param string $element - * @param string $pos - * - * @return void - */ - // Insert element into array - function ins2ary(&$ary, $element, $pos) - { - $ar1=array_slice($ary, 0, $pos); $ar1[]=$element; - $ary=array_merge($ar1, array_slice($ary, $pos)); - } - - /* - * Xml parse collection functions - *************************************** end **********************************************/ - - - /** - * evalJScript - * - * @param string $c - * - * @return void - */ - function evalJScript($c){ - print(""); - } - - - /** - * Inflects a string with accented characters and other characteres not suitable for file names, by defaul replace with undescore - * - * @author Erik Amaru Ortiz - * @param (string) string to convert - * @param (string) character for replace - * @param (array) additional characteres map - * - */ - function inflect($string, $replacement = '_', $map = array()) { - if (is_array($replacement)) { - $map = $replacement; - $replacement = '_'; - } - - $quotedReplacement = preg_quote($replacement, '/'); - - $default = array( - '/à|á|å|â/' => 'a', - '/è|é|ê|ẽ|ë/' => 'e', - '/ì|í|î/' => 'i', - '/ò|ó|ô|ø/' => 'o', - '/ù|ú|ů|û/' => 'u', - '/ç/' => 'c', - '/ñ/' => 'n', - '/ä|æ/' => 'ae', - '/ö/' => 'oe', - '/ü/' => 'ue', - '/Ä/' => 'Ae', - '/Ü/' => 'Ue', - '/Ö/' => 'Oe', - '/ß/' => 'ss', - '/\.|\,|\:|\-|\\|\//' => " ", - '/\\s+/' => $replacement - ); - - $map = array_merge($default, $map); - return preg_replace(array_keys($map), array_values($map), $string); - } - - /** - * pr - * - * @param string $var - * - * @return void - */ - function pr($var) - { - print("
");
-    print_r($var);
-    print("
"); - } - - /** - * dump - * - * @param string $var - * - * @return void - */ - function dump($var){ - print("
");
-    var_dump($var);
-    print("
"); - } - - /** - * stripCDATA - * - * @param string $string - * - * @return string str_replace - */ - function stripCDATA($string){ - preg_match_all('//is', $string, $matches); - return str_replace($matches[0], $matches[1], $string); - } - - /** - * Get the temporal directory path on differents O.S. i.e. /temp -> linux, C:/Temp -> win - * @author - */ - function sys_get_temp_dir() { - if ( !function_exists('sys_get_temp_dir') ){ - // Based on http://www.phpit.net/ - // article/creating-zip-tar-archives-dynamically-php/2/ - // Try to get from environment variable - if ( !empty($_ENV['TMP']) ){ - return realpath( $_ENV['TMP'] ); - } else if ( !empty($_ENV['TMPDIR']) ){ - return realpath( $_ENV['TMPDIR'] ); - } else if ( !empty($_ENV['TEMP']) ){ - return realpath( $_ENV['TEMP'] ); - } else {// Detect by creating a temporary file - // Try to use system's temporary directory - // as random name shouldn't exist - $temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' ); - if ( $temp_file ){ - $temp_dir = realpath( dirname($temp_file) ); - unlink( $temp_file ); - return $temp_dir; - } else { - return FALSE; - } - } - } else { - return sys_get_temp_dir(); - } - } - - /** - * Get the content of a compose pmos web service response - * Returns an array when has a valid reponse, if the response is invalid returns an object containing a status_code and message properties. - * - * @author - */ - function PMWSCompositeResponse($oResp, $prop) { - $Resp = new stdClass(); - - if( is_object($oResp) && isset($oResp->{$prop}) ){ - $list = $oResp->{$prop}; - - if( is_object($list) ){ - $aList[0] = $list; - } else { - $aList = $list; - } - - $result = true; - if( is_array($aList) ){ - foreach($aList as $item){ - if( !isset($item->guid) ){ - $result = false; - break; - } - } - } else { - $Resp->status_code = -1; - $Resp->message = "Bad respose type for ({$prop})"; - } - - if( $result ){ - //verifing if the response has a composite response into a guid value of the first row. - $tmp = explode(' ', trim($aList[0]->guid)); - if( sizeof($tmp) >= 2 ){ //the guid can't has a space, so this should be a ws response - $Resp->status_code = $tmp[0]; - $Resp->message = substr($aList[0]->guid, strpos($aList[0]->guid, ' ') + 1); - } else { - return $aList; - } - - } else { - $Resp->status_code = -2; - $Resp->message = "Bad respose, the response has not a uniform struct."; - } - } else if( is_object($oResp) ){ - return Array(); - } else { - $Resp->status_code = -1; - $Resp->message = "1 Bad respose type for ({$prop})"; - } - return $Resp; - } - /** * Validate and emai address in complete forms, * @@ -4737,871 +4785,685 @@ function get_mobile_data( $pv_browser_user_agent ) return $a_mobile_data; } - function getBrowser() - { - $u_agent = $_SERVER['HTTP_USER_AGENT']; - $bname = 'Unknown'; - $platform = 'Unknown'; - $version= ""; - - //First get the platform? - if (preg_match('/linux/i', $u_agent)) { - $platform = 'linux'; - } - elseif (preg_match('/macintosh|mac os x/i', $u_agent)) { - $platform = 'mac'; - } - elseif (preg_match('/windows|win32/i', $u_agent)) { - $platform = 'windows'; - } - - // Next get the name of the useragent yes seperately and for good reason - if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent)) - { - $bname = 'Internet Explorer'; - $ub = "MSIE"; - } - elseif(preg_match('/Firefox/i',$u_agent)) - { - $bname = 'Mozilla Firefox'; - $ub = "Firefox"; - } - elseif(preg_match('/Chrome/i',$u_agent)) - { - $bname = 'Google Chrome'; - $ub = "Chrome"; - } - elseif(preg_match('/Safari/i',$u_agent)) - { - $bname = 'Apple Safari'; - $ub = "Safari"; - } - elseif(preg_match('/Opera/i',$u_agent)) - { - $bname = 'Opera'; - $ub = "Opera"; - } - elseif(preg_match('/Netscape/i',$u_agent)) - { - $bname = 'Netscape'; - $ub = "Netscape"; - } - - // finally get the correct version number - $known = array('Version', $ub, 'other'); - $pattern = '#(?P' . join('|', $known) . ')[/ ]+(?P[0-9.|a-zA-Z.]*)#'; - @preg_match_all($pattern, $u_agent, $matches); - - // see how many we have - $i = count($matches['browser']); - if ($i != 1) { - //we will have two since we are not using 'other' argument yet - //see if version is before or after the name - if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){ - $version= $matches['version'][0]; - } - else { - $version= $matches['version'][1]; - } - } - else { - $version= $matches['version'][0]; - } - - // check if we have a number - if ($version==null || $version=="") {$version="?";} - - return array( - 'userAgent' => $u_agent, - 'name' => strtolower($ub), - 'longName' => $bname, - 'version' => $version, - 'platform' => $platform, - 'pattern' => $pattern - ); - } - - - -// track total script execution time -function script_time() -{ - static $script_time; - $elapsed_time = ''; - /* + function getBrowser () + { + $u_agent = $_SERVER['HTTP_USER_AGENT']; + $bname = 'Unknown'; + $platform = 'Unknown'; + $version = ""; + + //First get the platform? + if (preg_match( '/linux/i', $u_agent )) { + $platform = 'linux'; + } elseif (preg_match( '/macintosh|mac os x/i', $u_agent )) { + $platform = 'mac'; + } elseif (preg_match( '/windows|win32/i', $u_agent )) { + $platform = 'windows'; + } + + // Next get the name of the useragent yes seperately and for good reason + if (preg_match( '/MSIE/i', $u_agent ) && ! preg_match( '/Opera/i', $u_agent )) { + $bname = 'Internet Explorer'; + $ub = "MSIE"; + } elseif (preg_match( '/Firefox/i', $u_agent )) { + $bname = 'Mozilla Firefox'; + $ub = "Firefox"; + } elseif (preg_match( '/Chrome/i', $u_agent )) { + $bname = 'Google Chrome'; + $ub = "Chrome"; + } elseif (preg_match( '/Safari/i', $u_agent )) { + $bname = 'Apple Safari'; + $ub = "Safari"; + } elseif (preg_match( '/Opera/i', $u_agent )) { + $bname = 'Opera'; + $ub = "Opera"; + } elseif (preg_match( '/Netscape/i', $u_agent )) { + $bname = 'Netscape'; + $ub = "Netscape"; + } + + // finally get the correct version number + $known = array ('Version',$ub,'other' + ); + $pattern = '#(?P' . join( '|', $known ) . ')[/ ]+(?P[0-9.|a-zA-Z.]*)#'; + @preg_match_all( $pattern, $u_agent, $matches ); + + // see how many we have + $i = count( $matches['browser'] ); + if ($i != 1) { + //we will have two since we are not using 'other' argument yet + //see if version is before or after the name + if (strripos( $u_agent, "Version" ) < strripos( $u_agent, $ub )) { + $version = $matches['version'][0]; + } else { + $version = $matches['version'][1]; + } + } else { + $version = $matches['version'][0]; + } + + // check if we have a number + if ($version == null || $version == "") { + $version = "?"; + } + + return array ('userAgent' => $u_agent,'name' => strtolower( $ub ),'longName' => $bname,'version' => $version,'platform' => $platform,'pattern' => $pattern + ); + } + + // track total script execution time + function script_time () + { + static $script_time; + $elapsed_time = ''; + /* note that microtime(true) requires php 5 or greater for microtime(true) - */ - if ( sprintf("%01.1f", phpversion() ) >= 5 ) { - if ( is_null( $script_time) ) { - $script_time = microtime(true); - } - else { - // note: (string)$var is same as strval($var) - // $elapsed_time = (string)( microtime(true) - $script_time ); - $elapsed_time = ( microtime(true) - $script_time ); - $elapsed_time = sprintf("%01.8f", $elapsed_time ); - $script_time = NULL; // can't unset a static variable - return $elapsed_time; - } - } -} -function getDirectorySize($path,$maxmtime=0) -{ - $totalsize = 0; - $totalcount = 0; - $dircount = 0; - if ($handle = opendir ($path)) - { - while (false !== ($file = readdir($handle))) - { - $nextpath = $path . '/' . $file; - if ($file != '.' && $file != '..' && !is_link ($nextpath) && $file != '.svn') - { - if (is_dir ($nextpath)) - { - $dircount++; - $result = G::getDirectorySize($nextpath,$maxmtime); - $totalsize += $result['size']; - $totalcount += $result['count']; - $dircount += $result['dircount']; - $maxmtime=$result['maxmtime']>$maxmtime?$result['maxmtime']:$maxmtime; - } - elseif (is_file ($nextpath)) - { - $totalsize += filesize ($nextpath); - $totalcount++; - - - $mtime = filemtime($nextpath); - if($mtime>$maxmtime) $maxmtime=$mtime; - - - } - } - } - } - closedir ($handle); - $total['size'] = $totalsize; - $total['count'] = $totalcount; - $total['dircount'] = $dircount; - $total['maxmtime'] = $maxmtime; - - return $total; -} - - /** - * Get checksum from multiple files - * @author erik amaru ortiz - */ - function getCacheFileNameByPattern($path, $pattern) - { - if ($file = glob($path . $pattern)) - preg_match('/[a-f0-9]{32}/', $file[0], $match); - else - $file[0] = ''; - return array('filename'=>$file[0], 'checksum'=>(isset($match[0])? $match[0]: '')); - } - - - /** - * Get checksum from multiple files - * @author erik amaru ortiz - */ - function getCheckSum($files) - { - G::LoadClass('system'); - $key = System::getVersion(); - - if (!is_array($files)) { - $tmp = $files; - $files = array(); - $files[0] = $tmp; - } - - $checkSum = ''; - foreach ($files as $file) { - if (is_file($file)) - $checkSum .= md5_file($file); - } - return md5($checkSum.$key); - } - - /** - * parse_ini_string - Define parse_ini_string if it doesn't exist. - Does accept lines starting with ; as comments - Does not accept comments after values - */ - function parse_ini_string($string){ - if( function_exists('parse_ini_string') ) { - return parse_ini_string($string); - } - else { - $array = Array(); - $lines = explode("\n", $string ); - - foreach( $lines as $line ) { - $statement = preg_match( "/^(?!;)(?P[\w+\.\-]+?)\s*=\s*(?P.+?)\s*$/", $line, $match ); - if( $statement ) { - $key = $match[ 'key' ]; - $value = $match[ 'value' ]; - - //Remove quote - if( preg_match( "/^\".*\"$/", $value ) || preg_match( "/^'.*'$/", $value ) ) { - $value = mb_substr( $value, 1, mb_strlen( $value ) - 2 ); - } - - $array[ $key ] = $value; - } - } - return $array; - } - } - - /** - * disableEnableINIvariable - disable or enable a variable in ini file, this is useful for editing the env.ini file - automatically get the value, and change to inverse value, I mean from true to false and viceversa - */ - function disableEnableINIvariable( $inifile, $variable ) { - $enabled = 'false'; - if ( file_exists($inifile ) ) { - $fp = fopen( $inifile, 'r' ); - $line = fgets($fp); - $found = false; - $buffer = null; - - while ( !feof($fp) ) { - $config = G::parse_ini_string($line); - if ( isset($config[$variable] )) { - $enabled = $config[$variable]; - $buffer .= sprintf("%s = %d \n", $variable, 1- $enabled ); - $found = true; - } - else { - $buffer .= trim($line) . "\n"; - } - $line = fgets($fp); - } - fclose($fp); - if ( !$found ) $buffer .= sprintf("\n%s = 1 \n", $variable ); - - @file_put_contents( $inifile, $buffer); - } - else { - $contents = file_put_contents($inifile, sprintf("\n%s = 1\n", $variable)); - } - } - - /** - * set a variable in ini file - */ - function setINIvariable( $inifile, $variable, $value ) { - if ( file_exists($inifile ) ) { - $fp = fopen( $inifile, 'r' ); - $line = fgets($fp); - $found = false; - $buffer = null; - - while ( !feof($fp) ) { - $config = G::parse_ini_string($line); - if ( isset($config[$variable] )) { - $enabled = $config[$variable]; - $buffer .= sprintf("%s = %s \n", $variable, $value ); - $found = true; - } - else { - $buffer .= trim($line) . "\n"; - } - $line = fgets($fp); - } - fclose($fp); - if ( !$found ) $buffer .= sprintf("\n%s = %s \n", $variable, $value ); - - file_put_contents( $inifile, $buffer); - } - else { - $contents = file_put_contents($inifile, sprintf("\n%s = $s\n", $variable, $value)); - } - } - - function write_php_ini($file, $array) - { - $res = array(); - foreach($array as $key => $val) - { - if(is_array($val)) - { - $res[] = "[$key]"; - foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"'); - } - else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"'); - } - file_put_contents($file, implode("\r\n", $res)); - } - - - /** - * verify if all files & directories passed by param. are writable - * @author Erik Amaru Ortiz - * @param $resources array a list of files to verify write access - */ - function verifyWriteAccess($resources) - { - $noWritable = array(); - foreach ($resources as $i => $resource) { - if (!is_writable($resource)) { - $noWritable[] = $resource; - } - } - - if (count($noWritable) > 0) { - $e = new Exception("Write access not allowed for ProcessMaker resources"); - $e->files = $noWritable; - throw $e; - } - } - - /** - * render a smarty template - * @author Erik Amaru Ortiz - * @param $template string containing the template filename on /gulliver/templates/ directory - * @param $data associative array containig the template data - */ - function renderTemplate($template, $data=array()) - { - if (!defined('PATH_THIRDPARTY')) { - throw new Exception('System constant (PATH_THIRDPARTY) is not defined!'); - } - - require_once PATH_THIRDPARTY . 'smarty/libs/Smarty.class.php'; - $fInfo = pathinfo($template); - - $tplExists = true; - - // file has absolute path - if (substr($template, 0, 1) != PATH_SEP) { - $template = PATH_TEMPLATE . $template; - } - - // fix for template that have dot in its name but is not a valid extension - if (isset($fInfo['extension']) && ($fInfo['extension'] != 'tpl' || $fInfo['extension'] != 'html')) { - unset($fInfo['extension']); - } - - if (!isset($fInfo['extension'])) { - if (file_exists($template . '.tpl')) { - $template .= '.tpl'; - } - else if (file_exists($template . '.html')) { - $template .= '.html'; - } - else { - $tplExists = false; - } - } - else { - if (!file_exists($template)) { - $tplExists = false; - } - } - - if (!$tplExists) { - throw new Exception("Template: $template, doesn't exist!"); - } - - $smarty = new Smarty(); - $smarty->compile_dir = G::sys_get_temp_dir(); - $smarty->cache_dir = G::sys_get_temp_dir(); - $smarty->config_dir = PATH_THIRDPARTY . 'smarty/configs'; - - $smarty->template_dir = PATH_TEMPLATE; - $smarty->force_compile = true; - - foreach ($data as $key => $value) { - $smarty->assign($key, $value); - } - - $smarty->display($template); - } - - /** - * parse a smarty template and return teh result as string - * @author Erik Amaru Ortiz - * @param $template string containing the template filename on /gulliver/templates/ directory - * @param $data associative array containig the template data - * @return $content string containing the parsed template content - */ - function parseTemplate($template, $data=array()) - { - $content = ''; - - ob_start(); - G::renderTemplate($template, $data); - $content = ob_get_contents(); - ob_get_clean(); - - return $content; - } - - /** - * Update a ini file passing a array values, this function don't remove the original comments - * @author Erik Amaru Ortiz - * @licence GPL v2 (http://www.gnu.org/licenses/gpl-2.0.html) - * - * @param $file string containing the ini file to update - * @param $array associative array containing the config data - */ - function update_php_ini($file, $array) - { - $iniLines = array(); - $iniContent = array(); - - if (file_exists($file) && !is_writable($file)) { - throw new Exception("File $file, is not writable."); - } - - if (file_exists($file)) { - $iniContent = file($file); - } - - foreach ($iniContent as $line) { - $line = trim($line); - $lineParts = explode(';', $line); - $setting = G::parse_ini_string($lineParts[0]); - - if (is_array($setting) && count($setting) > 0) { - list($key, ) = array_keys($setting); - - if (isset($array[$key])) { - $value = $array[$key]; - $line = "$key = ".(is_numeric($value) ? $value : '"'.$value.'"'); - $line .= isset($lineParts[1]) ? ' ;' . $lineParts[1] : ''; - unset($array[$key]); - - $lastComment = array_pop($iniLines); - if (strpos($lastComment, "Setting $key") === false) { - $iniLines[] = $lastComment; - } - - $iniLines[] = ";Setting $key - Updated by System on " . date('D d M, Y H:i:s'); - } - } - $iniLines[] = $line; - } - - // inserting new values - foreach ($array as $key => $value) { - $line = "$key = ".(is_numeric($value) ? $value : '"'.$value.'"'); - $iniLines[] = ''; - $iniLines[] = ";Setting $key - Created by System on " . date('D d M, Y H:i:s'); - $iniLines[] = $line; - } - - $content = implode("\r\n", $iniLines); - - if (@file_put_contents($file, $content) === false) { - throw new Exception("G::update_php_ini() -> can't update file: $file"); - } - } - - /** - * recursive file & directories write permission detect - * @author Erik Amaru Ortiz - * @licence GPL v2 (http://www.gnu.org/licenses/gpl-2.0.html) - * - * @param $path string of directory or file to verify recursively - * @param $noWritableFiles (alternative) array passed by reference to store all no-writable files - * @return bool true if all files inside a directory path are writable, false in another case - */ - function is_writable_r($path, &$noWritableFiles = array()) - { - if (is_writable($path)){ - if (!is_dir($path)) - return true; - - $list = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR .'*'); - - $sw = true; - foreach ($list as $f) { - if (!G::is_writable_r($f, $noWritableFiles)) { - $sw = false; - } - } - - return $sw; - } - else { - if (!in_array($path, $noWritableFiles)) - $noWritableFiles[] = $path; - - return false; - } - } - - /** - * This method allow dispatch rest services using 'Restler' thirdparty library - * - * @author Erik Amaru Ortiz - */ - public function dispatchRestService($uri, $config, $apiClassesPath = '') - { - require_once 'restler/restler.php'; - - $rest = new Restler(); - $rest->setSupportedFormats('JsonFormat', 'XmlFormat'); - + */ + if (sprintf( "%01.1f", phpversion() ) >= 5) { + if (is_null( $script_time )) { + $script_time = microtime( true ); + } else { + // note: (string)$var is same as strval($var) + // $elapsed_time = (string)( microtime(true) - $script_time ); + $elapsed_time = (microtime( true ) - $script_time); + $elapsed_time = sprintf( "%01.8f", $elapsed_time ); + $script_time = NULL; // can't unset a static variable + return $elapsed_time; + } + } + } + + function getDirectorySize ($path, $maxmtime = 0) + { + $totalsize = 0; + $totalcount = 0; + $dircount = 0; + if ($handle = opendir( $path )) { + while (false !== ($file = readdir( $handle ))) { + $nextpath = $path . '/' . $file; + if ($file != '.' && $file != '..' && ! is_link( $nextpath ) && $file != '.svn') { + if (is_dir( $nextpath )) { + $dircount ++; + $result = G::getDirectorySize( $nextpath, $maxmtime ); + $totalsize += $result['size']; + $totalcount += $result['count']; + $dircount += $result['dircount']; + $maxmtime = $result['maxmtime'] > $maxmtime ? $result['maxmtime'] : $maxmtime; + } elseif (is_file( $nextpath )) { + $totalsize += filesize( $nextpath ); + $totalcount ++; + + $mtime = filemtime( $nextpath ); + if ($mtime > $maxmtime) + $maxmtime = $mtime; + + } + } + } + } + closedir( $handle ); + $total['size'] = $totalsize; + $total['count'] = $totalcount; + $total['dircount'] = $dircount; + $total['maxmtime'] = $maxmtime; + + return $total; + } + + /** + * Get checksum from multiple files + * + * @author erik amaru ortiz + */ + function getCacheFileNameByPattern ($path, $pattern) + { + if ($file = glob( $path . $pattern )) + preg_match( '/[a-f0-9]{32}/', $file[0], $match ); + else + $file[0] = ''; + return array ('filename' => $file[0],'checksum' => (isset( $match[0] ) ? $match[0] : '') + ); + } + + /** + * Get checksum from multiple files + * + * @author erik amaru ortiz + */ + function getCheckSum ($files) + { + G::LoadClass( 'system' ); + $key = System::getVersion(); + + if (! is_array( $files )) { + $tmp = $files; + $files = array (); + $files[0] = $tmp; + } + + $checkSum = ''; + foreach ($files as $file) { + if (is_file( $file )) + $checkSum .= md5_file( $file ); + } + return md5( $checkSum . $key ); + } + + /** + * parse_ini_string + * Define parse_ini_string if it doesn't exist. + * Does accept lines starting with ; as comments + * Does not accept comments after values + */ + function parse_ini_string ($string) + { + if (function_exists( 'parse_ini_string' )) { + return parse_ini_string( $string ); + } else { + $array = Array (); + $lines = explode( "\n", $string ); + + foreach ($lines as $line) { + $statement = preg_match( "/^(?!;)(?P[\w+\.\-]+?)\s*=\s*(?P.+?)\s*$/", $line, $match ); + if ($statement) { + $key = $match['key']; + $value = $match['value']; + + //Remove quote + if (preg_match( "/^\".*\"$/", $value ) || preg_match( "/^'.*'$/", $value )) { + $value = mb_substr( $value, 1, mb_strlen( $value ) - 2 ); + } + + $array[$key] = $value; + } + } + return $array; + } + } + + /** + * disableEnableINIvariable + * disable or enable a variable in ini file, this is useful for editing the env.ini file + * automatically get the value, and change to inverse value, I mean from true to false and viceversa + */ + function disableEnableINIvariable ($inifile, $variable) + { + $enabled = 'false'; + if (file_exists( $inifile )) { + $fp = fopen( $inifile, 'r' ); + $line = fgets( $fp ); + $found = false; + $buffer = null; + + while (! feof( $fp )) { + $config = G::parse_ini_string( $line ); + if (isset( $config[$variable] )) { + $enabled = $config[$variable]; + $buffer .= sprintf( "%s = %d \n", $variable, 1 - $enabled ); + $found = true; + } else { + $buffer .= trim( $line ) . "\n"; + } + $line = fgets( $fp ); + } + fclose( $fp ); + if (! $found) + $buffer .= sprintf( "\n%s = 1 \n", $variable ); + + @file_put_contents( $inifile, $buffer ); + } else { + $contents = file_put_contents( $inifile, sprintf( "\n%s = 1\n", $variable ) ); + } + } + + /** + * set a variable in ini file + */ + function setINIvariable ($inifile, $variable, $value) + { + if (file_exists( $inifile )) { + $fp = fopen( $inifile, 'r' ); + $line = fgets( $fp ); + $found = false; + $buffer = null; + + while (! feof( $fp )) { + $config = G::parse_ini_string( $line ); + if (isset( $config[$variable] )) { + $enabled = $config[$variable]; + $buffer .= sprintf( "%s = %s \n", $variable, $value ); + $found = true; + } else { + $buffer .= trim( $line ) . "\n"; + } + $line = fgets( $fp ); + } + fclose( $fp ); + if (! $found) + $buffer .= sprintf( "\n%s = %s \n", $variable, $value ); + + file_put_contents( $inifile, $buffer ); + } else { + $contents = file_put_contents( $inifile, sprintf( "\n%s = $s\n", $variable, $value ) ); + } + } + + function write_php_ini ($file, $array) + { + $res = array (); + foreach ($array as $key => $val) { + if (is_array( $val )) { + $res[] = "[$key]"; + foreach ($val as $skey => $sval) + $res[] = "$skey = " . (is_numeric( $sval ) ? $sval : '"' . $sval . '"'); + } else + $res[] = "$key = " . (is_numeric( $val ) ? $val : '"' . $val . '"'); + } + file_put_contents( $file, implode( "\r\n", $res ) ); + } + + /** + * verify if all files & directories passed by param. + * are writable + * + * @author Erik Amaru Ortiz + * @param $resources array a list of files to verify write access + */ + function verifyWriteAccess ($resources) + { + $noWritable = array (); + foreach ($resources as $i => $resource) { + if (! is_writable( $resource )) { + $noWritable[] = $resource; + } + } + + if (count( $noWritable ) > 0) { + $e = new Exception( "Write access not allowed for ProcessMaker resources" ); + $e->files = $noWritable; + throw $e; + } + } + + /** + * render a smarty template + * + * @author Erik Amaru Ortiz + * @param $template string containing the template filename on /gulliver/templates/ directory + * @param $data associative array containig the template data + */ + function renderTemplate ($template, $data = array()) + { + if (! defined( 'PATH_THIRDPARTY' )) { + throw new Exception( 'System constant (PATH_THIRDPARTY) is not defined!' ); + } + + require_once PATH_THIRDPARTY . 'smarty/libs/Smarty.class.php'; + $fInfo = pathinfo( $template ); + + $tplExists = true; + + // file has absolute path + if (substr( $template, 0, 1 ) != PATH_SEP) { + $template = PATH_TEMPLATE . $template; + } + + // fix for template that have dot in its name but is not a valid extension + if (isset( $fInfo['extension'] ) && ($fInfo['extension'] != 'tpl' || $fInfo['extension'] != 'html')) { + unset( $fInfo['extension'] ); + } + + if (! isset( $fInfo['extension'] )) { + if (file_exists( $template . '.tpl' )) { + $template .= '.tpl'; + } else if (file_exists( $template . '.html' )) { + $template .= '.html'; + } else { + $tplExists = false; + } + } else { + if (! file_exists( $template )) { + $tplExists = false; + } + } + + if (! $tplExists) { + throw new Exception( "Template: $template, doesn't exist!" ); + } + + $smarty = new Smarty(); + $smarty->compile_dir = G::sys_get_temp_dir(); + $smarty->cache_dir = G::sys_get_temp_dir(); + $smarty->config_dir = PATH_THIRDPARTY . 'smarty/configs'; + + $smarty->template_dir = PATH_TEMPLATE; + $smarty->force_compile = true; + + foreach ($data as $key => $value) { + $smarty->assign( $key, $value ); + } + + $smarty->display( $template ); + } + + /** + * parse a smarty template and return teh result as string + * + * @author Erik Amaru Ortiz + * @param $template string containing the template filename on /gulliver/templates/ directory + * @param $data associative array containig the template data + * @return $content string containing the parsed template content + */ + function parseTemplate ($template, $data = array()) + { + $content = ''; + + ob_start(); + G::renderTemplate( $template, $data ); + $content = ob_get_contents(); + ob_get_clean(); + + return $content; + } + + /** + * Update a ini file passing a array values, this function don't remove the original comments + * + * @author Erik Amaru Ortiz + * @licence GPL v2 (http://www.gnu.org/licenses/gpl-2.0.html) + * + * @param $file string containing the ini file to update + * @param $array associative array containing the config data + */ + function update_php_ini ($file, $array) + { + $iniLines = array (); + $iniContent = array (); + + if (file_exists( $file ) && ! is_writable( $file )) { + throw new Exception( "File $file, is not writable." ); + } + + if (file_exists( $file )) { + $iniContent = file( $file ); + } + + foreach ($iniContent as $line) { + $line = trim( $line ); + $lineParts = explode( ';', $line ); + $setting = G::parse_ini_string( $lineParts[0] ); + + if (is_array( $setting ) && count( $setting ) > 0) { + list ($key, ) = array_keys( $setting ); + + if (isset( $array[$key] )) { + $value = $array[$key]; + $line = "$key = " . (is_numeric( $value ) ? $value : '"' . $value . '"'); + $line .= isset( $lineParts[1] ) ? ' ;' . $lineParts[1] : ''; + unset( $array[$key] ); + + $lastComment = array_pop( $iniLines ); + if (strpos( $lastComment, "Setting $key" ) === false) { + $iniLines[] = $lastComment; + } + + $iniLines[] = ";Setting $key - Updated by System on " . date( 'D d M, Y H:i:s' ); + } + } + $iniLines[] = $line; + } + + // inserting new values + foreach ($array as $key => $value) { + $line = "$key = " . (is_numeric( $value ) ? $value : '"' . $value . '"'); + $iniLines[] = ''; + $iniLines[] = ";Setting $key - Created by System on " . date( 'D d M, Y H:i:s' ); + $iniLines[] = $line; + } + + $content = implode( "\r\n", $iniLines ); + + if (@file_put_contents( $file, $content ) === false) { + throw new Exception( "G::update_php_ini() -> can't update file: $file" ); + } + } + + /** + * recursive file & directories write permission detect + * + * @author Erik Amaru Ortiz + * @licence GPL v2 (http://www.gnu.org/licenses/gpl-2.0.html) + * + * @param $path string of directory or file to verify recursively + * @param $noWritableFiles (alternative) array passed by reference to store all no-writable files + * @return bool true if all files inside a directory path are writable, false in another case + */ + function is_writable_r ($path, &$noWritableFiles = array()) + { + if (is_writable( $path )) { + if (! is_dir( $path )) { + return true; + } + $list = glob( rtrim( $path, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . '*' ); + + $sw = true; + foreach ($list as $f) { + if (! G::is_writable_r( $f, $noWritableFiles )) { + $sw = false; + } + } + + return $sw; + } else { + if (! in_array( $path, $noWritableFiles )) { + $noWritableFiles[] = $path; + } + return false; + } + } + + /** + * This method allow dispatch rest services using 'Restler' thirdparty library + * + * @author Erik Amaru Ortiz + */ + public function dispatchRestService ($uri, $config, $apiClassesPath = '') + { + require_once 'restler/restler.php'; + + $rest = new Restler(); + $rest->setSupportedFormats( 'JsonFormat', 'XmlFormat' ); // getting all services class - $restClasses = array(); - $restClassesList = G::rglob('*', 0, PATH_CORE . 'services/'); - foreach ($restClassesList as $classFile) { - if (substr($classFile, -4) === '.php') { - $restClasses[str_replace('.php', '', basename($classFile))] = $classFile; - } - } - - if (! empty($apiClassesPath)) { - $pluginRestClasses = array(); - $restClassesList = G::rglob('*', 0, $apiClassesPath . 'services/'); - foreach ($restClassesList as $classFile) { - if (substr($classFile, -4) === '.php') { - $pluginRestClasses[str_replace('.php', '', basename($classFile))] = $classFile; - } - } - $restClasses = array_merge($restClasses, $pluginRestClasses); - } - - + $restClasses = array (); + $restClassesList = G::rglob( '*', 0, PATH_CORE . 'services/' ); + foreach ($restClassesList as $classFile) { + if (substr( $classFile, - 4 ) === '.php') { + $restClasses[str_replace( '.php', '', basename( $classFile ) )] = $classFile; + } + } + if (! empty( $apiClassesPath )) { + $pluginRestClasses = array (); + $restClassesList = G::rglob( '*', 0, $apiClassesPath . 'services/' ); + foreach ($restClassesList as $classFile) { + if (substr( $classFile, - 4 ) === '.php') { + $pluginRestClasses[str_replace( '.php', '', basename( $classFile ) )] = $classFile; + } + } + $restClasses = array_merge( $restClasses, $pluginRestClasses ); + } // hook to get rest api classes from plugins - if (class_exists('PMPluginRegistry')) { - $pluginRegistry = & PMPluginRegistry::getSingleton(); - $pluginClasses = $pluginRegistry->getRegisteredRestClassFiles(); - $restClasses = array_merge($restClasses, $pluginClasses); - } - - foreach ($restClasses as $key => $classFile) { - if ( !file_exists($classFile) ) { - unset($restClasses[$key]); - continue; - } + if (class_exists( 'PMPluginRegistry' )) { + $pluginRegistry = & PMPluginRegistry::getSingleton(); + $pluginClasses = $pluginRegistry->getRegisteredRestClassFiles(); + $restClasses = array_merge( $restClasses, $pluginClasses ); + } + foreach ($restClasses as $key => $classFile) { + if (! file_exists( $classFile )) { + unset( $restClasses[$key] ); + continue; + } //load the file, and check if exist the class inside it. - require_once $classFile; - $namespace = 'Services_Rest_'; - $className = str_replace('.php', '', basename($classFile)); - + require_once $classFile; + $namespace = 'Services_Rest_'; + $className = str_replace( '.php', '', basename( $classFile ) ); + // if the core class does not exists try resolve the for a plugin - if (! class_exists($namespace . $className)) { - $namespace = 'Plugin_Services_Rest_'; - + if (! class_exists( $namespace . $className )) { + $namespace = 'Plugin_Services_Rest_'; // Couldn't resolve the class name, just skipp it - if (! class_exists($namespace . $className)) { - unset($restClasses[$key]); - continue; - } - } + if (! class_exists( $namespace . $className )) { + unset( $restClasses[$key] ); + continue; + } + } // verify if there is an auth class implementing 'iAuthenticate' - $classNameAuth = $namespace . $className; - $reflClass = new ReflectionClass($classNameAuth); + $classNameAuth = $namespace . $className; + $reflClass = new ReflectionClass( $classNameAuth ); // that wasn't from plugin - if ($reflClass->implementsInterface('iAuthenticate') && $namespace != 'Plugin_Services_Rest_') { + if ($reflClass->implementsInterface( 'iAuthenticate' ) && $namespace != 'Plugin_Services_Rest_') { // auth class found, set as restler authentication class handler - $rest->addAuthenticationClass($classNameAuth); - } else { + $rest->addAuthenticationClass( $classNameAuth ); + } else { // add api class - $rest->addAPIClass($classNameAuth); - } - } + $rest->addAPIClass( $classNameAuth ); + } + } //end foreach rest class - // resolving the class for current request - $uriPart = explode('/', $uri); - $requestedClass = ''; - - if (isset($uriPart[1])) { - $requestedClass = ucfirst($uriPart[1]); - } - if (class_exists('Services_Rest_' . $requestedClass)) { - $namespace = 'Services_Rest_'; - } elseif (class_exists('Plugin_Services_Rest_' . $requestedClass)) { - $namespace = 'Plugin_Services_Rest_'; - } else { - $namespace = ''; - } + $uriPart = explode( '/', $uri ); + $requestedClass = ''; + if (isset( $uriPart[1] )) { + $requestedClass = ucfirst( $uriPart[1] ); + } + if (class_exists( 'Services_Rest_' . $requestedClass )) { + $namespace = 'Services_Rest_'; + } elseif (class_exists( 'Plugin_Services_Rest_' . $requestedClass )) { + $namespace = 'Plugin_Services_Rest_'; + } else { + $namespace = ''; + } // end resolv. - // Send additional headers (if exists) configured on rest-config.ini - if (array_key_exists('HEADERS', $config)) { - foreach ($config['HEADERS'] as $name => $value) { - header("$name: $value"); + if (array_key_exists( 'HEADERS', $config )) { + foreach ($config['HEADERS'] as $name => $value) { + header( "$name: $value" ); } } - // to handle a request with "OPTIONS" method - if (! empty($namespace) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') { - $reflClass = new ReflectionClass($namespace . $requestedClass); - + if (! empty( $namespace ) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') { + $reflClass = new ReflectionClass( $namespace . $requestedClass ); // if the rest class has not a "options" method - if (! $reflClass->hasMethod('options')) { - header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, HEADERS'); - header('Access-Control-Allow-Headers: authorization, content-type'); - header("Access-Control-Allow-Credentials", "false"); - header('Access-Control-Max-Age: 60'); - exit(); + if (! $reflClass->hasMethod( 'options' )) { + header( 'Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, HEADERS' ); + header( 'Access-Control-Allow-Headers: authorization, content-type' ); + header( "Access-Control-Allow-Credentials", "false" ); + header( 'Access-Control-Max-Age: 60' ); + exit(); } } - // override global REQUEST_URI to pass to Restler library - $_SERVER['REQUEST_URI'] = '/' . strtolower($namespace) . ltrim($uri, '/'); - + $_SERVER['REQUEST_URI'] = '/' . strtolower( $namespace ) . ltrim( $uri, '/' ); // handle the rest request - $rest->handle(); - } - - public function reservedWordsSql() - { + $rest->handle(); + } + + public function reservedWordsSql () + { //Reserved words SQL - $reservedWordsSql = array( - "ACCESSIBLE", "ACTION", "ADD", "ALL", "ALTER", - "ANALYZE", "AND", "ANY", "AS", "ASC", - "ASENSITIVE", "AUTHORIZATION", "BACKUP", "BEFORE", "BEGIN", - "BETWEEN", "BIGINT", "BINARY", "BIT", "BLOB", - "BOTH", "BREAK", "BROWSE", "BULK", "BY", - "CALL", "CASCADE", "CASE", "CHANGE", "CHAR", - "CHARACTER", "CHECK", "CHECKPOINT", "CLOSE", "CLUSTERED", - "COALESCE", "COLLATE", "COLUMN", "COMMIT", "COMPUTE", - "CONDITION", "CONSTRAINT", "CONTAINS", "CONTAINSTABLE", "CONTINUE", - "CONVERT", "CREATE", "CROSS", "CURRENT", "CURRENT_DATE", - "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", "CURSOR", "DATABASE", - "DATABASES", "DATE", "DAY_HOUR", "DAY_MICROSECOND", "DAY_MINUTE", - "DAY_SECOND", "DBCC", "DEALLOCATE", "DEC", "DECIMAL", - "DECLARE", "DEFAULT", "DELAYED", "DELETE", "DENY", - "DESC", "DESCRIBE", "DETERMINISTIC", "DISK", "DISTINCT", - "DISTINCTROW", "DISTRIBUTED", "DIV", "DOUBLE", "DROP", - "DUAL", "DUMMY", "DUMP", "EACH", "ELSE", - "ELSEIF", "ENCLOSED", "END", "ENUM", "ERRLVL", - "ESCAPE", "ESCAPED", "EXCEPT", "EXEC", "EXECUTE", - "EXISTS", "EXIT", "EXPLAIN", "FALSE", "FETCH", - "FILE", "FILLFACTOR", "FLOAT", "FLOAT4", "FLOAT8", - "FOR", "FORCE", "FOREIGN", "FREETEXT", "FREETEXTTABLE", - "FROM", "FULL", "FULLTEXT", "FUNCTION", "GENERAL", - "GOTO", "GRANT", "GROUP", "HAVING", "HIGH_PRIORITY", - "HOLDLOCK", "HOUR_MICROSECOND", "HOUR_MINUTE", "HOUR_SECOND", "IDENTITY", - "IDENTITYCOL", "IDENTITY_INSERT", "IF", "IGNORE", "IGNORE_SERVER_IDS", - "IN", "INDEX", "INFILE", "INNER", "INOUT", - "INSENSITIVE", "INSERT", "INT", "INT1", "INT2", - "INT3", "INT4", "INT8", "INTEGER", "INTERSECT", - "INTERVAL", "INTO", "IS", "ITERATE", "JOIN", - "KEY", "KEYS", "KILL", "LEADING", "LEAVE", - "LEFT", "LIKE", "LIMIT", "LINEAR", "LINENO", - "LINES", "LOAD", "LOCALTIME", "LOCALTIMESTAMP", "LOCK", - "LONG", "LONGBLOB", "LONGTEXT", "LOOP", "LOW_PRIORITY", - "MASTER_HEARTBEAT_PERIOD", "MASTER_SSL_VERIFY_SERVER_CERT", "MATCH", "MAXVALUE", "MEDIUMBLOB", - "MEDIUMINT", "MEDIUMTEXT", "MIDDLEINT", "MINUTE_MICROSECOND", "MINUTE_SECOND", - "MOD", "MODIFIES", "NATIONAL", "NATURAL", "NO", - "NOCHECK", "NONCLUSTERED", "NOT", "NO_WRITE_TO_BINLOG", "NULL", - "NULLIF", "NUMERIC", "OF", "OFF", "OFFSETS", - "ON", "OPEN", "OPENDATASOURCE", "OPENQUERY", "OPENROWSET", - "OPENXML", "OPTIMIZE", "OPTION", "OPTIONALLY", "OR", - "ORDER", "OUT", "OUTER", "OUTFILE", "OVER", - "PERCENT", "PLAN", "PRECISION", "PRIMARY", "PRINT", - "PROC", "PROCEDURE", "PUBLIC", "PURGE", "RAISERROR", - "RANGE", "READ", "READS", "READTEXT", "READ_WRITE", - "REAL", "RECONFIGURE", "REFERENCES", "REGEXP", "RELEASE", - "RENAME", "REPEAT", "REPLACE", "REPLICATION", "REQUIRE", - "RESIGNAL", "RESTORE", "RESTRICT", "RETURN", "REVOKE", - "RIGHT", "RLIKE", "ROLLBACK", "ROWCOUNT", "ROWGUIDCOL", - "RULE", "SAVE", "SCHEMA", "SCHEMAS", "SECOND_MICROSECOND", - "SELECT", "SENSITIVE", "SEPARATOR", "SESSION_USER", "SET", - "SETUSER", "SHOW", "SHUTDOWN", "SIGNAL", "SLOW", - "SMALLINT", "SOME", "SPATIAL", "SPECIFIC", "SQL", - "SQLEXCEPTION", "SQLSTATE", "SQLWARNING", "SQL_BIG_RESULT", "SQL_CALC_FOUND_ROWS", - "SQL_SMALL_RESULT", "SSL", "STARTING", "STATISTICS", "STRAIGHT_JOIN", - "SYSTEM_USER", "TABLE", "TERMINATED", "TEXT", "TEXTSIZE", - "THEN", "TIME", "TIMESTAMP", "TINYBLOB", "TINYINT", - "TINYTEXT", "TO", "TOP", "TRAILING", "TRAN", - "TRANSACTION", "TRIGGER", "TRUE", "TRUNCATE", "TSEQUAL", - "UNDO", "UNION", "UNIQUE", "UNLOCK", "UNSIGNED", - "UPDATE", "UPDATETEXT", "USAGE", "USE", "USER", - "USING", "UTC_DATE", "UTC_TIME", "UTC_TIMESTAMP", "VALUES", - "VARBINARY", "VARCHAR", "VARCHARACTER", "VARYING", "VIEW", - "WAITFOR", "WHEN", "WHERE", "WHILE", "WITH", - "WRITE", "WRITETEXT", "XOR", "YEAR_MONTH", "ZEROFILL" - ); - - return $reservedWordsSql; - } - - /* Friendly functions. - /** - * isWinOs - * - * @return true if the 3 first letters of PHP_OS got 'WIN', otherwise false. - */ - function isWinOs() - { - return strtoupper(substr(PHP_OS, 0, 3)) == "WIN"; - } - - /** - * isNTOs - * - * @return true if PHP_OS is 'WINNT', otherwise false. - */ - function isNTOs() - { - return PHP_OS == "WINNT"; - } - - /** - * isLinuxOs - * - * @return true if PHP_OS (upper text) got 'LINUX', otherwise false. - */ - function isLinuxOs() - { - return strtoupper(PHP_OS) == "LINUX"; - } - - /** - * getDirSize - * - * @path of the directory that want to check. smaller than getDirectorySize function. - */ - function getDirSize($path) - { - $io = popen('/usr/bin/du -sb '.$path, 'r'); - $size = intval(fgets($io,80)); - pclose($io); - return $size; - } - - /** - * getMinText, Used with longer size labels to minimize them, don't like it but works. - * - * @text Contains the text to be cut according to $maxTextLenght - * @maxTextLength got the max length of the text. - * return the min text plus '...' - */ - function getMinText ($text,$maxTextLenght) - { - $points = "..."; - $lengthPoints = strlen($points); - if(strlen($text) > $maxTextLenght){ - $text = substr($text,0,$maxTextLenght - $lengthPoints) . $points; - } - return $text;//TODO: perhaps it shouls return an array to don't loose the original string text - } - - /** - * isPMUnderUpdating, Used to set a file flag tio check if PM is upgrading. - * - * @setFlag Contains the flag to set or unset the temporary file: - * 0 to delete the temporary file flag - * 1 to set the temporary file flag. - * 2 or bigger to check if the temporary file exists. - * return true if the file exists, otherwise false. - */ - function isPMUnderUpdating($setFlag = 2) - { - $fileCheck = PATH_DATA."UPDATE.dat"; - if($setFlag == 0){ - if (file_exists($fileCheck)){ - unlink ($fileCheck); - } - } - else if($setFlag == 1){ - $fp = fopen($fileCheck,'w'); - $line = fputs($fp,"true"); - } - //checking temporary file - if($setFlag >= 1){ - if ( file_exists($fileCheck)){ - return true; - } - } - return false; - } + $reservedWordsSql = array ("ACCESSIBLE","ACTION","ADD","ALL","ALTER","ANALYZE","AND","ANY","AS","ASC","ASENSITIVE","AUTHORIZATION","BACKUP","BEFORE","BEGIN","BETWEEN","BIGINT","BINARY","BIT","BLOB","BOTH","BREAK","BROWSE","BULK","BY","CALL","CASCADE","CASE","CHANGE","CHAR","CHARACTER","CHECK","CHECKPOINT","CLOSE","CLUSTERED","COALESCE","COLLATE","COLUMN","COMMIT","COMPUTE","CONDITION","CONSTRAINT","CONTAINS","CONTAINSTABLE","CONTINUE","CONVERT","CREATE","CROSS","CURRENT","CURRENT_DATE","CURRENT_TIME","CURRENT_TIMESTAMP","CURRENT_USER","CURSOR","DATABASE","DATABASES","DATE","DAY_HOUR","DAY_MICROSECOND","DAY_MINUTE","DAY_SECOND","DBCC","DEALLOCATE","DEC","DECIMAL","DECLARE","DEFAULT","DELAYED","DELETE","DENY","DESC","DESCRIBE","DETERMINISTIC","DISK","DISTINCT","DISTINCTROW", + "DISTRIBUTED","DIV","DOUBLE","DROP","DUAL","DUMMY","DUMP","EACH","ELSE","ELSEIF","ENCLOSED","END","ENUM","ERRLVL","ESCAPE","ESCAPED","EXCEPT","EXEC","EXECUTE","EXISTS","EXIT","EXPLAIN","FALSE","FETCH","FILE","FILLFACTOR","FLOAT","FLOAT4","FLOAT8","FOR","FORCE","FOREIGN","FREETEXT","FREETEXTTABLE","FROM","FULL","FULLTEXT","FUNCTION","GENERAL","GOTO","GRANT","GROUP","HAVING","HIGH_PRIORITY","HOLDLOCK","HOUR_MICROSECOND","HOUR_MINUTE","HOUR_SECOND","IDENTITY","IDENTITYCOL","IDENTITY_INSERT","IF","IGNORE","IGNORE_SERVER_IDS","IN","INDEX","INFILE","INNER","INOUT","INSENSITIVE","INSERT","INT","INT1","INT2","INT3","INT4","INT8","INTEGER","INTERSECT","INTERVAL","INTO","IS","ITERATE","JOIN","KEY","KEYS","KILL","LEADING","LEAVE","LEFT","LIKE","LIMIT","LINEAR","LINENO","LINES", + "LOAD","LOCALTIME","LOCALTIMESTAMP","LOCK","LONG","LONGBLOB","LONGTEXT","LOOP","LOW_PRIORITY","MASTER_HEARTBEAT_PERIOD","MASTER_SSL_VERIFY_SERVER_CERT","MATCH","MAXVALUE","MEDIUMBLOB","MEDIUMINT","MEDIUMTEXT","MIDDLEINT","MINUTE_MICROSECOND","MINUTE_SECOND","MOD","MODIFIES","NATIONAL","NATURAL","NO","NOCHECK","NONCLUSTERED","NOT","NO_WRITE_TO_BINLOG","NULL","NULLIF","NUMERIC","OF","OFF","OFFSETS","ON","OPEN","OPENDATASOURCE","OPENQUERY","OPENROWSET","OPENXML","OPTIMIZE","OPTION","OPTIONALLY","OR","ORDER","OUT","OUTER","OUTFILE","OVER","PERCENT","PLAN","PRECISION","PRIMARY","PRINT","PROC","PROCEDURE","PUBLIC","PURGE","RAISERROR","RANGE","READ","READS","READTEXT","READ_WRITE","REAL","RECONFIGURE","REFERENCES","REGEXP","RELEASE","RENAME","REPEAT","REPLACE", + "REPLICATION","REQUIRE","RESIGNAL","RESTORE","RESTRICT","RETURN","REVOKE","RIGHT","RLIKE","ROLLBACK","ROWCOUNT","ROWGUIDCOL","RULE","SAVE","SCHEMA","SCHEMAS","SECOND_MICROSECOND","SELECT","SENSITIVE","SEPARATOR","SESSION_USER","SET","SETUSER","SHOW","SHUTDOWN","SIGNAL","SLOW","SMALLINT","SOME","SPATIAL","SPECIFIC","SQL","SQLEXCEPTION","SQLSTATE","SQLWARNING","SQL_BIG_RESULT","SQL_CALC_FOUND_ROWS","SQL_SMALL_RESULT","SSL","STARTING","STATISTICS","STRAIGHT_JOIN","SYSTEM_USER","TABLE","TERMINATED","TEXT","TEXTSIZE","THEN","TIME","TIMESTAMP","TINYBLOB","TINYINT","TINYTEXT","TO","TOP","TRAILING","TRAN","TRANSACTION","TRIGGER","TRUE","TRUNCATE","TSEQUAL","UNDO","UNION","UNIQUE","UNLOCK","UNSIGNED","UPDATE","UPDATETEXT","USAGE","USE","USER","USING","UTC_DATE","UTC_TIME", + "UTC_TIMESTAMP","VALUES","VARBINARY","VARCHAR","VARCHARACTER","VARYING","VIEW","WAITFOR","WHEN","WHERE","WHILE","WITH","WRITE","WRITETEXT","XOR","YEAR_MONTH","ZEROFILL"); + return $reservedWordsSql; + } +} + +/** + * eprint + * + * @param string $s default value '' + * @param string $c default value null + * + * @return void + */ +function eprint ($s = "", $c = null) +{ + if (G::isHttpRequest()) { + if (isset( $c )) { + echo "
$s
"; + } else { + echo "
$s
"; + } + } else { + if (isset( $c )) { + switch ($c) { + case 'green': + printf( "\033[0;35;32m$s\033[0m" ); + return; + case 'red': + printf( "\033[0;35;31m$s\033[0m" ); + return; + case 'blue': + printf( "\033[0;35;34m$s\033[0m" ); + return; + default: + print "$s"; + } + } else { + print "$s"; + } + } +} + +/** + * println + * + * @param string $s + * + * @return eprintln($s) + */ +function println ($s) +{ + return eprintln( $s ); +} + +/** + * eprintln + * + * @param string $s + * @param string $c + * + * @return void + */ +function eprintln ($s = "", $c = null) +{ + if (G::isHttpRequest()) { + if (isset( $c )) { + echo "
$s
"; + } else { + echo "
$s
"; + } + } else { + if (isset( $c ) && (PHP_OS != 'WINNT')) { + switch ($c) { + case 'green': + printf( "\033[0;35;32m$s\033[0m\n" ); + return; + case 'red': + printf( "\033[0;35;31m$s\033[0m\n" ); + return; + case 'blue': + printf( "\033[0;35;34m$s\033[0m\n" ); + return; + } + } + print "$s\n"; + } +} + +function __ ($msgID, $lang = SYS_LANG, $data = null) +{ + return G::LoadTranslation( $msgID, $lang, $data ); } -/** - * eprint - * - * @param string $s default value '' - * @param string $c default value null - * - * @return void - */ -function eprint($s = "", $c = null){ - if( G::isHttpRequest() ){ - if(isset($c)){ - echo "
$s
"; - } else - echo "
$s
"; - } else { - if(isset($c)){ - switch($c){ - case 'green': - printf("\033[0;35;32m$s\033[0m"); - return; - case 'red': - printf("\033[0;35;31m$s\033[0m"); - return; - case 'blue': - printf("\033[0;35;34m$s\033[0m"); - return; - default: print "$s"; - } - } else - print "$s"; - } -} - -/** - * println - * - * @param string $s - * - * @return eprintln($s) - */ -function println($s){ - return eprintln($s); -} - -/** - * eprintln - * - * @param string $s - * @param string $c - * - * @return void - */ -function eprintln($s="", $c=null){ - if( G::isHttpRequest() ){ - if(isset($c)){ - echo "
$s
"; - } else - echo "
$s
"; - } else { - if(isset($c) && (PHP_OS != 'WINNT')){ - switch($c){ - case 'green': - printf("\033[0;35;32m$s\033[0m\n"); - return; - case 'red': - printf("\033[0;35;31m$s\033[0m\n"); - return; - case 'blue': - printf("\033[0;35;34m$s\033[0m\n"); - return; - } - } - print "$s\n"; - } - - -} - -function __($msgID , $lang = SYS_LANG, $data = null) -{ - return G::LoadTranslation($msgID, $lang, $data); -}