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

<?php
	$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
	mysql_select_db(get_cfg_var("SIPDB"),$db);
	$userid=$_REQUEST["userid"];
	$loginname=$_REQUEST["loginname"];
	if ($userid!="") {
		$sqlstr="select userid,loginname,username,gpid from users where userid='".$userid."' and checked='n'";
	}
	else {
		$sqlstr="select userid,loginname,username,gpid from users where loginname='".$loginname."' and checked='n'";
	}
	$rs=mysql_query($sqlstr,$db);
	if ( ($row = mysql_fetch_array($rs))==FALSE ) {
		mysql_free_result($rs);
		mysql_close($db);
		echo("不存在此用户ID！");
		exit;
	}
	$userid=$row["userid"];
	$loginname=$row["loginname"];
	$username=$row["username"];
	$gpid=strval($row["gpid"]);
	mysql_free_result($rs);
	$gpname="";
	if ($gpid!="0") {			//有组别
		$rs=mysql_query("select gpname from groups where gpid=".$gpid,$db);
		if ($row = mysql_fetch_array($rs)) {
			$gpname=$row["gpname"];
		}
		else {
			$gpid="0";
		}
		mysql_free_result($rs);
	}
	for ($n=1;$n<=7;$n++) {
		$settime[$n]="";
		$rs=mysql_query("select starttime,endtime from allowtimelist where userid='".$userid."' and weeknumber=".strval($n)." order by starttime",$db);
		while ($row = mysql_fetch_array($rs)) {
			$starttime=$row["starttime"];
			$endtime=$row["endtime"];
			if ($settime[$n]=="") {
				$settime[$n]=$starttime."-".$endtime;
			}
			else {
				$settime[$n]=$settime[$n].",".$starttime."-".$endtime;
			}
		}
		mysql_free_result($rs);
	}
	$settime0="";
	$rs=mysql_query("select starttime,endtime from allowtimelist where userid='".$userid."' and weeknumber=0 order by starttime",$db);
	while ($row = mysql_fetch_array($rs)) {
		$starttime=$row["starttime"];
		$endtime=$row["endtime"];
		if ($settime0=="") {
			$settime0=$starttime."-".$endtime;
		}
		else {
			$settime0=$settime0.",".$starttime."-".$endtime;
		}
	}
	mysql_free_result($rs);
	$settype=3;
	if ($settime0!="") {
		$settype=1;
	}
	else {
		if ($settime[1]!="" || $settime[2]!="" || $settime[3]!="" || $settime[4]!="" || $settime[5]!="" || $settime[6]!="" || $settime[7]!="") {
			$settype=2;
		}
	}
	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>

<SCRIPT LANGUAGE="javascript">
function myload()
{
	document.form1.settype.value="<?php echo $settype; ?>";
	if (document.form1.settype.value=="1") {
        document.all.time0.style.display="";
		document.form1.settype[0].checked=true;
	}
	else {
        document.all.time0.style.display="none";
	}
	if (document.form1.settype.value=="2") {
        document.all.time1.style.display="";
        document.all.time2.style.display="";
        document.all.time3.style.display="";
        document.all.time4.style.display="";
        document.all.time5.style.display="";
        document.all.time6.style.display="";
        document.all.time7.style.display="";
		document.form1.settype[1].checked=true;
	}
	else {
        document.all.time1.style.display="none";
        document.all.time2.style.display="none";
        document.all.time3.style.display="none";
        document.all.time4.style.display="none";
        document.all.time5.style.display="none";
        document.all.time6.style.display="none";
        document.all.time7.style.display="none";
	}
}

function SetValue()
{
	cancelBubble=true;
	if (document.form1.settype[0].checked) {
        document.all.time0.style.display="";
        document.all.time1.style.display="none";
        document.all.time2.style.display="none";
        document.all.time3.style.display="none";
        document.all.time4.style.display="none";
        document.all.time5.style.display="none";
        document.all.time6.style.display="none";
        document.all.time7.style.display="none";
	}
	else {
		if (document.form1.settype[1].checked) {
	        document.all.time0.style.display="none";
    	    document.all.time1.style.display="";
       		document.all.time2.style.display="";
	        document.all.time3.style.display="";
    	    document.all.time4.style.display="";
	       	 document.all.time5.style.display="";
    	    document.all.time6.style.display="";
       		 document.all.time7.style.display="";
		}
		else {
	        document.all.time0.style.display="none";
	        document.all.time1.style.display="none";
	        document.all.time2.style.display="none";
	        document.all.time3.style.display="none";
	        document.all.time4.style.display="none";
	        document.all.time5.style.display="none";
	        document.all.time6.style.display="none";
	        document.all.time7.style.display="none";
		}
	}
}
</SCRIPT>

</head>

<body background="bkg.bmp" onload="javascript:myload();">

<p align="center"><font size="5"><b>用户每天允许上网时间管理</b></font></p>
<hr color="#999966">

<form name="form1" method="post" action="userallowtime2.php">
<input type=hidden name=loginname value=<?php echo $loginname; ?>>
<input type=hidden name=userid value=<?php echo $userid; ?>>
<div align="center">
  <center>
  <table border="1" width="93%" bordercolor="#008080" cellspacing="0" cellpadding="5">
    <tr>
      <td width="29%" height="38">用户ID</td>
      <td width="71%" height="38">
        <p align="center"><?php echo $loginname; ?></td>
    </tr>
    <tr>
      <td width="29%" height="38">用户名称</td>
      <td width="71%" height="38">
        <p align="center">&nbsp;<?php echo $username; ?></td>
    </tr>
    <tr>
      <td width="29%" height="38">所属组别</td>
      <td width="71%" height="38">
      <p align="center">&nbsp;      
      <?php
      if ($gpid!="0") {
      		echo("<a href=groupallowtime1.php?gpid=".$gpid."&gpname=".$gpname." target=_blank>".$gpname."</a>");
      }
      ?>
      </td>
    </tr>
    <tr>
      <td width="29%" height="38">设置方式</td>
      <td width="71%" height="38">
      <input type="radio" value="1" name="settype" onclick="SetValue(this);">每天全部相同&nbsp;   
      <input type="radio" name="settype" value="2" onclick="SetValue(this);">每天单独设置&nbsp;   
      <input type="radio" name="settype" value="3" checked onclick="SetValue(this);">无限制
      </td>
    </tr>
    <tr id="time0">
      <td width="29%" height="38">每天允许上网时间段</td>
      <td width="71%" height="38">
      <p align="center">
      <input type="text" name="settime0" size="50" value="<?php echo $settime0; ?>">
      </p>
      </td>
    </tr>
    <tr id="time1">
      <td width="29%" height="38">周一允许上网时间段</td>
      <td width="71%" height="38">
      <p align="center">
      <input type="text" name="settime1" size="50" value="<?php echo $settime[1]; ?>">
      </p>
      </td>
    </tr>
    <tr id="time2">
      <td width="29%" height="38">周二允许上网时间段</td>
      <td width="71%" height="38">
      <p align="center">
      <input type="text" name="settime2" size="50" value="<?php echo $settime[2]; ?>">
      </p>
      </td>
    </tr>
    <tr id="time3">
      <td width="29%" height="38">周三允许上网时间段</td>
      <td width="71%" height="38">
      <p align="center">
      <input type="text" name="settime3" size="50" value="<?php echo $settime[3]; ?>">
      </p>
      </td>
    </tr>
    <tr id="time4">
      <td width="29%" height="38">周四允许上网时间段</td>
      <td width="71%" height="38">
      <p align="center">
      <input type="text" name="settime4" size="50" value="<?php echo $settime[4]; ?>">
      </p>
      </td>
    </tr>
    <tr id="time5">
      <td width="29%" height="38">周五允许上网时间段</td>
      <td width="71%" height="38">
      <p align="center">
      <input type="text" name="settime5" size="50" value="<?php echo $settime[5]; ?>">
      </p>
      </td>
    </tr>
    <tr id="time6">
      <td width="29%" height="38">周六允许上网时间段</td>
      <td width="71%" height="38">
      <p align="center">
      <input type="text" name="settime6" size="50" value="<?php echo $settime[6]; ?>">
      </p>
      </td>
    </tr>
    <tr id="time7">
      <td width="29%" height="38">周日允许上网时间段</td>
      <td width="71%" height="38">
      <p align="center">
      <input type="text" name="settime7" size="50" value="<?php echo $settime[7]; ?>">
      </p>
      </td>
    </tr>
    <tr>
      <td width="100%" height="39" colspan="2">
        <p align="center"><input type="submit" value="提交" name="B1"></td>
    </tr>
  </table>
  </center>
</div>
</form>

<p>说明：</p>
<p>1、允许上网时间段，设置格式为：hh:mm-hh:mm,hh:mm-hh:mm,hh:mm-hh:mm。hh:mm-hh:mm，表示从xx时xx分到xx时xx分，这段时间可以上网。如果存在多个时间段，时间段之间以“,”（<b>英文的逗号，非中文的逗号</b>）隔开。例如，09:00-09:30,12:00-13:00,17:30-18:00。</p>
<p>2、开始时间和结束时间，只能设置xx时xx分，不精确到秒。时间是24小时制，下午时间从13点开始。</p>
<p>3、开始时间和结束时间，格式都是hh:mm，例如从12:00到13:00。不足2位数字的，前面要以0补齐。例如从09:05到09:35。如时间格式不对，就可能无法达到实际的控制效果，后果自负。</p>
<p>4、每天，总共可以设置10个允许上网的时间段。不在设置时间段的范围，则用户被禁止上网。</p>
<p>5、每天设置的时间段，时间范围不能存在重叠或交叉，跨度必须互相分隔。</p>
<p>6、如果是“每天单独设置”的方式，而且某天没有设置，则视作该天没有上网时间限制，可在全天任意时候上网。</p>
<p>7、如果一个用户所属组别也存在设置的每天允许上网时间段，同时也设置该用户自身的允许时间段，则以该用户自身的设置为准，再不受其组别设置的影响。</p>

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

</html>
