<?php
	require_once "pageBase.php";
	require_once dirname(__FILE__)."/../bin/web/page.php";
	require_once dirname(__FILE__)."/../dal/userDAL.php";
	require_once dirname(__FILE__)."/../dal/contactDAL.php";
	require_once dirname(__FILE__)."/../dal/orderDAL.php";

	class _header extends page {
		public $userID;
	
		public function __construct() {
			parent::__construct();
		}

		//覆蓋父類load()方法
		public function load() {
			parent::loadTemplateFile(dirname(__FILE__) . "/templates/header.html");
	
			$pageBase = new pageBase();
	
			// 使用者
			$dalU = new userDAL();
			$dalU->UserID = $this->userID;
			$dalU->loadRecord();
			parent::addParameter("LoginName", $dalU->LoginName);
			parent::addParameter("UserName", $dalU->UserName);

			// Line 登入用戶頭像
			$userImage = ($dalU->LinePicture != "") ? "<i class=\"lineImg\" style='background-image: url({$dalU->LinePicture});'></i>" : "<i class=\"fa fa-user fa-lg\"></i>";
			parent::addParameter("userImage", $userImage);
	
			// 現在時間
			$dateTime = date("Y-m-d H:i:s");
			parent::addParameter("dateTime", $dateTime);
	
			// 系統更新
			$version = ($pageBase->getCurrentUserID() == "1") ? "<a class=\"d_flex f_aitems_center\" href=\"check_version.php\" title=\"更新\"><svg class=\"mr_1 fa svg_stroke_g_500\"><use xlink:href=\"svg/icons.svg#refreshCw\"></use></svg><span>更新</span></a>" : "";
			parent::addParameter("version", $version);
			
			// 聯絡我們顯示
			$countC = 0;
			$numC = "";
			$textC = "";
			if ($pageBase->chkUserLimit('26')) {
				$dalC = new contactDAL();
				$countC = $dalC->countRecordset(array(), "a.`IsView`='0'");
				$numC = ($countC > 0) ? "<b class=\"d_block badge badge_warning\">{$countC}</b>" : "<b></b>";
				$textC = "<a href=\"contactList.php\" title=\"聯絡我們\"><svg class=\"fa svg_stroke_g_500\"><use xlink:href=\"svg/side.svg#messagec\"></use></svg><span>聯絡我們</span>{$numC}</a>";
			}
			
			// 線上訂單顯示
			$countO = 0;
			$numO = "";
			$textO = "";
			if ($pageBase->chkUserLimit('24') || $pageBase->getRegistryValue("webType") == "20") {
				$dalO = new orderDAL();
				$countO = $dalO->countRecordset(array(), "a.`IsView`='0'");
				$numO = ($countO > 0) ? "<b class=\"d_block badge badge_info\">{$countO}</b>" : "<b></b>";
				$textO = "<a href=\"orderList.php\" title=\"線上訂單\"><svg class=\"fa svg_stroke_g_500\"><use xlink:href=\"svg/side.svg#clipboard\"></use></svg><span>線上訂單</span>{$numO}</a>";
			}
			
			// 通知
			$isnotify = "";
			$notify_list = "";
			if (($countC + $countO) > 0) {
				$isnotify = " move_bell";
				$notify_list = "<div class=\"pos_fix\" id=\"notify_list\" data-type=\"1\">{$textC}{$textO}</div>";
			}
			parent::addParameter("isnotify", $isnotify);
			parent::addParameter("notify_list", $notify_list);
			
			parent::load();
		}
	}
?>