<?php
// +----------------------------------------------------------------------
// | 万通CMS网站管理系统
// +----------------------------------------------------------------------
// | Copyright (c) 2009-2019 http://www.wtcms.cn All rights reserved.
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | Author: 万通CMS <925153133@qq.com>
// +----------------------------------------------------------------------
class ConfigAction extends CommonAction{
	Public function index(){
		$this->display();
	}
	
	Public function upconfig(){
		if($this->isPost()){
			if($_FILES['web_logo']['name']<>"" || $_FILES['web_qrcode']['name']<>""){
				$info=$this->uploadimg();
				  if(count($info)==2){
					  $_POST['web_logo']=$info[0]['savename'];
					  $_POST['web_qrcode']=$info[1]['savename'];
				  }else{
					  $_POST[$info[0]['key']]=$info[0]['savename'];
				  }
			}
			if (get_magic_quotes_gpc()) {
				$_POST['web_count'] = stripslashes($_POST['web_count']);
				$_POST['web_baidu'] = stripslashes($_POST['web_baidu']);
				$_POST['seo_description'] = stripslashes($_POST['seo_description']);
			}
			
			if($this->setconfig($_POST,'../config.php')){
				$this->success('修改成功',U('Config/index'));
			}else{
				$this->error('修改失败');
			}
		}else{
			$this->error('非法操作');
		}
	}
	
	Public function dellogo(){
		$name=$this->_get('name');
		$type=$this->_get('type');
		switch ($type) {
			case 'logo':
				$array=array('WEB_LOGO'=>'');
				break;
			case 'water':
				$array=array('WATER_LOGO'=>'');
				break;
			default:
				$array=array('WEB_QRCODE'=>'');
				break;
		}
		if($this->setconfig($array,'../config.php')){
			if(delimg('../Uploads/'.$name)){
				echo 1;
			}else{
				echo 0;
			}
		}else{
			$this->error('删除失败');
		}
	}
	
	Public function water(){
		$this->display();
	}

	Public function savewater(){
		$alpha=$this->_post('water_alpha','intval');
		if ($alpha < 0 || $alpha > 100) {
			$this->error('请填0-100之间的整数');
		}
		if ($_POST['num']) {
			$info=$this->uploadimg();
			$_POST['water_logo']=$info[0]['savename'];
			unset($_POST['num']);
		}
		$_POST['water_alpha']=$alpha;
		if($this->setconfig($_POST,'../config.php')){
			$this->success('设置成功');
		}else{
			$this->error('设置失败');
		}	
	}

	Public function setstatic(){
		$arrs=include'../static.php';
		$this->statics=$arrs;
		$this->display();
	}

	Public function savestatic(){
		if ($this->isPost()) {
			foreach ($_POST as $v) {
				if (!preg_match('/^[a-zA-Z0-9-_]{1,200}$/i',$v)) {
					$this->error('必须是1位以上的字母，数字，下划线或-');
				}
			}
			$_POST['search']="search";
			$_POST['feedback']="feedback";
			$_POST['inquiry']="inquiry";
			$array=array_map("strtolower", $_POST);
			if (count($array) != count(array_unique($array))) {
				$this->error('不能有重复值，不能使用search,feedback,inquiry');
			}
			unset($_POST['search']);
			unset($_POST['feedback']);
			unset($_POST['inquiry']);
			if ($this->setconfig($_POST,'../static.php')) {
				$this->success('设置成功');
			} else {
				$this->error('设置失败');
			}		
		}
	}

	Public function title(){
		$titledata=include'../title.php';
		$this->assign('titledata',$titledata);
		$this->display();
	}

	Public function uptitle(){
		if($this->isPost()){
			if (get_magic_quotes_gpc()) {
				$_POST=array_map(stripslashes, $_POST);
			}
			if($this->setconfig($_POST,'../title.php')){
				$this->success('修改成功',U('Config/title'));
			}else{
				$this->error('修改失败');
			}
		}else{
			$this->error('非法操作');
		}
	}

	
}
?>