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

Version 0.9.9

Copyright (C) 2006-2009  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");

if (!isset($_SESSION["lng"])) $_SESSION["lng"]="fr";
include_once("../lng/".$_SESSION["lng"].".inc.php"); // Paramètres de language
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/fic_age.inc.php");
include_once("../inc/fic_cli.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_rel.inc.php");
include_once("../inc/fic_tec.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é (uniquement sur création)
$crl = strip_tags(trim($_GET['crl'])); // Récupération code Relevé Licence
$cc = strip_tags(trim($_GET['cc'])); // Récupération code Client
$ca = strip_tags(trim($_GET['ca'])); // Récupération code Agence

$pbm_rlic=FALSE;

$msg_err_type="Aucune licence pour cette marque";

if (@$_SESSION["niv_log"] == 1)
	$td = "view";

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

if ($td<>"add")
{
	if ($crl <> "")
	{
		// Récupération des informations dossier relevé
		$row = lit_enr_rlic($crl);
		if (is_array($row))
		{
			extract ($row);
	
			$row = lit_enr_cli($rlic_codecli,TRUE);
			if (is_array($row))
			{
				extract($row);
				$ca=$cli_prop;
				$cc=$cli_code;
			}

			// Vérification des tentatives de hack
			switch (@$_SESSION["niv_log"])
			{
				// Contrôle qu'un client n'essaye pas de "hacker" un relevé
				case 1 :
					$tab_cli=give_tab_rcli($_SESSION["code_log"],TRUE);
					if (in_array($rlic_codecli,$tab_cli)==FALSE)
						$pbm_rlic=TRUE;
					break;
			// Contrôle qu'une agence n'essaye pas de "hacker" un relevé
				case 3 :
				case 4 :
					if (($rlic_codeage <> @$_SESSION["code_age"]) OR ($cli_prop <> @$_SESSION["code_age"]))
						$pbm_rlic = TRUE;
					break;
			}
			
			if ($pbm_rlic==FALSE)
			{
				$exist_in_rpbm = exist_rlic_in_rpbm($crl);
				if ($exist_in_rpbm==TRUE)
					$exist_in_rpbm=1;
				else
					$exist_in_rpbm=0;
	
				$rlic_daterelf = formatedate($rlic_daterel);
				$rlic_datevalf = formatedate($rlic_dateval);
				$rlic_dateoutf = formatedate($rlic_dateout);
				$rlic_mdvalf = formatedate($rlic_mdval);
				$rlic_mdlmajf = formatedate($rlic_mdlmaj);
			}
		}
		else
			$pbm_rlic = TRUE;
	}
	else
		$pbm_rlic = TRUE;
}
else
{
	if ($cc <> "")
	{
		// Contrôle qu'un client n'essaye pas de "hacker" un relevé
		if ((@$_SESSION["niv_log"] == 1) AND ($cc <> @$_SESSION["code_log"]))
			$pbm_rlic = TRUE;

		$row = lit_enr_cli($cc,TRUE);
		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_rlic = TRUE;
					break;
				default :
					break;
			}
			
			$row = lit_enr_rel_cli($cli_code);
			if (is_array($row))
			{
				extract($row);
				if ($cli_ste<>"")
					$rlic_idsite = -2;
				else
					$rlic_idsite = 0;
				$ca=$cli_prop;
			}

			$rlic_daterelf = $datef;
			$rlic_dateoutf = "";
			$rlic_code = crecodesession("RL");
			$rlic_coderel = $rel_code;
			$rlic_codecli = $cc;
			$rlic_codeage = $ca;
			$rlic_maxcli = 1;
	
		}
		else
			$pbm_rlic=TRUE;
	}
}

switch ($td)
{
	case "add":
		$titre = "AJOUT FICHE RELEVE LICENCE";
		break;
	case "edit":
		$titre = "MISE A JOUR FICHE RELEVE LICENCE";
		break;
	case "view":
		$titre = "DETAIL FICHE RELEVE LICENCE";
		break;
	case "del":
		$titre = "SUPPRESSION FICHE RELEVE LICENCE";
		break;
	default :
		$pbm_rlic=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 - <?PHP echo $title_esp_prive; ?> : Fiche Relev&eacute; Licence</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-<?PHP echo $_SESSION["lng"]; ?>.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:daterelf ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date création ; stok:frmok ; stbad:frmbad",
<?PHP
if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
{
?>
	"nom:codeage ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
}
else
{
?>
	"nom:codeage ; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; stok:frmok ; stbad:frmbad",
<?PHP
}
if (($td == "add") or ($td=="edit"))
{ 
?>
	"nom:site ; format:liste ; req:Y ; txt:Lieu d'utilisation ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
}
else
{
?>
	"nom:site ; format:txt ; req:Y ; txt:Lieu d'utilisation ; stok:frmok ; stbad:frmbad",
<?PHP
}
if ($td == "add")
{ 
?>
	"nom:codetec ; format:liste ; req:Y ; txt:Technicien ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
}
else
{
?>
	"nom:codetec ; format:txt ; req:Y ; txt:Technicien ; stok:frmok ; stbad:frmbad",
<?PHP 
}
if (($rlic_dateoutf == "") and ($td <> "view"))
{ 
?>
	"nom:codema ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_edit); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:codetl ; format:liste ; req:Y ; txt:Type de licence ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:codemed ; format:liste ; req:Y ; txt:Type de média ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
}
else
{
?>
	"nom:codema ; format:txt ; req:Y ; txt:Editeur ; stok:frmok ; stbad:frmbad",
	"nom:codetl ; format:txt ; req:Y ; txt:Type de licence ; stok:frmok ; stbad:frmbad",
	"nom:codemed ; format:txt ; req:Y ; txt:Type de média ; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:modele ; format:txt ; req:Y ; txt:Modèle ; lmx:40 ; stok:frmok ; stbad:frmbad",
	"nom:version ; format:txt ; req:Y ; txt:Version ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:maxcli ; format:unsigned ; req:Y ; txt:Nombre maximum de postes ; lmx:4 ; stok:frmok ; stbad:frmbad",
	"nom:numlic ; format:txt ; req:N ; txt:Numéro de licence ; lmx:40 ; stok:frmok ; stbad:frmbad",
	"nom:cleflic ; format:txt ; req:N ; txt:Clef de débridage ; lmx:40 ; stok:frmok ; stbad:frmbad",
	"nom:nota ; format:txt ; req:N ; txt:<?PHP echo html_entity_decode($txt_chp_notes); ?> ; stok:frmok ; stbad:frmbad",
	"nom:signataire ; format:txt ; req:Y ; txt:Validé par ; lmx:50 ; 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>

<!-- Scripts Ajax -->
<script type="text/javascript" src="../ajax/util.js"></script>
<script type="text/javascript" src="../ajax/SelectUpdater.js"></script>

<?PHP if (($pbm_rlic==FALSE) AND (@$_SESSION["niv_log"] <> 1)) { ?>
<script type="text/javascript">
<!--        
function updateTypes() 
{
	typesUpdater = new SelectUpdater("codetl", "<?PHP echo $rep_appli.'/ajax/'; ?>recuptypes.php?mque=", "attn", "msg", "<?PHP echo $msg_err_type; ?>");
	anciencodema = "";
	document.getElementById("codema").onchange = function() {
		var listema = document.getElementById("codema");
		var codema = listema.options[listema.selectedIndex].value;
		if (codema.length > 0)
		{
			if (codema != anciencodema)
			{
				// Faire l'appel Ajax
				typesUpdater.run(codema);
				anciencodema = codema;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			typesUpdater.reset();
			anciencodema = "";
		}
	}
}
//-->
</script>
<?PHP } ?>

</head>

<?PHP if ($td == "del"){ ?>
<body onload="warndel();metReadonly();">
<?PHP } else { ?>
<body onLoad="verif_pw(document.getElementById('tmdp').value,false,'nivpwt');verif_pw(document.getElementById('mmdp').value,false,'nivpm');metFocus();updateTypes();">
<?PHP  }
include_once("../inc/entete.inc.php"); 
if ($pbm_rlic==FALSE)
{
	// Récupération id site
	if (isset($_POST["site"]))
		$idscli = strip_tags(trim($_POST['site']));
	else
		$idscli=-1;
	
	// Récupération filtre problème
	if (isset($_POST["pbms"]))
		$pbm = intval(strip_tags(trim($_POST['pbms']))); 
	else
		$pbm=0;
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<!-- Affiché uniquement s'il y a un code client -->
<?PHP
if ($cc <> "")
{
?>
<table width="100%" border="0">
<tr>
	<td width="33%">
	<?PHP
	if (@$_SESSION["niv_log"] <> 1)
		echo '<a href="rel_maj.php?td=edit&cr='.$rlic_coderel.'">Retour au dossier de relev&eacute;';
	else
		echo '<a href="rel_maj.php">Retour au dossier de relev&eacute;';
	?>
    </td>
	<td width="33%" align="center" class="annot_petit_it">
	(<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> : <?PHP echo $txt_div_saisoblg; ?>)
	</td>
	<td width="33%" align="right">
	<?PHP
	if (($td == "edit") OR ($td == "view"))
	{
	?>
	<select name="etats" size="1" id="etats" onChange="javascript:; lanceimp(this.value); this.value='';" class="annot_petit">
	<option value="" selected>&raquo; Etats &laquo;</option>
	<?PHP
		$urlimp = "rlp_pdf.php?cr=".$crl."&te=l&pbm=0";
		echo "<option value=\"".$urlimp."\" class=\"icone\" style=\"background-image: url(../img/sel_print.gif);\">Relev&eacute;</option>\n";

		$urlimp = "rlp_pdf.php?cr=".$crl."&te=l&pbm=1";
		echo "<option value=\"".$urlimp."\" class=\"icone\" style=\"background-image: url(../img/sel_rel.gif);\">Relev&eacute; et probl&egrave;mes</option>\n";
	?>		
	</select>
	<?PHP 
	} 
	else 
		echo "&nbsp;";
	?>
	</td>
</tr>
</table>

<form name="rlic_maj" method="post" action="rlic_enr.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
<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 $rlic_codecli ?>">
<?PHP if ($td == "add") { ?>
	<input name="code" type="hidden" id="code" value="<?PHP echo $rlic_code ?>">
	<input name="dateoutf" type="hidden" id="dateoutf" value="<?PHP echo $rlic_dateoutf ?>">
<?PHP } else {?>
	<input name="code" type="hidden" id="code" value="<?PHP echo $rlic_code ?>">
	<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $rlic_codeage ?>">
	<input name="codetec" type="hidden" id="codetec" value="<?PHP echo $rlic_codetec ?>">
<?PHP } ?>


<!-- Date de création -->
<!-- Date de sortie de la licence -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_daterelf" align="right">Date Cr&eacute;ation </td>
	<?PHP if ($td <> "add") { ?>
		<td width="240">
	<?PHP } else { ?>
		<td>
	<?PHP }?>
		<input name="daterelf" type="text" id="daterelf" value="<?PHP echo $rlic_daterelf ?>" size="10" maxlength="10" readonly="1">
		<?PHP if ($td == "add") { ?>
		<img src="../img/calendar.png" align="absmiddle" id="f_img_daterelf" title="<?PHP echo $alt_chxdate; ?>">
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<span class="annot_std_it">(
		<a href="javascript:;" onClick="document.rlic_maj.daterelf.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="document.rlic_maj.daterelf.value=''")> Annuler</a> )</span>
		<?PHP } ?>
	</td>
	<?PHP if ($td <> "add") { ?>
	<td width="160" class="rubfrm" id="f_dateoutf" align="right">Sortie du parc le</td>
	<td>
		<input name="dateoutf" type="text" id="dateoutf" value="<?PHP echo $rlic_dateoutf ?>" size="10" maxlength="10" readonly="1">
		<?PHP
			if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
			{
		?>
			<img src="../img/calendar.png" align="absmiddle" id="f_img_dateoutf" title="<?PHP echo $alt_chxdate; ?>">
			<span class="annot_std_it">(
			<a href="javascript:;" onClick="document.rlic_maj.dateoutf.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
			<a href="javascript:;" onclick="document.rlic_maj.dateoutf.value=''")> Annuler</a> )</span>
		<?PHP
			}
		?>
	</td>
	<?PHP } ?>
</tr>
</table>

<!-- Code du dossier de relevé -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_coderel" align="right">Dossier de relev&eacute; </td>
	<td width="240">
		<input name="coderel" type="text" id="coderel" value="<?PHP echo $rlic_coderel ?>" size="20" maxlength="20" readonly="1">
	</td>
	<td>
	<?PHP if (($td <> "add") AND ($td <> "view") AND ($rlic_dateoutf == "")) { ?>
	<span class="annot_petit_it">ATTENTION : d&egrave;s que la licence est sortie du parc, la fiche n'est plus modifiable.</span>
	<?PHP } else {?>
	&nbsp;
	<?PHP } ?>
	</td>
</tr>
</table>

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

<!-- Affichage du client -->
<table width="100%" border="0">
<tr>
	<td class="rubfrm" id="f_codecli" align="center">Client
	<?PHP
	if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
		echo " <img src=\"../img/".$ico_cpta[$cli_cpta]."\" title =\"".$mess_cpta[$cli_cpta]."\" border=\"0\" align=\"absmiddle\">";
	?>
	</td>
</tr>
</table>

<!-- Détails client -->
<table width="100%"  border="0">
<tr>
	<td valign="top" bgcolor="#C5CED7">
	<?PHP
	echo "<span class=\"annot_std_gras\">";
	if ($cli_ste <>"") 
		echo $cli_ste."<br>";
	else
		echo $cli_civilite." ".$cli_prenom." ".$cli_nom."<br>";
	echo "</span>";
	echo $cli_adr1."<br />";
	if ($cli_adr2 <>"") 
		echo $cli_adr2."<br />";
	echo Retournecp_openId($cli_ville,TRUE)." ".Retourneville_openId($cli_ville,TRUE)."<br />";
	$chemin_imagesco = $chemin_images."/telc.png"; 
	echo "<img src=\"".$chemin_imagesco."\" align=\"bottom\">";
	echo " ".$cli_telf."<br>";
	?>
	</td>
	<td width="60" 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/eye.png" 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>

<!-- Site d'usage de la licence -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_site" align="right">Lieu d'utilisation</td>
	<td>
	<?PHP
		if (($rlic_dateoutf == "") and ($cli_ste<>"") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc, professionnel, et si pas en visualisation
		{
	?>
			<select name="site" id="site" onChange="warnmovesclirlp('<?PHP echo $exist_in_rpbm; ?>',<?PHP echo $rlic_idsite; ?>)">
			<option>---Choisissez le lieu d'utilisation--</option>
			<option value="-1" <?PHP if ($rlic_idsite == -1) echo "selected"?>>Tous les sites</option>
			<option value="0" <?PHP if ($rlic_idsite == 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`='".$cc."' ORDER BY scli_ste";
				$rs = mysql_query($rech) or die(mysql_error());
			
				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 ($rlic_idsite == $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>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP
			}
			else
			{
			?>
				<input name="site" type="hidden" id="site" value="<?PHP echo $rlic_idsite; ?>">
			<?PHP
				switch ($rlic_idsite)
				{
				case -1 :
				?>
						<input name="nsite" type="text" id="nsite" value="Tous les sites" readonly="1">
				<?PHP
					break;
				case 0 :
				?>
						<input name="nsite" type="text" id="nsite" value="Site principal" readonly="1">
				<?PHP
					break;
				default :
						$nom_site="";
						$row=lit_enr_scli_id($rlic_idsite,TRUE);
						if (is_array($row))
						{
							extract($row);
							if ($scli_adr2<>"")
								$nom_site = $scli_ste." (".$scli_adr1.", ".$scli_adr2.", ".Retournecp_openId($scli_ville,TRUE)." ".Retourneville_openId($scli_ville,TRUE).")";
							else
								$nom_site = $scli_ste." (".$scli_adr1.", ".Retournecp_openId($scli_ville,TRUE)." ".Retourneville_openId($scli_ville,TRUE).")";
						}
				?>
						<input name="nsite" type="text" id="nsite" value="<?PHP echo htmlspecialchars($nom_site); ?>" size="100" readonly="1">
				<?PHP
					break;
				}
			}
		?>
	</td>
</tr>
</table>

<table width="100%"  border="0">
<tr>
	<td class="rubfrm" colspan="2"  id="f_codecli" align="center">
		Relev&eacute; effectu&eacute; par
	</td>
	</tr>
</table>

<!-- Code de l'agence (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_codeage" align="right">Agence</td>
	<td>
		<?PHP
			$row = lit_enr_age($ca,TRUE);
			if (is_array($row))
				extract($row);
			$nom_code = $age_nom." (".$age_code.")";
		?>
		<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $ca; ?>">
		<input name="nagence" type="text" id="nagence" value="<?PHP echo htmlspecialchars($nom_code); ?>" size="50" readonly="1">
	</td>
</tr>
</table>

<!-- Code du technicien (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_codetec" align="right">Technicien</td>
	<td>
		<?PHP
		if ($td =="add")  // Ajout = zone modifiable (on peut choisir un technicien)
		{ 
			// Création de la liste des techniciens actifs
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBTEC." WHERE `tec_dateout`='0000-00-00' AND `tec_codeage` = '".$ca."' ORDER BY tec_nom ";
			$rs = mysql_query($rech) or die(mysql_error());

			if (mysql_num_rows($rs) <> 0)
			{
			?>
			
			<select name="codetec" id="codetec">

			<?PHP
				echo "<option value=\"\">".$sel_lst_tec."</option>";
	
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
	
					$nom_prenom = $tec_nom." ".$tec_prenom;
					if ($rlic_codetec == $tec_code)
						echo '<option value="'.$tec_code.'" selected>'.$nom_prenom.'</option>';
					else
						echo '<option value="'.$tec_code.'">'.$nom_prenom.'</option>';
				}
			?>
			</select>
			<?PHP
			}
			else
			{
			?>
				<select name="codetec" id="codetec">
				<option>-- Pas de technicien actif --</option>
				</select>
			<?PHP
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP 
		} 
		else  // Edition ou suppression = zone non modifiable (affichage seul)
		{
			$row = lit_enr_tec($rlic_codetec,TRUE);
			if (is_array($row))
				extract($row);
		?>
		<input name="nomtec" type="text" id="nomtec" value="<?PHP echo htmlspecialchars($tec_nom." ".$tec_prenom); ?>" size="50" readonly="1">
		<?PHP 
		} 
		?>
	</td>
</tr>
</table>


<!-- Délai du relevé -->
<table width="100%"  border="0">
<tr>
	<td class="rubfrm" colspan="2" align="center">
		D&eacute;tail du relev&eacute;
	</td>
	</tr>
</table>

<!-- Marque/Nom de l'éditeur -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_codema" align="right"><?PHP echo $txt_chp_edit; ?></td>
	<td>
		<?PHP
		// Création de la liste des marques
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
			$rech = "SELECT * FROM ".TBMQUE." WHERE `mque_code`<>'*' AND (`mque_type`=0 OR `mque_type`=2) ORDER BY mque_ste";
			$rs = mysql_query($rech) or die(mysql_error());
		?>
			<select name="codema" id="codema">
	
			<?PHP
				echo "<option value=\"\">-- Choisissez une marque --</option>";
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
	
					if ($rlic_codema == $mque_code)
						echo '<option value="'.$mque_code.'" selected>'.$mque_ste.'</option>';
					else
						echo '<option value="'.$mque_code.'">'.$mque_ste.'</option>';
				}
			?>
			</select>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP
		}
		else
		{
			$rech = "SELECT * FROM ".TBMQUE." WHERE `mque_code` = '".$rlic_codema."'";
			$rs = mysql_query($rech) or die(mysql_error());
			if ($row = mysql_fetch_array($rs))
			{
				extract ($row);
			}
		?>
			<input name="codema" type="hidden" id="codema" value="<?PHP echo $rlic_codema; ?>">
			<input name="nomma" type="text" id="nomma" value="<?PHP echo htmlspecialchars($mque_ste); ?>" size="40" readonly="1">
		<?PHP
		}
		// mysql_free_result($rs);
		mysql_close($conn);
		?>
	</td>
</tr>
</table>

<!-- Type de la licence -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_codetl" align="right">Type</td>
	<td>
		<?PHP
		
		// Création de la liste des types
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);		
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
			$rech = "SELECT * FROM ".TBRLTL." WHERE rltl_codema='".$rlic_codema."' OR rltl_codema='*'  ORDER BY rltl_desc";
			$rs = mysql_query($rech) or die(mysql_error());

		?>
		
			<select name="codetl" id="codetl">
	
			<?PHP
				echo "<option value=\"\">-- Choisissez un type --</option>";
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
	
					if ($rlic_codetl == $rltl_code)
					{
						echo '<option value="'.$rltl_code.'" selected>'.$rltl_desc.'</option>';
					}
					else
					{
						echo '<option value="'.$rltl_code.'">'.$rltl_desc.'</option>';
					}
				}
			?>
			</select>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<span id="attn"></span><span id="msg" style="background-color:#FF0000; color:#FFFF00; font-weight:bold"><?PHP if ((mysql_num_rows($rs)==0) AND ($td=="edit")) echo htmlspecialchars($msg_err_type)?></span>
		<?PHP
		}
		else
		{
			$rech = "SELECT * FROM ".TBRLTL." WHERE `rltl_code` = '".$rlic_codetl."'";
			$rs = mysql_query($rech) or die(mysql_error());
			if ($row = mysql_fetch_array($rs))
			{
				extract ($row);
			}
		?>
			<input name="codetl" type="hidden" id="codetl" value="<?PHP echo $rlic_codetl; ?>">
			<input name="nomtl" type="text" id="nomtl" value="<?PHP echo htmlspecialchars($rltl_desc); ?>" size="40" readonly="1">
		<?PHP
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
	</td>
</tr>
</table>

<!-- Modèle de la licence -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_modele" align="right">
		Mod&egrave;le
	</td>
    <td>
	<?PHP
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
	?>
		<input name="modele" type="text" id="modele" value="<?PHP echo htmlspecialchars($rlic_modele); ?>" size="40"> <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP
		}
		else
		{
	?>
		<input name="modele" type="text" id="modele" value="<?PHP echo htmlspecialchars($rlic_modele); ?>" size="40" readonly="1">
	<?PHP
		}
	?>
	</td>
</tr>
</table>

<!-- Version de la licence -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_version" align="right">
		Version
	</td>
    <td>
	<?PHP if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
	?>
		<input name="version" type="text" id="version" value="<?PHP echo htmlspecialchars($rlic_version); ?>" size="10"> <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP
		}
		else
		{
	?>
		<input name="version" type="text" id="version" value="<?PHP echo htmlspecialchars($rlic_version); ?>" size="10" readonly="1">
	<?PHP
		}
	?>
	</td>
</tr>
</table>

<!-- Nb Maximum de clients -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_maxcli" align="right">
		Maximum de postes
	</td>
    <td>
		<?PHP 
		if ($td <> "add")
			$nb_rlic_utilisees = nb_rlic($rlic_codecli,$rlic_code);
		
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
		?>
			<input name="maxcli" type="text" id="maxcli" value="<?PHP echo $rlic_maxcli ?>" size="4" maxlength="4" align="right" <?PHP if ($td <> "add") { ?>onChange="verif_max('<?PHP echo $nb_rlic_utilisees; ?>','wmax',this.value)"<?PHP } ?>> 
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP 
		}
		else
		{
		?>
			<input name="maxcli" type="text" id="maxcli" value="<?PHP echo $rlic_maxcli ?>" size="4" maxlength="4" align="right" readonly="1"> 
		<?PHP
		}

		if ($td <> "add")
		{
		?>
			<span class="annot_petit_it">(Utilis&eacute; : <?PHP echo $nb_rlic_utilisees; ?> )</span>
			<span id="wmax">
		<?PHP 
			if ($nb_rlic_utilisees > $rlic_maxcli)
			{
				echo "<span class=\"alerte1\">";
				echo "Maximum d&eacute;pass&eacute;";
				echo "</span>";
			}
	
			if ($nb_rlic_utilisees == $rlic_maxcli)
			{
				echo "<span class=\"alerte1\">";
				echo "Maximum atteint";
				echo "</span>";
			}
		?>
			</span>
		<?PHP
		}
		?>
	</td>
</tr>
</table>

<!-- Type de média -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_codemed" align="right">Type M&eacute;dia</td>
	<td>
		<?PHP
		
		// Création de la liste des types
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);		
		
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
			$rech = "SELECT * FROM ".TBRLMED." ORDER BY rlmed_desc";
			$rs = mysql_query($rech) or die(mysql_error());
	
		?>
			
			<select name="codemed" id="codemed">
	
			<?PHP
				if ($rlic_codemed <> "")
					echo "<option value=\"\">-- Choisissez un média --</option>";
				else
					echo "<option value=\"\" selected>-- Choisissez un média --</option>";
	
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
	
					if ($rlic_codemed == $rlmed_code)
					{
						echo '<option value="'.$rlmed_code.'" selected>'.$rlmed_desc.'</option>';
					}
					else
					{
						echo '<option value="'.$rlmed_code.'">'.$rlmed_desc.'</option>';
					}
				}
			?>
			</select>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP
		}
		else
		{
			$rech = "SELECT * FROM ".TBRLMED." WHERE `rlmed_code` = '".$rlic_codemed."'";
			$rs = mysql_query($rech) or die(mysql_error());
			if ($row = mysql_fetch_array($rs))
			{
				extract ($row);
			}
		?>
			<input name="codemed" type="hidden" id="codemed" value="<?PHP echo $rlic_codemed; ?>">
			<input name="nommed" type="text" id="nommed" value="<?PHP echo htmlspecialchars($rlmed_desc); ?>" size="40" readonly="1">
		<?PHP
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
	</td>
</tr>
</table>

<!-- Numéro de la licence -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_numlic" align="right">
		Num&eacute;ro
	</td>
    <td>
		<?PHP		
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
		?>
			<input name="numlic" type="text" id="numlic" value="<?PHP echo htmlspecialchars($rlic_numlic); ?>" size="40">
		<?PHP
		}
		else
		{
		?>
			<input name="numlic" type="text" id="numlic" value="<?PHP echo htmlspecialchars($rlic_numlic); ?>" size="40" readonly="1">
		<?PHP
		}
		?>
	</td>
</tr>
</table>


<!-- Clef de la licence -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_cleflic" align="right">
		Clef Activation
	</td>
    <td>
		<?PHP		
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
		?>
			<input name="cleflic" type="text" id="cleflic" value="<?PHP echo htmlspecialchars($rlic_cleflic); ?>" size="40">
		<?PHP
		}
		else
		{
		?>
			<input name="cleflic" type="text" id="cleflic" value="<?PHP echo htmlspecialchars($rlic_cleflic); ?>" size="40" readonly="1">
		<?PHP
		}
		?>
	</td>
</tr>
</table>

<!-- Licence à jour ? -->
<!-- Licence Légale ? -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_ajour" align="right">
		A Jour ?
	</td>
    <td width="100">
	<?PHP 
	if (($td == "add") OR ($td=="edit"))
	{ 
		echo "<select name=\"ajour\" size=\"1\" id=\"ajour\">";
		foreach ($non_oui as $key=>$value)
		{
			echo "<option value=\"".$value."\"";
			if ($key==$rlic_ajour)
				echo " selected=\"selected\"";
			echo ">".$value."</option>";
		}
		echo "</select>";
	}
	else
	{ 
	?>
	<input name="ajour" type="text" id="ajour" value="<?PHP echo $non_oui[$rlic_ajour]; ?>" size="3" readonly="1">
	<?PHP
	}
	?>		
	</td>
	<td width="160" class="rubfrm" id="f_legale" align="right">
		L&eacute;gale ?
	</td>
    <td>
	<?PHP 
	if (($td == "add") OR ($td=="edit"))
	{ 
		echo "<select name=\"legale\" size=\"1\" id=\"legale\">";
		foreach ($non_oui as $key=>$value)
		{
			echo "<option value=\"".$value."\"";
			if ($key==$rlic_legal)
				echo " selected=\"selected\"";
			echo ">".$value."</option>";
		}
		echo "</select>";
	}
	else
	{ 
	?>
	<input name="legale" type="text" id="legale" value="<?PHP echo $non_oui[$rlic_legal]; ?>" size="3" readonly="1">
	<?PHP
	}
	?>		
	<span class="annot_petit_it">
	(Non : pas l&eacute;gale ou pas pu avoir de confirmation)
	</span>
	</td>
</tr>
</table>

<!-- Date de validité -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_datevalf" align="right">Date Validit&eacute; </td>
	<td>
		<input name="datevalf" type="text" id="datevalf" value="<?PHP echo $rlic_datevalf ?>" size="10" maxlength="10" readonly="1" onChange="verif_dout(this.value,'wvalfout','0');">
		<?PHP		
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
		?>
			<img src="../img/calendar.png" align="absmiddle" id="f_img_datevalf" title="<?PHP echo $alt_chxdate; ?>">
			<span class="annot_std_it">(
			<a href="javascript:;" onClick="document.rlic_maj.datevalf.value='';verif_dout(document.rlic_maj.datevalf.value,'wvalfout','0');"><img src="../img/raz.png" border="0" align="absmiddle"></a>
			<a href="javascript:;" onclick="document.rlic_maj.datevalf.value='';verif_dout(document.rlic_maj.datevalf.value,'wvalfout','0');")> Annuler</a> )</span>
			<span id="wvalfout">
			<?PHP
			if ($rlic_datevalf <>"")
			{
				if (echeance_depassee_date($datea,$rlic_dateval))
				{
					echo "<span class=\"alerte1\">";
					echo "Ech&eacute;ance d&eacute;pass&eacute;e";
					echo "</span>";
				}
			}
			?>
			</span>
		<?PHP
		}
		?>
	</td>
</tr>
</table>

<!-- Signé par -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_signataire" align="right">
		Valid&eacute; par
	</td>
    <td>
		<?PHP		
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
		?>
			<input name="signataire" type="text" id="signataire" value="<?PHP echo htmlspecialchars($rlic_signataire); ?>" size="50">
		  <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		 <?PHP
		 }
		 else
		 {
		 ?>
			<input name="signataire" type="text" id="signataire" value="<?PHP echo htmlspecialchars($rlic_signataire); ?>" size="50" readonly="1">
		 <?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" class="bton_std" id="RAZ" value="Tout r&eacute;initialiser">
	<input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_enr; ?>">
<?PHP 
}
if ($td == "del") // Bouton si en mode suppression
{ 
?>
	<input name="del" type="submit" class="bton_std" id="del" value="<?PHP echo $but_del; ?>">
<?PHP 
} 
?>
</p>

<input name="maxmnu" type="hidden" id="maxmnu" value="6">

<!-- Compléments -->
<table width="100%"  border="0" cellspacing="0">
<tr>
	<td height="25" class="rubfrm" align="center">
		Informations compl&eacute;mentaires
	</td>
	<td height="25" width="25" class="rubfrm" >
		<div align="center">
		 <span id="close_menu" style="display:none"><img src="../img/top.png" border="0" title="Fermer menu" alt="Fermer menu" align="absmiddle" onClick="javascript:;close_mnu_rel();"></span>
		</div>
	</td>
</tr>
</table>

<div id="menu_rel" class="menu_ongletfull">
<a class="ongleti" id="m1" href="javascript:;" onclick="set_mnu_rel(this.id);" onFocus="this.blur();"><?PHP echo $txt_chp_notes; ?></a>
<a class="ongleti" id="m2" href="javascript:;" onclick="set_mnu_rel(this.id);" onFocus="this.blur();">Mat&eacute;riels</a>
<a class="ongleti" id="m3" href="javascript:;" onclick="set_mnu_rel(this.id);" onFocus="this.blur();">T&eacute;l&eacute;maintenance</a>
<a class="ongleti" id="m4" href="javascript:;" onclick="set_mnu_rel(this.id);" onFocus="this.blur();">Mises &agrave; jour</a>
<a class="ongleti" id="m5" href="javascript:;" onclick="set_mnu_rel(this.id);" onFocus="this.blur();">Contrats</a>
<a class="ongleti" id="m6" href="javascript:;" onclick="set_mnu_rel(this.id);" onFocus="this.blur();">Probl&egrave;mes</a>
</div>
<br>


<div id="detailm1" style="display:none">
<!-- Notes -->
<table width="100%"  border="0">
  <tr>
    <td>
		<?PHP		
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
		?>
			<textarea name="nota" rows="5" id="nota"><?PHP echo htmlspecialchars($rlic_nota) ?></textarea>
		<?PHP
		}
		else
		{
		?>
			<textarea name="nota" rows="5" id="nota" readonly><?PHP echo htmlspecialchars($rlic_nota) ?></textarea>
		<?PHP
		}
		?>
	</td>
  </tr>
</table>
</div>

<div id="detailm2" style="display:none">
<?PHP
// Création de la liste des relevés produits utilisant ce relevé licences
$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);
$rech = "SELECT * FROM ".TBRPDT." WHERE rpdt_dateout = '0000-00-00' AND rpdt_codecli = '".$rlic_codecli."'";
$rech.= " AND rpdt_coderlic LIKE '%".$rlic_code."%'";
$rech.= " ORDER BY rpdt_code";
$rs = mysql_query($rech) or die(mysql_error());

if (mysql_num_rows($rs) <> 0)
{
	echo "<table class=\"MtableD\" border=\"0\" width=\"100%\" 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 "Cat&eacute;gorie";
	echo "</th>\n";
	echo "<th>";
	echo "Marque / Mod&egrave;le / NS / Emplacement ";
	echo "</th>\n";
	echo "<th>";
	echo "Fin Gar.";
	echo "</th>\n";
	echo "<th>";
	echo "Editer";
	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"]." ";
		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 htmlspecialchars($row2["rpcat_desc"]);
			else
				echo "-";
		}
		else
			echo "-";
		mysql_free_result($rs2);
		echo "</td>\n";

		echo "<td>\n";
		$rech2 = "SELECT * FROM ".TBMQUE." WHERE `mque_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 htmlspecialchars($row2["mque_ste"]);
			else
				echo "-";
		}
		else
			echo "-";
		mysql_free_result($rs2);

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

		echo "<td align=\"center\">\n";
		echo formatedate($row["rpdt_fingar"]);
		if  (formatedate($row["rpdt_fingar"]) <> "")
		{
			if ((echeance_depassee_date($datea,$row["rpdt_fingar"]) == TRUE)  AND (formatedate($row["rpdt_dateout"]) == ""))
				echo " <img src=\"../img/dateout.png\" title =\"Hors garantie\" border=\"0\" align=\"absmiddle\">";
		}
		echo "</td>\n";

		echo "<td align=\"center\">\n";
		if (($td <> "view") AND ($td <> "del"))
		{
			$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\" title=\"Voir ou Modifier\" 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/eye.png\" title=\"".$alt_voir."\" border=\"0\" align=\"absmiddle\"></a>";
		}
		if (($rlic_dateoutf == "") AND ($td <> "del"))
		{
			$lst_pbmrel = TRUE;
			echo " ";
			echo "<a href=\"rpbm_maj.php?td=add&tr=2&cr=".$row["rpdt_code"]."&cap=1\"><img src=\"../img/addpbm.png\" title=\"D&eacute;clarer un probl&egrave;me\" border=\"0\" align=\"absmiddle\"></a>";
		}
		else
			echo "&nbsp;";
		echo "</td>\n";
		echo "</tr>\n";
	
		$j++;
	}

	echo "</table>\n";
	// Fin affichage table détails licences

	$taille_piedla ="small";
	include_once("piedla.inc.php");
	?>
<?PHP
}
else
{
	echo "Pas de mat&eacute;riel utilisant cette licence";
}
mysql_free_result($rs);
mysql_close($conn);
?>
</div>

<div id="detailm3"  style="display:none">
<!-- Détail télémaintenance -->

<!-- Type d'accès -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_ta" align="right">
		Type d'acc&egrave;s
	</td>
	<td>
	<?PHP
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
	{ 
		// Création de la liste des types d'accès
		
		$rech = "SELECT * FROM ".TBRLPTMTA." ORDER BY rlptmta_desc";
		$rs = mysql_query($rech) or die(mysql_error());

		?>
		
		<select name="codeta" id="codeta">

		<?PHP
			if ($rlic_codeta <> "")
				echo "<option value=\"\">-- Choisissez un type d'accès --</option>";
			else
				echo "<option value=\"\" selected>-- Choisissez un type d'accès --</option>";

			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);

				if ($rlic_codeta == $rlptmta_code)
				{
					echo '<option value="'.$rlptmta_code.'" selected>'.$rlptmta_desc.'</option>';
				}
				else
				{
					echo '<option value="'.$rlptmta_code.'">'.$rlptmta_desc.'</option>';
				}
			}
		?>
		</select>
	<?PHP
	}
	else
	{
		$rech = "SELECT * FROM ".TBRLPTMTA." WHERE `rlptmta_code` = '".$rlic_codeta."'";
		$rs = mysql_query($rech) or die(mysql_error());
		if ($row = mysql_fetch_array($rs))
		{
			extract ($row);
		}
	?>
		<input name="codeta" type="hidden" id="codeta" value="<?PHP echo $rlic_codeta; ?>">
		<input name="nomta" type="text" id="nomta" value="<?PHP echo htmlspecialchars($rlptmta_desc); ?>" size="40" readonly="1">
	<?PHP
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	</td>
</tr>
</table>

<!-- Mode d'accès -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_tma" align="right">
		Mode d'acc&egrave;s
	</td>
    <td>
	<?PHP 
	if (($td == "add") OR ($td == "edit"))
	{ 
		echo "<select id=\"tma\" name=\"tma\">";
		foreach ($maj_typesma as $key=>$value)
		{
			echo "<option value=\"".$key."\"";
			if ($key==$rlic_tma)
				echo" selected=\"selected\"";
			echo ">".$value."</option>";
		}
		echo "</select>";
		echo "<span class=\"annot_petit_it\">(Depuis o&ugrave; peut-on effectuer une t&eacute;l&eacute;maintenance sur cette licence)</span>";
	}
	else
	{
	?>
		<input name="tta" type="text" id="tta" value="<?PHP echo $maj_typesma[$rlic_tma]; ?>" size="20" readonly="1">
	<?PHP
	}
	?>		
	</td>
</tr>
</table>

<!-- Logiciel de télémaintenance -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_tl" align="right">
		Logiciel t&eacute;l&eacute;m.
	</td>
	<td>
	<?PHP
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
	{ 
		// Création de la liste des logiciels télémaintenance
		$rech = "SELECT * FROM ".TBRLPTML." ORDER BY rlptml_desc";
		$rs = mysql_query($rech) or die(mysql_error());

		?>
		
		<select name="codel" id="codel">

		<?PHP
			if ($rlic_codel <> "")
				echo "<option value=\"\">-- Choisissez un logiciel de télémaintenance --</option>";
			else
				echo "<option value=\"\" selected>-- Choisissez un logiciel de télémaintenance --</option>";

			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);

				if ($rlic_codel == $rlptml_code)
				{
					echo '<option value="'.$rlptml_code.'" selected>'.$rlptml_desc.'</option>';
				}
				else
				{
					echo '<option value="'.$rlptml_code.'">'.$rlptml_desc.'</option>';
				}
			}
		?>
		</select>
	<?PHP
	}
	else
	{
		$rech = "SELECT * FROM ".TBRLPTML." WHERE `rlptml_code` = '".$rlic_codel."'";
		$rs = mysql_query($rech) or die(mysql_error());
		if ($row = mysql_fetch_array($rs))
		{
			extract ($row);
		}
	?>
		<input name="codel" type="hidden" id="codel" value="<?PHP echo $rlic_codel; ?>">
		<input name="noml" type="text" id="noml" value="<?PHP echo htmlspecialchars($rlptml_desc); ?>" size="40" readonly="1">
	<?PHP
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	</td>
</tr>
</table>

<!-- Mode service ? -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_tser" align="right">
		Mode service ?
	</td>
    <td>
	<?PHP 
	if (($td == "add") OR ($td=="edit"))
	{ 
		echo "<select name=\"tser\" size=\"1\" id=\"tser\">";
		foreach ($non_oui as $key=>$value)
		{
			echo "<option value=\"".$value."\"";
			if ($key==$rlic_tser)
				echo " selected=\"selected\"";
			echo ">".$value."</option>";
		}
		echo "</select>";
		echo "<span class=\"annot_petit_it\">(Le logiciel se charge-t'il en mode normal ou en mode service ?)</span>";
	}
	else
	{ 
	?>
	<input name="tser" type="text" id="tser" value="<?PHP echo $non_oui[$rlic_tser]; ?>" size="3" readonly="1">
	<?PHP
	}
	?>		
	</td>
</tr>
</table>

<!-- Lien accès -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_tlien" align="right">
		Lien d'acc&egrave;s
	</td>
	<td>
		<?PHP
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
		?>
			<input name="tlien" type="text" id="tlien" value="<?PHP echo htmlspecialchars($rlic_tlien); ?>" size="40" >
		<?PHP
		}
		else
		{
		?>
			<input name="tlien" type="text" id="tlien" value="<?PHP echo htmlspecialchars($rlic_tlien); ?>" size="40" readonly="1">
		<?PHP
		}
		?>
	</td>
</tr>
</table>

<!-- Login / MDP -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_tlogin" align="right">
		Login / MDP
	</td>
	<td>
		<?PHP
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
		?>
			<input name="tlogin" type="text" id="tlogin" value="<?PHP echo htmlspecialchars($rlic_tlogin); ?>" size="40" > /
			<input name="tmdp" type="text" id="tmdp" value="<?PHP echo htmlspecialchars($rlic_tmdp); ?>" size="40" onChange="verif_pw(this.value,true,'nivpwt');">
		<?PHP
		}
		else
		{
		?>
			<input name="tlogin" type="text" id="tlogin" value="<?PHP echo htmlspecialchars($rlic_tlogin); ?>" size="40" readonly="1"> /
			<input name="tmdp" type="text" id="tmdp" value="<?PHP echo htmlspecialchars($rlic_tmdp); ?>" size="40" readonly="1">
		<?PHP
		}
		?>
		<span id="nivpwt"></span>
	</td>
</tr>
</table>

<!-- Arrêt d'exploitation ? -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_tae" align="right">
		Arr&ecirc;t exploitation ?
	</td>
    <td>
	<?PHP 
	if (($td == "add") OR ($td=="edit"))
	{ 
		echo "<select name=\"tae\" size=\"1\" id=\"tae\">";
		foreach ($non_oui as $key=>$value)
		{
			echo "<option value=\"".$value."\"";
			if ($key==$rlic_tae)
				echo " selected=\"selected\"";
			echo ">".$value."</option>";
		}
		echo "</select>";
		echo "<span class=\"annot_petit_it\">(Doit-on arr&ecirc;ter l'exploitation de cette licence  en cas de t&eacute;l&eacute;maintenance ?)</span>";
	}
	else
	{ 
	?>
	<input name="tae" type="text" id="tae" value="<?PHP echo $non_oui[$rlic_tae]; ?>" size="3" readonly="1">
	<?PHP
	}
	?>		
	</td>
</tr>
</table>

<!-- Redémarrage ? -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_tred" align="right">
		Red&eacute;marrage ?
	</td>
    <td>
	<?PHP 
	if (($td == "add") OR ($td=="edit"))
	{ 
		echo "<select name=\"tred\" size=\"1\" id=\"tred\">";
		foreach ($non_oui as $key=>$value)
		{
			echo "<option value=\"".$value."\"";
			if ($key==$rlic_tred)
				echo " selected=\"selected\"";
			echo ">".$value."</option>";
		}
		echo "</select>";
		echo "<span class=\"annot_petit_it\">(Doit-on red&eacute;marrer le mat&eacute;riel utilisant cette licence en cas de t&eacute;l&eacute;maintenance ?)</span>";
	}
	else
	{ 
	?>
	<input name="tred" type="text" id="tred" value="<?PHP echo $non_oui[$rlic_tred]; ?>" size="3" readonly="1">
	<?PHP
	}
	?>		
	</td>
</tr>
</table>
</div>

<div id="detailm4"  style="display:none">
<!-- Détail Mises à jour -->

<!-- Mode  -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_mode" align="right">
		Mode
	</td>
	<td>
	<?PHP
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
	{ 
		// Création de la liste des modes de mises à jour
		
		$rech = "SELECT * FROM ".TBRLPMM." ORDER BY rlpmm_desc";
		$rs = mysql_query($rech) or die(mysql_error());

		?>
		
		<select name="codem" id="codem">

		<?PHP
			if ($rlic_codem <> "")
				echo "<option value=\"\">-- Choisissez un mode de mise à jour --</option>";
			else
				echo "<option value=\"\" selected>-- Choisissez un mode de mise à jour --</option>";

			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);

				if ($rlic_codem == $rlpmm_code)
				{
					echo '<option value="'.$rlpmm_code.'" selected>'.$rlpmm_desc.'</option>';
				}
				else
				{
					echo '<option value="'.$rlpmm_code.'">'.$rlpmm_desc.'</option>';
				}
			}
		?>
		</select>
	<?PHP
	}
	else
	{
		$rech = "SELECT * FROM ".TBRLPMM." WHERE `rlpmm_code` = '".$rlic_codem."'";
		$rs = mysql_query($rech) or die(mysql_error());
		if ($row = mysql_fetch_array($rs))
		{
			extract ($row);
		}
	?>
		<input name="codem" type="hidden" id="codem" value="<?PHP echo $rlic_codem; ?>">
		<input name="nommm" type="text" id="nommm" value="<?PHP echo htmlspecialchars($rlpmm_desc); ?>" size="40" readonly="1">
	<?PHP
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	</td>
</tr>
</table>

<!-- Fréquence et type  -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_per" align="right">
		Fr&eacute;quence / Type
	</td>
	<td>
	<?PHP
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
	{ 
		// Création de la liste des fréquence
		$rech = "SELECT * FROM ".TBPER." ORDER BY per_nbj";
		$rs = mysql_query($rech) or die(mysql_error());

		if (mysql_num_rows($rs) <> 0)
		{
	?>
		<select name="mper" id="mper">
	<?PHP
			if ($rlic_mper <> "")
				echo "<option value=\"\">-- Choisissez une fréquence de mise à jour--</option>";
			else
				echo "<option value=\"\" selected>-- Choisissez une fréquence de mise à jour--</option>";

			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);

				if ($per_nbj <> 0)
					$txt_nbj = " (tous les ".$per_nbj." jours)";
				else
					$txt_nbj = " (à la demande)";

				if ($rlic_mper == $per_code)
					echo '<option value="'.$per_code.'" selected>'.$per_desc.$txt_nbj.'</option>';
				else
					echo '<option value="'.$per_code.'">'.$per_desc.$txt_nbj.'</option>';
			}
		?>
		</select>
	<?PHP
		}
		else
		{
	?>
			<select name="mper" id="mper">
			<option>-- Pas de fr&eacute;quence à choisir --</option>
			</select>
	<?PHP
		}
	}
	else
	{
		$rech = "SELECT * FROM ".TBPER." WHERE `per_code` = '".$rlic_mper."'";
		$rs = mysql_query($rech) or die(mysql_error());
		if ($row = mysql_fetch_array($rs))
		{
			extract ($row);
		}
	?>
		<input name="mper" type="hidden" id="mper" value="<?PHP echo $rlic_mper ?>">
		<input name="tper" type="text" id="tper" value="<?PHP echo htmlspecialchars($per_desc); ?>" size="20" maxlength="20" readonly="1">
	<?PHP
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	 / 
	<select id="mtype" name="mtype">
	<?PHP
	foreach ($maj_types as $key=>$value)
	{
		echo "<option value=\"".$key."\"";
		if ($key==$rlic_mmode)
			echo" selected=\"selected\"";
		echo ">".$value."</option>";
	}
	?>
	</select>
	</td>
</tr>
</table>

<!-- Login / MDP -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_mlogin" align="right">
		Login / MDP
	</td>
	<td>
		<?PHP
		if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
		{ 
		?>
			<input name="mlogin" type="text" id="mlogin" value="<?PHP echo htmlspecialchars($rlic_mlogin); ?>" size="40" > /
			<input name="mmdp" type="text" id="mmdp" value="<?PHP echo htmlspecialchars($rlic_mmdp); ?>" size="40" onChange="verif_pw(this.value,true,'nivpwm');">
		<?PHP
		}
		else
		{
		?>
			<input name="mlogin" type="text" id="mlogin" value="<?PHP echo htmlspecialchars($rlic_mlogin); ?>" size="40" readonly="1"> /
			<input name="mmdp" type="text" id="mmdp" value="<?PHP echo htmlspecialchars($rlic_mmdp); ?>" size="40" readonly="1">
		<?PHP
		}
		?>
		<span id="nivpwm"></span>
	</td>
</tr>
</table>

<!-- Date validité -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_mdval" align="right">
		Date d'&eacute;ch&eacute;ance
	</td>
	<td>
	<input name="mdvalf" type="text" id="mdvalf" value="<?PHP echo $rlic_mdvalf ?>" size="10" maxlength="10" readonly="1" onChange="verif_dout(this.value,'wmdvalfout','0');">
	<?PHP
	if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
	{ 
	?>
		<img src="../img/calendar.png" align="absmiddle" id="f_img_mdvalf" title="<?PHP echo $alt_chxdate; ?>">
		<span class="annot_std_it">(
		<a href="javascript:;" onClick="document.rpdt_maj.mdvalf.value='';verif_dout(document.rpdt_maj.mdvalf.value,'wmdvalfout','0');"><img src="../img/raz.png" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="document.rpdt_maj.mdvalf.value='';verif_dout(document.rpdt_maj.mdvalf.value,'wmdvalfout','0');")> Annuler</a> )</span>
		<span class="annot_petit_it">(Ne rien mettre si illimit&eacute;)</span>
	<?PHP
	}
	?>
	<span id="wmdvalfout">
	<?PHP
	if ($rlic_mdvalf <> "")
	{
		if (echeance_depassee_date($datea,$rlic_mdval) == TRUE)
		{
			echo "<span class=\"alerte1\">";
			echo "Ech&eacute;ance d&eacute;pass&eacute;e";
			echo "</span>";
		}
	}
	?>
	</span>
	</td>
</tr>
</table>

<!-- Date dernière mise à jour -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_mlmaj" align="right">
		Derni&egrave;re mise &agrave; jour
	</td>
	<td>
	<input name="mdlmajf" type="text" id="mdlmajf" value="<?PHP echo $rlic_mdlmajf ?>" size="10" maxlength="10" readonly="1">
	<?PHP
	if (($rlic_dateoutf == "") and ($td <> "view") and ($td<>"del"))  // zone modifiable si pas sorti du parc et si pas en visualisation
	{ 
	?>
		<img src="../img/calendar.png" align="absmiddle" id="f_img_mdlmajf" title="<?PHP echo $alt_chxdate; ?>">
		<span class="annot_std_it">(
		<a href="javascript:;" onClick="document.rpdt_maj.mdlmajf.value='';verif_dout(document.rpdt_maj.mdlmajf.value,'wmdvalfout','1');"><img src="../img/raz.png" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="document.rpdt_maj.mdlmajf.value=''verif_dout(document.rpdt_maj.mdlmajf.value,'wmdvalfout','1');")> Annuler</a> )</span>
	<?PHP
	}
	?>
	</td>
</tr>
</table>

<!-- Arrêt d'exploitation ? -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_mae" align="right">
		Arr&ecirc;t exploitation ?
	</td>
    <td>
	<?PHP 
	if (($td == "add") OR ($td=="edit"))
	{ 
		echo "<select name=\"mae\" size=\"1\" id=\"mae\">";
		foreach ($non_oui as $key=>$value)
		{
			echo "<option value=\"".$value."\"";
			if ($key==$rlic_mae)
				echo " selected=\"selected\"";
			echo ">".$value."</option>";
		}
		echo "</select>";
		echo "<span class=\"annot_petit_it\">(Doit-on arr&ecirc;ter l'exploitation de cette licence en cas de mise &agrave; jour ?)</span>";
	}
	else
	{ 
	?>
	<input name="mae" type="text" id="mae" value="<?PHP echo $non_oui[$rlic_mae]; ?>" size="3" readonly="1">
	<?PHP
	}
	?>		
	</td>
</tr>
</table>

<!-- Redémarrage ? -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_mred" align="right">
		Red&eacute;marrage ?
	</td>
    <td>
	<?PHP 
	if (($td == "add") OR ($td=="edit"))
	{ 
		echo "<select name=\"mred\" size=\"1\" id=\"mred\">";
		foreach ($non_oui as $key=>$value)
		{
			echo "<option value=\"".$value."\"";
			if ($key==$rlic_mred)
				echo " selected=\"selected\"";
			echo ">".$value."</option>";
		}
		echo "</select>";
		echo "<span class=\"annot_petit_it\">(Doit-on red&eacute;marrer le mat&eacute;riel utilisant cette licence  en cas de mise &agrave; jour ?)</span>";
	}
	else
	{ 
	?>
	<input name="mred" type="text" id="mred" value="<?PHP echo $non_oui[$rlic_red]; ?>" size="3" readonly="1">
	<?PHP
	}
	?>		
	</td>
</tr>
</table>
</div>
</form>

<div id="detailm5"  style="display:none">
<!-- Liste des contrats gérant cette licence -->
<table width="100%"  border="0">
<tr>
	<td>
<?PHP
	// Création de la liste des contrats actifs
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech = "SELECT * FROM ".TBCOCL." WHERE `cocl_coderlp` LIKE '%".$rlic_code."%'";
	$rech.=" ORDER BY `cocl_code`";
	$rs = mysql_query($rech) or die(mysql_error());

	if (mysql_num_rows($rs) <> 0)
	{
		echo "<table class=\"MtableD\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";     
		 
		// Création de l'entête de la table "détails contrats"
		echo "<th>";
		echo "Code";
		echo "</th>\n";
		echo "<th>";
		echo "Cr&eacute;&eacute; le";
		echo "</th>\n";
		echo "<th>";
		echo "D&eacute;but";
		echo "</th>\n";
		echo "<th>";
		echo "Fin";
		echo "</th>\n";
		echo "<th>";
		echo $txt_ent_lst_clic;
		echo "</th>\n";

		$j = 0;
		
		while ($row = mysql_fetch_assoc($rs)) 
		{         
			// Création de l'entête de ligne (TR)
			creetrlstdet($j);
			
			 $echeance_ok = TRUE;
			 if (formatedate($row["cocl_datef"]) <> "")
			 {
				if (echeance_depassee_date($datea,$row["cocl_datef"]) == TRUE)
					$echeance_ok = FALSE;
			 }
	
			 echo "<td>".$row["cocl_code"];
	
			 // CREATION d'icône si signé
			  if (formatedate($row["cocl_datesig"]) <> "")
			  {
				$lst_sig = TRUE;
				 echo " <img src=\"../img/ok.png\" title =\"Signé le ".formatedate($row["cocl_datesig"])."\" border=\"0\" align=\"absmiddle\">";
			  }
	
			 // CREATION d'icône si terminé
			  if ((formatedate($row["cocl_datefin"]) <> "") OR ($echeance_ok == FALSE))
			  {
				$lst_fini = TRUE;
				if (formatedate($row["cocl_datefin"]) <> "")
					echo " <img src=\"../img/warn.png\" title =\"Terminé le ".formatedate($row["cocl_datefin"])."\" border=\"0\" align=\"absmiddle\">";
				else
					echo " <img src=\"../img/warn.png\" title =\"Terminé le ".formatedate($row["cocl_datef"])."\" border=\"0\" align=\"absmiddle\">";
			  }
	
			 // Détail contrat
			 echo "<br>";
			 echo "<span class=\"annot_petit_it\">";
			 $rech2 = "SELECT * FROM " .TBCO. " WHERE co_code = '".$row["cocl_codeco"]."'";
			 $rs2 = mysql_query($rech2) or die(mysql_error());
			 if ($row2 = mysql_fetch_array($rs2))
			 {
				$txt = formatetxt($row2["co_nom"]);
				echo "->".htmlspecialchars($txt,ENT_NOQUOTES);
			 }
	
			 echo "</span>";
			 echo "</td>\n";

			 echo "<td>";
			 echo "<div align=\"center\">";
			 echo formatedate($row["cocl_datecrea"]);
			 echo "</div>";
			 echo "</td>\n";
			 echo "<td>";
			 echo "<div align=\"center\">";
			 echo formatedate($row["cocl_dated"]);
			 echo "</div>";
			 echo "</td>\n";
			 echo "<td>";
			 echo "<div align=\"center\">";
			 if (formatedate($row["cocl_datef"]) == "")
				echo "&nbsp;";
			 else
				echo formatedate($row["cocl_datef"]);
			 echo "</div>";
			 echo "</td>\n";

			// CREATION lien dynamique sur icône (édition, impression, etc...)
			 echo "<td>";
			 echo "<div align=\"center\">";
	
	
			 if (@$_SESSION["niv_log"] >= 4) // Edition uniquement si >=agence
			 {
				if ((formatedate($row["cocl_datefin"]) == "") AND ($echeance_ok == TRUE))
				{
					$lst_maj = TRUE;
					
					echo "<a href=\"cocl_maj.php?td=edit&co=".$row["cocl_code"]."&cc=".$row["cocl_codecli"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\"></a>";
				}
				else
				{
					$lst_voir = TRUE;
					
					echo "<a href=\"cocl_maj.php?td=view&co=".$row["cocl_code"]."&cc=".$row["cocl_codecli"]."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\"></a>";
				}
			 }	
	
			 if (@$_SESSION["niv_log"] <= 3) // Voir si <=Technicien
			 {
				$lst_voir = TRUE;
				
				echo "<a href=\"cocl_maj.php?td=view&co=".$row["cocl_code"]."&cc=".$row["cocl_codecli"]."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\"></a>";
			 }	
	
			 if (@$_SESSION["niv_log"] >= 3) // Création intervention uniquement si  >=technicien et pas fini
			 {
				 if ((formatedate($row["cocl_datefin"]) == "") AND (formatedate($row["cocl_datesig"]) <> "") AND ($echeance_ok == TRUE))
				 {
					$lst_int = TRUE;
					
					echo " ";
					$url_int = "int_maj.php?td=add&ci=&cc=".$row["cocl_codecli"]."&ca=".$row["cocl_codeage"]."&co=".$row["cocl_code"];
					echo "<a href=\"".$url_int."\"><img src=\"../img/int.png\" title=\" ".$alt_saisintcocl.$row["cocl_code"]."\"  border=\"0\" align=\"absmiddle\"></a>";
				 }
			 }
			
			 $lst_imp = TRUE;
			
			 $urlimp = "cocl_pdf.php?code=".$row["cocl_code"];
			 echo " ";
			 echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/print.png\" title=\"".$alt_impcocl."\" border=\"0\" align=\"absmiddle\"></a>";
		
			 echo "</div>";
			 echo "</td>\n";

			echo "</tr>\n";
		
			$j++;
		}

		echo "</table>\n";
		// Fin affichage table détails licences

		$taille_piedla ="small";
		include_once("piedla.inc.php");
	}
	else
		echo "Aucun contrat couvrant cette licence.<br>";
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	</td>
</tr>
</table>
</div>

<div id="detailm6" style="display:none">
<!-- Liste des problèmes déclarés -->
<?PHP
if (exist_rpbm($rlic_code) == TRUE)
{
?>
<table width="100%"  border="0">
<tr>
	<td class="rubfrm" colspan="2" align="center">
		Historique des probl&egrave;mes
	</td>
</tr>
</table>

<form name="pbm_lst" id="pbm_lst" method="post" action="rlic_maj.php?td=<?PHP echo $td; ?>&crl=<?PHP echo $crl; ?>">
<table width="100%"  border="0">
<tr>
	<td width="180" class="rubfrm" id="f_site" align="right">Filtre par lieu </td>
	<?PHP 
	if ($cli_ste<>"")
	{
	?>
	<td>
		<select name="site" id="site" onChange="document.getElementById('pbm_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) or die(mysql_error());
		
			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" align="right">Filtre par probl&egrave;mes </td>
	<td>
	<input type="radio" name="pbms" style="background : #FFFFFF;" value="0" <?PHP if ($pbm==0) echo "checked"?>  onClick="document.getElementById('pbm_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('pbm_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('pbm_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_search" align="right">Filtre par mot </td>
<td>
	<input type="text" name="search" value="<?php if(!empty($_POST['search']))echo $_POST['search']; ?>" onChange="document.getElementById('pbm_lst').submit();"> 
	<a href="javascript:;" onclick="document.pbm_lst.search.value='';document.getElementById('pbm_lst').submit();"><img src="../img/raz.png" border="0" align="absmiddle"></a>
</td>
</tr>
</table>
</form>

<table width="100%"  border="0">
<tr>
	<td>
		<span class="annot_gras_it">Liste des probl&egrave;mes d&eacute;clar&eacute;s sur cette licence</span> (<img src="../img/rpbmint.png" border="0" align="absmiddle" > = en cours d&rsquo;intervention)</span>
	</td>
	<td align="right">
		<?PHP
		if (($td <> "del") AND ($rlic_dateoutf == ""))
		{
			$url_add = "rpbm_maj.php?td=add&tr=1&cr=".$rlic_code."&cap=1";
		?>
			<a href="<?PHP echo $url_add; ?>"><img src="../img/add.png" title ="D&eacute;clarer un probl&egrave;me" border="0" align="absmiddle"></a>
			<a href="<?PHP echo $url_add; ?>"> D&eacute;clarer un probl&egrave;me</a>
		<?PHP } else { ?>
			&nbsp;
		<?PHP } ?>
	</td>
</tr>
</table>

<table width="100%"  border="0">
<tr>
	<td>
		<?PHP
		// Création de la liste des problèmes déclarés
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);

		switch($pbm)
		{
			case 0 :
				$rech = "SELECT * FROM ".TBRPBM." WHERE `rpbm_coderlp` = '".$rlic_code."'";
				break;
			case 1 :
				$rech = "SELECT * FROM ".TBRPBM." WHERE `rpbm_coderlp` = '".$rlic_code."'";
				$rech.=" AND (".TBRPBM.".rpbm_codeint IS NULL)";
				break;
			case 2 :
				$rech = "SELECT * FROM ".TBRPBM." WHERE `rpbm_coderlp` = '".$rlic_code."'";
				$rech.=" AND (".TBRPBM.".rpbm_codeint IS NOT NULL)";
				break;
		}
	
		if ($idscli!=-1)
			$rech.=" AND (".TBRPBM.".rpbm_idsite = '".$idscli."' OR ".TBRPBM.".rpbm_idsite = '-1')";
	
		if(isset($_POST['search']) && !empty($_POST['search']))  
		{
			$rech .= " AND (";
			 if (datefrcorrecte(trim($_POST['search'])) == TRUE)
			 {
				 $daterech = datefrang(trim($_POST['search']));
				 $rech .= " rpbm_datecrea LIKE '%".addslashes($daterech)."%' OR";
				 $rech .= " rpbm_datett LIKE '%".addslashes($daterech)."%' OR";
			 }
			$rech .= " rpbm_signale LIKE '%".str_escape(trim($_POST['search']))."%' OR";
			$rech .= " rpbm_pbm LIKE '%".str_escape(trim($_POST['search']))."%' OR";
			$rech .= " rpbm_codeint LIKE '%".str_escape(trim($_POST['search']))."%' OR";
			$rech = substr($rech,0,strlen($rech)-3);
			$rech.=")";
		}
	
		$rech.= " ORDER BY `rpbm_datecrea`";
		$rs = mysql_query($rech) or die(mysql_error());

		if (mysql_num_rows($rs) <> 0)
		{
			echo "<table class=\"MtableD\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";     
			 
			// Création de l'entête de la table "détails 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 "Probl&egrave;me";
			if ($idscli<0)
				echo"<div align=\"right\">(site)</div>";
			echo "</th>\n";
			echo "<th>";
			echo "R&eacute;solu le";
			echo "</th>\n";
			echo "<th>";
			echo $txt_ent_lst_clic;
			echo "</th>\n";

			$j = 0;
			
			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"]);
				if (($row["rpbm_codeint"] <> "") AND (formatedate($row["rpbm_datett"]) == ""))
					echo "<img src=\"../img/rpbmint.png\" border=\"0\" align=\"absmiddle\" title =\"Intervention ".$row["rpbm_codeint"]."\" border=\"0\">";
				echo "</td>\n";
				echo "<td>\n";
				echo htmlspecialchars($row["rpbm_signale"],ENT_NOQUOTES);
				echo "</td>\n";
				echo "<td>\n";
				$tab_txtpbm = cesuretxt_tab($row["rpbm_pbm"],100);
				$txtpbm="";
				foreach ($tab_txtpbm as $index_ligne=>$ligne)
					$txtpbm .= htmlspecialchars($ligne,ENT_NOQUOTES)."<br>";
				echo $txtpbm;
				if ($idscli<0)
				{
					if ($row["rpbm_idsite"]<>0)
					{
						$row2=lit_enr_scli_id($row["rpbm_idsite"],FALSE);
						if (is_array($row2))
						{
							extract($row2);
							echo "<div align=\"right\" class=\"annot_petit_it\">";
							if ($scli_adr2<>"")
								$nom_site = $scli_ste."<br>".$scli_adr1."<br>".$scli_adr2."<br>".Retournecp_openId($scli_ville,FALSE)." ".Retourneville_openId($scli_ville,FALSE);
							else
								$nom_site = $scli_ste."<br>".$scli_adr1."<br>".Retournecp_openId($scli_ville,FALSE)." ".Retourneville_openId($scli_ville,FALSE);
							echo $nom_site;
							echo "</div>";
						}
					}
					else
					{
						echo "<div align=\"right\" class=\"annot_petit_it\">";
						echo "Site principal";
						echo "</div>";
					}
				}
				echo "</td>\n";
				echo "<td align=\"center\">\n";
				echo formatedate($row["rpbm_datett"]);
				if (formatedate($row["rpbm_datett"]) <> "")
				{
					echo "<span class=\"annot_petit_it\">";
					echo "<br>Int. ".$row["rpbm_codeint"];
					echo "</span>";
				}
				echo "</td>\n";

				echo "<td align=\"center\">\n";
				if ($td <> "del")
				{
					if ($row["rpbm_codeint"] == "") // On peut éditer ou supprimer uniquement si aucune intervention n'est rattachée
					{
						$lst_maj = TRUE;
						echo "<a href=\"rpbm_maj.php?td=edit&tr=1&cr=".$row["rpbm_coderlp"]."&id=".$row["rpbm_id"]."&cap=1\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\"></a>";
	
						$lst_del = TRUE;
						echo " ";					
						echo "<a href=\"rpbm_maj.php?td=del&tr=1&cr=".$row["rpbm_coderlp"]."&id=".$row["rpbm_id"]."&cap=1\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\"></a>";
					}
					else
					{
						$lst_voir = TRUE;
						echo "<a href=\"rpbm_maj.php?td=view&tr=1&cr=".$row["rpbm_coderlp"]."&id=".$row["rpbm_id"]."&cap=1\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\"></a>";
					}
				}
				else
				{
					echo "-";
				}
				echo "</tr>\n";
			
				$j++;
			}

			echo "</table>\n";
			// Fin affichage table détails licences

			$taille_piedla ="small";
			include_once("piedla.inc.php");
		}
		else
			echo "Aucun probl&egrave;me avec le filtre demand&eacute;.<br>";
		mysql_free_result($rs);
		mysql_close($conn);
		?>
	</td>
</tr>
</table>
<?PHP
}
else
{
	if ($td <> "add")
	{
?>
	<table width="100%"  border="0">
	<tr>
		<td>
			<span class="annot_gras_it">Aucun probl&egrave;me d&eacute;clar&eacute;</span>
		</td>
		<td align="right">
			<?PHP
			if (($td <> "del") AND ($rlic_dateoutf == ""))
			{
				$url_add = "rpbm_maj.php?td=add&tr=1&cr=".$rlic_code."&cap=1";
			?>
				<a href="<?PHP echo $url_add; ?>"><img src="../img/add.png" title ="D&eacute;clarer un probl&egrave;me" border="0" align="absmiddle"></a>
				<a href="<?PHP echo $url_add; ?>"> D&eacute;clarer un probl&egrave;me</a>
			<?PHP } else { ?>
				&nbsp;
			<?PHP } ?>
		</td>
	</tr>
	</table>
<?PHP
	}
}
?>
</div>

<?PHP
if (($idscli!=-1) OR ($pbm!=0) OR (isset($_POST['search']) && !empty($_POST['search'])))
{
?>
<script type="text/javascript">
<!--
set_mnu_rel('m6');
//-->
</script>
<?PHP
}
?>

<script type="text/javascript">
<!--
<?PHP if ($td == "add") { ?>
Calendar.setup({
	inputField     :    "daterelf",     // id of the input field
	ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
	button         :    "f_img_daterelf",  // trigger for the calendar (button ID)
	align          :    "Br",           // alignment (defaults to "Bl")
	electric	   :	false,
	singleClick    :    true
});
<?PHP } ?>
Calendar.setup({
	inputField     :    "dateoutf",     // id of the input field
	ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
	button         :    "f_img_dateoutf",  // trigger for the calendar (button ID)
	align          :    "Br",           // alignment (defaults to "Bl")
	electric	   :	false,
	singleClick    :    true
});
Calendar.setup({
	inputField     :    "datevalf",     // id of the input field
	ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
	button         :    "f_img_datevalf",  // trigger for the calendar (button ID)
	align          :    "Br",           // alignment (defaults to "Bl")
	electric	   :	false,
	singleClick    :    true
});
Calendar.setup({
	inputField     :    "mdvalf",     // id of the input field
	ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
	button         :    "f_img_mdvalf",  // trigger for the calendar (button ID)
	align          :    "Br",           // alignment (defaults to "Bl")
	electric	   :	false,
	singleClick    :    true
});
Calendar.setup({
	inputField     :    "mdlmajf",     // id of the input field
	ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
	button         :    "f_img_mdlmajf",  // trigger for the calendar (button ID)
	align          :    "Br",           // alignment (defaults to "Bl")
	electric	   :	false,
	singleClick    :    true
});
//-->
</script>
<?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("","rel") ?>);
	warnnbtype(<?PHP echo nb_typlic() ?>);
	warnnbmedia(<?PHP echo nb_media() ?>);
	//-->
	</script>
<?PHP
}
else
{
	if ($td == "edit")
	{
?>
	<script type="text/javascript">
	<!--
	warncpta(<?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=('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">Erreur sur les param&egrave;tres...</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");
?>
