Location: PHPKode > projects > Fretsweb > fretsweb-1.2/fretsweb/admin/init_db.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/>.
*/

require_once "common.php";

//Login Test
session_start();
if($_SESSION['in'] < 2)
{
	header('location: login.php?need=admin');
	die();
}

?>
<html>
<head>
<title>Init DB</title>
<link href="../css.php" rel="stylesheet" type="text/css" />
<link href="../images/favicon.png" rel="icon">
</head>
<body><center>
<h2>Reset database</h2>
<?php
include_once "log.php";
include_once "backup.php";

// called after a form submission?
if( array_key_exists('_submit_check', $_POST) ) 
{	
	mysql_query( "DROP TABLE IF EXISTS `contest_scores`" );
	mysql_query( "DROP TABLE IF EXISTS `contest_songs`" );
	mysql_query( "DROP TABLE IF EXISTS `contest_players`" );
	mysql_query( "DROP TABLE IF EXISTS `contest_logs`" );
	mysql_query( "DROP TABLE IF EXISTS `contest_config`" );
	mysql_query( "DROP TABLE IF EXISTS `contest_forum`" );
	mysql_query( "DROP TABLE IF EXISTS `contest_news`" );

	//create the 'forum' table
	$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() );
	$sql = "INSERT INTO `contest_forum` (`name`,`text`) VALUES ('Fretsweb','Hello everyone!\nIt seems that the forum has been deleted. 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!')";
	mysql_query( $sql );
	
	// create the 'songs' table
	$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'" );

	// create the 'players' table
	$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'" );

	// create the 'scores' table
	$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'" );
	
	//Create the news table, used for RSS feeds.
	$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 ('Database reset', 'The database is reset, therefore is the news also reset. You\'ll see the news here.', 'usermessage', '9')";
	mysql_query($sql);
	
	// create the 'logs' table
	$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'" );
	
	// create the 'config' table
	$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'" );

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

	echo( "<p>Database initialization successful</p>" );
	clog("DB RESET");
}
?>

<p>Do you really want to push that button? Are you sure, really sure, entirely sure?
Pushing it will remove all the data from the database! Are you sure you made your backup? Don't do it. Really. Many lives depend on it. </p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
	<input type="hidden" name="_submit_check" value="1"/> 
	<input type="submit" value="Do as I say! Reset the database!">
</form>

<p><b><a href="index.php">Back to main administration panel</a></b><p>
</center></body>
</html>

<?php
	// close DB
	mysql_close( $db_link ); 
?>

Return current item: Fretsweb