<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.5 www.exoops.info 2006/03 
// $Id: lostpass.php,v 1.4 2003/03/19 06:58:41 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
$xoopsOption['pagetype'] = 'user';
$xoopsOption['page_style'] = 8;
include_once("mainfile.php");
if ( !isset($email) || $email == "" ) {
	redirect_header("user.php", 2, _US_SORRYNOTFOUND);
	exit();
	}
$getuser = XoopsUser::getAllUsers(array("email='".$myts->oopsAddSlashesGPC($email)."'"), true);
if ( empty($getuser) ) {
	redirect_header("user.php", 2, _US_SORRYNOTFOUND);
	exit();
	} else {
		$areyou = substr($getuser[0]->getVar("pass"), 0, 5);
		if ( isset($code) && $areyou == $code ) {
			$newpass     = makepass();
			$xoopsMailer =& getMailer();
			$xoopsMailer->useMail();
			$xoopsMailer->setTemplate("lostpass2.tpl");
			$xoopsMailer->assign("SITENAME", $bcoosConfig['title']);
			$xoopsMailer->assign("ADMINMAIL", $bcoosConfig['adminmail']);
			$xoopsMailer->assign("SITEURL", XOOPS_URL."/");
			$xoopsMailer->assign("IP", _REMOTE_ADDR);
			$xoopsMailer->assign("NEWPWD", $newpass);
			$xoopsMailer->setToUsers($getuser[0]->getVar("uid"));
			$xoopsMailer->setFromEmail($bcoosConfig['adminmail']);
			$xoopsMailer->setFromName($bcoosConfig['title']);
			$xoopsMailer->setSubject(sprintf(_US_NEWPWDREQ, XOOPS_URL));
			if ( !$xoopsMailer->send() ) {
				echo $xoopsMailer->getErrors();
			}
// Next step: add the new password to the database
$cryptpass = md5($newpass);
$query     = "UPDATE ".$db->prefix("users")." SET pass='$cryptpass' WHERE uid=".$getuser[0]->getVar("uid")."";
if ( !$db->query($query) ) {
	include_once("header.php");
	echo _US_MAILPWDNG;
	include_once("footer.php");
	exit();
}
redirect_header("user.php", 3, sprintf(_US_PWDMAILED, $getuser[0]->getVar("uname")));
exit();
// If no Code, send it
} else {
	$xoopsMailer =& getMailer();
	$xoopsMailer->useMail();
	if (!empty($_POST['actkey'])) {
		$xoopsMailer->setTemplate("actkey.tpl");
		$xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $uname));
		} else {
			$xoopsMailer->setTemplate("lostpass1.tpl");
			$xoopsMailer->assign("NEWPWD_LINK", XOOPS_URL."/lostpass.php?email=".$email."&code=".$areyou);
			$xoopsMailer->setSubject(sprintf(_US_NEWPWDREQ, $bcoosConfig['title']));
		}
	$xoopsMailer->assign("SITENAME", $bcoosConfig['title']);
	$xoopsMailer->assign("ADMINMAIL", $bcoosConfig['adminmail']);
	$xoopsMailer->assign("SITEURL", XOOPS_URL."/");
	$xoopsMailer->assign("IP", _REMOTE_ADDR);
	$xoopsMailer->setToUsers($getuser[0]->getVar("uid"));
	$xoopsMailer->setFromEmail($bcoosConfig['adminmail']);
	$xoopsMailer->setFromName($bcoosConfig['title']);
	include_once("header.php");
	if ( !$xoopsMailer->send() ) {
		echo $xoopsMailer->getErrors();
		}
	echo "<h4>";
	printf(_US_CONFMAIL, $getuser[0]->getVar("uname"));
	echo "</h4>";
	include_once("footer.php");
	}
}
?>
