S2OJ/web/app/controllers/hack.php

119 lines
3.8 KiB
PHP
Raw Normal View History

2016-07-18 16:39:37 +00:00
<?php
2022-11-06 02:26:21 +00:00
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('data');
requireLib('bootstrap5');
requireLib('hljs');
2022-03-17 04:00:03 +00:00
2022-11-06 02:26:21 +00:00
Auth::check() || redirectToLogin();
UOJHack::init(UOJRequest::get('id')) || UOJResponse::page404();
UOJHack::cur()->setProblem() || UOJResponse::page404();
UOJHack::cur()->userCanView(Auth::user(), ['ensure' => true]);
2022-03-17 04:00:03 +00:00
2022-11-06 02:26:21 +00:00
if (UOJHack::cur()->setSubmission()) {
UOJHack::cur()->submission->setAsCur();
UOJSubmission::cur()->setProblem(['problem' => UOJHack::cur()->problem]) || UOJResponse::page404();
UOJSubmission::cur()->userCanView(Auth::user(), ['ensure' => true]);
}
2022-04-03 10:18:17 +00:00
2022-11-06 02:26:21 +00:00
if (UOJHack::cur()->userCanDelete(Auth::user())) {
2023-01-15 13:41:48 +00:00
$delete_form = new UOJForm('delete');
2022-11-06 02:26:21 +00:00
$delete_form->handle = function () {
DB::delete([
"delete from hacks",
"where", ["id" => UOJHack::info('id')]
]);
};
2023-01-15 13:41:48 +00:00
$delete_form->config['submit_container']['class'] = 'text-end';
$delete_form->config['submit_button']['class'] = 'btn btn-sm btn-danger';
$delete_form->config['submit_button']['text'] = '删除此 Hack';
$delete_form->config['confirm']['smart'] = true;
2022-11-06 02:26:21 +00:00
$delete_form->succ_href = "/hacks";
$delete_form->runAtServer();
}
2022-09-25 02:44:33 +00:00
2022-11-06 02:26:21 +00:00
if (UOJHack::cur()->userCanReview(Auth::user())) {
2023-01-15 13:41:48 +00:00
$addex_form = new UOJForm('addex');
2022-11-06 02:26:21 +00:00
$addex_form->handle = function () {
$input = UOJContext::storagePath() . UOJHack::info('input');
$new_in = "{$input}_in";
$new_out = "{$input}_out";
$reason = null;
$err = dataAddHackPoint(UOJHack::cur()->problem->info, $new_in, $new_out, $reason, Auth::user());
$err === '' || UOJResponse::message($err);
unlink($new_in);
unlink($new_out);
DB::update([
"update hacks",
"set", [
'status' => 'Judged',
], "where", ['id' => UOJHack::info('id')]
]);
};
2023-01-15 13:41:48 +00:00
$addex_form->config['submit_button']['class'] = 'btn btn-sm btn-danger';
$addex_form->config['submit_button']['text'] = '确认无误,添加到测试数据';
$addex_form->config['submit_container']['class'] = 'mt-3 text-end';
$addex_form->config['confirm']['text'] = '将这个 Hack 数据添加到测试数据中';
2022-11-06 02:26:21 +00:00
$addex_form->succ_href = "/hacks";
$addex_form->runAtServer();
}
2016-07-18 16:39:37 +00:00
2022-11-06 02:26:21 +00:00
$perm = UOJHack::cur()->viewerCanSeeComponents(Auth::user());
?>
2023-01-15 13:41:48 +00:00
2022-11-06 02:26:21 +00:00
<?php echoUOJPageHeader(UOJLocale::get('problems::hack') . ' #' . UOJHack::info('id')) ?>
2016-07-18 16:39:37 +00:00
2022-11-06 02:26:21 +00:00
<h1>
<?= UOJLocale::get('problems::hack') . ' #' . UOJHack::info('id') ?>
2022-09-25 02:44:33 +00:00
</h1>
2022-11-06 02:26:21 +00:00
<?php echoHackListOnlyOne(UOJHack::info(), [], Auth::user()) ?>
<?php if (UOJHack::cur()->hasJudged()) : ?>
<?php if ($perm['high_level_details']) : ?>
<div class="card mb-3">
<div class="card-header fw-bold">
<?= UOJLocale::get('details') ?>
</div>
<div class="card-body p-0">
<?php
$styler = new HackDetailsStyler();
if (!$perm['low_level_details']) {
$styler->fade_all_details = true;
$styler->show_small_tip = false;
}
echoJudgmentDetails(UOJHack::info('details'), $styler, 'details');
?>
<?php if ($perm['manager_view'] && !$perm['low_level_details']) : ?>
<hr />
<h4 class="text-info">全部详细信息(仅管理员可见)</h4>
<?php echoHackDetails(UOJHack::info('details'), 'all_details') ?>
<?php endif ?>
</div>
2016-07-18 16:39:37 +00:00
</div>
2022-11-06 02:26:21 +00:00
<?php endif ?>
2016-07-18 16:39:37 +00:00
<?php endif ?>
2022-09-25 02:44:33 +00:00
2022-11-06 02:26:21 +00:00
<h2 class="mt-3">
<?= UOJLocale::get('problems::submission') . ' #' . UOJSubmission::info('id') ?>
2022-09-25 02:44:33 +00:00
</h2>
2022-11-06 02:26:21 +00:00
<?php if (UOJSubmission::cur()) : ?>
<?php UOJSubmission::cur()->echoStatusTable(['show_actual_score' => $perm['score']], Auth::user()) ?>
<?php if ($perm['content'] || $perm['manager_view']) : ?>
<?php UOJSubmission::cur()->echoContent() ?>
<?php endif ?>
<?php else : ?>
<h3 class="text-danger">提交记录信息损坏</h3>
2016-07-18 16:39:37 +00:00
<?php endif ?>
2022-11-06 02:26:21 +00:00
<?php if (isset($delete_form)) : ?>
2016-07-18 16:39:37 +00:00
<?php $delete_form->printHTML() ?>
<?php endif ?>
2022-11-06 02:26:21 +00:00
<?php if (isset($addex_form)) : ?>
<?php $addex_form->printHTML() ?>
<?php endif ?>
2016-07-18 16:39:37 +00:00
<?php echoUOJPageFooter() ?>