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