Files
FamilyBook/templates/people/import.php
T

95 lines
4.0 KiB
PHP
Raw Normal View History

<?php
/**
* 名册导入(v24 用户 2026-10-03 第 1 条)。
*
* 页面就两件事:挑文件 → 看结果。所以做成**一页**(提交后同页出报告),
* 不跳到"导入历史"之类的第二页 —— 一次导入看完就该结束。
*
* @param array $groups 我能用的分组(导入进来的人可以先归到一组)
* @param array|null $report ContactImporter::run 的结果(null = 还没导入)
*/
$report = $report ?? null;
$canMove = \App\Auth::canWrite();
?>
<div class="page-head">
<h1>导入联系人</h1>
<span class="sub">从手机 / 邮箱导出的通讯录批量加进名册</span>
<div class="actions">
<a class="btn btn-ghost btn-sm" href="<?= e(url('people')) ?>">返回名册</a>
</div>
</div>
<div class="card card-pad">
<h2 class="cinema-h2">选一份文件</h2>
<p class="small muted" style="margin:0 0 14px">
支持 <b>.vcf</b>(vCard,iPhone / 安卓 / 谷歌联系人 / Outlook 都能导出)与
<b>.csv / .txt</b>(表头里有「姓名 / 手机 / 邮箱」之类就能认,中英文表头都行)。
<br>
导入规则:<b>手机号或姓名已经在名册里的,不会重复建人</b>,
只把「他还没有的信息」补上去(已有的一律不动);其余才新建。
</p>
<form method="post" action="<?= e(url('people/import')) ?>" enctype="multipart/form-data">
<?= csrf_field() ?>
<div class="form-grid">
<div class="field full">
<label for="imp-file">联系人文件 *</label>
<input class="input" type="file" id="imp-file" name="contacts"
accept=".vcf,.csv,.txt,text/vcard,text/csv,text/plain" required>
</div>
<div class="field">
<label for="imp-group">加进哪一组</label>
<select class="select" id="imp-group" name="group_id">
<option value="0">先不分类</option>
<?php foreach ($groups as $g): ?>
<option value="<?= (int)$g['id'] ?>"><?= e((string)$g['name']) ?></option>
<?php endforeach; ?>
</select>
<span class="tip">只影响<b>新建</b>的那些人;已有的人保持他原来的分组。</span>
</div>
</div>
<div class="btn-row">
<button class="btn" type="submit">开始导入</button>
</div>
</form>
</div>
<?php if ($report): ?>
<div class="card card-pad">
<h2 class="cinema-h2">
导入结果
<span class="hint">新增 <?= (int)$report['added'] ?> · 补充 <?= (int)$report['updated'] ?> · 无需改动 <?= (int)$report['skipped'] ?></span>
</h2>
<?php if (!$report['people']): ?>
<p class="empty-hint">文件里没有可导入的联系人。</p>
<?php else: ?>
<?php /* ⚠️ 报告的是"这条记录做了什么",逐条列出来:
批量操作最怕"导完不知道改了什么"(尤其"补充"这一类会动到已有的人)。 */ ?>
<div class="table-wrap">
<table class="table">
<thead><tr><th>联系人</th><th>结果</th><th>补上了什么</th></tr></thead>
<tbody>
<?php foreach ($report['people'] as $row): ?>
<?php
$act = (string)$row['action'];
$word = $act === 'added' ? '新建' : ($act === 'updated' ? '补充信息' : '无需改动');
$cls = $act === 'added' ? 'led-asset' : ($act === 'updated' ? 'led-asset' : '');
?>
<tr>
<td><?= e((string)$row['name']) ?></td>
<td class="<?= $cls ?>"><?= e($word) ?></td>
<td class="small muted">
<?= $row['added'] ? e(implode('、', (array)$row['added'])) : '—' ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<div class="btn-row" style="margin-top:14px">
<a class="btn btn-ghost" href="<?= e(url('people')) ?>">去看名册</a>
<a class="btn btn-ghost" href="<?= e(url('people/import')) ?>">再导一份</a>
</div>
</div>
<?php endif; ?>