S2OJ/web/app/controllers/groups.php

111 lines
2.7 KiB
PHP
Raw Normal View History

2022-03-20 00:07:46 +00:00
<?php
2022-10-22 11:24:48 +00:00
requireLib('bootstrap5');
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('data');
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin();
}
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page();
}
if (isSuperUser($myUser)) {
$new_group_form = new UOJForm('new_group');
$new_group_form->handle = function() {
DB::query("insert into `groups` (title, is_hidden) values ('新小组', 1)");
};
$new_group_form->submit_button_config['align'] = 'right';
$new_group_form->submit_button_config['class_str'] = 'btn btn-primary';
$new_group_form->submit_button_config['text'] = UOJLocale::get('add new group');
$new_group_form->submit_button_config['smart_confirm'] = '';
$new_group_form->runAtServer();
}
?>
2022-03-20 00:07:46 +00:00
<?php echoUOJPageHeader(UOJLocale::get('groups')) ?>
2022-09-25 06:16:36 +00:00
<div class="row">
2022-10-22 11:24:48 +00:00
<!-- left col -->
2022-09-26 23:57:01 +00:00
<div class="col-lg-9">
2022-10-22 11:24:48 +00:00
<!-- title container -->
2022-09-24 05:39:45 +00:00
<div class="d-flex justify-content-between">
2022-10-22 11:24:48 +00:00
2022-09-24 05:39:45 +00:00
<h1 class="h2">
<?= UOJLocale::get('groups') ?>
</h1>
2022-10-22 11:24:48 +00:00
<?php if (isset($new_group_form)): ?>
<div class="text-end mb-2">
<?php $new_group_form->printHTML(); ?>
</div>
2022-09-24 05:39:45 +00:00
<?php endif ?>
</div>
2022-10-22 11:24:48 +00:00
<!-- end title container -->
2022-03-20 00:07:46 +00:00
<?php
2022-10-22 11:24:48 +00:00
$groups_caption = UOJLocale::get('groups');
$users_caption = UOJLocale::get('users count');
$header = <<<EOD
2022-03-20 00:07:46 +00:00
<tr>
<th class="text-center" style="width:5em;">ID</th>
<th>{$groups_caption}</th>
<th class="text-center" style="width:8em;">{$users_caption}</th>
</tr>
EOD;
2022-10-22 11:24:48 +00:00
if (isSuperUser($myUser)) {
$cond = "1";
} else {
$cond = 'is_hidden = 0';
}
echoLongTable(
['a.id as group_id', 'a.title as title', 'a.is_hidden as is_hidden', 'count(b.username) as user_count'],
"`groups` a left join groups_users b on a.id = b.group_id",
$cond,
'group by a.id order by a.id asc',
$header,
function ($group) use ($myUser) {
echo '<tr class="text-center">';
echo '<td>';
echo '#', $group['group_id'], '</td>';
echo '<td class="text-start">';
echo '<a class="text-decoration-none" href="/group/', $group['group_id'], '">', $group['title'], '</a>';
if ($group['is_hidden']) {
echo ' <span class="badge text-bg-danger"><i class="bi bi-eye-slash-fill"></i> ', UOJLocale::get('hidden'), '</span> ';
}
echo '</td>';
echo "<td>{$group['user_count']}</td>";
echo '</tr>';
},
[
'page_len' => 40,
'div_classes' => ['card', 'my-3'],
'table_classes' => ['table', 'uoj-table', 'mb-0'],
'head_pagination' => true,
'pagination_table' => "`groups`",
]
);
?>
2022-10-19 03:57:06 +00:00
<!-- end left col -->
2022-09-25 06:16:36 +00:00
</div>
2022-10-19 03:57:06 +00:00
<!-- right col -->
<aside class="col-lg-3 mt-3 mt-lg-0">
<?php uojIncludeView('sidebar', array()); ?>
2022-09-25 06:16:36 +00:00
</aside>
</div>
2022-03-20 00:07:46 +00:00
<?php echoUOJPageFooter() ?>