<?php
include("CheckSession.php");
$_SESSION['QueryTimeSql'] = "";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="description" content="馬戲團" />
	<title>馬戲團</title>
	<Script Language="javascript" src="control/calendar.js"></Script>
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/JavaScript">
	<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//-->
</script>
<?php
require_once("class/DBConfig.php");
require_once("class/DBOperation.php");

$db = new DBOperation();
$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
$ARights = "";
$querySql = "";
if ($_SESSION['rightLevel'] == "0") {
	$querySql = "select * from AdminUser,GroupRights where AGroupId = GId and AFlag = '1' order by ACreateTime,GRightLevel";
} elseif ($_SESSION['rightLevel'] == "1") {
	$querySql = "select AId,AName,AAccount,AFlag,GName from AdminUser,GroupRights where AFlag = '1' and AGroupId = GId And AGroupId = " . $_SESSION['groupId'] . " order by AId";
} elseif ($_SESSION['rightLevel'] == "2") {
	$querySql = "select ARights from AdminUser where AId = " . $_SESSION['userId'] . " and AFlag = '1'";
	$db->query($querySql);
	$myrow = $db->fetch_array();
	$ARights = $myrow['ARights'];
	$querySql = "";
}
if ($querySql != "") {
	$db->query($querySql);
}
?>

<body onload="MM_preloadImages('images/Query1.jpg')">
	<form name="CustomerBuyTimesForm" method="post" action="CustomerBuyTimesQueryIndexW.php" id="CustomerBuyTimesForm">
		<table border="1" cellspacing="0" cellspadding="0" width="100%">
			<!--
<tr>
<td align="center" colspan="2">
<span class="title"><b>客戶資料查詢</b></span>
</td>
</tr>
-->
			<tr>
				<td align="left" colspan="2">
					&nbsp;
				</td>
			</tr>
			<tr>
				<td align="center" width="20%">
					<span class="t12">誰的客戶</span>
				</td>
				<td align="left">
					<?php
					if ($_SESSION['rightLevel'] != "2") {
						$i = 0;
						while ($myrow = $db->fetch_array()) {
							$i = $i + 1;
					?>
							<input type="radio" value="<?php echo $myrow['AId'] . "&" . $myrow['AName']; ?>" <?php if ($i == 1) echo "checked"; ?> name="AId">
							<span class="t12"><?php echo $myrow['AName']; ?></span>
							<?php
							if ($i % 6 == 0) {
								echo "<br>";
							}
							?>
						<?php
						}
						$db->close_db();
					} else {
						?>
						<input type="hidden" value="<?php echo $_SESSION['userId']; ?>" name="AId" id="AId">
						<span class="t12"><?php echo $_SESSION['username1']; ?></span>
					<?php
					}
					?>
				</td>
			</tr>
			<tr>
				<td align="left" width="15%">
					<span class="t12">消費</span>
				</td>
				<td align="left" width="85%">
					<span class="t12">
						<input type="checkbox" name="CCostOne" id="CCostOne" value="CostOne">只消費
						<input type="text" name="CCostTimes" id="CCostTimes" size="2" maxlength="2" class="t12" value="0" />
						次
					</span>
				</td>
			</tr>
			<tr>
				<td align="left" width="15%">
					<span class="t12">地區</span>
				</td>
				<td align="left" width="85%">
					<table border="0" cellspacing="5" cellspading="5">
						<tr>
							<td>
								<span class="t12">
									<input type="checkbox" name="chkTaipei" id="chkTaipei" value="N:Taipei">台北
								</span>
								<br>
								<span class="t12">
									<input type="checkbox" name="chkTainan" id="chkTainan" value="S:Tainan">台南
								</span>
							</td>
							<td>
								<span class="t12">
									<input type="checkbox" name="chkTaoyuan" id="chkTaoyuan" value="N:Taoyuan">桃園
								</span>
								<br>
								<span class="t12">
									<input type="checkbox" name="chkKaohsiung" id="chkKaohsiung" value="S:Kaohsiung">高雄
								</span>
							</td>
							<td>
								<span class="t12">
									<input type="checkbox" name="chkZhongli" id="chkZhongli" value="N:Zhongli">中壢
								</span>
								<br>
								<span class="t12">
									<input type="checkbox" name="chkHualien" id="chkHualien" value="E:Hualien">花蓮
								</span>
							</td>
							<td>
								<span class="t12">
									<input type="checkbox" name="chkHsinchu" id="chkHsinchu" value="M:Hsinchu">新竹
								</span>
								<br>
								<span class="t12">
									<input type="checkbox" name="chkToufen" id="chkToufen" value="M:Toufen">頭份
								</span>
							</td>
							<td>
								<span class="t12">
									<input type="checkbox" name="chkTaichung" id="chkTaichung" value="M:Taichung">台中
								</span>
								<br>
								&nbsp;
							</td>
							<td>
								<span class="t12">
									<input type="checkbox" name="chkZhanghua" id="chkZhanghua" value="M:Zhanghua">彰投
								</span>
								<br>
								&nbsp;
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td align="center" colspan="2">
					<?php
					if ($_SESSION['username'] == "admin") {
					?>
						<a href="javascript:CustomerBuyTimesForm.submit();">
							<img src="images/Query1.jpg" ID="ImgLogIn" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('ImgLogIn','','images/Query2.jpg',1)">
						</a>
					<?php
					}
					?>
				</td>
			</tr>
		</table>

		</td>
		</tr>
		</table>
	</form>
</body>

</html>