<?
include_once("./_common.php");
include_once("$g4[path]/lib/mailer.lib.php");

if ($member[mb_id]) 
{
    echo "<script type='text/javascript'>";
    echo "alert('该会员正在登录状态！密码查询失败！');";
    echo "window.close();";
    echo "opener.document.location.reload();";
    echo "</script>";
    exit;
}

$key = get_session("captcha_keystring");
if (!($key && $key == $_POST[wr_key])) {
    session_unregister("captcha_keystring");
    alert_close("非正常访问！程序终止！");
}

$email = trim($_POST['mb_email']);

if (!$email) 
    alert_close("邮件地址错误！");

$sql = " select count(*) as cnt from $g4[member_table] where mb_email = '$email' ";
$row = sql_fetch($sql);
if ($row[cnt] > 1)
    alert("邮件地址重复！\\n\\n请与管理员联系");

$sql = " select mb_no, mb_id, mb_name, mb_nick, mb_email, mb_datetime from $g4[member_table] where mb_email = '$email' ";
$mb = sql_fetch($sql);
if (!$mb[mb_id]) 
    alert("找不到您查询的会员信息");
else if (is_admin($mb[mb_id])) 
    alert("禁止查询！");

// 创建随机字符
srand(time());
$randval = rand(4, 6); 

$change_password = substr(md5(get_microtime()), 0, $randval);

$mb_lost_certify = sql_password($change_password);
$mb_datetime     = sql_password($mb[mb_datetime]);

// 添加字段
sql_query(" ALTER TABLE `$g4[member_table]` ADD `mb_lost_certify` VARCHAR( 255 ) NOT NULL AFTER `mb_memo` ", false);

$sql = " update $g4[member_table]
            set mb_lost_certify = '$mb_lost_certify'
          where mb_id = '$mb[mb_id]' ";
sql_query($sql);

$href = "$g4[url]/$g4[bbs]/password_lost_certify.php?mb_no=$mb[mb_no]&mb_datetime=$mb_datetime&mb_lost_certify=$mb_lost_certify";

$subject = "您查询的用户名/密码信息";

$content = "";
$content .= "<div style='line-height:180%;'>";
$content .= "<p>您的会员信息</p>";
$content .= "<hr>";
$content .= "<ul>";
$content .= "<li>登录用户名 : $mb[mb_id]</li>";
$content .= "<li>临时密码 : <span style='color:#ff3300; font:13px Verdana;'><strong>$change_password</strong></span></li>";
$content .= "<li>姓名 : ".addslashes($mb[mb_name])."</li>";
$content .= "<li>昵称 : ".addslashes($mb[mb_nick])."</li>";
$content .= "<li>邮件地址 : ".addslashes($mb[mb_email])."</li>";
$content .= "<li>请求时间 : $g4[time_ymdhis]</li>";
$content .= "<li>个人主页 : $g4[url]</li>";
$content .= "</ul>";
$content .= "<hr>";
$content .= "<p><a href='$href' target='_blank'>$href</a></p>";
$content .= "<p>";
$content .= "1. 请点击链接进行用户名/密码查询程序，如果无法直接点击，请复制到浏览器地址栏后访问<br />";
$content .= "2. 进入链接将看到临时登录页面<br />";
$content .= "3. 请使用邮件中告知的临时密码登录<br />";
$content .= "4. 登录后请您尽快修改您的密码";
$content .= "</p>";
$content .= "<p>注意！如果您未申请过用户名/密码查询请求，请直接忽视掉此邮件。</p>";
$content .= "<p></p>";
$content .= "</div>";

$admin = get_admin('super');
mailer($admin[mb_nick], $admin[mb_email], $mb[mb_email], $subject, $content, 1);

alert_close("$email 已发送认证邮件！请您到您的Email信箱确认！");
?>