<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php
if ((isset($_GET['check_id'])) && ($_GET['check_id'] != "")) {

  $deleteSQL = sprintf("DELETE FROM user WHERE level<'%s' AND id='%s'",$_SESSION['login_lv'],$_GET['check_id']);
  mysql_select_db($database_BE2, $BE2);
  $Result1= mysql_query($deleteSQL, $BE2) or die(mysql_error());
 
}
 

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Rt2 = 10;
$pageNum_Rt2 = 0;
if (isset($_GET['pageNum_Rt2'])) {
  $pageNum_Rt2 = $_GET['pageNum_Rt2'];
}
$startRow_Rt2 = $pageNum_Rt2 * $maxRows_Rt2;

mysql_select_db($database_BE2, $BE2);
if($myadmin){
	$query_Rt2 = sprintf("SELECT * FROM user where fn='Y' AND level<'%s' ORDER BY id ASC",$_SESSION['login_lv']);
	} else{
 $query_Rt2 = sprintf("SELECT * FROM user where fn='Y' AND level<'%s' AND stat='%s' ORDER BY id ASC",$_SESSION['login_lv'],$_SESSION['login_group']);
 }
$query_limit_Rt2 = sprintf("%s LIMIT %d, %d", $query_Rt2, $startRow_Rt2, $maxRows_Rt2);
$Rt2 = mysql_query($query_limit_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);

if (isset($_GET['totalRows_Rt2'])) {
  $totalRows_Rt2 = $_GET['totalRows_Rt2'];
} else {
  $all_Rt2 = mysql_query($query_Rt2);
  $totalRows_Rt2 = mysql_num_rows($all_Rt2);
}
$totalPages_Rt2 = ceil($totalRows_Rt2/$maxRows_Rt2)-1;

$queryString_Rt2 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Rt2") == false && 
        stristr($param, "totalRows_Rt2") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Rt2 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Rt2 = sprintf("&totalRows_Rt2=%d%s", $totalRows_Rt2, $queryString_Rt2);
?>
 <div class="row">
 <div class="col-md-12">
				
 <div class="panel panel-default">
        <div class="panel-heading">
							<h3 class="panel-title">帳號管理</h3>
							
							<div class="panel-options">
								<a href="main.php?act=user_add">
									<i class="fa-plus"></i>
								</a>
							</div>
						</div> 
<?php if ($totalRows_Rt2 > 0) { // Show if recordset not empty ?>
<div id="content" align="center">
 <table cellspacing="0" class="table table-small-font table-bordered table-striped">
        <tr>
          <th align="center" valign="top" nowrap="nowrap" class="font2">使用者帳號</th>
          <th valign="top" nowrap="nowrap" class="font2">密碼</th>
          <th align="center" valign="top" class="font2">編輯</th>
          <th align="center" valign="middle" class="font2">刪除</th>
        </tr>
        <?php do { ?>
        <tr>
          <th width="30%" align="center" valign="top" nowrap="nowrap" class="font3"><?php echo $row_Rt2['name']; ?></th>
          <td width="37%" align="center" valign="top" class="font3">******</td>
          <td width="16%" align="center" valign="top" class="font3"><a href="main.php?act=user_edit&id=<?php echo $row_Rt2['id']; ?>"><img src="images/edit.png" alt="修改項目名稱" width="16" height="16" border="0" /></a></td>
          <td width="17%" align="center" valign="middle" class="font3"><a href="javascript:if(confirm('確定要刪除嗎?'))location='<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, $pageNum_Rt2 , $queryString_Rt2)?><? echo "&check_id=".$row_Rt2['id']; ?>'"><img src="images/del.png" alt="刪除項目" width="16" height="16" border="0"/></a></td>
        </tr>
 
        <?php } while ($row_Rt2 = mysql_fetch_assoc($Rt2)); ?>
        <tr>
          <td height="3" colspan="4" align="center" ><table border="0">
            <tr>
              <td><?php if ($pageNum_Rt2 > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, 0, $queryString_Rt2); ?>">第一頁</a>
                <?php } // Show if not first page ?></td>
              <td><?php if ($pageNum_Rt2 > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, max(0, $pageNum_Rt2 - 1), $queryString_Rt2); ?>">上一頁</a>
                <?php } // Show if not first page ?></td>
              <td><?php if ($pageNum_Rt2 < $totalPages_Rt2) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, min($totalPages_Rt2, $pageNum_Rt2 + 1), $queryString_Rt2); ?>">下一頁</a>
                <?php } // Show if not last page ?></td>
              <td><?php if ($pageNum_Rt2 < $totalPages_Rt2) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, $totalPages_Rt2, $queryString_Rt2); ?>">最後一頁</a>
                <?php } // Show if not last page ?></td>
            </tr>
          </table></td>
        </tr>
      </table>
</div>
<?php } // Show if recordset not empty ?>
<!-- end #content -->
<!-- end #sidebar -->
<?php if ($totalRows_Rt2 == 0) { // Show if recordset empty ?>
<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>尚無使用者、請新增</td>
  </tr>
</table>

 
<?php } // Show if recordset empty ?>
</div>
</div>
</div>
<?php
mysql_free_result($Rt2);
?>
