<?php
	require_once "pageBase.php";
	require_once "dal/areaDAL.php";
	require_once "dal/cityDAL.php";
	class _new_member1 extends pageBase {
		public function load() {
			if ($this->registry->isCustomer == 0) {
				header("Location: /404.php");
				exit();
			}

			$this->loadData();
			parent::loadTemplateFile("templates/{$this->registry->webTemplates}/new_member1.html");
			parent::load();
		}

		public function loadData() {
			//橫幅廣告
			$this->picturetype = "130";

			/* 縣市、地區 */
			$dalC = new cityDAL();
			$dalA = new areaDAL();
			$aryJ = [];

			$dataC = $dalC->executeRecordset([], "a.`Visible`=1");
			foreach ($dataC as $rows) {
				$aryA = [];
				$intoAry = [parent::addArray(":cityID", $rows["CityID"], "int")];
				$dataA = $dalA->executeRecordset($intoAry, "a.`CityID`=:cityID AND a.`Visible`=1");
				foreach ($dataA as $rows2) {
					$aryA[] = ["AreaID" => $rows2["AreaID"], "ZipCode" => $rows2["ZipCode"], "AreaName" => urlencode($rows2["AreaName"])];
				}
				$aryJ[] = ["CityID" => $rows["CityID"], "CityName" => urlencode($rows["CityName"]), "aryA" => $aryA];
			}
			$txtJ = urldecode(json_encode($aryJ));
			parent::addParameter("txtJ", $txtJ);
			
			// 會員相關數據設定
			$sessionData = [
				"email", "pass", "nick", "name", "sex",
				"mobile", "city", "area", "address", "phone", "line"
			];
			foreach ($sessionData as $dataKey) {
				$sessionValue = isset($_SESSION["newmember_" . $dataKey]) ? $_SESSION["newmember_" . $dataKey] : "";
				parent::addParameter($dataKey, $sessionValue);
			}
			
			parent::loadData();
		}
	}

	$page = new _new_member1();
	$page->load();
	$page->render();
?>