<?php
@header("Content-type: text/html; charset=utf-8");
require_once(dirname(__FILE__) . '/../common/db.class.php');
require_once(dirname(__FILE__) . '/../common/function.php');
require_once(dirname(__FILE__) . '/../common/session_helper.php');
$action=$_GET['action'];
switch ($action){
	// case 'setcustombg':
	// 	setcustombg();
	// 	break;
	case 'setlogo':
		setlogo();
		break;
	case 'setbottomlogo':
		setbottomlogo();
		break;
	case 'seterweima':
		seterweima();
		break;
	case 'setwelcometext1':
		setwelcometext1();
		break;
	case 'setwelcometext2':
		setwelcometext2();
		break;
	case 'qrcodetoptext':
		setqrcodetoptext();
		break;
	case 'menucolor':
		setmenucolor();
		break;
}


//调整页面底部菜单颜色
function setmenucolor(){
	$load=Loader::getInstance();
	$val=isset($_GET['menucolor'])?$_GET['menucolor']:'#fff';
	$load->model('System_Config_model');
	$return=$load->system_config_model->set('menucolor',$val);
	if($return){
		echo '{"code":1,"message":"修改成功"}';
		return ;
	}else{
		echo '{"code":-2,"message":"修改失败"}';
		return ;
	}

}
//设置左上角logo
function setlogo(){
	$load=Loader::getInstance();
	$load->model('Wall_model');
	$data=array('logoimg'=>0);
	if (!empty($_FILES['logo']['type'])) {
		//上传文件
		/*** example usage ***/
		// $filename = $_FILES['logo']['name'];
		// $info = pathinfo($filename);
		// require_once('../common/FileUploadFactory.php');
		// $fuf=new FileUploadFactory(SAVEFILEMODE);
		// $file=$fuf->SaveFormFile($_FILES['logo']);

		$load=Loader::getInstance();
	    $load->model('Attachment_model');
	    $file=$load->attachment_model->saveFormFile($_FILES['logo']);

		$data=array('logoimg'=>$file['id']);
	}

	$result=$load->wall_model->setConfig($data);
	echo "<script>alert('微信墙顶部Logo已经配置成功！');history.go(-1);</script>";
}
//设置左下角logo
function setbottomlogo(){
	$load=Loader::getInstance();
	$load->model('Wall_model');
	$data=array('bottom_logoimg'=>0);
	if (!empty($_FILES['bottomlogo']['type'])) {
		//上传文件
		/*** example usage ***/
		// $filename = $_FILES['bottomlogo']['name'];
		// $info = pathinfo($filename);
		// require_once('../common/FileUploadFactory.php');
		// $fuf=new FileUploadFactory(SAVEFILEMODE);
		// $file=$fuf->SaveFormFile($_FILES['bottomlogo']);

		$load=Loader::getInstance();
	    $load->model('Attachment_model');
	    $file=$load->attachment_model->saveFormFile($_FILES['bottomlogo']);

		$data=array('bottom_logoimg'=>$file['id']);

	}
	$result=$load->wall_model->setConfig($data);
	echo "<script>alert('微信墙底部Logo已经配置成功！');history.go(-1);</script>";
}
//设置活动二维码
function seterweima(){
	$load=Loader::getInstance();
	$load->model('Weixin_model');
	$data=array('erweima'=>0);
	if (!empty($_FILES['erweima']['type'])) {
		// if ("image/jpeg" != $_FILES['erweima']["type"] && "image/png" != $_FILES['erweima']["type"]) {
		// 	echo "不能上传该文件格式";
		// 	exit;
		// }
		//上传的文件
		// require_once('../common/FileUploadFactory.php');
		// $fuf=new FileUploadFactory(SAVEFILEMODE);
		// $file=$fuf->SaveFormFile($_FILES['erweima']);


		// $load=Loader::getInstance();
	    $load->model('Attachment_model');
	    $file=$load->attachment_model->saveFormFile($_FILES['erweima']);
		
		$data=array('erweima'=>$file['id']);
	}
	$result=$load->weixin_model->setConfig($data);
	echo "<script>alert('二维码已经配置成功！');history.go(-1);</script>";
}
//设置欢迎语1
function setwelcometext1(){

	$text=isset($_POST['welcometext1'])?strval($_POST['welcometext1']):'';
	$load=Loader::getInstance();
	$load->model('Wall_model');
	$data=array('welcometext1'=>$text);
	$result=$load->wall_model->setConfig($data);

	if($result){
		$resultdata=array('code'=>1,'message'=>'修改成功');
		echo json_encode($resultdata);
		return;
	}else{
		$resultdata=array('code'=>-1,'message'=>'修改失败');
		echo json_encode($resultdata);
		return;
	}
}
//设置欢迎语2
function setwelcometext2(){
	$text=isset($_POST['welcometext2'])?strval($_POST['welcometext2']):'';

	$load=Loader::getInstance();
	$load->model('Wall_model');
	$data=array('welcometext2'=>$text);
	$result=$load->wall_model->setConfig($data);

	if($result){
		$resultdata=array('code'=>1,'message'=>'修改成功');
		echo json_encode($resultdata);
		return;
	}else{
		$resultdata=array('code'=>-1,'message'=>'修改失败');
		echo json_encode($resultdata);
		return;
	}
}
//设置二维码上面的文字
function setqrcodetoptext(){
	$text=isset($_POST['qrcodetoptext'])?strval($_POST['qrcodetoptext']):'';
	$load=Loader::getInstance();
	$load->model('Wall_model');
	$data=array('qrcodetoptext'=>$text);
	$result=$load->wall_model->setConfig($data);
	if($result){
		$resultdata=array('code'=>1,'message'=>'修改成功');
		echo json_encode($resultdata);
		return;
	}else{
		$resultdata=array('code'=>-1,'message'=>'修改失败');
		echo json_encode($resultdata);
		return;
	}
}