<?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(TRUE)==FALSE) header("Location: ../index.php");
if (CheckNivLog("1")==FALSE) header("Location: ../index.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_hum.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 : D&eacute;claration de probl&egrave;me</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 vérifications -->
<script language="JavaScript" src="../jscript/verif_form.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:chxml ; format:liste ; req:Y ; txt:Matériel ou licence concerné ; vmn:1 ; 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();">
<?PHP
include_once("../inc/entete.inc.php"); 
if ($pbm_mdpc==FALSE)
{
	if ($pbm_expw==FALSE)
	{
		if ($nouvpwok==FALSE)
		{
?>
<p align="center"><span class="titrepage">DECLARATION DE PROBLEME</span></p>
<br>
<form name="dpbm" id="dpbm" action="" method="post">
<table width="800" border="0" align="center">
<tr>
	<td class="rubfrm" id="f_chxml">
	<div align="center">
	Merci de choisir le mat&eacute;riel ou la licence ayant un probl&egrave;me,<br>
	puis de valider
	</div>
	</td>
</tr>
<tr>
	<td align="center">
	<div class="annot_petit_gras">
	Affichage
	</div>
	<span class="annot_petit_it">
	Licences = Relev&eacute;(Site utilisateur, Marque Mod&egrave;le Version)<br>
	Mat&eacute;riels = Relev&eacute; (Site utilisateur, Inventaire, Marque Mod&egrave;le Num&eacute;ro de s&eacute;rie)
	</span>
	<br><br>
	<select name="chxml" id="chxml">
	<?PHP
	echo "<option value)=\"\">-- Choisissez une licence ou un matériel--</option>";

	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);

	// Création de la liste des licences actives
	$rech = "SELECT * FROM ".TBRLIC." WHERE `rlic_codecli` = '".@$_SESSION["code_log"]."' AND `rlic_dateout` = '0000-00-00' ORDER BY rlic_code";
	$rs = mysql_query($rech);

	if (mysql_num_rows($rs) <> 0)
	{
	?>
	

	<?PHP
		echo "<option value)=\"\" disabled=\"disabled\"></option>\n";
		echo "<option value)=\"\" disabled=\"disabled\">-- Licences actives--</option>\n";

		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
		
			$lien = "rpbm_maj.php?td=add&tr=1&cr=".$rlic_code."&cap=0";
			$nom = $rlic_code;
			if ($rlic_idsite<>-1)
			{
				if ($rlic_idsite<>0)
				{
					$rech2 = "SELECT * FROM ".TBSCLI." WHERE `scli_codecli` = '".@$_SESSION["code_log"]."' AND `scli_id` = '".$rlic_idsite."'";
					$rs2 = mysql_query($rech2);
					if ($row2 = mysql_fetch_array($rs2)) 
					{
						extract($row2);
						$nom.=" (".$scli_ste." - ".Retourneville_openId($scli_ville,FALSE).", ";
					}
				}
				else
					$nom.=" (Site principal, ";
			}
			else
				$nom.=" (Tous les sites, ";

			$rech2 = "SELECT * FROM ".TBMQUE." WHERE `mque_code` = '".$rlic_codema."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2)) 
			{
				extract($row2);
				$nom.=$mque_ste." ";
			}

			$nom.=$rlic_modele." ".$rlic_version.")";

			echo "<option value=\"".$lien."\"";
			echo ">".$nom."</option>\n";
		}
	}
	else
	{
	?>
		<option value="" disabled="disabled">-- Aucune licence active --</option>
	<?PHP
	}
	
	// Création de la liste des matériels actifs
	$rech = "SELECT * FROM ".TBRPDT." WHERE `rpdt_codecli` = '".@$_SESSION["code_log"]."' AND `rpdt_dateout` = '0000-00-00' ORDER BY rpdt_code";
	$rs = mysql_query($rech);

	if (mysql_num_rows($rs) <> 0)
	{
	?>
	

	<?PHP
		echo "<option value)=\"\" disabled=\"disabled\"></option>\n";
		echo "<option value)=\"\" disabled=\"disabled\">-- Matériels actifs --</option>\n";

		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
		
			$lien = "rpbm_maj.php?td=add&tr=2&cr=".$rpdt_code."&cap=0";
			$nom = $rpdt_code;
			if ($rpdt_idsite<>-1)
			{
				if ($rpdt_idsite<>0)
				{
					$rech2 = "SELECT * FROM ".TBSCLI." WHERE `scli_codecli` = '".@$_SESSION["code_log"]."' AND `scli_id` = '".$rpdt_idsite."'";
					$rs2 = mysql_query($rech2);
					if ($row2 = mysql_fetch_array($rs2)) 
					{
						extract($row2);
						$nom.=" (".$scli_ste." - ".Retourneville_openId($scli_ville,FALSE).", ";
					}
				}
				else
					$nom.=" (Site principal, ";
			}
			else
				$nom.=" (Tous les sites, ";
				
			$nom.=$rpdt_codep.", ";

			$rech2 = "SELECT * FROM ".TBMQUE." WHERE `mque_code` = '".$rpdt_codema."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2)) 
			{
				extract($row2);
				$nom.=$mque_ste." ";
			}

			$nom.=$rpdt_modele." ".$rpdt_ns.")";

			echo "<option value=\"".$lien."\"";
			echo ">".$nom."</option>\n";
		}
	}
	else
	{
	?>
		<option value="" disabled="disabled">-- Aucune licence active --</option>
	<?PHP
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	</select>
	<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</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="button" class="bton_fmarr_std" id="val" value="Valider" onClick="javascript:; verif_chxml(this,tab_champ,'','');">
</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");
	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");
?>
