<?php
	require_once "pageBase.php";
	require_once "../bin/system/conver.php";
	require_once "../dal/registryDAL.php";
	require_once "../bin/web/repeater.php";
	class _outsideSet extends pageBase{
		//覆蓋父類load()方法
		public function load(){
			if(!parent::chkUserLimit('43')){
				parent::alert2('您沒有使用此頁面的權限!如有疑問請洽主管理者!','index.php');
				exit;
			}

			if(!parent::isPostBack())
				$this->loadData();
			else
				$this->saveData();

			parent::load();
		}
		public function loadData(){
			$lineTitle = registryDAL::getRegistryValue("lineTitle");
			$lineQRCode = registryDAL::getRegistryValue("lineQRCode");

			$fbFansURL = registryDAL::getRegistryValue("fbFansURL");
			$fbFansFriendFace = registryDAL::getRegistryValue("fbFansFriendFace");
			$fbFansCoverPhoto = registryDAL::getRegistryValue("fbFansCoverPhoto");
			$fbFansPagePost = registryDAL::getRegistryValue("fbFansPagePost");
			$fbFansSidePageShow = registryDAL::getRegistryValue("fbFansSidePageShow");
			$fbFansSidePageType = registryDAL::getRegistryValue("fbFansSidePageType");
			$fbFansLOGO = registryDAL::getRegistryValue("fbFansLOGO");

			$googlemapAddress = registryDAL::getRegistryValue("googlemapAddress");
			$googlemapIndex = registryDAL::getRegistryValue("googlemapIndex");
			$googlemapSidePageShow = registryDAL::getRegistryValue("googlemapSidePageShow");
			$googlemapMain = registryDAL::getRegistryValue("googlemapMain");

			$youtubeURL = registryDAL::getRegistryValue("youtubeURL");
			$youtubeSidePageShow = registryDAL::getRegistryValue("youtubeSidePageShow");

			$headHTML = registryDAL::getRegistryValue("headHTML");
			$bodyTopHTML = registryDAL::getRegistryValue("bodyTopHTML");

			parent::addParameter("lineTitle",$lineTitle);
			parent::addParameter("lineQRCode",$lineQRCode);
			parent::addParameter("fbFansURL",$fbFansURL);
			parent::addParameter("fbFansFriendFace",$fbFansFriendFace);
			parent::addParameter("fbFansCoverPhoto",$fbFansCoverPhoto);
			parent::addParameter("fbFansPagePost",$fbFansPagePost);
			parent::addParameter("fbFansSidePageType",$fbFansSidePageType);
			parent::addParameter("fbFansLOGO",$fbFansLOGO);
			parent::addParameter("googlemapAddress",$googlemapAddress);
			parent::addParameter("googlemapIndex",$googlemapIndex);
			//parent::addParameter("googlemapSidePage",$googlemapSidePage);
			parent::addParameter("googlemapMain",$googlemapMain);
			parent::addParameter("youtubeURL",$youtubeURL);
			//parent::addParameter("youtubeSidePage",$youtubeSidePage);
			parent::addParameter("headHTML",$headHTML);
			parent::addParameter("bodyTopHTML",$bodyTopHTML);

			$aryPS = explode(",",$fbFansSidePageShow);
			$dataPS = array();
			foreach($aryPS as $value){
				$dataPS[]["Value"] = $value;
			}
			$listPS = new repeater();
			$listPS->id = "listPS";
			$listPS->dataSource = $dataPS;
			parent::addControl($listPS);

			$aryGMSPS = explode(",",$googlemapSidePageShow);
			$dataGMSPS = array();
			foreach($aryGMSPS as $value){
				$dataGMSPS[]["Value"] = $value;
			}
			$listGMSPS = new repeater();
			$listGMSPS->id = "listGMSPS";
			$listGMSPS->dataSource = $dataGMSPS;
			parent::addControl($listGMSPS);

			$aryYSPS = explode(",",$youtubeSidePageShow);
			$dataYSPS = array();
			foreach($aryYSPS as $value){
				$dataYSPS[]["Value"] = $value;
			}
			$listYSPS = new repeater();
			$listYSPS->id = "listYSPS";
			$listYSPS->dataSource = $dataYSPS;
			parent::addControl($listYSPS);

			parent::loadTemplateFile(dirname(__FILE__)."/templates/outsideSet.html");
			parent::loadData();
		}
		public function saveData(){
			$lineTitle = conver::toDbString(trim($_POST["lineTitle"]));
			$lineQRCode = conver::toDbString(trim($_POST["lineQRCode"]));
			$fbFansURL = conver::toDbString(trim($_POST["fbFansURL"]));
			$fbFansFriendFace = conver::toDbString(trim($_POST["fbFansFriendFace"]));
			$fbFansCoverPhoto = conver::toDbString(trim($_POST["fbFansCoverPhoto"]));
			$fbFansPagePost = conver::toDbString(trim($_POST["fbFansPagePost"]));
			$aryPS = $_POST["fbFansSidePageShow"];
			if(isset($aryPS)){
				$fbFansSidePageShow = implode(",",$aryPS);
			}else{
				$fbFansSidePageShow = "";
			}
			$fbFansSidePageType = conver::toDbString(trim($_POST["fbFansSidePageType"]));
			$fbFansLOGO = conver::toDbString(trim($_POST["fbFansLOGO"]));
			$googlemapAddress = conver::toDbString(trim($_POST["googlemapAddress"]));
			$googlemapIndex = conver::toDbString(trim($_POST["googlemapIndex"]));
			//$googlemapSidePage = conver::toDbString(trim($_POST["googlemapSidePage"]));
			$aryGMSPS = $_POST["googlemapSidePageShow"];
			if(isset($aryGMSPS)){
				$googlemapSidePageShow = implode(",",$aryGMSPS);
			}else{
				$googlemapSidePageShow = "";
			}
			$googlemapMain = conver::toDbString(trim($_POST["googlemapMain"]));
			$youtubeURL = conver::toDbString(trim($_POST["youtubeURL"]));
			//$youtubeSidePage = conver::toDbString(trim($_POST["youtubeSidePage"]));
			$aryYSPS = $_POST["youtubeSidePageShow"];
			if(isset($aryYSPS)){
				$youtubeSidePageShow = implode(",",$aryYSPS);
			}else{
				$youtubeSidePageShow = "";
			}
			$headHTML = trim($_POST["headHTML"]);
			$headHTML = str_replace("'","\"",$headHTML);
			$bodyTopHTML = trim($_POST["bodyTopHTML"]);
			$bodyTopHTML = str_replace("'","\"",$bodyTopHTML);
			registryDAL::saveRegistry("lineTitle",$lineTitle);
			registryDAL::saveRegistry("lineQRCode",$lineQRCode);
			registryDAL::saveRegistry("fbFansURL",$fbFansURL);
			registryDAL::saveRegistry("fbFansFriendFace",$fbFansFriendFace);
			registryDAL::saveRegistry("fbFansCoverPhoto",$fbFansCoverPhoto);
			registryDAL::saveRegistry("fbFansPagePost",$fbFansPagePost);
			registryDAL::saveRegistry("fbFansSidePageShow",$fbFansSidePageShow);
			registryDAL::saveRegistry("fbFansSidePageType",$fbFansSidePageType);
			registryDAL::saveRegistry("fbFansLOGO",$fbFansLOGO);
			registryDAL::saveRegistry("googlemapAddress",$googlemapAddress);
			registryDAL::saveRegistry("googlemapIndex",$googlemapIndex);
			registryDAL::saveRegistry("googlemapSidePageShow",$googlemapSidePageShow);
			registryDAL::saveRegistry("googlemapMain",$googlemapMain);
			registryDAL::saveRegistry("youtubeURL",$youtubeURL);
			registryDAL::saveRegistry("youtubeSidePageShow",$youtubeSidePageShow);
			registryDAL::saveRegistry("headHTML",$headHTML);
			registryDAL::saveRegistry("bodyTopHTML",$bodyTopHTML);
			parent::alert2("儲存完畢!","outsideSet.php");
		}
	}

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