Files
FamilyBook/templates/calendar/event.php
T

85 lines
4.1 KiB
PHP
Raw Normal View History

<?php
/**
* 一条自定义日程:查看 / 改 / 删。
*
* ⚠️ 从月视图点**观影 / 旅程 / 任务**那些条会直接跳到对应模块(它们的"编辑页"在那里),
* 这里只处理 calendar_events 里真正属于某本日历的自定义日程。
*/
$canWrite = \App\Auth::canWrite() && !empty($ev['_can_write']);
?>
<div class="page-head">
<h1><?= e((string)$ev['title']) ?></h1>
<span class="sub"><?= e((string)($ev['starts_at'] ?? '')) ?></span>
<div class="actions">
<a class="btn btn-ghost" href="<?= e(url('calendar', ['ym' => substr((string)$ev['starts_at'], 0, 7)])) ?>">返回日程</a>
</div>
</div>
<div class="card card-pad">
<?php if (!$canWrite): ?>
<dl class="kv">
<div class="kv-row"><dt>日期</dt><dd><?= e((string)$ev['starts_at']) ?></dd></div>
<?php if (!empty($ev['ends_at'])): ?>
<div class="kv-row"><dt>到</dt><dd><?= e((string)$ev['ends_at']) ?></dd></div>
<?php endif; ?>
<div class="kv-row"><dt>时间</dt>
<dd><?= empty($ev['all_day']) ? e(substr((string)$ev['start_time'], 0, 5) . ' – ' . substr((string)$ev['end_time'], 0, 5)) : '全天' ?></dd>
</div>
<?php if (!empty($ev['note'])): ?>
<div class="kv-row"><dt>备注</dt><dd><?= nl2br(e((string)$ev['note'])) ?></dd></div>
<?php endif; ?>
</dl>
<p class="empty-hint">这本日历你只有只读权限,看得到但不能改。</p>
<?php else: ?>
<form method="post" action="<?= e(url('calendar/event_update')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$ev['id'] ?>">
<?php $ym = substr((string)$ev['starts_at'], 0, 7); ?>
<input type="hidden" name="ym" value="<?= e($ym) ?>">
<div class="form-grid">
<div class="field full">
<label for="ev-title">标题 *</label>
<input class="input" id="ev-title" name="title" required value="<?= e((string)$ev['title']) ?>">
</div>
<div class="field">
<label for="ev-date">开始日期 *</label>
<input class="input" type="date" id="ev-date" name="date" required
value="<?= e((string)$ev['starts_at']) ?>">
</div>
<div class="field">
<label for="ev-end">结束日期(跨天时填)</label>
<input class="input" type="date" id="ev-end" name="end_date" value="<?= e((string)($ev['ends_at'] ?? '')) ?>">
</div>
<div class="field full">
<label><input type="checkbox" name="all_day" value="1" <?= empty($ev['all_day']) ? '' : 'checked' ?>> 全天(不填具体时分)</label>
</div>
<div class="field">
<label for="ev-st">开始时刻</label>
<input class="input" type="time" id="ev-st" name="start_time" value="<?= e(substr((string)($ev['start_time'] ?? ''), 0, 5)) ?>">
</div>
<div class="field">
<label for="ev-et">结束时刻</label>
<input class="input" type="time" id="ev-et" name="end_time" value="<?= e(substr((string)($ev['end_time'] ?? ''), 0, 5)) ?>">
</div>
<div class="field full">
<label for="ev-note">备注</label>
<textarea class="input" id="ev-note" name="note" rows="3"><?= e((string)($ev['note'] ?? '')) ?></textarea>
</div>
</div>
<div class="btn-row">
<button class="btn" type="submit">保存</button>
<a class="btn btn-ghost" href="<?= e(url('calendar', ['ym' => $ym])) ?>">取消</a>
</div>
</form>
<?php /* ⚠️ 删除表单必须放在上面那个表单**外面**:<form> 套 <form> 是非法 HTML,
浏览器会把外层表单在嵌套处切开,"保存"按钮就失效了。 */ ?>
<form method="post" action="<?= e(url('calendar/event_del')) ?>" class="ev-del"
onsubmit="return confirm('删除这条日程?')">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$ev['id'] ?>">
<input type="hidden" name="ym" value="<?= e($ym) ?>">
<button class="btn btn-danger btn-sm" type="submit">删除这条日程</button>
</form>
<?php endif; ?>
</div>