<?php

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

  Script: Maian Events 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...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` varchar(50) NOT NULL default '',
  `addDate` date NOT NULL default '0000-00-00',
  `eventid` 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',
  PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."comments";
 
 // Install table...events..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."events (
  `id` int(7) NOT NULL auto_increment,
  `title` text NOT NULL,
  `fromDate` date NOT NULL default '0000-00-00',
  `toDate` date NOT NULL default '0000-00-00',
  `addDate` date NOT NULL default '0000-00-00',
  `keywords` text NOT NULL,
  `description` text NOT NULL,
  `contact` enum('0','1') NOT NULL default '0',
  `email` varchar(250) NOT NULL default '',
  `en_comments` enum('0','1') NOT NULL default '0',
  `finish` enum('1','2','3') NOT NULL default '3',
  `comments` mediumtext NOT NULL,
  `is_archived` enum('0','1') NOT NULL default '0',
  `rss_date` varchar(35) NOT NULL default '',
  PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."events";
 
 // Install table...pictures..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."pictures (
  `id` int(4) NOT NULL auto_increment,
  `identifier` tinyint(1) NOT NULL default '0',
  `eventid` int(10) NOT NULL default '0',
  `name` varchar(200) NOT NULL default '',
  `thumb` text NOT NULL,
  `image` text NOT NULL,
  PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM");
 
 $report[] = ($query ? $setup9 : $setup10);
 $table[]  = $database['prefix']."pictures";
 
 // Install table...settings..
 $query = mysql_query("
 CREATE TABLE ".$database['prefix']."settings (
  `id` tinyint(1) NOT NULL default '0',
  `website` varchar(250) NOT NULL default '',
  `email` varchar(250) NOT NULL default '',
  `folder` text NOT NULL,
  `formatdate` varchar(15) NOT NULL default '%e %M %Y',
  `language` varchar(50) NOT NULL default 'english.php',
  `theme` varchar(50) NOT NULL default 'standard',
  `modr` enum('0','1') NOT NULL default '0',
  `approve` enum('0','1') NOT NULL default '0',
  `captcha` enum('0','1') NOT NULL default '0',
  `dayspan` enum('0','1') NOT NULL default '0',
  `tswitch` enum('0','1') NOT NULL default '0',
  `meta_keys` mediumtext NOT NULL,
  `meta_desc` mediumtext NOT NULL,
  `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 '25',
  PRIMARY KEY  (`id`)
) ENGINE=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`, `folder`, `formatdate`, `language`, `theme`, `modr`, 
  `approve`, `captcha`, `dayspan`, `tswitch`, `meta_keys`, `meta_desc`, `smtp`, `smtp_host`, `smtp_user`, `smtp_pass`, 
  `smtp_port`) VALUES(1, 'My Calendar', 'you@yoursite.com', 'http://www.yoursite.co.uk/events', '%e %M %Y', 'english.php', 
  'standard', '0', '0', '1', '1', '0', '', '', '0', 'localhost', '', '', '25')");
  
  $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 $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>
