Location: PHPKode > projects > Fretsweb > fretsweb-1.2/fretsweb/install.php
<?php

/*
Fretsweb - A Frets on Fire chart server
Copyright (C) 2009  Daan Sprenkels

This program 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, either version 3 of the License, or
(at your option) any later version.

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, see <http://www.gnu.org/licenses/>.
*/


// Set the error reporting: no notices
error_reporting(E_ALL ^ E_NOTICE);


// Include log so we can log the installation
include_once "admin/log.php";


// If config.php is set, then Fretsweb is already installed
if(file_exists("config.php"))
{
	header('location: admin');
	die('Already installed!');
}


// Session start needed for $_SESSION['config_file']
session_start();


// Send headers for content-type
header('Content-Type: text/html; charset=utf-8');


// Check if the form has been submitted
if(isset($_POST['installsubmit']))
{
	if(strlen($_POST['adminpasswd']) >= 4)
	{
		if($_POST['adminpasswd'] == $_POST['adminpasswdc'] && $_POST['dbpasswd'] == $_POST['dbpasswdc'])
		{
			$db_host = $_POST['dbhost'];
			$db_user = $_POST['dbuser'];
			$db_passwd = $_POST['dbpasswd'];
			$db_name = $_POST['dbname'];
			// Set a config file, which can be downloaded in install2.php
			$_SESSION['config_file'] = '<?php

// This is the database host
$db_host = "' . $db_host . '";

// Database username (like root)
$db_user = "' . $db_user . '";

// Database password.
// Don\'t worry, this will never be shown
$db_passwd = "' . $db_passwd . '";

// Database name
$db_name = "' . $db_name . '";

?>';
			$db_link = @mysql_connect($db_host, $db_user, $db_passwd);
			// Check if the mysql_information is valid
			if(@mysql_select_db($db_name, $db_link))
			{
				// $newpasswd will be needed in `contest_config`
				$newpasswd = $_POST['adminpasswd'];
				//---- Begin installing database


// Table `contest_config`

// Create `contest_config`
mysql_query("DROP TABLE IF EXISTS `contest_config`");
$sql = "CREATE TABLE `contest_config` (
		`name` VARCHAR( 80 ) NOT NULL PRIMARY KEY,
		`value` VARCHAR( 512 ) NOT NULL
	)";
mysql_query($sql) or die("Cannot create table `contest_config`: " . mysql_error());

// Fill `contest_config`
$sql = "INSERT INTO `contest_config` (`name`, `value`) VALUES
	('title', 'Random text'),
	('admin_password', '$newpasswd'),
	('contest_points', '25, 20, 18, 16, 14, 12, 10, 8, 7, 6, 5, 4, 3, 2, 1'),
	('allowallplayers', 'false'),
	('showuploadurl', 'false'),
	('allowjoinrequests', 'true'),
	('allowsongrequests', 'true'),
	('contest_status', 'closed'),
	('allowforum', 'true'),
	('feed', '4'),
	('version', '1.2'),
	('language', 'en');";
mysql_query($sql) or die("Cannot fill table `contest_config`: " . mysql_error());


// Table `contest_forum`
mysql_query("DROP TABLE IF EXISTS `contest_forum`");
// Create `contest_forum`
$sql = "CREATE TABLE `contest_forum` (
		`name` VARCHAR( 100 ) NOT NULL,
		`text` TEXT NOT NULL ,
		`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
	)";
mysql_query($sql) or die( "Cannot create table `contest_forum`: " . mysql_error());
// Fill `contest_forum` with a starting message
$sql = "INSERT INTO `contest_forum` (`name`, `text`) VALUES
	('Fretsweb', 'Hello everyone!\nIt seems that Fretsweb has been installed. Congratulations! On this forum everyone can post his or her message. It\'s the main road to coming in contact with your Administrator, have fun! Have questions the Administrator can\'t solve? Send them to me at hide@address.com')";
mysql_query($sql) or die("Cannot fill table `contest_forum`: " . mysql_error());


// Table `contest_logs`
mysql_query("DROP TABLE IF EXISTS `contest_logs`");
// Create `contest_logs`
$sql = "CREATE TABLE `contest_logs` (
		`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
		`timestamp` TIMESTAMP,
		`text` VARCHAR( 200 ) NOT NULL
	)";
mysql_query( $sql ) or die( "Cannot create table `contest_logs`: " . mysql_error() );


// Table `contest_news`
mysql_query("DROP TABLE IF EXISTS `contest_news`");
// Create `contest_news`
$sql = "CREATE TABLE `contest_news` (
		`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		`title` VARCHAR( 100 ) NOT NULL,
		`text` TEXT NOT NULL, 
		`code` TEXT NOT NULL,
		`priority` TINYINT( 1 ) NOT NULL ,
		`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
	)";
mysql_query($sql) or die("Cannot create table `contest_news`: " . mysql_error());
// And fill it with a first post
$sql = "INSERT INTO `contest_news` (`title`, `text`, `code`, `priority`) VALUES ('Fretsweb install', 'Fretsweb is installed. Now you have this news page/feed. Here you can see all Fretsweb\'s updates.', '9')";
mysql_query($sql);


// Table `contest_players`
mysql_query( "DROP TABLE IF EXISTS `contest_players`" );
// Create `contest_players`
$sql= "CREATE TABLE `contest_players` (
		`name` VARCHAR( 100 ) NOT NULL PRIMARY KEY,
		`Supaeasy` BOOL NOT NULL,
		`Easy` BOOL NOT NULL,
		`Medium` BOOL NOT NULL,
		`Amazing` BOOL NOT NULL,
		`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
		`joinrequest` BOOL NOT NULL DEFAULT '0'
	)";
mysql_query($sql) or die("Cannot create table `contest_players`: " . mysql_error());


// Table `contest_scores`
mysql_query( "DROP TABLE IF EXISTS `contest_scores`" );
// Create `contest_scores`
$sql = "CREATE TABLE `contest_scores` (
		`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		`hash` VARCHAR( 40 ) NOT NULL, 
		`difficulty` VARCHAR( 50 ) NOT NULL ,
		`score` INT NOT NULL ,
		`stars` INT NOT NULL ,
		`notes_hit` INT(11) NOT NULL,
		`notes_all` INT(11) NOT NULL,
		`note_streak` INT(11) NOT NULL,
		`original_score` INT(11) NOT NULL,
		`version` VARCHAR(80) NOT NULL,
		`name` VARCHAR( 100 ) NOT NULL,
		`score_hash` VARCHAR(80) NOT NULL,
		`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
		UNIQUE (
			`hash` ,
 			`difficulty` ,
 			`name` )
	)";
mysql_query($sql) or die( "Cannot create table `contest_scores`: " . mysql_error() );


// Table `contest_songs`
mysql_query( "DROP TABLE IF EXISTS `contest_songs`" );
// Create `contest_songs`
$sql = "CREATE TABLE `contest_songs` (
		`hash` VARCHAR( 40 ) NOT NULL PRIMARY KEY,
		`artist` TEXT NOT NULL ,
		`title` TEXT NOT NULL ,
		`link` TEXT NOT NULL ,
		`request` TINYINT(1) NOT NULL DEFAULT '0'
	)";
mysql_query($sql) or die ("Cannot create table `contest_songs`: " . mysql_error());


// Add the starting songs... (bangbang, defy, twibmpg)
// (It's a pack)
$file_handle = fopen('songdir/start/pack.sql', 'r');
$file_read = fread($file_handle, filesize('songdir/start/pack.sql'));
mysql_query($file_read);
fclose($file_handle);
				//---- End installing database
				
				// Check if the data is stored by checking if the admin passwd is set
				$sql = "SELECT `value` FROM `contest_config` WHERE `name`='admin_password'";
				$query = mysql_query($sql);
				$rows = mysql_fetch_row($query);
				$passwd = $rows[0];
				if($passwd == $newpasswd)
				{
					// Succes! Go to install2.php
					header('location: install2.php');
					clog("Installation...");
					unset($fh);
					// Close database link
					mysql_close($db_link);
					die();
				}
				else
				{
					$info = "<p class=\"info\">Oh, no! Something went terribly wrong! I would not know what happened, really! Please contact me if you get this error at hide@address.com</p><p class=\"info\">" . mysql_error().'</p>';
				}
			}
			else
			{
				$info = "<p class=\"info\">Wrong database information, or the filled in database does not exist.</p>";
			}
		}
		else
		{
			$info = "<p class=\"info\">Some passwords are not identical!</p>";
		}
	}
	else
	{
		$info = "<p class=\"info\">Admin password must be 4 or more digits!</p>";
	}
}

?><html>
 <head>
  <title>Fretsweb</title>
  <link rel="stylesheet" href="css.php" type="text/css">
  <link rel="icon" href="images/favicon.png">
 </head>
 <body>
  <div id="page">
   <div id="content">
    <p class="logoContainer">
     <img id="logo" src="images/logo.png" alt="Frets on Fire">
    </p>
    <h1>Fretsweb installation</h1>
    <?php
    
// Write $info if needed
if(isset($info))
{
	echo $info;
}

    ?>
    <p>Hello, I'm Daan. I'll be guiding you through this installation.</p>
    <ol>
     <li>
      <p>
       Upload everything to your webserver. You probably have done this already if you see this.
      </p>
     </li>
     <li>
      <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
       <p>
        Fill in these informations and click continue:
       </p>
       <p>
        <dl>
         <dt>
          Mysql host:
         </dt>
         <dd>
          <input type="text" name="dbhost">
         </dd>
         <dt>
          Mysql username:
         </dt>
         <dd>
          <input type="text" name="dbuser">
         </dd>
         <dt>
          Mysql password (twice the same):
         </dt>
         <dd>
          <input type="password" name="dbpasswd">
          <input type="password" name="dbpasswdc">
         </dd>
         <dt>
          Database name:
         </dt>
         <dd>
          <input type="text" name="dbname">
          If this database does not exist, create it first!
         </dd>
         <dt>
          Admin password (twice the same):
         </dt>
         <dd>
          <input type="password" name="adminpasswd">
          <input type="password" name="adminpasswdc">
         </dd>
         <dt/>
         <dd>
          <input type="submit" name="installsubmit" value="Continue">
         </dd>
        </dl>
       </p>
      </form>
     </li>
    </ol>
   </div>
   <div id="footer">
    <div class="menuPane">
     FretsWeb 1.2 by Daan Sprenkels<br/>hide@address.com
    </div>
   </div>
  </div>
 </body>
</html>
Return current item: Fretsweb