From c78032628c4d7354f831d1a8bcf21ba03076d6bb Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 18 Oct 2022 07:50:08 +0800 Subject: [PATCH] refactor(web/user/system_msg): bootstrap5 --- web/app/controllers/user_system_msg.php | 116 +++++++++++++++++++----- 1 file changed, 95 insertions(+), 21 deletions(-) diff --git a/web/app/controllers/user_system_msg.php b/web/app/controllers/user_system_msg.php index cc9a0f4..185c61b 100644 --- a/web/app/controllers/user_system_msg.php +++ b/web/app/controllers/user_system_msg.php @@ -1,4 +1,7 @@ - 消息 - 时间 - -EOD; - function echoSysMsg($msg) { - echo $msg['read_time'] == null ? '' : ''; - echo ''; - echo '

'.$msg['title'].'

'; - echo $msg['content']; - echo ''; - echo ''.$msg['send_time'].''; - echo ''; + function newDeleteSystemMsgForm($id) { + $form = new UOJForm('remove_system_msg_' . $id); + + $form->addHidden("msg_id", $id, function($msg_id) { + global $user; + + if (!validateUInt($msg_id)) { + return '消息 ID 不是有效的数字'; + } + + $msg = DB::selectFirst("select * from user_system_msg where id = {$msg_id}"); + if (!$msg || $msg['receiver'] != $user['username']) { + return '消息不存在'; + } + + return ''; + }, null); + $form->handle = function() { + $msg_id = $_POST["msg_id"]; + DB::delete("delete from user_system_msg where id = {$msg_id}"); + }; + $form->submit_button_config['text'] = '删除'; + $form->submit_button_config['margin_class'] = 'mt-0'; + $form->submit_button_config['class_str'] = 'btn btn-link text-decoration-none text-danger p-0'; + $form->submit_button_config['align'] = 'inline'; + $form->submit_button_config['smart_confirm'] = ''; + + return $form; + } + + $pag_config = [ + 'page_len' => 20, + '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; + + if (isSuperUser($myUser)) { + $delete_form = newDeleteSystemMsgForm($msg['id']); + $delete_form->runAtServer(); + $system_msgs[$idx]['delete_form'] = $delete_form; + } + } + + if (Auth::id() == $user['username']) { + DB::update("update user_system_msg set read_time = now() where receiver = '" . $user['username'] . "'"); } ?> + -

系统消息

- array('table'))) ?> - + +

+ 系统消息 +

+ +
+ +
+ +pagination() ?> +