<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $sn2=explode(",",$_POST['sn']);
  $st2=explode(",",$_POST['st']);
  $x= array_search($_POST['raid'],$sn2) ;
  $myst=$st2[$x]; 	
  $insertSQL = sprintf("INSERT INTO ap2 (webid, raid, radoc, ratshow, ratxt, ramark, raicon,raaddr, raindex) VALUES (%s,%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['webid'], "int"),
                       GetSQLValueString($_POST['raid'], "int"),
                       GetSQLValueString($_POST['radoc'], "text"),
					   GetSQLValueString($_POST['ratshow'], "text"),
					   GetSQLValueString($myst, "text"),
					   GetSQLValueString($_POST['ramark'], "int"),
					   GetSQLValueString($_POST['raicon'], "int"),
					   GetSQLValueString($_POST['raaddr'], "text"),
                       GetSQLValueString($_POST['raindex'], "int"));

 mysql_select_db($database_BE2, $BE2);
 $Result1 = mysql_query($insertSQL, $BE2) or die(mysql_error());
 
  $insertGoTo = $_POST['url'];
  //header(sprintf("Location: %s", $insertGoTo));
  //  $insertGoTo = $_POST['url'];
  // header(sprintf("Location: %s", $insertGoTo)); 
 $write='資料已更新...'; 
 echo  "<script>alert('".$write."');location.href='".$_POST['url']."';</script>";
  
}

mysql_select_db($database_BE2, $BE2);
$query_Rtf = "SELECT * FROM ap1 WHERE ra4='Y' ORDER BY raid ASC";
$Rtf = mysql_query($query_Rtf, $BE2) or die(mysql_error());
$row_Rtf = mysql_fetch_assoc($Rtf);
$totalRows_Rtf = mysql_num_rows($Rtf);
?>
<form action="" method="post" name="form1" id="form1">
  <table width="501" align="center">
    <tr valign="baseline">
      <th width="207" align="right" nowrap="nowrap">版型模塊:</th>
      <td width="282"><select name="raid">
        <?php 
	$st='';
	$sn='';	
do {  
$st .= $row_Rtf['ra7'].",";
$sn .= $row_Rtf['raid'].","; 
?>
        <option value="<?php echo $row_Rtf['raid']?>" ><?php echo $row_Rtf['ra1'].")".$row_Rtf['ra2']?></option>
        <?php
} while ($row_Rtf = mysql_fetch_assoc($Rtf));
?>
      </select></td>
    </tr>
    <tr> </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right">模塊說明:</th>
      <td><input type="text" name="radoc" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right">模塊<span class="font2">橫幅</span>標題顯示:</th>
      <td><select name="ratshow" id="ratshow">
        <option value="Y">顯示標題</option>
        <option value="N">不顯示標題</option>
      </select></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">模塊橫幅標題左上圖示:</span></th>
      <td><select name="raicon" id="raicon">
        <option value="0">不用</option>
        <option value="1">start</option>
        <option value="2">hot</option>
        <option value="2">new</option>
      </select></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">圖形物件標題顯示:</span></th>
      <td><select name="ramark" id="ramark">
        <option value="0" selected="selected">不顯示</option>
        <option value="1">上標</option>
        <option value="2">下標</option>
        <option value="3">圖形內標</option>
      </select></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right"><span class="font2">模塊位置:</span></th>
      <td><select name="raaddr" id="raaddr">
        <option value="M" selected="selected">主區域</option>
        <option value="L">左方區域(如果有)</option>
        <option value="R">右方區域(如果有)</option>
      </select></td>
    </tr>
    <tr valign="baseline">
      <th nowrap="nowrap" align="right">排列序:</th>
      <td><input name="raindex" type="text" value="" size="4" maxlength="4" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><input name="sn" type="hidden" id="sn" value="<? echo $sn;?>" />
      <input name="st" type="hidden" id="st" value="<? echo $st;?>" /></td>
      <td><input type="submit" value="插入記錄" /></td>
    </tr>
  </table>
  <input type="hidden" name="webid" value="<?= $_GET['webid'] ?>" />
  <input type="hidden" name="MM_insert" value="form1" />
  <input name="url" type="hidden" id="url" value="<? echo $_SERVER['HTTP_REFERER'];?>" />
</form>

<?php
mysql_free_result($Rtf);
?>
