<?php
/*
* @ServerMon v1.1
* @Developed by Maksa988
* @www.Server-Mon.ru
* @Copyright (C) 2014
*/
 if(!defined('SMON'))
	die('Hacking attempt!');
	
class games extends Controller {
	public function __construct() {

		$this->header();
		$this->model('users');
		$this->model('games');
		
		if(empty($_SESSION['user_id'])):
			return $this->view(array('login/index'), $this->data); //Загружаем шаблон
		endif;
		
		$user = $this->usersModel->getUser($_SESSION['user_id']);
		$this->data['user'] = $user;
		
		if($user['user_group'] != $this->setting('admin_group')):
			$this->data['error'] = 'Вы не имеете доступа!';
			return $this->view(array('login/index'), $this->data); //Загружаем шаблон
		endif;
		
		$this->data['activeSection'] = 'modules';
		$this->data['menu'] = array(array('url'=> 'games/add', 'icon' => 'plus', 'name'=> 'Добавить игру')); 
		
		if($this->GET('delete') >= '1'){
			if($this->gamesModel->deleteGame($this->GET('delete'))){
				$this->data['success'] = 'Игра удалена';
			} else {
				$this->data['error'] = 'Произошла ошибка. Повторите попытку.';
			}
		}
		
		$this->data['games'] = $this->gamesModel->getGames();
		
		return $this->view(array('common/header', 'games/index', 'common/footer'), $this->data); //Загружаем шаблон
	}
}