Files
FamilyBook/templates/days/form.php
T

96 lines
3.7 KiB
PHP
Raw Normal View History

<?php
/**
* 新建 / 编辑纪念日(v24 用户第 13 条)
*
* 用户原话:「可以根据阴历和阳历来设置纪念日 …… 纪念日,需要按照阴历和阳历进行重复。」
* 所以重复方式这一栏是核心:阳历 / 农历 / 只此一次。
* 选农历时,下面的月/日填的是**农历**的月日(不是什么公历日期换算)。
*
* @param array|null $editing 编辑时的既有记录
* @param array $people 名册
*/
$e0 = $editing ?: [];
$v = static fn(string $k, $def = '') => $e0[$k] ?? $def;
$repeat = (string)($e0['repeat_type'] ?? 'solar');
?>
<div class="page-head">
<h1><?= $editing ? '编辑纪念日' : '新建纪念日' ?></h1>
<div class="actions">
<a class="btn btn-ghost" href="<?= e(url('days')) ?>">返回</a>
</div>
</div>
<form class="card card-pad" method="post" action="<?= e(url('days/save')) ?>">
<?= csrf_field() ?>
<?php if ($editing): ?><input type="hidden" name="id" value="<?= (int)$e0['id'] ?>"><?php endif; ?>
<div class="form-grid">
<div class="field full">
<label for="an-title">叫什么 *</label>
<input class="input" id="an-title" name="title" required
value="<?= e((string)$v('title')) ?>" placeholder="如:结婚纪念日">
</div>
<div class="field">
<label for="an-repeat">按什么重复 *</label>
<select class="select" id="an-repeat" name="repeat_type">
<?php foreach (\App\Anniversary::REPEAT as $rk => $rv): ?>
<option value="<?= e($rk) ?>" <?= $repeat === $rk ? 'selected' : '' ?>><?= e($rv) ?></option>
<?php endforeach; ?>
</select>
<span class="tip">选「农历」时,下面填的是**农历**的月日(不是公历)。</span>
</div>
<div class="field">
<label for="an-kind">分类</label>
<input class="input" id="an-kind" name="kind" list="anKinds"
value="<?= e((string)$v('kind')) ?>" placeholder="如:结婚纪念日">
<datalist id="anKinds">
<?php foreach (\App\Anniversary::PRESET_KINDS as $k): ?>
<option value="<?= e($k) ?>"></option>
<?php endforeach; ?>
</datalist>
</div>
<div class="field">
<label for="an-month">月 *</label>
<input class="input" id="an-month" name="month" type="number" min="1" max="12" required
value="<?= (int)$v('month', 1) ?>">
</div>
<div class="field">
<label for="an-day">日 *</label>
<input class="input" id="an-day" name="day" type="number" min="1" max="31" required
value="<?= (int)$v('day', 1) ?>">
</div>
<div class="field">
<label for="an-person">与谁相关</label>
<select class="select" id="an-person" name="person_id">
<option value="0">不指定</option>
<?php foreach ($people as $p): ?>
<option value="<?= (int)$p['id'] ?>" <?= (int)$v('person_id', 0) === (int)$p['id'] ? 'selected' : '' ?>>
<?= e(person_name($p)) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="field">
<label for="an-leap">农历闰月</label>
<label class="chk-inline">
<input type="checkbox" id="an-leap" name="is_leap" value="1" <?= !empty($e0['is_leap']) ? 'checked' : '' ?>>
<span>这个农历月是闰月</span>
</label>
</div>
<div class="field full">
<label for="an-note">备注</label>
<textarea class="input" id="an-note" name="note" rows="2"><?= e((string)$v('note')) ?></textarea>
</div>
</div>
<div class="btn-row">
<button class="btn" type="submit"><?= $editing ? '保存' : '添加' ?></button>
<a class="btn btn-ghost" href="<?= e(url('days')) ?>">取消</a>
</div>
</form>