<?php require_once('../Connections/BE2.php'); ?>
<?php


if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
	
  $updateSQL = sprintf("update adpic set flag='%s',doc='%s',link='%s',ind='%s',img='%s',imgext='%s' ,imgtxt='%s',linktag='%s',sdate='%s',edate='%s',bman='%s',bmm1='%s',bmm2='%s' WHERE id='%s'",$_POST['flag'],$_POST['doc'],$_POST['link'],$_POST['ind'],$_POST['img'],$_POST['imgext'],$_POST['imgtxt'],$_POST['linktag'],$_POST['sdate'],$_POST['edate'],$_POST['bussman'],$_POST['bmm1'],$_POST['bmm2'],$_POST['id']);
  mysql_select_db($database_BE2, $BE2);
  $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());  
	
  $updateGoTo = $_POST['url'];
   echo '<script>window.location.replace("'.$updateGoTo.'");</script>';

  
  // header(sprintf("Location: %s", $updateGoTo));
}

$bid=-1;
if(isset($_GET['id'])){
	$bid=$_GET['id'];
	}  
if($bid<0){ exit;}

mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("select * from adpic WHERE xid='%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($row_Rt2['id']=="" ){
  $insertSQL = sprintf("insert into adpic (xid) VALUES('%s')",$bid);
  mysql_select_db($database_BE2, $BE2);
  $Result1 = mysql_query($insertSQL, $BE2) or die(mysql_error());  
  
  $query_Rt2 = sprintf("select * from adpic WHERE xid='%s'",$bid);
  mysql_select_db($database_BE2, $BE2);
  $Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
  $row_Rt2 = mysql_fetch_assoc($Rt2);
  $totalRows_Rt2  = mysql_num_rows($Rt2);
  
	}
mysql_select_db($database_BE2, $BE2);
$query_Rtm = "SELECT * FROM buser WHERE flag = 'Y' ORDER BY id ASC";
$Rtm = mysql_query($query_Rtm, $BE2) or die(mysql_error());
$row_Rtm = mysql_fetch_assoc($Rtm);
$totalRows_Rtm = mysql_num_rows($Rtm);


?>

<form action="" method="post" name="form1" id="form1">
 
<table border="0" align="center" cellpadding="0" cellspacing="0">
 
    <tr >
      <td width="10">&nbsp;</td>
      <td width="135"><input name="doc" type="hidden" id="doc" value="<? echo $row_Rt2['doc'];?>" />
      <input name="bid" type="hidden" id="bid" value="<? echo $row_Rt2['c0'];?>" />
      <input name="img" type="hidden" id="img" value="<? echo $row_Rt2['img'];?>" />
      <input name="imgext" type="hidden" id="imgext" value="<? echo $row_Rt2['imgext'];?>" /></td>
      <td width="183"><input name="link" type="hidden" id="link" value="" size="40" /></td>
      <td width="33"><label for="select"></label>
        <input name="linktag" type="hidden" id="linktag" value="_self" />
            </td>
      <td width="160"><input name="ind" type="hidden" id="ind" value="0" /></td>
      <td width="171">&nbsp;</td>
    </tr>
 
    <tr class="font2">
      <td>&nbsp;</td>
      <th align="right" nowrap="nowrap">啟用日期</th>
      <td><input name="sdate" type="text" id="sdate" value="<? echo $row_Rt2['sdate'];?>" /></td>
      <td>&nbsp;</td>
      <th nowrap="nowrap"> 開啟使用</th>
      <td><select name="flag">
        <option value="Y" <? if($row_Rt2['flag']=='Y'){ ?> selected="selected" <? } ?>>Y</option>
        <option value="N" <? if($row_Rt2['flag']=='N'){ ?> selected="selected" <? } ?>>N</option>
      </select></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <th align="right" nowrap="nowrap">截止日期</th>
      <td><input name="edate" type="text" id="edate" value="<? echo $row_Rt2['edate'];?>" /></td>
      <td>&nbsp;</td>
      <th nowrap="nowrap">&nbsp;</th>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <th align="right" nowrap="nowrap">業務</th>
      <td><select name="bussman" id="bussman">
        <?php do { ?>
        <option value="<?php echo $row_Rtm['id']?>"<?php if (!(strcmp($row_Rtm['id'], $row_Rt2['bman']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Rtm['aname']?></option>
        <?php
       } while ($row_Rtm = mysql_fetch_assoc($Rtm));
      ?>
      </select></td>
      <td>&nbsp;</td>
      <th nowrap="nowrap">&nbsp;</th>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <th align="right" nowrap="nowrap">商品金額</th>
      <td><input name="bmm1" type="text" id="bmm1" value="" size="12" maxlength="6" /></td>
      <td>&nbsp;</td>
      <th nowrap="nowrap">業務獎金</th>
      <td><input name="bmm2" type="text" id="bmm2" value="" size="12" maxlength="6" /></td>
    </tr>
</table> 
 
 
  
  
  
  <table width="100%" align="center">
    <tr valign="baseline">
      <td valign="top" nowrap="nowrap">
        <? // htmlentities($row_Rt2['imgtxt'], ENT_COMPAT, 'utf-8'); ?>
        <textarea name="imgtxt" id="imgtxt" rows=30 cols=70 class="ckeditor"><?= $row_Rt2['imgtxt']  ?></textarea></td>
    </tr>
    <tr valign="baseline">
      <td align="center" nowrap="nowrap"><input type="submit" value="更新記錄" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="id" value="<?php echo $row_Rt2['id']; ?>" />
  <input name="url" type="hidden" id="url" value="<? echo $_SERVER['HTTP_REFERER'];?>" />
</form>
<div id="back"><a href="javascript:history.back();"><img src="images/back.gif" alt="回上一頁" title="回上一頁" width="115" height="32" border="0"></a></div> 
 
<?php
mysql_free_result($Rt2);
?>
