<?php /*------------------ 檔頭(引入檔案) ------------------*/ //使用樣板檔 $xoopsOption['template_main'] = "tad_honor_adm_main.html"; //引入XOOPS後台檔案檔頭(必要) include 'header.php'; //引入共同檔案設定檔(必要) include_once "../function.php"; //引入自訂的共同函數檔 /*------------------ 流程判斷(告訴程式現在要做什麼) -----------------*/ //$op 為XOOPS常用之動作變數,用來告知程式欲執行之動作 $op=isset($_REQUEST['op'])?$_REQUEST['op']:""; $honor_sn=isset($_REQUEST['honor_sn'])?intval($_REQUEST['honor_sn']):""; //判斷目前動作該執行哪一個 switch($op){ //呈現編輯表單 case "honor_form": honor_form($honor_sn); break; //寫入資料庫 case "add_honor": add_honor(); //header("location:main.php"); redirect_header('main.php', 3, "儲存完成!"); break; //更新資料庫 case "update_honor": update_honor($honor_sn); redirect_header('main.php', 3, "更新完成!"); break; //刪除資料 case "delete_honor": delete_honor($honor_sn); header("location:main.php"); break; //預設動作(列出) default: list_honor(); break; } /*------------------ 所有函數(實際執行動作) ------------------*/ //榮譽榜編輯表單 function honor_form($honor_sn=""){ global $xoopsTpl, $xoopsUser,$xoopsDB; if($honor_sn){ //資料表套用前置字串 $tbl=$xoopsDB->prefix("tad_honor"); $sql="select * from {$tbl} where honor_sn='{$honor_sn}'"; $result = $xoopsDB->query($sql) or die(mysql_error()); $all=$xoopsDB->fetchArray($result); $honor_year=$all['honor_year']; $honor_date=$all['honor_date']; $honor_students=$all['honor_students']; $honor_descript=$all['honor_descript']; $honor_teachers=$all['honor_teachers']; $honor_note=$all['honor_note']; $uid=$all['uid']; $op="update_honor"; }else{ //預設值 $honor_year="103"; $honor_date=""; $honor_students=""; $honor_descript=""; $honor_teachers=""; $honor_note=""; $uid=$xoopsUser->uid(); $op="add_honor"; } //引入XOOPS表單 include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php"); //建立XOOPS表單 $form = new XoopsThemeForm('榮譽榜編輯表單', 'honor_form', 'main.php', 'post', true , '榮譽榜編輯表單'); //在表單中,加入一個文字輸入框 $form->addElement(new XoopsFormText('學年度', 'honor_year', 3 , 3 , $honor_year) , true); //在表單中,加入一個日期輸入框 $form->addElement(new XoopsFormTextDateSelect('得獎日期', 'honor_date', 20 , $honor_date) , true); //在表單中,加入一個文字輸入框 $form_honor_students = new XoopsFormText('得獎者', 'honor_students' , 255 , 255 , $honor_students); $form_honor_students->setExtra("class='span12' placeholder='請填入得獎者'"); $form->addElement($form_honor_students , true); //在表單中,加入一個大量文字輸入框 $form_honor_descript = new XoopsFormTextArea('得獎事項', 'honor_descript' , $honor_descript , 5 , 255); $form_honor_descript->setExtra("class='span12' placeholder='請填入得獎事項'"); $form->addElement($form_honor_descript , true); //在表單中,加入一個文字輸入框 $form->addElement(new XoopsFormText('指導老師', 'honor_teachers', 255 , 255 , $honor_teachers) , false); //在表單中,加入一個大量文字輸入框 $form_honor_note = new XoopsFormTextArea('備註', 'honor_note' , $honor_note , 5 , 255); $form_honor_note->setExtra("class='span12' placeholder='請填入備註'"); $form->addElement($form_honor_note , false); //在表單中,加入一個隱藏表單 $form->addElement(new XoopsFormHidden('uid' , $uid)); $form->addElement(new XoopsFormHidden('op' , $op)); $form->addElement(new XoopsFormHidden('honor_sn' , $honor_sn)); $Tray1=new XoopsFormElementTray('', ' ', ''); $Tray1->addElement(new XoopsFormButton('', '', '送出', 'submit')); $Tray1->addElement(new XoopsFormButton('', '', '清除', 'reset')); $form->addElement($Tray1); //將表單物件轉換為表單語法 $f=$form->render(); //將表單語法套用到樣板中 $xoopsTpl->assign('honor_form' , $f); $xoopsTpl->assign('now_op' , 'honor_form'); $xoopsTpl->assign('temp_title' , '榮譽榜編輯表單'); } //新增事件到資料庫 function add_honor(){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("<br />" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } $myts =& MyTextSanitizer::getInstance(); $_POST['honor_year']=$myts->addSlashes($_POST['honor_year']); $_POST['honor_date']=$myts->addSlashes($_POST['honor_date']); $_POST['honor_students']=$myts->addSlashes($_POST['honor_students']); $_POST['honor_descript']=$myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers']=$myts->addSlashes($_POST['honor_teachers']); $_POST['honor_note']=$myts->addSlashes($_POST['honor_note']); $tbl=$xoopsDB->prefix("tad_honor"); $sql="INSERT INTO `{$tbl}` (`honor_year`, `honor_date`, `honor_students`, `honor_descript`, `honor_teachers`, `honor_note`, `uid`) VALUES ( '{$_POST['honor_year']}' , '{$_POST['honor_date']}' , '{$_POST['honor_students']}' , '{$_POST['honor_descript']}' , '{$_POST['honor_teachers']}' , '{$_POST['honor_note']}' , '{$_POST['uid']}')"; $xoopsDB->query($sql) or die(mysql_error()); } //更新事件到資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("<br />" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } $myts =& MyTextSanitizer::getInstance(); $_POST['honor_year']=$myts->addSlashes($_POST['honor_year']); $_POST['honor_date']=$myts->addSlashes($_POST['honor_date']); $_POST['honor_students']=$myts->addSlashes($_POST['honor_students']); $_POST['honor_descript']=$myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers']=$myts->addSlashes($_POST['honor_teachers']); $_POST['honor_note']=$myts->addSlashes($_POST['honor_note']); $tbl=$xoopsDB->prefix("tad_honor"); $sql="update `{$tbl}` set `honor_year`='{$_POST['honor_year']}' , `honor_date`='{$_POST['honor_date']}', `honor_students`='{$_POST['honor_students']}', `honor_descript`='{$_POST['honor_descript']}', `honor_teachers`='{$_POST['honor_teachers']}', `honor_note`='{$_POST['honor_note']}' where honor_sn='$honor_sn'"; $xoopsDB->queryF($sql) or die(mysql_error()); } //刪除榮譽榜事件 function delete_honor($honor_sn=""){ global $xoopsDB; $tbl=$xoopsDB->prefix("tad_honor"); $sql="delete from `{$tbl}` where honor_sn='$honor_sn'"; $xoopsDB->queryF($sql) or die(mysql_error()); } /*------------------ 檔尾(輸出內容到樣板) ------------------*/ include "footer.php"; //XOOPS檔尾 ?>