<?php
class IndexAction extends baseAction {
    public function index(){
		$this->display('index');
	}
	public function main(){
		$security_info=array();
		
		if(count($security_info)<=0){
			$this->assign('no_security_info',0);
		}
		else{
			$this->assign('no_security_info',1);
		}	
		$this->assign('security_info',$security_info);
        $disk_space = @disk_free_space(".")/pow(1024,2);
		$server_info = array(
		    '程序版本'=>C('version'),		
            '操作系统'=>PHP_OS,
            '运行环境'=>$_SERVER["SERVER_SOFTWARE"],	
            '上传附件限制'=>ini_get('upload_max_filesize'),
            '执行时间限制'=>ini_get('max_execution_time').'秒',		
            '服务器域名/IP'=>$_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
            '剩余空间'=>round($disk_space < 1024 ? $disk_space:$disk_space/1024 ,2).($disk_space<1024?'M':'G'),
		);
        $this->assign('set',$this->setting);
		$this->assign('server_info',$server_info);	
		$this->display('main');
	}
	public function web_setting(){
		$result = M('web_setting')->select();
		foreach($result as $k=>$v){
			$list[$v['name']] = $v['value'];
		}
		$this->assign('data',$list);
		$this->display('web_setting');
	}
	public function sms_setting(){
		
		$result = M('web_setting')->select();
		foreach($result as $k=>$v){
			$list[$v['name']] = $v['value'];
		}
		$this->assign('data',$list);
		$this->display('sms_setting');
	}
	public function email_setting(){
		
		$result = M('web_setting')->select();
		foreach($result as $k=>$v){
			$list[$v['name']] = $v['value'];
		}
		$this->assign('data',$list);
		$this->display('email_setting');
	}
	public function ajax_websetting(){
		if(IS_POST){
			foreach($_POST as $k=>$v){
				M('web_setting')->where("name = '$k'")->save(array("value"=>$this->_post($k)));
			}

	   	 	$data = '<?php
				$domain = "'. C('domain') .'";
				$wap_domain = "'. C('mobile_domain') .'";
				$qq_app_key = "'. I('qq_app_key') .'";
				$qq_app_secret = "'. I('qq_app_secret') .'";
				?>';
			file_put_contents('./data/site.php', $data);
			$this->ajaxReturn("","修改成功",1);
		}else{
			$this->ajaxReturn("","参数错误",0);
		}
	}
	public function ajax_seo(){
		if(IS_POST){
			$model = $this->_post('model');
			M('seo')->where("model = '".$model."'")->delete();
			unset($_POST['model']);
			foreach($_POST as $k=>$v){
				$map['name'] = $k;
				$map['model'] = $model;
				$map['value'] = $this->_post($k);
				$g = M('seo')->data($map)->add();
			}
			if(!empty($g)){
				$this->ajaxReturn("","操作成功",1);
			}else{
				$this->ajaxReturn("","操作失败",0);
			}
		}else{
			$this->ajaxReturn("","操作失败",0);
		}
	}
	public function test_mobile(){
		 if(IS_POST){
		 	if($this->_post('sms_apikey') && $this->_post('sms_mobile')) {
				import('@.ORG.sms.sms');
				$sms = new sms();
				$return = $sms->sms_send($this->_post('sms_apikey'),$this->_post('sms_mobile'),'【'. $this->_post('sms_p') .'】您的验证码是1111');
				if($return['code'] == '0') {
					echo 1;//发送成功
				}
			}
		 }
	}
	public function test_email(){
		if(IS_POST){
		 	if($this->_post('smtp_email')) {
				import('@.ORG.sms.smtp');
				$mail = new MySendMail();
				$mail->setServer($this->_post('smtp_host'), $this->_post('smtp_username'), $this->_post('smtp_password'),$this->_post('smtp_port')); //到服务器的SSL连接
				//如果不需要到服务器的SSL连接，这样设置服务器：$mail->setServer("smtp.126.com", "XXX@126.com", "XXX");
				$mail->setFrom($this->_post('smtp_email'));
				$mail->setReceiver($this->_post("smtp_username"));
				$mail_title = "测试标题";
				$mail_body = "<h2>测试内容</h2>";
				$mail->setMail($mail_title,  $mail_body);
				echo $mail->sendMail();
			}
		 }
	}
	public function seo(){
		$result = M('seo')->select();
		foreach($result as $k=>$v){
			$data[$v['name']] = $v['value'];
		}
		$this->assign('data',$data);
		$this->display('seo_news');
	}
	public function member(){
		$result = M('web_setting')->select();
		foreach($result as $k=>$v){
			$list[$v['name']] = $v['value'];
		}
		$this->assign('data',$list);
		$this->display('index_member');
	}
	public function top(){
		
		$username = cookie('feimao_username');
		$this->assign('username',$username);
		$this->display('top');
	}

	public function del_cache(){
		$dirs = array('./Runtime/');
		@mkdir('Runtime',0777,true);
		//清理缓存
		foreach($dirs as $value) {
			$this->rmdirr($value);
		}
		$this->assign("jumpUrl","javascript:history.go(-1);");
		$this->success('系统缓存清除成功！');
	}
}