prefix('tad_ebook'); $sql="select * from `{$tbl}` where ebook_sn='{$ebook_sn}'"; $result=$xoopsDB->query($sql) or die(mysql_error()); $all=$xoopsDB->fetchArray($result); $ebook_title=$myts->htmlSpecialChars($all['ebook_title']); $ebook_post_date=strtotime($myts->htmlSpecialChars($all['ebook_post_date'])); $ebook_publish_date=strtotime($myts->htmlSpecialChars($all['ebook_publish_date'])); $ebook_content=$myts->displayTarea($all['ebook_content'], 1, 1, 1, 1, 0); $op='update_ebook'; }else{ $ebook_title = ""; $ebook_post_date = time() + 3600 * 24 * 14; $ebook_publish_date = time() + 3600 * 24 * 28; $ebook_content=""; $op='insert_ebook'; } //引入表單物件 include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php"); $form = new XoopsThemeForm('電子校刊管理表單', 'ebook', 'main.php', 'post', true); $form->setExtra("enctype='multipart/form-data'"); $Text = new XoopsFormText('電子校刊標題', 'ebook_title', 200 , 80 , $ebook_title); //$Text->setExtra("style='width: 400px; color: white; background-color: #000000;'"); $Text->setExtra("style='width: 400px;'"); $Text->setExtra("placeholder='"._MA_TADEBOOK_PLACEHOLDER."'"); $form->addElement($Text); $DateSelect=new XoopsFormTextDateSelect('投稿截止日', 'ebook_post_date', 15, $ebook_post_date); $DateSelect->setExtra("style='width: 100px;'"); $form->addElement($DateSelect); $DateSelect1=new XoopsFormTextDateSelect(_MA_TADEBOOK_PUBLIC_DATE, 'ebook_publish_date', 15, $ebook_publish_date); $DateSelect1->setExtra("style='width: 100px;'"); $form->addElement($DateSelect1); //CK編輯器 if(!file_exists(XOOPS_ROOT_PATH."/modules/tadtools/ck.php")){ redirect_header("http://www.tad0616.net/modules/tad_uploader/index.php?of_cat_sn=50",3, _TAD_NEED_TADTOOLS); } include_once XOOPS_ROOT_PATH."/modules/tadtools/ck.php"; $fck=new CKEditor("tad_ebook","ebook_content",$ebook_content); $fck->setHeight(350); $editor=$fck->render(); $form->addElement(new XoopsFormLabel('內容說明', $editor)); //上傳表單(enctype='multipart/form-data') include_once XOOPS_ROOT_PATH."/modules/tadtools/TadUpFiles.php" ; $TadUpFiles=new TadUpFiles("tad_ebook"); $TadUpFiles->set_col('ebook_sn',$ebook_sn); $upform=$TadUpFiles->upform(true,'ebook_pic'); $form->addElement(new XoopsFormLabel('上傳封面圖', "$upform")); $Tray=new XoopsFormElementTray('', ' ', ''); $Tray->addElement(new XoopsFormButton('', '', _SUBMIT, 'submit')); $Tray->addElement(new XoopsFormButton('', '', _RESET, 'reset')); $form->addElement($Tray); $form->addElement(new XoopsFormHidden('ebook_sn', $ebook_sn)); $form->addElement(new XoopsFormHidden('op', $op)); //安全機制 $form->addElement(new XoopsFormHiddenToken('XOOPS_TOKEN_REQUEST',360)); $ebook_form = $form->render(); $xoopsTpl->assign('ebook_form' , $ebook_form); } //寫入資料庫 function insert_ebook(){ global $xoopsDB; //安全判斷 if(!$GLOBALS['xoopsSecurity']->check()){ //錯誤訊息 $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); //轉向到首頁 redirect_header($_SERVER['PHP_SELF'],3, $error); } $myts =& MyTextSanitizer::getInstance(); $ebook_title=$myts->addSlashes($_POST['ebook_title']); $ebook_post_date=$myts->addSlashes($_POST['ebook_post_date']); $ebook_publish_date=$myts->addSlashes($_POST['ebook_publish_date']); $ebook_content=$myts->addSlashes($_POST['ebook_content']); $tbl=$xoopsDB->prefix('tad_ebook'); $sql="insert into `{$tbl}` (`ebook_title` ,`ebook_post_date` , `ebook_publish_date` , `ebook_content`) values('{$ebook_title}' , '{$ebook_post_date}' ,'{$ebook_publish_date}' ,'{$ebook_content}')"; $xoopsDB->query($sql) or die(mysql_error()); $ebook_sn=$xoopsDB->getInsertId(); //儲存: include_once XOOPS_ROOT_PATH."/modules/tadtools/TadUpFiles.php" ; $TadUpFiles=new TadUpFiles("tad_ebook"); $TadUpFiles->set_col('ebook_sn',$ebook_sn,0); $TadUpFiles->upload_file('ebook_pic',1024,150,NULL,NULL,true); $extra_tags['EBOOK_TITLE'] = $ebook_title; $extra_tags['POST_DATE'] = $ebook_post_date; $extra_tags['PUBLISH_DATE'] = $ebook_publish_date; $notification_handler =& xoops_gethandler('notification'); $notification_handler->triggerEvent ('global', 0 , 'new_ebook', $extra_tags); } //列出所有書籍 function ebook_list(){ global $xoopsDB , $xoopsTpl; //單一檔案真實路徑: include_once XOOPS_ROOT_PATH."/modules/tadtools/TadUpFiles.php" ; $TadUpFiles=new TadUpFiles("tad_ebook"); $myts =& MyTextSanitizer::getInstance(); $tbl=$xoopsDB->prefix('tad_ebook'); $sql="select * from `{$tbl}` order by ebook_sn desc"; $result=$xoopsDB->query($sql) or die(mysql_error()); $i=0; $all_data=""; while($all=$xoopsDB->fetchArray($result)){ $all['ebook_title']=$myts->htmlSpecialChars($all['ebook_title']); $all['del_title']=urlencode($all['ebook_title']); $all['ebook_post_date']=$myts->htmlSpecialChars($all['ebook_post_date']); $all['ebook_publish_date']=$myts->htmlSpecialChars($all['ebook_publish_date']); $TadUpFiles->set_col('ebook_sn',$all['ebook_sn']); $all['ebook_pic']=$TadUpFiles->get_pic_file('thumb'); $all_data[$i]=$all; $i++; } //die(var_export($all_data)); $xoopsTpl->assign('all_data' , $all_data); } //從資料庫刪除 function del_ebook($ebook_sn=""){ global $xoopsDB; $tbl=$xoopsDB->prefix('tad_ebook'); $sql="delete from `{$tbl}` where ebook_sn='{$ebook_sn}'"; $xoopsDB->queryF($sql) or die(mysql_error()); include_once XOOPS_ROOT_PATH."/modules/tadtools/TadUpFiles.php" ; $TadUpFiles=new TadUpFiles("tad_ebook"); $TadUpFiles->set_col('ebook_sn',$ebook_sn); $TadUpFiles->del_files(); } //更新資料庫 function update_ebook($ebook_sn=""){ global $xoopsDB; //安全判斷 if(!$GLOBALS['xoopsSecurity']->check()){ //錯誤訊息 $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); //轉向到首頁 redirect_header($_SERVER['PHP_SELF'],3, $error); } $myts =& MyTextSanitizer::getInstance(); $ebook_title=$myts->addSlashes($_POST['ebook_title']); $ebook_post_date=$myts->addSlashes($_POST['ebook_post_date']); $ebook_publish_date=$myts->addSlashes($_POST['ebook_publish_date']); $ebook_content=$myts->addSlashes($_POST['ebook_content']); $tbl=$xoopsDB->prefix('tad_ebook'); $sql=" update `{$tbl}` set `ebook_title`='{$ebook_title}' , `ebook_post_date`='{$ebook_post_date}' , `ebook_publish_date`='{$ebook_publish_date}', `ebook_content`='{$ebook_content}' where ebook_sn='{$ebook_sn}'"; $xoopsDB->queryF($sql) or die(mysql_error()); //儲存: include_once XOOPS_ROOT_PATH."/modules/tadtools/TadUpFiles.php" ; $TadUpFiles=new TadUpFiles("tad_ebook"); $TadUpFiles->set_col('ebook_sn',$ebook_sn,0); $TadUpFiles->upload_file('ebook_pic',1024,150,NULL,NULL,true); } /*-----------執行動作判斷區----------*/ $op=empty($_REQUEST['op'])?"":$_REQUEST['op']; $ebook_sn=isset($_REQUEST['ebook_sn'])?intval($_REQUEST['ebook_sn']):""; switch($op){ case "insert_ebook": insert_ebook(); //header("location:{$_SERVER['PHP_SELF']}"); redirect_header($_SERVER['PHP_SELF'],3, "儲存完成!"); exit; break; case "del_ebook": del_ebook($ebook_sn); header("location:{$_SERVER['PHP_SELF']}"); exit; break; case "update_ebook": update_ebook($ebook_sn); header("location:{$_SERVER['PHP_SELF']}"); exit; break; case "edit_ebook": ebook_form($ebook_sn); break; default: ebook_form(); ebook_list(); break; } /*-----------引入檔案區--------------*/ include_once 'footer.php'; ?> ```
進階搜尋
87人線上 (27人在瀏覽線上書籍)
會員: 0
訪客: 87