<?php /*-----------引入檔案區--------------*/ include_once "header.php"; $xoopsOption['template_main'] = set_bootstrap("tad_ebook_post.html"); include_once XOOPS_ROOT_PATH."/header.php"; if(!$xoopsUser){ redirect_header("index.php",3, "請先登入!"); } /*-----------function區--------------*/ //編輯表單 function edit_form(){ global $xoopsTpl , $xoopsUser , $xoopsDB; $uid=""; if($xoopsUser){ $uid=$xoopsUser->uid(); $page_content=""; 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","page_content",$page_content); $fck->setHeight(350); $editor=$fck->render(); $xoopsTpl->assign('editor' , $editor); //安全機制 include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php"); $XoopsFormHiddenToken=new XoopsFormHiddenToken(); $HiddenToken = $XoopsFormHiddenToken->render(); $xoopsTpl->assign('HiddenToken' , $HiddenToken); //取出可投稿期數資料 $myts =& MyTextSanitizer::getInstance(); //2015-04-25 10:47:56 $today=date("Y-m-d H:i:s"); $tbl=$xoopsDB->prefix('tad_ebook'); $sql="select * from `{$tbl}` where `ebook_post_date` > '{$today}' order by `ebook_post_date` limit 0,1"; $result=$xoopsDB->query($sql) or redirect_header("index.php",3, mysql_error()); $ebook=$xoopsDB->fetchArray($result); $ebook['ebook_title']=$myts->htmlSpecialChars($ebook['ebook_title']); $ebook['ebook_post_date']=$myts->htmlSpecialChars($ebook['ebook_post_date']); $ebook['ebook_publish_date']=$myts->htmlSpecialChars($ebook['ebook_publish_date']); $xoopsTpl->assign('ebook' , $ebook); }else{ redirect_header(XOOPS_URL."/user.php",3, "請先登入,才能投稿。"); } $xoopsTpl->assign('uid' , $uid); } //儲存文章 function insert_page(){ global $xoopsDB,$xoopsUser; include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php"); //安全判斷 if(!$GLOBALS['xoopsSecurity']->check()){ //錯誤訊息 $error=implode("<br />" , $GLOBALS['xoopsSecurity']->getErrors()); //轉向到首頁 redirect_header($_SERVER['PHP_SELF'],3, $error); } $myts =& MyTextSanitizer::getInstance(); $page_title=$myts->addSlashes($_POST['page_title']); $page_content=$myts->addSlashes($_POST['page_content']); $page_tag=$myts->addSlashes($_POST['page_tag']); $ebook_sn=intval($_POST['ebook_sn']); $page_author=$xoopsUser->name(); if(empty($page_author)){ $page_author=$xoopsUser->uname(); } $uid=$xoopsUser->uid(); $page_post_time=date("Y-m-d H:i:s"); $tbl=$xoopsDB->prefix('tad_ebook_page'); $sql="insert into `{$tbl}` (`ebook_sn`, `page_title`, `page_content`, `page_author`, `uid`, `page_sort`, `page_status`, `page_post_time`, `page_counter`, `page_tag`) values('{$ebook_sn}' , '{$page_title}' ,'{$page_content}' ,'{$page_author}' ,'{$uid}' ,'0' ,'' , '{$page_post_time}' ,'0' ,'{$page_tag}')"; $xoopsDB->queryF($sql) or die(mysql_error()); $page_sn=$xoopsDB->getInsertId(); return $page_sn; } //列自己的文章 function list_my_page(){ global $xoopsUser ,$xoopsDB ,$xoopsTpl ,$xoopsModuleConfig; $uid=$xoopsUser->uid(); $tbl=$xoopsDB->prefix('tad_ebook_page'); $sql="select * from `{$tbl}` where `uid` = '{$uid}'"; //getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項); $PageBar=getPageBar($sql, $xoopsModuleConfig['show_num'], 10,NULL,NULL,$bootstrap); $bar=$PageBar['bar']; $sql=$PageBar['sql']; $total=$PageBar['total']; $xoopsTpl->assign('bar',$bar); $xoopsTpl->assign('total',$total); $result=$xoopsDB->query($sql) or redirect_header("index.php",3, mysql_error()); while($page=$xoopsDB->fetchArray($result)){ $all_page[]=$page; } $xoopsTpl->assign('all_page',$all_page); $xoopsTpl->assign('op', 'show_my_page'); } /*-----------執行動作判斷區----------*/ $op=empty($_REQUEST['op'])?"":$_REQUEST['op']; switch($op){ case "insert_page": $page_sn=insert_page(); header("location: index.php?page_sn={$page_sn}"); exit; break; case "edit_form": edit_form(); break; default: list_my_page(); break; } /*-----------秀出結果區--------------*/ $xoopsTpl->assign( "toolbar" , toolbar_bootstrap($interface_menu)) ; include_once XOOPS_ROOT_PATH.'/footer.php'; ?>