<?php
/* Focntion appelé de la page de login, avant chargement complet de l'aplication. */
function new_pass($_POST){
	include("../include/sys_config.php"); // general
	include("config/sys_path.php"); // spe admin
	include("config/sys_config.php"); // spe admin
	var_config_cst($_PX_config,'');
	include_once("../include/sys_tbl_sql.php");
	var_config_cst($TBL,'');
	_prefix_chemin();
	function Genere_Password($size){
		 $characters = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
		 $password='';
		 for($i=0;$i<$size;$i++){
			$password .= ($i%2) ? strtoupper($characters[array_rand($characters)]) : $characters[array_rand($characters)];
		}
		return $password;
	}
	function up_user_base ($login,$pas){
		echo $query =" UPDATE ".TBL_SYS_CONFIG_PERSO_INC.'  SET '.$login.' = \''. $pas .'\'  ';
		return sql ('',TBL_SYS_CONFIG_PERSO_INC,'_user_',$query,'');
	}


	include("config/sys_config_perso.php");
	$lg=trim($_POST['login_user_pass']);
	if  (isset($_user_[$lg])){
		$bak_file='config/users/'.$_user_[$_POST['login_user_pass']].'.inc';
		require($bak_file);
		$mail= $_perso_['email'];
		$name= $_perso_['nom'];
		$pass=Genere_Password(6);
		$key= md5($_POST['login_user_pass'] . $pass);
		$title="Nouveaux passe pour accéder à ".NOM_DU_SITE." \n\r ";
		$mesage= " Votre nouveau mot de passe pour la connexion à  est: ".$pass. " \n Vous pouvez accéder à l'interface du manager à: ". URL_ADMIN ." \n " ;
		if(tep_mail($name, $mail, $title, $mesage, NOM_DU_SITE, EMAIL_WEBMASTER)==true) echo nett_acen(FORM_MAIL_RETOUR_OK) ;
		else echo nett_acen(TXT_ALERT_ADMIN_LOG);
		sleep(2);
		$files='config/users/'.$key.'.inc';
		copy($bak_file,$files);
		calibre_droit_file($files);
		print up_user_base ($_POST['login_user_pass'] ,$key);
		unlink ($files);
		redirect("index.php");
	}else {
		print ("<p><strong>aucun utilisateur nommé ".$_POST['login_user_pass']."</strong></p>");
		redirect("index.php");
	}
}
?>