<?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>
<?php

require_once("class/DBConfig.php");
require_once("class/DBOperation.php");
require_once("class/MacOperation.php");

$action = $_GET["action"];
$CNicknameQ = $_GET['CNickname'];
$CNAreaQ = $_GET['CNArea'];
$CMAreaQ = $_GET['CMArea'];
$CSAreaQ = $_GET['CSArea'];
$CAreaQ = $_GET['CArea'];
$CSourceQ = $_GET['CSource'];
$CTelQ = $_GET['CTel'];
$ChkGreenQ = $_GET['chkGreen'];
$ChkBlackQ = $_GET['chkBlack'];
$ChkRedQ = $_GET['chkRed'];
//$CMissQ = $_GET['CMiss'];

$CNickname = "";
$CArea = "";
$CSource = "";
$CGreenTel = "";
$CBlackTel = "";
$CRedTel = "";
$CMemo = "";
$CMiss = "";
$id = "";

$db = new DBOperation();

$id = $_GET["id"];
if($id == null || $id == "")
{
	echo '<script type="text/javascript">';
  echo 'alert("無明細資料，請重新查詢!!!");';
  echo 'history.go(-1);';
  echo '</script>';
  exit;
}

$FieldRights = $_SESSION['fieldRights'];
$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
$db->query("SELECT * FROM Customer where CId = '".$db->mysql_real_escape_string($id)."'");
$row = $db->fetch_row();
$CNickname = $row[1];
$CArea = $row[2];

$CTempArea = "";
if(str_indexof($CArea,"Taipei") >= 0)
{
	if($CTempArea == "")
	{
		$CTempArea = "台北";
	}
	else
	{
		$CTempArea = $CTempArea." "."台北";
	}
}
if(str_indexof($CArea,"Taoyuan") >= 0)
{
	if($CTempArea == "")
	{
		$CTempArea = "桃園";
	}
	else
	{
		$CTempArea = $CTempArea." "."桃園";
	}
}
if(str_indexof($CArea,"Zhongli") >= 0)
{
	if($CTempArea == "")
	{
		$CTempArea = "中壢";
	}
	else
	{
		$CTempArea = $CTempArea." "."中壢";
	}
}
if(str_indexof($CArea,"Hsinchu") >= 0)
{
	if($CTempArea == "")
	{
		$CTempArea = "新竹";
	}
	else
	{
		$CTempArea = $CTempArea." "."新竹";
	}
}
if(str_indexof($CArea,"Taichung") >= 0)
{
	if($CTempArea == "")
	{
		$CTempArea = "台中";
	}
	else
	{
		$CTempArea = $CTempArea." "."台中";
	}
}
if(str_indexof($CArea,"Zhanghua") >= 0)
{
	if($CTempArea == "")
	{
		$CTempArea = "彰投";
	}
	else
	{
		$CTempArea = $CTempArea." "."彰投";
	}
}
if(str_indexof($CArea,"Tainan") >= 0)
{
	if($CTempArea == "")
	{
		$CTempArea = "台南";
	}
	else
	{
		$CTempArea = $CTempArea." "."台南";
	}
}
if(str_indexof($CArea,"Kaohsiung") >= 0)
{
	if($CTempArea == "")
	{
		$CTempArea = "高雄";
	}
	else
	{
		$CTempArea = $CTempArea." "."高雄";
	}
}
if(str_indexof($CArea,"Hualien") >= 0)
{
	if($CTempArea == "")
	{
		$CTempArea = "花蓮";
	}
	else
	{
		$CTempArea = $CTempArea." "."花蓮";
	}
}
if(str_indexof($CArea,"Toufen") >= 0)
{
	if($CTempArea == "")
	{
		$CTempArea = "頭份";
	}
	else
	{
		$CTempArea = $CTempArea." "."頭份";
	}
}

if(str_indexof($FieldRights,"CSource") >= 0)
{
	$CSource = $row[3];
}
else
{
	$CSource = "";
}
if(str_indexof($FieldRights,"CGreenTel") >= 0)
{
	$CGreenTel = $row[4];
}
else
{
	$CGreenTel = "";
}
if(str_indexof($FieldRights,"CBlackTel") >= 0)
{
	$CBlackTel = $row[5];
}
else
{
	$CBlackTel = "";
}
if(str_indexof($FieldRights,"CRedTel") >= 0)
{
	$CRedTel = $row[6];
}
else
{
	$CRedTel = "";
}
if(str_indexof($FieldRights,"CMemo") >= 0)
{
	$CMemo = nl2br($row[7]);
}
else
{
	$CMemo = "";
}

$CTempMemo = "";
if(str_indexof($CMemo,"01") >= 0)
{
	if($CTempMemo == "")
	{
		$CTempMemo = "高價";
	}
	else
	{
		$CTempMemo = $CTempMemo." "."高價";
	}
}
if(str_indexof($CMemo,"02") >= 0)
{
	if($CTempMemo == "")
	{
		$CTempMemo = "常客";
	}
	else
	{
		$CTempMemo = $CTempMemo." "."常客";
	}
}
if(str_indexof($CMemo,"03") >= 0)
{
	if($CTempMemo == "")
	{
		$CTempMemo = "好客";
	}
	else
	{
		$CTempMemo = $CTempMemo." "."好客";
	}
}
if(str_indexof($CMemo,"04") >= 0)
{
	if($CTempMemo == "")
	{
		$CTempMemo = "不傳";
	}
	else
	{
		$CTempMemo = $CTempMemo." "."不傳";
	}
}
if(str_indexof($CMemo,"05") >= 0)
{
	if($CTempMemo == "")
	{
		$CTempMemo = "大奶";
	}
	else
	{
		$CTempMemo = $CTempMemo." "."大奶";
	}
}
if(str_indexof($CMemo,"06") >= 0)
{
	if($CTempMemo == "")
	{
		$CTempMemo = "腿長";
	}
	else
	{
		$CTempMemo = $CTempMemo." "."腿長";
	}
}
if(str_indexof($CMemo,"07") >= 0)
{
	if($CTempMemo == "")
	{
		$CTempMemo = "臉蛋";
	}
	else
	{
		$CTempMemo = $CTempMemo." "."臉蛋";
	}
}


$db->close_db();
$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
$querySql = "select CId,CMiss,CPayDate from CMissContent where CCId = '".$id."' order by CPayDate desc";
$db->query($querySql);

while($myrow = $db->fetch_array())
{
	if($CMiss == "")
	{
		$CMiss = $myrow['CPayDate']." - ".$myrow['CMiss'];
	}
	else
	{
		$CMiss = $CMiss."<br>".$myrow['CPayDate']." - ".$myrow['CMiss'];
	}
}

$db->close_db();


?>
<body>
<form name="GroupRightsForm" method="post" action="CustomerQueryIndex.php" id="GroupRightsForm">
<input type="hidden" name="CNickname" id="action" value="<?php echo $CNicknameQ; ?>"/>
<input type="hidden" name="CArea" id="action" value="<?php echo $CAreaQ; ?>"/>
<input type="hidden" name="CNArea" id="action" value="<?php echo $CNAreaQ; ?>"/>
<input type="hidden" name="CMArea" id="action" value="<?php echo $CMAreaQ; ?>"/>
<input type="hidden" name="CSArea" id="action" value="<?php echo $CSAreaQ; ?>"/>
<input type="hidden" name="CSource" id="action" value="<?php echo $CSourceQ; ?>"/>
<input type="hidden" name="CTel" id="action" value="<?php echo $CTelQ; ?>"/>
<input type="hidden" name="chkGreen" id="action" value="<?php echo $chkGreenQ; ?>"/>
<input type="hidden" name="chkBlack" id="action" value="<?php echo $chkBlackQ; ?>"/>
<input type="hidden" name="chkRed" id="action" value="<?php echo $chkRedQ; ?>"/>
<!--<input type="hidden" name="CMiss" id="action" value="<?php echo $CMissQ; ?>"/>--?
<table border="0" cellspacing="0" cellspadding="0" width="90%">
<!--
<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="left" colspan="2">
<span class="t14b"><b>客戶資料</b></span>
</td>
</tr>
<tr>
<td align="left" colspan="2">
<table border="3" cellspacing="2" cellspadding="2" width="100%">
<tr>
<td align="left" width="15%">
<span class="t12">暱稱</span>
</td>
<td align="left" width="85%">
<span class="t12"><?php echo $CNickname ?></span>
</td>
</tr>

<tr>
<td align="left" width="15%">
<span class="t12">地區</span>
</td>
<td align="left" width="85%">
<span class="t12"><?php echo $CTempArea ?></span>
</td>
</tr>

<?php
if(str_indexof($FieldRights,"CSource") >= 0)
{
?>
<tr>
<td align="left">
<span class="t12">來源</span>
</td>
<td align="left">
<?php 
if($CSource == "W")
{
	echo "<span style=class='t12'>微信</span>";
}
elseif($CSource == "L")
{
	echo "<span style=class='t12'>Line</span>";
}
elseif($CSource == "G")
{
	echo "<span style=class='t12'>遇見</span>";
}
elseif($CSource == "T")
{
	echo "<span style=class='t12'>電話</span>";
}
elseif($CSource == "O")
{
	echo "<span style=class='t12'>其他</span>";
}
?>
</td>
</tr>
<?php
}
?>
<?php
if(str_indexof($FieldRights,"CGreenTel") >= 0)
{
?>
<tr>
<td align="left" width="15%">
<span class="t12g">
<b>電話(綠)</b>
</span>
</td>
<td align="left" width="85%">
<span class="t12g">
<b><?php if($CGreenTel != "") echo $CGreenTel;else echo "&nbsp;" ?></b>
</span>
</td>
</tr>
</b>
</span>
<?php
}
?>
<?php
if(str_indexof($FieldRights,"CBlackTel") >= 0)
{
?>
<tr>
<td align="left" width="15%">
<span class="t12">
<b>電話(黑)</b>
</span>
</td>
<td align="left" width="85%">
<span class="t12">
<b><?php if($CBlackTel != "") echo $CBlackTel;else echo "&nbsp;" ?></b>
</span>
</td>
</tr>
<?php
}
?>
<?php
if(str_indexof($FieldRights,"CRedTel") >= 0)
{
?>
<tr>
<td align="left" width="15%">
<span class="t12r">
<b>電話(紅)</b>
</span>
</td>
<td align="left" width="85%">
<span class="t12r">
<b><?php if($CRedTel != "") echo $CRedTel;else echo "&nbsp;" ?></b>
</span>
</td>
</tr>
<?php
}
?>
<?php
if(str_indexof($FieldRights,"CMemo") >= 0)
{
?>

<tr>
<td align="left" width="15%">
<span class="t12">喜好<br>/其他</span>
</td>
<td align="left" width="85%">
<span class="t12"><?php if($CTempMemo != "") echo $CTempMemo;else echo "&nbsp;" ?></span>
</td>
</tr>
<?php
}
?>
<?php
if(str_indexof($FieldRights,"CMemo") >= 0)
{
?>

<tr>
<td align="left" width="15%">
<span class="t12">消費內容</span>
</td>
<td align="left" width="85%">
<span class="t12"><?php if($CMiss != "") echo $CMiss;else echo "&nbsp;" ?></span>
</td>
</tr>

<?php
}
?>
<tr>
<td  align="center" colspan="2">
<input type="submit" name="btnSub" id="btnSub" value="返回" class"t12"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
