<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php
 

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE buser SET name=%s, aname=%s, stat=%s, mail=%s, tel=%s, flag=%s WHERE id=%s",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['aname'], "text"),
                       GetSQLValueString($_POST['stat'], "text"),
                       GetSQLValueString($_POST['mail'], "text"),
                       GetSQLValueString($_POST['tel'], "text"),
                       GetSQLValueString($_POST['flag'], "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 buser 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="36%" align="center">
    <tr valign="baseline">
      <th width="5%" height="38" align="right" valign="top" nowrap="nowrap"><span class="font1">使用者帳號</span>：</th>
      <td width="95%" valign="baseline"><input name="name" type="text" id="name" value="<?php echo $row_Rt2['name']; ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <th height="30" align="right" valign="top" nowrap="nowrap"><span class="font1">姓名</span>：</th>
      <td valign="baseline"><input name="aname" type="text" id="aname" value="<?php echo $row_Rt2['aname']; ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <th height="30" align="right" valign="middle" nowrap="nowrap"><span class="font1">連絡電話：</span></th>
      <td height="30" align="left" valign="middle" nowrap="nowrap"><input name="tel" type="text" id="tel" value="<?php echo $row_Rt2['tel']; ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <th height="30" align="right" valign="middle" nowrap="nowrap">Email：</th>
      <td height="30" align="left" valign="middle" nowrap="nowrap"><label for="stat">
        <input name="mail" type="text" id="mail" value="<?php echo $row_Rt2['mail']; ?>" size="32" />
      </label></td>
    </tr>
    <tr valign="baseline">
      <th height="30" align="right" valign="middle" nowrap="nowrap">業務狀態:</th>
      <td height="30" align="left" valign="middle" nowrap="nowrap"><label for="flag"></label>
        <select name="flag" id="flag">
          <option value="Y" <?php if (!(strcmp("Y", $row_Rt2['flag']))) {echo "selected=\"selected\"";} ?>>Y</option>
          <option value="N" <?php if (!(strcmp("N", $row_Rt2['flag']))) {echo "selected=\"selected\"";} ?>>N</option>
        </select>        
      <label for="radio"></label></td>
    </tr>
    <tr valign="baseline">
      <td height="40" colspan="2" align="center" valign="middle" nowrap="nowrap"><input name="id" type="hidden" id="id" value="<?php echo $row_Rt2['id']; ?>" />
<input name="stat" type="hidden" id="stat" value="<?php echo $row_Rt2['stat']; ?>" size="32" />  <? if($row_Rt2['stat']<>"A"){?><input type="submit" value="編輯使用者" /><? }?></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
  <input name="url" type="hidden" id="url" value="<?= $_SERVER['HTTP_REFERER']; ?>" />
  <input type="hidden" name="MM_update" value="form1" />
</form>
 

<?php
mysql_free_result($Rt2);
?>
