Location: PHPKode > projects > PHP Manual Creator > install/index.php
<?php
// Include the current config file
require_once("../includes/config.php");

$install_version = '1.0';

// Check to see if the script is already installed
if(isset($config['installed']))
{
	if($config['version'] == $install_version)
	{
		// Exit the script
		exit('PHP Manual Creator is already installed.');
	}
	else
	{
		header('Location: upgrade_'.$config['version'].'.php');
		exit;
	}
}

// If they have submitted the form
if(isset($_POST['DBName']))
{
	// Check that their config file is writtable
	if(is_writable('../includes/config.php'))
	{
		// Try to connect to the database details they provided
		if(mysql_connect($_POST['DBHost'], $_POST['DBUser'], $_POST['DBPass']))
		{
			// Try to select the database specified
			if(mysql_select_db($_POST['DBName']))
			{
				$site_path = str_replace('\\','/',ereg_replace('install', '', dirname(__FILE__)));
				$site_url = "http://" . $_SERVER['HTTP_HOST'] . ereg_replace ("index.php", "", ereg_replace ("install/", "", $_SERVER['PHP_SELF']));
			
				// Content that will be written to the config file
				$content = "<?php\n";
				$content.= "\$config['db']['host'] = '".addslashes($_POST['DBHost'])."';\n";
				$content.= "\$config['db']['name'] = '".addslashes($_POST['DBName'])."';\n";
				$content.= "\$config['db']['user'] = '".addslashes($_POST['DBUser'])."';\n";
				$content.= "\$config['db']['pass'] = '".addslashes($_POST['DBPass'])."';\n";
				$content.= "\$config['db']['pre'] = '".addslashes($_POST['DBPre'])."';\n";
				$content.= "\n";
				$content.= "\$config['version'] = '".$config['version']."';\n";
				$content.= "\$config['installed'] = '1';\n";
				$content.= "?>";
			
				// Open the includes/config.php for writting
				$handle = fopen('../includes/config.php', 'w');
				// Write the config file
				fwrite($handle, $content);
				// Close the file
				fclose($handle);
			
				// Create Admin Table
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."admins` (  `admin_id` int(11) unsigned NOT NULL auto_increment,  `username` varchar(40) NOT NULL default '',  `password` varchar(40) NOT NULL default '',  PRIMARY KEY  (`admin_id`)) TYPE=MyISAM;");
				// Insert Admin Details			
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."admins` VALUES (1, '".addslashes($_POST['adminuser'])."', '".addslashes(md5($_POST['adminpass']))."');");
				// Create Admin Menu table
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."amenu` (  `menu_id` smallint(3) unsigned NOT NULL auto_increment,  `sort_id` smallint(3) unsigned NOT NULL default '0',  `parent_id` smallint(3) unsigned NOT NULL default '0',  `menu_title` varchar(40) NOT NULL default '',  `menu_icon` varchar(100) NOT NULL default '',  `menu_url` varchar(255) NOT NULL default '',  `menu_target` varchar(10) NOT NULL default '',  `menu_desc` varchar(100) NOT NULL default '',  PRIMARY KEY  (`menu_id`)) TYPE=MyISAM;");
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES (38, 0, 0, 'Configuration', '', '', '', '');");
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES (40, 10, 38, 'Database', '<img src=\"images/icons/smicon_config.gif\">', 'database.php', '', '');");
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES (41, 10, 0, 'Manuals', '', '', '', '');");
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES (42, 0, 41, 'Add Manual', '<img src=\"images/icons/smicon_addrule.gif\">', 'manual_add.php', '', '');");
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES (46, 0, 41, 'Edit Manual', '<img src=\"images/icons/smicon_editrule.gif\">', 'manual_view.php', '', '');");
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES (43, 20, 0, 'Pages', '', '', '', '');");
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES (44, 0, 43, 'Add Page', '<img src=\"images/icons/smicon_addrule.gif\">', 'page_add.php', '', '');");
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES (45, 2, 43, 'Edit Page', '<img src=\"images/icons/smicon_editrule.gif\">', 'page_view.php', '', '');");
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES (47, 3, 43, 'Sort Pages', '<img src=\"images/icons/smicon_editrule.gif\">', 'page_sort.php', '', '');");
				// Create Manuals Table
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."manuals` ( `manual_id` int(11) unsigned NOT NULL auto_increment,  `manual_title` varchar(200) NOT NULL default '',  `manual_tpl` varchar(50) NOT NULL default '',  PRIMARY KEY  (`manual_id`)) TYPE=MyISAM ;");
				// Create Pages Table
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."pages` (  `page_id` int(11) unsigned NOT NULL auto_increment,`sort` int(11) unsigned NOT NULL default '0',`manual_id` int(11) unsigned NOT NULL default '0',`parent_id` int(11) unsigned NOT NULL default '0',  `page_title` varchar(100) NOT NULL default '', `page_body` mediumtext NOT NULL,  PRIMARY KEY  (`page_id`),  KEY `manual_id` (`manual_id`)) TYPE=MyISAM;");

				
				header("Location: installed.php");
				exit;
			}
			else
			{
				// The database doesn't exist
				echo '<script>alert(\'Could not find database '.$_POST['DBName'].'\r\n\r\n'.addslashes(mysql_error()).'\');</script>';
			}
		}
		else
		{
			// The username/password does not have access to that database
			echo '<script>alert(\'Could not connect to MySQL using these details.\r\n\r\n'.addslashes(mysql_error()).'\');</script>';
		}
	}
	else
	{
		// Can't write to the includes/config.php file
		echo '<script>alert(\'Could not write to your includes/config.php file.\r\n\r\nPlease check that you have set the chmod/permisions to 0777\');</script>';
	}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PHP Manual Creator - Install</title>
<style type="text/css">
<!--
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
}
.style12 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }
.style15 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; }
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
-->
</style>
</head>

<body>
<div align="center">
 <br>
  <form name="form1" method="post" action="index.php">
  <table border="0" cellpadding="0" cellspacing="0">
    <tr><td>  Welcome to the PHP Manual Creator installation, Please fill in the details<br>
  below and then click &quot;Install&quot;<br>
  <br>
  <Br>
    <table border="0" cellspacing="0" cellpadding="3">
      <tr>
        <td colspan="3"><span class="style15">MySQL Details</span></td>
      </tr>
      <tr>
        <td><span class="style12">MySQL Host: </span></td>
        <td><input style="width:150px;" name="DBHost" type="text" id="DBHost" value="<? if(isset($_POST['DBHost'])){ echo $_POST['DBHost']; } ELSE { echo 'localhost'; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The host address of your MySQL database, usually localhost');">(?)</a> </span></td>
      </tr>
      <tr>
        <td><span class="style12">MySQL Username:</span></td>
        <td><input style="width:150px;" name="DBUser" type="text" id="DBUser" value="<? if(isset($_POST['DBUser'])){ echo $_POST['DBUser']; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The username used to access your MySQL database');">(?)</a> </span></td>
      </tr>
      <tr>
        <td><span class="style12">MySQL Password:</span></td>
        <td><input style="width:150px;" name="DBPass" type="password" id="DBPass" value="<? if(isset($_POST['DBPass'])){ echo $_POST['DBPass']; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The password used to access your MySQL database');">(?)</a> </span></td>
      </tr>
      <tr>
        <td><span class="style12">MySQL Database Name: </span></td>
        <td><input style="width:150px;" name="DBName" type="text" id="DBName" value="<? if(isset($_POST['DBName'])){ echo $_POST['DBName']; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The name of your database, you must have first created this.');">(?)</a> </span></td>
      </tr>
      <tr>
        <td><span class="style12">MySQL Table Prefix: </span></td>
        <td><input style="width:150px;" name="DBPre" type="text" id="DBPre" value="<? if(isset($_POST['DBPre'])){ echo $_POST['DBPre']; } else { echo 'man_'; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The text that follows the table names, not required');">(?)</a> </span></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="3"><span class="style15">Admin Details </span></td>
      </tr>
      <tr>
        <td><span class="style12">Admin Username: </span></td>
        <td><input style="width:150px;" name="adminuser" type="text" id="adminuser" value="<? if(isset($_POST['adminuser'])){ echo $_POST['adminuser']; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The username that will be used when managing the site');">(?)</a> </span></td>
      </tr>
      <tr>
        <td><span class="style12">Admin Password: </span></td>
        <td><input style="width:150px;" name="adminpass" type="password" id="adminpass" value="<? if(isset($_POST['adminpass'])){ echo $_POST['adminpass']; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The password that will be used when managing the site');">(?)</a> </span></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input style="width:150px;" name="Submit" type="submit" value="Install"></td>
        <td>&nbsp;</td>
      </tr>
    </table>
	</td></tr></table>
  </form>
  <span class="footer style1">  <br>
  <br>
  &copy; 2007 <a href="http://www.kubelabs.com/phpmanualcreator.php">Kubelabs.com</a></span>
</div>
</body>
</html>
Return current item: PHP Manual Creator