mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-09 23:08:42 +00:00
feat: testcase download
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e0cffaa762
commit
67c29e3add
@ -5,12 +5,12 @@
|
||||
become403Page(UOJLocale::get('need login'));
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser)) {
|
||||
if (!isNormalUser($myUser) && $_GET['type'] != 'attachment') {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
switch ($_GET['type']) {
|
||||
case 'problem':
|
||||
case 'attachment':
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
@ -33,12 +33,96 @@
|
||||
$id = $_GET['id'];
|
||||
|
||||
$file_name = "/var/uoj_data/$id/download.zip";
|
||||
$download_name = "problem_$id.zip";
|
||||
$download_name = "problem_{$id}_attachment.zip";
|
||||
break;
|
||||
|
||||
case 'problem':
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
if (!isProblemVisibleToUser($problem, $myUser)) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
$id = $_GET['id'];
|
||||
$file_name = "/var/uoj_data/$id.zip";
|
||||
$download_name = "problem_$id.zip";
|
||||
|
||||
break;
|
||||
|
||||
case 'testcase':
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
if (!isProblemVisibleToUser($problem, $myUser)) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
$id = $_GET['id'];
|
||||
$problem_conf = getUOJConf("/var/uoj_data/$id/problem.conf");
|
||||
|
||||
if ($problem_conf == -1 || $problem_conf == -2) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
if (!validateUInt($_GET['testcase_id'])) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
$testcase_id = $_GET['testcase_id'];
|
||||
$testcase_group = isset($_GET['testcase_group']) && $_GET['testcase_group'] == 'extra' ? 'extra' : 'normal';
|
||||
|
||||
if ($testcase_group == 'extra') {
|
||||
$n_ex_tests = getUOJConfVal($problem_conf, 'n_ex_tests', 0);
|
||||
|
||||
if ($testcase_id < 1 || $testcase_id > $n_ex_tests) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
switch ($_GET['testcase_type']) {
|
||||
case 'input':
|
||||
$file_name = "/var/uoj_data/$id/" . getUOJProblemExtraInputFileName($problem_conf, $testcase_id);
|
||||
$download_name = getUOJProblemExtraInputFileName($problem_conf, $testcase_id);
|
||||
break;
|
||||
|
||||
case 'output':
|
||||
$file_name = "/var/uoj_data/$id/" . getUOJProblemExtraOutputFileName($problem_conf, $testcase_id);
|
||||
$download_name = getUOJProblemExtraOutputFileName($problem_conf, $testcase_id);
|
||||
break;
|
||||
|
||||
default:
|
||||
become404Page();
|
||||
}
|
||||
} else {
|
||||
$n_tests = getUOJConfVal($problem_conf, 'n_tests', 10);
|
||||
|
||||
if ($testcase_id < 1 || $testcase_id > $n_tests) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
switch ($_GET['testcase_type']) {
|
||||
case 'input':
|
||||
$file_name = "/var/uoj_data/$id/" . getUOJProblemInputFileName($problem_conf, $testcase_id);
|
||||
$download_name = getUOJProblemInputFileName($problem_conf, $testcase_id);
|
||||
break;
|
||||
case 'output':
|
||||
$file_name = "/var/uoj_data/$id/" . getUOJProblemOutputFileName($problem_conf, $testcase_id);
|
||||
$download_name = getUOJProblemOutputFileName($problem_conf, $testcase_id);
|
||||
break;
|
||||
default:
|
||||
become404Page();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'testlib.h':
|
||||
$file_name = "/opt/uoj/judger/uoj_judger/include/testlib.h";
|
||||
$download_name = "testlib.h";
|
||||
break;
|
||||
|
||||
default:
|
||||
become404Page();
|
||||
}
|
||||
|
@ -242,7 +242,10 @@ EOD
|
||||
<h1 class="col-md-7 text-center"><?= $problem_letter ?>. <?= $problem['title'] ?></h1>
|
||||
<div class="col-md-2 text-right" id="contest-countdown"></div>
|
||||
</div>
|
||||
<a role="button" class="btn btn-info float-right" href="/contest/<?= $contest['id'] ?>/problem/<?= $problem['id'] ?>/statistics"><span class="glyphicon glyphicon-stats"></span> <?= UOJLocale::get('problems::statistics') ?></a>
|
||||
<div class="btn-group float-right" role="group">
|
||||
<a role="button" class="btn btn-primary" href="<?= HTML::url("/download.php?type=attachment&id={$problem['id']}") ?>"><span class="glyphicon glyphicon-download-alt"></span> 附件下载</a>
|
||||
<a role="button" class="btn btn-info" href="/contest/<?= $contest['id'] ?>/problem/<?= $problem['id'] ?>/statistics"><span class="glyphicon glyphicon-stats"></span> <?= UOJLocale::get('problems::statistics') ?></a>
|
||||
</div>
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<script type="text/javascript">
|
||||
checkContestNotice(<?= $contest['id'] ?>, '<?= UOJTime::$time_now_str ?>');
|
||||
@ -251,7 +254,11 @@ $('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJ
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<h1 class="page-header text-center">#<?= $problem['id']?>. <?= $problem['title'] ?></h1>
|
||||
<a role="button" class="btn btn-info float-right" href="/problem/<?= $problem['id'] ?>/statistics"><span class="glyphicon glyphicon-stats"></span> <?= UOJLocale::get('problems::statistics') ?></a>
|
||||
<div class="btn-group float-right" role="group">
|
||||
<a role="button" class="btn btn-primary" href="<?= HTML::url("/download.php?type=problem&id={$problem['id']}") ?>"><span class="glyphicon glyphicon-tasks"></span> 测试数据</a>
|
||||
<a role="button" class="btn btn-primary" href="<?= HTML::url("/download.php?type=attachment&id={$problem['id']}") ?>"><span class="glyphicon glyphicon-download-alt"></span> 附件下载</a>
|
||||
<a role="button" class="btn btn-info" href="/problem/<?= $problem['id'] ?>/statistics"><span class="glyphicon glyphicon-stats"></span> <?= UOJLocale::get('problems::statistics') ?></a>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
|
@ -125,7 +125,6 @@
|
||||
|
||||
$info_form = new UOJForm('info');
|
||||
$http_host = HTML::escape(UOJContext::httpHost());
|
||||
$download_url = HTML::url("/download.php?type=problem&id={$problem['id']}");
|
||||
$info_form->appendHTML(<<<EOD
|
||||
<div class="form-group row">
|
||||
<!--<label class="col-sm-3 control-label">zip上传数据</label>
|
||||
@ -140,6 +139,19 @@
|
||||
</div>
|
||||
EOD
|
||||
);
|
||||
$attachment_url = HTML::url("/download.php?type=attachment&id={$problem['id']}");
|
||||
$info_form->appendHTML(<<<EOD
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-3 control-label">problem_{$problem['id']}_attachment.zip</label>
|
||||
<div class="col-sm-9">
|
||||
<div class="form-control-static">
|
||||
<a href="$attachment_url">$attachment_url</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
EOD
|
||||
);
|
||||
$download_url = HTML::url("/download.php?type=problem&id={$problem['id']}");
|
||||
$info_form->appendHTML(<<<EOD
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-3 control-label">problem_{$problem['id']}.zip</label>
|
||||
|
@ -136,6 +136,9 @@
|
||||
<?php
|
||||
$REQUIRE_LIB['shjs'] = "";
|
||||
?>
|
||||
<script>
|
||||
var problem_id = parseInt('<?= $submission['problem_id'] ?>');
|
||||
</script>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('problems::submission').' #'.$submission['id']) ?>
|
||||
<?php echoSubmissionsListOnlyOne($submission, array(), $myUser) ?>
|
||||
|
||||
|
@ -616,7 +616,7 @@ class JudgementDetailsPrinter {
|
||||
if ($this->styler->collapse_in) {
|
||||
$accordion_collapse_class .= ' in';
|
||||
}
|
||||
echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
|
||||
echo '<div id="', $accordion_collapse, '" class="uoj-testcase ', $accordion_collapse_class, '" data-test=' . $test_num . '>';
|
||||
echo '<div class="card-body">';
|
||||
|
||||
$this->_print_c($node);
|
||||
@ -680,11 +680,11 @@ class JudgementDetailsPrinter {
|
||||
echo '</div>';
|
||||
}
|
||||
} elseif ($node->nodeName == 'in') {
|
||||
echo "<h4>input:</h4><pre>\n";
|
||||
echo "<h4>input: <a class=\"uoj-testcase-download-input\"></a></h4><pre>\n";
|
||||
$this->_print_c($node);
|
||||
echo "\n</pre>";
|
||||
} elseif ($node->nodeName == 'out') {
|
||||
echo "<h4>output:</h4><pre>\n";
|
||||
echo "<h4>output: <a class=\"uoj-testcase-download-output\"></a></h4><pre>\n";
|
||||
$this->_print_c($node);
|
||||
echo "\n</pre>";
|
||||
} elseif ($node->nodeName == 'res') {
|
||||
|
@ -354,6 +354,23 @@ $.fn.countdown = function(rest, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
$.fn.uoj_testcase = function() {
|
||||
return this.each(function() {
|
||||
var id = parseInt($(this).data('test'));
|
||||
|
||||
if (id > 0 && problem_id) {
|
||||
$('.uoj-testcase-download-input', this)
|
||||
.html('<span class="glyphicon glyphicon-download-alt"></span> 下载')
|
||||
.attr('href', '/download.php?type=testcase&id=' + problem_id + '&testcase_id=' + id + '&testcase_type=input')
|
||||
.addClass('btn btn-secondary btn-sm float-right');
|
||||
$('.uoj-testcase-download-output', this)
|
||||
.html('<span class="glyphicon glyphicon-download-alt"></span> 下载')
|
||||
.attr('href', '/download.php?type=testcase&id=' + problem_id + '&testcase_id=' + id + '&testcase_type=output')
|
||||
.addClass('btn btn-secondary btn-sm float-right');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// update_judgement_status
|
||||
update_judgement_status_list = []
|
||||
function update_judgement_status_details(id) {
|
||||
@ -388,6 +405,7 @@ $.fn.uoj_highlight = function() {
|
||||
return $(this).each(function() {
|
||||
$(this).find("span.uoj-username").each(replaceWithHighlightUsername);
|
||||
$(this).find(".uoj-honor").uoj_honor();
|
||||
$(this).find(".uoj-testcase").uoj_testcase();
|
||||
$(this).find(".uoj-score").each(function() {
|
||||
var score = parseInt($(this).text());
|
||||
var maxscore = parseInt($(this).data('max'));
|
||||
|
Loading…
Reference in New Issue
Block a user