<?php
/*
script: install/index.php
purpose: php image host installation script
copyright: copyright 2004 Php Image Host. All Rights Reserved. You may modify this file for use on your
					site running a licenced copy of the Php Image Host scripts.
					You must not distribute this file or derivations of it.
Nullified By CrAcKlOvE
*/


require_once(dirname(__FILE__).'/../includes/db.inc.php');
require_once(dirname(__FILE__).'/../classes/ace.class.php');
$ace =& new ace($conn);

$config = $ace->loadsettings();

if( !$config->installed ){

	$varnames = array('admin_email', 'siteurl', 'sitename', 'image_folder', 'image_url', 'thumb_folder', 'thumb_url',
							'reminder_email_from', 'paypal_email', 'signup_email_from');
	$vars = array();

	$errors = array();
	if( $ace->getstr('install', $_POST) != '' ){
		foreach( $varnames as $v ) $vars[$v] = $ace->getstr($v, $_POST);
		if( !$ace->validateemail($vars['admin_email']) ) $errors[] = 'You must enter a valid admin email address.';
		if( !$ace->validateemail($vars['paypal_email']) ) $errors[] = 'You must enter a valid paypal email address.';
		if( !$ace->validateemail($vars['reminder_email_from']) ) $errors[] = 'You must enter a valid email address to send password reminders from.';
		if( !$ace->validateemail($vars['signup_email_from'])) $errors[] = 'You must enter a valid email address to send new account emails to.';
		if( !@is_dir($vars['image_folder'])  ){
			$errors[] = 'You must enter the full path to the folder where images are stored.';
		}elseif(  !@is_writable($vars['image_folder']) ){
			$errors[] =  'You must set the permissions for the images folder so that php can write to it.';
		}else{
			if( !preg_match('/\/$/i',$vars['image_folder']) ) $vars['image_folder'].='/';
		}
		if( !@is_dir($vars['thumb_folder'])  ){
			$errors[] = 'You must enter the full path to the folder where thumbnail images are stored.';
		}elseif(  !@is_writable($vars['thumb_folder']) ){
			$errors[] =  'You must set the permissions for the thumbnail images folder so that php can write to it.';
		}else{
			if( !preg_match('/\/$/i',$vars['image_folder']) ) $vars['thumb_folder'].='/';
		}
		if( !preg_match('/\/$/i',$vars['thumb_url']) ) $vars['thumb_url'].='/';
		if( !preg_match('/\/$/i',$vars['image_url']) ) $vars['image_url'].='/';
		if( !preg_match('/\/$/i',$vars['siteurl']) ) $vars['siteurl'].='/';
		if( !preg_match('/^http.*:\/\/.{1,}\..{2,}\/$/i', $vars['siteurl'] ) ){
			$errors[] = 'You must enter the full url for your site, including the "http://", and the trailing "/".';
		}
		if( count($errors) == 0 ){
			$sql = "UPDATE settings SET installed=1, paypal_account_email='".addslashes($vars['paypal_email'])."' ";
			foreach( $vars as $n=>$v ) $sql .= ",$n='".addslashes($v)."' ";
			$res = @mysql_query($sql);
			if( $res ){
				$config->installed = 1;
			}else{
				$errors[] = 'A database error occurred. mySQL Says: '.mysql_error();
			}
		}	
	}else{
		$domain = $_SERVER['HTTP_HOST'];
		$vars['sitename'] = 'My Image Host';
		$baseurl = 'http://'.$domain;
		$path = preg_replace('/\/install.*$/i', '',$_SERVER['SCRIPT_NAME']);
		$vars['siteurl'] = 'http://'.$domain.$path;
		if( !preg_match('/\/$/i', $vars['siteurl']) ) $vars['siteurl'] .= '/';
		$vars['image_url'] = $vars['siteurl'].'images/';
		$vars['thumb_url'] = $vars['siteurl'].'thumbs/';
		$vars['image_folder'] = realpath(dirname(__FILE__).'/../images/').'/';
		$vars['thumb_folder'] = realpath(dirname(__FILE__).'/../thumbs/').'/';
		$domain = preg_replace('/^www\.(.{1,})\.(.{1,})$/i', '$1.$2', $domain);
		$vars['admin_email'] = 'admin@'.$domain;
		$vars['paypal_email'] = 'paypal@'.$domain;
		$vars['reminder_email_from'] = 'reminder@'.$domain;
		$vars['signup_email_from'] = 'newmember@'.$domain;
	}

}
?>
<html>
<head>
<title>Php Image Host Installation Script</title>
<style type="text/css">
<!--
body, div, td,tr, input{
	font-family: arial;
	font-size: 10pt;
}

body, h3{
	text-align: center;
}

h3{
	font-size: 11pt
}

h4{
	font-size: 10pt;
}

input{
	width: 400px;
}	

.label{
	padding: 5px;
	font-weight: bold;
	text-align: right;
	text-align: right;
	vertical-align: top;
}

.field{
	color: #555555;
	padding: 5px;
	text-align: left;
	vertical-align: top;
}

tr{
	background-color:#eeeeff;
}
-->
</style>
</head>
<body>
<h3>Welcome to the Php Image Host installation setup.</h3>
<div style="text-align: center;">
Have you read the installation instructions?</a>
</div>
<?php
if( count($errors) > 0 ){
?>
<div style="text-align: center; font-weight: bold; color: red;">
The following errors occurred:<br /><br /><?php echo join("<br /><br />\n", $errors);?>
</div>
<?php
}
if( $config->installed ){
?>
<h4>Installation &amp; Configuration Complete!</h4>
You have successfully installed and configured Php Image Host on this server.<br /><br />
To make further changes to this installation, please <a href="../admin/index.php">login to the admin area</a>
 using the username "admin" and the password "password".
<b>Please change these values on the settings page ASAP!</b>
<br /><br />
To see your site in action, <a href="../index.php">visit the home page</a>.
<br /><br />
<h3>IMPORTANT: Please delete the "install" directory and all files in it from your server.</h3>
<?php
}else{
?>
<h4>Setup Custom Settings</h4>
<form action="index.php" method="post">
<table align="center" cellspacing="1" cellpadding="0" border="0" style="width: 600px; background-color: #aaaaaa;">
<tr>
	<td class="label">Site Name:</td>
	<td class="field"><input type="text" name="sitename" value="<?php echo htmlspecialchars($vars['sitename']);?>" />
		<br />Enter the name for your site (eg. "My Image Host").
	</td>
</tr>
<tr>
	<td class="label">Site Url:</td>
	<td class="field"><input type="text" name="siteurl" value="<?php echo htmlspecialchars($vars['siteurl']);?>" />
		<br />Enter the full url for your site, including http, domain name, and trailing slash: eg: "http://www.myimagehost.com/".
	</td>
</tr>
<tr>
	<td class="label">Image URL:</td>
	<td class="field"><input type="text" name="image_url" value="<?php echo htmlspecialchars($vars['image_url']);?>" />
		<br />Enter the full url to the folder where uploaded images are stored (by default this is http://www.yoursite.com/images/).
	</td>
</tr>
<tr>
	<td class="label">Thumbnail URL:</td>
	<td class="field"><input type="text" name="thumb_url" value="<?php echo htmlspecialchars($vars['thumb_url']);?>" />
		<br />Enter the full url to the folder where thumbnail images are stored (by default this is http://www.yoursite.com/thumbs/).
	</td>
</tr>
<tr>
	<td class="label">Full path to images folder:</td>
	<td class="field"><input type="text" name="image_folder" value="<?php echo htmlspecialchars($vars['image_folder']);?>" />
		<br />Enter the full directory path on your server to the folder where images are stored (eg. /home/user/public_html/images/).
	</td>
</tr>
<tr>
	<td class="label">Full path to thumbnail images folder:</td>
	<td class="field"><input type="text" name="thumb_folder" value="<?php echo htmlspecialchars($vars['thumb_folder']);?>" />
		<br />Enter the full directory path on your server to the folder where thumbnail images are stored (eg. /home/user/public_html/thumbs/).
	</td>
</tr>
<tr>
	<td class="label">Admin Email Address:</td>
	<td class="field"><input type="text" name="admin_email" value="<?php echo htmlspecialchars($vars['admin_email']);?>" />
		<br />Your email address. Messages submitted via the contact form will be sent to this email address.
	</td>
</tr>
<tr>
	<td class="label">PayPal Email Address:</td>
	<td class="field"><input type="text" name="paypal_email" value="<?php echo htmlspecialchars($vars['paypal_email']);?>" />
		<br />Your paypal email address. This is the paypal account that payments for account upgrades are paid to.
	</td>
</tr>
<tr>
	<td class="label">Send Password Reminders From:</td>
	<td class="field"><input type="text" name="reminder_email_from" value="<?php echo htmlspecialchars($vars['reminder_email_from']);?>" />
		<br />Enter the email address shown as the "from" address when password reminders are emailed to your members.
	</td>
</tr>
<tr>
	<td class="label">Send Signup Emails From:</td>
	<td class="field"><input type="text" name="signup_email_from" value="<?php echo htmlspecialchars($vars['signup_email_from']);?>" />
		<br />Enter the email address shown as the "from" address when emails are sent when a member opens an account.
	</td>
</tr>

<tr>
	<td class="label">&nbsp;</td>
	<td class="field"><input type="submit" name="install" value="Install Php Image Host" /></td>
</tr>
</table>
</form
<?php
}
?>
</body>
</html>
