//顯示預設頁面內容 function list_actions() { global $xoopsTpl, $xoopsDB, $isAdmin; $tbl=$xoopsDB->prefix('actions'); $where=$isAdmin?'':"WHERE `enable` = '1'"; $sql="SELECT * FROM `{$tbl}` $where ORDER BY `end_date` DESC"; //getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項); $PageBar = getPageBar($sql, 5, 10); $bar = $PageBar['bar']; $sql = $PageBar['sql']; $total = $PageBar['total']; $xoopsTpl->assign('bar', $bar); $xoopsTpl->assign('total', $total); $result = $xoopsDB->query($sql) or web_error($sql); //取回資料 $actions=[]; $myts = MyTextSanitizer::getInstance(); while($action=$xoopsDB->fetchArray($result)){ $action['title'] = $myts->htmlSpecialChars($action['title']); $action['content'] = $myts->displayTarea($action['content'], 1, 1, 1, 1, 0); $action['overdue'] = time() > strtotime($action['end_date'])?1:0; $actions[]=$action; } $xoopsTpl->assign('actions', $actions); include_once XOOPS_ROOT_PATH . "/modules/tadtools/sweet_alert.php"; $sweet_alert = new sweet_alert(); $sweet_alert->render("delete_action", "admin/main.php?op=delete_action&action_id=", 'action_id'); }
得到的 $bar 就是工具列, $total 則是資料總數,我們可以江浙兩個變數送至樣板來使用,故修改 templates/tad_signup_index.tpl,在裡面加入:
<{if $op=="list_actions"}> <h2>活動列表<small>(共 <{$total}> 個活動)</small></h2> <table class="table table-bordered table-hover table-striped"> <tr class="info"> <th>活動日期</th> <th>活動名稱</th> <th>截止日期</th> <th>功能</th> </tr> <{foreach from=$actions item=action}> <tr> <td><{$action.action_date}></td> <td> <{if $action.enable!=1}> <span class="label label-danger">已關閉</span> <{/if}> <{if $action.overdue}> <span class="label label-warning">已過期</span> <{/if}> <a href="index.php?action_id=<{$action.action_id}>"><{$action.title}></a> </td> <td><{$action.end_date}></td> <td> <{if $isAdmin}> <a href="javascript:delete_action(<{$action.action_id}>)" class="btn btn-danger btn-xs">刪除</a> <a href="admin/main.php?action_id=<{$action.action_id}>" class="btn btn-warning btn-xs">編輯</a> <{/if}> <a href="index.php?action_id=<{$action.action_id}>" class="btn btn-info btn-xs">詳情</a> </td> </tr> <{/foreach}> </table> <{$bar}> <{/if}>