<?php
	require_once "pageBase.php";
	require_once "../bin/web/repeater.php";
	require_once "../dal/templateDAL.php";

	class _templateList extends pageBase {
		public function load() {
			$this->limitID = "53";
			if (!parent::chkUserLimit()) {
				$this->alertMsg = "您沒有使用此頁面的權限!如有疑問請洽主管理者!";
				$this->locationHref = "index.php";
			} else {
				$this->loadData();
			}
			parent::loadTemplateFile(dirname(__FILE__) . "/templates/templateList.html");
			parent::load();
		}
		
		public function loadData() {
			/* 宣告&參數 */
			$dal = new templateDAL();
			$data = $dal->executeRecordset();
			
			$url = "https://tp60.appleseotw.com/apple/vault/template/list";
			$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);
			$data2 = [];
			foreach ($aryJ->aryT as $rows) {
				$flag = 0;
				foreach ($data as $rows2) {
					if ($rows->Path == $rows2["PathName"]) {
						$flag++;
						break;
					}
				}
				if ($flag === 0) $data2[] = [ "Name" => $rows->Name, "Path" => $rows->Path, "Image" => $rows->Image, "File" => $rows->File, "Web" => $rows->Web ];
			}
			$list2 = new repeater();
			$list2->id = "list2";
			$list2->dataSource = $data2;
			parent::addControl($list2);

			parent::loadData();
		}
	}

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