<?php
	require_once "pageBase.php";
	require_once "../dal/registryDAL.php";
	class _market extends pageBase {
		public function load() {
			$this->limitID = "20";
			if (!parent::chkUserLimit()) {
				$this->alertMsg = "您沒有使用此頁面的權限!如有疑問請洽主管理者!";
				$this->locationHref = "index.php";
			} else {
				$this->loadData();
			}
			parent::loadTemplateFile(dirname(__FILE__) . "/templates/market.html");
			parent::load();
		}
		
		public function loadData() {
			if (!isset($_SESSION["marketLink"])) {
				$url = "https://tp60.appleseotw.com/apple/vault/market/show";
				$ch = curl_init();
				curl_setopt_array($ch, [
					CURLOPT_URL => $url,
					CURLOPT_SSL_VERIFYPEER => false,
					CURLOPT_SSL_VERIFYHOST => 1,
					CURLOPT_HEADER => false,
					CURLOPT_RETURNTRANSFER => 1
				]);
				$result = curl_exec($ch);
				curl_close($ch);
	
				$aryJ = json_decode($result);
	
				if ($aryJ->status == 0) {
					$_SESSION["marketName"] = $aryJ->marketName;
					$_SESSION["marketLink"] = $aryJ->marketLink;
				} else {
					$this->alertMsg = $aryJ->message;
					$this->locationHref = "index.php";
				}
			}

			parent::addParameter("marketName", $_SESSION["marketName"]);
			parent::addParameter("marketLink", $_SESSION["marketLink"]);
			
			parent::loadData();
		}
	}
	$page = new _market();
	$page->load();
	$page->render();
?>