:::

5-7 /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) or web_error($sql);
043    $all = $xoopsDB->fetchArray($result);
044 
045    //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note
046    foreach ($all as $k => $v) {
047        $$k = $v;
048    }
049 
050    //取得分類資料(phone_book_cate)
051    $phone_book_cate_arr = get_phone_book_cate($cate_sn);
052 
053    //過濾讀出的變數值
054    $name     = $myts->htmlSpecialChars($name);
055    $birthday = $myts->htmlSpecialChars($birthday);
056    $phone    = $myts->htmlSpecialChars($phone);
057    $email    = $myts->htmlSpecialChars($email);
058    $zip      = $myts->htmlSpecialChars($zip);
059    $county   = $myts->htmlSpecialChars($county);
060    $city     = $myts->htmlSpecialChars($city);
061    $addr     = $myts->htmlSpecialChars($addr);
062    $note     = $myts->displayTarea($note, 0, 1, 0, 1, 1);
063 
064    $xoopsTpl->assign('sn', $sn);
065    $xoopsTpl->assign('cate_sn', $cate_sn);
066    $xoopsTpl->assign('cate_sn_title', $phone_book_cate_arr['cate_title']);
067    $xoopsTpl->assign('name', $name);
068    $xoopsTpl->assign('birthday', $birthday);
069    $xoopsTpl->assign('phone', $phone);
070    $xoopsTpl->assign('email', $email);
071    $xoopsTpl->assign('zip', $zip);
072    $xoopsTpl->assign('county', $county);
073    $xoopsTpl->assign('city', $city);
074    $xoopsTpl->assign('addr', $addr);
075    $xoopsTpl->assign('note', $note);
076    $xoopsTpl->assign('action', $_SERVER['PHP_SELF']);
077    $xoopsTpl->assign('now_op', 'show_one_phone_book');
078 
079 
080    $sql = "select cate_sn, cate_title from `" . $xoopsDB->prefix("phone_book_cate") . "` where `cate_enable` = '1' order by cate_sort";
081    $result = $xoopsDB->query($sqlor web_error($sql);
082    while(list($csn, $cate_title) = $xoopsDB->fetchRow($result)){
083        $arr[$csn]=$cate_title;
084    }
085    $arr['selected']=$cate_sn;
086    $json=json_encode($arr);
087    $json=str_replace('"',"'",$json);
088 
089 
090    include_once XOOPS_ROOT_PATH."/modules/tadtools/jeditable.php";
091    $file="save_phone_book.php";
092    $jeditable = new jeditable();
093    //此處加入欲直接點擊編輯的欄位設定
094    $jeditable->setTextCol("#name", $file, '240px', '36px', "{'sn':$sn }", "點擊編輯");
095    $jeditable->setTextAreaCol("#note", $file, '500px', '150px', "{'sn':$sn, 'op':'textarea'}", "點擊編輯");
096    $jeditable->setSelectCol("#cate_sn", $file, $json, "{'sn' : $sn}", "點擊編輯");
097 
098    $jeditable_set=$jeditable->render();
099    $xoopsTpl->assign("jeditable_set",$jeditable_set);
100 
101}
102 
103//以流水號取得某筆phone_book_cate資料
104function get_phone_book_cate($cate_sn = '')
105{
106    global $xoopsDB;
107 
108    if (empty($cate_sn)) {
109        return;
110    }
111 
112    $sql = "select * from `" . $xoopsDB->prefix("phone_book_cate") . "`
113    where `cate_sn` = '{$cate_sn}'";
114    $result = $xoopsDB->query($sql)
115    or web_error($sql);
116    $data = $xoopsDB->fetchArray($result);
117    return $data;
118}
119 
120//列出所有phone_book資料
121function list_phone_book($def_cate_sn = "", $def_county="", $def_city="", $def_keyword="")
122{
123    global $xoopsDB, $xoopsTpl, $isAdmin;
124 
125    //get_jquery(true);
126 
127    $and_name=$and_cate_sn=$and_city="";
128    if(!empty($def_keyword)){
129        $and_name="and (`name` like '%{$def_keyword}%' or `city` like '%{$def_keyword}%' or `county` like '%{$def_keyword}%' or `addr` like '%{$def_keyword}%')";
130    }else{
131        $and_cate_sn = empty($def_cate_sn) ? "" : "and `cate_sn` = '{$def_cate_sn}'";
132        $and_county = empty($def_county) ? "" : "and `county` = '{$def_county}'";
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_county $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 web_error($sql);
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    $xoopsTpl->assign('def_cate_sn', $def_cate_sn);
195    $xoopsTpl->assign('def_county', $def_county);
196    $xoopsTpl->assign('def_city', $def_city);
197    $xoopsTpl->assign('def_keyword', $def_keyword);
198 
199 
200    //擷取縣市陣列
201    $county_arr=get_county_arr();
202 
203    //套用到樣板
204    $xoopsTpl->assign('county_arr', $county_arr);
205 
206    //表格自適應
207    if(file_exists(XOOPS_ROOT_PATH."/modules/tadtools/FooTable.php")){
208      include_once XOOPS_ROOT_PATH."/modules/tadtools/FooTable.php";
209      $FooTable = new FooTable();
210      $FooTableJS=$FooTable->render(true);
211      $xoopsTpl->assign('FooTableJS' , $FooTableJS);
212    }
213}
214 
215//擷取縣市陣列
216function get_county_arr(){
217    global $xoopsDB;
218 
219    $sql = "select county from `" . $xoopsDB->prefix("phone_book") . "` group by county order by zip";
220    $result = $xoopsDB->query($sql) or web_error($sql);
221    while (list($county) = $xoopsDB->fetchRow($result)) {
222        $county_arr[] = $county;
223    }
224    return $county_arr;
225}
226 
227//取得 phone_book_cate 的所有資料陣列
228function get_phone_book_cate_arr()
229{
230    global $xoopsDB;
231 
232    $sql = "select * from `" . $xoopsDB->prefix("phone_book_cate") . "`
233    where `cate_enable` = '1'";
234    $result = $xoopsDB->query($sql)
235    or web_error($sql);
236    while ($data = $xoopsDB->fetchArray($result)) {
237        $cate_sn       = $data['cate_sn'];
238        $all[$cate_sn] = $data;
239    }
240    return $all;
241}
242/*-----------執行動作判斷區----------*/
243include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php');
244$op      = system_CleanVars($_REQUEST, 'op', '', 'string');
245$city    = system_CleanVars($_REQUEST, 'city', '', 'string');
246$sn      = system_CleanVars($_REQUEST, 'sn', '', 'int');
247$cate_sn = system_CleanVars($_REQUEST, 'cate_sn', '', 'int');
248$county    = system_CleanVars($_REQUEST, 'county', '', 'string');
249$keyword    = system_CleanVars($_REQUEST, 'keyword', '', 'string');
250 
251switch ($op) {
252    /*---判斷動作請貼在下方---*/
253 
254    default:
255        if (empty($sn)) {
256            list_phone_book($cate_sn,$county,$city,$keyword);
257        } else {
258            show_one_phone_book($sn);
259        }
260        break;
261 
262        /*---判斷動作請貼在上方---*/
263}
264 
265/*-----------秀出結果區--------------*/
266$xoopsTpl->assign("toolbar", toolbar_bootstrap($interface_menu));
267$xoopsTpl->assign("isAdmin", $isAdmin);
268include_once XOOPS_ROOT_PATH . '/footer.php';

 


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1245%26tbsn%3D39

書籍目錄

展開 | 闔起

線上使用者

77人線上 (12人在瀏覽線上書籍)

會員: 0

訪客: 77

更多…