<?php
// $Id: lostpass.php,v 1.4 2005/10/28 11:56:02 ohwada Exp $

// 2005-09-04 K.OHWADA
// BUG 2932: dont work correctly when register_long_arrays = off

// 2004-11-28 K.OHWADA
// write fair, delete unnecessary comments

// 2004-10-20 K.OHWADA
// use system lang file
//   _WLS_US_xx -> _US_xx

// 2004/08/10 K.OHWADA
// enable to install this module two or more. 

//================================================================
// lostpass
// use class weblinksLink
// porting from system
// 2004/01/23 K.OHWADA
//================================================================

// enable to install this module two or more. 

include "header.php";

$xoopsOption['pagetype'] = "user";

// BUG 2932: dont work correctly when register_long_arrays = off
$lid   = get_post_int('lid');
$email = get_post('email');

if ( empty($lid) )
{
	redirect_header("singlelink.php?lid=$lid",2,_WLS_EMAILNOTFOUND);
	exit();
}

$record = $tbl_link->getRowByLid($lid);

if ( $email != $record['mail'] )
{
	redirect_header("singlelink.php?lid=$lid",2,_WLS_EMAILNOTFOUND);
	exit();
}

$passwd = $tbl_link->make_passwd();
$tbl_link->updatePasswd($lid, $passwd);

$name   = $record['name'];
if (empty($name))  $name = $xoops_user_uname;

$entry   = $MODULE_URL."/modlink.php?lid=$lid&code=$passwd";
$tempdir = $MODULE_ROOT."/language/".$XOOPS_LANGUAGE."/mail_template/";

$xoopsMailer =& getMailer();
$xoopsMailer->useMail();
$xoopsMailer->setTemplateDir($tempdir);
$xoopsMailer->setTemplate("lostpass.tpl");
$xoopsMailer->assign("SITENAME", $xoops_site_name);
$xoopsMailer->assign("ADMINMAIL", $xoops_site_email);
$xoopsMailer->assign("SITEURL", $xoops_site_url);
$xoopsMailer->assign("IP", $server_remote_addr);
$xoopsMailer->assign("NAME",  $name);
$xoopsMailer->assign("ENTRY", $entry);
$xoopsMailer->setToEmails($email);
$xoopsMailer->setFromEmail( $xoops_site_email );
$xoopsMailer->setFromName( $xoops_site_name );
$xoopsMailer->setSubject( sprintf(_US_NEWPWDREQ, $xoops_site_name) );

include XOOPS_ROOT_PATH."/header.php";
echo "<h3>"._WLS_REQUESTMOD."</h3>";
if ( !$xoopsMailer->send() )
{
	echo $xoopsMailer->getErrors();
}
else
{	
	echo "<h4>";
	printf(_US_CONFMAIL,$name);
	echo "</h4>";
}
include XOOPS_ROOT_PATH.'/footer.php';

?>
