:::
主內容區域
10. index.php
<?php
/*-----------引入檔案區--------------*/
include_once "header.php";
$xoopsOption['template_main'] = "tad_signup_index.tpl";
include_once XOOPS_ROOT_PATH . "/header.php";
/*-----------function區--------------*/
//顯示預設頁面內容
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();
if($isAdmin){
$sweet_alert->render("delete_action", "admin/main.php?op=delete_action&action_id=", 'action_id');
}
$sweet_alert->render("delete_signup", "index.php?op=delete_signup&action_id=", 'action_id', "確定要取消嗎?" , "取消後就不能參加活動囉!" , "是!含淚取消!");
}
//顯示預設頁面內容
function show_action($action_id)
{
global $xoopsTpl, $xoopsDB;
$tbl=$xoopsDB->prefix('actions');
$sql="SELECT * FROM `{$tbl}` WHERE `action_id` = '{$action_id}' and `enable` = '1'";
//送至資料庫
$result = $xoopsDB->query($sql) or web_error($sql);
//取回資料
$action=$xoopsDB->fetchArray($result);
$myts = MyTextSanitizer::getInstance();
$action['title'] = $myts->htmlSpecialChars($action['title']);
$action['content'] = $myts->displayTarea($action['content'], 1, 1, 1, 1, 0);
$xoopsTpl->assign('action', $action);
}
function signup($action_id){
global $xoopsDB, $xoopsUser;
$uid=$xoopsUser->uid();
// $signup_date=date("Y-m-d H:i:s");
//寫SQL
$tbl=$xoopsDB->prefix('signups');
$sql = "INSERT INTO `$tbl`
( `uid`, `action_id`, `signup_date`)
VALUES ('{$uid}', '{$action_id}', NOW())";
//送至資料庫
$xoopsDB->queryF($sql) or web_error($sql);
//報名後,將現在的活動編號,加入「已報名活動陣列中」
$_SESSION['uid_signup'][]=$action_id;
}
function delete_signup($action_id){
global $xoopsDB, $xoopsUser;
$uid=$xoopsUser->uid();
//寫SQL
$tbl=$xoopsDB->prefix('signups');
$sql = "DELETE FROM `$tbl` WHERE `action_id` = '{$action_id}' and `uid` = '{$uid}'";
$xoopsDB->queryF($sql) or web_error($sql);
$_SESSION['uid_signup']=array_diff($_SESSION['uid_signup'],$action_id);
}
/*-----------執行動作判斷區----------*/
include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php');
$op = system_CleanVars($_REQUEST, 'op', '', 'string');
$action_id = system_CleanVars($_REQUEST, 'action_id', 0, 'int');
switch ($op) {
case "signup":
signup($action_id);
header("location:{$_SERVER['PHP_SELF']}?action_id=$action_id");
exit;
case "delete_signup":
delete_signup($action_id);
header("location:{$_SERVER['PHP_SELF']}?action_id=$action_id");
exit;
default:
if($action_id){
show_action($action_id);
$op='show_action';
}else{
list_actions();
$op='list_actions';
}
break;
}
/*-----------秀出結果區--------------*/
$xoopsTpl->assign('op', $op);
$xoopsTpl->assign("toolbar", toolbar_bootstrap($interface_menu));
$xoopsTpl->assign('isAdmin', $isAdmin);
include_once XOOPS_ROOT_PATH . '/footer.php';
9. header.php