線上書籍

Home

1041 XOOPS模組開發

<?php /*-----------引入檔案區--------------*/ $xoopsOption['template_main'] = "tad_ebook_adm_main.html"; include_once "header.php"; include_once "../function.php"; /*-----------function區--------------*/ //管理電子校刊表單 function ebook_form(){ global $xoopsTpl , $xoopsDB; $ebook_title = ""; $ebook_post_date = time() + 3600 * 24 * 14; $ebook_publish_date = time() + 3600 * 24 * 28; //引入表單物件 include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php"); $form = new XoopsThemeForm('電子校刊管理表單', 'ebook', 'main.php', 'post', true); $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='請輸入標題'"); $form->addElement($Text); $DateSelect=new XoopsFormTextDateSelect('投稿截止日', 'ebook_post_date', 15, $ebook_post_date); $DateSelect->setExtra("style='width: 100px;'"); $form->addElement($DateSelect); $DateSelect1=new XoopsFormTextDateSelect('出刊日', 'ebook_publish_date', 15, $ebook_publish_date); $DateSelect1->setExtra("style='width: 100px;'"); $form->addElement($DateSelect1); $Tray=new XoopsFormElementTray('', '&nbsp;', ''); $Tray->addElement(new XoopsFormButton('', '', '送出', 'submit')); $Tray->addElement(new XoopsFormButton('', '', '清除', 'reset')); $form->addElement($Tray); $Hidden =new XoopsFormHidden('op', 'insert_ebook'); $form->addElement($Hidden); $ebook_form = $form->render(); $xoopsTpl->assign('ebook_form' , $ebook_form); } //寫入資料庫 function insert_ebook(){ global $xoopsDB; $tbl=$xoopsDB->prefix('tad_ebook'); $sql="insert into `{$tbl}` (`ebook_title` ,`ebook_post_date` , `ebook_publish_date`) values('{$_POST['ebook_title']}' , '{$_POST['ebook_post_date']}' ,'{$_POST['ebook_publish_date']}')"; $xoopsDB->query($sql) or die(mysql_error()); } /*-----------執行動作判斷區----------*/ $op=empty($_REQUEST['op'])?"":$_REQUEST['op']; switch($op){ case "insert_ebook": insert_ebook(); header("location:{$_SERVER['PHP_SELF']}"); break; default: ebook_form(); break; } /*-----------引入檔案區--------------*/ include_once 'footer.php'; ?>