2026-10-02 09:28:07 +08:00
|
|
|
|
<?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'] ?>">
|
2026-10-03 08:18:05 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
$ppName = 'person_id';
|
|
|
|
|
|
$ppPeople = array_values(array_filter($people,
|
|
|
|
|
|
fn($p) => (int)$p['id'] !== (int)\App\Auth::personId()));
|
|
|
|
|
|
$ppSelected = [];
|
|
|
|
|
|
$ppMode = 'single';
|
|
|
|
|
|
$ppOpenBtn = '选择要共享给谁';
|
|
|
|
|
|
$ppTitle = '共享给谁';
|
|
|
|
|
|
$ppEmptyText = '未选择';
|
|
|
|
|
|
require __DIR__ . '/../_person_picker.php';
|
|
|
|
|
|
?>
|
2026-10-02 09:28:07 +08:00
|
|
|
|
<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">
|
2026-10-03 08:18:05 +08:00
|
|
|
|
<?php /* v24 第 7 条:每本都能导出 .ics(预置本也能 —— 导的是派生出来的内容)。 */ ?>
|
|
|
|
|
|
<a class="btn btn-ghost btn-sm"
|
|
|
|
|
|
href="<?= e(url('calendar/export', ['id' => (int)$c['id']])) ?>">导出 ics</a>
|
2026-10-02 09:28:07 +08:00
|
|
|
|
<?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>
|
|
|
|
|
|
|
2026-10-03 08:18:05 +08:00
|
|
|
|
<?php if ($canWrite): ?>
|
|
|
|
|
|
<?php /* v24 第 7 条:把一个 .ics 文件里的日程整批导进某一本。
|
|
|
|
|
|
只能导进自定义本 —— 观影/旅行两本是派生的,塞进去就成了孤儿日程
|
|
|
|
|
|
(日历里有、观影列表里没有)。 */ ?>
|
|
|
|
|
|
<div class="card card-pad">
|
|
|
|
|
|
<h2 class="cinema-h2">
|
|
|
|
|
|
导入 ics
|
|
|
|
|
|
<span class="hint">把别的日历导出的 .ics 文件整批装进来</span>
|
|
|
|
|
|
</h2>
|
|
|
|
|
|
<p class="small muted" style="margin:0 0 16px">
|
|
|
|
|
|
同一个文件导两次也<b>不会重复</b>:每条日程有个全球唯一的 UID,
|
|
|
|
|
|
已经导过的会被更新,而不是再插一条。
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<form method="post" action="<?= e(url('calendar/import')) ?>" enctype="multipart/form-data">
|
|
|
|
|
|
<?= csrf_field() ?>
|
|
|
|
|
|
<div class="form-grid">
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label for="im-cal">导进哪一本 *</label>
|
|
|
|
|
|
<select class="select" id="im-cal" name="calendar_id">
|
|
|
|
|
|
<?php foreach ($cals as $c): ?>
|
|
|
|
|
|
<?php if (($c['kind'] ?? '') !== 'custom') { continue; } ?>
|
|
|
|
|
|
<option value="<?= (int)$c['id'] ?>"><?= e((string)$c['name']) ?></option>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label for="im-file">.ics 文件 *</label>
|
|
|
|
|
|
<input class="input" type="file" id="im-file" name="ics" accept=".ics,text/calendar" required>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="btn-row">
|
|
|
|
|
|
<button class="btn btn-sm" type="submit">导入</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
<?php /* v24 第 7 条后半:CalDAV —— 把我的日历本订阅到手机/别的日历程序里 */ ?>
|
|
|
|
|
|
<div class="card card-pad">
|
|
|
|
|
|
<h2 class="cinema-h2">
|
|
|
|
|
|
CalDAV 订阅
|
|
|
|
|
|
<span class="hint">在手机日历 / DAVx⁵ / Thunderbird 里订阅你的日历本</span>
|
|
|
|
|
|
</h2>
|
|
|
|
|
|
<p class="small muted" style="margin:0 0 12px">
|
|
|
|
|
|
填下面这个地址 + 你的<b>姓名或手机号</b> + <b>CalDAV 口令</b>,就能把「我的日历本」
|
|
|
|
|
|
同步到别的日历程序里。这是<b>只读</b>订阅的 —— 在手机上改日程请回到本站来改。
|
|
|
|
|
|
<br>口令与登录密码是<b>分开的</b>:订阅凭据会被客户端长期存着,所以另发一个,
|
|
|
|
|
|
随时可换、不影响登录。
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label>服务器地址</label>
|
|
|
|
|
|
<input class="input mono" readonly
|
|
|
|
|
|
value="<?= e(rtrim((string)fb_config('base_url', ''), '/') . '/dav/') ?>">
|
|
|
|
|
|
<span class="tip">在日历客户端里填这一条即可,会列出你所有的日历本。</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php if (!empty($cdPlain)): ?>
|
|
|
|
|
|
<p class="tip" style="background:#FFF6E5;border-color:#E8C98A;padding:8px 12px;border-radius:8px">
|
|
|
|
|
|
<b>这是你的新口令,只显示这一次,请立刻复制走:</b>
|
|
|
|
|
|
<br><code class="mono" style="font-size:15px"><?= e($cdPlain) ?></code>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<?php if ($canWrite): ?>
|
|
|
|
|
|
<div class="btn-row">
|
|
|
|
|
|
<form method="post" action="<?= e(url('calendar/caldav_token')) ?>" class="res-inline">
|
|
|
|
|
|
<?= csrf_field() ?>
|
|
|
|
|
|
<button class="btn btn-sm" type="submit">
|
|
|
|
|
|
<?= !empty($cdHas) ? '重置 CalDAV 口令' : '生成 CalDAV 口令' ?>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
<?php if (!empty($cdHas)): ?>
|
|
|
|
|
|
<form method="post" action="<?= e(url('calendar/caldav_revoke')) ?>" class="res-inline">
|
|
|
|
|
|
<?= csrf_field() ?>
|
|
|
|
|
|
<button class="btn btn-ghost btn-sm" type="submit"
|
|
|
|
|
|
onclick="return confirm('撤销后所有已订阅的客户端都会失去访问。')">撤销口令</button>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
<span class="node-badge">口令已配置</span>
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
<span class="node-badge">还没配置口令</span>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-10-02 09:28:07 +08:00
|
|
|
|
<?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; ?>
|