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

Version 0.9.7

Copyright (C) 2006-2007  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_do.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_ot.inc.php");
include_once("../inc/fic_statut.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/fic_zc.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");
Archivelog(@$_SESSION["code_log"]);

$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
$ca = strip_tags(trim($_GET['ca'])); // Récupération code Agence
$co = strip_tags(trim($_GET['co'])); // Récupération code contrat
$_SESSION["pbm_choisis"] = "";

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

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

if ($ca<> "")
{
	// Contrôle qu'une agence n'essaye pas de "hacker" un contrat
	if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($ca <> @$_SESSION["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 ((@$_SESSION["niv_log"] == 1) AND ($int_codecli <> @$_SESSION["code_log"]))
				$pbm_int = TRUE;
			// Contrôle qu'une agence n'essaye pas de "hacker" une intervention
			if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($cocl_codeage <> @$_SESSION["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);

		if ($td <> "add")
		{
			// Contrôle qu'un client n'essaye pas de "hacker" une intervention
			if ((@$_SESSION["niv_log"] == 1) AND ($int_codecli <> @$_SESSION["code_log"]))
				$pbm_int = TRUE;

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

			// Contrôle qu'un donneur d'ordres n'essaye pas de "hacker" une intervention
			if (((@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 6)) AND ($int_codedo <> @$_SESSION["code_do"]))
				$pbm_int = TRUE;
		}

		// Construction de la chaîne des problèmes sélectionnés
		$lstpbm=cree_str_lstpbm_int($ci);
		$txtmat="";
		$txtpbm="";
		$txtfait="";
		$_SESSION["pbm_choisis"] = $lstpbm;
		if ($lstpbm<>"")
		{
			$txtmat=htmlspecialchars(cree_txt_matos_int($lstpbm),ENT_QUOTES);
			$txtpbm=htmlspecialchars(cree_txt_pbm_int($lstpbm),ENT_QUOTES);
			$txtfait=htmlspecialchars(cree_txt_fait_int($lstpbm),ENT_QUOTES);
		}
		$_SESSION["txtmatlst"] = $txtmat;
		$_SESSION["txtpbmlst"] = $txtpbm;
		$_SESSION["txtfaitlst"] = $txtfait;

		// 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);
		
		// Si intervention terminée, on force le mode "view"
		if ($int_datefinf <> "")
			$td="view";

		// Si intervention commençée et en mode donneur d'ordres, on force le mode "view"
		if ((@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 6))
		{
			if ((($int_codetec<>"") AND ($int_codetec<>"-1")) OR ($int_durees<>0) OR ($int_fait<>"") OR ($int_dateprevf<>"") OR ($int_datefinf<>""))
				$td="view";
		}

		// Récupération heure rdv
		$int_hrdv = substr($int_hrdv,0,5);
		if ($int_daterdvf=="") // Si pas de RDV, pas d'heure possible...
			$int_hrdv="";

		if ($td == "edit")
		{
			$cc=$int_codecli;
			$ca=$int_codeage;
		}

		if ($td == "add")
		{
			$int_dateddef = $datef;
			$int_code = $ci;
			$int_codecli = $cc;
			$int_codeage = $ca;
			$int_codereg = "EC";
			$int_hrdv = "07:00";
		}
	
		// 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);
				}
			}
			if ($str_tec_traitants!="")
				$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 == "add")
	{
		$int_dateddef = $datef;
		$int_code = crecodesession("I");
		$ci = $int_code;
		$int_hrdv = "07:00";
		$int_acpte= "0.00";
		$int_codecocl = $co;
		if ((@$_SESSION["niv_log"]==7) OR (@$_SESSION["niv_log"]==6))
			$int_codedo=@$_SESSION["code_do"];
		else
			$int_codedo="";
		$int_codest="";
		$_SESSION["pbm_choisis"] ="";
		$_SESSION["txtmatlst"] = "";
		$_SESSION["txtpbmlst"] = "";
		$_SESSION["txtfaitlst"] = "";
	}
	else
		$pbm_int=TRUE;
}

$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
		switch(@$_SESSION["niv_log"])
		{
			case 3 :
			case 4 :
				if (client_age_ok($cli_code,@$_SESSION["code_age"],TRUE)==FALSE)
					$pbm_cli = TRUE;
				break;
			default :
				break;
		}
		
		$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" :
			if ((@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7))
				$titre = "SAISIE ORDRE INTERVENTION";
			else
				$titre = "SAISIE INTERVENTION";
		break;
	case "edit" :
			if ((@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7))
				$titre = "MISE A JOUR ORDRE INTERVENTION";
			else
			$titre = "MISE A JOUR INTERVENTION";
		break;
	case "view" :
			if (@$_SESSION["niv_log"] == 1)
				$titre = "DETAIL INTERVENTION";
			else
			{
				if ((@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7))
					$titre = "VISUALISATION ORDRE INTERVENTION";
				else
					$titre = "VISUALISATION INTERVENTION";
			}
		break;
	case "del":
			if ((@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7))
				$titre = "SUPPRESSION ORDRE INTERVENTION";
			else
				$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 -->

<script language="JavaScript" src="../jscript/coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour fenêtres -->
<script language="JavaScript" src="../jscript/fen.js"></script>

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

<!-- Définition Javascript pour calendrier popup -->
  <!-- Feuille de Style -->
  <link rel="stylesheet" type="text/css" media="all" href="../jscript/jscal/skins/aqua/theme.css" title="Aqua" />

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

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscript/jscal/lang/calendar-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="../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 == "edit")  OR ($td=="add"))
{
?>
<script language="javascript">
var tab1_champ=new Array(
	"nom:dateddef ; format:date ; masque:jj-mm-aaaa ; req:Y ; txt:Date demande ; stok:frmok ; stbad:frmbad",
<?PHP
	if ($td=="add")
	{
		if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["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: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
	}
	if ($td=="add")
	{
?>		
	"nom:codeorig; format:liste ; req:Y ; txt:Origine ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP } else { ?>
	"nom:nomorig; format:txt ; req:Y ; txt:Origine ; stok:frmok ; stbad:frmbad",
<?PHP
	}
	if ($td=="add")
	{
?>
	"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
	}
	if ($td=="add")
	{
?>
	"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
	}

	if (@$_SESSION["niv_log"] <> 2)
	{
?>
	"nom:hrdv; format:liste ; req:N ; txt:Heure rendez-vous ; 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:acpte; format:reel_ns ; req:Y ; txt:Acompte ; stok:frmok ; stbad:frmbad",
<?PHP
	}
	
	if ($td <> "add")
	{
?>
	"nom:codetec; format:liste ; req:Y ; txt:Responsable dossier ; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:fait; format:txt ; req:N ; txt:Travail effectué; stok:frmok ; stbad:frmbad",
	"nom:codereg; format:liste ; req:Y ; txt:Règlement ; vmn:1; stok:frmok ; stbad:frmbad",
<?PHP
	} 
?>
	"nom:mat; format:txt ; req:Y ; txt:Matériel ; stok:frmok ; stbad:frmbad",
	"nom:pbm; format:txt ; req:Y ; txt:Descriptif problème ; 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 fenêtres -->
<script language="JavaScript" src="../jscript/fen.js"></script>

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

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

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

<?PHP cre_js_pdti($td,$ci,$int_acpte,""); ?>

</head>

<?PHP
switch ($td)
{
	case "del" :
		switch (@$_SESSION["niv_log"])
		{
			case 6 :
			case 7 :
				echo "<body onload=\"tst_aff_tpsoff(document.int_maj.dureeoff.value);metReadonly();warndel();\">";
				break;
			default :
				echo "<body onload=\"tbpdti();tst_aff_tpsoff(document.int_maj.dureeoff.value);metReadonly();warndel();\">";
				break;
		}
		break;
	case "view" :
		switch (@$_SESSION["niv_log"])
		{
			case 1 :
				echo "<body onload=\"tbpdti();tst_aff_tpsoff(document.int_maj.dureeoff.value);metReadonly();\">";
				break;
			case 6 :
			case 7 :
				echo "<body onload=\"verif_pw(document.getElementById('mdpsys').value,false,'nivpw');tst_aff_tpsoff(document.int_maj.dureeoff.value);metReadonly();\">";
				break;
			default :
				echo "<body onload=\"verif_pw(document.getElementById('mdpsys').value,false,'nivpw');tbpdti();tst_aff_tpsoff(document.int_maj.dureeoff.value);metReadonly();\">";
				break;
		}
		break;
	case "add" :
		echo "<body onLoad=\"metFocus();tst_res_cocl(document.int_maj.codecocl.selectedIndex,true)\">";
		break;
	case "edit" :
		switch (@$_SESSION["niv_log"])
		{
			case 6 :
			case 7 :
				echo "<body onLoad=\"verif_pw(document.getElementById('mdpsys').value,false,'nivpw');metFocus();tst_aff_tpsoff(document.int_maj.dureeoff.value);\">";
				break;
			default :
				echo "<body onLoad=\"verif_pw(document.getElementById('mdpsys').value,false,'nivpw');metFocus();tst_res_cocl(document.int_maj.codecocl.selectedIndex,true);tst_aff_tpsoff(document.int_maj.dureeoff.value);tbpdti();\">";
				break;
		}
		break;
}

include_once("entete.inc.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 (@$_SESSION["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 clients</a></em></strong></td>
	<?PHP } ?>
	<td width="20%" valign="top"><div id="oblig" align="center" class="annot_gras_it">(<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"> : Saisie obligatoire)
</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> 
	<?PHP if ((@$_SESSION["niv_log"] ==4) OR (@$_SESSION["niv_log"] ==3) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] ==9)) { ?>
	 / <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 } } ?>
    </div></td>
</tr>
</table>
<form name="int_maj" method="post" action="int_enr.php" onSubmit="javascript:; return (verif_int(this,tab1_champ,'','',document.int_maj.idsite.value));">
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="codecli" type="hidden" id="codecli" value="<?PHP echo $int_codecli ?>">
<input name="prev" type="hidden" id="prev" value="<?PHP echo $cli_prev ?>">
<input name="exdateprevf" type="hidden" id="exdateprevf" value="<?PHP echo $int_dateprevf ?>">
<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; ?>">
<input name="codedo" type="hidden" id="codedo" value="<?PHP echo $int_codedo ?>">	
<?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") AND (@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
{
  $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" alt="Champ obligatoire">
		<?PHP } ?>
	</td>
</tr>
</table>

<!-- Code de l'intervention et affectation sous-traitant (affiché uniquement si édition ou suppression) -->
<?PHP if ($td <> "add") {?>
<table width="900"  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">
		<?PHP
		if (($int_codedo <>"") AND (@$_SESSION["niv_log"] ==4) OR (@$_SESSION["niv_log"] ==3) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
		{
			$row=lit_enr_do($int_codedo);
			if (is_array($row))
			{
				extract($row);
				echo " <span class=\"annot_gras_it\">";
				echo "Ordre donn&eacute; par ";
				echo $do_nom;
				echo "</span>";
			}
		} 

		if ((@$_SESSION["niv_log"] ==5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
		{
			if (nb_st_actifs()>0)
			{
			  $url_affot = "ot_lst.php?tx=i&ci=".$ci;
		?>
		 <input name="sst" type="button" class="bton_fmarr_std" id="sst" value="G&eacute;rer les sous-traitants" style="text-decoration: none; font-size: 11px; color:White ;font-weight:bold;background-color: #666666;" onclick="fensaisie('<?PHP echo $url_affot; ?>',1000,650,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');">
		<?PHP
			}
		?>
			<span id="strot" style="visibility:visible">
		<?PHP
			$nb_ot=nb_ot($int_code);
			if ($nb_ot>0)
			{
				echo "<span class=\"annot_petit_it\">";
				echo "(Actuellement : ".$nb_ot." bon";
				if ($nb_ot>1)
					echo"s";
				echo" de travail";
				$nb_ot_actifs=nb_ot_actifs($int_code);
				if ($nb_ot_actifs>0)
					echo ", dont ".$nb_ot_actifs." non termin&eacute;";
				if ($nb_ot_actifs>1)
					echo "s";
				echo")";
				echo "</span>";
			}
		?>
			</div>
		<?PHP
		}
		?>
	</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 ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["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>
	<?PHP if ((($td=="add") OR ($td=="edit")) AND ($cli_ste<>"") AND (@$_SESSION["niv_log"] <> 2))
	{
	?>
	<td width="185" align="center" valign="bottom" class="ent_clisite" <?PHP if (nb_scli_actifs($int_codecli)>0) echo 'onclick="javascript:; fen_sites_int(document.int_maj.codecli.value,document.int_maj.td.value,document.int_maj.code.value,document.int_maj.idsite.value,document.int_maj.codecocl.value);"'?>>
	<?PHP
	}
	else
	{
	?>
	<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<>"") AND (@$_SESSION["niv_log"] <> 2))
	{
	?>
	<img src="../img/sites.gif" title="Choisir un site" width="16" height="16" border="0" align="bottom">
	<?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_openId($cli_ville,TRUE)." ".Retourneville_openId($cli_ville,TRUE)."<br>";
	echo "Tel : ".$cli_telf."<br>";
	?>
	</td>
	<?PHP if ((($td=="add") OR ($td=="edit")) AND ($cli_ste<>"") AND (@$_SESSION["niv_log"] <> 2))
	{
	?>
	<td width="185" valign="top" bgcolor="#CCFFCC" <?PHP if (nb_scli_actifs($int_codecli)>0) echo 'onclick="javascript:; fen_sites_int(document.int_maj.codecli.value,document.int_maj.td.value,document.int_maj.code.value,document.int_maj.idsite.value,document.int_maj.codecocl.value);"'?> >
	<?PHP
	}
	else
	{
	?>
	<td width="185" valign="top" bgcolor="#CCFFCC">
	<?PHP
	}
	?>
	<div id="nomsite">
	<?PHP
	echo nom_scli($int_idsite,TRUE);
	?>
	</div>
	</td>
	<td width="30" valign="top">
	<?PHP 
	if (@$_SESSION["niv_log"] >= 3)
	{
	  $url_affnotesc = "aff_notesc.php?cc=".$cc;
	?>
	  <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_affnotesc; ?>',930,380,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/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 ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 2))
			{
				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' AND `age_codepays` = '".$cli_codepays."' 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 (dep_in_zcc_age_open($cli_dep,$cli_codepays,$age_code,FALSE))
								{
									$age_nomcode = $age_nom." (".$age_code.")";
									if ($int_codeage == $age_code)
										echo '<option value="'.$age_code.'" selected>'.$age_nomcode.'</option>';
									else
										echo '<option value="'.$age_code.'">'.$age_nomcode.'</option>';
								}
							}
						?>
						</select>
						<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
				<?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($_SESSION["code_age"]);
				extract ($row);
				$age_nomcode = $age_nom." (".$age_code.")";
			?>
				<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $_SESSION["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 <> "") {?>
<?PHP
if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
{
?>
<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'";
			if ($td=="add")
			{
				$rech.=" AND `cocl_datefin` = '0000-00-00' AND `cocl_datesig` <> '0000-00-00'";
				$rech.=" AND `cocl_dated` <= '".$datea."' AND (`cocl_datef` >= '".$datea."' OR `cocl_datef` = '0000-00-00')";
			}
			else
			{
				$rech.=" AND ((`cocl_datefin` = '0000-00-00' AND `cocl_datesig` <> '0000-00-00'";
				$rech.=" AND `cocl_dated` <= '".$int_datedde."' AND (`cocl_datef` >= '".$int_datedde."' OR `cocl_datef` = '0000-00-00'))";
				if ($int_codecocl<>"")
					$rech.=" OR cocl_code='".$int_codecocl."')";
				else
					$rech.=")";
			}
			$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>
		</td>
		<?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="75" readonly="1">
		</td>
		<td align="left">
			<div id="res" style="display:blovk" 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>
		</td>
		<?PHP
			}
			else
			{
		?>
				<span class="annot_gras_it">
				Pas de contrat affect&eacute; &agrave; cette intervention
				</span>
		</td>
		<?PHP
			}
		}
		?>
		</tr>
		</table>
	</td>
</tr>
</table>
<?PHP } else { ?>
<input name="codecocl" type="hidden" id="codecocl" value="">
<?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 value=\"\">-- 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" alt="Champ obligatoire">
		<?PHP
		} 
		else // Sinon, on affiche simplement l'origine de la demande
		{
			$row = lit_enr_orig($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" alt="Champ obligatoire">
        <?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" <?PHP if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6)) echo "onChange=\"warnlieu();\"";?>>
			<?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" alt="Champ obligatoire"> 
        <?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 (@$_SESSION["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" alt="Champ obligatoire"> <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 -->
<?PHP
if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
{
?>
<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='';"><img src="../img/raz.gif" width="12" height="12" border="0" align="absmiddle"></a>
			</span> 
			 (heure :
				<select name="hrdv" id="hrdv">
				<?PHP
				if ($int_hrdv=="")
					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=substr(sec_heure($i),0,5);

					if ($int_hrdv == $heure)
						echo '<option value="'.$heure.'" selected>'.$heure.'</option>';
					else
						echo '<option value="'.$heure.'">'.$heure.'</option>';
				}
				?>
				</select>
			)		
			<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>
<?PHP } else { ?>
<input name="daterdvf" type="hidden" id="daterdvf" value="">
<input name="hrdv" type="hidden" id="hrdv" value="">
<?PHP } ?>
<!-- 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"))
		{ 
			$exist_rpbm=exist_rpbm_actif_site($td,$int_codecli,$int_code,$int_idsite);

			if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
			{
		?>
			<div id="boutmat">
			<table width="630"  border="0">
			<tr>
				<td>
					<input name="addpbm" type="button" class="bton_fmarr_std" 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.td.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" class="bton_fmarr_std" id="modmat" value="Modifier saisie" onClick="document.int_maj.mat.readOnly=false; document.int_maj.mat.focus(); this.style.backgroundColor='#00FFFF';">
				</td>
			</tr>
			</table>
			</div>
		<?PHP
			}
			
			if (($exist_rpbm == TRUE) AND (@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
			{
		?>
			<textarea name="mat" cols="95" rows="5" id="mat" readonly="readonly" onBlur="document.int_maj.mat.readOnly=true; document.int_maj.modmat.style.backgroundColor='#CCCCCC';"><?PHP echo htmlspecialchars($int_mat,ENT_QUOTES); ?></textarea>
		<?PHP
			}
			else
			{
		?>
			<textarea name="mat" cols="95" rows="5" id="mat"><?PHP echo htmlspecialchars($int_mat,ENT_QUOTES); ?></textarea>
		<?PHP
			}
		?>
			<img src="../img/oblig.gif" width="10" height="11" align="top"> 
		<?PHP
			if (($exist_rpbm == FALSE) AND (@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
			{
		?>
			<div id="notamat" class="annot_petit_it">Si vous avez choisi des probl&egrave;mes, ne saisissez pas de texte compl&eacute;mentaire dans celui g&eacute;n&eacute;r&eacute; par SMI, mais avant ou apr&egrave;s.</div>
			<script type="text/javascript">
			display('boutmat','none');
			display('notamat','none');
			</script>
		<?PHP
			}
		?>
		<?PHP } else { ?>
			<textarea name="mat" cols="95" rows="5" id="mat" readonly="readonly"><?PHP echo htmlspecialchars($int_mat,ENT_QUOTES); ?></textarea>
		<?PHP } ?>
	</td>
</tr>
</table>
<?PHP
if (@$_SESSION["niv_log"] >= 3)
{
?>
<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 htmlspecialchars($int_login) ?>" size="20">
			/
			<input name="mdpsys" type="text" id="mdpsys" value="<?PHP echo htmlspecialchars($int_mdpsys) ?>" size="20" onChange="verif_pw(this.value,true,'nivpw');">
		<?PHP } else { ?>
			<input name="login" type="text" id="login" value="<?PHP echo htmlspecialchars($int_login) ?>" size="20" readonly="1">
			/
			<input name="mdpsys" type="text" id="mdpsys" value="<?PHP echo htmlspecialchars($int_mdpsys) ?>" size="20" readonly="1">
		<?PHP } ?>
		<span id="nivpw"></span>
	</td>
</tr>
</table>
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_mdpbios"><div align="right">MDP BIOS </div></td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
			<input name="mdpbios" type="text" id="mdpbios" value="<?PHP echo htmlspecialchars($int_mdpbios) ?>" size="20">
		<?PHP } else { ?>
			<input name="mdpbios" type="text" id="mdpbios" value="<?PHP echo htmlspecialchars($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 ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
			{
		?>
			<div id="boutpbm">
			<table width="630"  border="0">
			<tr>
				<td>&nbsp;</td>
				<td align="right">
					<input name="modpbm" type="button" class="bton_fmarr_std" id="modpbm" value="Modifier saisie" onClick="document.int_maj.pbm.readOnly = false; document.int_maj.pbm.focus();  this.style.backgroundColor='#00FFFF';">
				</td>
			</tr>
			</table>
			</div>
		<?PHP
			}
		
			if (($exist_rpbm == TRUE) AND (@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
			{
		?>
			<textarea name="pbm" cols="95" rows="5" id="pbm" readonly="readonly" onBlur="document.int_maj.pbm.readOnly=true; document.int_maj.modpbm.style.backgroundColor='#CCCCCC';"><?PHP echo htmlspecialchars($int_pbm,ENT_QUOTES); ?></textarea>
		<?PHP
			}
			else
			{
		?>
			<textarea name="pbm" cols="95" rows="5" id="pbm"><?PHP echo htmlspecialchars($int_pbm,ENT_QUOTES); ?></textarea>
		<?PHP
			}
		?>
			<img src="../img/oblig.gif" width="10" height="11" align="top">
		<?PHP
			if (($exist_rpbm == FALSE) AND (@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
			{
		?>
			<div id="notapbm" class="annot_petit_it">Si vous avez choisi des probl&egrave;mes, ne saisissez pas de texte compl&eacute;mentaire dans celui g&eacute;n&eacute;r&eacute; par SMI, mais avant ou apr&egrave;s.</div>
			<script type="text/javascript">
			display('boutpbm','none');
			display('notapbm','none');
			</script>
		<?PHP
			}
		} else { ?>
			<textarea name="pbm" cols="95" rows="5" id="pbm" readonly><?PHP echo htmlspecialchars($int_pbm,ENT_QUOTES); ?></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"))
		{
			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 htmlspecialchars($int_fgar) ?>" size="30" readonly="1">
		<?PHP }
		}
		?>
	</td>
</tr>
</table>

<?PHP
if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
{
?>
<!-- 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" alt="Champ obligatoire"><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 } else { ?>
<input name="acpte" type="hidden" id="acpte" value="<?PHP echo $int_acpte ?>">
<?PHP } ?>

<?PHP if ($td <> "add") { ?>  
<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") AND  ((@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6)))
		{ 
			// 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_tecr();">
			<?PHP
				echo '<option value="">-- Choisissez un technicien --</option>';
				if ($int_codetec == "-1")
					echo "<option value=\"-1\" selected>-- Dossier non affect&eacute; --</option>";
				else
					echo "<option value=\"-1\">-- Dossier non affect&eacute; --</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" alt="Champ obligatoire"> 
			<?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);
}
		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>
		<?PHP
		if ((($td == "edit") OR ($td == "view")) AND  ((@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6)))
		{ 
			if ($td == "edit")
				$url_detinth = "inth_maj.php?td=add&ci=".$ci;
			else
				$url_detinth = "inth_maj.php?td=view&ci=".$ci;
		?>
			<textarea name="tect" cols="98" rows="2" id="tect" readonly="readonly" onclick="fen_deth_int('<?PHP echo $url_detinth; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');"><?PHP echo $str_tec_traitants; ?></textarea>
		<?PHP
		}
		else
		{
		?>
			<textarea name="tect" cols="98" rows="2" id="tect" readonly="readonly"><?PHP echo $str_tec_traitants; ?></textarea>
		<?PHP
		}
		?>
	</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>
		<!-- Détails internes du temps passé -->
		<?PHP
		if (($td == "edit") OR ($td == "view"))
		{ 
			if (($td == "edit") AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
				$url_detinth = "inth_maj.php?td=add&ci=".$ci;
			else
				$url_detinth = "inth_maj.php?td=view&ci=".$ci;
		?>
			<input name="duree" type="text" id="duree" value="<?PHP echo substr(sec_heure($int_durees),0,5) ?>" size="5" maxlength="5" readonly="1" onclick="fen_deth_int('<?PHP echo $url_detinth; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');"> 
			<a href="javascript:;" onclick="fen_deth_int('<?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="fen_deth_int('<?PHP echo $url_detinth; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> D&eacute;tails horaires &amp; techniciens</a>
		<?PHP
		}
		else
		{
		?>
			<input name="duree" type="text" id="duree" value="<?PHP echo substr(sec_heure($int_durees),0,5) ?>" size="5" maxlength="5" readonly="1"> 
		<?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(this.value)"> 
		)
		</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") AND  ((@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6)))
		{ 
			$url_traitepbm = "rpbmtt_maj.php?ci=".$int_code;
			
		?>
			<div id="boutfait">
			<table width="630"  border="0">
			<tr>
				<td>
					<input name="ttpbm" type="button" class="bton_fmarr_std" id="ttpbm" value="Probl&egrave;mes trait&eacute;s" onClick="fen_rpbmtt_int('<?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" class="bton_fmarr_std" id="modfait" value="Modifier saisie" onClick="document.int_maj.fait.readOnly = false; document.int_maj.fait.focus(); this.style.backgroundColor='#00FFFF';">
				</td>
			</tr>
			</table>
			</div>
		<?PHP
			if ($exist_rpbm == TRUE)
			{
		?>
			<textarea name="fait" cols="98" rows="5" id="fait" onChange="verif_fait();" onBlur="document.int_maj.fait.readOnly = true; document.int_maj.modfait.className='bton_fmarr_std';"><?PHP echo htmlspecialchars($int_fait,ENT_QUOTES) ?></textarea>
		<?PHP
			}
			else
			{
		?>
			<textarea name="fait" cols="98" rows="5" id="fait" onChange="verif_fait();"><?PHP echo htmlspecialchars($int_fait,ENT_QUOTES); ?></textarea>
		<?PHP
			}

			if ($exist_rpbm == FALSE)
			{
		?>
			<div id="notafait" class="annot_petit_it">Si vous avez trait&eacute; des probl&egrave;mes, ne saisissez pas de texte compl&eacute;mentaire dans celui g&eacute;n&eacute;r&eacute; par SMI, mais avant ou apr&egrave;s.</div>
			<script type="text/javascript">
			display('boutfait','none');
			display('notafait','none');
			</script>
		<?PHP
			}
		} 
		else 
		{ 
		?>
			<textarea name="fait" cols="98" rows="5" id="fait" readonly="1"><?PHP echo htmlspecialchars($int_fait,ENT_QUOTES) ?></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" readonly="1" onChange="verif_dprev();">
		<?PHP
		if (($td == "edit") AND  ((@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6)))
		{ 
		?>
		<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_codereg"><div align="right">R&egrave;glement</div></td>
    <td>
		<?PHP
		if (($td == "edit") AND  ((@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6)))
		{ 
		?>
			<select name="codereg" id="codereg">
			<?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" alt="Champ obligatoire"> 
        <?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="codereg" type="hidden" id="codereg" value="<?PHP echo $int_codereg ?>" size="50" maxlength="50" readonly="1">
	        <input name="nreg" type="text" id="nreg" 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" readonly="1" onChange="verif_dfin();">
		<?PHP
		if (($td == "edit") AND  ((@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6)))
		{ 
		?>
		<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 -->
  
<!-- Zone de saisie des articles et prestations -->
<?PHP
if (($td == "edit") OR ($td == "del") OR ($td == "view"))
{
	if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
	{
?>
	<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>
	<div id="detpdti">
	<?PHP
	$urlchoixart = "pdt_lst.php?ta=i&td=".$td."&cc=".$cc."&ci=".$ci;
	?>
	</div>
	<!-- 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 ((nb_art_in_int($ci) <> 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"))
			{
				foreach($pieces_hs as $key=>$value)
				{
					echo '<input type="radio" name="pieces_hs" style="background : #FFFFFF;" value="'.$key.'"';
					if ($key==$int_pces)
						echo ' checked';
					echo '>';
					echo " ".$value." ";
					if ($key<>(count($pieces_hs)-1))
						echo "/";
				}
			}
			else
			{
				echo $pieces_hs[$int_pces];
			}
			?>
			</span>
			</div>
			</td>
		</tr>
		</table>
	<?PHP 
	} 
	?>

	<!-- Lien d'ajout d'article ou de prestation-->
	<?PHP
	if ($td <> "del")
	{
		if (($td == "edit") AND (@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
		{
	?>
		<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>
		<br>
	<?PHP
		}
	}
	}
}
?>
<input name="totalint" type="hidden" id="totalint" value="<?PHP echo $totalint ?>">
<p align="center">
<?PHP
if (($td == "edit") OR ($td == "add"))
{
?>
	<input name="RAZ" type="reset" class="bton_fmarr_std" id="RAZ" value="R&eacute;initialiser">
	<input name="enr" type="submit" class="bton_fmarr_std" id="enr" value="Enregistrer">
<?PHP
	if (@$_SESSION["niv_log"] <> 2)
	{
?>
			<input name="enrimp" type="submit" class="bton_fmarr_std" id="enrimp" value="Enregistrer & Imprimer">
<?PHP
	} 
}
if ($td == "del") // Bouton si en mode suppression
{ 
?>
	<input name="del" type="submit" class="bton_fmarr_std" id="del" value="Supprimer">
<?PHP 
} 
?>
</p>
</form>
	
<?PHP 
if (($td <> "view") AND ($td<>"del"))
{
?>
	<script type="text/javascript">
	<?PHP
	if ($td=="add")
	{
	?>
	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          :    "Br",           // alignment (defaults to "Bl")
		electric	   :	false,
		singleClick    :    true
	});
	<?PHP
	}
	?>
	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          :    "Tr",           // alignment (defaults to "Bl")
		electric	   :	false,
		singleClick    :    true
	});
	<?PHP if (($td == "edit") AND  ((@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6)))
	{
	?>
	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          :    "Tr",           // alignment (defaults to "Bl")
		electric	   :	false,
		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          :    "Tr",           // alignment (defaults to "Bl")
		electric	   :	false,
		singleClick    :    true
	});
	<?PHP
	}
	?>
	</script>
<?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() ?>);
	warncpta(<?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">
		warncpta(<?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 (@$_SESSION["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 ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["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
		}
	}
}
include_once("pied.php");
?>
