<?php
	require_once "pageBase.php";
	require_once "../bin/system/utility.php";
	require_once "../dal/paypageDAL.php";

	class _paypageView extends pageBase {
		private string $id;
		private string $pUrl;
		private $dal;
		
		public function load() {
			$this->dal = new paypageDAL();
			$this->id = parent::getInput("id","0");
			$this->pUrl = urldecode(parent::getInput("pUrl","paypageList.php"));
			
			$this->limitID = "77";
			if (!parent::chkUserLimit()) {
				$this->alertMsg = "您沒有使用此頁面的權限!如有疑問請洽主管理者!";
				$this->locationHref = "index.php";
			} else {
				parent::isPostBack() ? $this->saveData() : $this->loadData();
			}
			parent::loadTemplateFile(dirname(__FILE__) . "/templates/paypageView.html");
			parent::load();
		}

		public function loadData(){
			$arrS = ["1" => "付款成功", "0" => "待付款", "-1" => "付款失敗", "-2" => "逾時未付款"];
			if (!empty($this->id) && $this->id != 0) {
				$this->dal->ID = $this->id;
				$this->dal->loadRecord();

				$status = ($this->dal->Status >= "-2" && $this->dal->Status <= "1") ? $arrS[$this->dal->Status] : "-";
				parent::addParameter("PayerName", $this->dal->PayerName);
				parent::addParameter("MerchantOrderNo", $this->dal->MerchantOrderNo);
				parent::addParameter("Amt", $this->dal->Amt);
				parent::addParameter("ItemDesc", $this->dal->ItemDesc);
				parent::addParameter("ExpireTime", date("Y-m-d H:i:s", (int)$this->dal->ExpireTime));
				parent::addParameter("Email", $this->dal->Email);
				parent::addParameter("OrderComment", $this->dal->OrderComment);
				parent::addParameter("Status", $status);
				parent::addParameter("ReStatus", $this->dal->ReStatus);
				parent::addParameter("ReMessage", $this->dal->ReMessage);
				parent::addParameter("TradeNo", $this->dal->TradeNo);
				parent::addParameter("PaymentType", $this->dal->PaymentType);
				parent::addParameter("PayTime", $this->dal->PayTime);
				parent::addParameter("PayIP", $this->dal->PayIP);
				parent::addParameter("CreatedTime", date("Y-m-d H:i:s", (int)$this->dal->CreatedTime));
				parent::addParameter("CreatedIP", $this->dal->CreatedIP);
				parent::addParameter("ReplyTime", date("Y-m-d H:i:s", (int)$this->dal->ReplyTime));
				parent::addParameter("ReplyIP", $this->dal->ReplyIP);
			} else {
				parent::redirect($this->pUrl);
			}

			parent::addParameter("pUrl", $this->pUrl);
			parent::loadData();
		}
	}

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