:::
所有書籍
「[1042] XOOPS模組開發進階」目錄
MarkDown
2. 表單驗證及點擊編輯
1. jquery入門及連動選單
1-1 /templates/phone_book_index_b3.html
1-2 /index.php
1-3 /ajax.php
2. 表單驗證及點擊編輯
2-1 /admin/main.php
2-2 /templates/phone_book_adm_main_b3.html
2-3 /index.php
2-4 /templates/phone_book_index_b3.html
2-5 /save_phone_book.php
2-6 /get_name.php
3. 自適應表格及拉動排序
3-1 /index.php
3-2 /templates/phone_book_index_b3.html
3-3 /admin/cate.php
3-4 /templates/phone_book_adm_cate_b3.html
3-5 /admin/main.php
3-6 /templates/phone_book_adm_main_b3.html
3-7 (利用FooTable的分頁+json功能)/index.php
3-8 (利用FooTable的分頁+json功能)/templates/phone_book_index_b3.html
3-9 (利用FooTable的分頁+json功能)/columns.json
3-10 (利用FooTable的分頁+json功能)/rows.json
3-11 (舊版FooTable)/index.php
3-12 (舊版FooTable)/templates/phone_book_index_b3.html
3-13 (舊版FooTable)tadtools/FooTable.php
4. 大小月曆應用
4-1 /templates/phone_book_adm_main_b3.html
4-2 /interface_menu.php
4-3 /birthday.php
4-4 /templates/phone_book_birthday_b3.html
4-5 /xoops_version.php
4-5 /get_event.php
5. Google圖表應用及頁籤
5-1 /interface_menu.php
5-2 /chart.php
5-3 /templates/phone_book_chart_b3.html
5-4 /xoops_version.php
5-5 /ajax.php
5-6 /templates/phone_book_index_b3.html
5-7 /index.php
5-8 /templates/phone_book_adm_main_b3.html
6. 各種文字檔的匯出匯入
6-1 /interface_menu.php
6-2 /html.php
6-3 /index.php
6-4 /function.php
6-5 /csv.php
6-6 /templates/phone_book_adm_main_b3.html
6-7 /admin/main.php
6-8 /json.php
6-9 /get_json.php
6-10 資料庫語法
7. Excel的匯出與匯入
7-1 /header.php
7-2 /excel.php
7-3 /test.php
7-4 /excel_one.php
7-5 /templates/phone_book_adm_main_b3.html
7-6 /admin/main.php
7-7 /index.php
7-8 /templates/phone_book_index_b3.html
8. 產生PDF檔
8-1 /header.php
8-2 /pdf.php
8-3 /pdf.php (多檔下載版)
9. 輸出Word檔及圖片檔
9-1 /header.php
9-2 /word.php
9-3 /index.php
9-4 /templates/phone_book_index_b3.html
2-2 /templates/phone_book_adm_main_b3.html
\[1042\] XOOPS模組開發進階 ==================== ``` <pre class="brush:php;highlight:[94,95,96,97,98,99,100,101,196,197,198,199,200,201,202,203,204,205,206,207,208,209];"> <?php /** * Phone Book module * * You may not change or alter any portion of this comment or credits * of supporting developers from this source code or any supporting source code * which is considered copyrighted (c) material of the original comment or credit authors. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ * @license http://www.fsf.org/copyleft/gpl.html GNU public license * @package Phone Book * @since 2.5 * @author tad * @version $Id $ **/ /*-----------引入檔案區--------------*/ $xoopsOption['template_main'] = 'phone_book_adm_main_b3.html'; include_once "header.php"; include_once "../function.php"; /*-----------功能函數區--------------*/ //phone_book編輯表單 function phone_book_form($sn = '') { global $xoopsDB, $xoopsTpl; //抓取預設值 if (!empty($sn)) { $DBV = get_phone_book($sn); } else { $DBV = array(); } //預設值設定 //設定 sn 欄位的預設值 $sn = !isset($DBV['sn']) ? $sn : $DBV['sn']; $xoopsTpl->assign('sn', $sn); //設定 cate_sn 欄位的預設值 $cate_sn = !isset($DBV['cate_sn']) ? '' : $DBV['cate_sn']; $xoopsTpl->assign('cate_sn', $cate_sn); //設定 name 欄位的預設值 $name = !isset($DBV['name']) ? '' : $DBV['name']; $xoopsTpl->assign('name', $name); //設定 birthday 欄位的預設值 $birthday = !isset($DBV['birthday']) ? date("Y-m-d") : $DBV['birthday']; $xoopsTpl->assign('birthday', $birthday); //設定 phone 欄位的預設值 $phone = !isset($DBV['phone']) ? '' : $DBV['phone']; $xoopsTpl->assign('phone', $phone); //設定 email 欄位的預設值 $email = !isset($DBV['email']) ? '' : $DBV['email']; $xoopsTpl->assign('email', $email); //設定 zip 欄位的預設值 $zip = !isset($DBV['zip']) ? '' : $DBV['zip']; $xoopsTpl->assign('zip', $zip); //設定 county 欄位的預設值 $county = !isset($DBV['county']) ? '' : $DBV['county']; $xoopsTpl->assign('county', $county); //設定 city 欄位的預設值 $city = !isset($DBV['city']) ? '' : $DBV['city']; $xoopsTpl->assign('city', $city); //設定 addr 欄位的預設值 $addr = !isset($DBV['addr']) ? '' : $DBV['addr']; $xoopsTpl->assign('addr', $addr); //設定 note 欄位的預設值 $note = !isset($DBV['note']) ? '' : $DBV['note']; $xoopsTpl->assign('note', $note); $op = empty($sn) ? "insert_phone_book" : "update_phone_book"; //$op = "replace_phone_book"; //分類編號 $sql = "select `cate_sn`, `cate_title` from `" . $xoopsDB->prefix("phone_book_cate") . "` order by cate_sort"; $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error()); $i = 0; $cate_sn_options_array = ''; while (list($cate_sn, $cate_title) = $xoopsDB->fetchRow($result)) { $cate_sn_options_array[$i]['cate_sn'] = $cate_sn; $cate_sn_options_array[$i]['cate_title'] = $cate_title; $i++; } $xoopsTpl->assign("cate_sn_options", $cate_sn_options_array); $xoopsTpl->assign('action', $_SERVER["PHP_SELF"]); $xoopsTpl->assign('now_op', 'phone_book_form'); $xoopsTpl->assign('next_op', $op); //套用formValidator驗證機制 if(!file_exists(TADTOOLS_PATH."/formValidator.php")){ redirect_header("index.php", 3, _TAD_NEED_TADTOOLS); } include_once TADTOOLS_PATH."/formValidator.php"; $formValidator = new formValidator("#myForm", true); $formValidator_code = $formValidator->render('centerRight'); $xoopsTpl->assign("formValidator_code",$formValidator_code); } //以流水號取得某筆phone_book資料 function get_phone_book($sn = '') { global $xoopsDB; if (empty($sn)) { return; } $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "` where `sn` = '{$sn}'"; $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error()); $data = $xoopsDB->fetchArray($result); return $data; } //新增資料到phone_book中 function insert_phone_book() { global $xoopsDB, $xoopsUser; $myts = MyTextSanitizer::getInstance(); $sn = intval($_POST['sn']); $cate_sn = $_POST['cate_sn']; $name = $myts->addSlashes($_POST['name']); $birthday = $myts->addSlashes($_POST['birthday']); $phone = $myts->addSlashes($_POST['phone']); $email = $myts->addSlashes($_POST['email']); $zip = $myts->addSlashes($_POST['zip']); $county = $myts->addSlashes($_POST['county']); $city = $myts->addSlashes($_POST['city']); $addr = $myts->addSlashes($_POST['addr']); $note = $myts->addSlashes($_POST['note']); $sql = "insert into `" . $xoopsDB->prefix("phone_book") . "` ( `cate_sn`, `name`, `birthday`, `phone`, `email`, `zip`, `county`, `city`, `addr`, `note` ) values( '{$cate_sn}', '{$name}', '{$birthday}', '{$phone}', '{$email}', '{$zip}', '{$county}', '{$city}', '{$addr}', '{$note}' )"; $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error()); //取得最後新增資料的流水編號 $sn = $xoopsDB->getInsertId(); return $sn; } //更新phone_book某一筆資料 function update_phone_book($sn = '') { global $xoopsDB, $xoopsUser; $myts = MyTextSanitizer::getInstance(); $sn = intval($_POST['sn']); $cate_sn = $_POST['cate_sn']; $name = $myts->addSlashes($_POST['name']); $birthday = $myts->addSlashes($_POST['birthday']); $phone = $myts->addSlashes($_POST['phone']); $email = $myts->addSlashes($_POST['email']); $zip = $myts->addSlashes($_POST['zip']); $county = $myts->addSlashes($_POST['county']); $city = $myts->addSlashes($_POST['city']); $addr = $myts->addSlashes($_POST['addr']); $note = $myts->addSlashes($_POST['note']); // if($_POST['name']==""){ // die('姓名為必填'); // } //字數檢查 $name_len = mb_strlen($name ,'utf-8'); if( $name_len < 2 or $name_len > 4){ die("姓名為必填,必須至少兩個字,最多四個字,您只填了 {$name_len} 個字。"); } if($phone==""){ die('電話為必填'); } if($email!=""){ if (!preg_match("/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$/", $email)) { die("信箱驗證失敗"); } } $sql = "update `" . $xoopsDB->prefix("phone_book") . "` set `cate_sn` = '{$cate_sn}', `name` = '{$name}', `birthday` = '{$birthday}', `phone` = '{$phone}', `email` = '{$email}', `zip` = '{$zip}', `county` = '{$county}', `city` = '{$city}', `addr` = '{$addr}', `note` = '{$note}' where `sn` = '$sn'"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error()); return $sn; } //刪除phone_book某筆資料資料 function delete_phone_book($sn = '') { global $xoopsDB; if (empty($sn)) { return; } $sql = "delete from `" . $xoopsDB->prefix("phone_book") . "` where `sn` = '{$sn}'"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error()); } //以流水號秀出某筆phone_book資料內容 function show_one_phone_book($sn = '') { global $xoopsDB, $xoopsTpl; if (empty($sn)) { return; } else { $sn = intval($sn); } $myts = MyTextSanitizer::getInstance(); $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "` where `sn` = '{$sn}' "; $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error()); $all = $xoopsDB->fetchArray($result); //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note foreach ($all as $k => $v) { $$k = $v; } //取得分類資料(phone_book_cate) $phone_book_cate_arr = get_phone_book_cate($cate_sn); //過濾讀出的變數值 $name = $myts->htmlSpecialChars($name); $birthday = $myts->htmlSpecialChars($birthday); $phone = $myts->htmlSpecialChars($phone); $email = $myts->htmlSpecialChars($email); $zip = $myts->htmlSpecialChars($zip); $county = $myts->htmlSpecialChars($county); $city = $myts->htmlSpecialChars($city); $addr = $myts->htmlSpecialChars($addr); $note = $myts->displayTarea($note, 0, 1, 0, 1, 1); $xoopsTpl->assign('sn', $sn); $xoopsTpl->assign('cate_sn', $cate_sn); $xoopsTpl->assign('cate_sn_title', $phone_book_cate_arr['cate_title']); $xoopsTpl->assign('name', $name); $xoopsTpl->assign('birthday', $birthday); $xoopsTpl->assign('phone', $phone); $xoopsTpl->assign('email', $email); $xoopsTpl->assign('zip', $zip); $xoopsTpl->assign('county', $county); $xoopsTpl->assign('city', $city); $xoopsTpl->assign('addr', $addr); $xoopsTpl->assign('note', nl2br($note)); $xoopsTpl->assign('action', $_SERVER['PHP_SELF']); $xoopsTpl->assign('now_op', 'show_one_phone_book'); } //以流水號取得某筆phone_book_cate資料 function get_phone_book_cate($cate_sn = '') { global $xoopsDB; if (empty($cate_sn)) { return; } $sql = "select * from `" . $xoopsDB->prefix("phone_book_cate") . "` where `cate_sn` = '{$cate_sn}'"; $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error()); $data = $xoopsDB->fetchArray($result); return $data; } //列出所有phone_book資料 function list_phone_book() { global $xoopsDB, $xoopsTpl; $myts = MyTextSanitizer::getInstance(); $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "` "; //getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項); $PageBar = getPageBar($sql, 20, 10, null, null, $bootstrap); $bar = $PageBar['bar']; $sql = $PageBar['sql']; $total = $PageBar['total']; $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error()); $all_content = ''; $i = 0; while ($all = $xoopsDB->fetchArray($result)) { //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note foreach ($all as $k => $v) { $$k = $v; } //過濾讀出的變數值 $name = $myts->htmlSpecialChars($name); $birthday = $myts->htmlSpecialChars($birthday); $phone = $myts->htmlSpecialChars($phone); $email = $myts->htmlSpecialChars($email); $zip = $myts->htmlSpecialChars($zip); $county = $myts->htmlSpecialChars($county); $city = $myts->htmlSpecialChars($city); $addr = $myts->htmlSpecialChars($addr); $note = $myts->displayTarea($note, 0, 1, 0, 1, 1); $all_content[$i]['sn'] = $sn; $all_content[$i]['cate_sn'] = $phone_book_cate_arr[$cate_sn]['cate_title']; $all_content[$i]['name'] = $name; $all_content[$i]['birthday'] = $birthday; $all_content[$i]['phone'] = $phone; $all_content[$i]['email'] = $email; $all_content[$i]['zip'] = $zip; $all_content[$i]['county'] = $county; $all_content[$i]['city'] = $city; $all_content[$i]['addr'] = $addr; $all_content[$i]['note'] = $note; $i++; } $xoopsTpl->assign('bar', $bar); $xoopsTpl->assign('action', $_SERVER['PHP_SELF']); $xoopsTpl->assign('all_content', $all_content); $xoopsTpl->assign('now_op', 'list_phone_book'); } /*-----------執行動作判斷區----------*/ include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php'); $op = system_CleanVars($_REQUEST, 'op', '', 'string'); $sn = system_CleanVars($_REQUEST, 'sn', '', 'int'); $cate_sn = system_CleanVars($_REQUEST, 'cate_sn', '', 'int'); switch ($op) { /*---判斷動作請貼在下方---*/ //替換資料 //case "replace_phone_book": // replace_phone_book(); // header("location: {$_SERVER['PHP_SELF']}?sn=$sn"); // exit; //break; //新增資料 case "insert_phone_book": $sn = insert_phone_book(); header("location: {$_SERVER['PHP_SELF']}?sn=$sn"); exit; break; //更新資料 case "update_phone_book": update_phone_book($sn); header("location: {$_SERVER['PHP_SELF']}?sn=$sn"); exit; break; case "phone_book_form": phone_book_form($sn); break; case "delete_phone_book": delete_phone_book($sn); header("location: {$_SERVER['PHP_SELF']}"); exit; break; default: if (empty($sn)) { list_phone_book(); //$main .= phone_book_form($sn); } else { show_one_phone_book($sn); } break; /*---判斷動作請貼在上方---*/ } /*-----------秀出結果區--------------*/ $xoopsTpl->assign("isAdmin", true); $xoTheme->addStylesheet(XOOPS_URL . '/modules/tadtools/css/xoops_adm.css'); include_once 'footer.php'; ```
:::
搜尋
search
進階搜尋
QR Code 區塊
快速登入
所有討論區
「PHP全端開發」線上課程討論區
XOOPS使用討論區
一般研習學員
社大學員專用
路過哈啦區
XOOPS佈景設計
XOOPS模組開發
Tad書籍區
即時留言簿
書籍目錄
總目錄
1.jquery入門及連動選單
1-1/templates/phone_book_index_b3.html
1-2/index.php
1-3/ajax.php
2.表單驗證及點擊編輯
2-1/admin/main.php
2-2/templates/phone_book_adm_main_b3.html
2-3/index.php
2-4/templates/phone_book_index_b3.html
2-5/save_phone_book.php
2-6/get_name.php
3.自適應表格及拉動排序
3-1/index.php
3-2/templates/phone_book_index_b3.html
3-3/admin/cate.php
3-4/templates/phone_book_adm_cate_b3.html
3-5/admin/main.php
3-6/templates/phone_book_adm_main_b3.html
3-7(利用FooTable的分頁+json功能)/index.php
3-8(利用FooTable的分頁+json功能)/templates/phone_book_index_b3.html
3-9(利用FooTable的分頁+json功能)/columns.json
3-10(利用FooTable的分頁+json功能)/rows.json
3-11(舊版FooTable)/index.php
3-12(舊版FooTable)/templates/phone_book_index_b3.html
3-13(舊版FooTable)tadtools/FooTable.php
4.大小月曆應用
4-1/templates/phone_book_adm_main_b3.html
4-2/interface_menu.php
4-3/birthday.php
4-4/templates/phone_book_birthday_b3.html
4-5/xoops_version.php
4-5/get_event.php
5.Google圖表應用及頁籤
5-1/interface_menu.php
5-2/chart.php
5-3/templates/phone_book_chart_b3.html
5-4/xoops_version.php
5-5/ajax.php
5-6/templates/phone_book_index_b3.html
5-7/index.php
5-8/templates/phone_book_adm_main_b3.html
6.各種文字檔的匯出匯入
6-1/interface_menu.php
6-2/html.php
6-3/index.php
6-4/function.php
6-5/csv.php
6-6/templates/phone_book_adm_main_b3.html
6-7/admin/main.php
6-8/json.php
6-9/get_json.php
6-10資料庫語法
7.Excel的匯出與匯入
7-1/header.php
7-2/excel.php
7-3/test.php
7-4/excel_one.php
7-5/templates/phone_book_adm_main_b3.html
7-6/admin/main.php
7-7/index.php
7-8/templates/phone_book_index_b3.html
8.產生PDF檔
8-1/header.php
8-2/pdf.php
8-3/pdf.php (多檔下載版)
9.輸出Word檔及圖片檔
9-1/header.php
9-2/word.php
9-3/index.php
9-4/templates/phone_book_index_b3.html
展開
|
闔起
線上使用者
62
人線上 (
9
人在瀏覽
線上書籍
)
會員: 0
訪客: 62
更多…
:::
主選單
NTPC OpenID
活動報名
模組控制台
進階區塊管理
站長工具箱(急救版)
網站地圖
Tad Tools 工具包
站長工具箱
行事曆
討論留言
嵌入區塊模組
快速登入
網站計數器
好站連結
最新消息
檔案下載
線上書籍
電子相簿
影音播放
常見問題
萬用表單
友站消息
社大學員
新聞
下載
教材
影音
討論
其他選單
好站連結
行事曆
電子相簿
常見問題
萬用表單
即時留言簿
友站消息
社大學員
登入
登入
帳號
密碼
登入