<?php
/*
* @ServerMon v1.1
* @Developed by Maksa988
* @www.Server-Mon.ru
* @Copyright (C) 2014
*/
 if(!defined('SMON'))
	die('Hacking attempt!');
	
class voteModel extends Controller {
	public function checkVote ($ip) {
		global $db;
		$sql = "SELECT * FROM `".$this->cfg('prefix')."vote` WHERE `vote_ip` = '{$ip}' ORDER BY `vote_id` DESC LIMIT 1";
		$result = $db->query($sql);

		if($result->num_rows >= 1){
			return $result->fetch_assoc();
		}
		return false;
	}
	public function newVote($ip, $server) {
		global $db;
		$sql = "INSERT INTO `".$this->cfg('prefix')."vote` 
		(	`server_id`, 
			`vote_time`, 
			`vote_ip`
		) VALUES (
			?, 
			NOW(), 
			?)";
		$stmt = $db->prepare($sql);
		$stmt->bind_param('ss', $server, $ip);
		$stmt->execute();
		return $db->insert_id;
		$stmt->close();
	}
	public function getVote($param = '') {
		global $db;
		$sql = "SELECT * FROM `".$this->cfg('prefix')."vote` ".$param;
		$result = $db->query($sql);

		$items = array();
		
		if($result->num_rows >= 1){
			while($data = $result->fetch_assoc())
			$items[] = $data;
			
			return $items;
		}
		return false;
	}
	public function clearVote(){
		global $db;
		$sql = "TRUNCATE `".$this->cfg('prefix')."vote`";
		$db->query($sql);
		
		if(!$db->error) {
			return true;
		}
		return false;;
	}
}