<?php
/* Nulled by Wizzywig */
/***********ÊÚÑíÈ***********/
/**          saher        **/
/**  ãäÊÏíÇÊ ÔÈÇÈ æÕÈÇíÇ  **/
/**   www.shababtop.com   **/
/**  saher1986@live.com   **/
/***************************/

session_start();

// Report all errors, except notices
error_reporting(0);
@ini_set(‘display_errors’, 0);

// Get the install step
if (!empty($_GET['mode'])) 
    $page = $_GET['mode']; 
else 
    $page = "requirements"; 
	
// Check which page we are on
if($page == "requirements")
	$checktest = 1;
else if ($page == "database")
	$checktest = 2;
else if ($page == "admin")
	$checktest = 3;
else if ($page == "config")
	$checktest = 4;
else if ($page == "final")
	$checktest = 5;
	
// Gets the folder path without filename
function GetFileDir($php_self) { 
	$filename = explode("/", $php_self);
	for( $i = 0; $i < (count($filename) - 1); ++$i ) { 
		$filename2 .= $filename[$i].'/'; 
	} 
	return $filename2; 
} 

// Require the page header
require_once("includes/pages_header.php");
require_once("includes/functions_install.php");

// Check PHP Version
if (version_compare(PHP_VERSION, '4.3.3') < 0)
{
	echo '
			<b>You are running an unsupported PHP version. Please upgrade to PHP 4.3.3 or higher before trying to install arrowchat.</b>
		 ';
	require_once("includes/pages_footer.php");
	die();
}

// If step is requirements...
if ($page == "requirements") {
	
	$configwrite = is__writable("../config.php");
	if ($configwrite) {
		$configwrite = "Pass";
		$configwrite2 = "class=\"pass\"";
	} else {
		$configwrite = "Fail, Unwritable or Not Found";
		$configwrite2 = "class=\"fail\"";
	}
	
	$cachewrite = is__writable("../cache/");
	if ($cachewrite) {
		$cachewrite = "Pass";
		$cachewrite2 = "class=\"pass\"";
	} else {
		$cachewrite = "Fail, Unwritable or Not Found";
		$cachewrite2 = "class=\"fail\"";
	}
	
	$dbcheck = checkDB();
	if ($dbcheck) {
		$dbcheck = "Pass";
		$dbcheck2 = "class=\"pass\"";
	} else {
		$dbcheck = "Fail";
		$dbcheck2 = "class=\"fail\"";
	}		
			
	echo '
			
			Welcome to ArrowChat.  Before proceeding, we need to make sure that your server meets the minimum requirements for installation.
			<br /><br />

			<table class="form-table"> 
				<tr> 
					<th scope="row"><label for="phpver">PHP Version</label></th> 
					<td><span class="pass">Pass</span></td> 
					<td>You must be running 4.3.3 or higher.</td> 
				</tr> 
				<tr> 
					<th scope="row"><label for="mysql">mySQL</label></th> 
					<td><span '.$dbcheck2.'>'.$dbcheck.'</span></td> 
					<td>Your server must be able to use mySQL databases.</td> 
				</tr> 
				<tr> 
					<th scope="row"><label for="configwrite">Config.php Writable</label></th> 
					<td><span '.$configwrite2.'>'.$configwrite.'</span></td> 
					<td>You must CHMOD the config.php file to at least 666 for installation only.</td> 
				</tr> 
				<tr> 
					<th scope="row"><label for="cachewrite">Cache Writable</label></th> 
					<td><span '.$cachewrite2.'>'.$cachewrite.'</span></td> 
					<td>You must CHMOD the cache folder to at least 777.</td> 
				</tr>   
			</table>';
						
	if ($configwrite == "Pass" && $cachewrite == "Pass" && $dbcheck == "Pass")
		echo '
		
			<br />
			<input class="button" type="button" value="Let\'s Go!" onClick="window.location.href=\'index.php?mode=database\';" />';
	else
		echo '
		
			<br />
			<input class="button" type="button" value="Test Again" onClick="window.location.reload();this.className=\'buttondown\'" />';
}

// If step is database...
if ($page == "database") {	

	$success = false;
	
	if (!empty($_POST['version'])) {
	
		$_SESSION['version']				= $_POST['version'];
		$_SESSION['db_host'] 				= $_POST['server'];
		$_SESSION['db_port']				= $_POST['port'];
		$_SESSION['db_name']	 			= $_POST['dbname'];
		$_SESSION['db_username'] 			= $_POST['dbusername'];
		$_SESSION['db_password'] 			= $_POST['dbpassword'];
		$_SESSION['db_prefix'] 				= $_POST['prefix'];

		if ($_POST['version'] == "phpbb") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/config.php"))
				include_once dirname(dirname(dirname(__FILE__)))."/config.php";
			else
				$error = "Arrowchat could not find your phpBB configuration file.  Check to make sure that the arrowchat folder is located within your phpBB folder.";
		}
		if ($_POST['version'] == "cbuilder") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/configuration.php"))
				include_once dirname(dirname(dirname(__FILE__)))."/configuration.php";
			else
				$error = "Arrowchat could not find your Community Builder configuration file.  Check to make sure that the arrowchat folder is located within your Community Builder folder.";
		}
		if ($_POST['version'] == "jomsocial") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/configuration.php"))
				include_once dirname(dirname(dirname(__FILE__)))."/configuration.php";
			else
				$error = "Arrowchat could not find your JomSocial configuration file.  Check to make sure that the arrowchat folder is located within your JomSocial folder.";
		}
		if ($_POST['version'] == "vbulletin") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/includes/config.php"))
				include_once dirname(dirname(dirname(__FILE__)))."/includes/config.php";
			else
				$error = "Arrowchat could not find your vBulletin configuration file.  Check to make sure that the arrowchat folder is located within your vBulletin folder.";
		}
		if ($_POST['version'] == "wordpress") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/wp-load.php"))
				include_once dirname(dirname(dirname(__FILE__)))."/wp-load.php";
			else
				$error = "Arrowchat could not find your WordPress configuration file.  Check to make sure that the arrowchat folder is located within your WordPress folder.";
		}
		if ($_POST['version'] == "buddypress") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/wp-load.php"))
				include_once dirname(dirname(dirname(__FILE__)))."/wp-load.php";
			else
				$error = "Arrowchat could not find your BuddyPress configuration file.  Check to make sure that the arrowchat folder is located within your BuddyPress folder.";
		}
		if ($_POST['version'] == "smf") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/Settings.php"))
				include_once dirname(dirname(dirname(__FILE__)))."/Settings.php";
			else
				$error = "Arrowchat could not find your Simple Machines Forum configuration file.  Check to make sure that the arrowchat folder is located within your Simple Machines Forum folder.";
		}
		if ($_POST['version'] == "dzoic") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/includes/config/config.inc.php"))
				include_once dirname(dirname(dirname(__FILE__)))."/includes/config/config.inc.php";
			else
				$error = "Arrowchat could not find your DZOIC configuration file.  Check to make sure that the arrowchat folder is located within your DZOIC folder.";
		}
		if ($_POST['version'] == "socialengine") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/include/database_config.php"))
				include_once dirname(dirname(dirname(__FILE__)))."/include/database_config.php";
			else
				$error = "Arrowchat could not find your Social Engine configuration file.  Check to make sure that the arrowchat folder is located within your Social Engine folder.";
		}
		if ($_POST['version'] == "ipboard") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/conf_global.php"))
				include_once dirname(dirname(dirname(__FILE__)))."/conf_global.php";
			else
				$error = "Arrowchat could not find your IP.Board configuration file.  Check to make sure that the arrowchat folder is located within your IP.Board folder.";
		}
		if ($_POST['version'] == "drupal") {
			if (file_exists(dirname(dirname(dirname(__FILE__)))."/includes/bootstrap.inc"))
				include_once dirname(dirname(dirname(__FILE__)))."/includes/bootstrap.inc";
			else
				$error = "Arrowchat could not find your Drupal configuration file.  Check to make sure that the arrowchat folder is located within your Drupal folder.";
		}
		
		if (empty($error)) {
			$dbh = mysql_connect($_POST['server'].":".$_POST['port'],$_POST['dbusername'],$_POST['dbpassword']);
			if ($dbh) {
				$success = true;
				echo '<div class="success"><div style="font-weight: bold;">Connection Successful:</div>Arrowchat connected to your database successfully.  Please click continue.</div><br /><br />';
				echo '<input class="button" type="button" value="Continue" onClick="window.location.href=\'index.php?mode=admin\';" />';
			} else {
				$error = "Arrowchat was unable to connect to the database with the provided information.  Check your details and try again.";
			}	
		}
		
		if (!empty($error))
			echo '<div class="error"><div style="font-weight: bold;">Oops! There is an error:</div>'.$error.'</div><br />';
	}
	
	if (!$success) {
		$installs = array(
						"standalone" => array(0 => "Standalone", 1 => "standalone", 2 => "localhost", 3 => "3306"),
						"buddypress" => array(0 => "BuddyPress", 1 => "buddypress", 2 => "localhost", 3 => "3306"),
						"drupal" => array(0 => "Drupal", 1 => "drupal", 2 => "localhost", 3 => "3306"),
						"dzoic" => array(0 => "DZOIC", 1 => "dzoic", 2 => "localhost", 3 => "3306"),
						"ipboard" => array(0 => "IP.Board", 1 => "ipboard", 2 => "localhost", 3 => "3306"),
						"jomsocial" => array(0 => "JomSocial", 1 => "jomsocial", 2 => "localhost", 3 => "3306"),
						"phpbb" => array(0 => "phpBB", 1 => "phpbb", 2 => "localhost", 3 => "3306"),
						"phpfox" => array(0 => "phpFox", 1 => "phpfox", 2 => "localhost", 3 => "3306"),
						"phpnuke" => array(0 => "PHP-Nuke", 1 => "phpnuke", 2 => "localhost", 3 => "3306"),
						"smf" => array(0 => "Simple Machines Forum", 1 => "smf", 2 => "localhost", 3 => "3306"),
						"socialengine" => array(0 => "Social Engine", 1 => "socialengine", 2 => "localhost", 3 => "3306"),
						"vbulletin" => array(0 => "vBulletin", 1 => "vbulletin", 2 => "localhost", 3 => "3306"),
						"wordpress" => array(0 => "WordPress", 1 => "wordpress", 2 => "localhost", 3 => "3306")
						);
				
		echo '
				<script type="text/javascript">
					function hideAll() {';
		foreach ($installs as $install) {
			echo '
						document.getElementById("'.$install[1].'").style.display = "none";';
		}
		if ($_POST['version'] == "standalone")
			$s2 = "selected";
		else
			$s2 = "";
		echo '
					}
					function showDiv(sel) {
					  hideAll();
					  if (sel.selectedIndex != -1)
						{document.getElementById(sel.options[sel.selectedIndex].value).style.display = "block";}
					}
				</script>

				Please choose your installation type first.  Then, fill out the required information so that arrowchat can connect to your database.  If you are unsure about these details, please contact your host.
				<br /><br />
				
				<div class="left"><b>Choose an Installation Type:</b></div><div class="right"><select onchange="showDiv(this)" style="margin-bottom: 5px; width: 200px;font-size: 15px;"><option>Choose a type</option><option>------------------------------</option><option value="standalone" '.$s2.'>Standalone (not listed)</option><option>------------------------------</option>';
				
		foreach ($installs as $install) {
			if ($install[1] != "standalone") {
				if ($install[1] == $_POST['version'])
					$s = "selected";
				else
					$s = "";
					
				echo '<option value="'.$install[1].'" '.$s.'>'.$install[0].'</option>';
			}
		}
				
		echo '</select></div><div class="clear"></div><br />';
			
		$showNext = showNext();
		
		foreach ($installs as $install) {
			if ($install[1] == "standalone") {
				$msg = "Use this installation only if your software is not listed in the drop-down list. Standalone will alone you to configure any site with arrowchat.";
				$msg2 = "Do not create a separate database for ArrowChat. Use the same database information that your users are currently located within.";
			} else {
				$msg = "Use this installation only if you have ".$install[0]." installed on your website.";
				$msg2 = "Do not create a separate database for ArrowChat. Use the same database information that your users are currently located within.";
			}
			
			if (isset($_SESSION['db_host']))
				$server = $_SESSION['db_host'];
			else
				$server = "localhost";
				
			if (isset($_SESSION['db_port']))
				$port = $_SESSION['db_port'];
			else
				$port = "3306";
				
			echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?mode=database">';
			echo '<div id="'.$install[1].'" style="display:none;">'.$msg.'<br /><br />
			
			<b>'.$msg2.'</b><br /><br />

			<table class="form-table"> 
				<tr> 
					<th scope="row"><label for="phpver">Database Host</label></th> 
					<td><input type="text" name="server" value="'.$server.'" /></td> 
					<td>99% chance you won\'t need to change this value.</td> 
				</tr> 
				<tr> 
					<th scope="row"><label for="mysql">Database Port</label></th> 
					<td><input type="text" name="port" value="'.$port.'" /></td> 
					<td>99% chance you won\'t need to change this value.</td> 
				</tr> 
				<tr> 
					<th scope="row"><label for="configwrite">Database Name</label></th> 
					<td><input type="text" name="dbname" value="'.$_SESSION[db_name].'" /></td> 
					<td>The name of your existing user database.</td> 
				</tr>  
				<tr> 
					<th scope="row"><label for="configwrite">Username</label></th> 
					<td><input type="text" name="dbusername" value="'.$_SESSION[db_username].'" /></td> 
					<td>Your MySQL username</td> 
				</tr>  
				<tr> 
					<th scope="row"><label for="configwrite">Password</label></th> 
					<td><input type="password" name="dbpassword" value="'.$_SESSION[db_password].'" /></td> 
					<td>...and MySQL password.</td> 
				</tr>  
				<tr> 
					<th scope="row"><label for="configwrite">Prefix</label></th> 
					<td><input type="text" name="prefix" value="'.$_SESSION[db_prefix].'" /></td> 
					<td>The prefix for your existing user database.</td> 
				</tr>  
			</table>

			<input type="hidden" name="version" value="'.$install[1].'" />
			'.$showNext.'</div>';
			echo '</form>';
		}
		
		if (!empty($_POST['version'])) {
			echo '	<script type="text/javascript">
						document.getElementById("'.$_POST[version].'").style.display = "block";
					</script>';
		}
	
	}
}

// If step is admin settings...
if ($page == "admin") {	

	$success = false;

	if (isset($_POST['admin_username'])) {
	
		$_SESSION['admin_username']			= $_POST['admin_username'];
		$_SESSION['admin_password']			= $_POST['admin_password'];
		$_SESSION['admin_password_confirm'] = $_POST['admin_password_confirm'];
		$_SESSION['admin_email']			= $_POST['admin_email'];
		$_SESSION['admin_email_confirm']	= $_POST['admin_email_confirm'];
	
		if (empty($_POST['admin_username'])) {
			$error = "You must enter an admin username.";
		}
		
		if (empty($_POST['admin_password'])) {
			$error = "You must enter an admin password.";
		}
		
		if (empty($_POST['admin_password_confirm'])) {
			$error = "You must enter a confirmation password.";
		}
		
		if (empty($_POST['admin_email'])) {
			$error = "You must enter an admin email.";
		}
		
		if (empty($_POST['admin_email_confirm'])) {
			$error = "You must enter a confirmation email.";
		}
		
		if (empty($_POST['admin_username'])) {
			$error = "You must enter an admin username.";
		}
		
		if (strtolower($_POST['admin_email']) != strtolower($_POST['admin_email_confirm'])) {
			$error = "Your email and confirmation email do not match.";
		}
		
		if ($_POST['admin_password'] != $_POST['admin_password_confirm']) {
			$error = "Your password and confirmation password do not match.";
		}
	
		if (empty($error)) {
			$success = true;
			echo '<div class="success"><div style="font-weight: bold;">Admin Details Successful:</div>Your administrator details were set.  Please click continue.</div><br /><br />';
			echo '<input class="button" type="button" value="Continue" onClick="window.location.href=\'index.php?mode=config\';" />';
		}
		
		if (!empty($error))
			echo '<div class="error"><div style="font-weight: bold;">Oops! There is an error:</div>'.$error.'</div><br />';
	}
		
	if (!$success) {
		echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?mode=admin">';
		echo '
				Enter the administration details for your ArrowChat installation below.
				<br /><br />
				
				<table class="form-table"> 
					<tr> 
						<th scope="row"><label for="phpver">Admin Username</label></th> 
						<td><input type="text" name="admin_username" value="'.$_SESSION[admin_username].'" /></td> 
						<td>The username you\'ll use to login with.</td> 
					</tr> 
					<tr> 
						<th scope="row"><label for="mysql">Admin Password</label></th> 
						<td><input type="password" name="admin_password" value="'.$_SESSION[admin_password].'" /></td> 
						<td>Your admin password</td> 
					</tr> 
					<tr> 
						<th scope="row"><label for="configwrite">Confirm Password</label></th> 
						<td><input type="password" name="admin_password_confirm" value="'.$_SESSION[admin_password_confirm].'" /></td> 
						<td>...and confirm your password.</td> 
					</tr>  
					<tr> 
						<th scope="row"><label for="configwrite">Admin Email</label></th> 
						<td><input type="text" name="admin_email" value="'.$_SESSION[admin_email].'" /></td> 
						<td>Your admin email</td> 
					</tr>  
					<tr> 
						<th scope="row"><label for="configwrite">Confirm Email</label></th> 
						<td><input type="text" name="admin_email_confirm" value="'.$_SESSION[admin_email_confirm].'" /></td> 
						<td>...and confirm your email.</td> 
					</tr>  
				</table>
					
				'.showNext().'</div>';
		echo '</form>';
		echo '<div class="clear"></div><br />';
	}

}

// If step is config settings...
if ($page == "config") {	

	$success = false;
	
	if (isset($_POST['config_path'])) {
	
		$_SESSION['config_path']				= $_POST['config_path'];
		$_SESSION['config_subdomain']			= $_POST['config_subdomain'];
		$_SESSION['config_table_user']			= $_POST['config_table_user'];
		$_SESSION['config_field_username']		= $_POST['config_field_username'];
		$_SESSION['config_field_userid']		= $_POST['config_field_userid'];
		$_SESSION['config_field_avatar']		= $_POST['config_field_avatar'];
		$_SESSION['config_table_friends']		= $_POST['config_table_friends'];
		$_SESSION['config_field_friend_userid']	= $_POST['config_field_friend_userid'];
		$_SESSION['config_field_friendid']		= $_POST['config_field_friendid'];
		$_SESSION['config_field_friend_check']	= $_POST['config_field_friend_check'];
	
		if (empty($_POST['config_path'])) {
			$error = "You must enter the ArrowChat path.";
		}
		
		if (empty($_POST['config_subdomain'])) {
			$error = "You must enter the subdomain URL.";
		}
	
		if (empty($error)) {
			$success = true;
			echo '<div class="success"><div style="font-weight: bold;">Configuration Successful:</div>Your configuration details were set.  Please click continue.</div><br /><br />';
			echo '<input class="button" type="button" value="Continue" onClick="window.location.href=\'index.php?mode=final\';" />';
		}
		
		if (!empty($error))
			echo '<div class="error"><div style="font-weight: bold;">Oops! There is an error:</div>'.$error.'</div><br />';
	}
	
	$installs = array(
					"standalone" => array(0 => "", 1 => "", 2 => "", 3 => "", 4 => "", 5 => "", 6 => "", 7 => "",),
					"jomsocial" => array(0 => "users", 1 => "name", 2 => "id", 3 => "thumb", 4 => "community_connection", 5 => "connect_from", 6 => "connect_to", 7 => "status"),
					"phpbb" => array(0 => "users", 1 => "username", 2 => "user_id", 3 => "user_avatar", 4 => "zebra", 5 => "user_id", 6 => "zebra_id", 7 => "friend"),
					"vbulletin" => array(0 => "user", 1 => "username", 2 => "userid", 3 => "userid", 4 => "userlist", 5 => "userid", 6 => "relationid", 7 => "friend"),
					"ipboard" => array(0 => "members", 1 => "members_display_name", 2 => "member_id", 3 => "pp_thumb_photo", 4 => "profile_friends", 5 => "friends_member_id", 6 => "friends_friend_id", 7 => "friends_approved"),
					"wordpress" => array(0 => "users", 1 => "display_name", 2 => "ID", 3 => "user_email", 4 => "useronline", 5 => "userid", 6 => "relationid", 7 => "friend"),
					"buddypress" => array(0 => "users", 1 => "display_name", 2 => "ID", 3 => "user_email", 4 => "bp_friends", 5 => "initiator_user_id", 6 => "friend_user_id", 7 => "is_confirmed"),
					"socialengine" => array(0 => "users", 1 => "user_displayname", 2 => "user_id", 3 => "user_photo", 4 => "friends", 5 => "friend_user_id1", 6 => "friend_user_id2", 7 => "friend_status"),
					"dzoic" => array(0 => "members", 1 => "username", 2 => "mem_id", 3 => "photo_small", 4 => "Not Required", 5 => "Not Required", 6 => "Not Required", 7 => "Not Required"),
					"smf" => array(0 => "members", 1 => "memberName", 2 => "ID_MEMBER", 3 => "avatar", 4 => "Not Required", 5 => "Not Required", 6 => "Not Required", 7 => "Not Required"),
					"drupal" => array(0 => "users", 1 => "name", 2 => "uid", 3 => "uid", 4 => "Not Required", 5 => "Not Required", 6 => "Not Required", 7 => "Not Required"),
					"phpnuke" => array(0 => "users", 1 => "username", 2 => "user_id", 3 => "user_avatar", 4 => "Not Required", 5 => "Not Required", 6 => "Not Required", 7 => "Not Required"),
					"phpfox" => array(0 => "user", 1 => "user_name", 2 => "user_id", 3 => "user_image", 4 => "friend", 5 => "user_id", 6 => "friend_user_id", 7 => "Not Required"),
					);
					
	if (isset($_SESSION['config_path'])) {
		$config_path 				= $_SESSION['config_path'];
		$config_subdomain 			= $_SESSION['config_subdomain'];
		$config_table_user 			= $_SESSION['config_table_user'];
		$config_field_username 		= $_SESSION['config_field_username'];
		$config_field_userid 		= $_SESSION['config_field_userid'];
		$config_field_avatar 		= $_SESSION['config_field_avatar'];
		$config_table_friends 		= $_SESSION['config_table_friends'];
		$config_field_friend_userid = $_SESSION['config_field_friend_userid'];
		$config_field_friendid 		= $_SESSION['config_field_friendid'];
		$config_field_friend_check  = $_SESSION['config_field_friend_check'];
	} else {
		$config_path 				= substr(GetFileDir($_SERVER['PHP_SELF']), 0, -8);
		$config_subdomain 			= "";
		$config_table_user 			= $installs[$_SESSION['version']][0];
		$config_field_username 		= $installs[$_SESSION['version']][1];
		$config_field_userid 		= $installs[$_SESSION['version']][2];
		$config_field_avatar 		= $installs[$_SESSION['version']][3];
		$config_table_friends 		= $installs[$_SESSION['version']][4];
		$config_field_friend_userid = $installs[$_SESSION['version']][5];
		$config_field_friendid 		= $installs[$_SESSION['version']][6];
		$config_field_friend_check  = $installs[$_SESSION['version']][7];
	}

		
	if (!$success) {
		echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?mode=config">';
		echo '
				Enter the configuration details for your ArrowChat installation below.  Make sure these details are correct or your installation will not work properly.
				<br /><br />
				
				<table class="form-table"> 
					<tr> 
						<th scope="row"><label for="phpver">ArrowChat Path</label></th> 
						<td><input type="text" name="config_path" value="'.$config_path.'" /></td> 
						<td>The path where your ArrowChat installation is located.</td> 
					</tr> 
					<tr> 
						<th scope="row"><label for="mysql">Subdomain URL</label></th> 
						<td><input type="text" name="config_subdomain" value="'.$config_subdomain.'" /></td> 
						<td>The subdomain URL where your ArrowChat files are located. <br />Ex: channel.domain.com</td> 
					</tr> 
					<tr>
						<td colspan="3" style="background-color:#fff;"><b>Database Details</b><br />In order for ArrowChat to connect with your existing database, we need some details about your database.</td>
					</tr>
					<tr> 
						<th scope="row"><label for="configwrite">User Table</label></th> 
						<td><input type="text" name="config_table_user" value="'.$config_table_user.'" /></td> 
						<td>The name of the table where your usernames and IDs are located</td> 
					</tr>  
					<tr> 
						<th scope="row"><label for="configwrite">Username Field</label></th> 
						<td><input type="text" name="config_field_username" value="'.$config_field_username.'" /></td> 
						<td>...and the name of the username field in that table</td> 
					</tr>  
					<tr> 
						<th scope="row"><label for="configwrite">User ID Field</label></th> 
						<td><input type="text" name="config_field_userid" value="'.$config_field_userid.'" /></td> 
						<td>...and the name of the user ID field in that table</td> 
					</tr>  
					<tr> 
						<th scope="row"><label for="configwrite">User Avatar Field</label></th> 
						<td><input type="text" name="config_field_avatar" value="'.$config_field_avatar.'" /></td> 
						<td>...and the name of the avatar field in that table (optional, if exists).</td> 
					</tr>  
					<tr> 
						<th scope="row"><label for="configwrite">Friends Table</label></th> 
						<td><input type="text" name="config_table_friends" value="'.$config_table_friends.'" /></td> 
						<td>The name of the table where the friends data is located</td> 
					</tr>  
					<tr> 
						<th scope="row"><label for="configwrite">Friends User ID Field</label></th> 
						<td><input type="text" name="config_field_friend_userid" value="'.$config_field_friend_userid.'" /></td> 
						<td>...and the name of the user ID field in that table</td> 
					</tr>  
					<tr> 
						<th scope="row"><label for="configwrite">Friends Friend ID Field</label></th> 
						<td><input type="text" name="config_field_friendid" value="'.$config_field_friendid.'" /></td> 
						<td>...and the name of the friend ID in that table</td> 
					</tr>  
					<tr> 
						<th scope="row"><label for="configwrite">Friends Check Field</label></th> 
						<td><input type="text" name="config_field_friend_check" value="'.$config_field_friend_check.'" /></td> 
						<td>...and the name of the field that determines in the users are friends in that table.</td> 
					</tr>  
				</table>
					
				'.showNext().'</div>';
		echo '</form>';
		echo '<div class="clear"></div><br />';
	}

}

// If step is final...
if ($page == "final") {

	$success = false;

	if (!empty($_POST['write_files'])) {
	
		$_SESSION['in_arrowchat'] = 1;
		
		$dbh = mysql_connect($_SESSION[db_host].':'.$_SESSION[db_port],$_SESSION[db_username],$_SESSION[db_password]);
		mysql_selectdb($_SESSION[db_name],$dbh);
		
		$dbms_schema = 'schemas/mysql_schema.sql';

		$remove_remarks = "remove_remarks";
		$delimiter = ";";

		$sql_query = @file_get_contents($dbms_schema);

		$remove_remarks($sql_query);

		$sql_query = split_sql_file($sql_query, $delimiter);

		foreach ($sql_query as $sql)
		{
			mysql_query($sql);
		}
		
		$sql_ary = array(
			"INSERT INTO `arrowchat_themes` (`id`, `folder`, `name`, `active`, `default`) 
				VALUES (1, 'new_facebook', 'New Facebook', 1, 1)",

			"INSERT INTO `arrowchat_smilies` (`id`, `name`, `code`) 
				VALUES (1, 'smiley', ':)'), (2, 'smiley-sad', ':('), (3, 'smiley-lol', ':D'), (4, 'smiley-wink', ';)'), (5, 'smiley-surprise', ':o'), (6, 'smiley-cool', '8)'), (7, 'smiley-neutral', ':|'), (8, 'smiley-cry', ':''('), (9, 'smiley-razz', ':p'), (10, 'smiley-confuse', ':s'), (11, 'smiley', ':-)'), (12, 'smiley-sad', ':-('), (13, 'smiley-wink', ';-)'), (14, 'smiley-surprise', ':-o'), (15, 'smiley-cool', '8-)'), (16, 'smiley-neutral', ':-|'), (17, 'smiley-razz', ':-p'), (18, 'smiley-confuse', ':-s'), (20, 'smiley-mad', '>:(')",
				
			"INSERT INTO `arrowchat_notifications_markup` (`id`, `name`, `type`, `markup`) 
				VALUES (1, 'Private Messages', 1, '<div class=\"arrowchat_notification_box arrowchat_blue_link\">\r\n	<img src=\"".$_SESSION[config_path]."themes/new_facebook/images/icons/notification_message_icon.png\" class=\"arrowchat_notification_icon\" />\r\n	<a href=\"#\">{author_name}</a> has sent you a new message.<br />\r\n	<div class=\"arrowchat_received\">Received {longago}</div>\r\n</div>\r\n<div class=\"arrowchat_notifications_divider\"></div>'), (2, 'Friend Requests', 2, '<div class=\"arrowchat_notification_box arrowchat_blue_link\">\r\n	<img src=\"".$_SESSION[config_path]."themes/new_facebook/images/icons/notification_friend_icon.png\" class=\"arrowchat_notification_icon\" />\r\n	<a href=\"#\">{author_name}</a> has sent you a friend request.<br />\r\n	<div class=\"arrowchat_received\">Received {longago}</div>\r\n</div>\r\n<div class=\"arrowchat_notifications_divider\"></div>'), (3, 'Wall Post', 3, '<div class=\"arrowchat_notification_box arrowchat_blue_link\">\r\n	<img src=\"".$_SESSION[config_path]."themes/new_facebook/images/icons/notification_wall_post.png\" class=\"arrowchat_notification_icon\" />\r\n	<a href=\"#\">{author_name}</a> has wrote on your wall.<br />\r\n	<div class=\"arrowchat_received\">Received {longago}</div>\r\n</div>\r\n<div class=\"arrowchat_notifications_divider\"></div>')",

			"INSERT INTO `arrowchat_config` (`config_name`, `config_value`, `is_dynamic`) 
				VALUES ('theme', 'new_facebook', 0), ('channel_name', '".$_SESSION[config_subdomain]."', 0), ('base_url', '".$_SESSION[config_path]."', 0), ('online_timeout', '30', 0), ('disable_smilies', '0', 0), ('auto_popup_chatbox', '1', 0), ('heart_beat', '2', 0), ('language', 'ar', 0), ('idle_time', '5', 0), ('install_time', '".time()."', 0), ('chatrooms_on', '0', 0), ('notifications_on', '0', 0), ('hide_bar_on', '1', 0), ('applications_on', '0', 0), ('popout_chat_on', '0', 0), ('theme_change_on', '0', 0), ('disable_long_polling', '0', 0)",
				
			"INSERT INTO `arrowchat_admin` (`id`, `username`, `password`, `email`) 
				VALUES (1, '".$_SESSION[admin_username]."', '".md5($_SESSION[admin_password])."', '".$_SESSION[admin_email]."')",
				
			"ALTER TABLE `arrowchat_trayicons`
				MODIFY location VARCHAR(255)",
				
			"ALTER TABLE `arrowchat_trayicons`
				MODIFY icon VARCHAR(255)"

		);
		
		foreach ($sql_ary as $sql)
		{
			mysql_query($sql);
		}
		
		$sql = "INSERT INTO arrowchat_config (config_name, config_value, is_dynamic)
			VALUES ('disable_long_polling', '0', '0')";
		mysql_query($sql);
		
		write_config_file();
		$rename = write_functions_file();
		write_cache_file();
		
		$success = true;
	}

	if (!$success) {
		echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?mode=final">';
		echo '
				This final step will write all your information to the files and database.
				<br /><br />
					
				<div class="clear"></div><br /><input class="button" name="write_files" type="submit" value="Write Files & Setup Database" /></div>';
		echo '</form>';
		echo '<div class="clear"></div><br />';
	}
	
	if ($success) {
		require_once(dirname(__FILE__)."/includes/functions_php.php");
		$header = htmlspecialchars('<link type="text/css" rel="stylesheet" media="all" href="'.$_SESSION[config_path].'external.php?type=css" charset="utf-8" />
<script type="text/javascript" src="'.$_SESSION[config_path].'includes/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="'.$_SESSION[config_path].'includes/js/jquery-ui-1.7.2.custom.min.js"></script>');
		$footer = htmlspecialchars('<script type="text/javascript" src="'.$_SESSION[config_path].'external.php?type=js" charset="utf-8"></script>');

		echo '<b>Congratulations!</b> Your ArrowChat installation is now complete.<br /><br />
			<b>Just a few more steps...</b><br /><br />
			1. CHMOD your config.php file to not be writable<br /><br />
			2. Download and upload this config file to the root folder of your subdomain:<br />
			<a href="download.php">Download Config File</a>
			<br /><br />
			3. Add this code to your page\'s header before the &lt;/head&gt; tag:<br /><br />
			<div style="overflow: auto; border: 1px dotted #dbdbdb;"><pre>'.$header.'</pre></div><br /><br />
			and this to your page\'s footer right before the &lt;/body&gt; tag...<br /><br />
			<div style="overflow: auto; border: 1px dotted #dbdbdb;"><pre>'.$footer.'</pre></div>
			<br /><br />';
			
		echo getFinalInstructions($_SESSION['version']);
			
		echo '<br /><br />
			4. Delete the install folder immediately<br /><br />';
		if (!$rename) {
			echo'
			5. The installer was unable to rename your functions_receive file.  You must go to your includes folder and rename the functions_receive_'.$_SESSION[version].'.php file to functions_receive.php.<br /><br />';
		}
			echo '<input class="button" type="button" value="Go to Admin Panel" onClick="window.location.href=\'../admin/\';" />
		';
	}
}

require_once("includes/pages_footer.php");

?>