Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Mon, Jan 6, 6:09 AM

in-portal

Index: branches/RC/admin/install.php
===================================================================
--- branches/RC/admin/install.php (revision 10303)
+++ branches/RC/admin/install.php (revision 10304)
@@ -1,2050 +1,2058 @@
<?php
error_reporting(E_ALL);
set_time_limit(0);
ini_set('memory_limit', -1);
define('BACKUP_NAME', 'dump(.*).txt'); // how backup dump files are named
$general_error = '';
// new path detection without K4 init: begin
define('FULL_PATH', realpath(dirname(__FILE__).'/..'));
define('ADMIN_DIRECTORY', preg_replace('/^'.preg_quote(FULL_PATH, '/').'/', '', realpath(dirname(__FILE__))));
define('BASE_PATH', rtrim(preg_replace('#'.ADMIN_DIRECTORY.'$#', '', str_replace('\\', '/', dirname($_SERVER['PHP_SELF']))), '/'));
$rootURL = 'http://'.$_SERVER['HTTP_HOST'].rtrim(BASE_PATH, '/').ADMIN_DIRECTORY.'/';
// new path detection without K4 init: end
$pathtoroot = FULL_PATH.'/';
$admin = trim(ADMIN_DIRECTORY, '/');
ini_set('include_path', '.');
if (!defined('IS_INSTALL')) define('IS_INSTALL',1);
if( file_exists($pathtoroot.'debug.php') && !(defined('DEBUG_MODE') && DEBUG_MODE) ) include_once($pathtoroot.'debug.php');
$state = isset($_GET["state"]) ? $_GET["state"] : '';
if(!strlen($state))
{
$state = isset($_POST['state']) ? $_POST['state'] : '';
}
if (!defined("GET_LICENSE_URL")) {
define("GET_LICENSE_URL", "http://www.intechnic.com/myaccount/license.php");
}
require_once $pathtoroot.$admin.'/install/install_lib.php';
$install_type = GetVar('install_type', true);
$force_finish = isset($_REQUEST['ff']) ? true : false;
$ini_file = FULL_PATH.'/config.php';
if (file_exists($ini_file)) {
$write_access = is_writable($ini_file);
$ini_vars = inst_parse_portal_ini($ini_file, true);
foreach ($ini_vars as $secname => $section) {
foreach ($section as $key => $value) {
$key = 'g_'.str_replace('-', '', $key);
global $$key;
$$key = $value;
}
}
}
else
{
$state="";
$write_access = is_writable($pathtoroot);
if($write_access)
{
set_ini_value('Database', 'DBType', '');
set_ini_value('Database', 'DBHost', '');
set_ini_value('Database', 'DBUser', '');
set_ini_value('Database', 'DBUserPassword', '');
set_ini_value('Database', 'DBName', '');
set_ini_value('Module Versions', 'In-Portal', '');
save_values();
}
}
$titles[1] = "General Site Setup";
$configs[1] = "in-portal:configure_general";
$mods[1] = "In-Portal";
$titles[2] = "User Setup";
$configs[2] = "in-portal:configure_users";
$mods[2] = "In-Portal:Users";
$titles[3] = "Category Display Setup";
$configs[3] = "in-portal:configure_categories";
$mods[3] = "In-Portal";
// simulate rootURL variable: begin
$rootURL = 'http://'.dirname($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']);
$tmp = explode('/', $rootURL);
if( $tmp[ count($tmp) - 1 ] == $admin) unset( $tmp[ count($tmp) - 1 ] );
$rootURL = implode('/', $tmp).'/';
unset($tmp);
//echo "RU: $rootURL<br>";
// simulate rootURL variable: end
$db_savings = Array('dbinfo', 'db_config_save', 'db_reconfig_save'); //, 'reinstall_process'
if( isset($g_DBType) && $g_DBType && strlen($state)>0 && !in_array($state, $db_savings) )
{
define('REL_PATH', 'admin');
require_once($pathtoroot."kernel/startup.php");
$localURL=$rootURL."kernel/";
$adminURL = $rootURL.$admin;
$imagesURL = $adminURL."/images";
//admin only util
$pathtolocal = $pathtoroot."kernel/";
require_once ($pathtoroot.$admin."/include/elements.php");
//require_once ($pathtoroot."kernel/admin/include/navmenu.php");
require_once ($pathtolocal."admin/include/navmenu.php");
require_once($pathtoroot.$admin."/toolbar.php");
set_cookie(SESSION_COOKIE_NAME, '', adodb_mktime() - 3600, rtrim(BASE_PATH, '/') );
}
function GetPathChar($path = null)
{
if( !isset($path) ) $path = $GLOBALS['pathtoroot'];
$pos = strpos($path, ':');
return ($pos === false) ? "/" : "\\";
}
function SuperStrip($str, $inverse = false)
{
$str = $inverse ? str_replace("%5C","\\",$str) : str_replace("\\","%5C",$str);
return stripslashes($str);
}
$skip_step = false;
require_once($pathtoroot.$admin."/install/inst_ado.php");
$helpURL = $rootURL.$admin.'/help/install_help.php?destform=popup&help_usage=install';
?>
<html>
<head>
<title>In-Portal Installation</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Notepad">
<link rel="stylesheet" type="text/css" href="include/style.css">
<LINK REL="stylesheet" TYPE="text/css" href="install/2col.css">
<SCRIPT LANGUAGE="JavaScript1.2">
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function swap(imgid, src){
var ob = document.getElementById(imgid);
ob.src = 'images/' + src;
}
function Continue() {
document.iform1.submit();
}
function CreatePopup(window_name, url, width, height)
{
// creates a popup window & returns it
if(url == null && typeof(url) == 'undefined' ) url = '';
if(width == null && typeof(width) == 'undefined' ) width = 750;
if(height == null && typeof(height) == 'undefined' ) height = 400;
return window.open(url,window_name,'width='+width+',height='+height+',status=yes,resizable=yes,menubar=no,scrollbars=yes,toolbar=no');
}
function ShowHelp(section)
{
var frm = document.getElementById('help_form');
frm.section.value = section;
frm.method = 'POST';
CreatePopup('HelpPopup','<?php echo $rootURL.$admin; ?>/help/blank.html'); // , null, 600);
frm.target = 'HelpPopup';
frm.submit();
}
</SCRIPT>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" style="height: 100%">
<form name="help_form" id="help_form" action="<?php echo $helpURL; ?>" method="post"><input type="hidden" id="section" name="section" value=""></form>
<form enctype="multipart/form-data" name="iform1" id="iform1" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
<tr>
<td height="90">
<table cellpadding="0" cellspacing="0" border="0" width="100%" height="90">
<tr>
<td rowspan="3" valign="top"><a href="http://www.in-portal.net" target="_top"><img title="In-portal" src="images/globe.gif" width="84" height="91" border="0"></a></td>
<td rowspan="3" valign="top"><a href="http://www.in-portal.net" target="_top"><img title="In-portal" src="images/logo.gif" width="150" height="91" border="0"></a></td>
<td rowspan="3" width="100000" align="right">&nbsp;</td>
<td width="400"><img title="" src="images/blocks.gif" width="400" height="73"></td>
</tr>
<tr><td align="right" background="images/version_bg.gif" class="head_version" valign="top"><img title="" src="images/spacer.gif" width="1" height="14">In-Portal Version <?php echo GetMaxPortalVersion($pathtoroot.$admin)?>: English US</td></tr>
<tr><td><img title="" src="images/blocks2.gif" width="400" height="2"><br></td></tr>
<tr><td bgcolor="black" colspan="4"><img title="" src="images/spacer.gif" width="1" height="1"><br></td></tr>
</table>
</td>
</tr>
<?php
require_once($pathtoroot."kernel/include/adodb/adodb.inc.php");
if(!strlen($state))
$state = @$_POST["state"];
//echo $state;
if(strlen($state)==0)
{
$ado =& inst_GetADODBConnection();
$installed = $ado ? TableExists($ado,"ConfigurationAdmin,Category,Permissions") : false;
if(!minimum_php_version("4.1.2"))
{
$general_error = "You have version ".phpversion()." - please upgrade!";
//die();
}
if(!$write_access)
{
if ($general_error != '') {
$general_error .= '<br /><br />';
}
$general_error .= "Install cannot write to config.php in the root directory of your in-portal installation ($pathtoroot).";
//die();
}
if(!is_writable($pathtoroot."themes/"))
{
if ($general_error != '') {
$general_error .= '<br /><br />';
}
$general_error .= "In-portal's Theme directory must be writable (".$pathtoroot."themes/).";
//die();
}
if(!is_writable($pathtoroot."kernel/images/"))
{
if ($general_error != '') {
$general_error .= '<br /><br />';
}
$general_error .= "In-portal's Image Upload directory must be writable (".$pathtoroot."kernel/images/).";
//die();
}
if(!is_writable($pathtoroot."kernel/images/pending"))
{
if ($general_error != '') {
$general_error .= '<br /><br />';
}
$general_error .= "In-portal's Pending Image Upload directory must be writable (".$pathtoroot."kernel/images/pending).";
//die();
}
if(!is_writable($pathtoroot.$admin."/backupdata/"))
{
if ($general_error != '') {
$general_error .= '<br /><br />';
}
$general_error .= "In-portal's Backup directory must be writable (".$pathtoroot.$admin."/backupdata/).";
//die();
}
if(!is_writable($pathtoroot.$admin."/export/"))
{
if ($general_error != '') {
$general_error .= '<br /><br />';
}
$general_error .= "In-portal's Export directory must be writable (".$pathtoroot.$admin."/export/).";
//die();
}
if(!is_writable($pathtoroot."kernel/stylesheets/"))
{
if ($general_error != '') {
$general_error .= '<br /><br />';
}
$general_error .= "In-portal's stylesheets directory must be writable (".$pathtoroot."kernel/stylesheets/).";
//die();
}
if(!is_writable($pathtoroot."kernel/user_files/"))
{
if ($general_error != '') {
$general_error .= '<br /><br />';
}
$general_error .= "In-portal's CMS images directory must be writable (".$pathtoroot."kernel/user_files/).";
//die();
}
if(!is_writable($pathtoroot."kernel/cache/"))
{
if ($general_error != '') {
$general_error .= '<br /><br />';
}
$general_error .= "In-portal's templates cache directory must be writable (".$pathtoroot."kernel/cache/).";
//die();
}
if($installed)
{
$state="reinstall";
}
else {
$state="dbinfo";
}
}
if($state=="reinstall_process")
{
$login_err_mesg = ''; // always init vars before use
if( !isset($g_License) ) $g_License = '';
$lic = base64_decode($g_License);
if(strlen($lic))
{
a83570933e44bc66b31dd7127cf3f23a($lic);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
}
$LoggedIn = FALSE;
if($_POST["UserName"]=="root")
{
$ado =& inst_GetADODBConnection();
$sql = "SELECT * FROM ".$g_TablePrefix."ConfigurationValues WHERE VariableName='RootPass'";
$rs = $ado->Execute($sql);
if($rs && !$rs->EOF)
{
$RootPass = $rs->fields["VariableValue"];
if(strlen($RootPass)>0) {
if (ConvertVersion($g_InPortal) >= ConvertVersion("1.3.0")) {
$LoggedIn = ($RootPass==md5(md5($_POST["UserPass"]).'b38'));
}
else {
$LoggedIn = ($RootPass==md5($_POST["UserPass"]));
}
}
}
else {
$login_err_mesg = 'Invalid username or password';
}
}
else
{
$act = '';
if (ConvertVersion($g_InPortal) >= ConvertVersion("1.0.5")) {
$act = 'check';
}
$rfile = @fopen(GET_LICENSE_URL."?login=".md5($_POST['UserName'])."&password=".md5($_POST['UserPass'])."&action=$act&license_code=".base64_encode($g_LicenseCode)."&version=".GetMaxPortalVersion($pathtoroot.$admin)."&domain=".base64_encode($_SERVER['HTTP_HOST']), "r");
if (!$rfile) {
$login_err_mesg = "Unable to connect to the Intechnic server!";
$LoggedIn = false;
}
else {
$rcontents = '';
while (!feof($rfile)) {
$line = fgets($rfile, 10000);
$rcontents .= $line;
}
@fclose($rfile);
if (substr($rcontents, 0, 5) == 'Error') {
$login_err_mesg = substr($rcontents, 6);
$LoggedIn = false;
}
else {
$LoggedIn = true;
}
}
//$LoggedIn = ($i_User == $_POST["UserName"] && ($i_Pswd == $_POST["UserPass"]) && strlen($i_User)>0) || strlen($i_User)==0;
}
if($LoggedIn)
{
if (!(int)$_POST["inp_opt"]) {
$state="reinstall";
$inst_error = "Please select one of the options above!";
}
else {
switch((int)$_POST["inp_opt"])
{
case 0:
$inst_error = "Please select an option above";
break;
case 1:
/* clean out all tables */
$install_type = 4;
$ado =& inst_GetADODBConnection();
$filename = $pathtoroot.$admin."/install/inportal_remove.sql";
RunSchemaFile($ado,$filename);
// removing other tables
$tables = $ado->MetaTables();
foreach($tables as $tab_name) {
if (stristr($tab_name, $g_TablePrefix."ses_")) {
$sql = "DROP TABLE IF EXISTS $tab_name";
$ado->Execute($sql);
}
}
/* run install again */
$state="license";
break;
case 2:
$install_type = 3;
$state="dbinfo";
break;
case 3:
$install_type = 5;
$state="license";
break;
case 4:
$install_type = 6;
/* clean out all tables */
$ado =& inst_GetADODBConnection();
//$filename = $pathtoroot.$admin."/install/inportal_remove.sql";
//RunSchemaFile($ado,$filename);
/* run install again */
$state="restore_select";
break;
case 5:
$install_type = 7;
/* change DB config */
$state="db_reconfig";
break;
case 6:
$install_type = 8;
$state = "upgrade";
break;
case 7:
$install_type = 9;
$state = "fix_paths";
break;
}
}
}
else
{
$state="reinstall";
$login_error = $login_err_mesg;//"Invalid Username or Password - Try Again";
}
}
if ($state == "upgrade") {
$ado =& inst_GetADODBConnection();
$Modules = array();
$Texts = array();
if (ConvertVersion(GetMaxPortalVersion($pathtoroot.$admin)) >= ConvertVersion("1.0.5") && ($g_LicenseCode == '' && $g_License != '')) {
$state = 'reinstall';
$inst_error = "Your license must be updated before you can upgrade. Please don't use 'Existing License' option, instead either Download from Intechnic or Upload a new license file!";
}
else {
$sql = "SELECT Name, Version, Path FROM ".$g_TablePrefix."Modules ORDER BY LoadOrder asc";
$rs = $ado->Execute($sql);
$i = 0;
while ($rs && !$rs->EOF) {
$p = $rs->fields['Path'];
if ($rs->fields['Name'] == 'In-Portal') {
$p = '';
}
$dir_name = $pathtoroot.$p."admin";///install/upgrades/";
if($rs->fields['Version'] != $newver = GetMaxPortalVersion($dir_name))
{
////////////////////
$mod_path = $rs->fields['Path'];
$current_version = $rs->fields['Version'];
if ($rs->fields['Name'] == 'In-Portal') $mod_path = '';
$dir_name = $pathtoroot.$mod_path."/admin/install/upgrades/";
$dir = @dir($dir_name);
if (!$dir) {
$rs->MoveNext();
continue;
}
$upgrades_arr = Array();
$new_version = '';
while ($file = $dir->read()) {
if ($file != "." && $file != ".." && !is_dir($dir_name.$file)) {
if (strstr($file, 'inportal_check_v')) {
$upgrades_arr[] = $file;
}
}
}
usort($upgrades_arr, "VersionSort");
$result=0;
$failCheck=1;
$stopCheck=2;
$CheckErrors = Array();
foreach($upgrades_arr as $file)
{
$file_tmp = str_replace("inportal_check_v", "", $file);
$file_tmp = str_replace(".php", "", $file_tmp);
if (ConvertVersion($file_tmp) > ConvertVersion($current_version)) {
$filename = $pathtoroot.$mod_path."/admin/install/upgrades/$file";
if(file_exists($filename))
{
include($filename);
if( $result & 2 ) break;
}
}
}
////////////////////
$Modules[] = Array('module'=>$rs->fields['Name'],'curver'=>$rs->fields['Version'],'newver'=>$newver,'error'=>$result!='pass');
// $Texts[] = $rs->fields['Name']." (".$rs->fields['Version']." ".prompt_language("la_to")." ".GetMaxPortalVersion($dir_name).")";
}
/*$dir = @dir($dir_name);
while ($file = $dir->read()) {
if ($file != "." && $file != ".." && !is_dir($dir_name.$file))
{
if (strstr($file, 'inportal_upgrade_v')) {
$file = str_replace("inportal_upgrade_v", "", $file);
$file = str_replace(".sql", "", $file);
//$sql = "SELECT count(*) AS count FROM ".$g_TablePrefix."Modules WHERE Name = '".$rs->fields['Name']."' AND Version = '$file'";
//$rs1 = $ado->Execute($sql);
if ($rs1->fields['count'] == 0 && ConvertVersion($file) > ConvertVersion($rs->fields['Version'])) {
if ($Modules[$i-1] == $rs->fields['Name']) {
$Texts[$i-1] = $rs->fields['Name']." (".$rs->fields['Version']." ".prompt_language("la_to")." ".$file.")";
$i--;
}
else {
$Texts[$i] = $rs->fields['Name']." (".$rs->fields['Version']." ".prompt_language("la_to")." ".$file.")";
$Modules[$i] = $rs->fields['Name'];
}
$i++;
}
}
}
}*/
$rs->MoveNext();
}
$sql = 'DELETE FROM '.$g_TablePrefix.'Cache WHERE VarName IN ("config_files","configs_parsed","sections_parsed")';
$ado->Execute($sql);
$include_file = $pathtoroot.$admin."/install/upgrade.php";
}
}
if ($state == "upgrade_process") {
// K4 applition is now always available during upgrade process
if (!defined('FULL_PATH')) {
define('FULL_PATH', realpath(dirname(__FILE__).'/..'));
}
include_once(FULL_PATH.'/core/kernel/startup.php');
$application =& kApplication::Instance();
$application->Init();
// force rereading of configs
$unit_config_reader =& $application->recallObject('kUnitConfigReader');
$unit_config_reader->scanModules(MODULES_PATH);
$ado =& inst_GetADODBConnection();
$mod_arr = $_POST['modules'];
$mod_str = '';
foreach ($mod_arr as $tmp_mod) {
$mod_str .= "'$tmp_mod',";
}
$mod_str = substr($mod_str, 0, strlen($mod_str) - 1);
$sql = "SELECT Name FROM ".$g_TablePrefix."Modules WHERE Name IN ($mod_str) ORDER BY LoadOrder";
$rs = $ado->Execute($sql);
$mod_arr = array();
while ($rs && !$rs->EOF) {
$mod_arr[] = $rs->fields['Name'];
$rs->MoveNext();
}
foreach($mod_arr as $p)
{
$mod_name = strtolower($p);
$sql = "SELECT Version, Path FROM ".$g_TablePrefix."Modules WHERE Name = '$p'";
$rs = $ado->Execute($sql);
$current_version = $rs->fields['Version'];
if ($mod_name == 'in-portal') {
$mod_path = '';
}
else {
$mod_path = $rs->fields['Path'];
}
$dir_name = $pathtoroot.$mod_path."/admin/install/upgrades/";
$dir = @dir($dir_name);
$upgrades_arr = Array();
$new_version = '';
while ($file = $dir->read()) {
if ($file != "." && $file != ".." && !is_dir($dir_name.$file)) {
if (strstr($file, 'inportal_upgrade_v')) {
$upgrades_arr[] = $file;
}
}
}
usort($upgrades_arr, "VersionSort");
foreach($upgrades_arr as $file)
{
preg_match('/inportal_upgrade_v(.*).(php|sql)$/', $file, $rets);
$tmp_version = $rets[1];
$tmp_extension = $rets[2];
if (ConvertVersion($tmp_version) > ConvertVersion($current_version) )
{
$filename = $pathtoroot.$mod_path."/admin/install/upgrades/$file";
//echo "Running: $filename<br>";
// SQL is processed FIRST (before corresponding PHP according to the sorting order in VersionSort()
if( file_exists($filename) )
{
if($tmp_extension == 'sql')
{
RunSQLFile($ado, $filename);
}
else
{
include_once $filename;
}
}
}
}
set_ini_value("Module Versions", $p, GetMaxPortalVersion($pathtoroot.$mod_path."/admin/"));
save_values();
}
// compile stylesheets: begin
define('FULL_PATH', realpath(dirname(__FILE__).'/..'));
include_once(FULL_PATH.'/core/kernel/startup.php');
$application =& kApplication::Instance();
$application->Init();
// $objThemes->CreateMissingThemes(false);
$application->HandleEvent($theme_event, 'adm:OnRebuildThemes');
$css_hash = $application->Conn->GetCol('SELECT LOWER(Name) AS Name, StylesheetId FROM '.TABLE_PREFIX.'Stylesheets', 'StylesheetId');
$css_table = $application->getUnitOption('css','TableName');
$css_idfield = $application->getUnitOption('css','IDField');
$theme_table = $application->getUnitOption('theme', 'TableName');
$theme_idfield = $application->getUnitOption('theme', 'IDField');
$theme_update_sql = 'UPDATE '.$theme_table.' SET '.$css_idfield.' = %s WHERE LOWER(Name) = %s';
foreach($css_hash as $stylesheet_id => $theme_name)
{
$css_item =& $application->recallObject('css', null, Array('skip_autoload' => true));
$css_item->Load($stylesheet_id);
$css_item->Compile();
$application->Conn->Query( sprintf($theme_update_sql, $stylesheet_id, $application->Conn->qstr( getArrayValue($css_hash,$stylesheet_id) ) ) );
}
// do redirect, because upgrade scripts can eat a lot or memory used for language pack upgrade operation
$application->Redirect('install', Array('state' => 'languagepack_upgrade'), '', 'install.php');
// compile stylesheets: end
$state = 'languagepack_upgrade';
}
// upgrade language pack
if($state=='languagepack_upgrade')
{
$state = 'lang_install_init';
if( is_object($application) ) $application->SetVar('lang', Array('english.lang') );
$force_finish = true;
}
if ($state == 'fix_paths') {
$ado = inst_GetADODBConnection();
$sql = "SELECT * FROM ".$g_TablePrefix."ConfigurationValues WHERE VariableName = 'Site_Name' OR VariableName LIKE '%Path%'";
$path_rs = $ado->Execute($sql);
$include_file = $pathtoroot.$admin."/install/fix_paths.php";
}
if ($state == 'fix_paths_process') {
$ado = inst_GetADODBConnection();
//$state = 'fix_paths';
//$include_file = $pathtoroot.$admin."/install/fix_paths.php";
foreach($_POST["values"] as $key => $value) {
$sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '".$value."' WHERE VariableName = '".$key."'";
$ado->Execute($sql);
}
$state = "finish";
}
if($state=="db_reconfig_save")
{
$ini_vars = inst_parse_portal_ini($ini_file,TRUE);
foreach($ini_vars as $secname => $section)
{
foreach($section as $key => $value)
{
$key = "g_".str_replace("-", "", $key);
global $$key;
$$key = $value;
}
}
unset($ado);
$ado = VerifyDB('db_reconfig', 'finish', 'SaveDBConfig', true);
}
if($state=="db_reconfig")
{
$include_file = $pathtoroot.$admin."/install/db_reconfig.php";
}
if($state=="restore_file")
{
if($_POST["submit"]=="Update")
{
$filepath = $_POST["backupdir"];
$state="restore_select";
}
else
{
$filepath = stripslashes($_POST['backupdir']);
$backupfile = $filepath.'/'.str_replace('(.*)', $_POST['backupdate'], BACKUP_NAME);
if(file_exists($backupfile) && is_readable($backupfile))
{
$ado =& inst_GetADODBConnection();
$show_warning = false;
if (!$_POST['warning_ok']) {
// Here we comapre versions between backup and config
$file_contents = file_get_contents($backupfile);
$file_tmp_cont = explode("#------------------------------------------", $file_contents);
$tmp_vers = $file_tmp_cont[0];
$vers_arr = explode(";", $tmp_vers);
$ini_values = inst_parse_portal_ini($ini_file);
foreach ($ini_values as $key => $value) {
foreach ($vers_arr as $k) {
if (strstr($k, $key)) {
if (!strstr($k, $value)) {
$show_warning = true;
}
}
}
}
//$show_warning = true;
}
if (!$show_warning) {
$filename = $pathtoroot.$admin.'/install/inportal_remove.sql';
RunSchemaFile($ado,$filename);
$state="restore_run";
}
else {
$state = "warning";
$include_file = $pathtoroot.$admin."/install/warning.php";
}
}
else {
if ($_POST['backupdate'] != '') {
$include_file = $pathtoroot.$admin."/install/restore_select.php";
$restore_error = "$backupfile not found or could not be read";
}
else {
$include_file = $pathtoroot.$admin."/install/restore_select.php";
$restore_error = "No backup selected!!!";
}
}
}
//echo $restore_error;
}
if($state=="restore_select")
{
if( isset($_POST['backupdir']) ) $filepath = stripslashes($_POST['backupdir']);
$include_file = $pathtoroot.$admin."/install/restore_select.php";
}
if($state=="restore_run")
{
$ado =& inst_GetADODBConnection();
$FileOffset = (int)$_GET["Offset"];
if(!strlen($backupfile))
$backupfile = SuperStrip($_GET['File'], true);
$include_file = $pathtoroot.$admin."/install/restore_run.php";
}
if($state=="db_config_save")
{
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();
$ini_vars = inst_parse_portal_ini($ini_file,TRUE);
foreach($ini_vars as $secname => $section)
{
foreach($section as $key => $value)
{
$key = "g_".str_replace("-", "", $key);
global $$key;
$$key = $value;
}
}
unset($ado);
$ado = VerifyDB('dbinfo', 'license');
}
if($state=="dbinfo")
{
if ($install_type == '') {
$install_type = 1;
}
$include_file = $pathtoroot.$admin."/install/dbinfo.php";
}
if ($state == "download_license") {
$ValidLicense = FALSE;
$lic_login = isset($_POST['login']) ? $_POST['login'] : '';
$lic_password = isset($_POST['password']) ? $_POST['password'] : '';
if ($lic_login != '' && $lic_password != '') {
// Here we determine weather login is ok & check available licenses
$rfile = @fopen(GET_LICENSE_URL."?login=".md5($_POST['login'])."&password=".md5($_POST['password'])."&version=".GetMaxPortalVersion($pathtoroot.$admin)."&domain=".base64_encode($_SERVER['HTTP_HOST']), "r");
if (!$rfile) {
$get_license_error = "Unable to connect to the Intechnic server! Please try again later!";
$state = "get_license";
$include_file = $pathtoroot.$admin."/install/get_license.php";
}
else {
$rcontents = '';
while (!feof($rfile)) {
$line = fgets($rfile, 10000);
$rcontents .= $line;
}
@fclose($rfile);
if (substr($rcontents, 0, 5) == 'Error') {
$get_license_error = substr($rcontents, 6);
$state = "get_license";
$include_file = $pathtoroot.$admin."/install/get_license.php";
}
else {
if (substr($rcontents, 0, 3) == "SEL") {
$state = "download_license";
$license_select = substr($rcontents, 4);
$include_file = $pathtoroot.$admin."/install/download_license.php";
}
else {
// Here we get one license
$tmp_data = explode('Code==:', $rcontents);
$data = base64_decode(str_replace("In-Portal License File - do not edit!\n", "", $tmp_data[0]));
a83570933e44bc66b31dd7127cf3f23a($data);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
if($ValidLicense)
{
set_ini_value("Intechnic","License",base64_encode($data));
set_ini_value("Intechnic","LicenseCode",$tmp_data[1]);
save_values();
$state="domain_select";
$got_license = 1;
}
else {
$license_error="Invalid License File";
}
if(!$ValidLicense)
{
$state="license";
}
}
}
}
}
else if ($_POST['licenses'] == '') {
$state = "get_license";
$get_license_error = "Username and / or password not specified!!!";
$include_file = $pathtoroot.$admin."/install/get_license.php";
}
else {
// Here we download license
$rfile = @fopen(GET_LICENSE_URL."?license_id=".md5($_POST['licenses'])."&dlog=".md5($_POST['dlog'])."&dpass=".md5($_POST['dpass'])."&version=".GetMaxPortalVersion($pathtoroot.$admin)."&domain=".base64_encode($_POST['domain']), "r");
if (!$rfile) {
$get_license_error = "Unable to connect to the Intechnic server! Please try again later!";
$state = "get_license";
$include_file = $pathtoroot.$admin."/install/get_license.php";
}
else {
$rcontents = '';
while (!feof($rfile)) {
$line = fgets($rfile, 10000);
$rcontents .= $line;
}
@fclose($rfile);
if (substr($rcontents, 0, 5) == 'Error') {
$download_license_error = substr($rcontents, 6);
$state = "download_license";
$include_file = $pathtoroot.$admin."/install/download_license.php";
}
else {
$tmp_data = explode('Code==:', $rcontents);
$data = base64_decode(str_replace("In-Portal License File - do not edit!\n", "", $tmp_data[0]));
a83570933e44bc66b31dd7127cf3f23a($data);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
if($ValidLicense)
{
set_ini_value("Intechnic","License",base64_encode($data));
// old licensing script doen't return 2nd parameter (licanse code)
if( isset($tmp_data[1]) ) set_ini_value("Intechnic","LicenseCode",$tmp_data[1]);
save_values();
$state="domain_select";
}
else {
$license_error="Invalid License File";
}
if(!$ValidLicense)
{
$state="license";
}
}
}
}
}
if($state=="license_process")
{
$ValidLicense = FALSE;
$tmp_lic_opt = GetVar('lic_opt', true);
switch($tmp_lic_opt)
{
case 1: /* download from intechnic */
$include_file = $pathtoroot.$admin."/install/get_license.php";
$state = "get_license";
//if(!$ValidLicense)
//{
// $state="license";
//}
break;
case 2: /* upload file */
$file = $_FILES["licfile"];
if(is_array($file))
{
move_uploaded_file($file["tmp_name"],$pathtoroot."themes/tmp.lic");
@chmod($pathtoroot."themes/tmp.lic", 0666);
$fp = @fopen($pathtoroot."themes/tmp.lic","rb");
if($fp)
{
$lic = fread($fp,filesize($pathtoroot."themes/tmp.lic"));
fclose($fp);
}
$tmp_data = ae666b1b8279502f4c4b570f133d513e(FALSE,$pathtoroot."themes/tmp.lic");
$data = $tmp_data[0];
@unlink($pathtoroot."themes/tmp.lic");
a83570933e44bc66b31dd7127cf3f23a($data);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
if($ValidLicense)
{
set_ini_value("Intechnic","License",base64_encode($data));
set_ini_value("Intechnic","LicenseCode",$tmp_data[1]);
save_values();
$state="domain_select";
}
else
$license_error="Invalid License File";
}
if(!$ValidLicense)
{
$state="license";
}
break;
case 3: /* existing */
if(strlen($g_License))
{
$lic = base64_decode($g_License);
a83570933e44bc66b31dd7127cf3f23a($lic);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
if($ValidLicense)
{
$state="domain_select";
}
else
{
$state="license";
$license_error="Invalid or corrupt license detected";
}
}
else
{
$state="license";
$license_error="Missing License File";
}
if(!$ValidLicense)
{
$state="license";
}
break;
case 4:
//set_ini_value("Intechnic","License",base64_encode("local"));
//set_ini_value("Intechnic","LicenseCode",base64_encode("local"));
//save_values();
$state="domain_select";
break;
}
if($ValidLicense)
$state="domain_select";
}
if($state=="license")
{
$include_file = $pathtoroot.$admin."/install/sel_license.php";
}
if($state=="reinstall")
{
$ado =& inst_GetADODBConnection();
$show_upgrade = false;
$sql = "SELECT Name FROM ".$g_TablePrefix."Modules";
$rs = $ado->Execute($sql);
$modules = '';
while ($rs && !$rs->EOF) {
$modules .= strtolower($rs->fields['Name']).',';
$rs->MoveNext();
}
$mod_arr = explode(",", substr($modules, 0, strlen($modules) - 1));
foreach($mod_arr as $p)
{
if ($p == 'in-portal') {
$p = '';
}
$dir_name = $pathtoroot.$p."/admin/install/upgrades/";
$dir = @dir($dir_name);
//echo "<pre>"; print_r($dir); echo "</pre>";
if ($dir === false) continue;
while ($file = $dir->read()) {
if ($file != "." && $file != ".." && !is_dir($dir_name.$file))
{
if( preg_match('/inportal_upgrade_v(.*).(php|sql)$/', $file, $rets) )
{
if($p == '') $p = 'in-portal';
$sql = "SELECT Version FROM ".$g_TablePrefix."Modules WHERE Name = '".$p."'";
$rs = $ado->Execute($sql);
if( ConvertVersion($rs->fields['Version']) < ConvertVersion( $rets[1] ) )
{
$show_upgrade = true;
}
}
}
}
}
if ( !isset($install_type) || $install_type == '') {
$install_type = 2;
}
$include_file = $pathtoroot.$admin."/install/reinstall.php";
}
if($state=="login")
{
$lic = base64_decode($g_License);
if(strlen($lic))
{
a83570933e44bc66b31dd7127cf3f23a($lic);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
}
if(!$ValidLicense)
{
$state="license";
}
else
if($i_User == $_POST["UserName"] || $i_Pswd == $_POST["UserPass"])
{
$state = "domain_select";
}
else
{
$state="getuser";
$login_error = "Invalid User Name or Password. If you don't know your username or password, contact Intechnic Support";
}
//die();
}
if($state=="getuser")
{
$include_file = $pathtoroot.$admin."/install/login.php";
}
if($state=="set_domain")
{
if( !is_array($i_Keys) || !count($i_Keys) )
{
$lic = base64_decode($g_License);
if(strlen($lic))
{
a83570933e44bc66b31dd7127cf3f23a($lic);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
}
}
if($_POST["domain"]==1)
{
$domain = $_SERVER['HTTP_HOST'];
if (strstr($domain, $i_Keys[0]['domain']) || de3ec1b7a142cccd0d51f03d24280744($domain)) {
set_ini_value("Intechnic","Domain",$domain);
save_values();
$state="runsql";
}
else {
$DomainError = 'Domain name selected does not match domain name in the license!';
$state = "domain_select";
}
}
else
{
$domain = str_replace(" ", "", $_POST["other"]);
if ($domain != '') {
if (strstr($domain, $i_Keys[0]['domain']) || de3ec1b7a142cccd0d51f03d24280744($domain)) {
set_ini_value("Intechnic","Domain",$domain);
save_values();
$state="runsql";
}
else {
$DomainError = 'Domain name entered does not match domain name in the license!';
$state = "domain_select";
}
}
else {
$DomainError = 'Please enter valid domain!';
$state = "domain_select";
}
}
}
if($state=="domain_select")
{
if(!is_array($i_Keys))
{
$lic = base64_decode($g_License);
if(strlen($lic))
{
a83570933e44bc66b31dd7127cf3f23a($lic);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
}
}
$include_file = $pathtoroot.$admin."/install/domain.php";
}
if($state=="runsql")
{
$ado =& inst_GetADODBConnection();
$installed = TableExists($ado,"ConfigurationAdmin,Category,Permissions");
if(!$installed)
{
// run core install script
K4_RunSQL('/core/install/install_schema.sql');
K4_RunSQL('/core/install/install_data.sql');
K4_SetModuleVersion('Core');
// run in-portal install script
$filename = $pathtoroot.$admin."/install/inportal_schema.sql";
RunSchemaFile($ado,$filename);
$filename = $pathtoroot.$admin."/install/inportal_data.sql";
RunSQLFile($ado,$filename);
$sql = 'UPDATE '.$g_TablePrefix.'ConfigurationValues SET VariableValue = %s WHERE VariableName = %s';
$ado->Execute( sprintf($sql, $ado->qstr('portal@'.$ini_vars['Intechnic']['Domain']), $ado->qstr('Smtp_AdminMailFrom') ) );
$sql = "SELECT Version FROM ".$g_TablePrefix."Modules WHERE Name = 'In-Portal'";
$rs = $ado->Execute($sql);
set_ini_value("Module Versions", "In-Portal", $rs->fields['Version']);
save_values();
require_once $pathtoroot.'kernel/include/tag-class.php';
if( !is_object($objTagList) ) $objTagList = new clsTagList();
// install kernel specific tags
$objTagList->DeleteTags(); // delete all existing tags in db
// create 3 predifined tags (because there no functions with such names
$t = new clsTagFunction();
$t->Set("name","include");
$t->Set("description","insert template output into the current template");
$t->Create();
$t->AddAttribute("_template","tpl","Template to insert","",TRUE);
$t->AddAttribute("_supresserror","bool","Supress missing template errors","",FALSE);
$t->AddAttribute("_dataexists","bool","Only include template output if content exists (content is defined by the tags in the template)","",FALSE);
$t->AddAttribute("_nodatatemplate","tpl","Template to include if the nodataexists condition is true","",FALSE);
unset($t);
$t = new clsTagFunction();
$t->Set("name","perm_include");
$t->Set("description","insert template output into the current template if permissions are set");
$t->Create();
$t->AddAttribute("_template","tpl","Template to insert","",TRUE);
$t->AddAttribute("_noaccess","tpl","Template to insert if access is denied","",FALSE);
$t->AddAttribute("_permission","","Comma-separated list of permissions, any of which will grant access","",FALSE);
$t->AddAttribute("_module","","Used in place of the _permission attribute, this attribute verifies the module listed is enabled","",FALSE);
$t->AddAttribute("_system","bool","Must be set to true if any permissions in _permission list is a system permission","",FALSE);
$t->AddAttribute("_supresserror","bool","Supress missing template errors","",FALSE);
$t->AddAttribute("_dataexists","bool","Only include template output if content exists (content is defined by the tags in the template)","",FALSE);
$t->AddAttribute("_nodatatemplate","tpl","Template to include if the nodataexists condition is true","",FALSE);
unset($t);
$t = new clsTagFunction();
$t->Set("name","mod_include");
$t->Set("description","insert templates from all enabled modules. No error occurs if the template does not exist.");
$t->Create();
$t->AddAttribute("_template","tpl","Template to insert. This template path should be relative to the module template root directory","",TRUE);
$t->AddAttribute("_modules","","Comma-separated list of modules. Defaults to all enabled modules if not set","",FALSE);
$t->AddAttribute("_supresserror","bool","Supress missing template errors","",FALSE);
$t->AddAttribute("_dataexists","bool","Only include template output if content exists (content is defined by the tags in the template)","",FALSE);
$t->AddAttribute("_nodatatemplate","tpl","Template to include if the nodataexists condition is true","",FALSE);
$objTagList->ParseFile($pathtoroot.'kernel/parser.php'); // insert module tags
if( is_array($ItemTagFiles) )
foreach($ItemTagFiles as $file)
$objTagList->ParseItemFile($pathtoroot.$file);
$state="RootPass";
}
else {
$include_file = $pathtoroot.$admin."/install/install_finish.php";
$state="finish";
}
}
if($state=="RootSetPass")
{
$pass = $_POST["RootPass"];
if(strlen($pass)<4)
{
$PassError = "Root Password must be at least 4 characters";
$state = "RootPass";
}
else if ($pass != $_POST["RootPassConfirm"]) {
$PassError = "Passwords does not match";
$state = "RootPass";
}
else
{
$pass = md5(md5($pass).'b38');
$sql = ' UPDATE '.$g_TablePrefix.'ConfigurationValues
SET VariableValue = '.$ado->qstr($pass).'
WHERE VariableName = "RootPass";';
$ado =& inst_GetADODBConnection();
$ado->Execute($sql);
$state="modselect";
}
}
if($state=="RootPass")
{
$include_file = $pathtoroot.$admin."/install/rootpass.php";
}
if($state=="lang_install_init")
{
$ado =& inst_GetADODBConnection();
if( TableExists($ado, 'Language,Phrase') )
{
// KERNEL 4 INIT: BEGIN
define('FULL_PATH', realpath(dirname(__FILE__).'/..'));
include_once(FULL_PATH.'/core/kernel/startup.php');
$application =& kApplication::Instance();
$application->Init();
// KERNEL 4 INIT: END
$lang_xml =& $application->recallObject('LangXML');
if (defined('DBG_FAST_INSTALL') && DBG_FAST_INSTALL) {
$lang_xml->tables['phrases'] = TABLE_PREFIX.'Phrase';
$lang_xml->tables['emailmessages'] = TABLE_PREFIX.'EmailMessage';
}
else {
$lang_xml->renameTable('phrases', TABLE_PREFIX.'ImportPhrases');
$lang_xml->renameTable('emailmessages', TABLE_PREFIX.'ImportEvents');
}
$lang_xml->lang_object->TableName = $application->getUnitOption('lang','TableName');
$languages = $application->GetVar('lang');
if($languages)
{
$kernel_db =& $application->GetADODBConnection();
$modules_table = $application->getUnitOption('mod','TableName');
$modules = $kernel_db->GetCol('SELECT Path, Name FROM '.$modules_table, 'Name');
$modules['In-Portal'] = '';
foreach($languages as $lang_file)
{
foreach($modules as $module_name => $module_folder)
{
$lang_path = MODULES_PATH.'/'.$module_folder.'admin/install/langpacks';
$lang_xml->Parse($lang_path.'/'.$lang_file, '|0|1|2|', '');
if($force_finish) $lang_xml->lang_object->Update();
}
}
if (defined('DBG_FAST_INSTALL') && DBG_FAST_INSTALL) {
$state = 'lang_default';
}
else {
$state = 'lang_install';
}
}
else
{
$state = 'lang_select';
}
$application->Done();
}
else
{
$general_error = 'Database error! No language tables found!';
}
}
if($state=="lang_install")
{
define('FORCE_CONFIG_CACHE', 1);
/* do pack install */
$Offset = (int)$_GET["Offset"];
$Status = (int)$_GET["Status"];
$PhraseTable = $g_TablePrefix."ImportPhrases";
$EventTable = $g_TablePrefix."ImportEvents";
$Total = TableCount($Status == 0 ? $PhraseTable : $EventTable, '', 0);
if($Status == 0)
{
$Offset = $objLanguages->ReadImportTable($PhraseTable, 1,"0,1,2", $force_finish ? false : true, 200,$Offset);
if($Offset >= $Total)
{
$Offset=0;
$Status=1;
}
$next_step = GetVar('next_step', true);
if($force_finish == true) $next_step = 3;
$NextUrl = $_SERVER['PHP_SELF']."?Offset=$Offset&Status=$Status&state=lang_install&next_step=$next_step&install_type=$install_type";
if($force_finish == true) $NextUrl .= '&ff=1';
$include_file = $pathtoroot.$admin."/install/lang_run.php";
}
else
{
if(!is_object($objMessageList))
$objMessageList = new clsEmailMessageList();
$Offset = $objMessageList->ReadImportTable($EventTable, $force_finish ? false : true,300,$Offset);
if($Offset > $Total)
{
$next_step = GetVar('next_step', true);
if($force_finish == true) $next_step = 3;
$NextUrl = $_SERVER['PHP_SELF']."?Offset=$Offset&Status=$Status&State=lang_install&next_step=$next_step&install_type=$install_type";
if($force_finish == true) $NextUrl .= '&ff=1';
$include_file = $pathtoroot.$admin."/install/lang_run.php";
}
else
{
$db =& GetADODBConnection();
$prefix = $g_TablePrefix;
$db->Execute('DROP TABLE IF EXISTS '.$PhraseTable);
$db->Execute('DROP TABLE IF EXISTS '.$EventTable);
if(!$force_finish)
{
$state = 'lang_default';
}
else
{
$_POST['next_step'] = 4;
$state = 'finish';
$include_file = $pathtoroot.$admin."/install/install_finish.php";
}
}
}
}
if($state=="lang_default_set")
{
// phpinfo(INFO_VARIABLES);
/*$ado =& inst_GetADODBConnection();
$PhraseTable = GetTablePrefix()."ImportPhrases";
$EventTable = GetTablePrefix()."ImportEvents";
$ado->Execute("DROP TABLE IF EXISTS $PhraseTable");
$ado->Execute("DROP TABLE IF EXISTS $EventTable");*/
$Id = $_POST["lang"];
$objLanguages->SetPrimary($Id);
if (defined('DBG_FAST_INSTALL')) {
$state = 'theme_sel';
}
else {
$state="postconfig_1";
}
}
if($state=="lang_default")
{
$Packs = Array();
$objLanguages->Clear();
$objLanguages->LoadAllLanguages();
foreach($objLanguages->Items as $l)
{
$Packs[$l->Get("LanguageId")] = $l->Get("PackName");
}
$include_file = $pathtoroot.$admin."/install/lang_default.php";
}
if($state=="modinstall")
{
$doms = $_POST["domain"];
if(is_array($doms))
{
$ado =& inst_GetADODBConnection();
require_once $pathtoroot.'kernel/include/tag-class.php';
if( !isset($objTagList) || !is_object($objTagList) ) $objTagList = new clsTagList();
-
+
// TODO: make possible to define module install order (e.g. via special order file in module directory, because db info is not available before module is installed)
$ebay_key = array_search('in-auction', $doms);
if ($ebay_key !== false) {
unset($doms[$ebay_key]);
$doms[] = 'in-auction';
}
foreach($doms as $p)
{
$filename = $pathtoroot.$p.'/admin/install.php';
if(file_exists($filename) )
{
include($filename);
}
}
}
/* $sql = "SELECT Name FROM ".GetTablePrefix()."Modules";
$rs = $ado->Execute($sql);
while($rs && !$rs->EOF)
{
$p = $rs->fields['Name'];
$mod_name = strtolower($p);
if ($mod_name == 'in-portal') {
$mod_name = '';
}
$dir_name = $pathtoroot.$mod_name."/admin/install/upgrades/";
$dir = @dir($dir_name);
$new_version = '';
$tmp1 = 0;
$tmp2 = 0;
while ($file = $dir->read()) {
if ($file != "." && $file != ".." && !is_dir($dir_name.$file))
{
$file = str_replace("inportal_upgrade_v", "", $file);
$file = str_replace(".sql", "", $file);
if ($file != '' && !strstr($file, 'changelog') && !strstr($file, 'readme')) {
$tmp1 = str_replace(".", "", $file);
if ($tmp1 > $tmp2) {
$new_version = $file;
}
}
}
$tmp2 = $tmp1;
}
$version_nrs = explode(".", $new_version);
for ($i = 0; $i < $version_nrs[0] + 1; $i++) {
for ($j = 0; $j < $version_nrs[1] + 1; $j++) {
for ($k = 0; $k < $version_nrs[2] + 1; $k++) {
$try_version = "$i.$j.$k";
$filename = $pathtoroot.$mod_name."/admin/install/upgrades/inportal_upgrade_v$try_version.sql";
if(file_exists($filename))
{
RunSQLFile($ado, $filename);
set_ini_value("Module Versions", $p, $try_version);
save_values();
}
}
}
}
$rs->MoveNext();
}
*/
$state="lang_select";
}
if($state=="modselect")
{
/* /admin/install.php */
$UrlLen = (strlen($admin) + 12)*-1;
$pathguess =substr($_SERVER["SCRIPT_NAME"],0,$UrlLen);
$sitepath = $pathguess;
$esc_path = str_replace("\\","/",$pathtoroot);
$esc_path = str_replace("/","\\",$esc_path);
//set_ini_value("Site","DomainName",$_SERVER["HTTP_HOST"]);
//$g_DomainName= $_SERVER["HTTP_HOST"];
save_values();
$ado =& inst_GetADODBConnection();
if(substr($sitepath,0,1)!="/")
$sitepath="/".$sitepath;
if(substr($sitepath,-1)!="/")
$sitepath .= "/";
$sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '$sitepath' WHERE VariableName='Site_Path'";
$ado->Execute($sql);
$sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '$g_Domain' WHERE VariableName='Server_Name'";
$ado->Execute($sql);
$sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '".$_SERVER['DOCUMENT_ROOT'].$sitepath.$admin."/backupdata' WHERE VariableName='Backup_Path'";
$ado->Execute($sql);
$Modules = a48d819089308a9aeb447e7248b2587f();
if (count($Modules) > 0) {
$include_file = $pathtoroot.$admin."/install/modselect.php";
}
else {
$state = "lang_select";
$skip_step = true;
}
}
if($state=="lang_select")
{
$Packs = GetLanguageList();
$include_file = $pathtoroot.$admin."/install/lang_select.php";
}
if(substr($state,0,10)=="postconfig")
{
$p = explode("_",$state);
$step = $p[1];
if ($_POST['Site_Path'] != '') {
$sql = "SELECT Name, Version FROM ".$g_TablePrefix."Modules";
$rs = $ado->Execute($sql);
$modules_str = '';
while ($rs && !$rs->EOF) {
$modules_str .= $rs->fields['Name'].' ('.$rs->fields['Version'].'),';
$rs->MoveNext();
}
$modules_str = substr($modules_str, 0, strlen($modules_str) - 1);
$rfile = @fopen(GET_LICENSE_URL."?url=".base64_encode($_SERVER['HTTP_HOST'].$_POST['Site_Path'])."&modules=".base64_encode($modules_str)."&license_code=".base64_encode($g_LicenseCode)."&version=".GetMaxPortalVersion($pathtoroot.$admin)."&domain=".md5($_SERVER['HTTP_HOST']), "r");
if (!$rfile) {
//$get_license_error = "Unable to connect to the Intechnic server! Please try again later!";
//$state = "postconfig_1";
//$include_file = $pathtoroot.$admin."/install/postconfig.php";
}
else {
$rcontents = '';
while (!feof($rfile)) {
$line = fgets($rfile, 10000);
$rcontents .= $line;
}
@fclose($rfile);
}
}
if(strlen($_POST["oldstate"])>0)
{
$s = explode("_",$_POST["oldstate"]);
$oldstep = $s[1];
if($oldstep<count($configs))
{
$section = $configs[$oldstep];
$module = $mods[$oldstep];
$title = $titles[$oldstep];
$objAdmin = new clsConfigAdmin($module,$section,TRUE);
$objAdmin->SaveItems($_POST,TRUE);
}
}
$section = $configs[$step];
$module = $mods[$step];
$title = $titles[$step];
$step++;
if($step <= count($configs)+1)
{
$include_file = $pathtoroot.$admin."/install/postconfig.php";
}
else
$state = "theme_sel";
}
if($state=="theme_sel")
{
$objThemes->CreateMissingThemes(true);
$include_file = $pathtoroot.$admin."/install/theme_select.php";
}
if($state=="theme_set")
{
## get & define Non-Blocking & Blocking versions ##
$blocking_sockets = minimum_php_version("4.3.0")? 0 : 1;
$ado =& inst_GetADODBConnection();
$sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '$blocking_sockets' WHERE VariableName='SocketBlockingMode'";
$ado->Execute($sql);
## get & define Non-Blocking & Blocking versions ##
$theme_id = $_POST["theme"];
$pathchar="/";
//$objThemes->SetPrimaryTheme($theme_id);
$t = $objThemes->GetItem($theme_id);
$t->Set("Enabled",1);
$t->Set("PrimaryTheme",1);
$t->Update();
$t->VerifyTemplates();
$include_file = $pathtoroot.$admin."/install/install_finish.php";
$state="finish";
}
if ($state == "adm_login") {
$ado =& inst_GetADODBConnection();
$sql = 'UPDATE '.TABLE_PREFIX.'UserSession
SET LastAccessed = 0
WHERE PortalUserId IN (0,-2)';
$ado->Execute($sql);
echo "<script>window.location='index.php';</script>";
}
if ($state == "finish") {
$ado =& inst_GetADODBConnection();
$PhraseTable = $g_TablePrefix."ImportPhrases";
$EventTable = $g_TablePrefix."ImportEvents";
$ado->Execute("DROP TABLE IF EXISTS $PhraseTable");
$ado->Execute("DROP TABLE IF EXISTS $EventTable");
$ado->Execute('INSERT INTO '.$g_TablePrefix.'Cache (VarName, Data) VALUES (\'ForcePermCacheUpdate\', \'1\')');
+ if ($application->ConfigValue('InstallFinished') === false) {
+ $fields_hash = Array (
+ 'VariableName' => 'InstallFinished',
+ 'VariableValue' => 1,
+ );
+ $application->Conn->doInsert($fields_hash, TABLE_PREFIX.'ConfigurationValues');
+ }
+
$include_file = $pathtoroot.$admin."/install/install_finish.php";
}
// init variables
$vars = Array('db_error','restore_error','PassError','DomainError','login_error','inst_error');
foreach($vars as $var_name) ReSetVar($var_name);
switch($state)
{
case "modselect":
$title = "Select Modules";
$help = "<p>Select the In-Portal modules you wish to install. The modules listed to the right ";
$help .="are all modules included in this installation that are licensed to run on this server. </p>";
break;
case "reinstall":
$title = "Installation Maintenance";
$help = "<p>A Configuration file has been detected on your system and it appears In-Portal is correctly installed. ";
$help .="In order to work with the maintenance functions provided to the left you must provide the Intechnic ";
$help .="Username and Password you used when obtaining the license file residing on the server, or your admin Root password. ";
$help .=" <i>(Use Username 'root' if using your root password)</i></p>";
$help .= "<p>To removing your existing database and start with a fresh installation, select the first option ";
$help .= "provided. Note that this operation cannot be undone and no backups are made! Use at your own risk.</p>";
$help .="<p>If you wish to scrap your current installation and install to a new location, choose the second option. ";
$help .="If this option is selected you will be prompted for new database configuration information.</p>";
$help .="<p>The <i>Update License Information</i> option is used to update your In-Portal license data. Select this option if you have ";
$help .="modified your licensing status with Intechnic, or you have received new license data via email</p>";
$help .="<p>The <i>Fix Paths</i> option should be used when the location of the In-portal files has changed. For example, if you moved them from one folder to another. It will update all settings and ensure the program is operational at the new location.</p>";
break;
case "fix_paths":
$title = "Fix Paths";
$help = "<p>The <i>Fix Paths</i> option should be used when the location of the In-portal files has changed. For example, if you moved them from one folder to another. It will update all settings and ensure the program is operational at the new location.<p>";
break;
case "RootPass":
$title = "Set Admin Root Password";
$help = "<p>The Root Password is initially required to access the admin sections of In-Portal. ";
$help .="The root user cannot be used to access the front-end of the system, so it is recommended that you ";
$help .="create additional users with admin privlidges.</p>";
break;
case "finish":
$title = "Thank You!";
$help ="<P>Thanks for using In-Portal! Be sure to visit <A TARGET=\"_new\" HREF=\"http://www.in-portal.net\">www.in-portal.net</A> ";
$help.=" for the latest news, module releases and support. </p>";
$help.="<p>*Make sure to clean your browser' cache after upgrading In-portal version</p>";
break;
case "license":
$title = "License Configuration";
$help ="<p>A License is required to run In-Portal on a server connected to the Internet. You ";
$help.="can run In-Portal on localhost, non-routable IP addresses, or other computers on your LAN. ";
$help.="If Intechnic has provided you with a license file, upload it here. Otherwise select the first ";
$help.="option to allow Install to download your license for you.</p>";
$help.="<p>If a valid license has been detected on your server, you can choose the <i>Use Existing License</i> ";
$help.="and continue the installation process</p>";
break;
case "domain_select":
$title="Select Licensed Domain";
$help ="<p>Select the domain you wish to configure In-Portal for. The <i>Other</i> option ";
$help.=" can be used to configure In-Portal for use on a local domain.</p>";
$help.="<p>For local domains, enter the hostname or LAN IP Address of the machine running In-Portal.</p>";
break;
case "db_reconfig":
case "dbinfo":
$title="Database Configuration";
$help = "<p>In-Portal needs to connect to your Database Server. Please provide the database server type*, ";
$help .="host name (<i>normally \"localhost\"</i>), Database user name, and database Password. ";
$help .="These fields are required to connect to the database.</p><p>If you would like In-Portal ";
$help .="to use a table prefix, enter it in the field provided. This prefix can be any ";
$help .=" text which can be used in the names of tables on your system. The characters entered in this field ";
$help .=" are placed <i>before</i> the names of the tables used by In-Portal. For example, if you enter \"inp_\"";
$help .=" into the prefix field, the table named Category will be named inp_Category.</p>";
break;
case "lang_select":
$title="Language Pack Installation";
$help = "<p>Select the language packs you wish to install. Each language pack contains all the phrases ";
$help .="used by the In-Portal administration and the default template set. Note that at least one ";
$help .="pack <b>must</b> be installed.</p>";
break;
case "lang_default":
$title="Select Default Language";
$help = "<p>Select which language should be considered the \"default\" language. This is the language ";
$help .="used by In-Portal when a language has not been selected by the user. This selection is applicable ";
$help .="to both the administration and front-end.</p>";
break;
case "lang_install":
$title="Installing Language Packs";
$help = "<p>The language packs you have selected are being installed. You may install more languages at a ";
$help.="later time from the Regional admin section.</p>";
break;
case "postconfig_1":
$help = "<P>These options define the general operation of In-Portal. Items listed here are ";
$help .="required for In-Portal's operation.</p><p>When you have finished, click <i>save</i> to continue.</p>";
break;
case "postconfig_2":
$help = "<P>User Management configuration options determine how In-Portal manages your user base.</p>";
$help .="<p>The groups listed to the right are pre-defined by the installation process and may be changed ";
$help .="through the Groups section of admin.</p>";
break;
case "postconfig_3":
$help = "<P>The options listed here are used to control the category list display functions of In-Portal. </p>";
break;
case "theme_sel":
$title="Select Default Theme";
$help = "<P>This theme will be used whenever a front-end session is started. ";
$help .="If you intend to upload a new theme and use that as default, you can do so through the ";
$help .="admin at a later date. A default theme is required for session management.</p>";
break;
case "get_license":
$title="Download License from Intechnic";
$help ="<p>A License is required to run In-Portal on a server connected to the Internet. You ";
$help.="can run In-Portal on localhost, non-routable IP addresses, or other computers on your LAN.</p>";
$help.="<p>Here as you have selected download license from Intechnic you have to input your username and ";
$help.="password of your In-Business account in order to download all your available licenses.</p>";
break;
case "download_license":
$title="Download License from Intechnic";
$help ="<p>A License is required to run In-Portal on a server connected to the Internet. You ";
$help.="can run In-Portal on localhost, non-routable IP addresses, or other computers on your LAN.</p>";
$help.="<p>Please choose the license from the drop down for this site! </p> ";
break;
case "restore_select":
$title="Select Restore File";
$help = "<P>Select the restore file to use to reinstall In-Portal. If your backups are not performed ";
$help .= "in the default location, you can enter the location of the backup directory and click the ";
$help .="<i>Update</i> button.</p>";
case "restore_run":
$title= "Restore in Progress";
$help = "<P>Restoration of your system is in progress. When the restore has completed, the installation ";
$help .="will continue as normal. Hitting the <i>Cancel</i> button will restart the entire installation process. ";
break;
case "warning":
$title = "Restore in Progress";
$help = "<p>Please approve that you understand that you are restoring your In-Portal data base from other version of In-Portal.</p>";
break;
case "update":
$title = "Update In-Portal";
$help = "<p>Select modules from the list, you need to update to the last downloaded version of In-Portal</p>";
break;
}
$tmp_step = GetVar('next_step', true);
if (!$tmp_step) {
$tmp_step = 1;
}
if ( isset($got_license) && $got_license == 1) {
$tmp_step++;
}
$next_step = $tmp_step + 1;
if ($general_error != '') {
$state = '';
$title = '';
$help = '';
$general_error = $general_error.'<br /><br />Installation cannot continue!';
}
if ($include_file == '' && $general_error == '' && $state == '') {
$state = '';
$title = '';
$help = '';
$filename = $pathtoroot.$admin."/install/inportal_remove.sql";
RunSQLFile($ado,$filename);
$general_error = 'Unexpected installation error! <br /><br />Installation has been stopped!';
}
if ($restore_error != '') {
$next_step = 3;
$tmp_step = 2;
}
if ($PassError != '') {
$tmp_step = 4;
$next_step = 5;
}
if ($DomainError != '') {
$tmp_step--;
$next_step = $tmp_step + 1;
}
if ($db_error != '') {
$tmp_step--;
$next_step = $tmp_step + 1;
}
if ($state == "warning") {
$tmp_step--;
$next_step = $tmp_step + 1;
}
if ($skip_step) {
$tmp_step++;
$next_step = $tmp_step + 1;
}
?>
<tr height="100%">
<td valign="top">
<table cellpadding=10 cellspacing=0 border=0 width="100%" height="100%">
<tr valign="top">
<td style="width: 200px; background: #009ff0 url(images/bg_install_menu.gif) no-repeat bottom right; border-right: 1px solid #000">
<img src="images/spacer.gif" width="180" height="1" border="0" title=""><br>
<span class="admintitle-white">Installation</span>
<!--<ol class="install">
<li class="current">Licence Verification
<li>Configuration
<li>File Permissions
<li>Security
<li>Integrity Check
</ol>
</td>-->
<?php
$lic_opt = isset($_POST['lic_opt']) ? $_POST['lic_opt'] : false;
if ($general_error == '') {
?>
<?php if ($install_type == 1) { ?>
<ol class="install">
<li <?php if ($tmp_step == 1) { ?>class="current"<?php } ?>>Database Configuration
<li <?php if ($tmp_step == 2 || $lic_opt == 1) { ?>class="current"<?php } ?>>Select License
<li <?php if ($tmp_step == 3 && $lic_opt != 1) { ?>class="current"<?php } ?>>Select Domain
<li <?php if ($tmp_step == 4 ) { ?>class="current"<?php } ?>>Set Root Password
<li <?php if ($tmp_step == 5) { ?>class="current"<?php } ?>>Select Modules to Install
<li <?php if ($tmp_step == 6) { ?>class="current"<?php } ?>>Install Language Packs
<li <?php if ($tmp_step == 7) { ?>class="current"<?php } ?>>Post-Install Configuration
<li <?php if ($tmp_step == 8) { ?>class="current"<?php } ?>>Finish
</ol>
<?php } else if ($install_type == 2) { ?>
<ol class="install">
<li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
<!--<li <?php if (($tmp_step == 2 && $login_error == '' && $inst_error == '') || $_POST['lic_opt'] == 1) { ?>class="current"<?php } ?>>Select License
<li <?php if ($tmp_step == 3 && $_POST['lic_opt'] != 1) { ?>class="current"<?php } ?>>Select Domain
<li <?php if ($tmp_step == 4) { ?>class="current"<?php } ?>>Set Root Password
<li <?php if ($tmp_step == 5) { ?>class="current"<?php } ?>>Select Modules to Install
<li <?php if ($tmp_step == 6) { ?>class="current"<?php } ?>>Install Language Packs
<li <?php if ($tmp_step == 7) { ?>class="current"<?php } ?>>Post-Install Configuration
<li <?php if ($tmp_step == 8) { ?>class="current"<?php } ?>>Finish-->
</ol>
<?php } else if ($install_type == 3) { ?>
<ol class="install">
<li>License Verification
<li <?php if ($tmp_step == 2) { ?>class="current"<?php } ?>>Database Configuration
<li <?php if ($tmp_step == 3 || $_POST['lic_opt'] == 1) { ?>class="current"<?php } ?>>Select License
<li <?php if ($tmp_step == 4 && $_POST['lic_opt'] != 1) { ?>class="current"<?php } ?>>Select Domain
<li <?php if ($tmp_step == 5) { ?>class="current"<?php } ?>>Set Root Password
<li <?php if ($tmp_step == 6) { ?>class="current"<?php } ?>>Select Modules to Install
<li <?php if ($tmp_step == 7) { ?>class="current"<?php } ?>>Install Language Packs
<li <?php if ($tmp_step == 8) { ?>class="current"<?php } ?>>Post-Install Configuration
<li <?php if ($tmp_step == 9) { ?>class="current"<?php } ?>>Finish
</ol>
<?php } else if ($install_type == 4) { ?>
<ol class="install">
<li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
<li <?php if (($tmp_step == 2 && $login_error == '' && $inst_error == '') || $lic_opt == 1) { ?>class="current"<?php } ?>>Select License
<li <?php if ($tmp_step == 3 && $_POST['lic_opt'] != 1) { ?>class="current"<?php } ?>>Select Domain
<li <?php if ($tmp_step == 4) { ?>class="current"<?php } ?>>Set Root Password
<li <?php if ($tmp_step == 5) { ?>class="current"<?php } ?>>Select Modules to Install
<li <?php if ($tmp_step == 6) { ?>class="current"<?php } ?>>Install Language Packs
<li <?php if ($tmp_step == 7) { ?>class="current"<?php } ?>>Post-Install Configuration
<li <?php if ($tmp_step == 8) { ?>class="current"<?php } ?>>Finish
</ol>
<?php } else if ($install_type == 5) { ?>
<ol class="install">
<li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
<li <?php if (($tmp_step == 2 && $login_error == '' && $inst_error == '') || $lic_opt == 1) { ?>class="current"<?php } ?>>Select License
<li <?php if ($tmp_step == 3 && $lic_opt != 1) { ?>class="current"<?php } ?>>Select Domain
<li <?php if ($tmp_step == 4) { ?>class="current"<?php } ?>>Finish
</ol>
<?php } else if ($install_type == 6) { ?>
<ol class="install">
<li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
<li <?php if (($tmp_step == 2 && $login_error == '' && $inst_error == '') || $_GET['show_prev'] == 1 || $_POST['backupdir']) { ?>class="current"<?php } ?>>Select Backup File
<li <?php if ($tmp_step == 3 && $_POST['lic_opt'] != 1 && $_GET['show_prev'] != 1 && !$_POST['backupdir']) { ?>class="current"<?php } ?>>Finish
</ol>
<?php } else if ($install_type == 7) { ?>
<ol class="install">
<li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
<li <?php if ($tmp_step == 2 && $login_error == '' && $inst_error == '') { ?>class="current"<?php } ?>>Database Configuration
<li <?php if ($tmp_step == 3) { ?>class="current"<?php } ?>>Finish
</ol>
<?php } else if ($install_type == 8) { ?>
<ol class="install">
<li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
<li <?php if ($tmp_step == 2 && $login_error == '' && $inst_error == '') { ?>class="current"<?php } ?>>Select Modules to Upgrade
<li <?php if ($tmp_step == 3) { ?>class="current"<?php } ?>>Language Pack Upgrade
<li <?php if ($tmp_step == 4) { ?>class="current"<?php } ?>>Finish
</ol>
<?php } else if ($install_type == 9) { ?>
<ol class="install">
<li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
<li <?php if ($tmp_step == 2 && $login_error == '' && $inst_error == '') { ?>class="current"<?php } ?>>Fix Paths
<li <?php if ($tmp_step == 3) { ?>class="current"<?php } ?>>Finish
</ol>
<?php } ?>
<?php include($include_file); ?>
<?php } else { ?>
<?php include("install/general_error.php"); ?>
<?php } ?>
<td width="40%" style="border-left: 1px solid #000; background: #f0f0f0">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="subsectiontitle" style="border-bottom: 1px solid #000000; background-color:#999"><?php if( isset($title) ) echo $title;?></td>
</tr>
<tr>
<td class="text"><?php if( isset($help) ) echo $help;?></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td id="footer">
Powered by In-portal &copy; 1997-2008, Intechnic Corporation. All rights reserved.
<br><img src="images/spacer.gif" width="1" height="10" title="">
</td>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file
Property changes on: branches/RC/admin/install.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.115.2.4
\ No newline at end of property
+1.115.2.5
\ No newline at end of property
Index: branches/RC/admin/index.php
===================================================================
--- branches/RC/admin/index.php (revision 10303)
+++ branches/RC/admin/index.php (revision 10304)
@@ -1,42 +1,46 @@
<?php
-$start = getmicrotime();
+ $start = getmicrotime();
-define('ADMIN', 1);
-define('FULL_PATH', realpath(dirname(__FILE__).'/..') );
-if (!file_exists(FULL_PATH.'/core/kernel/application.php')) {
- die('Please re-checkout _inportal_kernel4 cvs module into the root directory ('.FULL_PATH.') and remove kernel/kernel4 folder. Make sure to checkout correct branch (RC or HEAD).');
-}
-include_once(FULL_PATH.'/core/kernel/startup.php');
-
-/*
- kApplication $application
-*/
-$application =& kApplication::Instance();
-$application->Init();
-$application->Run();
-$application->Done();
-
-$end = getmicrotime();
-
-function getmicrotime()
-{
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
-}
-
-//update_memory_check_script();
-
-function update_memory_check_script() {
- $files = get_included_files();
- $script = '$files = Array('."\n";
- foreach ($files as $file_name) {
- $script .= "\t\t'".str_replace(FULL_PATH, '', $file_name)."',\n";
+ define('ADMIN', 1);
+ define('FULL_PATH', realpath(dirname(__FILE__).'/..') );
+ if (!file_exists(FULL_PATH.'/core/kernel/application.php')) {
+ die('Please re-checkout _inportal_kernel4 cvs module into the root directory ('.FULL_PATH.') and remove kernel/kernel4 folder. Make sure to checkout correct branch (RC or HEAD).');
}
- $script .= ");\n";
- echo "<pre>";
- echo $script;
- echo "</pre>";
-}
+ include_once(FULL_PATH.'/core/kernel/startup.php');
+
+ if (DIRECTORY_SEPARATOR != '\\') {
+ // force user to remove write permissions for important files (Linux only)
+ if (check_write_permissions(FULL_PATH.'/config.php') || check_write_permissions(FULL_PATH)) {
+ die('Please remove write permissions from "config.php" file and root website folder.');
+ }
+ }
+
+ $application =& kApplication::Instance();
+ $application->Init();
+ $application->Run();
+ $application->Done();
+
+ $end = getmicrotime();
+
+ function getmicrotime()
+ {
+ list($usec, $sec) = explode(" ", microtime());
+ return ((float)$usec + (float)$sec);
+ }
+
+ //update_memory_check_script();
+
+ function update_memory_check_script() {
+ $files = get_included_files();
+ $script = '$files = Array('."\n";
+ foreach ($files as $file_name) {
+ $script .= "\t\t'".str_replace(FULL_PATH, '', $file_name)."',\n";
+ }
+ $script .= ");\n";
+ echo "<pre>";
+ echo $script;
+ echo "</pre>";
+ }
?>
\ No newline at end of file
Property changes on: branches/RC/admin/index.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.26
\ No newline at end of property
+1.26.2.1
\ No newline at end of property
Index: branches/RC/admin/install/upgrades/inportal_upgrade_v4.3.0.php
===================================================================
--- branches/RC/admin/install/upgrades/inportal_upgrade_v4.3.0.php (nonexistent)
+++ branches/RC/admin/install/upgrades/inportal_upgrade_v4.3.0.php (revision 10304)
@@ -0,0 +1,11 @@
+<?php
+ $application =& kApplication::Instance();
+
+ if ($application->ConfigValue('InstallFinished') === false) {
+ $fields_hash = Array (
+ 'VariableName' => 'InstallFinished',
+ 'VariableValue' => 1,
+ );
+ $application->Conn->doInsert($fields_hash, TABLE_PREFIX.'ConfigurationValues');
+ }
+?>
\ No newline at end of file
Property changes on: branches/RC/admin/install/upgrades/inportal_upgrade_v4.3.0.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1.2.1
\ No newline at end of property
Index: branches/RC/core/kernel/utility/debugger.php
===================================================================
--- branches/RC/core/kernel/utility/debugger.php (revision 10303)
+++ branches/RC/core/kernel/utility/debugger.php (revision 10304)
@@ -1,1309 +1,1310 @@
<?php
if( !class_exists('Debugger') ) {
class Debugger {
/**
* Set to true if fatal error occured
*
* @var bool
*/
var $IsFatalError = false;
/**
* Debugger data for building report
*
* @var Array
*/
var $Data = Array();
var $ProfilerData = Array();
var $ProfilerTotals = Array();
var $ProfilerTotalCount = Array();
var $ProfilePoints = Array();
/**
* Prevent recursion when processing debug_backtrace() function results
*
* @var Array
*/
var $RecursionStack = Array();
var $scrollbarWidth = 0;
/**
* Long errors are saved here, because trigger_error doesn't support error messages over 1KB in size
*
* @var Array
*/
var $longErrors = Array();
var $IncludesData = Array();
var $IncludeLevel = 0;
var $reportDone = false;
/**
* Transparent spacer image used in case of none spacer image defined via SPACER_URL contant.
* Used while drawing progress bars (memory usage, time usage, etc.)
*
* @var string
*/
var $dummyImage = '';
/**
* Temporary files created by debugger will be stored here
*
* @var string
*/
var $tempFolder = '';
/**
* Debug rows will be separated using this string before writing to debug file
*
* @var string
*/
var $rowSeparator = '@@';
/**
* Base URL for debugger includes
*
* @var string
*/
var $baseURL = '';
function Debugger()
{
global $start, $dbg_options;
// check if user haven't defined DEBUG_MODE contant directly
if (defined('DEBUG_MODE') && DEBUG_MODE) {
die('error: contant DEBUG_MODE defined directly, please use <strong>$dbg_options</strong> array instead');
}
// check IP before enabling debug mode
$ip_match = $this->ipMatch(isset($dbg_options['DBG_IP']) ? $dbg_options['DBG_IP'] : '');
if (!$ip_match) {
define('DEBUG_MODE', 0);
return ;
}
// debug is allowed for user, continue initialization
$this->InitDebugger();
$this->profileStart('kernel4_startup', 'Startup and Initialization of kernel4', $start);
$this->profileStart('script_runtime', 'Script runtime', $start);
error_reporting(E_ALL);
ini_set('display_errors', $this->constOn('DBG_ZEND_PRESENT') ? 0 : 1); // show errors on screen in case if not in Zend Studio debugging
$this->scrollbarWidth = $this->isGecko() ? 22 : 25; // vertical scrollbar width differs in Firefox and other browsers
$this->appendRequest();
}
/**
* Checks, that user IP address is within allowed range
*
* @param string $ip_list semi-column (by default) separated ip address list
* @param string $separator ip address separator (default ";")
*
* @return bool
*/
function ipMatch($ip_list, $separator = ';')
{
$ip_match = false;
$ip_addresses = $ip_list ? explode($separator, $ip_list) : Array ();
foreach ($ip_addresses as $ip_address) {
if ($this->netMatch($ip_address, $_SERVER['REMOTE_ADDR'])) {
$ip_match = true;
break;
}
}
return $ip_match;
}
/**
* Set's default values to constants debugger uses
*
*/
function InitDebugger()
{
global $dbg_options;
unset($_REQUEST['debug_host'], $_REQUEST['debug_fastfile'], $dbg_options['DBG_IP']); // this var messed up whole detection stuff :(
// Detect fact, that this session beeing debugged by Zend Studio
foreach ($_REQUEST as $rq_name => $rq_value) {
if (substr($rq_name, 0, 6) == 'debug_') {
$this->safeDefine('DBG_ZEND_PRESENT', 1);
break;
}
}
$this->safeDefine('DBG_ZEND_PRESENT', 0); // set this constant value to 0 (zero) to debug debugger using Zend Studio
// set default values for debugger constants
$dbg_constMap = Array(
'DBG_USE_HIGHLIGHT' => 1, // highlight output same as php code using "highlight_string" function
'DBG_WINDOW_WIDTH' => 700, // set width of debugger window (in pixels) for better viewing large amount of debug data
'DBG_USE_SHUTDOWN_FUNC' => DBG_ZEND_PRESENT ? 0 : 1, // use shutdown function to include debugger code into output
'DBG_HANDLE_ERRORS' => DBG_ZEND_PRESENT ? 0 : 1, // handle all allowed by php (see php manual) errors instead of default handler
'DBG_IGNORE_STRICT_ERRORS' => 1, // ignore PHP5 errors about private/public view modified missing in class declarations
'DBG_DOMVIEWER' => '/temp/domviewer.html', // path to DOMViewer on website
'DOC_ROOT' => str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT']) ), // windows hack
'DBG_LOCAL_BASE_PATH' => 'w:', // replace DOC_ROOT in filenames (in errors) using this path
);
// only for IE, in case if no windows php script editor defined
if (!defined('DBG_EDITOR')) {
// $dbg_constMap['DBG_EDITOR'] = 'c:\Program Files\UltraEdit\uedit32.exe %F/%L';
$dbg_constMap['DBG_EDITOR'] = 'c:\Program Files\Zend\ZendStudio-5.2.0\bin\ZDE.exe %F';
}
if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] && constOn('DBG_SKIP_AJAX')) {
$this->safeDefine('DBG_SKIP_REPORTING', 1);
}
// user defined options override debugger defaults
$dbg_constMap = $this->array_merge_recursive2($dbg_constMap, $dbg_options);
// when validation configs, don't show sqls for better validation error displaying
if (array_key_exists('DBG_VALIDATE_CONFIGS', $dbg_constMap) && $dbg_constMap['DBG_VALIDATE_CONFIGS']) {
$dbg_constMap['DBG_SQL_PROFILE'] = 0;
}
foreach ($dbg_constMap as $dbg_constName => $dbg_constValue) {
$this->safeDefine($dbg_constName, $dbg_constValue);
}
}
function constOn($const_name)
{
return defined($const_name) && constant($const_name);
}
function safeDefine($const_name, $const_value) {
if (!defined($const_name)) {
define($const_name, $const_value);
}
}
function array_merge_recursive2($paArray1, $paArray2)
{
if (!is_array($paArray1) or !is_array($paArray2)) {
return $paArray2;
}
foreach ($paArray2 AS $sKey2 => $sValue2) {
$paArray1[$sKey2] = isset($paArray1[$sKey2]) ? array_merge_recursive2($paArray1[$sKey2], $sValue2) : $sValue2;
}
return $paArray1;
}
function netMatch($network, $ip) {
$network = trim($network);
$ip = trim($ip);
if ($network == $ip) {
// comparing 2 ip addresses directly
return true;
}
$d = strpos($network, '-');
if ($d === false) {
// sigle subnet specified
$ip_arr = explode('/', $network);
if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)) {
$ip_arr[0] .= '.0'; // Alternate form 194.1.4/24
}
$network_long = ip2long($ip_arr[0]);
$x = ip2long($ip_arr[1]);
$mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1]));
$ip_long = ip2long($ip);
return ($ip_long & $mask) == ($network_long & $mask);
}
else {
// ip address range specified
$from = ip2long(trim(substr($network, 0, $d)));
$to = ip2long(trim(substr($network, $d + 1)));
$ip = ip2long($ip);
return ($ip >= $from && $ip <= $to);
}
}
function InitReport()
{
if (!class_exists('kApplication')) return false;
$application =& kApplication::Instance();
// string used to separate debugger records while in file (used in debugger dump filename too)
$this->rowSeparator = '@'.(is_object($application->Factory) ? $application->GetSID() : 0).'@';
// include debugger files from this url
$reg_exp = '/^'.preg_quote(FULL_PATH, '/').'/';
$kernel_path = preg_replace($reg_exp, '', KERNEL_PATH, 1);
$this->baseURL = PROTOCOL.SERVER_NAME.rtrim(BASE_PATH, '/').$kernel_path.'/utility/debugger';
// save debug output in this folder
$this->tempFolder = defined('WRITEABLE') ? WRITEABLE.'/cache' : FULL_PATH.'/kernel/cache';
}
function mapLongError($msg)
{
$key = $this->generateID();
$this->longErrors[$key] = $msg;
return $key;
}
/**
* Appends all passed variable values (wihout variable names) to debug output
*
*/
function dumpVars()
{
$dump_mode = 'var_dump';
$dumpVars = func_get_args();
if ($dumpVars[count($dumpVars) - 1] === 'STRICT') {
$dump_mode = 'strict_var_dump';
array_pop($dumpVars);
}
foreach ($dumpVars as $varValue) {
$this->Data[] = Array('value' => $varValue, 'debug_type' => $dump_mode);
}
}
function prepareHTML($dataIndex)
{
$Data =& $this->Data[$dataIndex];
if ($Data['debug_type'] == 'html') {
return $Data['html'];
}
switch ($Data['debug_type']) {
case 'error':
$fileLink = $this->getFileLink($Data['file'], $Data['line']);
$ret = '<b class="debug_error">'.$this->getErrorNameByCode($Data['no']).'</b>: '.$Data['str'];
$ret .= ' in <b>'.$fileLink.'</b> on line <b>'.$Data['line'].'</b>';
return $ret;
break;
case 'var_dump':
return $this->highlightString( $this->print_r($Data['value'], true) );
break;
case 'strict_var_dump':
return $this->highlightString( var_export($Data['value'], true) );
break;
case 'trace':
ini_set('memory_limit', '500M');
$trace =& $Data['trace'];
$i = 0; $traceCount = count($trace);
$ret = '';
while ($i < $traceCount) {
$traceRec =& $trace[$i];
$argsID = 'trace_args_'.$dataIndex.'_'.$i;
$has_args = isset($traceRec['args']);
if (isset($traceRec['file'])) {
$func_name = isset($traceRec['class']) ? $traceRec['class'].$traceRec['type'].$traceRec['function'] : $traceRec['function'];
$args_link = $has_args ? '<a href="javascript:$Debugger.ToggleTraceArgs(\''.$argsID.'\');" title="Show/Hide Function Arguments"><b>Function</b></a>' : '<b>Function</b>';
$ret .= $args_link.': '.$this->getFileLink($traceRec['file'], $traceRec['line'], $func_name);
$ret .= ' in <b>'.basename($traceRec['file']).'</b> on line <b>'.$traceRec['line'].'</b><br>';
}
else {
$ret .= 'no file information available';
}
if ($has_args) {
// if parameter value is longer then 200 symbols, then leave only first 50
$args = $this->highlightString($this->print_r($traceRec['args'], true));
$ret .= '<div id="'.$argsID.'" style="display: none;">'.$args.'</div>';
}
$i++;
}
return $ret;
break;
case 'profiler':
$profileKey = $Data['profile_key'];
$Data =& $this->ProfilerData[$profileKey];
$runtime = ($Data['ends'] - $Data['begins']); // in seconds
$totals_key = getArrayValue($Data, 'totalsKey');
if ($totals_key) {
$total_before = $Data['totalsBefore'];
$total = $this->ProfilerTotals[$totals_key];
$div_width = Array();
$total_width = ($this->getWindowWidth() - 10);
$div_width['before'] = round(($total_before / $total) * $total_width);
$div_width['current'] = round(($runtime / $total) * $total_width);
$div_width['left'] = round((($total - $total_before - $runtime) / $total) * $total_width);
$ret = '<b>Name</b>: '.$Data['description'].'<br />';
$additional = isset($Data['additional']) ? $Data['additional'] : Array ();
if (isset($Data['file'])) {
array_unshift($additional, Array('name' => 'File', 'value' => $this->getFileLink($Data['file'], $Data['line'], basename($Data['file']).':'.$Data['line'])));
}
array_unshift($additional, Array('name' => 'Runtime', 'value' => $runtime.'s'));
foreach ($additional as $mixed_param) {
$ret .= '[<strong>'.$mixed_param['name'].'</strong>: '.$mixed_param['value'].'] ';
}
/*if (isset($Data['file'])) {
$ret .= '[<b>Runtime</b>: '.$runtime.'s] [<b>File</b>: '.$this->getFileLink($Data['file'], $Data['line'], basename($Data['file']).':'.$Data['line']).']<br />';
}
else {
$ret .= '<b>Runtime</b>: '.$runtime.'s<br />';
}*/
$ret .= '<div class="dbg_profiler" style="width: '.$div_width['before'].'px; border-right: 0px; background-color: #298DDF;"><img src="'.$this->dummyImage.'" width="1" height="1"/></div>';
$ret .= '<div class="dbg_profiler" style="width: '.$div_width['current'].'px; border-left: 0px; border-right: 0px; background-color: #EF4A4A;"><img src="'.$this->dummyImage.'" width="1" height="1"/></div>';
$ret .= '<div class="dbg_profiler" style="width: '.$div_width['left'].'px; border-left: 0px; background-color: #DFDFDF;"><img src="'.$this->dummyImage.'" width="1" height="1"/></div>';
return $ret;
}
else {
return '<b>Name</b>: '.$Data['description'].'<br><b>Runtime</b>: '.$runtime.'s';
}
break;
default:
return 'incorrect debug data';
break;
}
}
function getWindowWidth()
{
return DBG_WINDOW_WIDTH - $this->scrollbarWidth - 8;
}
/**
* Tells debugger to skip objects that are heavy in plan of memory usage while printing debug_backtrace results
*
* @param Object $object
* @return bool
*/
function IsBigObject(&$object)
{
$skip_classes = Array(
defined('APPLICATION_CLASS') ? APPLICATION_CLASS : 'kApplication',
'kFactory',
'kUnitConfigReader',
'TemplateParser',
);
foreach ($skip_classes as $class_name) {
if (strtolower(get_class($object)) == strtolower($class_name)) {
return true;
}
}
return false;
}
/**
* Advanced version of print_r (for debugger only). Don't print objects recursively
*
* @param Array $array
* @param bool $return_output return output or print it out
* @param int $tab_count offset in tabs
* @return string
*/
function print_r(&$array, $return_output = false, $tab_count = -1)
{
static $first_line = true;
// not an array at all
if (!is_array($array)) {
switch (gettype($array)) {
case 'NULL':
return 'NULL'."\n";
break;
case 'object':
return $this->processObject($array, $tab_count);
break;
default:
// number or string
if (mb_strlen($array) > 200) {
$array = mb_substr($array, 0, 50).' ...';
}
return $array."\n";
break;
}
}
$output = '';
$tab_count++;
$output .= "Array\n".str_repeat(' ', $tab_count)."(\n";
$tab_count++;
$tabsign = $tab_count ? str_repeat(' ', $tab_count) : '';
$array_keys = array_keys($array);
foreach ($array_keys as $key) {
switch (gettype($array[$key])) {
case 'array':
$output .= $tabsign.'['.$key.'] = '.$this->print_r($array[$key], true, $tab_count);
break;
case 'boolean':
$output .= $tabsign.'['.$key.'] = '.($array[$key] ? 'true' : 'false')."\n";
break;
case 'integer':
case 'double':
case 'string':
if (mb_strlen($array[$key]) > 200) {
$array[$key] = mb_substr($array[$key], 0, 50).' ...';
}
$output .= $tabsign.'['.$key.'] = '.$array[$key]."\n";
break;
case 'NULL':
$output .= $tabsign.'['.$key."] = NULL\n";
break;
case 'object':
$output .= $tabsign.'['.$key."] = ";
$output .= "Object (".get_class($array[$key]).") = \n".str_repeat(' ', $tab_count + 1)."(\n";
$output .= $this->processObject($array[$key], $tab_count + 2);
$output .= str_repeat(' ', $tab_count + 1).")\n";
break;
default:
$output .= $tabsign.'['.$key.'] unknown = '.gettype($array[$key])."\n";
break;
}
}
$tab_count--;
$output .= str_repeat(' ', $tab_count).")\n";
if ($first_line) {
$first_line = false;
$output .= "\n";
}
$tab_count--;
if ($return_output) {
return $output;
}
else {
echo $output;
}
return true;
}
function processObject(&$object, $tab_count)
{
$object_class = get_class($object);
if (!in_array($object_class, $this->RecursionStack)) {
if ($this->IsBigObject($object)) {
return 'SKIPPED (class: '.$object_class.")\n";
}
$attribute_names = get_class_vars($object_class);
if (!$attribute_names) {
return "NO_ATTRIBUTES\n";
}
else {
$output = '';
array_push($this->RecursionStack, $object_class);
$tabsign = $tab_count ? str_repeat(' ', $tab_count) : '';
foreach ($attribute_names as $attribute_name => $attribute_value) {
if (is_object($object->$attribute_name)) {
// it is object
$output .= $tabsign.'['.$attribute_name.'] = '.$this->processObject($object->$attribute_name, $tab_count + 1);
}
else {
$output .= $tabsign.'['.$attribute_name.'] = '.$this->print_r($object->$attribute_name, true, $tab_count);
}
}
array_pop($this->RecursionStack);
return $output;
}
}
else {
// object [in recursion stack]
return '*** RECURSION *** (class: '.$object_class.")\n";
}
}
/**
* Format SQL Query using predefined formatting
* and highlighting techniques
*
* @param string $sql
* @return string
*/
function formatSQL($sql)
{
$sql = preg_replace('/(\n|\t| )+/is', ' ', $sql);
$sql = preg_replace('/(CREATE TABLE|DROP TABLE|SELECT|UPDATE|SET|REPLACE|INSERT|DELETE|VALUES|FROM|LEFT JOIN|INNER JOIN|LIMIT|WHERE|HAVING|GROUP BY|ORDER BY) /is', "\n\t$1 ", $sql);
return $this->highlightString($sql);
}
function highlightString($string)
{
if (!$this->constOn('DBG_USE_HIGHLIGHT')) {
return $string;
}
$string = str_replace( Array('\\', '/') , Array('_no_match_string_', '_n_m_s_'), $string);
$string = highlight_string('<?php'.$string.'?>', true);
$string = str_replace( Array('_no_match_string_', '_n_m_s_'), Array('\\', '/'), $string);
return preg_replace('/&lt;\?(.*)php(.*)\?&gt;/Us', '\\2', $string);
}
/**
* Determine by php type of browser used to show debugger
*
* @return bool
*/
function isGecko()
{
// we need isset because we may run scripts from shell with no user_agent at all
return isset($_SERVER['HTTP_USER_AGENT']) && mb_strpos(mb_strtolower($_SERVER['HTTP_USER_AGENT']), 'firefox') !== false;
}
/**
* Returns link for editing php file (from error) in external editor
*
* @param string $file filename with path from root folder
* @param int $lineno line number in file where error is found
* @param string $title text to show on file edit link
* @return string
*/
function getFileLink($file, $lineno = 1, $title = '')
{
if (!$title) {
$title = str_replace('/', '\\', $this->getLocalFile($file));
}
if ($this->isGecko()) {
return '<a href="file://'.$this->getLocalFile($file).'">'.$title.'</a>';
}
else {
return '<a href="javascript:$Debugger.editFile(\''.$this->getLocalFile($file).'\', '.$lineno.');" title="'.$file.'">'.$title.'</a>';
}
}
/**
* Converts filepath on server to filepath in mapped DocumentRoot on developer pc
*
* @param string $remoteFile
* @return string
*/
function getLocalFile($remoteFile)
{
return preg_replace('/^'.preg_quote(DOC_ROOT, '/').'/', DBG_LOCAL_BASE_PATH, $remoteFile, 1);
}
/**
* Appends call trace till this method call
*
*/
function appendTrace()
{
$trace = debug_backtrace();
array_shift($trace);
$this->Data[] = Array('trace' => $trace, 'debug_type' => 'trace');
}
function appendMemoryUsage($msg, $used = null)
{
if (!isset($used)) {
$used = round(memory_get_usage() / 1024);
}
$this->appendHTML('<b>Memory usage</b> '.$msg.' '.$used.'Kb');
}
/**
* Appends HTML code whithout transformations
*
* @param string $html
*/
function appendHTML($html)
{
$this->Data[] = Array('html' => $html, 'debug_type' => 'html');
}
/**
* Change debugger info that was already generated before.
* Returns true if html was set.
*
* @param int $index
* @param string $html
* @param string $type = {'append','prepend','replace'}
* @return bool
*/
function setHTMLByIndex($index, $html, $type = 'append')
{
if (!isset($this->Data[$index]) || $this->Data[$index]['debug_type'] != 'html') {
return false;
}
switch ($type) {
case 'append':
$this->Data[$index]['html'] .= '<br>'.$html;
break;
case 'prepend':
$this->Data[$index]['html'] = $this->Data[$index]['html'].'<br>'.$html;
break;
case 'replace':
$this->Data[$index]['html'] = $html;
break;
}
return true;
}
/**
* Move $debugLineCount lines of input from debug output
* end to beginning.
*
* @param int $debugLineCount
*/
function moveToBegin($debugLineCount)
{
$lines = array_splice($this->Data,count($this->Data)-$debugLineCount,$debugLineCount);
$this->Data = array_merge($lines,$this->Data);
}
function moveAfterRow($new_row, $debugLineCount)
{
$lines = array_splice($this->Data,count($this->Data)-$debugLineCount,$debugLineCount);
$rows_before = array_splice($this->Data,0,$new_row,$lines);
$this->Data = array_merge($rows_before,$this->Data);
}
function appendRequest()
{
if (isset($_SERVER['SCRIPT_FILENAME'])) {
$script = $_SERVER['SCRIPT_FILENAME'];
}
else {
$script = $_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF'];
}
$this->appendHTML('ScriptName: <b>'.$this->getFileLink($script, 1, basename($script)).'</b> (<b>'.dirname($script).'</b>)');
if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] == 'yes') {
$this->appendHTML('RequestURI: '.$_SERVER['REQUEST_URI'].' (QS Length:'.mb_strlen($_SERVER['QUERY_STRING']).')');
}
$this->appendHTML('<a href="http://www.brainjar.com/dhtml/domviewer/" target="_blank">DomViewer</a>: <input id="dbg_domviewer" type="text" value="window" style="border: 1px solid #000000;"/>&nbsp;<button class="button" onclick="return $Debugger.OpenDOMViewer();">Show</button>');
ob_start();
?>
<table border="0" cellspacing="0" cellpadding="0" class="dbg_flat_table" style="width: <?php echo $this->getWindowWidth(); ?>px;">
<thead style="font-weight: bold;">
<td width="20">Src</td><td>Name</td><td>Value</td>
</thead>
<?php
foreach ($_REQUEST as $key => $value) {
if(!is_array($value) && trim($value) == '') {
$value = '<b class="debug_error">no value</b>';
}
else {
$value = htmlspecialchars($this->print_r($value, true));
}
$in_cookie = isset($_COOKIE[$key]);
$src = isset($_GET[$key]) && !$in_cookie ? 'GE' : (isset($_POST[$key]) && !$in_cookie ? 'PO' : ($in_cookie ? 'CO' : '?') );
echo '<tr><td>'.$src.'</td><td>'.$key.'</td><td>'.$value.'</td></tr>';
}
?>
</table>
<?php
$this->appendHTML(ob_get_contents());
ob_end_clean();
}
/**
* Appends php session content to debugger output
*
*/
function appendSession()
{
if (isset($_SESSION) && $_SESSION) {
$this->appendHTML('PHP Session: [<b>'.ini_get('session.name').'</b>]');
$this->dumpVars($_SESSION);
$this->moveToBegin(2);
}
}
function profileStart($key, $description = null, $timeStamp = null)
{
if (!isset($timeStamp)) {
$timeStamp = $this->getMoment();
}
$this->ProfilerData[$key] = Array('begins' => $timeStamp, 'ends' => 5000, 'debuggerRowID' => count($this->Data));
if (isset($description)) {
$this->ProfilerData[$key]['description'] = $description;
}
if (substr($key, 0, 4) == 'sql_') {
// append place from what was called
$trace_results = debug_backtrace();
$trace_count = count($trace_results);
$i = 0;
while ($i < $trace_count) {
$trace_file = basename($trace_results[$i]['file']);
if ($trace_file != 'db_connection.php' && $trace_file != 'adodb.inc.php') {
break;
}
$i++;
}
$this->ProfilerData[$key]['file'] = $trace_results[$i]['file'];
$this->ProfilerData[$key]['line'] = $trace_results[$i]['line'];
unset($trace_results);
}
$this->Data[] = Array('profile_key' => $key, 'debug_type' => 'profiler');
}
function profileFinish($key, $description = null, $timeStamp = null)
{
if (!isset($timeStamp)) {
$timeStamp = $this->getMoment();
}
$this->ProfilerData[$key]['ends'] = $timeStamp;
if (isset($description)) {
$this->ProfilerData[$key]['description'] = $description;
}
if (substr($key, 0, 4) == 'sql_') {
$func_arguments = func_get_args();
$rows_affected = $func_arguments[3];
if ($rows_affected > 0) {
$additional = Array (
Array ('name' => 'Affected Rows', 'value' => $rows_affected),
);
if (isset($func_arguments[4])) {
$additional[] = Array ('name' => 'Result', 'value' => $func_arguments[4]);
}
$this->ProfilerData[$key]['additional'] =& $additional;
}
}
}
function profilerAddTotal($total_key, $key = null, $value = null)
{
if (!isset($this->ProfilerTotals[$total_key])) {
$this->ProfilerTotals[$total_key] = 0;
$this->ProfilerTotalCount[$total_key] = 0;
}
if (!isset($value)) {
$value = $this->ProfilerData[$key]['ends'] - $this->ProfilerData[$key]['begins'];
}
if (isset($key)) {
$this->ProfilerData[$key]['totalsKey'] = $total_key;
$this->ProfilerData[$key]['totalsBefore'] = $this->ProfilerTotals[$total_key];
}
$this->ProfilerTotals[$total_key] += $value;
$this->ProfilerTotalCount[$total_key]++;
}
function getMoment()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
function generateID()
{
list($usec, $sec) = explode(' ', microtime());
$id_part_1 = substr($usec, 4, 4);
$id_part_2 = mt_rand(1,9);
$id_part_3 = substr($sec, 6, 4);
$digit_one = substr($id_part_1, 0, 1);
if ($digit_one == 0) {
$digit_one = mt_rand(1,9);
$id_part_1 = ereg_replace("^0",'',$id_part_1);
$id_part_1=$digit_one.$id_part_1;
}
return $id_part_1.$id_part_2.$id_part_3;
}
function getErrorNameByCode($error_code)
{
$error_map = Array(
'Fatal Error' => Array(E_USER_ERROR),
'Warning' => Array(E_WARNING, E_USER_WARNING),
'Notice' => Array(E_NOTICE, E_USER_NOTICE),
);
if (defined('E_STRICT')) {
$error_map['PHP5 Strict'] = Array(E_STRICT);
}
if (defined('E_RECOVERABLE_ERROR')) {
$error_map['Fatal Error (recoverable)'] = Array(E_RECOVERABLE_ERROR);
}
foreach ($error_map as $error_name => $error_codes) {
if (in_array($error_code, $error_codes)) {
return $error_name;
}
}
return '';
}
/**
* Returns profile total key (check against unexisting key too)
*
* @param string $key
* @return int
*/
function getProfilerTotal($key)
{
if (isset($this->ProfilerTotalCount[$key])) {
return (int)$this->ProfilerTotalCount[$key];
}
return 0;
}
function ProfilePoint($title, $level=1)
{
$trace_results = debug_backtrace();
$level = min($level,count($trace_results)-1);
do {
$point = $trace_results[$level];
$location = $point['file'].':'.$point['line'];
$level++;
$has_more = isset($trace_results[$level]);
} while ($has_more && $point['function'] == $trace_results[$level]['function'] );
if ($location == ':') {
echo '';
}
if (!isset($this->ProfilePoints[$title])) {
$this->ProfilePoints[$title] = array();
}
if (!isset($this->ProfilePoints[$title][$location])) {
$this->ProfilePoints[$title][$location] = 0;
}
$this->ProfilePoints[$title][$location]++;
}
/**
* Generates report
*
*/
function printReport($returnResult = false, $clean_output_buffer = true)
{
if ($this->reportDone) {
// don't print same report twice (in case if shutdown function used + compression + fatal error)
return '';
}
$this->profileFinish('script_runtime');
$this->breakOutofBuffering();
$debugger_start = memory_get_usage();
if (defined('SPACER_URL')) {
$this->dummyImage = SPACER_URL;
}
$this->InitReport(); // set parameters required by AJAX
// defined here, because user can define this contant while script is running, not event before debugger is started
$this->safeDefine('DBG_RAISE_ON_WARNINGS', 0);
$this->safeDefine('DBG_TOOLBAR_BUTTONS', 1);
$this->appendSession(); // show php session if any
// ensure, that 1st line of debug output always is this one:
$top_line = '<table cellspacing="0" cellpadding="0" style="width: '.$this->getWindowWidth().'px; margin: 0px;"><tr><td align="left" width="50%">[<a href="javascript:window.location.reload();">Reload Frame</a>] [<a href="javascript:$Debugger.Toggle(27);">Hide Debugger</a>]</td><td align="right" width="50%">[Current Time: <b>'.date('H:i:s').'</b>] [File Size: <b>#DBG_FILESIZE#</b>]</td></tr></table>';
$this->appendHTML($top_line);
$this->moveToBegin(1);
if (count($this->ProfilePoints)>0) {
foreach($this->ProfilePoints as $point => $locations) {
arsort($this->ProfilePoints[$point]);
}
$this->appendHTML($this->highlightString($this->print_r($this->ProfilePoints, true)));
/*foreach ($this->ProfilePoints as $point => $locations) {
foreach ($locations as $location => $occurences) {
}
}*/
}
if ($this->constOn('DBG_SQL_PROFILE') && isset($this->ProfilerTotals['sql'])) {
// sql query profiling was enabled -> show totals
$this->appendHTML('<b>SQL Total time:</b> '.$this->ProfilerTotals['sql'].' <b>Number of queries</b>: '.$this->ProfilerTotalCount['sql']);
}
if ($this->constOn('DBG_PROFILE_INCLUDES') && isset($this->ProfilerTotals['includes'])) {
// included file profiling was enabled -> show totals
$this->appendHTML('<b>Included Files Total time:</b> '.$this->ProfilerTotals['includes'].' Number of includes: '.$this->ProfilerTotalCount['includes']);
}
if ($this->constOn('DBG_PROFILE_MEMORY')) {
// detailed memory usage reporting by objects was enabled -> show totals
$this->appendHTML('<b>Memory used by Objects:</b> '.round($this->ProfilerTotals['objects'] / 1024, 2).'Kb');
}
if ($this->constOn('DBG_INCLUDED_FILES')) {
$files = get_included_files();
$this->appendHTML('<b>Included files:</b>');
foreach ($files as $file) {
$this->appendHTML($this->getFileLink($this->getLocalFile($file)).' ('.round(filesize($file) / 1024, 2).'Kb)');
}
}
/*if ($this->constOn('DBG_PROFILE_INCLUDES')) {
$this->appendHTML('<b>Included files statistics:</b>'.( $this->constOn('DBG_SORT_INCLUDES_MEM') ? ' (sorted by memory usage)':''));
$totals = Array( 'mem' => 0, 'time' => 0);
$totals_configs = Array( 'mem' => 0, 'time' => 0);
if (is_array($this->IncludesData['mem'])) {
if ( $this->constOn('DBG_SORT_INCLUDES_MEM') ) {
array_multisort($this->IncludesData['mem'], SORT_DESC, $this->IncludesData['file'], $this->IncludesData['time'], $this->IncludesData['level']);
}
foreach ($this->IncludesData['file'] as $key => $file_name) {
$this->appendHTML( str_repeat('&nbsp;->&nbsp;', ($this->IncludesData['level'][$key] >= 0 ? $this->IncludesData['level'][$key] : 0)).$file_name.' Mem: '.sprintf("%.4f Kb", $this->IncludesData['mem'][$key]/1024).' Time: '.sprintf("%.4f", $this->IncludesData['time'][$key]));
if ($this->IncludesData['level'][$key] == 0) {
$totals['mem'] += $this->IncludesData['mem'][$key];
$totals['time'] += $this->IncludesData['time'][$key];
}
else if ($this->IncludesData['level'][$key] == -1) {
$totals_configs['mem'] += $this->IncludesData['mem'][$key];
$totals_configs['time'] += $this->IncludesData['time'][$key];
}
}
$this->appendHTML('<b>Sub-Total classes:</b> '.' Mem: '.sprintf("%.4f Kb", $totals['mem']/1024).' Time: '.sprintf("%.4f", $totals['time']));
$this->appendHTML('<b>Sub-Total configs:</b> '.' Mem: '.sprintf("%.4f Kb", $totals_configs['mem']/1024).' Time: '.sprintf("%.4f", $totals_configs['time']));
$this->appendHTML('<span class="error"><b>Grand Total:</b></span> '.' Mem: '.sprintf("%.4f Kb", ($totals['mem']+$totals_configs['mem'])/1024).' Time: '.sprintf("%.4f", $totals['time']+$totals_configs['time']));
}
}*/
$is_ajax = isset($_GET['ajax']) && $_GET['ajax'] == 'yes';
$skip_reporting = $this->constOn('DBG_SKIP_REPORTING') || $this->constOn('DBG_ZEND_PRESENT');
if (($is_ajax && !constOn('DBG_SKIP_AJAX')) || !$skip_reporting) {
$debug_file = $this->tempFolder.'/debug_'.$this->rowSeparator.'.txt';
if (file_exists($debug_file)) unlink($debug_file);
$i = 0;
$fp = fopen($debug_file, 'a');
$lineCount = count($this->Data);
while ($i < $lineCount) {
fwrite($fp, $this->prepareHTML($i).$this->rowSeparator);
$i++;
}
fclose($fp);
}
if ($skip_reporting) {
// let debugger write report and then don't output anything
$this->reportDone = true;
return '';
}
$dbg_path = str_replace(FULL_PATH, '', $this->tempFolder);
ob_start();
// the <script .. /script> and hidden div helps browser to break out of script tag or attribute esacped
// with " or ' in case fatal error (or user-error) occurs inside it in compiled template,
// otherwise it has no effect
?>
<div style="display: none" x='nothing'><script></script></div><html><body></body></html>
<script type="text/javascript" src="<?php echo $this->baseURL; ?>/debugger.js"></script>
<link rel="stylesheet" rev="stylesheet" href="<?php echo $this->baseURL; ?>/debugger.css" type="text/css" media="screen" />
<div id="debug_layer" class="debug_layer_container" style="display: none; width: <?php echo DBG_WINDOW_WIDTH; ?>px;">
<div class="debug_layer" style="width: <?php echo $this->getWindowWidth(); ?>px;">
<table width="100%" cellpadding="0" cellspacing="1" border="0" class="debug_layer_table" style="width: <?php echo $this->getWindowWidth(); ?>px;" align="left">
<tbody id="debug_table"></tbody>
</table>
</div>
</div>
<script type="text/javascript">
var $Debugger = new Debugger(<?php echo "'".$this->rowSeparator."', ".$this->getProfilerTotal('error_handling').', '.($this->IsFatalError ? 'true' : 'false').', '.$this->getProfilerTotal('sql'); ?>);
$Debugger.DOMViewerURL = '<?php echo constant('DBG_DOMVIEWER'); ?>';
$Debugger.EditorPath = '<?php echo defined('DBG_EDITOR') ? addslashes(DBG_EDITOR) : '' ?>';
$Debugger.DebugURL = '<?php echo $this->baseURL.'/debugger_responce.php?sid='.$this->rowSeparator.'&path='.urlencode($dbg_path); ?>';
<?php
if ($this->IsFatalError || DBG_RAISE_ON_WARNINGS) {
echo '$Debugger.Toggle();';
}
if (DBG_TOOLBAR_BUTTONS) {
echo '$Debugger.AddToolbar("$Debugger");';
}
?>
window.focus();
</script>
<?php
if (!isset($this->ProfilerTotals['error_handling'])) {
$memory_used = $debugger_start;
$this->ProfilerTotalCount['error_handling'] = 0;
}
else {
$memory_used = $debugger_start - $this->ProfilerTotals['error_handling'];
}
if ($returnResult) {
$ret = ob_get_contents();
if ($clean_output_buffer) {
ob_end_clean();
}
$ret .= $this->getShortReport($memory_used);
$this->reportDone = true;
return $ret;
}
else {
if (!$this->constOn('DBG_HIDE_FULL_REPORT')) {
$this->breakOutofBuffering();
}
elseif ($clean_output_buffer) {
ob_clean();
}
echo $this->getShortReport($memory_used);
$this->reportDone = true;
}
}
/**
* Format's memory usage report by debugger
*
* @return string
* @access private
*/
function getShortReport($memory_used)
{
if ($this->constOn('DBG_TOOLBAR_BUTTONS')) {
// we have sql & error count in toolbar, don't duplicate here
$info = Array(
'Script Runtime' => 'PROFILE:script_runtime',
'SQL\'s Runtime' => 'PROFILE_T:sql',
);
}
else {
// toolbar not visible, then show sql & error count too
$info = Array (
'Script Runtime' => 'PROFILE:script_runtime',
'SQL\'s Runtime' => 'PROFILE_T:sql',
'-' => 'SEP:-',
'Notice / Warning' => 'PROFILE_TC:error_handling',
'SQLs Count' => 'PROFILE_TC:sql',
);
}
$ret = '<tr><td>Application:</td><td><b>'.$this->formatSize($memory_used).'</b> ('.$memory_used.')</td></tr>';
foreach ($info as $title => $value_key) {
list ($record_type, $record_data) = explode(':', $value_key, 2);
switch ($record_type) {
case 'PROFILE': // profiler totals value
$Data =& $this->ProfilerData[$record_data];
$profile_time = ($Data['ends'] - $Data['begins']); // in seconds
$ret .= '<tr><td>'.$title.':</td><td><b>'.sprintf('%.5f', $profile_time).' s</b></td></tr>';
break;
case 'PROFILE_TC': // profile totals record count
$record_cell = '<td>';
if ($record_data == 'error_handling' && $this->ProfilerTotalCount[$record_data] > 0) {
$record_cell = '<td class="debug_error">';
}
$ret .= '<tr>'.$record_cell.$title.':</td>'.$record_cell.'<b>'.$this->ProfilerTotalCount[$record_data].'</b></td></tr>';
break;
case 'PROFILE_T': // profile total
$record_cell = '<td>';
- $ret .= '<tr>'.$record_cell.$title.':</td>'.$record_cell.'<b>'.sprintf('%.5f', $this->ProfilerTotals[$record_data]).' s</b></td></tr>';
+ $total = array_key_exists($record_data, $this->ProfilerTotals) ? $this->ProfilerTotals[$record_data] : 0;
+ $ret .= '<tr>'.$record_cell.$title.':</td>'.$record_cell.'<b>'.sprintf('%.5f', $total).' s</b></td></tr>';
break;
case 'SEP':
$ret .= '<tr><td colspan="2" style="height: 1px; background-color: #000000; padding: 0px;"><img src="'.$this->dummyImage.'" height="1" alt=""/></td></tr>';
break;
}
}
return '<br /><table class="dbg_stats_table"><tr><td style="border-color: #FFFFFF;"><table class="dbg_stats_table" align="left">'.$ret.'</table></td></tr></table>';
}
/**
* User-defined error handler
*
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param array $errcontext
*/
function saveError($errno, $errstr, $errfile = '', $errline = '', $errcontext = '')
{
$this->ProfilerData['error_handling']['begins'] = memory_get_usage();
$errorType = $this->getErrorNameByCode($errno);
if (!$errorType) {
trigger_error('Unknown error type ['.$errno.']', E_USER_ERROR);
return false;
}
if ($this->constOn('DBG_IGNORE_STRICT_ERRORS') && defined('E_STRICT') && ($errno == E_STRICT)) return;
if (preg_match('/(.*)#([\d]+)$/', $errstr, $rets) ) {
// replace short message with long one (due triger_error limitations on message size)
$long_id = $rets[2];
$errstr = $this->longErrors[$long_id];
unset($this->longErrors[$long_id]);
}
if (mb_strpos($errfile,'eval()\'d code') !== false) {
$errstr = '[<b>EVAL</b>, line <b>'.$errline.'</b>]: '.$errstr;
$tmpStr = $errfile;
$pos = mb_strpos($tmpStr,'(');
$errfile = mb_substr($tmpStr, 0, $pos);
$pos++;
$errline = mb_substr($tmpStr,$pos,mb_strpos($tmpStr,')',$pos)-$pos);
}
$this->Data[] = Array('no' => $errno, 'str' => $errstr, 'file' => $errfile, 'line' => $errline, 'context' => $errcontext, 'debug_type' => 'error');
$this->ProfilerData['error_handling']['ends'] = memory_get_usage();
$this->profilerAddTotal('error_handling', 'error_handling');
if (substr($errorType, 0, 5) == 'Fatal') {
$this->IsFatalError = true;
// append debugger report to data in buffer & clean buffer afterwards
die( $this->breakOutofBuffering(false) . $this->printReport(true) );
}
}
function breakOutofBuffering($flush = true)
{
$buffer_content = Array();
while (ob_get_level()) {
$buffer_content[] = ob_get_clean();
}
$ret = implode('', array_reverse($buffer_content));
if ($flush) {
echo $ret;
flush();
}
return $ret;
}
function saveToFile($msg)
{
$fp = fopen($_SERVER['DOCUMENT_ROOT'].'/vb_debug.txt', 'a');
fwrite($fp, $msg."\n");
fclose($fp);
}
/**
* Formats file/memory size in nice way
*
* @param int $bytes
* @return string
* @access public
*/
function formatSize($bytes)
{
if ($bytes >= 1099511627776) {
$return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
$suffix = "TB";
} elseif ($bytes >= 1073741824) {
$return = round($bytes / 1024 / 1024 / 1024, 2);
$suffix = "GB";
} elseif ($bytes >= 1048576) {
$return = round($bytes / 1024 / 1024, 2);
$suffix = "MB";
} elseif ($bytes >= 1024) {
$return = round($bytes / 1024, 2);
$suffix = "KB";
} else {
$return = $bytes;
$suffix = "Byte";
}
$return .= ' '.$suffix;
return $return;
}
function printConstants($constants)
{
if (!is_array($constants)) {
$constants = explode(',', $constants);
}
$contant_tpl = '<tr><td>%s</td><td><b>%s</b></td></tr>';
$ret = '<table class="dbg_flat_table" style="width: '.$this->getWindowWidth().'px;">';
foreach ($constants as $constant_name) {
$ret .= sprintf($contant_tpl, $constant_name, constant($constant_name));
}
$ret .= '</table>';
$this->appendHTML($ret);
}
function AttachToApplication() {
if (!$this->constOn('DBG_HANDLE_ERRORS')) return true;
if (class_exists('kApplication')) {
restore_error_handler();
$application =& kApplication::Instance();
$application->Debugger =& $this;
$application->errorHandlers[] = Array(&$this, 'saveError');
}
else {
set_error_handler(Array(&$this, 'saveError'));
}
}
}
if (!function_exists('memory_get_usage')) {
function memory_get_usage(){ return -1; }
}
if (!Debugger::constOn('DBG_ZEND_PRESENT')) {
$debugger = new Debugger();
}
if (Debugger::constOn('DBG_USE_SHUTDOWN_FUNC')) {
register_shutdown_function( Array(&$debugger, 'printReport') );
}
}
?>
\ No newline at end of file
Property changes on: branches/RC/core/kernel/utility/debugger.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.76.2.3
\ No newline at end of property
+1.76.2.4
\ No newline at end of property
Index: branches/RC/core/kernel/globals.php
===================================================================
--- branches/RC/core/kernel/globals.php (revision 10303)
+++ branches/RC/core/kernel/globals.php (revision 10304)
@@ -1,633 +1,645 @@
<?php
if( !function_exists('array_merge_recursive2') )
{
/**
* array_merge_recursive2()
*
* Similar to array_merge_recursive but keyed-valued are always overwritten.
* Priority goes to the 2nd array.
*
* @static yes
* @param $paArray1 array
* @param $paArray2 array
* @return array
* @access public
*/
function array_merge_recursive2($paArray1, $paArray2)
{
if (!is_array($paArray1) or !is_array($paArray2)) { return $paArray2; }
foreach ($paArray2 AS $sKey2 => $sValue2)
{
$paArray1[$sKey2] = isset($paArray1[$sKey2]) ? array_merge_recursive2($paArray1[$sKey2], $sValue2) : $sValue2;
// $paArray1[$sKey2] = array_merge_recursive2( getArrayValue($paArray1,$sKey2), $sValue2);
}
return $paArray1;
}
}
/**
* @return int
* @param $array array
* @param $value mixed
* @desc Prepend a reference to an element to the beginning of an array. Renumbers numeric keys, so $value is always inserted to $array[0]
*/
function array_unshift_ref(&$array, &$value)
{
$return = array_unshift($array,'');
$array[0] =& $value;
return $return;
}
/**
* Same as print_r, budet designed for viewing in web page
*
* @param Array $data
* @param string $label
*/
function print_pre($data, $label='', $on_screen = false)
{
$is_debug = false;
if (class_exists('kApplication') && !$on_screen) {
$application =& kApplication::Instance();
$is_debug = $application->isDebugMode();
}
if ($is_debug) {
if ($label) $application->Debugger->appendHTML('<b>'.$label.'</b>');
$application->Debugger->dumpVars($data);
}
else
{
if ($label) echo '<b>', $label, '</b><br>';
echo '<pre>', print_r($data, true), '</pre>';
}
}
/**
* Returns array value if key exists
*
* @param Array $array searchable array
* @param int $key array key
* @return string
* @access public
*/
//
function getArrayValue(&$array, $key)
{
// global $debugger;
// if (is_object($debugger)) $debugger->ProfilePoint('getArrayValue', 1);
$ret = isset($array[$key]) ? $array[$key] : false;
if ($ret && func_num_args() > 2) {
for ($i = 2; $i < func_num_args(); $i++) {
$cur_key = func_get_arg($i);
$ret = getArrayValue( $ret, $cur_key );
if ($ret === false) break;
}
}
return $ret;
}
/**
* Rename key in associative array, maintaining keys order
*
* @param Array $array Associative Array
* @param mixed $old Old key name
* @param mixed $new New key name
* @access public
*/
function array_rename_key(&$array, $old, $new)
{
foreach ($array as $key => $val)
{
$new_array[ $key == $old ? $new : $key] = $val;
}
$array = $new_array;
}
/**
* Define constant if it was not already defined before
*
* @param string $const_name
* @param string $const_value
* @access public
*/
function safeDefine($const_name, $const_value)
{
if(!defined($const_name)) define($const_name,$const_value);
}
if( !function_exists('parse_portal_ini') )
{
function parse_portal_ini($file, $parse_section = false)
{
if (!file_exists($file)) return 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 = mb_substr($line,1,(mb_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;
}
}
if( !function_exists('getmicrotime') )
{
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
}
if( !function_exists('k4_include_once') )
{
function k4_include_once($file)
{
global $debugger;
if ( defined('DEBUG_MODE') && DEBUG_MODE && isset($debugger) && constOn('DBG_PROFILE_INCLUDES') )
{
if ( in_array($file, get_required_files()) ) return;
global $debugger;
/* $debugger->IncludeLevel++;
$before_mem = memory_get_usage();
*/
$debugger->ProfileStart('inc_'.crc32($file), $file);
include_once($file);
$debugger->ProfileFinish('inc_'.crc32($file));
$debugger->profilerAddTotal('includes', 'inc_'.crc32($file));
/* $used_mem = memory_get_usage() - $before_mem;
$debugger->IncludeLevel--;
$debugger->IncludesData['file'][] = str_replace(FULL_PATH, '', $file);
$debugger->IncludesData['mem'][] = $used_mem;
$debugger->IncludesData['time'][] = $used_time;
$debugger->IncludesData['level'][] = $debugger->IncludeLevel;
*/
}
else
{
include_once($file);
}
}
}
/**
* Checks if string passed is serialized array
*
* @param string $string
* @return bool
*/
function IsSerialized($string)
{
if( is_array($string) ) return false;
return preg_match('/a:([\d]+):{/', $string);
}
if (!function_exists('makepassword4')){
function makepassword4($length=10)
{
$pass_length=$length;
$p1=array('b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z');
$p2=array('a','e','i','o','u');
$p3=array('1','2','3','4','5','6','7','8','9');
$p4=array('(','&',')',';','%'); // if you need real strong stuff
// how much elements in the array
// can be done with a array count but counting once here is faster
$s1=21;// this is the count of $p1
$s2=5; // this is the count of $p2
$s3=9; // this is the count of $p3
$s4=5; // this is the count of $p4
// possible readable combinations
$c1='121'; // will be like 'bab'
$c2='212'; // will be like 'aba'
$c3='12'; // will be like 'ab'
$c4='3'; // will be just a number '1 to 9' if you dont like number delete the 3
// $c5='4'; // uncomment to active the strong stuff
$comb='4'; // the amount of combinations you made above (and did not comment out)
for ($p=0;$p<$pass_length;)
{
mt_srand((double)microtime()*1000000);
$strpart=mt_rand(1,$comb);
// checking if the stringpart is not the same as the previous one
if($strpart<>$previous)
{
$pass_structure.=${'c'.$strpart};
// shortcutting the loop a bit
$p=$p+mb_strlen(${'c'.$strpart});
}
$previous=$strpart;
}
// generating the password from the structure defined in $pass_structure
for ($g=0;$g<mb_strlen($pass_structure);$g++)
{
mt_srand((double)microtime()*1000000);
$sel=mb_substr($pass_structure,$g,1);
$pass.=${'p'.$sel}[mt_rand(0,-1+${'s'.$sel})];
}
return $pass;
}
}
if( !function_exists('unhtmlentities') )
{
function unhtmlentities($string)
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
return strtr($string, $trans_tbl);
}
}
if( !function_exists('curl_post') )
{
/**
* submits $url with $post as POST
*
* @param string $url
* @param unknown_type $post
* @return unknown
*/
function curl_post($url, $post, $headers=null, $request_type = 'POST', $curl_options=null)
{
if( is_array($post) )
{
$params_str = '';
foreach($post as $key => $value) $params_str .= $key.'='.urlencode($value).'&';
$post = $params_str;
}
$ch = curl_init($url);
$dbg = false;
if (defined('DEBUG_MODE') && DEBUG_MODE && constOn('DBG_CURL')) {
$dbg = true;
safeDefine('DBG_CURL_LOGFILE', '/curl.log');
$log = fopen(FULL_PATH.DBG_CURL_LOGFILE, 'a');
curl_setopt($ch, CURLOPT_FILE, $log);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_STDERR, $log);
//curl_setopt($ch, CURLOPT_WRITEHEADER, $log);
}
if (!is_null($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
// if we have post data, then POST else use GET method instead
if ($request_type == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
elseif ($request_type == 'GET' && isset($post) && strlen($post) > 0) {
curl_setopt($ch, CURLOPT_URL, preg_match('/\?/', $url) ? $url.'&'.$post : $url.'?'.$post);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_REFERER, PROTOCOL.SERVER_NAME);
curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
if (is_array($curl_options)) {
foreach ($curl_options as $option => $value) {
curl_setopt($ch, $option, $value);
}
}
$ret = curl_exec($ch);
$GLOBALS['curl_errorno'] = curl_errno($ch);
$GLOBALS['curl_error'] = curl_error($ch);
curl_close($ch);
if ($dbg) {
fwrite($log, "\n".$ret);
fclose($log);
}
return $ret;
}
}
if( !function_exists('memory_get_usage') )
{
function memory_get_usage(){ return -1; }
}
function &ref_call_user_func_array($callable, $args)
{
if( is_scalar($callable) )
{
// $callable is the name of a function
$call = $callable;
}
else
{
if( is_object($callable[0]) )
{
// $callable is an object and a method name
$call = "\$callable[0]->{$callable[1]}";
}
else
{
// $callable is a class name and a static method
$call = "{$callable[0]}::{$callable[1]}";
}
}
// Note because the keys in $args might be strings
// we do this in a slightly round about way.
$argumentString = Array();
$argumentKeys = array_keys($args);
foreach($argumentKeys as $argK)
{
$argumentString[] = "\$args[$argumentKeys[$argK]]";
}
$argumentString = implode($argumentString, ', ');
// Note also that eval doesn't return references, so we
// work around it in this way...
eval("\$result =& {$call}({$argumentString});");
return $result;
}
/**
* Checks if constant is defined and has positive value
*
* @param string $const_name
* @return bool
*/
function constOn($const_name)
{
return defined($const_name) && constant($const_name);
}
function Kg2Pounds($kg)
{
$major = floor( round($kg / POUND_TO_KG, 3) );
$minor = abs(round(($kg - $major * POUND_TO_KG) / POUND_TO_KG * 16, 2));
return array($major, $minor);
}
function Pounds2Kg($pounds, $ounces=0)
{
return round(($pounds + ($ounces / 16)) * POUND_TO_KG, 5);
}
/**
* Formats file/memory size in nice way
*
* @param int $bytes
* @return string
* @access public
*/
function formatSize($bytes)
{
if ($bytes >= 1099511627776) {
$return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
$suffix = "TB";
} elseif ($bytes >= 1073741824) {
$return = round($bytes / 1024 / 1024 / 1024, 2);
$suffix = "GB";
} elseif ($bytes >= 1048576) {
$return = round($bytes / 1024 / 1024, 2);
$suffix = "MB";
} elseif ($bytes >= 1024) {
$return = round($bytes / 1024, 2);
$suffix = "KB";
} else {
$return = $bytes;
$suffix = "Byte";
}
$return .= ' '.$suffix;
return $return;
}
/**
* Enter description here...
*
* @param resource $filePointer the file resource to write to
* @param Array $data the data to write out
* @param string $delimiter the field separator
* @param string $enclosure symbol to enclose field data to
* @param string $recordSeparator symbols to separate records with
*/
function fputcsv2($filePointer, $data, $delimiter = ',', $enclosure = '"', $recordSeparator = "\r\n")
{
foreach($data as $field_index => $field_value) {
// replaces an enclosure with two enclosures
$data[$field_index] = str_replace($enclosure, $enclosure.$enclosure, $field_value);
}
$line = $enclosure.implode($enclosure.$delimiter.$enclosure, $data).$enclosure.$recordSeparator;
$line = preg_replace('/'.preg_quote($enclosure).'([0-9\.]+)'.preg_quote($enclosure).'/', '$1', $line);
fwrite($filePointer, $line);
}
/**
* Enter description here...
*
* @param resource $filePointer the file resource to write to
* @param Array $data the data to write out
* @param string $delimiter the field separator
* @param string $enclosure symbol to enclose field data to
* @param string $recordSeparator symbols to separate records with
*/
function getcsvline($data, $delimiter = ',', $enclosure = '"', $recordSeparator = "\r\n")
{
foreach($data as $field_index => $field_value) {
// replaces an enclosure with two enclosures
$data[$field_index] = str_replace($enclosure, $enclosure.$enclosure, $field_value);
}
$line = $enclosure.implode($enclosure.$delimiter.$enclosure, $data).$enclosure.$recordSeparator;
$line = preg_replace('/'.preg_quote($enclosure).'([0-9\.]+)'.preg_quote($enclosure).'/', '$1', $line);
return $line;
}
/**
* Allows to replace #section# within any string with current section
*
* @param string $string
* @return string
*/
function replaceModuleSection($string)
{
$application =& kApplication::Instance();
$module_section = $application->RecallVar('section');
if ($module_section) {
// substitute section instead of #section# parameter in title preset name
$module_section = explode(':', $module_section);
$section = preg_replace('/(configuration|configure)_(.*)/i', '\\2', $module_section[count($module_section) == 2 ? 1 : 0]);
$string = str_replace('#section#', mb_strtolower($section), $string);
}
return $string;
}
/**
* Checks, that user IP address is within allowed range
*
* @param string $ip_list semi-column (by default) separated ip address list
* @param string $separator ip address separator (default ";")
*
* @return bool
*/
function ipMatch($ip_list, $separator = ';')
{
$ip_match = false;
$ip_addresses = $ip_list ? explode($separator, $ip_list) : Array ();
foreach ($ip_addresses as $ip_address) {
if (netMatch($ip_address, $_SERVER['REMOTE_ADDR'])) {
$ip_match = true;
break;
}
}
return $ip_match;
}
function netMatch($network, $ip) {
$network = trim($network);
$ip = trim($ip);
if ($network == $ip) {
// comparing 2 ip addresses directly
return true;
}
$d = strpos($network, '-');
if ($d === false) {
// sigle subnet specified
$ip_arr = explode('/', $network);
if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)) {
$ip_arr[0] .= '.0'; // Alternate form 194.1.4/24
}
$network_long = ip2long($ip_arr[0]);
$x = ip2long($ip_arr[1]);
$mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1]));
$ip_long = ip2long($ip);
return ($ip_long & $mask) == ($network_long & $mask);
}
else {
// ip address range specified
$from = ip2long(trim(substr($network, 0, $d)));
$to = ip2long(trim(substr($network, $d + 1)));
$ip = ip2long($ip);
return ($ip >= $from && $ip <= $to);
}
}
function request_headers()
{
if(function_exists("apache_request_headers")) // If apache_request_headers() exists...
{
if($headers = apache_request_headers()) // And works...
{
return $headers; // Use it
}
}
$headers = array();
foreach(array_keys($_SERVER) as $skey)
{
if(substr($skey, 0, 5) == "HTTP_")
{
$headername = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($skey, 0, 5)))));
$headers[$headername] = $_SERVER[$skey];
}
}
return $headers;
}
+ /**
+ * Checks that file is writable by group or others
+ *
+ * @param string $file
+ * @return boolean
+ */
+ function check_write_permissions($file)
+ {
+ $permissions = fileperms($file);
+ return $permissions & 0x0010 || $permissions & 0x0002;
+ }
+
if (!function_exists('easter_date')) {
// calculates easter date, when calendar extension not installed in php
// see also: http://php.prod.intechnic.lv/manual/en/function.easter-date.php
function easter_date ($Year) {
/*
G is the Golden Number-1
H is 23-Epact (modulo 30)
I is the number of days from 21 March to the Paschal full moon
J is the weekday for the Paschal full moon (0=Sunday,
1=Monday, etc.)
L is the number of days from 21 March to the Sunday on or before
the Paschal full moon (a number between -6 and 28)
*/
$G = $Year % 19;
$C = (int)($Year / 100);
$H = (int)($C - ($C / 4) - ((8*$C+13) / 25) + 19*$G + 15) % 30;
$I = (int)$H - (int)($H / 28)*(1 - (int)($H / 28)*(int)(29 / ($H + 1))*((int)(21 - $G) / 11));
$J = ($Year + (int)($Year/4) + $I + 2 - $C + (int)($C/4)) % 7;
$L = $I - $J;
$m = 3 + (int)(($L + 40) / 44);
$d = $L + 28 - 31 * ((int)($m / 4));
$y = $Year;
$E = mktime(0,0,0, $m, $d, $y);
return $E;
}
}
?>
\ No newline at end of file
Property changes on: branches/RC/core/kernel/globals.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.37.2.3
\ No newline at end of property
+1.37.2.4
\ No newline at end of property
Index: branches/RC/core/install.php
===================================================================
--- branches/RC/core/install.php (revision 10303)
+++ branches/RC/core/install.php (revision 10304)
@@ -1,1202 +1,1207 @@
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
define('IS_INSTALL', 1);
define('ADMIN', 1);
define('FULL_PATH', realpath(dirname(__FILE__).'/..') );
define('REL_PATH', '/core');
/**
* Upgrade sqls are located using this mask
*
*/
define('UPGRADES_FILE', FULL_PATH.'/%sinstall/upgrades.%s');
/**
* Format of version identificator in upgrade files
*
*/
define('VERSION_MARK', '# ===== v ([\d]+\.[\d]+\.[\d]+) =====');
// print_pre($_POST);
$install_engine = new kInstallator();
$install_engine->Init();
$install_engine->Run();
$install_engine->Done();
class kInstallator {
/**
* Reference to kApplication class object
*
* @var kApplication
*/
var $Application = null;
/**
* Connection to database
*
* @var kDBConnection
*/
var $Conn = null;
/**
* Path to config.php
*
* @var string
*/
var $INIFile = '';
/**
* XML file containing steps information
*
* @var string
*/
var $StepDBFile = '';
/**
* Parsed data from config.php
*
* @var Array
*/
var $systemConfig = Array ();
/**
* Step name, that currently being processed
*
* @var string
*/
var $currentStep = '';
/**
* Steps list (preset) to use for current installation
*
* @var string
*/
var $stepsPreset = '';
/**
* Installtion steps to be done
*
* @var Array
*/
var $steps = Array(
'fresh_install' => Array ('check_paths', 'db_config', 'root_password', 'choose_modules', 'finish'),
'already_installed' => Array ('install_setup'),
'upgrade' => Array ('install_setup', 'upgrade_modules', /* ..., */ 'finish'),
'db_reconfig' => Array ('install_setup',/* ..., */ 'finish'),
'fix_paths' => Array ('install_setup',/* ..., */ 'finish'),
);
/**
* Steps, that doesn't required admin to be logged-in to proceed
*
* @var Array
*/
var $skipLoginSteps = Array ('root_password', 'choose_modules', 'finish', -1);
/**
* Steps, on which kApplication should not be initialized, because of missing correct db table structure
*
* @var Array
*/
var $skipApplicationSteps = Array ('check_paths', 'db_config'/*, 'install_setup'*/); // remove install_setup when application will work separately from install
/**
* Folders that should be writeable to continue installation
*
* @var Array
*/
var $writeableFolders = Array ('/system');
/**
* Contains last error message text
*
* @var string
*/
var $errorMessage = '';
/**
* Base path for includes in templates
*
* @var string
*/
var $baseURL = '';
/**
* Holds number of last executed query in the SQL
*
* @var unknown_type
*/
var $LastQueryNum = 0;
function Init()
{
$this->INIFile = FULL_PATH.'/config.php';
$this->StepDBFile = FULL_PATH.'/'.REL_PATH.'/install/steps_db.xml';
$base_path = rtrim(preg_replace('/'.preg_quote(rtrim(REL_PATH, '/'), '/').'$/', '', str_replace('\\', '/', dirname($_SERVER['PHP_SELF']))), '/');
$this->baseURL = 'http://'.$_SERVER['HTTP_HOST'].$base_path.'/core/install/';
set_error_handler( Array(&$this, 'ErrorHandler') );
if (file_exists($this->INIFile)) {
// if config.php found, then check his write permission too
$this->writeableFolders[] = '/config.php';
}
else {
$this->writeableFolders[] = '/';
}
$this->systemConfig = $this->ParseConfig(true);
$this->systemConfig['Misc']['WriteablePath'] = '/system'; // for development purposes
$this->systemConfig['Misc']['Domain'] = $_SERVER['HTTP_HOST']; // for redirects from SSL mode
$this->currentStep = $this->GetVar('step');
// can't check login on steps where no application present anyways :)
$this->skipLoginSteps = array_unique(array_merge($this->skipLoginSteps, $this->skipApplicationSteps));
$this->SelectPreset();
if (!$this->currentStep) {
$this->SetFirstStep(); // sets first step of current preset
}
$this->InitStep();
}
function SetFirstStep()
{
reset($this->steps[$this->stepsPreset]);
$this->currentStep = current($this->steps[$this->stepsPreset]);
}
/**
* Selects preset to proceed based on various criteria
*
*/
function SelectPreset()
{
$preset = $this->GetVar('preset');
if (file_exists($this->INIFile) && $this->systemConfig) {
// only at installation first step
$status = $this->CheckDatabase(false);
if ($status && $this->AlreadyInstalled()) {
// if already installed, then all future actions need login to work
$this->skipLoginSteps = Array (-1);
if (!$preset) {
$preset = 'already_installed';
$this->currentStep = '';
}
}
}
if ($preset === false) {
$preset = 'fresh_install'; // default preset
}
$this->stepsPreset = $preset;
}
function GetVar($name)
{
return isset($_REQUEST[$name]) ? $_REQUEST[$name] : false;
}
/**
* Performs needed intialization of data, that step requires
*
*/
function InitStep()
{
$require_login = !in_array($this->currentStep, $this->skipLoginSteps);
$this->InitApplication($require_login);
if ($require_login) {
// step require login to proceed
if (!$this->Application->LoggedIn()) {
$this->stepsPreset = 'already_installed';
$this->SetFirstStep();
}
}
switch ($this->currentStep) {
case 'check_paths':
foreach ($this->writeableFolders as $folder_path) {
$file_path = FULL_PATH.$folder_path;
if (!is_writable($file_path)) {
$this->errorMessage = 'Install cannot write to specified folder in the root directory of your installation';
break;
}
}
break;
case 'db_config':
$section_name = 'Database';
$fields = Array ('DBType', 'DBHost', 'DBName', 'DBUser', 'DBUserPassword', 'DBCollation', 'TablePrefix');
if (!isset($this->systemConfig[$section_name])) {
$this->systemConfig[$section_name] = Array ();
}
// set fields
foreach ($fields as $field_name) {
$submit_value = $this->GetVar($field_name);
if ($submit_value !== false) {
$this->systemConfig[$section_name][$field_name] = $submit_value;
}
elseif (!isset($this->systemConfig[$section_name][$field_name])) {
$this->systemConfig[$section_name][$field_name] = '';
}
}
break;
case 'choose_modules':
// if no modules found, then proceed to next step
$modules = $this->ScanModules();
if (!$modules) {
$this->currentStep = $this->GetNextStep();
}
break;
case 'upgrade_modules':
// get installed modules from db and compare their versions to upgrade script
$modules = $this->GetUpgradableModules();
if (!$modules) {
$this->currentStep = $this->GetNextStep();
}
break;
case 'install_setup':
$next_preset = $this->Application->GetVar('next_preset');
if ($next_preset !== false && $this->Application->GetVar('login') == 'root') {
// option was choosen, then verify password & login user
$login_event = new kEvent('u.current:OnLogin');
$this->Application->HandleEvent($login_event);
if ($login_event->status == erSUCCESS) {
// login succeeded
if (!isset($this->steps[$next_preset])) {
$this->errorMessage = 'Preset "'.$next_preset.'" not yet implemented';
}
else {
$this->stepsPreset = $next_preset;
}
}
else {
// login failed
$user =& $this->Application->recallObject('u.current');
/* @var $user UsersItem */
$this->errorMessage = $user->GetErrorMsg('ValidateLogin').'. If you don\'t know your username or password, contact Intechnic Support';
}
}
else {
// if preset was not choosen, then raise error
$this->errorMessage = 'Please select action to perform';
}
break;
}
$this->PerformValidation(); // returns validation status (just in case)
}
/**
* Validates data entered by user
*
* @return bool
*/
function PerformValidation()
{
if ($this->GetVar('step') != $this->currentStep) {
// just redirect from previous step, don't validate
return true;
}
$status = true;
switch ($this->currentStep) {
case 'db_config':
// 1. check if required fields are filled
$section_name = 'Database';
$required_fields = Array ('DBType', 'DBHost', 'DBName', 'DBUser', 'DBCollation');
foreach ($required_fields as $required_field) {
if (!$this->systemConfig[$section_name][$required_field]) {
$status = false;
$this->errorMessage = 'Please fill all required fields';
break;
}
}
if (!$status) break;
// 2. check permissions, that use have in this database
$status = $this->CheckDatabase();
break;
case 'root_password':
// check, that password & verify password match
$password = $this->Application->GetVar('root_password');
$password_verify = $this->Application->GetVar('root_password_verify');
if ($password != $password_verify) {
$this->errorMessage = 'Passwords does not match';
}
elseif (mb_strlen($password) < 4) {
$this->errorMessage = 'Root Password must be at least 4 characters';
}
$status = $this->errorMessage == '';
break;
}
return $status;
}
/**
* Perform installation step actions
*
*/
function Run()
{
if ($this->errorMessage) {
// was error during data validation stage
return ;
}
switch ($this->currentStep) {
case 'db_config':
// store db configuration
$sql = 'SHOW COLLATION
LIKE \''.$this->systemConfig['Database']['DBCollation'].'\'';
$collation_info = $this->Conn->Query($sql);
if ($collation_info) {
$this->systemConfig['Database']['DBCharset'] = $collation_info[0]['Charset'];
// database is already connected, that's why set collation on the fly
$this->Conn->Query('SET NAMES \''.$this->systemConfig['Database']['DBCharset'].'\' COLLATE \''.$this->systemConfig['Database']['DBCollation'].'\'');
}
$this->SaveConfig();
// import base data into database
$this->RunSQL('/core/install/install_schema.sql');
$this->RunSQL('/core/install/install_data.sql');
// set module "Core" version after install (based on upgrade scripts)
$this->SetModuleVersion('Core');
break;
case 'root_password':
// update root password in database
$password = md5( md5($this->Application->GetVar('root_password')) . 'b38');
$this->SetConfigValue('RootPass', $password);
// set Site_Path (for SSL & old in-portal code)
$this->SetConfigValue('Site_Path', BASE_PATH.'/');
// import base language for core (english)
$this->ImportLanguage('/core/install/english');
// set imported language as primary
$lang =& $this->Application->recallObject('lang.-item', null, Array('skip_autoload' => true));
/* @var $lang LanguagesItem */
$lang->Load(1); // fresh install => ID=1
$lang->setPrimary();
break;
case 'choose_modules':
// run module install scripts
$modules = $this->Application->GetVar('modules');
if ($modules) {
foreach ($modules as $module) {
$install_file = MODULES_PATH.'/'.$module.'/install.php';
if (file_exists($install_file)) {
include_once($install_file);
// set module version after install (based on upgrade scripts)
$this->SetModuleVersion($module);
}
}
}
// scan themes
$this->Application->HandleEvent($themes_event, 'adm:OnRebuildThemes');
$this->Conn->Query('UPDATE '.TABLE_PREFIX.'Theme SET Enabled=1, PrimaryTheme =1 LIMIT 1');
// update categories cache
$updater =& $this->Application->recallObject('kPermCacheUpdater');
/* @var $updater kPermCacheUpdater */
$updater->OneStepRun();
break;
case 'upgrade_modules':
// get installed modules from db and compare their versions to upgrade script
$modules = $this->Application->GetVar('modules');
if ($modules) {
$upgrade_data = $this->GetUpgradableModules();
$start_from_module = $this->GetVar('continue_from_module');
$start_from_query = $this->GetVar('continue_from_query');
if (!$start_from_query) $start_from_query = 0;
foreach ($modules as $module_name) {
if ($start_from_module && $module_name != $start_from_module) {
continue;
}
else {
$start_from_module = false; //otherwise it will skip all modules after the one we start with!
}
$module_info = $upgrade_data[$module_name];
$upgrades_file = sprintf(UPGRADES_FILE, $module_info['Path'], 'sql');
$sqls = file_get_contents($upgrades_file);
$version_mark = preg_replace('/(\(.*?\))/', $module_info['FromVersion'], VERSION_MARK);
// get only sqls from next (relative to current) version to end of file
$start_pos = strpos($sqls, $version_mark);
$sqls = substr($sqls, $start_pos);
preg_match_all('/'.VERSION_MARK.'/s', $sqls, $regs);
if (!$start_from_module) {
$this->RunUpgrades($module_info['Path'], $regs[1], 'before');
}
if (!$this->RunSQLText($sqls, null, null, $start_from_query)) {
$this->errorMessage .= '<input type="hidden" name="continue_from_module" value="'.$module_name.'">';
$this->errorMessage .= '<input type="hidden" name="continue_from_query" value="'.$this->LastQueryNum.'">';
$this->errorMessage .= '<br/>Click Continue button below to skip this query and go further<br/>';
$this->Done();
}
$start_from_query = 0; // so that next module start from the beggining
$this->RunUpgrades($module_info['Path'], $regs[1], 'after');
// after upgrade sqls are executed update version
$this->SetModuleVersion($module_name, $module_info['ToVersion']);
}
}
else {
$this->errorMessage = 'Please select module(-s) to upgrade';
}
break;
case 'finish':
// delete cache
$sql = 'DELETE FROM '.TABLE_PREFIX.'Cache
WHERE VarName IN ("config_files","configs_parsed","sections_parsed")';
$this->Conn->Query($sql);
// set installation finished mark
if ($this->Application->ConfigValue('InstallFinished') === false) {
$fields_hash = Array (
'VariableName' => 'InstallFinished',
'VariableValue' => 1,
);
$this->Conn->doInsert($fields_hash, TABLE_PREFIX.'ConfigurationValues');
}
break;
}
if ($this->errorMessage) {
// was error during run stage
return ;
}
$this->currentStep = $this->GetNextStep();
$this->InitStep(); // init next step (that will be shown now)
$this->InitApplication();
if ($this->currentStep == -1) {
// step after last step -> redirect to admin
$this->Application->Redirect('index', null, '', 'index.php');
}
}
/**
* Run upgrade PHP scripts for module with specified path
*
* @param string $module_path
* @param Array $versions
* @param string $mode upgrade mode = {before,after}
*/
function RunUpgrades($module_path, $versions, $mode)
{
static $upgrade_classes = Array ();
$upgrades_file = sprintf(UPGRADES_FILE, $module_path, 'php');
if (!file_exists($upgrades_file) || !$versions) {
return ;
}
if (!isset($upgrade_classes[$module_path])) {
// save class name, because 2nd time
// (in after call $upgrade_class variable will not be present)
include_once $upgrades_file;
$upgrade_classes[$module_path] = $upgrade_class;
}
$upgrade_object = new $upgrade_classes[$module_path]();
if (method_exists($upgrade_object, 'setInstallator')) {
$upgrade_object->setInstallator($this);
}
foreach ($versions as $version) {
$upgrade_method = 'Upgrade_'.str_replace('.', '_', $version);
if (method_exists($upgrade_object, $upgrade_method)) {
$upgrade_object->$upgrade_method($mode);
}
}
}
/**
* Sets module version to passed
*
* @param string $module_name
* @param string $version
*/
function SetModuleVersion($module_name, $version = false)
{
if ($version === false) {
$version = $this->GetMaxModuleVersion($module_name);
}
$table_prefix = $this->systemConfig['Database']['TablePrefix'];
$sql = 'UPDATE '.$table_prefix.'Modules
SET Version = "'.$version.'"
WHERE Name = "'.$module_name.'"';
$this->Conn->Query($sql);
}
/**
* Sets new configuration variable value
*
* @param string $name
* @param mixed $value
*/
function SetConfigValue($name, $value)
{
$sql = 'UPDATE '.TABLE_PREFIX.'ConfigurationValues
SET VariableValue = '.$this->Conn->qstr($value).'
WHERE VariableName = '.$this->Conn->qstr($name);
$this->Conn->Query($sql);
}
/**
* Initialize kApplication
*
* @param bool $force initialize in any case
*/
function InitApplication($force = false)
{
if (($force || !in_array($this->currentStep, $this->skipApplicationSteps)) && !isset($this->Application)) {
// step is allowed for application usage & it was not initialized in previous step
global $start, $debugger, $dbg_options;
include_once(FULL_PATH.'/core/kernel/startup.php');
$this->Application =& kApplication::Instance();
$this->Application->Init();
$this->Conn =& $this->Application->GetADODBConnection();
}
}
/**
* Show next step screen
*
*/
function Done($error_message = null)
{
if (isset($error_message)) {
$this->errorMessage = $error_message;
}
include_once (FULL_PATH.'/'.REL_PATH.'/install/incs/install.tpl');
if (isset($this->Application)) {
$this->Application->Done();
// echo 'SID: ['.$this->Application->GetSID().']<br />';
}
exit;
}
function GetMaxModuleVersion($module_name)
{
$upgrades_file = sprintf(UPGRADES_FILE, mb_strtolower($module_name).'/', 'sql');
if (!file_exists($upgrades_file)) {
// no upgrade file
return '4.0.1';
}
$sqls = file_get_contents($upgrades_file);
$versions_found = preg_match_all('/'.VERSION_MARK.'/s', $sqls, $regs);
if (!$versions_found) {
// upgrades file doesn't contain version definitions
return '4.0.1';
}
return end($regs[1]);
}
function ConnectToDatabase()
{
include_once FULL_PATH.'/core/kernel/db/db_connection.php';
if (!isset($this->systemConfig['Database']['DBType']) ||
!isset($this->systemConfig['Database']['DBUser']) ||
!isset($this->systemConfig['Database']['DBName'])
) {
return false;
}
$this->Conn = new kDBConnection($this->systemConfig['Database']['DBType'], Array(&$this, 'DBErrorHandler'));
$this->Conn->Connect($this->systemConfig['Database']['DBHost'], $this->systemConfig['Database']['DBUser'], $this->systemConfig['Database']['DBUserPassword'], $this->systemConfig['Database']['DBName']);
return $this->Conn->errorCode == 0;
}
/**
* Checks if core is already installed
*
* @return bool
*/
function AlreadyInstalled()
{
$table_prefix = $this->systemConfig['Database']['TablePrefix'];
- return $this->TableExists('ConfigurationValues') && $this->Conn->GetOne('SELECT VariableValue FROM '.$table_prefix.'ConfigurationValues WHERE VariableName = \'InstallFinished\'');
+
+ $sql = 'SELECT VariableValue
+ FROM '.$table_prefix.'ConfigurationValues
+ WHERE VariableName = "InstallFinished"';
+
+ return $this->TableExists('ConfigurationValues') && $this->Conn->GetOne($sql);
}
function CheckDatabase($check_installed = true)
{
// perform various check type to database specified
// 1. user is allowed to connect to database
// 2. user has all types of permissions in database
if (mb_strlen($this->systemConfig['Database']['TablePrefix']) > 7) {
$this->errorMessage = 'Table prefix should not be longer than 7 characters';
return false;
}
// connect to database
$status = $this->ConnectToDatabase();
if ($status) {
// if connected, then check if all sql statements work
$sql_tests[] = 'DROP TABLE IF EXISTS test_table';
$sql_tests[] = 'CREATE TABLE test_table(test_col mediumint(6))';
$sql_tests[] = 'LOCK TABLES test_table WRITE';
$sql_tests[] = 'INSERT INTO test_table(test_col) VALUES (5)';
$sql_tests[] = 'UPDATE test_table SET test_col = 12';
$sql_tests[] = 'UNLOCK TABLES';
$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) {
$this->Conn->Query($sql_test);
if ($this->Conn->getErrorCode() != 0) {
$status = false;
break;
}
}
if ($status) {
// if statements work & connection made, then check table existance
if ($check_installed && $this->AlreadyInstalled()) {
$this->errorMessage = 'An In-Portal Database already exists at this location';
return false;
}
}
else {
// user has insufficient permissions in database specified
$db_error = 'Permission Error: ('.$this->Conn->getErrorCode().') '.$this->Conn->getErrorMsg();
return false;
}
}
else {
// was error while connecting
if (!$this->Conn) return false;
$this->errorMessage = 'Connection Error: ('.$this->Conn->getErrorCode().') '.$this->Conn->getErrorMsg();
return false;
}
return true;
}
/**
* Checks if all passed tables exists
*
* @param string $tables comma separated tables list
* @return bool
*/
function TableExists($tables)
{
$prefix = $this->systemConfig['Database']['TablePrefix'];
$all_found = true;
$tables = explode(',', $tables);
foreach ($tables as $table_name) {
$sql = 'SHOW TABLES LIKE "'.$prefix.$table_name.'"';
if (count($this->Conn->Query($sql)) == 0) {
$all_found = false;
break;
}
}
return $all_found;
}
/**
* Runs SQLs from file
*
* @param string $filename
* @param mixed $replace_from
* @param mixed $replace_to
*/
function RunSQL($filename, $replace_from = null, $replace_to = null)
{
if (!file_exists(FULL_PATH.$filename)) {
return ;
}
$sqls = file_get_contents(FULL_PATH.$filename);
if (!$this->RunSQLText($sqls, $replace_from, $replace_to)) {
$this->Done();
}
}
/**
* Runs SQLs from string
*
* @param string $sqls
* @param mixed $replace_from
* @param mixed $replace_to
*/
function RunSQLText(&$sqls, $replace_from = null, $replace_to = null, $start_from=0)
{
$table_prefix = $this->systemConfig['Database']['TablePrefix'];
// add prefix to all tables
if (strlen($table_prefix) > 0) {
$replacements = Array ('CREATE TABLE ', 'INSERT INTO ', 'UPDATE ', 'ALTER TABLE ', 'DELETE FROM ', 'REPLACE INTO ');
foreach ($replacements as $replacement) {
$sqls = str_replace($replacement, $replacement.$table_prefix, $sqls);
}
$sqls = str_replace('DROP TABLE ', 'DROP TABLE IF EXISTS '.$table_prefix, $sqls);
}
if (isset($replace_from) && isset($replace_to)) {
// replace something additionally, e.g. module root category
$sqls = str_replace($replace_from, $replace_to, $sqls);
}
$sqls = str_replace("\r\n", "\n", $sqls); // convert to linux line endings
$sqls = preg_replace("/#([^;]*?)\n/", '', $sqls); // remove all comments
$sqls = explode(";\n", $sqls);
for ($i=$start_from; $i<count($sqls); $i++) {
$sql = trim($sqls[$i]);
if (!$sql) {
continue; // usually last line
}
if (substr($sql, 0, 13) == 'CREATE TABLE ' && $this->systemConfig['Database']['DBCollation']) {
// it is CREATE TABLE statement -> add collation
$sql .= ' COLLATE \''.$this->systemConfig['Database']['DBCollation'].'\'';
}
$this->Conn->Query($sql);
if ($this->Conn->getErrorCode() != 0) {
$this->errorMessage = 'Error: ('.$this->Conn->getErrorCode().') '.$this->Conn->getErrorMsg().'<br /><br />Database Query:<pre>'.htmlspecialchars($sql).'</pre>';
$this->LastQueryNum = $i+1;
return false;
}
}
return true;
}
function ImportLanguage($lang_file)
{
$lang_file = FULL_PATH.$lang_file.'.lang';
if (!file_exists($lang_file)) {
return ;
}
$lang_xml =& $this->Application->recallObjectP('LangXML', null, Array(), false); // false - don't use temp tables
$lang_xml->Parse($lang_file, '|0|1|2|', '');
}
/**
* Returns modules list found in modules folder
*
* @return Array
*/
function ScanModules()
{
static $modules = null;
if (!isset($modules)) {
$modules = Array();
$fh = opendir(MODULES_PATH);
while (($sub_folder = readdir($fh))) {
$folder_path = MODULES_PATH.'/'.$sub_folder;
if ($sub_folder != '.' && $sub_folder != '..' && is_dir($folder_path)) {
if ($sub_folder == 'core') {
// skip modules here
continue;
}
// this is folder in MODULES_PATH directory
if (file_exists($folder_path.'/install.php') && file_exists($folder_path.'/install/install_schema.sql')) {
$modules[] = $sub_folder;
}
}
}
}
return $modules;
}
/**
* Converts module version in format X.Y.Z to signle integer
*
* @param string $version
* @return int
*/
function ConvertModuleVersion($version)
{
$parts = explode('.', $version);
$bin = '';
foreach ($parts as $part) {
$bin .= str_pad(decbin($part), 8, '0', STR_PAD_LEFT);
}
return bindec($bin);
}
/**
* Returns list of modules, that can be upgraded
*
*/
function GetUpgradableModules()
{
$ret = Array ();
foreach ($this->Application->ModuleInfo as $module_name => $module_info) {
$upgrades_file = sprintf(UPGRADES_FILE, $module_info['Path'], 'sql');
if (!file_exists($upgrades_file)) {
// no upgrade file
continue;
}
$sqls = file_get_contents($upgrades_file);
$versions_found = preg_match_all('/'.VERSION_MARK.'/s', $sqls, $regs);
if (!$versions_found) {
// upgrades file doesn't contain version definitions
continue;
}
$to_version = end($regs[1]);
$this_version = $this->ConvertModuleVersion($module_info['Version']);
if ($this->ConvertModuleVersion($to_version) > $this_version) {
// destination version is greather then current
foreach ($regs[1] as $version) {
if ($this->ConvertModuleVersion($version) > $this_version) {
$from_version = $version;
break;
}
}
$version_info = Array (
'FromVersion' => $from_version,
'ToVersion' => $to_version,
);
$ret[$module_name] = array_merge_recursive2($module_info, $version_info);
}
}
return $ret;
}
/**
* Returns content to show for current step
*
* @return string
*/
function GetStepBody()
{
$step_template = FULL_PATH.'/core/install/step_templates/'.$this->currentStep.'.tpl';
if (file_exists($step_template)) {
ob_start();
include_once ($step_template);
return ob_get_clean();
}
return '{step template "'.$this->currentStep.'" missing}';
}
/**
* Parses step information file, cache result for current step ONLY & return it
*
* @return Array
*/
function &_getStepInfo()
{
static $info = Array('help_title' => null, 'step_title' => null, 'help_body' => null, 'queried' => false);
if (!$info['queried']) {
$fdata = file_get_contents($this->StepDBFile);
$parser = xml_parser_create();
xml_parse_into_struct($parser, $fdata, $values, $index);
xml_parser_free($parser);
foreach ($index['STEP'] as $section_index) {
$step_data =& $values[$section_index];
if ($step_data['attributes']['NAME'] == $this->currentStep) {
$info['step_title'] = $step_data['attributes']['TITLE'];
if (isset($step_data['attributes']['HELP_TITLE'])) {
$info['help_title'] = $step_data['attributes']['HELP_TITLE'];
}
else {
// if help title not set, then use step title
$info['help_title'] = $step_data['attributes']['TITLE'];
}
$info['help_body'] = trim($step_data['value']);
break;
}
}
$info['queried'] = true;
}
return $info;
}
/**
* Returns particular information abou current step
*
* @param string $info_type
* @return string
*/
function GetStepInfo($info_type)
{
$step_info =& $this->_getStepInfo();
if (isset($step_info[$info_type])) {
return $step_info[$info_type];
}
return '{step "'.$this->currentStep.'"; param "'.$info_type.'" missing}';
}
/**
* Returns passed steps titles
*
* @param Array $steps
* @return Array
* @see kInstaller:PrintSteps
*/
function _getStepTitles($steps)
{
$fdata = file_get_contents($this->StepDBFile);
$parser = xml_parser_create();
xml_parse_into_struct($parser, $fdata, $values, $index);
xml_parser_free($parser);
$ret = Array ();
foreach ($index['STEP'] as $section_index) {
$step_data =& $values[$section_index];
if (in_array($step_data['attributes']['NAME'], $steps)) {
$ret[ $step_data['attributes']['NAME'] ] = $step_data['attributes']['TITLE'];
}
}
return $ret;
}
/**
* Returns current step number in active steps_preset.
* Value can't be cached, because same step can have different number in different presets
*
* @return int
*/
function GetStepNumber()
{
return array_search($this->currentStep, $this->steps[$this->stepsPreset]) + 1;
}
/**
* Returns step name to process next
*
* @return string
*/
function GetNextStep()
{
$next_index = $this->GetStepNumber();
if ($next_index > count($this->steps[$this->stepsPreset]) - 1) {
return -1;
}
return $this->steps[$this->stepsPreset][$next_index];
}
/**
* Returns step name, that was processed before this step
*
* @return string
*/
function GetPreviousStep()
{
$next_index = $this->GetStepNumber() - 1;
if ($next_index < 0) {
$next_index = 0;
}
return $this->steps[$this->stepsPreset][$next_index];
}
/**
* Prints all steps from active steps preset and highlights current step
*
* @param string $active_tpl
* @param string $passive_tpl
* @return string
*/
function PrintSteps($active_tpl, $passive_tpl)
{
$ret = '';
$step_titles = $this->_getStepTitles($this->steps[$this->stepsPreset]);
foreach ($this->steps[$this->stepsPreset] as $step_name) {
$template = $step_name == $this->currentStep ? $active_tpl : $passive_tpl;
$ret .= sprintf($template, $step_titles[$step_name]);
}
return $ret;
}
function ParseConfig($parse_section = false)
{
if (!file_exists($this->INIFile)) {
return Array();
}
if( file_exists($this->INIFile) && !is_readable($this->INIFile) ) {
die('Could Not Open Ini File');
}
$contents = file($this->INIFile);
$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 = mb_substr($line, 1, (mb_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);
}
}
}
}
if ($resave) {
$fp = fopen($this->INIFile, 'w');
reset($contents);
fwrite($fp,'<'.'?'.'php die() ?'.">\n\n");
foreach ($contents as $line) {
fwrite($fp,"$line");
}
fclose($fp);
}
return $retval;
}
function SaveConfig()
{
$fp = fopen($this->INIFile, 'w');
fwrite($fp,'<'.'?'.'php die() ?'.">\n\n");
foreach ($this->systemConfig as $section_name => $section_data) {
fwrite($fp, '['.$section_name."]\n");
foreach ($section_data as $key => $value) {
fwrite($fp, $key.' = "'.$value.'"'."\n");
}
fwrite($fp, "\n");
}
fclose($fp);
}
/**
* Installation error handler for sql errors
*
* @param int $code
* @param string $msg
* @param string $sql
* @return bool
* @access private
*/
function DBErrorHandler($code, $msg, $sql)
{
$this->errorMessage = 'Query: <br />'.htmlspecialchars($sql).'<br />execution result is error:<br />['.$code.'] '.$msg;
return true;
}
/**
* Installation error handler
*
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param Array $errcontext
*/
function ErrorHandler($errno, $errstr, $errfile = '', $errline = '', $errcontext = '')
{
if ($errno == E_USER_ERROR) {
// only react on user fatal errors
$this->Done($errstr);
}
}
}
/*function print_pre($s)
{
echo '<pre>', print_r($s, true). '</pre>';
}*/
?>
\ No newline at end of file
Property changes on: branches/RC/core/install.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.12.2.4
\ No newline at end of property
+1.12.2.5
\ No newline at end of property

Event Timeline