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

	class _autokeywordAddWord extends pageBase
	{
		private $dal;

		//覆蓋父類load()方法
		public function load()
		{
			$this->dal = new autokeywordDAL();
			$this->loadData();
			parent::load();
		}
		public function loadData()
		{
			$this->dal->KeywordTitle = trim(conver::toDbString($_POST["KeywordTitle"]));
			if($this->dal->KeywordTitle == ""){
				parent::alert("請輸入關鍵字");
			}else{
				$SameName = $this->dal->countRecordset("a.KeywordTitle='".$this->dal->KeywordTitle."'");
				if($SameName > 0){
					parent::alert("此關鍵字已經存在");
				}else{
					$orderNO = $this->dal->countRecordset();
					$this->dal->OrderNO = ($orderNO + 1) * 10;
					$this->dal->insertRecord();
					parent::redirect("autokeywordList.php");
				}
			}
		}
	}

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