<?php
include("CheckSession.php");
?>
<!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>
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<script language="javascript">
	function SendInsert(objThisUi) {
		document.form1.action = "CustomerIndex.php?page=1";
		form1.submit();
	}
</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);
}

$AddTel = "";
if (isset($_GET["AddTel"])) {
	$AddTel = $_GET["AddTel"];
}

?>

<body>
	<form name="form1" method="post" action="CustomerIndex2.php">
		<table border="0" cellspacing="1" cellspadding="1" width="95%">
			<input type="hidden" id="AddTel" name="AddTel" value="<?php echo $AddTel; ?>">
			<tr>
				<td align="center" colspan="2">
					<span class="title"><b>新增/修改客戶資料</b></span>
				</td>
			</tr>
			<tr>
				<td align="center" colspan="2" width="70%">
					&nbsp;
				</td>
			</tr>
			<tr>
				<td align="center" colspan="2" width="70%">
					<table width="100%" border="1" cellspacing="2" cellpadding="2">
						<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']; ?>" <?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>
							<?php
							if ($_SESSION['rightLevel'] != "2") {
								if (str_indexof($_SESSION['rights'], "B1U") >= 0) {
							?>
									<td align="center">
										<input type="button" name="btnView" id="btnSub" value="查看/修改" class="t12" onclick="javascript:SendInsert(this);" style="WIDTH:150px;Height:40px;" />
									</td>
								<?php
								} else {
								?>
									<td align="center">
										&nbsp;
									</td>
								<?php
								}
								?>
								<?php
								if ((str_indexof($_SESSION['rights'], "B1I") >= 0)) {
								?>
									<td align="center">
										<input type="submit" name="btnSub" id="btnSub" value="新增客戶資料" class="t12" style="WIDTH:550px;Height:40px;" />
									</td>
								<?php
								} else {
								?>
									<td align="center">
										&nbsp;
									</td>
								<?php
								}
							} else {
								if (str_indexof($ARights, "D") >= 0) {
								?>
									<td align="center">
										<input type="button" name="btnView" id="btnSub" value="刪除" class="t12" onclick="javascript:SendInsert(this);" style="WIDTH:150px;Height:40px;" />
									</td>
								<?php
								} else {
								?>
									<td align="center">
										&nbsp;
									</td>
								<?php
								}
								?>
								<?php
								if ((str_indexof($ARights, "I") >= 0)) {
								?>
									<td align="center">
										<input type="submit" name="btnSub" id="btnSub" value="新增客戶資料" class="t12" style="WIDTH:550px;Height:40px;" />
									</td>
								<?php
								} else {
								?>
									<td align="center">
										&nbsp;
									</td>
							<?php
								}
							}
							?>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</form>
</body>

</html>