:::
7-3 加入確認後刪除的機制
- 先在list_action中利用 tadtools內建的 sweet_alert 類別來產生刪除的js函數,以便做出「確認後刪除的功能」:
//顯示活動列表 function list_action() { global $xoopsDB, $xoopsTpl; $tbl = $xoopsDB->prefix('actions'); $sql = "SELECT * FROM `{$tbl}` WHERE `enable` ='1' AND `end_date` > now() ORDER BY `end_date` DESC"; $result = $xoopsDB->query($sql) or web_error($sql); $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); $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'); } - render()的第一個參數是js的刪除函數名稱,第二個參數則是執行刪除的路徑,最後一個參數是傳入的編號名稱。
- 編輯 templates/tad_signup_index.tpl 樣板,根據身份加入「刪除」按鈕
<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>
7-2 更新活動