Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Contests can now be run for a predefined period #18

Merged
merged 2 commits into from
Jun 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
else
include('header.php');
connectdb();
date_default_timezone_set('UTC');
?>
<li class="active"><a href="#">Admin Panel</a></li>
<li><a href="users.php">Users</a></li>
Expand Down Expand Up @@ -43,13 +44,14 @@
<div>
<form method="post" action="update.php">
<?php
$query = "SELECT name, accept, c, cpp, java, python FROM prefs";
$query = "SELECT name, start, end, c, cpp, java, python FROM prefs";
$result = mysql_query($query);
$fields = mysql_fetch_array($result);
?>
<input type="hidden" name="action" value="settings"/>
Name of event: <input name="name" type="text" value="<?php echo($fields['name']);?>"/><br/>
<input name="accept" type="checkbox" <?php if($fields['accept']==1) echo("checked=\"true\"");?>/> <span class="label label-important">Accept submissions</span><br/>
Start Time in UTC (dd/mm/yy hh:mm:ss): <input name="start" type="text" value="<?php echo(date('d/m/y H:i:s',$fields['start']));?>"/><br/>
End Time in UTC (dd/mm/yy hh:mm:ss): <input name="end" type="text" value="<?php echo(date('d/m/y H:i:s',$fields['end']));?>"/><br/>
<h1><small>Languages</small></h1>
<input name="c" type="checkbox" <?php if($fields['c']==1) echo("checked=\"true\"");?>/> C<br/>
<input name="cpp" type="checkbox" <?php if($fields['cpp']==1) echo("checked=\"true\"");?>/> C++<br/>
Expand Down
8 changes: 6 additions & 2 deletions admin/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
include('../functions.php');
connectdb();
date_default_timezone_set('UTC');
if(isset($_POST['action'])){
if($_POST['action']=='email') {
// update the admin email
Expand Down Expand Up @@ -39,12 +40,15 @@
if(trim($_POST['name']) == "")
header("Location: index.php?derror=1");
else {
if($_POST['accept']=='on') $accept=1; else $accept=0;
list($day, $month, $year, $hour, $minute) = split('[/ :]', $_POST['start']);
$start=mktime($hour, $minute,0, $month, $day, $year);
list($day, $month, $year, $hour, $minute) = split('[/ :]', $_POST['end']);
$end=mktime($hour, $minute,0, $month, $day, $year);
if($_POST['c']=='on') $c=1; else $c=0;
if($_POST['cpp']=='on') $cpp=1; else $cpp=0;
if($_POST['java']=='on') $java=1; else $java=0;
if($_POST['python']=='on') $python=1; else $python=0;
mysql_query("UPDATE prefs SET name='".mysql_real_escape_string($_POST['name'])."', accept=$accept, c=$c, cpp=$cpp, java=$java, python=$python");
mysql_query("UPDATE prefs SET name='".mysql_real_escape_string($_POST['name'])."', start=$start, end=$end, c=$c, cpp=$cpp, java=$java, python=$python");
header("Location: index.php?changed=1");
}
} else if($_POST['action']=='addproblem') {
Expand Down
15 changes: 11 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@
if(isset($_GET['success']))
echo("<div class=\"alert alert-success\">\nCongratulations! You have solved the problem successfully.\n</div>");
?>
Below is a list of available problems for you to solve.<br/><br/>
<ul class="nav nav-list">
<li class="nav-header">AVAILABLE PROBLEMS</li>
<?php
<?php
$query = "SELECT * FROM prefs";
$result = mysql_query($query);
$accept = mysql_fetch_array($result);
if($accept['start']>time())
echo("<div class=\"alert alert-error\">\nThe contest has not started yet.\n</div>");
else{
echo"Below is a list of available problems for you to solve.<br/><br/>";
echo"<ul class=\"nav nav-list\">";
echo"<li class=\"nav-header\">AVAILABLE PROBLEMS</li>";
// list all the problems from the database
$query = "SELECT * FROM problems";
$result = mysql_query($query);
Expand All @@ -58,6 +64,7 @@
echo("<li><a href=\"index.php?id=".$row['sl']."\">".$row['name'].$tag."</a></li>\n");
}
}
}
?>
</ul>
<?php
Expand Down
7 changes: 4 additions & 3 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
// create the preferences table
mysql_query("CREATE TABLE IF NOT EXISTS `prefs` (
`name` varchar(30) NOT NULL,
`accept` int(11) NOT NULL,
`start` int(11) NOT NULL,
`end` int(11) NOT NULL,
`c` int(11) NOT NULL,
`cpp` int(11) NOT NULL,
`java` int(11) NOT NULL,
`python` int(11) NOT NULL,
`formula` text NOT NULL
)");
// fill it with default preferences
mysql_query("INSERT INTO `prefs` (`name`, `accept`, `c`, `cpp`, `java`, `python`, `forumla`) VALUES
('Codejudge', 1, 1, 1, 1, 1,'\$score = \$points / \$attempts')");
mysql_query("INSERT INTO `prefs` (`name`, `start`, 'end', `c`, `cpp`, `java`, `python`, `forumla`) VALUES
('Codejudge', 01/01/70 00:00:00, 01/01/70 00:00:00, 1, 1, 1,'\$score = \$points / \$attempts')");
// create the problems table
mysql_query("CREATE TABLE IF NOT EXISTS `problems` (
`sl` int(11) NOT NULL AUTO_INCREMENT,
Expand Down
6 changes: 4 additions & 2 deletions solve.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
$query = "SELECT status FROM users WHERE username='".$_SESSION['username']."'";
$result = mysql_query($query);
$status = mysql_fetch_array($result);
if($accept['accept'] == 0)
if($accept['end'] < time())
echo("<div class=\"alert alert-error\">\nSubmissions are closed now!\n</div>");
if($status['status'] == 0)
echo("<div class=\"alert alert-error\">\nYou have been banned. You cannot submit a solution.\n</div>");
if($accept['start']>time())
header('location:index.php');
?>
<h1><small>Submit Solution</small></h1>
<?php
Expand Down Expand Up @@ -105,7 +107,7 @@
Filename: <input class="span8" type="text" id="filename" name="filename" value="<?php if(!($num == 0)) echo($fields['filename']);?>"/>
<br/>Type your program below:<br/><br/>
<textarea style="font-family: mono; height:400px;" class="span9" name="soln" id="text"><?php if(!($num == 0)) echo($fields['soln']);?></textarea><br/>
<?php if($accept['accept'] == 1 and $status['status'] == 1) echo("<input type=\"submit\" value=\"Run\" class=\"btn btn-primary btn-large\"/>");
<?php if($accept['end'] > time() and $status['status'] == 1) echo("<input type=\"submit\" value=\"Run\" class=\"btn btn-primary btn-large\"/>");
else echo("<input type=\"submit\" value=\"Run\" class=\"btn disabled btn-large\" disabled=\"disabled\"/>");
?>
<span class="label label-info">You are allowed to use any of the following languages:
Expand Down