<?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 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];}
}

function MM_openBrWindow(theURL,winName,win_width,win_height) { 
  var PosX = ((screen.width-win_width)/100)*99; 
  var PosY = ((screen.height-win_height)/100)*99;
  features = "status=no,toolbar=no,scrollbars=yes,resizable=yes,width=750,Height=550,top="+PosY+",left="+PosX;; 
  var newwin = window.open(theURL,winName,features); 
} 
//-->
</script>
<SCRIPT language="JavaScript">
	function checkDelete(id) {
		if (confirm("確定要刪除嗎????")) {
			location.href = "CustomerQueryDeleteDeal.php?id=" + id;
		}
	}
</SCRIPT>
<?php
require_once("class/DBConfig.php");
require_once("class/DBOperation.php");

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require "../Exception.php";
require "../PHPMailer.php";
require "../SMTP.php";

$db = new DBOperation();

if ($_SESSION['QuerySql'] == "") {
	$CQueryTel = $_POST['CQueryTel'];
	$CQueryTel = trim($CQueryTel);

	$queryCond = "";
	$querySql = "";
	$querySpecSql = "(1=1 ";
	$querySql = $querySql . " where (1=1 ";

	if ($CQueryTel != null && $CQueryTel != "") {
		if ($queryCond == "") {
			$queryCond = "電話 : " . $CQueryTel;
		} else {
			$queryCond = $queryCond . ",電話 : " . $CQueryTel;
		}
		$queryTelSql = "";
		$querySql = $querySql . " and (";
		$querySpecSql = $querySpecSql . " and (";
		if ($queryTelSql == "") {
			$queryTelSql = " CGreenTel like '%" . $CQueryTel . "%'";
		} else {
			$queryTelSql = $queryTelSql . " or CGreenTel like '%" . $CQueryTel . "%'";
		}
		if ($queryTelSql == "") {
			$queryTelSql = " CBlackTel like '%" . $CQueryTel . "%'";
		} else {
			$queryTelSql = $queryTelSql . " or CBlackTel like '%" . $CQueryTel . "%'";
		}
		if ($queryTelSql == "") {
			$queryTelSql = " CRedTel like '%" . $CQueryTel . "%'";
		} else {
			$queryTelSql = $queryTelSql . " or CRedTel like '%" . $CQueryTel . "%'";
		}
		$querySql = $querySql . $queryTelSql;
		$querySql = $querySql . " )";

		$querySpecSql = $querySpecSql . $queryTelSql;
		$querySpecSql = $querySpecSql . " )";
	}


	$queryAreaSql = "";
	$chkTaipei = $_POST['chkTaipei'];
	$queryAreaCond = "";
	if ($chkTaipei != null && $chkTaipei != "") {
		if ($queryAreaCond == "") {
			$queryAreaCond = "地區 : 台北";
		} else {
			$queryAreaCond = $queryAreaCond . ",台北";
		}

		if ($queryAreaSql == "") {
			$queryAreaSql = " CArea like '%N:Taipei%'";
		} else {
			$queryAreaSql = $queryAreaSql . " or CArea like '%N:Taipei%'";
		}
	}
	$chkTaoyuan = $_POST['chkTaoyuan'];
	if ($chkTaoyuan != null && $chkTaoyuan != "") {
		if ($queryAreaCond == "") {
			$queryAreaCond = "地區 : 桃園";
		} else {
			$queryAreaCond = $queryAreaCond . ",桃園";
		}

		if ($queryAreaSql == "") {
			$queryAreaSql = " CArea like '%N:Taoyuan%'";
		} else {
			$queryAreaSql = $queryAreaSql . " or CArea like '%N:Taoyuan%'";
		}
	}
	$chkZhongli = $_POST['chkZhongli'];
	if ($chkZhongli != null && $chkZhongli != "") {
		if ($queryAreaCond == "") {
			$queryAreaCond = "地區 : 中壢";
		} else {
			$queryAreaCond = $queryAreaCond . ",中壢";
		}

		if ($queryAreaSql == "") {
			$queryAreaSql = " CArea like '%N:Zhongli%'";
		} else {
			$queryAreaSql = $queryAreaSql . " or CArea like '%N:Zhongli%'";
		}
	}
	$chkHsinchu = $_POST['chkHsinchu'];
	if ($chkHsinchu != null && $chkHsinchu != "") {
		if ($queryAreaCond == "") {
			$queryAreaCond = "地區 : 新竹";
		} else {
			$queryAreaCond = $queryAreaCond . ",新竹";
		}

		if ($queryAreaSql == "") {
			$queryAreaSql = " CArea like '%M:Hsinchu%'";
		} else {
			$queryAreaSql = $queryAreaSql . " or CArea like '%M:Hsinchu%'";
		}
	}
	$chkTaichung = $_POST['chkTaichung'];
	if ($chkTaichung != null && $chkTaichung != "") {
		if ($queryAreaCond == "") {
			$queryAreaCond = "地區 : 台中";
		} else {
			$queryAreaCond = $queryAreaCond . ",台中";
		}

		if ($queryAreaSql == "") {
			$queryAreaSql = " CArea like '%M:Taichung%'";
		} else {
			$queryAreaSql = $queryAreaSql . " or CArea like '%M:Taichung%'";
		}
	}
	$chkZhanghua = $_POST['chkZhanghua'];
	if ($chkZhanghua != null && $chkZhanghua != "") {
		if ($queryAreaCond == "") {
			$queryAreaCond = "地區 : 彰投";
		} else {
			$queryAreaCond = $queryAreaCond . ",彰投";
		}

		if ($queryAreaSql == "") {
			$queryAreaSql = " CArea like '%M:Zhanghua%'";
		} else {
			$queryAreaSql = $queryAreaSql . " or CArea like '%M:Zhanghua%'";
		}
	}
	$chkTainan = $_POST['chkTainan'];
	if ($chkTainan != null && $chkTainan != "") {
		if ($queryAreaCond == "") {
			$queryAreaCond = "地區 : 台南";
		} else {
			$queryAreaCond = $queryAreaCond . ",台南";
		}

		if ($queryAreaSql == "") {
			$queryAreaSql = " CArea like '%S:Tainan%'";
		} else {
			$queryAreaSql = $queryAreaSql . " or CArea like '%S:Tainan%'";
		}
	}
	$chkKaohsiung = $_POST['chkKaohsiung'];
	if ($chkKaohsiung != null && $chkKaohsiung != "") {
		if ($queryAreaCond == "") {
			$queryAreaCond = "地區 : 高雄";
		} else {
			$queryAreaCond = $queryAreaCond . ",高雄";
		}

		if ($queryAreaSql == "") {
			$queryAreaSql = " CArea like '%S:Kaohsiung%'";
		} else {
			$queryAreaSql = $queryAreaSql . " or CArea like '%S:Kaohsiung%'";
		}
	}

	$chkHualien = $_POST['chkHualien'];
	if ($chkHualien != null && $chkHualien != "") {
		if ($queryAreaCond == "") {
			$queryAreaCond = "地區 : 花蓮";
		} else {
			$queryAreaCond = $queryAreaCond . ",花蓮";
		}

		if ($queryAreaSql == "") {
			$queryAreaSql = " CArea like '%E:Hualien%'";
		} else {
			$queryAreaSql = $queryAreaSql . " or CArea like '%E:Hualien%'";
		}
	}
	$chkToufen = $_POST['chkToufen'];
	if ($chkToufen != null && $chkToufen != "") {
		if ($queryAreaCond == "") {
			$queryAreaCond = "地區 : 頭份";
		} else {
			$queryAreaCond = $queryAreaCond . ",頭份";
		}

		if ($queryAreaSql == "") {
			$queryAreaSql = " CArea like '%M:Toufen%'";
		} else {
			$queryAreaSql = $queryAreaSql . " or CArea like '%M:Toufen%'";
		}
	}

	if ($queryAreaCond != "") {
		if ($queryCond == "") {
			$queryCond = $queryAreaCond;
		} else {
			$queryCond = $queryCond . "," . $queryAreaCond;
		}
	}
	if ($queryAreaSql != "") {
		$querySql = $querySql . " And (";
		$querySql = $querySql . $queryAreaSql;
		$querySql = $querySql . " )";

		$querySpecSql = $querySpecSql . " And (";
		$querySpecSql = $querySpecSql . $queryAreaSql;
		$querySpecSql = $querySpecSql . " )";
	}

	$querySourceSql = "";
	$querySourceCond = "";
	$chkSourceL = $_POST['chkSourceL'];
	if ($chkSourceL != null && $chkSourceL != "") {
		if ($querySourceCond == "") {
			$querySourceCond = "來源 : Line";
		} else {
			$querySourceCond = $querySourceCond . ",Line";
		}

		if ($querySourceSql == "") {
			$querySourceSql = " CSource like '%L%'";
		} else {
			$querySourceSql = $querySourceSql . " or CSource like '%L%'";
		}
	}

	$chkSourceW = $_POST['chkSourceW'];
	if ($chkSourceW != null && $chkSourceW != "") {
		if ($querySourceCond == "") {
			$querySourceCond = "來源 : 微信";
		} else {
			$querySourceCond = $querySourceCond . ",微信";
		}

		if ($querySourceSql == "") {
			$querySourceSql = " CSource like '%W%'";
		} else {
			$querySourceSql = $querySourceSql . " or CSource like '%W%'";
		}
	}

	$chkSourceT = $_POST['chkSourceT'];
	if ($chkSourceT != null && $chkSourceT != "") {
		if ($querySourceCond == "") {
			$querySourceCond = "來源 : 電話";
		} else {
			$querySourceCond = $querySourceCond . ",電話";
		}

		if ($querySourceSql == "") {
			$querySourceSql = " CSource like '%T%'";
		} else {
			$querySourceSql = $querySourceSql . " or CSource like '%T%'";
		}
	}

	$chkSourceG = $_POST['chkSourceG'];
	if ($chkSourceG != null && $chkSourceG != "") {
		if ($querySourceCond == "") {
			$querySourceCond = "來源 : 即時通";
		} else {
			$querySourceCond = $querySourceCond . ",即時通";
		}

		if ($querySourceSql == "") {
			$querySourceSql = " CSource like '%G%'";
		} else {
			$querySourceSql = $querySourceSql . " or CSource like '%G%'";
		}
	}

	$chkSourceS = $_POST['chkSourceS'];
	if ($chkSourceS != null && $chkSourceS != "") {
		if ($querySourceCond == "") {
			$querySourceCond = "來源 : SKYPE";
		} else {
			$querySourceCond = $querySourceCond . ",SKYPE";
		}

		if ($querySourceSql == "") {
			$querySourceSql = " CSource like '%S%'";
		} else {
			$querySourceSql = $querySourceSql . " or CSource like '%S%'";
		}
	}

	$chkSourceO = $_POST['chkSourceO'];
	if ($chkSourceO != null && $chkSourceO != "") {
		if ($querySourceCond == "") {
			$querySourceCond = "來源 : 其他";
		} else {
			$querySourceCond = $querySourceCond . ",其他";
		}

		if ($querySourceSql == "") {
			$querySourceSql = " CSource like '%O%'";
		} else {
			$querySourceSql = $querySourceSql . " or CSource like '%O%'";
		}
	}

	if ($querySourceSql != "") {
		if ($queryCond == "") {
			$queryCond = $querySourceCond;
		} else {
			$queryCond = $queryCond . "," . $querySourceCond;
		}
	}

	if ($querySourceSql != "") {
		$querySql = $querySql . " And (";
		$querySql = $querySql . $querySourceSql;
		$querySql = $querySql . " )";

		$querySpecSql = $querySpecSql . " And (";
		$querySpecSql = $querySpecSql . $querySourceSql;
		$querySpecSql = $querySpecSql . " )";
	}

	$CNickName = $_POST['CNickName'];
	if ($CNickName != null && $CNickName != "") {
		if ($queryCond == "") {
			$queryCond = "暱稱/其他 : " . $CNickName;
		} else {
			$queryCond = $queryCond . ",暱稱/其他 : " . $CNickName;
		}
		$querySql = $querySql . " And CNickname like '%" . $CNickName . "%'";
		$querySpecSql = $querySpecSql . " And CNickname like '%" . $CNickName . "%'";
	}

	$queryClassSql = "";
	$queryClassCond = "";
	$chkClassA = $_POST['chkClassA'];
	if ($chkClassA != null && $chkClassA != "") {
		if ($queryClassCond == "") {
			$queryClassCond = "類別 : A";
		} else {
			$queryClassCond = $queryClassCond . ",A";
		}

		if ($queryClassSql == "") {
			$queryClassSql = " CClass like '%A%'";
		} else {
			$queryClassSql = $queryClassSql . " or CClass like '%A%'";
		}
	}

	$chkClassB = $_POST['chkClassB'];
	if ($chkClassB != null && $chkClassB != "") {
		if ($queryClassCond == "") {
			$queryClassCond = "類別 : B";
		} else {
			$queryClassCond = $queryClassCond . ",B";
		}

		if ($queryClassSql == "") {
			$queryClassSql = " CClass like '%B%'";
		} else {
			$queryClassSql = $queryClassSql . " or CClass like '%B%'";
		}
	}

	$chkClassC = $_POST['chkClassC'];
	if ($chkClassC != null && $chkClassC != "") {
		if ($queryClassCond == "") {
			$queryClassCond = "類別 : C";
		} else {
			$queryClassCond = $queryClassCond . ",C";
		}

		if ($queryClassSql == "") {
			$queryClassSql = " CClass like '%C%'";
		} else {
			$queryClassSql = $queryClassSql . " or CClass like '%C%'";
		}
	}

	$chkClassD = $_POST['chkClassD'];
	if ($chkClassD != null && $chkClassD != "") {
		if ($queryClassCond == "") {
			$queryClassCond = "類別 : D";
		} else {
			$queryClassCond = $queryClassCond . ",D";
		}

		if ($queryClassSql == "") {
			$queryClassSql = " CClass like '%D%'";
		} else {
			$queryClassSql = $queryClassSql . " or CClass like '%D%'";
		}
	}


	if ($queryClassCond != "") {
		if ($queryCond == "") {
			$queryCond = $queryClassCond;
		} else {
			$queryCond = $queryCond . "," . $queryClassCond;
		}
	}

	if ($queryClassSql != "") {
		$querySql = $querySql . " And (";
		$querySql = $querySql . $queryClassSql;
		$querySql = $querySql . " )";

		$querySpecSql = $querySpecSql . " And (";
		$querySpecSql = $querySpecSql . $queryClassSql;
		$querySpecSql = $querySpecSql . " )";
	}



	$CMemo = "";
	$queryMemoSql = "";
	$queryMemoSpecSql = "";

	for ($x = 1; $x <= 52; $x++) {
		$tempStr = "";
		if ($x <= 9)
			$tempStr = "0" . $x;
		else
			$tempStr = (string)$x;
		$chk01 = $_POST['chk' . $tempStr];
		if ($chk01 != null && $chk01 != "") {
			if ($queryMemoSql == "") {
				$queryMemoSql = " CMemo like '%" . $chk01 . "%'";
			} else {
				$queryMemoSql = $queryMemoSql . " or CMemo like '%" . $chk01 . "%'";
			}

			if ($chk01 == "01") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 高價";
				} else {
					$queryMemoCond = $queryMemoCond . ",高價";
				}
			}
			if ($chk01 == "02") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 好客";
				} else {
					$queryMemoCond = $queryMemoCond . ",好客";
				}
			}
			if ($chk01 == "03") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 常客";
				} else {
					$queryMemoCond = $queryMemoCond . ",常客";
				}
			}
			if ($chk01 == "04") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 固定";
				} else {
					$queryMemoCond = $queryMemoCond . ",固定";
				}
			}
			if ($chk01 == "05") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 新人";
				} else {
					$queryMemoCond = $queryMemoCond . ",新人";
				}
			}
			if ($chk01 == "06") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 不挑";
				} else {
					$queryMemoCond = $queryMemoCond . ",不挑";
				}
			}
			if ($chk01 == "07") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 年輕";
				} else {
					$queryMemoCond = $queryMemoCond . ",年輕";
				}
			}
			if ($chk01 == "08") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 臉蛋";
				} else {
					$queryMemoCond = $queryMemoCond . ",臉蛋";
				}
			}

			if ($chk01 == "09") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 學生";
				} else {
					$queryMemoCond = $queryMemoCond . ",學生";
				}
			}

			if ($chk01 == "10") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 高挑";
				} else {
					$queryMemoCond = $queryMemoCond . ",高挑";
				}
			}

			if ($chk01 == "11") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 骨感";
				} else {
					$queryMemoCond = $queryMemoCond . ",骨感";
				}
			}

			if ($chk01 == "12") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 美腿";
				} else {
					$queryMemoCond = $queryMemoCond . ",美腿";
				}
			}

			if ($chk01 == "13") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 氣質";
				} else {
					$queryMemoCond = $queryMemoCond . ",氣質";
				}
			}

			if ($chk01 == "14") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 清純";
				} else {
					$queryMemoCond = $queryMemoCond . ",清純";
				}
			}

			if ($chk01 == "15") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 可愛";
				} else {
					$queryMemoCond = $queryMemoCond . ",可愛";
				}
			}

			if ($chk01 == "16") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : OL";
				} else {
					$queryMemoCond = $queryMemoCond . ",OL";
				}
			}

			if ($chk01 == "17") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 大奶";
				} else {
					$queryMemoCond = $queryMemoCond . ",大奶";
				}
			}

			if ($chk01 == "18") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 要LG";
				} else {
					$queryMemoCond = $queryMemoCond . ",要LG";
				}
			}

			if ($chk01 == "19") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 無套BJ";
				} else {
					$queryMemoCond = $queryMemoCond . ",無套BJ";
				}
			}

			if ($chk01 == "20") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 主動";
				} else {
					$queryMemoCond = $queryMemoCond . ",主動";
				}
			}

			if ($chk01 == "21") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 不傳";
				} else {
					$queryMemoCond = $queryMemoCond . ",不傳";
				}
			}

			if ($chk01 == "22") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 很挑";
				} else {
					$queryMemoCond = $queryMemoCond . ",很挑";
				}
			}

			if ($chk01 == "23") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 無套做";
				} else {
					$queryMemoCond = $queryMemoCond . ",無套做";
				}
			}

			if ($chk01 == "24") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 絲襪";
				} else {
					$queryMemoCond = $queryMemoCond . ",絲襪";
				}
			}

			if ($chk01 == "25") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 不抽菸";
				} else {
					$queryMemoCond = $queryMemoCond . ",不抽菸";
				}
			}

			if ($chk01 == "26") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 熟女";
				} else {
					$queryMemoCond = $queryMemoCond . ",熟女";
				}
			}

			if ($chk01 == "27") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 服務好";
				} else {
					$queryMemoCond = $queryMemoCond . ",服務好";
				}
			}

			if ($chk01 == "28") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 膚白";
				} else {
					$queryMemoCond = $queryMemoCond . ",膚白";
				}
			}

			if ($chk01 == "29") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 加節";
				} else {
					$queryMemoCond = $queryMemoCond . ",加節";
				}
			}

			if ($chk01 == "30") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 嬌小";
				} else {
					$queryMemoCond = $queryMemoCond . ",嬌小";
				}
			}

			if ($chk01 == "31") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 漂亮";
				} else {
					$queryMemoCond = $queryMemoCond . ",漂亮";
				}
			}

			if ($chk01 == "32") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 要求高";
				} else {
					$queryMemoCond = $queryMemoCond . ",要求高";
				}
			}

			if ($chk01 == "33") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 注重身材";
				} else {
					$queryMemoCond = $queryMemoCond . ",注重身材";
				}
			}

			if ($chk01 == "34") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 女友FU";
				} else {
					$queryMemoCond = $queryMemoCond . ",女友FU";
				}
			}

			if ($chk01 == "35") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 無刺青";
				} else {
					$queryMemoCond = $queryMemoCond . ",無刺青";
				}
			}

			if ($chk01 == "36") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 長髮";
				} else {
					$queryMemoCond = $queryMemoCond . ",長髮";
				}
			}

			if ($chk01 == "37") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 大眼";
				} else {
					$queryMemoCond = $queryMemoCond . ",大眼";
				}
			}

			if ($chk01 == "38") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 活潑";
				} else {
					$queryMemoCond = $queryMemoCond . ",活潑";
				}
			}

			if ($chk01 == "39") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 兼職型";
				} else {
					$queryMemoCond = $queryMemoCond . ",兼職型";
				}
			}

			if ($chk01 == "40") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 不要大陸";
				} else {
					$queryMemoCond = $queryMemoCond . ",不要大陸";
				}
			}

			if ($chk01 == "41") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 要大陸";
				} else {
					$queryMemoCond = $queryMemoCond . ",要大陸";
				}
			}

			if ($chk01 == "42") {
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 要外國人";
				} else {
					$queryMemoCond = $queryMemoCond . ",要外國人";
				}
			}

			if ($chk01 == "43") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 奧客";
				} else {
					$queryMemoCond = $queryMemoCond . ",奧客";
				}
			}

			if ($chk01 == "44") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 注意";
				} else {
					$queryMemoCond = $queryMemoCond . ",注意";
				}
			}

			if ($chk01 == "45") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 空號";
				} else {
					$queryMemoCond = $queryMemoCond . ",空號";
				}
			}

			if ($chk01 == "46") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 危險";
				} else {
					$queryMemoCond = $queryMemoCond . ",危險";
				}
			}

			if ($chk01 == "47") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 問題";
				} else {
					$queryMemoCond = $queryMemoCond . ",問題";
				}
			}

			if ($chk01 == "48") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 俄羅斯";
				} else {
					$queryMemoCond = $queryMemoCond . ",俄羅斯";
				}
			}

			if ($chk01 == "49") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 按摩";
				} else {
					$queryMemoCond = $queryMemoCond . ",按摩";
				}
			}

			if ($chk01 == "50") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 半套";
				} else {
					$queryMemoCond = $queryMemoCond . ",半套";
				}
			}

			if ($chk01 == "51") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 全套";
				} else {
					$queryMemoCond = $queryMemoCond . ",半套";
				}
			}

			if ($chk01 == "52") {
				if ($queryMemoSpecSql == "") {
					$queryMemoSpecSql = " CMemo like '%" . $chk01 . "%'";
				} else {
					$queryMemoSpecSql = $queryMemoSpecSql . " or CMemo like '%" . $chk01 . "%'";
				}
				if ($queryMemoCond == "") {
					$queryMemoCond = "喜好/備註 : 工作室";
				} else {
					$queryMemoCond = $queryMemoCond . ",半套";
				}
			}
		}
	}

	if ($queryCond == "") {
		$queryCond = $queryMemoCond;
	} else {
		$queryCond = $queryCond . "," . $queryMemoCond;
	}

	if ($queryMemoSql != "") {
		$querySql = $querySql . " And (";
		$querySql = $querySql . $queryMemoSql;
		$querySql = $querySql . " )";
	}

	if ($queryMemoSpecSql != "") {
		$querySpecSql = $querySpecSql . " And (";
		$querySpecSql = $querySpecSql . $queryMemoSpecSql;
		$querySpecSql = $querySpecSql . " )";
	}

	if ($_SESSION['rightLevel'] == "0") {
		$querySql = $querySql . " and CCreateAcc = AId)";
	} elseif ($_SESSION['rightLevel'] == "1" || $_SESSION['rightLevel'] == "2") {
		$querySql = $querySql . " and CCreateAcc = AId And AId in (select AId from AdminUser where AFlag = '1' and AGroupId = " . $_SESSION['groupId'] . "))";
	} //elseif ($_SESSION['rightLevel'] == "2") {
	//	$querySql = $querySql . " and CCreateAcc = AId And CCreateAcc = '" . $_SESSION['userId'] . "')";
	//}
	if ($queryMemoSpecSql != "") {
		$querySpecSql = $querySpecSql . " and CCreateAcc = AId And AId in (select AId from AdminUser where AFlag = '1' and AGroupId = " . $_SESSION['groupId'] . "))";
		$querySql = $querySql . " or " . $querySpecSql;
	} else {
		$queryMemoSpecSql = " CMemo like '%43%' or CMemo like '%44%' or CMemo like '%45%' or CMemo like '%46%' or CMemo like '%47%'";
		$querySpecSql = $querySpecSql . " And (";
		$querySpecSql = $querySpecSql . $queryMemoSpecSql;
		$querySpecSql = $querySpecSql . " )";
		$querySpecSql = $querySpecSql . " and CCreateAcc = AId And AId in (select AId from AdminUser where AFlag = '1' and AGroupId = " . $_SESSION['groupId'] . "))";
		$querySql = $querySql . " or " . $querySpecSql;
	}
	$querySql = $querySql . " order by CCreateDateTime desc";

	$_SESSION['QuerySql'] = $querySql;
	$_SESSION['QueryCond'] = $queryCond;
	$_SESSION['QueryTel'] = $CQueryTel;

	if (strlen($CQueryTel) >= 8) {
		//判斷查詢次數
		$id = $_SESSION['userId'];
		$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
		$db->query("SELECT * FROM AdminUser where AId = '" . $db->mysql_real_escape_string($id) . "'");
		$row = $db->fetch_row();
		$AUserName = $row[1];
		$AHourExTimes = $row[17];
		$ADayExTimes = $row[18];
		$AHourNowTimes = $row[20];
		$AHourTime = $row[21];
		$ADayNowTimes = $row[22];
		$ADayTime = $row[23];
		$db->close_db();
		if ($AHourTime == null || $AHourTime == "") {
			$AHourTime = date("Y-m-d H:i:s");
		}
		if ($ADayNowTimes == null || $ADayNowTimes == "") {
			$ADayNowTimes = date("Y-m-d H:i:s");
		}

		//先抓最新小時登記時間 則取出最新小時登記時間 的最初時間和最後時間
		//比如 現在抓到最後小時登記時間為 2024/05/23 13:10:10  則最初時間 2024/05/23 13:00:00 最後時間 2024/05/23 13:59:59
		//抓取現在時間  
		//若是在最初時間和最後時間中間 則現時查詢次數+1 = 現時查詢次數
		//若不是在最初時間和最後時間中間 則更新現時查詢次數為0 及最新小時登記時間
		//若現時查詢次數 超過 小時查詢次數上限 則發送EMAIL  更新現時查詢次數為0 及最新小時登記時間
		//若現時查詢次數 未超過 小時查詢次數上限 更新現時查詢次數為現時查詢次數 及最新小時登記時間

		if ($AHourExTimes != -1) {
			$AHourTime_Date = strtotime($AHourTime);
			$AHourTime_Start = date("Y-m-d H", $AHourTime_Date) . ":00:00";
			$AHourTime_End = date("Y-m-d H", $AHourTime_Date) . ":59:59";
			//抓出現在時間
			$today = date("Y-m-d H:i:s");
			if (strtotime($today) >= strtotime($AHourTime_Start) && strtotime($today) <= strtotime($AHourTime_End)) {
				//現在查詢時間和最新小時登記時間在同一個小時段
				//現時查詢次數+1
				$AHourNowTimes = $AHourNowTimes + 1;
				//若$AHourTime 超過 時查詢限制次數
				if ($AHourNowTimes > $AHourExTimes) {
					//發送異常Email.....				
					$EX_EMAIL1 = "";
					$EX_EMAIL2 = "";
					$EX_EMAIL3 = "";

					$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
					$db->query("SELECT SValue FROM SysConfig  where SName = 'EX_EMAIL1'");
					$row = $db->fetch_row();
					$EX_EMAIL1 = $row[0];

					$db->query("SELECT SValue FROM SysConfig  where SName = 'EX_EMAIL2'");
					$row = $db->fetch_row();
					$EX_EMAIL2 = $row[0];

					$db->query("SELECT SValue FROM SysConfig  where SName = 'EX_EMAIL3'");
					$row = $db->fetch_row();
					$EX_EMAIL3 = $row[0];

					$db->close_db();

					$AllEmail = "";
					if (!empty($EX_EMAIL1)) {
						if (empty($AllEmail)) {
							$AllEmail = $EX_EMAIL1;
						} else {
							$AllEmail .= "," . $EX_EMAIL1;
						}
					}
					if (!empty($EX_EMAIL2)) {
						if (empty($EX_EMAIL2)) {
							$AllEmail = $EX_EMAIL2;
						} else {
							$AllEmail .= "," . $EX_EMAIL2;
						}
					}
					if (!empty($EX_EMAIL3)) {
						if (empty($EX_EMAIL3)) {
							$AllEmail = $EX_EMAIL3;
						} else {
							$AllEmail .= "," . $EX_EMAIL3;
						}
					}

					if (!empty($AllEmail)) {
						$mail = new PHPMailer(); // Passing `true` enables exceptions
						try {
							$mail->CharSet = "UTF-8";
							$mail->SMTPDebug = 0; // Enable verbose debug output
							$mail->isSMTP(); // Set mailer to use SMTP
							$mail->Host = "dream-circus.com"; //設定有任何指向主機空間的網址名稱
							$mail->SMTPAuth = true; // Enable SMTP authentication
							$mail->Username = "admin@dream-circus.com"; // 在cPanel新增mail的帳號（需要完整的mail帳號，含@後都要填寫）
							$mail->Password = "Ecom@7172"; //在cPanel新增mail帳號時設定的密碼，請小心是否有空格，空格也算一碼。
							$mail->SMTPSecure = "TLS"; // 寄信時使用TLS/SSL加密，若不需要請改寫：false。
							$mail->Port = 587; // TLS加密的port為587；SSL加密的port為465；若不用TLS/SSL，請改用25
							$mail->setFrom("admin@dream-circus.com", "admin"); // 顯示寄件人Mail帳號，需要與上述設定Mail帳號相同，後面'Tang'是填寫顯示寄件人的名稱。
							if (!empty($EX_EMAIL1)) {
								$mail->addAddress($EX_EMAIL1, "Mail One"); //收件者的Email
							}
							if (!empty($EX_EMAIL2)) {
								$mail->addAddress($EX_EMAIL2, "Mail Two"); //收件者的Email
							}
							if (!empty($EX_EMAIL3)) {
								$mail->addAddress($EX_EMAIL3, "Mail Three"); //收件者的Email
							}
							$mail->isHTML(true); // Set email format to HTML
							$mailContent = "<font size=3>";
							$mailContent .= "姓名 : " . $AUserName ."/"."帳號 : " . $_SESSION['username'] ."/". date("Y/m/d h:i:sa")."超過每(時)上限";
							//$mailContent .= "<br />" . "異常性質 : 在小時時間內查詢次數異常";
							//$mailContent .= "<br />" . "查詢異常次數 : " . $AHourNowTimes;
							//$mailContent .= "<br />" . "查詢限制次數 : " . $AHourExTimes;
							$mailContent .= "</font>";
							$mail->Subject = "異常 : 在小時時間內查詢次數異常"; //信件主旨
							$mail->Body = $mailContent; //信件內容
							$mail->send();
							//echo "Message has been sent";
						} catch (Exception $e) {
							echo "Message could not be sent.";
							echo "Mailer Error: " . $mail->ErrorInfo;
						}
					}
					//現時更新次數為0
					$AHourNowTimes = 0;
				}
			} else {
				//現在查詢時間和最新小時登記時間在不同一個小時段 表示是之前的 則歸0次數
				$AHourNowTimes = 0;
			}
		}

		if ($ADayExTimes != -1) {
			//先抓最新天登記時間 則取出最新天登記時間 的最初時間和最後時間
			//比如 現在抓到最後天登記時間為 2024/05/23 13:10:10  則最初時間 2024/05/23 00:00:00 最後時間 2024/05/23 23:59:59
			//抓取現在時間  若是在最初時間和最後時間 則現天查詢次數+1 = 現天查詢次數
			//若不是在最初時間和最後時間中間 則更新現天查詢次數為0 及最新天登記時間
			//若現天查詢次數 超過 天查詢次數上限 則發送EMAIL  更新天查詢次數為0 及最新天登記時間
			//若現天查詢次數 未超過 天查詢次數上限 更新現天查詢次數為現天查詢次數 及最新天登記時間
			$ADayTime_Date = strtotime($ADayTime);
			$ADayTime_Start = date("Y-m-d", $ADayTime_Date) . " 00:00:00";
			$ADayTime_End = date("Y-m-d", $ADayTime_Date) . " 23:59:59";
			//抓出現在時間
			$today = date("Y-m-d H:i:s");
			if (strtotime($today) >= strtotime($ADayTime_Start) && strtotime($today) <= strtotime($ADayTime_End)) {
				//現在查詢時間和最新天登記時間在同一天
				//現時查詢次數+1
				$ADayNowTimes = $ADayNowTimes + 1;
				//若$AHourTime 超過 天查詢限制次數
				if ($ADayNowTimes > $ADayExTimes) {
					//發送異常Email.....
					//發送異常Email.....				
					$EX_EMAIL1 = "";
					$EX_EMAIL2 = "";
					$EX_EMAIL3 = "";

					$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
					$db->query("SELECT SValue FROM SysConfig  where SName = 'EX_EMAIL1'");
					$row = $db->fetch_row();
					$EX_EMAIL1 = $row[0];

					$db->query("SELECT SValue FROM SysConfig  where SName = 'EX_EMAIL2'");
					$row = $db->fetch_row();
					$EX_EMAIL2 = $row[0];

					$db->query("SELECT SValue FROM SysConfig  where SName = 'EX_EMAIL3'");
					$row = $db->fetch_row();
					$EX_EMAIL3 = $row[0];

					$db->close_db();

					$AllEmail = "";
					if (!empty($EX_EMAIL1)) {
						if (empty($AllEmail)) {
							$AllEmail = $EX_EMAIL1;
						} else {
							$AllEmail .= "," . $EX_EMAIL1;
						}
					}
					if (!empty($EX_EMAIL2)) {
						if (empty($EX_EMAIL2)) {
							$AllEmail = $EX_EMAIL2;
						} else {
							$AllEmail .= "," . $EX_EMAIL2;
						}
					}
					if (!empty($EX_EMAIL3)) {
						if (empty($EX_EMAIL3)) {
							$AllEmail = $EX_EMAIL3;
						} else {
							$AllEmail .= "," . $EX_EMAIL3;
						}
					}

					if (!empty($AllEmail)) {
						$mail = new PHPMailer(); // Passing `true` enables exceptions
						try {
							$mail->CharSet = "UTF-8";
							$mail->SMTPDebug = 0; // Enable verbose debug output
							$mail->isSMTP(); // Set mailer to use SMTP
							$mail->Host = "dream-circus.com"; //設定有任何指向主機空間的網址名稱
							$mail->SMTPAuth = true; // Enable SMTP authentication
							$mail->Username = "admin@dream-circus.com"; // 在cPanel新增mail的帳號（需要完整的mail帳號，含@後都要填寫）
							$mail->Password = "Ecom@7172"; //在cPanel新增mail帳號時設定的密碼，請小心是否有空格，空格也算一碼。
							$mail->SMTPSecure = "TLS"; // 寄信時使用TLS/SSL加密，若不需要請改寫：false。
							$mail->Port = 587; // TLS加密的port為587；SSL加密的port為465；若不用TLS/SSL，請改用25
							$mail->setFrom("admin@dream-circus.com", "admin"); // 顯示寄件人Mail帳號，需要與上述設定Mail帳號相同，後面'Tang'是填寫顯示寄件人的名稱。
							if (!empty($EX_EMAIL1)) {
								$mail->addAddress($EX_EMAIL1, "Mail One"); //收件者的Email
							}
							if (!empty($EX_EMAIL2)) {
								$mail->addAddress($EX_EMAIL2, "Mail Two"); //收件者的Email
							}
							if (!empty($EX_EMAIL3)) {
								$mail->addAddress($EX_EMAIL3, "Mail Three"); //收件者的Email
							}
							$mail->isHTML(true); // Set email format to HTML
							$mailContent = "<font size=3>";
							$mailContent .= "姓名 : " . $AUserName ."/"."帳號 : " . $_SESSION['username'] ."/". date("Y/m/d h:i:sa")."超過每(日)上限";
							//$mailContent .= "<br />" . "異常性質 : 在一天時間內查詢次數異常";
							//$mailContent .= "<br />" . "查詢異常次數 : " . $AHourNowTimes;
							//$mailContent .= "<br />" . "查詢限制次數 : " . $AHourExTimes;
							$mailContent .= "</font>";
							$mail->Subject = "異常 : 在一天時間內查詢次數異常"; //信件主旨						
							$mail->Body = $mailContent; //信件內容
							$mail->send();
							//echo "Message has been sent";
						} catch (Exception $e) {
							echo "Message could not be sent.";
							echo "Mailer Error: " . $mail->ErrorInfo;
						}
					}
					//現時更新次數為0
					$ADayNowTimes = 0;
				}
			} else {
				//現在查詢時間和最新天登記時間在不同一天 表示是之前的 則歸0次數
				$ADayNowTimes = 0;
			}
		}


		//更新
		$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
		$updateSql = "UPDATE AdminUser set AHourNowTimes = " . $AHourNowTimes
			. ",AHourTime = '" . Date('Y-m-d H:i:s') . "'"
			. ",ADayNowTimes = " . $ADayNowTimes
			. ",ADayTime = '" . Date('Y-m-d H:i:s') . "'"
			. " where AId = " . $id;
		$db->query($updateSql);
		$db->close_db();
	}
} else {
	$CQueryTel = $_SESSION['QueryTel'];
	$querySql = $_SESSION['QuerySql'];
	$queryCond = $_SESSION['QueryCond'];
}


$querySqlCount = "select count(*) from Customer,AdminUser " . $querySql;


$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
$db->query($querySqlCount);
$row = $db->fetch_row();
$db->close_db();
$numrows = $row[0];

$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
$querySql1 = "select * from Customer,AdminUser " . $querySql;
$db->query($querySql1);


if ($queryCond == "") {
	$queryCond = "無";
}
?>

<body onload="MM_preloadImages('images/LastPage1.jpg')">
	<form name="form" method="post" action="CustomerInput.php">
		<table border="0" cellspacing="1" cellspadding="1" width="100%">
			<tr>
				<td align="left" colspan="2">
					<span class="t12"><b>查詢條件 : <?php echo $queryCond; ?></b></span>
				</td>
			</tr>
			<tr>
				<td align="center" colspan="2">
					&nbsp;
				</td>
			</tr>
			<tr>
				<td align="left">
					<span class="t12b"><b>
							<?php echo "總共" . $numrows . "筆資料"; ?></b></span>
				</td>
				<td align="right">
					<?php
					if (($_SESSION['rightLevel'] == "0" && (str_indexof($_SESSION['rights'], "B1I") >= 0)) ||
						($_SESSION['rightLevel'] == "1" && (str_indexof($_SESSION['rights'], "B1I") >= 0)) ||
						($_SESSION['rightLevel'] == "2" && (str_indexof($_SESSION['userRights'], "I") >= 0))
					) {
					?>
						<input type="button" name="btnAdd" id="btnAdd" value="新     增" class="t12" onclick="MM_openBrWindow('CustomerQueryIndex1.php?AddTel=<?php echo $CQueryTel; ?>','AddWin',600,500)" style="WIDTH:150px;Height:30px;" />
					<?php
					}
					?>
					&nbsp;
					<a href="javascript:location.href='CustomerQueryEasyInputW.php';">
						<img src="images/LastPage1.jpg" ID="ImgLogIn" width="118" height="25" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('ImgLogIn','','images/LastPage2.jpg',1)">
					</a>
				</td>
			</tr>
			<tr>
				<td align="left" colspan="2" width="100%">
					<?php
					if ($myrow = $db->fetch_array()) {
						$i = 0;
					?>
						<table width="100%" border="1" cellspacing="2" cellpadding="2">
							<tr>
								<?php if ($_SESSION['username'] == "admin") { ?>
									<td width="8%" bgcolor="#E1E9FB" align="center"><span class="t12r">序號</span></td>
								<?php } ?>
								<td width="32%" bgcolor="#E1E9FB" align="center"><span class="t12r">地區</span></td>
								<td width="32%" bgcolor="#E1E9FB" align="center"><span class="t12r">暱稱/其他</span></td>
								<td width="10%" bgcolor="#E1E9FB" align="center"><span class="t12r">誰的客戶</span></td>
								<td width="6%" bgcolor="#E1E9FB" align="center"><span class="t12r">查看</span></td>
								<td width="6%" bgcolor="#E1E9FB" align="center"><span class="t12r">新增</span></td>
								<td width="6%" bgcolor="#E1E9FB" align="center"><span class="t12r">刪除</span></td>
							</tr>
							<?php
							$index = 0;
							do {
								$i++;
								$CTempArea = "";
								if (str_indexof($myrow['CArea'], "Taipei") >= 0) {
									if ($CTempArea == "") {
										$CTempArea = "台北";
									} else {
										$CTempArea = $CTempArea . " " . "台北";
									}
								}
								if (str_indexof($myrow['CArea'], "Taoyuan") >= 0) {
									if ($CTempArea == "") {
										$CTempArea = "桃園";
									} else {
										$CTempArea = $CTempArea . " " . "桃園";
									}
								}
								if (str_indexof($myrow['CArea'], "Zhongli") >= 0) {
									if ($CTempArea == "") {
										$CTempArea = "中壢";
									} else {
										$CTempArea = $CTempArea . " " . "中壢";
									}
								}
								if (str_indexof($myrow['CArea'], "Hsinchu") >= 0) {
									if ($CTempArea == "") {
										$CTempArea = "新竹";
									} else {
										$CTempArea = $CTempArea . " " . "新竹";
									}
								}
								if (str_indexof($myrow['CArea'], "Taichung") >= 0) {
									if ($CTempArea == "") {
										$CTempArea = "台中";
									} else {
										$CTempArea = $CTempArea . " " . "台中";
									}
								}
								if (str_indexof($myrow['CArea'], "Zhanghua") >= 0) {
									if ($CTempArea == "") {
										$CTempArea = "彰投";
									} else {
										$CTempArea = $CTempArea . " " . "彰投";
									}
								}
								if (str_indexof($myrow['CArea'], "Tainan") >= 0) {
									if ($CTempArea == "") {
										$CTempArea = "台南";
									} else {
										$CTempArea = $CTempArea . " " . "台南";
									}
								}
								if (str_indexof($myrow['CArea'], "Kaohsiung") >= 0) {
									if ($CTempArea == "") {
										$CTempArea = "高雄";
									} else {
										$CTempArea = $CTempArea . " " . "高雄";
									}
								}
								if (str_indexof($myrow['CArea'], "Hualien") >= 0) {
									if ($CTempArea == "") {
										$CTempArea = "花蓮";
									} else {
										$CTempArea = $CTempArea . " " . "花蓮";
									}
								}
								if (str_indexof($myrow['CArea'], "Toufen") >= 0) {
									if ($CTempArea == "") {
										$CTempArea = "頭份";
									} else {
										$CTempArea = $CTempArea . " " . "頭份";
									}
								}
								if ($CTempArea == null || $CTempArea == "") {
									$CTempArea = "&nbsp;";
								}
								$SingleTel = "";
								if ($SingleTel == "" && $myrow['CBlackTel'] != null && $myrow['CBlackTel'] != "") {
									$SingleTel = $myrow['CBlackTel'];
								}
								if ($SingleTel == "" && $myrow['CRedTel'] != null && $myrow['CRedTel'] != "") {
									$SingleTel = $myrow['CRedTel'];
								}
								if ($SingleTel == "" && $myrow['CGreenTel'] != null && $myrow['CGreenTel'] != "") {
									$SingleTel = $myrow['CGreenTel'];
								}
							?>
								<tr>
									<?php if ($_SESSION['username'] == "admin") { ?>
										<td bgcolor="#E6F2FF"><?php if ($_SESSION['username'] == "admin") {
																	echo $myrow['CId'];
																} ?></td>
									<?php } ?>
									<td bgcolor="#E6F2FF">
										<span class="t12">
											<?php echo $CTempArea; ?></span>
									</td>
									<td bgcolor="#E6F2FF">
										<span class="t12">
											<?php echo $myrow['CNickname']; ?></span>
									</td>
									<td bgcolor="#E6F2FF">
										<span class="t12">
											<?php echo $myrow['AName']; ?></span>
									</td>
									<td bgcolor="#E6F2FF" align="center">
										<span class="t12">
											<a href="CustomerQueryResultW.php?id=<?php echo $myrow['CId']; ?>">
												<b>明細</b></a></span>
									</td>
									<td bgcolor="#E6F2FF" align="center">
										<?php
										if (($_SESSION['rightLevel'] == "0" && (str_indexof($_SESSION['rights'], "B1I") >= 0)) ||
											($_SESSION['rightLevel'] == "1" && (str_indexof($_SESSION['rights'], "B1I") >= 0)) ||
											($_SESSION['rightLevel'] == "2" && (str_indexof($_SESSION['userRights'], "I") >= 0))
										) {
										?>
											<span class="t12">
												<a href="javascript:void(0);" onclick="MM_openBrWindow('CustomerQueryIndex1.php?AddTel=<?php echo $SingleTel; ?>','AddWin',600,500)">
													<b>新增</b></a></span>
										<?php
										} else
											echo "&nbsp;";
										?>
									</td>
									<td bgcolor="#E6F2FF" align="center">
										<?php
										if (($_SESSION['rightLevel'] == "0" && (str_indexof($_SESSION['rights'], "B1D") >= 0)) ||
											($_SESSION['rightLevel'] == "1" && (str_indexof($_SESSION['rights'], "B1D") >= 0)) ||
											($_SESSION['rightLevel'] == "2" && (str_indexof($_SESSION['userRights'], "D") >= 0))
										) {
										?>
											<span class="t12">
												<a href="javascript:void(0);" onclick="checkDelete('<?php echo $myrow['CId']; ?>');">
													<b>刪除</b></a></span>
										<?php
										} else
											echo "&nbsp;";
										?>
									</td>
								</tr>
						<?php
							} while ($myrow = $db->fetch_array());
							echo "</table>";
						}
						?>
				</td>
			</tr>
		</table>
	</form>
</body>

</html>