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

		public function load(): void {
			$action = parent::getPost("do");
			switch ($action) {
				case "vis":
					$this->visible();
					break;
				case "del":
					$this->delete();
					break;
				default:
					echo "-2";
			}

			parent::load();
		}
		
		private function visible() {
			$id = parent::getPost("id");
			$vis = parent::getPost("vis");
		
			$this->dal->MenuID = $id;
			$this->dal->loadRecord();
			$this->dal->Visible = $vis;
		
			echo ($this->dal->updateRecord()) ? $vis : "-1";
		}

		private function delete() {
			$id = parent::getPost("id");
			$result = $this->dal->deleteRecord($id);
		
			echo $result ? "1" : "-1";
		}
	}

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