<?php
	require_once "pageBase.php";
	require_once "../bin/system/conver.php";
	require_once "../dal/templateDAL.php";

	class _templateDownload extends pageBase{
		//覆蓋父類load()方法
		public function load(){
			if(!parent::chkUserLimit('30')){
				parent::alert2('您沒有使用此頁面的權限!如有疑問請洽主管理者!','index.php');
				exit;
			}

			$this->saveData();
			parent::load();
		}
		public function saveData(){
			$dal = new templateDAL();
			$id = conver::toDbString(trim($_GET["id"]));

			if(is_numeric($id)){
				$dal->TemplateID = $id;
				$dal->loadRecord();
				if($dal->File != '' && file_exists("..".$dal->File)){
					$bname = basename($dal->File);
					header("Content-type:application");
					header("Content-Disposition: attachment; filename=".$bname);
					readfile("http://".$_SERVER['HTTP_HOST'].$dal->File);
					exit(0);
				}else{
					header('Content-type:text/html; charset=utf-8');
					echo "<script type='text/javascript'>";
					echo "window.alert('此版型無說明文件!');";
					echo "window.opener = null;";
					echo "window.close();";
					echo "</script>";
				}
			}else{
				header('Content-type:text/html; charset=utf-8');
				echo "<script type='text/javascript'>";
				echo "window.alert('查無檔案!');";
				echo "window.opener = null;";
				echo "window.close();";
				echo "</script>";
			}
		}
	}

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