<?php

/*++++++++++++++++++++++++++++++++++++++++

  Script: Maian Gallery v2.0
  Written by: David Ian Bennett
  E-Mail: support@maianscriptworld.co.uk
  Website: http://www.maianscriptworld.co.uk

  ++++++++++++++++++++++++++++++++++++++++
  
  This File: index.php
  Description: Installation File

  ++++++++++++++++++++++++++++++++++++++++*/

error_reporting(E_ALL ^ E_NOTICE);
define ('FOLDER_PATH', dirname(__FILE__).'/');
define ('RELATIVE_PATH', '../');

include(FOLDER_PATH.'lang.php');
include(RELATIVE_PATH.'inc/db_connection.inc.php');

$stage1  = true;
$stage2  = false;
$stage3  = false;
$report  = array();
$table   = array();
$count   = 0;

// Install tables..
if (isset($_POST['one'])) 
{
 $stage1 = false;
 
 // Install table...allowed_emails..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."allowed_emails (
  id int(10) unsigned NOT NULL auto_increment,
  email varchar(250) NOT NULL default '',
  PRIMARY KEY  (id)
 ) TYPE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."allowed_emails";
 
 // Install table...banned..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."banned (
  id int(10) unsigned NOT NULL auto_increment,
  address varchar(250) NOT NULL default '',
  PRIMARY KEY  (id)
 ) TYPE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."banned";
 
 // Install table...categories..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."categories (
  id int(10) unsigned NOT NULL auto_increment,
  catname varchar(100) NOT NULL default '',
  comments text NOT NULL,
  keywords text NOT NULL,
  description text NOT NULL,
  en_cat enum('0','1') NOT NULL default '0',
  en_comments enum('0','1') NOT NULL default '0',
  en_slideshow enum('0','1') NOT NULL default '0',
  en_watermarks enum('0','1') NOT NULL default '0',
  parent enum('0','1') NOT NULL default '0',
  child int(7) NOT NULL default '0',
  folder varchar(50) NOT NULL default '',
  mp3 text NOT NULL,
  PRIMARY KEY  (id)
 ) TYPE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."categories";
 
 // Install table...comments..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."comments (
  id int(10) unsigned NOT NULL auto_increment,
  `name` varchar(200) NOT NULL default '',
  email varchar(250) NOT NULL default '',
  ip_address varchar(50) NOT NULL default '',
  addDate date NOT NULL default '0000-00-00',
  catID int(10) NOT NULL default '0',
  imageID int(10) NOT NULL default '0',
  comments mediumtext NOT NULL,
  is_active enum('0','1') NOT NULL default '0',
  is_approved enum('0','1') NOT NULL default '0',
  verification_key varchar(50) NOT NULL default '',
  PRIMARY KEY  (id)
 ) TYPE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."comments";
 
 // Install table...images..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."images (
  id int(10) unsigned NOT NULL auto_increment,
  `name` varchar(200) NOT NULL default '',
  addDate date default NULL default '0000-00-00',
  cat varchar(10) NOT NULL default '0',
  comments text NOT NULL,
  keywords text NOT NULL,
  description text NOT NULL,
  isize int(10) NOT NULL default '0',
  tsize int(10) NOT NULL default '0',
  imagepath varchar(250) NOT NULL default '',
  thumbpath varchar(250) NOT NULL default '',
  visits int(10) unsigned NOT NULL default '0',
  details text NOT NULL,
  sale_item enum('0','1') NOT NULL default '0',
  rss_date varchar(35) NOT NULL default '',
  enabled enum('0','1') NOT NULL default '0',
  PRIMARY KEY  (id),
  UNIQUE KEY imagepath (imagepath),
  UNIQUE KEY thumbpath (thumbpath)
 ) TYPE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."images";
 
 // Install table...ipndata..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."ipndata (
  id int(7) NOT NULL auto_increment,
  first_name varchar(64) NOT NULL default '',
  last_name varchar(64) NOT NULL default '',
  pay_date date NOT NULL default '0000-00-00',
  address text NOT NULL,
  email varchar(127) NOT NULL default '',
  memo text NOT NULL,
  payment_status varchar(20) NOT NULL default '',
  pending_reason varchar(20) NOT NULL default '',
  gross varchar(10) NOT NULL default '',
  fee varchar(10) NOT NULL default '',
  txn_id varchar(17) NOT NULL default '',
  invoice varchar(127) NOT NULL default '',
  cartID varchar(32) NOT NULL default '',
  pictureShipping varchar(100) NOT NULL default '',
  activeCart enum('0','1') NOT NULL default '0',
  `status` enum('0','1','2') NOT NULL default '0',
  PRIMARY KEY  (id)
 ) TYPE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."ipndata";
 
 // Install table...paypal..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."paypal (
  id tinyint(2) NOT NULL auto_increment,
  ppEmail varchar(250) NOT NULL default '',
  ppLog enum('0','1') NOT NULL default '0',
  ppSandbox enum('0','1') NOT NULL default '0',
  ppStyle varchar(100) NOT NULL default '',
  ppCurrency char(3) NOT NULL default 'GBP',
  ppSSL enum('0','1') NOT NULL default '0',
  ppShipDefault varchar(10) NOT NULL default '',
  ppShipSingle varchar(10) NOT NULL default '',
  PRIMARY KEY  (id)
 ) TYPE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."paypal";
 
 // Install table...purchases..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."purchases (
  id int(7) NOT NULL auto_increment,
  pictureID int(7) NOT NULL default '0',
  pictureSize varchar(100) NOT NULL default '',
  pictureCost varchar(100) NOT NULL default '',
  pictureItem varchar(100) NOT NULL default '',
  pictureQty int(7) NOT NULL default '0',
  cartID varchar(32) NOT NULL default '',
  PRIMARY KEY  (id)
 ) TYPE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."purchases";
 
 // Install table...settings..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."settings (
  id tinyint(1) NOT NULL auto_increment,
  website varchar(100) NOT NULL default '',
  email varchar(100) NOT NULL default '',
  homepage varchar(250) NOT NULL default '',
  folder varchar(250) NOT NULL default '',
  folder_name varchar(250) NOT NULL default '',
  date_format varchar(25) NOT NULL default '',
  mysql_date varchar(25) NOT NULL default '',
  date_ts timestamp,
  theme varchar(50) NOT NULL default '',
  themeswitcher enum('0','1') NOT NULL default '0',
  `language` varchar(40) NOT NULL default '',
  modr enum('0','1') NOT NULL default '0',
  captcha enum('0','1') NOT NULL default '0',
  aboutsite mediumtext NOT NULL,
  licence mediumtext NOT NULL,
  thumbpage tinyint(3) NOT NULL default '0',
  comthumbpage tinyint(3) NOT NULL default '0',
  commentsorder enum('0','1') NOT NULL default '0',
  cart enum('0','1') NOT NULL default '0',
  comments enum('0','1') NOT NULL default '0',
  approve enum('0','1') NOT NULL default '0',
  verification enum('0','1') NOT NULL default '0',
  slideshow enum('0','1') NOT NULL default '0',
  slidespeeds varchar(100) NOT NULL default '',
  slidewindow varchar(10) NOT NULL default '',
  mp3 text NOT NULL,
  greybox enum('0','1') NOT NULL default '0',
  watermarks enum('0','1') NOT NULL default '0',
  watertext varchar(50) NOT NULL default '',
  waterhspace int(3) NOT NULL default '0',
  watervspace int(3) NOT NULL default '0',
  waterfont varchar(7) NOT NULL default '',
  watersize int(2) NOT NULL default '0',
  watertextr int(3) NOT NULL default '0',
  watertextg int(3) NOT NULL default '0',
  watertextb int(3) NOT NULL default '0',
  waterangle int(2) NOT NULL default '0',
  autothumb enum('0','1') NOT NULL default '0',
  autowidth varchar(3) NOT NULL default '0',
  autoheight varchar(3) NOT NULL default '0',
  thumbwidth varchar(3) NOT NULL default '0',
  thumbheight varchar(3) NOT NULL default '0',
  imgwidth varchar(3) NOT NULL default '0',
  imgheight varchar(3) NOT NULL default '0',
  pagedisplaysize varchar(3) NOT NULL default '540',
  windowsizes varchar(15) NOT NULL default '',
  keywords text NOT NULL,
  description text NOT NULL,
  `reset` enum('0','1') NOT NULL default '0',
  smtp enum('0','1') NOT NULL default '0',
  smtp_host varchar(100) NOT NULL default 'localhost',
  smtp_user varchar(100) NOT NULL default '',
  smtp_pass varchar(100) NOT NULL default '',
  smtp_port varchar(100) NOT NULL default '',
  PRIMARY KEY  (id)
 ) TYPE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."settings";
 
 $stage2 = true;
 
}

// Install data..
if (isset($_POST['two']))
{
  mysql_query("
  INSERT INTO ".$database['prefix']."settings (id, website, email, homepage, folder, folder_name, date_format, mysql_date, 
  date_ts, theme, themeswitcher, language, modr, captcha, aboutsite, licence, thumbpage, comthumbpage, 
  commentsorder, cart, comments, approve, verification, slideshow, slidespeeds, slidewindow, mp3, greybox, 
  watermarks, watertext, waterhspace, watervspace, waterfont, watersize, watertextr, watertextg, watertextb, 
  waterangle, autothumb, autowidth, autoheight, thumbwidth, thumbheight, imgwidth, 
  imgheight, pagedisplaysize, windowsizes, keywords, description, reset, smtp, smtp_host, smtp_user, smtp_pass, 
  smtp_port) VALUES( 1, 'My Photo Gallery', 'you@youremail.com', 'http://www.yoursite.co.uk', 'http://www.yoursite.co.uk/gallery', 
  'categories', 'j F Y', '%e %b %Y', now(), 'standard', '0', 'english.php', '0', '1', '','', '12', '10', '1', 
  '0', '1', '1', '0', '1', '20000,15000,9000','575,470', '', '1', '0', 'Watermark', '150', '150', 'arial', 
  '12', '255', '255', '255', '30', '1', '90', '60', '0', '0', '640', '480', '540', '680,540', '', '', '0', '0',
  'localhost', '', '', '25')");
  
  mysql_query("INSERT INTO ".$database['prefix']."paypal (
  id, ppEmail, ppLog, ppSandbox, ppStyle, ppCurrency, ppSSL, ppShipDefault, ppShipSingle) VALUES(
  1, 'you@yoursite.com', '0', '0', '', 'GBP', '0', '0', '0')
  ");
  
  $stage1 = false;
  $stage2 = false;
  $stage3 = true;
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<meta http-equiv="content-type" content="text/html; charset=<?php echo $charset; ?>">
<title><?php echo $setup; ?></title>
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>

<body>
<form method="post" action="index.php">
<div align="center">
<table width="600" cellspacing="0" cellpadding="0" class="mainTable">
<tr>
  <td align="center" class="headCell">- <?php echo $setup; ?> -</td>
</tr>
<?php
if ($stage1)
{

?>
<tr>
  <td align="center" class="pad"><br><?php echo $setup2; ?><br><br>
  <table width="100%" cellspacing="0" cellpadding="0" class="areaTable">
  <tr>
    <td class="pad" width="60%"><b><?php echo $setup3; ?></b></td>
    <td class="pad" width="40%"><span class="info"><?php echo $database['host']; ?></span></td>
  </tr>
  <tr>  
    <td class="pad"><b><?php echo $setup4; ?></b></td>
    <td class="pad"><span class="info"><?php echo $database['database']; ?></span></td>
  </tr>
  <tr>  
    <td class="pad"><b><?php echo $setup5; ?></b></td>
    <td class="pad"><span class="info"><?php echo $database['username']; ?></span></td>
  </tr>
  <tr>  
    <td class="pad"><b><?php echo $setup6; ?></b></td>
    <td class="pad"><span class="info"><?php echo $database['password']; ?></span></td>
  </tr>
  <tr>  
    <td class="pad"><b><?php echo $setup7; ?></b></td>
    <td class="pad"><span class="info"><?php echo $database['prefix']; ?></span></td>
  </tr>
  </table>
  </td>
</tr>
<tr>
  <td align="center" class="pad"><?php echo $setup17; ?>:<br><br>
  <table width="100%" cellspacing="0" cellpadding="0" class="areaTable">
  <tr>
    <td class="pad" width="60%"><b><?php echo $setup16; ?></b></td>
    <td class="pad" width="40%"><span class="info">v<?php echo phpversion(); ?> - <b><?php echo (phpversion()>'4.3.0' ? $setup19 : $setup22); ?></b></span></td>
  </tr>
  <tr>
    <td class="pad"><b><?php echo $setup15; ?></b></td>
    <td class="pad"><span class="info"><b><?php echo (function_exists('curl_setopt') ? $setup19 : $setup20); ?></b></span></td>
  </tr>
  <tr>
    <td class="pad"><b><?php echo $setup18; ?></b></td>
    <td class="pad"><span class="info"><b><?php echo (function_exists('imagecreatetruecolor') ? $setup19 : $setup20); ?></b></span></td>
  </tr>
  </table>
  <?php
  if (phpversion()>'4.3.0')
  {
  ?>
  <p class="button"><input class="formButton" name="one" type="submit" value="<?php echo $setup8; ?> &raquo;" title="<?php echo $setup8; ?>" /></p>
  <?php
  } else {
  ?>
  <p class="button" style="color:red;font-size:16px;margin-top:5px"><b><?php echo $setup23; ?></b></p>
  <?php
  }
  ?>
  </td>
</tr>
<?php
}
if ($stage2 && !$stage1)
{
?>
<tr>
  <td align="center" class="pad"><br><?php echo $setup14; ?><br><br>
  <table width="100%" cellspacing="0" cellpadding="0" class="areaTable">
  <?php
  
  // Show results..
  for ($i=0; $i<count($report); $i++)
  {
  ?>
  <tr>  
    <td class="pad" width="60%"><b><?php echo $table[$i]; ?></b></td>
    <td class="pad" width="40%"><span class="info"><?php echo $report[$i]; ?></span></td>
  </tr>
  <?php
  }
  
  ?>
  </table>
  <?php
  if (array_search($setup10,$report)===FALSE)
  {
  ?>
  <p class="button"><input class="formButton" name="two" type="submit" value="<?php echo $setup12; ?> &raquo;" title="<?php echo $setup12; ?>" /></p>
  <?php
  }
  else
  {
    echo '<span class="error_info"><br>'.$setup11.'</span>';
  }
  ?>
  </td>
</tr>
<?php
}
if ($stage3 && (!$stage1 && !$stage2))
{
?>
<tr>
  <td align="center" class="pad"><br><?php echo $setup13; ?><br><br>
  </td>
</tr>  
<?php
}
?>
</table>
</div>
</form>
</body>
</html>
