diff --git a/sql/mysql_db_structure.sql b/sql/mysql_db_structure.sql index 44d5745a85..b5a4045d30 100644 --- a/sql/mysql_db_structure.sql +++ b/sql/mysql_db_structure.sql @@ -358,6 +358,7 @@ CREATE TABLE `testcase` ( `probid` varchar(8) NOT NULL COMMENT 'Corresponding problem ID', `rank` int(4) NOT NULL COMMENT 'Determines order of the testcases in judging', `description` varchar(255) default NULL COMMENT 'Description of this testcase', + `sample` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT 'Sample testcases can be shared with teams.', PRIMARY KEY (`testcaseid`), UNIQUE KEY `rank` (`probid`,`rank`), KEY `probid` (`probid`), diff --git a/sql/upgrade/upgrade_to-online_judge.sql b/sql/upgrade/upgrade_to-online_judge.sql index 88139fd157..fd4a9b5555 100644 --- a/sql/upgrade/upgrade_to-online_judge.sql +++ b/sql/upgrade/upgrade_to-online_judge.sql @@ -8,12 +8,16 @@ -- -- @UPGRADE-CHECK@ -SELECT 1; +ALTER TABLE `testcase` ADD COLUMN `sample` tinyint(1) default NULL; +ALTER TABLE `testcase` DROP COLUMN `sample`; -- -- Create additional structures -- +ALTER TABLE `testcase` + ADD COLUMN `sample` tinyint(1) unsigned NOT NULL default '0' COMMENT 'Sample testcases can be shared with teams.' AFTER `description`; + -- -- Transfer data from old to new structure -- diff --git a/www/js/domjudge.js b/www/js/domjudge.js index 66cd665b14..f79998c6b4 100644 --- a/www/js/domjudge.js +++ b/www/js/domjudge.js @@ -62,6 +62,31 @@ function hideTcDescEdit(descid) node.parentNode.appendChild(span); } +// make corresponding testcase sample dropdown editable +function editTcSample(tcid) +{ + var node = document.getElementById('sample_' + tcid + '_'); + node.parentNode.setAttribute('onclick', ''); + var remove = node.nextSibling; + while (remove.nodeName == '#text') + remove = remove.nextSibling; + node.parentNode.removeChild(remove); + node.style.display = 'block'; + node.setAttribute('name', 'sample[' + tcid + ']'); +} + +// hides sample dropdown field if javascript is enabled +function hideTcSample(tcid, str) +{ + var node = document.getElementById('sample_' + tcid + '_'); + node.style.display = 'none'; + node.setAttribute('name', 'invalid'); + + var span = document.createElement('span'); + span.innerHTML = str; + node.parentNode.appendChild(span); +} + // Autodetection of problem, language in websubmit function detectProblemLanguage(filename) { diff --git a/www/jury/testcase.php b/www/jury/testcase.php index f7171e2664..253cfccf30 100644 --- a/www/jury/testcase.php +++ b/www/jury/testcase.php @@ -128,6 +128,14 @@ } } + if ( isset($_POST['sample'][$rank]) ) { + $DB->q('UPDATE testcase SET sample = %i WHERE probid = %s + AND rank = %i', $_POST['sample'][$rank], $probid, $rank); + $result .= "
  • Set testcase $rank to be " . + ($_POST['sample'][$rank] ? "" : "not ") . + "a sample testcase
  • \n"; + } + if ( isset($_POST['description'][$rank]) ) { $DB->q('UPDATE testcase SET description = %s WHERE probid = %s AND rank = %i', $_POST['description'][$rank], $probid, $rank); @@ -154,10 +162,11 @@ if ( !empty($content['input']) && !empty($content['output']) ) { $DB->q("INSERT INTO testcase - (probid,rank,md5sum_input,md5sum_output,input,output,description) - VALUES (%s,%i,%s,%s,%s,%s,%s)", + (probid,rank,md5sum_input,md5sum_output,input,output,description,sample) + VALUES (%s,%i,%s,%s,%s,%s,%s,%i)", $probid, $rank, md5(@$content['input']), md5(@$content['output']), - @$content['input'], @$content['output'], @$_POST['add_desc']); + @$content['input'], @$content['output'], @$_POST['add_desc'], + @$_POST['add_sample']); auditlog('testcase', $probid, 'added', "rank $rank"); $result .= "
  • Added new testcase $rank from " . @@ -172,7 +181,8 @@ echo "\n\n"; // Reload testcase data after updates - $data = $DB->q('KEYTABLE SELECT rank AS ARRAYKEY, testcaseid, rank, description, + $data = $DB->q('KEYTABLE SELECT rank AS ARRAYKEY, testcaseid, rank, + description, sample, OCTET_LENGTH(input) AS size_input, md5sum_input, OCTET_LENGTH(output) AS size_output, md5sum_output FROM testcase WHERE probid = %s ORDER BY rank', $probid); @@ -196,7 +206,7 @@ sizemd5 upload new'; -?>description +?>sampledescription " . + addSelect("sample[$rank]",array("no", "yes"), $row['sample'], true) . ""; + + // hide sample dropdown field if javascript is enabled + echo ""; echo "" . "" . @@ -235,6 +251,8 @@ echo ""; } else { + echo "" . + printyn($row['issample']) . ""; echo "" . htmlspecialchars($row['description']) . ""; } @@ -252,6 +270,7 @@ +
    Input testdata:
    Output testdata:
    Sample testcase:
    Description:
    q('MAYBETUPLE SELECT p.probid, p.name AS probname, submittime, - s.valid, l.name AS langname, result, output_compile, verified + s.valid, l.name AS langname, result, output_compile, verified, judgingid FROM judging j LEFT JOIN submission s USING (submitid) LEFT JOIN language l USING (langid) @@ -75,4 +75,53 @@ echo "

    Compilation output is disabled.

    \n"; } +if ( @$row['result']!='compiler-error' ) { + $runs = $DB->q('SELECT r.*, t.rank, t.description FROM testcase t + LEFT JOIN judging_run r ON ( r.testcaseid = t.testcaseid AND + r.judgingid = %i ) + WHERE t.probid = %s AND t.sample = 1 ORDER BY rank', + $row['judgingid'], $row['probid']); + + $runinfo = $runs->gettable(); + echo '

    Run(s) on the provided sample data

    '; + + foreach ( $runinfo as $run ) { + echo "

    Run $run[rank]

    \n\n"; + if ( $run['runresult']===NULL ) { + echo "

    Run not finished yet.

    \n"; + continue; + } + echo "\n" . + "" . + "" . + "" . + "
    Description:" . + htmlspecialchars($run['description']) . "
    Runtime:$run[runtime] sec
    Result: $run[runresult]
    \n\n"; + echo "
    Program output
    \n"; + if ( @$run['output_run'] ) { + echo "
    ".
    +			    htmlspecialchars($run['output_run'])."
    \n\n"; + } else { + echo "

    There was no program output.

    \n"; + } + echo "
    Diff output
    \n"; + if ( @$run['output_diff'] ) { + echo "
    ";
    +			echo parseDiff($run['output_diff']);
    +			echo "
    \n\n"; + } else { + echo "

    There was no diff output.

    \n"; + } + echo "
    Error output (info/debug/errors)
    \n"; + if ( @$run['output_error'] ) { + echo "
    ".
    +			    htmlspecialchars($run['output_error'])."
    \n\n"; + } else { + echo "

    There was no stderr output.

    \n"; + } + } +} + require(LIBWWWDIR . '/footer.php');