176 lines
8.0 KiB
PHP
176 lines
8.0 KiB
PHP
<?php
|
||||
|
|
/**
|
|||
|
|
* 日历本管理(v12):建本 / 改名 / 换色 / 删除 / 共享给别人(只读或可写)。
|
|||
|
|
*
|
|||
|
|
* ⚠️ 「观影」「旅行」两本是系统预置的,不能改名也不能删 ——
|
|||
|
|
* 它们的日程是从观影模块与旅程模块实时汇总出来的,删掉就再也回不来了
|
|||
|
|
* (Calendar::delete 里也只删 kind='custom',这里是同一道栅栏的界面侧)。
|
|||
|
|
*
|
|||
|
|
* @param array $cals 我自己的日历本(kind 任意)
|
|||
|
|
* @param array $shared 别人共享给我的
|
|||
|
|
* @param array $people 名册(共享下拉用)
|
|||
|
|
*/
|
|||
|
|
$isEditing = !empty($editing);
|
|||
|
|
$canWrite = \App\Auth::canWrite();
|
|||
|
|
?>
|
|||
|
|
<div class="page-head">
|
|||
|
|
<h1>日历本</h1>
|
|||
|
|
<span class="sub">共 <?= count($cals) ?> 本<?= $shared ? ',别人共享给我 ' . count($shared) . ' 本' : '' ?></span>
|
|||
|
|
<div class="actions">
|
|||
|
|
<a class="btn btn-ghost" href="<?= e(url('calendar')) ?>">返回日程</a>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<?php if (!$canWrite): ?>
|
|||
|
|
<div class="card card-pad empty"><b>只读账号</b>访客只能查看日历本,不能新建或修改。</div>
|
|||
|
|
<?php else: ?>
|
|||
|
|
<div class="card card-pad">
|
|||
|
|
<h2 class="cinema-h2"><?= $isEditing ? '编辑日历本' : '新建日历本' ?></h2>
|
|||
|
|
<form method="post" action="<?= e(url($isEditing ? 'calendar/cal_update' : 'calendar/cal_add')) ?>">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<?php if ($isEditing): ?>
|
|||
|
|
<input type="hidden" name="id" value="<?= (int)$editing['id'] ?>">
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<div class="form-grid">
|
|||
|
|
<div class="field">
|
|||
|
|
<label for="cb-name">名字 *</label>
|
|||
|
|
<input class="input" id="cb-name" name="name" required
|
|||
|
|
value="<?= e(old('name', $editing['name'] ?? '')) ?>" placeholder="如:体检 / 值日">
|
|||
|
|
</div>
|
|||
|
|
<div class="field">
|
|||
|
|
<label for="cb-color">颜色</label>
|
|||
|
|
<div class="color-row">
|
|||
|
|
<input type="color" id="cb-color" name="color" class="color-picker"
|
|||
|
|
value="<?= e(old('color', $editing['color'] ?? '#4A7C82')) ?>">
|
|||
|
|
<span class="color-hex"><?= e(old('color', $editing['color'] ?? '#4A7C82')) ?></span>
|
|||
|
|
<span class="preset-palette">
|
|||
|
|
<?php foreach (\App\Calendar::PRESET_CAL_COLORS as $pc): ?>
|
|||
|
|
<span class="preset-color" data-color="<?= $pc ?>" style="background: <?= $pc ?>;" title="<?= $pc ?>"></span>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</span>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
<div class="btn-row">
|
|||
|
|
<button class="btn" type="submit"><?= $isEditing ? '保存' : '新建' ?></button>
|
|||
|
|
<?php if ($isEditing): ?>
|
|||
|
|
<a class="btn btn-ghost" href="<?= e(url('calendar/calendars')) ?>">取消</a>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</div>
|
|||
|
|
</form>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
|
|||
|
|
<div class="card card-pad">
|
|||
|
|
<h2 class="cinema-h2">我自己的</h2>
|
|||
|
|
<?php if (!$cals): ?>
|
|||
|
|
<p class="empty-hint">还没有日历本。</p>
|
|||
|
|
<?php else: ?>
|
|||
|
|
<div class="table-wrap">
|
|||
|
|
<table class="table">
|
|||
|
|
<thead>
|
|||
|
|
<tr><th>名字</th><th>颜色</th><th>共享给</th><?php if ($canWrite): ?><th>操作</th><?php endif; ?></tr>
|
|||
|
|
</thead>
|
|||
|
|
<tbody>
|
|||
|
|
<?php foreach ($cals as $c): ?>
|
|||
|
|
<tr>
|
|||
|
|
<td>
|
|||
|
|
<b><?= e((string)$c['name']) ?></b>
|
|||
|
|
<?php if (($c['kind'] ?? '') !== 'custom'): ?>
|
|||
|
|
<span class="node-badge">系统预置</span>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</td>
|
|||
|
|
<td>
|
|||
|
|
<span class="color-preview" style="background: <?= e((string)$c['color']) ?>;"></span>
|
|||
|
|
<span class="mono"><?= e((string)$c['color']) ?></span>
|
|||
|
|
</td>
|
|||
|
|
<td>
|
|||
|
|
<?php $sh = $shares[(int)$c['id']] ?? []; ?>
|
|||
|
|
<?php if (!$sh): ?>
|
|||
|
|
<span class="link-quiet">不共享</span>
|
|||
|
|
<?php else: ?>
|
|||
|
|
<div class="trip-people">
|
|||
|
|
<?php foreach ($sh as $s): ?>
|
|||
|
|
<?= person_chip($s) ?>
|
|||
|
|
<span class="node-badge"><?= ($s['perm'] ?? '') === 'write' ? '可写' : '只读' ?></span>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if ($canWrite && $people): ?>
|
|||
|
|
<details class="node-add">
|
|||
|
|
<summary class="link-quiet">共享设置</summary>
|
|||
|
|
<form class="inline-form" method="post" action="<?= e(url('calendar/cal_share')) ?>">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="id" value="<?= (int)$c['id'] ?>">
|
|||
|
|
<select class="select" name="person_id">
|
|||
|
|
<?php foreach ($people as $p): ?>
|
|||
|
|
<?php if ((int)$p['id'] === (int)\App\Auth::personId()) { continue; } ?>
|
|||
|
|
<option value="<?= (int)$p['id'] ?>"><?= e(person_name($p)) ?></option>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</select>
|
|||
|
|
<select class="select" name="perm">
|
|||
|
|
<option value="read">只读</option>
|
|||
|
|
<option value="write">可写</option>
|
|||
|
|
</select>
|
|||
|
|
<button class="btn btn-sm" type="submit">共享</button>
|
|||
|
|
</form>
|
|||
|
|
<?php foreach ($sh as $s): ?>
|
|||
|
|
<form class="inline-form" method="post" action="<?= e(url('calendar/cal_unshare')) ?>">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="id" value="<?= (int)$c['id'] ?>">
|
|||
|
|
<input type="hidden" name="person_id" value="<?= (int)$s['person_id'] ?>">
|
|||
|
|
<span class="cal-share-name"><?= e(person_name($s)) ?></span>
|
|||
|
|
<button class="btn btn-ghost btn-sm" type="submit">取消共享</button>
|
|||
|
|
</form>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</details>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</td>
|
|||
|
|
<?php if ($canWrite): ?>
|
|||
|
|
<td>
|
|||
|
|
<div class="actions">
|
|||
|
|
<?php if (($c['kind'] ?? '') === 'custom'): ?>
|
|||
|
|
<a class="btn btn-ghost btn-sm"
|
|||
|
|
href="<?= e(url('calendar/calendars', ['edit' => (int)$c['id']])) ?>">编辑</a>
|
|||
|
|
<form method="post" action="<?= e(url('calendar/cal_del')) ?>"
|
|||
|
|
onsubmit="return confirm('删除「<?= e((string)$c['name']) ?>」?本子里的日程会一起删掉。')">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="id" value="<?= (int)$c['id'] ?>">
|
|||
|
|
<button class="btn btn-danger btn-sm" type="submit">删除</button>
|
|||
|
|
</form>
|
|||
|
|
<?php else: ?>
|
|||
|
|
<span class="link-quiet">不可改</span>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</div>
|
|||
|
|
</td>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</tr>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</tbody>
|
|||
|
|
</table>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<?php if ($shared): ?>
|
|||
|
|
<div class="card card-pad">
|
|||
|
|
<h2 class="cinema-h2">别人共享给我的</h2>
|
|||
|
|
<div class="table-wrap">
|
|||
|
|
<table class="table">
|
|||
|
|
<thead><tr><th>名字</th><th>谁的</th><th>我的权限</th></tr></thead>
|
|||
|
|
<tbody>
|
|||
|
|
<?php foreach ($shared as $c): ?>
|
|||
|
|
<tr>
|
|||
|
|
<td><b><?= e((string)$c['name']) ?></b></td>
|
|||
|
|
<?php /* 共享过来的行里"人"的字段带着前缀(owner_name / owner_nick),
|
|||
|
|
不是 person_name() 直接认的 name / my_nickname —— 在这里适配一次。 */ ?>
|
|||
|
|
<td><?= e(person_name(['name' => $c['owner_name'] ?? '', 'my_nickname' => $c['owner_nick'] ?? ''])) ?></td>
|
|||
|
|
<td><span class="node-badge"><?= ($c['perm'] ?? '') === 'write' ? '可写' : '只读' ?></span></td>
|
|||
|
|
</tr>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</tbody>
|
|||
|
|
</table>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|