<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php
 
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE ap1 SET ra1=%s, ra2=%s, ra3=%s, ra4=%s, ra5=%s, ra6=%s WHERE raid=%s",
                       GetSQLValueString($_POST['ra1'], "text"),
                       GetSQLValueString($_POST['ra2'], "text"),
                       GetSQLValueString($_POST['ra3'], "int"),
                       GetSQLValueString($_POST['ra4'], "text"),
					   GetSQLValueString($_POST['ra5'], "int"),
					   GetSQLValueString($_POST['ra6'], "int"),
                       GetSQLValueString($_POST['raid'], "int"));

  mysql_select_db($database_BE2, $BE2);
  $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());

  $updateGoTo = $_POST['url'];
  echo "<script>location.href = '".$updateGoTo."';</script>";
  
  //header(sprintf("Location: %s", $updateGoTo));
  //Cannot modify header information
}

$colname_Rt2 = "-1";
if (isset($_GET['id'])) {
  $colname_Rt2 = $_GET['id'];
}
mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("SELECT * FROM ap1 WHERE raid = %s", GetSQLValueString($colname_Rt2, "int"));
$Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);
$totalRows_Rt2 = mysql_num_rows($Rt2);
?>
 
 <div class="row">
 <div class="col-md-12">
				
 <div class="panel panel-default">
        <div class="panel-heading">
		   <h3 class="panel-title">編輯廣告說明</h3>
        </div>
 
<form action="" method="post" name="form1" id="form1" class="form-horizontal">


   <table cellspacing="0" class="table table-small-font table-bordered table-striped">
    <tr valign="baseline">
      <th width="143" align="right" nowrap="nowrap"><span class="font2">廣告區塊</span>:</th>
      <td width="362"><input type="text" name="ra1" value="<?php echo htmlentities($row_Rt2['ra1'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">廣告圖檔說明</span>:</th>
      <td><input type="text" name="ra2" value="<?php echo htmlentities($row_Rt2['ra2'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">廣告價格</span>:</th>
      <td><input type="text" name="ra3" value="<?php echo htmlentities($row_Rt2['ra3'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">廣告天數</span>:</th>
      <td><input type="text" name="ra5" value="<?php echo htmlentities($row_Rt2['ra5'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">廣告圖數量</span>:</th>
      <td><input type="text" name="ra6" value="<?php echo htmlentities($row_Rt2['ra6'], ENT_COMPAT, 'utf-8'); ?>" size="32" />
        0, 表不設限</td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">使用</span>:</th>
      <td><select name="ra4">
        <option value="Y" <?php if (!(strcmp("Y", htmlentities($row_Rt2['ra4'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>使用</option>
        <option value="N" <?php if (!(strcmp("N", htmlentities($row_Rt2['ra4'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>暫停使用</option>
      </select></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right">&nbsp;</th>
      <td><input type="submit" value="更新記錄" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="raid" value="<?php echo $row_Rt2['raid']; ?>" />
  <input name="url" type="hidden" id="url" value="<?php 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> 
</div>
				</div>
			</div>
<?php
mysql_free_result($Rt2);
?>
