<?php
	require_once "pageBase.php";
	require_once "../bin/web/repeater.php";
	require_once "../bin/web/tables/article.php";

	class _leaderboardArticle extends pageBase {
		public function load() {
			$this->limitID = "44";
			if (!parent::chkUserLimit() || registryDAL::getRegistryValue("isAnalyze") == 0) {
				$this->alertMsg = "您沒有使用此頁面的權限!如有疑問請洽主管理者!";
				$this->locationHref = "index.php";
			} else {
				$this->loadData();
			}
			parent::loadTemplateFile(dirname(__FILE__) . "/templates/leaderboardArticle.html");
			parent::load();
		}
		
		public function loadData() {
			$dal = new articleDAL();
			$article = new article();

			$data = $dal->executeRecordset([], "a.`Disable`=0", "a.`ViewCount` DESC,a.`ArticleID`", 0, 3);
			foreach ($data as &$item) {
				$item["Visible"] = ($item["Visible"] == "1") ? "<span class=\"badge badge_soft_success\">啟用</span>" : "<span class=\"badge badge_soft_danger\">不啟用</span>";
				$item["OnlineTime"] = ($item["OnlineTime"] == 0) ? "-" : date("Y-m-d H:i:s", $item["OnlineTime"]);
				
				$item["WebLink"] = $article->linkArticleDetail($item["ArticleID"]);
			}
			$list = new repeater();
			$list->id = "list";
			$list->dataSource = $data;
			parent::addControl($list);

			parent::loadData();
		}
	}

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