Location: PHPKode > projects > Butterfly Organizer > install/index.php
<?php
/*
Butterfly Organizer
Copyright (C) 2007-2008 Butterfly Media Romania

This file is part of Butterfly Organizer.

Butterfly Organizer is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

error_reporting(E_ALL);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Butterfly Organizer Installation</title>
<style type="text/css">
<!--
body, table, td {
	background-color:#ffffff;
	color: #666666;
	font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
	font-size: 9pt
}

-->
</style>
</head>

<body>
<h1>Butterfly Organizer Installation</h1>

<?php

if(isset($_POST['submit'])) {
	$dbhost = $_POST['dbhost'];
	$dbname = $_POST['dbname'];
	$dbuser = $_POST['dbuser'];
	$dbpass = $_POST['dbpass'];

	$database = mysql_connect($dbhost, $dbuser, $dbpass);
	mysql_select_db($dbname, $database) or die('DATABASE ERROR! COULD NOT CONNECT TO DATABASE!');

	echo '<h2>Installation progress</h2>';

	echo 'Initializing installation;<br />';
	$sql = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';";
	$result = mysql_query($sql);

	echo 'Creating tables;<br />';
	$sql = "CREATE TABLE IF NOT EXISTS `contacts` (`id` mediumint(9) NOT NULL auto_increment,`firstname` tinytext,`lastname` tinytext,`address` tinytext,`city` tinytext,`phone` tinytext,`email` tinytext,`notes` text NOT NULL, PRIMARY KEY  (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=19;";
	$result = mysql_query($sql);
	$sql = "CREATE TABLE IF NOT EXISTS `notes` (`id` int(10) unsigned NOT NULL auto_increment,`text` varchar(100) NOT NULL, PRIMARY KEY  (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=17;";
	$result = mysql_query($sql);
	$sql = "CREATE TABLE IF NOT EXISTS `settings` (`id` int(11) NOT NULL auto_increment,`owner` text NOT NULL,`color_used_account` text NOT NULL,`color_empty_account` text NOT NULL,PRIMARY KEY  (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4;";
	$result = mysql_query($sql);

	echo 'Saving settings;<br />';
	$sql = "INSERT INTO `settings` (`id`, `owner`, `color_used_account`, `color_empty_account`) VALUES (1, 'Butterfly Media Romania', '#333333', '#CCCCCC');";
	$result = mysql_query($sql);

	echo 'Adding sample data;<br />';
	$sql = "CREATE TABLE IF NOT EXISTS `test_category` (`id` int(11) NOT NULL auto_increment,`date` text NOT NULL,`reference` text NOT NULL,`name` text NOT NULL,`url` text NOT NULL,`username` text NOT NULL,`password` text NOT NULL,`notes` text NOT NULL,`other` text NOT NULL,`lastmodified` text NOT NULL, PRIMARY KEY  (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2;";
	$result = mysql_query($sql);
	$sql = "INSERT INTO `test_category` (`id`, `date`, `reference`, `name`, `url`, `username`, `password`, `notes`, `other`, `lastmodified`) VALUES (1, '05.04.2008', 'testaccount', 'Test Account', 'http://www.google.com', 'username', 'password', 'some notes here', 'maybe I should find some <lorem ipsum> text', 'April 9, 2008, 11:14 pm');";
	$result = mysql_query($sql);
	$sql = "INSERT INTO `contacts` (`id`, `firstname`, `lastname`, `address`, `city`, `phone`, `email`, `notes`) VALUES (17, 'Ciprian', 'Popescu', '26 Whiskey Street', 'Constanta', '0040722783992', 'hide@address.com', 'this is a test contact to see the behaviour of contact manager');";
	$result = mysql_query($sql);
	$sql = "INSERT INTO `notes` (`id`, `text`) VALUES (7, 'My !TODO! task.'),(8, 'Release *Butterfly Organizer*.'),(9, 'this is my test'),(15, 'azi tres saas');";
	$result = mysql_query($sql);

	echo '<span style="color:#00ff00; font-weight:bold">Success!</span><br />';

	echo '<h2>What now?</h2>';
	echo '<h5><a href="../">Go to Butterfly Organizer index screen</a>.</h5>';
}
else {
?>
<h5 style="text-align:justify">Welcome to Butterfly Organizer. Please complete the following form with your database details, and press the &quot;<strong>Install</strong>&quot; button.</h5>

<h2 style="text-align:left">Step 1</h2>
<h5 style="text-align:justify">Create a database called &laquo;<em>organizer</em>&raquo;.</h5>

<?php
	echo "<form method='post' action='index.php'>";
	echo "<table>";
	echo "<tr><td>Database host:</td><td><input type='text' name='dbhost' value='localhost' /></td></tr>";
	echo "<tr><td>Database name:</td><td><input type='text' name='dbname' value='organizer' /></td></tr>";
	echo "<tr><td>Database user:</td><td><input type='text' name='dbuser' value='root' /></td></tr>";
	echo "<tr><td>Database password:</td><td><input type='text' name='dbpass' value='' /></td></tr>";
	echo "<tr><td colspan='2'><input type='submit' id='submit' name='submit' value='Install' /></td></tr>";
	echo "</table>";
	echo "</form>";
?>

<h2 style="text-align:left">Step 2</h2>
<h5 style="text-align:justify">CHMOD 777 <em>lists/</em> and <em>log/</em> directories.</h5>

<h2 style="text-align:left">Step 3</h2>
<h5 style="text-align:justify">You are ready to run Butterfly Organizer!</h5>

<h2 style="text-align:left">Misc</h2>
<h5 style="text-align:justify">Read carefully the Help section to learn all the features of Butterfly Organizer.</h5>

<?php }?>
</body>
</html>
Return current item: Butterfly Organizer