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

Version 0.9.9

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

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

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

Contact : galawa@free.fr

Web : http://smitst.homelinux.com
****************************************************************************************/


// Vérification des tentatives de hack
$pos=strpos($_SERVER['PHP_SELF'],"inc.php");
if ($pos===FALSE)
	$ok_inc=TRUE;
else
	$ok_inc=FALSE;
if ($ok_inc==FALSE) header("Location: ../index.php");

include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_ot.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/fic_tac.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_statut.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

$tx = strip_tags(trim($_GET['tx'])); // Source de l'appel m:depuis le menu, i:depuis l'intervention
$td = strip_tags(trim($_GET['td'])); // Récupération type demande
$cc = strip_tags(trim($_GET['cc'])); // Récupération code Client
$ci = strip_tags(trim($_GET['ci'])); // Récupération code Intervention
$co = strip_tags(trim($_GET['co'])); // Récupération code Ordre de travail 
$si = strip_tags(trim($_GET['si'])); // Récupération id du site
$tr = strip_tags(trim($_GET['tr'])); // Récupération technicien responsable
$ca = strip_tags(trim($_GET['ca'])); // Récupération code agence

$pbm_ot = FALSE;
$pbm_cli=FALSE;

$msg1_err_type="Aucun sous-traitant pour cette spécialité dans ce département";

if (($tx<>"m") AND ($tx<>"i"))
	$pbm_ot=TRUE;
	
if ((@$_SESSION["niv_log"] <> 3) AND (@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 5) AND (@$_SESSION["niv_log"] <> 9) AND (@$_SESSION["niv_log"] <> 10) AND (@$_SESSION["niv_log"] <> 11))
	$pbm_ot=TRUE;

if ($ci<> "")
{
	// Récupération des informations Intervention
	$row = lit_enr_int($ci);
	if (is_array($row))
	{
		extract ($row);

		if (($int_codecli==$cc) AND ($int_idsite==$si))
		{
			$row2 = lit_enr_cli($int_codecli,TRUE);
			if (is_array($row2))
			{
				extract ($row2);
				if ($si>0)
				{
					$row3=lit_enr_scli_id($si,TRUE);
					if (is_array($row3))
					{
						extract ($row3);
						if ($scli_codecli<>$cc)
							$pbm_cli=TRUE;
					}
					else
						$pbm_cli = TRUE;
				}
				else
				{
					$scli_codepays=$cli_codepays;
					$scli_dep=$cli_dep;
				}
			}
			else
				$pbm_cli = TRUE;
		}
		else
			$pbm_cli = TRUE;
	}
	else
		$pbm_ot=TRUE;
}
else
{
	if ($tx=="i")
		$pbm_ot=TRUE;
	else
	{
		$row2 = lit_enr_cli($cc,TRUE);
		if (is_array($row2))
		{
			extract ($row2);
			if ($si>0)
			{
				$row3=lit_enr_scli_id($si,TRUE);
				if (is_array($row3))
				{
					extract ($row3);
					if ($scli_codecli<>$cc)
						$pbm_cli=TRUE;
				}
				else
					$pbm_cli = TRUE;
			}
			else
			{
				$scli_codepays=$cli_codepays;
				$scli_dep=$cli_dep;
			}
		}
		else
			$pbm_cli = TRUE;
	}
}

if (($pbm_ot==FALSE) AND ($pbm_cli==FALSE))
{
	if ($co <> "")
	{
		// Récupération des informations ordre
		$row = lit_enr_ot($co);
		if (is_array($row))
		{
			extract ($row);
			
			$ci=$ot_codeint;
			
			// Formatage des dates en français
			$ot_datecreaf = formatedate($ot_datecrea);
			$ot_datemodf = formatedate($ot_datemod);
			$ot_dateddef = formatedate($ot_datedde);
			$ot_daterdvf = formatedate($ot_daterdv);
			$ot_dateprevf = formatedate($ot_dateprev);
			$ot_datefinf = formatedate($ot_datefin);
			
			// Si intervention terminée, on force le mode "view"
			if ($ot_datefinf <> "")
				$td="view";
	
			// Récupération heure rdv
			$ot_hrdv = substr($ot_hrdv,0,5);
			if ($ot_daterdvf=="") // Si pas de RDV, pas d'heure possible...
				$ot_hrdv="";
	
			// 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 `" .TBOTH. "` WHERE `oth_codeot`= '".$co."'";
				$rs = mysql_query($rech) or die(mysql_error());
				if (mysql_num_rows($rs) <> 0)
				{
					while ($row = mysql_fetch_assoc($rs)) 
					{         
						$nbtotalsec = $nbtotalsec + diff_time_sec($row["oth_heurea"],$row["oth_heured"]);
						if ($row["oth_offert"] == 1)
							$nbtotalsecoff = $nbtotalsecoff + diff_time_sec($row["oth_heurea"],$row["oth_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 ($ot_durees <> $nbtotalsec)
				{
					$rech = "UPDATE `" .TBOT. "` SET `ot_datemod`='".$datea."', `ot_codemod`='".$codeuser."',`ot_durees`='".$nbtotalsec."'";
					$rech .=" WHERE `ot_code` = '".$co."'";
					$rs = mysql_query($rech) or die(mysql_error());
					$ot_durees = $nbtotalsec;
				}
		
				// Chaîne des techniciens traitants
				$rech = "SELECT DISTINCT oth_codetec FROM `" .TBOTH. "` WHERE `oth_codeot`= '".$co."'";
				$rs = mysql_query($rech) or die(mysql_error());
				if (mysql_num_rows($rs) <> 0)
				{
					while ($row = mysql_fetch_assoc($rs)) 
					{
						$rech2 = "SELECT tec_nom, tec_prenom FROM `" .TBTEC. "` WHERE `tec_code`= '".$row["oth_codetec"]."' ORDER BY tec_nom";
						$rs2 = mysql_query($rech2) or die(mysql_error());
						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);
			}

			if ($td <> "add")
			{
				// Contrôle qu'un sous-traitant n'essaye pas de "hacker" un ordre
				if (((@$_SESSION["niv_log"] == 11) OR (@$_SESSION["niv_log"] == 10)) AND ($ot_codest <> @$_SESSION["code_st"]))
					$pbm_ot = TRUE;
			}
		}
		else
			$pbm_ot = TRUE;
	}
	else
	{
		$td="add";
		$ot_dateddef = $datef;
		$ot_code = crecodesession("OR");
		$co = $ot_code;
		$ot_codest="";
		$ot_ccli=-1;
	}

	if (($tr<>"") AND ($tr<>"-1"))
	{
		switch (@$_SESSION["niv_log"])
		{
			case 3 :
			case 10 :
				if (@$_SESSION["code_log"]<>$tr)
					$pbm_ot=TRUE;
				break;
			case 4 :
				if ($ci<>"")
				{
					if ((@$_SESSION["code_age"]<>$int_codeage) AND (@$_SESSION["code_age"]<>$int_codeages))
						$pbm_ot=TRUE;
				}
				break;
			case 11 :
				$row=lit_enr_tec($tr,TRUE);
				if (is_array($row))
				{
					extract($row);
					if (@$_SESSION["code_st"]<>$tec_codest) $pbm_ot=TRUE;
				}
				else
					$pbm_ot=TRUE;
				break;
			default :
				break;
		}
	}
	else
	{
		if (($tx=="i") AND ($tr==""))
			$pbm_ot = TRUE;
	}
}

switch ($td)
{
	case "add" :
		$titre = "SAISIE BON DE TRAVAIL";
		// Si pas de code intervention -> A régulariser
		if ($ci=="") 
			$ci="--AR--";
		$ot_idsite=$si;
		break;
	case "edit" :
		$titre = "MISE A JOUR BON DE TRAVAIL";
		break;
	case "view" :
		$titre = "DETAIL BON DE TRAVAIL";
		break;
	case "del":
		$titre = "SUPPRESSION BON DE TRAVAIL";
		break;
	default:
		$titre = "PROBLEME";
		$pbm_ot=TRUE;
		break;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - <?PHP echo $title_esp_prive; ?> : Fiche Ordre Sous-Traitance</title>

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

<!-- Feuille de style & Script pour le menu -->

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

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

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

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

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

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscript/jscal/lang/calendar-<?PHP echo $_SESSION["lng"]; ?>.js"></script>

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="../jscript/jscal/calendar-setup.js"></script>
<!-- Fin de la définition Javascript pour calendrier popup -->


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


<?PHP 
if (($td == "edit")  OR ($td=="add"))
{
?>
<script language="javascript">
<!--
var tab1_champ=new Array(
	"nom:dateddef ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date demande ; stok:frmok ; stbad:frmbad",
	"nom:ccli; format:liste ; req:Y ; txt:Contact client ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
if ($td =="add")
{ 
?>
	"nom:codesp; format:listem ; req:Y ; txt:Spécialité ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
	if ((@$_SESSION["niv_log"] <> 10) AND (@$_SESSION["niv_log"] <> 11))
	{
?>
	"nom:codest; format:liste ; req:Y ; txt:Sous-traitant ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP }} else {
	if ((@$_SESSION["niv_log"] <> 10) AND (@$_SESSION["niv_log"] <> 11))
	{
?>
	"nom:codest; format:txt ; req:Y ; txt:Sous-traitant ; stok:frmok ; stbad:frmbad",
<?PHP } } ?>
	"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:liste ; 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 ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
	{
		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",
<?PHP
		}
	}
?>
	"nom:pbm; format:txt ; req:Y ; txt:Travail à effectuer; 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,$ot_acpte,""); ?>

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

<?PHP if (($pbm_ot==FALSE) AND ($pbm_cli==FALSE) AND ($td=="add")) { ?>
<script type="text/javascript">
<!--        
function updatest()
{
	stUpdater = new SelectUpdater("codest", "<?PHP echo $rep_appli.'/ajax/'; ?>recupst.php?sp=", "attn1", "msg1", "<?PHP echo $msg1_err_type; ?>");
	anciensp = "";
	var txthtml = "<option><?PHP echo $sel_lst_makechx; ?></option>\n";
	document.getElementById("codesp").onchange = function() {
		var listesp = document.getElementById("codesp");
		if (listesp.options.length>0)
		{
			var payscli = document.getElementById("payscli").value;
			var depcli = document.getElementById("depcli").value;
			var txtsp = "";
			var txtspfinal = "";
			var toutes=false;
			for (var i=1; i<listesp.options.length; i++)
			{
				if (listesp.options[i].selected) 
				{
					if (listesp.options[i].value=='*')
					{
						toutes=true;
					}
					txtsp += listesp.options[i].value+"_";
				} 
			}
			txtspfinal = txtsp.substring(0,txtsp.length-1);
		}
		
		if (txtspfinal.length > 0)
		{
			if ((txtspfinal!='*') && (toutes==true))
			{
				alert('Toutes doit être sélectionné seul');
				// Remettre la liste a vide et annuler l'appel eventuel
				stUpdater.reset();
				listesp.options[0].selected=true;
				for (var i=1; i<listesp.options.length; i++)
				{
					listesp.options[i].selected=false;
				}
				document.getElementById("codest").innerHTML=txthtml;
				document.getElementById("attn1").innerHTML = "";
				document.getElementById("msg1").innerHTML = "<?PHP echo $msg1_err_type; ?>";
				anciensp = "";
			}
			else
			{
				if (txtspfinal != anciensp)
				{
					// Faire l'appel Ajax
					var prmget=payscli+"_"+depcli+"_"+txtspfinal;
					stUpdater.run(prmget);
					anciensp = txtspfinal;
				}
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			stUpdater.reset();
			document.getElementById("codest").innerHTML=txthtml;
			document.getElementById("attn1").innerHTML = "";
			document.getElementById("msg1").innerHTML = "<?PHP echo $msg1_err_type; ?>";
			anciensp = "";
		}
	}
}
//-->
</script>
<?PHP } ?>

</head>

<?PHP 
if ((nb_cli("") <>0) AND (nb_st_actifs() <> 0) AND (nb_statuts() <> 0) AND (nb_lieux() <> 0) AND (nb_civ() <> 0))
{
	switch ($td)
	{
		case "del" :
			echo "<body onload=\"metReadonly();warndel();";
			if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
				echo "tst_aff_tpsoff(document.ot_maj.dureeoff.value);";
			echo "\">";
			break;
		case "view" :
			echo "<body onload=\"metReadonly();";
			if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
				echo "tst_aff_tpsoff(document.ot_maj.dureeoff.value);";
			echo "\">";
			break;
		case "add" :
			echo "<body onLoad=\"metFocus();updatest();\">";
			break;
		case "edit" :
			echo "<body onLoad=\"metFocus();";
			if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
				echo "tst_aff_tpsoff(document.ot_maj.dureeoff.value);";
			echo "\">";
			break;
	}
}
else
	echo "<body>";

if ($tx == "m") 
	include_once("../inc/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, un statut, un lieu, une civilité, un technicien dans l'agence, et un mode de règlement -->
<?PHP
if (($pbm_ot == FALSE) AND ($pbm_cli == FALSE))
{
	if ((nb_cli("") <>0) AND (nb_st_actifs() <> 0) AND (nb_statuts() <> 0) AND (nb_lieux() <> 0) AND (nb_civ() <> 0))
	{
?>
<table width="100%"  border="0">
<tr>
	<td width="33%">
	<?PHP 
	if ($tx=="i") 
	{ 
		$url_retliste="ot_lst.php?td=".$td."&tx=".$tx."&ca=".$ca."&ci=".$ci."&tl=2&cc=".$cc."&si=".$si."&tr=".$tr."&co=&ord=DES&tri=Code";
	?>
    <input name="quit" type="button" class="bton_std" id="quit" value="<?PHP echo $but_quit; ?>" style="text-decoration: none; font-size: 11px; color:White ;font-weight:bold;background-color: #666666;" onClick="javascript:; self.close();">
     <input name="lst" type="button" class="bton_std" id="lst" value="<?PHP echo $txt_lnk_ret_liste; ?>" style="text-decoration: none; font-size: 11px; color:White ;font-weight:bold;background-color: #666666;" onClick="javascript:; window.location=('<?PHP echo $url_retliste; ?>');">
	<?PHP } else { 
		$url_retliste="ot_lst.php?tx=".$tx."&tl=2&ord=DES&tri=Code";
	?>
	<strong><em><a href="<?PHP echo $url_retliste; ?>"><?PHP echo $txt_lnk_ret_liste; ?></a></em></strong>
	<?PHP } ?>
	</td>
	<td width="33%" valign="top" align="center" class="annot_std_gras">
	<?PHP 
	if ($ci<>"--AR--")
	{
		if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
			echo "Rattach&eacute; &agrave; l'intervention ".$ci;
		else
			echo "&nbsp;";
	}
	else
		echo "A r&eacute;gulariser";
	?>
	</td>
	<td width="33%">
	<div align="right">
	<?PHP if (($td == "edit") OR ($td == "view")) 
		{
		$urlimp1 = "ot_pdf.php?co=".$co;
		?>
        <a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp1; ?>');")><img src="../img/print.png" title="Imprimer" border="0" align="absmiddle"></a> 
		<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp1; ?>');")> Imprimer</a> 
	<?PHP } ?>
    </td>
</tr>
</table>
<?PHP 
if (($td == "edit")  OR ($td=="add"))
{
?>
<form name="ot_maj" method="post" action="ot_enr.php" onSubmit="javascript:; return (verif_ot(this,tab1_champ,'',''));">
<?PHP } else { ?>
<form name="ot_maj" method="post" action="ot_enr.php">
<?PHP } ?>
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="tx" type="hidden" id="tx" value="<?PHP echo $tx ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="codeint" type="hidden" id="codeint" value="<?PHP echo $ci ?>">
<input name="ca" type="hidden" id="ca" value="<?PHP echo $ca ?>">
<input name="cc" type="hidden" id="cc" value="<?PHP echo $cc ?>">
<input name="si" type="hidden" id="si" value="<?PHP echo $si ?>">
<input name="tr" type="hidden" id="tr" value="<?PHP echo $tr ?>">
<input name="co" type="hidden" id="co" value="<?PHP echo $co ?>">
<?PHP if ($td == "add") { ?>
<input name="code" type="hidden" id="code" value="<?PHP echo $ot_code ?>">
<input name="payscli" type="hidden" id="payscli" value="<?PHP echo $scli_codepays ?>">
<input name="depcli" type="hidden" id="depcli" value="<?PHP echo $scli_dep ?>">
<?PHP } ?>

<!-- Date de demande -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_dateddef" align="right">Date Demande </td>
	<td>
		<input name="dateddef" type="text" id="dateddef" value="<?PHP echo $ot_dateddef; ?>" size="10" maxlength="10" readonly="1">
		<?PHP if ($td == "add") { ?>
		<img src="../img/calendar.png" align="absmiddle" id="f_img_dateddef" title="<?PHP echo $alt_chxdate; ?>">
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } ?>
	</td>
	<td align="right">
	<?PHP
	if ((((@$_SESSION["niv_log"] ==5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($td=="edit")) AND ($tx=="m"))
	{
		echo '<span id="strtac" style="visibility:visible">';
		$nb_tac=nb_tac(6,$ot_code,TRUE);
		if ($nb_tac>0)
		{
			echo "<span class=\"annot_petit_it\">";
			echo "( ".$nb_tac." t&acirc;che";
			if ($nb_ot>1)
				echo"s";
			$nb_tac_actives=nb_tac_actives(6,$ot_code,TRUE);
			if ($nb_tac_actives>0)
				echo ", dont ".$nb_tac_actives." non termin&eacute;e";
			if ($nb_tac_actives>1)
				echo "s";
			echo")";
			echo "</span>";
		}
		else
		{
			echo "<span class=\"annot_petit_gras\">";
			echo "T&acirc;ches : ";
			echo "</span>";
		}
		echo '</span>';

	?>
		<select class="annot_petit" name="tac" size="1" id="tac" onChange="javascript:; document.location.href=this.value">
		<option value="" class="annot_petit">--- Faites votre choix ---</option>
		<?PHP if ($nb_tac>0) { ?>
		<option value="<?PHP echo "tac_lst.php?ord=DES&tri=Code&fi=8&search=".$ot_code;?>" class="annot_petit">Voir les tâches</option>
		<?PHP } ?>
		<option value="<?PHP echo "tac_maj.php?td=add&tr=6&cr=".$ot_code;?>" class="annot_petit">Ajouter tâche</option>
		</select>
	<?PHP
	}
	else
		echo "&nbsp;";
	?>
	</td>
</tr>
</table>

<!-- Code de l'ordre (affiché uniquement si édition ou suppression) -->
<?PHP if ($td <> "add") {?>
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_codeint" align="right">Code </td>
	<td>
		<input name="code" type="text" id="code" value="<?PHP echo $ot_code ?>" size="20" maxlength="20" readonly="1">
		<?PHP 
		if (((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5)  OR (@$_SESSION["niv_log"] == 9)) AND ($ot_codeint=="--AR--")) 
			echo '<span class="annot_gras_it"> A r&eacute;gulariser</span>';
		?>
	</td>
</tr>
</table>
<?PHP }  ?>

<!-- Code de l'agence qui gère le client -->
<?PHP 
if (((@$_SESSION["niv_log"] == 10) OR (@$_SESSION["niv_log"] == 11) OR (@$_SESSION["niv_log"] == 5)  OR (@$_SESSION["niv_log"] == 9))) { ?>
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_codeint" align="right">G&eacute;r&eacute; par</td>
	<td>
	<?PHP
	$txt_age="";
	$row = lit_enr_age($cli_prop,TRUE);
	if (is_array($row))
	{
		extract($row);
		$txt_age=$age_nom." (".$age_telf.")";
	}
	?>
		<input name="codeage" type="text" id="codeage" value="<?PHP echo $txt_age ?>" size="70" maxlength="70" readonly="1">
	</td>
</tr>
</table>
<?PHP }  ?>

<!-- Code du sous-traitant (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
<table width="100%"  border="0">
<?PHP
if ($td =="add")  // Ajout = zone modifiable (on peut choisir un sous-traitant)
{ 
?>
<tr>
	<td width="160" class="rubfrm" id="f_agence" align="right">Sp&eacute;cialit&eacute;</td>
	<td>
	<?PHP
	// Création de la liste des spécialités
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	// Filtre sur agences ouvertes
	$rech = "SELECT * FROM ".TBSP." ORDER BY sp_desc";
	$rs = mysql_query($rech) or die(mysql_error());

	?>
	<select name="codesp" id="codesp" multiple="multiple" size="3">
	<?PHP
		echo "<option>".$sel_lst_makechx."</option>";
		echo "<option value=\"*\">Toutes les spécialités</option>";

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

			$sp_nomcode = $sp_desc." (".$sp_code.")";
			echo '<option value="'.$sp_code.'">'.$sp_nomcode.'</option>';
		}
	?>
	</select>
	 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	 <br />
	<span class="annot_petit_it">
	(Vous pouvez en s&eacute;lectionner plusieur avec Ctrl + clic gauche)
	</span>
	<?PHP
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	</td>
</tr>
<?PHP } 

if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
{
?>
<tr>
	<td width="160" class="rubfrm" id="f_agence" align="right">Sous-traitant</td>
	<td>
		<?PHP
		if ($td =="add")  // Ajout = zone modifiable (on peut choisir un sous-traitant)
		{ 
			if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
			{
		?>
				<select name="codest" id="codest">
				<option><?PHP echo $sel_lst_makechx; ?></option>
				</select>
				 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				 <br />
				<span id="attn1"></span><span id="msg1" class="ptitre_std_gras_jaune_frouge"><?PHP echo htmlspecialchars($msg1_err_type)?></span>
		<?PHP
			}
			else
			{
				$row = lit_enr_st($_SESSION["code_st"]);
				extract ($row);
				$st_nomcode = $st_nom." (".$st_code.")";
			?>
				<input name="codest" type="hidden" id="codest" value="<?PHP echo $_SESSION["code_st"]; ?>">
				<input name="nst" type="text" id="nst" value="<?PHP echo $st_nomcode; ?>" size="50" maxlength="50" readonly="1">
			<?PHP
			}	
		} 
		else  // Edition ou suppression = zone non modifiable (affichage seul)
		{
			$row = lit_enr_st($ot_codest);
			extract($row);
			$st_nomcode = $st_nom." (".$st_code.")";
		?>
		<input name="codest" type="hidden" id="codest" value="<?PHP echo $ot_codest; ?>">
		<input name="nst" type="text" id="nst" value="<?PHP echo $st_nomcode ?>" size="50" maxlength="50" readonly="1">
		<?PHP 
		} 
		?>
	</td>
</tr>
<?PHP 
}
?>
</table>

<!-- Affichage du client -->
<table width="100%"  border="0">
<tr>
	<td class="rubfrm" id="f_codecli" align="center" colspan="2">Client </td>
</tr>
</table>

<!-- Détails client -->
<table width="100%"  border="0">
<tr>
	<?PHP
	if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5)  OR (@$_SESSION["niv_log"] == 9))
	{
	?>
	<td width="50%" align="center" valign="bottom" class="ent_clisite">Compte client</td>
	<?PHP
	}
	?>
	<td align="center" valign="bottom" class="ent_clisite">Site d'intervention</td>
</tr>
<tr>
	<?PHP
	if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5)  OR (@$_SESSION["niv_log"] == 9))
	{
	?>
	<td width="50%" valign="top" bgcolor="#C5CED7">
	<?PHP
	echo "<span class=\"annot_std_gras\">";
	if ($cli_ste <>"") 
		echo $cli_ste."<br />";
	else
		echo $cli_civilite." ".$cli_prenom." ".$cli_nom."<br />";
	echo "</span>";
	echo $cli_adr1."<br />";
	if ($cli_adr2 <>"") 
		echo $cli_adr2."<br />";
	echo Retournecp_openId($cli_ville,TRUE)." ".Retourneville_openId($cli_ville,TRUE)."<br />";
	echo "Tel : ".$cli_telf."<br />";
	?>
	</td>
	<?PHP } ?>
	<td valign="top" bgcolor="#C5CED7">
	<div id="nomsite">
	<?PHP
	switch (@$_SESSION["niv_log"])
	{
		case 10 :
		case 11 :
			if ($si<>0)
				echo nom_scli($si,TRUE,TRUE,FALSE);
			else
			{
				$row=lit_enr_cli($ot_codecli,TRUE);
				if (is_array($row))
				{
					extract($row);
					$nom_site.="<strong>";
					if ($cli_ste<>"")
						$nom_site.= $cli_ste."<br />";
					else
						$nom_site.= $cli_civilite." ".$cli_prenom." ".$cli_nom."<br />";
					$nom_site.="</strong>";
					$nom_site.= $cli_adr1."<br />";
					if ($cli_adr2<>"")
						$nom_site.= $cli_adr2."<br />";
					$nom_site.= Retournecp_openId($cli_ville,TRUE)." ".Retourneville_openId($cli_ville,TRUE)."<br />";
					$nom_site.= "Tel : ".$cli_telf;
				}
				echo $nom_site;
			}
			break;
		default :
			echo nom_scli($si,TRUE,TRUE,FALSE);
			break;
	}
	?>
	</div>
	</td>
</tr>
</table>

<!-- Contact client -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_ccli" align="right">Contact client</td>
	<td>
		<?PHP
		if (($td =="add") OR ($td =="edit"))  // Ajout ou édition = zone modifiable (on peut choisir un contact)
		{ 
			if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
			{
				if ($cli_ste <>"")
				{
					// Création de la liste des contacts du client
					echo '<select name="ccli" id="ccli">';
					echo "<option value=\"\">-- Choisissez un  contact --</option>";
					$txt_ccli = $cli_nom." ".$cli_prenom." (Contact principal";
					$txt_ccli.= " - ".$cli_telf.")";
					echo '<option value="-1"';
					if (intval($ot_ccli) == -1)
						echo ' selected';
					echo '>'.$txt_ccli.'</option>';
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);

					// Données site client
					if (intval($ot_idsite)>0)
					{
						$rech = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_id` = '$ot_idsite'";
						$rs = mysql_query($rech)or die(mysql_error());
						if ($resultat = mysql_fetch_array($rs)) 
						{
							extract($resultat);
							$txt_ccli = $scli_rnom." ".$scli_rprenom." (Contact site";
							$txt_ccli.= " - ".$scli_telf.")";
							echo '<option value="0"';
							if (intval($ot_ccli) == 0)
								echo ' selected';
							echo '>'.$txt_ccli.'</option>';
						}
						mysql_free_result($rs);
					}
					// Filtre sur client
					$rech = "SELECT * FROM ".TBCCLI." WHERE `ccli_codecli` = '".$cli_code."' ORDER BY ccli_nom";
					$rs = mysql_query($rech) or die(mysql_error());
					if (mysql_num_rows($rs) <> 0)
					{
						while ($resultat = mysql_fetch_array($rs)) 
						{
							extract($resultat);
			
							$txt_ccli = $ccli_nom." ".$ccli_prenom;
							$row2=lit_enr_fonc($ccli_codefonc,FALSE);
							if (is_array($row2))
							{
								extract($row2);
								$txt_fonc=$fonc_desc;
							}
							else
								$txt_fonc=$ccli_codefonc;
							$txt_ccli.=" (".$txt_fonc;
							$txt_ccli.= " - ".$ccli_telf.")";
							echo '<option value="'.$ccli_id.'"';
							if (intval($ot_ccli) == $ccli_id)
								echo ' selected';
							echo '>'.$txt_ccli.'</option>';
						}
					}
					mysql_free_result($rs);
					mysql_close($conn);
					echo '</select>';
					echo '<img src="../img/oblig.png" align="absmiddle" alt="'.$alt_chp_oblig.'">';
				?>
					<a href="javascript:;" onclick="fen_ccli_ot('<?PHP echo $cli_code; ?>');"><img src="../img/ctacts.png" border="0" align="absmiddle"></a>
					<a href="javascript:;" onclick="fen_ccli_ot('<?PHP echo $cli_code; ?>');"> Ajouter un contact </a>
				<?PHP
				}
				else
				{
					$txt_ccli="";
					$row = lit_enr_ccli_id_in_cli($ot_ccli,$cli_code);
					if (is_array($row))
					{
						extract ($row);
						$txt_ccli = $ccli_nom." ".$ccli_prenom;
						$row2=lit_enr_fonc($ccli_codefonc,TRUE);
						if (is_array($row2))
						{
							extract($row2);
							$txt_fonc=$fonc_desc;
						}
						else
							$txt_fonc=$ccli_codefonc;
						$txt_ccli.=" (".$txt_fonc;
						$txt_ccli.= " - ".$ccli_telf.")";
					}
					else
						$txt_ccli="Pas de contact";
				?>
				<input name="ccli" type="hidden" id="ccli" value="<?PHP echo $ot_ccli; ?>">
				<input name="nccli" type="text" id="nccli" value="<?PHP echo $txt_ccli; ?>" size="100" maxlength="100" readonly="1">
			<?PHP
				}	
			}
			else
			{
				$txt_ccli="Pas de contact";
				switch (intval($ot_ccli))
				{
					case -1 :
						$txt_ccli = $cli_nom." ".$cli_prenom." (Contact principal";
						$txt_ccli.= " - ".$cli_telf.")";
						break;
					case 0 :
						$row = lit_enr_scli_id($ot_idsite,TRUE);
						if (is_array($row))
						{
							extract ($row);
							$txt_ccli = $scli_rnom." ".$scli_rprenom." (Contact site";
							$txt_ccli.= " - ".$scli_telf.")";
						}
						break;
					default :
						$row = lit_enr_ccli_id_in_cli($ot_ccli,$cli_code);
						if (is_array($row))
						{
							extract ($row);
							$txt_ccli = $ccli_nom." ".$ccli_prenom;
							$row2=lit_enr_fonc($ccli_codefonc,TRUE);
							if (is_array($row2))
							{
								extract($row2);
								$txt_fonc=$fonc_desc;
							}
							else
								$txt_fonc=$ccli_codefonc;
							$txt_ccli.=" (".$txt_fonc;
							$txt_ccli.= " - ".$cli_telf.")";
						}
						break;
				}
			?>
				<input name="ccli" type="hidden" id="ccli" value="<?PHP echo $ot_ccli; ?>">
				<input name="nccli" type="text" id="nccli" value="<?PHP echo $txt_ccli; ?>" size="100" maxlength="100" readonly="1">
			<?PHP
			}	
		} 
		else  // Vue ou suppression = zone non modifiable (affichage seul)
		{
			$txt_ccli="Pas de contact";
			switch (intval($ot_ccli))
			{
				case -1 :
					$txt_ccli = $cli_nom." ".$cli_prenom." (Contact principal";
					$txt_ccli.= " - ".$cli_telf.")";
					break;
				case 0 :
					$row = lit_enr_scli_id($ot_idsite,TRUE);
					if (is_array($row))
					{
						extract ($row);
						$txt_ccli = $scli_rnom." ".$scli_rprenom." (Contact site";
						$txt_ccli.= " - ".$ccli_telf.")";
					}
					break;
				default :
					$row = lit_enr_ccli_id_in_cli($ot_ccli,$cli_code);
					if (is_array($row))
					{
						extract ($row);
						$txt_ccli = $ccli_nom." ".$ccli_prenom;
						$row2=lit_enr_fonc($ccli_codefonc,TRUE);
						if (is_array($row2))
						{
							extract($row2);
							$txt_fonc=$fonc_desc;
						}
						else
							$txt_fonc=$ccli_codefonc;
						$txt_ccli.=" (".$txt_fonc;
						$txt_ccli.= " - ".$cli_telf.")";
					}
					break;
			}
			echo '<input name="ccli" type="hidden" id="ccli" value="'.$o_ccli.'">';
			echo '<input name="nccli" type="text" id="nccli" value="'.$txt_ccli.'" size="100" maxlength="100" readonly="1">';
		} 
		?>
	</td>
</tr>
</table>

<!-- Paramètres de la demande -->
<table width="100%"  border="0">
  <tr>
    <td width="160" class="rubfrm" id="f_statut" align="right">Statut </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);
				// Pour clore, il faut remplir la date de cloture
				// Pas d'attente de commande client pour un ordre
				if (($statut_code <> "CLOT") AND ($statut_code <> "ACC"))
				{
					if ($ot_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.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
        <?PHP
		}
		else // Si c'est clot, on se contente d'afficher le statut
		{
			$txt_statut = "";
			if ($ot_codestatut <> "")
			{
				$row = lit_enr_statut($ot_codestatut);
				if (is_array($row))
				{
					extract($row);
					$txt_statut = $statut_desc;
				}
			}
			if ($txt_statut<>"")
			{
		?>
			<input name="codestatut" type="hidden" id="codestatut" value="<?PHP echo $ot_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" align="right">Lieu </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=\"warnlieu2();\"";?>>
			<?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) or die(mysql_error());
	
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
	
				if ($ot_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.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> 
        <?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` = '".$ot_codelieu."'";
			$rs = mysql_query($rech) or die(mysql_error());
			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 $ot_codelieu ?>" size="50" maxlength="50" readonly="1">
	        <input name="lieu" type="text" id="lieu" value="<?PHP echo $lieu_desc ?>" size="50" maxlength="50" readonly="1">
        <?PHP
		}
		?>
	</td>
  </tr>
  <tr>
    <td class="rubfrm" id="f_urg" align="right">Niveau d'urgence </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 ($ot_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.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> <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 $ot_urg ?>" size="50" maxlength="50" readonly="1">
	        <input name="urg" type="text" id="urg" value="<?PHP echo $niv_urgence[$ot_urg] ?>" size="50" maxlength="50" readonly="1">
        <?PHP
		}
		?>	</td>
  </tr>
</table>

<!-- Date de RDV -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_rdv" align="right">Date RDV </td>
	<td>
		<input name="daterdvf" type="text" id="daterdvf" value="<?PHP echo $ot_daterdvf ?>" size="10" maxlength="10" readonly="1" onChange="warn_rdv2();">
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
			<img src="../img/calendar.png" align="absmiddle" id="f_img_daterdvf" title="<?PHP echo $alt_chxdate; ?>">
			<span class="annot_std_gras">
			<a href="javascript:;" onclick="document.ot_maj.daterdvf.value='';document.ot_maj.hrdv.value='';"><img src="../img/raz.png" border="0" align="absmiddle"></a>
			</span> 
			 (heure :
				<select name="hrdv" id="hrdv">
				<?PHP
				if ($ot_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=heure_to_hhmm(sec_heure($i));

					if ($ot_hrdv == $heure)
						echo '<option value="'.$heure.'" selected>'.$heure.'</option>';
					else
						echo '<option value="'.$heure.'">'.$heure.'</option>';
				}
				?>
				</select>
			)		
			<a href="javascript:;" onclick="document.ot_maj.hrdv.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
		<?PHP } else { ?>
			 (heure :
			<input name="hrdv" type="text" id="hrdv" value="<?PHP echo heure_to_hhmm($ot_hrdv); ?>" size="5" maxlength="8" readonly="1">
			)
		<?PHP } ?>
        <span class="annot_petit_it">hh:mm</span></td>
</tr>
</table>

<!-- Matériel et problème de la demande -->
<table width="100%"  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"))
	{ 
	?>
	<textarea name="mat" rows="5" id="mat"><?PHP echo htmlspecialchars($ot_mat,ENT_QUOTES); ?></textarea>
	 <img src="../img/oblig.png" align="absmiddle" align="top"> 
	<?PHP } else { ?>
		<textarea name="mat" rows="5" id="mat" readonly="readonly"><?PHP echo htmlspecialchars($ot_mat,ENT_QUOTES); ?></textarea>
	<?PHP } ?>
	</td>
</tr>
</table>

<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_pbm">
	<div align="right">Travail &agrave; effectuer</div>
	</td>
	<td>
	<?PHP
	if (($td == "add") OR ($td == "edit"))
	{
	?>
	<textarea name="pbm" rows="5" id="pbm"><?PHP echo htmlspecialchars($ot_pbm,ENT_QUOTES); ?></textarea>
	 <img src="../img/oblig.png" align="absmiddle" align="top">
	<?PHP } else { ?>
	<textarea name="pbm" rows="5" id="pbm" readonly><?PHP echo htmlspecialchars($ot_pbm,ENT_QUOTES); ?></textarea>
	<?PHP } ?>
	</td>
</tr>
</table>

<!-- Intervention sous garantie ou pas ? -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_gar" align="right">Garantie</td>
	<td>
	<?PHP
	if (($td == "add") OR ($td == "edit"))
	{
		if ($ot_gar == 0)
		{
		?>
			<select name="gar" id="gar" onChange="verif_gar2(this.value);">
			<option value="0" selected><?PHP echo $sel_lst_non; ?></option>
			<option value="1"><?PHP echo $sel_lst_oui; ?></option>
			</select>
		<?PHP
		}
		else
		{
		?>
			<select name="gar" id="gar" onChange="verif_gar2(this.value);">
			<option value="0"><?PHP echo $sel_lst_non; ?></option>
			<option value="1" selected><?PHP echo $sel_lst_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 $ot_fgar ?>" size="30" maxlength="30" onBlur="verif_fgar2(this.value)"> 
		<span class="annot_petit_it"> (Obligatoire si garanti)</span>	
   <?PHP 
   } 
   else 
   { 
		if ($ot_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($ot_fgar) ?>" size="30" readonly="1">
	<?PHP }
	}
	?>
	</td>
</tr>
</table>

<?PHP
$aff_ok=TRUE;
$modif_ok=TRUE;
switch ($td)
{
	case "add" :
		$aff_ok=FALSE;
	default :
		switch (@$_SESSION["niv_log"])
		{
			case 3 :
				$modif_ok=FALSE;
				if ($tr<>@$_SESSION["code_log"])
					$aff_ok=FALSE;
				break;
			case 4 :
				$modif_ok=FALSE;
				if (($tr<>"") AND ($tr<>"-1"))
				{
					$row=lit_enr_tec($tr,TRUE);
					if (is_array($row))
					{
						extract($row);
						if ($tec_codeage<>@$_SESSION["code_log"])
							$aff_ok=FALSE;
					}
				}
				break;
			default :
				break;
		}
		break;
}

if ($aff_ok == TRUE) {
?>
<br />
<!-- Technicien Responsable -->
<table width="100%"  border="0">
  <tr>
    <td width="160" class="rubfrm" id="f_codetec" align="right">Responsable dossier</td>
    <td>
	<?PHP
	if (($td == "edit") AND ($modif_ok==TRUE))
	{ 
		// Création de la liste des Techniciens du sous-traitant
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM ".TBTEC." WHERE `tec_codest` = '$ot_codest' ORDER BY tec_nom";
		$rs = mysql_query($rech) or die(mysql_error());

		if (mysql_num_rows($rs) <> 0)
		{
		?>
			<select name="codetec" id="codetec" onChange="verif_tec2();">
		<?PHP
			echo '<option value="">'.$sel_lst_tec.'</option>';
			if ($ot_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 ($ot_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.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> 
		<?PHP
		}
		else
		{
		?>
			<select name="codetec" id="codetec">
			<option>-- Pas de technicien actif --</option>
			</select>
		<?PHP
		}
		mysql_free_result($rs);
		mysql_close($conn);
	}
	else
	{
		$row = lit_enr_tec($ot_codetec,TRUE);
		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 $ot_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="100%"  border="0">
  <tr>
    <td width="160" class="rubfrm" id="f_tect" align="right">Technicien(s) traitant(s) </td>
    <td>
	<?PHP
	if (($td == "edit") OR ($td == "view"))
	{ 
		if ($td == "edit")
		{
			if ($modif_ok==TRUE)
				$url_detoth = "oth_maj.php?td=add&co=".$co;
			else
				$url_detoth = "oth_maj.php?td=view&co=".$co;
		}
		else
			$url_detoth = "oth_maj.php?td=view&co=".$co;
	?>
		<textarea name="tect" rows="2" id="tect" readonly="readonly" onclick="fen2_deth_ot('<?PHP echo $url_detoth; ?>',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" rows="2" id="tect" readonly="readonly"><?PHP echo $str_tec_traitants; ?></textarea>
	<?PHP
	}
	?>
	</td>
  </tr>
</table>

<!-- Travail effectué -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_duree" align="right">Temps travaill&eacute;</td>
	<td>
	<!-- Détails internes du temps passé -->
	<?PHP
	if (($td == "edit") OR ($td == "view"))
	{ 
		if ($td == "edit")
		{
			if ($modif_ok==TRUE)
				$url_detoth = "oth_maj.php?td=add&co=".$co;
			else
				$url_detoth = "oth_maj.php?td=view&co=".$co;
		}
		else
			$url_detoth = "oth_maj.php?td=view&co=".$co;
	?>
		<input name="duree" type="text" id="duree" value="<?PHP echo heure_to_hhmm(sec_heure($ot_durees,3,TRUE)); ?>" size="6" maxlength="6" readonly="1" onclick="fen2_deth_ot('<?PHP echo $url_detoth; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');"> 
		<a href="javascript:;" onclick="fen2_deth_ot('<?PHP echo $url_detoth; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/clock.png" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="fen2_deth_ot('<?PHP echo $url_detoth; ?>',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 heure_to_hhmm(sec_heure($ot_durees,3,TRUE)) ?>" size="6" maxlength="6" 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 heure_to_hhmm(sec_heure($nbtotalsecoff),3,TRUE) ?>" size="6" maxlength="6" 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" align="right">Travail effectu&eacute; </td>
	<td>
	<?PHP
	if (($td == "edit") AND ($modif_ok==TRUE))
	{ 
	?>
		<textarea name="fait" rows="5" id="fait" onChange="verif_fait2();"><?PHP echo htmlspecialchars($ot_fait,ENT_QUOTES); ?></textarea>
	<?PHP
	} 
	else 
	{ 
	?>
		<textarea name="fait" rows="5" id="fait" readonly="1"><?PHP echo htmlspecialchars($ot_fait,ENT_QUOTES) ?></textarea>
	<?PHP 
	}
	?>
	</td>
</tr>
</table>

<!-- Date d'appel de l'agence une fois le dossier traité -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_dateprevf" align="right">Agence pr&eacute;venue  le </td>
	<td>
		<input name="dateprevf" type="text" id="dateprevf" value="<?PHP echo $ot_dateprevf ?>" size="10" readonly="1" onChange="verif_dprev2();">
	<?PHP
	if (($td == "edit") AND ($modif_ok==TRUE))
	{ 
	?>
	<img src="../img/calendar.png" align="absmiddle" id="f_img_dateprevf" title="<?PHP echo $alt_chxdate; ?>">
	<a href="javascript:;" onclick="document.ot_maj.dateprevf.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a>
	<?PHP } ?>
	</td>
</tr>
</table>

<!-- Date de clôture du dossier -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_datefinf" align="right">Dossier cl&ocirc;t le </td>
	<td>
		<input name="datefinf" type="text" id="datefinf" value="<?PHP echo $ot_datefinf ?>" size="10" readonly="1" onChange="verif_dfin2();">
	<?PHP
	if (($td == "edit") AND ($modif_ok==TRUE))
	{ 
	?>
		<img src="../img/calendar.png" align="absmiddle" id="f_img_datefinf" title="<?PHP echo $alt_chxdate; ?>">
		<a href="javascript:;" onclick="document.ot_maj.datefinf.value=''"><img src="../img/raz.png" 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 } else { ?> 
<input name="dateprevf" type="hidden" id="dateprevf" value="<?PHP echo $ot_dateprevf ?>">
<input name="datefinf" type="hidden" id="datefinf" value="<?PHP echo $ot_datefinf ?>">
<?PHP } ?>
<!-- Fin de zone exclue si création -->
  
<p align="center">
<?PHP
if (($td == "edit") OR ($td == "add"))
{
?>
	<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
	<input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_enr; ?>">
	<input name="enrimp" type="submit" class="bton_std" id="enrimp" value="Enregistrer & Imprimer">
<?PHP
}
if ($td == "del") // Bouton si en mode suppression
{ 
?>
	<input name="del" type="submit" class="bton_std" id="del" value="<?PHP echo $but_del; ?>">
<?PHP 
} 
?>
</p>
</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       :    "<?PHP echo $datefmtc; ?>",      // 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       :    "<?PHP echo $datefmtc; ?>",      // 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 ($modif_ok==TRUE))
	{
	?>
	Calendar.setup({
		inputField     :    "dateprevf",     // id of the input field
		ifFormat       :    "<?PHP echo $datefmtc; ?>",      // 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       :    "<?PHP echo $datefmtc; ?>",      // 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
}
?>
<!-- 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_st_actifs() == 0)
		{
	?>
		<script type="text/javascript">
		<!--
		setTimeout("self.location.href=('st_lst.php');",2000)
		//-->
		</script>
		<p align="center" class="annot_std_it">Il faut au moins un sous-traitant actif ...</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"><?PHP echo $alert_nociv; ?></p>
	<?PHP
		}

		if ($tx=="i")
		{
	?>
	<script type="text/javascript">
	<!--
	setTimeout("self.close();",2000)
	//-->
	</script>
	<?PHP
		}
	}
}
else
{
	echo '<p align="center" class="annot_std_it">'.$alert_prm.'...</p>';
?>
	<script type="text/javascript">
	<!--
<?PHP	if ($tx=="i") { ?>
	setTimeout("self.close();",2000);
<?PHP } else { ?>
	// setTimeout("self.location.href=('index.php');",2000);
<?PHP } ?>
	//-->
	</script>
<?PHP
}
if ($tx == "m")
	include_once("pied.php");
else
{
	echo '</body>';
	echo '</html>';
}
?>