S2OJ/web/app/controllers/groups.php

135 lines
3.4 KiB
PHP
Raw Normal View History

2022-03-20 00:07:46 +00:00
<?php
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('data');
2022-09-18 04:58:35 +00:00
if (!Auth::check()) {
redirectToLogin();
2022-09-18 04:58:35 +00:00
}
2022-04-03 10:18:17 +00:00
2022-09-18 04:58:35 +00:00
if (!isNormalUser($myUser)) {
become403Page();
}
2022-04-03 10:18:17 +00:00
2022-09-24 05:41:31 +00:00
if (!isset($_COOKIE['bootstrap4'])) {
$REQUIRE_LIB['bootstrap5'] = '';
}
2022-09-24 05:39:45 +00:00
2022-03-20 00:07:46 +00:00
if (isSuperUser($myUser)) {
2022-03-20 09:19:07 +00:00
$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
}
function echoGroup($group) {
2022-09-24 05:39:45 +00:00
global $myUser, $REQUIRE_LIB;
2022-03-20 00:07:46 +00:00
2022-03-20 09:19:07 +00:00
echo '<tr class="text-center">';
echo '<td>';
echo '#', $group['group_id'], '</td>';
2022-03-20 00:07:46 +00:00
2022-09-24 05:41:31 +00:00
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo '<td class="text-start">';
} else {
echo '<td class="text-left">';
}
2022-03-20 09:19:07 +00:00
if ($group['is_hidden']) {
echo ' <span class="text-danger">[隐藏]</span> ';
}
2022-09-24 05:39:45 +00:00
echo '<a ';
2022-09-24 05:41:31 +00:00
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo ' class="text-decoration-none" ';
}
echo ' href="/group/', $group['group_id'], '">', $group['title'], '</a>';
2022-03-20 09:19:07 +00:00
echo '</td>';
2022-03-20 00:07:46 +00:00
2022-03-20 09:19:07 +00:00
echo "<td>{$group['user_count']}</td>";
2022-03-20 00:07:46 +00:00
2022-03-20 09:19:07 +00:00
echo '</tr>';
2022-03-20 00:07:46 +00:00
}
2022-09-18 04:58:35 +00:00
?>
2022-03-20 00:07:46 +00:00
<?php echoUOJPageHeader(UOJLocale::get('groups')) ?>
2022-09-24 05:39:45 +00:00
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
2022-09-25 06:16:36 +00:00
<div class="row">
2022-09-26 23:57:01 +00:00
<div class="col-lg-9">
2022-09-24 05:39:45 +00:00
<div class="d-flex justify-content-between">
<?php endif ?>
<h1 class="h2">
<?= UOJLocale::get('groups') ?>
</h1>
<?php if (isSuperUser($myUser)): ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="text-end mb-2">
<?php endif ?>
<?php $new_group_form->printHTML(); ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
<?php endif ?>
<?php endif ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
<?php endif ?>
2022-03-20 00:07:46 +00:00
<?php
2022-09-18 04:58:35 +00:00
$groups_caption = UOJLocale::get('groups');
2022-03-20 00:07:46 +00:00
$users_caption = UOJLocale::get('users count');
$header = <<<EOD
<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;
if (isSuperUser($myUser)) {
2022-03-20 09:19:07 +00:00
$cond = "1";
2022-03-20 00:07:46 +00:00
} else {
2022-03-20 09:19:07 +00:00
$cond = 'is_hidden = 0';
2022-03-20 00:07:46 +00:00
}
$from = "`groups` a left join groups_users b on a.id = b.group_id";
2022-09-24 05:41:31 +00:00
$table_config = array('page_len' => 40,
'table_classes' => array('table', 'table-bordered', 'table-hover', 'table-striped'),
'head_pagination' => true,
'pagination_table' => "`groups`"
);
2022-09-24 05:39:45 +00:00
2022-09-24 05:41:31 +00:00
if (isset($REQUIRE_LIB['bootstrap5'])) {
2022-09-25 10:39:46 +00:00
$table_config['div_classes'] = array('card', 'my-3');
2022-09-24 05:41:31 +00:00
$table_config['table_classes'] = array('table', 'uoj-table', 'mb-0');
}
2022-09-24 05:39:45 +00:00
2022-03-20 00:07:46 +00:00
echoLongTable(
2022-09-18 04:58:35 +00:00
array('a.id as group_id', 'a.title as title', 'a.is_hidden as is_hidden', 'count(b.username) as user_count'),
$from, $cond, 'group by a.id order by a.id asc',
$header,
'echoGroup',
2022-09-24 05:41:31 +00:00
$table_config
2022-09-18 04:58:35 +00:00
);
?>
2022-03-20 00:07:46 +00:00
2022-09-25 06:16:36 +00:00
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
2022-09-26 23:57:01 +00:00
<aside class="col mt-3 mt-lg-0">
2022-09-25 06:16:36 +00:00
<?php
uojIncludeView('sidebar', array());
2022-09-25 10:30:17 +00:00
?>
2022-09-25 06:16:36 +00:00
</aside>
</div>
<?php endif ?>
2022-03-20 00:07:46 +00:00
<?php echoUOJPageFooter() ?>