Index: trunk/admin/install/install_lib.php =================================================================== diff -u -r1566 -r1591 --- trunk/admin/install/install_lib.php (.../install_lib.php) (revision 1566) +++ trunk/admin/install/install_lib.php (.../install_lib.php) (revision 1591) @@ -1,825 +1,825 @@ -read()) { - if ($file != "." && $file != ".." && !is_dir($admindirname.$file)) { - if (strstr($file, 'inportal_upgrade_v')) { - $upgrades_arr[] = $file; - } - } - } - - usort($upgrades_arr, "VersionSort"); - - foreach($upgrades_arr as $file) { - $file_tmp = str_replace("inportal_upgrade_v", "", $file); - $file_tmp = str_replace(".sql", "", $file_tmp); - - if (ConvertVersion($file_tmp) > ConvertVersion($version)) { - $version = $file_tmp; - } - } - - return $version; -} - -function ConvertVersion($version) -{ - $parts = explode('.', $version); - - $bin = ''; - foreach ($parts as $part) { - $bin .= str_pad(decbin($part), 8, '0', STR_PAD_LEFT); - } - - $dec = bindec($bin); - - return $dec; -} - -function TableExists(&$ado, $tables) -{ - global $g_TablePrefix; - - $t = explode(",",$tables); - - $i = $ado->MetaTables(); - for($x=0;$x\n\n"); - foreach($ini_vars as $secname => $section) - { - fwrite($fp,"[".$secname."]\n"); - foreach($section as $key => $value) fwrite($fp,"$key = \"$value\"\n"); - fwrite($fp,"\n"); - } - fclose($fp); - //} -} - -function getConnectionInterface($action, $dbo_type='adodb') -{ - if($dbo_type == 'adodb') - { - switch($action) - { - case 'query': return 'Execute'; break; - case 'errorno': return 'ErrorNo'; break; - case 'errormsg': return 'ErrorMsg'; break; - } - } - - if($dbo_type == 'dbconnection') - { - switch($action) - { - case 'query': return 'Query'; break; - case 'errorno': return 'getErrorCode'; break; - case 'errormsg': return 'getErrorMsg'; break; - } - - } -} - -function RunSchemaFile(&$ado, $filename, $dbo_type='adodb') -{ - if( file_exists($filename) ) - { - $sql = file_get_contents($filename); - if($sql) RunSchemaText($ado,$sql,$dbo_type); - } -} - -function RunSchemaText(&$ado, $sql, $dbo_type='adodb') -{ - global $g_TablePrefix; - - if(strlen($g_TablePrefix)) - { - $what = "CREATE TABLE "; - $replace = "CREATE TABLE ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - - $what = "DROP TABLE "; - $replace = "DROP TABLE IF EXISTS ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - - $what = "INSERT INTO "; - $replace = "INSERT INTO ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - - $what = "UPDATE "; - $replace = "UPDATE ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - - $what = "ALTER TABLE "; - $replace = "ALTER TABLE ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - } - - $commands = explode("# --------------------------------------------------------",$sql); - if(count($commands)>0) - { - $query_func = getConnectionInterface('query',$dbo_type); - $errorno_func = getConnectionInterface('errorno',$dbo_type); - $errormsg_func = getConnectionInterface('errormsg',$dbo_type); - - for($i = 0; $i < count($commands); $i++) - { - $cmd = $commands[$i]; - $cmd = trim($cmd); - if(strlen($cmd)>0) - { - $ado->$query_func($cmd); - if($ado->$errorno_func() != 0) - { - $db_error = $ado->$errormsg_func()." COMMAND:
$cmd
"; - } - } - } - } -} - -function RunSQLText(&$ado, $allsql, $dbo_type='adodb') -{ - global $g_TablePrefix; - - $line = 0; - $query_func = getConnectionInterface('query',$dbo_type); - $errorno_func = getConnectionInterface('errorno',$dbo_type); - $errormsg_func = getConnectionInterface('errormsg',$dbo_type); - - while($line0 && substr($sql,0,1)!="#") - { - if(strlen($g_TablePrefix)) - { - $what = "CREATE TABLE "; - $replace = "CREATE TABLE ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - - $what = "DELETE FROM "; - $replace = "DELETE FROM ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - - $what = "DROP TABLE "; - $replace = "DROP TABLE IF EXISTS ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - - $what = "DROP TABLE IF EXISTS "; - $replace = "DROP TABLE IF EXISTS ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - - $what = "INSERT INTO "; - $replace = "INSERT INTO ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - - $what = "UPDATE "; - $replace = "UPDATE ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - - $what = "ALTER TABLE "; - $replace = "ALTER TABLE ".$g_TablePrefix; - $sql = ereg_replace($what, $replace, $sql); - } - $sql = trim($sql); - if(strlen($sql)>0) - { - $ado->$query_func($sql); - if($ado->$errorno_func()!=0) - { - $db_error = $ado->$errormsg_func()." COMMAND:
$sql
"; - $error = TRUE; - } - } - } - $line++; - } -} - -function RunSQLFile(&$ado, $filename, $dbo_type='adodb') -{ - if(file_exists($filename)) - { - $allsql = file($filename); - RunSQLText($ado,$allsql,$dbo_type); - } -} - -function RunRestoreFile($ado,$filename,$FileOffset,$MaxLines) -{ - $size = filesize($filename); - - if($FileOffset > $size) - return -2; - - $fp = fopen($filename,"r"); - if(!$fp) - return -1; - - if($FileOffset>0) - { - fseek($fp,$FileOffset); - } - else - { - $EndOfSQL = FALSE; - $sql = ""; - while(!feof($fp) && !$EndOfSQL) - { - $l = fgets($fp,16384); - if(substr($l,0,11)=="INSERT INTO") - { - $EndOfSQL = TRUE; - } - else - { - $sql .= $l; - $FileOffset = ftell($fp) - strlen($l); - } - } - if(strlen($sql)) - { - RunSchemaText($ado,$sql); - } - fseek($fp,$FileOffset); - } - $LinesRead = 0; - $sql = ""; - $AllSql = array(); - while($LinesRead < $MaxLines && !feof($fp)) - { - $sql = fgets($fp, 16384); - if(strlen($sql)) - { - $AllSql[] = $sql; - $LinesRead++; - } - } - if(!feof($fp)) - { - $FileOffset = ftell($fp); - } - else - { - $FileOffset = $TotalSize; - } - fclose($fp); - if(count($AllSql)>0) - RunSQLText($ado,$AllSql); - return (int)$FileOffset; -} - - -function _inst_keyED($txt,$encrypt_key) -{ - $encrypt_key = md5($encrypt_key); - $ctr=0; - $tmp = ""; - for ($i=0;$i= 5 && $i < 7) return _inst_GetObscureValue($z)*_inst_GetObscureValue('e'); - if ($i > 30) return Array(0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74); - if ($i > 20) return 99; - if ($i > 10) return '.'.(_inst_GetObscureValue(6.5)+1); - if ($i == 'a') return 0xa; -} - -function _inst_Chr($val) -{ - $x = _inst_GetObscureValue(25); - $f = chr($x).chr($x+5).chr($x+15); - return $f($val); -} - -function _inst_IsLocalSite($domain) -{ - $ee = _inst_GetObscureValue(35); - foreach ($ee as $e) { - $yy .= _inst_Chr($e); - } - $localb = FALSE; - if(substr($domain,0,3)==_inst_GetObscureValue('x')) - { - $b = substr($domain,0,6); - $p = explode(".",$domain); - $subnet = $p[1]; - if($p[1]>15 && $p[1]<32) - $localb=TRUE; - } - $zz = _inst_GetObscureValue('z')._inst_GetObscureValue(5).'.'.(int)_inst_GetObscureValue(7)._inst_GetObscureValue(12); - $ff = _inst_GetObscureValue('z')+65; - $hh = $ff-0x18; - if($domain==$yy || $domain==$zz || substr($domain,0,7)==$ff._inst_Chr(46).$hh || - substr($domain,0,3)==_inst_GetObscureValue('a')._inst_Chr(46) || $localb || strpos($domain,".")==0) - { - return TRUE; - } - return FALSE; -} - -function _inst_falseIsLocalSite($domain) -{ - $localb = FALSE; - if(substr($domain,0,3)=="172" || $domain == '##code##') - { - $b = substr($domain,0,6); - $p = explode(".",$domain); - $subnet = $p[1]; - if($p[1]>15 && $p[1]<32) - $localb=TRUE; - } - if($domain=="localhost" || $domain=="127.0.0.1" || substr($domain,0,7)=="192.168" || - substr($domain,0,3)=="10." || $localb || strpos($domain,".")==0) - { - return TRUE; - } - return FALSE; -} - -function ed592fe427e1ce60e32ffcb0c82d8557($name) -{ - return _inst_ModuleLicensed($name); -} - -function _inst_ModuleLicensed($name) -{ - global $i_Keys, $objConfig, $g_License, $g_Domain; - - $lic = base64_decode($g_License); - _inst_ParseLicense($lic); - - $modules = array(); - if(!_inst_IsLocalSite($g_Domain)) - { - for($x=0;$x\n") { - $resave = true; - } - $ln++; - $line = trim($line); - $line = eregi_replace(';[.]*','',$line); - if(strlen($line) > 0) { - if(eregi('^[[a-z]+]$',str_replace(' ', '', $line))) { - $section = substr($line,1,(strlen($line)-2)); - if ($parse_section) { - $retval[$section] = array(); - } - continue; - } elseif(eregi('=',$line)) { - list($key,$val) = explode(' = ',$line); - if (!$parse_section) { - $retval[trim($key)] = str_replace('"', '', $val); - } - else { - $retval[$section][trim($key)] = str_replace('"', '', $val); - } - } //end if - } //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 a48d819089308a9aeb447e7248b2587f() -{ - return _inst_GetModuleList(); -} - -function _inst_GetModuleList() -{ - global $rootpath,$pathchar,$admin, $pathtoroot; - - $path = $pathtoroot; - - $new = array(); - if ($dir = @opendir($path)) - { - while (($file = readdir($dir)) !== false) - { - if($file !="." && $file !=".." && substr($file,0,1)!="_") - { - if(is_dir($path."/".$file)) - { - $ModuleAdminDir = $path.$file.'/admin/'; - $inst_file = $ModuleAdminDir.'install.php'; - if( file_exists($inst_file) && file_exists($ModuleAdminDir.'install/inportal_schema.sql') ) - { - if(_inst_ModuleLicensed($file)) { - $new[$file] = $inst_file; - } - } - } - } - } - closedir($dir); - } - return array_keys($new); -} - -function GetDirList ($dirName) -{ - - $filedates = array(); - $d = dir($dirName); - - while($entry = $d->read()) - { - if ($entry != "." && $entry != "..") - { - if (!is_dir($dirName."/".$entry)) - { - $filedate[]=$entry; - } - } - } - $d->close(); - return $filedate; -} - -function GetLanguageList() -{ - global $pathtoroot, $admin; - - $packs = array(); - $dir = $pathtoroot.$admin."/install/langpacks"; - $files = GetDirList($dir); - - if(is_array($files)) - { - foreach($files as $f) - { - $p = pathinfo($f); - if($p["extension"]=="lang") - { - $packs[] = $f; - } - } - } - return $packs; -} - -function section_header($title, $return_result = false) -{ - $ret = ''. - '
 '.$title.''. - ''. - "". - '
'; - if( $return_result ) - return $ret; - else - echo $ret; -} - -function &VerifyDB($error_state, $next_state, $success_func = null, $db_must_exist = false) -{ - // perform various check type to database specified - // 1. user is allowed to connect to database - // 2. user has all types of permissions in database - global $state, $db_error; - - // enshure we use data from post & not from config - $GLOBALS['g_DBType'] = $_POST["ServerType"]; - $GLOBALS['g_DBHost'] = $_POST["ServerHost"]; - $GLOBALS['g_DBName'] = $_POST["ServerDB"]; - $GLOBALS['g_DBUser'] = $_POST["ServerUser"]; - $GLOBALS['g_DBUserPassword'] = $_POST["ServerPass"]; - - // connect to database - $ado =& inst_GetADODBConnection(); - if($ado->ErrorNo() != 0) - { - // was error while connecting - $db_error = "Connection Error: (".$ado->ErrorNo().") ".$ado->ErrorMsg(); - $state = $error_state; - - } - elseif( $ado->ErrorNo() == 0 ) - { - // if connected, then check if all sql statements work - $test_result = 1; - - $sql_tests[] = 'DROP TABLE IF EXISTS test_table'; - $sql_tests[] = 'CREATE TABLE test_table(test_col mediumint(6))'; - $sql_tests[] = 'INSERT INTO test_table(test_col) VALUES (5)'; - $sql_tests[] = 'UPDATE test_table SET test_col = 12'; - $sql_tests[] = 'ALTER TABLE test_table ADD COLUMN new_col varchar(10)'; - $sql_tests[] = 'SELECT * FROM test_table'; - $sql_tests[] = 'DELETE FROM test_table'; - $sql_tests[] = 'DROP TABLE IF EXISTS test_table'; - - foreach($sql_tests as $sql_test) - { - $ado->Execute($sql_test); - if( $ado->ErrorNo()!=0 ) - { - $test_result = 0; - break; - } - } - - if($test_result == 1) - { - // if statements work & connection made, then check table existance - $db_exists = TableExists($ado,"ConfigurationAdmin,Category,Permissions"); - if($db_exists != $db_must_exist) - { - $state = $error_state; - $db_error = $db_must_exist ? 'An In-Portal Database already exists at this location' : 'An In-Portal Database was not found at this location'; - } - else - { - $state = $next_state; - if( isset($success_func) ) $success_func(); - } - } - else - { - // user has insufficient permissions in database specified - $db_error = "Permission Error: (".$ado->ErrorNo().") ".$ado->ErrorMsg(); - $state = $error_state; - } - } - return $ado; -} - -function SaveDBConfig() -{ - // save new database configuration - set_ini_value("Database", "DBType",$_POST["ServerType"]); - set_ini_value("Database", "DBHost",$_POST["ServerHost"]); - set_ini_value("Database", "DBName",$_POST["ServerDB"]); - set_ini_value("Database", "DBUser",$_POST["ServerUser"]); - set_ini_value("Database", "DBUserPassword",$_POST["ServerPass"]); - set_ini_value("Database","TablePrefix",$_POST["TablePrefix"]); - save_values(); - $GLOBALS['include_file'] = 'install/install_finish.php'; -} - -function ReSetVar($var) -{ - // define varible if not defined before - if( !isset($GLOBALS[$var]) ) $GLOBALS[$var] = ''; -} - -// if globals.php not yet included (1st steps of install), -// then define GetVar function -if( !function_exists('GetVar') ) -{ - 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 RadioChecked($name, $value) -{ - // return " checked" word in case if radio is checked - $submit_value = GetVar($name); - return $submit_value == $value ? ' checked' : ''; -} - -?> +read()) { + if ($file != "." && $file != ".." && !is_dir($admindirname.$file)) { + if (strstr($file, 'inportal_upgrade_v')) { + $upgrades_arr[] = $file; + } + } + } + + usort($upgrades_arr, "VersionSort"); + + foreach($upgrades_arr as $file) { + $file_tmp = str_replace("inportal_upgrade_v", "", $file); + $file_tmp = str_replace(".sql", "", $file_tmp); + + if (ConvertVersion($file_tmp) > ConvertVersion($version)) { + $version = $file_tmp; + } + } + + return $version; +} + +function ConvertVersion($version) +{ + $parts = explode('.', $version); + + $bin = ''; + foreach ($parts as $part) { + $bin .= str_pad(decbin($part), 8, '0', STR_PAD_LEFT); + } + + $dec = bindec($bin); + + return $dec; +} + +function TableExists(&$ado, $tables) +{ + global $g_TablePrefix; + + $t = explode(",",$tables); + + $i = $ado->MetaTables(); + for($x=0;$x\n\n"); + foreach($ini_vars as $secname => $section) + { + fwrite($fp,"[".$secname."]\n"); + foreach($section as $key => $value) fwrite($fp,"$key = \"$value\"\n"); + fwrite($fp,"\n"); + } + fclose($fp); + //} +} + +function getConnectionInterface($action, $dbo_type='adodb') +{ + if($dbo_type == 'adodb') + { + switch($action) + { + case 'query': return 'Execute'; break; + case 'errorno': return 'ErrorNo'; break; + case 'errormsg': return 'ErrorMsg'; break; + } + } + + if($dbo_type == 'dbconnection') + { + switch($action) + { + case 'query': return 'Query'; break; + case 'errorno': return 'getErrorCode'; break; + case 'errormsg': return 'getErrorMsg'; break; + } + + } +} + +function RunSchemaFile(&$ado, $filename, $dbo_type='adodb') +{ + if( file_exists($filename) ) + { + $sql = file_get_contents($filename); + if($sql) RunSchemaText($ado,$sql,$dbo_type); + } +} + +function RunSchemaText(&$ado, $sql, $dbo_type='adodb') +{ + global $g_TablePrefix; + + if(strlen($g_TablePrefix)) + { + $what = "CREATE TABLE "; + $replace = "CREATE TABLE ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + + $what = "DROP TABLE "; + $replace = "DROP TABLE IF EXISTS ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + + $what = "INSERT INTO "; + $replace = "INSERT INTO ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + + $what = "UPDATE "; + $replace = "UPDATE ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + + $what = "ALTER TABLE "; + $replace = "ALTER TABLE ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + } + + $commands = explode("# --------------------------------------------------------",$sql); + if(count($commands)>0) + { + $query_func = getConnectionInterface('query',$dbo_type); + $errorno_func = getConnectionInterface('errorno',$dbo_type); + $errormsg_func = getConnectionInterface('errormsg',$dbo_type); + + for($i = 0; $i < count($commands); $i++) + { + $cmd = $commands[$i]; + $cmd = trim($cmd); + if(strlen($cmd)>0) + { + $ado->$query_func($cmd); + if($ado->$errorno_func() != 0) + { + $db_error = $ado->$errormsg_func()." COMMAND:
$cmd
"; + } + } + } + } +} + +function RunSQLText(&$ado, $allsql, $dbo_type='adodb') +{ + global $g_TablePrefix; + + $line = 0; + $query_func = getConnectionInterface('query',$dbo_type); + $errorno_func = getConnectionInterface('errorno',$dbo_type); + $errormsg_func = getConnectionInterface('errormsg',$dbo_type); + + while($line0 && substr($sql,0,1)!="#") + { + if(strlen($g_TablePrefix)) + { + $what = "CREATE TABLE "; + $replace = "CREATE TABLE ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + + $what = "DELETE FROM "; + $replace = "DELETE FROM ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + + $what = "DROP TABLE "; + $replace = "DROP TABLE IF EXISTS ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + + $what = "DROP TABLE IF EXISTS "; + $replace = "DROP TABLE IF EXISTS ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + + $what = "INSERT INTO "; + $replace = "INSERT INTO ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + + $what = "UPDATE "; + $replace = "UPDATE ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + + $what = "ALTER TABLE "; + $replace = "ALTER TABLE ".$g_TablePrefix; + $sql = ereg_replace($what, $replace, $sql); + } + $sql = trim($sql); + if(strlen($sql)>0) + { + $ado->$query_func($sql); + if($ado->$errorno_func()!=0) + { + $db_error = $ado->$errormsg_func()." COMMAND:
$sql
"; + $error = TRUE; + } + } + } + $line++; + } +} + +function RunSQLFile(&$ado, $filename, $dbo_type='adodb') +{ + if(file_exists($filename)) + { + $allsql = file($filename); + RunSQLText($ado,$allsql,$dbo_type); + } +} + +function RunRestoreFile($ado,$filename,$FileOffset,$MaxLines) +{ + $size = filesize($filename); + + if($FileOffset > $size) + return -2; + + $fp = fopen($filename,"r"); + if(!$fp) + return -1; + + if($FileOffset>0) + { + fseek($fp,$FileOffset); + } + else + { + $EndOfSQL = FALSE; + $sql = ""; + while(!feof($fp) && !$EndOfSQL) + { + $l = fgets($fp,16384); + if(substr($l,0,11)=="INSERT INTO") + { + $EndOfSQL = TRUE; + } + else + { + $sql .= $l; + $FileOffset = ftell($fp) - strlen($l); + } + } + if(strlen($sql)) + { + RunSchemaText($ado,$sql); + } + fseek($fp,$FileOffset); + } + $LinesRead = 0; + $sql = ""; + $AllSql = array(); + while($LinesRead < $MaxLines && !feof($fp)) + { + $sql = fgets($fp, 16384); + if(strlen($sql)) + { + $AllSql[] = $sql; + $LinesRead++; + } + } + if(!feof($fp)) + { + $FileOffset = ftell($fp); + } + else + { + $FileOffset = $TotalSize; + } + fclose($fp); + if(count($AllSql)>0) + RunSQLText($ado,$AllSql); + return (int)$FileOffset; +} + + +function _inst_keyED($txt,$encrypt_key) +{ + $encrypt_key = md5($encrypt_key); + $ctr=0; + $tmp = ""; + for ($i=0;$i= 5 && $i < 7) return _inst_GetObscureValue($z)*_inst_GetObscureValue('e'); + if ($i > 30) return Array(0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74); + if ($i > 20) return 99; + if ($i > 10) return '.'.(_inst_GetObscureValue(6.5)+1); + if ($i == 'a') return 0xa; +} + +function _inst_Chr($val) +{ + $x = _inst_GetObscureValue(25); + $f = chr($x).chr($x+5).chr($x+15); + return $f($val); +} + +function _inst_IsLocalSite($domain) +{ + $ee = _inst_GetObscureValue(35); + foreach ($ee as $e) { + $yy .= _inst_Chr($e); + } + $localb = FALSE; + if(substr($domain,0,3)==_inst_GetObscureValue('x')) + { + $b = substr($domain,0,6); + $p = explode(".",$domain); + $subnet = $p[1]; + if($p[1]>15 && $p[1]<32) + $localb=TRUE; + } + $zz = _inst_GetObscureValue('z')._inst_GetObscureValue(5).'.'.(int)_inst_GetObscureValue(7)._inst_GetObscureValue(12); + $ff = _inst_GetObscureValue('z')+65; + $hh = $ff-0x18; + if($domain==$yy || $domain==$zz || substr($domain,0,7)==$ff._inst_Chr(46).$hh || + substr($domain,0,3)==_inst_GetObscureValue('a')._inst_Chr(46) || $localb || strpos($domain,".")==0) + { + return TRUE; + } + return FALSE; +} + +function _inst_falseIsLocalSite($domain) +{ + $localb = FALSE; + if(substr($domain,0,3)=="172" || $domain == '##code##') + { + $b = substr($domain,0,6); + $p = explode(".",$domain); + $subnet = $p[1]; + if($p[1]>15 && $p[1]<32) + $localb=TRUE; + } + if($domain=="localhost" || $domain=="127.0.0.1" || substr($domain,0,7)=="192.168" || + substr($domain,0,3)=="10." || $localb || strpos($domain,".")==0) + { + return TRUE; + } + return FALSE; +} + +function ed592fe427e1ce60e32ffcb0c82d8557($name) +{ + return _inst_ModuleLicensed($name); +} + +function _inst_ModuleLicensed($name) +{ + global $i_Keys, $objConfig, $g_License, $g_Domain; + + $lic = base64_decode($g_License); + _inst_ParseLicense($lic); + + $modules = array(); + if(!_inst_IsLocalSite($g_Domain)) + { + for($x=0;$x\n") { + $resave = true; + } + $ln++; + $line = trim($line); + $line = eregi_replace(';[.]*','',$line); + if(strlen($line) > 0) { + if(eregi('^[[a-z]+]$',str_replace(' ', '', $line))) { + $section = substr($line,1,(strlen($line)-2)); + if ($parse_section) { + $retval[$section] = array(); + } + continue; + } elseif(eregi('=',$line)) { + list($key,$val) = explode(' = ',$line); + if (!$parse_section) { + $retval[trim($key)] = str_replace('"', '', $val); + } + else { + $retval[$section][trim($key)] = str_replace('"', '', $val); + } + } //end if + } //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 a48d819089308a9aeb447e7248b2587f() +{ + return _inst_GetModuleList(); +} + +function _inst_GetModuleList() +{ + global $rootpath,$pathchar,$admin, $pathtoroot; + + $path = $pathtoroot; + + $new = array(); + if ($dir = @opendir($path)) + { + while (($file = readdir($dir)) !== false) + { + if($file !="." && $file !=".." && substr($file,0,1)!="_") + { + if(is_dir($path."/".$file)) + { + $ModuleAdminDir = $path.$file.'/admin/'; + $inst_file = $ModuleAdminDir.'install.php'; + if( file_exists($inst_file) && file_exists($ModuleAdminDir.'install/inportal_schema.sql') ) + { + if(_inst_ModuleLicensed($file)) { + $new[$file] = $inst_file; + } + } + } + } + } + closedir($dir); + } + return array_keys($new); +} + +function GetDirList ($dirName) +{ + + $filedates = array(); + $d = dir($dirName); + + while($entry = $d->read()) + { + if ($entry != "." && $entry != "..") + { + if (!is_dir($dirName."/".$entry)) + { + $filedate[]=$entry; + } + } + } + $d->close(); + return $filedate; +} + +function GetLanguageList() +{ + global $pathtoroot, $admin; + + $packs = array(); + $dir = $pathtoroot.$admin."/install/langpacks"; + $files = GetDirList($dir); + + if(is_array($files)) + { + foreach($files as $f) + { + $p = pathinfo($f); + if($p["extension"]=="lang") + { + $packs[] = $f; + } + } + } + return $packs; +} + +function section_header($title, $return_result = false) +{ + $ret = ''. + '
 '.$title.''. + ''. + "". + '
'; + if( $return_result ) + return $ret; + else + echo $ret; +} + +function &VerifyDB($error_state, $next_state, $success_func = null, $db_must_exist = false) +{ + // perform various check type to database specified + // 1. user is allowed to connect to database + // 2. user has all types of permissions in database + global $state, $db_error; + + // enshure we use data from post & not from config + $GLOBALS['g_DBType'] = $_POST["ServerType"]; + $GLOBALS['g_DBHost'] = $_POST["ServerHost"]; + $GLOBALS['g_DBName'] = $_POST["ServerDB"]; + $GLOBALS['g_DBUser'] = $_POST["ServerUser"]; + $GLOBALS['g_DBUserPassword'] = $_POST["ServerPass"]; + + // connect to database + $ado =& inst_GetADODBConnection(); + if($ado->ErrorNo() != 0) + { + // was error while connecting + $db_error = "Connection Error: (".$ado->ErrorNo().") ".$ado->ErrorMsg(); + $state = $error_state; + + } + elseif( $ado->ErrorNo() == 0 ) + { + // if connected, then check if all sql statements work + $test_result = 1; + + $sql_tests[] = 'DROP TABLE IF EXISTS test_table'; + $sql_tests[] = 'CREATE TABLE test_table(test_col mediumint(6))'; + $sql_tests[] = 'INSERT INTO test_table(test_col) VALUES (5)'; + $sql_tests[] = 'UPDATE test_table SET test_col = 12'; + $sql_tests[] = 'ALTER TABLE test_table ADD COLUMN new_col varchar(10)'; + $sql_tests[] = 'SELECT * FROM test_table'; + $sql_tests[] = 'DELETE FROM test_table'; + $sql_tests[] = 'DROP TABLE IF EXISTS test_table'; + + foreach($sql_tests as $sql_test) + { + $ado->Execute($sql_test); + if( $ado->ErrorNo()!=0 ) + { + $test_result = 0; + break; + } + } + + if($test_result == 1) + { + // if statements work & connection made, then check table existance + $db_exists = TableExists($ado,"ConfigurationAdmin,Category,Permissions"); + if($db_exists != $db_must_exist) + { + $state = $error_state; + $db_error = $db_must_exist ? 'An In-Portal Database already exists at this location' : 'An In-Portal Database was not found at this location'; + } + else + { + $state = $next_state; + if( isset($success_func) ) $success_func(); + } + } + else + { + // user has insufficient permissions in database specified + $db_error = "Permission Error: (".$ado->ErrorNo().") ".$ado->ErrorMsg(); + $state = $error_state; + } + } + return $ado; +} + +function SaveDBConfig() +{ + // save new database configuration + set_ini_value("Database", "DBType",$_POST["ServerType"]); + set_ini_value("Database", "DBHost",$_POST["ServerHost"]); + set_ini_value("Database", "DBName",$_POST["ServerDB"]); + set_ini_value("Database", "DBUser",$_POST["ServerUser"]); + set_ini_value("Database", "DBUserPassword",$_POST["ServerPass"]); + set_ini_value("Database","TablePrefix",$_POST["TablePrefix"]); + save_values(); + $GLOBALS['include_file'] = 'install/install_finish.php'; +} + +function ReSetVar($var) +{ + // define varible if not defined before + if( !isset($GLOBALS[$var]) ) $GLOBALS[$var] = ''; +} + +// if globals.php not yet included (1st steps of install), +// then define GetVar function +if( !function_exists('GetVar') ) +{ + 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 RadioChecked($name, $value) +{ + // return " checked" word in case if radio is checked + $submit_value = GetVar($name); + return $submit_value == $value ? ' checked' : ''; +} + +?> Index: trunk/kernel/units/modules/modules_event_handler.php =================================================================== diff -u -r1566 -r1591 --- trunk/kernel/units/modules/modules_event_handler.php (.../modules_event_handler.php) (revision 1566) +++ trunk/kernel/units/modules/modules_event_handler.php (.../modules_event_handler.php) (revision 1591) @@ -1,6 +1,6 @@ Application->SetVar($this->Prefix."_".$event->Special."_id", $event->Special); + $this->Application->SetVar( $event->getPrefixSpecial(true).'_id', $event->Special); parent::OnItemBuild($event); } - function SetCustomQuery(&$event){ - $object=&$event->getObject(); - $object->addFilter("current_module", "Name=".$event->Special); - - } + function SetCustomQuery(&$event) + { + $object=&$event->getObject(); + $object->addFilter('current_module', 'Name='.$event->Special); + } -} + } ?> \ No newline at end of file Index: trunk/core/kernel/application.php =================================================================== diff -u -r1560 -r1591 --- trunk/core/kernel/application.php (.../application.php) (revision 1560) +++ trunk/core/kernel/application.php (.../application.php) (revision 1591) @@ -202,8 +202,19 @@ function GetPrimaryCurrency() { - $table = $this->getUnitOption('curr','TableName'); - return $this->DB->GetOne('SELECT ISO FROM '.$table.' WHERE IsPrimary = 1'); + $this->setUnitOption('mod','AutoLoad',false); + $module =& $this->recallObject('mod'); + $this->setUnitOption('mod','AutoLoad',true); + + if( $module->Load('In-Commerce') ) + { + $table = $this->getUnitOption('curr','TableName'); + return $this->DB->GetOne('SELECT ISO FROM '.$table.' WHERE IsPrimary = 1'); + } + else + { + return 'USD'; + } } /** Index: trunk/core/units/modules/modules_event_handler.php =================================================================== diff -u -r1566 -r1591 --- trunk/core/units/modules/modules_event_handler.php (.../modules_event_handler.php) (revision 1566) +++ trunk/core/units/modules/modules_event_handler.php (.../modules_event_handler.php) (revision 1591) @@ -1,6 +1,6 @@ Application->SetVar($this->Prefix."_".$event->Special."_id", $event->Special); + $this->Application->SetVar( $event->getPrefixSpecial(true).'_id', $event->Special); parent::OnItemBuild($event); } - function SetCustomQuery(&$event){ - $object=&$event->getObject(); - $object->addFilter("current_module", "Name=".$event->Special); - - } + function SetCustomQuery(&$event) + { + $object=&$event->getObject(); + $object->addFilter('current_module', 'Name='.$event->Special); + } -} + } ?> \ No newline at end of file