Skip to content

Commit

Permalink
Add preferences for downloading problem data
Browse files Browse the repository at this point in the history
Fine grained settings for whether teams or the public can download
problemtext or sample testcases
  • Loading branch information
Keith Johnson committed Nov 6, 2015
1 parent d986f97 commit a94ab49
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 11 deletions.
17 changes: 15 additions & 2 deletions lib/www/common.php
Expand Up @@ -577,8 +577,7 @@ function putSampleDataList() {
global $cid, $cdata, $DB;
$fdata = calcFreezeData($cdata);

$show_sample = dbconfig_get('show_sample_output', 0);
if ( ! $show_sample ) {
if ( ! have_sampletestcases() ) {
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";
Expand Down Expand Up @@ -656,6 +655,20 @@ function have_problemtexts()
AND cid = %i', $cid) > 0;
}

/**
* Returns true if at least one problem in the current contest has a
* sample testcase in the database.
*/
function have_sampletestcases()
{
global $DB, $cid;
return $DB->q('VALUE SELECT COUNT(*) FROM problem
INNER JOIN contestproblem USING (probid)
LEFT JOIN testcase USING (probid)
WHERE sample = 1
AND cid = %i', $cid) > 0;
}

/**
* Maps domjudge language id to Ace language id
*/
Expand Down
7 changes: 6 additions & 1 deletion sql/mysql_db_defaultdata.sql
Expand Up @@ -38,7 +38,12 @@ INSERT INTO `configuration` (`name`, `value`, `type`, `description`) VALUES
('allow_registration', '0', 'bool', 'Allow users to register themselves with the system?'),
('judgehost_warning', '30', 'int', 'Time in seconds after a judgehost last checked in before showing its status as "warning".'),
('judgehost_critical', '120', 'int', 'Time in seconds after a judgehost last checked in before showing its status as "critical".'),
('thumbnail_size', '128', 'int', 'Maximum width/height of a thumbnail for uploaded testcase images.');
('thumbnail_size', '128', 'int', 'Maximum width/height of a thumbnail for uploaded testcase images.'),
('download_problemtext', '1', 'bool', 'Allows teams to download problem text when logged in'),
('download_samples', '1', 'bool', 'Allow teams to download sample testcases when logged in'),
('public_dl_problemtext', '0', 'bool', 'Allow everyone to download problem text for public contests'),
('public_dl_samples', '0', 'bool', 'Allow everyone to download sample testcases for public contests');


--
-- Dumping data for table `executable`
Expand Down
2 changes: 1 addition & 1 deletion www/public/menu.php
@@ -1,7 +1,7 @@
<nav><div id="menutop">
<a href="index.php" accesskey="h">home</a>
<?php
if ( have_problemtexts() ) {
if ( have_problemtexts() || have_sampletestcases() ) {
echo "<a href=\"problems.php\" accesskey=\"p\">problems</a>\n";
}
logged_in(); // fill userdata
Expand Down
5 changes: 5 additions & 0 deletions www/public/problem.php
Expand Up @@ -9,6 +9,11 @@

require('init.php');

$download_enabled = dbconfig_get('public_dl_problemtext', 0);
if (!$download_enabled) {
error("Problem text downloads disabled by admin");
}

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

Expand Down
15 changes: 14 additions & 1 deletion www/public/problems.php
Expand Up @@ -11,8 +11,21 @@
$title = 'Problem statements';
require(LIBWWWDIR . '/header.php');

$show_problemtext = dbconfig_get('public_dl_problemtext', 0);
echo "<h1>Problem statements</h1>\n\n";
if ($show_problemtext) {
putProblemTextList();
} else {
echo "<p>Problem text disabled</p>";
}

putProblemTextList();

$show_sample = dbconfig_get('public_dl_samples', 0);
echo "<h1>Sample data</h1>\n\n";
if ($show_sample) {
putSampleDataList();
} else {
echo "<p>Sample testcases disabled</p>";
}

require(LIBWWWDIR . '/footer.php');
25 changes: 25 additions & 0 deletions www/public/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('public_dl_samples', 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'");
}
2 changes: 1 addition & 1 deletion www/team/menu.php
Expand Up @@ -4,7 +4,7 @@

echo "<a target=\"_top\" href=\"index.php\" accesskey=\"o\">overview</a>\n";

if ( have_problemtexts() ) {
if ( have_problemtexts() || have_sampletestcases()) {
echo "<a target=\"_top\" href=\"problems.php\" accesskey=\"t\">problems</a>\n";
}

Expand Down
5 changes: 5 additions & 0 deletions www/team/problem.php
Expand Up @@ -9,6 +9,11 @@

require('init.php');

$download_enabled = dbconfig_get('download_problemtext', 1);
if (!$download_enabled) {
error("Problem text downloads disabled by admin");
}

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

Expand Down
16 changes: 12 additions & 4 deletions www/team/problems.php
Expand Up @@ -11,12 +11,20 @@
$title = 'Problem statements';
require(LIBWWWDIR . '/header.php');

$show_problemtext = dbconfig_get('download_problemtext', 1);
echo "<h1>Problem statements</h1>\n\n";
if ($show_problemtext) {
putProblemTextList();
} else {
echo "<p>Problem text disabled</p>";
}

putProblemTextList();

$show_sample = dbconfig_get('download_samples', 1);
echo "<h1>Sample data</h1>\n\n";

putSampleDataList();
if ($show_sample) {
putSampleDataList();
} else {
echo "<p>Sample testcases disabled</p>";
}

require(LIBWWWDIR . '/footer.php');
2 changes: 1 addition & 1 deletion www/team/testcase.php
Expand Up @@ -9,7 +9,7 @@

require('init.php');

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

0 comments on commit a94ab49

Please sign in to comment.