Compare commits

..

3 Commits

Author SHA1 Message Date
67c29e3add
feat: testcase download
All checks were successful
continuous-integration/drone/push Build is passing
2022-09-20 13:10:25 +08:00
e0cffaa762
feat: remove user from contest 2022-09-20 11:02:37 +08:00
85c93c7073
chore: update faq 2022-09-20 10:46:32 +08:00
8 changed files with 161 additions and 11 deletions

View File

@ -84,6 +84,30 @@
updateContestPlayerNum($contest);
};
$add_group_to_contest_form->runAtServer();
$remove_user_from_contest_form = new UOJForm('remove_user_from_contest');
$remove_user_from_contest_form->addInput('remove_username', 'text', '用户名', '',
function ($x) {
global $contest;
if (!validateUsername($x)) {
return '用户名不合法';
}
if (!queryUser($x)) {
return '用户不存在';
}
return '';
},
null
);
$remove_user_from_contest_form->submit_button_config['align'] = 'compressed';
$remove_user_from_contest_form->submit_button_config['text'] = '移除该用户';
$remove_user_from_contest_form->submit_button_config['class_str'] = 'mt-2 btn btn-danger';
$remove_user_from_contest_form->handle = function() {
global $contest;
DB::query("delete from contests_registrants where username = '{$_POST['remove_username']}' and contest_id = {$contest['id']}");
updateContestPlayerNum($contest);
};
$remove_user_from_contest_form->runAtServer();
}
$has_contest_permission = hasContestPermission($myUser, $contest);
@ -170,6 +194,9 @@
if (isset($add_group_to_contest_form)) {
$add_group_to_contest_form->printHTML();
}
if (isset($remove_user_from_contest_form)) {
$remove_user_from_contest_form->printHTML();
}
}
)
);

View File

@ -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();
}

View File

@ -198,8 +198,7 @@
<div class="card-body">
<p>如果你想出题、想办比赛、发现了BUG或者对网站有什么建议可以通过下面的方式联系我们</p>
<ul>
<li>私信联系<?= UOJConfig::$data['profile']['administrator'] ?>。</li>
<li>邮件联系<?= UOJConfig::$data['profile']['admin-email'] ?>。</li>
<li>邮件联系 <a href="/user/profile/baoshuo" class="uoj-username">baoshuo</a><a href="mailto:i@baoshuo.ren">i@baoshuo.ren</a>)或者 <a href="/user/profile/nekko" class="uoj-username">nekko</a><a href="mailto:1139855151@qq.com">1139855151@qq.com</a>)。</li>
<?php if (UOJConfig::$data['profile']['QQ-group']!=''): ?>
<li>你也可以进QQ群水水群号是<?= UOJConfig::$data['profile']['QQ-group'] ?>。</li>
<?php endif ?>

View File

@ -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">

View File

@ -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>

View File

@ -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) ?>

View File

@ -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') {

View File

@ -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'));