<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../lib/cs_conn.php");
include_once("../lib/cs_common.php");
if(CS_UserFun==1) exit(Web_Error('抱歉,本站会员功能已经关闭!','/'));
if(isset($_COOKIE["cs_name"])) echo "<script>window.location.href ='space.php?ac=home';</script>"; 
$ac=CS_Request("ac");
$username=CS_Request("username");
$userpass=CS_Request("userpass");
$code=CS_Request("code");
if($ac=='pass'){
    if(empty($username)||empty($userpass)) exit(Msg_Error('抱歉,用户名和密码不能为空!','javascript:history.go(-1);'));
             $sql="update ".Getdbname('user')." set CS_Pass='".md5($userpass)."' where CS_Name='".$username."'";
             if($db->query($sql)){
	          exit(Msg_Error('恭喜您，修改成功了!','javascript:history.go(-1);'));
             }else{
	          exit(Msg_Error('抱歉，修改失败了!','javascript:history.go(-1);'));
             }
}
?><!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>找回密码 - <?php echo CS_WebName?></title>
    <link rel="stylesheet" href="css/style.css" />
    <script src="../public/js/jquery.js"></script>
    <script language="javascript"> 
        $(document).ready(function(){
        $("#loginsubmit").click(function(){
		var username=$("#username").val();
	$("#username").css("border-color","#666 #ccc #ccc #666");
	    if(username==""){
		$("#username").css("border","1px solid red");
		$("#tishi").text("请输入正确的账号！").css("color","red");
		return false;}
	    else if((len(username)<4)||(len(username)>16)){
		$("#username").css("border","1px solid red");
		$("#tishi").text("账号限制4-16位！").css("color","red");
		return false;}
	    });
        });
        function len(s) {
	    var l = 0;
	    var a = s.split("");
	    for (var i=0;i<a.length;i++) {
	    if (a[i].charCodeAt(0)<299) {
		l++;
		}
	    else{
               l+=2;
		}
	    }
	    return l;
        }
    </script>
</head>
<body>
<div class="header">
    	<h1><a href="http://<?php echo CS_WebUrl?>/" class=""><?php echo CS_WebName?></a></h1>
        <div class="point">
             <a href="<?php echo CS_WebPath?>">网站首页</a>
<?php
	global $db;
	$sqlw="select * from ".Getdbname('class')." where cs_sid=1 order by CS_sid desc";
	$rs=$db->query($sqlw);
	$num=$db->num_rows($rs);
	$nums=5;
	if($num<$nums){
		$j=$num;
	}else{
		$j=$nums;
	}
	for($i=0;$i<$j;$i++){
		$row=$db->fetch_array($rs);
           echo '<a href="'.LinkUrl('list','dance','id',$row['CS_ID']).'" target="art">'.$row["CS_Name"].'</a>';
	}
?> 
             <a href="./">会员中心</a>
        </div>
</div>
<div class="lo_ct w960">
	<div class="lo_left ft">
		<dl>
			<dt><img src="images/dj.gif" alt="<?php echo CS_WebName?>" width="300" height="200" /></dt>
			<dd>
				<strong>《<?php echo CS_WebName?>》</strong>
				<p>在这里你可以上传个人原创、翻唱的音乐作品供大家分享并进行交流。<a href="reg.php" title="免费注册"  class="red">立即注册&gt;&gt;</a></p>
			</dd>
		</dl>
	</div>
	<div class="login_rt">
	<div class="lo_login rt">
		<h2>会员密码找回</h2>	
		<div id="tishi" class="wr">&nbsp;</div>	
<?php 
if($ac=='mail'){
   
         global $db;
         $sql1="select * from ".Getdbname('user')." where cs_name='".$username."'";
	 $row=$db->getRow($sql1);
         if($row){   
	     $xincode=mt_rand();   //随机数
             setcookie("chshcmspass",$xincode,time()+3200,'/');
             $code="http://".$_SERVER['HTTP_HOST'].CS_WebPath."user/pass.php?ac=code&username=".$username."&code=".md5($username.$xincode);
             $conent="<b><font color=#0000ff>您刚刚在".CS_WebName."会员中心找回了密码!</font></b><br><br>修改新密码地址：<a href=".$code." target=_blank><font color=red>".$code."</font></a><br><br>此连接时间为30分钟内有效，过期无效!<br><br>如果不能直接打开，请复制到浏览器打开!<br><br>发送者:<a href=http://".$_SERVER['HTTP_HOST'].CS_WebPath." target=_blank>".CS_WebName."</a><div>";

                      $send=$smtp->sendmail($row['CS_Email'],CS_Mailname,'密码找回服务',$conent,'HTML');
                      if($send==1){
                         echo '<table class="lo_list"><tr><th>&nbsp;</th><td height="90"><b><font color=red>恭喜您，您的登录密码已经发送直您的邮箱，请登入邮箱查询!</font></b></td></tr></table>';
		      }else{
                         echo '<table class="lo_list"><tr><th>&nbsp;</th><td height="90"><b><font color=#0000ff>抱歉，邮件发送失败，请联系管理员!</font></b></td></tr></table>';
		      }
                      echo "<script>setTimeout(\"window.location='javascript:history.go(-1);'\",20000);</script>";
         }else{
              echo '<table class="lo_list"><tr><th>&nbsp;</th><td>&nbsp;</td></tr><tr><th>&nbsp;</th><td height="90"><b><font color=red>抱歉，该用户名不存在!</font></b></td></tr></table>';
              echo "<script>setTimeout(\"window.location='javascript:history.go(-1);'\",2000);</script>";
         }
}elseif($ac=='code'){
      if(isset($_COOKIE["chshcmspass"])){
	   $CS_Codes=$_COOKIE["chshcmspass"];
      }else{
	   $CS_Codes="chshdjcms";
      }
      $codess=md5($username.$CS_Codes);
     if($codess!=$code){
              echo '<table class="lo_list"><tr><th>&nbsp;</th><td>&nbsp;</td></tr><tr><th>&nbsp;</th><td height="90"><b><font color=#0000ff>对不起，验证已经过期，请重新找回!</font></b></td></tr></table>';
              echo "<script>setTimeout(\"window.location='pass.php'\",3000);</script>";
     }else{
?>
                <form name="regform" action="?ac=pass" method="post">
		<table class="lo_list">
			<tr>
				<th>通行证：</th>
				<td><input name="username" type="text" id="username" value="<?php echo $username?>" class="lo_inp" onfocus="this.style.borderColor='#F93'" onblur="this.style.borderColor='#CCC'"/></td>
			</tr>
			<tr>
				<th>输入新密码：</th>
				<td><input name="userpass" type="password" id="userpass" value="" class="lo_inp" onfocus="this.style.borderColor='#F93'" onblur="this.style.borderColor='#CCC'"/></td>
			</tr>
			<tr>
				<th>&nbsp;</th>
				<td><input type="submit" name="Button" value="修  改" class="lo_bnt" /></td>
			</tr>
			<tr>
				<th>&nbsp;</th>
				<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="reg.php" title="免费注册">免费注册</a>
                                </td>
			</tr>
		</table>
<?php
     }
}else{
?>
                <form name="regform" action="?ac=mail" method="post">
		<table class="lo_list">
			<tr>
				<th>通行证：</th>
				<td><input name="username" type="text" id="username" class="lo_inp" onfocus="this.style.borderColor='#F93'" onblur="this.style.borderColor='#CCC'"/></td>
			</tr>
			<tr>
				<th>&nbsp;</th>
				<td><input type="submit" name="Button" value="找  回" id="loginsubmit" class="lo_bnt" /></td>
			</tr>
			<tr>
				<th>&nbsp;</th>
				<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="reg.php" title="免费注册">免费注册</a>
                                </td>
			</tr>
		</table>
<?php } ?>
	</div>
	<div class="cl"></div>
</div></div>
<div class="dw_fr w960">
Copyright (C) 2009-2013 <?php echo CS_WebUrl?>, All Rights Reserved. <a href="http://<?php echo CS_WebUrl?>/" title="<?php echo CS_WebName?>"><?php echo CS_WebName?></a> 版权所有<br />
增值电信业务经营许可证：<?php echo CS_Webicp?> <?php echo html_entity_decode(stripslashes(CS_WebCount))?>
</div>
</form>
</body>
</html>
