Skip to content

Commit

Permalink
Allow teams to download sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Johnson committed Nov 6, 2015
1 parent 4622405 commit 054c8c0
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
70 changes: 70 additions & 0 deletions lib/www/common.php
Expand Up @@ -573,6 +573,76 @@ function putProblemTextList()
}
}

function putSampleDataList() {
global $cid, $cdata, $DB;
$fdata = calcFreezeData($cdata);

$show_sample = dbconfig_get('show_sample_output', 0);
if ( ! $show_sample ) {
echo "<p class=\"nodata\">No sample data available for this contest.</p>\n\n";
} elseif ( !$fdata['cstarted'] ) {
echo "<p class=\"nodata\">Sample data will appear here at contest start.</p>\n\n";
} else {
// otherwise, display list
$res = $DB->q('SELECT
p.probid,cp.shortname,p.name,t.testcaseid,t.description
FROM problem p
INNER JOIN contestproblem cp USING (probid)
LEFT JOIN testcase t USING (probid)
WHERE cid = %i AND allow_submit = 1 AND
t.sample = 1 ORDER BY p.probid,shortname', $cid);
$currentprobid = -1;
if ( $res->count() > 0 ) {
while($row = $res->next()) {
if ($row['probid'] != $currentprobid) {
echo '<h4>Problem ' . htmlspecialchars($row['shortname']) . ': ' .
htmlspecialchars($row['name']) . "</h4>\n";
$currentprobid = $row['probid'];
$i = 1;
}
echo "<ul>\n";
print '<li> ' .
'<img src="../images/txt.png" alt="" /> ' .
'Testcase ' . $i . ": " . htmlspecialchars($row['description']) . ' ' .
'(<a href="testcase.php?id=' . urlencode($row['testcaseid']) . '&fetch=input">input</a>)' .
'(<a href="testcase.php?id=' . urlencode($row['testcaseid']) . '&fetch=output">output</a>)' .
"</li>\n";
echo "</ul>\n";
$i++;
}
} else {
echo "<p class=\"nodata\">No sample data available for this contest.</p>\n\n";
}
}
}

function putSampleData($testcaseid, $fetch) {
global $DB, $cdata;

$testcase = $DB->q("MAYBETUPLE SELECT cid, shortname, testcaseid,
$fetch, OCTET_LENGTH($fetch) as size
FROM problem INNER JOIN contestproblem USING (probid)
LEFT JOIN testcase USING (probid)
WHERE sample = 1
AND testcaseid = %i AND cid = %i", $testcaseid, $cdata['cid']);

if ( empty($testcase) ||
!(IS_JURY ||
($testcase['cid']==$cdata['cid'] && difftime($cdata['starttime'],now())<=0)) ) {
error("Testcase t$testcaseid not found or not available");
}

$ext = substr($fetch,0,-3);
$filename = "$testcase[shortname]-t$testcase[testcaseid].$ext";

header("Content-Type: text/plain; name=\"$filename\"");
header("Content-Disposition: inline; filename=\"$filename\"");
header("Content-Length: " . strlen($testcase['size']));

echo $testcase[$fetch];

exit(0);
}
/**
* Returns true if at least one problem in the current contest has a
* problem statement text in the database.
Expand Down
6 changes: 5 additions & 1 deletion www/team/problems.php
@@ -1,6 +1,6 @@
<?php
/**
* View/download problem texts
* View/download problem texts and sample data
*
* Part of the DOMjudge Programming Contest Jury System and licenced
* under the GNU GPL. See README and COPYING for details.
Expand All @@ -15,4 +15,8 @@

putProblemTextList();

echo "<h1>Sample data</h1>\n\n";

putSampleDataList();

require(LIBWWWDIR . '/footer.php');
25 changes: 25 additions & 0 deletions www/team/testcase.php
@@ -0,0 +1,25 @@
<?php
/**
* View/download a specific problem text. This page could later be
* extended to provide more details, like sample test cases.
*
* Part of the DOMjudge Programming Contest Jury System and licenced
* under the GNU GPL. See README and COPYING for details.
*/

require('init.php');

$show_sample = dbconfig_get('show_sample_output', 0);
if (!$show_sample) {
error("Sample testcases disabled by admin");
}

$id = getRequestID();
if ( empty($id) ) error("Missing testcase id");

$FILES = array('input','output');
if ( isset($_GET['fetch']) && in_array($_GET['fetch'], $FILES) ) {
putSampleData($id, $_GET['fetch']);
} else {
error("Missing or invalid value for 'fetch'");
}

0 comments on commit 054c8c0

Please sign in to comment.