Example #1
0
function infreeze($cdata, $time)
{
    if (!empty($cdata['freezetime']) && difftime($time, $cdata['freezetime']) > 0 && (empty($cdata['unfreezetime']) || difftime($time, $cdata['unfreezetime']) <= 0)) {
        return TRUE;
    }
    return FALSE;
}
Example #2
0
}
if (!function_exists('curl_init')) {
    error("PHP cURL extension required. Please install the php5-curl package.");
}
if (isset($_REQUEST['fetch'])) {
    $ch = curl_init(ICPCWSCLICS . $contest);
} else {
    $ch = curl_init(ICPCWSSTANDINGS . $contest);
}
curl_setopt($ch, CURLOPT_USERAGENT, "DOMjudge/" . DOMJUDGE_VERSION);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "{$token}:");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json"));
if (isset($_REQUEST['upload'])) {
    if (difftime($cdata['endtime'], now()) >= 0) {
        error("Contest did not end yet. Refusing to upload standings before contest end.");
    }
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    $data = '<?xml version="1.0" encoding="UTF-8"?><icpc computeCitations="1" name="Upload_via_DOMjudge_' . date("c") . '">';
    $teams = $DB->q('SELECT teamid, externalid FROM team
	                 WHERE externalid IS NOT NULL AND enabled=1');
    while ($row = $teams->next()) {
        $totals = $DB->q('MAYBETUPLE SELECT points, totaltime
		                  FROM rankcache_jury
		                  WHERE cid = %i AND teamid = %i', $cid, $row['teamid']);
        if ($totals === null) {
            $totals['points'] = $totals['totaltime'] = 0;
        }
        $rank = calcTeamRank($cdata, $row['teamid'], $totals, TRUE);
Example #3
0
</td></tr>
<tr><td>Restriction:</td><td>
	<?php 
if (is_null($row['restrictionname'])) {
    echo '<i>None</i>';
} else {
    echo '<a href="judgehost_restriction.php?id=' . urlencode($row['restrictionid']) . '">' . htmlspecialchars($row['restrictionname']) . '</a>';
}
?>
</td></tr>
<tr><td>Status:</td><td>
<?php 
if (empty($row['polltime'])) {
    echo "Judgehost never checked in.";
} else {
    $reltime = floor(difftime(now(), $row['polltime']));
    if ($reltime < dbconfig_get('judgehost_warning', 30)) {
        echo "OK";
    } else {
        if ($reltime < dbconfig_get('judgehost_critical', 120)) {
            echo "Warning";
        } else {
            echo "Critical";
        }
    }
    echo ", time since judgehost last checked in: " . printtimediff($row['polltime']) . 's.';
}
?>
</td></tr>
</table>
Example #4
0
     $rows = $DB->q('TABLE SELECT * FROM contest WHERE cid IN (%Ai)', $curcids);
 }
 echo "</legend>\n\n";
 foreach ($rows as $row) {
     $prevchecked = false;
     $hasstarted = difftime($row['starttime'], $now) <= 0;
     $hasended = difftime($row['endtime'], $now) <= 0;
     $hasfrozen = !empty($row['freezetime']) && difftime($row['freezetime'], $now) <= 0;
     $hasunfrozen = !empty($row['unfreezetime']) && difftime($row['unfreezetime'], $now) <= 0;
     $contestname = specialchars(sprintf('%s (%s - c%d)', $row['name'], $row['shortname'], $row['cid']));
     echo "<form action=\"contests.php\" method=\"post\">\n";
     echo addHidden('cid', $row['cid']);
     echo "<fieldset><legend>{$contestname}</legend>\n";
     echo "<table>\n";
     foreach ($times as $time) {
         $haspassed = difftime($row[$time . 'time'], $now) <= 0;
         echo "<tr><td>";
         // display checkmark when done or ellipsis when next up
         if (empty($row[$time . 'time'])) {
             // don't display anything before an empty row
         } elseif ($haspassed) {
             echo "<img src=\"../images/s_success.png\" alt=\"&#10003;\" class=\"picto\" />\n";
             $prevchecked = true;
         } elseif ($prevchecked) {
             echo "…";
             $prevchecked = false;
         }
         echo "</td><td>" . ucfirst($time) . " time:</td><td>" . printtime($row[$time . 'time'], '%Y-%m-%d %H:%M (%Z)') . "</td><td>";
         // Show a button for setting the time to now(), only when that
         // makes sense. E.g. only for end contest when contest has started.
         // No button for 'activate', because when shown by definition always already active
Example #5
0
 * under the GNU GPL. See README and COPYING for details.
 */
require 'init.php';
$title = 'Submit';
if (!isset($_POST['submit'])) {
    header('Location: ./');
    return;
}
if (is_null($cid)) {
    require LIBWWWDIR . '/header.php';
    echo "<p class=\"nodata\">No active contest</p>\n";
    require LIBWWWDIR . '/footer.php';
    exit;
}
$now = now();
if (!checkrole('jury') && difftime($cdata['starttime'], $now) > 0) {
    require LIBWWWDIR . '/header.php';
    echo "<p class=\"nodata\">Contest has not yet started.</p>\n";
    require LIBWWWDIR . '/footer.php';
    exit;
}
/** helper to output an error message. */
function err($string)
{
    // Annoying PHP: we need to import global variables here...
    global $title;
    require LIBWWWDIR . '/header.php';
    echo "<h2>Submit - error</h2>\n\n";
    echo '<div id="uploadstatus">';
    logmsg(LOG_WARNING, $string);
    echo '</div>';
Example #6
0
}
$viewall = TRUE;
// Restore most recent view from cookie (overridden by explicit selection)
if (isset($_COOKIE['domjudge_balloonviewall'])) {
    $viewall = $_COOKIE['domjudge_balloonviewall'];
}
// Did someone press the view button?
if (isset($_REQUEST['viewall'])) {
    $viewall = $_REQUEST['viewall'];
}
dj_setcookie('domjudge_balloonviewall', $viewall);
$refresh = array('after' => 15, 'url' => 'balloons.php');
require LIBWWWDIR . '/header.php';
echo "<h1>Balloon Status</h1>\n\n";
foreach ($cdatas as $cdata) {
    if (isset($cdata['freezetime']) && difftime($cdata['freezetime'], now()) <= 0) {
        echo "<h4>Scoreboard of c{$cdata['cid']} ({$cdata['shortname']}) is now frozen.</h4>\n\n";
    }
}
echo addForm($pagename, 'get') . "<p>\n" . addHidden('viewall', $viewall ? 0 : 1) . addSubmit($viewall ? 'view unsent only' : 'view all') . "</p>\n" . addEndForm();
$contestids = $cids;
if ($cid !== null) {
    $contestids = array($cid);
}
// Problem metadata: colours and names.
if (empty($cids)) {
    $probs_data = array();
} else {
    $probs_data = $DB->q('KEYTABLE SELECT probid AS ARRAYKEY,name,color,cid
	                      FROM problem
	                      INNER JOIN contestproblem USING (probid)
Example #7
0
/**
 * Output a form to send a new clarification.
 * Set respid to a clarid, to make only responses to same
 * sender(s)/recipient(s) or ALL selectable.
 */
function putClarificationForm($action, $respid = NULL, $onlycontest = NULL)
{
    $cdatas = getCurContests(TRUE);
    if (isset($onlycontest)) {
        $cdatas = array($onlycontest => $cdatas[$onlycontest]);
    }
    $cids = array_keys($cdatas);
    if (empty($cids)) {
        echo '<p class="nodata">No active contests</p>';
        return;
    }
    require_once 'forms.php';
    global $DB;
    ?>

<script type="text/javascript">
<!--
function confirmClar() {
<?php 
    if (IS_JURY) {
        ?>
	var sendto_field = document.forms['sendclar'].sendto;
	var sendto = sendto_field.value;
	var sendto_text = sendto_field.options[sendto_field.selectedIndex].text;

	if ( sendto=='domjudge-must-select' ) {
		alert('You must select a recipient for this clarification.');
		return false;
	}
	return confirm("Send clarification to " + sendto_text + "?");
<?php 
    } else {
        ?>
	return confirm("Send clarification request to Jury?");
<?php 
    }
    ?>
}
// -->
</script>

<?php 
    echo addForm($action, 'post', 'sendclar');
    echo "<table>\n";
    if ($respid) {
        $clar = $DB->q('MAYBETUPLE SELECT c.*, t.name AS toname, f.name AS fromname
		                FROM clarification c
		                LEFT JOIN team t ON (t.teamid = c.recipient)
		                LEFT JOIN team f ON (f.teamid = c.sender)
		                WHERE c.clarid = %i', $respid);
    }
    if (IS_JURY) {
        // list all possible recipients in the "sendto" box
        echo "<tr><td><b><label for=\"sendto\">Send to</label>:</b></td><td>\n";
        if (!empty($respid)) {
            echo addHidden('id', $respid);
        }
        $options = array('domjudge-must-select' => '(select...)', '' => 'ALL');
        if (!$respid) {
            $teams = $DB->q('KEYVALUETABLE SELECT teamid, name
			                 FROM team
			                 ORDER BY categoryid ASC, team.name COLLATE utf8_general_ci ASC');
            $options += $teams;
        } else {
            if ($clar['sender']) {
                $options[$clar['sender']] = $clar['fromname'] . ' (t' . $clar['sender'] . ')';
            } else {
                if ($clar['recipient']) {
                    $options[$clar['recipient']] = $clar['toname'] . ' (t' . $clar['recipient'] . ')';
                }
            }
        }
        echo addSelect('sendto', $options, 'domjudge-must-select', true);
        echo "</td></tr>\n";
    } else {
        echo "<tr><td><b>To:</b></td><td>Jury</td></tr>\n";
    }
    // Select box for a specific problem (only when the contest
    // has started) or general issue.
    $options = array();
    foreach ($cdatas as $cid => $cdata) {
        $row = $DB->q('TUPLE SELECT CONCAT(cid, "-general") AS c
		               FROM contest WHERE cid = %i', $cid);
        if (IS_JURY && count($cdatas) > 1) {
            $options[$row['c']] = "{$cdata['shortname']} - General issue";
        } else {
            $options[$row['c']] = "General issue";
        }
        if (difftime($cdata['starttime'], now()) <= 0) {
            $problem_options = $DB->q('KEYVALUETABLE SELECT CONCAT(cid, "-", probid),
				                             CONCAT(shortname, ": ", name) as name
				        FROM problem
				        INNER JOIN contestproblem USING (probid)
				        WHERE cid = %i AND allow_submit = 1
				        ORDER BY shortname ASC', $cid);
            if (IS_JURY && count($cdatas) > 1) {
                foreach ($problem_options as &$problem_option) {
                    $problem_option = $cdata['shortname'] . ' - ' . $problem_option;
                }
                unset($problem_option);
            }
            $options += $problem_options;
        }
    }
    echo "<tr><td><b>Subject:</b></td><td>\n" . addSelect('problem', $options, $respid ? $clar['cid'] . '-' . $clar['probid'] : 'general', true) . "</td></tr>\n";
    ?>
<tr>
<td><b><label for="bodytext">Text</label>:</b></td>
<td><?php 
    $body = "";
    if ($respid) {
        $text = explode("\n", wrap_unquoted($clar['body']), 75);
        foreach ($text as $line) {
            $body .= "> {$line}\n";
        }
    }
    echo addTextArea('bodytext', $body, 80, 10, 'required');
    ?>
</td></tr>
<tr>
<td>&nbsp;</td>
<td><?php 
    echo addSubmit('Send', 'submit', 'return confirmClar()');
    ?>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
<!--
document.forms['sendclar'].bodytext.focus();
document.forms['sendclar'].bodytext.select();
// -->
</script>
<?php 
}
Example #8
0
$from = $cdata['starttime'];
$workcontest = $DB->q($query, $now, $from, $from);
$clen = difftime($now, $cdata['starttime']);
if ($res->count() == 0) {
    echo "<p class=\"nodata\">No judgehosts defined</p>\n\n";
} else {
    echo "<table class=\"list sortable\">\n<thead>\n" . "<tr><th scope=\"col\">hostname</th>" . "<th scope=\"col\">active</th>" . "<th class=\"sorttable_nosort\">status</th>" . "<th class=\"sorttable_nosort\">restriction</th>" . "<th class=\"sorttable_nosort\">load</th></tr>\n" . "</thead>\n<tbody>\n";
    while ($row = $res->next()) {
        $link = '<a href="judgehost.php?id=' . urlencode($row['hostname']) . '">';
        echo "<tr" . ($row['active'] ? '' : ' class="disabled"') . "><td>" . $link . printhost($row['hostname']) . '</a>' . "</td><td class=\"tdcenter\">" . $link . printyn($row['active']) . "</a></td>";
        echo "<td class=\"tdcenter ";
        if (empty($row['polltime'])) {
            echo "judgehost-nocon";
            echo "\" title =\"never checked in\">";
        } else {
            $reltime = floor(difftime($now, $row['polltime']));
            if ($reltime < dbconfig_get('judgehost_warning', 30)) {
                echo "judgehost-ok";
            } else {
                if ($reltime < dbconfig_get('judgehost_critical', 120)) {
                    echo "judgehost-warn";
                } else {
                    echo "judgehost-crit";
                }
            }
            echo "\" title =\"last checked in {$reltime} seconds ago\">";
        }
        echo $link . CIRCLE_SYM . "</a></td>";
        echo "<td>" . $link . (is_null($row['name']) ? '<i>none</i>' : $row['name']) . '</a></td>';
        echo "<td title=\"load during the last 2 and 10 minutes and the whole contest\">" . $link . sprintf('%.2f&nbsp;%.2f&nbsp;%.2f', @$work2min[$row['hostname']] / (2 * 60), @$work10min[$row['hostname']] / (10 * 60), @$workcontest[$row['hostname']] / $clen) . "</a></td>";
        if (IS_ADMIN) {
Example #9
0
/**
 * Outputs a problem description text, either as download or inline.
 * It is assumed that the headers have not been sent yet, and this
 * function terminates the PHP script execution.
 */
function putProblemText($probid)
{
    global $DB, $cdata;
    $prob = $DB->q("MAYBETUPLE SELECT cid, shortname, problemtext, problemtext_type\n\t                FROM problem INNER JOIN contestproblem USING (probid)\n\t                WHERE OCTET_LENGTH(problemtext) > 0\n\t                AND probid = %i AND cid = %i", $probid, $cdata['cid']);
    if (empty($prob) || !(IS_JURY || $prob['cid'] == $cdata['cid'] && difftime($cdata['starttime'], now()) <= 0)) {
        error("Problem p{$probid} not found or not available");
    }
    switch ($prob['problemtext_type']) {
        case 'pdf':
            $mimetype = 'application/pdf';
            break;
        case 'html':
            $mimetype = 'text/html';
            break;
        case 'txt':
            $mimetype = 'text/plain';
            break;
        default:
            error("Problem p{$probid} text has unknown type");
    }
    $filename = "prob-{$prob['shortname']}.{$prob['problemtext_type']}";
    header("Content-Type: {$mimetype}; name=\"{$filename}\"");
    header("Content-Disposition: inline; filename=\"{$filename}\"");
    header("Content-Length: " . strlen($prob['problemtext']));
    echo $prob['problemtext'];
    exit(0);
}
Example #10
0
<?php

/**
 * Upload form for documents to be sent to the printer.
 *
 * Part of the DOMjudge Programming Contest Jury System and licenced
 * under the GNU GPL. See README and COPYING for details.
 */
require 'init.php';
$title = 'Print';
require LIBWWWDIR . '/header.php';
echo "<h1>Print source</h1>\n\n";
if (!have_printing()) {
    error("Printing disabled.");
}
// Seems reasonable to require that there's a contest running
// before allowing to submit printouts.
if (is_null($cid) || difftime($cdata['starttime'], now()) > 0) {
    echo "<p class=\"nodata\">Contest has not yet started.</p>\n";
    require LIBWWWDIR . '/footer.php';
    exit;
}
if (isset($_POST['langid'])) {
    handle_print_upload();
} else {
    put_print_form();
}
require LIBWWWDIR . '/footer.php';
Example #11
0
            $timestamp += (double) $jrun['runtime'];
        }
        XMLaddnode($run, 'judged', 'True');
        XMLaddnode($run, 'status', 'done');
        XMLaddnode($run, 'result', $result_map[$jdata['result']]);
        if ($jdata['result'] == 'correct') {
            XMLaddnode($run, 'solved', 'True');
            XMLaddnode($run, 'penalty', 'False');
        } else {
            XMLaddnode($run, 'solved', 'False');
            if ($compile_penalty == 0 && $jdata['result'] == 'compiler-error') {
                XMLaddnode($run, 'penalty', 'False');
            } else {
                XMLaddnode($run, 'penalty', 'True');
            }
        }
    }
}
// We don't support a finalize attribute in DOMjudge master branch, so
// just output some fake data if the contest has finished.
if (difftime(now(), $cdata['endtime']) >= 0) {
    $node = XMLaddnode($root, 'finalized');
    XMLaddnode($node, 'timestamp', $cdata['endtime']);
    XMLaddnode($node, 'last-gold', 0);
    XMLaddnode($node, 'last-silver', 0);
    XMLaddnode($node, 'last-bronze', 0);
    XMLaddnode($node, 'comment', 'Automatically finalized by DOMjudge');
}
header('Content-Type: text/xml; charset=' . DJ_CHARACTER_SET);
$xmldoc->formatOutput = true;
echo $xmldoc->saveXML();
Example #12
0
/**
 * Outputs a specific sample testcase for a problem.
 * A testcase is sample if it is marked as such. It's then available from
 * the team interface for download.
 *
 * $seq is the number of the testcase when selecting only the testcases
 * marked sample for the given problem, ordered by testcaseid. This is
 * done as to not leak the total number of testcases to teams.
 *
 * $type is "in" or "out".
 */
function putSampleTestcase($probid, $seq, $type)
{
    global $DB, $cdata;
    $sample = $DB->q('MAYBETUPLE SELECT shortname, ' . $type . 'put AS content
	                  FROM problem INNER JOIN testcase USING (probid)
	                  INNER JOIN contestproblem USING (probid)
	                  WHERE probid = %i AND cid = %i AND allow_submit = 1
	                  AND sample = 1 ORDER BY testcaseid ASC LIMIT %i,1', $probid, $cdata['cid'], $seq - 1);
    if (empty($sample) || difftime($cdata['starttime'], now()) > 0) {
        error("Problem p{$probid} not found or not available");
    }
    $probname = $sample['shortname'];
    $filename = "sample-{$probname}.{$seq}.{$type}";
    header("Content-Type: text/plain; name=\"{$filename}\"");
    header("Content-Disposition: attachment; filename=\"{$filename}\"");
    header("Content-Length: " . strlen($sample['content']));
    echo $sample['content'];
    exit(0);
}
Example #13
0
        XMLaddnode($node, 'to-all', isset($row['recipient']) ? 'False' : 'True');
    } else {
        XMLaddnode($node, 'answered', 'False');
    }
}
$compile_penalty = dbconfig_get('compile_penalty', 0);
// write out runs
while ($row = $events->next()) {
    if ($row['description'] != 'problem submitted' && $row['description'] != 'problem judged') {
        continue;
    }
    $data = $DB->q('MAYBETUPLE SELECT submittime, teamid, probid, name AS langname, valid
	                FROM submission
	                LEFT JOIN language USING (langid)
	                WHERE valid = 1 AND submitid = %i', $row['submitid']);
    if (empty($data) || difftime($data['submittime'], $cdata['endtime']) >= 0 || !isset($prob_to_id[$data['probid']]) || !isset($team_to_id[$data['teamid']])) {
        continue;
    }
    $run = XMLaddnode($root, 'run');
    XMLaddnode($run, 'id', $row['submitid']);
    XMLaddnode($run, 'problem', $prob_to_id[$data['probid']]);
    XMLaddnode($run, 'team', $team_to_id[$data['teamid']]);
    XMLaddnode($run, 'timestamp', $row['eventtime']);
    XMLaddnode($run, 'time', calcContestTime($data['submittime'], $cid));
    XMLaddnode($run, 'language', $data['langname']);
    if ($row['description'] == 'problem submitted') {
        XMLaddnode($run, 'judged', 'False');
        XMLaddnode($run, 'status', 'fresh');
    } else {
        $jdata = $DB->q('MAYBETUPLE SELECT result, starttime FROM judging j
		                 LEFT JOIN submission USING(submitid)
Example #14
0
function check_judging($data, $keydata = null)
{
    if (!empty($data['endtime']) && difftime($data['endtime'], $data['starttime']) < 0) {
        ch_error('Judging ended before it started');
    }
    if (!empty($data['submittime']) && difftime($data['starttime'], $data['submittime']) < 0) {
        ch_error('Judging started before it was submitted (clocks unsynched?)');
    }
    return $data;
}
Example #15
0
/**
 * This function takes a (set of) temporary file(s) of a submission,
 * validates it and puts it into the database. Additionally it
 * moves it to a backup storage.
 */
function submit_solution($team, $prob, $contest, $lang, $files, $filenames, $origsubmitid = NULL)
{
    global $DB;
    if (empty($team)) {
        error("No value for Team.");
    }
    if (empty($prob)) {
        error("No value for Problem.");
    }
    if (empty($contest)) {
        error("No value for Contest.");
    }
    if (empty($lang)) {
        error("No value for Language.");
    }
    if (!is_array($files) || count($files) == 0) {
        error("No files specified.");
    }
    if (count($files) > dbconfig_get('sourcefiles_limit', 100)) {
        error("Tried to submit more than the allowed number of source files.");
    }
    if (!is_array($filenames) || count($filenames) != count($files)) {
        error("Nonmatching (number of) filenames specified.");
    }
    if (count($filenames) != count(array_unique($filenames))) {
        error("Duplicate filenames detected.");
    }
    $sourcesize = dbconfig_get('sourcesize_limit');
    // If no contest has started yet, refuse submissions.
    $now = now();
    $contestdata = $DB->q('MAYBETUPLE SELECT starttime,endtime FROM contest WHERE cid = %i', $contest);
    if (!isset($contestdata)) {
        error("Contest c{$contest} not found.");
    }
    if (difftime($contestdata['starttime'], $now) > 0) {
        error("The contest is closed, no submissions accepted. [c{$contest}]");
    }
    // Check 2: valid parameters?
    if (!($langid = $DB->q('MAYBEVALUE SELECT langid FROM language
	                        WHERE langid = %s AND allow_submit = 1', $lang))) {
        error("Language '{$lang}' not found in database or not submittable.");
    }
    if (!($teamid = $DB->q('MAYBEVALUE SELECT teamid FROM team
	                        WHERE teamid = %i AND enabled = 1', $team))) {
        error("Team '{$team}' not found in database or not enabled.");
    }
    $probdata = $DB->q('MAYBETUPLE SELECT probid, points FROM problem
	                    INNER JOIN contestproblem USING (probid)
	                    WHERE probid = %s AND cid = %i AND allow_submit = 1', $prob, $contest);
    if (empty($probdata)) {
        error("Problem p{$prob} not found in database or not submittable [c{$contest}].");
    } else {
        $points = $probdata['points'];
        $probid = $probdata['probid'];
    }
    // Reindex arrays numerically to allow simultaneously iterating
    // over both $files and $filenames.
    $files = array_values($files);
    $filenames = array_values($filenames);
    $totalsize = 0;
    for ($i = 0; $i < count($files); $i++) {
        if (!is_readable($files[$i])) {
            error("File '" . $files[$i] . "' not found (or not readable).");
        }
        if (!preg_match(FILENAME_REGEX, $filenames[$i])) {
            error("Illegal filename '" . $filenames[$i] . "'.");
        }
        $totalsize += filesize($files[$i]);
    }
    if ($totalsize > $sourcesize * 1024) {
        error("Submission file(s) are larger than {$sourcesize} kB.");
    }
    logmsg(LOG_INFO, "input verified");
    // Insert submission into the database
    $id = $DB->q('RETURNID INSERT INTO submission
	              (cid, teamid, probid, langid, submittime, origsubmitid)
	              VALUES (%i, %i, %i, %s, %s, %i)', $contest, $teamid, $probid, $langid, $now, $origsubmitid);
    for ($rank = 0; $rank < count($files); $rank++) {
        $DB->q('INSERT INTO submission_file
		        (submitid, filename, rank, sourcecode) VALUES (%i, %s, %i, %s)', $id, $filenames[$rank], $rank, getFileContents($files[$rank], false));
    }
    // Recalculate scoreboard cache for pending submissions
    calcScoreRow($contest, $teamid, $probid);
    // Log to event table
    $DB->q('INSERT INTO event (eventtime, cid, teamid, langid, probid, submitid, description)
	        VALUES(%s, %i, %i, %s, %i, %i, "problem submitted")', now(), $contest, $teamid, $langid, $probid, $id);
    if (is_writable(SUBMITDIR)) {
        // Copy the submission to SUBMITDIR for safe-keeping
        for ($rank = 0; $rank < count($files); $rank++) {
            $fdata = array('cid' => $contest, 'submitid' => $id, 'teamid' => $teamid, 'probid' => $probid, 'langid' => $langid, 'rank' => $rank, 'filename' => $filenames[$rank]);
            $tofile = SUBMITDIR . '/' . getSourceFilename($fdata);
            if (!@copy($files[$rank], $tofile)) {
                warning("Could not copy '" . $files[$rank] . "' to '" . $tofile . "'");
            }
        }
    } else {
        logmsg(LOG_DEBUG, "SUBMITDIR not writable, skipping");
    }
    if (difftime($contestdata['endtime'], $now) <= 0) {
        logmsg(LOG_INFO, "The contest is closed, submission stored but not processed. [c{$contest}]");
    }
    return $id;
}
Example #16
0
 * under the GNU GPL. See README and COPYING for details.
 */
require 'init.php';
$title = 'Submit';
if (!isset($_POST['submit'])) {
    header('Location: ./');
    return;
}
if (is_null($cid)) {
    require LIBWWWDIR . '/header.php';
    echo "<p class=\"nodata\">No active contest</p>\n";
    require LIBWWWDIR . '/footer.php';
    exit;
}
$now = now();
if (difftime($cdata['starttime'], $now) > 0) {
    require LIBWWWDIR . '/header.php';
    echo "<p class=\"nodata\">Contest has not yet started.</p>\n";
    require LIBWWWDIR . '/footer.php';
    exit;
}
/** helper to output an error message. */
function err($string)
{
    // Annoying PHP: we need to import global variables here...
    global $title;
    require LIBWWWDIR . '/header.php';
    echo "<h2>Submit - error</h2>\n\n";
    echo '<div id="uploadstatus">';
    logmsg(LOG_WARNING, $string);
    echo '</div>';
Example #17
0
/**
 * Problems information
 */
function problems($args)
{
    global $DB, $cdatas, $userdata;
    checkargs($args, array('cid'));
    $cid = safe_int($args['cid']);
    // Check that user has access to the problems in this contest:
    if (checkrole('team')) {
        $cdatas = getCurContests(TRUE, $userdata['teamid']);
    }
    if (checkrole('jury') || isset($cdatas[$cid]) && difftime(now(), $cdatas[$cid]['starttime']) >= 0) {
        $pdatas = $DB->q('TABLE SELECT probid AS id, shortname AS label, shortname, name, color
		                  FROM problem
		                  INNER JOIN contestproblem USING (probid)
		                  WHERE cid = %i AND allow_submit = 1 ORDER BY probid', $cid);
    } else {
        $pdatas = array();
    }
    foreach ($pdatas as $key => $pdata) {
        if (!isset($pdata['color'])) {
            $pdatas[$key]['rgb'] = null;
        } elseif (preg_match('/^#[[:xdigit:]]{3,6}$/', $pdata['color'])) {
            $pdatas[$key]['rgb'] = $pdata['color'];
            $pdatas[$key]['color'] = hex_to_color($pdata['color']);
        } else {
            $pdatas[$key]['rgb'] = color_to_hex($pdata['color']);
        }
    }
    return array_map(function ($pdata) {
        return array('id' => safe_int($pdata['id']), 'label' => $pdata['label'], 'short_name' => $pdata['shortname'], 'name' => $pdata['name'], 'rgb' => $pdata['rgb'], 'color' => $pdata['color']);
    }, $pdatas);
}
Example #18
0
/**
 * Given an array of contest data, calculates whether the contest
 * has already started ('cstarted'), and if scoreboard is currently
 * frozen ('showfrozen') or final ('showfinal').
 */
function calcFreezeData($cdata)
{
    $fdata = array();
    if ($cdata == null) {
        return array('showfinal' => false, 'showfrozen' => false, 'cstarted' => false);
    }
    // Show final scores if contest is over and unfreezetime has been
    // reached, or if contest is over and no freezetime had been set.
    // We can compare $now and the dbfields stringwise.
    $now = now();
    $fdata['showfinal'] = !isset($cdata['freezetime']) && difftime($cdata['endtime'], $now) <= 0 || isset($cdata['unfreezetime']) && difftime($cdata['unfreezetime'], $now) <= 0;
    // freeze scoreboard if freeze time has been reached and
    // we're not showing the final score yet
    $fdata['showfrozen'] = !$fdata['showfinal'] && isset($cdata['freezetime']) && difftime($cdata['freezetime'], $now) <= 0;
    // contest is active but has not yet started
    $fdata['cstarted'] = difftime($cdata['starttime'], $now) <= 0;
    return $fdata;
}
Example #19
0
                LEFT JOIN judgehost_restriction r USING (restrictionid)
                WHERE hostname = %s', $id);
// get the judgings for a specific key and value pair
// select only specific fields to avoid retrieving large blobs
$cids = getCurContests(FALSE);
if (!empty($cids)) {
    $jdata = $DB->q('KEYTABLE SELECT judgingid AS ARRAYKEY, judgingid, submitid,
	                 j.starttime, j.endtime, judgehost, result, verified,
	                 j.valid, j.rejudgingid, r.valid AS rejudgevalid,
	                 (j.endtime IS NULL AND j.valid=0 AND (r.valid IS NULL OR r.valid)) AS aborted
	                 FROM judging j
	                 LEFT JOIN rejudging r USING(rejudgingid)
	                 WHERE cid IN (%Ai) AND judgehost = %s
	                 ORDER BY j.starttime DESC, judgingid DESC', $cids, $data['hostname']);
}
$reltime = floor(difftime(now(), $data['polltime']));
$status = 'Undefined';
if ($reltime < dbconfig_get('judgehost_warning', 30)) {
    $status = "OK";
} else {
    if ($reltime < dbconfig_get('judgehost_critical', 120)) {
        $status = "Warning";
    } else {
        $status = "Critical";
    }
}
// KLUDGE: Add the following PHP functions to Twig, this should be
// fixed differently.
$twig_safe = array('is_safe' => array('html'));
$twig->addFunction(new Twig_SimpleFunction('delLink', 'delLink', $twig_safe));
$twig->addFunction(new Twig_SimpleFunction('rejudgeForm', 'rejudgeForm', $twig_safe));