<?php
	require_once dirname(__FILE__)."/../bin/web/repeater.php";
	require_once dirname(__FILE__)."/../dal/book_categoryDAL.php";
	require_once dirname(__FILE__)."/../dal/categoryDAL.php";
	require_once dirname(__FILE__)."/../dal/faq_categoryDAL.php";
	require_once dirname(__FILE__)."/../dal/htaccessDAL.php";
	require_once dirname(__FILE__)."/../dal/news_categoryDAL.php";
	require_once dirname(__FILE__)."/../dal/pictureDAL.php";
	require_once dirname(__FILE__)."/../dal/webmenuDAL.php";

	class _header extends webPartBase{
		public $is_index = false;
		public $picturetype = 30;
		public $NoPicImage;
		public $pwk;

		public function load(){
			$this->loadData();
			parent::load();
		}
		public function loadData(){
			if(isset($_SESSION["CustomerID"])){
				parent::addParameter("topMenu1","<a class='login' href='memberlogout.html'>登出</a>");
				parent::addParameter("topMenu2","");
				parent::addParameter("topMenu3","Hello, &nbsp; &nbsp;".$_SESSION["CustomerName"]." &nbsp; &nbsp;︳");
			}else{
				parent::addParameter("topMenu1","<a class='login' href='memberlogin.html'>登入</a>");
				parent::addParameter("topMenu2","<a class='member' href='newmember.html'>註冊</a>");
				parent::addParameter("topMenu3","");
			}

			//網站H1
			parent::addParameter("webH1",$this->registry->webH1);
			parent::addParameter("webTitle",$this->registry->webTitle);
			parent::addParameter("webKeyword",$this->registry->webKeyword);
			parent::addParameter("webMarquee",$this->registry->webMarquee);
			parent::addParameter("webPhone",$this->registry->webPhone);
			parent::addParameter("webEmail",$this->registry->webEmail);
			parent::addParameter("webName",$this->registry->webName);
			parent::addParameter("googlemapAddress",urlencode($this->registry->googlemapAddress));
			if($this->registry->webJumpType != "0"){
				parent::addParameter("headerStyle","  style='position: relative !important;'");
				parent::addParameter("headerTop","");
			}else{
				parent::addParameter("headerTop","headerTop");
			}

			////logo
			$dalP = new pictureDAL();
			$dalP->PictureType = "10";
			$dalP->TypeOrderNO = "0";
			$dalP->loadRecord();
			if(trim($dalP->Image) == ''){
				parent::addParameter("logoImage",$this->NoPicImage);
				parent::addParameter("logoStyle"," style='display:none; width: auto;'");
			}else{
				if(file_exists(".".$dalP->Image)){
					parent::addParameter("logoImage",$dalP->Image);
					parent::addParameter("logoStyle","");
				}else{
					parent::addParameter("logoImage",$this->NoPicImage);
					parent::addParameter("logoStyle"," style='display:none; width: auto;'");
				}
			}
			if(trim($dalP->Title) == ''){
				parent::addParameter("logoTitle",$this->registry->webName);
			}else{
				parent::addParameter("logoTitle",$dalP->Title);
			}
			if(trim($dalP->Link) == ''){
				parent::addParameter("logoLink","/");
			}else{
				parent::addParameter("logoLink",$dalP->Link);
			}

			//網頁網址設定
			$dalH = new htaccessDAL();
			$dalH->ID = "1";
			$dalH->loadRecord();
			$htLink1 = $dalH->HtmlName;
			$dalH->ID = "2";
			$dalH->loadRecord();
			$htLink2 = $dalH->HtmlName;
			$dalH->ID = "3";
			$dalH->loadRecord();
			$htLink3 = $dalH->HtmlName;
			$dalH->ID = "4";
			$dalH->loadRecord();
			$htLink4 = $dalH->HtmlName;
			$dalH->ID = "5";
			$dalH->loadRecord();
			$htLink5 = $dalH->HtmlName;
			$dalH->ID = "6";
			$dalH->loadRecord();
			$htLink6 = $dalH->HtmlName;
			$dalH->ID = "7";
			$dalH->loadRecord();
			$htLink7 = $dalH->HtmlName;
			parent::addParameter("actionLink",$htLink4);


			//主選單
			$dalWM = new webmenuDAL();
			$dalC = new categoryDAL();
			$dalNC = new news_categoryDAL();
			$dalFC = new faq_categoryDAL();
			$dalBC = new book_categoryDAL();
			$dataWM = $dalWM->executeRecordset("a.`Visible`='1'");
			for($i=0;$i<count($dataWM);$i++){
				$dataWM[$i]["MenuID"] = $dataWM[$i]["MenuID"];
				if($i == 4){
					$dataWM[$i]["className"] = " class='newsLink'";
				}else if($i == 7){
					$dataWM[$i]["className"] = " class='last'";
				}
				switch($dataWM[$i]["MenuType"]){
					case "0":
						$dataWM[$i]["htLink"] = $htLink1;
						$dataWM[$i]["SubList"] = "";
						break;
					case "1":
						$dataWM[$i]["htLink"] = $htLink4;
						if($dataWM[$i]["SubMenu"] == "0"){
							$dataWM[$i]["SubList"] = "";
						}else{
							$dataC = $dalC->executeRecordset("a.`ParentID`='0' AND a.`Visible`='1'");
							for($j=0;$j<count($dataC);$j++){
								$dataSC = $dalC->executeRecordset("a.`ParentID`='".$dataC[$j]["CategoryID"]."' AND a.`Visible`='1'");
								if(count($dataSC) == 0){
									$dataWM[$i]["SubList"] .= "<li";
									if($j == (count($dataC) - 1)){
										$dataWM[$i]["SubList"] .= " class='last'";
									}
									$dataWM[$i]["SubList"] .= "><a href='".$htLink4.$dataC[$j]["CategoryID"].".html'>".$dataC[$j]["CategoryName"]."</a></li>";
								}else{
									$dataWM[$i]["SubList"] .= "<li";
									if($j == (count($dataC) - 1)){
										$dataWM[$i]["SubList"] .= " class='last'";
									}
									$dataWM[$i]["SubList"] .= "><p>".$dataC[$j]["CategoryName"]."</p><ul class='subOption'>";
									for($k=0;$k<count($dataSC);$k++){
										$dataWM[$i]["SubList"] .= "<li";
										if($k == (count($dataSC) - 1)){
											$dataWM[$i]["SubList"] .= " class='last'";
										}
										$dataWM[$i]["SubList"] .= "><a href='".$htLink4.$dataSC[$k]["CategoryID"].".html'>".$dataSC[$k]["CategoryName"]."</a></li>";
									}
									$dataWM[$i]["SubList"] .= "</ul></li>";
								}
							}
						}
						break;
					case "2":
						$dataWM[$i]["htLink"] = $htLink2;
						
						if($dataWM[$i]["SubMenu"] == "0"){
							$dataWM[$i]["SubList"] = "";
						}else{
							$dataNC = $dalNC->executeRecordset("a.`Visible`='1'");
							for($j=0;$j<count($dataNC);$j++){
								$dataWM[$i]["SubList"] .= "<li";
								if($j == (count($dataNC) - 1)){
									$dataWM[$i]["SubList"] .= " class='last'";
								}
								$dataWM[$i]["SubList"] .= "><a href='".$htLink2.$dataNC[$j]["CategoryID"].".html'>".$dataNC[$j]["CategoryName"]."</a></li>";
							}
						}
						break;
					case "3":
						$dataWM[$i]["htLink"] = $htLink3;
						if($dataWM[$i]["SubMenu"] == "0"){
							$dataWM[$i]["SubList"] = "";
						}else{
							$dataFC = $dalFC->executeRecordset("a.`Visible`='1'");
							for($j=0;$j<count($dataFC);$j++){
								$dataWM[$i]["SubList"] .= "<li";
								if($j == (count($dataFC) - 1)){
									$dataWM[$i]["SubList"] .= " class='last'";
								}
								$dataWM[$i]["SubList"] .= "><a href='".$htLink3.$dataFC[$j]["CategoryID"].".html'>".$dataFC[$j]["CategoryName"]."</a></li>";
							}
						}
						break;
					case "4":
						$dataWM[$i]["htLink"] = $htLink5;
						if($dataWM[$i]["SubMenu"] == "0"){
							$dataWM[$i]["SubList"] = "";
						}else{
							$dataBC = $dalBC->executeRecordset("a.`Visible`='1'");
							for($j=0;$j<count($dataBC);$j++){
								$dataWM[$i]["SubList"] .= "<li";
								if($j == (count($dataBC) - 1)){
									$dataWM[$i]["SubList"] .= " class='last'";
								}
								$dataWM[$i]["SubList"] .= "><a href='".$htLink5.$dataBC[$j]["CategoryID"].".html'>".$dataBC[$j]["CategoryName"]."</a></li>";
							}
						}
						break;
					case "5":
						$dataWM[$i]["htLink"] = $htLink6;
						$dataWM[$i]["SubList"] = "";
						break;
				}
			}
			$listWM = new repeater();
			$listWM->id = "listWM";
			$listWM->dataSource = $dataWM;
			parent::addControl($listWM);

			$listWM2 = new repeater();
			$listWM2->id = "listWM2";
			$listWM2->dataSource = $dataWM;
			parent::addControl($listWM2);
			
			parent::loadTemplateFile(dirname(__FILE__)."/../templates/webParts/".$this->registry->webTemplates."/header_in.html");
			parent::addParameter("pwk", $this->pwk);
		}
	}
?>