<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<0023>")) {	//没有权限
		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">

<SCRIPT LANGUAGE="javascript">
function setoper(obj)
{
	if (obj.value=="删除") {
		obj.form.opertype.value="delete";
	}
	else {
		obj.form.opertype.value="update";
	}
	obj.form.submit();
}
</SCRIPT>

<title>特殊客房单价管理</title>
</head>

<body background="bkg.bmp">

<p align="center"><font size="5"><b>特殊客房单价管理</b></font></p>
<hr color="#999966">

<?php
	$timestr=strftime("%Y-%m-%d %H:%M:%S");
	$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
	mysql_select_db(get_cfg_var("SIPDB"),$db);
	$price=trim($_REQUEST["price"]);
	$loginname=trim($_REQUEST["loginname"]);
	$opertype=trim($_REQUEST["opertype"]);
	if ($loginname!="" && $opertype!="") {
		if ($price=="") {
			$price="0";
		}
		if ($opertype=="add") {				//增加
			$rs=mysql_query( "select price from rooms where loginname='".$loginname."'",$db );
			if (($row = mysql_fetch_array($rs))==FALSE) {
				mysql_free_result($rs);
				mysql_query( "insert into rooms(loginname,price) values('".$loginname."',".$price.")",$db );
				mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','添加特殊房间号：".$loginname."')",$db );
				echo("<p align=center>特殊房间号".$loginname."成功添加！</p>");
			} else {
				mysql_free_result($rs);
				echo("<p align=center>特殊房间号".$loginname."已经存在，不能重复添加！</p>");
			}
		} elseif ($opertype=="delete") {		//删除
			$rs=mysql_query( "select price from rooms where loginname='".$loginname."'",$db );
			if ($row = mysql_fetch_array($rs)) {
				mysql_free_result($rs);
				mysql_query( "delete from rooms where loginname='".$loginname."'",$db );
				mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','删除特殊房间号：".$loginname."')",$db );
				echo("<p align=center>特殊房间号".$loginname."成功删除！</p>");
			} else {
				mysql_free_result($rs);
				echo("<p align=center>特殊房间号".$loginname."不存在！</p>");
			}
		} else {								//修改
			$rs=mysql_query( "select price from rooms where loginname='".$loginname."'",$db );
			if ($row = mysql_fetch_array($rs)) {
				mysql_free_result($rs);
				mysql_query( "update rooms set price=".$price." where loginname='".$loginname."'",$db );
				mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','修改特殊房间号单价：".$loginname."')",$db );
				echo("<p align=center>特殊房间号".$loginname."的单价成功修改！</p>");
			} else {
				mysql_free_result($rs);
				echo("<p align=center>特殊房间号".$loginname."不存在！</p>");
			}
		}
	}
?>

<div align="center">
  <center>
  <table border="1" width="500" height="39" bordercolor="#008080" cellspacing="0" cellpadding="0">
    <tr>
      <td width="140" align="center" height="30">房间号</td>
      <td width="314" align="center" height="30">结帐单价</td>
    </tr>

<?php
	$n=1;
	$rs = mysql_query("select loginname,price from rooms order by loginname",$db);
	while ($row = mysql_fetch_array($rs)) {
		echo("<tr>");
    	echo("<td>&nbsp;".$row["loginname"]."</td>");
	    echo("<td>");
		echo("<form name=form".strval($n)." method=POST action=rooms.php>");
    	echo("<input type=hidden name=opertype value=update>");
	    echo("<input type=hidden name=loginname value=".$row["loginname"].">");
		echo("<input type=text name=price size=8 value=".strval($row["price"]).">元");
    	echo("&nbsp;<input type=button value=修改 name=B1 onclick=".chr(34)."javascript:setoper(this)".chr(34).">");
    	echo("&nbsp;<input type=button value=删除 name=B2 onclick=".chr(34)."javascript:setoper(this)".chr(34).">");
		echo("</form>");
    	echo("</td>");
	    echo("</tr>");
    	$n=$n+1;
	}
    mysql_free_result($rs);
    mysql_close($db);
?>
  </table>
  </center>
</div>
<br>
      <form name=addform method=POST action=rooms.php>
      <p align="center">
      <input type=hidden name=opertype value=add>
      房间号<input type=text name=loginname size=20>
      单价<input type=text name=price size=8> 
      <input type=submit value=添加 name=B1> 
      </p>
      </form>
<p align="left">备注说明：特殊客房，一般是指酒店在房间内备有上网电脑的客房，此功能也是为此业务管理需求而设计。而且，即使是特殊客房，也只针对按天计费类型的客人有效，对其它计费类型的客人无效。特殊客房的客人，如果是按天计费类型，则结帐时，费用不是按统一的结算单价来计算，而是按照这里设定的房间号对应单价来计算。</p>
<hr>
<p align="center">SIP酒店上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>

</body>

</html>
