<?php require_once('../Connections/BE2.php'); ?>
<?php


if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE tb5 SET fe1=%s, fekid=%s, fe2=%s, fe3=%s, fe4=%s, fe5=%s WHERE fe0=%s",
                       GetSQLValueString($_POST['fe1'], "int"),
                       GetSQLValueString($_POST['fe2'], "int"),
					   GetSQLValueString($_POST['fe2t'],"text"),
					   GetSQLValueString($_POST['fe3'], "text"),
                       GetSQLValueString($_POST['fe4'], "int"),
					   GetSQLValueString($_POST['fe5'], "text"),
                       GetSQLValueString($_POST['fe0'], "int"));

 // echo $updateSQL ;
   mysql_select_db($database_BE2, $BE2);
   $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());

   $updateGoTo = $_POST['url'];
   header(sprintf("Location: %s", $updateGoTo));
}

$colname_Rt2 = "-1";
if (isset($_GET['id'])) {
  $colname_Rt2 = $_GET['id'];
}
mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("SELECT * FROM tb5 WHERE fe0 = %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);

mysql_select_db($database_BE2, $BE2);
$query_Rtc = sprintf("SELECT distinct(fekid),fe2 FROM tb5 where fekid='%s' order by fe1,fe2,fe4",$row_Rt2['fekid']);
$Rtc = mysql_query($query_Rtc, $BE2) or die(mysql_error());
$row_Rtc = mysql_fetch_assoc($Rtc);
$totalRows_Rtc  = mysql_num_rows($Rtc); 

?>
 
<form action="" method="POST" name="form1" id="form1">
  <table width="618" align="center">
    <tr valign="baseline">
      <td align="right" nowrap="nowrap">選單:</td>
      <td><select name="fe1" id="fe1" onChange="setfe2()">
        <option value="6" <? if($row_Rt2['fe1']==6){ echo 'selected="selected"';}?>>租車查詢</option>
        <option value="7" <? if($row_Rt2['fe1']==7){ echo 'selected="selected"';}?>>觀光旅遊</option>
        <option value="10" <? if($row_Rt2['fe1']==10){ echo 'selected="selected"';}?>>企業徵才</option>
      </select></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="font2">項目:</span></td>
      <td><select name="fe2" id="fe2" >
          <? do { ?>
          <option value="<?= $row_Rtc['fekid'] ; ?>" <? if($row_Rtc['fe2']==$row_Rt2['fe2']){ echo 'selected="selected"';}?>><?php echo $row_Rtc['fe2'] ; ?></option>
          <?php } while ($row_Rtc = mysql_fetch_assoc($Rtc)); ?>
      </select> <input name="fe2t" type="hidden" id="fe2t" value="<?= $row_Rt2['fe2']; ?>" size="12" /></td>
    </tr>
    <tr valign="baseline">
      <td width="33" align="right" nowrap="nowrap"><span class="font2">服務分類</span>:</td>
      <td width="357"><input name="fe3" type="text" id="fe1" value="<?php echo $row_Rt2['fe3']; ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">服務說明</span>:</td>
      <td><textarea name="fe5" cols="40" rows="6" id="fe5"><?php echo $row_Rt2['fe5']; ?></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">排列序</span>:</td>
      <td><input type="text" name="fe4" value="<?php echo $row_Rt2['fe4']; ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><input name="fe0" type="hidden" id="fe0" value="<?php echo $row_Rt2['fe0']; ?>" />        
        <input name="url" type="hidden" id="url" value="<? echo $_SERVER['HTTP_REFERER']?>" /></td>
      <td><input type="submit" value="更新記錄" /></td>
    </tr>
  </table>
  <input name="MM_update" type="hidden" id="MM_update" value="form1" />

</form>
<?php
mysql_free_result($Rtc);
mysql_free_result($Rt2);
?>
