S2OJ/web/app/controllers/problem_set.php

420 lines
12 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');
2022-03-17 04:00:03 +00:00
2022-11-06 02:26:21 +00:00
Auth::check() || redirectToLogin();
2022-11-11 23:10:34 +00:00
UOJUser::checkPermission(Auth::user(), 'problems.view') || UOJResponse::page403();
2022-04-03 10:18:17 +00:00
2022-11-11 23:10:34 +00:00
if (UOJProblem::userCanCreateProblem(Auth::user())) {
2022-11-07 05:57:23 +00:00
$default_statement = <<<'EOD'
## 题目描述
在此处填写题目描述。题目中的图片应上传至 S2OJ 图床中(点击顶栏 应用——图床 进入),以免丢失。
2022-11-07 05:57:23 +00:00
## 输入格式
在此处约定输入数据的格式。
## 输出格式
在此处说明输入数据的格式要求。
## 输入输出样例
2022-11-16 06:25:32 +00:00
### 样例输入 #1
2022-11-07 05:57:23 +00:00
```text
样例 1 的输入内容
```
2022-11-16 06:25:32 +00:00
### 样例输出 #1
2022-11-07 05:57:23 +00:00
```text
样例 1 的输出内容
```
### 样例解释 #1
样例 1 的解释与说明。
### 样例 #2
<!-- 大样例,如无大样例请删除本节。请根据实际情况修改下方的文件名。 -->
见右侧「附件下载」中的 `ex_data2.in/out`
## 数据范围与约定
<!-- 请根据实际情况修改下方的数据范围。 -->
- 对于 $50\%$ 的数据,【替换此处】。
- 对于 $100\%$ 的数据,【替换此处】。
2022-11-07 05:57:23 +00:00
如有,在此处填写其他于题意或数据相关的说明。
EOD;
2023-01-15 13:53:26 +00:00
$new_problem_form = new UOJForm('new_problem');
2022-11-07 05:57:23 +00:00
$new_problem_form->handle = function () use ($default_statement) {
2022-11-06 02:26:21 +00:00
DB::insert([
"insert into problems",
"(title, uploader, is_hidden, submission_requirement, extra_config)",
"values", DB::tuple(["New Problem", Auth::id(), 1, "{}", "{}"])
2022-11-06 02:26:21 +00:00
]);
$id = DB::insert_id();
DB::insert([
"insert into problems_contents",
"(id, statement, statement_md)",
2022-11-07 05:57:23 +00:00
"values", DB::tuple([
$id,
HTML::purifier()->purify(HTML::parsedown()->text($default_statement)),
$default_statement,
])
2022-11-06 02:26:21 +00:00
]);
dataNewProblem($id);
redirectTo("/problem/{$id}/manage/statement");
die();
2022-11-06 02:26:21 +00:00
};
$new_problem_form->config['submit_container']['class'] = '';
$new_problem_form->config['submit_button']['class'] = 'bg-transparent border-0 d-block w-100 px-3 py-2 text-start';
$new_problem_form->config['submit_button']['text'] = '<i class="bi bi-plus-lg"></i> 新建本地题目';
2023-01-31 10:30:53 +00:00
$new_problem_form->config['confirm']['text'] = '你真的要添加新题吗?';
2022-11-06 02:26:21 +00:00
$new_problem_form->runAtServer();
}
function getProblemTR($info) {
$problem = new UOJProblem($info);
$html = HTML::tag_begin('tr', ['class' => 'text-center']);
$html .= HTML::tag('td', ['class' => $info['submission_id'] ? 'table-success' : ''], "#{$info['id']}");
2023-02-20 02:54:01 +00:00
$html .= HTML::tag_begin('td', ['class' => 'text-start align-middle']);
2022-11-06 02:26:21 +00:00
$html .= $problem->getLink(['with' => 'none']);
if ($problem->isUserOwnProblem(Auth::user())) {
2023-02-20 02:54:01 +00:00
$html .= ' <a href="/problems?my=on"><span class="badge text-white bg-info align-middle">' . UOJLocale::get('problems::my problem') . '</span></a> ';
2016-07-18 16:39:37 +00:00
}
if ($info['type'] == 'remote') {
2023-02-20 02:54:01 +00:00
$html .= ' ' . HTML::tag('a', ['class' => 'badge text-bg-success align-middle', 'href' => '/problems/remote'], '远端评测题');
}
2022-11-06 02:26:21 +00:00
if ($info['is_hidden']) {
2023-02-20 02:54:01 +00:00
$html .= ' <a href="/problems?is_hidden=on"><span class="badge text-bg-danger align-middle"><i class="bi bi-eye-slash-fill"></i> ' . UOJLocale::get('hidden') . '</span></a> ';
2016-07-18 16:39:37 +00:00
}
2022-11-06 02:26:21 +00:00
if (isset($_COOKIE['show_tags_mode'])) {
$html .= HTML::tag_begin('span', ['class' => 'float-end']);
2022-11-06 02:26:21 +00:00
foreach ($problem->queryTags() as $tag) {
2023-02-20 02:54:01 +00:00
$html .= ' <a class="uoj-problem-tag">' . '<span class="badge bg-secondary align-middle">' . HTML::escape($tag) . '</span>' . '</a> ';
2022-11-06 02:26:21 +00:00
}
$html .= HTML::tag_end('span');
2016-07-18 16:39:37 +00:00
}
$html .= HTML::tag_end('td');
2022-11-06 02:26:21 +00:00
if (isset($_COOKIE['show_submit_mode'])) {
$perc = $info['submit_num'] > 0 ? round(100 * $info['ac_num'] / $info['submit_num']) : 0;
2022-12-04 11:00:18 +00:00
$html .= HTML::tag(
'td',
2023-02-20 02:54:01 +00:00
[
'class' => 'align-middle',
],
2022-12-04 11:00:18 +00:00
HTML::tag(
'div',
[
2023-02-20 02:54:01 +00:00
'class' => 'progress h-100',
2022-12-04 11:00:18 +00:00
'data-bs-toggle' => 'tooltip',
'data-bs-title' => "{$info['ac_num']} / {$info['submit_num']}",
'data-bs-placement' => 'bottom',
],
HTML::tag('div', [
'class' => 'progress-bar bg-success',
'role' => 'progressbar',
'aria-valuenow' => $perc,
'aria-valuemin' => 0,
'aria-valuemax' => 100,
'style' => "width: {$perc}%; min-width: 20px;",
], "{$perc}%")
)
);
}
2022-12-05 09:14:43 +00:00
$html .= HTML::tag('td', [], $problem->getDifficultyHTML());
$html .= HTML::tag('td', [], ClickZans::getCntBlock($problem->info['zan']));
$html .= HTML::tag_end('tr');
2022-11-06 02:26:21 +00:00
return $html;
}
2022-11-06 02:26:21 +00:00
$cond = [];
$search_tag = UOJRequest::get('tag', 'is_string', null);
$search_content = UOJRequest::get('search', 'is_string', '');
$search_is_effective = false;
$cur_tab = UOJRequest::get('tab', 'is_string', 'all');
if ($cur_tab == 'template') {
$search_tag = "模板题";
2023-01-29 14:31:02 +00:00
} else if ($cur_tab == 'remote') {
$cond['type'] = 'remote';
2022-11-06 02:26:21 +00:00
}
if (is_string($search_tag)) {
$cond[] = [
DB::rawvalue($search_tag), "in", DB::rawbracket([
"select tag from problems_tags",
"where", ["problems_tags.problem_id" => DB::raw("problems.id")]
])
];
}
if ($search_content !== '') {
foreach (explode(' ', $search_content) as $key) {
if (strlen($key) > 0) {
$cond[] = DB::lor([
[DB::instr(DB::raw('title'), $key), '>', 0],
DB::exists([
"select tag from problems_tags",
"where", [
[DB::instr(DB::raw('tag'), $key), '>', 0],
"problems_tags.problem_id" => DB::raw("problems.id")
]
]),
"id" => $key,
]);
$search_is_effective = true;
}
}
2022-11-06 02:26:21 +00:00
}
2022-11-06 02:26:21 +00:00
if (isset($_GET['is_hidden'])) {
$cond['problems.is_hidden'] = true;
2022-11-06 02:26:21 +00:00
}
if (Auth::check() && isset($_GET['my'])) {
$cond['problems.uploader'] = Auth::id();
2022-11-06 02:26:21 +00:00
}
2022-12-05 09:14:43 +00:00
if (isset($_GET['min_difficulty']) && $_GET['min_difficulty']) {
$cond[] = ['problems.difficulty', '>=', $_GET['min_difficulty']];
}
if (isset($_GET['max_difficulty']) && $_GET['max_difficulty']) {
$cond[] = ['problems.difficulty', '<=', $_GET['max_difficulty']];
2022-12-05 03:54:58 +00:00
}
if (empty($cond)) {
2022-11-06 02:26:21 +00:00
$cond = '1';
}
$header = '<tr>';
$header .= '<th class="text-center" style="width:5em;">ID</th>';
$header .= '<th>' . UOJLocale::get('problems::problem') . '</th>';
if (isset($_COOKIE['show_submit_mode'])) {
$header .= '<th class="text-center" style="width:125px;">' . UOJLocale::get('problems::ac ratio') . '</th>';
}
2022-12-05 09:14:43 +00:00
$header .= '<th class="text-center" style="width:4em;">' . UOJLocale::get('problems::difficulty') . '</th>';
2022-11-06 02:26:21 +00:00
$header .= '<th class="text-center" style="width:50px;">' . UOJLocale::get('appraisal') . '</th>';
$header .= '</tr>';
2023-01-29 14:31:02 +00:00
$tabs_info = [
'all' => [
2022-11-06 02:26:21 +00:00
'name' => UOJLocale::get('problems::all problems'),
'url' => "/problems"
2023-01-29 14:31:02 +00:00
],
'template' => [
2022-11-06 02:26:21 +00:00
'name' => UOJLocale::get('problems::template problems'),
'url' => "/problems/template"
2023-01-29 14:31:02 +00:00
],
'remote' => [
'name' => UOJLocale::get('problems::remote problems'),
'url' => "/problems/remote"
],
];
2022-11-06 02:26:21 +00:00
$pag = new Paginator([
'col_names' => ['*'],
'table_name' => [
"problems left join best_ac_submissions",
"on", [
"best_ac_submissions.submitter" => Auth::id(),
"problems.id" => DB::raw("best_ac_submissions.problem_id")
],
],
'cond' => $cond,
'tail' => "order by id asc",
2023-02-17 13:50:04 +00:00
'page_len' => 50,
2022-11-06 02:26:21 +00:00
'post_filter' => function ($problem) {
return (new UOJProblem($problem))->userCanView(Auth::user());
2022-09-29 02:10:24 +00:00
}
2022-11-06 02:26:21 +00:00
]);
// if ($search_is_effective) {
// $search_summary = [
// 'count_in_cur_page' => $pag->countInCurPage(),
// 'first_a_few' => []
// ];
// foreach ($pag->get(5) as $info) {
// $problem = new UOJProblem($info);
// $search_summary['first_a_few'][] = [
// 'type' => 'problem',
// 'id' => $problem->info['id'],
// 'title' => $problem->getTitle()
// ];
// }
// DB::insert([
// "insert into search_requests",
// "(created_at, remote_addr, type, cache_id, q, content, result)",
// "values", DB::tuple([DB::now(), UOJContext::remoteAddr(), 'search', 0, $search_content, UOJContext::requestURI(), json_encode($search_summary)])
// ]);
// }
?>
2016-07-18 16:39:37 +00:00
<?php echoUOJPageHeader(UOJLocale::get('problems')) ?>
2022-09-24 05:39:55 +00:00
2022-09-25 06:16:36 +00:00
<div class="row">
2022-11-06 02:26:21 +00:00
<!-- left col -->
2022-12-05 09:14:43 +00:00
<div class="col-md-9">
2022-11-06 02:26:21 +00:00
<!-- title -->
<div class="d-flex justify-content-between flex-wrap">
2022-11-06 02:26:21 +00:00
<h1>
<?= UOJLocale::get('problems') ?>
</h1>
<div>
<?= HTML::tablist($tabs_info, $cur_tab, 'nav-pills') ?>
</div>
2022-09-24 02:18:55 +00:00
</div>
2022-11-06 02:26:21 +00:00
<!-- end title -->
2022-09-24 02:18:55 +00:00
<?= $pag->pagination() ?>
<div class="text-end">
<div class="form-check d-inline-block me-2">
<input type="checkbox" id="input-show_tags_mode" class="form-check-input" <?= isset($_COOKIE['show_tags_mode']) ? 'checked="checked" ' : '' ?> />
<label class="form-check-label" for="input-show_tags_mode">
<?= UOJLocale::get('problems::show tags') ?>
</label>
2022-11-06 02:26:21 +00:00
</div>
2022-09-29 02:10:24 +00:00
<div class="form-check d-inline-block">
<input type="checkbox" id="input-show_submit_mode" class="form-check-input" <?= isset($_COOKIE['show_submit_mode']) ? 'checked="checked" ' : '' ?> />
<label class="form-check-label" for="input-show_submit_mode">
<?= UOJLocale::get('problems::show statistics') ?>
</label>
2022-11-06 02:26:21 +00:00
</div>
2022-09-29 02:10:24 +00:00
</div>
2022-09-25 06:16:36 +00:00
2022-11-06 02:26:21 +00:00
<script type="text/javascript">
$('#input-show_tags_mode').click(function() {
if (this.checked) {
$.cookie('show_tags_mode', '', {
2022-12-03 06:58:06 +00:00
path: '/problems',
expires: 365,
2022-11-06 02:26:21 +00:00
});
} else {
$.removeCookie('show_tags_mode', {
2022-12-03 06:58:06 +00:00
path: '/problems',
2022-11-06 02:26:21 +00:00
});
}
location.reload();
});
$('#input-show_submit_mode').click(function() {
if (this.checked) {
$.cookie('show_submit_mode', '', {
2022-12-03 06:58:06 +00:00
path: '/problems',
expires: 365,
2022-11-06 02:26:21 +00:00
});
} else {
$.removeCookie('show_submit_mode', {
2022-12-03 06:58:06 +00:00
path: '/problems'
2022-11-06 02:26:21 +00:00
});
}
location.reload();
});
</script>
2022-09-25 06:16:36 +00:00
2022-11-06 02:26:21 +00:00
<div class="card my-3">
<?=
HTML::responsive_table($header, $pag->get(), [
'table_attr' => [
'class' => ['table', 'uoj-table', 'mb-0'],
],
'tr' => function ($row, $idx) {
return getProblemTR($row);
}
]);
?>
</div>
<?= $pag->pagination() ?>
</div>
2022-11-06 02:26:21 +00:00
<!-- end left col -->
<!-- right col -->
2022-12-05 09:14:43 +00:00
<aside class="col-md-3 mt-3 mt-md-0">
2022-11-06 02:26:21 +00:00
<!-- search bar -->
<form method="get" class="mb-3" id="form-problem_search">
<div class="input-group mb-3">
<input id="search-input" name="search" type="text" class="form-control" placeholder="搜索">
<button class="btn btn-outline-secondary" type="submit">
<i class="bi bi-search"></i>
</button>
</div>
2022-12-05 03:54:58 +00:00
<div>
<?php if (Auth::check()) : ?>
<div class="form-check d-inline-block">
<input type="checkbox" name="my" <?= isset($_GET['my']) ? 'checked="checked"' : '' ?> class="form-check-input" id="input-my">
<label class="form-check-label" for="input-my">
我的题目
</label>
</div>
<?php endif ?>
<?php if (UOJProblem::userCanManageSomeProblem(Auth::user())) : ?>
<div class="form-check d-inline-block ms-2">
<input type="checkbox" name="is_hidden" <?= isset($_GET['is_hidden']) ? 'checked="checked"' : '' ?> class="form-check-input" id="input-is_hidden">
<label class="form-check-label" for="input-is_hidden">
隐藏题目
</label>
</div>
<?php endif ?>
</div>
2022-12-05 09:14:43 +00:00
<div class="card mt-3">
<div class="card-header fw-bold">
题目难度
</div>
<div class="card-body">
<div class="input-group input-group-sm">
<input type="text" class="form-control" name="min_difficulty" id="input-min_difficulty" maxlength="4" style="width:4em" placeholder="800" value="<?= HTML::escape($_GET['min_difficulty']) ?>" autocomplete="off" />
<span class="input-group-text">~</span>
<input type="text" class="form-control" name="max_difficulty" id="input-max_difficulty" maxlength="4" style="width:4em" placeholder="3500" value="<?= HTML::escape($_GET['max_difficulty']) ?>" autocomplete="off" />
<button type="submit" class="btn btn-outline-secondary">
<i class="bi bi-funnel"></i>
</button>
</div>
2022-11-06 02:26:21 +00:00
</div>
2022-12-05 03:54:58 +00:00
</div>
2022-11-06 02:26:21 +00:00
</form>
<script>
$('#search-input').val(new URLSearchParams(location.search).get('search'));
2022-12-05 03:54:58 +00:00
$('#input-my, #input-is_hidden, #input-difficulty').change(function() {
2022-11-06 02:26:21 +00:00
$('#form-problem_search').submit();
});
</script>
<?php if (UOJProblem::userCanCreateProblem(Auth::user())) : ?>
<div class="card mb-3">
<div class="card-header fw-bold">
新建题目
</div>
<div class="list-group list-group-flush">
<div class="list-group-item list-group-item-action p-0">
<?php $new_problem_form->printHTML() ?>
</div>
2023-01-29 14:31:02 +00:00
<a class="list-group-item list-group-item-action" href="/problems/remote/new">
<i class="bi bi-cloud-plus"></i>
新建远端评测题目
</a>
</div>
</div>
<?php endif ?>
2022-11-06 02:26:21 +00:00
<!-- sidebar -->
<?php uojIncludeView('sidebar') ?>
</aside>
2022-09-25 06:16:36 +00:00
</div>
2022-11-10 00:16:48 +00:00
<?php echoUOJPageFooter() ?>