<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2011 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Easyindex                     |
// +----------------------------------------------------------------------+
// | Authors: Aswin<aswin.j@armiasystems.com>             		  |
// +----------------------------------------------------------------------+
?>
<?php
error_reporting(0);
session_start();

function isValidUsername($str)
{
    if (trim($str) !="" ) {
          if ( eregi ( "[^0-9a-zA-Z+_]", $str ) ) {
                         return false;
             }else{
                    return true;
         }
    }else{
                return false;
    }

}
function splitsqlfile($sql, $delimiter)
{
    // Split up our string into "possible" SQL statements.
    $tokens = explode($delimiter, $sql);
    // try to save mem.
    $sql = "";
    $output = array();
    // we don't actually care about the matches preg gives us.
    $matches = array();
    // this is faster than calling count($oktens) every time thru the loop.
    $token_count = count($tokens);
    for ($i = 0; $i < $token_count; $i++) {
        // Don't wanna add an empty string as the last thing in the array.
        if (($i != ($token_count - 1)) || (strlen($tokens[$i] > 0))) {
            // This is the total number of single quotes in the token.
            $total_quotes = preg_match_all("/'/", $tokens[$i], $matches);
            // Counts single quotes that are preceded by an odd number of backslashes,
            // which means they're escaped quotes.
            $escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$i], $matches);

            $unescaped_quotes = $total_quotes - $escaped_quotes;
            // If the number of unescaped quotes is even, then the delimiter did NOT occur inside a string literal.
            if (($unescaped_quotes % 2) == 0) {
                // It's a complete sql statement.
                $output[] = $tokens[$i];
                // save memory.
                $tokens[$i] = "";
            } else {
                // incomplete sql statement. keep adding tokens until we have a complete one.
                // $temp will hold what we have so far.
                $temp = $tokens[$i] . $delimiter;
                // save memory..
                $tokens[$i] = "";
                // Do we have a complete statement yet?
                $complete_stmt = false;

                for ($j = $i + 1; (!$complete_stmt && ($j < $token_count)); $j++) {
                    // This is the total number of single quotes in the token.
                    $total_quotes = preg_match_all("/'/", $tokens[$j], $matches);
                    // Counts single quotes that are preceded by an odd number of backslashes,
                    // which means they're escaped quotes.
                    $escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$j], $matches);

                    $unescaped_quotes = $total_quotes - $escaped_quotes;

                    if (($unescaped_quotes % 2) == 1) {
                        // odd number of unescaped quotes. In combination with the previous incomplete
                        // statement(s), we now have a complete statement. (2 odds always make an even)
                        $output[] = $temp . $tokens[$j];
                        // save memory.
                        $tokens[$j] = "";
                        $temp = "";
                        // exit the loop.
                        $complete_stmt = true;
                        // make sure the outer loop continues at the right point.
                        $i = $j;
                    } else {
                        // even number of unescaped quotes. We still don't have a complete statement.
                        // (1 odd and 1 even always make an odd)
                        $temp .= $tokens[$j] . $delimiter;
                        // save memory.
                        $tokens[$j] = "";
                    }
                } // for..
            } // else
        }
    }
    return $output;
}
function isValidTableName($str)
{
    if (trim($str) != "") {
        if (eregi ("[^a-zA-Z+_]", $str)) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}
function isValidEmail($email)
{
    $email = trim($email);
    if ($email == "")
        return false;
//    if (!eregi("^" . "[a-z0-9]+([_\\.-][a-z0-9]+)*" . // user
//            "@" . "([a-z0-9]+([\.-][a-z0-9]+)*)+" . // domain
//            "\\.[a-z]{2,}" . // sld, tld
//            "$", $email, $regs)
//            ) {
    if (!preg_match("/^" . "[a-z0-9]+([_\\.-][a-z0-9]+)*" . // user
            "@" . "([a-z0-9]+([\.-][a-z0-9]+)*)+" . // domain
            "\\.[a-z]{2,}" . // sld, tld
            "$/i", $email, $regs)
            ) {
        return false;
    } else {
        return true;
    }
}
function isNotNull($value)
{
    if (is_array($value)) {
        if (sizeof($value) > 0) {
            return true;
        } else {
            return false;
        }
    } else {
        if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
            return true;
        } else {
            return false;
        }
    }
}

function isValidWebImageType($mimetype,$filename,$tempname)
{
	$blacklist = array("php", "phtml", "php3", "php4", "js", "shtml", "pl" ,"py", "exe");
	foreach ($blacklist as $file)
	{
		if(preg_match("/\.$file\$/i", "$filename"))
		{
			return false;
		}
	}
	//check if its image file
	if (!getimagesize($tempname))
	{
		return false;
	}

    if (($mimetype == "image/pjpeg") || ($mimetype == "image/jpeg") || ($mimetype == "image/x-png") || ($mimetype == "image/png") || ($mimetype == "image/gif") ||
            ($mimetype == "image/x-windows-bmp") || ($mimetype == "image/bmp")) {
        return true;
    } else {
        return false;
    }
}

function isValidWMImageType($mimetype,$filename,$tempname)
{
	$blacklist = array("php", "phtml", "php3", "php4", "js", "shtml", "pl" ,"py", "exe");
	foreach ($blacklist as $file)
	{
		if(preg_match("/\.$file\$/i", "$filename"))
		{
			return false;
		}
	}
	//check if its image file
	if (!getimagesize($tempname))
	{
		return false;
	}
	if ($mimetype == "image/gif") {
        return true;
    } else {
        return false;
    }
}

function getFilePermission($file){
	$perm = fileperms($file);
	if($perm === false){
		return "0000";
	}else{
		return substr(sprintf('%o', $perm), -4);
	}

}
function stripslashes_deep($value){
        $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
        return $value;
}
function getServerOS()
{
	return strtoupper(substr(PHP_OS, 0, 3));
}

//deprecated in php 5.3
//@set_magic_quotes_runtime(0);

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

function file_writable($file){
    $permission = substr(sprintf('%o', fileperms($file)), -4);
    if($permission == '0777' || $permission == '0666'){
        return true;
    }
    else{
        return false;
    }
}

$schemafile = "schema.sql";
//$schemafile_forum = "schema_forum.sql";
$datafile = "data.sql";
//$datafile_forum = "data_forum.sql";
$configfile = "../easyindex_config.php";

/*
 * check if application has been installed
 */
$configcontents = @fread(@fopen($configfile, 'r'), @filesize($configfile));
$pos = strpos($configcontents, "2.0.1");
if ($pos === false) {;
} else {
    header("Location: ../index");
}

$fullurl = $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if($_SERVER['HTTPS']=='on'){
	$http = "https://";
}else {
	$http = "http://";
}
$pos = strrpos($fullurl, "/");
if ($pos === false) { // note: three equal signs
    // not found...
} else {
    $fullurl = substr($fullurl, 0, $pos);
}

$installed = false;
$txtDBServerName        =       "localhost";
$txtTablePrefix		=	"EasyIndex_";

$settingsfile           =       "../config/settings.php";
$globalfile             =       "../config/globals.php";

$txtSiteURL             =       "http://".$fullurl;
$txtSecureSiteURL       =       "https://" . $fullurl;
$txtSiteURLt            =       "http://".$fullurl;
$txtSecureSiteURLt      =       "https://" . $fullurl;

/* *********************************check server configuration *****************************************************/

  $server_flag      = true;
  $server_warning   = true;

  $val1 = ini_get("safe_mode");
  $val2 = ini_get("file_uploads");
  $val3 = ini_get("open_basedir");

  $gd           = function_exists('gd_info');
  $curl         = function_exists('curl_init');
  $mysql        = function_exists('mysqli_connect');
  $exec         = strpos(ini_get("disable_functions"), "exec");

  $ffmpeg       = trim(@exec('which ffmpeg'));

  if(!empty($val1) || $val1==1){
      $server_flag = false;
  }
  elseif((empty($val2) || $val2 !=1)){
      $server_flag = false;
  }
  elseif((!empty($val3) || $val3==1)){
      $server_flag = false;
  }
  elseif(!$gd){
      $server_flag = false;
  }
  elseif(!$curl){
      $server_flag = false;
  }
  elseif(!$mysql){
      $server_flag = false;
  }
  elseif($exec){
      $server_warning = false;
  }
  elseif(empty($ffmpeg)){
      $server_warning = false;
  }

  $openbasedircheck =   "0" ;
  if($_POST["submittest"] == "Upload"){
        $uploadpath=substr($_FILES['testupload']['tmp_name'],0,strlen($_FILES['testupload']['tmp_name'])-strlen(basename($_FILES['testupload']['tmp_name']))-1);

        $val3=$val3.":"."  ";
        $openbasedirarray=explode(":",$val3);

        if(in_array($uploadpath,$openbasedirarray)){
           $openbasedircheck="1";
        }
        $_SESSION['sess_openbasedircheck']=$openbasedircheck;
  }


   $mysqlsupport=true;
   if (!function_exists('mysqli_connect')) {

        $mysqlsupport = false;
    }

  if(!$server_flag){
       $serverconfiguration =   "FAILURE";
  }else{
       $serverconfiguration =   "OK";
  }

/*--------------------Check server PHP configuration---------------------------*/
$sapi_type = php_sapi_name();
$chmodstatus = '000';
if (substr($sapi_type, 0, 3) == 'cgi'){
	$chmodstatus = '755';
        $write = 'WRITABLE';
}else{
    if(substr(@php_uname(s),0,7) == "Windows"){
	$chmodstatus = '000';
    }
    else{
	$chmodstatus = '777';
    }
    $write = 'UNWRITABLE';
}

$directories = array("/uploads/image/", "/uploads/video/", "/uploads/doc/", "/public/images/default/", "/config/settings.php", "/config/globals.php",
                     "/public/images/default/mainlogo.png", "/public/images/default/mainlogo_disp.png", "/public/images/default/mainbanner.gif", "/public/images/default/mainbanner_disp.gif", "/easyindex_config.php");

$perm_msg  = '';
$perm_flag = true;
$host_name = parse_url($_SERVER['HTTP_HOST']);

if($chmodstatus == '777'){
    if(isset($_POST["btnContinue"]) && !isset($_POST["auto_set"])){
        $txtFTPusername = $_POST['FTPusername'];
        $txtFTPpassword = $_POST['FTPpassword'];

        if(trim($txtFTPusername) == ''){
            $perm_msg .= '* Please enter FTP username <br/>';
        }
        if(trim($txtFTPpassword) == ''){
            $perm_msg .= '* Please enter FTP password <br/>';
        }
        else{
            $conn_id = @ftp_connect($host_name["path"]);
            $login_result = @ftp_login($conn_id, $txtFTPusername, $txtFTPpassword);
            if($login_result){
                $mode = 777;
                $np = '0'.$mode;

                $user_install = str_replace('/upgrade2.0', '', getcwd());

                //get the path staring from public_html
                $path_parts = explode('/public_html', $user_install);
                $user_install = '/public_html'.$path_parts[1];

                foreach($directories as $directory){
                    $edited_path = str_replace('..', '', $directory);
                    $directory = $user_install.$edited_path;
                    if($directory[strlen($directory) - 1] == '/'){
                        $directory  = substr($directory, 0, strlen($directory) - 1);
                    }
                    if(!@ftp_chmod($conn_id, eval("return({$np});"), $directory)){
                        $perm_flag = false;
                    }
                }

                if(!$perm_flag){
                    $perm_msg .= '* Sorry, an error occurred. Please try again or set the permissions manually <br/>';
                }
                else{
                    $perm_msg  = '<b>* File permissions successfuly set </b><br/>';
                }
            }
            else{
                $perm_msg .= '* Sorry, could not connect to the server. Please check the credentials <br/>';
            }
        }
    }
}
elseif($chmodstatus == '755'){
    //cgi handler requires 755 so no file permission change needed
}
elseif($chmodstatus == '000'){
    //ftp_chmod wont work on windows
}

/*-----------------------------------------------------------------------------*/

if($write == 'UNWRITABLE'){
    $imagedir                   = "../uploads/image/";
    $videodir                   = "../uploads/video/";
    $docdir                     = "../uploads/doc";
    $defaultdir 		= "../public/images/default/";
    $logo_file                  = "../public/images/default/mainlogo.png";
    $logo_tmb_file              = "../public/images/default/mainlogo_disp.png";
    $banner_file                = "../public/images/default/mainbanner.gif";
    $banner_tmb_file            = "../public/images/default/mainbanner_disp.gif";
    $settings_file              = "../config/settings.php";
    $globals_file               = "../config/globals.php";
    $config_file                = "../easyindex_config.php";
}//end if

$error = false;
$error_message = '';

//show alert only for non-cgi servers
if($chmodstatus == '777' || $chmodstatus == '000'){
    if(!file_writable($imagedir)){
        $error = true;
        $error_message .= " * Change the permission of 'uploads/image' folder to 777 <br>";
    }//end if

    if(!file_writable($videodir)){
        $error = true;
        $error_message .= " * Change the permission of 'uploads/video' folder to 777 <br>";
    }//end if

    if(!file_writable($docdir)){
        $error = true;
        $error_message .= " * Change the permission of 'uploads/doc' folder to 777 <br>";
    }//end if

    if(!file_writable($defaultdir)){
        $error = true;
        $error_message .= " * Change the permission of 'public/images/default' folder to 777 <br>";
    }//end if

    if(!file_writable($logo_file)){
        $error = true;
        $error_message .= " * Change the permission of 'public/images/default/mainlogo.png' to 777 <br>";
    }//end if

    if(!file_writable($logo_tmb_file)){
        $error = true;
        $error_message .= " * Change the permission of 'public/images/default/mainlogo_disp.png' to 777 <br>";
    }//end if

    if(!file_writable($banner_file)){
        $error = true;
        $error_message .= " * Change the permission of 'public/images/default/mainbanner.gif' to 777 <br>";
    }//end if

    if(!file_writable($banner_tmb_file)){
        $error = true;
        $error_message .= " * Change the permission of 'public/images/default/mainbanner_disp.gif' to 777 <br>";
    }//end if

    if(!file_writable($settings_file)){
        $error = true;
        $error_message .= " * Change the permission of 'config/settings.php' to 777 <br>";
    }//end if

    if(!file_writable($globals_file)){
        $error = true;
        $error_message .= " * Change the permission of 'config/globals.php' to 777 <br>";
    }//end if

    if(!file_writable($config_file)){
        $error = true;
        $error_message .= " * Change the permission of 'easyindex_config.php' to 777 <br>";
    }//end if
}

/*----------------------------------------------------------------------------------------------------------------*/
$message = "";

//include_once('../config.php');
include_once($settingsfile);
$database = MYSQL_USERNAME;
$databasePassword = MYSQL_PASSWORD;
$server =  MYSQL_HOST;
$databaseName = MYSQL_DB;
$sqlUser    = $database;
$sqlPass    = $databasePassword;
$sqlHost    = $server;
$sqlDB      = $databaseName;

$db_error = false;

$connection = @mysqli_connect($sqlHost, $sqlUser, $sqlPass);
if ($connection === false) {
    $error = true;
    $db_error = true;
    $message .= " * Connection Not Successful! Please verify your database details!<br>";
    $serverconfiguration    = "FAILURE";
} else {
    $dbselected = @mysqli_select_db($connection,$sqlDB);
    if (!$dbselected) {
        $error = true;
        $db_error = true;
        $message .= " * Database could not be selected! Please verify your database details!<br>";
        $serverconfiguration    = "FAILURE";
    }
}

if(!$db_error){
    //get the list of custom fields added
    $textTypeArray = array();
    $imtTypeArray = array();
/*
    $customfields_qry = mysqli_query("SELECT * FROM iscriptseitbl_productdesc") or die(mysqli_error($connection));
    if($customfields_qry){
        while($customfields_res = mysqli_fetch_array($customfields_qry)){
            switch($customfields_res['vInType']){
                case 'text':
                    $textTypeArray[] = $customfields_res['vFldname'];
                    break;
                case 'textarea':
                    $textTypeArray[] = $customfields_res['vFldname'];
                    break;
                case 'file-img/jpeg':
                    $imtTypeArray[] = $customfields_res['vFldname'];
                    break;
                default:
                    break;
            }
        }
    }
    */
}

$post_flag = false;

if ($_POST["btnContinue"] == "Upgrade" ) {
    $post_flag = true;
    /*
    $txtAdminEmail           = $_POST["txtAdminEmail"];
    $txtTablePrefix          = $_POST["txtTablePrefix"];
    $txtLicenseKey           = $_POST["txtLicenseKey"];
    $txtSiteName             = $_POST["txtSiteName"];

    if (!isNotNull($txtSiteName)) {
        $message .= " * Site Name is empty!" . "<br>";
        $error = true;
    }
    if (!isNotNull($txtAdminEmail)) {
        $message .= " * Admin Email is empty!" . "<br>";
        $error = true;
    } else {
        if (!isValidEmail($txtAdminEmail)) {
            $message .= " * Invalid Admin Email!" . "<br>";
            $error = true;
        }
    }
    
    */
    if ($error) {
        $message = "<u><b>Please correct the following errors to continue:</b></u>" . "<br><br>" . $message;
        // echo $message;
    }
    else{
        $fp = fopen($configfile, "w+");
        $configcontent = "<?php\n";
        $configcontent .= "define('INSTALLED', true); \n\n";
        $configcontent .= "define('VERSION', '2.0'); \n\n";
        $configcontent .= "ini_set('display_errors', '0'); \n\n";
        $configcontent .= "error_reporting(0); \n\n";
        $configcontent .= "define('VERSION', '2.0.1'); \n\n";
        $configcontent .= "\n?>";
        fwrite($fp, $configcontent);

        $fpp = fopen($settingsfile, "w+");
        $dbconfigcontent = "<?php\n";
        $dbconfigcontent .= '$s = empty('.'$_SERVER["HTTPS"]'.") ? '' : (".'$_SERVER["HTTPS"]'." == 'on') ? 's' : ''; \n\n";
        $dbconfigcontent .= '$protocol = substr(strtolower('.'$_SERVER["SERVER_PROTOCOL"]'."), 0, strpos(strtolower(".'$_SERVER["SERVER_PROTOCOL"]'.'), "/")) .$s . "://";'." \n\n";
        $dbconfigcontent .= 'define("PROTOCOL", $protocol);'." \n\n";
        $dbconfigcontent .= "define('MYSQL_HOST', '".$sqlHost."'); \n\n";
        $dbconfigcontent .= "define('MYSQL_USERNAME','". $sqlUser ."'); \n\n";
        $dbconfigcontent .= "define('MYSQL_PASSWORD',  '". $sqlPass ."'); \n\n";
        $dbconfigcontent .= "define('MYSQL_DB', '". $sqlDB ."'); \n\n";
        $dbconfigcontent .= "define('MYSQL_TABLE_PREFIX',  '". $txtTablePrefix ."'); \n\n";
        $dbconfigcontent .= "define('PAGE_LIST_COUNT', 5 ); \n\n";
        $dbconfigcontent .= "define('SANDBOX', 'no'); \n\n";
        $dbconfigcontent .= "define('USERNAME_LENGTH', '5'); \n\n";
        $dbconfigcontent .= "define('PASSWORD_LENGTH', '5'); \n\n";
        $dbconfigcontent .= "\n?>";
        echo $dbconfigcontent;
        fwrite($fpp, $dbconfigcontent);
        
       /*
        //STEP : 1 --> rename the tables
        mysqli_query("RENAME TABLE `iscriptseitbl_admin` TO `".$txtTablePrefix."admin`") or die(mysqli_error($connection));
        mysqli_query("RENAME TABLE `iscriptseitbl_users` TO `".$txtTablePrefix."users`") or die(mysqli_error($connection));
        mysqli_query("RENAME TABLE `iscriptseitbl_category` TO `".$txtTablePrefix."category`") or die(mysqli_error($connection));
        mysqli_query("RENAME TABLE `iscriptseitbl_product` TO `".$txtTablePrefix."product`") or die(mysqli_error($connection));
        
        
        //STEP : 4 --> rename the columns of product table add the new fields & update the table name
        $title_flag = $desc_flag = $img_flag = false;

        if(isset($_POST['title_placeholder']) && $_POST['title_placeholder'] <> 'NA'){
            mysqli_query("ALTER TABLE `".$txtTablePrefix."product` CHANGE `{$_POST['title_placeholder']}` `Title` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL") or die(mysqli_error($connection));
            $title_flag = true;
        }
        if(isset($_POST['desc_placeholder']) && $_POST['desc_placeholder'] <> 'NA'){
            mysqli_query("ALTER TABLE `".$txtTablePrefix."product` CHANGE `{$_POST['desc_placeholder']}` `Description` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL") or die(mysqli_error($connection));
            $desc_flag = true;
        }
        if(isset($_POST['img_placeholder']) && $_POST['img_placeholder'] <> 'NA'){
            mysqli_query("ALTER TABLE `".$txtTablePrefix."product` CHANGE `{$_POST['img_placeholder']}` `Image` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL") or die(mysqli_error($connection));
            $img_flag = true;
        }
        
        
        mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `nStatus` INT NOT NULL DEFAULT '0'");
        mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `nFeatured` INT NOT NULL DEFAULT '0'");
        mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `maxSearches` BIGINT NOT NULL");
        if(!$title_flag) mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `Title` TEXT NOT NULL");
        if(!$desc_flag) mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `Description` TEXT NOT NULL");
        if(!$img_flag) mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `Image` TEXT NOT NULL");
        mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `Video` TEXT NOT NULL");
        mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `VideoURL` TEXT NOT NULL");
        mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `Zipcode` TEXT NOT NULL");
        mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `Address` TEXT NOT NULL");
        mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `Country` VARCHAR( 250 ) NOT NULL");
        mysqli_query("ALTER TABLE `".$txtTablePrefix."product` ADD `Chart` TEXT NOT NULL");
        */

        $sqlquery = @fread(@fopen($schemafile, 'r'), @filesize($schemafile));
       	$sqlquery = preg_replace('/EasyIndex_/', $txtTablePrefix, $sqlquery);
        $sqlquery = splitsqlfile($sqlquery, ";");
        // creating the tables......................................
        for($i = 0; $i < sizeof($sqlquery); $i++) {
            mysqli_query($connection,$sqlquery[$i]);
        }
        /*
        $sqlquery = @fread(@fopen($schemafile_forum, 'r'), @filesize($schemafile_forum));
        $sqlquery = splitsqlfile($sqlquery, ";");
        // creating the tables......................................
        for($i = 0; $i < sizeof($sqlquery); $i++) {
            mysqli_query($sqlquery[$i], $connection);
        }
        */
        $dataquery = @fread(@fopen($datafile, 'r'), @filesize($datafile));
        $dataquery = preg_replace('/EasyIndex_/', $txtTablePrefix, $dataquery);
        $dataquery = splitsqlfile($dataquery, ";");
        // populating the tables with initial data......................................
        for($i = 0; $i < sizeof($dataquery); $i++) {
            mysqli_query($connection,$dataquery[$i]) or die(mysqli_error($connection));;
        }
        /*
        $dataquery = @fread(@fopen($datafile_forum, 'r'), @filesize($datafile_forum));
        $dataquery = splitsqlfile($dataquery, ";");
        // populating the tables with initial data......................................
        for($i = 0; $i < sizeof($dataquery); $i++) {
            mysqli_query($dataquery[$i], $connection);
        }

        $sqlsettings		=	"UPDATE ".$txtTablePrefix."settings SET value = '".addslashes($txtSiteName)."' WHERE settingfield ='siteName'";
        mysqli_query($sqlsettings) or die(mysqli_error($connection));
        $sqlsettings1		=	"UPDATE ".$txtTablePrefix."settings SET value = '".addslashes($txtAdminEmail)."' WHERE settingfield ='adminEmail'";
        mysqli_query($sqlsettings1) or die(mysqli_error($connection));
        $sqlsettings1		=	"UPDATE ".$txtTablePrefix."settings SET value = '".addslashes($txtLicenseKey)."' WHERE settingfield ='licenseKey'";
        mysqli_query($sqlsettings1) or die(mysqli_error($connection));
        $sqlsettings1		=	"UPDATE ".$txtTablePrefix."settings SET value = '".$txtSecureSiteURL."' WHERE settingfield ='secureURL'";
        mysqli_query($sqlsettings1) or die(mysqli_error($connection));
        $sqlsettings1		=	"UPDATE ".$txtTablePrefix."settings SET value = '$G_type_browsing' WHERE settingfield ='siteListingMode'";
        mysqli_query($sqlsettings1) or die(mysqli_error($connection));

        //forum
        $sqlsettings1		=	"UPDATE data SET adminEmail = '".addslashes($txtAdminEmail)."' WHERE defaultTheme ='easyOrange'";
        mysqli_query($sqlsettings1) or die(mysqli_error($connection));
        $sqlsettings1		=	"UPDATE data SET sitename = '".addslashes($txtSiteName)."' WHERE defaultTheme ='easyOrange'";
        mysqli_query($sqlsettings1) or die(mysqli_error($connection));
        $sqlsettings1		=	"UPDATE users SET password = '".$adminpassword."', email = '".addslashes($txtAdminEmail)."' WHERE username ='admin'";
        mysqli_query($sqlsettings1) or die(mysqli_error($connection));


        //---------------------------------------------------------------------------------------------------------------------------------------------------------------//

        //prevent script from getting timed out
        set_time_limit(0);

        
        //STEP : 2 --> insert the fields into productdesc table
        //$customfields_qry = mysqli_query("SELECT * FROM iscriptseitbl_productdesc ORDER BY id") or die(mysqli_error($connection));
        $customfields_qry = mysqli_query("SELECT * FROM iscriptseitbl_productdesc") or die(mysqli_error($connection));
        if($customfields_qry){            
            
            if(isset($_POST['title_placeholder'])) $objArray[] = $_POST['title_placeholder'];
            if(isset($_POST['desc_placeholder'])) $objArray[] = $_POST['desc_placeholder'];
            if(isset($_POST['img_placeholder'])) $objArray[] = $_POST['img_placeholder'];
            if(is_array($objArray)){
                while($customfields_res = mysqli_fetch_array($customfields_qry)){
                    if(!in_array($customfields_res['vFldname'], $objArray)){
                        mysqli_query("INSERT INTO ".$txtTablePrefix."productdesc VALUES('', '{$customfields_res['vFldname']}', '{$customfields_res['vFlddesc']}', '{$customfields_res['vFldType']}', '{$customfields_res['vFldSize']}', '{$customfields_res['vFldSearch']}', '{$customfields_res['vInType']}', '{$customfields_res['vlink']}', '0', '0', '0', '0')");
                    }


                    if($customfields_res['vInType'] == 'file-img/jpeg' || $customfields_res['vInType'] == 'file-doc/txt'){
                        $fieldArray[]       = $customfields_res['vFldname'];
                        $fieldTypeArray[]   = $customfields_res['vInType'];
                    }
                }
            }
            else{
                while($customfields_res = mysqli_fetch_array($customfields_qry)){
                    mysqli_query("INSERT INTO ".$txtTablePrefix."productdesc VALUES('', '{$customfields_res['vFldname']}', '{$customfields_res['vFlddesc']}', '{$customfields_res['vFldType']}', '{$customfields_res['vFldSize']}', '{$customfields_res['vFldSearch']}', '{$customfields_res['vInType']}', '{$customfields_res['vlink']}', '0', '0', '0', '0')");

                    if($customfields_res['vInType'] == 'file-img/jpeg' || $customfields_res['vInType'] == 'file-doc/txt'){
                        $fieldArray[]       = $customfields_res['vFldname'];
                        $fieldTypeArray[]   = $customfields_res['vInType'];
                    }
                }
            }
            
        }       


        //STEP : 3 --> alter current products table move images & files from pic folder to corresponding new folders
        if(is_array($fieldArray)){
            //print_r($fieldArray);

            include_once("../lib/resize.php");
            $fieldNames = implode(',', $fieldArray);
            $abs_path = str_replace('upgrade2.0', '', dirname(__FILE__));

            $customfields_qry = mysqli_query("SELECT  nBusId,{$fieldNames} FROM `".$txtTablePrefix."product`") or die(mysqli_error($connection));
            if($customfields_qry){
                while($customfields_res = mysqli_fetch_array($customfields_qry)){
                    foreach($fieldArray as $field_key => $fields){

                        $file_path          = $customfields_res[$fields];
                        $modified_file_path = str_replace('pics/', '', $file_path);

                        if(trim($modified_file_path) <> ''){

                            //echo "UPDATE iscriptseitbl_product SET $fields = '$modified_file_path' WHERE nBusId = {$customfields_res['nBusId']}"."<br/>";

                            //move the file to the new folder
                            switch($fieldTypeArray[$field_key]){
                                case 'file-img/jpeg':
                                    $dir_path = 'image';
                                    break;
                                case 'file-doc/txt':
                                    $dir_path = 'doc';
                                    break;
                                default:
                                    $dir_path = 'image';
                                    break;
                            }
                            copy($abs_path.'pics/'.$modified_file_path, $abs_path.'uploads/'.$dir_path.'/'.$modified_file_path);

                            if($fieldTypeArray[$field_key] == 'file-img/jpeg'){
                                $file_parts = explode(".", $modified_file_path);
                                $file_name = '';
                                foreach($file_parts as $parts){
                                    if($parts <> end($file_parts)){
                                        $file_name .= $parts.'.';
                                    }
                                }
                                $file_name_151 = $file_name."_151x151.".end($file_parts);
                                $file_name_302 = $file_name."_302x302.".end($file_parts);
                                $file_name_450 = $file_name."_450x450.".end($file_parts);

                                $resizeObj = new LibResize($abs_path.'uploads/'.$dir_path.'/'.$modified_file_path);
                                $resizeObj->resizeImage(151, 151, 'exact');
                                $resizeObj->saveImage($abs_path.'uploads/'.$dir_path.'/'.$file_name_151, 100);

                                $resizeObj = new LibResize($abs_path.'uploads/'.$dir_path.'/'.$modified_file_path);
                                $resizeObj->resizeImage(302, 302, 'exact');
                                $resizeObj->saveImage($abs_path.'uploads/'.$dir_path.'/'.$file_name_302, 100);

                                $resizeObj = new LibResize($abs_path.'uploads/'.$dir_path.'/'.$modified_file_path);
                                $resizeObj->resizeImage(450, 400, 'exact');
                                $resizeObj->saveImage($abs_path.'uploads/'.$dir_path.'/'.$file_name_450, 100);

                                //update the db entry
                                mysqli_query("UPDATE `".$txtTablePrefix."product` SET $fields = '$file_name_302' WHERE nBusId = {$customfields_res['nBusId']}");
                            }
                            else{
                                mysqli_query("UPDATE `".$txtTablePrefix."product` SET $fields = '$modified_file_path' WHERE nBusId = {$customfields_res['nBusId']}");
                            }

                        }

                    }
                }
            }
        }
        mysqli_query("DROP TABLE `iscriptseitbl_productdesc`") or die(mysqli_error($connection));
        
*/

//        mysqli_query("RENAME TABLE `iscriptseitbl_product` TO `".$txtTablePrefix."product`") or die(mysqli_error($connection));
        //---------------------------------------------------------------------------------------------------------------------------------------------------------------//


        
        /* -------------- /
        New code for install tracker, added by girish
        /------------------*/
        $string		= "";
        $pro		= urlencode("EasyIndex 2.1.0");
        $dom		= urlencode($txtSiteURL);
        $ipv		= urlencode($_SERVER['REMOTE_ADDR']);
        $mai		= urlencode($txtAdminEmail);
        $string		= "pro=$pro&dom=$dom&ipv=$ipv&mai=$mai";
        $contents	= "no";
        $file		= @fopen("http://www.iscripts.com/installtracker.php?$string", 'r');
        if ($file) {
                $contents = @fread($file, 8192);
        }
        /* -------------- /
        New code for install tracker, added by girish
        /------------------*/

        $installed = true;
    }
}

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
	case "text":
	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''";
	  break;
	case "long":
	case "int":
	  $theValue = ($theValue != "") ? intval($theValue) : "''";
	  break;
	case "double":
	  $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "''";
	  break;
	case "date":
	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''";
	  break;
	case "defined":
	  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
	  break;
  }
  return $theValue;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>EasyIndex Upgrader</title>
<link href="../public/styles/easyOrange/admin/admin_main.css" rel="stylesheet" type="text/css">
</head>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
    function divToggle(elem)
    {
        if($(elem).attr('checked')){
            $('#err_div').slideDown('slow');
        }
        else{
            $('#err_div').slideUp('slow');
        }
    }
</script>
<style type="text/css">
    .install_option {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt; color: #333333}
    .install_value_ok { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt; font-weight: bold; color: #009900 }
    .install_value_fail { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 7pt; font-weight: bold; color: #CC0000}
    .block_class{
    color:#F4700E;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-weight: bold;}
    .dropdwn_menu {
        border: 1px solid #CCCCCC;
        margin: 0;
        padding: 4px 5px;
        width: 52%;
    }
</style>
<body topmargin="0">
<div class="HeaderRow">
	<div class="HeaderContent sitewidth">


	<div class="installer_header_logo" align="left">
	<img src="../public/styles/easyOrange/images/installer_logo.png">
	</div>

		<div class="installer_header_right">
		<h4>Upgrader</h4>
		<!--items display area start -->
		<?php
		if(php_sapi_name() != 'apache2handler'){ ?>
		<div align="center" id="items_top_area">
		&nbsp;&nbsp;
		<a title="OnlineInstallationManual" href="#" onClick="window.open('<?php echo htmlentities($txtSiteURLt);?>/docs/Installation_Manual.pdf','OnlineInstallationManual','top=100,left=100,width=820,height=550,scrollbars=yes,toolbar=no,status=yrd');">Installation manual</a>
		| <a title="Readme" href="#" onClick="window.open('<?php echo htmlentities($txtSiteURLt);?>/docs/Readme.txt','Readme','top=100,left=100,width=820,height=550,scrollbars=yes,toolbar=no,status=yrd');">Readme</a> |
		<a title="If you have any difficulty, submit a ticket to the support department" href="#" onClick="window.open('http://www.iscripts.com/support/postticketbeforeregister.php','','top=100,left=100,width=820,height=550,scrollbars=yes,toolbar=no,status=yrd,resizable=yes');">
		Get Support</a>
		</div>
		<?php }else{ ?>
		<div align="center" id="items_top_area">
		&nbsp;&nbsp;
		<a title="OnlineInstallationManual" href="#" onClick="window.open('<?php echo htmlentities($txtSiteURL);?>/docs/Installation_Manual.pdf','OnlineInstallationManual','top=100,left=100,width=820,height=550,scrollbars=yes,toolbar=no,status=yrd');">Installation manual</a>
		| <a title="Readme" href="#" onClick="window.open('<?php echo htmlentities($txtSiteURL);?>/docs/Readme.txt','Readme','top=100,left=100,width=820,height=550,scrollbars=yes,toolbar=no,status=yrd');">Readme</a> |
		<a title="If you have any difficulty, submit a ticket to the support department" href="#" onClick="window.open('http://www.iscripts.com/support/postticketbeforeregister.php','','top=100,left=100,width=820,height=550,scrollbars=yes,toolbar=no,status=yrd,resizable=yes');">
		Get Support</a>
		</div>
		<?php } ?>
		</div>


<div class="clear"></div>
</div>
</div>

<!-- Content Area Starts -->
<div class="ContentRow">
	<div class="ContentMaincontainer sitewidth">


<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>

    <td width="76%" valign="top" height ="400">
	<!-- Here's where I want my views to be displayed -->
	<table width="80%" border="0" cellpadding="0" cellspacing="0" align="center">
	<tr>
		<td>
		<!--------Installer starts------------------------->
                            <?php
                            if ($serverconfiguration=="FAILURE")
                            {
                            ?>
                                            <table width="80%" border=0 align="center">
                                            <?php
                                            $ivo = "<span class='install_value_ok'>";
                                            $ivf = "<span class='install_value_fail'>";
                                            $sc = "</span>";
                                            echo "<tr><td class=maintext><b></b><br><br></td></tr>";
                                            echo "<tr><td class=maintext>Checking PHP Version... " . $ivo.PHP_VERSION.$sc . " ";
                                            if(version_compare(PHP_VERSION,"4.2.0") >=0 ) echo $ivo."".$sc; else {echo $ivf."(4.2.0 or higher required)".$sc; $fatal = true;}
                                            echo "</td></tr>";
                                            echo "<tr><td class=maintext>Checking System Information... " .$ivo. PHP_OS .$sc. "</td></tr>";
                                            echo "<tr><td class=maintext>Checking PHP Server API... " . $ivo. php_sapi_name().$sc . "</td></tr>";
                                            echo "<tr><td class=maintext>Checking Path to 'php.ini'... " . $ivo.PHP_CONFIG_FILE_PATH.$sc . "</td></tr>";
                                            $mysqlsupport=true;
                                            if (!function_exists('mysqli_connect')) {
                                                    $mysqlsupport = false;
                                            }
                                            echo "<tr><td class=maintext>Checking Mysql support... ";
                                            echo $ivo . (( $mysqlsupport) ? "On" : " $ivf This program requires MYSQL support. Please recompile your PHP with MYSQL Support.") . $sc;
                                            echo "</td></tr>";
                                            echo "<tr><td class=maintext>Checking safe_mode... ";
                                            $val1 = ini_get("safe_mode");
                                            echo  ((!empty($val1) || $val1==1) ? $ivf ."On-Please turn off safe_mode in the php.ini" : $ivo ."Off") . $sc;
                                            echo "</td></tr>";
                                            echo "<tr><td class=maintext>Checking file_uploads...";
                                            $val2 = ini_get("file_uploads");
                                            echo ((!empty($val2) || $val2==1) ? $ivo . "On" : $ivf . "Off - Please turn on file_uploads in the php.ini file").$sc;
                                            echo "</td></tr>";
                                            echo "<tr><td class=maintext>Checking open base directory...";
                                            $val3 = ini_get("open_basedir");
                                            echo ((!empty($val3) || $val3==1) ? $ivf . "On - $ivf Please upload a test file " : $ivo . "Off ") . $sc."</td></tr>";

                                            if((!empty($val3) || $val3==1)  and  (!empty($val2) || $val2==1) ){
                                                echo "<tr><td class=maintext>";
                                                    if($_POST["submittest"] == "Upload"){
                                                            $uploadpath=substr($_FILES['testupload']['tmp_name'],0,strlen($_FILES['testupload']['tmp_name'])-strlen(basename($_FILES['testupload']['tmp_name']))-1);
                                                            $uploadpatharray=explode("/",$uploadpath);
                                                            $openbasedirarray=explode(":",$val3);
                                                            $existflag=0;
                                                            $checkitem="";
                                                            for($i=1;$i<count($uploadpatharray);$i++){
                                                                    $checkitem=$checkitem."/".$uploadpatharray[$i];
                                                                    if(! in_array($checkitem,$openbasedirarray)  and ! in_array($checkitem."/",$openbasedirarray) ){
                                                                            ;
                                                                    }else{
                                                                            $existflag=1;
                                                                            break;
                                                                    }
                                                            }
                                                            if($existflag==1){
                                                                    $openbasedircheck="1";
                                                            }else{
                                                                    echo "<br>&nbsp;&nbsp;".$ivf."Please add '$uploadpath' in openbase directory entry of your configuration file.[contact your hosting provider]";
                                                            }
                                                            $_SESSION['sess_openbasedircheck']=$openbasedircheck;
                                                    }
                                                    if($openbasedircheck !="1"){
                                                    ?>
                                                            <form name=frmInstall method=post action="" enctype="multipart/form-data">
                                                                    file :&nbsp;
                                                            <input type=file name=testupload class=textbox>
                                                            <INPUT type="submit" name="submittest" value="Upload" class=button>
                                                            </form>
                                            <?php }
                                            echo "</td></tr>";
                                            }
                                            echo "<tr><td class=maintext>Checking CURL support... ";
                                            $val5 = function_exists('curl_init');
                                            if($val5){
                                                echo $ivo."On";
                                            }
                                            else{
                                                echo $ivf."Off-Please re-compile php with CURL support" . $sc;
                                            }
                                            echo "</td></tr>";
                                            echo "<tr><td class=maintext>Checking GD support... ";
                                            $val6 = function_exists('gd_info');
                                            if($val6){
                                                echo $ivo."On";
                                            }
                                            else{
                                                echo $ivf."Off-Please re-compile php with GD support" . $sc;
                                            }
                                            echo "</td></tr>";
                                            echo "<tr><td class=maintext>Checking EXEC function... ";
                                            $val7 = strpos(ini_get("disable_functions"), "exec");
                                            if(!$val7){
                                                echo $ivo."On";
                                            }
                                            else{
                                                echo $ivf."Off-Please enable EXEC funtion the php.ini if you wish to use the video section" . $sc;
                                            }
                                            echo "</td></tr>";
                                            echo "<tr><td class=maintext>Checking FFMPEG support... ";
                                            $val8 = trim(@exec('which ffmpeg'));
                                            if(!empty($val8)){
                                                echo $ivo."On";
                                            }
                                            else{
                                                echo $ivf."Off-Please re-compile php with FFMPEG support if you wish to use the video section" . $sc;
                                            }
                                            echo "</td></tr>";
                                            
                                            if($db_error){
                                                echo "<tr><td class=maintext>".$ivf.$message.$sc."</td></tr>";
                                            }

                                            echo "<tr><td class=maintext>".$ivf."Fatal errors detected.  Please correct the above red items and reload.</td></tr>";
                                            ?>
                                    </table>

                            <?php
                            } else if (!$installed ) {

                            ?>
                            <table width="80%" border="0" align="center">
                                <tr>
                                        <td align="center" ><b><font size="1">
                                                <div align="justify" >
                                                <br>
                                                <font color="#F4700E" size="+1">Thank you for choosing EasyIndex&nbsp;</font> <br><br>
                                                <font color="#000000" size="2"><img src="../img/dot.jpg">                                                    
                                                    To complete this upgradation please click on the upgrade button <!--enter the details below-->.</font>
                                                </div>

                                        </font></b>
                                        </td>
                                </tr>
                                <?php if($post_flag){ ?>
                                <tr>
                                        <td align=center class="message" >
                                                <div align="left" class="text_information">
                                                <br>
                                                <font color="#FF0000"><?php echo $message;?></font><br>
                                                <font color="#FF0000"><?php echo $error_message; ?></font><br>
                                                </div>
                                        </td>
                                </tr>
                                <?php } ?>
                                <tr>
                                        <td class=maintext align="left" >
                                        <br>
                                        <form name="frmInstall" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" enctype="multipart/form-data">
                                            <br>
                                          <!--   <FIELDSET>
                                            <LEGEND class='block_class'>File Permissions</LEGEND>
                                            <table width=85% border="0" cellpadding="2" cellspacing="2" class=maintext>
                                                    <tr>
                                                        <td colspan="2" align="left">
                                                            <b>
                                                            <?php if($chmodstatus == '777'){ ?>
                                                               iScripts EasyIndex requires that some of the folders have write permission. You can provide an FTP login so that this process is done automatically.<br/><br/>
                                                               For security reasons, it is best to create a separate FTP user account with access to the EasyIndex installation only and not the entire web server. Your host can assist you with this.
                                                               If you have difficulties completing installation without these credentials, please click "I would provide permissions manually" to do it yourself.<br/><br/>
                                                            <?php }elseif($chmodstatus == '000'){ ?>
                                                                iScripts EasyIndex requires that some of the folders have write permission. Please provide write permission for the following files :-<br/><br/>
                                                            <?php } elseif($chmodstatus == '755'){ ?>
                                                                iScripts EasyIndex requires that some of the folders have write permission.<br/><br/>
                                                            <?php } ?>
                                                            </b>
                                                        </td>
                                                    </tr>
                                                    <?php if($write == 'UNWRITABLE'){ ?>
                                                    <tr>
                                                            <td class=maintext align="left">FTP username</td>
                                                            <td width="61%" align=left>
                                                                    <input name="FTPusername"  id="FTPusername" type="text" size="50" value="<?php echo htmlentities($txtFTPusername);?>">
                                                            </td>
                                                    </tr>
                                                    <tr>
                                                            <td class=maintext align="left">FTP password</td>
                                                            <td width="61%" align=left>
                                                                    <input name="FTPpassword"  id="FTPpassword" type="password" size="50" value="<?php echo htmlentities($txtFTPpassword);?>">
                                                            </td>
                                                    </tr>
                                                    <?php if($chmodstatus == '777'){ ?>
                                                    <tr>
                                                        <td colspan="2" align="left">
                                                            <input type="checkbox" name="auto_set" id="auto_set" onclick="divToggle(this)" /> &nbsp; I would provide permissions manually
                                                        </td>
                                                    </tr>
                                                    <?php
                                                        }
                                                    }else{
                                                    ?>
                                                    <tr>
                                                        <td colspan="2" align="left">
                                                            <b>File permissions are OK.</b>
                                                        </td>
                                                    </tr>
                                                    <?php } ?>
                                            </table>
                                            <?php if($write == 'UNWRITABLE'){ ?>
                                            <div id="err_div" style="<?php if($chmodstatus == '777'){ ?>display:none<?php } ?>">
                                                        <fieldset>
                                                            <legend>Directories/Files List</legend>
                                                            <?php echo $error_message; ?>
                                                        </fieldset>
                                            </div>
                                            <?php } ?>
                                            </FIELDSET><br><br>
                                        <FIELDSET>
                                           
					<LEGEND class='block_class'>Database Details</LEGEND>
					<table width=85% border=0 cellpadding="2" cellspacing="2" class=maintext>
						<tr>
							<td colspan="2" class=maintext align="left">Table Prefix</td>
							<td width="61%" align=left>
								<input name="txtTablePrefix" class="installer_input"  id="txtTablePrefix" type="text"  maxlength="100" size="50" value="<?php echo htmlentities($txtTablePrefix);?>">
							</td>
						</tr>

					</table>
					</FIELDSET><br><br>
					<FIELDSET>
					<LEGEND class='block_class'>Site Details</LEGEND>
					<table width=85% border=0 cellpadding="2" cellspacing="2" class=maintext>
						<tr>
							<td colspan="2" class=maintext align="left">Site Name</td>
							<td width="61%" align=left>
								<input name="txtSiteName"  id="txtSiteName" type="text" maxlength="100" size="50" value="<?php echo htmlentities($txtSiteName);?>">
								<input name="txtSiteURL"  id="txtSiteURL" type="hidden" maxlength="100" value="<?php echo htmlentities($txtSiteURL);?>" readonly >
							</td>
						</tr>
						<tr>
							<td colspan="2" class=maintext align="left">License Key</td>
							<td width="61%" align=left>
								<input name="txtLicenseKey"  id="txtLicenseKey" type="text" maxlength="100" size="50" value="<?php echo htmlentities($txtLicenseKey);?>">
							</td>
						</tr>
					</table>
					</FIELDSET>
                                        <br>
                                        <br>
                                        <FIELDSET>
                                            <LEGEND class="block_class">Administration Details</LEGEND>
                                            <table width=85% border=0 cellpadding="2" cellspacing="2" class=maintext>
                                            <tr>
                                                    <td colspan="2" class=maintext  align="left">Admin Email</td>
                                                    <td width="61%" align=left>
                                                            <input name="txtAdminEmail"  id="txtAdminEmail" type="text"  maxlength="100" size="50" value="<?php echo htmlentities($txtAdminEmail);?>">
                                                    </td>
                                            </tr>
                                            </table>
                                        </FIELDSET>-->
                                        <?php if(!empty($textTypeArray) || !empty($imtTypeArray)){ ?>
                                        <br>
                                        <br>
                                        <FIELDSET>
                                            <LEGEND class="block_class">Upgrade Settings</LEGEND>
                                            <b>
                                                Please select the fields you would like to appear as the title, description & display image in your upgraded version of iScripts EasyIndex.<br/>
                                                Select 'Ignore' if you wish to add separate title, description or display image after upgrading.<br/><br/>
                                            </b>
                                            <table width=85% border=0 cellpadding="2" cellspacing="2" class="maintext">
                                            <tr>
                                                    <td colspan="2" class=maintext  align="left">Title</td>
                                                    <td width="61%" align=left>
                                                        <select name="title_placeholder" class="dropdwn_menu">
                                                            <option value="NA">Ignore</option>
                                                            <?php
                                                            if(!empty($textTypeArray)){
                                                                foreach($textTypeArray as $text){
                                                                    ?>
                                                                    <option value="<?php echo $text; ?>"><?php echo $text; ?></option>
                                                                    <?php
                                                                }
                                                            }
                                                            ?>
                                                        </select>
                                                    </td>
                                            </tr>
                                            <tr>
                                                    <td colspan="2" class=maintext  align="left">Description</td>
                                                    <td width="61%" align=left>
                                                        <select name="desc_placeholder" class="dropdwn_menu">
                                                            <option value="NA">Ignore</option>
                                                            <?php
                                                            if(!empty($textTypeArray)){
                                                                foreach($textTypeArray as $text){
                                                                    ?>
                                                                    <option value="<?php echo $text; ?>"><?php echo $text; ?></option>
                                                                    <?php
                                                                }
                                                            }
                                                            ?>
                                                        </select>
                                                    </td>
                                            </tr>
                                            <tr>
                                                    <td colspan="2" class=maintext  align="left">Image</td>
                                                    <td width="61%" align=left>
                                                        <select name="img_placeholder" class="dropdwn_menu">
                                                            <option value="NA">Ignore</option>
                                                            <?php
                                                            if(!empty($imtTypeArray)){
                                                                foreach($imtTypeArray as $img){
                                                                    ?>
                                                                    <option value="<?php echo $img; ?>"><?php echo $img; ?></option>
                                                                    <?php
                                                                }
                                                            }
                                                            ?>
                                                        </select>
                                                    </td>
                                            </tr>
                                            </table>
                                        </FIELDSET>
                                        <?php } ?>
                                            <br>
                                            <table width=85% border=0 cellpadding="2" cellspacing="2" class=maintext>
                                                    <tr><td>&nbsp;</td></tr>
                                                    <tr>
                                                            <td align="center">
                                                                    <input type="submit" name="btnContinue" value="Upgrade" class="btn_styles">
                                                            </td>
                                                    </tr>
                                            </table>
                                        </form>
                        </td>
                    </tr>
                </table>
                <?php
                }else{
                ?>
                <table width="80%" border="0" align="center">
		<tr>
			<td>
				<table width=85% border=0 cellpadding="2" cellspacing="2" class=maintext align="center">
					<br>
					<tr>
						<td align="center" class="maintext" >
							<font color="#F4700E" size="+1">Congratulations! The Installation Process was completed successfully!</font>
						</td>
					</tr>
					<tr>
						<td align="center" class="maintext" height="20" >&nbsp;</td>
					</tr>
					<?php
					$request_uri = explode('/',$_SERVER['REQUEST_URI']);
                                        $count =  count($request_uri);
                                        $count = $count - 3;
                                        $requestUri = '';
                                        for($i=1;$i<=$count;$i++) {
                                            $requestUri .= $request_uri[$i]."/";
                                        }
					$script_filename = explode('/',$_SERVER['SCRIPT_FILENAME']);
					/*$build_path = "http://".$_SERVER['HTTP_HOST']."/".$request_uri[1]."/admin/index/";
					$build_path_home = "http://".$_SERVER['HTTP_HOST']."/".$request_uri[1]."/index/";*/
                                        $build_path = "http://".$_SERVER['HTTP_HOST']."/".$requestUri."admin/index/";
					$build_path_home = "http://".$_SERVER['HTTP_HOST']."/".$requestUri."index/";
					?>
					<tr>
						<td align="center">
						<br>
						<fieldset>
						<legend class="block_class">Site Login Details</legend>
							<table cellpadding="0" cellspacing="0" width="80%" class="maintext" align="center">
								<tr>
									<td colspan="2">&nbsp;</td>
								</tr>
								<?php
								if(php_sapi_name() == 'apache2handler'){
									$apach	=	true;
								}else{
									$apach	=	false;
								}
								?>
									<tr>
										<td width="24%"><b><font size="-1">Admin URL&nbsp;:</font></b></td>
										<td width="76%"><a class="installer_link" style="cursor:pointer" href="<?php echo $build_path;?>"><?php echo $build_path;?>&nbsp;&nbsp;<img src="../public/styles/easyOrange/images/install_admin_link.png"></a></td>
									</tr>
									<tr>
										<td colspan="2">&nbsp;</td>
									</tr>
									<tr>
										<td colspan="2">&nbsp;</td>
									</tr>
									<tr>
										<td width="24%"><b><font size="-1">Home URL&nbsp;:</font></b></td>
										<td width="76%"><a class="installer_link" style="cursor:pointer" href="<?php echo $build_path_home;?>"><?php echo $build_path_home;?>&nbsp;&nbsp;<img src="../public/styles/easyOrange/images/install_home_link.png"></a></td>
									</tr>
															</table>
						</fieldset>
						</td>
					</tr>
                        <?php
                            echo "<tr><td class=maintext>";
                            $val7 = strpos(ini_get("disable_functions"), "exec");
                            if($val7){
                                echo "<span style='color:#FF0000; font-size:12px; font-weight:bold;'>Please enable EXEC funtion the php.ini if you wish to use the video section</span>";
                            }
                            echo "</td></tr>";
                            echo "<tr><td class=maintext>";
                            $val8 = trim(@exec('which ffmpeg'));
                            if(empty($val8)){
                                echo "<span style='color:#FF0000; font-size:12px; font-weight:bold;'>Please re-compile php with FFMPEG support if you wish to use the video section</span>";
                            }
                            echo "</td></tr>";
                        ?>
					<tr>
						<td align="center" class="maintext" height="20" >&nbsp;</td>
					</tr>
				</table>
			</td>
		</tr>
                </table>
                <?php

	}

	?>
	</td>
	</tr>
	</table>
      </td>
  </tr>
</table>

</div>
</div>


<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="10">
      <tr>
        <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="3">
              <tr>
                <td height="43" class="bigfont1" align="center"><div align="center" class="copyright"><!-- footr links comes here --></div></td>
              </tr>
            </table>
</td>
          </tr>
        </table></td>
      </tr>
    </table>
      </td>
  </tr>
</table>
</body>
</html>