<?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 $ **/ /*-----------引入檔案區--------------*/ include "header.php"; $xoopsOption['template_main'] = set_bootstrap('phone_book_index_b3.html'); include_once XOOPS_ROOT_PATH . "/header.php"; /*-----------功能函數區--------------*/ //以流水號秀出某筆phone_book資料內容 function show_one_phone_book($sn = '') { global $xoopsDB, $xoopsTpl, $isAdmin; 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 web_error($sql); $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', $note); $xoopsTpl->assign('action', $_SERVER['PHP_SELF']); $xoopsTpl->assign('now_op', 'show_one_phone_book'); $sql = "select cate_sn, cate_title from `" . $xoopsDB->prefix("phone_book_cate") . "` where `cate_enable` = '1' order by cate_sort"; $result = $xoopsDB->query($sql) or web_error($sql); while(list($csn, $cate_title) = $xoopsDB->fetchRow($result)){ $arr[$csn]=$cate_title; } $arr['selected']=$cate_sn; $json=json_encode($arr); $json=str_replace('"',"'",$json); include_once XOOPS_ROOT_PATH."/modules/tadtools/jeditable.php"; $file="save_phone_book.php"; $jeditable = new jeditable(); //此處加入欲直接點擊編輯的欄位設定 $jeditable->setTextCol("#name", $file, '240px', '36px', "{'sn':$sn }", "點擊編輯"); $jeditable->setTextAreaCol("#note", $file, '500px', '150px', "{'sn':$sn, 'op':'textarea'}", "點擊編輯"); $jeditable->setSelectCol("#cate_sn", $file, $json, "{'sn' : $sn}", "點擊編輯"); $jeditable_set=$jeditable->render(); $xoopsTpl->assign("jeditable_set",$jeditable_set); } //以流水號取得某筆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 web_error($sql); $data = $xoopsDB->fetchArray($result); return $data; } //列出所有phone_book資料 function list_phone_book($def_cate_sn = "", $def_county="", $def_city="", $def_keyword="") { global $xoopsDB, $xoopsTpl, $isAdmin; //get_jquery(true); $and_name=$and_cate_sn=$and_city=""; if(!empty($def_keyword)){ $and_name="and (`name` like '%{$def_keyword}%' or `city` like '%{$def_keyword}%' or `county` like '%{$def_keyword}%' or `addr` like '%{$def_keyword}%')"; }else{ $and_cate_sn = empty($def_cate_sn) ? "" : "and `cate_sn` = '{$def_cate_sn}'"; $and_county = empty($def_county) ? "" : "and `county` = '{$def_county}'"; $and_city = empty($def_city) ? "" : "and `city` = '{$def_city}'"; } //取得分類資料 $phone_book_cate_arr = get_phone_book_cate_arr(); $myts = MyTextSanitizer::getInstance(); $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "` where 1 $and_cate_sn $and_county $and_city $and_name"; //getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項); $PageBar = getPageBar($sql, 20, 10, null, null, $bootstrap); $bar = $PageBar['bar']; $sql = $PageBar['sql']; $total = $PageBar['total']; $result = $xoopsDB->query($sql) or web_error($sql); $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'] = $cate_sn; $all_content[$i]['cate_title'] = $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('isAdmin', $isAdmin); $xoopsTpl->assign('all_content', $all_content); $xoopsTpl->assign('now_op', 'list_phone_book'); $xoopsTpl->assign('cate_sn', $cate_sn); $xoopsTpl->assign('cate_arr', get_phone_book_cate_arr()); $xoopsTpl->assign('def_cate_sn', $def_cate_sn); $xoopsTpl->assign('def_county', $def_county); $xoopsTpl->assign('def_city', $def_city); $xoopsTpl->assign('def_keyword', $def_keyword); //擷取縣市陣列 $county_arr=get_county_arr(); //套用到樣板 $xoopsTpl->assign('county_arr', $county_arr); //表格自適應 if(file_exists(XOOPS_ROOT_PATH."/modules/tadtools/FooTable.php")){ include_once XOOPS_ROOT_PATH."/modules/tadtools/FooTable.php"; $FooTable = new FooTable(); $FooTableJS=$FooTable->render(true); $xoopsTpl->assign('FooTableJS' , $FooTableJS); } } //擷取縣市陣列 function get_county_arr(){ global $xoopsDB; $sql = "select county from `" . $xoopsDB->prefix("phone_book") . "` group by county order by zip"; $result = $xoopsDB->query($sql) or web_error($sql); while (list($county) = $xoopsDB->fetchRow($result)) { $county_arr[] = $county; } return $county_arr; } //取得 phone_book_cate 的所有資料陣列 function get_phone_book_cate_arr() { global $xoopsDB; $sql = "select * from `" . $xoopsDB->prefix("phone_book_cate") . "` where `cate_enable` = '1'"; $result = $xoopsDB->query($sql) or web_error($sql); while ($data = $xoopsDB->fetchArray($result)) { $cate_sn = $data['cate_sn']; $all[$cate_sn] = $data; } return $all; } /*-----------執行動作判斷區----------*/ include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php'); $op = system_CleanVars($_REQUEST, 'op', '', 'string'); $city = system_CleanVars($_REQUEST, 'city', '', 'string'); $sn = system_CleanVars($_REQUEST, 'sn', '', 'int'); $cate_sn = system_CleanVars($_REQUEST, 'cate_sn', '', 'int'); $county = system_CleanVars($_REQUEST, 'county', '', 'string'); $keyword = system_CleanVars($_REQUEST, 'keyword', '', 'string'); switch ($op) { /*---判斷動作請貼在下方---*/ default: if (empty($sn)) { list_phone_book($cate_sn,$county,$city,$keyword); } else { show_one_phone_book($sn); } break; /*---判斷動作請貼在上方---*/ } /*-----------秀出結果區--------------*/ $xoopsTpl->assign("toolbar", toolbar_bootstrap($interface_menu)); $xoopsTpl->assign("isAdmin", $isAdmin); include_once XOOPS_ROOT_PATH . '/footer.php';