<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php
 
//$picpath= "/products/"; 
$picpath= "/shoppic/"; 

$write='';
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
	
	$path = $wwwpath.$picpath.$_POST['webid']; 
    if(!is_dir($path)){
    mkdir($path);
    }
  if($_POST['piccount']>0){	
   for($i=0;$i<$_POST['piccount'];$i++){
     $img=sprintf("%04d",$_POST["bid"]).sprintf("%04d",rand(1,9999)).sprintf("%04d",rand(1,9999));
     $imgext=''; 
	 $imgtxt=''; 
     $ind=($i+1)*100;
     $updateSQL = sprintf("insert into c_adpic (flag,doc,link,ind,bid,img,imgext,imgtxt,xid,linktag,sdate,edate) VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
          "N",$_POST['doc'],$_POST['link'],$ind,$_POST['bid'],$img,$imgext,$imgtxt,$_POST['xid'],$_POST['linktag'],$_POST['sdate'],$_POST['edate']);
     mysql_select_db($database_BE2, $BE2);
     $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());  
    }
  }
  $write='資料已更新...';
  
  
 $insertGoTo = $_POST['url'];
 // header(sprintf("Location: %s", $insertGoTo)); 
 echo  "<script>alert('".$write."');location.href='".$_POST['url']."';</script>";
  }
 

$bid=-1;
if(isset($_GET['id'])){
	$bid=$_GET['id'];
	}  
$webid=-1; //webid
if(isset($_GET['webid'])){
	$webid=$_GET['webid'];
	} 
mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("select a.*,b.*,c.* from ap1 as a, c_ap2 as b,cuser as c WHERE a.raid=b.raid AND b.webid=c.cuid AND b.adid='%s'",$bid);
$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; } 
?>

<form id="form1" name="form1" method="POST" enctype="multipart/form-data" action="">
<table width="53%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th height="47" nowrap="nowrap" class="font2" >&nbsp;</th>
    <th colspan="4" nowrap="nowrap" class="font2" ><? echo $row_Rt2['webname']." ".$row_Rt2['radoc'];?></th>
    </tr>
  <tr>
    <th width="5%" nowrap="nowrap" class="font2" >&nbsp;</th>
    <th width="25%" nowrap="nowrap" class="font2" ><input name="doc" type="hidden" id="doc" value="" />
      新增圖片數量</th>
    <th width="23%" nowrap="nowrap" class="font2" ><input name="piccount" type="text" id="piccount" value="4" size="8" maxlength="2" /></th>
    <th width="26%" nowrap="nowrap" class="font2" ><input type="submit" name="Submit" value="送出" /></th>
    <th width="21%" nowrap="nowrap" class="font2" >&nbsp;</th>
    </tr>
 
    <tr >
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input name="link" type="hidden" id="link" value="" size="40" />
        <span class="font2">
        <input name="xid" type="hidden" id="xid" value="<? echo $row_Rt2['adid'];?>" />
        <input name="bid" type="hidden" id="bid" value="<? echo $row_Rt2['webid'];?>" />
      </span></td>
      <td>
      <input type="hidden" name="linktag" id="linktag" value="_self" />
      <input type="hidden" name="webid" id="webid" value="<? echo $row_Rt2['id'];?>" /></td>
      <td><input name="ind" type="hidden" id="ind" value="100" size="8" maxlength="5" /></td>
    </tr>
 
    <tr>
      <td height="28">&nbsp;</td>
      <th align="right">&nbsp;</th>
      <td><label for="sdate"></label>
      <input name="sdate" type="hidden" id="sdate" value="<? echo date("Y-m-d");?>" /></td>
      <td>&nbsp;</td>
      <td><input name="url" type="hidden" id="url" value="<? echo $_SERVER['HTTP_REFERER']; ?>" /></td>
    </tr>
    <tr>
      <td height="28">&nbsp;</td>
      <th align="right">&nbsp;</th>
      <td><input name="edate" type="hidden" id="edate" value="<? echo date("Y-m-d",time()+(86400*365));?>" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <th align="right">&nbsp;</th>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="4">        (廣告 <? echo $row_Rt2['ra1'];?> 區)<? echo $row_Rt2['ra2'];?> </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
</table> 

<input name="MM_insert" type="hidden" id="MM_insert" value="form1">
<input name="MM_bannerfile" type="hidden" id="MM_bannerfile" value="bannerfile" />
</form>



<?php
mysql_free_result($Rt2);
 
?>
