<?php
	require_once "pageBase.php";
	require_once "../bin/system/conver.php";
	require_once "../dal/registryDAL.php";
	class _contactSet extends pageBase {
		public function load() {
			$this->limitID = "27";
			if (!parent::chkUserLimit()) {
				$this->alertMsg = "您沒有使用此頁面的權限!如有疑問請洽主管理者!";
				$this->locationHref = "index.php";
			} else {
				parent::isPostBack() ? $this->saveData() : $this->loadData();
			}
			parent::loadTemplateFile(dirname(__FILE__) . "/templates/contactSet.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() {
			$arySN = parent::getPostArray("sideNavShow");
			$aryR = [
				"sideNavShow" => (isset($arySN)) ? implode(",", $arySN) : "",
				"ContactName" => parent::getPost("ContactName", ""),
				"webContact" => parent::getPost("webContact", "", 2),
				"ModifiedTime" => time(),
			];
			
			foreach ($aryR as $key => $value) {
				registryDAL::saveRegistry($key, $value);
			}
			
			$this->alertMsg = "儲存完畢!";
			$this->locationHref = "contactSet.php";
		}
	}

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