[1012]PHP進階開發及TadTools工具應用
<?php
/*-----------引入檔案區--------------*/
include_once "header.php";
include_once "up_file.php";
/*-----------function區--------------*/
$op=isset($_GET['op'])?$_GET['op']:"";
$sn=isset($_GET['sn'])?$_GET['sn']:"";
switch($op){
case "photo":
$main=get_photo($sn);
break;
case "file":
$main=get_files($sn);
break;
default:
$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;
}
$main="
<table summary='list_table' id='tbl' style='width:100%;'>
<tr><th nowrap>姓名</th><td>{$name}</td></tr>
<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>";
break;
}
$sql = "select sn,name from `".$xoopsDB->prefix("contact")."` ";
$result = $xoopsDB->query($sql);
while(list($sn,$name)=$xoopsDB->fetchRow($result)){
$selected=($sn==$_GET['sn'])?"selected":"";
$option.="<option value='$sn' $selected>$name</option>";
}
echo "<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' href='".XOOPS_URL."/modules/tadtools/jquery.mobile/jquery.mobile.css' />
<script src='".XOOPS_URL."/modules/tadtools/jquery/jquery.js'></script>
<script src='".XOOPS_URL."/modules/tadtools/jquery.mobile/jquery.mobile.js'></script>
</head>
<body>
<div data-role='page' id='p1'>
<div data-role='header'>
<a data-icon='arrow-l' data-rel='back'>回上頁</a>
<h3><select onChange=\"location.href='data.php?op=$op&sn=' + this.value\">$option</select></h3>
<a href='pda.php' data-icon='home'>回首頁</a>
<div data-role='navbar' >
<ul>
<li><a href='data.php?op=base&sn={$_GET['sn']}' data-icon='star' data-iconpos='top' data-theme='a'>基本資料</a></li>
<li><a href='data.php?op=photo&sn={$_GET['sn']}' data-icon='search' data-iconpos='top' data-theme='a'>相關相片</a></li>
<li><a href='data.php?op=file&sn={$_GET['sn']}' data-icon='check' data-iconpos='top' data-theme='a'>相關檔案</a></li>
</ul>
</div>
</div>
<div data-role='content'>
{$main}
</div>
<div data-role='footer'></div>
</div>
</body>
</html>
";
function get_photo($sn=""){
$photo_file=get_pic_file('photo' , $sn , 1 );
$photo="<img src='{$photo_file}'>";
return $photo;
}
function get_files($sn=""){
$file=show_files('files' , $sn );
return $file;
}
?>