:::

8-3 上課範例:index.php

001<?php
002/*** 引入檔案 ***/
003include_once '../../mainfile.php';
004include_once XOOPS_ROOT_PATH."/header.php";
005 
006/*** 函數檔 ***/
007 
008//新增記事表單
009function add_form(){
010  global $xoopsDB;
011 
012 
013  $option="";
014  //抓取資料庫中的分類選項
015  $sql="select * from ".$xoopsDB->prefix("tad_note_cate")." where cate_enable='1' order by `cate_sort`";
016  $result = $xoopsDB->query($sql) or redirect_header('cate.php', 3, mysql_error());
017  while($cate=$xoopsDB->fetchArray($result)){
018    $option.="<option value='{$cate['cate_sn']}'>{$cate['cate_title']}</option>";
019  }
020 
021  //取得現在時間
022  $note_date=date("Y-m-d H:i:s");
023 
024  $main="
025  <script type='text/javascript' src='class/ckeditor/ckeditor.js'></script>
026  <script language='javascript' type='text/javascript' src='class/DatePicker/WdatePicker.js'></script>
027  <h3>記事編輯</h3>
028  <form action='{$_SERVER['PHP_SELF']}' method='post'>
029    <table>
030      <tr><th nowrap>所屬分類</th><td>
031        <select name='cate_sn'>
032        <option value='0'>不分類</option>
033        $option
034        </select>
035        </td></tr>
036      <tr><th>文章標題</th><td><input type='text' name='note_title' size=40 value=''></td></tr>
037      <tr><td colspan=2>
038        <textarea name='note_content' cols=40 rows=6 class='ckeditor' id='ckeditor'></textarea>
039        <script type='text/javascript'>
040          CKEDITOR.replace('ckeditor' , { skin : 'v2' , toolbar : 'MyToolbar' } );
041        </script>
042      </td></tr>
043      <tr><th>發布日期</th><td><input type='text' name='note_date' value='$note_date' onClick=\"WdatePicker({skin:'whyGreen' , dateFmt:'yyyy-MM-dd HH:mm:ss'})\" class='Wdate'></td></tr>
044      <tr><th>是否公開</th><td>
045        <input type='radio' name='note_public' value='1'> 是
046        <input type='radio' name='note_public' value='0'> 否
047        </td></tr>
048      <tr><th>排序</th><td><input type='text' name='note_sort' size=2></td></tr>
049    </table>
050 
051    <input type='hidden' name='op' value='save'>
052    <input type='submit' value='儲存'>
053 
054  </form>
055  ";
056 
057 
058  /*
059  所屬分類 cate_sn
060  文章標題 note_title
061  文章內容 note_content
062  發布日期 note_date
063  是否公開 note_public
064  排序 note_sort
065  */
066  return $main;
067}
068 
069 
070//儲存文章
071function save(){
072  global $xoopsDB , $xoopsUser;
073 
074  $uid = $xoopsUser->uid();
075 
076  $sql="insert into ".$xoopsDB->prefix("tad_notes")." (`cate_sn`, `note_title`, `note_content`, `note_date`, `note_public`, `note_count`, `uid`, `note_sort`) values('{$_POST['cate_sn']}' , '{$_POST['note_title']}' , '{$_POST['note_content']}' , '{$_POST['note_date']}' , '{$_POST['note_public']}' , '0' , '{$uid}' , '{$_POST['note_sort']}')";
077  $xoopsDB->query($sql) or redirect_header('index.php', 3, mysql_error());
078}
079 
080 
081function toolbar(){
082  $main="<a href='index.php?op=add_form'>新增記事</a>";
083  return $main;
084}
085 
086/*** 流程判斷 ***/
087$op=empty($_REQUEST['op'])?"":$_REQUEST['op'];
088 
089switch($op){
090 
091  case "save":
092  save();
093  header("location:index.php");
094  break;
095 
096  case "add_form":
097  $main=add_form();
098  break;
099 
100    default:
101    $main=toolbar();
102    break;
103}
104 
105/*** 輸出 ***/
106echo $main;
107include_once XOOPS_ROOT_PATH.'/footer.php';
108?>

:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D614%26tbsn%3D22

書籍目錄

展開 | 闔起

線上使用者

20人線上 (5人在瀏覽線上書籍)

會員: 0

訪客: 20

更多…