17-5
上課範例:admin/cate.php
003 | include_once XOOPS_ROOT_PATH. "/modules/" . $xoopsModule ->getVar( "dirname" ) . "/class/admin.php" ; |
004 | $index_admin = new ModuleAdmin() ; |
005 | echo $index_admin ->addNavigation( 'cate.php' ) ; |
011 | function cate_form( $cate_sn =null){ |
013 | include_once (XOOPS_ROOT_PATH. "/class/xoopsformloader.php" ); |
016 | if (! empty ( $cate_sn )){ |
017 | $cate =get_cate( $cate_sn ); |
023 | $form = new XoopsThemeForm( '分類設定' , 'cate' , 'cate.php' , 'post' ); |
026 | $XoopsFormText = new XoopsFormText( '分類標題' , 'cate_title' , 40 , 255 , $cate [ 'cate_title' ]); |
027 | $XoopsFormText ->setDescription ( "請設定一個分類名稱" ); |
028 | $form ->addElement( $XoopsFormText , true); |
030 | $form ->addElement( new XoopsFormText( '分類排序' , 'cate_sort' , 4 , 4 , $cate [ 'cate_sort' ]) , true); |
033 | $XoopsFormRadio = new XoopsFormRadio( '是否使用' , 'cate_enable' , $cate [ 'cate_enable' ]); |
038 | $XoopsFormRadio ->addOptionArray( $options ); |
040 | $form ->addElement( $XoopsFormRadio ); |
042 | if (! empty ( $cate_sn )){ |
043 | $form ->addElement( new XoopsFormHidden( 'op' , 'update' )); |
044 | $form ->addElement( new XoopsFormHidden( 'cate_sn' , $cate_sn )); |
046 | $form ->addElement( new XoopsFormHidden( 'op' , 'insert' )); |
050 | $Tray1 = new XoopsFormElementTray( '' , ' ' , 'name' ); |
051 | $Tray1 ->addElement( new XoopsFormButton( '' , '' , '送出' , 'submit' )); |
052 | $Tray1 ->addElement( new XoopsFormButton( '' , '' , '清除' , 'reset' )); |
053 | $form ->addElement( $Tray1 ); |
056 | $form ->addElement( new XoopsFormHiddenToken()); |
067 | function insert_cate(){ |
070 | if (! $GLOBALS [ 'xoopsSecurity' ]->check()){ |
071 | $error =implode( "<br />" , $GLOBALS [ 'xoopsSecurity' ]->getErrors()); |
072 | redirect_header( $_SERVER [ 'PHP_SELF' ],3, $error ); |
077 | $sql = "insert into " . $xoopsDB ->prefix( "tad_note_cate" ). " (`cate_title` , `cate_sort` , `cate_enable`) values('{$_POST['cate_title']}' , '{$_POST['cate_sort']}' , '{$_POST['cate_enable']}')" ; |
078 | $xoopsDB ->queryF( $sql ) or redirect_header( 'cate.php' , 3, mysql_error()); |
085 | $sql = "select * from " . $xoopsDB ->prefix( "tad_note_cate" ). " order by `cate_sort`" ; |
086 | $result = $xoopsDB ->query( $sql ) or redirect_header( 'cate.php' , 3, mysql_error()); |
090 | <table cellspacing=1 class = 'outer' > |
092 | <th> "._MA_TADNOTE_NOTE_SN." </th> |
093 | <th> "._MA_TADNOTE_NOTE_TITLE." </th> |
094 | <th> "._MA_TADNOTE_NOTE_SORT." </th> |
095 | <th> "._MA_TADNOTE_NOTE_PUBLIC." </th> |
096 | <th> "._MA_TADNOTE_NOTE_COUNT." </th> |
097 | <th> "._MA_TADNOTE_NOTE_FUNCTION." </th> |
100 | while ( $cate = $xoopsDB ->fetchArray( $result )){ |
102 | $class =( $i %2)? 'odd' : 'even' ; |
105 | $enable =( $cate [ 'cate_enable' ]== '1' )?_YES:_NO; |
109 | <td class = 'txtcenter' >{ $cate [ 'cate_sn' ]}</td> |
110 | <td>{ $cate [ 'cate_title' ]}</td> |
111 | <td class = 'txtcenter' >{ $cate [ 'cate_sort' ]}</td> |
112 | <td class = 'txtcenter' >{ $enable }</td> |
113 | <td class = 'txtcenter' >{ $cate [ 'cate_count' ]}</td> |
114 | <td class = 'txtcenter' ><a href= 'cate.php?op=delete&cate_sn={$cate[' cate_sn ']}' > "._MA_TADNOTE_DEL." </a> | <a href= 'cate.php?op=modify&cate_sn={$cate[' cate_sn ']}' > "._MA_TADNOTE_MODIFY." </a></td> |
126 | function delete_cate( $cate_sn =null){ |
127 | global $xoopsDB , $xoopsModule ; |
129 | $sql = "delete from " . $xoopsDB ->prefix( "tad_note_cate" ). " where cate_sn='$cate_sn'" ; |
130 | $xoopsDB ->queryF( $sql ) or redirect_header( 'cate.php' , 3, mysql_error()); |
132 | $mid = $xoopsModule ->getVar( 'mid' ); |
133 | xoops_notification_deletebyitem ( $mid , "cate" , $cate_sn ); |
138 | function update_cate( $cate_sn =null){ |
141 | if (! $GLOBALS [ 'xoopsSecurity' ]->check()){ |
142 | $error =implode( "<br />" , $GLOBALS [ 'xoopsSecurity' ]->getErrors()); |
143 | redirect_header( $_SERVER [ 'PHP_SELF' ],3, $error ); |
147 | $sql = "update " . $xoopsDB ->prefix( "tad_note_cate" ). " set `cate_title` ='{$_POST['cate_title']}' , `cate_sort` = '{$_POST['cate_sort']}' , `cate_enable` = '{$_POST['cate_enable']}' where `cate_sn` = '{$cate_sn}'" ; |
148 | $xoopsDB ->queryF( $sql ) or redirect_header( 'cate.php' , 3, mysql_error()); |
155 | $op = isset( $_REQUEST [ 'op' ])? $_REQUEST [ 'op' ] : "" ; |
156 | $cate_sn = isset( $_REQUEST [ 'cate_sn' ])? intval ( $_REQUEST [ 'cate_sn' ]) : "" ; |
164 | header( 'location:cate.php' ); |
168 | delete_cate( $cate_sn ); |
169 | header( 'location:cate.php' ); |
173 | $main = cate_form( $cate_sn ); |
177 | update_cate( $cate_sn ); |
178 | header( 'location:cate.php' ); |