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

<?php
	$userid=$_REQUEST["userid"];
	$loginname=$_REQUEST["loginname"];
	if ($userid=="" || $loginname=="") {
		echo("非法操作！");
		exit;
	}
	$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
	mysql_select_db(get_cfg_var("SIPDB"),$db);
	mysql_query( "delete from allowtimelist where userid='".$userid."'",$db );
	$settype=trim($_REQUEST["settype"]);
	if ($settype=="1") {		//全部相同
		$settime=trim($_REQUEST["settime0"]);
		if ($settime!="") {
			$n1=0;
			$n2=0;
			$n2=strpos($settime,",",$n1);
			while ($n2>0) {
				$tmpstr=substr($settime,$n1,$n2-$n1);
				$n3=strpos($tmpstr,"-",0);
				if ($n3>0) {
					$starttime=substr($tmpstr,0,$n3);
					$endtime=substr($tmpstr,$n3+1);
					if (strlen($starttime)==5 && strlen($endtime)==5) {
						mysql_query( "insert into allowtimelist values('".$userid."',0,'".$starttime."','".$endtime."')",$db );
					}
				}
				$n1=$n2+1;
				$n2=strpos($settime,",",$n1);
			}
			$tmpstr=substr($settime,$n1);
			$n3=strpos($tmpstr,"-",0);
			if ($n3>0) {
				$starttime=substr($tmpstr,0,$n3);
				$endtime=substr($tmpstr,$n3+1);
				if (strlen($starttime)==5 && strlen($endtime)==5) {
					mysql_query( "insert into allowtimelist values('".$userid."',0,'".$starttime."','".$endtime."')",$db );
				}
			}
		}
	}
	else {
		if ($settype=="2") {
			for($n=1;$n<=7;$n++) {
				$settime=trim($_REQUEST["settime".strval($n)]);
				if ($settime!="") {
					$n1=0;
					$n2=0;
					$n2=strpos($settime,",",$n1);
					while ($n2>0) {
						$tmpstr=substr($settime,$n1,$n2-$n1);
						$n3=strpos($tmpstr,"-",0);
						if ($n3>0) {
							$starttime=substr($tmpstr,0,$n3);
							$endtime=substr($tmpstr,$n3+1);
							if (strlen($starttime)==5 && strlen($endtime)==5) {
								mysql_query( "insert into allowtimelist values('".$userid."',".strval($n).",'".$starttime."','".$endtime."')",$db );
							}
						}
						$n1=$n2+1;
						$n2=strpos($settime,",",$n1);
					}
					$tmpstr=substr($settime,$n1);
					$n3=strpos($tmpstr,"-",0);
					if ($n3>0) {
						$starttime=substr($tmpstr,0,$n3);
						$endtime=substr($tmpstr,$n3+1);
						if (strlen($starttime)==5 && strlen($endtime)==5) {
							mysql_query( "insert into allowtimelist values('".$userid."',".strval($n).",'".$starttime."','".$endtime."')",$db );
						}
					}
				}
			}
		}
	}
	
	$timestr=strftime("%Y-%m-%d %H:%M:%S");
	mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','设置用户每天允许上网时间，用户ID：".$userid."')",$db );
	mysql_close($db);
?>

<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">用户 <?php echo $loginname; ?>”的每天允许上网时间设置保存成功！</p>

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

</html>
