<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php
 
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

  mysql_select_db($database_BE2, $BE2);
  $delete_SQL = sprintf("DELETE FROM storeadv WHERE rid='%s'",$_POST['rid']);
  $Rt2 = mysql_query($delete_SQL, $BE2) or die(mysql_error());
  $x=0;
  //echo $delete_SQL."<br>";
  
  $updateSQL = "INSERT INTO storeadv (rid, aid, ind1, sdate1, edate1) VALUES ";
  	  for($i=0;$i<$_POST['ckcount'];$i++){
	    if (isset($_POST['ck'.$i])){
           if($x>0){ $updateSQL .=",";}		  
		   $updateSQL .= sprintf("('%s','%s','%s','%s','%s' )",$_POST['rid'],$_POST['ck'.$i],$_POST['ind'.$i],$_POST['sdate'.$i],$_POST['edate'.$i] ); 
		   $x++;
		   }
	  }
	  
   if($x>0){ $updateSQL .=";";		
   mysql_select_db($database_BE2, $BE2);
   $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());
  // echo $updateSQL;
   }
   
   $updateGoTo = $_POST["url"];
   header(sprintf("Location: %s", $updateGoTo));
}

$bid=172; //商店專區
$rid=-1;
 if(isset($_POST['rid'])){$rid=$_POST['rid'] ;}
 else if(isset($_GET['rid'])){ 	$rid=$_GET['rid'];	}  



mysql_select_db($database_BE2, $BE2);
//$query_Rt2 = sprintf("select a.*,b.* from left join adpic WHERE xid='%s'",$bid);
$query_Rt2 = sprintf("select c.*,d.* from adpage as a,ap2 as b,adpic as c left join storeadv as d on d.aid=c.id AND d.rid=%s WHERE b.adid=c.xid  AND a.pid=b.webid  AND b.adid='%s'",$rid,$bid);
// echo $query_Rt2 ;


$Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);
$totalRows_Rt2  = mysql_num_rows($Rt2);  
?>
<?  // if($myadmin){ echo $query_Rt2; }?> 
<script type="text/javascript" charset="utf-8">
 
  	  
 function selectall(){	
   // $("#form1 input[type='checkbox'].child").prop ( "checked" , $(this).prop("checked" ) );
  $(".checkbox").prop('checked', $(this).prop("checked")); 
 }
 
</script>
<span class="ti2"><a href="main.php?act=ad2&webid=71">商店專門頁</a></span>

<form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <th colspan="2" nowrap="nowrap" class="font2">選取<span class="font3">
        <input name="select_all" type="checkbox" id="select_all" value="1" onclick="selectall()" />
      </span></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">&nbsp;</th>
    </tr>
    <?php 
	 
	 if($row_Rt2['id']<>""){    
	   $i=0;
	  do { 
	  
	  ?>
    <tr>
      <td colspan="2" align="center" class="font3"><label for="checkbox"></label> 
      <? 
	    $date='N';
		if($row_Rt2['aid']>0){ $date='Y' ;}?>
      <input name="ck<?= $i ?>" type="checkbox" id="ck<?= $i ?>" value="<?php echo $row_Rt2['id']; ?>" <? if($date=='Y'){ echo 'checked="checked"'; } ?>  class="checkbox"/></td>
      <td align="center" class="font3"><?php echo $row_Rt2['doc']; ?></td>
      <td align="center" class="font3"><img src="<?php 
	  //if($row_Rt2['raid']==14){ $img= 'images/youtube.png' ;}else{
		 $img= "/products/".$row_Rt2['img'].'.'.$row_Rt2['imgext'];
		//  }
	  echo $img ; ?>" alt="編輯圖檔元素" title="編輯圖檔元素" width="75" /></td>
      <td align="center" class="font3"><?php echo $row_Rt2['ind']; ?>
      <input name="ind<?= $i ?>" type="text" id="ind<?= $i ?>" value="<?= ($date=='Y')?$row_Rt2['ind1']:$row_Rt2['ind']; ?>" size="12" maxlength="12"/></td>
      <td align="center" class="font3"><?php echo $row_Rt2['sdate']; ?>
      <input name="sdate<?= $i ?>" type="text" id="sdate<?= $i ?>" value="<?= ($date=='Y')?$row_Rt2['sdate1']:$row_Rt2['sdate']; ?>" size="12" maxlength="12"/></td>
      <td align="center" class="font3"><?php echo $row_Rt2['edate']; ?>
      <input name="edate<?= $i ?>" type="text" id="edate<?= $i ?>" value="<?= ($date=='Y')?$row_Rt2['edate1']:$row_Rt2['edate']; ?>" size="12" maxlength="12"/></td>
      <td align="center" class="font3">&nbsp;</td>
    </tr>
    <?php 
	$i++;
	} while ($row_Rt2 = mysql_fetch_assoc($Rt2));  ?>
    <tr>
      <td colspan="9" align="center">
      <input name="rid" type="hidden" id="rid" value="<?= $rid; ?>" />
      <input type="hidden" name="MM_update" value="form1">
      <input name="url" type="hidden" id="url" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
      <input type="hidden" name="ckcount" id="ck" value="<?= $i ?>" /><input name="submit" type="submit" value="送出" /></td>
    </tr>
    <? } ?>
  </table>
</form>
<?php
mysql_free_result($Rt2);
?>
