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

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_time.inc.php") ?>
<?php require ("../inc/func_date.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php require ("../inc/fic.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$td = strip_tags(trim($_GET['td'])); // Récupération type demande
	$ci = strip_tags(trim($_GET['ci'])); // Récupération code Intervention
	$cc = strip_tags(trim($_GET['cc'])); // Récupération code Client
	$ct = strip_tags(trim($_GET['ct'])); // Récupération code Technicien traitant
	$ca = strip_tags(trim($_GET['ca'])); // Récupération code Agence
	$co = strip_tags(trim($_GET['co'])); // Récupération code contrat
	$HTTP_SESSION_VARS["pbm_choisis"] = "";

	$pbm_int = FALSE;
	$nbartint = 0;

	if ($ca<> "")
	{
		// 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 ($ca <> @$HTTP_SESSION_VARS["code_age"]))
			$pbm_int = TRUE;
		$int_codeage=$ca;
	}

	if (($co<> "") AND ($pbm_int == FALSE))
	{
		// Récupération des informations contrat
		$row = lit_enr_cocl($co);
		if (is_array($row))
		{
			extract ($row);
			// Contrôle qu'une agence n'essaye pas de "hacker" un contrat
			if ($td <> "add")
			{
				if (((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3)) AND ($cocl_codeage <> @$HTTP_SESSION_VARS["code_age"]))
					$pbm_int = TRUE;
			}
		}
		else
			$pbm_int = TRUE;
		$int_codecocl=$co;
	}

	if (($ci <> "") AND ($pbm_int == FALSE))
	{
		// Vérification qu'il existe bien des articles dans l'intervention
		$nbartint = nb_art_in_int($ci);

		// Récupération des informations intervention
		$row = lit_enr_int($ci);
		if (is_array($row))
		{
			extract ($row);

			// Si intervention terminée, force le mode "view"
			if (formatedate($int_datefin) <> "")
				$td="view";

			// Contrôle qu'une agence n'essaye pas de "hacker" une intervention
			if ($td <> "add")
			{
				if (((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3)) AND ($int_codeage <> @$HTTP_SESSION_VARS["code_age"]))
					$pbm_int = TRUE;
			}
		}
		else
			$pbm_int = TRUE;

		
		if ($pbm_int == FALSE)
		{
			// Construction de la chaîne des problèmes sélectionnés
			$lstpbm = "";
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT rpbm_id FROM `" .TBRPBM. "` WHERE `rpbm_codeint`= '".$ci."'";
			$rs = mysql_query($rech);
			while ($row = mysql_fetch_assoc($rs)) 
			{
				extract($row);
				$lstpbm .= $rpbm_id."-";
			}
			mysql_free_result($rs);
			mysql_close($conn);
			
			$HTTP_SESSION_VARS["pbm_choisis"] = $lstpbm;
	
			//Formatage des dates en français
			$int_datecreaf = formatedate($int_datecrea);
			$int_datemodf = formatedate($int_datemod);
			$int_dateddef = formatedate($int_datedde);
			$int_daterdvf = formatedate($int_daterdv);
			$int_dateprevf = formatedate($int_dateprev);
			$int_datefinf = formatedate($int_datefin);
			$int_datecertf = formatedate($int_datecert);
			
			if ($td == "edit")
			{
				$cc=$int_codecli;
				$ct=$int_codetec;
				$ca=$int_codeage;
				
				$titre = "MISE A JOUR INTERVENTION";
			}
	
			if ($td == "view")
				$titre = "VISUALISATION INTERVENTION";

			if ($td == "del")
				$titre = "SUPPRESSION INTERVENTION";
	
			if ($td == "add")
			{
				$int_dateddef = $datef;
				$int_code = $ci;
				$int_codecli = $cc;
				$int_codetec = $ct;
				$int_codeage = $ca;
				$int_codereg = "EC";
				$int_heurea = "00:00:00";
				$int_heuref = "00:00:00";
				
				$titre = "CREATION INTERVENTION";
			}
	
			// Récupération du total travaillé & Techniciens traitants
			$nbtotalsec = 0;
			$nbtotalsecoff = 0;
			$str_tec_traitants = "";
			if (($td == "edit") OR ($td == "view") OR ($td == "del"))
			{
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
		
				// Récupération total travaillé
				$rech = "SELECT * FROM `" .TBINTH. "` WHERE `inth_codeint`= '".$ci."'";
				$rs = mysql_query($rech);
				if (mysql_num_rows($rs) <> 0)
				{
					while ($row = mysql_fetch_assoc($rs)) 
					{         
						if ($row["inth_offert"] == 0)
							$nbtotalsec = $nbtotalsec + diff_time_sec($row["inth_heurea"],$row["inth_heured"]);
						else
							$nbtotalsecoff = $nbtotalsecoff + diff_time_sec($row["inth_heurea"],$row["inth_heured"]);
					}
				}

				// Si un utilisateur a quitté avant de sauver (bien qu'ayant modifié le détail horaire,
				// on remet en état car seul le détail horaire et technicien enregistré est valable
				if ($int_durees <> $nbtotalsec)
				{
					$rech = "UPDATE `" .TBINT. "` SET `int_datemod`='".$datea."', `int_codemod`='".$codeuser."',`int_durees`='".$nbtotalsec."'";
					$rech .=" WHERE `int_code` = '".$ci."'";
					$rs = mysql_query($rech) or die(mysql_error());
					$int_durees = $nbtotalsec;
				}
		
				// Chaîne des techniciens traitants
				$rech = "SELECT DISTINCT inth_codetec FROM `" .TBINTH. "` WHERE `inth_codeint`= '".$ci."'";
				$rs = mysql_query($rech);
				if (mysql_num_rows($rs) <> 0)
				{
					while ($row = mysql_fetch_assoc($rs)) 
					{
						$rech2 = "SELECT tec_nom, tec_prenom FROM `" .TBTEC. "` WHERE `tec_code`= '".$row["inth_codetec"]."' ORDER BY tec_nom";
						$rs2 = mysql_query($rech2);
						if (mysql_num_rows($rs2) <> 0)
						{
							if ($row2 = mysql_fetch_assoc($rs2))
								$str_tec_traitants .= $row2["tec_nom"]." ".$row2["tec_prenom"].", ";
						}
						mysql_free_result($rs2);
					}
				}
				$str_tec_traitants = substr($str_tec_traitants,0,strlen($str_tec_traitants)-2).".";
				mysql_free_result($rs);
				mysql_close($conn);
			}
		}
	}
	else
	{
		if ($td == "add")
		{
			$int_dateddef = $datef;
			$int_code = crecodesession("I");
			$ci = $int_code;
			$int_codereg= "EC";
			$int_codecocl = $co;
			
			$titre = "CREATION INTERVENTION";
		}

	}

	if (($cc <>"") AND ($pbm_int == FALSE))
	{
		$row = lit_enr_cli($cc);
		if (is_array($row))
		{
			extract ($row);

			// 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))
			{
				$row = lit_enr_age($HTTP_SESSION_VARS["code_age"]);
				extract ($row);
				$zc_couverte = $age_zone;
			}
			else
				$zc_couverte = zc_age_actives();

			// Contrôle qu'une agence n'essaye pas de "hacker" un client
			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_int = TRUE;
					}
				}
				else
				{
					$pbm_int = TRUE;
				}
			}
			$int_codecli = $cc;
		}
	}
?>

<!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 : Fiche Intervention</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../inc/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 validation des formulaires -->
<script language="JavaScript" src="../inc/validator.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>

</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 au moins un client, une agence active, une origine, un statut, un lieu, une civilité, un technicien dans l'agence, et un mode de règlement -->
<?PHP
if ($pbm_int == FALSE)
{
if ((nb_cli("") <>0) AND (nb_age_actives() <> 0) AND (nb_orig() <> 0) AND (nb_statuts() <> 0) AND (nb_lieux() <> 0) AND (nb_civ() <> 0) AND nb_tec("") AND nb_reg())
{
?>
<!-- Affiché uniquement s'il y a un code client -->
<?PHP
if ($cc <> "")
{
?>
<table width="100%"  border="0">
<tr>
	<?PHP if (@$HTTP_SESSION_VARS["niv_log"] <> 2) {?>
		<td width="40%"><strong><em><a href="int_lst.php?ta=m&ord=DES&tri=Code">Retour &agrave; la liste</a></em></strong></td>
	<?PHP } else { ?>
		<td width="40%"><strong><em><a href="index.php">Retour &agrave; la liste</a></em></strong></td>
	<?PHP } ?>
	<td width="20%" 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="40%">
	<div align="right">
	<?PHP
		if ($td == "edit")
		{
		$urlimp1 = "int_pdf.php?ci=".$ci;
		$urlimp2 = "int_pdf.php?ci=".$ci."&cgv=ok";
		?>
        <a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp1; ?>');")><img src="../img/print.gif" title="Imprimer (sans CGV)" width="22" height="22" border="0" align="absmiddle"></a> 
		<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp1; ?>');")> Imprimer (sans CGV) </a>/ 
        <a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp2; ?>');")><img src="../img/printc.gif" title="Imprimer (avec CGV)" width="22" height="22" border="0" align="absmiddle"></a> 
		<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp2; ?>');")> Imprimer (avec CGV)</a>
		<?PHP
		if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut tester le statut comptable
		{
		?>
			<br>
	        <a href="#intart"><img src="../img/art.png" title="Saisir les articles" width="22" height="22" border="0" align="absmiddle"></a> <a href="#intart")> Saisir les articles </a>
	<?PHP 
		} 
	}?>
    </div></td>
</tr>
</table>
<form name="int_maj" method="post" action="int_enr.php" onsubmit="return v.exec();">
<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 $int_codecli ?>">
<input name="lstpbm" type="hidden" id="lstpbm" value="rien">
<?PHP if ($td == "add") ?>
	<input name="code" type="hidden" id="code" value="<?PHP echo $int_code ?>">
<?PHP if (($td == "edit") OR ($td == "del")) { ?>
	<input name="code" type="hidden" id="code" value="<?PHP echo $ci ?>">
	<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $int_codeage ?>">	
	<input name="codeorig" type="hidden" id="codeorig" value="<?PHP echo $int_codeorig ?>">
<?PHP } ?>

<!-- Détails internes de la fiche intervention -->
<?PHP if ($td == "edit")
{
  $url_detint = "intd_maj.php?ci=".$ci;
?>
  <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_detint; ?>',800,300,'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_detint; ?>',800,300,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")> Détails</a><?PHP
}
?>

<!-- Date de demande -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_dateddef"><div align="right">Date Demande </div></td>
	<td>
		<input name="dateddef" type="text" id="dateddef" value="<?PHP echo $int_dateddef ?>" size="10" maxlength="10" readonly="1">
		<?PHP if ($td == "add") { ?>
		<img src="../img/calendar.png" id="f_img_dateddef" title="Choisir votre date" width="16" height="16">
		<img src="../img/oblig.gif" width="10" height="11">
		<?PHP } ?>
	</td>
</tr>
</table>

<!-- Code de l'intervention (affiché uniquement si édition ou suppression) -->
<?PHP if ($td <> "add") {?>
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_codeint"><div align="right">Code </div></td>
	<td>
		<input name="code" type="text" id="code" value="<?PHP echo $int_code ?>" size="20" maxlength="20" readonly="1">
	</td>
</tr>
</table>
<?PHP }  ?>

<!-- Affichage du client -->
<table width="800"  border="0">
<tr>
	<td width="400" class="tfvNormal" 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; ?>',800,400,'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; ?>',800,400,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")> Notes</a>
	<?PHP
	}
	else
		echo "&nbsp;";
	?>
	</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="tfvNormal" id="f_agence"><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 et couvrant le département du client
					
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					// Filtre sur agences ouvertes
					$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
							$i=0;
				
							while ($resultat = mysql_fetch_array($rs)) 
							{
								extract($resultat);
				
								// Vérifie zone de chalandise
								if (exist_chaine_in_seq($cli_dep,$age_zone) == TRUE)
								{
									if ($i == 0)
									{
										if ($int_codeage <> "")
											echo "<option value=\"\">-- Choisissez une agence --</option>";
										else
											echo "<option value=\"\" selected>-- Choisissez une agence --</option>";
									}
				
									if ($int_codeage == $age_code)
									{
										echo '<option value="'.$age_code.'" selected>'.$age_nom.'</option>';
									}
									else
									{
										echo '<option value="'.$age_code.'">'.$age_nom.'</option>';
									}
			
									$i++;
								}
							}
						?>
						</select>
						<img src="../img/oblig.gif" width="10" height="11">
				<?PHP
					}
					else
					{
						echo "<span class=\"annot_gras_it\">";
						echo "Pas d'agence ouverte";
						echo "</span>";
					}
					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);
				$age_nomcode = $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 $age_nomcode; ?>" size="50" maxlength="50" readonly="1">
			<?PHP
			}	
		} 
		else  // Edition ou suppression = zone non modifiable (affichage seul)
		{
			$row = lit_enr_age($int_codeage);
			extract($row);
			$age_nomcode = $age_nom." (".$age_code.")";
		?>
		<input name="nomage" type="text" id="nomage" value="<?PHP echo $age_nomcode ?>" size="50" maxlength="50" readonly="1">
		<?PHP 
		} 
		?>
	</td>
</tr>
</table>

<!-- Affectation d'un contrat à l'intervention -->
<?PHP if ($cc <> "") {?>
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_codeco"><div align="right">Sur le contrat</div></td>
	<td>
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable (on peut choisir un contrat)
		{ 
			
			// Création de la liste des contrats non terminés et signés
			// dont les dates de début et de fin "encadrent" la date du jour
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech ="SELECT * FROM ".TBCOCL." WHERE `cocl_codecli` = '$cc'";
			$rech.=" AND `cocl_datefin` = '0000-00-00' AND `cocl_datesig` <> '0000-00-00'";
			$rech.=" AND `cocl_dated` <= '".$datea."'";
			$rech.=" ORDER BY cocl_code";
			$rs = mysql_query($rech) or die(mysql_error());

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

			<?PHP
				$i=0;
	
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);

					if ($i == 0)
					{
						if ($int_codecocl <> "")
							echo "<option value=\"\">-- Choisissez un contrat --</option>";
						else
							echo "<option value=\"\" selected>-- Choisissez un contrat --</option>";
					}

					 $rech2 = "SELECT * FROM " .TBCO. " WHERE co_code = '".$cocl_codeco."'";
					 $rs2 = mysql_query($rech2) or die(mysql_error());
					 if ($row2 = mysql_fetch_array($rs2))
					 {
						if ($row["cocl_delai"] <> 0)
					 		$txt_cocl = $cocl_code." - ".$row2["co_nom"]." (".$row["cocl_delai"]."h ouvrées)";
						else
					 		$txt_cocl = $cocl_code." - ".$row2["co_nom"]." (Pas de d&eacute;lai)";
					 }

					if ($int_codecocl == $cocl_code)
						echo "<option value=\"".$cocl_code."\" selected>".$txt_cocl."</option>";
					else
						echo "<option value=\"".$cocl_code."\">".$txt_cocl."</option>";
					
					$i++;
				}
			?>
				</select>
 				<span class="annot_petit_it">(Non obligatoire)</span>
 	  <?PHP
			}
			else
			{
				echo "<span class=\"annot_gras_it\">";
				echo "Pas de contrat actif sur ce client";
				echo "</span>";
			}

			mysql_free_result($rs);
			mysql_close($conn);
		} 
		else  // Contrat clôt = zone non modifiable (affichage seul)
		{
			$txt_cocl = "";
			if ($int_codecocl <> "")
			{
				$row = lit_enr_cocl($int_codecocl);
				if (is_array($row))
					extract($row);
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rech2 = "SELECT * FROM " .TBCO. " WHERE co_code = '".$cocl_codeco."'";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if ($row2 = mysql_fetch_array($rs2))
				{
					$txt_cocl = $cocl_code." - ".$row2["co_nom"];
				}
				mysql_free_result($rs2);
				mysql_close($conn);
			}
		?>
			<input name="codecocl" type="hidden" id="codecocl" value="<?PHP echo $int_codecocl ?>">
			<input name="ncocl" type="text" id="ncocl" value="<?PHP echo $txt_cocl ?>" size="100" readonly="1">
		<?PHP
		}
		?>
	</td>
</tr>
</table>
<?PHP }  ?>

<!-- Paramètres de la demande -->
<table width="800"  border="0">
  <tr>
    <td width="160" class="tfvNormal" id="f_orig"><div align="right">Demand&eacute; par </div></td>
    <td>
		<?PHP 
		if ($td =="add") // Si ajout, on peut choisir l'origine de la demande
		{ 
		?>
        	<select name="codeorig" id="codeorig">
        <?PHP
			
			// Création de la liste des origines
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rs = mysql_query("SELECT * FROM ".TBORI." ORDER BY orig_desc");

			$i=0;

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

				if ($i == 0)
				{
					if ($int_codeorig <> "")
						echo "<option value=\"\">-- Choisissez une origine --</option>";
					else
						echo "<option value=\"\" selected>-- Choisissez une origine --</option>";
				}

				if ($int_codeorig == $orig_code)
					echo '<option value="'.$orig_code.'" selected>'.$orig_desc.'</option>';
				else
					echo '<option value="'.$orig_code.'">'.$orig_desc.'</option>';
				
				$i++;
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
	        </select>
        <img src="../img/oblig.gif" width="10" height="11">
        <?PHP 
		} 
		else // Sinon, on affiche simplement l'origine de la demande
		{
			$row = lit_enr_ori($int_codeorig);
			extract($row);
		?>
        <input name="nomorig" type="text" id="nomorig" value="<?PHP echo $orig_desc ?>" size="10" maxlength="10" readonly="1">
        <?PHP 
		} 
		?>
        <span class="annot_petit_it">(ATELIER = mat&eacute;riel directement apport&eacute; par le client)</span> </td>
  </tr>
  <tr>
    <td width="160" class="tfvNormal" id="f_statut"><div align="right">Statut </div></td>
    <td>
		<?PHP
		if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut changer le statut
		{
		?>
        	<select name="codestatut" id="codestatut">
        <?PHP
			
			// Création de la liste des Statuts
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rs = mysql_query("SELECT * FROM ".TBSTA." ORDER BY statut_desc");

			$i=0;

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

				if ($i == 0)
				{
					if ($int_codestatut <> "")
						echo "<option value=\"\">-- Choisissez un statut --</option>";
					else
						echo "<option value=\"\" selected>-- Choisissez un statut --</option>";
				}

				if ($statut_code <> "CLOT") // Pour clore, il faut remplir la date de cloture
				{
					if ($int_codestatut == $statut_code)
						echo '<option value="'.$statut_code.'" selected>'.$statut_desc.'</option>';
					else
						echo '<option value="'.$statut_code.'">'.$statut_desc.'</option>';
				}
				
				$i++;
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
	        </select>
        <img src="../img/oblig.gif" width="10" height="11">
        <?PHP
		}
		else // Si c'est clot, on se contente d'afficher le statut
		{
		?>
        <input name="codestatut" type="text" id="codestatut" value="<?PHP echo $int_codestatut ?>" size="50" maxlength="50" readonly="1">
        <?PHP
		}
		?>
    </td>
  </tr>
  <tr>
    <td width="160" class="tfvNormal" id="f_lieu"><div align="right">Lieu </div></td>
    <td>
		<?PHP
		if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut changer le statut
		{
		?>
			<select name="codelieu" id="codelieu" onChange="warn_lieu();">
			<?PHP
			
			// Création de la liste des Types Lieux
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBLIEU." ORDER BY lieu_desc";
			$rs = mysql_query($rech);
	
			$i=0;
	
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
	
				if ($i == 0)
				{
					if ($int_codelieu <> "")
						echo "<option value=\"\">-- Choisissez un lieu --</option>";
					else
						echo "<option value=\"\" selected>-- Choisissez un lieu --</option>";
				}
	
				if ($int_codelieu == $lieu_code)
					echo '<option value="'.$lieu_code.'" selected>'.$lieu_desc.'</option>';
				else
					echo '<option value="'.$lieu_code.'">'.$lieu_desc.'</option>';
				
				$i++;
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
		  </select>
	        <img src="../img/oblig.gif" width="10" height="11"> 
        <?PHP
		}
		else // Si c'est clot, on se contente d'afficher le lieu
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBLIEU." WHERE `lieu_code` = '".$int_codelieu."'";
			$rs = mysql_query($rech);
			if ($row = mysql_fetch_array($rs))
			{
				extract ($row);
			}
			mysql_free_result($rs);
			mysql_close($conn);
		?>
	        <input name="codelieu" type="hidden" id="codelieu" value="<?PHP echo $int_codelieu ?>" size="50" maxlength="50" readonly="1">
	        <input name="lieu" type="text" id="lieu" value="<?PHP echo $lieu_desc ?>" size="50" maxlength="50" readonly="1">
        <?PHP
		}
		?>
	</td>
  </tr>
  <tr>
    <td class="tfvNormal" id="f_urg"><div align="right">Niveau d'urgence </div></td>
    <td>
		<?PHP
		if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut changer le niveau d'urgence
		{
		?>
			<select name="urgence" id="urgence">
		  <?PHP
			
			// Création du niveau d'urgence
			
			$i=0;
	
			for ($i=0; $i<4; $i++)
			{
				if ($int_urg == $i)
					echo '<option value="'.$i.'" selected>'.$niv_urgence[$i].'</option>';
				else
					echo '<option value="'.$i.'">'.$niv_urgence[$i].'</option>';
			}
			?>
			</select>
		  <img src="../img/oblig.gif" width="10" height="11"> <span class="annot_petit_it">(A modifier uniquement sur demande express du client)</span> 
    <?PHP
		}
		else // Si c'est clot, on se contente d'afficher le niveau d'urgence
		{
		?>
	        <input name="urgence" type="hidden" id="urgence" value="<?PHP echo $int_urg ?>" size="50" maxlength="50" readonly="1">
	        <input name="urg" type="text" id="urg" value="<?PHP echo $niv_urgence[$int_urg] ?>" size="50" maxlength="50" readonly="1">
        <?PHP
		}
		?>	</td>
  </tr>
</table>

<!-- Date de RDV -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_rdv"><div align="right">Date RDV </div></td>
	<td>
		<input name="daterdvf" type="text" id="daterdvf" value="<?PHP echo $int_daterdvf ?>" size="10" maxlength="10" readonly="1" onChange="warn_rdv();">
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable (on peut choisir une date)
		{ 
		?>
			<img src="../img/calendar.png" id="f_img_daterdvf" title="Choisir votre date" width="16" height="16">
			<span class="annot_std_gras">
			<a href="javascript:;" onclick="document.int_maj.daterdvf.value='';warn_rdv();"><img src="../img/raz.gif" width="12" height="12" border="0" align="absmiddle"></a>
			</span> 
			 (heure :
			<input name="hrdv" type="text" id="hrdv" value="<?PHP echo $int_hrdv ?>" size="8" maxlength="8">
			)		
			<a href="javascript:;" onclick="document.int_maj.hrdv.value=''"><img src="../img/raz.gif" width="12" height="12" border="0" align="absmiddle"></a>
		<?PHP } else { ?>
			 (heure :
			<input name="hrdv" type="text" id="hrdv" value="<?PHP echo $int_hrdv ?>" size="8" maxlength="8" readonly="1">
			)
		<?PHP } ?>
        <span class="annot_petit_it">hh:mm:ss</span>	
	</td>
</tr>
</table>

<!-- Matériel, Logins/mots de passe et problème de la demande -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_mat">
		<div align="right">Mat&eacute;riel </div>
	</td>
	<td>
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable
		{ 
			// S'il y a des problèmes déclarés, affecté à cette intervention ou pas affectés du tout, on peut les choisir
			// UNIQUEMENT si le contrat n'est pas clôt !
			if (($td == "add") OR ($td =="edit"))
			{
				if (exist_rpbm_actif($td,$int_codecli,$int_code) == TRUE)
				{
					$url_recuppbm = "rpbm_lst.php?td=".$td."&cc=".$int_codecli."&ci=".$int_code;
			?>
					<table width="630"  border="0">
					<tr>
						<td>
							<input name="addpbm" type="button" id="addpbm" value="Probl&egrave;mes signal&eacute;s" style="background-color:#FF0000; color:#FFFF00; font-weight:bold;" onClick="fensaisie('<?PHP echo $url_recuppbm; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');">
							<span class="annot_petit_it">(Cliquer)</span>
						</td>
						<td align="right">
							<input name="modmat" type="button" id="modmat" value="Modifier" onClick="document.int_maj.mat.readOnly = false; document.int_maj.mat.focus(); this.style.backgroundColor='#00FFFF';">
						</td>
					</tr>
					</table>
					<textarea name="mat" cols="95" rows="5" id="mat" onBlur="document.int_maj.mat.readOnly = true; document.int_maj.modmat.style.backgroundColor='#CCCCCC';"><?PHP echo $int_mat ?></textarea>
			<?PHP
				}
				else
				{
				?>
					<textarea name="mat" cols="95" rows="5" id="mat"><?PHP echo $int_mat ?></textarea>
				<?PHP
				}
			}
			?>
			<img src="../img/oblig.gif" width="10" height="11" align="top"> 
		<?PHP } else { ?>
			<textarea name="mat" cols="95" rows="5" id="mat" readonly><?PHP echo $int_mat ?></textarea>
		<?PHP } ?>
	</td>
</tr>
</table>
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_login"><div align="right">Login/MDP Sys. </div></td>
	<td>
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable
		{ 
		?>
			<input name="login" type="text" id="login" value="<?PHP echo $int_login ?>" size="20" maxlength="20">
			/
			<input name="mdpsys" type="text" id="mdpsys" value="<?PHP echo $int_mdpsys ?>" size="20" maxlength="20">
		<?PHP } else { ?>
			<input name="login" type="text" id="login" value="<?PHP echo $int_login ?>" size="20" reaonly="1">
			/
			<input name="mdpsys" type="text" id="mdpsys" value="<?PHP echo $int_mdpsys ?>" size="20" readonly="1">
		<?PHP } ?>
	</td>
	<td width="120" class="tfvNormal" id="f_mdpbios"><div align="right">MDP BIOS </div></td>
	<td>
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable
		{ 
		?>
			<input name="mdpbios" type="text" id="mdpbios" value="<?PHP echo $int_mdpbios ?>" size="20" maxlength="20">
		<?PHP } else { ?>
			<input name="mdpbios" type="text" id="mdpbios" value="<?PHP echo $int_mdpbios ?>" size="20" readonly="1">
		<?PHP } ?>
	</td>
</tr>
</table>
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_pbm">
		<div align="right">
		<p>Descriptif probl&egrave;me</p>
		</div>
	</td>
	<td>
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable
		{ 
			if (($td == "add") OR ($td =="edit"))
			{
				if ((exist_rpbm_actif($td,$int_codecli,$int_code) == TRUE) AND ($int_datefinf == ""))
				{
		?>
					<table width="630"  border="0">
					<tr>
						<td>&nbsp;
							
						</td>
						<td align="right">
							<input name="modpbm" type="button" id="modpbm" value="Modifier" onClick="document.int_maj.pbm.readOnly = false; document.int_maj.pbm.focus();  this.style.backgroundColor='#00FFFF';">
						</td>
					</tr>
					</table>
					<textarea name="pbm" cols="95" rows="5" id="pbm" onBlur="document.int_maj.pbm.readOnly = true;  document.int_maj.modpbm.style.backgroundColor='#CCCCCC';"><?PHP echo $int_pbm ?></textarea>
			<?PHP
				}
				else
				{
				?>
					<textarea name="pbm" cols="95" rows="5" id="pbm"><?PHP echo $int_pbm ?></textarea>
				<?PHP
				}
			}
			else
			{
			?>
				<textarea name="pbm" cols="95" rows="5" id="pbm"><?PHP echo $int_pbm ?></textarea>
			<?PHP
			}
			?>
			<img src="../img/oblig.gif" width="10" height="11" align="top">
		<?PHP
		  } else { ?>
			<textarea name="pbm" cols="95" rows="5" id="pbm" readonly><?PHP echo $int_pbm ?></textarea>
		<?PHP } ?>
	</td>
</tr>
</table>

<!-- Intervention sous garantie ou pas ? -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_gar"><div align="right">Garantie</div></td>
	<td>
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable
		{ 
		?>
			<?PHP
			if ($int_gar == 0)
			{
			?>
				<select name="gar" id="gar" onChange="verif_gar(this.value);">
				<option value="0" selected>Non</option>
				<option value="1">Oui</option>
				</select>
			<?PHP
			}
			else
			{
			?>
				<select name="gar" id="gar" onChange="verif_gar(this.value);">
				<option value="0">Non</option>
				<option value="1" selected>Oui</option>
				</select>
			<?PHP
			}
			?>
			<span class="annot_std_gras">R&eacute;f&eacute;rence facture :</span>
			<input name="fgar" type="text" id="fgar" value="<?PHP echo $int_fgar ?>" size="30" maxlength="30" onBlur="verif_fgar(this.value)">
			<img src="../img/oblig.gif" width="10" height="11" align="top">
		  <span class="annot_petit_it">(Si oui)</span>	
	   <?PHP 
	   } 
	   else 
	   { 
 			if ($int_gar == 0)
			{
		?>
				<input name="gar" type="text" id="gar" value="Non" size="3" maxlength="3" readonly="1">
		<?PHP
			}
			else
			{
		?>
				<input name="gar" type="text" id="gar" value="Oui" size="3" maxlength="3" readonly="1">
			<input name="fgar" type="text" id="fgar" value="<?PHP echo $int_fgar ?>" size="30" maxlength="30" readonly="1">
		<?PHP }
		}
		?>
	</td>
</tr>
</table>

<!-- Acompte versé -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_acpte"><div align="right">Acompte (&euro; TTC) </div></td>
	<td>
		<?PHP
		if ($int_dateprevf == "")  // Si client prévenu = zone modifiable
		{ 
		?>
			<input name="acpte" type="text" id="acpte" align="right" value="<?PHP echo $int_acpte ?>" size="10" maxlength="10"> 
			<img src="../img/oblig.gif" width="10" height="11"><br>
			<span class="annot_std_it">(la d&eacute;cimale doit &ecirc;tre '</span><span class="annot_gras_it">.</span><span class="annot_std_it">' et pas la virgule !)</span> </p>
		<?PHP
		}
		else
		{
		?>
			<input name="acpte" type="text" id="acpte" align="right" value="<?PHP echo $int_acpte ?>" size="10" maxlength="10" readonly="1"> 
	   <?PHP 
		}
	   ?>
	</td>
</tr>
</table>

<?PHP if ($td <> "add") { ?>  <!-- Début de zone exclue si création -->
<br>
<!-- Technicien Responsable -->
<table width="800"  border="0">
  <tr>
    <td width="160" class="tfvNormal" id="f_codetec"><div align="right">Responsable dossier</div></td>
    <td>
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable
		{ 
		?>
			<?PHP
			
			// Création de la liste des Techniciens de l'agence
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBTEC." WHERE `tec_codeage` = '$int_codeage' ORDER BY tec_nom";
			$rs = mysql_query($rech);
	
			if (mysql_num_rows($rs) <> 0)
			{
			?>
				<select name="codetec" id="codetec" onChange="verif_tec();">
			<?PHP
				$i=0;
		
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
	
					if ($i == 0)
					{
						if ($int_codetec <> "")
							echo '<option value="">-- Choisissez un technicien --</option>';
						else
							echo '<option value="" selected>-- Choisissez un technicien --</option>';
					}
	
					if ($int_codetec == $tec_code)
						echo "<option value=\"".$tec_code."\" selected>".$tec_nom." ".$tec_prenom."</option>";
					else
						echo "<option value=\"".$tec_code."\">".$tec_nom." ".$tec_prenom."</option>";
					
					$i++;
				}
			?>
			  </select>
			<img src="../img/oblig.gif" width="10" height="11"> 
			<?PHP
			}
			else
			{
				echo "Pas de technicien actif sur cette agence";
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
		<?PHP
		}
		else
		{
			$row = lit_enr_tec($int_codetec);
			extract($row);
			$txt_tec = $tec_nom." ".$tec_prenom;
		?>
	        <input name="codetec" type="hidden" id="codetec" value="<?PHP echo $int_codetec ?>" size="50" maxlength="50" readonly="1">
	        <input name="tec" type="text" id="tec" value="<?PHP echo $txt_tec; ?>" size="50" maxlength="50" readonly="1">
		<?PHP } ?>
	</td>
  </tr>
</table>

<!-- Techniciens traitants -->
<table width="800"  border="0">
  <tr>
    <td width="160" class="tfvNormal" id="f_tect"><div align="right">Technicien(s) traitant(s) </div></td>
    <td>
		<textarea name="tect" cols="98" rows="2" id="tect" readonly="1"><?PHP echo $str_tec_traitants; ?></textarea>            
	</td>
  </tr>
</table>

<!-- Travail effectué -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_duree"><div align="right">Temps travaill&eacute;</div></td>
	<td>
		<input name="duree" type="text" id="duree" value="<?PHP echo sec_heure($int_durees) ?>" size="8" maxlength="8" readonly="1"> 
		<!-- Détails internes du temps passé -->
		<?PHP if (($td == "edit") OR ($td == "view"))
		{
			$url_detinth = "inth_maj.php?td=add&ci=".$ci;
		?>
			<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_detinth; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/clock.gif" width="16" height="16" border="0" align="absmiddle"></a>
			<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_detinth; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Détails horaires &amp; techniciens</a>
		<?PHP
		}
		if ($nbtotalsecoff <> 0)
		{
			echo "<br>";
			echo "<span class=\"annot_petit_it\">";
			echo "(Plus temps offert : ";
			?>
			<input name="dureeoff" type="text" id="dureeoff" value="<?PHP echo sec_heure($nbtotalsecoff) ?>" size="8" maxlength="8" readonly="1"> 
			<?PHP
			echo ")";
			echo "</span>";
		}
		?>
	</td>
</tr>
<tr>
	<td width="160" class="tfvNormal" id="f_fait"><div align="right">Travail effectu&eacute; </div></td>
	<td>
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable
		{ 
			// S'il y a des problèmes déclarés, affecté à cette intervention, on peut les mettre à jour
			// UNIQUEMENT si le contrat n'est pas clôt !
			if (($td == "add") OR ($td =="edit"))
			{
				if (exist_rpbm_attache($int_code) == TRUE)
				{
					$url_traitepbm = "rpbmtt_maj.php?ci=".$int_code;
			?>
					<table width="630"  border="0">
					<tr>
						<td>
							<input name="ttpbm" type="button" id="ttpbm" value="Probl&egrave;mes trait&eacute;s" style="background-color:#FF0000; color:#FFFF00; font-weight:bold;" onClick="fensaisie('<?PHP echo $url_traitepbm; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');">
							<span class="annot_petit_it">(Cliquer)</span>
						</td>
						<td align="right">
							<input name="modfait" type="button" id="modfait" value="Modifier" onClick="document.int_maj.fait.readOnly = false; document.int_maj.fait.focus(); this.style.backgroundColor='#00FFFF';">
						</td>
					</tr>
					</table>
					<textarea name="fait" cols="98" rows="5" id="fait" onChange="verif_fait();" onBlur="document.int_maj.mat.readOnly = true; document.int_maj.modmat.style.backgroundColor='#CCCCCC';"><?PHP echo $int_fait ?></textarea>            
		<?PHP
				}
				else
				{
		?>
				<textarea name="fait" cols="98" rows="5" id="fait" onChange="verif_fait();"><?PHP echo $int_fait ?></textarea>
		<?PHP
				}
			}
		} 
		else 
		{ 
		?>
			<textarea name="fait" cols="98" rows="5" id="fait" readonly="1"><?PHP echo $int_fait ?></textarea>            
		<?PHP 
		}
		?>
	</td>
</tr>
</table>

<!-- Date d'appel du client une fois le dossier traité -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_dateprevf"><div align="right">Client pr&eacute;venu  le </div></td>
	<td>
		<input name="dateprevf" type="text" id="dateprevf" value="<?PHP echo $int_dateprevf ?>" size="10" maxlength="10" readonly="1" onChange="verif_dprev();">
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable (on peut choisir une date)
		{ 
		?>
		<img src="../img/calendar.png" id="f_img_dateprevf" title="Choisir votre date" width="16" height="16">
		<a href="javascript:;" onclick="document.int_maj.dateprevf.value=''"><img src="../img/raz.gif" width="12" height="12" border="0" align="absmiddle"></a>
		<?PHP } ?>
	</td>
</tr>
</table>

<!-- Mode de règlement -->
<table width="800"  border="0">
  <tr>
    <td width="160" class="tfvNormal" id="f_reg"><div align="right">R&egrave;glement</div></td>
    <td>
		<?PHP
		if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut changer le règlement
		{
		?>
			<select name="reg" id="reg">
			<?PHP
			
			// Création de la liste des Règlements
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rs = mysql_query("SELECT * FROM ".TBREG." ORDER BY reg_desc");
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				if ($int_codereg == $reg_code)
				{
					echo '<option value="'.$reg_code.'" selected>'.$reg_desc.'</option>';
				}
				else
				{
					echo '<option value="'.$reg_code.'">'.$reg_desc.'</option>';
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
		  </select>
        <?PHP
		}
		else // Si c'est clot, on se contente d'afficher le règlement
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBREG." WHERE `reg_code` = '".$int_codereg."'";
			$rs = mysql_query($rech);
			if ($row = mysql_fetch_array($rs))
			{
				extract ($row);
			}
			mysql_free_result($rs);
			mysql_close($conn);
		?>
	        <input name="reg" type="hidden" id="codelieu" value="<?PHP echo $int_codereg ?>" size="50" maxlength="50" readonly="1">
	        <input name="creg" type="text" id="creg" value="<?PHP echo $reg_desc ?>" size="50" maxlength="50" readonly="1">
        <?PHP
		}
		?>
		  
	</td>
  </tr>
</table>

<!-- Date de clôture du dossier -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_datefinf"><div align="right">Dossier cl&ocirc;t le </div></td>
	<td>
		<input name="datefinf" type="text" id="datefinf" value="<?PHP echo $int_datefinf ?>" size="10" maxlength="10" readonly="1" onChange="verif_dfin();">
		<?PHP
		if ($int_datefinf == "")  // Si contrat non clôt = zone modifiable (on peut choisir une date)
		{ 
		?>
		<img src="../img/calendar.png" id="f_img_datefinf" title="Choisir votre date" width="16" height="16">
		<a href="javascript:;" onclick="document.int_maj.datefinf.value=''"><img src="../img/raz.gif" width="12" height="12" border="0" align="absmiddle"></a> <span class="annot_petit_it">(Si vous saisissez une date, le dossier sera cl&ocirc;t. Entrez vos pi&egrave;ces et prestations AVANT de cl&ocirc;re) </span>
		<?PHP } ?>
	</td>
</tr>
</table>
<?PHP } ?> <!-- Fin de zone exclue si création -->
  
<!-- Bouton de validation permettant l'enregistrement et le retour en saisie (pour les articles et prestation) -->
<div align="center">
<?PHP 
if ($td == "edit") 
{ 
	if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut changer le règlement
	{
?>
		<input name="intart" type="submit" id="intart" value="Valider pour saisir les articles">
		<br>
		<span class="annot_petit_it">(Sinon, saisissez les articles et prestations AVANT de remplir la fiche ci-dessus)</span> 
<?PHP 
	}
	else
		echo "<br><br>";
} 
?>
</div>

<!-- Zone de saisie des articles et prestations -->
<?PHP
if (($td == "edit") OR ($td == "del"))
{
?>
	<a name="intart"></a>
	<table width="800"  border="0">
	<tr>
		<td class="tfvNormal">
		<div align="left">Forfaits et pi&egrave;ces factur&eacute;es </div>
		</td>
	</tr>
	</table>

	<?PHP
	if ($nbartint <> 0) // Si des articles présents, on les affiche
	{ 
		$totalint = 0;
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM ".TBPDTI." WHERE pdti_codeint='".$ci."' ORDER BY 'pdti_id'";
		
		$rs = mysql_query($rech) or die(mysql_error());
		
		// *** Affichage de la table
		echo "<table class=\"Ltable\"  border=\"0\" width=\"800\">\n";     
		
		// Création entête
		echo "<th class=\"thlst\">Code</th>\n";
		echo "<th class=\"thlst\">Désignation + NS</th>\n";
		echo "<th class=\"thlst\">PU TTC</th>\n";
		echo "<th class=\"thlst\">Qté</th>\n";
		echo "<th class=\"thlst\">Total</th>\n";
		echo "<th class=\"thlst\">Cliquer</th>\n";
		
		$i = 0;
		
		while ($row = mysql_fetch_assoc($rs)) 
		{         
		
			// Extraction information article
			
			$rech2 = "SELECT pdt_des FROM ".TBPDT." WHERE pdt_code='".$row["pdti_codepdt"]."'";
			$rs2 = mysql_query($rech2) or die(mysql_error());
			
			while ($row2 = mysql_fetch_assoc($rs2)) 
			{
				extract($row2);
			}
			
			// Couleurs alternées
			if($i%2 == 0)  
				echo "<tr class=\"TRalter1\">\n";
			else
				echo "<tr class=\"TRalter2\">\n";
			
			echo "<td class=\"tdlst\" valign=\"top\">".$row["pdti_codepdt"]."</td>\n";
			echo "<td class=\"tdlst\" valign=\"top\">";
			echo $pdt_des;
			if ($row["pdti_ns"] <> "")
			{
				$ligne_cesure = cesuretxt_tab($row["pdti_ns"],100);
				$serie = "";
				foreach ($ligne_cesure as $index_ligne=>$ligne)
					$serie .= $ligne."<br>";
				echo "<br>";
				echo "&raquo; ";
				echo "<span class=\"annot_moy_it\">";
				echo "N/S : ".$serie;
				echo "</span>";
			}
			if ($row["pdti_texte"] <> "")
			{
				if ($row["pdti_ns"] == "")
					echo "<br>";
				$ligne_cesure = cesuretxt_tab($row["pdti_texte"],100);
				$commentaire = "";
				foreach ($ligne_cesure as $index_ligne=>$ligne)
					$commentaire .= $ligne."<br>";
				echo "<span class=\"annot_moy_it\">";
				echo $commentaire;
				echo "</span>";
			}
			echo "</td>\n";
			echo "<td class=\"tdlst\" valign=\"top\">";
			echo "<div align=\"right\">";
			echo $row["pdti_puttc"]."€";
			echo "</div>";
			echo "</td>\n";
			echo "<td class=\"tdlst\" valign=\"top\">";
			echo "<div align=\"right\">";
			echo $row["pdti_qte"];
			echo "</div>";
			echo "</td>\n";
			$total = $row["pdti_puttc"]*$row["pdti_qte"];
			echo "<td class=\"tdlst\" valign=\"top\">";
			echo "<div align=\"right\">";
			echo number_format($total,2,'.','')."€";
			echo "</div>";
			echo "</td>\n";		
			
			$totalint = $totalint+$total;
			
			// CREATION lien dynamique sur icône (édition, suppression, etc...)
			echo "<td >";
			echo "<div align=\"center\">";

			if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut éditer les articles
			{
				$urleditart = "pdti_maj.php?td=edit&ci=".$row["pdti_codeint"]."&ca=".$row["pdti_codepdt"];
				echo "<a href=\"javascript:;\" onclick=\"fensaisie('".$urleditart."',700,500,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');\")><img src=\"../img/edit.png\" title=\"Modifier la ligne article\" width=\"22\" height=\"22\" border=\"0\" align=\"absmiddle\"></a>";
				echo " ";
				$urldelart = "pdti_maj.php?td=del&ci=".$row["pdti_codeint"]."&ca=".$row["pdti_codepdt"];
				echo "<a href=\"javascript:;\" onclick=\"fensaisie('".$urldelart."',700,500,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');\")><img src=\"../img/del.gif\" title=\"Supprimer la ligne article\" width=\"22\" height=\"22\" border=\"0\" align=\"absmiddle\"></a>";
			}
			else
			{
				echo "&nbsp;";
			}
			echo "</div>";
			echo "</td>\n";
			
			echo "</tr>\n";
			
			$i++;
		}  
	
		echo "<tr class=\"TRalter3\">\n";
		echo "<td>\n</td>\n";
		echo "<td>\n</td>\n";
		echo "<td>\n</td>\n";
		echo "<td>";
		echo "<div align=\"right\">";
		echo "Total :";
		echo "</div>";
		echo "</td>\n";
		echo "<td>";
		echo "<div align=\"right\">";
		echo number_format($totalint,2,'.','')."€";
		echo "</div>";
		echo "</td>\n";		
		echo "<td>";
		echo "<div align=\"left\">";
		echo "TTC";
		echo "</div>";
		echo "<tr class=\"TRalter3\">\n";
		echo "<td>\n</td>\n";
		echo "<td>\n</td>\n";
		echo "<td>\n</td>\n";
		echo "<td>";
		echo "<div align=\"right\">";
		echo "Acompte :";
		echo "</div>";
		echo "</td>\n";
		echo "<td>";
		echo "<div align=\"right\">";
		echo "-".number_format($int_acpte,2,'.','')."€";
		echo "</div>";
		echo "<td>";
		echo "<div align=\"left\">";
		echo "TTC";
		echo "</div>";
		echo "</td>\n";
		echo "<tr class=\"TRalter3\">\n";
		echo "<td>\n</td>\n";
		echo "<td>\n</td>\n";
		echo "<td>\n</td>\n";
		echo "<td>";
		echo "<div align=\"right\">";
		echo "Net à payer :";
		echo "</div>";
		echo "</td>\n";
		echo "<td>";
		echo "<div align=\"right\">";
		echo number_format(($totalint-$int_acpte),2,'.','')."€";
		echo "</div>";
		echo "</td>\n";
		echo "<td>";
		echo "<div align=\"left\">";
		echo "TTC";
		echo "</div>";
		echo "</td>\n";
		echo "</tr>\n";
		
		echo "</table>\n";
		// *** Fin affichage de la table
		
		mysql_free_result($rs);
		mysql_close($conn);  
	}
	else
	{
		echo "<span class=\"annot_gras_it\">";
		echo "Aucun article ou prestation";
		echo "</span>";
		echo "<br>";
	}
		$urlchoixart = "pdt_lst.php?ta=i&td=".$td."&cc=".$cc."&ct=".$ct."&cte=".$cte."&ci=".$ci."&cx=";
	?>

	<!-- Choix de "l'avenir" des pièces changées -->
	<?PHP 
	// On peut choisir quoi faire avec les pièces, uniquement s'il y en a eu de changées
	// ET si le certificat de destruction n'a pas été envoyé
	if (($nbartint <> 0) AND ($int_datecertf == ""))
	{ 
	?>
		<table width="800" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td>
			<div align="center">
			<span class="annot_std_gras">Pi&egrave;ces hors service :</span> 
			<span class="annot_std_it"> 
			<?PHP
			if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut éditer
			{
			?>
				Sans objet
				<?PHP if ($int_pces == 0) { ?>
					<input type="radio" name="pieces_hs" style="background : #FFFFFF;" value="so" checked>
				<?PHP } else { ?>
					<input type="radio" name="pieces_hs" style="background : #FFFFFF;" value="so">
				<?PHP } ?>
				/ Rendues 
				<?PHP if ($int_pces == 1) { ?>
					<input type="radio" name="pieces_hs" style="background : #FFFFFF;" value="rend" checked>
				<?PHP } else { ?>
					<input type="radio" name="pieces_hs" style="background : #FFFFFF;" value="rend">
				<?PHP } ?>
				/ Conserv&eacute;es <?PHP if ($int_pces == 2) { ?>
					<input type="radio" name="pieces_hs" style="background : #FFFFFF;" value="cons" checked>
				<?PHP } else { ?>
					<input type="radio" name="pieces_hs" style="background : #FFFFFF;" value="cons">
				<?PHP } ?>
			<?PHP
			}
			else
			{
				if ($int_pces == 0)
					echo " Sans objet";
				if ($int_pces == 1)
					echo " Rendues";
				if ($int_pces == 2)
					echo " Conservées";
			} ?>
			</span>
			</div>
			</td>
		</tr>
		</table>
	<?PHP 
	} 
	?>

	<!-- Lien d'ajout d'article ou de prestation-->
	<?PHP
	if ($td <> "del")
	{
		if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut ajouter
		{
	?>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $urlchoixart; ?>',900,500,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/add.gif" width="22" height="22" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $urlchoixart; ?>',900,500,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Ajouter un article</a><span class="annot_std_it"> (Validez d'abord vos saisies!)</span> 
		<br>
	<?PHP
		}
	}
}
?>
<input name="totalint" type="hidden" id="totalint" value="<?PHP echo $totalint ?>">
<?PHP
	if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut ajouter
	{
?>
		<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">
		<?PHP
			if (@$HTTP_SESSION_VARS["niv_log"] <> 2)
			{
		?>
				<input name="enrimp" type="submit" id="enrimp" value="Enregistrer & Imprimer">
		<?PHP
			} 
		} 
		?>
		
		<?PHP 
		if ($td == "del") // Bouton si en mode suppression
		{ 
		?>
			<input name="del" type="submit" id="del" value="Supprimer">
		<?PHP 
		} 
		?>
		</p>
<?PHP } ?>		
</form>
	
<?PHP if ($td <> "add") 
{
	if ($int_datefinf == "")
	{
?>
	  <script type="text/javascript">
		Calendar.setup({
			inputField     :    "dateddef",     // id of the input field
			ifFormat       :    "%d-%m-%Y",      // format of the input field
			button         :    "f_img_dateddef",  // trigger for the calendar (button ID)
			align          :    "Ll",           // alignment (defaults to "Bl")
			singleClick    :    true
		});
		Calendar.setup({
			inputField     :    "daterdvf",     // id of the input field
			ifFormat       :    "%d-%m-%Y",      // format of the input field
			button         :    "f_img_daterdvf",  // trigger for the calendar (button ID)
			align          :    "Ll",           // alignment (defaults to "Bl")
			singleClick    :    true
		});
		Calendar.setup({
			inputField     :    "dateprevf",     // id of the input field
			ifFormat       :    "%d-%m-%Y",      // format of the input field
			button         :    "f_img_dateprevf",  // trigger for the calendar (button ID)
			align          :    "Ll",           // alignment (defaults to "Bl")
			singleClick    :    true
		});
		Calendar.setup({
			inputField     :    "datefinf",     // id of the input field
			ifFormat       :    "%d-%m-%Y",      // format of the input field
			button         :    "f_img_datefinf",  // trigger for the calendar (button ID)
			align          :    "Ll",           // alignment (defaults to "Bl")
			singleClick    :    true
		});
	</script>
<?PHP 
	}
	
	if ($td <> "del")
	{
?>
    
<script>
// form fields description structure
var a_fields = {
	'dateddef':{'l':'Date Demande','r':true,'f':'date','t':'f_dateddef'},
	'codeage':{'l':'Agence','r':true,'t':'f_agence'},
	'codecli':{'l':'Client','r':true,'t':'f_codecli'},
	'codeorig':{'l':'Origine','r':true,'t':'f_orig'},
	'codestatut':{'l':'Statut','r':true,'t':'f_statut'},
	'codelieu':{'l':'Lieu','r':true,'t':'f_lieu'},
	'hrdv':{'l':'Heure Rendez-vous','r':false,'f':'time','t':'f_rdv'},
	'mat':{'l':'Matériel','r':true,'t':'f_mat'},
	'login':{'l':'Login','r':false,'t':'f_login','mx':20},
	'mdpsys':{'l':'MDP systèmes','r':false,'t':'f_login','mx':20},
	'mdpbios':{'l':'MDP Bios','r':false,'t':'f_mdpbios','mx':20},
	'pbm':{'l':'Descriptif Problème','r':true,'t':'f_pbm'},
	'acpte':{'l':'Acompte','r':false,'f':'real','t':'f_acpte','mx':10},
},

o_config = {
	'to_disable' : ['enr', 'RAZ'],
	'alert' : 1
}

// validator constructor call
var v = new validator('int_maj', a_fields, o_config);
</script>
<?PHP
	}
} 
else 
{ 
?>
  <script type="text/javascript">
	Calendar.setup({
		inputField     :    "dateddef",     // id of the input field
		ifFormat       :    "%d-%m-%Y",      // format of the input field
		button         :    "f_img_dateddef",  // trigger for the calendar (button ID)
		align          :    "Ll",           // alignment (defaults to "Bl")
		singleClick    :    true
	});
	Calendar.setup({
		inputField     :    "daterdvf",     // id of the input field
		ifFormat       :    "%d-%m-%Y",      // format of the input field
		button         :    "f_img_daterdvf",  // trigger for the calendar (button ID)
		align          :    "Ll",           // alignment (defaults to "Bl")
		singleClick    :    true
	});
</script>
    
<script>
// form fields description structure
var a_fields = {
	'dateddef':{'l':'Date Demande','r':true,'f':'date','t':'f_dateddef'},
	'codeage':{'l':'Agence','r':true,'t':'f_agence'},
	'codecli':{'l':'Client','r':true,'t':'f_codecli'},
	'codeorig':{'l':'Origine','r':true,'t':'f_orig'},
	'codestatut':{'l':'Statut','r':true,'t':'f_statut'},
	'codelieu':{'l':'Lieu','r':true,'t':'f_lieu'},
	'hrdv':{'l':'Heure Rendez-vous','r':false,'f':'time','t':'f_rdv'},
	'mat':{'l':'Matériel','r':true,'t':'f_mat'},
	'login':{'l':'Login','r':false,'t':'f_login','mx':20},
	'mdpsys':{'l':'MDP systèmes','r':false,'t':'f_login','mx':20},
	'mdpbios':{'l':'MDP Bios','r':false,'t':'f_mdpbios','mx':20},
	'pbm':{'l':'Descriptif Problème','r':true,'t':'f_pbm'}
},

o_config = {
	'to_disable' : ['enr', 'RAZ'],
	'alert' : 1
}

// validator constructor call
var v = new validator('int_maj', a_fields, o_config);
</script>
<?PHP 
} 
?>

<?PHP if ($td == "add") 
{
?>
	<script type="text/javascript">
	warnnbage(<?PHP echo nb_age_actives(); ?>,"interv");
	warnnbcli(<?PHP echo nb_cli(""); ?>,"interv");
	warnnbtec(<?PHP echo nb_tec_actifs() ?>);
	warnedit(<?PHP echo $cli_cpta; ?>,"interv");
	</script>
<?PHP
}
else
{
	if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut tester le statut comptable
	{
?>
		<script type="text/javascript">
		warnedit(<?PHP echo $cli_cpta; ?>,"interv");
		</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?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de choisir un client...</p>
<?PHP
}
?>
<!-- Affiché uniquement s'il y a au moins un client, une agence active, une origine, un statut, un lieu, une civilité, un technicien dans l'agence, et un mode de règlement -->
<?PHP
}
else
{
	if (nb_cli("") == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('cli_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins un client...</p>
<?PHP
	}

	if (nb_age_actives() == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('age_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Il faut au moins une agence active ...</p>
<?PHP
	}

	if (nb_orig() == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('orig_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Il faut au moins une origine pour la demande d'intervention ...</p>
<?PHP
	}
	
	if (nb_statuts() == 0) 
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('statut_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Il faut au moins un statut pour la demande d'intervention ...</p>
<?PHP
	}

	if (nb_lieux() == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('statut_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Il faut au moins un lieu pour la demande d'intervention ...</p>
<?PHP
	}
	
	if (nb_civ() == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('civ_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins une civilit&eacute;...</p>
<?PHP
	}

	if (nb_tec("") == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('tec_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins un technicien...</p>
<?PHP
	}

	if (nb_reg() == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('reg_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins un mode de r&egrave;glement...</p>
    <?PHP
	}
}
}
else
{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('int_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de choisir une de vos interventions...</p>
<?PHP
 }
?>
