S2OJ/web/app/controllers/problem_lists.php

164 lines
4.3 KiB
PHP
Raw Normal View History

2022-09-18 11:34:17 +00:00
<?php
if (!Auth::check()) {
become403Page(UOJLocale::get('need login'));
}
2022-09-24 05:24:48 +00:00
if (!isset($_COOKIE['bootstrap4'])) {
$REQUIRE_LIB['bootstrap5'] = '';
}
2022-09-18 11:34:17 +00:00
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('data');
if (isSuperUser($myUser)) {
$new_list_form = new UOJForm('new_list');
$new_list_form->handle = function() {
DB::query("insert into lists (title, is_hidden) values ('未命名题单', 1)");
};
$new_list_form->submit_button_config['align'] = 'right';
$new_list_form->submit_button_config['class_str'] = 'btn btn-primary';
$new_list_form->submit_button_config['text'] = UOJLocale::get('problems::add new list');
$new_list_form->submit_button_config['smart_confirm'] = '';
$new_list_form->runAtServer();
}
function echoList($list) {
2022-09-24 05:24:48 +00:00
global $myUser, $REQUIRE_LIB;
2022-09-18 11:34:17 +00:00
echo '<tr class="text-center">';
if ($list['problem_count'] == $list['accepted'] && $list['problem_count'] > 0) {
echo '<td class="success">';
} else {
echo '<td>';
}
echo '#', $list['list_id'], '</td>';
2022-09-24 05:24:48 +00:00
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo '<td class="text-start">';
} else {
echo '<td class="text-left">';
}
2022-09-18 11:34:17 +00:00
if ($list['is_hidden']) {
echo ' <span class="text-danger">[隐藏]</span> ';
}
2022-09-24 05:24:48 +00:00
echo '<a ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' class="text-decoration-none" ';
}
2022-09-24 06:26:49 +00:00
echo ' href="/problem_list/', $list['list_id'], '">', $list['title'], '</a> ';
2022-09-18 11:34:17 +00:00
foreach (queryProblemListTags($list['list_id']) as $tag) {
2022-09-24 05:24:48 +00:00
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo '<a class="uoj-list-tag my-1">';
echo '<span class="badge bg-secondary">';
} else {
echo '<a class="uoj-list-tag">';
echo '<span class="badge badge-pill badge-secondary">';
}
echo HTML::escape($tag), '</span>', '</a>';
2022-09-18 11:34:17 +00:00
}
echo '</td>';
echo "<td>{$list['accepted']}</td>";
echo "<td>{$list['problem_count']}</td>";
echo '</tr>';
}
?>
<?php echoUOJPageHeader(UOJLocale::get('problems lists')) ?>
2022-09-24 05:39:55 +00:00
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
2022-09-25 06:16:36 +00:00
<div class="row">
<div class="col-sm-12 col-md-9">
2022-09-24 05:39:55 +00:00
<div class="d-flex justify-content-between">
<?php endif ?>
<h1 class="h2">
<?= UOJLocale::get('problems lists') ?>
</h1>
2022-09-24 05:24:48 +00:00
<?php if (isSuperUser($myUser)): ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="text-end mb-2">
<?php endif ?>
<?php $new_list_form->printHTML(); ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
2022-09-24 05:39:55 +00:00
<?php endif ?>
2022-09-24 05:24:48 +00:00
<?php endif ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
<?php endif ?>
2022-09-18 11:34:17 +00:00
2022-09-24 05:24:48 +00:00
<?php
$problem_list_caption = UOJLocale::get('problems::problem list');
2022-09-18 11:34:17 +00:00
$ac_caption = UOJLocale::get('problems::ac');
$total_caption = UOJLocale::get('problems::total');
$header = <<<EOD
<tr>
<th class="text-center" style="width:5em;">ID</th>
<th>{$problem_list_caption}</th>
<th class="text-center" style="width:5em;">{$ac_caption}</th>
<th class="text-center" style="width:5em;">{$total_caption}</th>
</tr>
EOD;
$cond = array();
$search_tag = null;
if (isset($_GET['tag'])) {
$search_tag = $_GET['tag'];
}
if ($search_tag) {
$cond[] = "'" . DB::escape($search_tag) . "' in (select tag from lists_tags where lists_tags.list_id = a.id)";
}
if (!isSuperUser($myUser)) {
$cond[] = "is_hidden = 0";
}
if ($cond) {
$cond = join($cond, ' and ');
} else {
$cond = '1';
}
$from = "lists a left join lists_problems b on a.id = b.list_id left join best_ac_submissions c on (b.problem_id = c.problem_id and c.submitter = '{$myUser['username']}')";
2022-09-24 05:24:48 +00:00
$table_config = array(
'page_len' => 40,
'table_classes' => array('table', 'table-bordered', 'table-hover', 'table-striped'),
'head_pagination' => true,
'pagination_table' => 'lists'
);
if (isset($REQUIRE_LIB['bootstrap5'])) {
$table_config['div_classes'] = array('card', 'mb-3');
$table_config['table_classes'] = array('table', 'uoj-table', 'mb-0');
}
2022-09-18 11:34:17 +00:00
echoLongTable(
array('a.id as list_id', 'a.title as title', 'a.is_hidden as is_hidden', 'count(b.problem_id) as problem_count', 'count(c.submitter) as accepted'),
$from, $cond, 'group by a.id order by a.id desc',
$header,
'echoList',
2022-09-24 05:24:48 +00:00
$table_config,
2022-09-18 11:34:17 +00:00
);
?>
2022-09-25 06:16:36 +00:00
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
2022-09-25 10:28:43 +00:00
<aside class="col mt-3 mt-md-0">
2022-09-25 06:16:36 +00:00
<?php
uojIncludeView('sidebar', array());
?>
</aside>
</div>
<?php endif ?>
2022-09-18 11:34:17 +00:00
<?php echoUOJPageFooter() ?>