<?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/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_mque.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/fic_zc.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");
Archivelog(@$_SESSION["code_log"]);

$td = strip_tags(trim($_GET['td'])); // Récupération type demande
$cr = strip_tags(trim($_GET['cr'])); // Récupération code Relevé
$cc = strip_tags(trim($_GET['cc'])); // Récupération code Client

// Pour affichage de l'alert en cas de problème non affecté
$affwarn=TRUE;

// Récupération id site
if (isset($_POST["site"]))
{
	$idscli = strip_tags(trim($_POST['site']));
	$affwarn=FALSE;
}
else
	$idscli=-1;

// Récupération filtre problème
if (isset($_POST["pbms"]))
{
	$pbm = intval(strip_tags(trim($_POST['pbms']))); 
	$affwarn=FALSE;
}
else
	$pbm=0;

// Récupération filtre validité/garantie
if (isset($_POST["valg"]))
{
	$valg = intval(strip_tags(trim($_POST['valg']))); 
	$affwarn=FALSE;
}
else
	$valg=0;

// Vérification si  mot(s) recherché(s)
if (isset($_POST["valg"]))
	$affwarn=FALSE;

if (@$_SESSION["niv_log"] == 1)
{
	$td = "view";
	$cc = $_SESSION["code_log"];
}

$pbm_rel = FALSE;
$choixcli=FALSE;

if ($td<>"add")
{
	if ($cr <> "")
	{
		// Récupération des informations dossier relevé
		$row = lit_enr_rel($cr);
		if (is_array($row))
		{
			extract ($row);
	
			// Contrôle qu'un client n'essaye pas de "hacker" un contrat
			if ((@$_SESSION["niv_log"] == 1) AND ($rel_codecli <> @$_SESSION["code_log"]))
				$pbm_rel = TRUE;
	
			// Contrôle qu'une agence n'essaye pas de "hacker" un contrat
			if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($rel_codeage <> @$_SESSION["code_age"]))
				$pbm_rel = TRUE;
	
			$rel_datecreaf = formatedate($rel_datecrea);
			$rel_datemodf = formatedate($rel_datemod);
			$cc = $rel_codecli;

			$row = lit_enr_cli($rel_codecli);
			if (is_array($row))
			{
				extract($row);
				$ca=$cli_prop;
			}

		}
		else
			$pbm_rel = TRUE;
	}
	else
	{
		if (@$_SESSION["niv_log"] <> 1)
			$pbm_rel = TRUE;
		else
		{
			// Récupération des informations dossier relevé
			$row = lit_enr_rel_cli($cc);
			if (is_array($row))
			{
				extract($row);
				$rel_datecreaf = formatedate($rel_datecrea);
				$rel_datemodf = formatedate($rel_datemod);
				$cr=$rel_code;
				$row = lit_enr_cli($rel_codecli);
				if (is_array($row))
				{
					extract($row);
					$ca=$cli_prop;
				}
			}
			else
				$pbm_rel = TRUE;
		}
	}
}
else
{
	if ($cc<>"")
	{
		if (@$_SESSION["niv_log"] >= 3)
		{
			$row = lit_enr_cli($cc);
			if (is_array($row))
			{
				extract($row);
			
				// Contrôle qu'une agence n'essaye pas de "hacker" un relevé
				switch(@$_SESSION["niv_log"])
				{
					case 3 :
					case 4 :
						if (client_age_ok($cli_code,@$_SESSION["code_age"],TRUE)==FALSE)
							$pbm_rel = TRUE;
						break;
					default :
						break;
				}
				
				$ca=cli_prop;
			}
			else
				$pbm_rel=TRUE;
		}
		else
			$pbm_rel=TRUE;
	}
	else
		$choixcli=TRUE;
}

switch ($td)
{
	case "add" :
		$titre = "CREATION DOSSIER RELEVE";
		break;
	case "edit" :
		$titre = "MISE A JOUR DOSSIER RELEVE";
		break;
	case "view" :
			if (@$_SESSION["niv_log"] > 3)
				$titre = "VOIR DOSSIER RELEVE";
			if (@$_SESSION["niv_log"] == 1)
				$titre = "VOTRE RELEVE DE PARC";
		break;
	case "del" :
		$titre = "SUPPRESSION DOSSIER RELEVE";
		break;
	default :
		$pbm_rel=TRUE;
		break;
}
?>
<!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 : Dossier Relev&eacute;</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>

<!-- Définition Javascript pour calendrier popup -->
  <!-- Feuille de Style -->
  <link rel="stylesheet" type="text/css" media="all" href="../jscript/jscal/skins/aqua/theme.css" title="Aqua" />

  <!-- Script Javascript Principal -->
  <script type="text/javascript" src="../jscript/jscal/calendar.js"></script>

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscript/jscal/lang/calendar-fr.js"></script>

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="../jscript/jscal/calendar-setup.js"></script>
<!-- Fin de la définition Javascript pour calendrier popup -->

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

<script language="javascript">
var tab1_champ=new Array(
	"nom:datecreaf ; format:date ; masque:jj-mm-aaaa ; req:Y ; txt:Date création ; stok:frmok ; stbad:frmbad",
<?PHP
if ($td =="add")
{ 
	if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
	{
		if ($cli_prop == NULL) // On affiche la liste uniquement si le client est non affecté
		{
?>
	"nom:codeage ; format:liste ; req:Y ; txt:Agence ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
		}
		else
		{
?>
	"nom:codeage ; format:txt ; req:Y ; txt:Agence ; stok:frmok ; stbad:frmbad",
<?PHP
		}
	}
	else
	{
?>
	"nom:codeage ; format:txt ; req:Y ; txt:Agence ; stok:frmok ; stbad:frmbad",
<?PHP
	}
}
else
{
?>
	"nom:nomage ; format:txt ; req:Y ; txt:Agence ; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:rnum ; format:alphanum ; req:Y ; txt:Racine codage ; stok:frmok ; stbad:frmbad",
	"nom:num ; format:unsigned ; req:Y ; txt:Dernier numéro machine ; lmx:4 ; stok:frmok ; stbad:frmbad",
	"nom:nota ; format:txt ; req:N ; txt:Notes ; 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>

<?PHP if ($td == "del"){ ?>
<body onload="warndel();metReadonly();">
<?PHP } else { ?>
<body onLoad="metFocus();">
<?PHP }
include_once("entete.inc.php"); 
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<!-- Affiché uniquement s'il y a un code client -->
<?PHP
if ($pbm_rel == FALSE)
{
	if ($choixcli==FALSE)
	{
?>
<table width="100%"  border="0">
<tr>
	<td width="33%">
	<?PHP if ($td <> "view")
	{
	?>
	<p><strong><em><a href="rel_lst.php">Retour &agrave; la liste</a></em></strong></p>
	<?PHP
	}
	?>
	<p><em><a href="#LST" onclick="display('pas_detail','none');display('detail','block');">Licences &amp; Mat&eacute;riels</a>
	<?PHP if (@$_SESSION["niv_log"] == 1) { ?>
	 / <a href="javascript:;" onclick="self.location.href='dpbm.php';">D&eacute;clarer probl&egrave;mes</a>
	<?PHP } ?>
	</em></p>
	</td>
	<td width="33%" valign="top"><div id="oblig" align="center" class="annot_gras_it">(<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"> : Saisie obligatoire)</div>
	</td>
	<td width="33%"><div align="right">
	<div align="right">
	<?PHP
		if (($td == "edit") or ($td == "view"))
		{
		$urlimp = "rel_pdf.php?cr=".$cr."&pbm=0";
		?>
		<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")><img src="../img/print.gif" title="Imprimer relev&Eacute;" width="22" height="22" border="0" align="absmiddle"></a> 
		<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")> Imprimer le relev&eacute; </a></div>
	<?PHP 
		$urlimp = "rel_pdf.php?cr=".$cr."&pbm=1";
	?>
		<br>
		<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")><img src="../img/printc.gif" title="Imprimer relev&Eacute; (+ &eacute;tails probl&egrave;mes)" width="22" height="22" border="0" align="absmiddle"></a> 
		<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")> Imprimer le relev&eacute; (+ d&eacute;tails probl&egrave;mes) </a></div>
	<?PHP
		} 
	?>
	</div>
	</td>
</tr>
</table>
		
<form name="rel_maj" method="post" action="rel_enr.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'',''));">
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="codecli" type="hidden" id="codecli" value="<?PHP echo $cc ?>">
<?PHP if ($td == "add") { ?>
<input name="code" type="hidden" id="code" value="<?PHP echo $rel_code ?>">
<?PHP } ?>
<!-- Date de création -->
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_datecreaf"><div align="right">Date Cr&eacute;ation </div></td>
	<td>
		<input name="datecreaf" type="text" id="datecreaf" value="<?PHP echo $rel_datecreaf ?>" size="10" maxlength="10" readonly="1">
		<?PHP if ($td == "add") { ?>
		<img src="../img/calendar.png" id="f_img_datecreaf" title="Choisir votre date" width="16" height="16">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
		<span class="annot_std_it">(
		<a href="javascript:;" onClick="document.rel_maj.datecreaf.value=''"><img src="../img/raz.gif" width="12" height="12" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="document.rel_maj.datecreaf.value=''")> Annuler</a> )</span>
		<?PHP } ?>
	</td>
</tr>
</table>

<!-- Code du relevé client (affiché uniquement si édition ou suppression) -->
<?PHP if ($td <> "add") {?>
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_coderlic"><div align="right">Code </div></td>
	<td>
		<input name="code" type="text" id="code" value="<?PHP echo $rel_code ?>" size="20" maxlength="20" readonly="1">
	</td>
</tr>
</table>
<?PHP }  ?>

<!-- Affichage du client -->
<table width="800"  border="0">
<tr>
	<td width="400" class="rubfrm" colspan="2"  id="f_codecli">
		<div align="center">Client</div>
	</td>
  </tr>
</table>
	
<!-- Détails client -->
<table width="800"  border="0">
<tr>
	<td width="370" valign="top" bgcolor="#CCFFCC">
	<?PHP
	if (($cli_ste <>"") OR ($cli_nom <> ""))
		echo "<img src=\"../img/".$ico_cpta[$cli_cpta]."\" title =\"".$mess_cpta[$cli_cpta]."\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\">";
	echo "<b>";
	if ($cli_ste <>"") 
	{
		echo $cli_ste."<br>";
		echo "<span class=\"annot_gras_it\">";
	}
	echo $cli_civilite." ".$cli_prenom." ".$cli_nom."<br>";
	if ($cli_ste <>"") 
	{
		echo "</span>";
	}
	echo "</b>";
	echo $cli_adr1."<br>";
	if ($cli_adr2 <>"") 
		echo $cli_adr2."<br>";
	echo Retournecp_openId($cli_ville,TRUE)." ".Retourneville_openId($cli_ville,TRUE)."<br>";
	echo "Tel : ".$cli_telf."<br>";
	?>
	</td>
	<td width="30" valign="top">
	<?PHP 
	if (@$_SESSION["niv_log"] >= 3)
	{
	  $url_affnotesc = "aff_notesc.php?cc=".$cc;
	?>
	  <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_affnotesc; ?>',930,380,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/detail.gif" width="16" height="16" border="0" align="absmiddle"></a>
	  <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_affnotesc; ?>',930,380,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")> Notes</a>
	<?PHP
	}
	else
		echo "&nbsp;";
	?>
	</td>
  </tr>
</table>

<table width="800"  border="0">
<tr>
	<td width="400" class="rubfrm" colspan="2"  id="f_codecli">
		<div align="center">Dossier g&eacute;r&eacute; par</div>
	</td>
  </tr>
</table>

<!-- Code de l'agence (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_codeage"><div align="right">Agence</div></td>
	<td>
		<?PHP
		if ($td =="add")  // Ajout = zone modifiable (on peut choisir une agence)
		{ 
			if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
			{
				if ($cli_prop == NULL) // On affiche la liste uniquement si le client est non affecté
				{
					// Création de la liste des agences ouvertes
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					$rech = "SELECT * FROM ".TBAGE." WHERE `age_ouvert` = '1' ORDER BY age_nom";
					$rs = mysql_query($rech);
		
					if (mysql_num_rows($rs) <> 0)
					{
					?>
					
					<select name="codeage" id="codeage">
		
					<?PHP
						echo "<option value)=\"\">-- Choisissez une agence --</option>";

						while ($resultat = mysql_fetch_array($rs)) 
						{
							extract($resultat);
						
							// Vérifie zone de chalandise
							if (dep_in_zcc_age_open($cli_dep,$cli_codepays,$age_code,FALSE))
							{
								$nom_code = $age_nom." (".$age_code.")";
								echo "<option value=\"".$age_code."\"";
								if ($rel_codeage == $age_code)
									echo " selected";
								echo ">".$nom_code."</option>";
							}
						}
					?>
					</select>
					<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
					<?PHP
					}
					else
					{
					?>
						<select name="codeage" id="codeage">
						<option>-- Pas d'agence ouverte --</option>
						</select>
					<?PHP
					}
					mysql_free_result($rs);
					mysql_close($conn);
				}
				else
				{
					$row = lit_enr_age($cli_prop);
					extract($row);
					$age_nomcode = $age_nom." (".$age_code.")";
				?>
				<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $age_code ?>">
				<input name="nomage" type="text" id="nomage" value="<?PHP echo $age_nomcode ?>" size="50" maxlength="50" readonly="1">
				<?PHP
				}
			}
			else
			{
				$row = lit_enr_age($_SESSION["code_age"]);
				extract ($row);
				$nom_code = $age_nom." (".$age_code.")";
			?>
			<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $_SESSION["code_age"]; ?>">
			<input name="nagence" type="text" id="nagence" value="<?PHP echo $nom_code; ?>" size="50" maxlength="50" readonly="1">
			<?PHP
			}	
		} 
		else  // Edition ou suppression ou visualisation = zone non modifiable (affichage seul)
		{
			$row = lit_enr_age($rel_codeage);
			extract($row);
		?>
			<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $rel_codeage; ?>">
			<input name="nomage" type="text" id="nomage" value="<?PHP echo $age_nom." (".$age_code.")"; ?>" size="50" maxlength="50" readonly="1">
		<?PHP 
		} 
		?>
	</td>
</tr>
</table>

<!-- Délai du relevé -->
<table width="800"  border="0">
<tr>
	<td width="400" class="rubfrm" colspan="2">
		<div align="center">D&eacute;tail du dossier </div>
	</td>
  </tr>
</table>
		
<!-- Codage des machines-->
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_codemach">
		<div align="right">Codage inventaire </div>
		<div align="right"></div>
	</td>
	<td>
	  <?PHP
		if (($td <> "view") and ($td <> "del"))
		{
	  ?>
			Racine codage : 
			<input name="rnum" type="text" id="rnum" value="<?PHP echo $rel_rnum ?>" size="10" maxlength="10"> 
			<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">	    /
			Dernier num&eacute;ro machines : 
		  <?PHP
			if (nb_rpdtc($cc) == 0)
			{
		  ?>
			 <input name="num" type="text" id="num" value="<?PHP echo $rel_num ?>" size="4" maxlength="4"> 
			<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
		  <?PHP
			}
			else
			{
		  ?>
				<input name="num" type="text" id="num" value="<?PHP echo $rel_num ?>" size="4" maxlength="4" readonly="1"> 
				<br>
				<span class="annot_petit_it">(Dernier num&eacute;ro non modifiable car des relev&eacute;s machines ont d&eacute;j&agrave; &eacute;t&eacute; saisis) </span>
		  <?PHP
			}
		}
		else
		{
		?>
			Racine codage : 
			<input name="rnum" type="text" id="rnum" value="<?PHP echo $rel_rnum ?>" size="10" maxlength="10" readonly="1"> 
					/
			Dernier num&eacute;ro machines : 
			<input name="num" type="text" id="num" value="<?PHP echo $rel_num ?>" size="4" maxlength="4" readonly="1"> 
		<?PHP
		}
	  ?>
	</td>
</tr>
</table>

<!-- Notes -->
<table width="800"  border="0">
  <tr>
	<td width="160" valign="top" class="rubfrm" id="f_nota"><div align="right">Notes </div></td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{
		?>
			<textarea name="nota" cols="95" rows="5" id="nota"><?PHP echo htmlspecialchars($rel_nota) ?></textarea>
		<?PHP
		}
		else
		{
		?>
			<textarea name="nota" cols="95" rows="5" id="nota" readonly="readonly"><?PHP echo htmlspecialchars($rel_nota) ?></textarea>
		<?PHP
		}
		?>
	</td>
  </tr>
	<td colspan="2" align="center">
	<?PHP 
	if (($td == "edit") or ($td == "add")) // Boutons si en édition ou création
	{ 
	?>
		<input name="RAZ" type="reset" class="bton_fmarr_std" id="RAZ" value="R&eacute;initialiser">
		<input name="enr" type="submit" class="bton_fmarr_std" id="enr" value="Enregistrer">
		<input name="enrimp" type="submit" class="bton_fmarr_std" id="enrimp" value="Enregistrer &amp; Imprimer">
	<?PHP 
	} 

	if ($td == "del") // Bouton si en mode suppression
	{ 
	?>
		<input name="del" type="submit" class="bton_fmarr_std" id="del" value="Supprimer">
	<?PHP 
	} 
	?>
	</td>
  <tr>
  </tr>
</table>
</form>
<br>

<?PHP
if (($td <> "add") AND ($td<>"del")) // Affichage du détail uniquement en édition ou visualisation
{
?>
<form name="rel_lst" id="rel_lst" method="post" action="rel_maj.php?td=<?PHP echo $td; ?>&cr=<?PHP echo $cr; ?>&cc=<?PHP echo $cc; ?>&ca=<?PHP echo $ca; ?>#detlm">
<!-- Filtre sur site -->
<table width="800"  border="0">
<tr>
	<td width="800" class="rubfrm" colspan="2">
		<a name="detlm"></a>
		<div align="center"><a name="LST"></a>LISTE DES LICENCES &amp; MATERIELS</div>
	</td>
</tr>
<tr>
	<td width="180" class="rubfrm" id="f_site"><div align="right">Filtre par lieu </div></td>
	<?PHP 
	if ($cli_ste<>"")
	{
	?>
	<td>
		<select name="site" id="site" onChange="document.getElementById('rel_lst').submit();">
		<option value="-1" <?PHP if ($idscli == -1) echo "selected"?>>Tous les sites</option>
		<option value="0" <?PHP if ($idscli == 0) echo "selected"?>>Site principal</option>
		<?PHP
			// Création de la liste des sites actifs
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBSCLI." WHERE `scli_actif` = '1' AND `scli_codecli`='".$cli_code."' ORDER BY scli_ste";
			$rs = mysql_query($rech);
		
			if (mysql_num_rows($rs) <> 0)
			{
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
		
					if ($scli_adr2<>"")
						$nom_site = $scli_ste." (".$scli_adr1.", ".$scli_adr2.", ".Retournecp_openId($scli_ville,FALSE)." ".Retourneville_openId($scli_ville,FALSE).")";
					else
						$nom_site = $scli_ste." (".$scli_adr1.", ".Retournecp_openId($scli_ville,FALSE)." ".Retourneville_openId($scli_ville,FALSE).")";
					if ($idscli == $scli_id)
						echo '<option value="'.$scli_id.'" selected>'.$nom_site.'</option>';
					else
						echo '<option value="'.$scli_id.'">'.$nom_site.'</option>';
				}
			}
			mysql_free_result($rs);
		?>
		</select>
	</td>
	<?PHP
	}
	else
	{
	?>
	<td>
	<input name="site" type="hidden" id="site" value="0">
	<input name="nsite" type="text" id="nsite" value="Site principal" readonly="1">
	</td>
	<?PHP
	}
	?>
</tr>
<tr>
	<td width="180" class="rubfrm" id="f_pbm"><div align="right">Filtre par probl&egrave;mes </div></td>
	<td>
	<input type="radio" name="pbms" style="background : #FFFFFF;" value="0" <?PHP if ($pbm==0) echo "checked"?>  onClick="document.getElementById('rel_lst').submit();">
	<?PHP if ($pbm==0) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
	 Toutes les fiches
	<?PHP echo "</span>"; ?>
	<input type="radio" name="pbms" style="background : #FFFFFF;" value="1" <?PHP if ($pbm==1) echo "checked"?>  onClick="document.getElementById('rel_lst').submit();">
	<?PHP if ($pbm==1) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
	 Avec pbm(s) non trait&eacute;(s) 
	<?PHP echo "</span>"; ?>
	<input type="radio" name="pbms" style="background : #FFFFFF;" value="2" <?PHP if ($pbm==2) echo "checked"?>  onClick="document.getElementById('rel_lst').submit();">
	<?PHP if ($pbm==2) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
	 Avec pbms(s) trait&eacute;(s) ou en cours de traitement
	<?PHP echo "</span>"; ?>
	<br>
	<span class="annot_upetit_it">
	(&quot;Avec pbm(s) non trait&eacute;(s)&quot; = contient des probl&egrave;mes non affect&eacute;s &agrave; des interventions / &quot;Avec pbm(s) trait&eacute;(s) ou en cours de traitement&quot; = contient des probl&egrave;me r&eacute;solus ou affect&eacute;s)
	</span>
	</td>
</tr>
<tr>
	<td width="180" class="rubfrm" id="f_pbm"><div align="right">Filtre par validit&eacute;/gtie </div></td>
<td>
	<input type="radio" name="valg" style="background : #FFFFFF;" value="0" <?PHP if ($valg==0) echo "checked"?>  onClick="document.getElementById('rel_lst').submit();">
	<?PHP if ($valg==0) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
	Toutes les fiches
	<?PHP echo "</span>"; ?>
	<input type="radio" name="valg" style="background : #FFFFFF;" value="1" <?PHP if ($valg==1) echo "checked"?>  onClick="document.getElementById('rel_lst').submit();">
	<?PHP if ($valg==1) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
	Ech&eacute;ance &lt;=30 jours
	<?PHP echo "</span>"; ?>
	<input type="radio" name="valg" style="background : #FFFFFF;" value="2" <?PHP if ($valg==2) echo "checked"?>  onClick="document.getElementById('rel_lst').submit();">
	<?PHP if ($valg==2) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
	Ech&eacute;ance &lt;=60 jours
	<?PHP echo "</span>"; ?>
	<input type="radio" name="valg" style="background : #FFFFFF;" value="3" <?PHP if ($valg==3) echo "checked"?>  onClick="document.getElementById('rel_lst').submit();">
	<?PHP if ($valg==3) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
	Ech&eacute;ance d&eacute;pass&eacute;e
	<?PHP echo "</span>"; ?>
	<br>
	<span class="annot_upetit_it">
	(&quot;Ech&eacute;ance &lt;=xx jours&quot; = Dont la date de validit&eacute; ou de garantie est sup&eacute;rieure ou &eacute;gale &agrave; aujourd'hui et inf&eacute;rieure ou &eacute;gale &agrave; xx jours)
	</span>
</td>
</tr>
<tr>
	<td width="180" class="rubfrm" id="f_search"><div align="right">Filtre par mot </div></td>
<td>
	<input type="text" name="search" value="<?php if(!empty($_POST['search']))echo $_POST['search']; ?>" onChange="document.getElementById('rel_lst').submit();"> 
	<a href="javascript:;" onclick="document.rel_lst.search.value=''"><img src="../img/raz.gif" width="12" height="12" border="0" align="absmiddle"></a>
</td>
</tr>
</table>
</form>
<a name="PBM"></a>
<?PHP
if (($idscli!=-1) OR ($pbm!=0) OR ($valg!=0) OR (isset($_POST['search']) && !empty($_POST['search'])))
{
?>
<div id="pas_detail" style="display:none">
<?PHP
}
else
{
?>
<div id="pas_detail" style="display:block">
<?PHP
}

	if (@$_SESSION["niv_log"] >= 3)
	{
?>
	<a href="javascript:;" onclick="display('detail','block');display('pas_detail','none');")><img src="../img/view+.gif" title="Licences &amp; Mat&eacute;riels : D&eacute;tails / Ajouter / Editer / Supprimer / Probl&egrave;mes" width="22" height="22" border="0" align="absmiddle"></a> 
	<a href="javascript:;" onclick="display('detail','block');display('pas_detail','none');"> Licences &amp; Mat&eacute;riels : D&eacute;tails / Ajouter / Editer / Supprimer / Probl&egrave;mes</a>
<?PHP
	}
	else
	{
?>
	<a href="javascript:;" onclick="display('detail','block');display('pas_detail','none');")><img src="../img/view+.gif" title="Licences &amp; Mat&eacute;riels : D&eacute;tails / Probl&egrave;mes" width="22" height="22" border="0" align="absmiddle"></a> 
	<a href="javascript:;" onclick="display('detail','block');display('pas_detail','none');"> Licences &amp; Mat&eacute;riels : D&eacute;tails / Probl&egrave;mes</a>
<?PHP
	}
?>
</div>
<?PHP
if (($idscli!=-1) OR ($pbm!=0) OR ($valg!=0) OR (isset($_POST['search']) && !empty($_POST['search'])))
{
?>
<div id="detail" style="display:block">
<?PHP
}
else
{
?>
<div id="detail"  style="display:none">
<?PHP
}
?>
	<a href="javascript:;" onclick="display('pas_detail','block');display('detail','none');")><img src="../img/view-.gif" title="Pas de d&eacute;tail" width="22" height="22" border="0" align="absmiddle"></a> 
	<a href="javascript:;" onclick="display('pas_detail','block');display('detail','none');"> Pas de d&eacute;tail </a>
	<br>
	<span class="annot_petit_gras">L&eacute;gende :</span>
	 <img src="../img/exclam.gif" title ="Probl&egrave;me(s) non affect&eacute;(s)" border="0" align="absmiddle"> <span class="annot_petit">:</span><span class="annot_petit_it"> Probl&egrave;me(s) d&eacute;tect&eacute;(s)</span>
	 / <img src="../img/rpbmint.png" title ="Intervention(s) en cours" border="0" align="absmiddle" width="22" height="22"> <span class="annot_petit">:</span><span class="annot_petit_it"> Intervention(s) en cours</span>
	 / <img src="../img/dateout.gif" title ="Date d&eacute;pass&eacute;e" border="0" align="absmiddle" width="16" height="16"> <span class="annot_petit">:</span><span class="annot_petit_it"> Date d&eacute;pass&eacute;e</span>
	<br><br>
	<table width="800" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td>
			<span class="annot_gras_it">D&eacute;tail des fiches licences</span> <span class="annot_petit_it">(Laisser la souris sur les icônes pour le détail)</span>
		</td>
		<td align="right">
			<?PHP
			if (($td <> "del") and ($td <> "view"))
			{
				$url_add = "rlic_maj.php?td=add&cc=".$rel_codecli;
			?>
				<a href="<?PHP echo $url_add; ?>"><img src="../img/add.gif" title ="Ajouter fiche licence" width="<?PHP echo $hl_vign ?>"  border="0" align="absmiddle"></a>
				<a href="<?PHP echo $url_add; ?>"> Ajouter fiche Licence</a>
			<?PHP } else { ?>
				&nbsp;
			<?PHP } ?>
		</td>
	  </tr>
	</table>
	<?PHP
	
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);

	switch($pbm)
	{
		case 0 :
			$rech = "SELECT * FROM ".TBRLIC.", ".TBMQUE." WHERE ".TBRLIC.".rlic_codecli = '".$rel_codecli."' AND ".TBRLIC.".rlic_codema = ".TBMQUE.".mque_code";
			break;
		case 1 :
			$rech = "SELECT DISTINCT ".TBRLIC.".rlic_code, ".TBRLIC.".rlic_codecli, ".TBRLIC.".rlic_dateout, ".TBRLIC.".rlic_maxcli, ".TBRLIC.".rlic_daterel, ";
			$rech.= TBRLIC.".rlic_codema, ".TBRLIC.".rlic_modele, ".TBRLIC.".rlic_version, ".TBRLIC.".rlic_dateval, ".TBRLIC.".rlic_legal, ";
			$rech.= TBRPBM.".rpbm_coderlp, ".TBRPBM.".rpbm_codeint, ";
			$rech.= TBMQUE.".mque_ste ";
			$rech.= "FROM ".TBRLIC.", ".TBRPBM.", ".TBMQUE;
			$rech .=" WHERE ".TBRLIC.".rlic_codecli = '".$rel_codecli."' AND ".TBRLIC.".rlic_code = ".TBRPBM.".rpbm_coderlp AND ".TBRLIC.".rlic_codema = ".TBMQUE.".mque_code";
			$rech.=" AND (".TBRPBM.".rpbm_codeint IS NULL)";
			break;
		case 2 :
			$rech = "SELECT DISTINCT ".TBRLIC.".rlic_code, ".TBRLIC.".rlic_dateout, ".TBRLIC.".rlic_maxcli, ".TBRLIC.".rlic_daterel, ";
			$rech.= TBRLIC.".rlic_codema, ".TBRLIC.".rlic_modele, ".TBRLIC.".rlic_version, ".TBRLIC.".rlic_dateval, ".TBRLIC.".rlic_legal, ";
			$rech.= TBRPBM.".rpbm_coderlp, ".TBRPBM.".rpbm_codeint, ";
			$rech.= TBMQUE.".mque_ste ";
			$rech.= "FROM ".TBRLIC.", ".TBRPBM.", ".TBMQUE;
			$rech .=" WHERE ".TBRLIC.".rlic_codecli = '".$rel_codecli."' AND ".TBRLIC.".rlic_code = ".TBRPBM.".rpbm_coderlp AND ".TBRLIC.".rlic_codema = ".TBMQUE.".mque_code";
			$rech.=" AND (".TBRPBM.".rpbm_codeint IS NOT NULL)";
			break;
	}

	switch($valg)
	{
		case 0 :
			break;
		case 1 :
			$nouvdate=nouv_date_plus_jours($datea,30);
			$rech.=" AND (".TBRLIC.".rlic_dateval <= '".$nouvdate."' AND ".TBRLIC.".rlic_dateval >= '".$datea."' AND ".TBRLIC.".rlic_dateval <> '0000-00-00' AND ".TBRLIC.".rlic_dateout = '0000-00-00')";
			break;
		case 2 :
			$nouvdate=nouv_date_plus_jours($datea,60);
			$rech.=" AND (".TBRLIC.".rlic_dateval <= '".$nouvdate."' AND ".TBRLIC.".rlic_dateval >= '".$datea."' AND ".TBRLIC.".rlic_dateval <> '0000-00-00' AND ".TBRLIC.".rlic_dateout = '0000-00-00')";
			break;
		case 3 :
			$rech.=" AND (".TBRLIC.".rlic_dateval <= '".$datea."' AND ".TBRLIC.".rlic_dateval <> '0000-00-00' AND ".TBRLIC.".rlic_dateout = '0000-00-00')";
			break;
	}

	if ($idscli!=-1)
		$rech.=" AND (".TBRLIC.".rlic_idsite = '".$idscli."' OR ".TBRLIC.".rlic_idsite = '-1')";

	if(isset($_POST['search']) && !empty($_POST['search']))  
	{
		$rech .= " AND (";
		$rech .= " ".TBRLIC.".rlic_code LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		 if (datefrcorrecte(trim($_POST['search'])) == TRUE)
		 {
		 	 $daterech = datefrang(trim($_POST['search']));
			 $rech .= " ".TBRLIC.".rlic_daterel LIKE '%".addslashes($daterech)."%' OR";
			 $rech .= " ".TBRLIC.".rlic_dateval LIKE '%".addslashes($daterech)."%' OR";
		 }
		$rech .= " ".TBRLIC.".rlic_modele LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		$rech .= " ".TBRLIC.".rlic_version LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		$rech .= " ".TBMQUE.".mque_ste LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		$rech = substr($rech,0,strlen($rech)-3);
		$rech.=")";
	}

	$rech.=" ORDER BY ".TBRLIC.".rlic_daterel";
	
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) <> 0)
	{
		echo "<table class=\"MtableD\" border=\"0\" width=\"800\" cellpadding=\"0\" cellspacing=\"0\">\n";     
		 
		// Création de l'entête de la table "détails licences"
		echo "<th>";
		echo "Code Fiche";
		echo "</th>\n";
		echo "<th>";
		echo "Fiche créée le";
		echo "</th>\n";
		echo "<th>";
		echo "Editeur";
		echo "</th>\n";
		echo "<th>";
		echo "Modèle / Version";
		echo "</th>\n";
		echo "<th>";
		echo "Validité";
		echo "</th>\n";
		echo "<th>";
		echo "Cliquer";
		echo "</th>\n";
	
		$j = 0;
		
		while ($row = mysql_fetch_assoc($rs)) 
		{         
			// Création de l'entête de ligne (TR)
			creetrlstdet($j);
			
			echo "<td>\n";
			echo $row["rlic_code"]." ";
			if (formatedate($row["rlic_dateout"]) == "")
			{
				if ($row["rlic_legal"] == FALSE)
					echo "<img src=\"../img/point_rouge_clignotant.gif\" title=\"Licence ill&eacute;gale ou non confirm&eacute;e...\" border=\"0\" align=\"absmiddle\">";
				$nb_rlic_utilisees = 0;
				$rech2 = "SELECT * FROM `" .TBRPDT. "` WHERE `rpdt_codecli` = '".$rel_codecli."'";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if (mysql_num_rows($rs2) <> 0)
				{
					while ($resultat = mysql_fetch_array($rs2)) 
					{
						if (ereg($row["rlic_code"],$resultat["rpdt_coderlic"]))
							$nb_rlic_utilisees++;
					}
				}
				if ($nb_rlic_utilisees >= $row["rlic_maxcli"])
				{
					$txtlic = "Licences install&eacute;es : ".$nb_rlic_utilisees." / autoris&eacute;es : ".$row["rlic_maxcli"];
					echo " <img src=\"../img/cd.gif\" title =\"".$txtlic."\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\">";
				}
 
				// Vérification si problème(s) non affecté(s)
				if (($pbm==0) OR ($pbm==1))
				{
					$rexist2 = "SELECT * FROM ".TBRPBM."  WHERE rpbm_coderlp = '".$row["rlic_code"]."' AND rpbm_codeint IS NULL";
					$rs2 = mysql_query($rexist2) or die(mysql_error());
					if (mysql_num_rows($rs2) > 0)
					{
						echo " <img src=\"../img/exclam.gif\" title =\"Probl&egrave;me(s) non affect&eacute;(s) !\" border=\"0\" align=\"absmiddle\">";
					}
				}

				// Vérification si interventions en cours
				if (($pbm==0) OR ($pbm==2))
				{
					$rexist2 = "SELECT * FROM ".TBRPBM."  WHERE rpbm_coderlp = '".$row["rlic_code"]."' AND rpbm_codeint IS NOT NULL AND (rpbm_datett='0000-00-00' OR rpbm_datett IS NULL)";
					$rs2 = mysql_query($rexist2) or die(mysql_error());
					if (mysql_num_rows($rs2) > 0)
					{
						echo "<img src=\"../img/rpbmint.png\" border=\"0\" align=\"absmiddle\"  title =\"Intervention(s) en cours\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\">";
					}
				}
			}
			else
				echo " <img src=\"../img/warn.gif\" title =\"Sortie du parc depuis le ".formatedate($row["rlic_dateout"]).".\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\">";
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			echo formatedate($row["rlic_daterel"]);
			echo "</td>\n";

			echo "<td>\n";
			echo htmlspecialchars($row["mque_ste"],ENT_NOQUOTES);
			echo "</td>\n";

			echo "<td>\n";
			echo htmlspecialchars($row["rlic_modele"],ENT_NOQUOTES);
			if ($row["rlic_version"] <> "")
			{
				echo "<br>";
				echo "Version : ".htmlspecialchars($row["rlic_version"],ENT_NOQUOTES);
			}
			echo "</td>\n";

			echo "<td align=\"center\">\n";
			echo formatedate($row["rlic_dateval"]);

			// Vérification si date validité dépassée
			if ($valg==0)
			{
				if (formatedate($row["rlic_dateout"]) == "")
				{
					if  (formatedate($row["rlic_dateval"]) <> "")
					{
						if ((echeance_depassee_date($datea,$row["rlic_dateval"]) == TRUE)  AND (formatedate($row["rlic_dateout"]) == ""))
							echo " <img src=\"../img/dateout.gif\" title =\"Echéance dépassée !\" border=\"0\" align=\"absmiddle\">";
					}
				}
			}
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			if ($td <> "del")
			{
				if (formatedate($row["rlic_dateout"]) == "")
				{
					if ($td <> "view")
					{
						$lst_maj = TRUE;
						echo "<a href=\"rlic_maj.php?td=edit&crl=".$row["rlic_code"]."\"><img src=\"../img/edit.png\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
					}
					else
					{
						$lst_voir = TRUE;
						echo "<a href=\"rlic_maj.php?td=view&crl=".$row["rlic_code"]."\"><img src=\"../img/detail.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
					}
					echo " ";
					$lst_pbmrel = TRUE;
					echo "<a href=\"rpbm_maj.php?td=add&tr=1&cr=".$row["rlic_code"]."&cap=0\"><img src=\"../img/addpbm.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
					if ($td <> "view")
					{
						echo " ";
						$lst_del = TRUE;
						echo "<a href=\"rlic_maj.php?td=del&crl=".$row["rlic_code"]."\"><img src=\"../img/del.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
					}
				}
				else
				{
					$lst_voir = TRUE;
					echo "<a href=\"rlic_maj.php?td=view&crl=".$row["rlic_code"]."&cc=".$row["rlic_codecli"]."&ca=".$row["rlic_codeage"]."\"><img src=\"../img/detail.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
				}
			}
			else
			{
				echo "-";
			}
			echo "</tr>\n";
		
			$j++;
		}
		echo "</table>\n";
		// Fin affichage table détails licences

		$taille_piedla ="small";
		include("piedla.inc.php");
	}
	else
	{
		echo "Aucune fiche relev&eacute; licence cr&eacute;&eacute;e";
		if ($idscli!=-1)
			echo " sur ce site";
		else
			echo " sur ces sites";
		echo ", avec les filtres demand&eacute;s.<br>";
	}
	mysql_free_result($rs);
	mysql_close($conn);  
	
?>
	<br>
	<table width="800" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td>
			<span class="annot_gras_it">D&eacute;tail des fiches mat&eacute;riels</span> <span class="annot_petit_it">(Laisser la souris sur les icônes pour le détail)</span>
		</td>
		<td align="right">
			<?PHP
			if (($td <> "del") AND ($td <> "view"))
			{
				$url_add = "rpdt_maj.php?td=add&cc=".$rel_codecli;
			?>
				<a href="<?PHP echo $url_add; ?>"><img src="../img/add.gif" title ="Ajouter fiche mat&eacute;riel" width="<?PHP echo $hl_vign ?>"  border="0" align="absmiddle"></a>
				<a href="<?PHP echo $url_add; ?>"> Ajouter fiche mat&eacute;riel</a>
			<?PHP } else { ?>
				&nbsp;
			<?PHP } ?>
		</td>
	  </tr>
	</table>
	<?PHP
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);

	switch($pbm)
	{
		case 0 :
			$rech = "SELECT * FROM ".TBRPDT.", ".TBMQUE.", ".TBRPCAT." WHERE ".TBRPDT.".rpdt_codecli = '".$rel_codecli."' AND ".TBRPDT.".rpdt_codema = ".TBMQUE.".mque_code AND ".TBRPDT.".rpdt_codecat = ".TBRPCAT.".rpcat_code";
			break;
		case 1 :
			$rech = "SELECT DISTINCT ".TBRPDT.".rpdt_code, ".TBRPDT.".rpdt_codecli, ".TBRPDT.".rpdt_dateout, ".TBRPDT.".rpdt_daterel, ".TBRPDT.".rpdt_codecat, ";
			$rech.= TBRPDT.".rpdt_codema, ".TBRPDT.".rpdt_modele, ".TBRPDT.".rpdt_empl, ".TBRPDT.".rpdt_codep, ".TBRPDT.".rpdt_ns, ".TBRPDT.".rpdt_fingar, ";
			$rech.= TBRPBM.".rpbm_coderlp, ".TBRPBM.".rpbm_codeint, ";
			$rech.= TBMQUE.".mque_ste, ";
			$rech.= TBRPCAT.".rpcat_desc ";
			$rech.= "FROM ".TBRPDT.", ".TBRPBM.", ".TBMQUE.", ".TBRPCAT;
			$rech .=" WHERE ".TBRPDT.".rpdt_codecli = '".$rel_codecli."' AND ".TBRPDT.".rpdt_code = ".TBRPBM.".rpbm_coderlp AND ".TBRPDT.".rpdt_codema = ".TBMQUE.".mque_code AND ".TBRPDT.".rpdt_codecat = ".TBRPCAT.".rpcat_code";
			$rech.=" AND ".TBRPBM.".rpbm_codeint IS NULL";
			break;
		case 2 :
			$rech = "SELECT DISTINCT ".TBRPDT.".rpdt_code, ".TBRPDT.".rpdt_codecli, ".TBRPDT.".rpdt_dateout, ".TBRPDT.".rpdt_daterel, ".TBRPDT.".rpdt_codecat, ";
			$rech.= TBRPDT.".rpdt_codema, ".TBRPDT.".rpdt_modele, ".TBRPDT.".rpdt_empl, ".TBRPDT.".rpdt_codep, ".TBRPDT.".rpdt_ns, ".TBRPDT.".rpdt_fingar, ";
			$rech.= TBRPBM.".rpbm_coderlp, ".TBRPBM.".rpbm_codeint, ";
			$rech.= TBMQUE.".mque_ste, ";
			$rech.= TBRPCAT.".rpcat_desc ";
			$rech.= "FROM ".TBRPDT.", ".TBRPBM.", ".TBMQUE.", ".TBRPCAT;
			$rech .=" WHERE ".TBRPDT.".rpdt_codecli = '".$rel_codecli."' AND ".TBRPDT.".rpdt_code = ".TBRPBM.".rpbm_coderlp AND ".TBRPDT.".rpdt_codema = ".TBMQUE.".mque_code AND ".TBRPDT.".rpdt_codecat = ".TBRPCAT.".rpcat_code";
			$rech.=" AND ".TBRPBM.".rpbm_codeint IS NOT NULL";
			break;
	}

	switch($valg)
	{
		case 0 :
			break;
		case 1 :
			$nouvdate=nouv_date_plus_jours($datea,30);
			$rech.=" AND (".TBRPDT.".rpdt_fingar <= '".$nouvdate."' AND ".TBRPDT.".rpdt_fingar >= '".$datea."' AND ".TBRPDT.".rpdt_fingar <> '0000-00-00' AND ".TBRPDT.".rpdt_dateout = '0000-00-00')";
			break;
		case 2 :
			$nouvdate=nouv_date_plus_jours($datea,60);
			$rech.=" AND (".TBRPDT.".rpdt_fingar <= '".$nouvdate."' AND ".TBRPDT.".rpdt_fingar >= '".$datea."' AND ".TBRPDT.".rpdt_fingar <> '0000-00-00' AND ".TBRPDT.".rpdt_dateout = '0000-00-00')";
			break;
		case 3 :
			$rech.=" AND (".TBRPDT.".rpdt_fingar <= '".$datea."' AND ".TBRPDT.".rpdt_fingar <> '0000-00-00' AND ".TBRPDT.".rpdt_dateout = '0000-00-00')";
			break;
	}

	if ($idscli!=-1)
		$rech.=" AND (".TBRPDT.".rpdt_idsite = '".$idscli."' OR ".TBRPDT.".rpdt_idsite = '-1')";

	if( isset($_POST['search']) && !empty($_POST['search']))  
	{
		$rech .= " AND (";
		$rech .= " ".TBRPDT.".rpdt_code LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		 if (datefrcorrecte(trim($_POST['search'])) == TRUE)
		 {
		 	 $daterech = datefrang(trim($_POST['search']));
			 $rech .= " ".TBRPDT.".rpdt_daterel LIKE '%".addslashes($daterech)."%' OR";
			 $rech .= " ".TBRPDT.".rpdt_fingar LIKE '%".addslashes($daterech)."%' OR";
		 }
		$rech .= " ".TBRPDT.".rpdt_modele LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		$rech .= " ".TBRPDT.".rpdt_empl LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		$rech .= " ".TBRPDT.".rpdt_codep LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		$rech .= " ".TBRPDT.".rpdt_ns LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		$rech .= " ".TBRPCAT.".rpcat_desc LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		$rech .= " ".TBMQUE.".mque_ste LIKE '%".str_escape(trim($_POST['search']))."%' OR";
		$rech = substr($rech,0,strlen($rech)-3);
		$rech.=")";
	}

	$rech.=" ORDER BY ".TBRPDT.".rpdt_daterel";
	
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) <> 0)
	{
		echo "<table class=\"MtableD\" border=\"0\" width=\"800\" cellpadding=\"0\" cellspacing=\"0\">\n";     
		 
		// Création de l'entête de la table "détails matériels"
		echo "<th>";
		echo "Code Fiche / Inventaire";
		echo "</th>\n";
		echo "<th>";
		echo "Fiche créée le";
		echo "</th>\n";
		echo "<th>";
		echo "Catégorie";
		echo "</th>\n";
		echo "<th>";
		echo "Constructeur / Modèle / NS / Emplacement ";
		echo "</th>\n";
		echo "<th>";
		echo "Fin Gar.";
		echo "</th>\n";
		echo "<th>";
		echo "Cliquer";
		echo "</th>\n";
	
		$j = 0;
		
		while ($row = mysql_fetch_assoc($rs)) 
		{         
			// Création de l'entête de ligne (TR)
			creetrlstdet($j);
			
			echo "<td>\n";
			echo $row["rpdt_code"]."<br>";
			echo "(".$row["rpdt_codep"].") ";
			if (formatedate($row["rpdt_dateout"]) == "")
			{
 
				// Vérification si problème(s) non affecté(s)
				if (($pbm==0) OR ($pbm==1))
				{
					$rexist2 = "SELECT * FROM ".TBRPBM."  WHERE rpbm_coderlp = '".$row["rpdt_code"]."' AND rpbm_codeint IS NULL";
					$rs2 = mysql_query($rexist2) or die(mysql_error());
					if (mysql_num_rows($rs2) > 0)
					{
						echo " <img src=\"../img/exclam.gif\" title =\"Probl&egrave;me(s) non affect&eacute;(s) !\" border=\"0\" align=\"absmiddle\">";
					}
				}
	
				// Vérification si interventions en cours
				if (($pbm==0) OR ($pbm==2))
				{
					$rexist2 = "SELECT * FROM ".TBRPBM."  WHERE rpbm_coderlp = '".$row["rpdt_code"]."' AND rpbm_codeint IS NOT NULL AND (rpbm_datett='0000-00-00' OR rpbm_datett IS NULL)";
					$rs2 = mysql_query($rexist2) or die(mysql_error());
					if (mysql_num_rows($rs2) > 0)
					{
						echo "<img src=\"../img/rpbmint.png\" align=\"absmiddle\" title =\"Intervention(s) en cours\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\">";
					}
				}
			}
			else					
				echo " <img src=\"../img/warn.gif\" title =\"Sorti du parc depuis le ".formatedate($row["rpdt_dateout"]).".\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\">";
			echo "</td>\n";
			echo "<td align=\"center\">\n";
			echo formatedate($row["rpdt_daterel"]);
			echo "</td>\n";

			echo "<td>\n";
			echo htmlspecialchars($row["rpcat_desc"],ENT_NOQUOTES);
			echo "</td>\n";

			echo "<td>\n";
			echo htmlspecialchars($row["mque_ste"],ENT_NOQUOTES);
			if ($row["rpdt_modele"] <> "")
			{
				echo "<br>";
				echo htmlspecialchars($row["rpdt_modele"],ENT_NOQUOTES);
			}
			if ($row["rpdt_empl"] <> "")
			{
				echo "<br>";
				echo "Empl. : ".htmlspecialchars($row["rpdt_empl"],ENT_NOQUOTES);
			}
			if ($row["rpdt_ns"] <> "")
			{
				echo "<br>";
				echo "NS : ".htmlspecialchars($row["rpdt_ns"],ENT_NOQUOTES);
			}
			echo "</td>\n";


			echo "<td align=\"center\">\n";
			echo formatedate($row["rpdt_fingar"]);

			// Vérification si date garantie dépassée
			if ($valg==0)
			{
				if (formatedate($row["rlic_dateout"]) == "")
				{
					if  (formatedate($row["rpdt_fingar"]) <> "")
					{
						if ((echeance_depassee_date($datea,$row["rpdt_fingar"]) == TRUE)  AND (formatedate($row["rpdt_dateout"]) == ""))
							echo " <img src=\"../img/dateout.gif\" title =\"Plus sous garantie !\" border=\"0\" align=\"absmiddle\">";
					}
				}
			}
			echo "</td>\n";

			echo "<td align=\"center\">\n";
			if ($td <> "del")
			{
				if (formatedate($row["rpdt_dateout"]) == "")
				{
					if ($td <> "view")
					{
						$lst_maj = TRUE;
						echo "<a href=\"rpdt_maj.php?td=edit&crp=".$row["rpdt_code"]."\"><img src=\"../img/edit.png\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
					}
					else
					{
						$lst_voir = TRUE;
						echo "<a href=\"rpdt_maj.php?td=view&crp=".$row["rpdt_code"]."\"><img src=\"../img/detail.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
					}
					echo " ";
					$lst_pbmrel = TRUE;
					echo "<a href=\"rpbm_maj.php?td=add&tr=2&cr=".$row["rpdt_code"]."&cap=0\"><img src=\"../img/addpbm.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
					echo " ";
					if ($td <> "view")
					{
						$lst_del = TRUE;
						echo "<a href=\"rpdt_maj.php?td=del&crp=".$row["rpdt_code"]."\"><img src=\"../img/del.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
					}
				}
				else
				{
					$lst_voir = TRUE;
					echo "<a href=\"rpdt_maj.php?td=view&crp=".$row["rpdt_code"]."\"><img src=\"../img/detail.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
				}
			}
			else
			{
				echo "-";
			}
		
			echo "</tr>\n";
		
			$j++;
		}
	
		echo "</table>\n";
		// Fin affichage table détail
	
		$taille_piedla ="small";
		include("piedla.inc.php");
	}
	else
	{
		echo "Aucune fiche relev&eacute; matériel cr&eacute;&eacute;e";
		if ($idscli!=-1)
			echo " sur ce site";
		else
			echo " sur ces sites";
		echo ", avec les filtres demand&eacute;s.<br>";
	}

	mysql_free_result($rs);
	mysql_close($conn);  
}
?>
</div>
<!-- Fin affichage uniquement si edition ou visualisation -->
<?PHP if ($td == "add")
{
?>
	  <script type="text/javascript">
		Calendar.setup({
			inputField     :    "datecreaf",     // id of the input field
			ifFormat       :    "%d-%m-%Y",      // format of the input field
			button         :    "f_img_datecreaf",  // trigger for the calendar (button ID)
			align          :    "Br",           // alignment (defaults to "Bl")
			electric	   :	false,
			singleClick    :    true
		});
	</script>

	<script type="text/javascript">
	warnnbage(<?PHP echo nb_age_actives(); ?>,"cont");
	warnnbtec(<?PHP echo nb_tec_actifs() ?>);
	warnnbmarque(<?PHP echo nb_marques() ?>);
	warnnbtype(<?PHP echo nb_typlic() ?>);
	</script>
<?PHP 
}
else
{
	if ($td == "edit")
	{
?>
	<script type="text/javascript">
	warncpta(<?PHP echo $cli_cpta; ?>,"cont");
	</script>
<?PHP
		if ($affwarn==TRUE)
		{
			if (exist_rpbm_actif("add",$cli_code,"")==TRUE)
			{
?>
		<script type="text/javascript">
			alert('Il y a des problèmes non affectés sur ce relevé de parc.\nVoir la liste des licences et matériels.');
		</script>
<?PHP
			}
		}
	}
}
?>
<!-- Fin Affiché uniquement s'il y a un code client -->
<?PHP
	}
	else
	{
	?>
		<script type="text/javascript">
		setTimeout("self.location.href=('cli_lst.php');",2000)
		</script>
		<p align="center" class="annot_std_it">Merci de choisir un client...</p>
	<?PHP
	}
}
else
{
	if (@$_SESSION["niv_log"] == 1)
	{
?>
		<script type="text/javascript">
		setTimeout("self.location.href=('index.php');",2000)
		</script>
		<p align="center" class="annot_std_it">Pas de relev&eacute; cr&eacute;&eacute;...</p>
<?PHP
	}
	else
	{
?>
		<script type="text/javascript">
		setTimeout("self.location.href=('rel_lst.php');",2000)
		</script>
		<p align="center" class="annot_std_it">Erreur sur les param&egrave;tres...</p>
<?PHP
	}
}
include_once("pied.php");
?>
