<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
	by it308.com
*/
class Ajax extends Admin_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->library('mysession');
		$this->admin_name = $this->config->item('admin_name');
		header('Content-type:text/json');
	}
	/**
	 * 设置网站配置
	 */
	public function setsetting(){
		$this->ajax_login();
		$data['webname'] = $this->input->post('webname');
		$data['description'] = $this->input->post('description');
		$data['keywords'] = $this->input->post('keywords');
		$data['reg'] = $this->input->post('reg');
		$data['close'] = $this->input->post('close');
		if( $data['reg']=='on' ){
			$data['reg'] = 1;
		}else{
			$data['reg'] = 0;
		}
		if( $data['close']=='on' ){
			$data['close'] = 1;
		}else{
			$data['close'] = 0;
		}
		$data['closeq'] = $this->input->post('closeq');
		$this->load->model('setting_m');
		//循环更新
		$tmp = 0;
		$res = 0;
		foreach($data as $key=>$val){
			$tmp = $this->setting_m->set(array("name"=>$key,"value"=>$val),$key);
			if($tmp){
				$res=1;
			}
		}
		if($res){
			$res = array(
				'status' => 1,
				'msg' => '更新网站配置成功！',
			);
		}else{
			$res = array(
				'status' => -1,
				'msg' => '更新网站配置失败！',
			);
		}
		echo json_encode((object)$res);
	}
	//ajax检查登录
	public function ajax_login(){
		$suser = $this->mysession->userdata('emailsystemuser');
		if($suser==""){
			$res = array(
				'status' => -1,
				'msg' => '请登陆后在操作！',
			);
			exit(json_encode((object)$res));
			return false;
		}else{
			return true;
		}
	}
}
		