Location: PHPKode > projects > EZphotopress > ezphotopress-1.0.0/install/index.php
<?php
session_start();

require_once "../class/mysql.class.php";
require_once "../class/utils.class.php";

$utils = new Utils($db,null);
define('ABSPATH', dirname(dirname(__FILE__)));

$step = @$_GET['step'];
if (!isset($step)) {
	$step = 0;
}

//if the file exists redirect to admin page
if (is_numeric($step) && $step < 3 && file_exists(ABSPATH."/config.php")) {
	include '../config.php';
	header("Location: ".$_CONFIG['site_url']."admin/home.php");
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>EZPhotopPress Installation wizard</title>
		<link rel="stylesheet" type="text/css" href="../css/install.css">
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
		<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
		<script type="text/javascript" src="validation.js"></script>
	</head>
	<body>
		<h1 id="logo"><img alt="EZPhotoPress" src="../images/logo.png" /></h1>
		<?php
		switch ($step) {
			case 0:
				?>
				<!-- need  a logo -->
				<p>Welcome to EZPhotoPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.</p>
				<ol>
					<li>Database name</li>
					<li>Database username</li>
					<li>Database password</li>
					<li>Database host</li>
				</ol>
				<p><strong>If for any reason this automatic file creation doesn't work, don't worry. All this does is fill in the database information to a configuration file. You may also simply open <code>config.php</code> in a text editor, fill in your information, and save it as <code>config.php</code>. </strong></p>
				<p>In all likelihood, these items were supplied to you by your Web Host. If you do not have this information, then you will need to contact them before you can continue. If you&#8217;re all ready&hellip;</p>
				
				<p class="step"><a href="index.php?step=1" class="button">Start</a></p>
				<?php 
				break;
			case 1:
				?>
				<form method="post" action="index.php?step=2">
					<p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
					<table class="form-table">
						<tr>
							<th scope="row"><label for="dbname">Database Name</label></th>
							<td><input name="dbname" id="dbname" type="text" size="25" value="ezphotopress" /></td>
							<td>The name of the database you want to run EZPhotoPress. </td>
						</tr>
						<tr>
							<th scope="row"><label for="uname">User Name</label></th>
							<td><input name="uname" id="uname" type="text" size="25" value="username" /></td>
							<td>Your MySQL username</td>
						</tr>
						<tr>
							<th scope="row"><label for="pwd">Password</label></th>
							<td><input name="pwd" id="pwd" type="text" size="25" value="password" /></td>
							<td>...and your MySQL password.</td>
						</tr>
						<tr>
							<th scope="row"><label for="dbhost">Database Host</label></th>
							<td><input name="dbhost" id="dbhost" type="text" size="25" value="localhost" /></td>
							<td>You should be able to get this info from your web host, if <code>localhost</code> does not work.</td>
						</tr>
						<tr>
							<th scope="row"><label for="prefix">Table Prefix</label></th>
							<td><input name="prefix" id="prefix" type="text" value="ez_" size="25" /></td>
							<td>If you want to run multiple EZPhotoPress installations in a single database, change this.</td>
						</tr>
					</table>
						<p class="step"><input name="submit" type="submit" value="Submit" class="button" /></p>
				</form>
				<?php 
				break;
			case 2:
				//get values
				$dbname = $_POST['dbname'];
				$uname = $_POST['uname'];
				$pwd = $_POST['pwd'];
				$dbhost = $_POST['dbhost'];
				$prefix = $_POST['prefix'];
							
				//try the connection to db
			 	$db = new MySQL($dbhost,$uname,$pwd,$dbname,null) or die('Unable to establish connection ');
			 	if ($db->connectError) {
			 		include 'errordb.php';
			 	} else {
			 		$_SESSION['dbname'] = $dbname;
			 		$_SESSION['dbhost'] = $dbhost;
			 		$_SESSION['dbusername'] = $uname;
			 		$_SESSION['dbpassword'] = $pwd;
			 		$_SESSION['dbprefix'] = $prefix;
			 		//create contents for the file
			 		$fileContents = $utils->createFileInstall($dbhost,$uname,$pwd,$dbname,$prefix);
			 		if (is_writable(ABSPATH)) {
			 			$filename = ABSPATH."/config.php";
			 			$file = fopen($filename,"a");
			 			foreach ($fileContents as $row) {
							fwrite($file,$row."\n");			 				
			 			}
			 			fclose($file);
			 			?>
			 			<p>Connection to the database established successfully.</p>
						<p class="step"><a href="index.php?step=3" class="button">Next >>></a></p>
						<?php 
			 		} else { //not writable - show the file into a text area
			 			?>
			 			<p>Connection to the database established successfully.</p>
						<p>Sorry, you can not write file <b><code>config.php</code></b>.</p>
						<p>You can manually create the <b><code>config.php</code></b> file in the root directory and paste the following text in it.</p>
						<?php 
						$s = "";
			 			foreach ($fileContents as $row) {
							$s .= $row."\n";			 				
			 			}
						?>
						<textarea cols="98" rows="15" class="code"><?=$s?></textarea>
						<p>Once this is done, click "Next >>>"</p>
						<p class="step"><a href="index.php?step=3" class="button">Next >>></a></p>
						<?php
			 		}
			 	}
			 	break;
			 case 3:
			 	include 'adminForm.php';
			 	break;
			 case 4:
			 	//get values
			 	$title = $_POST['title'];
			 	$motto = $_POST['motto'];
			 	$siteUrl = $_POST['siteUrl'];
			 	$password = $_POST['password1'];
			 	$password2 = $_POST['password2'];
			 	$username = $_POST['username'];
			 	$email = $_POST['email'];
			 	
			 	//set the / at the end of the siteUrl if it not present
			 	if (!$utils->endsWith($siteUrl,"/")) {
			 		$siteUrl .= "/";	
			 	}
			 	//save data
			 	include 'installdb.php';
			 	
			 	$successChmod = 0; 
			 	try {
			 		//try to set at 777 the folders into images folder:
			 		// - category
			 		// - gallery
			 		// - gallery/thumb
			 		if (@chmod("../images/category/", 0777) && @chmod("../images/gallery/", 0777) && @chmod("../images/gallery/thumb", 0777)) {
			 			$successChmod = 1;
			 		}
			 	} catch (Exception $e) {
			 		
			 	}
			 	if ($successChmod == 0) {
			 		echo "- Please verify permissions for the follow folders:<br>";
			 		echo "images/category<br>";	
			 		echo "images/gallery<br>";
			 		echo "images/gallery/thumb<br>";
			 		echo "and set permission to 777<br>";
			 	}
			 	?>
			 	<p>Installation completed!!!!</p>
				<p class="step"><a href="<?=$siteUrl?>admin/home.php" class="button">Connect</a></p>
				<?php 
			 	break;
		}
		
		?>	
	</body>
</html>
Return current item: EZphotopress