3-1
上課範例:admin/index.php
004 | include_once "header_admin.php" ; |
008 | function contact_form( $sn = "" ){ |
009 | global $xoopsDB , $xoopsUser ; |
013 | $DBV =get_contact( $sn ); |
021 | $tel =(!isset( $DBV [ 'tel' ]))? "" : $DBV [ 'tel' ]; |
024 | $email =(!isset( $DBV [ 'email' ]))? "" : $DBV [ 'email' ]; |
027 | $name =(!isset( $DBV [ 'name' ]))? "" : $DBV [ 'name' ]; |
030 | $gsn =(!isset( $DBV [ 'gsn' ]))?null: $DBV [ 'gsn' ]; |
033 | $sn =(!isset( $DBV [ 'sn' ]))? $sn : $DBV [ 'sn' ]; |
036 | $birthday =(!isset( $DBV [ 'birthday' ]))? "" : $DBV [ 'birthday' ]; |
039 | $zip =(!isset( $DBV [ 'zip' ]))? "" : $DBV [ 'zip' ]; |
042 | $county =(!isset( $DBV [ 'county' ]))? "" : $DBV [ 'county' ]; |
045 | $city =(!isset( $DBV [ 'city' ]))? "" : $DBV [ 'city' ]; |
048 | $addr =(!isset( $DBV [ 'addr' ]))? "" : $DBV [ 'addr' ]; |
050 | $op =( empty ( $sn ))? "insert_contact" : "update_contact" ; |
053 | $jquery =get_jquery(); |
057 | <script language= 'javascript' src= '../class/twzipcode-1.3.1.js' ></script> |
058 | <script type= 'text/javascript' > |
059 | $(document).ready( function (){ |
060 | $.post( 'ajax.php' , function (data){ |
061 | $( '#menu1' ).html(data); |
062 | $.post( 'ajax.php' , {parent_gsn: $( '#menu1' ).val()} , function (data){ |
063 | $( '#menu2' ).html(data); |
067 | $( '#menu1' ).change( function (){ |
068 | $.post( 'ajax.php' , {parent_gsn: $( '#menu1' ).val()} , function (data){ |
069 | $( '#menu2' ).html(data); |
073 | $( '#AddrForm' ).twzipcode({ |
074 | countyName: 'county' , |
077 | countySel: '$county' , |
085 | <form action= '{$_SERVER[' PHP_SELF ']}' method= 'post' id= 'myForm' > |
087 | <table class = 'form_tbl' > |
090 | <tr><td class = 'title' nowrap>群組</td> |
092 | <select id= 'menu1' ></select> |
093 | <select name= 'gsn' id= 'menu2' ></select> |
097 | <tr><td class = 'title' nowrap>姓名</td> |
098 | <td class = 'col' ><input type= 'text' name= 'name' size= '20' value= '{$name}' id= 'name' ></td></tr> |
102 | <tr><td class = 'title' nowrap>電話</td> |
103 | <td class = 'col' ><input type= 'text' name= 'tel' size= '20' value= '{$tel}' id= 'tel' ></td></tr> |
106 | <tr><td class = 'title' nowrap>信箱</td> |
107 | <td class = 'col' ><input type= 'text' name= 'email' size= '20' value= '{$email}' id= 'email' ></td></tr> |
111 | <tr><td class = 'title' nowrap>生日</td> |
112 | <td class = 'col' ><input type= 'text' name= 'birthday' size= '20' value= '{$birthday}' id= 'birthday' ></td></tr> |
116 | <tr><td class = 'title' nowrap>地址</td> |
118 | <div style= 'position:relative;' > |
119 | <span id= 'AddrForm' ></span> |
120 | <input type= 'text' name= 'addr' size= '30' value= '{$addr}' id= 'addr' > |
125 | <td class = 'bar' colspan= '2' > |
128 | <input type= 'hidden' name= 'sn' value= '{$sn}' > |
130 | <input type= 'hidden' name= 'op' value= '{$op}' > |
131 | <input type= 'submit' value= '儲存' > |
138 | $main =div_3d( "通訊錄管理" , $main , "raised" ); |
146 | function insert_contact(){ |
147 | global $xoopsDB , $xoopsUser ; |
150 | $myts =& MyTextSanitizer::getInstance(); |
151 | $_POST [ 'tel' ]= $myts -> addSlashes ( $_POST [ 'tel' ]); |
152 | $_POST [ 'email' ]= $myts -> addSlashes ( $_POST [ 'email' ]); |
153 | $_POST [ 'name' ]= $myts -> addSlashes ( $_POST [ 'name' ]); |
154 | $_POST [ 'birthday' ]= $myts -> addSlashes ( $_POST [ 'birthday' ]); |
155 | $_POST [ 'zip' ]= $myts -> addSlashes ( $_POST [ 'zip' ]); |
156 | $_POST [ 'county' ]= $myts -> addSlashes ( $_POST [ 'county' ]); |
157 | $_POST [ 'city' ]= $myts -> addSlashes ( $_POST [ 'city' ]); |
158 | $_POST [ 'addr' ]= $myts -> addSlashes ( $_POST [ 'addr' ]); |
161 | $sql = "insert into `" . $xoopsDB ->prefix( "contact" )."` |
162 | (`tel` , `email` , `name` , `gsn` , `birthday` , `zip` , `county` , `city` , `addr`) |
163 | values( '{$_POST[' tel ']}' , '{$_POST[' email ']}' , '{$_POST[' name ']}' , '{$_POST[' gsn ']}' , '{$_POST[' birthday ']}' , '{$_POST[' zip ']}' , '{$_POST[' county ']}' , '{$_POST[' city ']}' , '{$_POST[' addr ']}' )"; |
164 | $xoopsDB ->query( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ],3, mysql_error()); |
167 | $sn = $xoopsDB ->getInsertId(); |
172 | function update_contact( $sn = "" ){ |
173 | global $xoopsDB , $xoopsUser ; |
176 | $myts =& MyTextSanitizer::getInstance(); |
177 | $_POST [ 'tel' ]= $myts -> addSlashes ( $_POST [ 'tel' ]); |
178 | $_POST [ 'email' ]= $myts -> addSlashes ( $_POST [ 'email' ]); |
179 | $_POST [ 'name' ]= $myts -> addSlashes ( $_POST [ 'name' ]); |
180 | $_POST [ 'birthday' ]= $myts -> addSlashes ( $_POST [ 'birthday' ]); |
181 | $_POST [ 'zip' ]= $myts -> addSlashes ( $_POST [ 'zip' ]); |
182 | $_POST [ 'county' ]= $myts -> addSlashes ( $_POST [ 'county' ]); |
183 | $_POST [ 'city' ]= $myts -> addSlashes ( $_POST [ 'city' ]); |
184 | $_POST [ 'addr' ]= $myts -> addSlashes ( $_POST [ 'addr' ]); |
187 | $sql = "update `" . $xoopsDB ->prefix( "contact" )."` set |
188 | `tel` = '{$_POST[' tel ']}' , |
189 | `email` = '{$_POST[' email ']}' , |
190 | `name` = '{$_POST[' name ']}' , |
191 | `gsn` = '{$_POST[' gsn ']}' , |
192 | `birthday` = '{$_POST[' birthday ']}' , |
193 | `zip` = '{$_POST[' zip ']}' , |
194 | `county` = '{$_POST[' county ']}' , |
195 | `city` = '{$_POST[' city ']}' , |
196 | `addr` = '{$_POST[' addr ']}' |
198 | $xoopsDB ->queryF( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ],3, mysql_error()); |
203 | function list_contact( $show_function =1){ |
204 | global $xoopsDB , $xoopsModule , $isAdmin ; |
206 | $sql = "select * from `" . $xoopsDB ->prefix( "contact" ). "` " ; |
207 | $result = $xoopsDB ->query( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ],3, mysql_error()); |
209 | $function_title =( $show_function )? "<th>功能</th>" : "" ; |
213 | while ( $all = $xoopsDB ->fetchArray( $result )){ |
215 | foreach ( $all as $k => $v ){ |
219 | $fun =( $show_function )?" |
221 | <a href= '{$_SERVER[' PHP_SELF ']}?op=contact_form&sn=$sn' class = 'link_button' >編輯</a> |
222 | <a href=\"javascript:delete_contact_func( $sn );\" class = 'link_button' >刪除</a> |
226 | $cate =get_contact_cate_all(); |
230 | <td>{ $cate [ $gsn ][ 'title' ]}</td> |
246 | $add_button =( $show_function )? "<a href='{$_SERVER['PHP_SELF']}?op=contact_form' class='link_button_r'>新增</a>" : "" ; |
251 | function delete_contact_func(sn){ |
252 | var sure = window.confirm( '確定刪除此資料?' ); |
254 | location.href=\"{ $_SERVER [ 'PHP_SELF' ]}?op=delete_contact&sn=\" + sn; |
258 | <table summary= 'list_table' id= 'tbl' style= 'width:100%;' > |
277 | <td colspan=11 class = 'bar' > |
284 | $main =div_3d( "" , $main , "corners" ); |
291 | function get_contact( $sn = "" ){ |
293 | if ( empty ( $sn )) return ; |
294 | $sql = "select * from `" . $xoopsDB ->prefix( "contact" ). "` where `sn` = '{$sn}'" ; |
295 | $result = $xoopsDB ->query( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ],3, mysql_error()); |
296 | $data = $xoopsDB ->fetchArray( $result ); |
301 | function delete_contact( $sn = "" ){ |
302 | global $xoopsDB , $isAdmin ; |
303 | $sql = "delete from `" . $xoopsDB ->prefix( "contact" ). "` where `sn` = '{$sn}'" ; |
304 | $xoopsDB ->queryF( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ],3, mysql_error()); |
309 | function get_contact_cate_options( $mode = 'show' , $default_gsn = "0" , $default_parent_gsn = "0" , $unselect_level = "" , $start_search_sn = "0" , $level =0){ |
310 | global $xoopsDB , $xoopsModule ; |
311 | $sql = "select `gsn` , `title` from `" . $xoopsDB ->prefix( "contact_cate" ). "` where `parent_gsn` = '{$start_search_sn}' order by `sort`" ; |
312 | $result = $xoopsDB ->query( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ] , 3, mysql_error()); |
314 | $prefix = str_repeat ( " " , $level ); |
317 | $unselect = explode ( "," , $unselect_level ); |
320 | while (list( $gsn , $title )= $xoopsDB ->fetchRow( $result )){ |
322 | $selected =( $gsn == $default_parent_gsn )? "selected=selected" : "" ; |
323 | $selected .=( $gsn == $default_gsn )? "disabled=disabled" : "" ; |
324 | $selected .=(in_array( $level , $unselect ))? "disabled=disabled" : "" ; |
326 | $selected =( $gsn == $default_gsn )? "selected=selected" : "" ; |
327 | $selected .=(in_array( $level , $unselect ))? "disabled=disabled" : "" ; |
329 | $main .= "<option value=$gsn $selected>{$prefix}{$title}</option>" ; |
330 | $main .=get_contact_cate_options( $mode , $default_gsn , $default_parent_gsn , $unselect_level , $gsn , $level ); |
338 | $op = empty ( $_REQUEST [ 'op' ])? "" : $_REQUEST [ 'op' ]; |
339 | $sn = empty ( $_REQUEST [ 'sn' ])? "" : intval ( $_REQUEST [ 'sn' ]); |
340 | $gsn = empty ( $_REQUEST [ 'gsn' ])? "" : intval ( $_REQUEST [ 'gsn' ]); |
341 | $files_sn = empty ( $_REQUEST [ 'files_sn' ])? "" : intval ( $_REQUEST [ 'files_sn' ]); |
348 | case "insert_contact" : |
349 | $sn =insert_contact(); |
350 | header( "location: {$_SERVER['PHP_SELF']}?sn=$sn" ); |
354 | case "update_contact" : |
356 | header( "location: {$_SERVER['PHP_SELF']}" ); |
361 | $main =contact_form( $sn ); |
365 | case "delete_contact" : |
367 | header( "location: {$_SERVER['PHP_SELF']}" ); |
372 | $main =list_contact(); |
380 | module_admin_footer( $main ,0); |