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

Version 0.9.6
Copyright (C) 2006  Sylvain FATOME

This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr
****************************************************************************************/

include ("../inc/config.inc.php");
?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_time.inc.php") ?>
<?php require ("../inc/func_date.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php require ("../inc/func_txt.inc.php") ?>
<?php require ("../inc/fic.inc.php") ?>
<?PHP
	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"] = "";

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

	$pbm_int = FALSE;
	$nbartint = 0;
	$int_idsite = 0;

	if (($td<>"add") AND ($td<>"edit") AND ($td<>"view") AND ($td<>"del"))
			$pbm_int=TRUE;

	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<> "")
	{
		// Récupération des informations contrat
		$row = lit_enr_cocl($co);
		if (is_array($row))
		{
			$int_codecocl=$co;

			extract ($row);

			if ($td <> "add")
			{
				// Contrôle qu'un client n'essaye pas de "hacker" une intervention
				if ((@$HTTP_SESSION_VARS["niv_log"] == 1) AND ($int_codecli <> @$HTTP_SESSION_VARS["code_log"]))
					$pbm_int = TRUE;
				// Contrôle qu'une agence n'essaye pas de "hacker" une intervention
				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;
	}

	if ($ci <> "")
	{
		// 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";

			if ($td <> "add")
			{
				// Contrôle qu'un client n'essaye pas de "hacker" une intervention
				if ((@$HTTP_SESSION_VARS["niv_log"] == 1) AND ($int_codecli <> @$HTTP_SESSION_VARS["code_log"]))
					$pbm_int = TRUE;
	
				// Contrôle qu'une agence n'essaye pas de "hacker" une intervention
				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;
			}

			// 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);
			
			// Récupération heure rdv
			$int_hrdv = substr($int_hrdv,0,5);

			if ($int_datefinf <> "")
				$td = "view";
				
			if ($td == "edit")
			{
				$cc=$int_codecli;
				$ct=$int_codetec;
				$ca=$int_codeage;
			}
	
			if ($td == "add")
			{
				$int_dateddef = $datef;
				$int_code = $ci;
				$int_codecli = $cc;
				$int_codetec = $ct;
				$int_codeage = $ca;
				$int_codereg = "EC";
			}
		
			// 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)) 
					{         
						$nbtotalsec = $nbtotalsec + diff_time_sec($row["inth_heurea"],$row["inth_heured"]);
						if ($row["inth_offert"] == 1)
							$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
			$pbm_int = TRUE;

		
	}
	else
	{
		if (($td=="edit") OR ($td=="view") OR ($td=="del"))
			$pbm_int=TRUE;

		if ($td == "add")
		{
			$int_dateddef = $datef;
			$int_code = crecodesession("I");
			$ci = $int_code;
			$int_codereg= "EC";
			$int_codecocl = $co;
		}

	}

	$pbm_cli=FALSE;
		
	if ($cc <>"")
	{
		$row = lit_enr_cli($cc);
		if (is_array($row))
		{
			$int_codecli = $cc;

			extract ($row);

			// Contrôle qu'une agence n'essaye pas de "hacker" une intervention
			if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
			{
				$row = lit_enr_age($HTTP_SESSION_VARS["code_age"]);
				extract ($row);
				$zc_couverte = $age_zone;
			}
			else
				$zc_couverte = zc_age_actives();

			if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
			{
				if (dep_in_zc($cli_dep,$zc_couverte) == TRUE) 
				{
					if (($cli_prop <> @$HTTP_SESSION_VARS["code_age"]) AND ($cli_prop <> NULL))
					{
						$pbm_cli = TRUE;
					}
				}
				else
				{
					$pbm_cli = TRUE;
				}
			}
			
			$nbsites=nb_scli_actifs($cc);
		}
		else
		{
			$pbm_cli = TRUE;
		}
	}
	else
	{
		if (($td=="edit") OR ($td=="view") OR ($td=="del"))
			$pbm_cli=TRUE;
	}
	
	switch ($td)
	{
		case "add" :
				$titre = "SAISIE INTERVENTION";
			break;
		case "edit" :
				$titre = "MISE A JOUR INTERVENTION";
			break;
		case "view" :
				if (@$HTTP_SESSION_VARS["niv_log"] == 1)
					$titre = "DETAIL INTERVENTION";
				else
					$titre = "VISUALISATION INTERVENTION";
			break;
		case "del":
				$titre = "SUPPRESSION INTERVENTION";
			break;
		default:
				$titre = "PROBLEME";
				$pbm_int=TRUE;
			break;
	}
	
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Fiche Intervention</title>

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

<!-- Feuille de style & Script pour le menu -->
<link href="../inc/menu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="../coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour affichages -->
<script language="JavaScript" src="../inc/aff.js"></script>

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

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

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

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

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

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="../jscal/calendar-setup.js"></script>

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

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

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

<!-- Fonction pour vérifier si résumé contrat doit être affiché -->
<script type="text/javascript">
function tst_res_cocl(index,premier)
{
	if (index>0)
	{
		display('res','block');
		display('pas_res','none');
		display('choixsiteoui','block');
		display('choixsitenon','none');
		if (premier==false)
		{
			if (document.int_maj.nbsites.value==0)
			{
				display('choixsiteoui','none');
				display('choixsitenon','block');
				document.int_maj.idsite.value='0';
				document.getElementById('nomsite').innerHTML='<strong>Site principal</strong>';
			}
			else
			{
				display('choixsiteoui','block');
				display('choixsitenon','none');
				document.int_maj.idsite.value='';
				document.getElementById('nomsite').innerHTML='';
			}
		}
	}
	else
	{
		display('res','none');
		display('pas_res','block');
		if (document.int_maj.nbsites.value==0)
		{
			display('choixsiteoui','none');
			display('choixsitenon','block');
			document.int_maj.idsite.value='0';
			document.getElementById('nomsite').innerHTML='<strong>Site principal</strong>';
		}
		else
		{
			display('choixsiteoui','block');
			display('choixsitenon','none');
		}
	}
}
</script>

<!-- Fonction pour ouvrir une fenêtre de résumé contrat en fonction du select -->
<script type="text/javascript">
function fen_res_cocl()
{
	var slct=document.getElementsByName('codecocl');
	var no_cocl=slct[0].value;
	if ((no_cocl) && (no_cocl!=''))
	{
		fensaisie('aff_rescocl.php?cocl='+no_cocl,900,800,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');
	}
}
</script>

<!-- Fonction pour ouvrir une fenêtre de choix du site -->
<script type="text/javascript">
function fen_sites_int(cli,typ,int,sit,con)
{
	if ((cli) && (cli!=''))
	{
		fensaisie('sitesi_lst.php?cc='+cli+'&td='+typ+'&ci='+int+'&si='+sit+'&co='+con,910,650,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');
	}
}
</script>

<!-- Fonction pour ouvrir une fenêtre de choix des problèmes -->
<script type="text/javascript">
function fen_rpbm_int(cli,typ,int,sit)
{
	if ((cli) && (cli!=''))
	{
		var url_rpbm='rpbm_lst.php?cc='+cli+'&td='+typ+'&ci='+int+'&si='+sit;
		fensaisie(url_rpbm,1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');
	}
}
</script>

<!-- Fonction pour vérifier si le temps offert doit être affiché -->
<script type="text/javascript">
function tst_aff_tpsoff()
{
	var tab_heure = document.int_maj.dureeoff.value.split(':');
	var nbsec = (Number(tab_heure[0])*3600)+(Number(tab_heure[1])*60);
	if (nbsec>0)
	{
		display('affoffoui','block');
		display('affoffnon','none');
	}
	else
	{
		display('affoffoui','none');
		display('affoffnon','block');
	}
}
</script>

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

<script language="javascript">
var tab1_champ=new Array(
<?PHP 
if ($td <> "add") 
{
	if ($td <> "del")
	{
?>
	"nom:dateddef ; format:date ; masque:jj-mm-aaaa ; req:Y ; txt:Date demande ; stok:frmok ; stbad:frmbad",
<?PHP
		if ((@$HTTP_SESSION_VARS["niv_log"] <> 4) AND (@$HTTP_SESSION_VARS["niv_log"] <> 3))
		{
			if ($cli_prop == NULL)
			{
?>
	"nom:codeage; format:liste ; req:Y ; txt:Agence ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
			}
			else
			{
?>
	"nom:codeage; format:txt ; req:Y ; txt:Agence ; stok:frmok ; stbad:frmbad",
<?PHP
			}
		}
		else
		{
?>
	"nom:codeage; format:txt ; req:Y ; txt:Agence ; stok:frmok ; stbad:frmbad",
<?PHP
		}
?>		
	"nom:nomorig; format:txt ; req:Y ; txt:Origine ; stok:frmok ; stbad:frmbad",
<?PHP
		if ($int_codestatut <> "CLOT")
		{
?>
	"nom:codestatut; format:liste ; req:Y ; txt:Statut ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
		}
		else
		{
?>
	"nom:codestatut; format:txt ; req:Y ; txt:Statut ; stok:frmok ; stbad:frmbad",
<?PHP
		}
?>
<?PHP
		if ($int_codestatut <> "CLOT")
		{
?>
	"nom:codelieu; format:liste ; req:Y ; txt:Statut ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
		}
		else
		{
?>
	"nom:codelieu; format:txt ; req:Y ; txt:Statut ; stok:frmok ; stbad:frmbad",
<?PHP
		}
?>
	"nom:hrdv; format:heurehhmm ; req:N ; txt:Heure rendez-vous ; stok:frmok ; stbad:frmbad",
	"nom:mat; format:txt ; req:Y ; txt:Matériel ; stok:frmok ; stbad:frmbad",
<?PHP
if (@$HTTP_SESSION_VARS["niv_log"] <> 1)
{
?>
	"nom:login; format:txt ; req:N ; txt:Login ; stok:frmok ; stbad:frmbad",
	"nom:mdpsys; format:txt ; req:N ; txt:Mot de passe système ; stok:frmok ; stbad:frmbad",
	"nom:mdpbios; format:txt ; req:N ; txt:Mot de passe BIOS ; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:pbm; format:txt ; req:Y ; txt:Descriptif problème ; stok:frmok ; stbad:frmbad",
	"nom:acpte; format:reel_ns ; req:Y ; txt:Acompte ; stok:frmok ; stbad:frmbad",
<?PHP
		if ($int_datefinf == "")
		{ 
?>
	"nom:codetec; format:liste ; req:Y ; txt:Responsable dossier ; vmn:1; stok:frmok ; stbad:frmbad",
<?PHP
		}
		else
		{
?>
	"nom:codetec; format:txt ; req:Y ; txt:Responsable dossier ; stok:frmok ; stbad:frmbad",
<?PHP
		}
?>
	"nom:fait; format:txt ; req:N ; txt:Travail effectué; stok:frmok ; stbad:frmbad",
<?PHP
		if ($int_codestatut <> "CLOT") // Si pas encore clot, on peut changer le règlement
		{
?>
	"nom:reg; format:liste ; req:Y ; txt:Règlement ; vmn:1; stok:frmok ; stbad:frmbad");
<?PHP
		}
		else
		{
?>
	"nom:reg; format:txt ; req:Y ; txt:Règlement ; stok:frmok ; stbad:frmbad");
<?PHP
		}
?>
<?PHP
	}
} 
else 
{ 
?>
	"nom:dateddef ; format:date ; masque:jj-mm-aaaa ; req:Y ; txt:Date demande ; stok:frmok ; stbad:frmbad",
<?PHP
		if ((@$HTTP_SESSION_VARS["niv_log"] <> 4) AND (@$HTTP_SESSION_VARS["niv_log"] <> 3))
		{
			if ($cli_prop == NULL)
			{
?>
	"nom:codeage; format:liste ; req:Y ; txt:Agence ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
			}
			else
			{
?>
	"nom:codeage; format:txt ; req:Y ; txt:Agence ; stok:frmok ; stbad:frmbad",
<?PHP
			}
		}
		else
		{
?>
	"nom:codeage; format:txt ; req:Y ; txt:Agence ; stok:frmok ; stbad:frmbad",
<?PHP
		}
?>		
	"nom:codeorig; format:liste ; req:Y ; txt:Origine ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:codestatut; format:liste ; req:Y ; txt:Statut ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:codelieu; format:liste ; req:Y ; txt:Statut ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:hrdv; format:heurehhmm ; req:N ; txt:Heure rendez-vous ; stok:frmok ; stbad:frmbad",
	"nom:mat; format:txt ; req:Y ; txt:Matériel ; stok:frmok ; stbad:frmbad",
	"nom:login; format:txt ; req:N ; txt:Login ; stok:frmok ; stbad:frmbad",
	"nom:mdpsys; format:txt ; req:N ; txt:Mot de passe système ; stok:frmok ; stbad:frmbad",
	"nom:mdpbios; format:txt ; req:N ; txt:Mot de passe BIOS ; stok:frmok ; stbad:frmbad",
	"nom:pbm; format:txt ; req:Y ; txt:Descriptif problème ; stok:frmok ; stbad:frmbad",
	"nom:acpte; format:reel_ns ; req:Y ; txt:Acompte ; stok:frmok ; stbad:frmbad");
<?PHP 
} 
?>
</script>

<!-- Fonction pour valider le formulaire -->
<script type="text/javascript">
function verif_saisie(formulaire,tab_champ,lng,val_id)
{
	var idok=true;
	if (val_id=="")
	{
		idok=false;
		alert('Vous devez choisir un site d\'intervention');
	}
	var rdvok=true;
	if ((document.int_maj.daterdvf.value!='') && (document.int_maj.hrdv.value==''))
	{
		rdvok=false;
		alert('Vous avez pris un rdv : vous devez choisir une heure de rdv');
	}
	if ((document.int_maj.hrdv.value!='') && (document.int_maj.daterdvf.value==''))
	{
		rdvok=false;
		alert('Vous avez choisi une heure de rdv sans date...');
	}
	var formok=VForm(formulaire,tab_champ,lng);
	if ((rdvok==true) && (idok==true) && (formok==true))
	{
		return true;
	}
	else
	{
		return false;
	}
}
</script>

</head>

<?PHP if ($td == "del"){ ?>
<body onLoad="warndel();">
<?PHP } else { ?>
<body onLoad="tst_res_cocl(document.int_maj.codecocl.selectedIndex,true);tst_aff_tpsoff(document.int_maj.dureeoff.value);">
<?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) AND ($pbm_cli==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?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") OR ($td == "view"))
		{
		$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") and ($td == "edit")) // Si pas encore clot et en mode édition, on peut saisir des articles
		{
		?>
			<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="javascript:; return (verif_saisie(this,tab1_champ,'',document.int_maj.idsite.value));">
<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">
<input name="idsite" type="hidden" id="idsite" value="<?PHP echo $int_idsite; ?>">
<input name="nbsites" type="hidden" id="nbsites" value="<?PHP echo $nbsites; ?>">
<?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="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="rubfrm" 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="rubfrm" 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="rubfrm" id="f_codecli">
		<div align="center">Client 
		</div>
	</td>
	<td width="30" valign="bottom">
	<?PHP
	if (@$HTTP_SESSION_VARS["niv_log"] >=3)
	{
		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\">";
	}
	else
		echo "&nbsp;";
	?>
	</td>
</tr>
</table>

<!-- Détails client -->
<table width="800"  border="0">
<tr>
	<td width="185" align="center" valign="bottom" class="ent_clisite">
	Compte client
	</td>
	<td width="185" align="center" valign="bottom" class="ent_clisite">
	<?PHP
	if (nb_scli_actifs($int_codecli)>0)
	{
	?>
	<div id="choixsiteoui" style="display:block">
	<?PHP
	}
	else
	{
	?>
	<div id="choixsiteoui" style="display:none">
	<?PHP
	}
	?>
	Site d'intervention
	<?PHP if ((($td=="add") OR ($td=="edit")) AND ($cli_ste<>""))
	{
	?>
	<a href="javascript:;" onclick="javascript:; fen_sites_int(document.int_maj.codecli.value,document.int_maj.typdde.value,document.int_maj.code.value,document.int_maj.idsite.value,document.int_maj.codecocl.value);")><img src="../img/sites.gif" title="Choisir un site" width="16" height="16" border="0" align="bottom"></a>
	<?PHP
	}
	?>
	</div>
	<?PHP
	if (nb_scli_actifs($int_codecli)>0)
	{
	?>
	<div id="choixsitenon" style="display:none">
	<?PHP
	}
	else
	{
	?>
	<div id="choixsitenon" style="display:block">
	<?PHP
	}
	?>
	Site d'intervention
	</div>
	</td>
	<td width="30" valign="top">&nbsp;
	
	</td>
</tr>
<tr>
	<td width="185" valign="top" bgcolor="#CCFFCC">
	<?PHP
	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="185" valign="top" bgcolor="#CCFFCC">
	<div id="nomsite">
	<?PHP
	echo nom_scli($int_idsite,TRUE);
	?>
	</div>
	</td>
	<td width="30" valign="top">
	<?PHP 
	if (@$HTTP_SESSION_VARS["niv_log"] >= 3)
	{
	  $url_affnotesc = "aff_notesc.php?cc=".$cc;
	?>
	  <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_affnotesc; ?>',930,380,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/detail.gif" width="16" height="16" border="0" align="absmiddle"></a>
	  <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_affnotesc; ?>',930,380,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")> Notes</a>
	<?PHP
	}
	else
		echo "&nbsp;";
	?>
	</td>
	</tr>
</table>

<!-- Code de l'agence (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_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
							echo "<option>-- Choisissez une agence --</option>";

							while ($resultat = mysql_fetch_array($rs)) 
							{
								extract($resultat);
				
								// Vérifie zone de chalandise
								if (exist_chaine_in_seq($cli_dep,$age_zone) == TRUE)
								{
									if ($int_codeage == $age_code)
									{
										echo '<option value="'.$age_code.'" selected>'.$age_nom.'</option>';
									}
									else
									{
										echo '<option value="'.$age_code.'">'.$age_nom.'</option>';
									}
								}
							}
						?>
						</select>
						<img src="../img/oblig.gif" width="10" height="11">
				<?PHP
					}
					else
					{
				?>
						<select name="codeage" id="codeage">
						<option>-- Pas d'agence active --</option>
						</select>
				<?PHP
					}
					mysql_free_result($rs);
					mysql_close($conn);
				}
				else
				{
					$row = lit_enr_age($cli_prop);
					extract($row);
					$age_nomcode = $age_nom." (".$age_code.")";
				?>
					<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $age_code ?>">
					<input name="nomage" type="text" id="nomage" value="<?PHP echo $age_nomcode ?>" size="50" maxlength="50" readonly="1">
				<?PHP
				}
			}
			else
			{
				$row = lit_enr_age($HTTP_SESSION_VARS["code_age"]);
				extract ($row);
				$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="rubfrm" id="f_codeco"><div align="right">Sur le contrat</div></td>
	<td>
		<table width="100%" border="0">
		<tr>
		<td width="200">
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
			<select name="codecocl" id="codecocl" onChange="tst_res_cocl(this.selectedIndex,false);">
		<?PHP
			// 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)
			{
				echo "<option value=\"\">-- Choisissez un contrat --</option>";

				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					$rech2 = "SELECT * FROM " .TBCO. " WHERE co_code = '".$cocl_codeco."'";
					$rs2 = mysql_query($rech2) or die(mysql_error());
					if ($row2 = mysql_fetch_array($rs2))
					{
						if ($cocl_delai <> 0)
							$txt_cocl = $cocl_code." - ".$row2["co_nom"]." (".$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>";
				}
			}
			else
			{
				echo "<option value=\"\">-- Pas de contrat actif sur ce client --</option>";
			}
		?>
			</select>
		<?PHP
			mysql_free_result($rs);
			mysql_close($conn);
		?>
		</td>
		<td align="left">
			<div id="res" style="display:none" align="left">
				<a href="javascript:;" onclick="javascript:; fen_res_cocl();")><img src="../img/detail.gif" title="R&eacute;sum&eacute; contrat" width="16" height="16" border="0" align="absmiddle"></a>
				<a href="javascript:;" onclick="javascript:; fen_res_cocl();")> R&eacute;sum&eacute; contrat</a>
			</div>
			<div id="pas_res"  style="display:block" align="left">
				&nbsp;
			</div>
		<?PHP
		} 
		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))
				{
					if ($cocl_delai <> 0)
						$txt_cocl = $cocl_code." - ".$row2["co_nom"]." (".$cocl_delai."h ouvrées)";
					else
						$txt_cocl = $cocl_code." - ".$row2["co_nom"]." (Pas de d&eacute;lai)";
				}
				mysql_free_result($rs2);
				mysql_close($conn);
			}
			if ($txt_cocl<>"")
			{
		?>
				<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
			}
			else
			{
		?>
				<span class="annot_gras_it">
				Pas de contrat affect&eacute; &agrave; cette intervention
				</span>
		<?PHP
			}
		}
		?>
		</td>
		</tr>
		</table>
	</td>
</tr>
</table>
<?PHP }  ?>

<!-- Paramètres de la demande -->
<table width="800"  border="0">
  <tr>
    <td width="160" class="rubfrm" 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
			
			echo "<option>-- Choisissez une origine --</option>";

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

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

				if ($int_codeorig == $orig_code)
					echo '<option value="'.$orig_code.'" selected>'.$orig_desc.'</option>';
				else
					echo '<option value="'.$orig_code.'">'.$orig_desc.'</option>';
			}
			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="rubfrm" id="f_statut"><div align="right">Statut </div></td>
    <td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
        	<select name="codestatut" id="codestatut">
        <?PHP
			
			echo "<option value=\"\">-- Choisissez un statut --</option>";

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

			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				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>';
				}
			}
			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
		{
			$txt_statut = "";
			if ($int_codestatut <> "")
			{
				$row = lit_enr_statut($int_codestatut);
				if (is_array($row))
				{
					extract($row);
					$txt_statut = $statut_desc;
				}
			}
			if ($txt_statut<>"")
			{
		?>
			<input name="codestatut" type="hidden" id="codestatut" value="<?PHP echo $int_codestatut ?>">
			<input name="nstatut" type="text" id="nstatut" value="<?PHP echo $txt_statut ?>" size="50" maxlength="50" readonly="1">
		<?PHP
			}
			else
			{
		?>
				<span class="annot_gras_it">
				Pas de statut affect&eacute; &agrave; cette intervention
				</span>
		<?PHP
			}
		}
		?>
    </td>
  </tr>
  <tr>
    <td width="160" class="rubfrm" id="f_lieu"><div align="right">Lieu </div></td>
    <td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{
		?>
			<select name="codelieu" id="codelieu" onChange="warn_lieu();">
			<?PHP
			
			echo "<option value=\"\">-- Choisissez un lieu --</option>";

			// 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);
	
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
	
				if ($int_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>
	        <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>
<?PHP
if (@$HTTP_SESSION_VARS["niv_log"] <> 1)
{
?>
  <tr>
    <td class="rubfrm" id="f_urg"><div align="right">Niveau d'urgence </div></td>
    <td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{
		?>
			<select name="urgence" id="urgence">
		  <?PHP
			
			// Création du niveau d'urgence
			
			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>
<?PHP
}
?>
</table>

<!-- Date de RDV -->
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" 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 (($td == "add") OR ($td == "edit"))
		{ 
		?>
			<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='';document.int_maj.hrdv.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="5" maxlength="5">
			)		
			<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="5" maxlength="8" readonly="1">
			)
		<?PHP } ?>
        <span class="annot_petit_it">hh:mm</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="rubfrm" id="f_mat">
		<div align="right">Mat&eacute;riel </div>
	</td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
			// 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)
				{
			?>
					<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="javascript:; fen_rpbm_int(document.int_maj.codecli.value,document.int_maj.typdde.value,document.int_maj.code.value,document.int_maj.idsite.value);">
							<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>
<?PHP
if (@$HTTP_SESSION_VARS["niv_log"] <> 1)
{
?>
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_login"><div align="right">Login/MDP Sys. </div></td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
			<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="rubfrm" 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>
<?PHP
}
?>
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_pbm">
		<div align="right">
		<p>Descriptif probl&egrave;me</p>
		</div>
	</td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
			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="rubfrm" id="f_gar"><div align="right">Garantie</div></td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
			<?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)"> 
			<span class="annot_petit_it"> (Obligatoire si garanti)</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="rubfrm" id="f_acpte"><div align="right">Acompte (&euro; TTC) </div></td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
			<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="rubfrm" id="f_codetec"><div align="right">Responsable dossier</div></td>
    <td>
		<?PHP
		if ($td == "edit")
		{ 
		?>
			<?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
				echo '<option>-- Choisissez un technicien --</option>';

				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					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>";
				}
			?>
			  </select>
			<img src="../img/oblig.gif" width="10" height="11"> 
			<?PHP
			}
			else
			{
			?>
				<select name="codetec" id="codetec" onChange="verif_tec();">
				<option>-- Pas de technicien actif sur cette agence --</option>
				</select>
			<?PHP
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
		<?PHP
		}
		else
		{
			$row = lit_enr_tec($int_codetec);
			if (is_array($row))
			{
				extract($row);
				$txt_tec = $tec_nom." ".$tec_prenom;
			}
			else
				$txt_tec="Pas de technicien affecté";
		?>
	        <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="rubfrm" 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="rubfrm" id="f_duree"><div align="right">Temps travaill&eacute;</div></td>
	<td>
		<input name="duree" type="text" id="duree" value="<?PHP echo substr(sec_heure($int_durees),0,5) ?>" size="5" maxlength="5" readonly="1"> 
		<!-- Détails internes du temps passé -->
		<?PHP
		if ($td == "edit")
		{
			$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
		}
		?>
		<span class="annot_petit_it">
		<div id="affoffoui" style="display:block">
		Dont temps offert : (
		<input name="dureeoff" type="text" id="dureeoff" value="<?PHP echo substr(sec_heure($nbtotalsecoff),0,5) ?>" size="5" maxlength="5" readonly="1" onChange="tst_aff_tpsoff()"> 
		)
		</div>
		<div id="affoffnon" style="display:none">
		&nbsp;
		</div>
		</span>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_fait"><div align="right">Travail effectu&eacute; </div></td>
	<td>
		<?PHP
		if ($td == "edit")
		{ 
			// 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="rubfrm" 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 ($td == "edit")
		{ 
		?>
		<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="rubfrm" id="f_reg"><div align="right">R&egrave;glement</div></td>
    <td>
		<?PHP
		if ($td == "edit")
		{
		?>
			<select name="reg" id="reg">
			<?PHP
			echo '<option>-- Choisissez un mode de règlement --</option>';
			
			// 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>
			<img src="../img/oblig.gif" width="10" height="11"> 
        <?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="rubfrm" 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 ($td == "edit")
		{ 
		?>
		<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") 
{ 
?>
	<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") OR ($td == "view"))
{
?>
	<a name="intart"></a>
	<table width="800"  border="0">
	<tr>
		<td class="rubfrm">
		<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";
		if ($td == "edit")
			echo "<th class=\"thlst\">Cliquer</th>\n";
		else
			echo "<th class=\"thlst\">&nbsp;</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;
			
			if ($td == "edit")
			{
				// CREATION lien dynamique sur icône (édition, suppression, etc...)
				echo "<td >";
				echo "<div align=\"center\">";
				$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>";
				echo "</div>";
				echo "</td>\n";
			}
			else
			{
				echo "<td >";
				echo "&nbsp;";
				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 (($td == "edit") OR ($td == "view"))
			{
			?>
				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 ($td == "edit")
		{
	?>
		<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 (($td == "edit") OR ($td == "add"))
	{
?>
		<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 
	}
?>
<?PHP	
	if ($td <> "del")
	{
?>
<?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>
<?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');",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');",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');",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');",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');",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=('lieu_lst.php');",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');",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');",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');",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
{
	if ($pbm_int==TRUE) 
	{
?>
		<script type="text/javascript">
		setTimeout("self.location.href=('int_lst.php?ord=DES&tri=Code');",2000)
		</script>
		<p align="center" class="annot_std_it">Merci de choisir une de vos interventions...</p>
<?PHP
	}
	else
	{
		if (@$HTTP_SESSION_VARS["niv_log"] == 1)
		{
?>
			<script type="text/javascript">
			setTimeout("self.location.href=('index.php');",2000)
			</script>
			<p align="center" class="annot_std_it">Ce n'est pas votre compte...</p>
<?PHP
		}
		if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
		{
?>
			<script type="text/javascript">
			setTimeout("self.location.href=('cli_lst.php');",2000)
			</script>
			<p align="center" class="annot_std_it">Merci de choisir un de vos clients...</p>
<?PHP
		}
	}
 }
?>
