Location: PHPKode > projects > MJGUEST > mjguest/setup/SetupUtility.php
<?php

ob_start();

set_magic_quotes_runtime(0);
@ini_set('magic_quotes_sybase',	false);
ignore_user_abort(true);
session_start();
@register_shutdown_function('session_write_close');

function remove_magic_quotes_gpc($value)
{
	if (get_magic_quotes_gpc())
		$value
		= is_array($value)
		? array_map('remove_magic_quotes_gpc', $value)
		: stripslashes($value)
		;
	
	return $value;
}

if ($_POST)	$_POST	= remove_magic_quotes_gpc($_POST);
if ($_GET)	$_GET	= remove_magic_quotes_gpc($_GET);

function autowrite()
{
	@chmod(SETUPFILE.'-temp', 0666);
	@chmod(SETUPFILE.'-temp', 0777);
	$f = @fopen(SETUPFILE.'-temp','wb');
	$res = ($f ? 1 : 0);
	@fclose($f);
	@unlink(SETUPFILE.'-temp');
	@chmod(SETUPFILE.'-temp', 0644);
	return $res;
}

define('NL',"\r\n");

// Email via PHP
function email($to, $subject, $msg) 
{
	@ini_set('SMTP','smtp.blu.it'); #PHP5: self::SMTP
	
	$headers
	= 'MIME-Version: 1.0'.NL #PHP5: self::NL
	. 'From: "MJGUEST"'.NL
	. 'To: '.$to.NL
	. 'X-Mailer: PHP'.NL
	. 'X-Priority: 1'.NL.NL
	;
	
	$bad_headers = array('/content-type:/', '/to:/', '/cc:/', '/bcc:/', '/\r/', '/\n/', '/%0a/', '/%0d/');
	
	return @mail($to, $subject, preg_replace($bad_headers, '', $msg), $headers);
}

define('mjguest_versionid', '6.8');

define('mjguest_basedir', '../');
define('DB_DIR', '../database/');
define('SETUPFILE', '../setup.ini.php'); // se cambia, modifica anche setup_generator.
$V_SETUP_EQ = '6.8'; // In generale, setupfile è identico dalla versione:... #tolto mjguest_installed, ma non fare upgrade (non necessario)
define('PHP_WIN_REQUIRED','4.3.3');
define('PHP_NIX_REQUIRED','4.3.3');
define('AGREEMENT', 'agreement.txt');
define('IMG_WRONG', '<img src="wrong.gif" />');
define('IMG_RIGHT', '<img src="correct.gif" />');

if (empty($_GET['step']))
{
	$_SESSION = array();
	$__STEP = 0;
} else $__STEP = $_GET['step'];

$__BACK		= 0;
$__NEXT		= 1;
$__FINISH	= 0;

$_SESSION['PHP5'] = @version_compare('5', PHP_VERSION, '<');

$DIR_ROOT = dirname(!empty($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : $_SERVER['PHP_SELF']);
$DIR_ROOT = substr($DIR_ROOT, 0, strrpos($DIR_ROOT, '/')).'/';

$mjguest_installed = file_exists(SETUPFILE) ? true : false;

if( ( $__STEP >= 1 ) and (@$_SESSION['okpass'] != 1 and !@isset($_POST['adminpass']) and $mjguest_installed and @$_SESSION['ACTION'] and @$_SESSION['ACTION'] != 'install'))
{
	ob_clean();
	print('Hacking attempt');
	ob_end_flush();
	exit;
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html dir="ltr">
<head>
<meta name="author" content="www.mdsjack.bo.it" />
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="cache-control" content="private" />
<meta name="robots" content="noindex,nofollow" />
<title>MJGUEST Setup Utility &copy; www.mdsjack.bo.it</title>
<style type="text/css">
* {	font-family: Tahoma, MS sans serif, Arial, Helvetica, sans-serif; font-size: 11px; }
body { overflow: auto; margin: 0px; padding: 0px; background-color: buttonface; }
p { margin: 0px; padding-top: 5px; padding-bottom: 5px; }
form { margin: 0px; }
strong { font-weight: bold; }
small { font-size: 90%; }
code {font-family: Courier New, Courier, monospace; font-size: 11px;}
div#header { margin: 0px; height: 60px; background-color: #ffffff; background-image: url('header.gif'); background-repeat: no-repeat; background-position: top right; border-width: 0px; border-bottom: 1px solid #ACA899; }
p { line-height: 150%; }
p#title { margin: 0px; padding-left: 25px; padding-top: 8px; text-indent: -10px; line-height: 100%; }
div#container { height: 396px; border-top: 1px solid #ffffff; border-bottom: 1px solid #ACA899; }
div#content { padding: 10px 30px 0px 30px; }
div#footer { height: 40px; border-top: 1px solid #ffffff; text-align: right; padding: 0px 10px 0px 0px; }
input.button { width: 85px; height: 20px; margin-top: 10px; }
tr { height: 60px; }
table.report { margin: 10px; width: 90%; }
td.rep_icon { width: 5%; text-align: center; vertical-align: top; }
td.rep_desc { width: 95%; text-align: left; vertical-align: top; }
button.install_icon { position:relative; float: left; width: 70px; height: 54px; margin-right: 10px; cursor:pointer; }
p.install_icon { height: 54px; }
fieldset { padding: 5px; border-color: white !important; border: 2px groove transparent; }
legend { margin-bottom: 0px; }
#agreement { width: 98%; height: 230px; }
input.radio { margin: 2px 5px 2px 0px; vertical-align: bottom !important; vertical-align: middle; }
ul { margin-left: 0px !important; margin: 10px 10px 0px 20px; }
select.usages, select.usages optgroup, select.usages option {font: 12px Arial, Helvetica, sans-serif; }
select.usages optgroup { font-style: italic; font-weight: bold; background: #606060; color: #f1f1f1; }
select.usages option { background: white; color: black; }
select.usages option.novice { background:#C8F7C8; }
select.usages option.medium { background:#FFEB80; }
select.usages option.expert { background:#FFD0BD; }
textarea.usage_code {overflow:auto; width:98%; height: 45px; font-family: Courier New, Courier, monospace; color:gray; cursor:pointer; }
</style>
<script type="text/javascript">

function button(which){ document.getElementById('IEact').value = which }
function on_off(button, active){ document.getElementById(button).disabled = !active }

var currentusage = 'usage_simplelink';
function showusage(which)
{
	if (!which.options[which.selectedIndex].value)
	{
		document.getElementById(currentusage).style.display = 'none';
		return false;
	}
	
	else which = which.options[which.selectedIndex].value;
	
	document.getElementById(currentusage).style.display = 'none';
	document.getElementById(which).style.display = '';
	currentusage = which;
}

function setup_gen()
{
	location.href='setup_generator.php';
	document.getElementById('goinst').style.display='';
	document.forms[0].action='?step=5&<?php echo SID?>';
	on_off('proceed',1);
}

function ask_remove_reason()
{
	document.getElementById('remove_reason').value = window.prompt('Customer Survey:\nI am uninstalling because... (briefly explain your wishes/expectations)','');
}

function sqlitepath(select, hint)
{
	document.getElementById('db_host').value
	= ((select.options[select.selectedIndex].value == 'sqlite2') || (select.options[select.selectedIndex].value == 'sqlite') || (select.options[select.selectedIndex].value == 'xml'))
	? hint
	: ''
}

</script>
<script type="text/javascript" charset="utf-8" src="<?php echo mjguest_basedir ?>interface/scripts/md5.js"></script>
</head>
<body>
<!--

  SetupUtility
  ====================================
  Official website: www.mdsjack.bo.it

-->
<form method="post" action="<?php echo basename($_SERVER['PHP_SELF'])?>?step=<?php echo ($__STEP+1)?>">

<div id="header"><p id="title"><strong>Setup Utility</strong><br /><br /><small>MJGUEST ver. <?php echo mjguest_versionid ?></small></p></div>
<div id="container">
<div id="content">
<noscript><span style="font-weight:bold;color: crimson">Please enable Javascript and refresh the page to run the installer properly!</span><br /></noscript>
<?php

SWITCH($__STEP):

CASE 0:

$__NEXT = 0;
$__NOHOME = 1;
$__FINISH = 1;

if($mjguest_installed):
	include_once SETUPFILE;
?>
	<fieldset><legend>Administrator Password</legend>
		<input type="password" name="adminpass" id="adminpass" value="" onfocus="this.value=''" onchange="this.value=md5(this.value)" />
		&nbsp;For safety reasons, please type your password. Default is &quot;password&quot;.
	</fieldset>
<?php endif ?>
	<br>
	<button type="submit" name="act" value="install" onclick="button('install')" tabindex="2" class="install_icon" <?php echo ($mjguest_installed ? 'disabled="disabled"' : '')?>>
		<img src="install.gif" alt="install" />
	</button>
	<p class="install_icon" <?php echo ($mjguest_installed ? 'disabled="disabled"' : '')?>>
		<strong>Install the application</strong>
		<br />Perform a new installation.
	</p>
	
	<button type="submit" name="act" value="upgrade" onclick="button('upgrade')" tabindex="4" class="install_icon" <?php echo (!$mjguest_installed ? 'disabled="disabled"' : '')?>>
		<img src="upgrade.gif" alt="upgrade" />
	</button>
	<p class="install_icon" <?php echo (!$mjguest_installed ? 'disabled="disabled"' : '')?>>
		<strong>Upgrade from version</strong>
		<select tabindex="3" name="upgrd_from" <?php echo (!$mjguest_installed ? 'disabled="disabled"' : '')?>>
			<option value="6.7">6.7</option>
			<option value="6.6">6.6</option>
			<?php if (db_type != 'xmldom'): ?>
			<option value="6.5">6.5</option>
			<option value="6.4">6.4</option>
			<?php endif; if (/*db_type != 'sqlite3' and */db_type != 'xmldom'): ?>
			<option value="6.3">6.3</option>
			<?php if (db_type != 'sqlite2' and db_type != 'pgsql8'): ?>
			<option value="6.2">6.2</option>
			<option value="6.1">6.1</option>
			<option value="6.0">6.0</option>
			<option value="5.0">5.0</option>
			<?php endif; endif; ?>
		</select>
		<br />Please select the version you currently have, before proceeding.
		<br />Note: after upgrading once to a same version, further attempts will fail.
	</p>
	<button type="submit" name="act" value="usage" onclick="button('usage')" tabindex="5" class="install_icon" <?php echo ($mjguest_installed ? '' : 'disabled="disabled"')?>>
		<img src="usage.gif" alt="remove" />
	</button>
	<p class="install_icon" <?php echo ($mjguest_installed ? '' : 'disabled="disabled"')?>>
		<strong>Usage tutorials</strong>
		<br />Show me how to open the guestbook from my web site.
		<br />
	</p>
	<button type="submit" name="act" value="pass_reminder" onclick="button('pass_reminder')" tabindex="5" class="install_icon" <?php echo ($mjguest_installed ? '' : 'disabled="disabled"')?>>
		<img src="key.gif" alt="remove" />
	</button>
	<p class="install_icon" <?php echo ($mjguest_installed ? '' : 'disabled="disabled"')?>>
		<strong>Password reminder</strong>
		<br />Administrator and Moderator will receive an e-mail with a password reminder.
		<br />
	</p>
	<button type="submit" name="act" value="remove" onclick="if(confirm('This operation will delete all your guestbook entries!\nProceed?')){ask_remove_reason(); button('remove'); return true;} else { return false; }" tabindex="6" class="install_icon" <?php echo ($mjguest_installed ? '' : 'disabled="disabled"')?>>
		<img src="remove.gif" alt="remove" />
	</button>
	<p class="install_icon" <?php echo ($mjguest_installed ? '' : 'disabled="disabled"')?>>
		<strong>Remove the application</strong>
		<br />Clean my database.
		<input type="hidden" name="remove_reason" id="remove_reason" />
	</p>
	<!--[if IE]>
	<input type="hidden" name="act" id="IEact" value="" />
	<![endif]-->

<?php
BREAK;

CASE 1:

$__BACK = 1;
$__NEXT = 0;

if (empty($_POST['act']) and empty($_SESSION['ACTION'])):
?>
	<div align="center">
		<p>Please choose what you would like to do by clicking on the big buttons.</p>
		<p>Press &quot;Back&quot; and retry.</p>
	</div>
<?php
	BREAK;
endif;

if (empty($_SESSION['ACTION'])) $_SESSION['ACTION'] = $_POST['act'];
if (empty($_SESSION['upgrd_from']) and $_SESSION['ACTION'] == 'upgrade') $_SESSION['upgrd_from'] = $_POST['upgrd_from'];

if($mjguest_installed and !@$_SESSION['okpass'] and $_SESSION['ACTION'] != 'usage' and $_SESSION['ACTION'] != 'pass_reminder')
{
	// Stesso codice che in UPGRADE, serve per adattare i vecchi parametri di setup alla verifica password
	
	if(file_exists(mjguest_basedir.'_files/setup.ini.php')) // Upgrade da 5.0
	{
		require_once mjguest_basedir.'_files/setup.ini.php';
		
		define('db_type', 'mysql3');
		define('db_host', $db_host);
		define('db_port', '');
		define('db_user', $db_user);
		define('db_pass', $db_pass);
		define('db_name', $db_name);
		define('db_flag', 'mjguest_');
	}
	else // Upgrade da 6.x...
		require_once SETUPFILE;
	
	if(!defined('db_type')) // ...Upgrade da 6.0 (era setup_db_type)
	{
		function retrocomp_db_type(){
			switch (setup_db_type){
				case 'mysql':	return 'mysql3'; break;
				case 'mysqli':	return 'mysql'; break;
				default: return setup_db_type;
			}
		}
		
		define('db_type', retrocomp_db_type());
		define('db_host', setup_db_host);
		define('db_port', setup_db_port);
		define('db_user', setup_db_user);
		define('db_pass', setup_db_pass);
		define('db_name', setup_db_name);
		define('db_flag', 'mjguest_');
	}
	else // ELSE ...Upgrade da 6.7 (setupfile nei parametri DB è uguale)
	{
		switch (db_type)
		{
			case 'mysql3':
				$new_db_type = 'mysql3';
			break;
			case 'mysql4':
				$new_db_type = 'mysql';
			break;
			case 'pgsql8':
				$new_db_type = 'pgsql';
			break;
			case 'sqlite2':
				$new_db_type = extension_loaded('pdo_sqlite') ? 'sqlite' : 'sqlite2';
			break;
			case 'xmldom':
				$new_db_type = 'xml';
			break;
		}
	}
	
	$db_type = !empty($new_db_type) ? $new_db_type : db_type;
	
	if (extension_loaded('pdo_'.$db_type))
	{
		require_once DB_DIR.'pdo.php';
		require_once DB_DIR.$db_type.'/driver_pdo.php';
	}
	else require_once DB_DIR.$db_type.'/driver.php';
	
	$db = &new db_driver(mjguest_basedir);
	$db->query('SELECT adminpass FROM '.$db->tables['[TBL=settings]']);
	
	if($_POST['adminpass'] !== md5($db->get_field())):
		$_SESSION['okpass'] = 0;
?>
	<p align="center" style="color: crimson"><strong>Administrator password is incorrect!</strong>
		<br />Please press &quot;Back&quot; and type your password before clicking on any button.
	</p>
	<p align="center">First of all, check if UPPER CASE is off. Password is case sensitive.
		<br>Secondly, if you have just installed the guestbook, remember the default password is &quot;password&quot;.
	</p>
<?php
		BREAK;
	else:
		$_SESSION['okpass'] = 1;
	endif;
	
	unset($db);
}

if($_SESSION['ACTION'] == 'usage')
{
?>
	<fieldset style="width:auto"><legend>Usage Tutuorials</legend>
	<div align="center">
		<p>Choose the appropriate usage for your kind of web site and according to your skills.
		<br>(in each group, options are ordered by difficulty. Color -if available- indicates diffculty)</p>
		
		<select onchange="showusage(this)" class="usages" style="">
			<option></option>
			<optgroup label="Stand-alone, Frame or iFrame">
				<option value="usage_simplelink" class="novice"> I'm a beginner... I just want to put the script in a clean page </option>
				<option value="usage_iframe" class="novice"> I want the script to show up in a dedicated iFrame inside my page </option>
				<option value="usage_frame" class="medium"> I have a page with frames. I want the script to open in one of them </option>
			</optgroup>
			<optgroup label="PopUp window">
				<!--option value="usage_simple" class="novice"> I want to open the script in a popup, from a simple text link </option-->
				<option value="usage_normal" class="novice"> I want to open the popup from an HTML link </option>
				<option value="usage_flash" class="expert"> I have a Flash&trade; website. I want to open the popup via ActionScript button </option>
			</optgroup>
			<optgroup label="Embedded via PHP">
				<option value="usage_include" class="expert"> I want to integrate the script via PHP to fit my layout and graphics </option>
			</optgroup>
		</select>
		</p>
		
		<div id="usage_simplelink" style="position:relative;display:none">
		<p>To open the guestbook from any page of your website, use the following link:</p>
		<p><textarea onfocus="this.select()" class="usage_code"
		readonly="readonly">&lt;a href="<?php echo $DIR_ROOT?>mjguest.php" target="_self"&gt;My Guestbook&lt;/a&gt;
</textarea>
		</p>
		<p>You can replace &quot;<code>My Guestbook</code>&quot; with a different text.</p>
		</div>
		
		<div id="usage_iframe" style="position:relative;display:none">
		<p>Place this code inside your web page, wherever you want the guestbook to show up:</p>
		<p><textarea onfocus="this.select()" class="usage_code"
		readonly="readonly">&lt;iframe name="mjguest" src="<?php echo $DIR_ROOT?>mjguest.php" height="580" width="570" scrolling="no" frameborder="0"&gt;&lt;!--// www.mdsjack.bo.it //--&gt;&lt;/iframe&gt;
</textarea>
		</p>
		</div>
		
		<div id="usage_frame" style="position:relative;display:none">
		<p>If using frames, take the code below and tweak it to suit your needs:</p>
		<p><textarea onfocus="this.select()" class="usage_code"
		readonly="readonly">&lt;frame name="mjguest" src="<?php echo $DIR_ROOT?>mjguest.php" /&gt;
</textarea>
		</p>
		</div>
		<!--
		<div id="usage_simple" style="position:relative;display:none">
		<p>To open the guestbook from any page of your website,<br />place the code below inside the HTML code of your web page.</p>
		<p><textarea onfocus="this.select()" class="usage_code"
		readonly="readonly">&lt;script type="text/javascript" src="<?php echo $DIR_ROOT?>guestbook.js.php?link=My Guestbook"&gt;&lt;!--// www.mdsjack.bo.it //--&gt;&lt;/script&gt;
&lt;noscript&gt&lt;a href="<?php echo $DIR_ROOT?>mjguest.php" target="_blank"&gt;My Guestbook&lt;/a&gt;&lt;/noscript&gt</textarea>
		</p>
		<p>This code will dynamically create a text <code>&lt;a&gt;</code> link.</p>
		<p>You can replace &quot;<code>My Guestbook</code>&quot; with a different text.</p>
		</div>
		-->
		<div id="usage_normal" style="position:relative;display:none">
		<p>To open the guestbook from any page of your website,<br />place the code below inside the HTML code of your web page.</p>
		<p>The HTML link is detached from the Javascript, so you can add your own CSS definitions.</p>
		<p><textarea onfocus="this.select()" class="usage_code" readonly="readonly">&lt;script type="text/javascript" src="<?php echo $DIR_ROOT?>guestbook.js.php"&gt;&lt;!--// www.mdsjack.bo.it //--&gt;&lt;/script&gt;
&lt;a href="<?php echo $DIR_ROOT?>mjguest.php" target="_blank" onclick="return guestbook()"&gt;My Guestbook&lt;/a&gt;
</textarea>
		</p>
		<p>You can replace &quot;<code>My Guestbook</code>&quot; with something else (an image, too). </p>
		</div>

		<div id="usage_flash" style="position:relative;display:none">
		<p>Place this code inside the page containing the your SWF interface:</p>
		<textarea onfocus="this.select()" class="usage_code" readonly="readonly">&lt;script type="text/javascript" src="<?php echo $DIR_ROOT?>guestbook.js.php"&gt;&lt;!--// www.mdsjack.bo.it //--&gt;&lt;/script&gt;
</textarea>
		<p>Then, to open the guestbook from a Flash button, use the ActionScript link below: </p>
		<p><textarea onfocus="this.select()" class="usage_code" readonly="readonly">on(release){
	getURL("javascript:guestbook(true)");
}
</textarea>
		</p>
		</div>

		<div id="usage_include" style="position:relative;display:none">
		<p>(1) If you guestbook web page has a &quot;.htm&quot; extension, rename it to &quot;.php&quot;.</p>
		<p>(2) Insert this code at the <u>very beginning</u> of your website header (it may be in an included file):
		<br /><textarea onfocus="this.select()" class="usage_code" readonly="readonly">&lt;?php ob_start(); $mjguest_embedded_iso = 1; if($mjguest_embedded_iso){function ob_utf8_encode($buffer){return utf8_encode($buffer);}ob_start('ob_utf8_encode');} ?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
</textarea><br/>(3) If your web pages are UTF-8 encoded, set &quot;<code>mjguest_embedded_iso</code>&quot; to &quot;<code>0</code>&quot;</p>
		<p>(4) Then, paste this code in your guestbook page, exactly where you want to include the script:<br />
		<textarea onfocus="this.select()" class="usage_code" readonly="readonly">&lt;?php define('mjguest_basedir', 'PATH_TO_MJGUEST/'); include(mjguest_basedir.'mjguest.php') ?&gt;
</textarea><br />(5) Replace &quot;<code>PATH_TO_MJGUEST</code>&quot; with the folder path from your web page is located (not the URL!).</p>
		<p>(6) Now, to edit the layout, the active CSS file is &quot;<code>style_embedded.css</code>&quot; in theme folder.</p>
		<!--
		<p style="text-align: left"><b>When the guestbook is embedded:</b>
		<br />- The page where the script is included should be UTF-8 encoded
		<br />- The active CSS file to edit is &quot;<code>style_embedded.css</code>&quot; in theme folder
		</p>
		-->
		</div>

	</div>
	</fieldset>
<?php
	$__FINISH = 1;
	BREAK;
}


if($_SESSION['ACTION'] == 'pass_reminder')
{
	// Stesso codice che in UPGRADE, serve per adattare i vecchi parametri di setup alla verifica password
	
	if(file_exists(mjguest_basedir.'_files/setup.ini.php')) // Upgrade da 5.0
	{
		require_once mjguest_basedir.'_files/setup.ini.php';
		
		define('db_type', 'mysql3');
		define('db_host', $db_host);
		define('db_port', '');
		define('db_user', $db_user);
		define('db_pass', $db_pass);
		define('db_name', $db_name);
		define('db_flag', 'mjguest_');
	}
	else // Upgrade da 6.x...
		require_once SETUPFILE;
	
	if(!defined('db_type')) // ...Upgrade da 6.0 (era setup_db_type)
	{
		function retrocomp_db_type(){
			switch (setup_db_type){
				case 'mysql':	return 'mysql3'; break;
				case 'mysqli':	return 'mysql'; break;
				default: return setup_db_type;
			}
		}
		
		define('db_type', retrocomp_db_type());
		define('db_host', setup_db_host);
		define('db_port', setup_db_port);
		define('db_user', setup_db_user);
		define('db_pass', setup_db_pass);
		define('db_name', setup_db_name);
		define('db_flag', 'mjguest_');
	}
	else // ELSE ...Upgrade da 6.8 (setupfile nei parametri DB è uguale)
	{
		switch (db_type)
		{
			case 'mysql3':
				$new_db_type = 'mysql3';
			break;
			case 'mysql4':
				$new_db_type = 'mysql';
			break;
			case 'pgsql8':
				$new_db_type = 'pgsql';
			break;
			case 'sqlite2':
				$new_db_type = extension_loaded('pdo_sqlite') ? 'sqlite' : 'sqlite2';
			break;
			case 'xmldom':
				$new_db_type = 'xml';
			break;
		}
	}
	
	$db_type = !empty($new_db_type) ? $new_db_type : db_type;
	
	if (extension_loaded('pdo_'.$db_type))
	{
		require_once DB_DIR.'pdo.php';
		require_once DB_DIR.$db_type.'/driver_pdo.php';
	}
	else require_once DB_DIR.$db_type.'/driver.php';
	
	$db = &new db_driver(mjguest_basedir);
	$db->ask('settings_load');
	$db->get_row();
	
	if (!mjguest_debugmode)
	{
		email($db->answer['adminmail'], 'Password reminder', 'Login Password: '.$db->answer['adminpass']);#.' (Requested by IP: '.$this->get('ip').')');
		email($db->answer['modmail'], 'Password reminder', 'Login Password: '.$db->answer['modpass']);#.' (Requested by IP: '.$this->get('ip').')');
	}
	
	echo '<p align="center">Please check your incoming email for the password reminder.</p>';
	
	unset($db);
	
	$__FINISH = 1;
	BREAK;
}

elseif($_SESSION['ACTION'] == 'remove')
{ /* Jump this step */ }

else
{
?>
	<fieldset><legend>User Agreement</legend>
		<p>Please read carefully the following terms and conditions. You must agree to proceed.</p>
		<div style="text-align:center"><iframe id="agreement" readonly="readonly" src="agreement.htm" style="background: white; color: black;"></iframe></div>
		<input name="accept_agreement" type="radio" value="1" class="radio" id="agreement_yes" onclick="on_off('proceed',1)" /><label for="agreement_yes">I accept the terms in the licence agreement</label>
		<br />
		<input name="accept_agreement" type="radio" value="0" class="radio" id="agreement_no" onclick="on_off('proceed',0)" checked="checked" /><label for="agreement_no">I do not accept the terms in the licence agreement</label>
	</fieldset>
<?php
	BREAK;
}

CASE 2:

if($_SESSION['ACTION'] == 'install' or $_SESSION['ACTION'] == 'upgrade')
{
	$__BACK = 1;
	
	$_SESSION['PHP_REQ'] = ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? PHP_WIN_REQUIRED : PHP_NIX_REQUIRED);
	###
	if(!function_exists('version_compare'))
	{ $_SESSION['PHP_OK'] = 0; $__NEXT = 0; }
	elseif(version_compare(PHP_VERSION, $_SESSION['PHP_REQ'], '>='))
	{ $_SESSION['PHP_OK'] = 1; }
	else
	{ $_SESSION['PHP_OK'] = 0; $__NEXT = 0; }
	#$_SESSION['PHP_OK'] = 0; $__NEXT = 0; #--dev--
	###
	if(function_exists('imagecreatetruecolor'))
		$gd_ok = 2; # GD2
	elseif(function_exists('imagecreate'))
		$gd_ok = 1; # GD1
	else
		$gd_ok = 0; # GD none
	if(function_exists('gd_info')) { $gd_info = gd_info(); $gd_info = $gd_info['GD Version']; }
	else { $gd_info = 'version '.$gd_ok; }
	
	###
	$upload_ok = (!@ini_get('file_uploads') or (@ini_get('open_basedir') != null)) ? 0 : 1;
	###
	$_SESSION['CHMOD_OK'] = autowrite();
	#$_SESSION['CHMOD_OK'] = 0; #--dev--
	
	###
	$zlib_ok = (extension_loaded('zlib') or file_exists(mjguest_basedir.'modules/settings.nozip.inc.php'));
	###
?>
	<fieldset><legend>System Requirements</legend>
		<table style="margin: 10px; width: 90%;">
			<tr>
				<td class="rep_icon"><?php echo ($_SESSION['PHP_OK'] == 1 ? IMG_RIGHT : IMG_WRONG)?></td>
				<td class="rep_desc"><strong>PHP version</strong>
<?php if($_SESSION['PHP_OK'] == 0): ?>
					<span style="color: crimson">
					<br />The server has an old PHP version (<?php echo PHP_VERSION?>) installed.
					<br />Please ask your provider to upgrade to the latest version available.
<?php else: ?>
					<span style="color: gray">
					<br />Installed: <?php echo PHP_VERSION?>
<?php endif; ?>
					</span>
				</td>
			</tr>
			<tr>
				<td class="rep_icon"><?php echo ($zlib_ok == 1 ? IMG_RIGHT : IMG_WRONG)?></td>
				<td class="rep_desc"><strong>Zlib Library</strong> (recommended)
<?php if($zlib_ok == 0): $__NEXT = 0; ?>
					<span style="color: crimson">
					<br />This PHP build doesn't support Zlib compression library.
					<br />Please download <a href="http://www.mdsjack.bo.it/files/mjguest<?php echo mjguest_versionid ?>-zlib_patch.zip" target="_blank">this official patch</a> to install the script without Zlib.
<?php else: ?>
					<span style="color: gray">
					<br />Installed.
<?php endif; ?>
					</span>
				</td>
			</tr>
			<tr>
				<td class="rep_icon"><?php echo ($upload_ok == 1 ? IMG_RIGHT : IMG_WRONG)?></td>
				<td class="rep_desc"><strong>File Upload</strong> (optional)
<?php if($upload_ok == 0): ?>
					<span style="color: crimson">
					<br />Your provider has chosen to restrict access to uploaded files.
					<br />Avatars <u>may not</u> work, until php configuration is changed by provider.
<?php else: ?>
					<span style="color: gray">
					<br />No restrictions detected.
<?php endif; ?>
					</span>
				</td>
			</tr>
			<tr>
				<td class="rep_icon"><?php echo ($gd_ok != 0 ? IMG_RIGHT : IMG_WRONG)?></td>
				<td class="rep_desc"><strong>GD Library</strong> (optional)
<?php if($gd_ok == 2): ?>
					<span style="color: gray">
					<br />Installed: <?php echo $gd_info?>
<?php elseif($gd_ok == 1): ?>
					<span style="color: gray">
					<br />Installed: <?php echo $gd_info?>
					</span>
					<span style="color: crimson">
					<br />Avatars will be rendered in <u>low quality</u> until your provider installs GD2 support.
<?php else: ?>
					<span style="color: crimson">
					<br />Avatars will be rendered as <u>distorted</u> until your provider installs GD support.
					<br />CAPTCHA security code <u>will not</u> work.
<?php endif; ?>
					</span>
				</td>
			</tr>
			<tr>
				<td class="rep_icon"><?php echo ($_SESSION['CHMOD_OK'] == 1 ? IMG_RIGHT : IMG_WRONG)?></td>
				<td class="rep_desc"><strong>Files Writing<!-- (Directory &quot;< ?=WRITE_DIR?>&quot;)--></strong> (optional)
<?php if($_SESSION['CHMOD_OK'] == 0): ?>
					<span style="color: crimson">
					<br />The setup file will not be generated automatically.
					<br />You will be given instructions on how to do that manually.
					<!--<br /><input type="button" value=" HELP " onclick="if(confirm('< ?=$chmod_error?>')) { document.getElementById('proceed').disabled = false }" />-->
<?php else: ?>
					<span style="color: gray">
					<br />Permissions granted.
<?php endif; ?>
					</span>
				</td>
			</tr>
		</table>
	</fieldset>
<?php
	// se torniamo indietro cancelliamo i dati immessi
	unset($_SESSION['DB_type'], $_SESSION['DB_host'], $_SESSION['DB_port'], $_SESSION['DB_user'], $_SESSION['DB_pass'], $_SESSION['DB_name'], $_SESSION['DB_flag']);
	
	BREAK;
}

CASE 3:

// se aggiorniamo (o cancelliamo), invece che ripetere i parametri, li prendiamo dal setupfile esistente e saltiamo lo step
if ($_SESSION['ACTION'] == 'upgrade')
{
	if(file_exists(mjguest_basedir.'_files/setup.ini.php')) // Upgrade da 5.0
	{
		require_once mjguest_basedir.'_files/setup.ini.php';
		
		define('db_type', 'mysql3');
		define('db_host', $db_host);
		define('db_port', '');
		define('db_user', $db_user);
		define('db_pass', $db_pass);
		define('db_name', $db_name);
		define('db_flag', 'mjguest_');
	}
	else // Upgrade da 6.x...
		require_once SETUPFILE;
	
	if(!defined('db_type')) // ...Upgrade da 6.0 (era setup_db_type)
	{
		function retrocomp_db_type(){
			switch (setup_db_type){
				case 'mysql':	return 'mysql3'; break;
				case 'mysqli':	return 'mysql'; break;
				default: return setup_db_type;
			}
		}
		
		define('db_type', retrocomp_db_type());
		define('db_host', setup_db_host);
		define('db_port', setup_db_port);
		define('db_user', setup_db_user);
		define('db_pass', setup_db_pass);
		define('db_name', setup_db_name);
		define('db_flag', 'mjguest_');
	}
	else // ELSE ...Upgrade da 6.8 (setupfile nei parametri DB è uguale)
	{
		switch (db_type)
		{
			case 'mysql3':
				$new_db_type = 'mysql3';
			break;
			case 'mysql4':
				$new_db_type = 'mysql';
			break;
			case 'pgsql8':
				$new_db_type = 'pgsql';
			break;
			case 'sqlite2':
				$new_db_type = extension_loaded('pdo_sqlite') ? 'sqlite' : 'sqlite2';
			break;
			case 'xmldom':
				$new_db_type = 'xml';
			break;
		}
	}
	
}


if ($_SESSION['ACTION'] == 'upgrade' or $_SESSION['ACTION'] == 'remove')
{
	$DB_TYPE = !empty($new_db_type) ? $new_db_type : db_type;
	
	$_SESSION['DB_type'] = $DB_TYPE;
	$_SESSION['DB_host'] = db_host;
	$_SESSION['DB_port'] = db_port;
	$_SESSION['DB_user'] = db_user;
	$_SESSION['DB_pass'] = db_pass;
	$_SESSION['DB_name'] = db_name;
	$_SESSION['DB_flag'] = db_flag;
}
elseif ($_SESSION['ACTION'] == 'install') //lo step dei parametri è solo se si Installa...
{
	if (empty($_SESSION['DB_type']))
	{ // siamo alla prima volta. altrimenti manteniamo i valori di sessione già inseriti e da cambiare.
		$_SESSION['DB_type'] = '';
		$_SESSION['DB_host'] = '';
		$_SESSION['DB_port'] = '';
		$_SESSION['DB_user'] = '';
		$_SESSION['DB_pass'] = '';
		$_SESSION['DB_name'] = '';
		$_SESSION['DB_flag'] = 'mjguest_';
	}

	$__BACK = 1;
	$__NEXT = 1;
	
	$sqlite_dir_hint = '';
	if(extension_loaded('sqlite') or class_exists('DOMDocument'))
	{
		if ($_SESSION['CHMOD_OK'] == 1)
			$sqlite_dir_hint = '';
		
		elseif (is_dir('./mdb-database/'))
			$sqlite_dir_hint = './mdb-database/';
			
		else $sqlite_dir_hint = '';
	}
?>
	<fieldset style="width:auto"><legend>Database parameters</legend>
<?php
	$db_installed = 0;
	ob_start();
	
?>
		<p align="center">Please provide necessary parameters for database connection.<br><b>Please ensure all the parameters are correct, before proceeding!</b></p>
		<style>
		tr { margin: 0px; padding: 0px; height: 15px; }
		td { margin: 0px; padding: 5px; height: 15px; }
		</style>
		<table style="width: 100%; margin: 0px; padding: 0px;" cellspacing="0" cellpadding="0">
			<tr>
				<td width="25%">
				<select style="width:122px" name="db_type" id="dbType" onchange="sqlitepath(this, '<?php echo $sqlite_dir_hint ?>')">
				<?php if(extension_loaded('mysql') and is_dir(DB_DIR.'mysql3')): $db_installed++ ?>
				<option value="mysql3"<?php if($_SESSION['DB_type'] == 'mysql3'): ?> selected="selected"<?php endif; ?>>MySQL 3.23+</option>
				<?php endif;
				if((extension_loaded('mysqli') or extension_loaded('pdo_mysql')) and is_dir(DB_DIR.'mysql')): $db_installed++ ?>
				<option value="mysql"<?php if($_SESSION['DB_type'] == 'mysql'): ?> selected="selected"<?php endif; ?>>MySQL 4.1+</option>
				<?php endif;
					if(extension_loaded('pdo_sqlite') and is_dir(DB_DIR.'sqlite')): $db_installed++ ?>
				<option value="sqlite"<?php if($_SESSION['DB_type'] == 'sqlite'): ?> selected="selected"<?php endif; ?>>SQLite 3+</option>
				<?php
					elseif(extension_loaded('sqlite') and is_dir(DB_DIR.'sqlite2')): $db_installed++ ?>
				<option value="sqlite2"<?php if($_SESSION['DB_type'] == 'sqlite2'): ?> selected="selected"<?php endif; ?>>SQLite 2.8+</option>
				<?php endif;
				if((extension_loaded('pgsql') or extension_loaded('pdo_pgsql')) and is_dir(DB_DIR.'pgsql')): $db_installed++ ?>
				<option value="pgsql"<?php if($_SESSION['DB_type'] == 'pgsql'): ?> selected="selected"<?php endif; ?>>PostgreSQL 8+</option>
				<?php endif;
				if(class_exists('DOMDocument') and is_dir(DB_DIR.'xml')): $db_installed++ ?>
				<option value="xml"<?php if($_SESSION['DB_type'] == 'xml'): ?> selected="selected"<?php endif; ?>>XML File</option>
				<?php endif; clearstatcache(); ?>
				</select>
				</td>
				<td width="*"><b>Database Type</b>: Choose the database to use among the available ones on your server.</td>
			</tr>
			<tr>
				<td width="25%"><input name="db_host" type="text" value="<?php echo $_SESSION['DB_host'] ?>" /></td>
				<td width="*"><b>Location</b>: it can be 'localhost' or an IP address.
				<br /><small>SQLite/XML: relative path from MJGUEST root folder to a writable directory where the database file will be placed.</small></td>
			</tr>
			<tr>
				<td width="25%"><input name="db_port" type="text" value="<?php echo $_SESSION['DB_port']?>" /></td>
				<td width="*"><b>Port</b>: it can be empty or a number.
				<br /><small>SQLite/XML: leave blank.</small></td>
			</tr>
			<tr>
				<td width="25%"><input name="db_user" type="text" value="<?php echo $_SESSION['DB_user']?>" /></td>
				<td width="*"><b>Username</b>: login data for private databases.
				<br /><small>SQLite/XML: leave blank.</small></td>
			</tr>
			<tr>
				<td width="25%"><input name="db_pass" type="text" value="<?php echo $_SESSION['DB_pass']?>" /></td>
				<td width="*"><b>Password</b>: login data for private databases.
				<br /><small>SQLite/XML: leave blank.</small></td>
			</tr>
			<tr>
				<td width="25%"><input name="db_name" type="text" value="<?php echo $_SESSION['DB_name']?>" /></td>
				<td width="*"><b>Database Name</b>: the database where tables will be created.
				<br /><small>SQLite/XML: database filename (without extension) up to your choice.</small></td>
			</tr>
			<tr>
				<td width="25%"><input name="db_flag" type="text" value="<?php echo $_SESSION['DB_flag']?>" /></td>
				<td width="*"><b>Guestbook Identifier</b>: If you're going to install multiple guestbooks on the same database, change this ID upon any new installation; otherwise leave default value.
			</tr>
		</table>
<?php

	if ($db_installed > 0):
		ob_end_flush();
	else:
		ob_end_clean();
		$__NEXT = 0;
?>
		<div align="center" style="color: crimson">
			<p><strong>No Database extensions enabled on this PHP server</strong>
			<br />Unable to install the script until at least one database is available.</p>
		</div>
<?php endif; ?>
	</fieldset>
<?php
	
	BREAK;
} // ...altrimenti lo saltiamo

CASE 4: // dopo averli inseriti passiamo subito alle query

$DB_WRITE_ERROR = 0;

if (!empty($_POST['db_type']))
{
	// se installiamo sovrascriviamo la sessione col post
	$_POST = remove_magic_quotes_gpc($_POST);
	$_SESSION['DB_type'] = $_POST['db_type'];
	$_SESSION['DB_host'] = $_POST['db_host'];
	$_SESSION['DB_port'] = $_POST['db_port'];
	$_SESSION['DB_user'] = $_POST['db_user'];
	$_SESSION['DB_pass'] = $_POST['db_pass'];
	$_SESSION['DB_name'] = $_POST['db_name'];
	$_SESSION['DB_flag'] = $_POST['db_flag'];
	
	// NO: se installiamo, non abbiamo ancora il file, quindi definiamo delle costanti provvisorie per far funzionare la classe DB
	define('db_type', $_SESSION['DB_type']);
	define('db_host', $_SESSION['DB_host']);
	define('db_port', $_SESSION['DB_port']);
	define('db_user', $_SESSION['DB_user']);
	define('db_pass', $_SESSION['DB_pass']);
	define('db_name', $_SESSION['DB_name']);
	define('db_flag', $_SESSION['DB_flag']);
	
	$DB_TYPE = db_type;
}

// Usiamo $DB_TYPE aggiornato (6.8) definito per UPGRADE a #766 e per INSTALL a #916

if ($_SESSION['DB_type'] !== '') // parametri sessione a posto.
{
	$file = DB_DIR.$DB_TYPE.'/'.($_SESSION['ACTION'] == 'upgrade' ? $_SESSION['ACTION'].$_SESSION['upgrd_from'] : $_SESSION['ACTION']).'.sql';
	@chmod($file, 0644);
	
	if (!file_exists($file))
		$DB_WRITE_ERROR = 1; #ERR_SQLFILE
	
	elseif(!is_readable($file))
		$DB_WRITE_ERROR = 2; #ERR_SQL_CHMOD
	
	else
	{
		if (extension_loaded('pdo_'.$DB_TYPE))
		{
			require_once DB_DIR.'pdo.php';
			require_once DB_DIR.$DB_TYPE.'/driver_pdo.php';
		}
		else require_once DB_DIR.$DB_TYPE.'/driver.php';
		
		$db = &new db_driver(mjguest_basedir);
		
		$db->sql
	#	print #debug
		($file);
		
		if($db->error != false)
			$DB_WRITE_ERROR = 3; #ERR_QUERY
	}
}
else // Errore scrittura sessioni
	$DB_WRITE_ERROR = 4; #ERR_SESSION


if ($_SESSION['ACTION'] != 'remove'):
?>
	<fieldset><legend>Database writing</legend>
	<div align="center">
<?php
	if($DB_WRITE_ERROR != 0):
		$__NEXT = 0;
		$__BACK = 1;
?>
	<div align="center" style="color: crimson">
		<p>
<?php
		switch ($DB_WRITE_ERROR):
			case 1:?>
		<strong>File &quot;<?php echo $file ?>&quot; was not found</strong>
		<br />You selected an invalid version to upgrade from.
		<br />Otherwise, please check if the file was correctly uploaded.
	<?php break;case 2:?>
		<strong>Unable to read file &quot;<?php echo $file ?>&quot;</strong>
		<br />Please press &quot;Back&quot;, CHMOD to 644 the file via FTP Software, then press &quot;Next&quot;.
	<?php break;case 3: ?>
		<strong>Unable to perform query on Database <?php echo $_SESSION['DB_type'] ?></strong>
		<br />Please press &quot;Back&quot; and choose different database parameters.
		</p>
		<p>If you keep having troubles, ask your Provider for info on database &quot;<?php echo $_SESSION['DB_type'] ?>&quot;
	<?php break;case 4: ?>
		<strong>Unknown error on writing database parameters.</strong>
	<?php endswitch; ?>
		</p>
		<p>For technical support, please visit official forums at<br /><a href="http://www.mdsjack.bo.it" target="_new">www.mdsjack.bo.it</a></p>
	</div>
<?php
	elseif($DB_WRITE_ERROR == 0):
		$__NEXT = 1;
		$__BACK = 0;
?>
	<div align="center">
		<p><strong>Database query successful!</strong>
		<br>You can now proceed saving setup file.</p>
	</div>
<?php endif; ?>
	</div>
	</fieldset>
<?php

endif;

if (($_SESSION['ACTION'] != 'remove' or $DB_WRITE_ERROR != 0)) // se cancelliamo andiamo direttamente al passo successivo
{
	echo "<script>document.forms[0].action='?step=5&".SID."';</script>";
	BREAK;
}


CASE 5:
	
if ($_SESSION['ACTION'] == 'remove'):
	$__FINISH = 1;
	if(@$_POST['remove_reason'] != 'null' and @$_POST['remove_reason'] != 'undefined' and @$_POST['remove_reason'] != null and @$_SERVER['SERVER_NAME'] != 'localhost') email(base64_decode('bWpndWVzdEBtZHNqYWNrLmJvLml0'), 'Script removed', 'The script has been uninstalled for this reason: '.$_POST['remove_reason']);
?>
	<fieldset><legend>Removal</legend>
	<div align="center">
		<p><strong>Operation completed!</strong>
		<br>To delete script files and folders, use your FTP application.</p>
		<p>To reinstall the script, please <?php if (!@unlink(SETUPFILE)) echo 'delete file &quot;'.basename(SETUPFILE).'&quot; and '; ?>press &quot;Home&quot;.
		</p>
	</div>
	</fielset>
<?php
elseif ($_SESSION['ACTION'] == 'install' or $_SESSION['ACTION'] == 'upgrade'):
/* scriviamo il setupfile / se il setupfile è cambiato lo aggiorniamo*/
?>
	<fieldset><legend>Setup File</legend>
	<div align="center">
<?php
	$__BACK = 0;
	$__NEXT = 0;
	$INI_WRITE_ERROR = 0;
	$cookiekey = md5(uniqid(rand(), true));
	$filecontents = "<?php
define('db_type', '{$_SESSION['DB_type']}');
define('db_host', '{$_SESSION['DB_host']}');
define('db_port', '{$_SESSION['DB_port']}');
define('db_user', '{$_SESSION['DB_user']}');
define('db_pass', '{$_SESSION['DB_pass']}');
define('db_name', '{$_SESSION['DB_name']}');
define('db_flag', '{$_SESSION['DB_flag']}');
define('mjguest_debugmode', false);
define('mjguest_cookiekey', '{$cookiekey}');
?>";
	
	if ($_SESSION['ACTION'] == 'upgrade' and version_compare($_SESSION['upgrd_from'], $V_SETUP_EQ, '>=')):
		
		$INI_WRITE_ERROR = -1; #ERR_NOUPDATES
	
	elseif($_SESSION['CHMOD_OK'] == 1):
		
		@chmod(SETUPFILE, 0666);
		require_once(mjguest_basedir.'resources/PEAR/file_put_contents.php');
		
		if (!file_put_contents(SETUPFILE, $filecontents))
			$INI_WRITE_ERROR = 1; #ERR_NOWRITE
		
		@chmod(SETUPFILE, 0644);
		$__NEXT = 1;
		
	elseif($_SESSION['CHMOD_OK'] == 0):
		
		if (!empty($_SESSION['INI_MANUALWRITE']))
		{
			if(file_exists(SETUPFILE))
			{
				include_once SETUPFILE;
				$INI_WRITE_ERROR = (db_type != $_SESSION['DB_type']) ? 2 : 0; #ERR_NOUPLOADED
			}
			else
				$INI_WRITE_ERROR = 2; #ERR_NOUPLOADED
		}
		else
			$INI_WRITE_ERROR = 1; #ERR_NOWRITE
		
	endif;
	
	
	if ($INI_WRITE_ERROR == 0):
		
		$__FINISH = 1;
		
		if(@$_SERVER['SERVER_NAME'] != 'localhost' and @$_SERVER['SERVER_NAME'] != '127.0.0.1' and $_SESSION['ACTION'] == 'install')
		{
			$insturl = 'http://'.@$_SERVER['SERVER_NAME'].@$DIR_ROOT.'mjguest.php';
			
			$f = @fsockopen("www.mdsjack.bo.it", 80);
			if ($f)
			{
				@fwrite($f, "GET /mjguest_customers.php?url=".urlencode($insturl)."&vid=".mjguest_versionid." HTTP/1.1\r\nHost: www.mdsjack.bo.it\r\n\r\n");
				@fclose($f);
			}
			else
				email(base64_decode('bWpndWVzdEBtZHNqYWNrLmJvLml0'), 'New installation', 'New installation performed at: '.$insturl);
		}
?>
		<p><b>Setup File generated correctly.</b>
		<br>Press &quot;Home&quot; to read the guestbook usage tutorials for your website.</p>
<?php elseif ($INI_WRITE_ERROR == 1): $_SESSION['INI_MANUALWRITE'] = true; ?>
        <p>Since setup file cannot be created automatically, you will have to download it.
        <br /><br /><u>Do not close the installer while performing these operations</u>.</p>
        <p style="line-height: 200%; width: 80%; text-align: left">
	        1) Click the button to download the file.
			<br />2) Choose to save the file in your computer.
			<br />3) Ensure that the file is called &quot;setup.ini.php&quot;, otherwise rename it.
			<br />4) Upload it to remote MJGUEST main directory.
			<br />5) Proceed installation by pressing &quot;Next&quot; button
		</p>
		<p><input id="setgen" type="button" onclick="setup_gen()" value="Get Setup File" />
		<br /><span id="goinst" style="display: none"><b>Now you can proceed and check the setup file.</b></span></p>
<?php elseif ($INI_WRITE_ERROR == 2): $__FINISH = 1; ?>
		<p style="color: crimson"><strong>File &quot;<?php echo basename(SETUPFILE)?>&quot; was not generated correctly</strong>
		<br />Follow the instructions below to create it manually.</p>
		<script>document.forms[0].action='?step=5&<?php echo SID?>';</script>
        <p style="width: 80%; text-align: left">
	        1) Create a file called &quot;<?php echo basename(SETUPFILE)?>&quot; with the following text in it.
			<br />2) Upload it to remote MJGUEST main directory.
		</p>
		<textarea onclick="this.select()" style="width: 80%; height: 200px; overflow: auto; font-family: Courier New, Courier, monospace;" readonly="readonly"><?php echo $filecontents; ?></textarea>
<?php elseif ($INI_WRITE_ERROR == -1): $__FINISH = 1; ?>
		<p><b>No Setup File updates needed.</b>
		<br>Press &quot;Home&quot; to read the guestbook usage tutorials for your website.</p>
<?php endif; ?>
	</div>
	</fieldset>
<?php
endif;

BREAK;

ENDSWITCH;
?>
</div>
</div>
<div id="footer">
<span  style="float:left; margin-left:10px">
	<input type="button" value="User Guide" class="button" onclick="window.open('<?php echo mjguest_basedir ?>UserGuide_en.htm')" />
</span>
<?php if($__FINISH == 0): ?>
	<input type="button" value="< Back" class="button" onclick="location.href='?step=<?php echo ($__STEP-1)?>&<?php echo SID?>'"<?php echo ($__BACK != 1 ? ' disabled="disabled"' : '')?> />
	<input type="submit" value="Next >" class="button" id="proceed"<?php echo ($__NEXT != 1 ? ' disabled="disabled"' : '')?> />
	<input type="button" value="Cancel" class="button" style="margin-left: 10px" onclick="if(confirm('If you quit now, the operation will not be completed.\n\nYou may also run SetupUtility at a later time.\n\nExit now?')) { self.close() }" />
<?php else: session_destroy();session_start(); if(!@$__NOHOME): ?>
	<input type="button" value="<< Home" class="button" onclick="location.href='?step=0';" /><?php endif; ?>
	<input type="button" value="Exit" class="button" style="margin-left: 10px" onclick="alert('Thanks for choosing this product!\n\nOfficial web site: www.mdsjack.bo.it'); self.close()" />
<?php endif; ?>
</div>
</form>
</body>
</html>
<?php
ob_end_flush();
#--dev--
#print('Sessioni: ');print_r($_SESSION);
#print('<br>Post: ');print_r($_POST);
?>
Return current item: MJGUEST