<?php
include("CheckSession.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="馬戲團" />
<title>馬戲團</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<?php

require_once("class/DBConfig.php");
require_once("class/DBOperation.php");

//设定每一页显示的记录数
$pagesize=20;

//取得记录总数，计算总页数用
$db = new DBOperation();
$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
$db->query("select count(*) from AdminUser where AFlag <> '2'");
$row = $db->fetch_row();
$db->close_db();
$numrows = $row[0];

//?算???
$pages=intval($numrows/$pagesize);

if($numrows%$pagesize)
{
	$pages++;
}
$page = $_GET["page"];
//判????置与否，如??定??首?
if(!isset($page))
{
  $page=1;
}
//判??到??
//if(isset($ys))
//{
//  if($ys>$pages)
//  {
//  	$page=$pages;
//  }
//  else
//  {     
//  	$page=$ys;
//  }
//}

//?算??偏移量     
$offset=$pagesize*($page-1);
$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
$querySql = "";

if($_SESSION['rightLevel'] == "0")
{
	$querySql = "select AId,AName,AAccount,AFlag,GName from AdminUser,GroupRights where AGroupId = GId and AFlag <> '2' order by AId limit $offset,$pagesize";
}
elseif($_SESSION['rightLevel'] == "1")
{
	$querySql = "select AId,AName,AAccount,AFlag,GName from AdminUser,GroupRights where AGroupId = GId And AGroupId = ".$_SESSION['groupId']." And AId <> ".$_SESSION['userId']." and and AFlag <> '2' order by AId limit $offset,$pagesize";
}

$db->query($querySql);

?>
<SCRIPT language="JavaScript">
function checkDelete(id)
{
	if(confirm("確定要刪除嗎????"))
	{
     location.href = "AdminUserDeleteDeal.php?id=" + id;
	}
}
</SCRIPT>
<body>
<form name="form" method="post" action="AdminUserInput.php?action=Insert">
<table border="0" cellspacing="1" cellspadding="1" width="95%">
<!--
<tr>
<td align="center" colspan="2">
<span class="title"><b>使用者管理</b></span>
</td>
</tr>
-->
<tr>
<td align="center" colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td align="left" colspan="2">
<input type="submit" name="btnSub" id="btnSub" value="新增使用者" class="t12" />
</td>
</tr>
<tr>
<td align="left" colspan="2" width="100%">
<?php
if($myrow = $db->fetch_array())     
{     
  $i=0;     
  ?>       
  <table width="100%" border="1" cellspacing="2" cellpadding="2">     
  <tr>     
  <td width="10%" bgcolor="#E1E9FB" align="center"><span class="t12r">序號</span></td>     
  <td width="30%" bgcolor="#E1E9FB" align="center"><span class="t12r">姓名</span></td>
  <td width="15%" bgcolor="#E1E9FB" align="center"><span class="t12r">帳號</span></td>
  <td width="15%" bgcolor="#E1E9FB" align="center"><span class="t12r">所屬群組</span></td>
  <td width="8%" bgcolor="#E1E9FB" align="center"><span class="t12r">狀態</span></td>
  <td width="10%" bgcolor="#E1E9FB" align="center"><span class="t12r">修改</span></td>
  <td width="10%" bgcolor="#E1E9FB" align="center"><span class="t12r">刪除</span></td>
  </tr>     
  <?php
  $index = 0;
  do{  	    
    $i++;    
  ?>     
	  <tr>     
	  <td bgcolor="#E6F2FF"><?php echo $myrow['AId'];?></td>     
	  <td bgcolor="#E6F2FF">
	  <span class="t12">
	  <?php echo $myrow['AName'];?></span></td>
	  <td bgcolor="#E6F2FF">
	  <span class="t12">
	  <?php echo $myrow['AAccount'];?></span></td>
	  <td bgcolor="#E6F2FF">
	  <span class="t12">
	  <?php echo $myrow['GName'];?></span></td>
	  <td bgcolor="#E6F2FF">
	  <span class="t12">
	  <?php if($myrow['AFlag'] == "1") echo "啟用"; else echo "停用";?></span></td>
	  <td bgcolor="#E6F2FF" align="center">
	  <span class="t12">
	  <a href="AdminUserInput.php?action=Update&id=<?php echo $myrow['AId'];?>")">
	  <b>修改</b></a></span></td>	  
	  <td bgcolor="#E6F2FF" align="center">
	  <span class="t12">
	  <?php if($myrow['AAccount'] != "admin")
	  {
	  ?>
	  <a href="javascript:void(0);" onclick="checkDelete('<?php echo $myrow['AId'];?>');">
	  <b>刪除</b></a></span>
	  <?php
	  }
	  else
	  {
	  	echo "&nbsp;";
	  }
	  ?>
	  </td>
	 
	  </tr>     
  <?php     
  }while($myrow = $db->fetch_array());
  echo "</table>"   ;     
  }     
  //?示???     
  echo "<br><div align='left'>共有".$pages."頁 (".$page."/".$pages.")<br><br>";     
  //?示分??     
  for($i=1;$i<$page;$i++)     
  echo "&nbsp;<a href='AdminUserIndex.php?page=".$i."'>第".$i."頁</a>&nbsp;";     
  echo "第".$page."頁";     
  for($i=$page+1;$i<=$pages;$i++)     
  echo "&nbsp;<a href='AdminUserIndex.php?page=".$i."'>第".$i."頁</a>&nbsp;";
  //echo "<br><br>";     
  //?示?到??     
  //echo "<form action='AdminUserIndex.php' method='post'>";     
  //?算首?、上一?、下一?、尾?的??值     
  $first=1;     
  $prev=$page-1;     
  $next=$page+1;     
  $last=$pages;     
  if($page>1)     
  {     
	  //echo "&nbsp;<a href='AdminUserIndex.php?page=".$first."'>首頁</a>&nbsp;";     
	  //echo "&nbsp;<a href='AdminUserIndex.php?page=".$prev."'>上一頁</a>&nbsp;";     
  }     
  if($page<$pages)     
  {     
	  //echo "&nbsp;<a href='fenye.php?page=".$next."'>下一頁</a>&nbsp;";     
	  //echo "&nbsp;<a href='fenye.php?page=".$last."'>尾頁</a>&nbsp;";     
  }     
  //echo "到&nbsp;<input type=text name='ys' size='2' value=".$page.">&nbsp;頁";     
  //echo "<input type=submit name='Submit' value='Go'>";     
  //echo "</form>";     
  echo "</div>"; 
?>
</td>
</tr>
</table>
</form>
</body>
</html>
