feat: group announcement
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2022-09-23 21:36:14 +08:00
parent 32caffc3ec
commit 4e1d156f0e
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
4 changed files with 60 additions and 1 deletions

View File

@ -442,6 +442,7 @@ UNLOCK TABLES;
CREATE TABLE `groups` ( CREATE TABLE `groups` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`title` text NOT NULL, `title` text NOT NULL,
`announcement` text NOT NULL DEFAULT '',
`is_hidden` tinyint(1) NOT NULL DEFAULT 0, `is_hidden` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;

View File

@ -176,6 +176,24 @@
DB::query("delete from assignments where list_id='{$list_id}' and group_id={$group_id}"); DB::query("delete from assignments where list_id='{$list_id}' and group_id={$group_id}");
}; };
$remove_assignment_form->runAtServer(); $remove_assignment_form->runAtServer();
$announcement_form = new UOJForm('announcement_form');
$announcement_form->addVTextArea('announcement_content', '公告', $group['announcement'],
function ($x) {
return '';
},
null
);
$announcement_form->submit_button_config['align'] = 'compressed';
$announcement_form->submit_button_config['text'] = '更新公告';
$announcement_form->handle = function() {
global $group_id, $myUser;
$content = $_POST['announcement_content'];
$esc_content = DB::escape($content);
DB::query("update groups set announcement = '{$esc_content}' where id = {$group_id}");
};
$announcement_form->runAtServer();
} }
?> ?>
@ -258,6 +276,11 @@
<?php $group_editor->printHTML(); ?> <?php $group_editor->printHTML(); ?>
</div> </div>
<h5>编辑小组公告</h5>
<div>
<?php $announcement_form->printHTML(); ?>
</div>
<h5>添加用户到小组</h5> <h5>添加用户到小组</h5>
<?php $add_new_user_form->printHTML(); ?> <?php $add_new_user_form->printHTML(); ?>

View File

@ -115,7 +115,7 @@ function queryGroup($id) {
function queryUserInGroup($group_id, $username) { function queryUserInGroup($group_id, $username) {
return DB::selectFirst("select * from groups_users where username='$username' and group_id='$group_id'", MYSQLI_ASSOC); return DB::selectFirst("select * from groups_users where username='$username' and group_id='$group_id'", MYSQLI_ASSOC);
} }
function queryGroupOfUser($username) { function queryGroupsOfUser($username) {
return DB::selectAll("select b.title as title, b.id as id from groups_users a inner join groups b on a.group_id = b.id where a.username = '$username' and b.is_hidden = 0 order by id", MYSQLI_ASSOC); return DB::selectAll("select b.title as title, b.id as id from groups_users a inner join groups b on a.group_id = b.id where a.username = '$username' and b.is_hidden = 0 order by id", MYSQLI_ASSOC);
} }
function queryGroupmateCurrentAC($username) { function queryGroupmateCurrentAC($username) {

View File

@ -282,6 +282,41 @@
<?php endif ?> <?php endif ?>
<?php uojIncludeView($PageNav, array('REQUIRE_LIB' => $REQUIRE_LIB)) ?> <?php uojIncludeView($PageNav, array('REQUIRE_LIB' => $REQUIRE_LIB)) ?>
<?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?>
<?php if (Auth::check()): ?>
<?php $groups = queryGroupsOfUser(Auth::id()); ?>
<?php if (count($groups)): ?>
<div class="card card-default mb-2" id="group-user-announcements">
<div class="card-header">
小组公告
</div>
<ul class="list-group list-group-flush">
<?php foreach ($groups as $group): ?>
<?php
$group_detail = DB::selectFirst("select * from groups where id = {$group['id']}");
$group_announcement = $group_detail['announcement'];
?>
<li class="list-group-item">
<a href="<?= HTML::url('/group/'.$group['id']) ?>">
<b><?= $group['title'] ?></b>
</a>
<?php if ($group_announcement): ?>
<div id="announcement-content-<?= $group['id'] ?>"></div>
<script>(function(){
$('#announcement-content-<?= $group['id'] ?>')
.html(DOMPurify.sanitize(decodeURIComponent("<?= urlencode($group_announcement) ?>"), <?= DOM_SANITIZE_CONFIG ?>));
})();</script>
<?php else: ?>
<div>(暂无公告)</div>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif ?>
<?php endif ?>
<?php endif ?>
<?php endif ?> <?php endif ?>