:::

2-3 /index.php

001<?php
002/**
003 * Phone Book module
004 *
005 * You may not change or alter any portion of this comment or credits
006 * of supporting developers from this source code or any supporting source code
007 * which is considered copyrighted (c) material of the original comment or credit authors.
008 * This program is distributed in the hope that it will be useful,
009 * but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
011 *
012 * @copyright  The XOOPS Project http://sourceforge.net/projects/xoops/
013 * @license    http://www.fsf.org/copyleft/gpl.html GNU public license
014 * @package    Phone Book
015 * @since      2.5
016 * @author     tad
017 * @version    $Id $
018 **/
019 
020/*-----------引入檔案區--------------*/
021include "header.php";
022$xoopsOption['template_main'] = set_bootstrap('phone_book_index_b3.html');
023include_once XOOPS_ROOT_PATH . "/header.php";
024 
025/*-----------功能函數區--------------*/
026 
027//以流水號秀出某筆phone_book資料內容
028function show_one_phone_book($sn = '')
029{
030    global $xoopsDB, $xoopsTpl, $isAdmin;
031 
032    if (empty($sn)) {
033        return;
034    } else {
035        $sn = intval($sn);
036    }
037 
038    $myts = MyTextSanitizer::getInstance();
039 
040    $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "`
041    where `sn` = '{$sn}' ";
042    $result = $xoopsDB->query($sql)
043    or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
044    $all = $xoopsDB->fetchArray($result);
045 
046    //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note
047    foreach ($all as $k => $v) {
048        $$k = $v;
049    }
050 
051    //取得分類資料(phone_book_cate)
052    $phone_book_cate_arr = get_phone_book_cate($cate_sn);
053 
054    //過濾讀出的變數值
055    $name     = $myts->htmlSpecialChars($name);
056    $birthday = $myts->htmlSpecialChars($birthday);
057    $phone    = $myts->htmlSpecialChars($phone);
058    $email    = $myts->htmlSpecialChars($email);
059    $zip      = $myts->htmlSpecialChars($zip);
060    $county   = $myts->htmlSpecialChars($county);
061    $city     = $myts->htmlSpecialChars($city);
062    $addr     = $myts->htmlSpecialChars($addr);
063    $note     = $myts->displayTarea($note, 0, 1, 0, 1, 1);
064 
065    $xoopsTpl->assign('sn', $sn);
066    $xoopsTpl->assign('cate_sn', $cate_sn);
067    $xoopsTpl->assign('cate_sn_title', $phone_book_cate_arr['cate_title']);
068    $xoopsTpl->assign('name', $name);
069    $xoopsTpl->assign('birthday', $birthday);
070    $xoopsTpl->assign('phone', $phone);
071    $xoopsTpl->assign('email', $email);
072    $xoopsTpl->assign('zip', $zip);
073    $xoopsTpl->assign('county', $county);
074    $xoopsTpl->assign('city', $city);
075    $xoopsTpl->assign('addr', $addr);
076    $xoopsTpl->assign('note', $note);
077    $xoopsTpl->assign('action', $_SERVER['PHP_SELF']);
078    $xoopsTpl->assign('now_op', 'show_one_phone_book');
079 
080 
081    $sql = "select cate_sn, cate_title from `" . $xoopsDB->prefix("phone_book_cate") . "` where `cate_enable` = '1' order by cate_sort";
082    $result = $xoopsDB->query($sqlor redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
083    while(list($csn, $cate_title) = $xoopsDB->fetchRow($result)){
084        $arr[$csn]=$cate_title;
085    }
086    $arr['selected']=$cate_sn;
087    $json=json_encode($arr);
088    $json=str_replace('"',"'",$json);
089 
090 
091    include_once XOOPS_ROOT_PATH."/modules/tadtools/jeditable.php";
092    $file="save_phone_book.php";
093    $jeditable = new jeditable();
094    //此處加入欲直接點擊編輯的欄位設定
095    $jeditable->setTextCol("#name", $file, '240px', '36px', "{'sn':$sn }", "點擊編輯");
096    $jeditable->setTextAreaCol("#note", $file, '500px', '150px', "{'sn':$sn, 'op':'textarea'}", "點擊編輯");
097    $jeditable->setSelectCol("#cate_sn", $file, $json, "{'sn' : $sn}", "點擊編輯");
098 
099    $jeditable_set=$jeditable->render();
100    $xoopsTpl->assign("jeditable_set",$jeditable_set);
101 
102}
103 
104//以流水號取得某筆phone_book_cate資料
105function get_phone_book_cate($cate_sn = '')
106{
107    global $xoopsDB;
108 
109    if (empty($cate_sn)) {
110        return;
111    }
112 
113    $sql = "select * from `" . $xoopsDB->prefix("phone_book_cate") . "`
114    where `cate_sn` = '{$cate_sn}'";
115    $result = $xoopsDB->query($sql)
116    or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
117    $data = $xoopsDB->fetchArray($result);
118    return $data;
119}
120 
121//列出所有phone_book資料
122function list_phone_book($def_cate_sn = "", $def_city="")
123{
124    global $xoopsDB, $xoopsTpl, $isAdmin;
125 
126    //get_jquery(true);
127 
128    $and_name=$and_cate_sn=$and_city="";
129    if(isset($_GET['keyword'])){
130        $and_name="and name='{$_GET['keyword']}'";
131    }else{
132        $and_cate_sn = empty($def_cate_sn) ? "" : "and `cate_sn` = '{$def_cate_sn}'";
133        $and_city = empty($def_city) ? "" : "and `city` = '{$def_city}'";
134    }
135 
136    //取得分類資料
137    $phone_book_cate_arr = get_phone_book_cate_arr();
138 
139    $myts = MyTextSanitizer::getInstance();
140 
141    $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "` where 1 $and_cate_sn $and_city $and_name";
142 
143    //getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項);
144    $PageBar = getPageBar($sql, 20, 10, null, null, $bootstrap);
145    $bar     = $PageBar['bar'];
146    $sql     = $PageBar['sql'];
147    $total   = $PageBar['total'];
148 
149    $result = $xoopsDB->query($sql)
150    or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
151 
152    $all_content = '';
153    $i           = 0;
154    while ($all = $xoopsDB->fetchArray($result)) {
155        //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note
156        foreach ($all as $k => $v) {
157            $$k = $v;
158        }
159 
160        //過濾讀出的變數值
161        $name     = $myts->htmlSpecialChars($name);
162        $birthday = $myts->htmlSpecialChars($birthday);
163        $phone    = $myts->htmlSpecialChars($phone);
164        $email    = $myts->htmlSpecialChars($email);
165        $zip      = $myts->htmlSpecialChars($zip);
166        $county   = $myts->htmlSpecialChars($county);
167        $city     = $myts->htmlSpecialChars($city);
168        $addr     = $myts->htmlSpecialChars($addr);
169        $note     = $myts->displayTarea($note, 0, 1, 0, 1, 1);
170 
171        $all_content[$i]['sn']         = $sn;
172        $all_content[$i]['cate_sn']    = $cate_sn;
173        $all_content[$i]['cate_title'] = $phone_book_cate_arr[$cate_sn]['cate_title'];
174        $all_content[$i]['name']       = $name;
175        $all_content[$i]['birthday']   = $birthday;
176        $all_content[$i]['phone']      = $phone;
177        $all_content[$i]['email']      = $email;
178        $all_content[$i]['zip']        = $zip;
179        $all_content[$i]['county']     = $county;
180        $all_content[$i]['city']       = $city;
181        $all_content[$i]['addr']       = $addr;
182        $all_content[$i]['note']       = $note;
183        $i++;
184    }
185 
186    $xoopsTpl->assign('bar', $bar);
187    $xoopsTpl->assign('action', $_SERVER['PHP_SELF']);
188    $xoopsTpl->assign('isAdmin', $isAdmin);
189    $xoopsTpl->assign('all_content', $all_content);
190    $xoopsTpl->assign('now_op', 'list_phone_book');
191    $xoopsTpl->assign('cate_sn', $cate_sn);
192    $xoopsTpl->assign('cate_arr', get_phone_book_cate_arr());
193 
194    //擷取縣市陣列
195    $county_arr=get_county_arr();
196 
197    //套用到樣板
198    $xoopsTpl->assign('county_arr', $county_arr);
199}
200 
201//擷取縣市陣列
202function get_county_arr(){
203    global $xoopsDB;
204 
205    $sql = "select county from `" . $xoopsDB->prefix("phone_book") . "` group by county order by zip";
206    $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
207    while (list($county) = $xoopsDB->fetchRow($result)) {
208        $county_arr[] = $county;
209    }
210    return $county_arr;
211}
212 
213//取得 phone_book_cate 的所有資料陣列
214function get_phone_book_cate_arr()
215{
216    global $xoopsDB;
217 
218    $sql = "select * from `" . $xoopsDB->prefix("phone_book_cate") . "`
219    where `cate_enable` = '1'";
220    $result = $xoopsDB->query($sql)
221    or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
222    while ($data = $xoopsDB->fetchArray($result)) {
223        $cate_sn       = $data['cate_sn'];
224        $all[$cate_sn] = $data;
225    }
226    return $all;
227}
228/*-----------執行動作判斷區----------*/
229include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php');
230$op      = system_CleanVars($_REQUEST, 'op', '', 'string');
231$city    = system_CleanVars($_REQUEST, 'city', '', 'string');
232$sn      = system_CleanVars($_REQUEST, 'sn', '', 'int');
233$cate_sn = system_CleanVars($_REQUEST, 'cate_sn', '', 'int');
234 
235switch ($op) {
236    /*---判斷動作請貼在下方---*/
237 
238    default:
239        if (empty($sn)) {
240            list_phone_book($cate_sn,$city);
241        } else {
242            show_one_phone_book($sn);
243        }
244        break;
245 
246        /*---判斷動作請貼在上方---*/
247}
248 
249/*-----------秀出結果區--------------*/
250$xoopsTpl->assign("toolbar", toolbar_bootstrap($interface_menu));
251$xoopsTpl->assign("isAdmin", $isAdmin);
252include_once XOOPS_ROOT_PATH . '/footer.php';

 


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.cp22.secserverpros.com%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1217%26tbsn%3D39

書籍目錄

展開 | 闔起

線上使用者

38人線上 (5人在瀏覽線上書籍)

會員: 0

訪客: 38

更多…