<?php 


class cabinet{
	public function index(){
		User::aut(true);
		Template::head('Ваш кабинет');
		Template::run(__CLASS__, 'index');
		Template::foot();
	}
	
	/**
	* Создать площадку
	*/
	public function creat_area(){
		User::aut(true);
		
		require_once  MODEL.'cabinet.class.php';
		$obj = new cabinet_model();
		$obj -> creat_area();
		
		Template::head('Добавить площадку');
		Template::run(__CLASS__, 'creat_area');
		Template::foot();
	}
	
	public function pass(){
		User::aut(true);
		
		require_once  MODEL.'cabinet.class.php';
		$obj = new cabinet_model();
		$obj -> pass();
		
		Template::head('Смена пароля');
		Template::run(__CLASS__, 'pass');
		Template::foot();
	}

		public function plus(){	
			$title = Core::query("SELECT * FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) -> fetch();
		require_once  MODEL.'cabinet.class.php';
		$obj = new cabinet_model();
		$obj -> plus();
		
		Template::run(__CLASS__, 'plus');
	}
	
		public function minus(){	
			$title = Core::query("SELECT * FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) -> fetch();
		require_once  MODEL.'cabinet.class.php';
		$obj = new cabinet_model();
		$obj -> minus();
		
		Template::run(__CLASS__, 'minus');
	}
	
		public function site(){
		User::aut(true);
		Template::head('Ваши площадки');
		Template::run(__CLASS__, 'site');
		Template::foot();
	}
	/**
	* Код для установки
	*/
	public function kod(){
		if(isset($_GET['get']) && Core::count("SELECT COUNT(*) FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) == true){
			User::aut(true);
			$title = Core::query("SELECT * FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) -> fetch();
			Template::head('Код счетчика');
			Template::run(__CLASS__, 'kod');
			Template::foot();
		}else{
			Core::redirect('/cabinet', 'Ошибка генерации кода');
		}
	}
	
	
	
	
		public function graphic(){
		if(isset($_GET['get'])){
			Template::run(__CLASS__, 'graphic');
		}
	}
	
		public function week(){
		if(isset($_GET['get']) && Core::count("SELECT COUNT(*) FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) == true){
			$title = Core::query("SELECT * FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) -> fetch();
			Template::head(Protect::title('Статистика по дням '.$title['url']));
			Template::run(__CLASS__, 'week');
			Template::foot();
		}else{
			Core::redirect('/cabinet', 'Сайт не найден');
		}
	}
	
			public function ip(){
		if(isset($_GET['get']) && Core::count("SELECT COUNT(*) FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) == true){
			$title = Core::query("SELECT * FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) -> fetch();
			Template::head(Protect::title('Статистика по ip '.$title['url']));
			Template::run(__CLASS__, 'ip');
			Template::foot();
		}else{
			Core::redirect('/cabinet', 'Сайт не найден');
		}
	}
				public function hours(){
		if(isset($_GET['get']) && Core::count("SELECT COUNT(*) FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) == true){
			$title = Core::query("SELECT * FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) -> fetch();
			Template::head(Protect::title('Статистика по часам '.$title['url']));
			Template::run(__CLASS__, 'hours');
			Template::foot();
		}else{
			Core::redirect('/cabinet', 'Сайт не найден');
		}
	}
	
					public function online(){
		if(isset($_GET['get']) && Core::count("SELECT COUNT(*) FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) == true){
			$title = Core::query("SELECT * FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) -> fetch();
Template::head(Protect::title('Статистика по онлайну '.$title['url']));
			Template::run(__CLASS__, 'online');
			Template::foot();
		}else{
			Core::redirect('/cabinet', 'Сайт не найден');
		}
	}
	/**
	* Статистика сайта
	*/
	public function statistic(){
		if(isset($_GET['get']) && Core::count("SELECT COUNT(*) FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) == true){
			$title = Core::query("SELECT * FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) -> fetch();
                        Template::head(Protect::title($title['title']));
			Template::run(__CLASS__, 'statistic');
			Template::foot();
		}else{
			Core::redirect('/cabinet', 'Сайт не найден');
		}
	}
	
}
?>