Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sat, Feb 1, 6:45 PM

in-portal

Index: trunk/admin/install.php
===================================================================
--- trunk/admin/install.php (revision 23)
+++ trunk/admin/install.php (revision 24)
@@ -1,1821 +1,1827 @@
<?php
error_reporting(0);
//$new_version = '1.0.2';
define("GET_LICENSE_URL", "http://www.in-portal.net/licensing/license.php");
define('BACKUP_NAME', 'dump(.*).txt'); // how backup dump files are named
$general_error = '';
if ($_POST['install_type'] != '') {
$install_type = $_POST['install_type'];
}
else if ($_GET['install_type'] != '') {
$install_type = $_GET['install_type'];
}
$pathtoroot = "";
if(!strlen($pathtoroot))
{
//$path=dirname(realpath($_SERVER['SCRIPT_FILENAME']));PATH_TRANSLATED
$path=dirname(realpath($_SERVER['PATH_TRANSLATED']));
if(strlen($path))
{
/* determine the OS type for path parsing */
$pos = strpos($path,":");
if ($pos === false)
{
$gOS_TYPE="unix";
$pathchar = "/";
}
else
{
$gOS_TYPE="win";
$pathchar="\\";
}
$p = $path.$pathchar;
/*Start looking for the root flag file */
while(!strlen($pathtoroot) && strlen($p))
{
$sub = substr($p,strlen($pathchar)*-1);
if($sub==$pathchar)
{
$filename = $p."root.flg";
}
else
$filename = $p.$pathchar."root.flg";
if(file_exists($filename))
{
$pathtoroot = $p;
}
else
{
$parent = realpath($p.$pathchar."..".$pathchar);
if($parent!=$p)
{
$p = $parent;
}
else
$p = "";
}
}
if(!strlen($pathtoroot))
$pathtoroot = ".".$pathchar;
}
else
{
$pathtoroot = ".".$pathchar;
}
}
$path_char = GetPathChar();
//phpinfo(INFO_VARIABLES);
$sub = substr($pathtoroot,strlen($pathchar)*-1);
if($sub!=$pathchar)
{
$pathtoroot = $pathtoroot.$pathchar;
}
$is_install = TRUE;
$admin = substr($path,strlen($pathtoroot));
$state = $_GET["state"];
if(!strlen($state))
{
$state = $_POST["state"];
}
include("install/install_lib.php");
$ini_file = $pathtoroot."config.php";
if(file_exists($ini_file))
{
$write_access = is_writable($ini_file);
$ini_vars = parse_ini_file($ini_file,TRUE);
foreach($ini_vars as $secname => $section)
{
foreach($section as $key => $value)
{
$key = "g_".$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";
if(strlen($g_DBType)>0 && strlen($state)>0 && $state !="dbinfo" && $state !="db_config_save")
{
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");
}
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);
}
require_once($pathtoroot.$admin."/install/inst_ado.php");
?>
<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();
}
</SCRIPT>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" style="height: 100%">
<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 alt="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 alt="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 alt="" 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 alt="" src="images/spacer.gif" width="1" height="14">In-Portal Version 1.0.0: English US</td></tr>
<tr><td><img alt="" src="images/blocks2.gif" width="400" height="2"><br></td></tr>
<tr><td bgcolor="black" colspan="4"><img alt="" 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();
if($ado)
{
$installed = TableExists($ado,"ConfigurationAdmin,Category,Permissions");
}
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."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 Exportd directory must be writable (".$pathtoroot."admin/export/).";
//die();
}
if($installed)
{
$state="reinstall";
}
else {
$state="dbinfo";
}
}
if($state=="reinstall_process")
{
$lic = base64_decode($g_License);
if(strlen($lic))
{
inst_ParseLicense($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)
$LoggedIn = ($RootPass==md5($_POST["UserPass"]));
}
}
else
{
$rfile = @fopen(GET_LICENSE_URL."?login=".md5($_POST['UserName'])."&password=".md5($_POST['UserPass'])."&domain=".$_SERVER['SERVER_NAME'], "r");
if (!$rfile) {
$LoggedIn = false;
}
else {
$rcontents = '';
while (!feof($rfile)) {
$line = fgets($rfile, 10000);
$rcontents .= $line;
}
@fclose($rfile);
if (substr($rcontents, 0, 5) == 'Error') {
$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);
/* 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;
}
}
}
else
{
$state="reinstall";
$login_error = "Invalid Username or Password - Try Again";
}
}
if ($state == "upgrade") {
$ado = inst_GetADODBConnection();
$Modules = array();
$Texts = array();
$sql = "SELECT Name, Version FROM ".$g_TablePrefix."Modules";
$rs = $ado->Execute($sql);
while ($rs && !$rs->EOF) {
$p = strtolower($rs->fields['Name']);
// $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>";
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 != '') {
$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) {
// $sql = "SELECT Version FROM ".$g_TablePrefix."Modules WHERE Name = '".$p."'";
// $rs2 = $ado->Execute($sql);
$Texts[] = $rs->fields['Name']." (".$rs->fields['Version']." ".prompt_language("la_to")." ".$file.")";
$Modules[] = $rs->fields['Name'];
}
}
}
}
$rs->MoveNext();
}
$include_file = "install/upgrade.php";
}
if ($state == "upgrade_process") {
$mod_arr = $_POST['modules'];
foreach($mod_arr as $p)
{
$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 != '') {
$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();
}
}
}
}
}
+ // upgrade language pack if some module upgrade options selected
+ if( isset($mod_arr) && is_array($mod_arr) )
+ {
+
+ }
+
$state = "finish";
$include_file = "install/install_finish.php";
}
if($state=="db_reconfig_save")
{
$ini_vars = parse_ini_file($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 = inst_GetADODBConnection();
if($ado->ErrorNo()!=0)
{
$db_error = "Connection Error: (".$ado->ErrorNo().") ".$ado->ErrorMsg();
$state = "db_reconfig";
}
else
{
if(!TableExists($ado,"ConfigurationAdmin,Category,Permissions"))
{
$state="db_reconfig";
$db_error = "An In-Portal Database was not found at this location";
}
else {
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();
$state = "finish";
$include_file = "install/install_finish.php";
}
}
}
if($state=="db_reconfig")
{
$include_file = "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.$path_char.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 = parse_ini_file($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.$path_char.'install'.$path_char.'inportal_remove.sql';
RunSchemaFile($ado,$filename);
$state="restore_run";
}
else {
$state = "warning";
$include_file = "install/warning.php";
}
}
else {
if ($_POST['backupdate'] != '') {
$include_file = "install/restore_select.php";
$restore_error = "$backupfile not found or could not be read";
}
else {
$include_file = "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 = "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 = "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 = parse_ini_file($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 = inst_GetADODBConnection();
if($ado->ErrorNo()!=0)
{
$db_error = "Connection Error: (".$ado->ErrorNo().") ".$ado->ErrorMsg();
$state = "dbinfo";
}
else
{
if(TableExists($ado,"ConfigurationAdmin,Category,Permissions"))
{
$state="dbinfo";
$db_error = "An In-Portal Database already exists at this location";
}
else
$state = "license";
}
}
if($state=="dbinfo")
{
if ($install_type == '') {
$install_type = 1;
}
$include_file = "install/dbinfo.php";
}
if ($state == "download_license") {
$ValidLicense = FALSE;
if ($_POST['login'] != '' && $_POST['password'] != '') {
// Here we determine weather login is ok & check available licenses
$rfile = @fopen(GET_LICENSE_URL."?login=".md5($_POST['login'])."&password=".md5($_POST['password'])."&domain=".$_SERVER['SERVER_NAME'], "r");
if (!$rfile) {
$get_license_error = "Unable to connect to the Intechnic server! Please try again later!";
$state = "get_license";
$include_file = "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 = "install/get_license.php";
}
else {
if (substr($rcontents, 0, 3) == "SEL") {
$state = "download_license";
$license_select = substr($rcontents, 4);
$include_file = "install/download_license.php";
}
else {
// Here we get one license
$data = base64_decode(str_replace("In-Portal License File - do not edit!\n", "", $rcontents));
inst_ParseLicense($data);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
if($ValidLicense)
{
set_ini_value("Intechnic","License",base64_encode($data));
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 = "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'])."&domain=".$_POST['domain'], "r");
if (!$rfile) {
$get_license_error = "Unable to connect to the Intechnic server! Please try again later!";
$state = "get_license";
$include_file = "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 = "install/download_license.php";
}
else {
$data = base64_decode(str_replace("In-Portal License File - do not edit!\n", "", $rcontents));
inst_ParseLicense($data);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
if($ValidLicense)
{
set_ini_value("Intechnic","License",base64_encode($data));
save_values();
$state="domain_select";
}
else {
$license_error="Invalid License File";
}
if(!$ValidLicense)
{
$state="license";
}
}
}
}
}
if($state=="license_process")
{
$ValidLicense = FALSE;
switch($_POST["lic_opt"])
{
case 1: /* download from intechnic */
$include_file = "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");
$fp = @fopen($pathtoroot."themes/tmp.lic","rb");
if($fp)
{
$lic = fread($fp,filesize($pathtoroot."themes/tmp.lic"));
fclose($fp);
}
$data = inst_LoadLicense(FALSE,$pathtoroot."themes/tmp.lic");
@unlink($pathtoroot."themes/tmp.lic");
inst_ParseLicense($data);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
if($ValidLicense)
{
set_ini_value("Intechnic","License",base64_encode($data));
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);
inst_ParseLicense($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:
$state="domain_select";
break;
}
if($ValidLicense)
$state="domain_select";
}
if($state=="license")
{
$include_file = "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>";
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 != '') {
if ($p == '') {
$p = 'in-portal';
}
$sql = "SELECT Version FROM ".$g_TablePrefix."Modules WHERE Name = '".$p."'";
$rs = $ado->Execute($sql);
if (str_replace(".", "", $rs->fields['Version']) < str_replace(".", "", $file)) {
$show_upgrade = true;
}
}
}
}
}
if ($install_type == '') {
$install_type = 2;
}
$include_file = "install/reinstall.php";
}
if($state=="login")
{
$lic = base64_decode($g_License);
if(strlen($lic))
{
inst_ParseLicense($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 = "install/login.php";
}
if($state=="set_domain")
{
if(!is_array($i_Keys))
{
$lic = base64_decode($g_License);
if(strlen($lic))
{
inst_ParseLicense($lic);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
}
}
if($_POST["domain"]==1)
{
$domain = $_SERVER['HTTP_HOST'];
set_ini_value("Intechnic","Domain",$domain);
save_values();
$state="runsql";
}
else
{
$domain = str_replace(" ", "", $_POST["other"]);
if ($domain != '') {
set_ini_value("Intechnic","Domain",$domain);
save_values();
$state="runsql";
}
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))
{
inst_ParseLicense($lic);
$ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
}
}
$include_file = "install/domain.php";
}
if($state=="runsql")
{
$ado = inst_GetADODBConnection();
$installed = TableExists($ado,"ConfigurationAdmin,Category,Permissions");
if(!$installed)
{
// create tables
$filename = $pathtoroot.$admin."/install/inportal_schema.sql";
RunSchemaFile($ado,$filename);
// insert default info
$filename = $pathtoroot.$admin."/install/inportal_data.sql";
RunSQLFile($ado,$filename);
$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 = "install/install_finish.php";
$state="finish";
}
}
if ($state == "finish") {
$include_file = "install/install_finish.php";
}
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($pass);
$sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '$pass' WHERE VariableName='RootPass' OR VariableName='RootPassVerify'";
$ado = inst_GetADODBConnection();
$ado->Execute($sql);
$state="modselect";
}
}
if($state=="RootPass")
{
$include_file = "install/rootpass.php";
}
if($state=="lang_install_init")
{
include_once($pathtoroot."kernel/include/xml.php");
$ado = inst_GetADODBConnection();
if (TableExists($ado, "Language,Phrase")) {
$MaxInserts = 200;
$PhraseTable = GetTablePrefix()."ImportPhrases";
$EventTable = GetTablePrefix()."ImportEvents";
$sql = "CREATE TABLE $PhraseTable SELECT Phrase,Translation,PhraseType,LanguageId FROM ".GetTablePrefix()."Phrase WHERE PhraseId=-1";
$ado->Execute($sql);
$sql = "CREATE TABLE $EventTable SELECT Template,MessageType,EventId,LanguageId FROM ".GetTablePrefix()."EmailMessage WHERE EmailMessageId=-1";
$ado->Execute($sql);
$sql = "SELECT EventId,Event,Type FROM ".GetTablePrefix()."Events";
$rs = $ado->Execute($sql);
$Events = array();
while($rs && !$rs->EOF)
{
$Events[$rs->fields["Event"]."_".$rs->fields["Type"]] = $rs->fields["EventId"];
$rs->MoveNext();
}
if(count($_POST["lang"])>0)
{
$Langs = $_POST["lang"];
for($x=0;$x<count($Langs);$x++)
{
$lang = $Langs[$x];
$p = $pathtoroot.$admin."/install/langpacks/".$lang;
/* parse xml file */
$fp = fopen($p,"r");
$xml = fread($fp,filesize($p));
fclose($fp);
unset($objInXML);
$objInXML = new xml_doc($xml);
$objInXML->parse();
$objInXML->getTag(0,$name,$attribs,$contents,$tags);
if(is_array($tags))
{
foreach($tags as $t)
{
$LangRoot =& $objInXML->getTagByID($t);
$PackName = $LangRoot->attributes["PACKNAME"];
$l = $objLanguages->GetItemByField("PackName",$PackName);
if(is_object($l))
{
$LangId = $l->Get("LanguageId");
}
else
{
$l = new clsLanguage();
$l->Set("Enabled",1);
$l->Create();
$NewLang = TRUE;
$LangId = $l->Get("LanguageId");
}
foreach($LangRoot->children as $tag)
{
switch($tag->name)
{
case "PHRASES":
foreach($tag->children as $PhraseTag)
{
$Phrase = $PhraseTag->attributes["LABEL"];
$Translation = base64_decode($PhraseTag->contents);
$PhraseType = $PhraseTag->attributes["TYPE"];
$psql = "INSERT INTO $PhraseTable (Phrase,Translation,PhraseType,LanguageId) VALUES ('$Phrase','$Translation',$PhraseType,$LangId)";
$ado->Execute($psql);
//echo "$psql <br>\n";
}
break;
case "DATEFORMAT":
$DateFormat = $tag->contents;
break;
case "TIMEFORMAT":
$TimeFormat = $tag->contents;
break;
case "DECIMAL":
$Decimal = $tag->contents;
break;
case "THOUSANDS":
$Thousands = $tag->contents;
break;
case "EVENTS":
foreach($tag->children as $EventTag)
{
$event = $EventTag->attributes["EVENT"];
$MsgType = strtolower($EventTag->attributes["MESSAGETYPE"]);
$template = base64_decode($EventTag->contents);
$Type = $EventTag->attributes["TYPE"];
$EventId = $Events[$event."_".$Type];
$esql = "INSERT INTO $EventTable (Template,MessageType,EventId,LanguageId) VALUES ('$template','$MsgType',$EventId,$LangId)";
$ado->Execute($esql);
//echo htmlentities($esql)."<br>\n";
}
break;
}
if($NewLang)
{
$l->Set("PackName",$PackName);
$l->Set("LocalName",$PackName);
$l->Set("DateFormat",$DateFormat);
$l->Set("TimeFormat",$TimeFormat);
$l->Set("DecimalPoint",$Decimal);
$l->Set("ThousandSep",$Thousands);
$l->Update();
}
}
}
}
}
$state="lang_install";
}
else {
$state="lang_select";
}
}
else {
$general_error = 'Database error! No language tables found!';
}
}
if($state=="lang_install")
{
/* do pack install */
$Offset = (int)$_GET["Offset"];
$Status = (int)$_GET["Status"];
$PhraseTable = GetTablePrefix()."ImportPhrases";
$EventTable = GetTablePrefix()."ImportEvents";
if($Status==0)
{
$Total = TableCount($PhraseTable,"",0);
}
else
{
$Total = TableCount($EventTable,"",0);
}
if($Status==0)
{
$Offset = $objLanguages->ReadImportTable($PhraseTable, 1,"0,1,2",TRUE,200,$Offset);
if($Offset>=$Total)
{
$Offset=0;
$Status=1;
}
if ($_POST['next_step']) {
$next_step = $_POST['next_step'];
}
else if ($_GET['next_step']) {
$next_step = $_GET['next_step'];
}
$NextUrl = $_SERVER['PHP_SELF']."?Offset=$Offset&Status=$Status&state=lang_install&next_step=$next_step&install_type=$install_type";
$include_file = "install/lang_run.php";
}
else
{
if(!is_object($objMessageList))
$objMessageList = new clsEmailMessageList();
$Offset = $objMessageList->ReadImportTable($EventTable,TRUE,100,$Offset);
if($Offset>$Total)
{
if ($_POST['next_step']) {
$next_step = $_POST['next_step'];
}
else if ($_GET['next_step']) {
$next_step = $_GET['next_step'];
}
$NextUrl = $_SERVER['PHP_SELF']."?Offset=$Offset&Status=$Status&State=lang_install&next_step=$next_step&install_type=$install_type";
$include_file = "install/lang_run.php";
}
else
$state="lang_default";
}
}
if($state=="lang_default_set")
{
// phpinfo(INFO_VARIABLES);
$ado = inst_GetADODBConnection();
$PhraseTable = GetTablePrefix()."ImportPhrases";
$EventTable = GetTablePrefix()."ImportEvents";
$ado->Execute("DROP TABLE $PhraseTable");
$ado->Execute("DROP TABLE $EventTable");
$Id = $_POST["lang"];
$objLanguages->SetPrimary($Id);
$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 = "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( !is_object($objTagList) ) $objTagList = new clsTagList();
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 != '') {
$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=="lang_select")
{
$Packs = GetLanguageList();
$include_file = "install/lang_select.php";
}
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["SERVER_NAME"]);
//$g_DomainName= $_SERVER["SERVER_NAME"];
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);
$Modules = inst_GetModuleList();
$include_file = "install/modselect.php";
}
if(substr($state,0,10)=="postconfig")
{
$p = explode("_",$state);
$step = $p[1];
if ($_POST['Site_Path'] != '') {
//echo "ok<br>";
$rfile = @fopen(GET_LICENSE_URL."?url=".base64_encode($_SERVER['SERVER_NAME'].$_POST['Site_Path'])."&domain=".md5($_SERVER['SERVER_NAME']), "r");
if (!$rfile) {
$get_license_error = "Unable to connect to the Intechnic server! Please try again later!";
$state = "postconfig_1";
$include_file = "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 = "install/postconfig.php";
}
else
$state = "theme_sel";
}
if($state=="theme_sel")
{
$objThemes->CreateMissingThemes();
$include_file = "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 = "install/install_finish.php";
$state="finish";
}
if ($state == "adm_login") {
echo "<script>window.location='index.php';</script>";
}
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>";
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>";
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;
}
if ($_POST['next_step']) {
$tmp_step = $_POST['next_step'];
}
else if ($_GET['next_step']) {
$tmp_step = $_GET['next_step'];
}
if (!$tmp_step) {
$tmp_step = 1;
}
if ($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;
}
?>
<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" alt=""><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 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 || $_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 == 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 == '') || $_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 == 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 == '') || $_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 } ?>>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 } ?>>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 echo $title;?></td>
</tr>
<tr>
<td class="text"><?php echo $help;?></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td id="footer">
Powered by In-portal &copy; 1997-2004, Intechnic Corporation. All rights reserved.
<br><img src="images/spacer.gif" width="1" height="10" alt="">
</td>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file
Property changes on: trunk/admin/install.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property
Index: trunk/admin/import/import.php
===================================================================
--- trunk/admin/import/import.php (revision 23)
+++ trunk/admin/import/import.php (revision 24)
@@ -1,927 +1,927 @@
<?php
#import script
#taking care of actual importing from in-link db to in-portal db
if(!strlen($pathtoroot))
{
$path=dirname(realpath($_SERVER['SCRIPT_FILENAME']));
if(strlen($path))
{
/* determine the OS type for path parsing */
$pos = strpos($path,":");
if ($pos === false)
{
$gOS_TYPE="unix";
$pathchar = "/";
}
else
{
$gOS_TYPE="win";
$pathchar="\\";
}
$p = $path.$pathchar;
/*Start looking for the root flag file */
while(!strlen($pathtoroot) && strlen($p))
{
$sub = substr($p,strlen($pathchar)*-1);
if($sub==$pathchar)
{
$filename = $p."root.flg";
}
else
$filename = $p.$pathchar."root.flg";
if(file_exists($filename))
{
$pathtoroot = $p;
}
else
{
$parent = realpath($p.$pathchar."..".$pathchar);
if($parent!=$p)
{
$p = $parent;
}
else
$p = "";
}
}
if(!strlen($pathtoroot))
$pathtoroot = ".".$pathchar;
}
else
{
$pathtoroot = ".".$pathchar;
}
}
$sub = substr($pathtoroot,strlen($pathchar)*-1);
if($sub!=$pathchar)
{
$pathtoroot = $pathtoroot.$pathchar;
}
require_once($pathtoroot."kernel/startup.php");
$admin = $objConfig->Get("AdminDirectory");
if(!strlen($admin))
$admin = "admin";
-print_pre($_REQUEST);
+
if ($_POST["Action"]=="Import")
{
$objSession->SetVariable("import_user_admin",$_POST["user_admin"]);
$objSession->SetVariable("import_user_regular",$_POST["user_regular"]);
$objSession->SetVariable("import_init_cat",$_POST["init_cat"]);
$objSession->SetVariable("image_name",$_POST["image_name"]);
$objSession->SetVariable("importtodo","initialize");
$objSession->SetVariable("importstart",0);
$objSession->SetVariable("importtotal",0);
if((int)$_POST["init_cat"]>0)
{
$c = $objCatList->GetItemByField("ResourceId",(int)$_POST["init_cat"]);
$c->UpdateACL();
$c->UpdateCachedPath();
}
}
$allgroups = $objGroups->GetAllGroupList();
$inlink_sql_type=$objSession->GetVariable("import_inlink_sql_type");
$inlink_server=$objSession->GetVariable("import_inlink_server");
$inlink_db=$objSession->GetVariable("import_inlink_db");
$inlink_user=$objSession->GetVariable("import_inlink_user");
$inlink_pass=$objSession->GetVariable("import_inlink_pass");
$user_admin=$objSession->GetVariable("import_user_admin");
$user_regular=$objSession->GetVariable("import_user_regular");
if(!is_object($c))
$c = $objCatList->GetItemByField("ResourceId",$objSession->GetVariable("import_init_cat"));
$init_cat= $c->Get("CategoryId");
$image_name=$objSession->GetVariable("image_name");
$start = $objSession->GetVariable("importstart");
$acl = explode(",",$c->GetACL("CATEGORY.VIEW"));
//IN-LINK connection
$linkconn=&ADONewConnection($inlink_sql_type);
$linkconn->PConnect($inlink_server, $inlink_user, $inlink_pass, $inlink_db);
if(!$linkconn)
{ echo "Database connection failed. DB Type: $sql_type, DB Server: $inlink_server, DB User: $inlink_user, DB Name: $inlink_db"; //fatal;
echo $linkconn->ErrorMsg();
die();
}
if($pconnect)
{
$linkconn->Close();
$linkconn = ADONewConnection($inlink_sql_type);
$linkconn->PConnect($inlink_server, $inlink_user, $inlink_pass, $inlink_db);
}
//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 Section
$section = "in-portal:inlink_inport";
//Set Environment Variable
$envar = "env=" . BuildEnv();
$sec = $objSections->GetSection($section);
$objCatToolBar = new clsToolBar();
$title = admin_language("la_performing_import")." - ".admin_language("la_Step")." 4";
//In-Portal
$portalconn = GetAdodbConnection();
$TablePrefix = "ses_".$objSession->GetSessionKey()."_".GetTablePrefix();
$olddbname=$inlink_db;
//$newdbname="inportal";
$newdbname=$g_DBName;
##############creating a temproary table have to be here
if ($_POST["Action"]=="Import")
{
$portalconn->Execute("DROP TABLE ".$TablePrefix."import");
$portalconn->Execute("DROP TABLE ".$TablePrefix."importcat");
$temptable = "CREATE TABLE ".$TablePrefix."import (otname varchar(40), oid int(11), ocustomid int(11), oparentid int(11), ntname varchar(40), nid int(11), nrid int(11), npid int(11)) ";
$portalconn->Execute($temptable);
$cattable ="CREATE TABLE ".$TablePrefix."importcat (op int(11), np int(11), flag int(11)) ";
$portalconn->Execute($cattable);
$newcat = 1;
}
global $admin, $pathtoroot;
require_once ($pathtoroot.$admin."/import/status.php"); #for status bar and all visual effects
$todo= $objSession->GetVariable("importtodo");
$total = $objSession->GetVariable("importtotal");
switch ($todo)
{
case "users":
status($start, $total, "users");
usersimport();
//setstart(0,"cats"); #for debugging
break;
case "cats":
status($start, $total, "cats");
catmanager();
#setstart(0,"links"); #for debugging
break;
case "links":
status($start, $total, "links");
linksimport();
#setstart(0,"custom");#For debugging only
break;
case "custom":
status($start, $total, "custom");
customimport();
#setstart(0,"relcat");#for debuggin only
break;
case "relcat":
status($start, $total, "relcat");
relcatimport();
#setstart(0,"terminate"); #for debuggin only
break;
case "terminate":
terminator();
status(1,1,"terminate");
break;
default:
status(0,0,"initializing");
setstart(0,"users"); #to start importing from users first
break;
}
function terminator()
{
global $portalconn;
$query="DROP TABLE IF EXISTS ".$TablePrefix."import, ".$TablePrefix."importcat";
$portalconn->Execute($query);
}
function reload()
{
global $newurl;
print '<script language="javascript">' ;
print " setTimeout('location.href=location.href',40);";
print ' </script>';
}
function setstart($mystart, $part)
{
global $objSession;
$objSession->SetVariable("importstart",$mystart);
$objSession->SetVariable("importtodo",$part);
reload();
}
function settotal($total)
{
global $objSession;
$objSession->SetVariable("importtotal",$total);
}
//users import from inlink to inportal
function usersimport()
{
global $objUsers, $objSession, $linkconn, $portalconn, $olddbname,
$user_admin,$objGroups, $user_regular, $start;
$counter = 0;
$limit = 350;
$oldtablename = "inl_users";
$newtablename = $objUsers->SourceTable;
if ($start == 0)
{
$query="select count(*) as NumUsers from inl_users";
$row =$linkconn->Execute($query);
if ($row && !$row->EOF)
{
settotal($row->fields["NumUsers"]);
}
}
$query="select * from inl_users LIMIT $start, $limit";
$row =$linkconn->Execute($query);
while($row && !$row->EOF)
{
$counter++; #needed to know when close to time out
if ($row->fields['user_name'] != "root") {
$olduserid=$row->fields["user_id"];
//$Login, $Password, $Email, $CreatedOn, $FirstName="", $LastName="", $Status=2,
// $Phone="", $Street="", $City="", $State="", $Zip="", $Country=""
if($row->fields["user_status"]==1)
{
$Status=1;
}
else
{
if($row->fields["user_pend"]==0)
{
$Status=2;
}
else
$Status=0;
}
$u = $objUsers->Add_User( $row->fields["user_name"], $row->fields["user_pass"], $row->fields["email"],
$row->fields["user_date"], $row->fields["first"], $row->fields["last"],
$Status);
$oldid=$row->fields["user_id"];
$oldcustom=$row->fields["user_cust"];
$newid=$u->Get("PortalUserId");
$resid=$u->Get("ResourceId");
#adding user to usergroup
$userpermission = $row->fields["user_perm"];
if ($userpermission==2 || $userpermission==1)
{
$glist = explode(",",$user_admin);
$Primary=1;
for($i=0;$i<count($glist);$i++)
{
$group=$objGroups->GetItem($glist[$i]);
$group->AddUser($newid,$Primary);
$Primary = 0;
}
}
else
{
$glist = explode(",",$user_regular);
$Primary=1;
for($i=0;$i<count($glist);$i++)
{
$group=$objGroups->GetItem($glist[$i]);
$group->AddUser($newid,$Primary);
$Primary = 0;
}
}
//$group=$objGroups->GetItem($g);
//$group->AddUser($newid,1);
#inserting values to the temproary table
$totemp = "INSERT INTO ".$TablePrefix."import (otname,oid,ocustomid,oparentid,ntname,nid,nrid,npid) ";
$tovalues= " VALUES ('$oldtablename',$olduserid,$oldcustom,0,'$newtablename', $newid, $resid, 0 )";
$totemp=$totemp.$tovalues;
$portalconn->Execute($totemp);
}
$row->moveNext();
}
if ($counter == $limit)
{
setstart($start+$limit, "users");
}
else
setstart(0,"cats");
}
//END OF USERS IMPORT ^^^^^^^^^^^^^^^^^^^^^
//Categories Import
function catmanager()
{
global $portalconn, $init_cat,$start;
if ($start == 0)
{
$counter = catimport(0,$init_cat);
setstart($counter,"cats");
$portalconn->Execute("UPDATE ".$TablePrefix."importcat SET flag=1 WHERE np=$init_cat");
}
else
{
$query="select * from ".$TablePrefix."importcat WHERE flag=0 LIMIT 0,1";
$row =$portalconn->Execute($query);
if($row && !$row->EOF)
{
$oldid= $row->fields["op"];
$newid = $row->fields["np"];
$counter= catimport($oldid,$newid);
$query2="UPDATE ".$TablePrefix."importcat SET flag=1 WHERE op=$oldid and np=$newid";
$portalconn->Execute($query2);
setstart($counter+$start-1,"cats");
$x=5;
}
else
{
setstart(0,"links");
}
}
}
#pushes into the quque
function pushid($op,$np)
{
global $linkconn, $portalconn;
$addnew = "INSERT INTO ".$TablePrefix."importcat (op,np,flag) VALUES ($op,$np,0)";
$portalconn->Execute($addnew);
}
function checkifexist($id)
{
global $linkconn;
$addnew = "select * from inl_cats where cat_sub=$id";
$row =$linkconn->Execute($addnew);
if ($row && !$row->EOF)
{
if ($row->fields["cat_id"] !=0)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
#import itself
function catimport($oldparentid, $parentid)
{
global $objCatList, $linkconn, $objUsers, $linkconn, $portalconn,
$olddbname, $user_admin,$objGroups, $user_regular, $acl,$allgroups, $c, $start;
$counter=0;
$objCacheCount = new clsCacheCountList();
if ($start == 0)
{
$query="select count(*) as CatCount from inl_cats";
$row =$linkconn->Execute($query);
if ($row && !$row->EOF)
{
settotal($row->fields["CatCount"]);
$catcount = $row->fields["CatCount"];
$catcount += (int)$c->Get("CachedDescendantCatsQty");
$c->Set("CachedDescendantCatsQty",$catcount);
$c->Update();
}
}
$query="select * from inl_cats WHERE cat_sub=$oldparentid";
$oldtablename = "inl_cats";
$newtablename = "Category";
$row =$linkconn->Execute($query);
if($row && !$row->EOF)
{
$RowCount = $row->NumRows();
$ResInc = $RowCount;
$ResourceId = GetNextResourceId($ResInc);
}
if($parentid>0)
{
$ParentCat = new clsCategory($parentid);
$Path = $ParentCat->Get("ParentPath");
}
while($row && !$row->EOF)
{
$counter++;
$cat = new clsCategory();
if($row->fields["cat_pend"]==0)
{
$Status=1;
}
else
{
if($row->fields["cat_vis"]==0)
{
$Status=2;
}
else
$Status=0;
}
$CreatedById = getnewid($row->fields["cat_id"]);
$cat->Set(array("ParentId", "Name", "Description", "CreatedOn", "EditorsPick", "Status", "HotItem",
"NewItem","PopItem", "Priority", "MetaKeywords", "MetaDescription", "CreatedById",
"CachedDescendantCatsQty"),
array($parentid, $row->fields["cat_name"], $row->fields["cat_desc"],
$row->fields["cat_date"], (int)$row->fields["cat_pick"], $Status, 2, 2, 2, 0,
$row->fields["meta_keywords"],$row->fields["meta_desc"],
(int)$CreatedById,(int)$row->fields["cat_cats"]));
$cat->Set("ResourceId",$ResourceId);
$ResourceId++;
$cat->Create();
$FullPath = $Path.$cat->Get("CategoryId")."|";
$cat->Set("ParentPath",$FullPath);
$cat->SetViewPerms("CATEGORY.VIEW",$acl,$allgroups);
$cat->Update();
$cat->UpdateCachedPath();
$objCacheCount->CategoryId= $cat->Get("CategoryId");
$objCacheCount->SetValue(0,0,0,0,0);
$newid = $cat->Get("CategoryId");
$resid = $cat->Get("ResourceId");
$oldid = $row->fields["cat_id"];
$oldcustom = $row->fields["cat_cust"];
$oldpid = $row->fields["cat_sub"];
#inserting values to the temproary table
$totemp = "INSERT INTO ".$TablePrefix."import (otname,oid,ocustomid,oparentid,ntname,nid,nrid,npid) ";
$tovalues= " VALUES ('$oldtablename',$oldid,$oldcustom,$oldpid,'$newtablename', $newid, $resid, $parentid )";
$totemp=$totemp.$tovalues;
$portalconn->Execute($totemp);
#pushes into the queue
if(checkifexist($oldid))
{
pushid($oldid,$newid);
}
$row->moveNext();
}
return $counter;
}
//Links Import
function linksimport()
{
global $objLinkList, $init_cat, $linkconn, $portalconn, $olddbname,
$user_admin,$objGroups, $user_regular, $start;
$limit = 750; #need to change to a higher number like 100, forty is only for debugging
$counter = 0;
set_time_limit(0);
if ($start == 0)
{
$query="select count(*) as LinkCount from inl_lc";
$row =$linkconn->Execute($query);
if ($row && !$row->EOF)
{
settotal($row->fields["LinkCount"]);
}
}
$query="select * from inl_lc INNER JOIN inl_links ON (inl_lc.link_id=inl_links.link_id) limit $start,$limit";
$oldtablename="inl_links";
$newtablename="link";
$row =$linkconn->Execute($query);
if($row && !$row->EOF)
{
$RowCount = $row->NumRows();
$ResInc = $RowCount;
$ResourceId = GetNextResourceId($ResInc);
}
while($row && !$row->EOF)
{
$counter++;
$oldid=$row->fields["link_id"];
$flag=1;
$oldcatid = $row->fields["cat_id"];
$pending = $row->fields["link_pend"];
#getting a new category id
$rs = $portalconn->Execute("SELECT nid FROM ".$TablePrefix."import WHERE ntname='Category' and oid=$oldcatid");
if ($rs && ! $rs->EOF)
{
$categoryid=$rs->fields["nid"];
}
else
{
$categoryid = $init_cat;
}
$rs = $portalconn->Execute("SELECT * FROM ".$TablePrefix."import WHERE otname='inl_link' AND oid='$oldid'");
if($rs && ! $rs->EOF)
{
$NewLinkId = $rs->fields["nid"];
}
else
$NewLinkId=0;
if ($NewLinkId==0)
{
#gets the new user id of the user who created a link
$newuserid=getnewid($row->fields["link_user"]);
#adds link to the IN-PORTAL
$link = new clsLink();
if($Pending==0)
{
$Status=1;
}
else
$Status=2;
$link->Set(array("Name", "Description", "Url", "CreatedOn", "Status", "EditorsPick",
"NewItem","PopItem","HotItem", "CreatedById", "CachedRating",
"CachedVotesQty","Hits", "Priority"),
array($row->fields["link_name"], $row->fields["link_desc"], $row->fields["link_url"], $row->fields["link_date"], $Status,
$row->fields["link_pick"], 2, 2, 2, $newuserid, (int)$row->fields["link_rating"],
(int)$row->fields["link_votes"],(int)$row->fields["link_hits"], 0));
$link->Set("ResourceId",$ResourceId);
$ResourceId++;
$link->Create();
$link->AddToCategory($categoryid,"",1);
$newid = $link->Get("LinkId");
$resid = $link->Get("ResourceId");
$oldcustom=$row->fields["link_cust"];
$linkimage =$row->fields["link_image"];
if ($linkimage)
{
addimage($resid,$linkimage);
}
#calls to import reviews
reviewimport($link,$oldid,$resid);
$parentid = 0;
$totemp = "INSERT INTO ".$TablePrefix."import (odb,otname,oid,ocustomid,oparentid,ndb,ntname,nid,nrid,npid) ";
$tovalues= " VALUES ('$olddbname','$oldtablename',$oldid,$oldcustom,$oldcatid,'inportal','$newtablename', $newid, $resid, $parentid )";
$totemp = $totemp.$tovalues;
//$portalconn->Execute($totemp);
}
else #if link is related to more than one category
{
$link = new clsLink($NewLinkId);
$link->AddtoCategory($categoryid,"",0);
}
#prelast while
$row->moveNext();
}
if ($counter == $limit)
{
setstart($start+$limit, "links");
}
else
{
setstart(0,"custom");
}
}
#importing image from the in-link
function addimage($resourceid, $imageurl)
{
global $objImageList, $image_name;
#echo "<br />IMAGE RESOURCEID: $resourceid IMAGE URL: $imageurl <br />";
if(!is_object($objImageList))
$objImageList = new clsImageList();
$LocalImage = 0;
$LocalThumb = 0;
if(!strlen($image_name))
$image_name="inlink_image";
$img = $objImageList->Add($image_name,"",$resourceid, 0, 0,"", $imageurl, 1,0, 1, 0,1);
}
#Reviews Import for links
function reviewimport($myclass,$oldid,$rid)
{
global $objCustomFieldList, $linkconn, $portalconn;
#ITEM AddReview($createdBy,$reviewText,0)
$query="select * from inl_reviews where rev_link= $oldid";
$row =$linkconn->Execute($query);
while($row && !$row->EOF)
{
$oldreviewuser= $row->fields["rev_user"];
if($oldreviewuser !=0) #meaning was not created by guest
{
$newrid=getnewid($oldreviewuser);
if ($newrid)
{
$temp=$myclass->AddReview($newrid,$row->fields["rev_text"],0,"127.0.0.1",1, "In-Link");
}
else
{
$temp=$myclass->AddReview(0,$row->fields["rev_text"],0,"127.0.0.1",1, "In-Link");
}
}
else #meaning was created by guest
{
$temp=$myclass->AddReview(0,$row->fields["rev_text"],0,"127.0.0.1",1, "In-Link");
}
$row->moveNext();
}
}
#HELPER FUNCTION THAT GETS THE NEW ID of the USER
function getnewid($oldid)
{
global $portalconn;
$query2="select * from ".$TablePrefix."import where otname='inl_users' and oid=".$oldid;
$row2=$portalconn->Execute($query2);
if ($row2->fields["nid"])
{
return $row2->fields["nid"];
}
else
{
return 0;
}
}
//^^^^^^^^^^^^^^^^^^^^^^ABOVE IS LINKS IMPORT
#########################################Custom Fields Import
#create a new CustomField first and then
#by selecting all and receiving from one record of inl_config the values of cc1,cc2,cc3,cc4,cc5,cc6,uc1,uc2,uc3,uc4,uc5,uc6,lc1,lc2,lc3,lc4,lc5,lc6
#go through all import table and if ocustomid occures get the row from inl_custom and
#create CustomMetaData field
#---------------------
#Regarding CustomField:
#FieldName= cc1,cc2 .... from inl_config
#FieldLabel= value of cc1, cc2 ....
#Type=4 for links 6 for users 0 category
#------------
#Regarding CustomMetaData
#ResourceId <= link id
#CustomFieldId <= id from the top
#Value = Value from the table custom
//VVVVV BELOW ARE CUSTOM FIELD IMPORT REQUIRES TO HAVE A TEMPROARY TABLE IMPORT
function customimport()
{
global $linkconn, $portalconn, $start;
$limit = 40; #just for debugging purposes, in real life set it to higher number
$counter=0;
if ($start == 0)
{
$r=buildfields();
$query="SELECT count(*) as cc from ".$TablePrefix."import WHERE NOT ocustomid=0";
$row =$portalconn->Execute($query);
if ($row && !$row->EOF)
{
settotal($row->fields["cc"]);
}
}
else
{
$r=getfields();
}
$query="SELECT * from ".$TablePrefix."import WHERE ocustomid!=0 limit $start,$limit";
$row =$portalconn->Execute($query);
while($row && !$row->EOF)
{
$counter++;
if ($row->fields["ocustomid"]!=0)
{
loadcustom($row->fields["ocustomid"],$row->fields["nrid"],$row->fields["otname"],$r);
}
$row->moveNext();
}
if ($counter == $limit)
{
setstart($start+$limit, "custom");
}
else
{
setstart(0,"relcat");
}
}
function loadcustom($customid,$rid,$tablename,$r)
{
global $linkconn, $objCustomDataList, $objSession;
$objCustomDataList->Clear();
if ($tablename =="inl_cats")
{
//$myfieldname="cc";
$fields = explode(",",$objSession->GetVariable("custom_category"));
}
else if($tablename =="inl_users")
{
//$myfieldname="uc";
$fields = explode(",",$objSession->GetVariable("custom_user"));
}
else if($tablename =="inl_links")
{
//$myfieldname="lc";
$fields = explode(",",$objSession->GetVariable("custom_links"));
}
$oldtablename="inl_links";
$newtablename="link";
$query="select * from inl_custom Where cust_id=$customid";
$row =$linkconn->Execute($query);
if ($row)
{
for ($x=0; $x<count($fields);$x++)
{
$cust=$row->fields["cust".$x];
if ($cust!="")
{
$fieldid =$r[$fields[$x]];
$objCustomDataList->SetFieldValue($fieldid,$rid,$cust);
}
}
$objCustomDataList->SaveData();
}
}
function buildfields() #building and populating an array
{
global $objCustomFieldList, $objSession,$linkconn;
$lc="lc";
$uc="uc";
$cc="cc";
$query = "SELECT * FROM inl_config WHERE name LIKE 'uc%'";
$row =$linkconn->Execute($query);
$names = array();
while($row && !$row->EOF)
{
$data = $row->fields;
$fieldlabel=$data["name"];
if(strlen($data["value"]))
{
$fieldlabel = $data["value"];
}
$f=$objCustomFieldList->AddField(6,$data["name"],$fieldlabel);
$r["'".$data["name"]."'"]=$f->Get("CustomFieldId");
$objSession->SetVariable("custom_".$data["name"],$f->Get("CustomFieldId"));
$names[] = $data["name"];
$row->MoveNext();
}
$objSession->SetVariable("custom_user",implode(",",$names));
unset($names);
$names = array();
$query = "SELECT * FROM inl_config WHERE name LIKE 'cc%'";
$row =$linkconn->Execute($query);
while($row && !$row->EOF)
{
$data = $row->fields;
$fieldlabel=$data["name"];
if(strlen($data["value"]))
{
$fieldlabel = $data["value"];
}
$f=$objCustomFieldList->AddField(1,$data["name"],$fieldlabel);
$r["'".$data["name"]."'"]=$f->Get("CustomFieldId");
$objSession->SetVariable("custom_".$data["name"],$f->Get("CustomFieldId"));
$names[] = $data["name"];
$row->MoveNext();
}
$objSession->SetVariable("custom_category",implode(",",$names));
unset($names);
$names = array();
$query = "SELECT * FROM inl_config WHERE name LIKE 'lc%'";
$row =$linkconn->Execute($query);
while($row && !$row->EOF)
{
$data = $row->fields;
$fieldlabel=$data["name"];
if(strlen($data["value"]))
{
$fieldlabel = $data["value"];
}
$f=$objCustomFieldList->AddField(4,$data["name"],$fieldlabel);
$r["'".$data["name"]."'"]=$f->Get("CustomFieldId");
$objSession->SetVariable("custom_".$data["name"],$f->Get("CustomFieldId"));
$names[] = $data["name"];
$row->MoveNext();
}
$objSession->SetVariable("custom_links",implode(",",$names));
return $r;
}
function getfields() #building and populating an array
{
global $objSession;
$lc="lc";
$uc="uc";
$cc="cc";
$userfields = explode(",",$objSession->GetVariable("custom_user"));
for ($x=0;$x<=count($userfields);$x++)
{
$r[$userfields[$x]]=$objSession->GetVariable("custom_".$userfields[$x]);
}
$catfields = explode(",",$objSession->GetVariable("custom_category"));
for ($x=0;$x<=count($catfields);$x++)
{
$r[$catfields[$x]]=$objSession->GetVariable("custom_".$catfields[$x]);
}
$linkfields = explode(",",$objSession->GetVariable("custom_links"));
for ($x=0;$x<=count($linkfields);$x++)
{
$r[$linkfields[$x]]=$objSession->GetVariable("custom_".$linkfields[$x]);
}
return $r;
}
################################################Relationships Import
function relcatimport()
{
global $linkconn,$objSession, $start;
$limit = 100;
$counter =0;
if ($start == 0)
{
$query="SELECT count(*) from inl_rel_cats";
$row =$linkconn->Execute($query);
if ($row && !$row->EOF)
{
settotal($row->fields[0]);
}
}
$objRelList = new clsRelationshipList();
$query="select * from inl_rel_cats LIMIT $start, $limit";
$row =$linkconn->Execute($query);
while($row && !$row->EOF)
{
$counter++;
$sourceid = newcatrid($row->fields["cat_id"]);
$targetid = newcatrid($row->fields["rel_id"]);
if ($sourceid !="" && $targetid !="")
{
$r = $objRelList->Add($sourceid, 1,$targetid, 1);
$r->Create();
}
$row->moveNext();
}
if ($counter == $limit)
{
setstart($start+$limit, "relcat");
}
else
{
setstart(0,"terminate");
}
}
function newcatrid($oid)
{
global $portalconn;
$query2="select * from ".$TablePrefix."import where otname='inl_cats' and oid=$oid";
$row =$portalconn->Execute($query2);
if ($row->fields["nrid"])
{
return $row->fields["nrid"];
}
else
{
return "";
}
}
// END OF RELATIONSHIP IMPORT
?>
\ No newline at end of file
Property changes on: trunk/admin/import/import.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property
Index: trunk/globals.php
===================================================================
--- trunk/globals.php (revision 23)
+++ trunk/globals.php (revision 24)
@@ -1,1313 +1,1272 @@
<?php
//global $g_DBType,$g_DBHost,$g_DBUser,$g_DBUserPassword,$g_DBName,$g_EnableCookies;
$vars = parse_ini_file($pathtoroot."config.php");
while($key = key($vars))
{
$key = "g_".$key;
global $$key;
$$key = current($vars); //variable variables
next($vars);
}
/*list the tables which contain item data */
$ItemTables = array();
$KeywordIgnore = array();
global $debuglevel;
$debuglevel=0;
$_GLOBALS["debuglevel"]=0;
/*New, Hot, Pop field values */
define('NEVER', 0);
define('ALWAYS', 1);
define('AUTO', 2);
/*Status Values */
define('STATUS_DISABLED', 0);
define('STATUS_ACTIVE', 1);
define('STATUS_PENDING', 2);
$LogLevel=0;
$LogFile = NULL;
function &GetADODBConnection()
{
global $g_adodbConnection, $g_DBType, $g_DBHost,$g_DBUser,$g_DBUserPassword,$g_DBName,$g_DebugMode;
global $ADODB_FETCH_MODE,$ADODB_COUNTRECS,$ADODB_CACHE_DIR,$pathtoroot;
if(!isset($g_adodbConnection) && strlen($g_DBType)>0)
{
$g_adodbConnection = ADONewConnection($g_DBType);
$connected = $g_adodbConnection->Connect($g_DBHost,$g_DBUser,$g_DBUserPassword,$g_DBName);
if(!$connected)
{
echo "Error connecting to database $g_DBHost <br>\n";
die();
}
$ADODB_CACHE_DIR = $pathtoroot."cache";
$ADODB_FETCH_MODE = 2;
$ADODB_COUNTRECS = FALSE;
$g_adodbConnection->debug = false;
$g_adodbConnection->cacheSecs = 3600;
}
elseif (!strlen($g_DBType)) {
global $rootURL;
echo "In-Portal is probably not installed, or configuration file is missing.<br>";
echo "Please use the installation script to fix the problem.<br><br>";
if (!preg_match('/admin/', $_SERVER['SCRIPT_FILENAME'])) {
$ins = 'admin/';
}
echo "<a href='$rootURL".$ins."install.php'>Go to installation script</a><br><br>";
flush();
die();
}
return $g_adodbConnection;
}
function GetNextResourceId($Increment=1)
{
$sql = "UPDATE ".GetTablePrefix()."IdGenerator SET lastid=lastid+".$Increment;
$adodbConnection = GetADODBConnection();
$adodbConnection->Execute($sql);
$rs = $adodbConnection->Execute("SELECT lastid FROM ".GetTablePrefix()."IdGenerator");
$val = $rs->fields["lastid"];
if(!$rs || $rs->EOF)
{
echo $adodbConnection->ErrorMsg();
$sql = "INSERT INTO ".GetTablePrefix()."IdGenerator (lastid) VALUES ($Increment)";
$adodbConnection->Execute($sql);
$val = 1;
}
$val = $val-($Increment-1);
return $val;
}
function AddSlash($s)
{
if(substr($s,-1) != "/")
{
return $s."/";
}
else
return $s;
}
function StripNewline($s)
{
$bfound = false;
while (strlen($s)>0 && !$bfound)
{
if(ord(substr($s,-1))<32)
{
$s = substr($s,0,-1);
}
else
$bfound = true;
}
return $s;
}
function DeleteElement($array, $indice)
{
for($i=$indice;$i<count($array)-1;$i++)
$array[$i] = $array[$i+1];
unset($array[count($array)-1]);
return $array;
}
function DeleteElementValue($needle, &$haystack)
{
while(($gotcha = array_search($needle,$haystack)) > -1)
unset($haystack[$gotcha]);
}
function TableCount($TableName, $where="",$JoinCats=1)
{
$db = GetADODBConnection();
if(!$JoinCats)
{
$sql = "SELECT count(*) as TableCount FROM $TableName";
}
else
$sql = "SELECT count(*) as TableCount FROM $TableName INNER JOIN ".GetTablePrefix()."CategoryItems ON ".GetTablePrefix()."CategoryItems.ItemResourceId=$TableName.ResourceId";
if(strlen($where)>0)
$sql .= " WHERE ".$where;
$rs = $db->Execute($sql);
// echo "SQL TABLE COUNT: ".$sql."<br>\n";
$res = $rs->fields["TableCount"];
return $res;
}
Function QueryCount($sql)
{
$countsql = "SELECT count(*) as TableCount ".substr($sql,strpos($sql," FROM "));
if(strpos($countsql,"LIMIT"))
$countsql = substr($countsql,0,strpos($countsql,"LIMIT"));
if(strpos($countsql,"ORDER BY"))
$countsql = substr($countsql,0,strpos($countsql,"ORDER BY"));
$db = GetADODBConnection();
$rs = $db->Execute($countsql);
//echo $countsql."<br>\n";
$res = $rs->fields["TableCount"];
return $res;
}
function GetPageCount($ItemsPerPage,$NumItems)
{
if($ItemsPerPage==0 || $NumItems==0)
{
return 1;
}
$value = $NumItems/$ItemsPerPage;
return ceil($value);
}
function GetTablePrefix()
{
global $g_TablePrefix;
return $g_TablePrefix;
}
function TableHasPrefix($t)
{
$pre = GetTablePrefix();
if(strlen($pre)>0)
{
if(substr($t,0,strlen($pre))==$pre)
{
return TRUE;
}
else
return FALSE;
}
else
return TRUE;
}
function AddTablePrefix($t)
{
if(!TableHasPrefix($t))
$t = GetTablePrefix().$t;
return $t;
}
function ThisDomain()
{
global $objConfig, $g_Domain;
if($objConfig->Get("DomainDetect"))
{
$d = $_SERVER['HTTP_HOST'];
}
else
$d = $g_Domain;
return $d;
}
function GetIndexUrl($secure=0)
{
global $indexURL, $rootURL, $secureURL;
switch($secure)
{
case 0:
$ret = $indexURL;
break;
case 1:
$ret = $secureURL."index.php";
break;
case 2:
$ret = $rootURL."index.php";
break;
default:
$ret = $i;
}
return $ret;
}
function GetLimitSQL($Page,$PerPage)
{
if($Page<1)
$Page=1;
if(is_numeric($PerPage))
{
if($PerPage==0)
$PerPage = 20;
$Start = ($Page-1)*$PerPage;
$limit = "LIMIT ".$Start.",".$PerPage;
}
else
$limit = NULL;
return $limit;
}
function filelist ($currentdir, $startdir=NULL,$ext=NULL)
{
global $pathchar;
//chdir ($currentdir);
// remember where we started from
if (!$startdir)
{
$startdir = $currentdir;
}
$d = @opendir($currentdir);
$files = array();
if(!$d)
return $files;
//list the files in the dir
while (false !== ($file = readdir($d)))
{
if ($file != ".." && $file != ".")
{
if (is_dir($currentdir."/".$file))
{
// If $file is a directory take a look inside
$a = filelist ($currentdir."/".$file, $startdir,$ext);
if(is_array($a))
$files = array_merge($files,$a);
}
else
{
if($ext!=NULL)
{
$extstr = stristr($file,".".$ext);
if(strlen($extstr))
$files[] = $currentdir."/".$file;
}
else
$files[] = $currentdir.'/'.$file;
}
}
}
closedir ($d);
return $files;
}
function DecimalToBin($dec,$WordLength=8)
{
$bits = array();
$str = str_pad(decbin($dec),$WordLength,"0",STR_PAD_LEFT);
for($i=$WordLength;$i>0;$i--)
{
$bits[$i-1] = (int)substr($str,$i-1,1);
}
return $bits;
}
function inp_escape($in, $html_enable=0)
{
$out = stripslashes($in);
$out = str_replace("\n", "\n^br^", $out);
if($html_enable==0)
{
$out=ereg_replace("<","&lt;",$out);
$out=ereg_replace(">","&gt;",$out);
$out=ereg_replace("\"","&quot;",$out);
$out = str_replace("\n^br^", "\n<br />", $out);
}
else
$out = str_replace("\n^br^", "\n", $out);
$out=addslashes($out);
return $out;
}
function inp_unescape($in)
{
$out=stripslashes($in);
return $out;
}
function inp_textarea_unescape($in)
{
$out=stripslashes($in);
$out = str_replace("\n<br />", "\n", $out);
return $out;
}
function HighlightKeywords($Keywords, $html, $OpenTag="", $CloseTag="")
{
global $objConfig;
if(!strlen($OpenTag))
$OpenTag = "<B>";
if(!strlen($CloseTag))
$CloseTag = "</B>";
$r = preg_split('((>)|(<))', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($Keywords as $k) {
for ($i = 0; $i < count($r); $i++) {
if ($r[$i] == "<") {
$i++; continue;
}
$r[$i] = preg_replace("/($k)/i", "$OpenTag\\1$CloseTag", $r[$i]);
}
}
return join("", $r);
}
/*
function HighlightKeywords($Keywords,$html, $OpenTag="", $CloseTag="")
{
global $objConfig;
if(!strlen($OpenTag))
$OpenTag = "<B>";
if(!strlen($CloseTag))
$CloseTag = "</B>";
$ret = strip_tags($html);
foreach ($Keywords as $k)
{
if(strlen($k))
{
//$html = str_replace("<$k>", ":#:", $html);
//$html = str_replace("</$k>", ":##:", $html);
//$html = strip_tags($html);
if ($html = preg_replace("/($k)/Ui","$OpenTag\\1$CloseTag", $html))
//if ($html = preg_replace("/(>[^<]*)($k)([^<]*< )/Ui","$OpenTag\\1$CloseTag", $html))
$ret = $html;
//$ret = str_replace(":#:", "<$k>", $ret);
//$ret = str_replace(":##:", "</$k>", $ret);
}
}
return $ret;
}
*/
function ExtractDatePart($part,$datestamp)
{
switch($part)
{
case "month":
if($datestamp<=0)
{
$ret = "";
}
else
$ret = adodb_date("m",$datestamp);
break;
case "day":
if($datestamp<=0)
{
$ret = "";
}
else
$ret = adodb_date("d", $datestamp);
break;
case "year":
if($datestamp<=0)
{
$ret = "";
}
else
$ret = adodb_date("Y", $datestamp);
break;
case "time_24hr":
if($datestamp<=0)
{
$ret = "";
}
else
$ret = adodb_date("H:i", $datestamp);
break;
case "time_12hr":
if($datestamp<=0)
{
$ret = "";
}
else
$ret = adodb_date("g:i a",$datestamp);
break;
}
return $ret;
}
function GetLocalTime($TimeStamp,$TargetZone=NULL)
{
if($TargetZone==NULL)
$TargetZone = $objConfig->Get("Config_Site_Time");
$server = $objConfig->Get("Config_Server_Time");
if($TargetZone!=$server)
{
$offset = ($server - $TargetZone) * -1;
$TimeStamp = $TimeStamp + (3600 * $offset);
}
return $TimeStamp;
}
function _unhtmlentities ($string)
{
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
return strtr ($string, $trans_tbl);
}
function getLastStr($hay, $need){
$getLastStr = 0;
$pos = strpos($hay, $need);
if (is_int ($pos)){ //this is to decide whether it is "false" or "0"
while($pos) {
$getLastStr = $getLastStr + $pos + strlen($need);
$hay = substr ($hay , $pos + strlen($need));
$pos = strpos($hay, $need);
}
return $getLastStr - strlen($need);
} else {
return -1; //if $need wasn´t found it returns "-1" , because it could return "0" if it´s found on position "0".
}
}
function ReplaceSingleTag($tag,$text)
{
$opentag = "[".$tag;
$closetag = "[/".$tag."]";
if(strstr($text,$opentag))
{
$pos = strpos($text,$opentag." ");
if($pos === false)
{
$pos = strpos($text,$opentag."]");
}
$endopen = strpos($text,"]",$pos);
$closepos = strpos($text,$closetag,$pos);
if($closepos)
{
$taglength = ($closepos - $endopen) + strlen($closetag);
$tagText = substr($text,$pos, $closepos + strlen($closetag) - $pos);
$innerText = substr($text,$endopen+1,$closepos - $endopen-1);
if($tag=="UL")
$innerText = str_replace("[*]","<LI>",$innerText);
$tagText = substr($tagText,1,($endopen - $pos)-1);
//echo "Matched $tagText <br>\n";
$tagText = "<".$tagText.">";
$replace_text = $tagText.$innerText."</".$tag.">";
$text = substr($text,0,$pos).$replace_text.substr($text,$closepos+strlen($closetag));
return $text;
}
else
return $text;
}
else
return $text;
}
function ReplaceTag($tag,$text)
{
$new_text = ReplaceSingleTag($tag,$text);
while($new_text != $text)
{
$text = $new_text;
$new_text = ReplaceSingleTag($tag,$text);
}
return $new_text;
}
function ReplaceURL($text)
{
while(strstr($text,"[URL"))
{
$urlpos = strpos($text,"[URL");
$endopen = strpos($text,"]",$urlpos);
if($endopen)
{
$url = "<A TARGET=\"_blank\"".substr($text,$urlpos+4,$endopen - ($urlpos+4));
$url .= ">";
$url = _unhtmlentities($url);
$text = substr($text,0,$urlpos).$url.substr($text,$endopen+1);
}
}
$text = str_replace("[/URL]","</A>",$text);
return $text;
}
function ReplaceBBCode($text)
{
global $objConfig;
$tags = explode(",",$objConfig->Get("BBTags"));
for($i=0;$i<count($tags);$i++)
{
$text = ReplaceTag(strtoupper($tags[$i]),$text);
}
$text = ReplaceURL($text);
return $text;
}
function GetMinValue($Table,$Field, $Where=NULL)
{
$ret = 0;
$sql = "SELECT min($Field) as val FROM $Table ";
if(strlen($where))
$sql .= "WHERE $Where";
$ado = GetADODBConnection();
$rs = $ado->execute($sql);
if($rs)
$ret = (int)$rs->fields["val"];
return $ret;
}
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function SetMissingDataErrors($f)
{
global $FormError;
$count = 0;
if(is_array($_POST))
{
if(is_array($_POST["required"]))
{
foreach($_POST["required"] as $r)
{
$found = FALSE;
if(is_array($_FILES))
{
if($_FILES[$r]["size"]>0)
$found=TRUE;
}
if(!strlen(trim($_POST[$r])) && !$found)
{
$count++;
if (($r == "dob_day") || ($r == "dob_month") || ($r == "dob_year"))
$r = "dob";
$tag = $_POST["errors"][$r];
if(!strlen($tag))
$tag = "lu_ferror_".$f."_".$r;
$FormError[$f][$r] = language($tag);
}
}
}
}
return $count;
}
function makepassword($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+strlen(${'c'.$strpart});
}
$previous=$strpart;
}
// generating the password from the structure defined in $pass_structure
for ($g=0;$g<strlen($pass_structure);$g++)
{
mt_srand((double)microtime()*1000000);
$sel=substr($pass_structure,$g,1);
$pass.=${'p'.$sel}[mt_rand(0,-1+${'s'.$sel})];
}
return $pass;
}
function LogEntry($text,$writefile=FALSE)
{
global $g_LogFile,$LogFile, $LogData, $LogLevel, $timestart;
static $last;
if(strlen($g_LogFile))
{
$el = str_pad(getmicrotime()- $timestart,10," ");
if($last>0)
$elapsed = getmicrotime() - $last;
if(strlen($el)>10)
$el = substr($el,0,10);
$indent = str_repeat(" ",$LogLevel);
$text = str_pad($text,$LogLevel,"==",STR_PAD_LEFT);
$LogData .= "$el:". round($elapsed,6).":$indent $text";
$last = getmicrotime();
if($writefile==TRUE && is_writable($g_LogFile))
{
if(!$LogFile)
{
if(file_exists($g_LogFile))
unlink($g_LogFile);
$LogFile=@fopen($g_LogFile,"w");
}
if($LogFile)
{
fputs($LogFile,$LogData);
}
}
}
}
function ValidEmail($email)
{
if (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email))
{
return TRUE;
}
else
{
return FALSE;
}
}
function language($phrase,$LangId=0)
{
global $objSession, $objLanguageCache, $objLanguages;
if($LangId==0)
$LangId = $objSession->Get("Language");
if($LangId==0)
$LangId = $objLanguages->GetPrimary();
$translation = $objLanguageCache->GetTranslation($phrase,$LangId);
return $translation;
}
function admin_language($phrase,$lang=0,$LinkMissing=FALSE)
{
global $objSession, $objLanguageCache, $objLanguages;
//echo "Language passed: $lang<br>";
if($lang==0)
$lang = $objSession->Get("Language");
//echo "Language from session: $lang<br>";
if($lang==0)
$lang = $objLanguages->GetPrimary();
//echo "Language after primary: $lang<br>";
//echo "Phrase: $phrase<br>";
$translation = $objLanguageCache->GetTranslation($phrase,$lang);
if($LinkMissing && substr($translation,0,1)=="!" && substr($translation,-1)=="!")
{
$res = "<A href=\"javascript:OpenPhraseEditor('&direct=1&label=$phrase'); \">$translation</A>";
return $res;
}
else
return $translation;
}
function prompt_language($phrase,$lang=0)
{
return admin_language($phrase,$lang,TRUE);
}
function GetPrimaryTranslation($Phrase)
{
global $objLanguages;
$l = $objLanguages->GetPrimary();
return language($Phrase,$l);
}
function CategoryNameCount($ParentId,$Name)
{
$cat_table = GetTablePrefix()."Category";
$sql = "SELECT Name from $cat_table WHERE ParentId=$ParentId AND ";
$sql .="(Name LIKE '".addslashes($Name)."' OR Name LIKE 'Copy of ".addslashes($Name)."' OR Name LIKE 'Copy % of ".addslashes($Name)."')";
$ado = GetADODBConnection();
$rs = $ado->Execute($sql);
$ret = array();
while($rs && !$rs->EOF)
{
$ret[] = $rs->fields["Name"];
$rs->MoveNext();
}
return $ret;
}
function CategoryItemNameCount($CategoryId,$Table,$Field,$Name)
{
$cat_table = GetTablePrefix()."CategoryItems";
$sql = "SELECT $Field FROM $Table INNER JOIN $cat_table ON ($Table.ResourceId=$cat_table.ItemResourceId) ";
$sql .=" WHERE ($Field LIKE 'Copy % of $Name' OR $Field LIKE '$Name' OR $Field LIKE 'Copy of $Name') AND CategoryId=$CategoryId";
//echo $sql."<br>\n ";
$ado = GetADODBConnection();
$rs = $ado->Execute($sql);
$ret = array();
while($rs && !$rs->EOF)
{
$ret[] = $rs->fields[$Field];
$rs->MoveNext();
}
return $ret;
}
function &GetItemCollection($ItemName)
{
global $objItemTypes;
if(is_numeric($ItemName))
{
$item = $objItemTypes->GetItem($ItemName);
}
else
$item = $objItemTypes->GetTypeByName($ItemName);
if(is_object($item))
{
$module = $item->Get("Module");
$prefix = ModuleTagPrefix($module);
$func = $prefix."_ItemCollection";
if(function_exists($func))
{
$var =& $func();
}
}
return $var;
}
function UpdateCategoryCount($ItemTypeName=0,$ListType=NULL)
{
global $objCountCache, $objItemTypes;
if(is_numeric($ItemName))
{
$item = $objItemTypes->GetItem($ItemName);
}
else
$item = $objItemTypes->GetTypeByName($ItemName);
if(is_object($item))
{
$ItemType = $item->Get("ItemType");
$sql = "DELETE FROM ".$objCountCache->SourceTable." WHERE ItemType=$ItemType";
if(is_numeric($ListType))
{
$sql .= " AND ListType=$ListType";
}
$objCountCache->adodbConnection->Execute($sql);
}
}
function UpdateModifiedCategoryCount($ItemTypeName,$CatId=NULL,$Modifier=0,$ExtraId=NULL)
{
}
function UpdateGroupCategoryCount($ItemTypeName,$CatId=NULL,$Modifier=0,$GroupId=NULL)
{
}
function GetTagCache($module,$tag,$attribs,$env)
{
global $objSystemCache, $objSession, $objConfig;
if($objConfig->Get("SystemTagCache"))
{
$name = $tag;
if(is_array($attribs))
{
foreach($attribs as $n => $val)
{
$name .= "-".$val;
}
}
$CachedValue = $objSystemCache->GetContextValue($name,$module,$env, $objSession->Get("GroupList"));
}
else
$CachedValue="";
return $CachedValue;
}
function SaveTagCache($module, $tag, $attribs, $env, $newvalue)
{
global $objSystemCache, $objSession, $objConfig;
if($objConfig->Get("SystemTagCache"))
{
$name = $tag;
if(is_array($attribs))
{
foreach($attribs as $a => $val)
{
$name .= "-".$val;
}
}
$objSystemCache->EditCacheItem($name,$newvalue,$module,0,$env,$objSession->Get("GroupList"));
}
}
function DeleteTagCache($name,$extraparams, $env="")
{
global $objSystemCache, $objConfig;
if($objConfig->Get("SystemTagCache"))
{
$where = "Name LIKE '$name%".$extraparams."'";
if(strlen($env))
$where .= " AND Context LIKE $env";
$objSystemCache->DeleteCachedItem($where);
}
}
function ParseTagLibrary()
{
$objTagList = new clsTagList();
$objTagList->ParseInportalTags();
unset($objTagList);
}
function GetDateFormat($LangId=0)
{
global $objLanguages;
if(!$LangId)
$LangId= $objLanguages->GetPrimary();
$l = $objLanguages->GetItem($LangId);
if(is_object($l))
{
$fmt = $l->Get("DateFormat");
}
else
$fmt = "m-d-Y";
return $fmt;
}
function GetTimeFormat($LangId=0)
{
global $objLanguages;
if(!$LangId)
$LangId= $objLanguages->GetPrimary();
$l = $objLanguages->GetItem($LangId);
if(is_object($l))
{
$fmt = $l->Get("TimeFormat");
}
else
$fmt = "H:i:s";
return $fmt;
}
function LangDate($TimeStamp=NULL,$LangId=0)
{
$fmt = GetDateFormat($LangId);
$ret = adodb_date($fmt,$TimeStamp);
return $ret;
}
function LangTime($TimeStamp=NULL,$LangId=0)
{
$fmt = GetTimeFormat($LangId);
$ret = adodb_date($fmt,$TimeStamp);
return $ret;
}
function LangNumber($Num,$DecPlaces=NULL,$LangId=0)
{
global $objLanguages;
if(!$LangId)
$LangId= $objLanguages->GetPrimary();
$l = $objLanguages->GetItem($LangId);
if(is_object($l))
{
$ret = number_format($Num,$DecPlaces,$l->Get("DecimalPoint"),$l->Get("ThousandSep"));
}
else
$ret = $num;
return $ret;
}
function replacePngTags($x, $spacer="images/spacer.gif")
{
global $rootURL,$pathtoroot;
// make sure that we are only replacing for the Windows versions of Internet
// Explorer 5+, and not Opera identified as MSIE
$msie='/msie\s([5-9])\.?[0-9]*.*(win)/i';
$opera='/opera\s+[0-9]+/i';
if(!isset($_SERVER['HTTP_USER_AGENT']) ||
!preg_match($msie,$_SERVER['HTTP_USER_AGENT']) ||
preg_match($opera,$_SERVER['HTTP_USER_AGENT']))
return $x;
// find all the png images in backgrounds
preg_match_all('/background-image:\s*url\(\'(.*\.png)\'\);/Uis',$x,$background);
for($i=0;$i<count($background[0]);$i++){
// simply replace:
// "background-image: url('image.png');"
// with:
// "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(
// enabled=true, sizingMethod=scale src='image.png');"
// haven't tested to see if background-repeat styles work...
$x=str_replace($background[0][$i],'filter:progid:DXImageTransform.'.
'Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale'.
' src=\''.$background[1][$i].'\');',$x);
}
// OK, time to find all the IMG tags with ".png" in them
preg_match_all('/(<img.*\.png.*>|<input.*type=([\'"])image\\2.*\.png.*>)/Uis',$x,$images);
while(list($imgnum,$v)=@each($images[0])){
$original=$v;
$atts=''; $width=0; $height=0;
// If the size is defined by styles, find
preg_match_all('/style=".*(width: ([0-9]+))px.*'.
'(height: ([0-9]+))px.*"/Ui',$v,$arr2);
if(is_array($arr2) && count($arr2[0])){
// size was defined by styles, get values
$width=$arr2[2][0];
$height=$arr2[4][0];
}
// size was not defined by styles, get values
preg_match_all('/width=\"?([0-9]+)\"?/i',$v,$arr2);
if(is_array($arr2) && count($arr2[0])){
$width=$arr2[1][0];
}
preg_match_all('/height=\"?([0-9]+)\"?/i',$v,$arr2);
if(is_array($arr2) && count($arr2[0])){
$height=$arr2[1][0];
}
preg_match_all('/src=\"([^\"]+\.png)\"/i',$v,$arr2);
if(isset($arr2[1][0]) && !empty($arr2[1][0]))
$image=$arr2[1][0];
else
$image=NULL;
// We do this so that we can put our spacer.gif image in the same
// directory as the image
$tmp=split('[\\/]',$image);
array_pop($tmp);
$image_path=join('/',$tmp);
if(substr($image,0,strlen($rootURL))==$rootURL)
{
$path = str_replace($rootURL,$pathtoroot,$image);
}
else
{
$path = $pathtoroot."themes/telestial/$image";
}
// echo "Sizing $path.. <br>\n";
// echo "Full Tag: ".htmlentities($image)."<br>\n";
//if(!$height || !$width)
//{
$g = imagecreatefrompng($path);
if($g)
{
$height = imagesy($g);
$width = imagesx($g);
}
//}
if(strlen($image_path)) $image_path.='/';
// end quote is already supplied by originial src attribute
$replace_src_with=$spacer.'" style="width: '.$width.
'px; height: '.$height.'px; filter: progid:DXImageTransform.'.
'Microsoft.AlphaImageLoader(src=\''.$image.'\', sizingMethod='.
'\'scale\')';
// now create the new tag from the old
$new_tag=str_replace($image,$replace_src_with,$original);
// now place the new tag into the content
$x=str_replace($original,$new_tag,$x);
}
return $x;
}
function print_pre($str)
{
// no comments here :)
echo '<pre>'.print_r($str, true).'</pre>';
}
function GetOptions($field) // by Alex
{
// get dropdown values from custom field
$tmp =& new clsCustomField();
$tmp->LoadFromDatabase($field, 'FieldName');
$tmp_values = $tmp->Get('ValueList');
unset($tmp);
$tmp_values = explode(',', $tmp_values);
foreach($tmp_values as $mixed)
{
$elem = explode('=', trim($mixed));
$ret[ $elem[0] ] = $elem[1];
}
return $ret;
}
function ResetPage($module_prefix, $page_variable = 'p')
{
// resets page in specific module when category is changed
if(!is_object($objSession)) // when changing pages session doesn't exist -> InPortal BUG
{
global $var_list, $SessionQueryString, $FrontEnd;
//if(!$var_list["sid"]) $var_list["sid"] = $_COOKIE["sid"];
$objSession = new clsUserSession($var_list["sid"],($SessionQueryString && $FrontEnd==1));
}
//echo "SID_RESET: ".$GLOBALS['var_list']["sid"].'(COOKIE_SID: '.$_COOKIE["sid"].')<br>';
$last_cat = $objSession->GetVariable('last_category');
$prev_cat = $objSession->GetVariable('prev_category');
//echo "Resetting Page [$prev_cat] -> [$last_cat]<br>";
if($prev_cat != $last_cat) $GLOBALS[$module_prefix.'_var_list'][$page_variable] = 1;
}
function GetVar($name)
{
return isset($_REQUEST[$name]) ? $_REQUEST[$name] : false;
}
function PassVar(&$source)
{
// source array + any count of key names in passed array
$params = func_get_args();
array_shift($params);
if( count($params) )
{
$ret = Array();
foreach($params as $var_name)
if( isset($source[$var_name]) )
$ret[] = $var_name.'='.$source[$var_name];
$ret = '&'.implode('&', $ret);
}
return $ret;
}
function GetSubmitVariable(&$array, $postfix)
{
// gets edit status of module
// used in case if some modules share
// common action parsed by kernel parser,
// but each module uses own EditStatus variable
$modules = Array('In-Link' => 'Link', 'In-News' => 'News', 'In-Bulletin' => 'Topic');
foreach($modules as $module => $prefix)
if( isset($array[$prefix.$postfix]) )
return Array('Module' => $module, 'variable' => $array[$prefix.$postfix]);
return false;
}
function GetModuleByAction()
{
$prefix2module = Array('m' => 'In-Portal', 'l' => 'In-Link', 'n' => 'In-News', 'bb' => 'In-Bulletin');
$action = $_REQUEST['Action'];
$module_prefix = explode('_', $action);
return $prefix2module[ $module_prefix[0] ];
}
function dir_size($dir) {
// calculates folder size based on filesizes inside it (recursively)
$totalsize=0;
if ($dirstream = @opendir($dir)) {
while (false !== ($filename = readdir($dirstream))) {
if ($filename!="." && $filename!="..")
{
if (is_file($dir."/".$filename))
$totalsize+=filesize($dir."/".$filename);
if (is_dir($dir."/".$filename))
$totalsize+=dir_size($dir."/".$filename);
}
}
}
closedir($dirstream);
return $totalsize;
}
function size($bytes) {
// shows formatted file/directory size
$types = Array("la_bytes","la_kilobytes","la_megabytes","la_gigabytes","la_terabytes");
$current = 0;
while ($bytes > 1024) {
$current++;
$bytes /= 1024;
}
return round($bytes,2)." ".language($types[$current]);
}
function echod($str)
{
// echo debug output
echo str_replace( Array('[',']'), Array('[<b>', '</b>]'), $str).'<br>';
}
function PrepareParams($source, $to_lower, $mapping)
{
// prepare array with form values to use with item
$result = Array();
foreach($to_lower as $field)
$result[ $field ] = $source[ strtolower($field) ];
if( is_array($mapping) )
{
foreach($mapping as $field_from => $field_to)
$result[$field_to] = $source[$field_from];
}
return $result;
}
function GetELT($field, $phrases = Array())
{
// returns FieldOptions equivalent in In-Portal
$ret = Array();
foreach($phrases as $phrase)
$ret[] = admin_language($phrase);
$ret = "'".implode("','", $ret)."'";
return 'ELT('.$field.','.$ret.')';
}
function GetModuleImgPath($module)
{
global $rootURL, $admin;
return $rootURL.$module.'/'.$admin.'/images';
}
function ActionPostProcess($StatusField, $ListClass, $ListObjectName = '', $IDField = null)
{
// each action postprocessing stuff from admin
if( !isset($_REQUEST[$StatusField]) ) return false;
$list =& $GLOBALS[$ListObjectName];
if( !is_object($list) ) $list = new $ListClass();
$SFValue = $_REQUEST[$StatusField]; // status field value
switch($SFValue)
{
case 1: // User hit "Save" button
$list->CopyFromEditTable($IDField);
break;
case 2: // User hit "Cancel" button
$list->PurgeEditTable($IDField);
break;
}
if( function_exists('SpecificProcessing') ) SpecificProcessing($StatusField, $SFValue);
if($SFValue == 1 || $SFValue == 2) $list->Clear();
}
function GetElem(&$array, $index)
{
// returns array element by index if
// such index exists
return isset($array[$index]) ? $array[$index] : false;
}
function MakeHTMLTag($element, $attrib_prefix)
{
$result = Array();
$ap_length = strlen($attrib_prefix);
foreach($element->attributes as $attib_name => $attr_value)
if( substr($attib_name, $ap_length) == $ap_length )
$result[] = substr($attib_name, $ap_length, strlen($attib_name)).'="'.$attr_value.'"';
return count($result) ? implode(' ', $result) : false;
}
-/* so I dont forget:
- - the decrypt function is defined in adodb-time and is called xp()
- - the keygen function is also declared in adodb-time as $b
- and eval'd() in dates.php
-*/
-
-
-
-/* //this comes from line 15; moved by PSK for readability
-
- $g_DBType = "mysql";
- $g_DBHost = "kiev";
-
- $g_DBUser = "root";
- $g_DBUserPassword = "";
- $g_DBName = "inportal";
-
-
-//$g_DBUser = "bloopered";
-//$g_DBUserPassword = "vFWPqJT017";
-//$g_DBName = "inportal";
-
- $g_TablePrefix = "";
-
- $g_EnableCookies = FALSE;
- $g_SessionExpirationLimit = 3600*1; // 1 hour
-
-//$g_PrivateMessageExpirationLimit = 2592000; // 30 days
-//$g_PrivateMessageThreadLimit = 50;
-//$g_DebugMode=0;
-
-//$g_defaultLanguage = "English";
-//$g_defaultTheme = "default";
-
- $g_TopRate = 4;
- $g_PopRate = 80;
- $g_NewDate = 5;
-
-
- $g_adodbConnection=NULL;
-*/
?>
Property changes on: trunk/globals.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property

Event Timeline