Location: PHPKode > projects > Fretsweb > fretsweb-1.2/fretsweb/admin/status.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";
include_once "log.php";

function contest_status_bool()
{
	$co = false;
	include dirname(__FILE__) . "/../lang/".$GLOBALS['language'].".php";
	$sql = "SELECT `value` FROM `contest_config` WHERE `name` = 'contest_status'";
	$query = mysql_query($sql);
	if(mysql_num_rows($query) <= 0)
		mysql_query('INSERT INTO `contest_config` (`name`, `value`) VALUES (`contest_status`,`closed`)');
	$row = mysql_fetch_row($query);
	$cont = $row[0];
	
	if ($cont == 'open')
		$co = true;
	elseif ($cont == 'closed')
		$co = false;
	else
	{
		$contarr = explode('-' , $cont);
		if(time() >= $contarr[0])
			if(time() <= $contarr[1] || $contarr[1] == 0)
				$co = true;
	}
	return $co;
}

function contest_status()
{
	$co = false;
	include dirname(__FILE__) . "/../lang/".$GLOBALS['language'].".php";
	$sql = "SELECT `value` FROM `contest_config` WHERE `name` = 'contest_status'";
	$query = mysql_query($sql);
	if(mysql_num_rows($query) <= 0)
		mysql_query('INSERT INTO `contest_config` (`name`, `value`) VALUES (`contest_status`,`closed`)');
	$row = mysql_fetch_row($query);
	$cont = $row[0];
	
	if ($cont == 'open')
		$co = true;
	elseif ($cont == 'closed')
		$co = false;
	else
	{
		$contarr = explode('-' , $cont);
		if(time() >= $contarr[0])
			if(time() <= $contarr[1] || $contarr[1] == 0)
				$co = true;
	}
	$co = contest_status_bool();
	if( $co == FALSE && isset($contarr[0]) )
		return sprintf($lang["CLOSED_until"], date('Y-m-d, H:i', $contarr[0]));
	elseif( $co == FALSE )
		return $lang["CLOSED"];
	elseif(isset($contarr[1]))
		return sprintf($lang["OPEN_until"], date('Y-m-d, H:i', $contarr[1]));
	else
		return $lang["OPEN"];
}

function contest_status_print()
{
	echo contest_status();
}

function contest_status_open()
{
	// open contest
	$sql = "UPDATE `contest_config` SET `value` = 'open' WHERE `name` = 'contest_status'" ;
	mysql_query($sql);
	clog("Contest opened");
	cfeed('Contest opened', "The contest is opened, if you have configured your uploadurl right, your scores will appear on Fretsweb.\n\nTo get your scores on Fretsweb:\nFirst make sure you have an account on Fretsweb. If joining is enabled, you can use the join page. If not, you need to get in contact with the site admin.\nThen change your uploadurl.\nThen enable your score uploading. (Many persons forget this one.)", 'configchange');
}

function contest_status_close()
{
	$sql = "UPDATE `contest_config` SET `value` = 'closed' WHERE `name` = 'contest_status'" ;
	mysql_query($sql);
	clog("Contest closed");
	cfeed('Contest closed', "The contest is closed, you can't upload anymore.", 'configchange');
}

function set_contest_status($starttime , $endtime)
{
	$sql = "UPDATE `contest_config` SET `value` = '$starttime-$endtime' WHERE `name` = 'contest_status'" ;
	mysql_query($sql);
	clog("Contest timer set from $starttime to $endtime");
}
?>
Return current item: Fretsweb