4-3
上課範例: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 ; |
207 | $sql = "select gsn,title from `" . $xoopsDB ->prefix( "contact_cate" ). "` where parent_gsn!='0' order by sort" ; |
208 | $result = $xoopsDB ->query( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ],3, mysql_error()); |
209 | while (list( $gsn , $title )= $xoopsDB ->fetchRow( $result )){ |
210 | $cate_arr []= "'$gsn':'$title'" ; |
212 | $cate_option =implode( " , " , $cate_arr ); |
215 | include_once XOOPS_ROOT_PATH. "/modules/tadtools/jeditable.php" ; |
217 | $jeditable = new jeditable(); |
224 | $sql = "select * from `" . $xoopsDB ->prefix( "contact" ). "` " ; |
225 | $result = $xoopsDB ->query( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ],3, mysql_error()); |
227 | $function_title =( $show_function )? "<th>功能</th>" : "" ; |
231 | while ( $all = $xoopsDB ->fetchArray( $result )){ |
233 | foreach ( $all as $k => $v ){ |
237 | $fun =( $show_function )?" |
239 | <a href= '{$_SERVER[' PHP_SELF ']}?op=contact_form&sn=$sn' class = 'link_button' >編輯</a> |
240 | <a href=\"javascript:delete_contact_func( $sn );\" class = 'link_button' >刪除</a> |
243 | $jeditable ->setSelectCol( "#gsn_{$sn}" , $file , "{{$cate_option}}" , "{'sn' : $sn , 'col' : 'gsn'}" ); |
244 | $jeditable ->setTextCol( "#name_{$sn}" , $file , '100px' , '12px' , "{'sn':$sn , 'col' : 'name'}" ); |
245 | $jeditable ->setTextCol( "#email_{$sn}" , $file , '100px' , '12px' , "{'sn':$sn , 'col' : 'email'}" ); |
247 | $cate =get_contact_cate_all(); |
251 | <td id= 'gsn_{$sn}' >{ $cate [ $gsn ][ 'title' ]}</td> |
252 | <td id= 'name_{$sn}' >{ $name }</td> |
254 | <td id= 'email_{$sn}' >{ $email }</td> |
265 | $jeditable_set = $jeditable ->render(); |
269 | $add_button =( $show_function )? "<a href='{$_SERVER['PHP_SELF']}?op=contact_form' class='link_button_r'>新增</a>" : "" ; |
276 | function delete_contact_func(sn){ |
277 | var sure = window.confirm( '確定刪除此資料?' ); |
279 | location.href=\"{ $_SERVER [ 'PHP_SELF' ]}?op=delete_contact&sn=\" + sn; |
283 | <table summary= 'list_table' id= 'tbl' style= 'width:100%;' > |
302 | <td colspan=11 class = 'bar' > |
309 | $main =div_3d( "" , $main , "corners" ); |
316 | function get_contact( $sn = "" ){ |
318 | if ( empty ( $sn )) return ; |
319 | $sql = "select * from `" . $xoopsDB ->prefix( "contact" ). "` where `sn` = '{$sn}'" ; |
320 | $result = $xoopsDB ->query( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ],3, mysql_error()); |
321 | $data = $xoopsDB ->fetchArray( $result ); |
326 | function delete_contact( $sn = "" ){ |
327 | global $xoopsDB , $isAdmin ; |
328 | $sql = "delete from `" . $xoopsDB ->prefix( "contact" ). "` where `sn` = '{$sn}'" ; |
329 | $xoopsDB ->queryF( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ],3, mysql_error()); |
334 | function get_contact_cate_options( $mode = 'show' , $default_gsn = "0" , $default_parent_gsn = "0" , $unselect_level = "" , $start_search_sn = "0" , $level =0){ |
335 | global $xoopsDB , $xoopsModule ; |
336 | $sql = "select `gsn` , `title` from `" . $xoopsDB ->prefix( "contact_cate" ). "` where `parent_gsn` = '{$start_search_sn}' order by `sort`" ; |
337 | $result = $xoopsDB ->query( $sql ) or redirect_header( $_SERVER [ 'PHP_SELF' ] , 3, mysql_error()); |
339 | $prefix = str_repeat ( " " , $level ); |
342 | $unselect = explode ( "," , $unselect_level ); |
345 | while (list( $gsn , $title )= $xoopsDB ->fetchRow( $result )){ |
347 | $selected =( $gsn == $default_parent_gsn )? "selected=selected" : "" ; |
348 | $selected .=( $gsn == $default_gsn )? "disabled=disabled" : "" ; |
349 | $selected .=(in_array( $level , $unselect ))? "disabled=disabled" : "" ; |
351 | $selected =( $gsn == $default_gsn )? "selected=selected" : "" ; |
352 | $selected .=(in_array( $level , $unselect ))? "disabled=disabled" : "" ; |
354 | $main .= "<option value=$gsn $selected>{$prefix}{$title}</option>" ; |
355 | $main .=get_contact_cate_options( $mode , $default_gsn , $default_parent_gsn , $unselect_level , $gsn , $level ); |
363 | $op = empty ( $_REQUEST [ 'op' ])? "" : $_REQUEST [ 'op' ]; |
364 | $sn = empty ( $_REQUEST [ 'sn' ])? "" : intval ( $_REQUEST [ 'sn' ]); |
365 | $gsn = empty ( $_REQUEST [ 'gsn' ])? "" : intval ( $_REQUEST [ 'gsn' ]); |
366 | $files_sn = empty ( $_REQUEST [ 'files_sn' ])? "" : intval ( $_REQUEST [ 'files_sn' ]); |
373 | case "insert_contact" : |
374 | $sn =insert_contact(); |
375 | header( "location: {$_SERVER['PHP_SELF']}?sn=$sn" ); |
379 | case "update_contact" : |
381 | header( "location: {$_SERVER['PHP_SELF']}" ); |
386 | $main =contact_form( $sn ); |
390 | case "delete_contact" : |
392 | header( "location: {$_SERVER['PHP_SELF']}" ); |
397 | $main =list_contact(); |
405 | module_admin_footer( $main ,0); |