csv.php
,加入 $type
變數,當 $type
值為 signup
時,才抓取完整內容:
<?php
use Xmf\Request;
use XoopsModules\Tad_signup\Tad_signup_actions;
use XoopsModules\Tad_signup\Tad_signup_data;
require_once __DIR__ . '/header.php';
if (!$_SESSION['can_add']) {
redirect_header($_SERVER['PHP_SELF'], 3, "您沒有權限使用此功能");
}
$id = Request::getInt('id');
$type = Request::getString('type');
$action = Tad_signup_actions::get($id);
if ($action['uid'] != $xoopsUser->uid()) {
redirect_header($_SERVER['PHP_SELF'], 3, "您沒有權限使用此功能");
}
$csv = [];
$head_row = explode("\n", $action['setup']);
$head = [];
foreach ($head_row as $head_data) {
$cols = explode(',', $head_data);
if (strpos($cols[0], '#') === false) {
$head[] = str_replace('*', '', trim($cols[0]));
}
}
$head[] = '錄取';
$head[] = '報名日期';
$head[] = '身份';
$csv[] = implode(',', $head);
if ($type == 'signup') {
$signup = Tad_signup_data::get_all($action['id']);
// Utility::dd($signup);
foreach ($signup as $signup_data) {
$iteam = [];
foreach ($signup_data['tdc'] as $user_data) {
$iteam[] = implode('|', $user_data);
}
if ($signup_data['accept'] === '1') {
$iteam[] = '錄取';
} elseif ($signup_data['accept'] === '0') {
$iteam[] = '未錄取';
} else {
$iteam[] = '尚未設定';
}
$iteam[] = $signup_data['signup_date'];
$iteam[] = $signup_data['tag'];
$csv[] = implode(',', $iteam);
}
}
$content = implode("\n", $csv);
$content = mb_convert_encoding($content, 'Big5');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename= {$action['title']}報名名單.csv");
echo $content;
exit;
templates\op_tad_signup_actions_show.tpl
按鈕的連結
<a href="<{$xoops_url}>/modules/tad_signup/csv.php?id=<{$id}>&type=signup" class="btn btn-primary"><i class="fa fa-file-text-o" aria-hidden="true"></i> 匯出CSV名單</a>
$head_row = explode("\n", $action['setup']);
$head = [];
foreach ($head_row as $head_data) {
$cols = explode(',', $head_data);
if (strpos($cols[0], '#') === false) {
$head[] = str_replace('*', '', trim($cols[0]));
}
}
$TadDataCenter = new TadDataCenter('tad_signup');
$head = $TadDataCenter->getAllColItems($action['setup']);
tadtools/class/TadDataCenter.php 必須是 2021/10/29 日以後的版本,可至此下載覆蓋
link to https://github.com/tadlearn/tad_signup/commit/62dc3b4df2468ddd9f3e145919ee1b04f5af032a \