<?php
	require_once "pageBase.php";
	require_once "../dal/registryDAL.php";
	class _iplimitSet extends pageBase {
		public function load() {
			$this->limitID = "62";
			if (!parent::chkUserLimit()) {
				$this->alertMsg = "您沒有使用此頁面的權限!如有疑問請洽主管理者!";
				$this->locationHref = "index.php";
			} else {
				parent::isPostBack() ? $this->saveData() : $this->loadData();
			}
			parent::loadTemplateFile(dirname(__FILE__) . "/templates/iplimitSet.html");
			parent::load();
		}
		
		public function loadData() {
			$webConfig = registryDAL::getRegistryValues();
			foreach ($webConfig as $key => &$value) {
				$value = $value ?? "";
				parent::addParameter($key, $value);
			}
			
			$getappleip = (parent::getCurrentUserID() == "1") ? "<a class=\"mr_2 btn btn_warning\" href=\"/api/getappleip.php\" target=\"_blank\">更新蘋果IP</a>" : "";
			parent::addParameter("getappleip", $getappleip);
			
			parent::loadData();
		}

		public function saveData() {
			$aryR = [
				"ipLimit1" => parent::getPost("ipLimit1"),
				"twipLimit" => parent::getPost("twipLimit"),
				"ipBlackList1" => parent::getPost("ipBlackList1"),
				"ipWhiteList1" => parent::getPost("ipWhiteList1"),
				"ipLimit2" => parent::getPost("ipLimit2"),
				"twipLimit2" => parent::getPost("twipLimit2"),
				"ipBlackList2" => parent::getPost("ipBlackList2"),
				"ipWhiteList2" => parent::getPost("ipWhiteList2"),
				"ModifiedTime" => time(),
			];

			foreach ($aryR as $key => $value) {
				registryDAL::saveRegistry($key, $value);
			}
			$this->alertMsg = "儲存完畢!";
			$this->locationHref = "iplimitSet.php";
		}
	}
	$page = new _iplimitSet();
	$page->load();
	$page->render();
?>