:::

7-2-2 產生 CSV 完整內容

您沒有觀看影片的權限

您沒有觀看影片的權限

請先登入,登入後,確認您的權限後,即可觀看影片。

  1. 編輯 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;
    

     

  2. 修改一下 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 \


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1748%26tbsn%3D48

書籍目錄

展開 | 闔起

線上使用者

52人線上 (8人在瀏覽線上書籍)

會員: 0

訪客: 52

更多…