<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<13>")) {	//没有权限
		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 6.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">
<?php
	$timestr=strftime("%Y-%m-%d %H:%M:%S");
	$userid=trim($_REQUEST["userid"]);
	$loginname=trim($_REQUEST["loginname"]);
	$gpname=trim($_REQUEST["gpname"]);
	$gpid="0";
	$oldgpid=$_REQUEST["oldgpid"];
	if ($oldgpid=="") {
	  $oldgpid="0";
	}
	$username=trim($_REQUEST["username"]);
	$usertel=trim($_REQUEST["usertel"]);
	$comment=trim($_REQUEST["comment"]);
	$ipaddr=trim($_REQUEST["ipaddr"]);
	$password=trim($_REQUEST["password"]);
	$timelength=trim($_REQUEST["timelength"]);
	$datalength=trim($_REQUEST["datalength"]);
	$userdept=trim($_REQUEST["userdept"]);
	$daytime=trim($_REQUEST["daytime"]);
	$daydata=trim($_REQUEST["daydata"]);
	$mac=trim($_REQUEST["mac"]);
	$band=trim($_REQUEST["band"]);
	if ($timelength=="") {
		$timelength="0";
	}
	if ($datalength=="") {
		$datalength="0";
	}
	if ($daytime=="") {
		$daytime="0";
	}
	if ($daydata=="") {
		$daydata="0";
	}
	if ($userid!="" && $loginname!="" && $password!="") {						//必须输入用户ID
		$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 from users where loginname='".$loginname."' and userid!='".$userid."' and checked='n'",$db );
		if ( ($row = mysql_fetch_array($rs))==FALSE ) {										//没有找到，没有其它相同用户ID
			mysql_free_result($rs);
            if ($gpname!="") {   
               $isnewgp="n";
               $rs=mysql_query("select * from groups where gpname='".$gpname."'",$db);     //判断是否需要建立新用户组
               if ( ($row = mysql_fetch_array($rs))==FALSE ) {
                  mysql_free_result($rs);
				  $gpid=strval(time()-strtotime("2005-01-01 01:01:01"));	//生成一个唯一组ID号
                  mysql_query("insert into groups(gpid,gpname,createtime,comment) values(".$gpid.",'".$gpname."','".$timestr."','')",$db);
                  $isnewgp="y";
                  echo("所输入组别为新组别，已成功创建<br>");
				}
               else {
                  mysql_free_result($rs);
               }        
				if ($isnewgp=="y") {
				   mysql_query("insert into operation values('".$_SESSION["operator"]."','".$timestr."','创建新用户组，组号：".$gpid.",组名：".$gpname."')",$db );
				}						
            }
            if ($gpname!="") {        //提取组别号
               $rs=mysql_query("select gpid from groups where gpname='".$gpname."'",$db);
			   $row = mysql_fetch_array($rs);
               $gpid=strval($row["gpid"]);
               mysql_free_result($rs);
            }
			mysql_query( "update users set loginname='".$loginname."',password='".$password."',gpid=".$gpid.",username='".$username."',usertel='".$usertel."',comment='".$comment."',ipaddr='".$ipaddr."',timelength=".$timelength.",datalength=".$datalength.",userdept='".$userdept."',daytime=".$daytime.",daydata=".$daydata.",mac='".$mac."' where userid='".$userid."'",$db );
			mysql_query( "delete from userband where loginname='".$loginname."'",$db );
			if ($band!="0") {
				mysql_query( "insert into userband values('".$loginname."',".$band.",0)",$db );
			}
			mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','修改用户属性，用户ID：".$userid."')",$db );
			if ($oldgpid!=$gpid) {
			   if ($gpid!="0") {
			      mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','添加组别成员,组号：".$gpid.",用户ID：".$userid."')",$db );
			   } else {
			      mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','删除组别成员,组号：".$oldgpid.",用户ID：".$userid."')",$db );
			   }
			}
			echo("修改成功！");
		} else {
			mysql_free_result($rs);
			echo("错误，该用户ID已经存在！");
		}
		mysql_close($db);
	} else {
		echo("必须输入用户ID和密码");
	}
?>
</p>
<hr>
<p align="center">SIP企业上网管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>

</body>

</html>
