<?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 GroupRights");
$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']);
$db->query("select GId,GName from GroupRights order by GId limit $offset,$pagesize");

?>
<SCRIPT language="JavaScript">
function checkDelete(id)
{
	if(confirm("確定要刪除嗎????"))
	{
     location.href = "GroupRightsDeleteDeal.php?id=" + id;
	}
}
</SCRIPT>
<body>
<form name="form" method="post" action="GroupRightsInput.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="45%" 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['GId'];?></td>     
	  <td bgcolor="#E6F2FF">
	  <span class="t12">
	  <?php echo $myrow['GName'];?></span></td>	  
	  <td bgcolor="#E6F2FF" align="center">
	  <span class="t12">
	  <a href="GroupRightsInput.php?action=Update&id=<?php echo $myrow['GId'];?>")">
	  <b>修改</b></a></span></td>
	  <td bgcolor="#E6F2FF" align="center">
	  <span class="t12">	  
	  <a href="javascript:void(0);" onclick="checkDelete('<?php echo $myrow['GId'];?>');">
	  <b>刪除</b></a></span></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='GroupRightsIndex.php?page=".$i."'>第".$i."頁</a>&nbsp;";     
  echo "第".$page."頁";     
  for($i=$page+1;$i<=$pages;$i++)     
  echo "&nbsp;<a href='GroupRightsIndex.php?page=".$i."'>第".$i."頁</a>&nbsp;";
  //echo "<br><br>";     
  //?示?到??     
  //echo "<form action='GroupRightsIndex.php' method='post'>";     
  //?算首?、上一?、下一?、尾?的??值     
  $first=1;     
  $prev=$page-1;     
  $next=$page+1;     
  $last=$pages;     
  if($page>1)     
  {     
	  //echo "&nbsp;<a href='GroupRightsIndex.php?page=".$first."'>首頁</a>&nbsp;";     
	  //echo "&nbsp;<a href='GroupRightsIndex.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>
