<?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 ap2 WHERE adid='%s'",$_GET['del_id']);
$Rt2 = mysql_query($delete_SQL, $BE2) or die(mysql_error());
}

$webid=1;
if(isset($_GET['webid'])){
	$webid=$_GET['webid'];
	} 


mysql_select_db($database_BE2, $BE2);
//$query_Rt2 = "SELECT a.*,b.* FROM ap1 as a ,ap2 as b left join adpic as c on b.adid=c.xid where a.raid=b.raid AND b.webid='$webid' order by b.raindex";
//$query_Rt2 = "SELECT a.*,b.*,count(c.xid) as xid FROM ap1 as a ,ap2 as b left join adpic as c on b.adid=c.xid where a.raid=b.raid AND b.webid='$webid' group by c.xid order by b.raindex";  
//$query_Rt2 = "select a.*,b.*,c.* from adpage as a, ap2 as b,ap1 as c where a.pid=b.webid and b.raid=c.raid and webid='$webid' order by b.raindex";
$query_Rt2 = "SELECT a.*,b.*,c.*,COUNT(d.xid) as dd FROM adpage AS a,ap1 AS c,ap2 AS b LEFT JOIN adpic AS d ON d.xid = b.adid WHERE a.pid = b.webid AND b.raid = c.raid AND webid = '$webid' GROUP BY b.adid ORDER BY b.raindex";
$Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);
$totalRows_Rt2  = mysql_num_rows($Rt2); 
?>
<h3><span class="ti2"><?= $row_Rt2['pdoc']?><a href="main.php?act=ad2_add&webid=<?php echo $webid; ?>" style="color:#F00">新增廣告區塊</a></span></h3>
 
<table width="743" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <th width="3%" nowrap="nowrap" class="font2">ID</th>
      <th width="10%" nowrap="nowrap" class="font2">廣告區塊</th>
      <th width="21%" nowrap="nowrap" class="font2">廣告圖檔說明</th>
      <th width="20%" nowrap="nowrap" class="font2">廣告說明</th>
      <th width="13%" nowrap="nowrap" class="font2">BANNER顯示</th>
      <th width="13%" nowrap="nowrap" class="font2">使用</th>
      <th width="13%" nowrap="nowrap" class="font2">標題</th>
      <th width="13%" nowrap="nowrap" class="font2">排列</th>
      <th width="10%" nowrap="nowrap" class="font2">廣告圖</th>
      <th width="10%" 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=ad2_edit&amp;id=<?php echo $row_Rt2['adid']; ?>"><img src="images/edit.png" alt="修改項目名稱" title="修改項目名稱" width="16" height="16" border="0" /></a></td>
      <td align="center" class="font3"><?php echo $row_Rt2['ra1']." - ".$row_Rt2['raid'] ; ?></td>
      <td class="font3"><?php echo $row_Rt2['ra2']; ?></td>
      <td align="center" class="font3"><?php echo $row_Rt2['radoc']; ?></td>
      <td align="center" class="font3"><?php if($row_Rt2['ratshow']=='N'){ echo '<font color="#0000CC">';} echo $row_Rt2['ratshow']; if($row_Rt2['ratshow']=='N'){ echo '</font>';} ?></td>
      <td align="center" class="font3"><?php if($row_Rt2['raflag']=='N'){ echo '<font color="#FF0000">';} echo $row_Rt2['raflag']; if($row_Rt2['raflag']=='N'){ echo '</font>';} ?></td>
      <td align="center" class="font3"><? $ar1=array("不顯示","上標","下標","圖形內標");
	                                       echo $ar1[$row_Rt2['ramark']];  ?></td>
      <td align="center" class="font3"><?= $row_Rt2['raindex']; ?></td>
      <td align="center" class="font3"><?= $row_Rt2['dd']; ?></td>
      <td align="center" class="font3">
      <? if($row_Rt2['ra7']=='Y'){?>
      <a href="main.php?act=ad_browsetxt&webid=<?= $webid ;?>&id=<?php echo $row_Rt2['adid']; ?>"><img src="images/html.png" alt="編輯內文" title="編輯內文" width="32" height="32" /></a>
      <? }else{?><a href="main.php?act=ad_browse&webid=<?= $webid ;?>&id=<?php echo $row_Rt2['adid']; ?>"><img src="images/browse.png" alt="編輯圖檔元素" title="編輯圖檔元素" width="32" height="32" /></a><? }?></td>
      <td width="10%" align="center" class="font3"><a href="javascript:if(confirm('確實要刪除嗎?'))location='<? echo 'main.php?act=ad2&del_id='.$row_Rt2['adid'] ;?>'"><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 colspan="12"></td>
    
    </tr>
  </table>

<?php
mysql_free_result($Rt2);
?>
