<?php
/*
* @ServerMon v1.1
* @Developed by Maksa988
* @www.Server-Mon.ru
* @Copyright (C) 2014
*/
 if(!defined('SMON'))
	die('Hacking attempt!');
	
class gamesModel extends Controller {
	public function getGames($param = '') {
		global $db;
		$sql = "SELECT * FROM `".$this->cfg('prefix')."games` ".$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 editGame($id, $name, $code, $connect){
		global $db;
		$sql .= "UPDATE `".$this->cfg('prefix')."games` SET";
		$sql .= "`game_name` = '{$name}',";
		$sql .= "`game_code` = '{$code}',";
		$sql .= "`game_icon` = '{$code}',";
		$sql .= "`game_query` = '{$code}',";
		$sql .= "`game_connect` = '{$connect}'";
		$sql .= "WHERE `game_id` = '{$id}'";
		$db->query($sql);
		
		if(!$db->error) {
			return true;
		}
		return false;
	}
	public function checkGame($id){
		global $db;
		$sql = "SELECT * FROM `".$this->cfg('prefix')."games` WHERE `game_id` = '{$id}' LIMIT 1";
		$result = $db->query($sql);

		if($result->num_rows == 1){
			return $result->fetch_assoc();
		}
		return false;
	}
	public function getGameInfo($code) {
		global $db;
		$sql = "SELECT * FROM `".$this->cfg('prefix')."games` WHERE `game_code` = '{$code}' LIMIT 1";
		$result = $db->query($sql);

		if($result->num_rows == 1){
			return $result->fetch_assoc();
		}
		return false;
	}
	public function addGame($name, $code, $connect) {
		global $db;
		$sql = "INSERT INTO `".$this->cfg('prefix')."games` 
		(	game_name, 
			game_code, 
			game_icon, 
			game_query, 
			game_connect
		) VALUES (
			'{$name}', 
			'{$code}', 
			'{$code}', 
			'{$code}', 
			'{$connect}')";
		$db->query($sql);
		
		if(!$db->error) {
			return $db->insert_id;
		}
		return false;
	}
	public function deleteGame($id) {
		global $db;
		$sql = "DELETE FROM `".$this->cfg('prefix')."games` WHERE `game_id` = '{$id}'";
		$db->query($sql);
		
		if(!$db->error) {
			return true;
		}
		return false;
	}
}