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

Version 0.9.6
Copyright (C) 2006  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
****************************************************************************************/

include ("../inc/config.inc.php");
?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_date.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php require ("../inc/func_txt.inc.php") ?>
<?php require ("../inc/lst.inc.php") ?>
<?PHP
	if (strip_tags(trim(@$_POST["val"])) == "Valider")
	{
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$tab_txtmatos=array();
		$tab_txtpbm=array();
		$lstpbm = "";
		if (count($_POST["rpbm_choisi"]) <> 0)
		{
			for ($i = 0; $i < count($_POST["rpbm_choisi"]); $i++)
			{
				$rech = "SELECT * FROM `" .TBRPBM. "` WHERE `rpbm_id`= '".$_POST["rpbm_choisi"][$i]."'";
				$rs = mysql_query($rech);
				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 ($rpbm_typrel == 1) // C'est une licence
							$rech2 = "SELECT * FROM `" .TBRLIC. "` WHERE `rlic_code`= '".$rpbm_coderlp."'";
						else // C'est du matériel
							$rech2 = "SELECT * FROM `" .TBRPDT. "` WHERE `rpdt_code`= '".$rpbm_coderlp."'";
						$rs2 = mysql_query($rech2);
						if ($row2 = mysql_fetch_array($rs2))
						{
							extract ($row2);
							
							$txtpbm_titre ="---- DETAIL PROBLEME N°".sprintf("%'010s",$rpbm_id)." ----";
							if ($rpbm_typrel == 1) // C'est une licence
							{
								$txtmatos_titre ="---- DETAIL LICENCE CONCERNEE PAR LE PROBLEME N°".sprintf("%'010s",$rpbm_id)." ----";
								$rech3 = "SELECT * FROM ".TBRLPMA." WHERE `rlpma_code` = '".$rlic_codema."'";
								$rs3 = mysql_query($rech3);
								if ($row3 = mysql_fetch_array($rs3))
								{
									extract ($row3);
								}
								$txtmatos_corps1 .= "Relevé ".$rlic_code." : ".$rlpma_desc." ".$rlic_modele." ".$rlic_version;
								mysql_free_result($rs3);
							}
							if ($rpbm_typrel == 2) // C'est du matériel
							{
								$txtmatos_titre ="---- DETAIL MATERIEL CONCERNE PAR LE PROBLEME N°".sprintf("%'010s",$rpbm_id)." ----";
								$rech3 = "SELECT * FROM ".TBRPCAT." WHERE `rpcat_code` = '".$rpdt_codecat."'";
								$rs3 = mysql_query($rech3);
								if ($row3 = mysql_fetch_array($rs3))
								{
									extract ($row3);
								}
								$rech3 = "SELECT * FROM ".TBRLPMA." WHERE `rlpma_code` = '".$rpdt_codema."'";
								$rs3 = mysql_query($rech3);
								if ($row3 = mysql_fetch_array($rs3))
								{
									extract ($row3);
								}
								$txtmatos_corps1 = "Relevé ".$rpdt_code." : ".$rpcat_desc." / ".$rlpma_desc." ".$rpdt_modele." (".$rpdt_codep.")";
								mysql_free_result($rs3);
							}
							$txtpbm_corps1 = $rpbm_pbm;
							$txtpbm_corps2 = "Signalé par ".$rpbm_signale.", le ".formatedate($rpbm_datecrea);
							$txtpbm_pied = "---- FIN PROBLEME N°".sprintf("%'010s",$rpbm_id)." ----";
							if ($rpbm_typrel == 1) // C'est une licence
								$txtmatos_pied = "---- FIN LICENCE CONCERNEE PAR LE PROBLEME N°".sprintf("%'010s",$rpbm_id)." ----";
							if ($rpbm_typrel == 2) // C'est du matériel
								$txtmatos_pied = "---- FIN MATERIEL CONCERNEE PAR LE PROBLEME N°".sprintf("%'010s",$rpbm_id)." ----";
							$tab_txtmatos[]=array($txtmatos_titre,$txtmatos_corps1,$txtmatos_pied);
							$tab_txtpbm[]=array($txtpbm_titre,$txtpbm_corps1,$txtpbm_corps2,$txtpbm_pied);
						}
						mysql_free_result($rs2);
					}
				}
				mysql_free_result($rs);
				$lstpbm .= $rpbm_id."-";
			}
		}
		mysql_close($conn);
		$HTTP_SESSION_VARS["pbm_choisis"] = $lstpbm;
	}
	else
	{
		Archivelog(@$HTTP_SESSION_VARS["code_log"]);

		$td = strip_tags(trim($_GET['td'])); // Récupération type de demande
		$cc = strip_tags(trim($_GET['cc'])); // Récupération code Client
		$ci = strip_tags(trim($_GET['ci'])); // Récupération code Intervention
		$si = strip_tags(trim($_GET['si'])); // Récupération de l'id du site
	}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>

<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Liste Probl&egrave;mes</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 -->
<link href="../inc/menu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="../coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour affichages -->
<script language="JavaScript" src="../inc/aff.js"></script>

<!-- Script Javascript pour moulinage des tableaux-->
<script language="JavaScript" src="../inc/phparray2js.js"></script>

</head>

<body>

<?PHP
echo @$_POST["val"];
if (strip_tags(trim(@$_POST["val"])) <> "Valider") // Si le formulaire n'a pas été validé
{
?>
	<p align="center"><span class="titrepage">LISTE DES PROBLEMES DECLARES</span></p>
	<?PHP if ($td == "add") { ?>
	<p align="center">Merci de choisir les probl&egrave;mes signal&eacute;s que vous souhaitez affecter &agrave; l'intervention en cours de cr&eacute;ation</p>
	<?PHP }
		if ($td == "edit") { 
	?>
	<p align="center">Merci de choisir les probl&egrave;mes signal&eacute;s que vous souhaitez affecter &agrave; l'intervention <span class="annot_std_gras"><?PHP echo $ci;?></span> </p>
	<p align="center" class="annot_gras_it">ATTENTION : apr&egrave;s validation, les zones &quot;mat&eacute;riel&quot; et &quot;probl&egrave;mes&quot; de la fiche intervention seront r&eacute;initialis&eacute;es avec les nouvelles valeurs.</p>
	<?PHP } ?>
	
	<form name="rpbm_lst" method="post" action="rpbm_lst.php">
	<?PHP
	// Création de la liste des relevés de problèmes non résolus
	
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech = "SELECT * FROM `" .TBRPBM. "` WHERE `rpbm_codecli`= '".$cc."' AND `rpbm_idsite`= '".$si."' ORDER BY `rpbm_datecrea`";
	
	$rs = mysql_query($rech);
	
	if (mysql_num_rows($rs) <> 0)
	{
	
	echo "<table class=\"MtableD\" border=\"0\" width=\"890\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";
	 
	// Création de l'entête de la table "relevés de problèmes"
	echo "<th>";
	echo "Déclaré le";
	echo "</th>\n";
	echo "<th>";
	echo "Déclaré par";
	echo "</th>\n";
	echo "<th>";
	echo "Problème";
	echo "</th>\n";
	echo "<th>";
	echo "Choisir";
	echo "</th>\n";
	
	$j = 0;
	$lstpbm = "";
	
	while ($row = mysql_fetch_assoc($rs)) 
	{         
		// Création de l'entête de ligne (TR)
		creetrlstdet($j);
		
		echo "<td align=\"center\">\n";
		echo formatedate($row["rpbm_datecrea"]);
		echo "</td>\n";
		echo "<td>\n";
		echo $row["rpbm_signale"];
		echo "</td>\n";

		echo "<td>\n";
		if ($row["rpbm_typrel"] == 1) // C'est une licence
			$rech2 = "SELECT * FROM `" .TBRLIC. "` WHERE `rlic_code`= '".$row["rpbm_coderlp"]."'";
		else // C'est du matériel
			$rech2 = "SELECT * FROM `" .TBRPDT. "` WHERE `rpdt_code`= '".$row["rpbm_coderlp"]."'";
		$rs2 = mysql_query($rech2);
		if ($row2 = mysql_fetch_array($rs2))
		{
			extract ($row2);

			if ($row["rpbm_typrel"] == 1) // C'est une licence
			{
				$rech3 = "SELECT * FROM ".TBRLPMA." WHERE `rlpma_code` = '".$rlic_codema."'";
				$rs3 = mysql_query($rech3);
				if ($row3 = mysql_fetch_array($rs3))
				{
					extract ($row3);
				}
				$txtmatos = "Licence / Relevé ".$rlic_code." : ".$rlpma_desc." ".$rlic_modele." ".$rlic_version;
				mysql_free_result($rs3);
			}
			if ($row["rpbm_typrel"] == 2) // C'est du matériel
			{
				$rech3 = "SELECT * FROM ".TBRPCAT." WHERE `rpcat_code` = '".$rpdt_codecat."'";
				$rs3 = mysql_query($rech3);
				if ($row3 = mysql_fetch_array($rs3))
				{
					extract ($row3);
				}
				$rech3 = "SELECT * FROM ".TBRLPMA." WHERE `rlpma_code` = '".$rpdt_codema."'";
				$rs3 = mysql_query($rech3);
				if ($row3 = mysql_fetch_array($rs3))
				{
					extract ($row3);
				}
				$txtmatos = "Matériel / Relevé ".$rpdt_code." : ".$rpcat_desc." / ".$rlpma_desc." ".$rpdt_modele." (".$rpdt_codep.")";
				mysql_free_result($rs3);
			}
		}
		mysql_free_result($rs2);

		echo $txtmatos."<br>";
		echo $row["rpbm_pbm"];
		echo "</td>\n";
		
		echo "<td align=\"center\">\n";
		$choisi = FALSE;
		if ($HTTP_SESSION_VARS["pbm_choisis"] <> "")
		{
			if (ereg($row["rpbm_id"],$HTTP_SESSION_VARS["pbm_choisis"]))
				$choisi = TRUE;
		}

		if ($choisi == TRUE)
		{
			if($j%2 == 0)  
				echo "<input type=\"checkbox\" name=\"rpbm_choisi[]\" value=\"".$row["rpbm_id"]."\" class=\"TRalter1D\" checked>";
			else
				echo "<input type=\"checkbox\" name=\"rpbm_choisi[]\" value=\"".$row["rpbm_id"]."\" class=\"TRalter2D\" checked>";
		}
		else
		{
			if($j%2 == 0)  
				echo "<input type=\"checkbox\" name=\"rpbm_choisi[]\" value=\"".$row["rpbm_id"]."\" class=\"TRalter1D\">";
			else
				echo "<input type=\"checkbox\" name=\"rpbm_choisi[]\" value=\"".$row["rpbm_id"]."\" class=\"TRalter2D\">";
		}
		echo "</td>\n";
	
		echo "</tr>\n";
	
		$j++;
	}
	
	echo "</table>\n";
	// Fin affichage table détails licences
	
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	<p align="center">
		<input name="RAZ" type="reset" id="RAZ" value="Remise &agrave; Z&eacute;ro">
		<input name="val" type="submit" id="val" value="Valider">
		<input name="annul" type="button" id="annul" value="Annuler" onClick="javascript:; self.close('fscomp');">
	</p>
	</form>
<?PHP
}
else
{
?>
<script type="text/javascript">
	var tableau1 = new PhpArray2Js("<?php echo htmlspecialchars(serialize($tab_txtmatos)); ?>");
	var tab1 = tableau1.retour();
	var tableau2 = new PhpArray2Js("<?php echo htmlspecialchars(serialize($tab_txtpbm)); ?>");
	var tab2 = tableau2.retour();
	var texte1 ="";
	var texte2 ="";
	

	for (i=0; i<tab1.length; i++)
	{
		texte1 += tab1[i].join("\n")+"\n\n";
	}

	for (i=0; i<tab2.length; i++)
	{
		texte2 += tab2[i].join("\n")+"\n\n";
	}

	window.opener.document.int_maj.mat.value=texte1;
	window.opener.document.int_maj.mat.readOnly = true;
	window.opener.document.int_maj.pbm.value=texte2;
	window.opener.document.int_maj.pbm.readOnly = true;
	self.close();
</script>
<?PHP
}
?>