117 lines
6.2 KiB
PHP
117 lines
6.2 KiB
PHP
<?php
|
||||
|
|
/**
|
|||
|
|
* 「名册分组」管理卡片 —— 从个人设置**搬出来**的(v52 用户 2026-10-15 第 6 条)。
|
|||
|
|
*
|
|||
|
|
* 用户原话:「名册右侧,只保留一个添加成员按钮,右侧再加一个设置按钮,
|
|||
|
|
* 点击后下拉设置,第一个就是导入联系人,第二个就是原来个人设置那里的
|
|||
|
|
* **名册分组**,这样**个人设置中就不显示名册分组的内容**了。」
|
|||
|
|
*
|
|||
|
|
* ⇒ 同一个卡片现在挂在「名册 → 设置 → 名册分组」这一页上(`templates/people/settings.php`)。
|
|||
|
|
* ⚠️ 表单 action 仍指向 `settings/groups/*`(**一个字段都没改**)——
|
|||
|
|
* 分组管理是"我自己的分组",与它挂在哪一页无关;
|
|||
|
|
* 换路由只会白白多一处要维护的东西(而且老书签/脚本会失效)。
|
|||
|
|
*
|
|||
|
|
* 变量(require 前设好;**入参仍用宿主那边的名字**,片段内部一律 pg* 前缀,见下):
|
|||
|
|
* $groups PersonGroup::orderFor(...) 的结果(公共 + 我的)
|
|||
|
|
* $groupCounts gid => 人数
|
|||
|
|
* $rosterCount 我的名册人数
|
|||
|
|
*/
|
|||
|
|
/* ⚠️ 变量名**必须带片段前缀**(pg*):模板片段与宿主 `require` 是**共享作用域**,
|
|||
|
|
用 `$groups` 这种通名会把宿主模板的同名变量覆盖掉(本项目有静态断言专门查这个)。 */
|
|||
|
|
$pgGroups = (array)($groups ?? []);
|
|||
|
|
$pgCounts = (array)($groupCounts ?? []);
|
|||
|
|
$pgRosterN = (int)($rosterCount ?? 0);
|
|||
|
|
$pgTotal = count($pgGroups);
|
|||
|
|
?>
|
|||
|
|
<div class="card card-pad">
|
|||
|
|
<h2 class="section-title">
|
|||
|
|
名册分组
|
|||
|
|
<span class="hint">公共的 + 我自己加的</span>
|
|||
|
|
</h2>
|
|||
|
|
<p class="small muted" style="margin:0 0 16px">
|
|||
|
|
名册是按「关系分组」分栏显示的。这里有两层:
|
|||
|
|
<b>公共分组</b>由管理员在「系统设置」里维护(全家都能用);
|
|||
|
|
你要是觉得不够,就在下面<b>加只给自己看的分组</b>,别人看不到、也不受影响。
|
|||
|
|
<br>
|
|||
|
|
列表里 <b>公共</b> 标的是大家共用的那几个。
|
|||
|
|
哪一组排前面也是你自己的习惯,用 ▲ ▼ 调 —— 别人看到的顺序不变。
|
|||
|
|
<br>
|
|||
|
|
你的名册现在有 <b><?= $pgRosterN ?></b> 人。
|
|||
|
|
</p>
|
|||
|
|
|
|||
|
|
<?php if (!$pgGroups): ?>
|
|||
|
|
<p class="small muted" style="margin:0 0 14px">还没有分组。加一个吧。</p>
|
|||
|
|
<?php else: ?>
|
|||
|
|
<ol class="order-list">
|
|||
|
|
<?php foreach ($pgGroups as $i => $g): $pgGid = (int)$g['id']; $pgOwn = (int)$g['owner_id']; ?>
|
|||
|
|
<li class="order-row">
|
|||
|
|
<span class="order-no"><?= $i + 1 ?></span>
|
|||
|
|
<span class="order-name">
|
|||
|
|
<?= e((string)$g['name']) ?>
|
|||
|
|
<?php if ($pgOwn === 0): ?><span class="badge">公共</span><?php else: ?><span class="badge badge-open">我的</span><?php endif; ?>
|
|||
|
|
</span>
|
|||
|
|
<span class="order-count"><?= (int)($pgCounts[$pgGid] ?? 0) ?> 人</span>
|
|||
|
|
<form method="post" action="<?= e(url('settings/groups/move')) ?>" class="order-move">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="id" value="<?= $pgGid ?>">
|
|||
|
|
<input type="hidden" name="scope" value="me">
|
|||
|
|
<button class="btn btn-ghost btn-sm" type="submit" name="dir" value="up"
|
|||
|
|
title="上移一组" <?= $i === 0 ? 'disabled' : '' ?>>▲</button>
|
|||
|
|
<button class="btn btn-ghost btn-sm" type="submit" name="dir" value="down"
|
|||
|
|
title="下移一组" <?= $i === $pgTotal - 1 ? 'disabled' : '' ?>>▼</button>
|
|||
|
|
</form>
|
|||
|
|
</li>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</ol>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
|
|||
|
|
<form method="post" action="<?= e(url('settings/groups/add')) ?>" class="inline-form" style="margin-top:16px">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="scope" value="me">
|
|||
|
|
<label class="sr-only" for="newMyGroup">新分组名</label>
|
|||
|
|
<input class="input" id="newMyGroup" name="name" maxlength="20" placeholder="例如:球友、老同学">
|
|||
|
|
<button class="btn btn-sm" type="submit">加一个我自己的分组</button>
|
|||
|
|
</form>
|
|||
|
|
|
|||
|
|
<?php
|
|||
|
|
// 只有我自己建的分组才给改名 / 删除 —— 公共分组要在系统设置里改(那是管理员的事),
|
|||
|
|
// 免得有人在自己设置里把"家人"改成别的、影响全家。
|
|||
|
|
$pgMine = array_values(array_filter($pgGroups, fn($g) => (int)$g['owner_id'] > 0));
|
|||
|
|
?>
|
|||
|
|
<?php if ($pgMine): ?>
|
|||
|
|
<ul class="group-manage" style="margin-top:14px">
|
|||
|
|
<?php foreach ($pgMine as $g): $pgGid = (int)$g['id']; ?>
|
|||
|
|
<li class="group-manage-row">
|
|||
|
|
<form method="post" action="<?= e(url('settings/groups/rename')) ?>" class="group-rename">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="id" value="<?= $pgGid ?>">
|
|||
|
|
<input type="hidden" name="scope" value="me">
|
|||
|
|
<label class="sr-only" for="gname<?= $pgGid ?>">分组名</label>
|
|||
|
|
<input class="input" id="gname<?= $pgGid ?>" name="name" maxlength="20"
|
|||
|
|
value="<?= e((string)$g['name']) ?>">
|
|||
|
|
<button class="btn btn-ghost btn-sm" type="submit">改名</button>
|
|||
|
|
</form>
|
|||
|
|
<span class="group-count muted small"><?= (int)($pgCounts[$pgGid] ?? 0) ?> 人</span>
|
|||
|
|
<?php /* 删除做成两步(<details>),不用 JS 也能防手滑 —— 一点就没了太容易出事 */ ?>
|
|||
|
|
<details class="del-wrap">
|
|||
|
|
<summary class="btn btn-ghost btn-sm">删除</summary>
|
|||
|
|
<form method="post" action="<?= e(url('settings/groups/delete')) ?>" class="del-confirm">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="id" value="<?= $pgGid ?>">
|
|||
|
|
<input type="hidden" name="scope" value="me">
|
|||
|
|
<span class="small muted">这组的人会变成「未分类」,确定?</span>
|
|||
|
|
<button class="btn btn-ghost btn-sm danger" type="submit">确认删除</button>
|
|||
|
|
</form>
|
|||
|
|
</details>
|
|||
|
|
</li>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</ul>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
|
|||
|
|
<?php if (\App\Auth::isAdmin()): ?>
|
|||
|
|
<p class="small muted" style="margin:16px 0 0">
|
|||
|
|
公共分组在「<a href="<?= e(url('settings')) ?>#public-groups">系统设置</a>」里维护。
|
|||
|
|
</p>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</div>
|
|||
|
|
<?php unset($pgGroups, $pgCounts, $pgRosterN, $pgTotal, $pgMine, $pgGid, $pgOwn, $g); ?>
|