<?php
	require_once "pageBase.php";
	require_once "../bin/system/conver.php";
	require_once "../bin/system/guid.php";
	require_once "../bin/web/repeater.php";
	require_once "../dal/line_gearingDAL.php";
	require_once "../function/function.php";
	class _lineGearing extends pageBase {
		private $dal;

		public function load() {
			$this->limitID = "71";
			$this->dal = new line_gearingDAL();

			$currentDate = new DateTime();
			$endDate = new DateTime('2025-03-20');
			if ($currentDate > $endDate) {
				$this->dal->batTruncate();
				$this->alertMsg = "Line Notify 已經停止服務!";
				$this->locationHref = "index.php";
			} else {
				if (!parent::chkUserLimit()) {
					$this->alertMsg = "您沒有使用此頁面的權限!如有疑問請洽主管理者!";
					$this->locationHref = "index.php";
				} else {
					$this->loadData();
				}
			}
			parent::loadTemplateFile(dirname(__FILE__) . "/templates/lineGearing.html");
			parent::load();
		}
		
		public function loadData(){
			/* 宣告&參數 */
			$p = parent::getGet("p", "1");
			$pz = parent::getGet("pz", "10");
			
			$intoAry = [];
			$filter = "";
			//頁數參數
			$rows = $this->dal->countRecordset($intoAry, $filter);
			$p = ($p > 0) ? $p : 1;
			$pz = ($pz > 0) ? $pz : 10;
			$pMax = ($rows > 0) ? ceil($rows / $pz) : 1;
			$p = ($p > $pMax) ? $pMax : $p;
			$start = ($p - 1) * $pz;

			// 頁導航
			$pagtxt = '沒有資料!';
			$chk_all = "";
			if ($rows > 0) {
				$pagtxt = parent::generatePagination($p, $pMax);
				$chk_all = "<p class=\"pos_lg_abs d_flex chk chk_all\"><font class=\"el-checkbox\"><input type=\"checkbox\" id=\"chkAll\" name=\"chkAll\"><span class=\"el-checkbox-style\"></span><span class=\"d_lg_none d_inblock\">全選</span></font></p>";
			}
			
			$data = $this->dal->executeRecordset($intoAry, $filter, "", $start, $pz);
			foreach ($data as &$item) {
				$item["TypeName"] = ($item["TargetType"] == "2") ? "<span class=\"badge badge_soft_teal\">群組</span>" : "<span class=\"badge badge_soft_primary\">個人</span>";
				
				$item["CreatedDate"] = date("Y-m-d", $item["CreatedTime"]);
			}
			$list = new repeater();
			$list->id = "list";
			$list->dataSource = $data;
			parent::addControl($list);
			
			parent::addParameter("p", $p);
			parent::addParameter("pz", $pz);
			parent::addParameter("pagtxt", $pagtxt);
			parent::addParameter("chk_all", $chk_all);

			parent::loadData();
		}
	}

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