[1012]PHP進階開發及TadTools工具應用
<?php
/*-----------引入檔案區--------------*/
include_once "header.php";
include_once "up_file.php";
$xoopsOption['template_main'] = "contact_index_tpl.html";
//手持裝置判斷
if(file_exists(XOOPS_ROOT_PATH."/modules/tadtools/mobile_device_detect.php")){
include_once XOOPS_ROOT_PATH."/modules/tadtools/mobile_device_detect.php";
mobile_device_detect(true, false, true, true, true, true, true, "pda.php?sn={$_GET['sn']}", false);
}
/*-----------function區--------------*/
//列出所有contact資料
function list_contact(){
global $xoopsDB , $xoopsModule , $isAdmin;
$jquery=get_jquery();
//刪除確認的JS
$main="
$jquery
<script type='text/javascript'>
$(document).ready(function(){
$.post('ajax.php' , function(data){
$('#menu1').html(data);
$.post('ajax.php' , {parent_gsn: $('#menu1').val()} , function(data){
$('#menu2').html(data);
contact_list();
});
});
$('#menu1').change(function(){
$.post('ajax.php' , {parent_gsn: $('#menu1').val()} , function(data){
$('#menu2').html(data);
contact_list();
});
});
$('#menu2').change(function(){
contact_list();
});
});
//去抓該分類的通訊錄
function contact_list(){
$.post('ajax.php' , {gsn: $('#menu2').val()} , function(data){
$('#contact_list').html(data);
});
}
</script>
<select id='menu1'></select>
<select name='gsn' id='menu2'></select>
<table summary='list_table' id='tbl' style='width:100%;'>
<tr>
<th>群組</th>
<th>姓名</th>
<th>電話</th>
<th>信箱</th>
<th>生日</th>
<th>地址</th>
</tr>
<tbody id='contact_list'>
$all_content
</tbody>
<tr>
<td colspan=11 class='bar'>
</td>
</tr>
</table>";
//raised,corners,inset
$main=div_3d("",$main,"corners");
return $main;
}
//以流水號秀出某筆contact資料內容
function show_one_contact($sn=""){
global $xoopsDB , $xoopsModule , $isAdmin;
if(empty($sn)){
return;
}else{
$sn=intval($sn);
}
$sql = "select * from `".$xoopsDB->prefix("contact")."` where `sn` = '{$sn}' ";
$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
$all=$xoopsDB->fetchArray($result);
//以下會產生這些變數: $tel , $email , $name , $gsn , $sn , $birthday , $zip , $county , $city , $addr
foreach($all as $k=>$v){
$$k=$v;
}
$cate=get_contact_cate($gsn);
$jquery_path=get_jquery(true); //TadTools引入jquery ui
$data="
$jquery_path
<script type='text/javascript' src='".XOOPS_URL."/modules/tadtools/jqueryCookie/jquery.cookie.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
$('#jquery-tabs').tabs({ cookie: { expires: 30 }});
});
</script>
<div id='jquery-tabs'>
<ul>
<li><a href='#tabs-1'>基本資料</a></li>
<li><a href='ajax2.php?op=photo&sn=$sn'>相關相片</a></li>
<li><a href='ajax2.php?op=file&sn=$sn'>相關檔案</a></li>
</ul>
<div id='tabs-1'>
<table summary='list_table' id='tbl' style='width:100%;'>
<tr><th nowrap>電話</th><td>{$tel}</td></tr>
<tr><th nowrap>信箱</th><td>{$email}</td></tr>
<tr><th nowrap>生日</th><td>{$birthday}</td></tr>
<tr><th nowrap>地址</th><td>{$zip} {$county}{$city}{$addr}</td></tr>
</table>
</div>
</div>
";
include_once XOOPS_ROOT_PATH."/modules/tadtools/qrcode/qrcode.php";
$a = new QR("Email:{$email}");
file_put_contents(XOOPS_ROOT_PATH."/uploads/qrcode/{$sn}.gif",$a->image(2));
$data.="<img src='".XOOPS_URL."/uploads/qrcode/{$sn}.gif'>";
//raised,corners,inset
$main=div_3d("{$cate['title']} / {$name}",$data,"corners");
return $main;
}
/*-----------執行動作判斷區----------*/
$op=empty($_REQUEST['op'])?"":$_REQUEST['op'];
$sn=empty($_REQUEST['sn'])?"":intval($_REQUEST['sn']);
$gsn=empty($_REQUEST['gsn'])?"":intval($_REQUEST['gsn']);
$files_sn=empty($_REQUEST['files_sn'])?"":intval($_REQUEST['files_sn']);
switch($op){
default:
if(empty($sn)){
$main=list_contact();
}else{
$main=show_one_contact($sn);
}
break;
}
/*-----------秀出結果區--------------*/
module_footer($main);
?>