Location: PHPKode > projects > phpCAMALEO > install/Setup.php
<?php
/***************************************************************************
 *	Install.php
 *
 *	begin		: August 2006
 *	version		: 25 October 2006
 *	copyright	: (C) 2006 grandolini.net
 *
 *	phpCAMALEO installation script
 *
 ***************************************************************************/
ob_start();
if(!isset($_SESSION[setupCAMALEO]))
{
	session_start(); $_SESSION[setupCAMALEO]=session_id(); $_SESSION[steps]=5;
	if(stristr($_SERVER[HTTP_USER_AGENT],'Firefox')){ $_SESSION[browser]='FF'; }
	if(stristr($_SERVER[HTTP_USER_AGENT],'MSIE'))	{ $_SESSION[browser]='IE'; }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>phpCAMALEO @> Setup</title>
	<link href="../skins/phpCAMALEO/alfa2.ico" rel="shortcut icon" type="image/x-icon" />
	<link href="../skins/phpCAMALEO/MAIN.CSS" type="text/css" rel="stylesheet" />
	<?php	
	#
	#	load the previous page
	if(isset($_GET[prev])) { $_SESSION[step]--; }
	if(!isset($_SESSION[step]) || $_SESSION[step]<0)			{ $_SESSION[step]=0; }
	if(!isset($_SESSION[server]) || $_SESSION[server]=='')		{ $_SESSION[server]='localhost'; }
	if(!isset($_SESSION[skypeini]) || $_SESSION[skypeini]=='')	{ $_SESSION[camaskype]='http://www.jdoqocy.com/6o65kjspjr68G7G8AB687AFDDCB'; $_SESSION[skypeini]='ok'; }
	#
///	$_SESSION[step]=0;	#debug
	if($_SESSION[step]==0)						{ $header='<td colspan="2"><h1>phpCAMALEO @> License Agreement</h1></td>'; }
	if($_SESSION[step]>0 && $_SESSION[step]<6)	{ $header='<td colspan="2"><h1>phpCAMALEO @> Setup <img src="cama-setup-'.$_SESSION[step].'.gif" /> </h1></td>'; }
	if($_SESSION[step]==6)						{ $header='<td><h1>Congratulations: your phpCAMALEO installation is successfully completed!</h1></td>'; }
	#
	switch($_SESSION[browser])
	{
		case 'FF': ?><link href="../skins/phpCAMALEO/MAIN_FF.CSS" rel="stylesheet" type="text/css" /><?php break;
		case 'IE': ?><link href="../skins/phpCAMALEO/MAIN_IE.CSS" rel="stylesheet" type="text/css" /><?php break;
	}
 	echo "\n\n";
	?>
	<script type="text/javascript" src="../common/js/fun2inc.js"></script>
</head>
<body>
<div id="popWin" style="z-index:99;position:absolute;top:-1000px;left:-3000px;width:100%;">popWin</div>
<iframe id="popWinLayer" style="z-index:98;position:absolute;top:-1000px;left:-3000px;border:0;">javascript:false;</iframe>
<form method="post" action="<?=$_SERVER[PHP_SELF]?>">
<table class="form_table" cellpadding="3" border="0">
	<tr><?=$header?></tr>
	<tr><td colspan="2"><hr id="line"></td></tr>
<?php
#=============================================
#
#	draws page contents pending on the step
#
#=============================================
switch($_SESSION[step])
{
	case 0:
		#----- license
		#
		?>
		<tr><td align="right">&nbsp;</td><td><?php 
					$tmp=file_get_contents('../LICENSE');
					$tmp=str_replace("\n",'<br />',$tmp); 
					echo $tmp;?></td></tr>
		<?php
		$_SESSION[button]='I Agree';
		break;
		#
	case 1:
		#----- server connection info
		#
		if($_POST[submit]=='next')
		{
			$server=$_POST[server]; $username=$_POST[username]; $password=$_POST[password];
		}
		else
		{		
			$server=$_SESSION[server]; $username=$_SESSION[username]; $password=$_SESSION[password];
		}
		?>
		<tr><td align="right">MySQL servername:</td><td><input class="form" type="text" name="server" value="<?=$server?>"></td></tr>
		<tr><td colspan="2" height="15px"></td></tr>
		<tr><td align="right">MySQL username:</td><td><input class="form" type="text" name="username" value="<?=$username?>"></td></tr>
		<tr><td align="right">MySQL password:</td><td><input class="form" type="password" name="password" value="<?=$password?>"></td></tr>
		<tr><td colspan="2"><script>document.forms[0].username.focus();</script></td></tr>
		<?php
		$_SESSION[button]='next';
		break;
		#
	case 2:
		#----- database to use
		#
		if($_POST[submit]=='next') { $database=$_POST[database]; } else { $database=$_SESSION[database]; }
		?>
		<tr><td align="right">Database name:</td><td><input class="form" type="text" name="database" value="<?=$database?>"></td></tr>
		<tr><td colspan="2"><script>document.forms[0].database.focus();</script></td></tr>
		<?php
		$_SESSION[button]='next';
		break;
		#
	case 3:
		#----- confirm database creation
		#
		?>
		<tr><td align="right">Database name:</td><td id="color0"><b><?=$_SESSION[database]?></b></td></tr>
		<tr><td colspan="2" height="15px"></td></tr>
		<tr><td colspan="2" align="center"><h3>Click on the next button to create the MySQL tables</h3></td></tr>
		<tr><td colspan="2" align="center"><small style="color:#ff0000;">Warning: tables will NOT be overwritten!<br />Be sure to drop tables if you need a fresh installation database.</small></td></tr>
		<tr><td colspan="2" align="center"><?=get_db_grants($_SESSION[server],$_SESSION[username],$_SESSION[password]);?></td></tr>
		<?php
		$_SESSION[button]='next';
		break;
		#
	case 4:
		#----- phpCAMALEO administrator info
		#
		if($_POST[submit]=='next')
		{
			$admin_id=$_POST[admin_id]; $admin_pw=$_POST[admin_pw]; $admin_pw2=$_POST[admin_pw2]; $admin_fname=$_POST[admin_fname]; $admin_email=$_POST[admin_email];
		}
		else
		{
			$admin_id=$_SESSION[admin_id]; $admin_pw=$_SESSION[admin_pw]; $admin_fname=$_SESSION[admin_fname]; $admin_email=$_SESSION[admin_email];
		}
		if($group_id=='')	{ $group_id='DEV'; }
		if($group_name=='')	{ $group_name='DEVELOPERS'; }
		?>
		<tr><td align="right">Database name:</td><td id="color0"><b><?=$_SESSION[database]?></b></td></tr>
		<tr><td colspan="2" align="center"><h3>Administrator information</h3>ALL fields are mandatory!</td></tr>
		<tr><td align="right">ID:</td><td id="color0"><input class="form" type="text" name="admin_id" value="<?=$admin_id?>"> (6 chars min)</td></tr>
		<tr><td align="right">Password:</td><td id="color0"><input class="form" type="password" name="admin_pw" value="<?=$admin_pw?>"> (6 chars min)</td></tr>
		<tr><td align="right">Retype password:</td><td id="color0"><input class="form" type="password" name="admin_pw2" value="<?=$admin_pw2?>"></td></tr>
		<tr><td align="right">Full name:</td><td><input class="form" type="text" name="admin_fname" value="<?=$admin_fname?>"></td></tr>
		<tr><td align="right">Email:</td><td><input class="form" type="text" name="admin_email" value="<?=$admin_email?>" size="32"></td></tr>
		<tr><td colspan="2" height="15px"></td></tr>
		<tr><td align="right">Group ID:</td><td id="color0"><input class="form" type="text" name="group_id" value="<?=$group_id?>"> (reserved for future use)</td></tr>
		<tr><td align="right">Group name:</td><td id="color0"><input class="form" type="text" name="group_name" value="<?=$group_name?>"> (reserved for future use)</td></tr>
		<tr><td colspan="2"><script>document.forms[0].admin_id.focus();</script></td></tr>
		<?php
		$_SESSION[button]='next';
		break;
		#
	case 5:
		#----- minimal phpCAMALEO configuration settings
		#
		$title=$_POST[title];		if($title=='')	{ $title='@ my local server'; }
		$skypeid=$_POST[skypeid];
		$skypelnk=$_POST[skypelnk];
		if($skypelnk=='') { $skypelnk=$_SESSION[camaskype]; $_SESSION[camaskype]=''; }
		$hashpad=$_POST[hashpad];	if($hashpad=='')	{ $hashpad='Tweeny weenie weggy wog: oh what fun to have a dog!'; }
		#
		if(!isset($_POST[_r_location]) || $_POST[_r_location]=='l') { $loc_onl='checked '; } else { $loc_onw='checked '; }
		#
		if($_SERVER[WINDIR]=='') { $os_onl='checked '; } else { $os_onw='checked '; }
		#
		if(!isset($_POST[_r_http]) || $_POST[_r_http]=='a') { $http_ona='checked '; } else { $http_oni='checked '; }
		if(!isset($_POST[_r_statmain]) || $_POST[_r_statmain]=='1') { $stat_on='checked '; } else { $stat_of='checked '; }
		if($_POST[_c_statuser]=='1') { $suser_on='checked '; }
		if($_POST[_c_statlang]=='1') { $slang_on='checked '; }
		if($_POST[_c_statpage]=='1') { $spage_on='checked '; }
		if($_POST[_c_statip]=='1') { $sip_on='checked '; }
		?>
		<tr><td colspan="2">Database name: <b id="color0"><?=$_SESSION[database]?></b>, Administrator: <b id="color0"><?=$_SESSION[admin_id]?></b></td></tr>
		<tr><td colspan="2"><hr id="line"></td></tr>
		<tr><td colspan="2" align="center"><h3>Please fill this last form to complete the setup</h3></td></tr>
		<tr><td align="right" valign="top">Title&nbsp;suffix:</td><td><input class="form" type="text" name="title" value="<?=$title?>" size="64"><br /><small id="color0">Added at the end of the &lt;title&gt; tag, useful to distiguish between a local or public page</small></td></tr>
		<tr><td align="right">System:</td><td>
			<fieldset class="form">
			<table>
				<tr>
					<td>Install&nbsp;location:</td>
					<td><input type="radio" <?=$loc_onl?>name="_r_location" value="l">&nbsp;Local</td>
					<td><input type="radio" <?=$loc_onw?>name="_r_location" value="w">&nbsp;Public server</td>
				</tr>
				<tr>
					<td></td>
					<td colspan="2"><small id="color0">On the Local server phpCAMALEO will show additional links and info that is better to avoid on the public server</small></td>
				</tr>
				<tr>
					<td>Operating&nbsp;system:</td>
					<td><input type="radio" <?=$os_onl?>name="_r_os" value="l">&nbsp;Linux</td>
					<td><input type="radio" <?=$os_onw?>name="_r_os" value="w">&nbsp;Windows</td>
				</tr>
				<tr>
					<td>HTTP&nbsp;Server:</td>
					<td><input type="radio" <?=$http_ona?>name="_r_http" value="a">&nbsp;Apache</td>
					<td><input type="radio" <?=$http_oni?>name="_r_http" value="i">&nbsp;IIS</td>
				</tr>
			</table>
			</fieldset>
		</td></tr>
		<tr><td align="right">Statistics:</td><td>
			<fieldset class="form">
			<table>
				<tr>
					<td>Main&nbsp;switch:</td>
					<td>
						<input type="radio" <?=$stat_on?>name="_r_statmain" value="1">&nbsp;On
						<input type="radio" <?=$stat_of?>name="_r_statmain" value="0">&nbsp;Off
					</td>
				</tr>
				<tr>
					<td>If&nbsp;ON:</td>
					<td>
						<input type="checkbox" <?=$suser_on?>name="_c_statuser" value="1">&nbsp;Logged users
						<input type="checkbox" <?=$slang_on?>name="_c_statlang" value="1">&nbsp;Language
						<input type="checkbox" <?=$spage_on?>name="_c_statpage" value="1">&nbsp;Visited pages
						<input type="checkbox" <?=$sip_on?>name="_c_statip" value="1">&nbsp;IP
					</td>
				</tr>
			</table>
			</fieldset>
		</td></tr>
		<tr><td align="right"><a href="http://www.jdoqocy.com/6o65kjspjr68G7G8AB687AFDDCB" target="_blank">Skype</a>:</td><td>
			<fieldset class="form">
			<table>
				<tr>
					<td valign="top">ID:</td><td><input class="form" type="text" name="skypeid" value="<?=$skypeid?>" size="32"><br /><small id="color0">Only needed if you like to show a Skype contact me button on the contact page</small></td>
				</tr>
				<tr>
					<td valign="top">Affiliate&nbsp;link:</td><td><input class="form" type="text" name="skypelnk" value="<?=$skypelnk?>" size="64"><br /><small id="color0">If you do NOT have a Skype affiliation link, please leave mine (http://www.jdoqocy.com/6o65kjspjr68G7G8AB687AFDDCB) here: doing this you will indirectly help this project</small></td>
				</tr>
			</table>
			</fieldset>
		</td></tr>
		<tr><td align="right" valign="top">Hash&nbsp;pad:</td><td><input class="form" type="text" name="hashpad" value="<?=$hashpad?>" size="64"><br /><small id="color0">A string that is used to pad out short strings for md5 encryption</small></td></tr>
		<tr><td colspan="2"><script>document.forms[0].title.focus();</script></td></tr>
		<?php
		$_SESSION[button]='next';
		break;
		#
	case 6:
		?>
		<tr><td colspan="2" align="center">Remember to remove the <b>/install</b> directory and all its contents.</td></tr>
		<tr><td colspan="2" align="center">You should also consider to chmod=555 the [root]/private directory.</td></tr>
		<?php
		$_SESSION[button]='next';
		break;
		#
}
#=============================================
#
#	handle user input
#
#=============================================
switch($_SESSION[step])
{
	case 0:
		if($_POST[submit]=='I Agree' || $_POST[submit]=='ignore GD library')
		{
			$errors=0;
			#
			#	check PHP version
			#
			$version_PHP=phpversion();
			if(version_compare($version_PHP,'4.4.1','<'))
			{
				$errors++;
				?><tr><td colspan="2" id="err" align="center">Your PHP version (<?=$version_PHP?>) is too low to support phpCAMALEO, you must at least upgrade to 4.4.1.</td></tr><?
			}
			#
			#	check required server privileges
			#
			if(!function_exists('imagecreate') && $_POST[submit]!='ignore GD library')
			{
				#	GD library is NOT installed
				#
				$errors++;
				$_SESSION[button]='ignore GD library';
				?><tr><td colspan="2" id="err" align="center">Warning: the GD library is NOT installed on this server.<br />You will be albe to use phpCAMALEO anyway, but security is compromised when using the form image validator.</td></tr><?
			}
			#
			#	check writing privileges
			#
			check_chmod('../tmp/test.txt','tmp');
			check_chmod('../private/test.txt','private');
			check_chmod('../skins/phpCAMALEO/lang/eng/test.txt','skins/phpCAMALEO/lang/eng');
			#
			if($errors==0)
			{
				$_SESSION[step]++; ob_end_clean(); header('Location: '.$_SERVER[PHP_SELF]);	# load the next page
			}
		}
		break;
		#
	case 1:	#---------------------------------
		if($_POST[submit]=='next')
		{
			$dbh=@mysql_connect($server,$username,$password);
			if($dbh=='') { $errors++; ?><tr><td colspan="2" id="err"><?=db_err()?></td></tr><?php } 
			else 
			{
				#	check MySQL version
				#
				$query_id=@mysql_query('SELECT VERSION() AS version');
				$row=@mysql_fetch_array($query_id,MYSQL_ASSOC);
				if($row[version]<'4.1.15')
				{
					$errors++;
					?><tr><td colspan="2" id="err" align="center">Your MySQL version (<?=$row[version]?>) is too low to support phpCAMALEO, you must at least upgrade to 4.1.15.</td></tr><?
				}
				#
				$_SESSION[server]=$_POST[server]; $_SESSION[username]=$_POST[username]; $_SESSION[password]=$_POST[password];
			}
			if(ini_get('register_globals')==true && ini_get('register_globals')==1)
			{
				?><tr><td colspan="2" id="err" align="center">WARNING! PHP is configured with REGISTER_GLOBALS on:<br />this configuration is dangerous for security issues!!<br />If this is a public server it is warmly advised to ask your ISP provider to change this setting.</td></tr><?
			}
			if($errors==0) { $_SESSION[step]++; ob_end_clean(); header('Location: '.$_SERVER[PHP_SELF]); }
		}
		break;
		#
	case 2:	#---------------------------------
		if($_POST[submit]=='next')
		{
			$dbh=@mysql_connect($_SESSION[server],$_SESSION[username],$_SESSION[password]);
			#
			$grants=get_db_grants($_SESSION[server],$_SESSION[username],'*ALREADYCONNECTED*');
			$_SESSION[CREATE]=false; $_SESSION[INSERT]=false;
			if(strpos($grants,'CREATE',0)>0)	{ $_SESSION[CREATE]=true; }
			if(strpos($grants,'INSERT',0)>0)	{ $_SESSION[INSERT]=true; }
			if(strpos($grants,'ALL',0)>0) 		{ $_SESSION[CREATE]=true; $_SESSION[INSERT]=true; }
			#                         ^^ this test can be dangerous: check php docs if your are going to use strpos!
			#
			$dbs=@mysql_select_db($database,$dbh);
			$_SESSION[database]=$_POST[database];
			if($dbs=='') { ?><tr><td colspan="2" id="err"><?=db_err()?></td></tr><?php }
			else
			{
				$_SESSION[step]++; ob_end_clean(); header('Location: '.$_SERVER[PHP_SELF]);
			}
			if(@mysql_errno()==1049)
			{
				#	db does not exhist
				#
				if($_SESSION[CREATE]==true) { $_SESSION[button]='create the db?'; $_SESSION[step]=2; }
				else
				{
					$_SESSION[button]='stop';
					?><tr><td colspan="2" id="err">Sorry but you do not have privileges to create a db =(</td></tr><?php
				}
			}
		}
		break;
		#
	case 3:	#---------------------------------
		if($_POST[submit]=='next' || $_POST[submit]=='ignore')
		{
			$dbh=@mysql_connect($_SESSION[server],$_SESSION[username],$_SESSION[password]);
			$dbs=@mysql_select_db($_SESSION[database],$dbh);
			$create=file('mysql_4.1_create.sql');
			$t=count($create);
			$errors=0;
			for($i=0;$i<$t;$i++)
			{
				#	create default tables
				#
				$data=trim($create[$i]);
				if($data!='')
				{
					$tmp=@mysql_query($data);
					if(@mysql_errno()>0) {  $errors++; ?><tr><td colspan="2" id="err"><?=db_err()?></td></tr><? }
				}
			}
			#
			#	shows confirmation msg and wait 3 secs before reloading the page
			#
			$_SESSION[step]++;
			if($errors==0)
			{
				$_SESSION[button]='next';
				?><script type="text/javascript">pop('MySQL tables creation successfully completed!','<?=$_SERVER[PHP_SELF]?>');</script><?php
			}
			else
			{
				$_SESSION[button]='ignore';
			}
		}
		break;
		#
	case 4:	#---------------------------------
		if($_POST[submit]=='next')
		{
			$dbh=@mysql_connect($_SESSION[server],$_SESSION[username],$_SESSION[password]);
			$dbs=@mysql_select_db($_SESSION[database],$dbh);
			$errors=0;
			$admin_email=strtolower($admin_email);
			#
			if(!$admin_id || strlen($admin_id)<6)	{ $errors++; ?><tr><td colspan="2" id="err">Admin ID is missing or is too short (min length 6 chars)</td></tr><? }
			if(!$admin_pw || strlen($admin_pw)<6)	{ $errors++; ?><tr><td colspan="2" id="err">Admin PASSWORD is missing or is too short (min length 6 chars)</td></tr><? }
			if($admin_pw!=$admin_pw2) 				{ $errors++; ?><tr><td colspan="2" id="err">Admin PASSWORD retyped wrongly</td></tr><? }
			if(!$admin_fname) { $errors++; ?><tr><td colspan="2" id="err">Admin FULL NAME is missing</td></tr><? }
			if(!eregi("^[\'+\\./0-9A-Z^_\`a-z{|}~\-]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+){1,5}$",$admin_email))
			{
				$errors++; ?><tr><td colspan="2" id="err">Admin EMAIL is not in the correct format</td></tr><?php
			}
			#
			if($errors==0)
			{
				#	update user and group records
				#
				$_SESSION[admin_id]		=$_POST[admin_id];
				$_SESSION[admin_pw]		=$_POST[admin_pw];
				$_SESSION[admin_email]	=$_POST[admin_email];
				$_SESSION[admin_fname]	=$_POST[admin_fname];
				$_SESSION[group_id]		=$_POST[group_id];
				$_SESSION[group_name]	=$_POST[group_name];
				#
				$ip		=$_SERVER[REMOTE_ADDR];
				$adminp	=md5($admin_pw);
				$regdate=date('Y-m-d');
				#
				$query_id=@mysql_query("SELECT * FROM `site_users` WHERE id='$_POST[admin_id]'");
				$row=@mysql_fetch_array($query_id,MYSQL_ASSOC);
				if($row=='')
				{
					#	insert user record
					#
					$tmp=@mysql_query("INSERT INTO `site_users` VALUES (NULL, 0, NULL, '$ip', '$_POST[admin_id]', '$adminp', '$_POST[admin_email]', '$_POST[admin_fname]', '$regdate', NULL, NULL, 0, 90, '0000-00-00', 1, 1, 10);");
					if(@mysql_errno()>0) { $errors++; ?><tr><td colspan="2" id="err"><?=db_err()?></td></tr><? }
					else { $ins_id=@mysql_insert_id(); }
				}
				else
				{
					#	user exhists already: gets the user pointer
					#
					$ins_id=$row[RRN];
				}
				$_SESSION[UserRRN]=$ins_id;
				#
				$query_id=@mysql_query("SELECT * FROM `site_users_teams` WHERE id='$_POST[group_id]'");
				$row=@mysql_fetch_array($query_id,MYSQL_ASSOC);
				if($row=='')
				{
					#	insert the group record
					#
					$tmp=@mysql_query("INSERT INTO `site_users_teams` VALUES (NULL, '$ins_id', '$_POST[group_id]', '$_POST[group_name]');");
					$ins_id=@mysql_insert_id();
					if(@mysql_errno()>0) { $errors++; ?><tr><td colspan="2" id="err"><?=db_err()?></td></tr><? }
				}
				else
				{
					#	team exhists already: gets the team pointer
					#
					$ins_id=$row[RRN];
				}
				$_SESSION[TeamRRN]=$ins_id;
			}
			if($errors==0)
			{
				$_SESSION[button]='next';
				$_SESSION[step]++; ob_end_clean(); header('Location: '.$_SERVER[PHP_SELF]);
			}
		}
		break;
		#
	case 5:	#---------------------------------
		$tmp=explode('/',substr(dirname($_SERVER[SCRIPT_NAME]),1)); $t=count($tmp)-1;
		$install_folder='';
		for($i=0;$i<$t;$i++) { $install_folder.=$tmp[$i].'/'; }
		$install_folder=substr($install_folder,0,-1);
		if($_POST[submit]=='next')
		{
			$dbh=@mysql_connect($_SESSION[server],$_SESSION[username],$_SESSION[password]);
			$dbs=@mysql_select_db($_SESSION[database],$dbh);
			$create=file('mysql_4.1_defaults.sql');
			$t=count($create);
			$errors=0;
			for($i=0;$i<$t;$i++)
			{
				#	populate the default tables
				#
				$data=trim($create[$i]);
				if($data!='')
				{
					#	replaces variable data
					#
					$data=str_replace('$$$=admin_email',$_SESSION[admin_email], $data);
					$data=str_replace('$$$=admin_fname',$_SESSION[admin_fname], $data);
					$data=str_replace('$$$=location',	$_POST[_r_location], $data);
					$data=str_replace('$$$=folder',		$install_folder, $data);
					$data=str_replace('$$$=os',			$_POST[_r_os], $data);
					$data=str_replace('$$$=title',		$_POST[title], $data);
					$data=str_replace('$$$=httpserver',	$_POST[_r_http], $data);
					$data=str_replace('$$$=skypeid',	$_POST[skypeid], $data);
					$data=str_replace('$$$=skypelnk',	$_POST[skypelnk], $data);
					$data=str_replace('$$$=stat_ip',	$_POST[_c_statip], $data);
					$data=str_replace('$$$=stat_lang',	$_POST[_c_statlang], $data);
					$data=str_replace('$$$=stat_main',	$_POST[_r_statmain], $data);
					$data=str_replace('$$$=stat_page',	$_POST[_c_statpage], $data);
					$data=str_replace('$$$=stat_user',	$_POST[_c_statuser], $data);
					$data=str_replace('$$$=hashpad',	$_POST[hashpad], $data);
					#
					$tmp=@mysql_query($data);
					if(@mysql_errno()>0) {  $errors++; ?><tr><td colspan="2" id="err">::<?=$data?>:: line:<?=($i+1)?><br /><?=db_err()?></td></tr><? }
				}
			}
			#
			#	create the database connection include (replace the actual file if already on disk!)
			#
			$fd=@fopen('../private/Host.inc','w');
			if(!$fd)
			{
				$result=@chmod('../private/',0777);
				if($result!=true)
				{
					$path=''; $tmp=explode('/',dirname($_SERVER[SCRIPT_NAME])); $t=count($tmp)-1;
					for($i=0;$i<$t;$i++) { $path.=$tmp[$i].'/'; }
					$errors++; ?><tr><td colspan="2" id="err" align="center">Impossible to save the MySQL connection info; to proceed please chmod=777 this directory:<br /><?=$_SERVER[DOCUMENT_ROOT].$path?>private</td></tr><?
				}
			}
			else
			{
				$fout=@fwrite($fd,'<?php $host=\''.$_SESSION[server].'\'; $user=\''.$_SESSION[username].'\'; $password=\''.$_SESSION[password].'\'; $db_main=\''.$_SESSION[database].'\'; ?>');
				@fclose($fd);
			}
			#
			if($errors==0)
			{
				$_SESSION[button]='next';
				$_SESSION[step]++;
				?><script type="text/javascript">document.forms[0].hashpad.focus(); pop('MySQL tables creation successfully populated!','<?=$_SERVER[PHP_SELF]?>');</script><?php
			}
		}
		break;
		#
	case 6:	#---------------------------------
		#
		#---| set admin privileges after installation |---#
		#
		$IP=$_SERVER[REMOTE_ADDR];
		$dbh=@mysql_connect($_SESSION[server],$_SESSION[username],$_SESSION[password]);
		$dbs=@mysql_select_db($_SESSION[database],$dbh);
		$query_id=@mysql_query("SELECT * FROM `online` WHERE ip='$IP'");
		$row=@mysql_fetch_array($query_id,MYSQL_ASSOC);
		if($row!='')
		{
			$sth=@mysql_query("UPDATE `online` SET skin='phpCAMALEO',user='".$_SESSION[admin_id]."',pw='".md5($_SESSION[admin_pw])."',privil='90',userRRN='".$_SESSION[UserRRN]."',team='".$_SESSION[TeamRRN]."',time='".time()."' WHERE ip='$IP' LIMIT 1");
		}
		else
		{
			$sth=@mysql_query("INSERT INTO `online` SET skin='phpCAMALEO',user='".$_SESSION[admin_id]."',pw='".md5($_SESSION[admin_pw])."',privil='90',userRRN='".$_SESSION[UserRRN]."',team='".$_SESSION[TeamRRN]."',time='".time()."',ip='$IP'");
		}
		unset
		(
			$_SESSION[UserRRN],
			$_SESSION[admin_id],
			$_SESSION[admin_pw],
			$_SESSION[admin_fname],
			$_SESSION[admin_email],
			$_SESSION[group_id],
			$_SESSION[group_name],
			$_SESSION[camaskype],
			$_SESSION[server],
			$_SESSION[username],
			$_SESSION[password],
			$_SESSION[database],
			$_SESSION[skypeini],
			$_SESSION[button],
			$_SESSION[steps],
			$_SESSION[CREATE],
			$_SESSION[INSERT]
		);
		$_SESSION[setupCAMALEO]='*OK*';
		#
		#	load the skin selection page
		#
		?><tr><td colspan="2"><hr id="line"></td></tr><tr><td colspan="2" align="center">
			<input class="button" type="button" onclick="javascript:window.location='../skinMNGR.php?installcomplete';" value="Complete Installation">
			</td></tr><?php
		break;
		#
}
if($_SESSION[button]!='')
{
	?>	<tr><td colspan="2"><hr id="line"></td></tr>
		<tr><td></td><td align="right">
			<?php
			if($_SESSION[step]>0) { ?><input class="button" type="button" onclick="javascript:window.location='<?=$_SERVER[PHP_SELF]?>?prev';" value="prev">&nbsp;&nbsp;<?php } 
			if($_SESSION[button]!='stop') { ?><input class="button" type="submit" name="submit" value="<?=$_SESSION[button]?>"></td></tr><?php }
}
#
if($_POST[submit]=='create the db?')
{
	#	create the db on request
	#
	$dbh=@mysql_connect($_SESSION[server],$_SESSION[username],$_SESSION[password]);
	$dbs=@mysql_select_db($_SESSION[database],$dbh);
	if($dbs=='')
	{
		$tmp=@mysql_query('CREATE DATABASE '.$_SESSION[database]);
		if(@mysql_errno()>0)
		{
			?><tr><td colspan="2" id="err"><?=db_err()?></td></tr><?
		}
		else
		{
			$_SESSION[step]++; ob_end_clean(); header('Location: '.$_SERVER[PHP_SELF]);
		}
	}
}
?>
	<tr><td colspan="2" height="55px"></td></tr>
	<tr><td colspan="2" align="center"><font style="font-size:75%;">Copyright &copy; 2006 grandolini.net &mdash; All Rights Reserved.</font></td></tr>
</table>
</form>
</body>
</html>
<?php
#
#	functions
#
#-----------------------------------
function db_err() { return('MySQL Error ('hide@address.com().'): 'hide@address.com()); }
#-----------------------------------
function get_db_grants($host,$user,$pass)
{
	if($pass!='*ALREADYCONNECTED*') { $dbh=@mysql_connect($host,$user,$pass); }
	#
	$query_id=mysql_query('SHOW GRANTS FOR '.$user.'@'.$host);
	$row=mysql_fetch_array($query_id,MYSQL_ASSOC);
	#
	$tmp=$row['Grants for '.$user.'@'.$host];
	list($grants,$tmp)=explode('TO',$tmp);
	#
	return($user.'@'.$host.' HAS '.substr($grants,6));
}
#-----------------------------------
function check_chmod($path,$folder)
#-----------------------------------
{
	global $errors;
	$fd=@fopen($path,'w');
	if(!$fd)
	{
		$result=@chmod('../'.$folder,0777);
		if($result!=true)
		{
			$path=''; $tmp=explode('/',dirname($_SERVER[SCRIPT_NAME])); $t=count($tmp)-1;
			for($i=0;$i<$t;$i++) { $path.=$tmp[$i].'/'; }
			$errors++; ?><tr><td colspan="2" id="err" align="center">To proceed please chmod=777 this directory:<br /><?=$_SERVER[DOCUMENT_ROOT].$path.$folder?></td></tr><?
		}
	}
	else
	{
		@fclose($fd); @unlink($path);
	}
}
?>
Return current item: phpCAMALEO