<?php
	require_once "pageBase.php";
	require_once "../dal/userDAL.php";
	require_once "../bin/web/repeater.php";
	require_once "../bin/system/utility.php";

	class _userList extends pageBase {
		private $dal;
		
		public function load() {
			$this->dal = new userDAL();
			$this->limitID = "21";
			if (!parent::chkUserLimit()) {
				$this->alertMsg = "您沒有使用此頁面的權限!如有疑問請洽主管理者!";
				$this->locationHref = "index.php";
			} else {
				$this->loadData();
			}
			parent::loadTemplateFile(dirname(__FILE__) . "/templates/userList.html");
			parent::load();
		}

		public function loadData() {
			//取得資料
			$data = $this->dal->executeRecordset([], "a.`UserID`!=1");
			$data = $this->formatData($data);
			$list = new repeater();
			$list->id = "list";
			$list->dataSource = $data;
			parent::addControl($list);
			
			parent::addParameter("currentUrl", utility::getCurrentUrl());
			parent::addParameter("encodeUrl", urlencode(utility::getCurrentUrl()));
			
			parent::loadData();
		}

		public function formatData($data) {
			foreach ($data as &$item) {
				$item["txtV"] = $item["Visible"] ? "<span class=\"badge badge_soft_success\">使用</span>" : "<span class=\"badge badge_soft_danger\">不使用</span>";
				$item["isLine"] = ($item["LineUID"] === "") ? "<span class=\"badge badge_soft_danger\">不綁定</span>" : "<span class=\"badge badge_soft_success\">綁定</span>";
				$item["isGmail"] = ($item["Gmail"] === "") ? "<span class=\"badge badge_soft_danger\">不綁定</span>" : "<span class=\"badge badge_soft_success\">綁定</span>";
				$item["isFb"] = ($item["FbAccount"] === "") ? "<span class=\"badge badge_soft_danger\">不綁定</span>" : "<span class=\"badge badge_soft_success\">綁定</span>";
				$item["encodeUrl"] = urlencode(utility::getCurrentUrl());
			}
			return $data;
		}
	}

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