S2OJ/web/app/controllers/submission.php
Baoshuo c5bb4a1a67
All checks were successful
continuous-integration/drone/push Build is passing
feat: redirect to login instead of return 403
2022-10-06 20:28:43 +08:00

229 lines
7.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
requirePHPLib('form');
requirePHPLib('judger');
if (!Auth::check()) {
redirectToLogin();
}
if (!validateUInt($_GET['id']) || !($submission = querySubmission($_GET['id']))) {
become404Page();
}
if (!isset($_COOKIE['bootstrap4'])) {
$REQUIRE_LIB['bootstrap5'] = '';
}
$submission_result = json_decode($submission['result'], true);
$problem = queryProblemBrief($submission['problem_id']);
$problem_extra_config = getProblemExtraConfig($problem);
if ($submission['contest_id']) {
$contest = queryContest($submission['contest_id']);
genMoreContestInfo($contest);
} else {
$contest = null;
if (!isNormalUser($myUser)) {
become403Page();
}
}
if (!isSubmissionVisibleToUser($submission, $problem, $myUser)) {
become403Page();
}
$out_status = explode(', ', $submission['status'])[0];
if ($_GET['get'] == 'status-details' && Auth::check() && $submission['submitter'] === Auth::id()) {
echo json_encode(array(
'judged' => $out_status == 'Judged',
'html' => getSubmissionStatusDetails($submission)
));
die();
}
$hackable = $submission['score'] == 100 && $problem['hackable'] == 1;
if ($hackable) {
$hack_form = new UOJForm('hack');
$hack_form->addTextFileInput('input', '输入数据');
$hack_form->addCheckBox('use_formatter', '帮我整理文末回车、行末空格、换行符', true);
$hack_form->handle = function(&$vdata) {
global $myUser, $problem, $submission;
if ($myUser == null) {
redirectToLogin();
}
if ($_POST["input_upload_type"] == 'file') {
$tmp_name = UOJForm::uploadedFileTmpName("input_file");
if ($tmp_name == null) {
becomeMsgPage('你在干啥……怎么什么都没交过来……?');
}
}
$fileName = uojRandAvaiableTmpFileName();
$fileFullName = UOJContext::storagePath().$fileName;
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";
DB::insert("insert into hacks (problem_id, submission_id, hacker, owner, input, input_type, submit_time, details, is_hidden) values ({$problem['id']}, {$submission['id']}, '{$myUser['username']}', '{$submission['submitter']}', '$fileName', '$input_type', now(), '', {$problem['is_hidden']})");
};
$hack_form->succ_href = "/hacks";
$hack_form->runAtServer();
}
if ($submission['status'] == 'Judged' && hasProblemPermission($myUser, $problem)) {
$rejudge_form = new UOJForm('rejudge');
$rejudge_form->handle = function() {
global $submission;
rejudgeSubmission($submission);
};
$rejudge_form->submit_button_config['class_str'] = 'btn btn-primary';
$rejudge_form->submit_button_config['text'] = '重新测试';
$rejudge_form->submit_button_config['align'] = 'right';
$rejudge_form->runAtServer();
}
if (isSuperUser($myUser)) {
$delete_form = new UOJForm('delete');
$delete_form->handle = function() {
global $submission;
$content = json_decode($submission['content'], true);
unlink(UOJContext::storagePath().$content['file_name']);
DB::delete("delete from submissions where id = {$submission['id']}");
updateBestACSubmissions($submission['submitter'], $submission['problem_id']);
};
$delete_form->submit_button_config['class_str'] = 'btn btn-danger';
$delete_form->submit_button_config['text'] = '删除此提交记录';
$delete_form->submit_button_config['align'] = 'right';
$delete_form->submit_button_config['smart_confirm'] = '';
$delete_form->succ_href = "/submissions";
$delete_form->runAtServer();
}
$should_show_content = hasViewPermission($problem_extra_config['view_content_type'], $myUser, $problem, $submission);
$should_show_all_details = hasViewPermission($problem_extra_config['view_all_details_type'], $myUser, $problem, $submission);
$should_show_details = hasViewPermission($problem_extra_config['view_details_type'], $myUser, $problem, $submission);
$should_show_details_to_me = isSuperUser($myUser);
if (explode(', ', $submission['status'])[0] != 'Judged') {
$should_show_all_details = false;
}
if ($contest != null && $contest['cur_progress'] == CONTEST_IN_PROGRESS) {
if ($contest['extra_config']["problem_{$submission['problem_id']}"] === 'no-details') {
$should_show_details = false;
}
}
if (!isSubmissionFullVisibleToUser($submission, $contest, $problem, $myUser)) {
$should_show_content = $should_show_all_details = false;
}
if ($contest != null && hasContestPermission($myUser, $contest)) {
$should_show_details_to_me = true;
$should_show_content = true;
$should_show_all_details = true;
}
if ($should_show_all_details) {
$styler = new SubmissionDetailsStyler();
if ((!$should_show_details || ($contest['extra_config']['contest_type']=='IOI' && $contest['cur_progress'] == CONTEST_IN_PROGRESS)) && !hasContestPermission($myUser, $contest)) {
$styler->fade_all_details = true;
$styler->show_small_tip = false;
if ($contest['extra_config']['contest_type']=='IOI' && $contest['cur_progress'] == CONTEST_IN_PROGRESS) {
$styler->ioi_contest_is_running = true;
}
}
}
?>
<?php
if (isset($REQUIRE_LIB['bootstrap5'])) {
$REQUIRE_LIB['hljs'] = '';
} else {
$REQUIRE_LIB['shjs'] = '';
}
?>
<script>
var problem_id = parseInt('<?= $submission['problem_id'] ?>');
</script>
<?php echoUOJPageHeader(UOJLocale::get('problems::submission').' #'.$submission['id']) ?>
<h1 class="h3">
<?= UOJLocale::get('problems::submission').' #'.$submission['id'] ?>
</h1>
<?php echoSubmissionsListOnlyOne($submission, array('id_hidden' => ''), $myUser) ?>
<?php if ($should_show_content): ?>
<?php echoSubmissionContent($submission, getProblemSubmissionRequirement($problem)) ?>
<?php if ($hackable): ?>
<p class="text-center">
这程序好像有点Bug我给组数据试试 <button id="button-display-hack" type="button" class="btn btn-danger btn-xs">Hack!</button>
</p>
<div id="div-form-hack" style="display:none" class="bot-buffer-md">
<?php $hack_form->printHTML() ?>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#button-display-hack').click(function() {
$('#div-form-hack').toggle('fast');
});
});
</script>
<?php endif ?>
<?php endif ?>
<?php if ($should_show_all_details): ?>
<div class="card border-info mb-3">
<div class="card-header bg-info">
<h4 class="card-title"><?= UOJLocale::get('details') ?></h4>
</div>
<?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="card-body">
<?php endif ?>
<?php echoJudgementDetails($submission_result['details'], $styler, 'details') ?>
<?php if ($should_show_details_to_me): ?>
<?php if (isset($submission_result['final_result'])): ?>
<hr />
<?php echoSubmissionDetails($submission_result['final_result']['details'], 'final_details') ?>
<?php endif ?>
<?php if ($styler->fade_all_details): ?>
<hr />
<?php echoSubmissionDetails($submission_result['details'], 'final_details') ?>
<?php endif ?>
<?php endif ?>
<?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
<?php endif ?>
</div>
<?php endif ?>
<?php if (isset($rejudge_form)): ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="text-end">
<?php endif ?>
<?php $rejudge_form->printHTML() ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
<?php endif ?>
<?php endif ?>
<?php if (isset($delete_form)): ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="text-end">
<?php endif ?>
<div class="top-buffer-sm">
<?php $delete_form->printHTML() ?>
</div>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
<?php endif ?>
<?php endif ?>
<?php echoUOJPageFooter() ?>