<?php require_once('../Connections/BE2.php'); ?>
<?php
 
$currentPage = "netinshop2.html";//$_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;
 
/*
webshop    網店管理   db webshop
ecardshop  廣告雲名片 db ecardshop
ecardshop2 wkid=1   九宮格區塊增加   db ecardext
netinshop2  wkid=2   九宮格商品區塊   db ecardext
netinshop3  wkid=3   九宮格店中店區塊  db ecardext


//  mkid company=2,member =1 

*/
if (isset($_GET['deleteid'])&& $_GET['deleteid']>0) {
  mysql_select_db($database_BE2, $BE2);
  $del_sql1 = sprintf("DELETE FROM ecardext WHERE wid='%s' AND wuid='%s'",$_GET['deleteid'],$_SESSION['login_coid']);
  mysql_query($del_sql1, $BE2) ;
}
mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("SELECT * FROM ecardext WHERE wuid='%s' AND wkid=2 order by windex",$_SESSION['login_coid']);
$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, "menu") == 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);

echo $query_Rt2;
  
?>	
		<!-- start: Content -->
		<div class="main ">
		
			<div class="row">
				<div class="col-lg-12">
					<h3 class="page-header"><i class="fa fa-indent"></i>九宮格商品區塊</h3>
					<ol class="breadcrumb">
						<li><i class="fa fa-home"></i><a href="index.html">首頁</a></li>
                        <li><i class="fa fa-list-alt"></i><a href="#">企業資料</a></li>
						<li><i class="fa fa-indent"></i>九宮格商品區塊</li>				
					</ol>
				</div>
			</div>

             

			<div class="row">	
				<div class="col-md-12">
					<div class="panel panel-default">
						<div class="panel-heading">
							<h2><i class="fa fa-list red"></i><span class="break"></span><strong>九宮格商品區塊</strong></h2>
						</div>


						<div class="panel-body">

					<h3 class="panel-title">&nbsp;</h3>
					            <div class="clearfix"></div>  
                    
                     <div style="overflow:scroll;">
				 <table class="table table-striped table-bordered bootstrap-datatable" style="min-width:800px;">
 
						<thead>
							<tr class="replace-inputs">
								<th width="38" class="center">#</th>
								<th width="89">圖檔</th>
								<th width="117" nowrap="nowrap">說明</th>
								<th width="261" nowrap="nowrap">連結</th>
								<th width="76" align="center" nowrap="nowrap">廣告類別</th>
								<th width="71" align="center" nowrap="nowrap">排序</th>
                                <th width="71" align="center" nowrap="nowrap">啟用</th>
                                <th width="71" align="center">編輯</th>
                                <th width="71" align="center">刪除</th>
                            </tr>
						</thead>
						<tbody>
                           <?php  
							if($totalRows_Rt2>0){
							$i=0;	
						 do { $i++;
						 if($row_Rt2['wkid2']=='P'){
						  $imagepath = "/admin/upload2_image/".sprintf("%07d",$row_Rt2['wuid']).'/'.$row_Rt2['wimg'].'.'.$row_Rt2['wimgext']; 
						 }else{ 
						  $imagepath='/shop/reimg/wpi_'.sprintf("%07d",$row_Rt2['wuid']).'_'.$row_Rt2['wrand'].'.'.$row_Rt2['wimgext'];
					 
						  //$imagepath = '/shop/reimg/'.$row_Rt2['wimg'].'.'.$row_Rt2['wimgext'] ;
						 
						 }
						 ?>
							<tr>
								<td height="78" class="center"><?= $i ?></td>
                                <td><? $img= $row_Rt2['wimg'].'.'.$row_Rt2['wimgext'];?><img name="simg<?= $i ?>" id="simg<?= $i ?>" src="<?= $imagepath ?>"  width="72" title="<?= $row_Rt2['wtitle'];?>" /></td>
                                <td><?= $row_Rt2['wtitle'];?></td>
                                <td>
                                <? if($row_Rt2['wkid2']=='P'){?>
                                  <a href="/categoryDetail-<?= $row_Rt2['wlink'];?>.html" target="_blank">/categoryDetail-<?= $row_Rt2['wlink'];?>.html</a> 
                                <? }else{?> 
                                  <a href="<?= $row_Rt2['wlink'];?>" target="_blank"><?= $row_Rt2['wlink'];?></a> 
                                 <? } ?>
                                </td>
                                <td align="center" valign="middle"><?= ($row_Rt2['wkid2']=='P')?'商品類別':'自定義';?></td>
                                <td align="center" valign="middle"><?= $row_Rt2['windex']?></td>
                                <td align="center" valign="middle"><?= ($row_Rt2['wflag']==1)?'Y':'N';?></td>
                                
                                <td align="center" valign="middle"><a href="editnetinshop2<?= ($row_Rt2['wkid2']=='P')?'':'b' ;?>.html?ed=Y&id=<?= $row_Rt2['wid'] ?>"><img src="images/edit.png" title="修改" width="16" height="16" border="0" /></a></td>
                                <td align="center" valign="middle"> <button type="button" class="label label-info" onclick="javascript:if(confirm('確定要刪除嗎?'))location='<?= $currentPage ?>?deleteid=<?= $row_Rt2['wid']; ?>'">刪除</button>    
</td>
                            </tr>
						
                        <?php } while ($row_Rt2 = mysql_fetch_assoc($Rt2)); ?>
				 
						<?	}  	?>
                        </tbody>
 
					</table>
				
                    
<div class="form-group form-actions">
				<? if($totalRows_Rt2<46){
                   
								  
								  ?>
                                    <input type="button" name="Sub2" value="新增商品廣告圖" class="btn btn-3d btn-black btn-md" onclick="location.href='editnetinshop2.html?ed=A&id=0'">
                                  
              <input type="button" name="Sub2" value="新增自定義廣告圖" class="btn btn-3d btn-black btn-md" onclick="location.href='editnetinshop2b.html?id=0'">
                                    
			    	<?     }   ?>					 
				              
              </div>   
              	        
                
                   <ul class="pagination">
                    <?    
                     if( $totalPages_Rt2 >0){	 
						    //分頁程式
if($totalPages_Rt2<5){
		 $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;
		   }  
		 } ?> 
                     <?php if ($pageNum_Rt2 > 0) { // Show if not first page ?>
                     <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, max(0, $pageNum_Rt2 - 1), $queryString_Rt2); ?>">上一頁</a></li><?php } // Show if not first page ?>
                    	<?	   
		for($i=$start;$i<=$end;$i++){
		if($i==$pageNum_Rt2){ echo '<li class="active"><a href="#">'.($i+1).'</a></li>';} else {?>
            <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, min($totalPages_Rt2, $i), $queryString_Rt2); ?>"><? echo $i+1 ;?></a></li>
                 
                        <?	}   }  ?>

                      <?php if ($pageNum_Rt2 < $totalPages_Rt2) { // Show if not last page ?>
            <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, min($totalPages_Rt2, $pageNum_Rt2 + 1), $queryString_Rt2); ?>">下一頁</a></li>
                        <?php }  
						             }  
									 
								 	 ?>
								
						  </ul>

                   </div>



					  </div>
					</div>
				</div><!--/col-->
			
			</div><!--/row-->

    
		</div>
		 
		<!-- end: Content -->
          
        
  <?php
mysql_free_result($Rt2);
 
?>        
    