<?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());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_ad2set")) {
  $insertSQL = sprintf("INSERT INTO adpage (pdoc,pdata,pindex,pmid) VALUES ( %s, %s, %s, %s)",
                       GetSQLValueString($_POST['pdoc'], "text"),
					   GetSQLValueString($_POST['pdata'], "text"),
                       GetSQLValueString($_POST['pindex'], "int"),
                       GetSQLValueString($_POST['pmid'], "int"));
	echo $insertSQL;				   
  mysql_select_db($database_BE2, $BE2);
  $Result1 = mysql_query($insertSQL, $BE2) or die(mysql_error());

//  $insertGoTo = $_POST['url'];
//  header(sprintf("Location: %s", $insertGoTo));
}

//$webid=1;
//if(isset($_GET['webid'])){
//	$webid=$_GET['webid'];
//	} 
$colname_Rt3 = "-1";
if (isset($_GET['mid'])) {
  $colname_Rt3 = $_GET['mid'];
}

$progam_arr1=array("login.html","register.html","contact.html");
if(! in_array( $rt3link,$progam_arr1) ){ 


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 a.pmid = '$colname_Rt3' GROUP BY b.adid ORDER BY b.raindex" ;
$query_Rt2 =  "SELECT a.*,b.*,c.*,COUNT(d.xid) as dd FROM adpage AS a  left join ap2 AS b on  a.pid = b.webid  left join ap1 AS c  on b.raid = c.raid   LEFT JOIN adpic AS d ON d.xid = b.adid WHERE   a.pmid = '$colname_Rt3' 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); 
 // echo $query_Rt2."<br>";

if($totalRows_Rt2>0){
?>
<span class="ti2"><?= $row_Rt2['pdoc']?> <a href="main.php?act=ad2_add&webid=<?php echo $row_Rt2['pid']; ?>">新增廣告區塊</a></span>
<? // if($myadmin){ echo '<br>'.$query_Rt2; }?> 
<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">ICON</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 
	 $p1=array("&nbsp;","START","HOT","NEW");
	
	 if($totalRows_Rt2>0){ 
	  do {
		  // check recno is set
		  if($row_Rt2['webid']>0){
		  ?>
    <tr onMouseOver="this.style.backgroundColor='#CCC';" onMouseOut=this.style.backgroundColor="#fff">
      <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"><?= $p1[$row_Rt2['raicon']]?></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" nowrap="nowrap" class="font3"><? $ar1=array("不顯示","上標","下標","圖形內標");
	                                       echo $ar1[$row_Rt2['ramark']];  ?></td>
      <td align="center" class="font3"><?= $row_Rt2['raindex']; ?></td>
      <td align="center" class="font3"><?php echo $row_Rt2['dd']; ?></td>
      <td align="center" class="font3">
      <? if($row_Rt2['ra7']=='Y'){?>
      
      <a href="main.php?act=ad_browsetxt&webid=<?= $row_Rt2['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=<?= $row_Rt2['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="13"></td>
    
    </tr>
  </table>

<?php
}else if($rt3title<>''){

	?>

<form action="" method="post" name="form1" id="form1">
  <table align="left">
    <tr valign="baseline">
      <th width="84" align="right" nowrap="nowrap"><span class="font2">廣告分頁說明</span>:</th>
      <td width="272"><input type="text" name="pdoc" value="<?php echo $row_Rt3['title']; ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">廣告分頁連結</span>:</th>
      <td><input name="plink" type="text" value="<?php echo $row_Rt3['link']; ?>" size="32" readonly="readonly" /></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">排列序</span>:</th>
      <td><input name="pindex" type="text" id="pindex" value="0" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">資料模式</span>:</th>
      <td><label for="select"></label>
        <select name="pdata" id="pdate">
          <option value="Y" selected="selected">廣告區塊模式</option>
          <option value="N">HTML 文字編輯</option>
      <? if($myadmin){?> <option value="P">php程式</option> <? }?>

      </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="建立連結新頁面" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form_ad2set" />
  <input name="url" type="hidden" id="url" value="<? echo $_SERVER['HTTP_REFERER'];?>" />
  <input name="pmid" type="hidden" id="pmid" value="<? echo $rt3mid;?>" />
</form>
	
<?	
  }
 
  mysql_free_result($Rt2);
 
  } else{ echo "程式保留.." ;} 
?>
