:::
所有書籍
「[981]PHP入門+XOOPS模組設計」目錄
MarkDown
17. 多國語系與圖形驗證
1. 相見歡
1-1 index.php 內容
2. PHP與表單
2-1 contact/index.php
3. 讓程式聰明又乾淨
3-1 index.php 原始語法
4. 寫入資料庫
4-1 index.php
5. 撈取資料庫資料
5-1 index.php
6. 把資料庫資料作成列表
6-1 index.php
7. 讓程式套用佈景
7-1 index.php
8. 加入修改刪除功能
8-1 index.php
9. 上傳檔案並做縮圖
9-1 index.php
10. 安裝XOOPS
10-1 index.php
11. XOOPS模組架構
11-1 index.php
11-2 index2.php
12. $xoopsUser應用
12-1 index.php
13. 分頁與搜尋
13-1 include/search.php
13-2 index.php
14. 樣板及評論
14-1 view.php
14-2 index.php
14-3 comment_new.php
15. 製作XOOPS區塊
15-1 blocks/new_contact.php
16. 偏好設定與所見即所得
16-1 view.php
17. 多國語系與圖形驗證
17-1 index.php
17-2 [語系]language/tchinese_utf8/modinfo.php
17-3 [語系]xoops_version.php
17-4 [語系]admin/menu.php
17-5 [sprintf示範]index.php
17-6 [sprintf示範]main.php
18. 模組自動功能
18-1 include/onUninstall.php
18-2 include/onUpdate.php
17-2 [語系]language/tchinese_utf8/modinfo.php
\[981\]PHP入門+XOOPS模組設計 ====================== <?php include\_once "../../mainfile.php"; include\_once "function.php"; define("\_DIR",XOOPS\_ROOT\_PATH."/uploads/tad\_contact"); $op=(empty($\_REQUEST\['op'\]))?"":$\_REQUEST\['op'\]; $sn=(empty($\_REQUEST\['sn'\]))?"0":intval($\_REQUEST\['sn'\]); switch($op){ case "show": $main= show\_data($sn); break; case "save": $sn= save\_data(); header("location:view.php?op=show&sn=$sn"); break; case "update": $sn= update(); header("location:view.php?op=show&sn=$sn"); break; case "add": $main= input\_form(0,"#6699ff"); break; case "del": del\_contact($sn); header("location:index.php"); break; case "modify": $main= input\_form(0,"#6699ff",$sn); break; default: $main= list\_all(); break; } include\_once XOOPS\_ROOT\_PATH."/header.php"; echo $main; include\_once XOOPS\_ROOT\_PATH.'/footer.php'; //刪除 function del\_contact($sn){ $sql="delete from `x233\_contact` where sn='{$sn}' "; mysql\_db\_query("tad\_9801",$sql) or die(mysql\_error()); } //顯示所有結果 function list\_all(){ global $xoopsDB,$xoopsUser,$xoopsModuleConfig; $i=0; $tbl=$xoopsDB->prefix('contact'); $sql="select \* from $tbl"; //PageBar(資料數, 每頁顯示幾筆資料, 最多顯示幾個頁數選項); $result = $xoopsDB->query($sql) or redirect\_header($\_SERVER\['PHP\_SELF'\],3, mysql\_error()); $total=$xoopsDB->getRowsNum($result); $navbar = new PageBar($total, $xoopsModuleConfig\['show\_num'\], 10); $mybar = $navbar->makeBar(); $bar= sprintf(\_BP\_TOOLBAR,$mybar\['total'\],$mybar\['current'\])."{$mybar\['left'\]}{$mybar\['center'\]}{$mybar\['right'\]}"; $sql.=$mybar\['sql'\]; //分頁工具列為 $bar $result=$xoopsDB->query($sql) or die(mysql\_error()); $tool\_title=($xoopsUser)?"<th>功能</th>":""; $main="<table border=1 style='width:auto;'> <tr><th>相片</th><th>姓名</th><th>性別</th><th>Email</th>$tool\_title</tr>"; while($data=$xoopsDB->fetchArray($result)){ $sex=($data\['sex'\]=="m")?"先生":"女士"; $color=($i % 2)?"white":"#f0f0f0"; $i++; $photo=\_DIR."/{$data\['sn'\]}\_s.png"; $show\_photo=XOOPS\_URL."/uploads/tad\_contact/{$data\['sn'\]}\_s.png"; $pic=(file\_exists($photo))?"<img src='$show\_photo'>":"沒有圖"; $tool=($xoopsUser)?"<td> <a href='index.php?op=modify&sn={$data\['sn'\]}'>編輯</a> | <a href='index.php?op=del&sn={$data\['sn'\]}'>刪除</a> </td>":""; $main.= " <tr bgcolor='$color'> <td>$pic</td> <td><a href='view.php?sn={$data\['sn'\]}'>{$data\['name'\]}</a></td> <td>{$sex}</td> <td>{$data\['email'\]}</td> $tool </tr>"; } $main.="</table> <p>$bar</p>"; return $main; } //單選判斷 function chk($val,$dbv){ if($val==$dbv){ return "checked"; } } //多選判斷 function chk2($val="",$dbv\_arr=array()){ if(in\_array($val,$dbv\_arr)){ return "checked"; } } //輸入表單 function input\_form($border=5,$bgcolor="#cccc66",$sn=""){ global $xoopsUser,$xoopsModule; if(!$xoopsUser){ //header("location:index.php"); redirect\_header("../../user.php",3,"您沒有權限,請先登入。"); } //修改模式 if(!empty($sn)){ $sql="select \* from `x233\_contact` where sn='$sn'"; $result=mysql\_db\_query("tad\_9801",$sql) or die(mysql\_error()); $data=mysql\_fetch\_array($result); //可秀出資料 $show\_data=explode(";",$data\['show\_data'\]); //縣市鄉鎮預設值 include "city\_menu/city.php"; $city\_def=default\_city($data\['city'\]); $town\_def=default\_town($data\['city'\],$data\['town'\]); if(empty($city\_def))$city\_def=0; if(empty($town\_def))$town\_def=0; $zip=$data\['zip'\]; $op="update"; }else{ //新增模式 //可秀出資料 $show\_data=array(); $city\_def=0; $town\_def=0; $zip="郵遞區號"; $op="save"; } $MDIR=$xoopsModule->getVar('dirname'); include(XOOPS\_ROOT\_PATH."/modules/{$MDIR}/class/fckeditor/fckeditor.php") ; $oFCKeditor = new FCKeditor('note') ; $oFCKeditor->BasePath = XOOPS\_URL."/modules/{$MDIR}/class/fckeditor/" ; $oFCKeditor->Config\['AutoDetectLanguage'\]=false; $oFCKeditor->Config\['DefaultLanguage'\] = 'zh' ; $oFCKeditor->ToolbarSet ='my'; $oFCKeditor->Width = '550' ; $oFCKeditor->Height = '200' ; $oFCKeditor->Value =$data\['note'\]; $editor=$oFCKeditor->CreateHtml() ; include\_once XOOPS\_ROOT\_PATH."/class/xoopsformloader.php";
$XoopsFormCaptcha=new XoopsFormCaptcha('','',false);
$Captcha=$XoopsFormCaptcha->render(); $data=" <script src='city\_menu/jquery-1.2.6.min.js'></script> <script> $(document).ready(function(){ initCS(); var disable\_empty\_list = true; }); </script> <script language='javascript' src='city\_menu/chainedselects.js'></script> <script language='javascript' src='city\_menu/city\_link.php'></script> <script language='javascript'> function initCS() { var form = document.myform; //初始化縣市鄉鎮選單 initListGroup('county', form.city, form.town); setTimeout('initLists()',0); } //縣市選單 function initLists() { var form = document.myform; form.city.selectedIndex = $city\_def; form.city.onchange(); setTimeout('initLists2()',0); } //鄉鎮選單 function initLists2() { var form = document.myform; form.town.selectedIndex = $town\_def; } </script> <form action='index.php' method='post' name='myform' enctype='multipart/form-data'> <table border={$border} align='center' bgcolor='{$bgcolor}'> <tr><th>姓名</th><td><input type='text' name='name' value='{$data\['name'\]}'></td></tr> <tr><th>性別</th><td> <input type='radio' name='sex' value='m' ".chk("m",$data\['sex'\]).">先生 <input type='radio' name='sex' value='f' ".chk("f",$data\['sex'\]).">女士 </td></tr> <tr><th>Email</th><td><input type='text' name='email' size=30 value='{$data\['email'\]}'></td></tr> <tr><th>電話</th><td><input type='text' name='tel' size=10 value='{$data\['tel'\]}'></td></tr> <tr><th>手機</th><td><input type='text' name='mtel' size=10 value='{$data\['mtel'\]}'></td></tr> <tr><th>地址</th><td> <input type='text' name='zip' size=5 value='{$zip}' onClick=\\" if(this.value=='郵遞區號'){ this.value=''; } \\"> <select name='city' style='width:80px;'></select> <select name='town' style='width:80px;'></select> <input type='text' name='address' size=30 value='{$data\['address'\]}'> </td></tr> <tr><th>服務單位</th><td><input type='text' name='company' size=30 value='{$data\['company'\]}'></td></tr> <tr><th>職稱</th><td><input type='text' name='job' size=10 value='{$data\['job'\]}'></td></tr> <tr><th>大頭照</th><td><input type='file' name='pic' size=20></td></tr> <tr><th>可秀出資料</th><td> <input type='checkbox' name='show\_data\[\]' value='性別' ".chk2("性別",$show\_data).">性別 <input type='checkbox' name='show\_data\[\]' value='Email' ".chk2("Email",$show\_data).">Email <input type='checkbox' name='show\_data\[\]' value='電話' ".chk2("電話",$show\_data).">電話 <input type='checkbox' name='show\_data\[\]' value='手機' ".chk2("手機",$show\_data).">手機 <input type='checkbox' name='show\_data\[\]' value='地址' ".chk2("地址",$show\_data).">地址 <input type='checkbox' name='show\_data\[\]' value='服務單位' ".chk2("服務單位",$show\_data).">服務單位 <input type='checkbox' name='show\_data\[\]' value='職稱' ".chk2("職稱",$show\_data).">職稱 </td></tr> <tr><th>其他說明</th><td> $editor</td></tr> <tr><th>圖形驗證</th><td> $Captcha</td></tr> </table> <input type='hidden' name='op' value='$op'> <input type='hidden' name='sn' value='{$sn}'> <p align='center'><input type='submit' value='儲存資料'></p> </form>"; return $data; } //儲存資料 function save\_data(){ global $xoopsDB,$xoopsUser; xoops\_load('captcha'); $xoopsCaptcha = XoopsCaptcha::getInstance(); if(!$xoopsCaptcha->verify()) { redirect\_header($\_SERVER\['PHP\_SELF'\], 5, $xoopsCaptcha->getMessage()); } if($xoopsUser){ $uid=$xoopsUser->uid(); } if(!empty($\_POST\['show\_data'\])){ $show\_data=implode(";",$\_POST\['show\_data'\]); } $tbl=$xoopsDB->prefix('contact'); $sql="insert into `$tbl` (`name`, `sex`, `email`, `tel`, `mtel`, `zip`, `city`, `town`, `addr`, `company`, `jobname`, `pic\_type`, `show\_data`, `note`, `post\_date`,`uid`) values('{$\_POST\['name'\]}' , '{$\_POST\['sex'\]}' , '{$\_POST\['email'\]}' , '{$\_POST\['tel'\]}' , '{$\_POST\['mtel'\]}' , '{$\_POST\['zip'\]}' , '{$\_POST\['city'\]}' , '{$\_POST\['town'\]}' , '{$\_POST\['addr'\]}' , '{$\_POST\['company'\]}' , '{$\_POST\['jobname'\]}' , '{$\_POST\['pic\_type'\]}' , '{$show\_data}' , '{$\_POST\['note'\]}',now(),'$uid')"; $xoopsDB->query($sql) or die(mysql\_error()); $sn=$xoopsDB->getInsertId(); upload($sn); return $sn; } //更新資料 function update(){ global $xoopsDB,$xoopsUser; xoops\_load('captcha'); $xoopsCaptcha = XoopsCaptcha::getInstance(); if(!$xoopsCaptcha->verify()) { redirect\_header($\_SERVER\['PHP\_SELF'\], 5, $xoopsCaptcha->getMessage()); } if($xoopsUser){ $uid=$xoopsUser->getVar('uid'); } if(!empty($\_POST\['show\_data'\])){ $show\_data=implode(";",$\_POST\['show\_data'\]); } $tbl=$xoopsDB->prefix('contact'); $sql="update `$tbl` set `name`='{$\_POST\['name'\]}', `sex`='{$\_POST\['sex'\]}', `email`='{$\_POST\['email'\]}', `tel`='{$\_POST\['tel'\]}', `mtel`='{$\_POST\['mtel'\]}', `zip`='{$\_POST\['zip'\]}', `city`='{$\_POST\['city'\]}', `town`='{$\_POST\['town'\]}', `addr`='{$\_POST\['addr'\]}', `company`='{$\_POST\['company'\]}', `jobname`='{$\_POST\['jobname'\]}', `pic\_type`='{$\_POST\['pic\_type'\]}', `show\_data`='{$show\_data}', `note`='{$\_POST\['note'\]}', `post\_date`=now(), `uid`='{$uid}' where sn='{$\_POST\['sn'\]}'"; $xoopsDB->queryF($sql) or die(mysql\_error()); upload($\_POST\['sn'\]); return $\_POST\['sn'\]; } function upload($sn=""){ if(empty($\_FILES\['pic'\]\['name'\])){ return; } include('class/upload/class.upload.php'); if(file\_exists(\_DIR."/{$sn}.png")){ unlink(\_DIR."/{$sn}.png"); unlink(\_DIR."/{$sn}\_s.png"); } $img\_handle = new upload($\_FILES\['pic'\],"zh\_TW"); if ($img\_handle->uploaded) { $img\_handle->file\_safe\_name = false; $img\_handle->file\_new\_name\_body = $sn; $img\_handle->image\_convert = 'png'; $img\_handle->image\_resize = true; $img\_handle->image\_x = 280; $img\_handle->image\_ratio\_y = true; $img\_handle->process(\_DIR); if ($img\_handle->processed) { //$img\_handle->clean(); } else { die($img\_handle->error); } } if ($img\_handle->uploaded) { $img\_handle->file\_safe\_name = false; $img\_handle->file\_new\_name\_body = $sn."\_s"; $img\_handle->image\_convert = 'png'; $img\_handle->image\_resize = true; $img\_handle->image\_x = 80; $img\_handle->image\_ratio\_y = true; $img\_handle->process(\_DIR); if ($img\_handle->processed) { $img\_handle->clean(); } else { die($img\_handle->error); } } } ?>
:::
搜尋
search
進階搜尋
QR Code 區塊
快速登入
所有討論區
「PHP全端開發」線上課程討論區
XOOPS使用討論區
一般研習學員
社大學員專用
路過哈啦區
XOOPS佈景設計
XOOPS模組開發
Tad書籍區
即時留言簿
書籍目錄
展開
|
闔起
線上使用者
260
人線上 (
99
人在瀏覽
線上書籍
)
會員: 0
訪客: 260
更多…
:::
主選單
NTPC OpenID
活動報名
模組控制台
進階區塊管理
站長工具箱(急救版)
網站地圖
Tad Tools 工具包
站長工具箱
行事曆
討論留言
嵌入區塊模組
快速登入
網站計數器
好站連結
最新消息
檔案下載
線上書籍
電子相簿
影音播放
常見問題
萬用表單
友站消息
社大學員
新聞
下載
教材
影音
討論
其他選單
好站連結
行事曆
電子相簿
常見問題
萬用表單
即時留言簿
友站消息
社大學員
登入
登入
帳號
密碼
登入