<?php
	require_once "pageBase.php";
	require_once "../../bin/system/conver.php";
	require_once "../../dal/template_categoryDAL.php";
	require_once "../../dal/templateDAL.php";
	class _template_category extends pageBase {
		private $dal;
		
		public function __construct() {
			$this->dal = new template_categoryDAL();
		}

		public function load(): void {
			$action = parent::getPost("do");
			switch ($action) {
				case "del":
					$this->delete();
					break;
				default:
					break;
			}
			parent::load();
		}
		
		private function delete() {
			$dalA = new templateDAL();
			$id = parent::getPost("id");
			$intoAry = [ parent::addArray(":categoryID", $id, "int") ];
			if ($dalA->countRecordset($intoAry, "a.`CategoryID`=:categoryID") > 0) {
				echo "-10";
			} else {
				echo ($this->dal->deleteRecord($id)) ? "1" : "-1";
			}
		}
	}

	$page = new _template_category();
	$page->load();
?>