<?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
****************************************************************************************/


// Vérification des tentatives de hack
$pos=strpos($_SERVER['PHP_SELF'],"inc.php");
if ($pos===FALSE)
	$ok_inc=TRUE;
else
	$ok_inc=FALSE;
if ($ok_inc==FALSE) header("Location: ../index.php");

include_once("../inc/config.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/lst.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_int.inc.php");

$pbm_rpbm=FALSE;

if (strip_tags(trim(@$_POST["val"])) == "Valider")
{
	$txtmatos="";
	$txtpbm="";
	$lstpbm = "";
	if (count($_POST["rpbm_choisi"]) <> 0)
	{
		for ($i = 0; $i < count($_POST["rpbm_choisi"]); $i++)
		{
			$lstpbm .= $_POST["rpbm_choisi"][$i]."-";
		}
	}
	if ($lstpbm!="")
		$lstpbm = substr($lstpbm,0,strlen($lstpbm)-1);
	if ($lstpbm<>"")
	{
		$txtmatos=htmlspecialchars(cree_txt_matos_int($lstpbm),ENT_QUOTES);
		$txtpbm=htmlspecialchars(cree_txt_pbm_int($lstpbm),ENT_QUOTES);
		$txtfait=htmlspecialchars(cree_txt_fait_int($lstpbm),ENT_QUOTES);
		$_SESSION["pbm_choisis"] = $lstpbm;
	}
	else
		$_SESSION["pbm_choisis"] = "";
}
else
{
	Archivelog(@$_SESSION["code_log"]);

	if ((isset($_GET['td'])) AND (isset($_GET['cc'])) AND (isset($_GET['ci'])) AND (isset($_GET['si'])))
	{
		$td = strip_tags(trim($_GET['td'])); // Récupération type de demande
		
		if (($td<>"add") AND ($td<>"edit"))
			$pbm_rpbm=TRUE;
		$cc = strip_tags(trim($_GET['cc'])); // Récupération code Client
		if ($cc<>"")
		{
			$row=lit_enr_cli($cc);
			if (!is_array($row))
				$pbm_rpbm=TRUE;
		}
		else
				$pbm_rpbm=TRUE;
		$ci = strip_tags(trim($_GET['ci'])); // Récupération code Intervention
		if ($ci<>"")
		{
			if ($td<>"add")
			{
				$row=lit_enr_int($ci);
				if (!is_array($row))
					$pbm_rpbm=TRUE;
			}
		}
		else
		{
			if ($td<>"add")
				$pbm_rpbm=TRUE;
		}
		$si = intval(strip_tags(trim($_GET['si']))); // Récupération de l'id du site
		if ($si<>0)
		{
			$row=lit_enr_scli($si,TRUE);
			if (!is_array($row))
				$pbm_rpbm=TRUE;
		}
	}
	else
		$pbm_rpbm=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 : 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 -->

<script language="JavaScript" src="../jscript/coolmenus/coolmenus4.js"></script>

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

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

</head>

<?PHP
if ($pbm_rpbm==FALSE)
{
if (strip_tags(trim(@$_POST["val"])) <> "Valider") // Si le formulaire n'a pas été validé
{
?>
<body onLoad="javascript:; document.rpbm_lst.check.value=valbouton(document.rpbm_lst);">
	<p align="center"><span class="titrepage">LISTE DES PROBLEMES DECLARES</span></p>
	<p align="center">Merci de choisir les probl&egrave;mes signal&eacute;s que vous souhaitez affecter &agrave; l'intervention
	<?PHP 
	if ($td == "add") 
	{ 
 		echo " en cours de cr&eacute;ation,";
	}	

	if ($td == "edit")
	{
		echo " <span class=\"annot_std_gras\">".$ci."</span>,";
	}
	
	if ($si==0)
	{
		echo "<br>et d&eacute;clar&eacute;s sur le <span class=\"annot_std_gras\">site principal</span>.";
	}

	if ($si>0)
	{
		$row = lit_enr_scli($si,TRUE);
		if (is_array($row)==TRUE)
		{
			extract($row);
			echo "<br>et d&eacute;clar&eacute;s sur le site : <span class=\"annot_std_gras\">".$scli_ste."</span>.";
		}
	}

	if (($td == "edit") OR ($td=="add"))
	{
		echo "<br><br><span 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.</span>";
	} 
	?>
	</p>
	
	<form name="rpbm_lst" method="post" action="rpbm_lst.php">
	<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
	<?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);
	if ($td == "edit") // On est édition d'intervention
		$rech = "SELECT * FROM `" .TBRPBM. "` WHERE (`rpbm_codeint` = '".$ci."' AND `rpbm_idsite`= '".$si."') OR (`rpbm_codecli`= '".$cc."' AND `rpbm_idsite`= '".$si."' AND `rpbm_codeint` IS NULL) ORDER BY `rpbm_datecrea`";
	if ($td == "add") // On est en création d'intervention
		$rech = "SELECT * FROM `" .TBRPBM. "` WHERE `rpbm_codecli`= '".$cc."' AND `rpbm_idsite`= '".$si."' AND `rpbm_codeint` IS NULL ORDER BY `rpbm_datecrea`";

	$rs = mysql_query($rech);
	
	if (mysql_num_rows($rs) <> 0)
	{
	echo "<p align=\"center\">";
	echo "<br>";
	echo "<input type=\"button\" name=\"check\" value=\"Tous\" class=\"bton_fgris_petit\" onclick=\"this.value=checkall(this.value,this.form);\">";
	echo "</p>";

	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&eacute;clar&eacute; le";
	echo "</th>\n";
	echo "<th>";
	echo "D&eacute;clar&eacute; par";
	echo "</th>\n";
	echo "<th>";
	echo "Relev&eacute; / Code Produit / Probl&egrave;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 ".TBMQUE." WHERE `mque_code` = '".$rlic_codema."'";
				$rs3 = mysql_query($rech3);
				if ($row3 = mysql_fetch_array($rs3))
				{
					extract ($row3);
				}
				$txtmatos = "Relevé ".htmlspecialchars($rlic_code,ENT_NOQUOTES)." (licence) :<br>".htmlspecialchars($mque_ste,ENT_NOQUOTES).", mod&egrave;le : ".htmlspecialchars($rlic_modele,ENT_NOQUOTES).", ver. : ".htmlspecialchars($rlic_version,ENT_NOQUOTES);
				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 ".TBMQUE." WHERE `mque_code` = '".$rpdt_codema."'";
				$rs3 = mysql_query($rech3);
				if ($row3 = mysql_fetch_array($rs3))
				{
					extract ($row3);
				}
				$txtmatos = "Relevé ".htmlspecialchars($rpdt_code,ENT_NOQUOTES)." (mat&eacute;riel) :<br>".htmlspecialchars($rpcat_desc,ENT_NOQUOTES)." / ".htmlspecialchars($mque_ste,ENT_NOQUOTES).", mod&egrave;le : ".htmlspecialchars($rpdt_modele,ENT_NOQUOTES)." (code : ".htmlspecialchars($rpdt_codep,ENT_NOQUOTES).")";
				mysql_free_result($rs3);
			}
		}
		mysql_free_result($rs2);

		echo "<b>".$txtmatos."</b><br><br>";
		$tab_txtpbm = cesuretxt_tab(htmlspecialchars($row["rpbm_pbm"],ENT_NOQUOTES),100);
		$txtpbm="";
		foreach ($tab_txtpbm as $index_ligne=>$ligne)
			$txtpbm .= $ligne."<br>";
		echo $txtpbm;
		echo "</td>\n";
		
		echo "<td align=\"center\">\n";
		$choisi = FALSE;
		if ($_SESSION["pbm_choisis"] <> "")
		{
			if (ereg($row["rpbm_id"],$_SESSION["pbm_choisis"]))
				$choisi = TRUE;
		}

		echo "<input type=\"checkbox\" name=\"rpbm_choisi[]\" value=\"".$row["rpbm_id"]."\"";
		if($j%2 == 0)
			echo " class=\"TRalter1D\"";
		else
			echo " class=\"TRalter2D\"";


		if ($choisi == TRUE)
			echo " checked";
			
		if ($td=="view")
			echo " disabled";
		else
			echo " onclick=\"document.rpbm_lst.check.value=valbouton(document.rpbm_lst);\"";
		echo ">";

		echo "</td>\n";
	
		echo "</tr>\n";
	
		$j++;
	}
	
	echo "</table>\n";
	// Fin affichage table détails licences
	?>
	<p align="center">
	<input name="RAZ" type="reset" class="bton_fmarr_std" id="RAZ" value="Remise &agrave; Z&eacute;ro">
	<input name="val" type="submit" class="bton_fmarr_std" id="val" value="Valider">
	<input name="annul" type="button" class="bton_fmarr_std" id="annul" value="Annuler" onClick="javascript:; self.close('fscomp');">
	</p>
	<?PHP	
	}
	else
	{
	?>
	<p align="center">
	<input name="annul" type="button" class="bton_fmarr_std" id="annul" value="Quitter" onClick="javascript:; self.close('fscomp');">
	</p>
	<?PHP
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	</form>
<?PHP
}
else
{
?>
<body>
<script type="text/javascript">
var valmat=window.opener.document.int_maj.mat.value;
var valpbm=window.opener.document.int_maj.pbm.value;
<?PHP
// On génère la variable qui va permettre de comparer
echo "var valtxtmat='".@$_SESSION["txtmatlst"]."';\n";
// Une fois que c'est fait, on réaffecte le nouveau texte généré
$_SESSION["txtmatlst"]=$txtmatos;
// On génère la variable du nouveau texte
echo "var txtmatos ='".$txtmatos."';\n";
// On génère la variable qui va permettre de comparer
echo "var valtxtpbm='".@$_SESSION["txtpbmlst"]."';\n";
// Une fois que c'est fait, on réaffecte le nouveau texte généré
$_SESSION["txtpbmlst"]=$txtpbm;
// On génère la variable du nouveau texte
echo "var txtpbm ='".$txtpbm."';\n";
?>
var matos=update_txt_in_txt(valmat,valtxtmat,txtmatos);
window.opener.document.int_maj.mat.value=matos;
window.opener.document.int_maj.mat.readOnly = true;
var pbm=update_txt_in_txt(valpbm,valtxtpbm,txtpbm);
window.opener.document.int_maj.pbm.value=pbm;
window.opener.document.int_maj.pbm.readOnly = true;
<?PHP
if 	(@$_POST["td"]=="edit")
{
?>
var valfait=window.opener.document.int_maj.fait.value;
<?PHP
// On génère la variable qui va permettre de comparer
echo "var valtxtfait='".@$_SESSION["txtfaitlst"]."';\n";
// Une fois que c'est fait, on réaffecte le nouveau texte généré
$_SESSION["txtfaitlst"]=$txtfait;
// On génère la variable du nouveau texte
echo "var txtfait ='".$txtfait."';\n";
?>
var fait=update_txt_in_txt(valfait,valtxtfait,txtfait);
window.opener.document.int_maj.fait.value=fait;
window.opener.document.int_maj.fait.readOnly = true;
<?PHP
}
?>
self.close();
</script>
<?PHP
}
}
else
{
?>
	<script type="text/javascript">
	self.close('fscomp');
	</script>
<?PHP
}
?>
</body>
</html>
