<?php
/*
* @ServerMon v1.1
* @Developed by Maksa988
* @www.Server-Mon.ru
* @Copyright (C) 2014
*/
 if(!defined('SMON'))
	die('Hacking attempt!');
	
class serverStatsModel extends Controller {
	public function getStats($id, $param = '1 DAY') {
		global $db;
		$sql = "SELECT * FROM `".$this->cfg('prefix')."servers_stats` WHERE `server_id` LIKE '".$id."' AND `server_stats_date` BETWEEN NOW() - INTERVAL ".$param." AND NOW() ORDER BY `server_stats_date`";
		$result = $db->query($sql);

		$items = array();
		
		if($result->num_rows >= 1){
			while($data = $result->fetch_assoc())
			$items[] = $data;
			
			return $items;
		}
		return false;
	}
	public function addStats($id, $players){
		global $db;
		$sql = "INSERT INTO `".$this->cfg('prefix')."servers_stats` 
		(
			`server_id`, 
			`server_stats_date`, 
			`server_stats_players`
		) VALUES (
			'{$id}', 
			NOW(), 
			'{$players}')";
		$db->query($sql);
		
		if(!$db->error) {
			return $db->insert_id;
		}
		return false;
	}
}