<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.7

Copyright (C) 2006-2007  Sylvain FATOME
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr

Web : http://smitst.homelinux.com
****************************************************************************************/

session_start(); 
include_once("../inc/config.inc.php");
include_once("../inc/func_log.inc.php");
if (CheckURLLog(FALSE)==FALSE) header("Location: ../index.php");
if (CheckNivLog("1")==FALSE) header("Location: ../index.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_txt.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_txtcm.inc.php");
include_once("../inc/func_mail.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../classes/phpmailer/class.phpmailer.php");
include_once("../inc/mail.inc.php");
Archivelog(@$_SESSION["code_log"]);

$pbm_mdpc=FALSE;
$pbm_expw=FALSE;
$nouvpwok=FALSE;
	
$row = lit_enr_cli(@$_SESSION["code_log"]);
if (is_array($row)==TRUE)
{
	extract ($row);
	
	// Récupération du mot de passe
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech = "SELECT * FROM `" .TBPW. "` WHERE `pw_code` = '" .@$_SESSION["code_log"]. "'";
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) == 1) // Il ne peut y avoir qu'un seul résultat
	{
		if ($row = mysql_fetch_array($rs))
		{
			extract ($row);

			if ($pw_actif == 0) // Le compte doit être actif
				$pbm_mdpc=TRUE;
			else
			{
				// On a validé
				if (strip_tags(trim(@$_POST["val"])) == "Valider")
				{
					if ((md5(trim(@$_POST["expw"]))==$pw_pass) AND (trim(@$_POST["expw"])<>trim(@$_POST["pw1"])))
					{
						$rech2 = "UPDATE `" .TBPW. "` SET `pw_pass`='".md5(trim(@$_POST["pw1"]))."' WHERE `pw_code` = '".@$_SESSION["code_log"]."'";
						$rs2 = mysql_query($rech2) or die(mysql_error());
						$nouvpwok=TRUE;
					}
					else
						$pbm_expw=TRUE;
				}
			}
		}
		else
			$pbm_mdpc=TRUE;
	}
	else
		$pbm_mdpc=TRUE;
	mysql_free_result($rs);
	mysql_close($conn);
	if ($nouvpwok==TRUE)
	{
		envoi_mail("Mise à jour mot de passe","cli","mdp","xxx","cli",@$_SESSION["code_log"],trim(@$_POST["pw1"]),"",TRUE);
	}
}
else
	$pbm_mdpc=TRUE;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-type=" content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Changement mot de passe</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../css/smi.css" rel="stylesheet" type="text/css">

<!-- Feuille de style & Script pour le menu -->
<script language="JavaScript" src="../jscript/coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour fenêtres -->
<script language="JavaScript" src="../jscript/fen.js"></script>

<!-- Scripts Javascript pour vérifications -->
<script language="JavaScript" src="../jscript/verif_field.js"></script>

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/vform/vform.js"></script>

<script language="javascript">
var tab_champ=new Array(
	"nom:expw ; format:txt ; req:Y ; txt:Ancien mot de passe ; lmn:1 ; lmx:20; stok:frmok ; stbad:frmbad",
	"nom:pw1 ; format:pw ; pwq:6 ; req:Y ; txt:Nouveau mot de passe; lmn:7 ; lmx:20; stok:frmok ; stbad:frmbad",
	"nom:pw2 ; format:pw ; pwq:6 ; req:Y ; txt:Nouveau mot de passe (confirmation); lmn:7 ; lmx:20; comp:pw1 ; stok:frmok ; stbad:frmbad");
</script>

<!-- Scripts Javascript pour alertes -->
<script language="JavaScript" src="../jscript/alertes.js"></script>

<!-- Scripts Javascript divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

</head>

<body onLoad="metFocus();verif_pw(document.pwl.value,false,'nivpw');">
<?PHP
include_once("../inc/entete.inc.php"); 
if ($pbm_mdpc==FALSE)
{
	if ($pbm_expw==FALSE)
	{
		if ($nouvpwok==FALSE)
		{
?>
<p align="center"><span class="titrepage">CHANGEMENT MOT DE PASSE</span></p>
<br>
<form name="mdpc" id="mdpc" action="mdpc.php" method="post" onSubmit="javascript:; return (VForm(this,tab_champ,'',''));">
<table width="650" border="0" align="center">
<tr>
	<td width="300" class="rubfrm" id="f_expw"><div align="right">Ancien mot de passe</div></td>
	<td>
		<input name="expw" type="password" id="expw" size="26">
	</td>
	<td>&nbsp;</td>
</tr>
<tr>
	<td width="150" class="rubfrm" id="f_pw1"><div align="right">Nouveau mot de passe</div></td>
	<td>
		<input name="pw1" type="text" id="pw1" size="26"  onChange="verif_pw(this.value,true,'nivpw');">
	</td>
	<td class="annot_petit_it">7 caract&egrave;res minimum<br>
	  Diff&eacute;rent de l'ancien</td>
</tr>
<tr nowrap="nowrap">
	<td width="150" id="f_pwq">
	<div align="right" class="annot_petit_it">Qualit&eacute; du mot de passe --></div>
	</td>
	<td>
		<span id="nivpw"><img src="../img/none.gif" width="10" height="17" align="absmiddle"></span>
	</td>
	<td class="annot_petit_it">&nbsp;</td>
</tr>
<tr>
	<td width="150" class="rubfrm" id="f_pw2"><div align="right">Nouveau mot de passe (confirmer)</div></td>
	<td>
		<input name="pw2" type="text" id="pw2" size="26">
	</td>
	<td>&nbsp;</td>
</tr>
</table>
<p align="center">
<input name="RAZ" type="reset" class="bton_fmarr_std" id="RAZ" value="R&eacute;initialiser">
<input name="val" type="submit" class="bton_fmarr_std" id="val" value="Valider">
</p>
</form>
<?PHP
		}
		else
		{
?>
	<script type="text/javascript">
	self.location.href=('index.php');
	</script>
<?PHP
		}
	}
	else
	{
?>
	<script type="text/javascript">
	alert("Problème sur la saisie des mots de passe\Mot de passe original erroné ou\nnouveau mot de passe identique au mot de passe original.");
	self.location.href=('mdpc.php');
	</script>
<?PHP
	}
}
else
{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('index.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Probl&ecirc;me sur les param&egrave;tres...</p>
<?PHP
}
include_once("pied.php");
?>
