<?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");

include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/lst.inc.php");
Archivelog(@$_SESSION["code_log"]);

if (isset($_GET['ci']))
	$codeint = strip_tags(trim(@$_GET['ci']));
else
	$codeint = strip_tags(trim(@$_POST['ci']));
if (isset($_GET['td']))
	$td = strip_tags(trim(@$_GET['td']));
else
	$td = strip_tags(trim(@$_POST['td']));
$id = strip_tags(trim(@$_GET['id']));
if (isset($_GET['cc']))
	$cc = strip_tags(trim(@$_GET['cc']));
else
	$cc = strip_tags(trim(@$_POST['cc']));
if (isset($_GET['co']))
	$co = strip_tags(trim(@$_GET['co']));
else
	$co = strip_tags(trim(@$_POST['co']));
if (isset($_GET['ca']))
	$ca = strip_tags(trim(@$_GET['ca']));
else
	$ca = strip_tags(trim(@$_POST['ca']));
if (isset($_GET['si']))
	$si = strip_tags(trim(@$_GET['si']));
else
	$si = strip_tags(trim(@$_POST['si']));
if (isset($_GET['cas']))
	$cas = strip_tags(trim(@$_GET['cas']));
else
	$cas = strip_tags(trim(@$_POST['cas']));
if (isset($_GET['drdv']))
	$drdv = strip_tags(trim(@$_GET['drdv']));
else
	$drdv = strip_tags(trim(@$_POST['drdv']));
if (isset($_GET['tr']))
	$tecr = strip_tags(trim(@$_GET['tr']));
else
	$tecr = strip_tags(trim(@$_POST['tr']));

$pbm_inth = FALSE;
$pbm_enr_inth = FALSE;
$msg="";
$inth_codeint="-1";

if ($codeint <> "")
{
	$row = lit_enr_int($codeint);
	if (is_array($row))
		extract($row);
	else
		$pbm_inth=TRUE;

	// Si pas d'enregistrement de détail horaire, on ne peut que ajouter
	if (nb_inth($codeint)==0)
		$td = "add";
		
	// Si intervention close ou si client/donneurs d'ordres, on ne peut que voir
	if ((formatedate($int_datefin) <> "") OR (@$_SESSION["niv_log"] == 1) OR (@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 6))
		$td = "view";

	// Vérification tentative de hack d'une agence
	if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($ca <> @$_SESSION["code_age"]) AND ($cas <> @$_SESSION["code_age"]))
		$pbm_inth = TRUE;

	// Vérification tentative de hack d'un donneur d'ordres
	if (((@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 6)) AND ($int_codedo <> @$_SESSION["code_do"]))
		$pbm_inth = TRUE;
}
else
	$pbm_inth=TRUE;

if (($ca <> "") AND ($cas<>""))
{
	$row = lit_enr_age($ca,TRUE);
	if (is_array($row))
		extract($row);
	else
		$pbm_inth=TRUE;

	$row = lit_enr_age($cas,TRUE);
	if (is_array($row))
		extract($row);
	else
	{
		if ($cas<>"-1")
			$pbm_inth=TRUE;
	}

	// Vérification tentative de hack d'une agence
	if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($ca <> @$_SESSION["code_age"]) AND ($cas <> @$_SESSION["code_age"]))
		$pbm_inth = TRUE;
}
else
	$pbm_inth=TRUE;

if ($pbm_inth == FALSE)
{
	if ($id=="")
		$id = strip_tags(trim(@$_POST["id"]));

	if (((strip_tags(trim(@$_POST["enr"])) == html_entity_decode($but_add)) OR (strip_tags(trim(@$_POST["enr"])) == html_entity_decode($but_modif))))
	{
		$datesais = strip_tags(trim(@$_POST["date"]));
		if ($datesais <> "")
			$date = datefrang($datesais);
		else
			$date ="";
		$codetec = strip_tags(trim(@$_POST["codetec"]));
		$codelieu = strip_tags(trim(@$_POST["codelieu"]));
		$heurea = strip_tags(trim(@$_POST["heurea"]));
		$heurea_full = $heurea.":00";
		$heured = strip_tags(trim(@$_POST["heured"]));
		$heured_full = $heured.":00";
		$indice=strip_tags(trim(@$_POST["ind"]));
		$offert = 0;
		if (strtolower(strip_tags(trim(@$_POST["offert"]))) == "on")
			$offert = 1;
		$acodemt = strip_tags(trim(@$_POST["a_mt"]));
		$aheured = strip_tags(trim(@$_POST["a_heured"]));
		if ($aheured=="")
			$aheured="00:00";
		$aheured_full = $aheured.":00";
		$aheuref = strip_tags(trim(@$_POST["a_heuref"]));
		if ($aheuref=="")
			$aheuref="00:00";
		$aheuref_full = $aheuref.":00";
		$akm = strip_tags(trim(@$_POST["a_km"]));
		$acd = strip_tags(trim(@$_POST["a_cd"]));
		$afa = strip_tags(trim(@$_POST["a_fa"]));
		$afad = strip_tags(trim(@$_POST["a_fad"]));
		$rcodemt = strip_tags(trim(@$_POST["r_mt"]));
		$rheured = strip_tags(trim(@$_POST["r_heured"]));
		if ($rheured=="")
			$rheured="00:00";
		$rheured_full = $rheured.":00";
		$rheuref = strip_tags(trim(@$_POST["r_heuref"]));
		if ($rheuref=="")
			$rheuref="00:00";
		$rheuref_full = $rheuref.":00";
		$rkm = strip_tags(trim(@$_POST["r_km"]));
		$rcd = strip_tags(trim(@$_POST["r_cd"]));
		$rfa = strip_tags(trim(@$_POST["r_fa"]));
		$rfad = strip_tags(trim(@$_POST["r_fad"]));
		$codeuser = @$_SESSION["code_log"];

		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		if (strip_tags(trim(@$_POST["enr"])) == html_entity_decode($but_add))
		{
			$rech = "INSERT INTO " .TBINTH;
			$rech.= " (inth_datecrea,inth_codecrea,inth_datemod,inth_codemod,inth_codeint,inth_date,inth_codetec,inth_codelieu,";
			$rech.= "inth_heurea,inth_heured,inth_codeind,inth_offert,inth_acodemt,inth_aheured,inth_aheuref,inth_akm,inth_acd,inth_afrais,";
			$rech.= "inth_afraisd,inth_rcodemt,inth_rheured,inth_rheuref,inth_rkm,inth_rcd,inth_rfrais,inth_rfraisd) VALUES";
			$rech.= " ('$datea','$codeuser','$datea','$codeuser','$codeint','$date','$codetec','$codelieu','$heurea_full','$heured_full','$indice',";
			$rech.= "'$offert','$acodemt','$aheured_full','$aheuref_full','$akm','$acd','$afa','$afad','$rcodemt','$rheured_full',";
			$rech.= "'$rheuref_full','$rkm','$rcd','$rfa','$rfad')";
		}
		if (strip_tags(trim(@$_POST["enr"])) == html_entity_decode($but_modif))
		{
			if ($id <> "")
			{
				$rech ="UPDATE `" .TBINTH;
				$rech.="` SET `inth_datemod`='".$datea."',`inth_codemod`='".$codeuser."', `inth_date`='".$date."',";
				$rech.=" `inth_codetec`='".$codetec."', `inth_codelieu`='".$codelieu."', `inth_heurea`='".$heurea_full."',";
				$rech.=" `inth_heured`='".$heured_full."', `inth_offert`='".$offert."',";
				$rech.=" `inth_acodemt`='".$acodemt."',`inth_aheured`='".$aheured_full."', `inth_codeind`='".$indice."',";
				$rechh.= "`inth_aheuref`='".$aheuref_full."',";
				$rech.=" `inth_akm`='".$akm."',`inth_acd`='".$acd."', `inth_afrais`='".$afa."', `inth_afraisd`='".$afad."',";
				$rech.=" `inth_rcodemt`='".$rcodemt."',`inth_rheured`='".$rheured_full."', `inth_rheuref`='".$rheuref_full."',";
				$rech.=" `inth_rkm`='".$rkm."',`inth_rcd`='".$rcd."', `inth_rfrais`='".$rfa."', `inth_rfraisd`='".$rfad."'";
				$rech.="  WHERE `inth_id` = '".$id."'";
			}
		}
		$rs = mysql_query($rech) or die(mysql_error());
		mysql_close($conn);
		$td ="add";
	}
	else
	{
		if (strip_tags(trim(@$_POST["enr"])) == html_entity_decode($but_del))
		{
			if ($id <> "")
			{
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rech = "DELETE FROM `" .TBINTH. "` WHERE `inth_id` = '$id'";
				$rs = mysql_query($rech) or die(mysql_error());
				mysql_close($conn);
			}
			$td ="add";
		}
	}
}

if ($pbm_inth == FALSE)
{
	if (($td == "edit") OR ($td == "view") OR ($td == "del"))
	{
		if ($id <> "")
		{
			$row = lit_enr_inth($id);
			if (is_array($row))
			{
				extract($row);
				$inth_heurea=substr($inth_heurea,0,5);
				$inth_heured=substr($inth_heured,0,5);
				$inth_aheured=substr($inth_aheured,0,5);
				$inth_aheuref=substr($inth_aheuref,0,5);
				$inth_rheured=substr($inth_rheured,0,5);
				$inth_rheuref=substr($inth_rheuref,0,5);
			}	
			$datesais = datefr($inth_date);	
		}
	}

	// Récupération du total travaillé & Techniciens traitants
	$nbtotalsec = 0;
	$nbtotalsecoff = 0;
	$str_tec_traitants = "";
	if (($td == "add") OR ($td == "edit") OR ($td == "view") OR ($td == "del"))
	{
		$nbtotalsec=tps_travaille_int($codeint,TRUE);
		$nbtotalsecoff=tps_offert_int($codeint,TRUE);
		$str_tec_traitants=str_tec_traitants_int($codeint,TRUE);
	}	
}
switch ($td)
{
	case "add" :
		$titre = "Ajouter Détail horaire";
		break;
	case "edit" :
		$titre = "Editer Détail horaire";
		break;
	case "del" :
		$titre = "Supprimer Détail horaire";
		break;
	case "view" :
		$titre = "Voir Détail horaire";
		break;
	default :
		$pbm_dosd=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; ?> : D&eacute;tail Horaire Intervention</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../css/smi.css" rel="stylesheet" type="text/css">

<!-- Scripts Javascript pour fenêtres -->
<script language="JavaScript" src="../jscript/fen.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>

<?PHP if (($td<>"del") AND ($td<>"view")) { ?>
<script language="javascript">
<!--
var tab1_champ=new Array(
	"nom:date ; format:date ; masque:<?PHP echo $datemsql; ?> ; vmn : <?PHP if (trim($drdv)<>"") echo $drdv; else echo formatedate($int_datedde); ?> ; req:Y ; txt:Date ; stok:frmok ; stbad:frmbad",
	"nom:codetec ; format:liste ; req:Y ; txt:Technicien ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:codelieu ; format:liste ; req:Y ; txt:Lieu ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:heurea ; format:liste ; req:Y ; txt:Heure de début ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:heured ; format:liste ; req:Y ; txt:Heure de fin ; vmn:1 ; stok:frmok ; stbad:frmbad");
//-->
</script>
<?PHP } ?>

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

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

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

</head>

<?PHP 
if ($td <> "edit")
{
	if ($pbm_inth == FALSE)
		echo '<body onLoad="javascript:; window.focus();">';
	else
		echo '<body>';
}
else
	echo "<body onLoad=\"javascript:; window.focus();verif_lieu(document.inth_maj.codelieu.value);verif_fa('a');verif_fa('r');metFocus();\">";

if (($pbm_inth == FALSE) AND ($pbm_enr_inth == FALSE))
{
	// On enregistre les codes obligatoires
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	// ->Code du contrat en cours (historique contrat)
	$rech = "SELECT * FROM " .TBCOCLH. " WHERE `coclh_codeint` = '$codeint'";
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) == 1)
	{
		$rech2 = "UPDATE `" .TBCOCLH. "` SET `coclh_codecocl`='".$co."'";
		$rech2 .=" WHERE `coclh_codeint` = '".$codeint."'";
	}
	else
	{
		$rech2 = "INSERT INTO " .TBCOCLH;
		$rech2.=" (coclh_codecli,coclh_codecocl,coclh_codeint)";
		$rech2.=" VALUES";
		$rech2.=" ('$cc','$co','$codeint')";
	}
	$rs2 = mysql_query($rech2) or die(mysql_error());
	mysql_free_result($rs);
	// ->code agence gestionnaire du compte
	// ->code technicien responsable de l'intervention
	// ->id du site d'intervention
	// ->Code du contrat en cours
	$rech = "UPDATE `" .TBINT. "` SET `int_datemod`='".$datea."', `int_codemod`='".$_SESSION["code_log"]."',";
	$rech.= " `int_codeage`='".$ca."', `int_codetec`='".$tecr."', `int_idsite`= '".$si."', `int_codecocl`= '".$co."'";
	$rech .=" WHERE `int_code` = '".$codeint."'";
	$rs = mysql_query($rech) or die(mysql_error());
	mysql_close($conn);
?>
<p align="center"> <span class="titrepage">DETAIL HORAIRE</span></p>
<p align="center"><span class="titre_gras">Pour l'intervention : <?php echo $codeint; ?></span>
<?PHP
if (($td=="add") AND (($_SESSION["niv_log"]==3) OR ($_SESSION["niv_log"]==4) OR ($_SESSION["niv_log"]==5) OR ($_SESSION["niv_log"]==9)))
	echo '<br /><span class="annot_petit_it">D&egrave;s que vous aurez saisi un d&eacute;tail, il ne sera plus possible de changer de site</span>';
?>
</p>
<div align="right">
<input name="quit" type="button" class="bton_std" id="quit" value="<?PHP echo $but_quit; ?>" style="text-decoration: none; font-size: 11px; color:White ;font-weight:bold;background-color: #666666;" onClick="javascript:; self.close('fscomp');">
</div>
<br />
<?PHP
$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);
$rech = "SELECT * FROM `" .TBINTH. "` WHERE `inth_codeint`= '".$codeint."' ORDER BY inth_date, inth_heurea";
$rs = mysql_query($rech) or die(mysql_error());

if (mysql_num_rows($rs) <> 0)
{
	echo "<table class=\"MtableD\" border=\"0\" width=\"890\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";
	 
	// Création de l'entête de la table "détail intervention"
	echo "<th>";
	echo "Date";
	echo "</th>\n";
	echo "<th>";
	echo "Technicien";
	echo "</th>\n";
	echo "<th>";
	echo "Lieu";
	echo "</th>\n";
	echo "<th>";
	echo "Heure début";
	echo "</th>\n";
	echo "<th>";
	echo "Heure fin";
	echo "</th>\n";
	echo "<th>";
	echo "Temps passé";
	echo "</th>\n";
	echo "<th>";
	echo "Indice";
	echo "</th>\n";
	echo "<th>";
	echo "Temps retenu";
	echo "</th>\n";
	echo "<th>";
	echo "Offert ?";
	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["inth_date"]);
		echo "<td>\n";
		echo $row["inth_codetec"];
		// Récupération et affichage détail technicien
		$rech2 = "SELECT * FROM `" .TBTEC. "` WHERE `tec_code`= '".$row["inth_codetec"]."'";
		$rs2 = mysql_query($rech2) or die(mysql_error());
		if (mysql_num_rows($rs2) <> 0)
		{
			if ($row2 = mysql_fetch_assoc($rs2)) 
			{
				extract($row2);
				echo "<br>";
				echo "<span class=\"annot_petit_it\">";
				echo $tec_nom." ".$tec_prenom." (".$tec_codeage.")";
				echo "</span>";
			}
		}
		else
			echo "&nbsp;";
		echo "</td>\n";
		echo "</td>\n";
		echo "<td align=\"center\">\n";
		// Récupération et affichage libellé lieu
		$rech2 = "SELECT * FROM `" .TBLIEU. "` WHERE `lieu_code`= '".$row["inth_codelieu"]."'";
		$rs2 = mysql_query($rech2) or die(mysql_error());
		if (mysql_num_rows($rs2) <> 0)
		{
			if ($row2 = mysql_fetch_assoc($rs2)) 
			{
				extract($row2);
				echo $lieu_desc;
			}
		}
		else
			echo "&nbsp;";
		echo "</td>\n";
		echo "<td align=\"center\">\n";
		echo substr($row["inth_heurea"],0,5);
		echo "</td>\n";
		echo "<td align=\"center\">\n";
		echo substr($row["inth_heured"],0,5);
		echo "</td>\n";
		$tpsreelsec=diff_time_sec($row["inth_heurea"],$row["inth_heured"]);
		echo "<td align=\"center\">\n";
		echo heure_to_hhmm(sec_heure($tpsreelsec));
		echo "</td>\n";
		echo "<td align=\"center\">\n";
		$ind_coeff=1;
		if ($row["inth_codeind"]=="-1")
			echo "-";
		else
		{
			echo $row["inth_codeind"];
			$row2=lit_enr_ind($row["inth_codeind"],FALSE);
			if (is_array($row2))
			{
				extract($row2);
				echo " <a href=\"#\" class=\"popi\"><img src=\"../img/help.png\" alt=\"D&eacute;tail\" border=\"0\" align=\"absmiddle\"><span>".$ind_desc." (coefficient ".$ind_coeff.")</span></a>";
			}
		}
		echo "</td>\n";
		echo "<td align=\"center\">\n";
		echo heure_to_hhmm(sec_heure($tpsreelsec*$ind_coeff));
		echo "</td>\n";
		echo "<td align=\"center\">\n";
		echo $non_oui2[$row["inth_offert"]];
		echo "</td>\n";
		echo "<td align=\"center\">\n";
		if ($td <> "view")
		{
			switch ($_SESSION["niv_log"])
			{
				case 3 :
					if (($tec_code==$_SESSION["code_log"]) OR ($tecr==$_SESSION["code_log"]))
					{
						$lst_maj = TRUE;
						echo "<a href=\"inth_maj.php?td=edit&ci=".$codeint."&id=".$row["inth_id"]."&cc=".$cc."&co=".$co."&ca=".$ca."&cas=".$cas."&drdv=".$drdv."&si=".$si."&tr=".$tecr."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\"></a>";
						echo " ";
			
						$lst_del = TRUE;
						echo "<a href=\"inth_maj.php?td=del&ci=".$codeint."&id=".$row["inth_id"]."&cc=".$cc."&co=".$co."&ca=".$ca."&cas=".$cas."&drdv=".$drdv."&si=".$si."&tr=".$tecr."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\"></a>";
					}
					break;
				case 4 :
					if ($tec_codeage==$_SESSION["code_age"])
					{
						$lst_maj = TRUE;
						echo "<a href=\"inth_maj.php?td=edit&ci=".$codeint."&id=".$row["inth_id"]."&cc=".$cc."&co=".$co."&ca=".$ca."&cas=".$cas."&drdv=".$drdv."&si=".$si."&tr=".$tecr."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\"></a>";
						echo " ";
			
						$lst_del = TRUE;
						echo "<a href=\"inth_maj.php?td=del&ci=".$codeint."&id=".$row["inth_id"]."&cc=".$cc."&co=".$co."&ca=".$ca."&cas=".$cas."&drdv=".$drdv."&si=".$si."&tr=".$tecr."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\"></a>";
					}
					break;
				default :
					$lst_maj = TRUE;
					echo "<a href=\"inth_maj.php?td=edit&ci=".$codeint."&id=".$row["inth_id"]."&cc=".$cc."&co=".$co."&ca=".$ca."&cas=".$cas."&drdv=".$drdv."&si=".$si."&tr=".$tecr."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\"></a>";
					echo " ";
		
					$lst_del = TRUE;
					echo "<a href=\"inth_maj.php?td=del&ci=".$codeint."&id=".$row["inth_id"]."&cc=".$cc."&co=".$co."&ca=".$ca."&cas=".$cas."&drdv=".$drdv."&si=".$si."&tr=".$tecr."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\"></a>";
					break;
			}
		}
		else
			echo "-";
		echo "</td>\n";

		echo "</tr>\n";
	
		$j++;
	}
	
	/* Totaux */
	
	// Total Général

	// Création de l'entête de ligne (TR)
	creetrlstdet($j);

	echo "<td colspan=\"7\" align=\"right\">";
	echo "<span class=\"annot_std_gras\">";
	echo "Temps total : ";
	echo "</span>";
	echo "</td>\n";
	echo "<td align=\"center\">";
	echo "<span class=\"annot_std_gras\">";
	echo heure_to_hhmm(sec_heure($nbtotalsec,3,TRUE));
	$du=heure_to_hhmm(sec_heure($nbtotalsec,3,TRUE));
	echo "</span>";
	echo "</td>\n";
	echo "<td colspan=\"2\">";
	echo "&nbsp;";
	echo "</td>\n";

	// Temps offert

	// Création de l'entête de ligne (TR)
	$j++;
	creetrlstdet($j);

	echo "<td colspan=\"7\" align=\"right\">";
	echo "<span class=\"annot_std_gras\">";
	echo "Temps offert : ";
	echo "</span>";
	echo "</td>\n";
	echo "<td align=\"center\">";
	if ($nbtotalsecoff <> 0)
	{
		echo "<span class=\"annot_std_gras\">";
		echo heure_to_hhmm(sec_heure($nbtotalsecoff,3,TRUE));
		$duo=heure_to_hhmm(sec_heure($nbtotalsecoff,3,TRUE));
		echo "</span>";
	}
	else
	{
		echo "-";
		$duo="00:00";
	}
	echo "</td>\n";
	echo "<td colspan=\"2\">";
	echo "&nbsp;";
	echo "</td>\n";

	// Temps retenu

	// Création de l'entête de ligne (TR)
	$j++;
	creetrlstdet($j);

	echo "</td>\n";
	echo "<td colspan=\"7\" align=\"right\">";
	echo "<span class=\"annot_std_gras\">";
	echo "Temps retenu : ";
	echo "</span>";
	echo "</td>\n";
	echo "<td align=\"center\">";
	echo "<span class=\"annot_std_gras\">";
	echo heure_to_hhmm(sec_heure($nbtotalsec-$nbtotalsecoff,3,TRUE));
	echo "</span>";
	echo "</td>\n";
	echo "<td colspan=\"2\">";
	echo "&nbsp;";
	echo "</td>\n";

	echo "</table>\n";
	// Fin affichage table détail horaire
	
	$pas_horaire=FALSE;
}
else
{
	$pas_horaire=TRUE;
	echo '<p class="annot_petit_it">Aucun d&eacute;tail horaire enregistr&eacute; </p>';
}
mysql_free_result($rs);
mysql_close($conn);

$taille_piedla="";
include_once("piedla.inc.php"); 

cre_js_coded($td,$cc,$co,$du,$duo,"window.opener.");

if ($td <> "view")
{
?>
	<br>
	<form name="inth_maj" class="form_pointilles" method="post" action="inth_maj.php" <?PHP if (($td<>"del") AND ($td<>"view")) { ?>onSubmit="javascript:; return (verif_inth(this,tab1_champ,'',''));"<?PHP }?>>
	<p align="center" class="annot_std_gras"><?PHP echo $titre; ?></p>
	<p align="center" class="annot_petit_it">Tous les champs sont obligatoires</p>
		<input name="td" type="hidden" id="td" value="<?PHP echo $td; ?>">
		<input name="ci" type="hidden" id="ci" value="<?PHP echo $codeint; ?>">
		<input name="id" type="hidden" id="id" value="<?PHP echo $id; ?>">
		<input name="cc" type="hidden" id="cc" value="<?PHP echo $cc; ?>">
		<input name="co" type="hidden" id="co" value="<?PHP echo $co; ?>">
		<input name="si" type="hidden" id="si" value="<?PHP echo $si; ?>">
		<input name="ca" type="hidden" id="ca" value="<?PHP echo $ca; ?>">
		<input name="cas" type="hidden" id="cas" value="<?PHP echo $cas; ?>">
		<input name="drdv" type="hidden" id="drdv" value="<?PHP echo $drdv; ?>">
		<input name="tr" type="hidden" id="tr" value="<?PHP echo $tecr; ?>">
		<table width="580"  border="0" align="center">
			<tr>
				<td width="20%" class="rubfrm" id="f_date" align="right">
					Date
				</td>
				<td align="left">
					<input name="date" type="text" id="date" value="<?PHP echo $datesais; ?>" size="10" maxlength="10" readonly="1">
					<img src="../img/calendar.png" align="absmiddle" id="f_img_date" title="<?PHP echo $alt_chxdate; ?>">
					<a href="javascript:;" onclick="document.inth_maj.date.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
					<div class="annot_petit_it">
					Au moins le 
					<?PHP 
					if (trim($drdv)<>"") 
						echo $drdv."(date du rendez-vous)";
					else 
						echo formatedate($int_datedde)."(date de cr&eacute;ation)";
					?>
					</div>
				</td>
			</tr>
			<tr>
				<td class="rubfrm" id="f_tec" align="right">Technicien</td>
				<td>
				<?PHP
					// Création de la liste des Techniciens
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					$rech = "SELECT int_codeage, int_idsite FROM ".TBINT." WHERE `int_code` =  '".$codeint."'";
					$rs = mysql_query($rech) or die(mysql_error());
					
					if (mysql_num_rows($rs) >0)
					{
						if ($row = mysql_fetch_array($rs)) 
						{
							extract($row);
							switch ($_SESSION["niv_log"])
							{
								case 3 :
									if ($tecr==$_SESSION["code_log"])
										$rech2 = "SELECT * FROM ".TBTEC." WHERE `tec_codeage` = '".$_SESSION["code_age"]."'";
									else
										$rech2 = "SELECT * FROM ".TBTEC." WHERE `tec_code` = '".$_SESSION["code_log"]."'";
									break;
								case 4 :
									$rech2 = "SELECT * FROM ".TBTEC." WHERE `tec_codeage` = '".$_SESSION["code_age"]."'";
									break;
								default :
									$rech2 = "SELECT * FROM ".TBTEC." WHERE ";
									
									if (($cas<>"-1") AND ($cas<>"$ca"))
										$rech2.="(";
									$rech2.= "`tec_codeage` = '".$ca."'";
									if (($cas<>"-1") AND ($cas<>"$ca"))
										$rech2.= " OR `tec_codeage` = '".$cas."')";
									break;
							}
							$rech2.=" AND `tec_out` = 0 ORDER BY tec_nom";
							$rs2 = mysql_query($rech2) or die(mysql_error());
					
							if (mysql_num_rows($rs2) >0)
							{
							?>
								<select name="codetec" id="codetec">
							<?PHP
								echo "<option value=\"\">".$sel_lst_tec."</option>";
						
								while ($resultat = mysql_fetch_array($rs2)) 
								{
									extract($resultat);
									$txt_tec = $tec_nom." ".$tec_prenom." (".$tec_codeage.")";
									echo '<option value="'.$tec_code.'"';
									if ($inth_codetec == $tec_code)
										echo ' selected';
										echo '>'.$txt_tec.'</option>';
								}
							?>
								</select>
							<?PHP
							}
							else
							{
							?>
								<select name="codetec" id="codetec">
								<option>-- Pas de technicien actif sur cette agence --</option>
								</select>
							<?PHP
							}
						}
					}
					mysql_free_result($rs);
					mysql_close($conn);
				?>
				</td>
			</tr>
			<tr>
				<td class="rubfrm" id="f_lieu" align="right">
					Lieu
				</td>
				<td align="left">
				<?PHP
				// Création de la liste cachée des lieux 
				// pour savoir si déplacement = "_"+codelieu
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rech = "SELECT * FROM ".TBLIEU;
				$rs = mysql_query($rech) or die(mysql_error());
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					echo '<input name="_'.$lieu_code.'" type="hidden" id="_'.$lieu_code.'" value="'.$lieu_depl.'">';
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
				<select name="codelieu" id="codelieu" onChange="verif_lieu(this.value);">
				<?PHP
					echo "<option>-- Choisissez un lieu --</option>";

					// Création de la liste des Lieux
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					$rech = "SELECT * FROM ".TBLIEU." ORDER BY lieu_desc";
					$rs = mysql_query($rech) or die(mysql_error());
			
					while ($resultat = mysql_fetch_array($rs)) 
					{
						extract($resultat);
						if ($inth_codelieu == $lieu_code)
							echo '<option value="'.$lieu_code.'" selected>'.$lieu_desc.'</option>';
						else
							echo '<option value="'.$lieu_code.'">'.$lieu_desc.'</option>';
					}
					mysql_free_result($rs);
					mysql_close($conn);
				?>
				  </select>
				</td>
			</tr>
			<tr>
				<td class="rubfrm" id="f_horaires" align="right">
					Horaires
				</td>
				<td align="left">
					 D&eacute;but 
					<select name="heurea" id="heurea">
					<?PHP
					if ($inth_heurea=="00:00:00")
						echo "<option value=\"\" selected></option>";
					else
						echo "<option value=\"\"></option>";
					
					// Création de la liste des heures
					for ($i=0; $i<86400 ;$i+=300)
					{
						$heure=heure_to_hhmm(sec_heure($i));
	
						if ($inth_heurea == $heure)
							echo '<option value="'.$heure.'" selected>'.$heure.'</option>';
						else
							echo '<option value="'.$heure.'">'.$heure.'</option>';
					}
					?>
					</select>
					<a href="javascript:;" onclick="document.inth_maj.heurea.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
					/ Fin 
					<select name="heured" id="heured">
					<?PHP
					if ($inth_heured=="00:00:00")
						echo "<option value=\"\" selected></option>";
					else
						echo "<option value=\"\"></option>";
					
					// Création de la liste des heures
					for ($i=0; $i<86400 ;$i+=300)
					{
						$heure=heure_to_hhmm(sec_heure($i));
	
						if ($inth_heured == $heure)
							echo '<option value="'.$heure.'" selected>'.$heure.'</option>';
						else
							echo '<option value="'.$heure.'">'.$heure.'</option>';
					}
					?>
					</select>
					<a href="javascript:;" onclick="document.inth_maj.heured.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
				</td>
			</tr>
			<tr>
				<td class="rubfrm" id="f_ind" align="right">Indice</td>
				<td>
				<?PHP
					// Création de la liste des Indices
					echo '<select name="ind" id="ind">';
					echo '<option value="-1"';
					if ($inth_codeind == "-1")
						echo ' selected';
					echo '>Pas d\'indice (coefficient 1)</option>';

					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					$rech = "SELECT ind_code, ind_desc, ind_coeff FROM ".TBIND." WHERE `ind_actif`=1 ORDER BY `ind_desc`";
					$rs = mysql_query($rech) or die(mysql_error());
					
					if (mysql_num_rows($rs) >0)
					{
						while ($resultat = mysql_fetch_array($rs)) 
						{
							extract($resultat);
							echo '<option value="'.$ind_code.'"';
							if ($inth_codeind == $ind_code)
								echo ' selected';
							echo '>'.$ind_desc.' (coefficient'.$ind_coeff.')</option>';
						}
					}
					echo '</select>';
					mysql_free_result($rs);
					mysql_close($conn);
				?>
				</td>
			</tr>
			<tr>
				<td class="rubfrm" id="f_offert" align="right">
					Offert
				</td>
				<td align="left">
				<?PHP if ($inth_offert == 1)
				{
				?>
					<input type="checkbox" name="offert" style="background : #FFFFFF;" checked>
				<?PHP
				}
				else
				{
				?>
					<input type="checkbox" name="offert" style="background : #FFFFFF;">
				<?PHP
				}
				?>
				</td>
			</tr>
		</table>
		<div id="det_depl" style="display:none">
		<p align="center" class="annot_std_gras">D&eacute;tail d&eacute;placement</p>
		<table width="890"  border="0" align="center">
		<tr>
			<td width="20%"></td>
			<td width="40%" class="rubfrm" id="f_aller" align="center" >Aller</td>
			<td class="rubfrm" id="f_retour" align="center">Retour</td>
		</tr>
		<tr>
			<td width="20%" class="rubfrm" id="f_transmt" align="right">Transport</td>
			<td width="40%" align="centerleft">
			<?PHP
			// Création de la liste cachée des moyens de transport
			// pour savoir si coût à saisir = "M_"+codemt
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBMT." WHERE `mt_valid`='1'";
			$rs = mysql_query($rech) or die(mysql_error());
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				echo '<input name="M_'.$mt_code.'" type="hidden" id="M_'.$mt_code.'" value="'.$mt_coutas.'">';
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			<select name="a_mt" id="a_mt">
			<?PHP
			echo "<option value=\"\">-- Moyen de transport --</option>";

			// Création de la liste des moyens de transport
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBMT." WHERE `mt_valid`='1' ORDER BY mt_des";
			$rs = mysql_query($rech) or die(mysql_error());
	
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				echo '<option value="'.$mt_code.'"';
				if ($inth_acodemt==$mt_code)
					echo ' selected';
				echo '>'.$mt_des;
				if ($mt_coutas==1)
					echo ' (AS)';
				echo '</option>';
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			</select>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</td>
			<td align="left">
			<select name="r_mt" id="r_mt">
			<?PHP
			echo "<option value=\"\">-- Moyen de transport --</option>";
			echo '<option value="-1"';
			if ($inth_rcodemt=='-1')
				echo ' selected';
			echo '>Pas de retour agence</option>';

			// Création de la liste des moyens de transport
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBMT." ORDER BY mt_des";
			$rs = mysql_query($rech) or die(mysql_error());
	
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				echo '<option value="'.$mt_code.'"';
				if ($inth_rcodemt==$mt_code)
					echo ' selected';
				echo '>'.$mt_des;
				if ($mt_coutas==1)
					echo ' (AS)';
				echo '</option>';
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			</select>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<div class="annot_petit_it">Pas de retour agence : d&eacute;part direct chez un autre client</div>
			</td>
		</tr>
		<tr>
			<td width="20%" class="rubfrm" id="f_transh" align="right">Horaires</td>
			<td width="40%" align="left">
			De <select name="a_heured" id="a_heured">
			<?PHP
			echo "<option value=\"\"></option>";
			
			// Création de la liste des heures
			for ($i=0; $i<86400 ;$i+=300)
			{
				$heure=heure_to_hhmm(sec_heure($i));
				echo '<option value="'.$heure.'"';
				if ($inth_aheured == $heure)
					echo ' selected';
				echo '>'.$heure.'</option>';
			}
			?>
			</select>
			<a href="javascript:;" onclick="document.inth_maj.a_heured.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
			 &agrave; 
			<select name="a_heuref" id="a_heuref">
			<?PHP
			echo "<option value=\"\"></option>";
			
			// Création de la liste des heures
			for ($i=0; $i<86400 ;$i+=300)
			{
				$heure=heure_to_hhmm(sec_heure($i));
				echo '<option value="'.$heure.'"';
				if ($inth_aheuref == $heure)
					echo ' selected';
				echo '>'.$heure.'</option>';
			}
			?>
			</select>
			<a href="javascript:;" onclick="document.inth_maj.a_heuref.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</td>
			<td align="left">
			De <select name="r_heured" id="r_heured">
			<?PHP
			echo "<option value=\"\"></option>";
			
			// Création de la liste des heures
			for ($i=0; $i<86400 ;$i+=300)
			{
				$heure=heure_to_hhmm(sec_heure($i));
				echo '<option value="'.$heure.'"';
				if ($inth_rheured == $heure)
					echo ' selected';
				echo '>'.$heure.'</option>';
			}
			?>
			</select>
			<a href="javascript:;" onclick="document.inth_maj.r_heured.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
			 &agrave; 
			<select name="r_heuref" id="r_heuref">
			<?PHP
			echo "<option value=\"\"></option>";
			
			// Création de la liste des heures
			for ($i=0; $i<86400 ;$i+=300)
			{
				$heure=heure_to_hhmm(sec_heure($i));
				echo '<option value="'.$heure.'"';
				if ($inth_rheuref == $heure)
					echo ' selected';
				echo '>'.$heure.'</option>';
			}
			?>
			</select>
			<a href="javascript:;" onclick="document.inth_maj.r_heuref.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</td>
		</tr>
		<tr>
			<td width="20%" class="rubfrm" id="f_transkm" align="right">Distance</td>
			<td width="40%" align="left">
			<input name="a_km" type="text" id="a_km" value="<?PHP echo format_num($inth_akm,2); ?>" size="10" onChange="formatedeci(this.id,2);"> km
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</td>
			<td align="left">
			<input name="r_km" type="text" id="r_km" value="<?PHP echo format_num($inth_rkm,2); ?>" size="10" onChange="formatedeci(this.id,2);"> km
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			</td>
		</tr>
		<tr>
			<td width="20%" class="rubfrm" id="f_transcd" align="right">Co&ucirc;t transport</td>
			<td width="40%" align="left">
			<input name="a_cd" type="text" id="a_cd" value="<?PHP echo format_num($inth_acd,2); ?>" size="10" onChange="formatedeci(this.id,2);"> <?PHP echo $lang['symbole_monnaie']; ?>
			<br /><span class="annot_petit_it">Uniquement si co&ucirc;t &agrave; saisir (AS)</span>
			</td>
			<td align="left">
			<input name="r_cd" type="text" id="r_cd" value="<?PHP echo format_num($inth_rcd,2); ?>" size="10" onChange="formatedeci(this.id,2);"> <?PHP echo $lang['symbole_monnaie']; ?>
			<br /><span class="annot_petit_it">Uniquement si co&ucirc;t &agrave; saisir (AS)</span>
			</td>
		</tr>
		<tr>
			<td width="20%" class="rubfrm" id="f_transfa" align="right">Frais annexes</td>
			<td width="40%" align="left">
			<input name="a_fa" type="text" id="a_fa" value="<?PHP echo format_num($inth_afrais,2); ?>" size="10" onChange="formatedeci(this.id,2);verif_fa('a');"> <?PHP echo $lang['symbole_monnaie']; ?>
			<br /><span class="annot_petit_it">Ne pas saisir de co&ucirc;t kilom&eacute;trique suppl&eacute;mentaire car il est automatiquement calcul&eacute;</span>
			</td>
			<td align="left">
			<input name="r_fa" type="text" id="r_fa" value="<?PHP echo format_num($inth_rfrais,2); ?>" size="10" onChange="formatedeci(this.id,2);verif_fa('r');"> <?PHP echo $lang['symbole_monnaie']; ?>
			<br /><span class="annot_petit_it">Ne pas saisir de co&ucirc;t kilom&eacute;trique suppl&eacute;mentaire car il est automatiquement calcul&eacute;</span>
			</td>
		</tr>
		<tr>
			<td width="20%" class="rubfrm" id="f_transfad" align="right">D&eacute;tail frais annexes</td>
			<td width="40%" align="left">
			<textarea name="a_fad" id="a_fad" rows="3" width="100%"><?PHP echo htmlspecialchars($inth_afraisd,ENT_QUOTES); ?></textarea>
			</td>
			<td align="center">
			<textarea name="r_fad" id="r_fad" rows="3" width="100%"><?PHP echo htmlspecialchars($inth_rfraisd,ENT_QUOTES); ?></textarea>
			</td>
		</tr>
		</table>
		</div>
		<p align="center">
		<input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.location.href='inth_maj.php?td=add&ci=<?PHP echo $codeint; ?>&cc=<?PHP echo $cc; ?>&co=<?PHP echo $co; ?>&si=<?PHP echo $si; ?>&ca=<?PHP echo $ca; ?>&cas=<?PHP echo $cas; ?>&drdv=<?PHP echo $drdv; ?>&tr=<?PHP echo $tecr; ?>';">
		<?PHP
			if ($td == "add")
			{
		?>
				<input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_add; ?>">
		<?PHP
			}
			if ($td == "edit")
			{
		?>
				<input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_modif; ?>">
		<?PHP
			}
			if ($td == "del")
			{
		?>
			<input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_del; ?>">
		<?PHP
			}
		?>
		</p>
	</form>
	
	<script type="text/javascript">
	<!--
		Calendar.setup({
			inputField     :    "date",     	// id of the input field
			ifFormat       :    "<?PHP echo $datefmtc; ?>",     // format of the input field
			button         :    "f_img_date",  	// trigger for the calendar (button ID)
			align          :    "Ll",           // alignment (defaults to "Bl")
			electric	   :	false,
			singleClick    :    true
		});
	//-->
	</script>

	<script type="text/javascript">
	<!--
	// On met à jour la liste des contrats possibles
	<?PHP
	$tab_cocl = array();
	// On récupère le nombre de contrats actifs pour ce client
	// dont les dates de début et de fin "encadrent" la date du jour ou de l'intervention
	// (si pas de date de rendez-vous, on prend la date de demande..sinon on prend la date de rendez-vous)
	$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` <= '".datefrang($drdv)."' AND (`cocl_datef` >= '".datefrang($drdv)."' OR `cocl_datef` = '0000-00-00'))";
	$rech.=")";
	$rech.=" ORDER BY cocl_code";
	$rs = mysql_query($rech) or die(mysql_error());
	$nb_cocl=mysql_num_rows($rs);
	
	// Construction du tableau des contrats du site
	if ($nb_cocl>0)
	{
		$tab_cocl[""]="-- Choisissez un contrat --";
	
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			$addok=TRUE;
			if ($si>0)
			{
				$rech2 = "SELECT * FROM " .TBSCLIC. " WHERE sclic_codecocl = '".$cocl_code."' AND sclic_idscli='".$si."'";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if (mysql_num_rows($rs2)==0)
					$addok=FALSE;
			}
			else
			{
				if ($cocl_sitep==FALSE)
					$addok=FALSE;
			}

			if ($addok==TRUE)
			{
				$rech2 = "SELECT * FROM " .TBCO. " WHERE co_code = '".$cocl_codeco."'";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if ($row2 = mysql_fetch_array($rs2))
					extract($row2);
				if ($cocl_delai <> 0)
					$txt_cocl = $cocl_code." - ".$co_nom." (".$cocl_delai."h";
				else
					$txt_cocl = $cocl_code." - ".$co_nom." (Pas de délai";
				if ($cocl_datef<>"0000-00-00")
					$txt_cocl.=", ".$txt_div_ech." ".formatedate($cocl_datef);
				else
					$txt_cocl.=", ".$txt_div_ssech." ";
				$txt_cocl.=")";

				if ($cocl_typh==1)
				{
					// On vérifie s'il y a du temps travaillé pour le contrat, sur cette intervention
					$tpstrav=0;
					$tpstrav=tps_trav_int($cocl_code,$int_code,FALSE);
					
					// On calcule le solde réel du contrat, en ne tenant pas compte du temps, pour cette intervention,
					// déjà utilisé dans ce contrat
					$solde_reel=soldes_reel_contrat($cocl_code,FALSE)+$tpstrav;
					$txt_cocl.=" - solde, hors cette intervention -> ".heure_to_hhmm(sec_heure($solde_reel,3,TRUE));
				}
	
				$tab_cocl[$cocl_code]=$txt_cocl;	
			}
		}
	}
	else
		$tab_cocl[""]="-- Pas de contrat actif sur ce client --";
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	var objet=window.opener.document.getElementById("codecocl");
	var codecocl=objet.value;
	objet.innerHTML="";
	<?PHP
	foreach ($tab_cocl as $key=>$value)
	{
	?>
		option = window.opener.document.createElement("option");
		option.text = "<?PHP echo $value; ?>";
		option.value = "<?PHP echo $key; ?>";
		if (!document.all)
		{
			before= objet.options[1];
		}
		else
		{
		  before=1;
		}
		objet.add(option,before);
	<?PHP
	}
	?>
	objet.value=codecocl;
	// MAJ des reports de contrats
	updatcoded();
	// MAJ des champs de temps
	maj_int('<?PHP echo heure_to_hhmm(sec_heure($nbtotalsec,3,TRUE)); ?>','<?PHP echo heure_to_hhmm(sec_heure($nbtotalsecoff,3,TRUE)); ?>','<?PHP echo $str_tec_traitants; ?>');
	// MAJ des prix de revient
	var objet1 = window.opener.document.getElementById("pxr");
	if (objet1)
	{
		objet1.innerHTML="<?PHP echo format_num(px_revient_int($codeint,TRUE),2); ?>";
	}
	//-->
	</script>
<?PHP
}
}
else
{
	if ($pbm_inth == TRUE)
	{
?>
		<script type="text/javascript">
		<!--
		self.close();
		//-->
		</script>
<?PHP
	}
	if ($pbm_enr_inth == TRUE)
	{
?>
		<p align="center" class="annot_std_it"><?PHP echo $msg; ?></p>
		<script type="text/javascript">
		<!--
		window.setTimeout("location=('inth_maj.php?ci=<?PHP echo $codeint; ?>&td=<?PHP echo $td; ?>&id=<?PHP echo $id; ?>');",3000)
		//-->
		</script>
<?PHP
	}
}
?>
</body>
</html>
