S2OJ/web/app/controllers/submission.php

243 lines
8.6 KiB
PHP
Raw Normal View History

2016-07-18 16:39:37 +00:00
<?php
2022-11-06 02:26:21 +00:00
requireLib('hljs');
requirePHPLib('form');
requirePHPLib('judger');
2022-03-17 04:00:03 +00:00
2022-11-06 02:26:21 +00:00
Auth::check() || redirectToLogin();
UOJSubmission::init(UOJRequest::get('id')) || UOJResponse::page404();
UOJSubmission::initProblemAndContest() || UOJResponse::page404();
UOJSubmission::cur()->userCanView(Auth::user(), ['ensure' => true]);
2022-09-24 13:19:48 +00:00
2022-11-06 02:26:21 +00:00
$perm = UOJSubmission::cur()->viewerCanSeeComponents(Auth::user());
2022-11-06 02:26:21 +00:00
$can_see_minor = false;
if ($perm['score']) {
$can_see_minor = UOJSubmission::cur()->userCanSeeMinorVersions(Auth::user());
UOJSubmissionHistory::init(UOJSubmission::cur(), ['minor' => $can_see_minor]) || UOJResponse::page404();
if (isset($_GET['time'])) {
$history_time = UOJRequest::get('time', 'is_short_string');
!empty($history_time) || UOJResponse::page404();
UOJSubmission::cur()->loadHistoryByTime($history_time) || UOJResponse::page404();
UOJSubmission::cur()->isMajor() || UOJResponse::page404();
} elseif (isset($_GET['tid'])) {
$can_see_minor || UOJResponse::page404();
UOJSubmission::cur()->loadHistoryByTID(UOJRequest::get('tid', 'validateUInt')) || UOJResponse::page404();
!UOJSubmission::cur()->isMajor() || UOJResponse::page404();
2016-07-18 16:39:37 +00:00
}
2022-11-06 02:26:21 +00:00
}
$submission = UOJSubmission::info();
$submission_result = UOJSubmission::cur()->getResult();
$problem = UOJProblem::info();
if ($can_see_minor) {
2023-01-16 13:28:05 +00:00
$minor_rejudge_form = new UOJForm('minor_rejudge');
2022-11-06 02:26:21 +00:00
$minor_rejudge_form->handle = function () {
UOJSubmission::rejudgeById(UOJSubmission::info('id'), [
'reason_text' => '管理员偷偷重测该提交记录',
'major' => false
]);
$tid = DB::insert_id();
redirectTo(UOJSubmission::cur()->getUriForNewTID($tid));
};
2023-01-16 13:28:05 +00:00
$minor_rejudge_form->config['submit_button']['class'] = 'btn btn-sm btn-primary';
$minor_rejudge_form->config['submit_button']['text'] = '偷偷重新测试';
$minor_rejudge_form->config['submit_container']['class'] = 'd-inline-block text-end';
2022-11-06 02:26:21 +00:00
$minor_rejudge_form->runAtServer();
}
if (UOJSubmission::cur()->isLatest()) {
if (UOJSubmission::cur()->preHackCheck()) {
$hack_form = new UOJForm('hack');
$hack_form->addTextFileInput('input', ['filename' => 'input.txt']);
$hack_form->addCheckBox('use_formatter', [
'label' => '帮我整理文末回车、行末空格、换行符',
'checked' => true,
]);
2022-11-06 02:26:21 +00:00
$hack_form->handle = function (&$vdata) {
global $problem, $submission;
Auth::check() || redirectToLogin();
2016-07-18 16:39:37 +00:00
if ($_POST["input_upload_type"] == 'file') {
$tmp_name = UOJForm::uploadedFileTmpName("input_file");
2016-07-18 16:39:37 +00:00
if ($tmp_name == null) {
2022-11-06 02:26:21 +00:00
UOJResponse::message('你在干啥……怎么什么都没交过来……?');
2016-07-18 16:39:37 +00:00
}
}
2022-11-06 02:26:21 +00:00
$fileName = FS::randomAvailableTmpFileName();
$fileFullName = UOJContext::storagePath() . $fileName;
2016-07-18 16:39:37 +00:00
if ($_POST["input_upload_type"] == 'editor') {
file_put_contents($fileFullName, $_POST['input_editor']);
} else {
move_uploaded_file($_FILES["input_file"]['tmp_name'], $fileFullName);
}
$input_type = isset($_POST['use_formatter']) ? "USE_FORMATTER" : "DONT_USE_FORMATTER";
2022-11-06 02:26:21 +00:00
DB::insert([
"insert into hacks",
"(problem_id, submission_id, hacker, owner, input, input_type, submit_time, status, details, is_hidden)",
"values", DB::tuple([
$problem['id'], $submission['id'], Auth::id(), $submission['submitter'],
$fileName, $input_type, DB::now(), 'Waiting', '', $problem['is_hidden']
])
]);
2016-07-18 16:39:37 +00:00
};
$hack_form->config['max_post_size'] = 25 * 1024 * 1024;
$hack_form->config['max_file_size_mb'] = 25;
2016-07-18 16:39:37 +00:00
$hack_form->succ_href = "/hacks";
$hack_form->runAtServer();
}
2022-11-06 02:26:21 +00:00
if (UOJSubmission::cur()->userCanRejudge(Auth::user())) {
2023-01-16 13:28:05 +00:00
$rejudge_form = new UOJForm('rejudge');
2022-11-06 02:26:21 +00:00
$rejudge_form->handle = function () {
UOJSubmission::rejudgeById(UOJSubmission::info('id'));
2016-07-18 16:39:37 +00:00
};
2023-01-16 13:28:05 +00:00
$rejudge_form->config['submit_button']['class'] = 'btn btn-sm btn-primary';
$rejudge_form->config['submit_button']['text'] = '重新测试';
$rejudge_form->config['submit_container']['class'] = 'text-end d-inline-block';
2016-07-18 16:39:37 +00:00
$rejudge_form->runAtServer();
}
2022-11-06 02:26:21 +00:00
if (UOJSubmission::cur()->userCanDelete(Auth::user())) {
2023-01-16 13:28:05 +00:00
$delete_form = new UOJForm('delete');
2022-11-06 02:26:21 +00:00
$delete_form->handle = function () {
UOJSubmission::cur()->delete();
2016-07-18 16:39:37 +00:00
};
2023-01-16 13:28:05 +00:00
$delete_form->config['submit_button']['class'] = 'btn btn-sm btn-danger';
$delete_form->config['submit_button']['text'] = '删除此提交记录';
$delete_form->config['submit_container']['class'] = 'text-end d-inline-block';
$delete_form->config['confirm']['smart'] = true;
2016-07-18 16:39:37 +00:00
$delete_form->succ_href = "/submissions";
$delete_form->runAtServer();
}
2022-11-06 02:26:21 +00:00
} else {
if (UOJSubmission::cur()->userCanDelete(Auth::user()) && !UOJSubmission::cur()->isMajor()) {
2023-01-16 13:28:05 +00:00
$delete_form = new UOJForm('delete');
2022-11-06 02:26:21 +00:00
$delete_form->handle = function () {
UOJSubmission::cur()->deleteThisMinorVersion();
};
2023-01-16 13:28:05 +00:00
$delete_form->config['submit_button']['class'] = 'btn btn-sm btn-danger';
$delete_form->config['submit_button']['text'] = '删除当前历史记录(保留其他历史记录)';
$delete_form->config['submit_container']['class'] = 'text-end d-inline-block';
$delete_form->config['confirm']['smart'] = true;
2022-11-06 02:26:21 +00:00
$delete_form->succ_href = UOJSubmission::cur()->getUriForLatest();
$delete_form->runAtServer();
2016-07-18 16:39:37 +00:00
}
2022-11-06 02:26:21 +00:00
}
?>
2022-09-20 05:10:25 +00:00
<script>
var problem_id = parseInt('<?= $submission['problem_id'] ?>');
</script>
2022-11-06 02:26:21 +00:00
<?php echoUOJPageHeader(UOJLocale::get('problems::submission') . ' #' . $submission['id']) ?>
2022-09-24 13:19:48 +00:00
2022-11-06 02:26:21 +00:00
<h1>
<?= UOJLocale::get('problems::submission') . ' #' . $submission['id'] ?>
2022-09-24 13:19:48 +00:00
</h1>
2022-11-06 02:26:21 +00:00
<?php UOJSubmission::cur()->echoStatusTable(['show_actual_score' => $perm['score'], 'id_hidden' => true], Auth::user()) ?>
<?php
if ($perm['score']) {
HTML::echoPanel('mb-3', '测评历史', function () {
UOJSubmissionHistory::cur()->echoTimeline();
});
}
?>
2016-07-18 16:39:37 +00:00
2022-11-06 02:26:21 +00:00
<?php
if ($perm['manager_view']) {
HTML::echoPanel('mb-3', '测评机信息(管理员可见)', function () {
if (empty(UOJSubmission::info('judger'))) {
echo '暂无';
} else {
$judger = DB::selectFirst([
"select * from judger_info",
"where", [
"judger_name" => UOJSubmission::info('judger')
]
]);
if (!$judger) {
echo '测评机信息损坏';
} else {
echo '<strong>', $judger['display_name'], ': </strong>', $judger['description'];
}
}
});
}
?>
<?php if ($perm['content'] || $perm['manager_view']) : ?>
<div>
2023-01-11 02:48:20 +00:00
<?php UOJSubmission::cur()->echoContent() ?>
</div>
2022-11-06 02:26:21 +00:00
<?php if (isset($hack_form)) : ?>
2016-07-18 16:39:37 +00:00
<p class="text-center">
这程序好像有点 Bug我给组数据试试 <button id="button-display-hack" type="button" class="btn btn-danger btn-xs">Hack!</button>
2016-07-18 16:39:37 +00:00
</p>
<div class="card mb-3" id="div-form-hack" style="display: none">
<div class="card-header">提交 Hack</div>
<div class="card-body">
<?php $hack_form->printHTML() ?>
</div>
<div class="card-footer bg-transparent small text-center text-danger">
2022-11-06 02:26:21 +00:00
Hack 功能是给大家互相查错用的。请勿故意提交错误代码,然后自己 Hack 自己、贼喊捉贼哦(故意贼喊捉贼会予以封禁处理)
</div>
2016-07-18 16:39:37 +00:00
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#button-display-hack').click(function() {
$('#div-form-hack').toggle('fast');
});
});
</script>
<?php endif ?>
<?php endif ?>
2022-11-06 02:26:21 +00:00
<?php
if (UOJSubmission::cur()->hasJudged()) {
if ($perm['high_level_details']) {
HTML::echoPanel(['card' => 'mb-3', 'body' => 'p-0'], UOJLocale::get('details'), function () use ($perm, $submission_result) {
$styler = new SubmissionDetailsStyler();
if (!$perm['low_level_details']) {
$styler->fade_all_details = true;
$styler->show_small_tip = false;
}
echoJudgmentDetails($submission_result['details'], $styler, 'details');
if ($perm['manager_view'] && !$perm['low_level_details']) {
echo '<hr />';
echo '<h4 class="text-info">全部详细信息(管理员可见)</h4>';
echoSubmissionDetails($submission_result['details'], 'all_details');
}
});
} else if ($perm['manager_view']) {
HTML::echoPanel(['card' => 'mb-3', 'body' => 'p-0'], '详细(管理员可见)', function () use ($submission_result) {
echoSubmissionDetails($submission_result['details'], 'details');
});
}
if ($perm['manager_view'] && isset($submission_result['final_result'])) {
HTML::echoPanel(['card' => 'mb-3', 'body' => 'p-0'], '终测结果预测(管理员可见)', function () use ($submission_result) {
echoSubmissionDetails($submission_result['final_result']['details'], 'final_details');
});
}
}
?>
<div class="d-flex gap-2 justify-content-end">
2023-01-11 02:48:20 +00:00
<?php if (isset($minor_rejudge_form)) : ?>
<?php $minor_rejudge_form->printHTML() ?>
<?php endif ?>
2016-07-18 16:39:37 +00:00
2023-01-11 02:48:20 +00:00
<?php if (isset($rejudge_form)) : ?>
<?php $rejudge_form->printHTML() ?>
<?php endif ?>
2016-07-18 16:39:37 +00:00
2023-01-11 02:48:20 +00:00
<?php if (isset($delete_form)) : ?>
<?php $delete_form->printHTML() ?>
<?php endif ?>
2022-11-06 02:26:21 +00:00
</div>
2022-10-22 13:12:13 +00:00
2016-07-18 16:39:37 +00:00
<?php echoUOJPageFooter() ?>