<?php 


class stat_model{	
	        public function plus(){
		if(isset($_GET['get'])){
		$site = Core::query("SELECT * FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) -> fetch();
		if(Core::count("SELECT COUNT(*) FROM `golos` WHERE `ip` = ? && `id_site` = ?", array($_SERVER['REMOTE_ADDR'], $site['id'])) == false){
			Core::query("INSERT INTO `golos` SET `ip` = ?, `id_site` = ?", array($_SERVER['REMOTE_ADDR'], $site['id']));
			Core::query("UPDATE `user_sites` SET `plus` = '".($site['plus'] + 1)."' WHERE `id` = ?", array($site['id']));
		Core::redirect('/stat/index/'.$site['id'].'', 'Ваш голос успешно зафиксирован');
		}else{
		Core::redirect('/stat/index/'.$site['id'].'', 'Голосовать можно раз в сутки');}
		}else{
		Core::redirect('/');
		}
	}
	
		public function minus(){
		if(isset($_GET['get'])){
				$site = Core::query("SELECT * FROM `user_sites` WHERE `id` = ?", array($_GET['get'])) -> fetch();
		if(Core::count("SELECT COUNT(*) FROM `golos` WHERE `ip` = ? && `id_site` = ?", array($_SERVER['REMOTE_ADDR'], $site['id'])) == false){
			Core::query("INSERT INTO `golos` SET `ip` = ?, `id_site` = ?", array($_SERVER['REMOTE_ADDR'], $site['id']));
			Core::query("UPDATE `user_sites` SET `minus` = '".($site['minus'] + 1)."' WHERE `id` = ?", array($site['id']));
		Core::redirect('/stat/index/'.$site['id'].'', 'Ваш голос успешно зафиксирован');
		}else{
		Core::redirect('/stat/index/'.$site['id'].'', 'Голосовать можно раз в сутки');}
		}else{
		Core::redirect('/');
		}
	}
	
	

}
?>