<?php require_once('Connections/BE2.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form")) {
  $updateSQL = sprintf("UPDATE new_user SET sex=%s, brithday=%s, tel=%s, htel=%s, addr=%s WHERE id=%s",
                       GetSQLValueString($_POST['sex'], "text"),
                       GetSQLValueString($_POST['brithday'], "date"),
                       GetSQLValueString($_POST['tel'], "text"),
                       GetSQLValueString($_POST['htel'], "text"),
                       GetSQLValueString($_POST['addr'], "text"),
                       GetSQLValueString($_SESSION['login_user'], "int"));

  mysql_select_db($database_BE2, $BE2);
  $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());
}

$colname_Rt2 = "-1";
if (isset($_SESSION['login_user'])) {
  $colname_Rt2 = $_SESSION['login_user'];
}
mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("SELECT * FROM new_user 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);
?>  <div id="font17-1"> 
                <h2>會員資料</h2>
                <form name="form1" action="<?php echo $editFormAction; ?>"  method="POST">
                <table border="0" cellspacing="2" cellpadding="0">
                  <tr>
                    <th width="152" height="30" valign="middle" nowrap="nowrap" class="s1">帳號：</th>
                    <td colspan="3" class="s12"><span class="s11"><?php echo $row_Rt2['memberid']; ?></span></td>
                  </tr>

                  <tr>
                    <th nowrap="nowrap" class="s1" height="30">會員編號：</th>
                    <td colspan="2"><span class="s11">AP<?php echo sprintf("%08d",$row_Rt2['mpid']); ?></span></td>
                    <td class="s12">&nbsp;</td>
                  </tr>
                  <tr>
                    <th nowrap="nowrap" class="s1" height="30">英文ID：</th>
                    <td colspan="2"><span class="s11"><?php echo $row_Rt2['meid']; ?></span></td>
                    <td class="s12">&nbsp;</td>
                  </tr>
                  <tr>
                    <th nowrap="nowrap" class="s1" height="30">姓名：</th>
                    <td width="169"><input name="textfield2" type="text" class="s12" id="textfield2" value="<?php echo $row_Rt2['username']; ?>" size="10" maxlength="8" readonly="readonly" /></td>
                    <th width="113" nowrap="nowrap" class="s1">性別：</th>
                    <td width="168" class="s12"><input  name="sex" type="radio" id="sex" value="M" <?php if (!(strcmp($row_Rt2['sex'],"M"))) {echo "checked=\"checked\"";} ?>/>
                      先生　
                      <input <?php if (!(strcmp($row_Rt2['sex'],"F"))) {echo "checked=\"checked\"";} ?> type="radio" name="sex" id="sex" value="F" />
                      小姐</td>
                    </tr>
                  <tr>
                    <th nowrap="nowrap" height="30" class="s1">生日：</th>
                    <td colspan="3"><input name="brithday" type="text" class="s12" id="textfield10" value="<?php echo $row_Rt2['brithday']; ?>" /></td>
                  </tr>
                  <tr>
                    <th nowrap="nowrap" height="30" class="s1">連絡電話：</th>
                    <td><input name="tel" type="text" class="s12" id="tel" value="<?php echo $row_Rt2['tel']; ?>" size="10" maxlength="15" /></td>
                    <th nowrap="nowrap" class="s1">行動電話：</th>
                    <td><input name="htel" type="text" class="s12" id="htel" value="<?php echo $row_Rt2['htel']; ?>" /></td>
                  </tr>
                  <tr>
                    <th nowrap="nowrap" class="s1" height="30">聯絡地址：</th>
                    <td colspan="3"><input name="addr" type="text" class="s12" id="addr" value="<?php echo $row_Rt2['addr']; ?>" />
                    <input name="id" type="hidden" class="s12" id="id" value="<?php echo $row_Rt2['addr']; ?>" /></td>
                  </tr>
                  <tr>
                    <td colspan="4" align="right"><input type="submit" name="button" id="button" value="送出" /></td>
                  </tr>
                </table>
                <input type="hidden" name="MM_update" value="form" />
                </form>
               
  </div>
    
<?php
mysql_free_result($Rt2);
?>
