<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php
 

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE message2 SET company=%s, email=%s, username=%s, tel=%s, htel=%s, addr=%s, sex=%s, doc=%s, masterdoc=%s, idate=%s, ckpay=%s, istat=%s WHERE id=%s",
                       GetSQLValueString($_POST['company'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['tel'], "text"),
                       GetSQLValueString($_POST['htel'], "text"),
                       GetSQLValueString($_POST['addr'], "text"),
                       GetSQLValueString($_POST['sex'], "text"),
                       GetSQLValueString($_POST['doc'], "text"),
					   GetSQLValueString($_POST['masterdoc'], "text"),
                       GetSQLValueString($_POST['idate'], "date"),
                       GetSQLValueString($_POST['ckpay'], "text"),
                       GetSQLValueString($_POST['istat'], "text"),
                       GetSQLValueString($_POST['id'], "int"));

  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 message2 WHERE id = %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);
?>
 
<form action="" method="post" name="form1" id="form1">
  <table width="656" align="center">
    <tr valign="baseline">
      <td width="176" align="right" nowrap="nowrap"><span class="font2">公司名稱</span>:</td>
      <td width="337"><input name="company" type="text" value="<?php echo htmlentities($row_Rt2['company'], ENT_COMPAT, 'utf-8'); ?>" size="32" readonly /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">Email:</span></td>
      <td><input name="email" type="text" value="<?php echo htmlentities($row_Rt2['email'], ENT_COMPAT, 'utf-8'); ?>" size="32" readonly /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">聯絡人</span>:</td>
      <td><input name="username" type="text" value="<?php echo htmlentities($row_Rt2['username'], ENT_COMPAT, 'utf-8'); ?>" size="32" readonly /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">電話</span>:</td>
      <td><input name="tel" type="text" value="<?php echo htmlentities($row_Rt2['tel'], ENT_COMPAT, 'utf-8'); ?>" size="32" readonly /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">手機</span>:</td>
      <td><input name="htel" type="text" value="<?php echo htmlentities($row_Rt2['htel'], ENT_COMPAT, 'utf-8'); ?>" size="32" readonly /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">通訊處</span>:</td>
      <td><input name="addr" type="text" value="<?php echo htmlentities($row_Rt2['addr'], ENT_COMPAT, 'utf-8'); ?>" size="32" readonly /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">性別:</span></td>
      <td><input name="sex" type="text" value="<?php echo htmlentities($row_Rt2['sex'], ENT_COMPAT, 'utf-8'); ?>" size="32" readonly /></td>
    </tr>
    <tr valign="baseline">
      <td align="right" valign="top" nowrap="nowrap"><span class="font2">公司官網:</span></td>
      <td><textarea name="doc" cols="40" rows="6" readonly><?php echo htmlentities($row_Rt2['doc'], ENT_COMPAT, 'utf-8'); ?></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">諮詢日期:</span></td>
      <td><input name="idate" type="text" value="<?php echo htmlentities($row_Rt2['idate'], ENT_COMPAT, 'utf-8'); ?>" size="32" readonly /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">願意加入特約店，請與我聯絡:</span></td>
      <td><input name="ckpay" type="text" value="<?php echo htmlentities($row_Rt2['ckpay'], ENT_COMPAT, 'utf-8'); ?>" size="4" readonly /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><span class="font2">狀態:</span></td>
      <td><select name="istat">
        <option value="Y" <?php if (!(strcmp("Y", htmlentities($row_Rt2['istat'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>已處理</option>
        <option value="N" <?php if (!(strcmp("N", htmlentities($row_Rt2['istat'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>未處理</option>
        <option value="D" <?php if (!(strcmp("D", htmlentities($row_Rt2['istat'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>保留</option>

      </select></td>
    </tr>
    <tr valign="baseline">
      <td align="right" valign="top" nowrap="nowrap"><span class="font2">備註說明:</span></td>
      <td><textarea name="masterdoc" cols="40" rows="6" id="masterdoc"><?php echo htmlentities($row_Rt2['masterdoc'], ENT_COMPAT, 'utf-8'); ?></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="更新記錄" /></td>
    </tr>
  </table>
  <input type="hidden" name="id" value="<?php echo $row_Rt2['id']; ?>" />
  <input type="hidden" name="MM_update" value="form1" />
  <input name="url" type="hidden" id="url" value="<?= $_SERVER['HTTP_REFERER']; ?>" />
</form>
 
<?php
mysql_free_result($Rt2);
?>
