Files
FamilyBook/templates/people/show.php
T

148 lines
6.5 KiB
PHP
Raw Normal View History

<?php
$age = age_from($person['birthday'] ?? '');
$isMe = (int)$person['id'] === (int)\App\Auth::personId();
$admin = \App\Auth::isAdmin();
?>
<div class="page-head">
<h1><?= e($person['name']) ?></h1>
<span class="sub">
<?php if (!empty($person['nickname'])): ?>小名 <?= e($person['nickname']) ?><?php endif; ?>
</span>
<div class="actions">
<?php if ($admin): ?>
<a class="btn btn-ghost btn-sm" href="<?= e(url('people/edit', ['id' => (int)$person['id']])) ?>">编辑</a>
<form method="post" action="<?= e(url('people/destroy')) ?>" style="display:inline"
onsubmit="return confirm('确定要从名册里移除 <?= e($person['name']) ?> 吗?相关的账号也会一起删掉。')">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$person['id'] ?>">
<button class="btn btn-danger btn-sm" type="submit">移除</button>
</form>
<?php endif; ?>
</div>
</div>
<div class="detail">
<aside class="detail-photo">
<img src="<?= e(\App\Upload::avatarUrl($person['avatar'])) ?>" alt="">
<div class="name"><?= e($person['name']) ?></div>
<div class="sub">
<?php if ($person['account_role'] === 'admin' && $person['account_status'] === 'active'): ?>
家庭管理员
<?php elseif (!empty($person['account_id'])): ?>
已开通登录<?= $person['account_status'] === 'disabled' ? '(已停用)' : '' ?>
<?php else: ?>
还没有开通登录
<?php endif; ?>
</div>
</aside>
<div>
<div class="card card-pad">
<dl class="kv">
<div class="kv-row">
<dt>姓名</dt><dd><?= e($person['name']) ?></dd>
</div>
<?php if (!empty($person['nickname'])): ?>
<div class="kv-row"><dt>小名</dt><dd><?= e($person['nickname']) ?></dd></div>
<?php endif; ?>
<div class="kv-row">
<dt>性别</dt>
<dd><?= $person['gender'] === 'm' ? '男' : ($person['gender'] === 'f' ? '女' : '未填写') ?></dd>
</div>
<div class="kv-row">
<dt>生日</dt>
<dd>
<?php if (!empty($person['birthday'])): ?>
<?= e($person['birthday']) ?>
<?php if ($age !== null): ?> · <?= (int)$age ?> 岁<?php endif; ?>
<?php $d = days_until_birthday($person['birthday']); ?>
<?php if ($d === 0): ?> · <span style="color:var(--brand)">今天生日</span>
<?php elseif ($d !== null): ?> · 还有 <?= (int)$d ?> 天<?php endif; ?>
<?php else: ?>
<span class="muted">未填写</span>
<?php endif; ?>
</dd>
</div>
<div class="kv-row">
<dt>手机号</dt>
<dd class="mono"><?= e(\App\Crypto::maskPhone($person['phone_encrypted'] ?? '')) ?></dd>
</div>
<div class="kv-row">
<dt>身份证号</dt>
<dd class="mono"><?= e(\App\Crypto::maskIdCard($person['id_card_encrypted'] ?? '')) ?></dd>
</div>
<?php if (!empty($person['email'])): ?>
<div class="kv-row"><dt>邮箱</dt><dd><?= e($person['email']) ?></dd></div>
<?php endif; ?>
<?php if (!empty($person['address'])): ?>
<div class="kv-row"><dt>住址</dt><dd><?= e($person['address']) ?></dd></div>
<?php endif; ?>
<?php if (!empty($person['note'])): ?>
<div class="kv-row"><dt>备注</dt><dd><?= nl2br(e($person['note'])) ?></dd></div>
<?php endif; ?>
<div class="kv-row">
<dt>最近登录</dt>
<dd><?= !empty($person['last_login_at']) ? e($person['last_login_at']) : '从未登录' ?></dd>
</div>
</dl>
</div>
<?php if ($admin): ?>
<div class="card card-pad" style="margin-top:16px">
<h2 class="section-title">登录账号</h2>
<?php if (empty($person['account_id'])): ?>
<p class="small muted" style="margin:0 0 14px">
开通后,<?= e($person['name']) ?> 就能用手机号和密码登录家书了。
</p>
<form method="post" action="<?= e(url('accounts/create')) ?>" class="form-grid">
<?= csrf_field() ?>
<input type="hidden" name="person_id" value="<?= (int)$person['id'] ?>">
<div class="field">
<label>登录密码</label>
<input class="input" name="password" type="password" placeholder="至少 8 位,含字母和数字" required>
</div>
<div class="field">
<label>角色</label>
<select class="select" name="role">
<option value="member">普通成员</option>
<option value="admin">管理员</option>
</select>
</div>
<div class="field full">
<button class="btn btn-sm" type="submit">开通账号</button>
</div>
</form>
<?php else: ?>
<p class="small muted" style="margin:0 0 14px">
账号已开通,登录名是 <?= e($person['name']) ?> 的手机号。
</p>
<div class="btn-row" style="margin-top:0;flex-wrap:wrap">
<?php if (!$isMe): ?>
<form method="post" action="<?= e(url('accounts/role')) ?>" style="display:inline">
<?= csrf_field() ?>
<input type="hidden" name="person_id" value="<?= (int)$person['id'] ?>">
<input type="hidden" name="role" value="<?= $person['account_role'] === 'admin' ? 'member' : 'admin' ?>">
<button class="btn btn-ghost btn-sm" type="submit">
<?= $person['account_role'] === 'admin' ? '取消管理员' : '设为管理员' ?>
</button>
</form>
<form method="post" action="<?= e(url('accounts/status')) ?>" style="display:inline">
<?= csrf_field() ?>
<input type="hidden" name="person_id" value="<?= (int)$person['id'] ?>">
<input type="hidden" name="status" value="<?= $person['account_status'] === 'active' ? 'disabled' : 'active' ?>">
<button class="btn btn-ghost btn-sm" type="submit">
<?= $person['account_status'] === 'active' ? '停用账号' : '启用账号' ?>
</button>
</form>
<?php else: ?>
<span class="small muted">这是你自己 —— 要改自己的权限,请让另一位管理员来操作。</span>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>