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

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="jscript">
//当点击超连接是显示组成员列表
function setresult(obj)
{
   var gpid=obj.href.match(/\d{1,}/);
   parent.gpinfo2.location.href="gpdetail1.php?gpid="+gpid;
}
//当删除组时刷新组详细信息和组成员列表为空
function setinfo1()
{
   if (document.form1.isdel.value=="y")
      {
       parent.gpinfo1.location.href="gpdetail.php";
       parent.gpinfo2.location.href="gpdetail1.php";
      }
}
</script>
<title>用户组列表</title>
<base target="_self">

<body background="bkg.bmp" style="background-attachment:fixed; background-position-y:200;" onload="setinfo1();">
<center>
<p align="center"><font size="3"><b>用户组列表</b></font></p>
<?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);
   $ispostback=$_REQUEST["ispostback"];                     //是否为回送
   $isdel="n";                                                 //反映是否删除了组
   if ($ispostback=="y") {
         echo("<table><tr><td align=left>");
         if ($_REQUEST["count"]!="") {              
            $gpcount=intval($_REQUEST["count"]);                 //当前页显示的组的数量
            for($i=1;$i<=$gpcount;$i++) {                        //删除组
               $del=$_REQUEST["del".strval($i)];
               if ($del=="del") {
                  $gpid=$_REQUEST["gp_id".strval($i)];
                  $rs=mysql_query("select gpname from groups where gpid=".$gpid,$db);
                  if ( ($row = mysql_fetch_array($rs))==FALSE ) {
                     echo("·要删除的用户组不存在<br>");
				  }
                  else {
					 mysql_free_result($rs);
                     mysql_query("delete from groups where gpid=".$gpid,$db);
                     mysql_query("update users set gpid=0 where gpid=".$gpid,$db);
                     mysql_query("insert into operation values('".$_SESSION["operator"]."','".$timestr."','删除用户组，组号：".$gpid.",组名：".$row["gpname"]."')",$db );
                     echo("<font size='2'>·".$row["gpname"]."已经被成功删除,用户表中所有该组用户的组别已被更新为无<br><font>");
                  }
                  $isdel="y";
               }
            }
         }
         echo("</td></tr></table>");
   }
?>
<form name="form1" method="POST" action="querygp.php">
<?php  
   $rs=mysql_query("select gpid,gpname from groups order by gpname",$db);
   if ( ($row = mysql_fetch_array($rs))==FALSE ) { 
      echo("<p align='center'>没用户组</p>");
      echo("<input type='hidden' name='isdel' value='".$isdel."'>");
   }
   else {
	  echo("<table border='1' bordercolor='#008080' cellspacing='0' cellpadding='0'>");
      echo("<tr><td align='center'>组名</td><td align='center'>删除该组</td></tr>");
      $n=0;
      while ($row) {
         $n=$n+1;
         echo("<tr>");
         echo("<td align='center'>&nbsp;<a href='gpdetail.php?gpid=".strval($row[0])."' target='gpinfo1' title='点击查看详细信息' onclick='setresult(this);'>".$row[1]."</a></td>");
         echo("<input type=hidden name=gp_id".strval($n)." value=".strval($row[0]).">");
         echo("<td align='center'>&nbsp;<input type=checkbox value=del name=del".strval($n)."></td>");
         echo("</tr>");
         $row = mysql_fetch_array($rs);
      }
      echo("</table>");
      echo("<br><input type='submit' name='b1' value='删除'><br>");
      echo("<br><font size='2'>1.点击组名以显示该组详细信息<br>2.如果删除用户组，用户表中所<br>有该组用户的组别将被更新为无</font>");
      echo("<input type='hidden' name='count' value='".strval($n)."'>");
      echo("<input type='hidden' name='ispostback' value='y'>");
      echo("<input type='hidden' name='isdel' value='".$isdel."'>");
   }
   mysql_free_result($rs);
   mysql_close($db);
?>
</form>
</center>
</body>
</html>
