<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php
/*
if(isset($_GET['del_id']) && ( $_GET['del_id']>0 )){
mysql_select_db($database_BE2, $BE2);
$delete_SQL = sprintf("delete from tb2 WHERE buid='%s'",$_GET['del_id']);
$Rt2 = mysql_query($delete_SQL, $BE2) or die(mysql_error());
}
*/

if ((isset($_POST["ran"])) && ($_POST["ran"] == "1111")) { 
   $updaterand = "UPDATE tb2 SET buind = FLOOR((1+RAND( ) + RAND( ) )*1000) WHERE buind >1000";
   mysql_select_db($database_BE2, $BE2);
   $Result1 = mysql_query($updaterand, $BE2) or die(mysql_error());
}


$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Rt2 = 15;
$pageNum_Rt2 = 0;
if (isset($_GET['pageNum_Rt2'])) {
  $pageNum_Rt2 = $_GET['pageNum_Rt2'];
}
$startRow_Rt2 = $pageNum_Rt2 * $maxRows_Rt2;

$colname_Rt2 = "-1";
if (isset($_GET['keyword'])) {
  $colname_Rt2 = $_GET['keyword'];
}


mysql_select_db($database_BE2, $BE2);
if ($colname_Rt2=='-1') { $query_Rt2 = "SELECT a.*,b.cuid FROM tb2 as a left join cuser as b on a.cuid4=b.cuid where 1 order by bc3,buind";}else{
	$query_Rt2 = sprintf("SELECT a.*,b.cuid FROM tb2 as a left join cuser as b on a.cuid4=b.cuid where a.bc2 like '%s' ORDER BY bc2 DESC",'%'.$colname_Rt2.'%');
	}

//$Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
//$row_Rt2 = mysql_fetch_assoc($Rt2);
//$totalRows_Rt2  = mysql_num_rows($Rt2); 

$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, "act") == 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);






?>
<form id="form1" name="form1" method="GET" action="">
 客戶快速搜尋
    <input type="text" name="keyword" id="keyword" />
    <input name="act" type="hidden" id="act" value="settb2" />
<input type="submit" name="Submit" value="送出" />

</form> 

<form id="form2" name="form2" method="POST" action="">
     <input name="ran" type="hidden" id="ran" value="1111"  />
    <input name="act2" type="hidden" id="act2" value="settb2" />
    <input type="submit" name="Submit" value="重置新亂數排列" />

</form> 
  <table width="871" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <th width="2%" nowrap="nowrap" class="font2">ID</th>
      <th width="18%" nowrap="nowrap" class="font2">公司名稱</th>
      <th width="9%" nowrap="nowrap" class="font2">縣市分區</th>
      <th width="9%" nowrap="nowrap" class="font2">分區</th>
      <th nowrap="nowrap" class="font2">通訊處</th>
      <th nowrap="nowrap" class="font2">電話FAX</th>
      <th nowrap="nowrap" class="font2">廣告城市</th>
      <th nowrap="nowrap" class="font2">網站</th>
      <th nowrap="nowrap" class="font2">啟用</th>
      <th nowrap="nowrap" class="font2">廣告</th>
      <th nowrap="nowrap" class="font2">排列值</th>
      <th nowrap="nowrap" class="font2">刪除</th>
    </tr>
    <?php 
	 if($totalRows_Rt2>0){ 
	  do { ?>
    <tr>
      <td align="center" class="font3"><a href="main.php?act=edittb2&amp;id=<?php echo $row_Rt2['buid']; ?>"><img src="images/edit.png" alt="修改項目名稱" title="修改項目名稱" width="16" height="16" border="0" /></a></td>
      <td align="center" class="font3"><?php echo $row_Rt2['bc2']; ?></td>
      <td align="center" class="font3"><?php echo $row_Rt2['bc3']; ?></td>
      <td align="center" class="font3"><?php echo $row_Rt2['bc4']; ?></td>
      <td width="26%" align="center" class="font3"><?php echo $row_Rt2['bc5']; ?>

      </td>
      <td width="18%" align="center" class="font3"><?php echo $row_Rt2['bc6']; ?></td>
      <td width="5%" align="center" class="font3"><a href="main.php?act=cuser_city2&amp;id=<?php echo $row_Rt2['buid']; ?>"><img src="images/browse.png" alt="修改項目名稱" width="32" height="32" border="0" /></a></td>
      <td width="5%" align="center" class="font3"><? if($row_Rt2['cuid']>0){?><a href="main.php?act=cuser_ad2&webid=<?= $row_Rt2['cuid']; ?>"><img src="images/w.png" width="26" height="26" /></a><? }else{?>
        <a href="main.php?act=cuser_addweb&id=<?= $row_Rt2['buid']; ?>"><img src="images/e.png" width="26" height="26" /></a><? } ?></td>
      <td width="4%" align="center" class="font3"><a href="#"><img src="images/<?php echo $row_Rt2['tb2flag']; ?>.png" width="26" height="26" /></a></td>
      <td width="4%" align="center" class="font3"><a href="#"><img src="images/N.png" width="26" height="26" /></a></td>
      <td width="9%" align="center" class="font3"><?= $row_Rt2['buind']; ?></td>
      <td width="9%" align="center" class="font3"><a href="javascript:if(confirm('確實要刪除嗎?'))location='<? echo 'main.php?act=settb2&del_id='.$row_Rt2['buid'] ;?>'"><img src="images/del.png" alt="刪除項目" width="16" height="16" border="0"/></a></td>
    </tr>
    <?php } while ($row_Rt2 = mysql_fetch_assoc($Rt2)); 
	 }
	  ?>

  </table>
<table width="697" border="0" align="left" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="34%">總筆數：<?php echo $totalRows_Rt2 ?>筆 </td>
                  <td width="66%"><div id="font_s">
                      <p>
                        <?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); ?>"><img src="images/first.jpg" alt="上一頁" title="上一頁" width="30" height="11" border="0" /></a>
                        <?php } // Show if not first page ?>
                        第
                        <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('self',this,0)">
                          <? for($i=0;$i<=$totalPages_Rt2;$i++){?>
                          <option value="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, $i, $queryString_Rt2); ?>" <? if($pageNum_Rt2==$i){ ?>selected="selected" <? }?>><? echo $i+1 ;?></option>
                          <? }?>
                        </select>
                        頁
                        <?php
	    //分頁程式
if($totalPages_Rt2<9){
		 $start=0;
		 $end=$totalPages_Rt2;
		}else{  
	    $start=$pageNum_Rt2-5;
		$end=$pageNum_Rt2+5;
        if ($start<0){
		 $start=0;
		 $end=10; } 
		 else { $end=$start+10 ;}
		 if ($end>$totalPages_Rt2){ 
		   $start = $end-$totalPages_Rt2-5;
		   $end=$totalPages_Rt2;
		   }
		 if ($end-$start>10){ 
		   $start = $end-10;
		   }  
		 }
		   
		for($i=$start;$i<=$end;$i++){
		if($i==$pageNum_Rt2){ echo "[".($i+1)."]";} else {?>
                        <a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, min($totalPages_Rt2, $i), $queryString_Rt2); ?>"> <? echo $i+1 ;?></a>
                        <?	}   }  ?>
                        <?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); ?>"><img src="images/next.png" alt="下一頁" title="下一頁" width="16" height="16" border="0" /></a>
                        <?php } // Show if not last page ?>
                      </p>
                  </div></td>
  </tr>
</table>
<?php
mysql_free_result($Rt2);
?>
