<?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/fic.inc.php") ?>
<?php require ("../inc/lst.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$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
	$ca = strip_tags(trim($_GET['ca'])); // Récupération code Agence

	if (strip_tags(trim(@$_POST["ok"])) == "Ok")
	{
		$idscli = strip_tags(trim($_POST['site'])); // Récupération id site
	}
	else
	{
		$idscli=-1;
	}
	
	if (@$HTTP_SESSION_VARS["niv_log"] == 1)
	{
		$td = "view";
		$cc = $HTTP_SESSION_VARS["code_log"];
		$ca = "";
	}

	if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
	{
		$ca = $HTTP_SESSION_VARS["code_age"];
	}

	$pbm_rel = FALSE;

	if ($cr <> "")
	{
		// Récupération des informations dossier relevé
		if ($td <> "view")
			$row = lit_enr_rel($cr);
		else
			$row = lit_enr_rel_cli($cc);
		if (is_array($row))
		{
			extract ($row);

			// Contrôle qu'une agence ou un client n'essaye pas de "hacker" un relevé
			if ($td <> "add")
			{
				// Contrôle qu'un client n'essaye pas de "hacker" un relevé
				if ((@$HTTP_SESSION_VARS["niv_log"] == 1) AND ($rel_codecli <> @$HTTP_SESSION_VARS["code_log"]))
					$pbm_rel = TRUE;
				// Contrôle qu'une agence n'essaye pas de "hacker" un contrat
				if (((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3)) AND ($rel_codeage <> @$HTTP_SESSION_VARS["code_age"]))
					$pbm_rel = TRUE;
			}

			$rel_datecreaf = formatedate($rel_datecrea);
			$rel_datemodf = formatedate($rel_datemod);
	
			if ($td == "edit")
			{
				$cc=$rel_codecli;
				$ca=$rel_codeage;
			}
	
			if ($td == "view")
			{
				$ca=$rel_codeage;
			}
	
			if ($td == "add")
			{
				$rel_datecreaf = $datef;
				$rel_datemodf = $datef;
				$rel_code = $cr;
				$rel_codecli = $cc;
				$rel_codeage = $ca;
			}
		}
		else
			$pbm_rel = TRUE;
	}
	else
	{
		if ($td == "view")
		{
			$row = lit_enr_rel_cli($cc);
			if (is_array($row))
				extract ($row);
			$ca=$rel_codeage;
			$cr=$rel_code;
			$rel_datecreaf = formatedate($rel_datecrea);
			$rel_datemodf = formatedate($rel_datemod);
		}

		if ($td == "add")
		{
			$rel_datecreaf = $datef;
			$rel_datemodf = $datef;
			$rel_code = crecodesession("R");
			$rel_codeage = $ca;
			$cr = $rel_code;
			$rel_num = 0;
		}

	}


	$pbm_cli = FALSE;

	if ($cc <>"")
	{
		// Contrôle qu'un client n'essaye pas de "hacker" un relevé
		if ((@$HTTP_SESSION_VARS["niv_log"] == 1) AND ($rel_codecli <> @$HTTP_SESSION_VARS["code_log"]))
			$pbm_cli = TRUE;

		$row = lit_enr_cli($cc);
		if (is_array($row))
		{
			extract ($row);
	
			$rel_codecli = $cc;

			// Contrôle qu'une agence n'essaye pas de "hacker" un relevé
			if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
			{
				$row = lit_enr_age($HTTP_SESSION_VARS["code_age"]);
				extract ($row);
				$zc_couverte = $age_zone;
	
			}
			else
				$zc_couverte = zc_age_actives();
		
			if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
			{
				if (dep_in_zc($cli_dep,$zc_couverte) == TRUE)
				{
					if (($cli_prop <> @$HTTP_SESSION_VARS["code_age"]) AND ($cli_prop <> NULL))
					{
						$pbm_cli = TRUE;
					}
				}
				else
				{
					$pbm_cli = TRUE;
				}
			}
		}
	}

	switch ($td)
	{
		case "add" :
			$titre = "CREATION DOSSIER RELEVE";
			break;
		case "edit" :
			$titre = "MISE A JOUR DOSSIER RELEVE";
			break;
		case "view" :
				if (@$HTTP_SESSION_VARS["niv_log"] > 3)
					$titre = "VOIR DOSSIER RELEVE";
				if (@$HTTP_SESSION_VARS["niv_log"] == 1)
					$titre = "VOTRE RELEVE DE PARC";
			break;
		case "del" :
			$titre = "SUPPRESSION DOSSIER RELEVE";
			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 -->
<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>

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

<!-- Définition Javascript pour calendrier popup -->

  <!-- Feuille de Style -->
  <link rel="stylesheet" type="text/css" media="all" href="../jscal/skins/aqua/theme.css" title="Aqua" />

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

  <!-- Choix du langage -->
  <script type="text/javascript" src="../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="../jscal/calendar-setup.js"></script>

<!-- Fin de la définition Javascript pour calendrier popup -->

<!-- Affichage nouvelle fenêtre pour impression -->
<script type="text/javascript">
	function lanceimp(page)
	{
	  window.open(page,'impression','width='+screen.width+' height='+screen.height);
	}
</script>

<!-- Fonction afficher/cacher un bloc div -->
<script type="text/javascript">
	function display(idobjet,etat)
	{
		var objet = document.getElementById(idobjet);
		etat = objet.style.display;
		if (etat == 'none')
			objet.style.display = 'block';
		else
			objet.style.display = 'none';
	}
</script>

<!-- 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 ((@$HTTP_SESSION_VARS["niv_log"] <> 4) AND (@$HTTP_SESSION_VARS["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>

</head>

<?PHP if ($td == "del"){ ?>
<body onload=warndel();>
<?PHP } else { ?>
<body>
<?PHP } ?>

<?php 
	include_once ("entete.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) AND ($pbm_cli==FALSE))
{
	if ($cc <> "")
	{
		if ($cr <> "")
		{
?>
		<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<br>
			</a></em></strong></p>
			<?PHP
			}
			else
			{
			?>
				&nbsp;
			<?PHP
			}
			?>
			</td>
			<td width="33%" valign="top"><div align="center"><span class="annot_gras_it">(<img src="../img/oblig.gif" width="10" height="11"> : Saisie obligatoire)</span> </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="typdde" type="hidden" id="typdde" value="<?PHP echo $td ?>">
		<input name="codecli" type="hidden" id="codecli" value="<?PHP echo $rel_codecli ?>">
		<?PHP if ($td == "add") { ?>
			<input name="code" type="hidden" id="code" value="<?PHP echo $rel_code ?>">
		<?PHP } else {?>
			<input name="code" type="hidden" id="code" value="<?PHP echo $rel_code ?>">
			<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $rel_codeage ?>">
		<?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">
				<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($cli_ville)." ".Retourneville($cli_ville)."<br>";
			echo "Tel : ".$cli_telf."<br>";
			?>
			</td>
			<td width="30" valign="top">
			<?PHP 
			if (@$HTTP_SESSION_VARS["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 ((@$HTTP_SESSION_VARS["niv_log"] <> 4) AND (@$HTTP_SESSION_VARS["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>-- Choisissez une agence --</option>";
								while ($resultat = mysql_fetch_array($rs)) 
								{
									extract($resultat);
					
									// Vérifie zone de chalandise
									if (exist_chaine_in_seq($cli_dep,$age_zone) == TRUE)
									{
										$nom_code = $age_nom." (".$age_code.")";
										if ($rel_codeage == $age_code)
											echo '<option value="'.$age_code.'" selected>'.$nom_code.'</option>';
										else
											echo '<option value="'.$age_code.'">'.$nom_code.'</option>';
									}
								}
							?>
							</select>
							<img src="../img/oblig.gif" width="10" height="11">
							<?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($HTTP_SESSION_VARS["code_age"]);
						extract ($row);
						$nom_code = $age_nom." (".$age_code.")";
					?>
						<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $HTTP_SESSION_VARS["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="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 machines </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">	    /
					Dernier num&eacute;ro machines : 
				  <?PHP
					if (nb_rpdtc($rel_codecli) == 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">
				  <?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 $rel_nota ?></textarea>
				<?PHP
				}
				else
				{
				?>
					<textarea name="nota" cols="95" rows="5" id="nota" readonly="readonly"><?PHP echo $rel_nota ?></textarea>
				<?PHP
				}
				?>
			</td>
		  </tr>
		</table>

		<p align="center">
		<?PHP 
		if (($td == "edit") or ($td == "add")) // Boutons si en édition ou création
		{ 
		?>
			<input name="RAZ" type="reset" id="RAZ" value="R&eacute;initialiser">
			<input name="enr" type="submit" id="enr" value="Enregistrer">
			<input name="enrimp" type="submit" id="enrimp" value="Enregistrer &amp; Imprimer">
		<?PHP 
		} 
		?>

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

		<?PHP
		if ($td <> "add")// Affichage du détail uniquement en édition ou visualisation
		{
		?>
			<br>
			<form name="rel_lst" method="post" action="rel_maj.php?td=<?PHP echo $td; ?>&cr=<?PHP echo $cr; ?>&cc=<?PHP echo $cc; ?>&ca=<?PHP echo $ca; ?>">
			<!-- Filtre sur site -->
			<table width="800"  border="0">
			<tr>
				<td width="160" class="rubfrm" id="f_site"><div align="right">Filtrer par lieu </div></td>
				<?PHP 
				if ($cli_ste<>"")
				{
				?>
				<td width="100">
					<select name="site" id="site">
					<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($scli_ville)." ".Retourneville($scli_ville).")";
								else
									$nom_site = $scli_ste." (".$scli_adr1.", ".Retournecp($scli_ville)." ".Retourneville($scli_ville).")";
								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>
				<td align="left">
					<input name="ok" type="submit" id="ok" value="Ok">
				</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>
			</table>
			</form>
		<?PHP
		if (strip_tags(trim(@$_POST["ok"])) == "Ok")
		{
		?>
		<div id="pas_detail" style="display:none">
		<?PHP
		}
		else
		{
		?>
		<div id="pas_detail" style="display:block">
		<?PHP
		}
		
			if (@$HTTP_SESSION_VARS["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 (strip_tags(trim(@$_POST["ok"])) == "Ok")
		{
		?>
		<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>
			<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_std_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&cr=".$rel_code."&crl=&cc=".$rel_codecli."&ca=".$rel_codeage;
					?>
						<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);

			if ($idscli==-1)
				$rech = "SELECT * FROM ".TBRLIC." WHERE `rlic_codecli` = '".$rel_codecli."' ORDER BY rlic_daterel";
			else
				$rech = "SELECT * FROM ".TBRLIC." WHERE `rlic_codecli` = '".$rel_codecli."' AND (`rlic_idsite` = '".$idscli."' OR  `rlic_idsite` = '-1') ORDER BY 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 "Marque";
				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égale...\" 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ées : ".$nb_rlic_utilisees." / autorisé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)
						$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\">";
						}
			
					}
					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";
					$rech2 = "SELECT * FROM ".TBRLPMA." WHERE `rlpma_code` = '".$row["rlic_codema"]."'";
					$rs2 = mysql_query($rech2) or die(mysql_error());
					if (mysql_num_rows($rs2) <> 0)
					{
						if ($row2 = mysql_fetch_array($rs2))
							echo $row2["rlpma_desc"];
						else
							echo "-";
					}
					else
						echo "-";
					mysql_free_result($rs2);
					echo "</td>\n";
		
					echo "<td>\n";
					echo $row["rlic_modele"];
					if ($row["rlic_version"] <> "")
					{
						echo "<br>";
						echo "Version : ".$row["rlic_version"];
					}
					echo "</td>\n";
		
					echo "<td align=\"center\">\n";
					echo formatedate($row["rlic_dateval"]);
					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/exclam.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"]."&cc=".$row["rlic_codecli"]."&ca=".$row["rlic_codeage"]."\"><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"]."&cc=".$row["rlic_codecli"]."&ca=".$row["rlic_codeage"]."\"><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"]."&cc=".$row["rlic_codecli"]."&ca=".$row["rlic_codeage"]."\"><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 ("../inc/piedla.php");
			}
			else
			{
				echo "Aucune fiche relevé licence créée.<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>
				</td>
				<td align="right">
					<?PHP
					if (($td <> "del") AND ($td <> "view"))
					{
						$url_add = "rpdt_maj.php?td=add&cr=".$rel_code."&crp=&cc=".$rel_codecli."&ca=".$rel_codeage;
					?>
						<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);
		
			if ($idscli==-1)
				$rech = "SELECT * FROM ".TBRPDT." WHERE `rpdt_codecli` = '".$rel_codecli."' ORDER BY rpdt_daterel";
			else
				$rech = "SELECT * FROM ".TBRPDT." WHERE `rpdt_codecli` = '".$rel_codecli."' AND (`rpdt_idsite` = '".$idscli."' OR `rpdt_idsite` = '-1') ORDER BY 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";
				echo "</th>\n";
				echo "<th>";
				echo "Fiche créée le";
				echo "</th>\n";
				echo "<th>";
				echo "Catégorie";
				echo "</th>\n";
				echo "<th>";
				echo "Marque / 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"]." ";
					if (formatedate($row["rpdt_dateout"]) == "")
					{
		 
						// Vérification si problème(s) non affecté(s)
						$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\">";
						}
			
					}
					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";
					$rech2 = "SELECT * FROM ".TBRPCAT." WHERE `rpcat_code` = '".$row["rpdt_codecat"]."'";
					$rs2 = mysql_query($rech2) or die(mysql_error());
					if (mysql_num_rows($rs2) <> 0)
					{
						if ($row2 = mysql_fetch_array($rs2))
							echo $row2["rpcat_desc"];
						else
							echo "-";
					}
					else
						echo "-";
					mysql_free_result($rs2);
					echo "</td>\n";
		
					echo "<td>\n";
					$rech2 = "SELECT * FROM ".TBRLPMA." WHERE `rlpma_code` = '".$row["rpdt_codema"]."'";
					$rs2 = mysql_query($rech2) or die(mysql_error());
					if (mysql_num_rows($rs2) <> 0)
					{
						if ($row2 = mysql_fetch_array($rs2))
							echo $row2["rlpma_desc"];
						else
							echo "-";
					}
					else
						echo "-";
					mysql_free_result($rs2);
					if ($row["rpdt_modele"] <> "")
					{
						echo "<br>";
						echo $row["rpdt_modele"];
					}
					if ($row["rpdt_empl"] <> "")
					{
						echo "<br>";
						echo "Empl. : ".$row["rpdt_empl"];
					}
					if ($row["rpdt_ns"] <> "")
					{
						echo "<br>";
						echo "NS : ".$row["rpdt_ns"];
					}
					echo "</td>\n";
		
		
					echo "<td align=\"center\">\n";
					echo formatedate($row["rpdt_fingar"]);
					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/exclam.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"]."&cc=".$row["rpdt_codecli"]."&ca=".$row["rpdt_codeage"]."\"><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"]."&cc=".$row["rpdt_codecli"]."&ca=".$row["rpdt_codeage"]."\"><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"]."&cc=".$row["rpdt_codecli"]."&ca=".$row["rpdt_codeage"]."\"><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"]."&cc=".$row["rpdt_codecli"]."&ca=".$row["rpdt_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étail
			
				$taille_piedla ="small";
				include ("../inc/piedla.php");
			}
			else
			{
				echo "Aucune fiche relevé matériel créée.<br>";
			}
		
			mysql_free_result($rs);
			mysql_close($conn);  
		?>
		</div>
		<?PHP
		}
		?>
	
	
		<?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          :    "Ll",           // alignment (defaults to "Bl")
					singleClick    :    true
				});
			</script>
		<?PHP
		}
		?>	
	
	<?PHP if ($td == "add") 
	{
	?>
		<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">
			warnedit(<?PHP echo $cli_cpta; ?>,"cont");
			</script>
	<?PHP
		}
	}
	?>  

<!-- Fin Affiché uniquement s'il y a un code client -->
<?PHP
		}
		else
		{
		?>
			<script type="text/javascript">
			setTimeout("self.location.href=('index.php');",2000)
			</script>
			<p align="center" class="annot_std_it">Pas de relev&eacute; sur ce compte...</p>
		<?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 ($pbm_rel==TRUE) 
	{
		if (@$HTTP_SESSION_VARS["niv_log"] == 1)
		{
?>
			<script type="text/javascript">
			setTimeout("self.location.href=('index.php');",2000)
			</script>
			<p align="center" class="annot_std_it">Merci de choisir votre relev&eacute;...</p>
<?PHP
		}
		if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
		{
?>
			<script type="text/javascript">
			setTimeout("self.location.href=('rel_lst.php');",2000)
			</script>
			<p align="center" class="annot_std_it">Merci de choisir un de vos relev&eacute;s...</p>
<?PHP
		}
	}
	else
	{
		if (@$HTTP_SESSION_VARS["niv_log"] == 1)
		{
?>
			<script type="text/javascript">
			setTimeout("self.location.href=('index.php');",2000)
			</script>
			<p align="center" class="annot_std_it">Ce n'est pas votre compte...</p>
<?PHP
		}
		if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
		{
?>
			<script type="text/javascript">
			setTimeout("self.location.href=('cli_lst.php');",2000)
			</script>
			<p align="center" class="annot_std_it">Merci de choisir un de vos clients...</p>
<?PHP
		}
	}
 }
?>
