<?php
class admin_configControl extends skymvc{
	
	function __construct(){
		parent::__construct();
		if(empty($_SESSION['ssadmin'])){
				$this->gourl("".APPADMIN."?m=admin&a=login");	
		}
	}
	
	public function onDefault(){
		$this->loadmodel("config");
		$data=$this->config->selectRow();
		$this->smarty->assign(array(
			"data"=>$data,
		));
		$this->smarty->display("config.html");
	}
	
	public function onsave(){
		$data["qqid"]=get_post("qqid","h");
		$data["qqkey"]=get_post("qqkey","h");
		$data["wbid"]=get_post("wbid","h");
		$data["wbkey"]=get_post("wbkey","h");
		$data["tbid"]=get_post("tbid","h");
		$data["tbkey"]=get_post("tbkey","h");
		$data["siteid"]=SITEID;
		$data["tbpid"]=get_post("tbpid","h");
		$data["phone_on"]=get_post("phone_on","i");
		$data["phone_user"]=get_post("phone_user","h");
		$data["phone_pwd"]=get_post("phone_pwd","h");
		$data["phone_num"]=get_post("phone_num","h");
		$data["smtphost"]=get_post("smtphost","h");
		$data["smtpport"]=get_post("smtpport","i");
		$data["smtpemail"]=get_post("smtpemail","h");
		$data["smtpuser"]=get_post("smtpuser","h");
		$data["smtppwd"]=get_post("smtppwd","h");
		$data["water_on"]=get_post("water_on","i");
		$data["water_type"]=get_post("water_type","i");
		$data["water_pos"]=get_post("water_pos","i");
		$data["water_str"]=get_post("water_str","h");
		$data["water_img"]=get_post("water_img","h");
		$data["water_size"]=get_post("water_size","i");
		$data["rewrite_on"]=get_post("rewrite_on","i");
		$data['rewrite_type']=get_post('rewrite_type','h');
		$data["spread_on"]=get_post("spread_on","i");
		$data["spread_discount"]=get_post("spread_discount","i");
		$data["grade_on"]=get_post("grade_on","i");
		$data["opentime"]=get_post("opentime","i");
		$data["starthour"]=get_post("starthour","i");
		$data["endhour"]=get_post("endhour","i");
		$data["startminute"]=get_post("startminute","i");
		$data["endminute"]=get_post("endminute","i");
		$data["showweek"]=get_post("showweek","i");
		$data["minprice"]=round(get_post("minprice"),1);
		$data["alipay"]=get_post("alipay","i");
		$data["tenpay"]=get_post("tenpay","i");
		$data['bdmapkey']=get_post('bdmapkey');
		$data['comment_status_check']=get_post('comment_status_check','i');
		$data['activity_topic_status_check']=get_post('activity_topic_status_check','i');
		$data['ob_gzip']=post('ob_gzip','i');
		$this->loadmodel("config");
		if($this->config->selectRow()){
			$this->config->update($data,"");
		}else{
			$this->config->insert($data);
		}
		$this->configfile();
		$this->qq($data);
		$this->weibo($data);
		$this->taobao($data);
		$this->gomsg("保存成功");
	}
	
	public function qq($data){
		$content='<?php
/*
先到http://connect.qq.com
*/
define("APPID","'.$data['qqid'].'");
define("APPKEY","'.$data['qqkey'].'");
define("CALLBACK","http://{$_SERVER[\'HTTP_HOST\']}/index.php?m=qqlogin&a=callback");
define("SCOPE","get_user_info,add_share,list_album,add_album,upload_pic,add_topic,add_one_blog,add_weibo");

?>';
		file_put_contents("config/qq_config.php",$content);
	}
	public function weibo($data){
		$content='<?php
//新浪微博接口
define("WB_AKEY" , "'.$data['wbid'].'" );
define("WB_SKEY" , "'.$data['wbkey'].'" );
define("CALLBACK","http://{$_SERVER[\'HTTP_HOST\']}/index.php?m=sinalogin&a=apilogin");

?>';
		file_put_contents("config/sina_config.php",$content);
	}
	public function taobao($data){
		$content='<?php
		define("TBPID","'.$data['tbpid'].'");
$tao_appconfig=array(
					array("'.$data['tbid'].'","'.$data['tbkey'].'"),
					 
			);
?>';
		file_put_contents("config/taobao_config.php",$content);
	}
	
	public function configfile()
	{
		$rs=$this->config->selectRow();
		unset($rs['id']);
		unset($rs['siteid']);
		$str='<?php'."\r\n";
		foreach($rs as $key=>$val)
		{
			$str.='define("'.strtoupper($key).'",'."\"{$val}\");\r\n";
			
		}
		$str.='?>';
		file_put_contents(ROOT_PATH."/config/setconfig.php",$str);
	}
	
	public function onTestPhone(){
		$this->loadModel("email");
		if($this->email->setSms(array("uid"=>get_post('phone_user'),"sign"=>get_post('phone_pwd')))->sendSms(get_post('phone_num'),"恭喜你，今天过得开心哦！")){
			echo "发送成功,请接收短信！";
		}else{
			echo "发送失败";
		}
		
	}
	
	public function onTestEmail(){
		$this->loadModel("email");
		
		if($this->email->setEmail($_GET)->sendEmail(get('smtpemail'),"这是测试内容哦","测试一下哦")){
			echo "邮件发送成功";
		}else{
			echo "邮件发送失败";
		}
	}
	
	
}

?>