<?php /*-----------引入檔案區--------------*/ $xoopsOption['template_main'] = "tad_signup_adm_main.tpl"; include_once "header.php"; include_once "../function.php"; /*-----------function區--------------*/ //編輯活動表單 function action_form($action_id="") { global $xoopsTpl, $xoopsDB; if($action_id){ $tbl=$xoopsDB->prefix('actions'); $sql="SELECT * FROM `{$tbl}` WHERE `action_id` = '{$action_id}'"; $result = $xoopsDB->query($sql) or web_error($sql); $val=$xoopsDB->fetchArray($result); $op="update_action"; }else{ $val['title']=""; $val['content']=""; $val['action_date']=date("Y-m-d", strtotime("+2 weeks")); $val['end_date']=date("Y-m-d 17:30:00", strtotime("+1 weeks")); $val['enable']="1"; $op="insert_action"; } include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php"); $form = new XoopsThemeForm('編輯活動', 'myform', 'main.php', 'post', true , '編輯活動'); $form->addElement(new XoopsFormText('活動名稱', 'title', 255 , 255 , $val['title']), false); //載入所見即所得編輯器 include_once XOOPS_ROOT_PATH . "/modules/tadtools/ck.php"; $ck = new CKEditor("tad_signup", "content", $val['content']); $ck->setHeight(350); $editor = $ck->render(); $form->addElement(new XoopsFormLabel('活動說明', $editor), false); //載入WdatePicker小月曆 include_once XOOPS_ROOT_PATH . "/modules/tadtools/cal.php"; $cal = new My97DatePicker(); $cal->render(); $action_date = new XoopsFormText('活動日期', 'action_date', 15, 15, $val['action_date']); $action_date->setExtra("onClick=\"WdatePicker()\""); $form->addElement($action_date, false); $end_date = new XoopsFormText('報名截止日', 'end_date', 15, 15, $val['end_date']); $end_date->setExtra("onClick=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})\""); $form->addElement($end_date, false); $form->addElement(new XoopsFormRadioYN('是否啟用', 'enable', $val['enable']), false); $Tray=new XoopsFormElementTray('', ' ', 'name'); $Tray->addElement(new XoopsFormHidden('op', $op)); $Tray->addElement(new XoopsFormHidden('action_id', $action_id)); $Tray->addElement(new XoopsFormButton('', 'name', '送出', 'submit')); $Tray->addElement(new XoopsFormButton('', 'name', '清除', 'reset')); $form->addElement($Tray); $action_form = $form->render(); $xoopsTpl->assign('action_form', $action_form); } //新增活動 function insert_action(){ global $xoopsDB, $xoopsUser; //安全判斷 if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("<br>" , $GLOBALS['xoopsSecurity']->getErrors()); throw new Exception($error); } //過濾資料 $title=clean_var('title', '活動名稱'); $content=clean_var('content'); $action_date=clean_var('action_date', '活動日期'); $end_date=clean_var('end_date', '報名截止日'); $enable=clean_var('enable', '是否啟用'); $uid=$xoopsUser->uid(); //寫SQL $tbl=$xoopsDB->prefix('actions'); $sql = "INSERT INTO `$tbl` ( `title`, `content`, `action_date`, `end_date`, `uid`, `enable`) VALUES ('{$title}', '{$content}', '{$action_date}', '{$end_date}', '{$uid}', '{$enable}')"; //送至資料庫 $xoopsDB->query($sql) or web_error($sql); //取得流水號 $action_id = $xoopsDB->getInsertId(); return $action_id; } function update_action(){ global $xoopsDB, $xoopsUser; //安全判斷 if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("<br>" , $GLOBALS['xoopsSecurity']->getErrors()); throw new Exception($error); } //過濾資料 $title=clean_var('title', '活動名稱'); $content=clean_var('content'); $action_date=clean_var('action_date', '活動日期'); $end_date=clean_var('end_date', '報名截止日'); $enable=clean_var('enable', '是否啟用'); $uid=$xoopsUser->uid(); $action_id=clean_var('action_id', '活動編號'); //寫SQL $tbl=$xoopsDB->prefix('actions'); $sql = "UPDATE `$tbl` SET `title` = '{$title}', `content` = '{$content}', `action_date`= '{$action_date}', `end_date` = '{$end_date}', `uid`= '{$uid}', `enable` ='{$enable}' WHERE `action_id` = '{$action_id}'"; //送至資料庫 $xoopsDB->query($sql) or web_error($sql); } function delete_action($action_id){ global $xoopsDB, $xoopsUser; // $uid=$xoopsUser->uid(); //寫SQL $tbl=$xoopsDB->prefix('actions'); $sql = "DELETE FROM `$tbl` WHERE `action_id` = '{$action_id}'"; //送至資料庫 $xoopsDB->queryF($sql) or web_error($sql); } /*-----------執行動作判斷區----------*/ 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'); try { switch ($op) { case "insert_action": $action_id = insert_action(); header("location: ../index.php?action_id=$action_id"); exit; case "delete_action": delete_action($action_id); header("location: ../index.php"); exit; case "update_action": update_action(); header("location: ../index.php?action_id=$action_id"); exit; default: action_form($action_id); break; } } catch (exception $e) { xoops_error($e->getMessage(), '錯誤訊息'); // redirect_header($_SERVER['PHP_SELF'], 3, $e->getMessage()); } include_once 'footer.php';