10-1
上課範例:index.php
003 | include_once '../../mainfile.php' ; |
004 | include_once XOOPS_ROOT_PATH. "/header.php" ; |
009 | function add_form( $note_sn =null){ |
010 | global $xoopsDB , $xoopsUser ; |
012 | if ( empty ( $xoopsUser ))redirect_header( 'index.php' , 3, "請先登入。" ); |
015 | $sql = "select * from " . $xoopsDB ->prefix( "tad_notes" ). " where `note_sn`='$note_sn'" ; |
016 | $result = $xoopsDB ->query( $sql ) or redirect_header( 'index.php' , 3, mysql_error()); |
017 | $doc = $xoopsDB ->fetchArray( $result ); |
021 | include_once (XOOPS_ROOT_PATH. "/class/xoopsformloader.php" ); |
022 | $XoopsFormHiddenToken = new XoopsFormHiddenToken(); |
023 | $token = $XoopsFormHiddenToken ->render(); |
027 | $sql = "select * from " . $xoopsDB ->prefix( "tad_note_cate" ). " where cate_enable='1' order by `cate_sort`" ; |
028 | $result = $xoopsDB ->query( $sql ) or redirect_header( 'index.php' , 3, mysql_error()); |
029 | while ( $cate = $xoopsDB ->fetchArray( $result )){ |
030 | $selected =( $cate [ 'cate_sn' ]== $doc [ 'cate_sn' ])? "selected" : "" ; |
031 | $option .= "<option value='{$cate['cate_sn']}' $selected>{$cate['cate_title']}</option>" ; |
035 | $note_sort = empty ( $note_sn )?get_max_sort(): $doc [ 'note_sort' ]; |
038 | $note_date = empty ( $note_sn )? date ( "Y-m-d H:i:s" ): $doc [ 'note_date' ]; |
040 | $note_public1 =( $doc [ 'note_public' ]== '1' )? "checked" : "" ; |
041 | $note_public0 =( $doc [ 'note_public' ]== '0' )? "checked" : "" ; |
045 | <script type= 'text/javascript' src= 'class/ckeditor/ckeditor.js' ></script> |
046 | <script language= 'javascript' type= 'text/javascript' src= 'class/DatePicker/WdatePicker.js' ></script> |
048 | <form action= '{$_SERVER[' PHP_SELF ']}' method= 'post' > |
050 | <tr><th nowrap>所屬分類</th><td> |
051 | <select name= 'cate_sn' > |
052 | <option value= '0' >不分類</option> |
056 | <tr><th>文章標題</th><td><input type= 'text' name= 'note_title' size=40 value= '{$doc[' note_title ']}' ></td></tr> |
058 | <textarea name= 'note_content' cols=40 rows=6 class = 'ckeditor' id= 'ckeditor' >{ $doc [ 'note_content' ]}</textarea> |
059 | <script type= 'text/javascript' > |
060 | CKEDITOR.replace( 'ckeditor' , { skin : 'v2' , toolbar : 'MyToolbar' } ); |
063 | <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> |
064 | <tr><th>是否公開</th><td> |
065 | <input type= 'radio' name= 'note_public' value= '1' $note_public1 > 是 |
066 | <input type= 'radio' name= 'note_public' value= '0' $note_public0 > 否 |
068 | <tr><th>排序</th><td><input type= 'text' name= 'note_sort' size=2 value= '$note_sort' ></td></tr> |
071 | <input type= 'hidden' name= 'op' value= 'save' > |
072 | <input type= 'submit' value= '儲存' > |
092 | global $xoopsDB , $xoopsUser ; |
094 | if (! $GLOBALS [ 'xoopsSecurity' ]->check()){ |
095 | $error =implode( "<br />" , $GLOBALS [ 'xoopsSecurity' ]->getErrors()); |
096 | redirect_header( $_SERVER [ 'PHP_SELF' ],3, $error ); |
099 | $myts =& MyTextSanitizer::getInstance(); |
100 | $_POST [ 'note_title' ] = $myts -> addSlashes ( $_POST [ 'note_title' ]); |
101 | $_POST [ 'note_content' ] = $myts -> addSlashes ( $_POST [ 'note_content' ]); |
102 | $_POST [ 'note_date' ] = $myts -> addSlashes ( $_POST [ 'note_date' ]); |
103 | $_POST [ 'note_sort' ] = $myts -> addSlashes ( $_POST [ 'note_sort' ]); |
105 | $uid = empty ( $xoopsUser )? 0 : $xoopsUser ->uid(); |
107 | $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']}')" ; |
108 | $xoopsDB ->query( $sql ) or redirect_header( 'index.php' , 3, mysql_error()); |
113 | $main = "<a href='index.php?op=add_form'>新增記事</a>" ; |
118 | function get_max_sort(){ |
121 | $sql = "select max(`note_sort`) from " . $xoopsDB ->prefix( "tad_notes" ). " where `note_public`='1'" ; |
122 | $result = $xoopsDB ->query( $sql ) or redirect_header( 'index.php' , 3, mysql_error()); |
123 | list( $max_sort )= $xoopsDB ->fetchRow( $result ); |
128 | function show_doc( $note_sn = '' ){ |
129 | global $xoopsDB , $xoopsUser ; |
131 | $now_uid =( $xoopsUser )? $xoopsUser ->uid(): "" ; |
133 | $myts =& MyTextSanitizer::getInstance(); |
136 | $sql = "select * from " . $xoopsDB ->prefix( "tad_notes" ). " where `note_public`='1' order by note_sort" ; |
137 | $result = $xoopsDB ->query( $sql ) or redirect_header( 'index.php' , 3, mysql_error()); |
139 | while ( $doc = $xoopsDB ->fetchArray( $result )){ |
141 | $doc [ 'note_title' ] = $myts ->htmlSpecialChars( $doc [ 'note_title' ]); |
142 | $doc [ 'note_date' ] = $myts ->htmlSpecialChars( $doc [ 'note_date' ]); |
144 | $tool =( $doc [ 'uid' ]== $now_uid )?"<a href= 'index.php?op=del¬e_sn={$doc[' note_sn ']}' >刪除</a> | |
145 | <a href= 'index.php?op=modify¬e_sn={$doc[' note_sn ']}' >修改</a> ":" "; |
148 | <td><a href= 'index.php?note_sn={$doc[' note_sn ']}' >{ $doc [ 'note_title' ]}</a></td> |
149 | <td>{ $doc [ 'note_date' ]}</td> |
155 | $sql = "select * from " . $xoopsDB ->prefix( "tad_notes" ). " where `note_sn`='$note_sn' and `note_public`='1'" ; |
156 | $result = $xoopsDB ->query( $sql ) or redirect_header( 'index.php' , 3, mysql_error()); |
157 | $doc = $xoopsDB ->fetchArray( $result ); |
159 | $doc [ 'note_title' ] = $myts ->htmlSpecialChars( $doc [ 'note_title' ]); |
160 | $doc [ 'note_date' ] = $myts ->htmlSpecialChars( $doc [ 'note_date' ]); |
161 | $doc [ 'note_content' ] = $myts ->displayTarea( $doc [ 'note_content' ], 1, 1, 0, 1, 0); |
164 | <h1>{ $doc [ 'note_title' ]}</h1> |
165 | <div>{ $doc [ 'note_date' ]}</div> |
166 | <div>{ $doc [ 'note_content' ]}</div> |
174 | function del_note( $note_sn =null){ |
177 | $sql = "delete from " . $xoopsDB ->prefix( "tad_notes" ). " where note_sn='$note_sn'" ; |
178 | $xoopsDB ->queryF( $sql ) or redirect_header( 'index.php' , 3, mysql_error()); |
183 | $op = empty ( $_REQUEST [ 'op' ])? "" : $_REQUEST [ 'op' ]; |
184 | $note_sn = empty ( $_REQUEST [ 'note_sn' ])? "" : intval ( $_REQUEST [ 'note_sn' ]); |
191 | header( "location:index.php" ); |
195 | $main =add_form( $note_sn ); |
201 | header( "location:index.php" ); |
209 | $main =show_doc( $note_sn ); |
214 | $current1 =( $_SERVER [ 'REQUEST_URI' ]== "/~tad0616/modules/tad_note/index.php" )? "class='current'" : "" ; |
215 | $current2 =( $_SERVER [ 'REQUEST_URI' ]== "/~tad0616/modules/tad_note/index.php?op=add_form" )? "class='current'" : "" ; |
218 | <link rel= 'stylesheet' href= 'menu/menu_style.css' type= 'text/css' /> |
220 | <li><a href= 'index.php' target= '_self' title= '所有記事' $current1 >所有記事</a></li> |
221 | <li><a href= 'index.php?op=add_form' target= '_self' title= '新增記事' $current2 >新增記事</a></li> |
227 | include_once XOOPS_ROOT_PATH. '/footer.php' ; |