<?php 

defined('IN_TS') or die('Access Denied.');

$options_lic = fileRead('options.php','data','system');

$arrhttphost = explode('.',$_SERVER['HTTP_HOST']);

$site_url = str_replace('http://','',$options_lic['site_url']);

$site_url_arr = explode('/',$site_url);



if($site_url_arr[0]<>$_SERVER['HTTP_HOST']){

	

	qiMsg("系统配置域名与当前域名不符合，请检查data/system_options.php文件");

	

	}





if(count($arrhttphost)<4){

	if(count($arrhttphost)<3){

		$SERVER = $arrhttphost[0].'.'.$arrhttphost[1];

	}else{

		

		$SERVER = $arrhttphost[1].'.'.$arrhttphost[2];

	}

}else{

	

	$SERVER = $arrhttphost[0].'.'.$arrhttphost[1].'.'.$arrhttphost[2].'.'.$arrhttphost[3];

	

}

$loch_url=base64_encode($_SERVER['HTTP_HOST']);



//$isurlcode = application($options_lic['site_lication'],$options_lic['lic_username']);;







if($le=='do'){

		$letutaocode = trim($_POST['letutaocode']);

		$lic_username = trim($_POST['lic_username']);

		if($letutaocode && $lic_username){

		$return_data = aac("system")->license->isCode($lic_username,$letutaocode);



	if($return_data=='10004'){ 

		

		

			qiMsg("授权用户名不存在,如不清楚请联系橙创客服！");

		

		}

	

		if($return_data=='10001'||$return_data=='10002'){

	

		$arrData = array(

			'site_lication' => $letutaocode,

			'lic_username' => $lic_username,

			);

			foreach ($arrData as $key => $val){

			$db->query("UPDATE ".dbprefix."system_options SET optionvalue='$val' where optionname='$key'");

		}

		

		$arrOptions = $db->fetch_all_assoc("select optionname,optionvalue from ".dbprefix."system_options");

		foreach($arrOptions as $item){

				$arrOption[$item['optionname']] = $item['optionvalue'];

		}

		

		fileWrite('system_options.php','data',$arrOption);

		

		

		qiMsg("恭喜您，授权成功，在使用过程中出现问题请到论坛交流：bbs.tuntron.com^_^",'<a href="index.php?app=system&ac=login">进入后台</a>');

			}else{

				

				qiMsg("授权码错误，或者用户名不存在,如不清楚请联系橙创客服！");

				

			}

	

		}else{

			

			qiMsg("授权码错误，或者用户名不存在,如不清楚请联系橙创客服！");

			

			

		}

	

}



if($le=='re_lic'){

	

	if(_post('submit','intval')){

		

		$countAdmin	= $db->once_fetch_assoc("select count(userid) from ".dbprefix."user where userid='1' and pwd='".md5(_post('adminpwd','trim'))."'");

		if($countAdmin['count(userid)'] == 0) qiMsg("您输入的管理员密码错误！");

		

		foreach($options_lic as $key=>$item){

		if($key=='site_lication'||$key=='lic_username'){

			

		}else{

			

			$arrOption[$key]= $item;	

			

		}

}

		if(is_array($arrOption)){

			fileWrite('system_options.php','data',$arrOption);

		}

		

		  header("Location:".SITE_URL."index.php?app=lic&ac=lication");

		

		

	}

	

	

}



include template("lication");