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


// Version here, so it's easy to change
$version = 1.2;


// Do not show notices
error_reporting(E_ALL ^ E_NOTICE);


// Include config.php, needed for database
require_once dirname(dirname(__FILE__)) . "/config.php";


// feed.php is used in so many files that you can include it here
require_once dirname(__FILE__) . "/feed.php";

// header.php is used in so many files that you can include it here
require_once dirname(__FILE__) . "/header.php";

// Connect to database
$db_link = mysql_connect($db_host, $db_user, $db_passwd);
mysql_select_db($db_name, $db_link);


// Fetch the configuration data
$sql = 'SELECT `name`, `value` FROM `contest_config`';
$query = mysql_query($sql);
while($row = mysql_fetch_row($query))
{
	$result[$row[0]] = $row[1];
}


// Set all the global variables


// Language
if(isset($_GET['language']))
{
	$language = $_GET['language'];
	setcookie('fretsweb_language', $language, time() + 31536000/*one year*/ , '/');
}
elseif(isset($_COOKIE['fretsweb_language']))
{
	$language = $_COOKIE['fretsweb_language'];
}
else
{
	$language = $result['language'];
}


// Title
$title = $result['title'];


// Admin password
$admin_passwd = $result['admin_password'];


// Allow all players
if(strtolower($result['allowallplayers']) == 'true')
	$allowallplayers = true;
else
	$allowallplayers = false;


// Allow join requests
if(strtolower($result['allowjoinrequests']) == 'true')
	$allowjoinrequests = true;
else
	$allowjoinrequests = false;


// Allow song requests
if(strtolower($result['allowsongrequests']) == 'true')
	$allowsongrequests = true;
else
	$allowsongrequests = false;


// Show upload URl
if(strtolower($result['showuploadurl']) == 'true')
	$showuploadurl = true;
else
	$showuploadurl = false;


// Enable forum
if(strtolower($result['allowforum']) == 'true')
	$allowforum = true;
else
	
	$allowforum = false;

// Contest points array
$ContestPoints = explode(',',$result['contest_points']);


// Feed priority
if(isset($result['feed']))
	$feed = $result['feed'];
else
{
	$sql = "INSERT INTO `contest_config` (`name`, `value`) VALUES  ('feed', '4')";
	mysql_query($sql);
	$feed = 4;
}


// Set allowforum if it doesn't exists in database
if(isset($result['allowforum']))
	$allowforum = $result['allowforum'];
else
{
	$sql = "INSERT INTO `contest_config` (`name`, `value`) VALUES  ('allowforum', 'true')";
	mysql_query($sql);
	$allowforum = true;
}

if(!isset($result['moderator_password']))
// Make it that a moderator password is set if it didn't exist, also make it unguessable.
// Just make a hash of a random integer, 40 bytes, and unpredictable
{
	$new_mod_passwd = sha1(rand());
	$sql = "INSERT INTO `contest_config` (`name`, `value`) VALUES ('moderator_password', '$new_mod_passwd')";
	mysql_query($sql);
	$result['moderator_password'] = $new_mod_passwd;
}
$moderator_passwd = $result['moderator_password'];

if($feed > 0)
	$head_feed = '<link rel="alternate" type="application/rss+xml" title="Fretsweb RSS-feed" href="feed.php">';
else
	$head_feed = '';

//Patch the version if needed
if(file_exists(dirname(__FILE__) . "/patch.php"))
	require_once dirname(__FILE__) . "/patch.php";

//Unset the variables, we don't need them and they'll only cause trouble.
unset($sql, $query, $row, $result);

?>
Return current item: Fretsweb