<?php require_once('Connections/CCOM.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']);
}


$colname_Recordset1 = "-1";
if (isset($_POST['m_email'])) {
  $colname_Recordset1 = $_POST['m_email'];
}
mysql_select_db($database_connSQL, $connSQL);
$query_Recordset1 = sprintf("SELECT * FROM memberdata WHERE m_email = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $connSQL) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);$colname_Recordset1 = "-1";
if (isset($_POST['m_email'])) {
  $colname_Recordset1 = $_POST['m_email'];
}
mysql_select_db($database_CCOM, $CCOM);
$query_Recordset1 = sprintf("SELECT * FROM memberdata WHERE m_email = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $CCOM) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php require_once('randompasswd.php'); ?>






<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>網站會員系統</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#99cc00">
<table width="720" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
   <td><table align="left" border="0" cellpadding="0" cellspacing="0" width="720">
	  <tr>
	   <td><img name="memberSystem_r1_c1" src="images/memberSystem_r1_c1.jpg" width="5" height="88" border="0" alt=""></td>
	   <td><img name="memberSystem_r1_c2" src="images/memberSystem_r1_c2.jpg" width="193" height="88" border="0" alt=""></td>
	   <td><img name="memberSystem_r1_c3" src="images/memberSystem_r1_c3.jpg" width="280" height="88" border="0" alt=""></td>
	   <td><table align="left" border="0" cellpadding="0" cellspacing="0" width="222">
	     <tr>
	       <td height="64" align="right" valign="bottom"><table border="0" cellpadding="0" cellspacing="0">
	         <tr>
	           <td><a href="index.php"><img name="memberSystem_r2_c4" src="images/memberSystem_r2_c4.jpg" width="48" height="53" border="0" alt=""></a></td>
	           <td width="11">&nbsp;</td>
	           <td><a href="memberadd.php"><img name="memberSystem_r2_c6" src="images/memberSystem_r2_c6.jpg" width="46" height="53" border="0" alt=""></a></td>
	           </tr>
	         </table></td>
	       </tr>
	     <tr>
	       <td><img name="memberSystem_r3_c4" src="images/memberSystem_r3_c4.jpg" width="222" height="24" border="0" alt=""></td>
	       </tr>
	     </table></td>
	   <td><img name="memberSystem_r1_c11" src="images/memberSystem_r1_c11.jpg" width="20" height="88" border="0" alt=""></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
   <td background="images/memberSystem_r4_c1.jpg"><table width="96%" border="0" align="center" cellpadding="10" cellspacing="0">
     <tr valign="top">
       <td><h1>忘記密碼</h1>
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
             <tr>
               <td width="100" align="center"><img src="images/icon_info2.gif" width="64" height="64"></td>
               <td align="center"><?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?>
                   <table width="100%" border="0" cellspacing="0" cellpadding="0">
                     <tr>您好，<br>
                       <td align="center"><p> <?php 
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
  $updateSQL = sprintf("UPDATE memberdata SET m_passwd=%s WHERE m_email=%s",
                       GetSQLValueString(md5($_POST['m_passwd']), "text"),
                       GetSQLValueString($_POST['m_email'], "text"));

  mysql_select_db($database_connSQL, $connSQL);
  $Result1 = mysql_query($updateSQL, $connSQL) or die(mysql_error());
} ?>親愛的<?php echo $row_Recordset1['m_name']; ?> 您的密碼已經寄往您所登錄的信箱中，<br>
                         請查收並妥善保管密碼。</p>
                         <p>
                           <input name="button" type="button" onclick="window.location='index.asp'" value="回到主頁面">
                        </p></td>
                     </tr>
                   </table>
                   <?php } // Show if recordset not empty ?>
                 <?php if ($totalRows_Recordset1 == 0) { // Show if recordset empty ?>
                   <table width="100%" border="0" cellspacing="0" cellpadding="0">
                     <tr>
                       <td align="center"><p>
                         
                           <?php /*start inputVar script*/ if (isset($_POST['m_email'])){ ?>
                           <?php /*start input_input script*/ if ($_POST['m_email'] == ""){ ?>
                             對不起，資料庫中並沒有您的資料！
                             <?php } /*end inputVar script*/ ?>
                           <?php } /*end input_input script*/ ?>
                       </p>
                         <form action="<?php echo $editFormAction; ?>" method="POST" name="form2">
                           <p>請您輸入申請時所使用的電子郵件：</p>
                           <p>
                             <input name="m_email" type="text" class="normalinput" id="m_email">
                             <input name="submit" type="submit" value="送出">
                             <input name="m_passwd" type="hidden" id="m_passwd" value="<?php echo generatePassword(8) ?>">
                           </p>
                           <input type="hidden" name="MM_update" value="form2">
                         </form></td>
                     </tr>
                   </table>
                   <?php } // Show if recordset empty ?>               </td>
             </tr>
           </table>
           <p>&nbsp;</p>
         </td>
       <td width="180"><p class="head1">會員登入</p>
           <form action="index.php" method="POST" name="form1">
             <table width="100%" border="0" cellspacing="0" cellpadding="4">
               <tr>
                 <th valign="baseline">帳號</th>
                 <td valign="baseline"><input name="username" type="text" class="normalinput" id="username" size="15"></td>
               </tr>
               <tr>
                 <th valign="baseline">密碼</th>
                 <td valign="baseline"><input name="passwd" type="password" class="normalinput" id="passwd" size="15"></td>
               </tr>
               <tr>
                 <td valign="baseline">&nbsp;</td>
                 <td valign="baseline"><input name="rememberMe" type="checkbox" id="rememberMe" value="1" checked>
                   記住我的帳號密碼</td>
               </tr>
               <tr>
                 <td colspan="2" align="center" valign="baseline"><input type="submit" name="Submit" value="登入系統"></td>
               </tr>
               <tr>
                 <td colspan="2" align="center" valign="baseline">&nbsp;</td>
               </tr>
             </table>
           </form>
           <p>&nbsp;</p></td></tr>
   </table></td>
  </tr>
  <tr>
   <td><img name="memberSystem_r6_c1" src="images/memberSystem_r6_c1.jpg" width="720" height="10" border="0" alt=""></td>
  </tr>
  <tr>
   <td><div id="siteinfo"></div></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
