<?php
/**
 * User module
 * 
 * Modifygiven user password from back-office
 * 
 * @package linea21\core\user
 * @author $Author$ - linea21 <info@linea21.com>
 * @version $Id$ 
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

//////////// Check Inclusion de pages ////////////
if (!class_exists('auth')) {
  include_once("../lib/lib_common.php");
  ReloadIndex('admin');
}
////////////

//////////// Check Droits utilisateur ////////////
if (!$l21auth->isSuperAdmin()) ReloadIndex('admin');
////////////

if(isset($_POST['id']))	$id=$_POST['id'];
if(isset($_GET['id']))	$id=$_GET['id'];

$requete=SQL_getAllUserInfo($id);
$result=$sql_object->DBSelect($requete);

// Do record exists?
if(!isset($result[0]['user_login'])) redirect_to('@module_default');

/** include envoi de mail */
include_once(override('../mail/mail_actions.php'));
include_once(override('../mail/send.php'));
$a = array();

$a['recipient'] = $result[0]['profile_email'];
$a['login'] = $result[0]['user_login'];

$user_object = new user;
$a['password']  = $user_object->GetNewPassword();
$result=$user_object->UpdateUserPassword($id, $a['password'], $sql_object);

$a['action'] ='change_pass';

$emailContainer = prepare_email($a);
$r = send_email($emailContainer);

/** end mail */
$link_confirm="confirm.php?rub=".$rub."&todo=".$todo;
if($result) header("Location: ".$link_confirm);
else  system_error();
?>