<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<0015>")) {	//没有权限
		ob_clean();
		header("Location: accesserror.html");
		exit;
	}
?>

<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>换房处理结果</title>
</head>

<body background="bkg.bmp">

<p align="center"><font size="5"><b>换房处理结果</b></font></p>
<hr color="#999966">


<p align="center">
<b>
<?php
	$timestr=strftime("%Y-%m-%d %H:%M:%S");
	$oldlogin = trim($_REQUEST["oldlogin"]);
	$newlogin = trim($_REQUEST["newlogin"]);
	if (oldlogin!="" && newlogin!="") {
		$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
		mysql_select_db(get_cfg_var("SIPDB"),$db);
		$rs = mysql_query("select userid,type from users where loginname='".$oldlogin."' and checked='n'",$db);	//取该用户开号数据
		if ($row = mysql_fetch_array($rs)) {
			$userid=$row["userid"];
			$usertype=$row["type"];
			mysql_free_result($rs);
			$ipaddr="";
			$rs = mysql_query("select ipaddr from login where userid='".$userid."'",$db);	//检查该客人是否还在上网
			if ($row = mysql_fetch_array($rs)) {
				$ipaddr=$row["ipaddr"];
			}
			mysql_free_result($rs);
			if ($ipaddr!="") {	//该客人还在上网
				mysql_close($db);
				ob_clean();
				header("Location: shutdown2.php?ipaddr=".$ipaddr);
				exit;
			}
			$rs = mysql_query("select userid from users where loginname='".$newlogin."' and checked='n'",$db);	//取该用户开号数据
			if (($row = mysql_fetch_array($rs))==FALSE) {
				mysql_free_result($rs);
				$newuserid="";
				$n=strpos($userid,"-");
				if ($n>0) {
					$newuserid=$newlogin.substr($userid,$n);
				}
				mysql_query( "update users set loginname='".$newlogin."' where userid='".$userid."'",$db );
				if ($newuserid!="") {
					mysql_query( "update users set userid='".$newuserid."' where userid='".$userid."'",$db );		//更换旧的userid，以便和新的登录ID保持一致
					mysql_query( "update history set userid='".$newuserid."' where userid='".$userid."'",$db );		//更换旧的userid，以便和新的登录ID保持一致
					mysql_query( "update cash set userid='".$newuserid."' where userid='".$userid."'",$db );		//更换旧的userid，以便和新的登录ID保持一致
				}
				mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','更换房间号，原用户ID：".$userid."，新用户ID：".$newuserid."')",$db );
				echo("旧的用户ID‘".$oldlogin."’已经成功更换为新的用户ID‘".$newlogin."’！");
			} else {
				mysql_free_result($rs);
				echo("新的用户ID已经有人在使用，不能更换!");
			}
		} else {
			mysql_free_result($rs);
			echo("找不到旧用户ID!");
		}
		mysql_close($db);
	} else {
		echo("必须输入旧用户ID和新用户ID！");
	}
?>
</b></p>


<hr>
<p align="center">SIP酒店上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>

</body>

</html>
