S2OJ/web/app/controllers/user_system_msg.php

124 lines
3.0 KiB
PHP
Raw Permalink Normal View History

2016-07-18 16:39:37 +00:00
<?php
2022-11-06 02:26:21 +00:00
requirePHPLib('form');
2022-11-06 02:26:21 +00:00
Auth::check() || redirectToLogin();
2022-04-03 10:18:17 +00:00
2022-11-06 02:26:21 +00:00
if (!($user = UOJUser::query($_GET['username']))) {
become404Page();
}
2022-11-06 02:26:21 +00:00
if (!isSuperUser(Auth::user()) && Auth::id() != $user['username']) {
become403Page();
}
2022-11-06 02:26:21 +00:00
function newDeleteSystemMsgForm($id) {
2023-01-15 23:51:30 +00:00
$form = new UOJForm('remove_system_msg_' . $id);
2022-11-06 02:26:21 +00:00
$form->addHidden("msg_id", $id, function ($msg_id) {
global $user;
2022-11-06 02:26:21 +00:00
if (!validateUInt($msg_id)) {
return '消息 ID 不是有效的数字';
}
2022-11-06 02:26:21 +00:00
$msg = DB::selectFirst("select * from user_system_msg where id = {$msg_id}");
if (!$msg || $msg['receiver'] != $user['username']) {
return '消息不存在';
}
2022-11-06 02:26:21 +00:00
return '';
}, null);
$form->handle = function () {
$msg_id = $_POST["msg_id"];
DB::delete("delete from user_system_msg where id = {$msg_id}");
};
2023-01-15 23:51:30 +00:00
$form->config['submit_button']['class'] = 'btn btn-link text-decoration-none text-danger p-0';
$form->config['submit_button']['text'] = '删除';
$form->config['submit_container']['class'] = 'd-inline';
$form->config['confirm']['smart'] = true;
2022-11-06 02:26:21 +00:00
return $form;
}
$pag_config = [
'page_len' => 10,
'col_names' => ['*'],
'table_name' => 'user_system_msg',
'cond' => "receiver = '{$user['username']}'",
'tail' => 'order by send_time desc',
];
$pag = new Paginator($pag_config);
$system_msgs = [];
foreach ($pag->get() as $idx => $msg) {
$system_msgs[$idx] = $msg;
2022-11-11 23:10:34 +00:00
if (isSuperUser(Auth::user())) {
2022-11-06 02:26:21 +00:00
$delete_form = newDeleteSystemMsgForm($msg['id']);
$delete_form->runAtServer();
$system_msgs[$idx]['delete_form'] = $delete_form;
}
2022-11-06 02:26:21 +00:00
}
?>
2016-07-18 16:39:37 +00:00
<?php echoUOJPageHeader('系统消息') ?>
<div class="row">
2022-11-06 02:26:21 +00:00
<!-- left col -->
<div class="col-lg-9">
<h1>系统消息</h1>
<div class="card mb-3">
<ul class="list-group list-group-flush">
<?php foreach ($system_msgs as $msg) : ?>
2022-11-11 23:10:40 +00:00
<li class="list-group-item
<?php if ($msg['read_time'] == null) : ?>
bg-warning bg-opacity-25
<?php endif ?>
">
2022-11-06 02:26:21 +00:00
<div class="mb-2 d-flex justify-content-between">
<div>
<?php if ($msg['title']) : ?>
<h4 class="d-inline"><?= $msg['title'] ?></h4>
<?php endif ?>
<span class="text-muted small ms-2 d-inline-block">
发送时间: <time><?= $msg['send_time'] ?></time>
</span>
</div>
<?php if (isset($msg['delete_form'])) : ?>
<?php $msg['delete_form']->printHTML() ?>
<?php endif ?>
</div>
<div><?= $msg['content'] ?></div>
</li>
<?php endforeach ?>
<?php if ($pag->isEmpty()) : ?>
2023-01-15 23:51:30 +00:00
<div class="text-center my-4">
2022-11-06 02:26:21 +00:00
<?= UOJLocale::get('none') ?>
</div>
<?php endif ?>
2022-11-06 02:26:21 +00:00
</ul>
</div>
2022-11-06 02:26:21 +00:00
<?= $pag->pagination() ?>
</div>
<!-- end left col -->
2022-11-06 02:26:21 +00:00
<!-- right col -->
<aside class="col-lg-3 mt-3 mt-lg-0">
<?php uojIncludeView('sidebar') ?>
</aside>
<!-- end right col -->
</div>
2022-11-06 02:26:21 +00:00
<?php
if (Auth::id() == $user['username']) {
DB::update("update user_system_msg set read_time = now() where receiver = '" . $user['username'] . "'");
}
?>
2016-07-18 16:39:37 +00:00
<?php echoUOJPageFooter() ?>