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

		$this->header();
		$this->model('users');
		$this->model('setting');
		
		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'] = 'setting';
		
		if($this->POST('main')){
			$title = $this->POST('title');
			$url = $this->POST('url');
			$description = $this->POST('description');
			$keywords = $this->POST('keywords');
			$theme = $this->POST('theme');
			$status = $this->POST('status');
			$off_message = $this->POST('off_message');
			
			if($title && $url && $off_message){
				if($this->settingModel->saveSetting("`setting_title` = '{$title}', `setting_keywords` = '{$keywords}', `setting_description` = '{$description}', `setting_url` = '{$url}', `setting_status` = '{$status}', `setting_theme` = '{$theme}', `setting_off_message` = '{$off_message}'")){
					$this->data['success'] = 'Настройки сайта сохранены!';
				} else {
					$this->data['error'] = 'При сохранении данных произошла ошибка. Повторите попытку!';
				}
			} else {
				$this->data['error'] = 'Некоторые поля обязательны для заполнения!';
			}
		}
		
		return $this->view(array('common/header', 'setting/index', 'common/footer'), $this->data); //Загружаем шаблон
	}
}