1   <?php
  2  
  3   error_reporting(E_ALL);
  4   set_time_limit(0);
  5   ini_set('memory_limit', -1);
  6  
  7   define('BACKUP_NAME', 'dump(.*).txt'); // how backup dump files are named
  8   $general_error = '';
  9  
  10   // new path detection without K4 init: begin
  11   define('FULL_PATH', realpath(dirname(__FILE__).'/..') );
  12   define('BASE_PATH', rtrim(preg_replace('#/admin$#', '', str_replace('\\', '/', dirname($_SERVER['PHP_SELF']))), '/'));
  13   $rootURL = 'http://'.$_SERVER['HTTP_HOST'].rtrim(BASE_PATH, '/').'/admin/';
  14   // new path detection without K4 init: end
  15  
  16   $pathtoroot = FULL_PATH.'/';
  17   $admin = 'admin';
  18  
  19   ini_set('include_path', '.');
  20  
  21   if (!defined('IS_INSTALL')) define('IS_INSTALL',1);
  22   if( file_exists($pathtoroot.'debug.php') && !(defined('DEBUG_MODE') && DEBUG_MODE) ) include_once($pathtoroot.'debug.php');
  23  
  24   $state = isset($_GET["state"]) ? $_GET["state"] : '';
  25   if(!strlen($state))
  26   {
  27           $state = isset($_POST['state']) ? $_POST['state'] : '';
  28   }
  29  
  30   if (!defined("GET_LICENSE_URL")) {
  31           define("GET_LICENSE_URL", "http://www.intechnic.com/myaccount/license.php");
  32   }
  33  
  34   require_once $pathtoroot.$admin.'/install/install_lib.php';
  35  
  36   $install_type = GetVar('install_type', true);
  37   $force_finish = isset($_REQUEST['ff']) ? true : false;
  38  
  39   $ini_file = $pathtoroot."config.php";
  40   if(file_exists($ini_file))
  41   {
  42       $write_access = is_writable($ini_file);
  43       $ini_vars = inst_parse_portal_ini($ini_file,TRUE);
  44  
  45       foreach($ini_vars as $secname => $section)
  46       {
  47         foreach($section as $key => $value)
  48         {
  49             $key = "g_".str_replace('-', '', $key);
  50             global $$key;
  51             $$key = $value;
  52         }
  53       }
  54   }
  55   else
  56   {
  57     $state="";
  58     $write_access = is_writable($pathtoroot);
  59     if($write_access)
  60     {
  61       set_ini_value("Database", "DBType", "");
  62       set_ini_value("Database", "DBHost", "");
  63       set_ini_value("Database", "DBUser", "");
  64       set_ini_value("Database", "DBUserPassword", "");
  65       set_ini_value("Database", "DBName", "");
  66       set_ini_value("Module Versions", "In-Portal", "");
  67  
  68       save_values();
  69     }
  70   }
  71  
  72   $titles[1] = "General Site Setup";
  73   $configs[1] = "in-portal:configure_general";
  74   $mods[1] = "In-Portal";
  75  
  76   $titles[2] = "User Setup";
  77   $configs[2] = "in-portal:configure_users";
  78   $mods[2] = "In-Portal:Users";
  79  
  80   $titles[3] = "Category Display Setup";
  81   $configs[3] = "in-portal:configure_categories";
  82   $mods[3] = "In-Portal";
  83  
  84   // simulate rootURL variable: begin
  85           $rootURL = 'http://'.dirname($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']);
  86           $tmp = explode('/', $rootURL);
  87           if( $tmp[ count($tmp) - 1 ] == $admin) unset( $tmp[ count($tmp) - 1 ] );
  88           $rootURL = implode('/', $tmp).'/';
  89           unset($tmp);
  90           //echo "RU: $rootURL<br>";
  91   // simulate rootURL variable: end
  92  
  93   $db_savings = Array('dbinfo', 'db_config_save', 'db_reconfig_save'); //, 'reinstall_process'
  94   if( isset($g_DBType) && $g_DBType && strlen($state)>0 && !in_array($state, $db_savings) )
  95   {
  96           define('REL_PATH', 'admin');
  97           require_once($pathtoroot."kernel/startup.php");
  98       $localURL=$rootURL."kernel/";
  99       $adminURL = $rootURL.$admin;
  100       $imagesURL = $adminURL."/images";
  101  
  102   //admin only util
  103  
  104       $pathtolocal = $pathtoroot."kernel/";
  105       require_once ($pathtoroot.$admin."/include/elements.php");
  106       //require_once ($pathtoroot."kernel/admin/include/navmenu.php");
  107       require_once ($pathtolocal."admin/include/navmenu.php");
  108       require_once($pathtoroot.$admin."/toolbar.php");
  109  
  110       set_cookie(SESSION_COOKIE_NAME, '', adodb_mktime() - 3600, rtrim(BASE_PATH, '/') );
  111   }
  112  
  113   function GetPathChar($path = null)
  114   {
  115           if( !isset($path) ) $path = $GLOBALS['pathtoroot'];
  116           $pos = strpos($path, ':');
  117       return ($pos === false) ? "/" : "\\";
  118   }
  119  
  120   function SuperStrip($str, $inverse = false)
  121   {
  122           $str = $inverse ? str_replace("%5C","\\",$str) : str_replace("\\","%5C",$str);
  123           return stripslashes($str);
  124   }
  125  
  126   $skip_step = false;
  127  
  128   require_once($pathtoroot.$admin."/install/inst_ado.php");
  129   $helpURL = $rootURL.$admin.'/help/install_help.php?destform=popup&help_usage=install';
  130   ?>
  131   <html>
  132   <head>
  133   <title>In-Portal Installation</title>
  134                   <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
  135                   <meta name="generator" content="Notepad">
  136                   <link rel="stylesheet" type="text/css" href="include/style.css">
  137           <LINK REL="stylesheet" TYPE="text/css" href="install/2col.css">
  138                   <SCRIPT LANGUAGE="JavaScript1.2">
  139                           function MM_preloadImages() { //v3.0
  140                            var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  141                              var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  142                              if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  143                           }
  144  
  145                           function swap(imgid, src){
  146                                   var ob = document.getElementById(imgid);
  147                                   ob.src = 'images/' + src;
  148                           }
  149  
  150                           function Continue() {
  151                                   document.iform1.submit();
  152                           }
  153  
  154                           function CreatePopup(window_name, url, width, height)
  155                           {
  156                                   // creates a popup window & returns it
  157                                   if(url == null && typeof(url) == 'undefined' ) url = '';
  158                                   if(width == null && typeof(width) == 'undefined' ) width = 750;
  159                                   if(height == null && typeof(height) == 'undefined' ) height = 400;
  160  
  161  
  162                                   return window.open(url,window_name,'width='+width+',height='+height+',status=yes,resizable=yes,menubar=no,scrollbars=yes,toolbar=no');
  163                           }
  164  
  165                           function ShowHelp(section)
  166                           {
  167                                   var frm = document.getElementById('help_form');
  168  
  169                                   frm.section.value = section;
  170                                   frm.method = 'POST';
  171                                   CreatePopup('HelpPopup','<?php echo $rootURL.$admin; ?>/help/blank.html'); // , null, 600);
  172                                   frm.target = 'HelpPopup';
  173                                   frm.submit();
  174                           }
  175  
  176                   </SCRIPT>
  177   </head>
  178  
  179   <body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" style="height: 100%">
  180   <form name="help_form" id="help_form" action="<?php echo $helpURL; ?>" method="post"><input type="hidden" id="section" name="section" value=""></form>
  181   <form enctype="multipart/form-data" name="iform1" id="iform1" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
  182   <table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
  183           <tr>
  184                   <td height="90">
  185                           <table cellpadding="0" cellspacing="0" border="0" width="100%" height="90">
  186                                   <tr>
  187                                           <td rowspan="3" valign="top"><a href="http://www.in-portal.net" target="_top"><img title="In-portal" src="images/globe.gif" width="84" height="91" border="0"></a></td>
  188                                           <td rowspan="3" valign="top"><a href="http://www.in-portal.net" target="_top"><img title="In-portal" src="images/logo.gif" width="150" height="91" border="0"></a></td>
  189                                           <td rowspan="3" width="100000" align="right">&nbsp;</td>
  190                                           <td width="400"><img title="" src="images/blocks.gif" width="400" height="73"></td>
  191                                   </tr>
  192                                   <tr><td align="right" background="images/version_bg.gif" class="head_version" valign="top"><img title="" src="images/spacer.gif" width="1" height="14">In-Portal Version <?php echo GetMaxPortalVersion($pathtoroot.$admin)?>: English US</td></tr>
  193                                   <tr><td><img title="" src="images/blocks2.gif" width="400" height="2"><br></td></tr>
  194                                   <tr><td bgcolor="black" colspan="4"><img title="" src="images/spacer.gif" width="1" height="1"><br></td></tr>
  195                           </table>
  196                   </td>
  197           </tr>
  198  
  199   <?php
  200   require_once($pathtoroot."kernel/include/adodb/adodb.inc.php");
  201  
  202   if(!strlen($state))
  203       $state = @$_POST["state"];
  204   //echo $state;
  205  
  206   if(strlen($state)==0)
  207   {
  208       $ado =& inst_GetADODBConnection();
  209       $installed = $ado ? TableExists($ado,"ConfigurationAdmin,Category,Permissions") : false;
  210  
  211       if(!minimum_php_version("4.1.2"))
  212       {
  213           $general_error = "You have version ".phpversion()." - please upgrade!";
  214           //die();
  215       }
  216  
  217       if(!$write_access)
  218       {
  219           if ($general_error != '') {
  220                   $general_error .= '<br /><br />';
  221           }
  222           $general_error .= "Install cannot write to config.php in the root directory of your in-portal installation ($pathtoroot).";
  223           //die();
  224       }
  225  
  226       if(!is_writable($pathtoroot."themes/"))
  227       {
  228           if ($general_error != '') {
  229                   $general_error .= '<br /><br />';
  230           }
  231           $general_error .= "In-portal's Theme directory must be writable (".$pathtoroot."themes/).";
  232           //die();
  233       }
  234  
  235       if(!is_writable($pathtoroot."kernel/images/"))
  236       {
  237           if ($general_error != '') {
  238                   $general_error .= '<br /><br />';
  239           }
  240           $general_error .= "In-portal's Image Upload directory must be writable (".$pathtoroot."kernel/images/).";
  241           //die();
  242       }
  243  
  244       if(!is_writable($pathtoroot."kernel/images/pending"))
  245       {
  246           if ($general_error != '') {
  247                   $general_error .= '<br /><br />';
  248           }
  249           $general_error .= "In-portal's Pending Image Upload directory must be writable (".$pathtoroot."kernel/images/pending).";
  250           //die();
  251       }
  252  
  253       if(!is_writable($pathtoroot."admin/backupdata/"))
  254       {
  255           if ($general_error != '') {
  256                   $general_error .= '<br /><br />';
  257           }
  258           $general_error .= "In-portal's Backup directory must be writable (".$pathtoroot."admin/backupdata/).";
  259           //die();
  260       }
  261  
  262       if(!is_writable($pathtoroot."admin/export/"))
  263       {
  264           if ($general_error != '') {
  265                   $general_error .= '<br /><br />';
  266           }
  267           $general_error .= "In-portal's Export directory must be writable (".$pathtoroot."admin/export/).";
  268           //die();
  269       }
  270  
  271       if(!is_writable($pathtoroot."kernel/stylesheets/"))
  272       {
  273           if ($general_error != '') {
  274                   $general_error .= '<br /><br />';
  275           }
  276           $general_error .= "In-portal's stylesheets directory must be writable (".$pathtoroot."kernel/stylesheets/).";
  277           //die();
  278       }
  279  
  280       if(!is_writable($pathtoroot."kernel/user_files/"))
  281       {
  282           if ($general_error != '') {
  283                   $general_error .= '<br /><br />';
  284           }
  285           $general_error .= "In-portal's CMS images directory must be writable (".$pathtoroot."kernel/user_files/).";
  286           //die();
  287       }
  288  
  289       if(!is_writable($pathtoroot."kernel/cache/"))
  290       {
  291           if ($general_error != '') {
  292                   $general_error .= '<br /><br />';
  293           }
  294           $general_error .= "In-portal's templates cache directory must be writable (".$pathtoroot."kernel/cache/).";
  295           //die();
  296       }
  297  
  298       if($installed)
  299       {
  300           $state="reinstall";
  301       }
  302       else {
  303         $state="dbinfo";
  304       }
  305  
  306   }
  307  
  308   if($state=="reinstall_process")
  309   {
  310           $login_err_mesg = ''; // always init vars before use
  311           if( !isset($g_License) ) $g_License = '';
  312           $lic = base64_decode($g_License);
  313           if(strlen($lic))
  314           {
  315                   a83570933e44bc66b31dd7127cf3f23a($lic);
  316                   $ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
  317           }
  318  
  319           $LoggedIn = FALSE;
  320           if($_POST["UserName"]=="root")
  321           {
  322                   $ado =& inst_GetADODBConnection();
  323                   $sql = "SELECT * FROM ".$g_TablePrefix."ConfigurationValues WHERE VariableName='RootPass'";
  324  
  325                   $rs = $ado->Execute($sql);
  326                   if($rs && !$rs->EOF)
  327                   {
  328                           $RootPass = $rs->fields["VariableValue"];
  329  
  330                           if(strlen($RootPass)>0) {
  331                                   if (ConvertVersion($g_InPortal) >= ConvertVersion("1.3.0")) {
  332                                           $LoggedIn = ($RootPass==md5(md5($_POST["UserPass"]).'b38'));
  333                                   }
  334                                   else {
  335                                           $LoggedIn = ($RootPass==md5($_POST["UserPass"]));
  336                                   }
  337                           }
  338                   }
  339                   else {
  340                           $login_err_mesg = 'Invalid username or password';
  341                   }
  342           }
  343           else
  344           {
  345                   $act = '';
  346                   if (ConvertVersion($g_InPortal) >= ConvertVersion("1.0.5")) {
  347                           $act = 'check';
  348                   }
  349                   $rfile = @fopen(GET_LICENSE_URL."?login=".md5($_POST['UserName'])."&password=".md5($_POST['UserPass'])."&action=$act&license_code=".base64_encode($g_LicenseCode)."&version=".GetMaxPortalVersion($pathtoroot.$admin)."&domain=".base64_encode($_SERVER['HTTP_HOST']), "r");
  350                   if (!$rfile) {
  351                           $login_err_mesg = "Unable to connect to the Intechnic server!";
  352                           $LoggedIn = false;
  353                   }
  354                   else {
  355                           $rcontents = '';
  356                           while (!feof($rfile)) {
  357                                   $line = fgets($rfile, 10000);
  358                                   $rcontents .= $line;
  359                           }
  360                           @fclose($rfile);
  361  
  362                           if (substr($rcontents, 0, 5) == 'Error') {
  363                                   $login_err_mesg = substr($rcontents, 6);
  364                                   $LoggedIn = false;
  365                           }
  366                           else {
  367                                   $LoggedIn = true;
  368                           }
  369                   }
  370                   //$LoggedIn = ($i_User == $_POST["UserName"] && ($i_Pswd == $_POST["UserPass"]) && strlen($i_User)>0) || strlen($i_User)==0;
  371           }
  372  
  373           if($LoggedIn)
  374           {
  375                   if (!(int)$_POST["inp_opt"]) {
  376                           $state="reinstall";
  377                           $inst_error = "Please select one of the options above!";
  378                   }
  379                   else {
  380                           switch((int)$_POST["inp_opt"])
  381                           {
  382                                   case 0:
  383                                   $inst_error = "Please select an option above";
  384                                   break;
  385                                   case 1:
  386                                   /* clean out all tables */
  387                                   $install_type = 4;
  388                                   $ado =& inst_GetADODBConnection();
  389                                   $filename = $pathtoroot.$admin."/install/inportal_remove.sql";
  390                                   RunSchemaFile($ado,$filename);
  391  
  392                                   // removing other tables
  393                                   $tables = $ado->MetaTables();
  394  
  395                                   foreach($tables as $tab_name) {
  396                                           if (stristr($tab_name, $g_TablePrefix."ses_")) {
  397                                                   $sql = "DROP TABLE IF EXISTS $tab_name";
  398                                                   $ado->Execute($sql);
  399                                           }
  400                                   }
  401  
  402                                   /* run install again */
  403                                   $state="license";
  404                                   break;
  405                                   case 2:
  406                                   $install_type = 3;
  407                                   $state="dbinfo";
  408                                   break;
  409                                   case 3:
  410                                   $install_type = 5;
  411                                   $state="license";
  412                                   break;
  413                                   case 4:
  414                                   $install_type = 6;
  415                                   /* clean out all tables */
  416                                   $ado =& inst_GetADODBConnection();
  417                                   //$filename = $pathtoroot.$admin."/install/inportal_remove.sql";
  418                                   //RunSchemaFile($ado,$filename);
  419                                   /* run install again */
  420                                   $state="restore_select";
  421                                   break;
  422                                   case 5:
  423                                   $install_type = 7;
  424                                   /* change DB config */
  425                                   $state="db_reconfig";
  426                                   break;
  427                                   case 6:
  428                                   $install_type = 8;
  429                                   $state = "upgrade";
  430                                   break;
  431                                   case 7:
  432                                   $install_type = 9;
  433                                   $state = "fix_paths";
  434                                   break;
  435                           }
  436                   }
  437           }
  438           else
  439           {
  440                   $state="reinstall";
  441                   $login_error = $login_err_mesg;//"Invalid Username or Password - Try Again";
  442           }
  443   }
  444  
  445   if ($state == "upgrade") {
  446       $ado =& inst_GetADODBConnection();
  447  
  448       $Modules = array();
  449       $Texts = array();
  450  
  451       if (ConvertVersion(GetMaxPortalVersion($pathtoroot.$admin)) >= ConvertVersion("1.0.5") && ($g_LicenseCode == '' && $g_License != '')) {
  452           $state = 'reinstall';
  453           $inst_error = "Your license must be updated before you can upgrade. Please don't use 'Existing License' option, instead either Download from Intechnic or Upload a new license file!";
  454       }
  455       else {
  456                   $sql = "SELECT Name, Version, Path FROM ".$g_TablePrefix."Modules ORDER BY LoadOrder asc";
  457  
  458                   $rs = $ado->Execute($sql);
  459  
  460                   $i = 0;
  461                   while ($rs && !$rs->EOF) {
  462                           $p = $rs->fields['Path'];
  463  
  464                   if ($rs->fields['Name'] == 'In-Portal') {
  465                           $p = '';
  466                   }
  467  
  468                   $dir_name = $pathtoroot.$p."admin";///install/upgrades/";
  469  
  470                           if($rs->fields['Version'] != $newver = GetMaxPortalVersion($dir_name))
  471                           {
  472  
  473   ////////////////////
  474  
  475                                   $mod_path = $rs->fields['Path'];
  476                                   $current_version = $rs->fields['Version'];
  477                           if ($rs->fields['Name'] == 'In-Portal') $mod_path = '';
  478  
  479                           $dir_name = $pathtoroot.$mod_path."/admin/install/upgrades/";
  480                           $dir = @dir($dir_name);
  481  
  482                           if (!$dir) {
  483                                   $rs->MoveNext();
  484                                   continue;
  485                           }
  486  
  487                           $upgrades_arr = Array();
  488  
  489                           $new_version = '';
  490                           while ($file = $dir->read()) {
  491                                                   if ($file != "." && $file != ".." && !is_dir($dir_name.$file)) {
  492                                                   if (strstr($file, 'inportal_check_v')) {
  493                                                           $upgrades_arr[] = $file;
  494                                                   }
  495                                                   }
  496                           }
  497  
  498                           usort($upgrades_arr, "VersionSort");
  499  
  500                                   $result=0;
  501                                   $failCheck=1;
  502                                   $stopCheck=2;
  503                                   $CheckErrors = Array();
  504  
  505                           foreach($upgrades_arr as $file)
  506                           {
  507                                 $file_tmp = str_replace("inportal_check_v", "", $file);
  508                                 $file_tmp = str_replace(".php", "", $file_tmp);
  509  
  510                                           if (ConvertVersion($file_tmp) > ConvertVersion($current_version)) {
  511                                           $filename = $pathtoroot.$mod_path."/admin/install/upgrades/$file";
  512                                           if(file_exists($filename))
  513                                                           {
  514                                                                           include($filename);
  515                                                                           if( $result & 2 ) break;
  516                                                           }
  517                                   }
  518                           }
  519  
  520   ////////////////////
  521  
  522                           $Modules[] = Array('module'=>$rs->fields['Name'],'curver'=>$rs->fields['Version'],'newver'=>$newver,'error'=>$result!='pass');
  523   //                      $Texts[] = $rs->fields['Name']." (".$rs->fields['Version']." ".prompt_language("la_to")." ".GetMaxPortalVersion($dir_name).")";
  524                           }
  525  
  526                   /*$dir = @dir($dir_name);
  527  
  528                   while ($file = $dir->read()) {
  529                           if ($file != "." && $file != ".." && !is_dir($dir_name.$file))
  530                           {
  531                                   if (strstr($file, 'inportal_upgrade_v')) {
  532                                           $file = str_replace("inportal_upgrade_v", "", $file);
  533                                           $file = str_replace(".sql", "", $file);
  534  
  535                                           //$sql = "SELECT count(*) AS count FROM ".$g_TablePrefix."Modules WHERE Name = '".$rs->fields['Name']."' AND Version = '$file'";
  536                                           //$rs1 = $ado->Execute($sql);
  537  
  538                                           if ($rs1->fields['count'] == 0 && ConvertVersion($file) > ConvertVersion($rs->fields['Version'])) {
  539                                                   if ($Modules[$i-1] == $rs->fields['Name']) {
  540                                                                                   $Texts[$i-1] = $rs->fields['Name']." (".$rs->fields['Version']." ".prompt_language("la_to")." ".$file.")";
  541                                                           $i--;
  542                                                   }
  543                                                   else {
  544                                                           $Texts[$i] = $rs->fields['Name']." (".$rs->fields['Version']." ".prompt_language("la_to")." ".$file.")";
  545                                                           $Modules[$i] = $rs->fields['Name'];
  546                                                   }
  547  
  548                                                   $i++;
  549                                           }
  550                                   }
  551                           }
  552                   }*/
  553  
  554                   $rs->MoveNext();
  555               }
  556  
  557               $sql = 'DELETE FROM '.$g_TablePrefix.'Cache WHERE VarName IN ("config_files","configs_parsed","sections_parsed")';
  558                           $ado->Execute($sql);
  559  
  560                   $include_file = $pathtoroot.$admin."/install/upgrade.php";
  561           }
  562   }
  563  
  564   if ($state == "upgrade_process") {
  565           // K4 applition is now always available during upgrade process
  566           if (!defined('FULL_PATH')) {
  567                   define('FULL_PATH', realpath(dirname(__FILE__).'/..'));
  568           }
  569  
  570           include_once(FULL_PATH.'/core/kernel/startup.php');
  571           $application =& kApplication::Instance();
  572           $application->Init();
  573  
  574           // force rereading of configs
  575           $unit_config_reader =& $application->recallObject('kUnitConfigReader');
  576           $unit_config_reader->scanModules(MODULES_PATH);
  577  
  578           $ado =& inst_GetADODBConnection();
  579           $mod_arr = $_POST['modules'];
  580  
  581           $mod_str = '';
  582           foreach ($mod_arr as $tmp_mod) {
  583                   $mod_str .= "'$tmp_mod',";
  584           }
  585  
  586           $mod_str = substr($mod_str, 0, strlen($mod_str) - 1);
  587  
  588           $sql = "SELECT Name FROM ".$g_TablePrefix."Modules WHERE Name IN ($mod_str) ORDER BY LoadOrder";
  589           $rs = $ado->Execute($sql);
  590  
  591           $mod_arr = array();
  592           while ($rs && !$rs->EOF) {
  593                   $mod_arr[] = $rs->fields['Name'];
  594                   $rs->MoveNext();
  595           }
  596  
  597       foreach($mod_arr as $p)
  598       {
  599         $mod_name = strtolower($p);
  600  
  601                           $sql = "SELECT Version, Path FROM ".$g_TablePrefix."Modules WHERE Name = '$p'";
  602                           $rs = $ado->Execute($sql);
  603  
  604                           $current_version = $rs->fields['Version'];
  605  
  606           if ($mod_name == 'in-portal') {
  607                   $mod_path = '';
  608           }
  609           else {
  610                   $mod_path = $rs->fields['Path'];
  611           }
  612  
  613           $dir_name = $pathtoroot.$mod_path."/admin/install/upgrades/";
  614           $dir = @dir($dir_name);
  615  
  616           $upgrades_arr = Array();
  617  
  618           $new_version = '';
  619           while ($file = $dir->read()) {
  620                           if ($file != "." && $file != ".." && !is_dir($dir_name.$file)) {
  621                           if (strstr($file, 'inportal_upgrade_v')) {
  622                                   $upgrades_arr[] = $file;
  623                           }
  624                           }
  625           }
  626  
  627           usort($upgrades_arr, "VersionSort");
  628  
  629           foreach($upgrades_arr as $file)
  630           {
  631                   preg_match('/inportal_upgrade_v(.*).(php|sql)$/', $file, $rets);
  632                   $tmp_version = $rets[1];
  633                   $tmp_extension = $rets[2];
  634  
  635                           if (ConvertVersion($tmp_version) > ConvertVersion($current_version) )
  636                           {
  637                           $filename = $pathtoroot.$mod_path."/admin/install/upgrades/$file";
  638                           //echo "Running: $filename<br>";
  639  
  640                           // SQL is processed FIRST (before corresponding PHP according to the sorting order in VersionSort()
  641                           if( file_exists($filename) )
  642                           {
  643                                   if($tmp_extension == 'sql')
  644                                   {
  645                                           RunSQLFile($ado, $filename);
  646                                   }
  647                                   else
  648                                   {
  649                                           include_once $filename;
  650                                   }
  651                           }
  652                   }
  653           }
  654  
  655           set_ini_value("Module Versions", $p, GetMaxPortalVersion($pathtoroot.$mod_path."/admin/"));
  656                   save_values();
  657       }
  658  
  659       // compile stylesheets: begin
  660           define('FULL_PATH', realpath(dirname(__FILE__).'/..'));
  661           include_once(FULL_PATH.'/core/kernel/startup.php');
  662           $application =& kApplication::Instance();
  663           $application->Init();
  664  
  665   //      $objThemes->CreateMissingThemes(false);
  666           $application->HandleEvent($theme_event, 'adm:OnRebuildThemes');
  667  
  668           $css_hash = $application->Conn->GetCol('SELECT LOWER(Name) AS Name, StylesheetId FROM '.TABLE_PREFIX.'Stylesheets', 'StylesheetId');
  669  
  670           $css_table = $application->getUnitOption('css','TableName');
  671           $css_idfield = $application->getUnitOption('css','IDField');
  672  
  673           $theme_table = $application->getUnitOption('theme', 'TableName');
  674           $theme_idfield = $application->getUnitOption('theme', 'IDField');
  675  
  676           $theme_update_sql = 'UPDATE '.$theme_table.' SET '.$css_idfield.' = %s WHERE LOWER(Name) = %s';
  677           foreach($css_hash as $stylesheet_id => $theme_name)
  678           {
  679                   $css_item =& $application->recallObject('css', null, Array('skip_autoload' => true));
  680                   $css_item->Load($stylesheet_id);
  681                   $css_item->Compile();
  682                   $application->Conn->Query( sprintf($theme_update_sql, $stylesheet_id, $application->Conn->qstr( getArrayValue($css_hash,$stylesheet_id) ) ) );
  683           }
  684  
  685           // do redirect, because upgrade scripts can eat a lot or memory used for language pack upgrade operation
  686           $application->Redirect('install', Array('state' => 'languagepack_upgrade'), '', 'install.php');
  687           // compile stylesheets: end
  688  
  689       $state = 'languagepack_upgrade';
  690   }
  691  
  692   // upgrade language pack
  693   if($state=='languagepack_upgrade')
  694   {
  695           $state = 'lang_install_init';
  696           if( is_object($application) ) $application->SetVar('lang', Array('english.lang') );
  697           $force_finish = true;
  698   }
  699  
  700   if ($state == 'fix_paths') {
  701           $ado = inst_GetADODBConnection();
  702           $sql = "SELECT * FROM ".$g_TablePrefix."ConfigurationValues WHERE VariableName = 'Site_Name' OR VariableName LIKE '%Path%'";
  703           $path_rs = $ado->Execute($sql);
  704           $include_file = $pathtoroot.$admin."/install/fix_paths.php";
  705   }
  706  
  707   if ($state == 'fix_paths_process') {
  708           $ado = inst_GetADODBConnection();
  709           //$state = 'fix_paths';
  710           //$include_file = $pathtoroot.$admin."/install/fix_paths.php";
  711           foreach($_POST["values"] as $key => $value) {
  712                   $sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '".$value."' WHERE VariableName = '".$key."'";
  713                   $ado->Execute($sql);
  714           }
  715  
  716           $state = "finish";
  717   }
  718  
  719   if($state=="db_reconfig_save")
  720   {
  721       $ini_vars = inst_parse_portal_ini($ini_file,TRUE);
  722  
  723       foreach($ini_vars as $secname => $section)
  724       {
  725         foreach($section as $key => $value)
  726         {
  727             $key = "g_".str_replace("-", "", $key);
  728             global $$key;
  729             $$key = $value;
  730         }
  731       }
  732       unset($ado);
  733           $ado = VerifyDB('db_reconfig', 'finish', 'SaveDBConfig', true);
  734   }
  735  
  736  
  737   if($state=="db_reconfig")
  738   {
  739     $include_file = $pathtoroot.$admin."/install/db_reconfig.php";
  740   }
  741  
  742   if($state=="restore_file")
  743   {
  744           if($_POST["submit"]=="Update")
  745           {
  746                   $filepath = $_POST["backupdir"];
  747                   $state="restore_select";
  748           }
  749           else
  750           {
  751                   $filepath = stripslashes($_POST['backupdir']);
  752                   $backupfile = $filepath.$path_char.str_replace('(.*)', $_POST['backupdate'], BACKUP_NAME);
  753  
  754                   if(file_exists($backupfile) && is_readable($backupfile))
  755                   {
  756              $ado =& inst_GetADODBConnection();
  757  
  758                  $show_warning = false;
  759  
  760              if (!$_POST['warning_ok']) {
  761                      // Here we comapre versions between backup and config
  762                      $file_contents = file_get_contents($backupfile);
  763  
  764                      $file_tmp_cont = explode("#------------------------------------------", $file_contents);
  765                      $tmp_vers = $file_tmp_cont[0];
  766  
  767                      $vers_arr = explode(";", $tmp_vers);
  768                      $ini_values = inst_parse_portal_ini($ini_file);
  769  
  770                      foreach ($ini_values as $key => $value) {
  771                                   foreach ($vers_arr as $k) {
  772                                           if (strstr($k, $key)) {
  773                                                   if (!strstr($k, $value)) {
  774                                                           $show_warning = true;
  775                                                   }
  776                                           }
  777                                   }
  778                      }
  779                      //$show_warning = true;
  780              }
  781  
  782              if (!$show_warning) {
  783                           $filename = $pathtoroot.$admin.$path_char.'install'.$path_char.'inportal_remove.sql';
  784                           RunSchemaFile($ado,$filename);
  785                           $state="restore_run";
  786              }
  787              else {
  788                           $state = "warning";
  789                           $include_file = $pathtoroot.$admin."/install/warning.php";
  790              }
  791                   }
  792                   else {
  793                           if ($_POST['backupdate'] != '') {
  794                                   $include_file = $pathtoroot.$admin."/install/restore_select.php";
  795                                   $restore_error = "$backupfile not found or could not be read";
  796                           }
  797                           else {
  798                                   $include_file = $pathtoroot.$admin."/install/restore_select.php";
  799                                   $restore_error = "No backup selected!!!";
  800                           }
  801                   }
  802           }
  803           //echo $restore_error;
  804   }
  805  
  806   if($state=="restore_select")
  807   {
  808           if( isset($_POST['backupdir']) ) $filepath = stripslashes($_POST['backupdir']);
  809           $include_file = $pathtoroot.$admin."/install/restore_select.php";
  810   }
  811  
  812   if($state=="restore_run")
  813   {
  814     $ado =& inst_GetADODBConnection();
  815     $FileOffset = (int)$_GET["Offset"];
  816     if(!strlen($backupfile))
  817       $backupfile = SuperStrip($_GET['File'], true);
  818  
  819     $include_file = $pathtoroot.$admin."/install/restore_run.php";
  820   }
  821  
  822   if($state=="db_config_save")
  823   {
  824       set_ini_value("Database", "DBType",$_POST["ServerType"]);
  825       set_ini_value("Database", "DBHost",$_POST["ServerHost"]);
  826       set_ini_value("Database", "DBName",$_POST["ServerDB"]);
  827       set_ini_value("Database", "DBUser",$_POST["ServerUser"]);
  828       set_ini_value("Database", "DBUserPassword",$_POST["ServerPass"]);
  829       set_ini_value("Database","TablePrefix",$_POST["TablePrefix"]);
  830  
  831       save_values();
  832       $ini_vars = inst_parse_portal_ini($ini_file,TRUE);
  833  
  834       foreach($ini_vars as $secname => $section)
  835       {
  836         foreach($section as $key => $value)
  837         {
  838             $key = "g_".str_replace("-", "", $key);
  839             global $$key;
  840             $$key = $value;
  841         }
  842       }
  843       unset($ado);
  844       $ado = VerifyDB('dbinfo', 'license');
  845   }
  846  
  847   if($state=="dbinfo")
  848   {
  849           if ($install_type == '') {
  850                   $install_type = 1;
  851           }
  852           $include_file = $pathtoroot.$admin."/install/dbinfo.php";
  853   }
  854  
  855   if ($state == "download_license") {
  856           $ValidLicense = FALSE;
  857  
  858           $lic_login = isset($_POST['login']) ? $_POST['login'] : '';
  859           $lic_password = isset($_POST['password']) ? $_POST['password'] : '';
  860  
  861           if ($lic_login != '' && $lic_password != '') {
  862                   // Here we determine weather login is ok & check available licenses
  863  
  864                   $rfile = @fopen(GET_LICENSE_URL."?login=".md5($_POST['login'])."&password=".md5($_POST['password'])."&version=".GetMaxPortalVersion($pathtoroot.$admin)."&domain=".base64_encode($_SERVER['HTTP_HOST']), "r");
  865                   if (!$rfile) {
  866                           $get_license_error = "Unable to connect to the Intechnic server! Please try again later!";
  867                           $state = "get_license";
  868                           $include_file = $pathtoroot.$admin."/install/get_license.php";
  869                   }
  870                   else {
  871                           $rcontents = '';
  872                           while (!feof($rfile)) {
  873                                   $line = fgets($rfile, 10000);
  874                                   $rcontents .= $line;
  875                           }
  876                           @fclose($rfile);
  877  
  878                           if (substr($rcontents, 0, 5) == 'Error') {
  879                                   $get_license_error = substr($rcontents, 6);
  880                                   $state = "get_license";
  881                                   $include_file = $pathtoroot.$admin."/install/get_license.php";
  882                           }
  883                           else {
  884                                   if (substr($rcontents, 0, 3) == "SEL") {
  885                                           $state = "download_license";
  886                                           $license_select = substr($rcontents, 4);
  887                                           $include_file = $pathtoroot.$admin."/install/download_license.php";
  888                                   }
  889                                   else {
  890                                           // Here we get one license
  891                                           $tmp_data = explode('Code==:', $rcontents);
  892  
  893                           $data = base64_decode(str_replace("In-Portal License File - do not edit!\n", "", $tmp_data[0]));
  894                                           a83570933e44bc66b31dd7127cf3f23a($data);
  895                               $ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
  896                               if($ValidLicense)
  897                               {
  898                                   set_ini_value("Intechnic","License",base64_encode($data));
  899                                   set_ini_value("Intechnic","LicenseCode",$tmp_data[1]);
  900                                   save_values();
  901                                   $state="domain_select";
  902                                   $got_license = 1;
  903                               }
  904                               else {
  905                                 $license_error="Invalid License File";
  906                               }
  907                                   if(!$ValidLicense)
  908                                   {
  909                                       $state="license";
  910                                   }
  911                                   }
  912                           }
  913                   }
  914  
  915           }
  916           else if ($_POST['licenses'] == '') {
  917                   $state = "get_license";
  918                   $get_license_error = "Username and / or password not specified!!!";
  919                   $include_file = $pathtoroot.$admin."/install/get_license.php";
  920           }
  921           else {
  922                   // Here we download license
  923                   $rfile = @fopen(GET_LICENSE_URL."?license_id=".md5($_POST['licenses'])."&dlog=".md5($_POST['dlog'])."&dpass=".md5($_POST['dpass'])."&version=".GetMaxPortalVersion($pathtoroot.$admin)."&domain=".base64_encode($_POST['domain']), "r");
  924                   if (!$rfile) {
  925                           $get_license_error = "Unable to connect to the Intechnic server! Please try again later!";
  926                           $state = "get_license";
  927                           $include_file = $pathtoroot.$admin."/install/get_license.php";
  928                   }
  929                   else {
  930                           $rcontents = '';
  931                           while (!feof($rfile)) {
  932                                   $line = fgets($rfile, 10000);
  933                                   $rcontents .= $line;
  934                           }
  935                           @fclose($rfile);
  936  
  937                           if (substr($rcontents, 0, 5) == 'Error') {
  938                                   $download_license_error = substr($rcontents, 6);
  939                                   $state = "download_license";
  940                                   $include_file = $pathtoroot.$admin."/install/download_license.php";
  941                           }
  942                           else {
  943                                   $tmp_data = explode('Code==:', $rcontents);
  944  
  945                       $data = base64_decode(str_replace("In-Portal License File - do not edit!\n", "", $tmp_data[0]));
  946                       a83570933e44bc66b31dd7127cf3f23a($data);
  947                       $ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
  948                       if($ValidLicense)
  949                       {
  950                           set_ini_value("Intechnic","License",base64_encode($data));
  951                           // old licensing script doen't return 2nd parameter (licanse code)
  952                           if( isset($tmp_data[1]) ) set_ini_value("Intechnic","LicenseCode",$tmp_data[1]);
  953                           save_values();
  954                           $state="domain_select";
  955                       }
  956                       else {
  957                         $license_error="Invalid License File";
  958                       }
  959                           if(!$ValidLicense)
  960                           {
  961                               $state="license";
  962                           }
  963                           }
  964                   }
  965           }
  966   }
  967  
  968   if($state=="license_process")
  969   {
  970       $ValidLicense = FALSE;
  971       $tmp_lic_opt = GetVar('lic_opt', true);
  972       switch($tmp_lic_opt)
  973       {
  974       case 1: /* download from intechnic */
  975           $include_file = $pathtoroot.$admin."/install/get_license.php";
  976           $state = "get_license";
  977           //if(!$ValidLicense)
  978           //{
  979           //    $state="license";
  980           //}
  981       break;
  982       case 2: /* upload file  */
  983           $file = $_FILES["licfile"];
  984           if(is_array($file))
  985           {
  986               move_uploaded_file($file["tmp_name"],$pathtoroot."themes/tmp.lic");
  987               @chmod($pathtoroot."themes/tmp.lic", 0666);
  988  
  989               $fp = @fopen($pathtoroot."themes/tmp.lic","rb");
  990               if($fp)
  991               {
  992                   $lic = fread($fp,filesize($pathtoroot."themes/tmp.lic"));
  993                   fclose($fp);
  994               }
  995  
  996               $tmp_data = ae666b1b8279502f4c4b570f133d513e(FALSE,$pathtoroot."themes/tmp.lic");
  997               $data = $tmp_data[0];
  998  
  999               @unlink($pathtoroot."themes/tmp.lic");
  1000               a83570933e44bc66b31dd7127cf3f23a($data);
  1001               $ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
  1002               if($ValidLicense)
  1003               {
  1004                   set_ini_value("Intechnic","License",base64_encode($data));
  1005                   set_ini_value("Intechnic","LicenseCode",$tmp_data[1]);
  1006                   save_values();
  1007                   $state="domain_select";
  1008               }
  1009               else
  1010                 $license_error="Invalid License File";
  1011           }
  1012           if(!$ValidLicense)
  1013           {
  1014               $state="license";
  1015           }
  1016       break;
  1017       case 3: /* existing */
  1018           if(strlen($g_License))
  1019           {
  1020               $lic = base64_decode($g_License);
  1021               a83570933e44bc66b31dd7127cf3f23a($lic);
  1022               $ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
  1023               if($ValidLicense)
  1024               {
  1025                   $state="domain_select";
  1026               }
  1027               else
  1028               {
  1029                   $state="license";
  1030                   $license_error="Invalid or corrupt license detected";
  1031               }
  1032           }
  1033           else
  1034           {
  1035               $state="license";
  1036               $license_error="Missing License File";
  1037           }
  1038           if(!$ValidLicense)
  1039           {
  1040               $state="license";
  1041           }
  1042       break;
  1043       case 4:
  1044          //set_ini_value("Intechnic","License",base64_encode("local"));
  1045          //set_ini_value("Intechnic","LicenseCode",base64_encode("local"));
  1046          //save_values();
  1047          $state="domain_select";
  1048       break;
  1049       }
  1050     if($ValidLicense)
  1051         $state="domain_select";
  1052   }
  1053  
  1054   if($state=="license")
  1055   {
  1056       $include_file = $pathtoroot.$admin."/install/sel_license.php";
  1057  
  1058   }
  1059  
  1060   if($state=="reinstall")
  1061   {
  1062       $ado =& inst_GetADODBConnection();
  1063  
  1064       $show_upgrade = false;
  1065  
  1066           $sql = "SELECT Name FROM ".$g_TablePrefix."Modules";
  1067           $rs = $ado->Execute($sql);
  1068  
  1069           $modules = '';
  1070           while ($rs && !$rs->EOF) {
  1071                   $modules .= strtolower($rs->fields['Name']).',';
  1072                   $rs->MoveNext();
  1073           }
  1074  
  1075           $mod_arr = explode(",", substr($modules, 0, strlen($modules) - 1));
  1076  
  1077       foreach($mod_arr as $p)
  1078       {
  1079           if ($p == 'in-portal') {
  1080                   $p = '';
  1081           }
  1082  
  1083           $dir_name = $pathtoroot.$p."/admin/install/upgrades/";
  1084  
  1085           $dir = @dir($dir_name);
  1086           //echo "<pre>"; print_r($dir); echo "</pre>";
  1087  
  1088           if ($dir === false) continue;
  1089  
  1090           while ($file = $dir->read()) {
  1091                   if ($file != "." && $file != ".." && !is_dir($dir_name.$file))
  1092                   {
  1093                           if( preg_match('/inportal_upgrade_v(.*).(php|sql)$/', $file, $rets) )
  1094                           {
  1095                                   if($p == '') $p = 'in-portal';
  1096  
  1097                                   $sql = "SELECT Version FROM ".$g_TablePrefix."Modules WHERE Name = '".$p."'";
  1098                                   $rs = $ado->Execute($sql);
  1099  
  1100                                   if( ConvertVersion($rs->fields['Version']) < ConvertVersion( $rets[1] ) )
  1101                                   {
  1102                                           $show_upgrade = true;
  1103                                   }
  1104                           }
  1105                   }
  1106           }
  1107       }
  1108  
  1109       if ( !isset($install_type) || $install_type == '') {
  1110           $install_type = 2;
  1111       }
  1112  
  1113           $include_file = $pathtoroot.$admin."/install/reinstall.php";
  1114   }
  1115  
  1116   if($state=="login")
  1117   {
  1118       $lic = base64_decode($g_License);
  1119       if(strlen($lic))
  1120       {
  1121               a83570933e44bc66b31dd7127cf3f23a($lic);
  1122               $ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
  1123       }
  1124  
  1125       if(!$ValidLicense)
  1126       {
  1127           $state="license";
  1128       }
  1129       else
  1130         if($i_User == $_POST["UserName"] || $i_Pswd == $_POST["UserPass"])
  1131         {
  1132            $state = "domain_select";
  1133         }
  1134         else
  1135         {
  1136           $state="getuser";
  1137           $login_error = "Invalid User Name or Password.  If you don't know your username or password, contact Intechnic Support";
  1138         }
  1139  
  1140       //die();
  1141   }
  1142  
  1143   if($state=="getuser")
  1144   {
  1145           $include_file = $pathtoroot.$admin."/install/login.php";
  1146   }
  1147  
  1148   if($state=="set_domain")
  1149   {
  1150       if( !is_array($i_Keys) || !count($i_Keys) )
  1151       {
  1152           $lic = base64_decode($g_License);
  1153           if(strlen($lic))
  1154           {
  1155              a83570933e44bc66b31dd7127cf3f23a($lic);
  1156              $ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
  1157           }
  1158       }
  1159  
  1160       if($_POST["domain"]==1)
  1161       {
  1162           $domain = $_SERVER['HTTP_HOST'];
  1163  
  1164           if (strstr($domain, $i_Keys[0]['domain']) || de3ec1b7a142cccd0d51f03d24280744($domain)) {
  1165                   set_ini_value("Intechnic","Domain",$domain);
  1166                   save_values();
  1167                   $state="runsql";
  1168           }
  1169           else {
  1170                   $DomainError = 'Domain name selected does not match domain name in the license!';
  1171                   $state = "domain_select";
  1172           }
  1173       }
  1174       else
  1175       {
  1176           $domain = str_replace(" ", "", $_POST["other"]);
  1177           if ($domain != '') {
  1178                   if (strstr($domain, $i_Keys[0]['domain']) || de3ec1b7a142cccd0d51f03d24280744($domain)) {
  1179                           set_ini_value("Intechnic","Domain",$domain);
  1180                           save_values();
  1181                           $state="runsql";
  1182                   }
  1183                   else {
  1184                           $DomainError = 'Domain name entered does not match domain name in the license!';
  1185                           $state = "domain_select";
  1186                   }
  1187           }
  1188           else {
  1189                   $DomainError = 'Please enter valid domain!';
  1190                   $state = "domain_select";
  1191           }
  1192       }
  1193   }
  1194  
  1195   if($state=="domain_select")
  1196   {
  1197       if(!is_array($i_Keys))
  1198       {
  1199           $lic = base64_decode($g_License);
  1200           if(strlen($lic))
  1201           {
  1202              a83570933e44bc66b31dd7127cf3f23a($lic);
  1203              $ValidLicense = ((strlen($i_User)>0) && (strlen($i_Pswd)>0));
  1204           }
  1205       }
  1206  
  1207       $include_file = $pathtoroot.$admin."/install/domain.php";
  1208   }
  1209  
  1210  
  1211   if($state=="runsql")
  1212   {
  1213     $ado =& inst_GetADODBConnection();
  1214     $installed = TableExists($ado,"ConfigurationAdmin,Category,Permissions");
  1215     if(!$installed)
  1216     {
  1217                   // run core install script
  1218                   K4_RunSQL('/core/install/install_schema.sql');
  1219                   K4_RunSQL('/core/install/install_data.sql');
  1220                   K4_SetModuleVersion('Core');
  1221  
  1222                   // run in-portal install script
  1223                   $filename = $pathtoroot.$admin."/install/inportal_schema.sql";
  1224           RunSchemaFile($ado,$filename);
  1225           $filename = $pathtoroot.$admin."/install/inportal_data.sql";
  1226           RunSQLFile($ado,$filename);
  1227  
  1228           $sql = 'UPDATE '.$g_TablePrefix.'ConfigurationValues SET VariableValue = %s WHERE VariableName = %s';
  1229           $ado->Execute( sprintf($sql, $ado->qstr('portal@'.$ini_vars['Intechnic']['Domain']), $ado->qstr('Smtp_AdminMailFrom') ) );
  1230  
  1231           $sql = "SELECT Version FROM ".$g_TablePrefix."Modules WHERE Name = 'In-Portal'";
  1232           $rs = $ado->Execute($sql);
  1233  
  1234           set_ini_value("Module Versions", "In-Portal", $rs->fields['Version']);
  1235           save_values();
  1236  
  1237           require_once $pathtoroot.'kernel/include/tag-class.php';
  1238           if( !is_object($objTagList) ) $objTagList = new clsTagList();
  1239  
  1240           // install kernel specific tags
  1241           $objTagList->DeleteTags(); // delete all existing tags in db
  1242  
  1243           // create 3 predifined tags (because there no functions with such names
  1244           $t = new clsTagFunction();
  1245           $t->Set("name","include");
  1246           $t->Set("description","insert template output into the current template");
  1247           $t->Create();
  1248           $t->AddAttribute("_template","tpl","Template to insert","",TRUE);
  1249           $t->AddAttribute("_supresserror","bool","Supress missing template errors","",FALSE);
  1250           $t->AddAttribute("_dataexists","bool","Only include template output if content exists (content is defined by the tags in the template)","",FALSE);
  1251           $t->AddAttribute("_nodatatemplate","tpl","Template to include if the nodataexists condition is true","",FALSE);
  1252                   unset($t);
  1253  
  1254           $t = new clsTagFunction();
  1255           $t->Set("name","perm_include");
  1256           $t->Set("description","insert template output into the current template if permissions are set");
  1257           $t->Create();
  1258           $t->AddAttribute("_template","tpl","Template to insert","",TRUE);
  1259           $t->AddAttribute("_noaccess","tpl","Template to insert if access is denied","",FALSE);
  1260           $t->AddAttribute("_permission","","Comma-separated list of permissions, any of which will grant access","",FALSE);
  1261           $t->AddAttribute("_module","","Used in place of the _permission attribute, this attribute verifies the module listed is enabled","",FALSE);
  1262           $t->AddAttribute("_system","bool","Must be set to true if any permissions in _permission list is a system permission","",FALSE);
  1263           $t->AddAttribute("_supresserror","bool","Supress missing template errors","",FALSE);
  1264           $t->AddAttribute("_dataexists","bool","Only include template output if content exists (content is defined by the tags in the template)","",FALSE);
  1265           $t->AddAttribute("_nodatatemplate","tpl","Template to include if the nodataexists condition is true","",FALSE);
  1266                   unset($t);
  1267  
  1268           $t = new clsTagFunction();
  1269           $t->Set("name","mod_include");
  1270           $t->Set("description","insert templates from all enabled modules.  No error occurs if the template does not exist.");
  1271           $t->Create();
  1272           $t->AddAttribute("_template","tpl","Template to insert.  This template path should be relative to the module template root directory","",TRUE);
  1273           $t->AddAttribute("_modules","","Comma-separated list of modules.  Defaults to all enabled modules if not set","",FALSE);
  1274           $t->AddAttribute("_supresserror","bool","Supress missing template errors","",FALSE);
  1275           $t->AddAttribute("_dataexists","bool","Only include template output if content exists (content is defined by the tags in the template)","",FALSE);
  1276           $t->AddAttribute("_nodatatemplate","tpl","Template to include if the nodataexists condition is true","",FALSE);
  1277  
  1278           $objTagList->ParseFile($pathtoroot.'kernel/parser.php'); // insert module tags
  1279  
  1280           if( is_array($ItemTagFiles) )
  1281                   foreach($ItemTagFiles as $file)
  1282                                   $objTagList->ParseItemFile($pathtoroot.$file);
  1283  
  1284           $state="RootPass";
  1285     }
  1286     else {
  1287             $include_file = $pathtoroot.$admin."/install/install_finish.php";
  1288         $state="finish";
  1289     }
  1290   }
  1291  
  1292   if($state=="RootSetPass")
  1293   {
  1294     $pass = $_POST["RootPass"];
  1295     if(strlen($pass)<4)
  1296     {
  1297         $PassError = "Root Password must be at least 4 characters";
  1298         $state = "RootPass";
  1299  
  1300     }
  1301     else if ($pass != $_POST["RootPassConfirm"]) {
  1302             $PassError = "Passwords does not match";
  1303             $state = "RootPass";
  1304     }
  1305     else
  1306     {
  1307             $pass = md5(md5($pass).'b38');
  1308         $sql = '  UPDATE '.$g_TablePrefix.'ConfigurationValues
  1309                           SET VariableValue = '.$ado->qstr($pass).'
  1310                           WHERE VariableName = "RootPass";';
  1311         $ado =& inst_GetADODBConnection();
  1312         $ado->Execute($sql);
  1313         $state="modselect";
  1314     }
  1315   }
  1316  
  1317   if($state=="RootPass")
  1318   {
  1319       $include_file = $pathtoroot.$admin."/install/rootpass.php";
  1320   }
  1321  
  1322   if($state=="lang_install_init")
  1323   {
  1324  
  1325           $ado =& inst_GetADODBConnection();
  1326  
  1327           if( TableExists($ado, 'Language,Phrase') )
  1328           {
  1329                   // KERNEL 4 INIT: BEGIN
  1330                   define('FULL_PATH', realpath(dirname(__FILE__).'/..'));
  1331                   include_once(FULL_PATH.'/core/kernel/startup.php');
  1332  
  1333                   $application =& kApplication::Instance();
  1334                   $application->Init();
  1335                   // KERNEL 4 INIT: END
  1336  
  1337                   $lang_xml =& $application->recallObject('LangXML');
  1338  
  1339                   if (defined('DBG_FAST_INSTALL') && DBG_FAST_INSTALL) {
  1340                           $lang_xml->tables['phrases'] = TABLE_PREFIX.'Phrase';
  1341                           $lang_xml->tables['emailmessages'] = TABLE_PREFIX.'EmailMessage';
  1342                   }
  1343                   else {
  1344                           $lang_xml->renameTable('phrases', TABLE_PREFIX.'ImportPhrases');
  1345                           $lang_xml->renameTable('emailmessages', TABLE_PREFIX.'ImportEvents');
  1346                   }
  1347  
  1348                   $lang_xml->lang_object->TableName = $application->getUnitOption('lang','TableName');
  1349  
  1350                   $languages = $application->GetVar('lang');
  1351                   if($languages)
  1352                   {
  1353                           $kernel_db =& $application->GetADODBConnection();
  1354                           $modules_table = $application->getUnitOption('mod','TableName');
  1355  
  1356                           $modules = $kernel_db->GetCol('SELECT Path, Name FROM '.$modules_table, 'Name');
  1357                           $modules['In-Portal'] = '';
  1358  
  1359                           foreach($languages as $lang_file)
  1360                           {
  1361                                   foreach($modules as $module_name => $module_folder)
  1362                                   {
  1363                                           $lang_path = MODULES_PATH.'/'.$module_folder.'admin/install/langpacks';
  1364                                           $lang_xml->Parse($lang_path.'/'.$lang_file, '|0|1|2|', '');
  1365                                           if($force_finish) $lang_xml->lang_object->Update();
  1366                                   }
  1367                           }
  1368  
  1369                           if (defined('DBG_FAST_INSTALL') && DBG_FAST_INSTALL) {
  1370                                   $state = 'lang_default';
  1371                           }
  1372                           else {
  1373                                   $state = 'lang_install';
  1374                           }
  1375                   }
  1376                   else
  1377                   {
  1378                           $state = 'lang_select';
  1379                   }
  1380  
  1381                   $application->Done();
  1382           }
  1383           else
  1384           {
  1385                   $general_error = 'Database error! No language tables found!';
  1386           }
  1387   }
  1388  
  1389   if($state=="lang_install")
  1390   {
  1391           define('FORCE_CONFIG_CACHE', 1);
  1392           /* do pack install */
  1393           $Offset = (int)$_GET["Offset"];
  1394           $Status = (int)$_GET["Status"];
  1395  
  1396           $PhraseTable = $g_TablePrefix."ImportPhrases";
  1397           $EventTable = $g_TablePrefix."ImportEvents";
  1398  
  1399           $Total = TableCount($Status == 0 ? $PhraseTable : $EventTable, '', 0);
  1400  
  1401           if($Status == 0)
  1402           {
  1403                   $Offset = $objLanguages->ReadImportTable($PhraseTable, 1,"0,1,2", $force_finish ? false : true, 200,$Offset);
  1404                   if($Offset >= $Total)
  1405                   {
  1406                           $Offset=0;
  1407                           $Status=1;
  1408                   }
  1409  
  1410                   $next_step = GetVar('next_step', true);
  1411  
  1412                   if($force_finish == true) $next_step = 3;
  1413                   $NextUrl = $_SERVER['PHP_SELF']."?Offset=$Offset&Status=$Status&state=lang_install&next_step=$next_step&install_type=$install_type";
  1414                   if($force_finish == true) $NextUrl .= '&ff=1';
  1415                   $include_file = $pathtoroot.$admin."/install/lang_run.php";
  1416           }
  1417           else
  1418           {
  1419                   if(!is_object($objMessageList))
  1420                   $objMessageList = new clsEmailMessageList();
  1421  
  1422                   $Offset = $objMessageList->ReadImportTable($EventTable, $force_finish ? false : true,300,$Offset);
  1423  
  1424                   if($Offset > $Total)
  1425                   {
  1426                           $next_step = GetVar('next_step', true);
  1427  
  1428                           if($force_finish == true) $next_step = 3;
  1429                           $NextUrl = $_SERVER['PHP_SELF']."?Offset=$Offset&Status=$Status&State=lang_install&next_step=$next_step&install_type=$install_type";
  1430                           if($force_finish == true) $NextUrl .= '&ff=1';
  1431                           $include_file = $pathtoroot.$admin."/install/lang_run.php";
  1432                   }
  1433                   else
  1434                   {
  1435                           $db =& GetADODBConnection();
  1436                           $prefix = $g_TablePrefix;
  1437                           $db->Execute('DROP TABLE IF EXISTS '.$PhraseTable);
  1438                           $db->Execute('DROP TABLE IF EXISTS '.$EventTable);
  1439  
  1440                           if(!$force_finish)
  1441                           {
  1442                                   $state = 'lang_default';
  1443                           }
  1444                           else
  1445                           {
  1446                                   $_POST['next_step'] = 4;
  1447                                   $state = 'finish';
  1448                                   $include_file = $pathtoroot.$admin."/install/install_finish.php";
  1449                           }
  1450                   }
  1451           }
  1452   }
  1453  
  1454   if($state=="lang_default_set")
  1455   {
  1456   //      phpinfo(INFO_VARIABLES);
  1457       /*$ado =& inst_GetADODBConnection();
  1458           $PhraseTable = GetTablePrefix()."ImportPhrases";
  1459           $EventTable = GetTablePrefix()."ImportEvents";
  1460           $ado->Execute("DROP TABLE IF EXISTS $PhraseTable");
  1461           $ado->Execute("DROP TABLE IF EXISTS $EventTable");*/
  1462  
  1463           $Id = $_POST["lang"];
  1464  
  1465           $objLanguages->SetPrimary($Id);
  1466           if (defined('DBG_FAST_INSTALL')) {
  1467                   $state = 'theme_sel';
  1468           }
  1469           else {
  1470                   $state="postconfig_1";
  1471           }
  1472   }
  1473  
  1474   if($state=="lang_default")
  1475   {
  1476           $Packs = Array();
  1477           $objLanguages->Clear();
  1478  
  1479           $objLanguages->LoadAllLanguages();
  1480           foreach($objLanguages->Items as $l)
  1481           {
  1482                   $Packs[$l->Get("LanguageId")] = $l->Get("PackName");
  1483           }
  1484           $include_file = $pathtoroot.$admin."/install/lang_default.php";
  1485   }
  1486  
  1487  
  1488  
  1489   if($state=="modinstall")
  1490   {
  1491       $doms = $_POST["domain"];
  1492       if(is_array($doms))
  1493       {
  1494           $ado =& inst_GetADODBConnection();
  1495           require_once $pathtoroot.'kernel/include/tag-class.php';
  1496           if( !isset($objTagList) || !is_object($objTagList) ) $objTagList = new clsTagList();
  1497           foreach($doms as $p)
  1498           {
  1499                   $filename = $pathtoroot.$p.'/admin/install.php';
  1500               if(file_exists($filename) )
  1501               {
  1502                   include($filename);
  1503               }
  1504           }
  1505  
  1506       }
  1507  
  1508   /*    $sql = "SELECT Name FROM ".GetTablePrefix()."Modules";
  1509       $rs = $ado->Execute($sql);
  1510  
  1511       while($rs && !$rs->EOF)
  1512       {
  1513           $p = $rs->fields['Name'];
  1514           $mod_name = strtolower($p);
  1515  
  1516           if ($mod_name == 'in-portal') {
  1517                   $mod_name = '';
  1518           }
  1519  
  1520           $dir_name = $pathtoroot.$mod_name."/admin/install/upgrades/";
  1521           $dir = @dir($dir_name);
  1522  
  1523           $new_version = '';
  1524           $tmp1 = 0;
  1525           $tmp2 = 0;
  1526           while ($file = $dir->read()) {
  1527                   if ($file != "." && $file != ".." && !is_dir($dir_name.$file))
  1528                   {
  1529                           $file = str_replace("inportal_upgrade_v", "", $file);
  1530                           $file = str_replace(".sql", "", $file);
  1531  
  1532                           if ($file != '' && !strstr($file, 'changelog') && !strstr($file, 'readme')) {
  1533                                   $tmp1 = str_replace(".", "", $file);
  1534                                   if ($tmp1 > $tmp2) {
  1535                                           $new_version = $file;
  1536                                   }
  1537                           }
  1538                   }
  1539                   $tmp2 = $tmp1;
  1540           }
  1541  
  1542  
  1543           $version_nrs = explode(".", $new_version);
  1544  
  1545           for ($i = 0; $i < $version_nrs[0] + 1; $i++) {
  1546                   for ($j = 0; $j < $version_nrs[1] + 1; $j++) {
  1547                           for ($k = 0; $k < $version_nrs[2] + 1; $k++) {
  1548                                   $try_version = "$i.$j.$k";
  1549  
  1550                                   $filename = $pathtoroot.$mod_name."/admin/install/upgrades/inportal_upgrade_v$try_version.sql";
  1551  
  1552                                   if(file_exists($filename))
  1553                                   {
  1554                                           RunSQLFile($ado, $filename);
  1555                                           set_ini_value("Module Versions", $p, $try_version);
  1556                                           save_values();
  1557                                   }
  1558                           }
  1559                   }
  1560           }
  1561  
  1562           $rs->MoveNext();
  1563       }
  1564   */
  1565       $state="lang_select";
  1566   }
  1567  
  1568   if($state=="modselect")
  1569   {
  1570    /* /admin/install.php */
  1571           $UrlLen = (strlen($admin) + 12)*-1;
  1572       $pathguess =substr($_SERVER["SCRIPT_NAME"],0,$UrlLen);
  1573       $sitepath = $pathguess;
  1574       $esc_path = str_replace("\\","/",$pathtoroot);
  1575       $esc_path = str_replace("/","\\",$esc_path);
  1576       //set_ini_value("Site","DomainName",$_SERVER["HTTP_HOST"]);
  1577       //$g_DomainName= $_SERVER["HTTP_HOST"];
  1578       save_values();
  1579  
  1580       $ado =& inst_GetADODBConnection();
  1581       if(substr($sitepath,0,1)!="/")
  1582           $sitepath="/".$sitepath;
  1583       if(substr($sitepath,-1)!="/")
  1584           $sitepath .= "/";
  1585  
  1586       $sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '$sitepath' WHERE VariableName='Site_Path'";
  1587       $ado->Execute($sql);
  1588       $sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '$g_Domain' WHERE VariableName='Server_Name'";
  1589       $ado->Execute($sql);
  1590       $sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '".$_SERVER['DOCUMENT_ROOT'].$sitepath."admin/backupdata' WHERE VariableName='Backup_Path'";
  1591       $ado->Execute($sql);
  1592       $Modules = a48d819089308a9aeb447e7248b2587f();
  1593  
  1594       if (count($Modules) > 0) {
  1595           $include_file = $pathtoroot.$admin."/install/modselect.php";
  1596       }
  1597       else {
  1598           $state = "lang_select";
  1599           $skip_step = true;
  1600       }
  1601   }
  1602  
  1603   if($state=="lang_select")
  1604   {
  1605           $Packs = GetLanguageList();
  1606           $include_file = $pathtoroot.$admin."/install/lang_select.php";
  1607   }
  1608  
  1609   if(substr($state,0,10)=="postconfig")
  1610   {
  1611       $p = explode("_",$state);
  1612       $step = $p[1];
  1613  
  1614       if ($_POST['Site_Path'] != '') {
  1615                   $sql = "SELECT Name, Version FROM ".$g_TablePrefix."Modules";
  1616                   $rs = $ado->Execute($sql);
  1617  
  1618                   $modules_str = '';
  1619                   while ($rs && !$rs->EOF) {
  1620                           $modules_str .= $rs->fields['Name'].' ('.$rs->fields['Version'].'),';
  1621                           $rs->MoveNext();
  1622                   }
  1623  
  1624                   $modules_str = substr($modules_str, 0, strlen($modules_str) - 1);
  1625                   $rfile = @fopen(GET_LICENSE_URL."?url=".base64_encode($_SERVER['HTTP_HOST'].$_POST['Site_Path'])."&modules=".base64_encode($modules_str)."&license_code=".base64_encode($g_LicenseCode)."&version=".GetMaxPortalVersion($pathtoroot.$admin)."&domain=".md5($_SERVER['HTTP_HOST']), "r");
  1626                   if (!$rfile) {
  1627                           //$get_license_error = "Unable to connect to the Intechnic server! Please try again later!";
  1628                           //$state = "postconfig_1";
  1629                           //$include_file = $pathtoroot.$admin."/install/postconfig.php";
  1630                   }
  1631                   else {
  1632                           $rcontents = '';
  1633                           while (!feof($rfile)) {
  1634                                   $line = fgets($rfile, 10000);
  1635                                   $rcontents .= $line;
  1636                           }
  1637                           @fclose($rfile);
  1638                   }
  1639  
  1640       }
  1641  
  1642       if(strlen($_POST["oldstate"])>0)
  1643       {
  1644         $s = explode("_",$_POST["oldstate"]);
  1645         $oldstep = $s[1];
  1646         if($oldstep<count($configs))
  1647         {
  1648             $section = $configs[$oldstep];
  1649             $module = $mods[$oldstep];
  1650             $title = $titles[$oldstep];
  1651             $objAdmin = new clsConfigAdmin($module,$section,TRUE);
  1652             $objAdmin->SaveItems($_POST,TRUE);
  1653         }
  1654       }
  1655       $section = $configs[$step];
  1656       $module = $mods[$step];
  1657       $title = $titles[$step];
  1658  
  1659       $step++;
  1660  
  1661       if($step <= count($configs)+1)
  1662       {
  1663            $include_file = $pathtoroot.$admin."/install/postconfig.php";
  1664       }
  1665       else
  1666           $state = "theme_sel";
  1667   }
  1668  
  1669   if($state=="theme_sel")
  1670   {
  1671       $objThemes->CreateMissingThemes(true);
  1672       $include_file = $pathtoroot.$admin."/install/theme_select.php";
  1673   }
  1674  
  1675   if($state=="theme_set")
  1676   {
  1677       ## get & define Non-Blocking & Blocking versions ##
  1678           $blocking_sockets = minimum_php_version("4.3.0")? 0 : 1;
  1679  
  1680           $ado =& inst_GetADODBConnection();
  1681       $sql = "UPDATE ".$g_TablePrefix."ConfigurationValues SET VariableValue = '$blocking_sockets' WHERE VariableName='SocketBlockingMode'";
  1682       $ado->Execute($sql);
  1683       ## get & define Non-Blocking & Blocking versions ##
  1684  
  1685  
  1686           $theme_id = $_POST["theme"];
  1687       $pathchar="/";
  1688       //$objThemes->SetPrimaryTheme($theme_id);
  1689       $t = $objThemes->GetItem($theme_id);
  1690       $t->Set("Enabled",1);
  1691       $t->Set("PrimaryTheme",1);
  1692       $t->Update();
  1693       $t->VerifyTemplates();
  1694           $include_file = $pathtoroot.$admin."/install/install_finish.php";
  1695       $state="finish";
  1696   }
  1697  
  1698   if ($state == "adm_login") {
  1699           $ado =& inst_GetADODBConnection();
  1700           $sql = 'UPDATE '.TABLE_PREFIX.'UserSession
  1701                           SET LastAccessed = 0
  1702                           WHERE PortalUserId IN (0,-2)';
  1703           $ado->Execute($sql);
  1704           
  1705           echo "<script>window.location='index.php';</script>";
  1706   }
  1707  
  1708   if ($state == "finish") {
  1709       $ado =& inst_GetADODBConnection();
  1710           $PhraseTable = $g_TablePrefix."ImportPhrases";
  1711           $EventTable = $g_TablePrefix."ImportEvents";
  1712           $ado->Execute("DROP TABLE IF EXISTS $PhraseTable");
  1713           $ado->Execute("DROP TABLE IF EXISTS $EventTable");
  1714           $ado->Execute('INSERT INTO '.$g_TablePrefix.'Cache (VarName, Data) VALUES (\'ForcePermCacheUpdate\', \'1\')');
  1715  
  1716           $include_file = $pathtoroot.$admin."/install/install_finish.php";
  1717   }
  1718  
  1719   // init variables
  1720   $vars = Array('db_error','restore_error','PassError','DomainError','login_error','inst_error');
  1721   foreach($vars as $var_name) ReSetVar($var_name);
  1722  
  1723   switch($state)
  1724   {
  1725   case "modselect":
  1726       $title = "Select Modules";
  1727       $help = "<p>Select the In-Portal modules you wish to install.  The modules listed to the right ";
  1728       $help .="are all modules included in this installation that are licensed to run on this server. </p>";
  1729   break;
  1730   case "reinstall":
  1731       $title = "Installation Maintenance";
  1732       $help = "<p>A Configuration file has been detected on your system and it appears In-Portal is correctly installed.  ";
  1733       $help .="In order to work with the maintenance functions provided to the left you must provide the Intechnic ";
  1734       $help .="Username and Password you used when obtaining the license file residing on the server, or your admin Root password. ";
  1735       $help .=" <i>(Use Username 'root' if using your root password)</i></p>";
  1736       $help .= "<p>To removing your existing database and start with a fresh installation, select the first option ";
  1737       $help .= "provided.  Note that this operation cannot be undone and no backups are made! Use at your own risk.</p>";
  1738       $help .="<p>If you wish to scrap your current installation and install to a new location, choose the second option. ";
  1739       $help .="If this option is selected you will be prompted for new database configuration information.</p>";
  1740       $help .="<p>The <i>Update License Information</i> option is used to update your In-Portal license data.  Select this option if you have ";
  1741       $help .="modified your licensing status with Intechnic, or you have received new license data via email</p>";
  1742       $help .="<p>The <i>Fix Paths</i> option should be used when the location of the In-portal files has changed. For example, if you moved them from one folder to another. It will update all settings and ensure the program is operational at the new location.</p>";
  1743   break;
  1744   case "fix_paths":
  1745           $title = "Fix Paths";
  1746           $help = "<p>The <i>Fix Paths</i> option should be used when the location of the In-portal files has changed. For example, if you moved them from one folder to another. It will update all settings and ensure the program is operational at the new location.<p>";
  1747   break;
  1748   case "RootPass":
  1749       $title = "Set Admin Root Password";
  1750       $help = "<p>The Root Password is initially required to access the admin sections of In-Portal. ";
  1751       $help .="The root user cannot be used to access the front-end of the system, so it is recommended that you ";
  1752       $help .="create additional users with admin privlidges.</p>";
  1753   break;
  1754   case "finish":
  1755       $title = "Thank You!";
  1756       $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> ";
  1757       $help.=" for the latest news, module releases and support. </p>";
  1758       $help.="<p>*Make sure to clean your browser' cache after upgrading In-portal version</p>";
  1759   break;
  1760   case "license":
  1761       $title = "License Configuration";
  1762       $help ="<p>A License is required to run In-Portal on a server connected to the Internet.  You ";
  1763       $help.="can run In-Portal on localhost, non-routable IP addresses, or other computers on your LAN. ";
  1764       $help.="If Intechnic has provided you with a license file, upload it here. Otherwise select the first ";
  1765       $help.="option to allow Install to download your license for you.</p>";
  1766       $help.="<p>If a valid license has been detected on your server, you can choose the <i>Use Existing License</i> ";
  1767       $help.="and continue the installation process</p>";
  1768   break;
  1769   case "domain_select":
  1770       $title="Select Licensed Domain";
  1771       $help ="<p>Select the domain you wish to configure In-Portal for.  The <i>Other</i> option ";
  1772       $help.=" can be used to configure In-Portal for use on a local domain.</p>";
  1773       $help.="<p>For local domains, enter the hostname or LAN IP Address of the machine running In-Portal.</p>";
  1774   break;
  1775   case "db_reconfig":
  1776   case "dbinfo":
  1777       $title="Database Configuration";
  1778       $help = "<p>In-Portal needs to connect to your Database Server.  Please provide the database server type*, ";
  1779       $help .="host name (<i>normally \"localhost\"</i>), Database user name, and database Password.  ";
  1780       $help .="These fields are required to connect to the database.</p><p>If you would like In-Portal ";
  1781       $help .="to use a table prefix, enter it in the field provided. This prefix can be any ";
  1782       $help .=" text which can be used in the names of tables on your system.  The characters entered in this field ";
  1783       $help .=" are placed <i>before</i> the names of the tables used by In-Portal.  For example, if you enter \"inp_\"";
  1784       $help .=" into the prefix field, the table named Category will be named inp_Category.</p>";
  1785   break;
  1786   case "lang_select":
  1787       $title="Language Pack Installation";
  1788       $help = "<p>Select the language packs you wish to install. Each language pack contains all the phrases ";
  1789       $help .="used by the In-Portal administration and the default template set. Note that at least one ";
  1790       $help .="pack <b>must</b> be installed.</p>";
  1791   break;
  1792   case "lang_default":
  1793       $title="Select Default Language";
  1794       $help = "<p>Select which language should be considered the \"default\" language.  This is the language ";
  1795       $help .="used by In-Portal when a language has not been selected by the user.  This selection is applicable ";
  1796       $help .="to both the administration and front-end.</p>";
  1797   break;
  1798   case "lang_install":
  1799           $title="Installing Language Packs";
  1800           $help = "<p>The language packs you have selected are being installed.  You may install more languages at a ";
  1801           $help.="later time from the Regional admin section.</p>";
  1802   break;
  1803   case "postconfig_1":
  1804       $help = "<P>These options define the general operation of In-Portal.  Items listed here are ";
  1805       $help .="required for In-Portal's operation.</p><p>When you have finished, click <i>save</i> to continue.</p>";
  1806   break;
  1807   case "postconfig_2":
  1808       $help = "<P>User Management configuration options determine how In-Portal manages your user base.</p>";
  1809       $help .="<p>The groups listed to the right are pre-defined by the installation process and may be changed ";
  1810       $help .="through the Groups section of admin.</p>";
  1811   break;
  1812   case "postconfig_3":
  1813       $help = "<P>The options listed here are used to control the category list display functions of In-Portal. </p>";
  1814   break;
  1815   case "theme_sel":
  1816       $title="Select Default Theme";
  1817       $help = "<P>This theme will be used whenever a front-end session is started. ";
  1818       $help .="If you intend to upload a new theme and use that as default, you can do so through the ";
  1819       $help .="admin at a later date.  A default theme is required for session management.</p>";
  1820   break;
  1821   case "get_license":
  1822       $title="Download License from Intechnic";
  1823       $help ="<p>A License is required to run In-Portal on a server connected to the Internet.  You ";
  1824       $help.="can run In-Portal on localhost, non-routable IP addresses, or other computers on your LAN.</p>";
  1825       $help.="<p>Here as you have selected download license from Intechnic you have to input your username and ";
  1826       $help.="password of your In-Business account in order to download all your available licenses.</p>";
  1827   break;
  1828   case "download_license":
  1829       $title="Download License from Intechnic";
  1830       $help ="<p>A License is required to run In-Portal on a server connected to the Internet.  You ";
  1831       $help.="can run In-Portal on localhost, non-routable IP addresses, or other computers on your LAN.</p>";
  1832       $help.="<p>Please choose the license from the drop down for this site! </p> ";
  1833   break;
  1834   case "restore_select":
  1835           $title="Select Restore File";
  1836           $help = "<P>Select the restore file to use to reinstall In-Portal.  If your backups are not performed ";
  1837           $help .= "in the default location, you can enter the location of the backup directory and click the ";
  1838           $help .="<i>Update</i> button.</p>";
  1839   case "restore_run":
  1840           $title= "Restore in Progress";
  1841           $help = "<P>Restoration of your system is in progress.  When the restore has completed, the installation ";
  1842           $help .="will continue as normal.  Hitting the <i>Cancel</i> button will restart the entire installation process. ";
  1843   break;
  1844   case "warning":
  1845           $title = "Restore in Progress";
  1846           $help = "<p>Please approve that you understand that you are restoring your In-Portal data base from other version of In-Portal.</p>";
  1847   break;
  1848   case "update":
  1849           $title = "Update In-Portal";
  1850           $help = "<p>Select modules from the list, you need to update to the last downloaded version of In-Portal</p>";
  1851   break;
  1852   }
  1853  
  1854   $tmp_step = GetVar('next_step', true);
  1855  
  1856   if (!$tmp_step) {
  1857           $tmp_step = 1;
  1858   }
  1859  
  1860   if ( isset($got_license) && $got_license == 1) {
  1861           $tmp_step++;
  1862   }
  1863  
  1864   $next_step = $tmp_step + 1;
  1865  
  1866   if ($general_error != '') {
  1867           $state = '';
  1868           $title = '';
  1869           $help = '';
  1870           $general_error = $general_error.'<br /><br />Installation cannot continue!';
  1871   }
  1872  
  1873   if ($include_file == '' && $general_error == '' && $state == '') {
  1874           $state = '';
  1875           $title = '';
  1876           $help = '';
  1877       $filename = $pathtoroot.$admin."/install/inportal_remove.sql";
  1878       RunSQLFile($ado,$filename);
  1879           $general_error = 'Unexpected installation error! <br /><br />Installation has been stopped!';
  1880   }
  1881  
  1882   if ($restore_error != '') {
  1883           $next_step = 3;
  1884           $tmp_step = 2;
  1885   }
  1886  
  1887   if ($PassError != '') {
  1888           $tmp_step = 4;
  1889           $next_step = 5;
  1890   }
  1891  
  1892   if ($DomainError != '') {
  1893           $tmp_step--;
  1894           $next_step = $tmp_step + 1;
  1895   }
  1896  
  1897   if ($db_error != '') {
  1898           $tmp_step--;
  1899           $next_step = $tmp_step + 1;
  1900   }
  1901  
  1902   if ($state == "warning") {
  1903           $tmp_step--;
  1904           $next_step = $tmp_step + 1;
  1905   }
  1906  
  1907   if ($skip_step) {
  1908           $tmp_step++;
  1909           $next_step = $tmp_step + 1;
  1910   }
  1911   ?>
  1912  
  1913           <tr height="100%">
  1914                   <td valign="top">
  1915                           <table cellpadding=10 cellspacing=0 border=0 width="100%" height="100%">
  1916                                   <tr valign="top">
  1917                                           <td style="width: 200px; background: #009ff0 url(images/bg_install_menu.gif) no-repeat bottom right; border-right: 1px solid #000">
  1918                                       <img src="images/spacer.gif" width="180" height="1" border="0" title=""><br>
  1919                                       <span class="admintitle-white">Installation</span>
  1920                                       <!--<ol class="install">
  1921                                           <li class="current">Licence Verification
  1922                                           <li>Configuration
  1923                                           <li>File Permissions
  1924                                           <li>Security
  1925                                           <li>Integrity Check
  1926                                       </ol>
  1927                                           </td>-->
  1928                                       <?php
  1929                                       $lic_opt = isset($_POST['lic_opt']) ? $_POST['lic_opt'] : false;
  1930                                       if ($general_error == '') {
  1931                                       ?>
  1932                                               <?php if ($install_type == 1) { ?>
  1933                                                           <ol class="install">
  1934                                                           <li <?php if ($tmp_step == 1) { ?>class="current"<?php } ?>>Database Configuration
  1935                                                           <li <?php if ($tmp_step == 2 || $lic_opt == 1) { ?>class="current"<?php } ?>>Select License
  1936                                                           <li <?php if ($tmp_step == 3 && $lic_opt != 1) { ?>class="current"<?php } ?>>Select Domain
  1937                                                           <li <?php if ($tmp_step == 4 ) { ?>class="current"<?php } ?>>Set Root Password
  1938                                                           <li <?php if ($tmp_step == 5) { ?>class="current"<?php } ?>>Select Modules to Install
  1939                                                           <li <?php if ($tmp_step == 6) { ?>class="current"<?php } ?>>Install Language Packs
  1940                                                           <li <?php if ($tmp_step == 7) { ?>class="current"<?php } ?>>Post-Install Configuration
  1941                                                           <li <?php if ($tmp_step == 8) { ?>class="current"<?php } ?>>Finish
  1942                                                   </ol>
  1943                                               <?php } else if ($install_type == 2) { ?>
  1944                                                           <ol class="install">
  1945                                                           <li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
  1946                                                           <!--<li <?php if (($tmp_step == 2 && $login_error == '' && $inst_error == '') || $_POST['lic_opt'] == 1) { ?>class="current"<?php } ?>>Select License
  1947                                                           <li <?php if ($tmp_step == 3 && $_POST['lic_opt'] != 1) { ?>class="current"<?php } ?>>Select Domain
  1948                                                           <li <?php if ($tmp_step == 4) { ?>class="current"<?php } ?>>Set Root Password
  1949                                                           <li <?php if ($tmp_step == 5) { ?>class="current"<?php } ?>>Select Modules to Install
  1950                                                           <li <?php if ($tmp_step == 6) { ?>class="current"<?php } ?>>Install Language Packs
  1951                                                           <li <?php if ($tmp_step == 7) { ?>class="current"<?php } ?>>Post-Install Configuration
  1952                                                           <li <?php if ($tmp_step == 8) { ?>class="current"<?php } ?>>Finish-->
  1953                                                   </ol>
  1954                                               <?php } else if ($install_type == 3) { ?>
  1955                                                           <ol class="install">
  1956                                                                   <li>License Verification
  1957                                                           <li <?php if ($tmp_step == 2) { ?>class="current"<?php } ?>>Database Configuration
  1958                                                           <li <?php if ($tmp_step == 3 || $_POST['lic_opt'] == 1) { ?>class="current"<?php } ?>>Select License
  1959                                                           <li <?php if ($tmp_step == 4 && $_POST['lic_opt'] != 1) { ?>class="current"<?php } ?>>Select Domain
  1960                                                           <li <?php if ($tmp_step == 5) { ?>class="current"<?php } ?>>Set Root Password
  1961                                                           <li <?php if ($tmp_step == 6) { ?>class="current"<?php } ?>>Select Modules to Install
  1962                                                           <li <?php if ($tmp_step == 7) { ?>class="current"<?php } ?>>Install Language Packs
  1963                                                           <li <?php if ($tmp_step == 8) { ?>class="current"<?php } ?>>Post-Install Configuration
  1964                                                           <li <?php if ($tmp_step == 9) { ?>class="current"<?php } ?>>Finish
  1965                                                   </ol>
  1966                                               <?php } else if ($install_type == 4) { ?>
  1967                                                           <ol class="install">
  1968                                                           <li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
  1969                                                           <li <?php if (($tmp_step == 2 && $login_error == '' && $inst_error == '') || $lic_opt == 1) { ?>class="current"<?php } ?>>Select License
  1970                                                           <li <?php if ($tmp_step == 3 && $_POST['lic_opt'] != 1) { ?>class="current"<?php } ?>>Select Domain
  1971                                                           <li <?php if ($tmp_step == 4) { ?>class="current"<?php } ?>>Set Root Password
  1972                                                           <li <?php if ($tmp_step == 5) { ?>class="current"<?php } ?>>Select Modules to Install
  1973                                                           <li <?php if ($tmp_step == 6) { ?>class="current"<?php } ?>>Install Language Packs
  1974                                                           <li <?php if ($tmp_step == 7) { ?>class="current"<?php } ?>>Post-Install Configuration
  1975                                                           <li <?php if ($tmp_step == 8) { ?>class="current"<?php } ?>>Finish
  1976                                                   </ol>
  1977                                               <?php } else if ($install_type == 5) { ?>
  1978                                                           <ol class="install">
  1979                                                           <li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
  1980                                                           <li <?php if (($tmp_step == 2 && $login_error == '' && $inst_error == '') || $lic_opt == 1) { ?>class="current"<?php } ?>>Select License
  1981                                                           <li <?php if ($tmp_step == 3 && $lic_opt != 1) { ?>class="current"<?php } ?>>Select Domain
  1982                                                           <li <?php if ($tmp_step == 4) { ?>class="current"<?php } ?>>Finish
  1983                                                   </ol>
  1984                                               <?php } else if ($install_type == 6) { ?>
  1985                                                           <ol class="install">
  1986                                                           <li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
  1987                                                           <li <?php if (($tmp_step == 2 && $login_error == '' && $inst_error == '') || $_GET['show_prev'] == 1 || $_POST['backupdir']) { ?>class="current"<?php } ?>>Select Backup File
  1988                                                           <li <?php if ($tmp_step == 3 && $_POST['lic_opt'] != 1 && $_GET['show_prev'] != 1 && !$_POST['backupdir']) { ?>class="current"<?php } ?>>Finish
  1989                                                   </ol>
  1990                                               <?php } else if ($install_type == 7) { ?>
  1991                                                           <ol class="install">
  1992                                                           <li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
  1993                                                           <li <?php if ($tmp_step == 2 && $login_error == '' && $inst_error == '') { ?>class="current"<?php } ?>>Database Configuration
  1994                                                           <li <?php if ($tmp_step == 3) { ?>class="current"<?php } ?>>Finish
  1995                                                   </ol>
  1996                                               <?php } else if ($install_type == 8) { ?>
  1997                                                           <ol class="install">
  1998                                                           <li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
  1999                                                           <li <?php if ($tmp_step == 2 && $login_error == '' && $inst_error == '') { ?>class="current"<?php } ?>>Select Modules to Upgrade
  2000                                                           <li <?php if ($tmp_step == 3) { ?>class="current"<?php } ?>>Language Pack Upgrade
  2001                                                           <li <?php if ($tmp_step == 4) { ?>class="current"<?php } ?>>Finish
  2002                                                   </ol>
  2003                                               <?php } else if ($install_type == 9) { ?>
  2004                                                           <ol class="install">
  2005                                                           <li <?php if ($tmp_step == 1 || $login_error != '' || $inst_error != '') { ?>class="current"<?php } ?>>License Verification
  2006                                                           <li <?php if ($tmp_step == 2 && $login_error == '' && $inst_error == '') { ?>class="current"<?php } ?>>Fix Paths
  2007                                                           <li <?php if ($tmp_step == 3) { ?>class="current"<?php } ?>>Finish
  2008                                                   </ol>
  2009                                               <?php } ?>
  2010                                                   <?php include($include_file); ?>
  2011                                           <?php } else { ?>
  2012                                                   <?php include("install/general_error.php"); ?>
  2013                                           <?php } ?>
  2014                           <td width="40%" style="border-left: 1px solid #000; background: #f0f0f0">
  2015                                   <table width="100%" border="0" cellspacing="0" cellpadding="4">
  2016                                                                   <tr>
  2017                                                                     <td class="subsectiontitle" style="border-bottom: 1px solid #000000; background-color:#999"><?php if( isset($title) ) echo $title;?></td>
  2018                                                                   </tr>
  2019                                                                   <tr>
  2020                                                                     <td class="text"><?php if( isset($help) ) echo $help;?></td>
  2021                                                                   </tr>
  2022                                                               </table>
  2023                           </td>
  2024                       </tr>
  2025                     </table>
  2026                                                   <br>
  2027                                           </td>
  2028                                   </tr>
  2029                           </table>
  2030                   </td>
  2031           </tr>
  2032  
  2033           <tr>
  2034                   <td id="footer">
  2035                           Powered by In-portal &copy; 1997-2007, Intechnic Corporation. All rights reserved.
  2036                           <br><img src="images/spacer.gif" width="1" height="10" title="">
  2037                   </td>
  2038           </tr>
  2039   </table>
  2040   </form>
  2041  
  2042   </body>
  2043   </html>