Index: trunk/globals.php =================================================================== diff -u -r25 -r314 --- trunk/globals.php (.../globals.php) (revision 25) +++ trunk/globals.php (.../globals.php) (revision 314) @@ -1,6 +1,6 @@ <?php -$vars = parse_ini_file($pathtoroot."config.php"); +$vars = parse_portal_ini($pathtoroot."config.php"); while($key = key($vars)) { @@ -16,8 +16,8 @@ $KeywordIgnore = array(); global $debuglevel; -$debuglevel=0; -$_GLOBALS["debuglevel"]=0; +$debuglevel = 0; +//$GLOBALS['debuglevel'] = 0; /*New, Hot, Pop field values */ define('NEVER', 0); @@ -32,14 +32,67 @@ $LogLevel=0; $LogFile = NULL; + +function parse_portal_ini($file, $parse_section = false) { + if(!file_exists($file) && !is_readable($file)) + die('Could Not Open Ini File'); + + $contents = file($file); + + $retval = array(); + + $section = ''; + $ln = 1; + $resave = false; + foreach($contents as $line) { + if ($ln == 1 && $line != '<'.'?'.'php die() ?'.">\n") { + $resave = true; + } + $ln++; + $line = trim($line); + $line = eregi_replace(';[.]*','',$line); + if(strlen($line) > 0) { + //echo $line . " - "; + if(eregi('^[[a-z]+]$',str_replace(' ', '', $line))) { + //echo 'section'; + $section = substr($line,1,(strlen($line)-2)); + if ($parse_section) { + $retval[$section] = array(); + } + continue; + } elseif(eregi('=',$line)) { + //echo 'main element'; + list($key,$val) = explode(' = ',$line); + if (!$parse_section) { + $retval[trim($key)] = str_replace('"', '', $val); + } + else { + $retval[$section][trim($key)] = str_replace('"', '', $val); + } + } //end if + //echo '<br />'; + } //end if + } //end foreach + if ($resave) { + $fp = fopen($file, "w"); + reset($contents); + fwrite($fp,'<'.'?'.'php die() ?'.">\n\n"); + foreach($contents as $line) fwrite($fp,"$line"); + fclose($fp); + } + + return $retval; +} + function &GetADODBConnection() { global $g_adodbConnection, $g_DBType, $g_DBHost,$g_DBUser,$g_DBUserPassword,$g_DBName,$g_DebugMode; global $ADODB_FETCH_MODE,$ADODB_COUNTRECS,$ADODB_CACHE_DIR,$pathtoroot; - + //echo '<pre>'.print_r( debug_backtrace() , true).'</pre>'; if(!isset($g_adodbConnection) && strlen($g_DBType)>0) { $g_adodbConnection = ADONewConnection($g_DBType); + $connected = $g_adodbConnection->Connect($g_DBHost,$g_DBUser,$g_DBUserPassword,$g_DBName); if(!$connected) { @@ -49,8 +102,9 @@ $ADODB_CACHE_DIR = $pathtoroot."cache"; $ADODB_FETCH_MODE = 2; $ADODB_COUNTRECS = FALSE; - $g_adodbConnection->debug = false; + $g_adodbConnection->debug = defined('ADODB_OUTP') ? 1 : 0; $g_adodbConnection->cacheSecs = 3600; + $g_adodbConnection->Execute('SET SQL_BIG_SELECTS=1'); } elseif (!strlen($g_DBType)) { global $rootURL; @@ -134,6 +188,7 @@ $sql = "SELECT count(*) as TableCount FROM $TableName INNER JOIN ".GetTablePrefix()."CategoryItems ON ".GetTablePrefix()."CategoryItems.ItemResourceId=$TableName.ResourceId"; if(strlen($where)>0) $sql .= " WHERE ".$where; + $rs = $db->Execute($sql); // echo "SQL TABLE COUNT: ".$sql."<br>\n"; @@ -590,8 +645,7 @@ $found = FALSE; if(is_array($_FILES)) { - if($_FILES[$r]["size"]>0) - $found=TRUE; + if( isset($_FILES[$r]) && $_FILES[$r]['size'] > 0 ) $found = TRUE; } if(!strlen(trim($_POST[$r])) && !$found) @@ -601,7 +655,7 @@ if (($r == "dob_day") || ($r == "dob_month") || ($r == "dob_year")) $r = "dob"; - $tag = $_POST["errors"][$r]; + $tag = isset($_POST["errors"]) ? $_POST["errors"][$r] : ''; if(!strlen($tag)) $tag = "lu_ferror_".$f."_".$r; $FormError[$f][$r] = language($tag); @@ -830,23 +884,19 @@ { global $objCountCache, $objItemTypes; - if(is_numeric($ItemName)) - { - $item = $objItemTypes->GetItem($ItemName); - } - else - $item = $objItemTypes->GetTypeByName($ItemName); - if(is_object($item)) - { - $ItemType = $item->Get("ItemType"); + if(is_numeric($ItemTypeName)) + $item = $objItemTypes->GetItem($ItemTypeName); + else + $item = $objItemTypes->GetTypeByName($ItemTypeName); + + if(is_object($item)) + { + $ItemType = $item->Get("ItemType"); - $sql = "DELETE FROM ".$objCountCache->SourceTable." WHERE ItemType=$ItemType"; - if(is_numeric($ListType)) - { - $sql .= " AND ListType=$ListType"; - } - $objCountCache->adodbConnection->Execute($sql); - } + $sql = "DELETE FROM ".$objCountCache->SourceTable." WHERE ItemType=$ItemType"; + if( is_numeric($ListType) ) $sql .= " AND ListType=$ListType"; + $objCountCache->adodbConnection->Execute($sql); + } } function UpdateModifiedCategoryCount($ItemTypeName,$CatId=NULL,$Modifier=0,$ExtraId=NULL) @@ -883,7 +933,7 @@ global $objSystemCache, $objSession, $objConfig; if($objConfig->Get("SystemTagCache")) - { + { $name = $tag; if(is_array($attribs)) { @@ -1103,7 +1153,8 @@ function ResetPage($module_prefix, $page_variable = 'p') { // resets page in specific module when category is changed - if(!is_object($objSession)) // when changing pages session doesn't exist -> InPortal BUG + global $objSession; + if( !is_object($objSession) ) // when changing pages session doesn't exist -> InPortal BUG { global $var_list, $SessionQueryString, $FrontEnd; //if(!$var_list["sid"]) $var_list["sid"] = $_COOKIE["sid"]; @@ -1117,9 +1168,15 @@ if($prev_cat != $last_cat) $GLOBALS[$module_prefix.'_var_list'][$page_variable] = 1; } -function GetVar($name) +if( !function_exists('GetVar') ) { - return isset($_REQUEST[$name]) ? $_REQUEST[$name] : false; + function GetVar($name, $post_priority = false) + { + if(!$post_priority) // follow gpc_order in php.ini + return isset($_REQUEST[$name]) ? $_REQUEST[$name] : false; + else // get variable from post 1stly if not found then from get + return isset($_POST[$name]) && $_POST[$name] ? $_POST[$name] : ( isset($_GET[$name]) && $_GET[$name] ? $_GET[$name] : false ); + } } function PassVar(&$source) @@ -1268,4 +1325,77 @@ return count($result) ? implode(' ', $result) : false; } +function GetImportScripts() +{ + // return currently installed import scripts + static $import_scripts = Array(); + if( count($import_scripts) == 0 ) + { + $sql = 'SELECT * FROM '.GetTablePrefix().'ImportScripts ORDER BY is_id'; + $db =& GetADODBConnection(); + $rs = $db->Execute($sql); + while(!$rs->EOF) + { + $rec =& $rs->fields; + $import_scripts[] = Array( 'label' => $rec['is_label'], 'url' => $rec['is_script'], + 'enabled' => $rec['is_enabled'], 'field_prefix' => $rec['is_field_prefix'], + 'id' => $rec['is_string_id'], 'required_fields' => $rec['is_requred_fields']); + $rs->MoveNext(); + } + } + return $import_scripts; +} + +function GetImportScript($id) +{ + $scripts = GetImportScripts(); + return isset($scripts[$id]) ? $scripts[$id] : false; +} +function GetNextTemplate($current_template) +{ + // used on front, returns next template to make + // redirect to + $dest = GetVar('dest', true); + if(!$dest) $dest = GetVar('DestTemplate', true); + return $dest ? $dest : $current_template; +} + + +// functions for dealign with enviroment variable construction +function GenerateModuleEnv($prefix, $var_list) +{ + // globalize module varible arrays + $main =& $GLOBALS[$prefix.'_var_list']; + $update =& $GLOBALS[$prefix.'_var_list_update']; + + //echo "VAR: [$main]; VAR_UPDATE: [$update]<br>"; + + // enshure that we have no empty values in enviroment variable + foreach($update as $vl_key => $vl_value) + if(!$vl_value) $update[$vl_key] = '0'; // unset($update[$vl_key]); + + // if update var count is zero, then do nothing + if(count($update) == 0) return ''; + + foreach($main as $vl_key => $vl_value) + if(!$vl_value) $main[$vl_key] = '0'; // unset($main[$vl_key]); + + $ret = Array(); + foreach($var_list as $var_name) + $ret[] = GetEnvVar($prefix, $var_name); + + return ':'.$prefix.implode('-',$ret); +} + +function GetEnvVar($prefix, $name) +{ + // get variable from template variable's list + // (used in module parsers to build env string) + $main =& $GLOBALS[$prefix.'_var_list']; + $update =& $GLOBALS[$prefix.'_var_list_update']; + return isset($update[$name]) ? $update[$name] : ( isset($main[$name]) ? $main[$name] : ''); +} + + + ?>