<?php
	require_once "pageBase.php";
	require_once "../dal/registryDAL.php";
	class _youtubeSet extends pageBase {
		public function load() {
			$this->limitID = "68";
			if (!parent::chkUserLimit()) {
				$this->alertMsg = "您沒有使用此頁面的權限!如有疑問請洽主管理者!";
				$this->locationHref = "index.php";
			} else {
				parent::isPostBack() ? $this->saveData() : $this->loadData();
			}
			parent::loadTemplateFile(dirname(__FILE__) . "/templates/youtubeSet.html");
			parent::load();
		}
		
		public function loadData() {
			$webConfig = registryDAL::getRegistryValues();
			foreach ($webConfig as $key => &$value) {
				$value = $value ?? "";
				parent::addParameter($key, $value);
			}
			parent::loadData();
		}
		
		public function saveData() {
			$aryYS = parent::getPostArray("youtubeSidePageShow");
			$aryR = [
				"youtubeURL" => parent::getPost("youtubeURL"),
				"youtubeSidePageShow" => $aryYS !== null ? implode(",", $aryYS) : "",
				"youtubeType" => parent::getPost("youtubeType","0"),
				"youtubeIndex" => parent::getPost("youtubeIndex","0"),
				"youtubeRel" => parent::getPost("youtubeRel", "0"),
				"youtubeAutoPlay" => parent::getPost("youtubeAutoPlay", "0"),
				"youtubeMute" => parent::getPost("youtubeMute", "0"),
				"youtubeLoop" => parent::getPost("youtubeLoop", "0"),
				"ModifiedTime" => time(),
			];
			
			foreach ($aryR as $key => $value) {
				registryDAL::saveRegistry($key, $value);
			}

			$this->alertMsg = "儲存完畢!";
			$this->locationHref = "youtubeSet.php";
		}
	}
	$page = new _youtubeSet();
	$page->load();
	$page->render();
?>