From 054c8c075b8db66ce81e810865d93ea81ef89e7a Mon Sep 17 00:00:00 2001 From: Keith Johnson Date: Wed, 21 Oct 2015 10:46:30 -0400 Subject: [PATCH] Allow teams to download sample data --- lib/www/common.php | 70 +++++++++++++++++++++++++++++++++++++++++++ www/team/problems.php | 6 +++- www/team/testcase.php | 25 ++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 www/team/testcase.php diff --git a/lib/www/common.php b/lib/www/common.php index 8fe8bb0106..5cc79be811 100644 --- a/lib/www/common.php +++ b/lib/www/common.php @@ -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 "

No sample data available for this contest.

\n\n"; + } elseif ( !$fdata['cstarted'] ) { + echo "

Sample data will appear here at contest start.

\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 '

Problem ' . htmlspecialchars($row['shortname']) . ': ' . + htmlspecialchars($row['name']) . "

\n"; + $currentprobid = $row['probid']; + $i = 1; + } + echo "\n"; + $i++; + } + } else { + echo "

No sample data available for this contest.

\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. diff --git a/www/team/problems.php b/www/team/problems.php index 80137fc9ae..3756e70692 100644 --- a/www/team/problems.php +++ b/www/team/problems.php @@ -1,6 +1,6 @@ Sample data\n\n"; + +putSampleDataList(); + require(LIBWWWDIR . '/footer.php'); diff --git a/www/team/testcase.php b/www/team/testcase.php new file mode 100644 index 0000000000..f914d56286 --- /dev/null +++ b/www/team/testcase.php @@ -0,0 +1,25 @@ +