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

Version 0.9.9

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

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

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

Contact : galawa@free.fr

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


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

include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_dos.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_loc.inc.php");
include_once("../inc/fic_ot.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_tac.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
$ct = strip_tags(trim($_GET['ct'])); // Récupération code Tâche

$pbm_tac = FALSE;
$modif_ok = FALSE;

$msg_err_tdest="Aucun destinataire";
$msg_err_trat="Rien &agrave; rattacher";

if ($ct <> "")
{
	// Récupération des informations tâche
	$row = lit_enr_tac($ct);
	if (is_array($row))
	{
		extract ($row);

		if ($td <> "add")
		{
			// Contrôle qu'on n'essaye pas de "hacker" une tâche
			switch (@$_SESSION["niv_log"])
			{
				// Technicien agence
				case 3 :
					if (($tac_typdest<>1) OR ($tac_codedest<>@$_SESSION["code_log"]))
						$pbm_tac=TRUE;
					break;
				// Agence
				case 4 :
					if (($tac_typdest<>1) AND ($tac_typdest<>2))
						$pbm_tac=TRUE;
					else
					{
						if ($tac_typdest==1)
						{
							$row2=lit_enr_tec($tac_codedest,TRUE);
							if (is_array($row2))
							{
								extract ($row2);
								if ($tec_codeage<>@$_SESSION["code_log"])
									$pbm_tac=TRUE;
							}
							else
								$pbm_tac=TRUE;
						}
						else
						{
							if ($tac_codedest<>@$_SESSION["code_log"])
								$pbm_tac=TRUE;
						}
					}
					break;
				// Sous-traitant
				case 10 :
					if (($tac_typdest<>3) AND ($tac_typdest<>4))
						$pbm_tac=TRUE;
					else
					{
						if ($tac_typdest==3)
						{
							$row2=lit_enr_tec($tac_codedest,TRUE);
							if (is_array($row2))
							{
								extract ($row2);
								if ($tec_codest<>@$_SESSION["code_log"])
									$pbm_tac=TRUE;
							}
							else
								$pbm_tac=TRUE;
						}
						else
						{
							if ($tac_codedest<>@$_SESSION["code_log"])
								$pbm_tac=TRUE;
						}
					}
					break;
				// Technicien sous-traitant
				case 11 :
					if (($tac_typdest<>3) OR ($tac_codedest<>@$_SESSION["code_log"]))
						$pbm_tac=TRUE;
					break;
			}
			if ($tac_codedest==@$_SESSION["code_log"])
				($tac_typdest=-1);
		}

		// Formatage des dates en français
		$tac_datecreaf = formatedate($tac_datecrea);
		$tac_datemodf = formatedate($tac_datemod);
		$tac_datefinpf = formatedate($tac_datefinp);
		$tac_datefinf = formatedate($tac_datefin);
		
		// Si dossier terminé, on force le mode "view"
		if ($tac_datefinf <> "")
			$td="view";
	}
	else
		$pbm_tac = TRUE;
}
else
{
	if ($td == "add")
	{
		$tac_code = crecodesession("TA");
		$ct = $tac_code;
	}
	else
		$pbm_tac=TRUE;
}

// On vérifie si appelé par ligne de commande (uniquement en ajout) + tentative de hack
if ($pbm_tac==FALSE)
{
	if (isset($_GET['tr']))
	{
		if ($td=="add")
		{
			$tr = intval(strip_tags(trim($_GET['tr']))); // Récupération type rattaché
			if (isset($_GET['cr']))
			{
				$cr = strip_tags(trim($_GET['cr'])); // Récupération code rattaché
				switch ($tr)
				{
					// Intervention
					case 1 :
						$row=lit_enr_int($cr);
						if (is_array($row))
						{
							extract($row);
							switch (@$_SESSION["niv_log"])
							{
								case 3 :
								case 4 :
									if (($int_codeage<>@$_SESSION["code_age"]) AND ($int_codeages<>@$_SESSION["code_age"]))
										$pbm_tac=TRUE;
									break;
								case 5 :
								case 9 :
									break;
								default :
									$pbm_tac=TRUE;
									break;
							}
							if (formatedate($int_datefin)<>"")
								$pbm_tac=TRUE;
						}
						else
							$pbm_tac=TRUE;
						break;
					// Contrat de maintenance
					case 2 :
						$row=lit_enr_cocl($cr);
						if (is_array($row))
						{
							extract($row);
							switch (@$_SESSION["niv_log"])
							{
								case 3 :
								case 4 :
									if ($cocl_codeage<>@$_SESSION["code_age"])
										$pbm_tac=TRUE;
									break;
								case 5 :
								case 9 :
									break;
								default :
									$pbm_tac=TRUE;
									break;
							}
							if (formatedate($cocl_datefin)<>"")
								$pbm_tac=TRUE;
						}
						else
							$pbm_tac=TRUE;
						break;
					// Contrat de location
					case 3 :
						$row=lit_enr_coloc($cr);
						if (is_array($row))
						{
							extract($row);
							switch (@$_SESSION["niv_log"])
							{
								case 3 :
								case 4 :
									if ($coloc_codeage<>@$_SESSION["code_age"])
										$pbm_tac=TRUE;
									break;
								case 5 :
								case 9 :
									break;
								default :
									$pbm_tac=TRUE;
									break;
							}
							if (formatedate($coloc_dateclos)<>"")
								$pbm_tac=TRUE;
						}
						else
							$pbm_tac=TRUE;
						break;
					// Dossier de suivi
					case 4 :
						$row=lit_enr_dos($cr);
						if (is_array($row))
						{
							extract($row);
							switch (@$_SESSION["niv_log"])
							{
								case 3 :
								case 4 :
									if ($dos_codeage<>@$_SESSION["code_age"])
										$pbm_tac=TRUE;
									break;
								case 5 :
								case 9 :
									break;
								default :
									$pbm_tac=TRUE;
									break;
							}
							if (formatedate($dos_datefin)<>"")
								$pbm_tac=TRUE;
						}
						else
							$pbm_tac=TRUE;
						break;
					// Relevé de parc
					case 5 :
						$row=lit_enr_rel($cr);
						if (is_array($row))
						{
							extract($row);
							switch (@$_SESSION["niv_log"])
							{
								case 3 :
								case 4 :
									if ($rel_codeage<>@$_SESSION["code_age"])
										$pbm_tac=TRUE;
									break;
								case 5 :
								case 9 :
									break;
								default :
									$pbm_tac=TRUE;
									break;
							}
						}
						else
							$pbm_tac=TRUE;
						break;
					// Ordre de travail
					case 6 :
						$row=lit_enr_ot($cr);
						if (is_array($row))
						{
							extract($row);
							switch (@$_SESSION["niv_log"])
							{
								case 10 :
								case 11 :
									if ($ot_codest<>@$_SESSION["code_st"])
										$pbm_tac=TRUE;
								case 3 :
								case 4 :
									$row=lit_enr_int($ot_codeint);
									if (is_array($row))
									{
										extract($row);
										if (($int_codeage<>@$_SESSION["code_age"]) AND ($int_codeages<>@$_SESSION["code_age"]))
											$pbm_tac=TRUE;
									}
									else
										$rpbm_tac=TRUE;
									break;
								case 5 :
								case 9 :
									break;
								default :
									$pbm_tac=TRUE;
									break;
							}
						}
						else
							$pbm_tac=TRUE;
						break;
					default :
						$pbm_tac=TRUE;
						break;
				}
				
				if ($pbm_tac==FALSE)
				{
					$tac_typrat=$tr;
					$tac_coderat=$cr;
				}
			}
			else
				$pbm_tac=TRUE;
		}
		else
			$pbm_tac=TRUE;
	}
	else
	{
		if (isset($_GET['cr']))
			$pbm_tac=TRUE;
	}
}

switch ($td)
{
	case "add" :
		$titre = "SAISIE TACHE";
		$tac_datecreaf = $datef;
		$tac_codecrea=@$_SESSION["code_log"];
		$tac_proba="";
		$tac_urg=-1;
		$tac_typrat=$tr;
		$tac_coderat=$cr;
		$modif_ok=TRUE;
		break;
	case "edit" :
		$titre = "MISE A JOUR TACHE";
		// On vérifie si le droit de modification est ok
		if (($tac_codecrea==@$_SESSION["code_log"]) OR (@$_SESSION["niv_log"]==9))
			$modif_ok=TRUE;
		break;
	case "view" :
		$titre = "VISUALISATION TACHE";
		break;
	case "del":
		$titre = "SUPPRESSION TACHE";
		break;
	default:
			$titre = "PROBLEME";
			$pbm_tac=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 Tâche</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:datecreaf ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date création ; stok:frmok ; stbad:frmbad",
	"nom:datefinpf ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date butoir ; stok:frmok ; stbad:frmbad",
	"nom:urgence; format:liste ; req:Y ; txt:Urgence ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:titred; format:txt ; req:Y ; txt:Titre ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:afaire; format:txt ; req:Y ; txt:A faire ; stok:frmok ; stbad:frmbad",
	"nom:codecat; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_cat); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:typdest; format:liste ; req:Y ; txt:Type destinataire ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:dest; format:liste ; req:Y ; txt:Destinataire(s) ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:typrat; format:liste ; req:Y ; txt:Type rattachement ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:rat; format:liste ; req:N ; txt:Rattaché à ; 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>

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

<?PHP if (($modif_ok==TRUE) AND ($pbm_tac==FALSE)) { ?>
<script type="text/javascript">
<!--
var tab_trat = new Array();
<?PHP
foreach ($tac_trat as $key=>$value)
{
	echo 'tab_trat['.$key.'] = "'.$value.'";';
}
echo 'var nl = '.@$_SESSION["niv_log"].';';
?>

function UpdlstTrat()
{
	var listetdest = document.getElementById("typdest");
	var tdest = listetdest.options[listetdest.selectedIndex].value;
	var listedest = document.getElementById("dest");
	var dest = listedest.options[listedest.selectedIndex].value;
	// RAZ type document rattaché
	var listetrat = document.getElementById("typrat");
	listetrat.innerHTML = "";
	// RAZ document rattaché
	var listerat = document.getElementById("rat");
	listerat.innerHTML = "";
	// On crée la première ligne de choix
	option = document.createElement("option");
	option.setAttribute("value","");
	option.innerHTML ="-- Faites votre choix --";
	listerat.appendChild(option);

	// Construction de la liste des types de documents rattachables
	// On crée la première ligne de choix
	option = document.createElement("option");
	option.setAttribute("value","");
	option.innerHTML ="-- Faites votre choix --";
	listetrat.appendChild(option);
	if ((tdest.length > 0) && (dest.length > 0))
	{
		// On crée les lignes suivantes
		for(var i in tab_trat)
		{
			if(isNaN(i) == false)
			{
				var affok = true;
				switch (parseInt(nl))
				{
					case 3 :
					case 4 :
						break;
					case 10 :
					case 11 :
						if ((parseInt(i)!=6) && (parseInt(i)!=-1)) { affok = false; }
						break;
					case 5 :
					case 9 :
						switch (parseInt(tdest))
						{
							case 3 :
							case 4 :
								if ((parseInt(i)!=6) && (parseInt(i)!=-1)) { affok = false; }
								break;
							default :
								break;
						}
						break;
				}
				if (affok == true)
				{
					option = document.createElement("option");
					option.setAttribute("value",parseInt(i));
					option.innerHTML = tab_trat[i];
					listetrat.appendChild(option);
				}
			}
		}
	}
}

function updateTdest()
{
	tdestUpdater = new SelectUpdater("dest", "<?PHP echo $rep_appli.'/ajax/'; ?>recuptdest.php?tdest=", "attn1", "msg1", "<?PHP echo $msg_err_tdest; ?>");
	ancientdest = "";
	document.getElementById("typdest").onchange = function() {
		var listetdest = document.getElementById("typdest");
		var tdest = listetdest.options[listetdest.selectedIndex].value;
		if (tdest.length > 0)
		{
			if (tdest != ancientdest)
			{
				// Faire l'appel Ajax
				var prmget=tdest;
				tdestUpdater.run(prmget);
				ancientdest = tdest;
				UpdlstTrat();
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			tdestUpdater.reset();
			ancientdest = "";
			UpdlstTrat();
		}
	}
}

function updateTrat()
{
	tratUpdater = new SelectUpdater("rat", "<?PHP echo $rep_appli.'/ajax/'; ?>recuptrat.php?trat=", "attn2", "msg2", "<?PHP echo $msg_err_trat; ?>");
	ancientrat = "";
	document.getElementById("typrat").onchange = function() {
		var listetrat = document.getElementById("typrat");
		var trat = listetrat.options[listetrat.selectedIndex].value;
		if (trat.length > 0)
		{
			if (trat != ancientrat)
			{
				// Faire l'appel Ajax
				var listetdest = document.getElementById("typdest");
				var tdest = listetdest.options[listetdest.selectedIndex].value;
				var listedest = document.getElementById("dest");
				var dest = listedest.options[listedest.selectedIndex].value;
				var prmget=trat+"_"+tdest+"_"+dest;
				tratUpdater.run(prmget);
				ancientrat = trat;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			tratUpdater.reset();
			ancientrat = "";
		}
	}
}
//-->
</script>
<?PHP } ?>

</head>

<?PHP
switch ($td)
{
	case "view" :
	case "del" :
		echo '<body onLoad="metReadonly();">';
		break;
	default :
		echo '<body onLoad="metFocus();';
		if (($modif_ok==TRUE) AND ($pbm_tac==FALSE))
			echo 'updateTdest();updateTrat();';
		echo '">';
		break;
}

include_once("../inc/entete.inc.php"); 
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<?PHP
if ($pbm_tac == FALSE)
{
	if (nb_tacc(0,'',TRUE) > 0) 
	{
?>
<table width="100%"  border="0">
<tr>
	<td width="40%"><strong><em><a href="tac_lst.php?ord=DES&tri=Code"><?PHP echo $txt_lnk_ret_liste; ?></a></em></strong></td>
	<td width="160" valign="top"><div id="oblig" align="center" class="annot_petit_it">(<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> : <?PHP echo $txt_div_saisoblg; ?>)</div>
	</td>
	<td width="40%">&nbsp;
	
    </td>
</tr>
</table>
<form name="tac_maj" method="post" action="tac_enr.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<?PHP if ($td == "add") { ?>
	<input name="code" type="hidden" id="code" value="<?PHP echo $tac_code ?>">
<?PHP } ?>

<!-- Code de la tâche (affiché uniquement si édition ou suppression) -->
<?PHP if ($td <> "add") {?>
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_code" align="right">Code</td>
	<td>
		<input name="code" type="text" id="code" value="<?PHP echo $tac_code ?>" size="20" maxlength="20" readonly="1">
	</td>
</tr>
</table>
<?PHP }  ?>

<!-- Date de création et fin prévue-->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_datecreaf" align="right">Date cr&eacute;ation</td>
	<td>
		<input name="datecreaf" type="text" id="datecreaf" value="<?PHP echo $tac_datecreaf; ?>" 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">
		<span class="annot_std_gras">Date butoir : </span><input name="datefinpf" type="text" id="datefinpf" value="<?PHP echo $tac_datefinpf ?>" size="10" maxlength="10" readonly="1">
		<?PHP if (($td == "add") OR (($td=="edit") AND (($tac_codecrea==@$_SESSION["code_log"]) OR (@$_SESSION["niv_log"]==9)))) { ?>
		<img src="../img/calendar.png" align="absmiddle" id="f_img_datefinpf" title="<?PHP echo $alt_chxdate; ?>">
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } ?>
	</td>
</tr>
</table>

<!-- Titre et "à faire" de la tâche -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_titred" align="right">Titre</td>
	<td>
		<?PHP
		if ($modif_ok==TRUE)
		{ 
		?>
			<input name="titred" type="text" id="titred" value="<?PHP echo htmlspecialchars($tac_titre) ?>" size="50">
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } else { ?>
			<input name="titred" type="text" id="titred" value="<?PHP echo htmlspecialchars($tac_titre) ?>" size="50" readonly="1">
		<?PHP } ?>
	</td>
    <td align="right">
		<span class="annot_std_gras">Niveau d'urgence : </span>
		<?PHP
		if ($modif_ok==TRUE)
		{
		?>
		<select name="urgence" id="urgence">
		  <?PHP
			echo "<option value=\"\">".$sel_lst_makechx."</option>";
			
			// Création du niveau d'urgence
			for ($i=0; $i<4; $i++)
			{
				if ($tac_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; ?>">
    <?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 $tac_urg ?>" readonly="1">
	        <input name="urg" type="text" id="urg" value="<?PHP echo $niv_urgence[$tac_urg] ?>" size="20" readonly="1">
        <?PHP
		}
		?>
	</td>
</tr>
</table>

<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_afaire" align="right">A faire</td>
	<td>
		<?PHP
		if ($modif_ok==TRUE)
		{ 
		?>
			<textarea name="afaire" rows="5" id="afaire" style="width:95%;"><?PHP echo htmlspecialchars($tac_afaire,ENT_QUOTES); ?></textarea>
			<img src="../img/oblig.png" align="top" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } else { ?>
			<textarea name="afaire" rows="5" id="afaire" readonly="readonly"><?PHP echo htmlspecialchars($tac_afaire,ENT_QUOTES); ?></textarea>
		<?PHP } ?>
	</td>
</tr>
</table>

<!-- Paramètres de la tâche -->
<table width="100%"  border="0">
  <tr>
    <td width="160" class="rubfrm" id="f_cat" align="right">Cat&eacute;gorie</td>
    <td>
		<?PHP
		if ($modif_ok==TRUE)
		{ 
		?>
       	<select name="codecat" id="codecat">
        <?PHP
			echo "<option value=\"\">".$sel_lst_makechx."</option>";

			// Création de la liste des Catégories
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rs = mysql_query("SELECT * FROM ".TBTACC." ORDER BY tacc_desc");

			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				if ($tac_codetacc == $tacc_code)
					echo '<option value="'.$tacc_code.'" selected>'.$tacc_desc.'</option>';
				else
					echo '<option value="'.$tacc_code.'">'.$tacc_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 la catégorie
		{
			$txt_statut = "";
			if ($tac_codetacc <> "")
			{
				$row = lit_enr_tacc($tac_codetacc);
				if (is_array($row))
				{
					extract($row);
					$txt_statut = $tacc_desc;
				}
			}
			if ($txt_statut<>"")
			{
		?>
			<input name="codecat" type="hidden" id="codecat" value="<?PHP echo $tac_codetacc ?>" readonly="1">
			<input name="ncat" type="text" id="ncat" value="<?PHP echo $txt_statut ?>" size="50" readonly="1">
		<?PHP
			}
			else
			{
		?>
				<span class="annot_gras_it">
				Pas de cat&eacute;gorie affect&eacute;e &agrave; ce dossier
				</span>
		<?PHP
			}
		}
		?>
    </td>
  </tr>
  <tr>
    <td class="rubfrm" id="f_typdest" align="right">Type destinataire</td>
    <td>
	  <?PHP
		if ($modif_ok==TRUE)
		{ 
			echo '<select name="typdest" id="typdest">';
			echo "<option value=\"\">".$sel_lst_makechx."</option>";
			foreach ($tac_tdest as $key=>$value)
			{
				$affok=TRUE;
				switch (@$_SESSION["niv_log"])
				{
					case 3 :
					case 11 :
						if ($key<>-1) $affok=FALSE;
						break;
					case 4 :
						if (($key<>-1) AND ($key<>1) AND ($key<>4)) $affok=FALSE;
						break;
					case 5 :
						if ($key==6) $affok=FALSE;
						break;
					case 10 :
						if (($key<>-1) AND ($key<>3)) $affok=FALSE;
						break;
				}
				if ($affok==TRUE)
				{
					echo '<option value="'.$key.'"'; 
					if ($tac_typdest == $key)
						echo ' selected';
					echo '>';
					echo $value."</option>";
				}
			}
			echo '</select>';
			echo '<img src="../img/oblig.png" align="absmiddle" alt="'.$alt_chp_oblig.'">';
		}
		else
		{
			echo '<input name="typdest" type="hidden" id="typdest" value="'.$tac_typdest.'" readonly="readonly">';
			echo '<input name="ntypdest" type="text" id="ntypdest" value="'.$tac_tdest[$tac_typdest].'" size="50" readonly="readonly">';
		}
		?>
	</td>
	</tr>
    <td class="rubfrm" id="f_dest" align="right">Destinataire(s)</td>
    <td>
	  <?PHP
		if ($modif_ok==TRUE)
		{ 
			$rech="";
			$nivdest=0;
			switch ($tac_typdest)
			{
				case -1 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
							$nivdest=1;
							break;
						case 4 :
							$nivdest=2;
							break;
						case 5 :
							$nivdest=5;
							break;
						case 9 :
							$nivdest=6;
							break;
						case 10 :
							$nivdest=4;
							break;
						case 11 :
							$nivdest=3;
							break;
					}
					break;
				default :
					$nivdest=intval($tac_typdest);
					break;
			}
			echo '<select name="dest" id="dest" onChange="UpdlstTrat();">';
			echo "<option value=\"\">".$sel_lst_makechx."</option>";
			switch ($nivdest)
			{
				case 1 :
					$rech = "SELECT * FROM ".TBTEC;
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 11 :
							$rech.= " WHERE tec_code='".@$_SESSION["code_log"]."'";
							break;
						case 4 :
							$rech.= " WHERE tec_codeage='".@$_SESSION["code_log"]."'";
							break;
						default :
							$rech.= " WHERE tec_codeage<>''";
							break;
					}
					$rech.= " AND tec_out=0 ORDER BY tec_nom";
					break;
				case 2 :
					$rech = "SELECT * FROM ".TBAGE." WHERE age_ouvert=1 ORDER BY age_nom";
					break;
				case 3 :
					$rech = "SELECT * FROM ".TBTEC;
					if (@$_SESSION["niv_log"]<>10)
						$rech.= " WHERE tec_codest<>''";
					else
						$rech.= " WHERE tec_codest='".@$_SESSION["code_log"]."'";
					$rech.= " AND tec_out=0 ORDER BY tec_nom";
					break;
				case 4 :
					$rech = "SELECT * FROM ".TBST." WHERE st_ouvert=1 ORDER BY st_nom";
					break;
			}
			if ($rech<>"")
			{
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query($rech) or die(mysql_error());
				if (mysql_num_rows($rs) <> 0)
				{
					while ($resultat = mysql_fetch_array($rs)) 
					{
						extract($resultat);
						$codedest="";
						switch ($nivdest)
						{
							case 1 :
								$codedest=$tec_code;
								$txtdest=$tec_nom." ".$tec_prenom." (".$tec_codeage.")";
								break;
							case 2 :
								$codedest=$age_code;
								$txtdest=$age_resp_nom." ".$age_resp_prenom." (".$age_code.")";
								break;
							case 3 :
								$codedest=$tec_code;
								$txtdest=$tec_nom." ".$tec_prenom." (".$tec_codest.")";
								break;
							case 4 :
								$codedest=$st_code;
								$txtdest=$st_resp_nom." ".$st_resp_prenom." (".$st_code.")";
								break;
						}
						if ($codedest<>"")
						{
							echo '<option value="'.$codedest.'"';
							if ($tac_codedest == $codedest)
								echo ' selected';
							echo '>'.$txtdest.'</option>';
						}
					}
				}
				mysql_free_result($rs);
				mysql_close();
			}
			else
			{
				$codedest="";
				switch ($nivdest)
				{
					case 5 :
						$codedest="CGE";
						$txtdest="Centre de gestion";
						break;
					case 6 :
						$codedest=$admin_code;
						$txtdest=$admin_code;
						break;
				}
				if ($codedest<>"")
				{
					echo '<option value="'.$codedest.'"';
					if ($tac_codedest == $codedest)
						echo ' selected';
					echo '>'.$txtdest.'</option>';
				}
			}
			echo '</select>';
			echo '<img src="../img/oblig.png" align="absmiddle" alt="'.$alt_chp_oblig.'">';
		?>
		 <span id="attn1"></span><span id="msg1" style="background-color:#FF0000; color:#FFFF00; font-weight:bold"><?PHP echo htmlspecialchars($msg1_err_tdest);?></span>
		<?PHP
		}
		else
		{
			echo '<input name="dest" type="hidden" id="dest" value="'.$tac_codedest.'" readonly="readonly">';
			switch ($tac_typdest)
			{
				case 1 :
					$row=lit_enr_tec($tac_codedest,TRUE);
					if (is_array($row))
						extract($row);
					$txtdest=$tec_nom." ".$tec_prenom." (".$tec_codeage.")";
					break;
				case 2 :
					$row=lit_enr_age($tac_codedest,TRUE);
					if (is_array($row))
						extract($row);
					$txtdest=$age_resp_nom." ".$age_resp_prenom." (".$age_code.")";
					break;
				case 3 :
					$row=lit_enr_tec($tac_codedest,TRUE);
					if (is_array($row))
						extract($row);
					$txtdest=$tec_nom." ".$tec_prenom." (".$tec_codest.")";
					break;
				case 4 :
					$row=lit_enr_st($tac_codedest);
					if (is_array($row))
						extract($row);
					$txtdest=$st_resp_nom." ".$st_resp_prenom." (".$st_code.")";
					break;
				case 5 :
					$txtdest="Centre de gestion";
					break;
				case 6 :
					$txtdest=$admin_code;
					break;
			}
			echo '<input name="ndest" type="text" id="ndest" value="'.$txtdest.'" size="50" readonly="readonly">';
		}
		?>
	</td>
	</tr>
  <tr>
    <td class="rubfrm" id="f_typrat" align="right">Type rattachement</td>
    <td>
	  <?PHP
		if ($modif_ok==TRUE)
		{ 
			echo '<select name="typrat" id="typrat">';
			echo "<option value=\"\">".$sel_lst_makechx."</option>";
			foreach ($tac_trat as $key=>$value)
			{
				$affok=TRUE;
				switch (@$_SESSION["niv_log"])
				{
					case 10 :
					case 11 :
						if (($key<>6) AND ($key<>-1)) $affok=FALSE;
						break;
					default :
						break;
				}
				if ($affok==TRUE)
				{
					echo '<option value="'.$key.'"'; 
					if ($tac_typrat == $key)
						echo ' selected';
					echo '>';
					echo $value."</option>";
				}
			}
			echo '</select>';
			echo '<img src="../img/oblig.png" align="absmiddle" alt="'.$alt_chp_oblig.'">';
		}
		else
		{
			echo '<input name="typrat" type="hidden" id="typrat" value="'.$tac_typrat.'" readonly="readonly">';
			echo '<input name="ntyprat" type="text" id="ntyprat" value="'.$tac_trat[$tac_typrat].'" size="50" readonly="readonly">';
		}
		?>
	</td>
	</tr>
    <td class="rubfrm" id="f_rat" align="right">Rattach&eacute; &agrave;</td>
    <td>
	  <?PHP
		if ($modif_ok==TRUE)
		{ 
			$rech="";
			echo '<select name="rat" id="rat">';
			echo "<option value=\"\">".$sel_lst_makechx."</option>";
			switch ($tac_typrat)
			{
				// Rien
				case -1 :
					break;
				// Interventions
				case 1 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
							$rech = "SELECT * FROM ".TBINT;
							$rech.= " WHERE int_codeage='".@$_SESSION["code_age"]."' OR int_codeages='".@$_SESSION["code_age"]."'";
							$rech.= " AND int_datefin='0000-00-00'";
							$rech.= " ORDER BY int_code DESC";
							break;
						case 10 :
						case 11 :
							break;
						default :
							$rech = "SELECT * FROM ".TBINT;
							$rech.= " WHERE int_datefin='0000-00-00'";
							$rech.= " ORDER BY int_code DESC";
							break;
					}
					break;
				// Contrat de maintenance
				case 2 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
							$rech = "SELECT * FROM ".TBCOCL;
							$rech.= " WHERE cocl_codeage='".@$_SESSION["code_age"]."'";
							$rech.= " AND cocl_datefin='0000-00-00'";
							$rech.= " ORDER BY cocl_code DESC";
							break;
						case 10 :
						case 11 :
							break;
						default :
							$rech = "SELECT * FROM ".TBCOCL;
							$rech.= " WHERE cocl_datefin='0000-00-00'";
							$rech.= " ORDER BY cocl_code DESC";
							break;
					}
					break;
				// Contrat de location
				case 3 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
							$rech = "SELECT * FROM ".TBCOLOC;
							$rech.= " WHERE coloc_codeage='".@$_SESSION["code_age"]."'";
							$rech.= " AND coloc_dateclos='0000-00-00'";
							$rech.= " ORDER BY coloc_code DESC";
							break;
						case 10 :
						case 11 :
							break;
						default :
							$rech = "SELECT * FROM ".TBCOLOC;
							$rech.= " WHERE coloc_dateclos='0000-00-00'";
							$rech.= " ORDER BY coloc_code DESC";
							break;
					}
					break;
				// Dossier de suivi
				case 4 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
							$rech = "SELECT * FROM ".TBDOS;
							$rech.= " WHERE dos_codeage='".@$_SESSION["code_age"]."'";
							$rech.= " AND dos_datefin='0000-00-00'";
							$rech.= " ORDER BY dos_code DESC";
							break;
						case 10 :
						case 11 :
							break;
						default :
							$rech = "SELECT * FROM ".TBDOS;
							$rech.= " WHERE dos_datefin='0000-00-00'";
							$rech.= " ORDER BY dos_code DESC";
							break;
					}
					break;
				// Relevé de parc
				case 5 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
							$rech = "SELECT * FROM ".TBREL;
							$rech.= " WHERE rel_codeage='".@$_SESSION["code_age"]."'";
							$rech.= " ORDER BY rel_code DESC";
							break;
						case 10 :
						case 11 :
							break;
						default :
							$rech = "SELECT * FROM ".TBREL;
							$rech.= " ORDER BY rel_code DESC";
							break;
					}
					break;
				// Bon de travail
				case 6 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
							$rech = "SELECT * FROM ".TBOT.", ".TBINT;
							$rech.= " WHERE (".TBOT.".ot_codeint=".TBINT.".int_code";
							$rech.= " AND ".TBINT.".int_codeage='".@$_SESSION["code_age"]."'";
							$rech.= " AND ".TBOT.".ot_datefin='0000-00-00')";
							$rech.= " ORDER BY ot_code DESC";
							break;
						case 10 :
						case 11 :
							$rech = "SELECT * FROM ".TBOT;
							$rech.= " WHERE ot_codest='".@$_SESSION["code_st"]."'";
							$rech.= " AND ot_datefin='0000-00-00'";
							$rech.= " ORDER BY ot_code DESC";
							break;
						default :
							$rech = "SELECT * FROM ".TBOT;
							$rech.= " WHERE ot_datefin='0000-00-00'";
							$rech.= " ORDER BY ot_code DESC";
							break;
					}
					break;
			}
			if ($rech<>"")
			{
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query($rech) or die(mysql_error());
				if (mysql_num_rows($rs) <> 0)
				{
					while ($resultat = mysql_fetch_array($rs)) 
					{
						extract($resultat);
						switch ($tac_typrat)
						{
							// Rien
							case -1 :
								break;
							// Interventions
							case 1 :
								$coderat=$int_code;
								$txtcli="";
								$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
								$rech2.= " WHERE cli_code='".$int_codecli."'";
								$rs2 = mysql_query($rech2) or die(mysql_error());
								if ($row2 = mysql_fetch_array($rs2))
									extract($row2);
								if (trim($cli_ste)<>"")
									$txtcli=$cli_ste;
								else
									$txtcli=$cli_nom." ".$cli_prenom;
								$txtrat=$int_code." du ".formatedate($int_datedde)." (".$txtcli.")";
								break;
							// Contrat de maintenance
							case 2 :
								$coderat=$cocl_code;
								$txtcli="";
								$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
								$rech2.= " WHERE cli_code='".$cocl_codecli."'";
								$rs2 = mysql_query($rech2) or die(mysql_error());
								if ($row2 = mysql_fetch_array($rs2))
									extract($row2);
								if (trim($cli_ste)<>"")
									$txtcli=$cli_ste;
								else
									$txtcli=$cli_nom." ".$cli_prenom;
								$txtrat=$cocl_code." du ".formatedate($cocl_datecrea)." (".$txtcli.")";
								break;
							// Contrat de location
							case 3 :
								$coderat=$coloc_code;
								$txtcli="";
								switch ($coloc_typcli)
								{
									// Client
									case 0 :
										$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
										$rech2.= " WHERE cli_code='".$coloc_codecli."'";
										break;
									// Agence
									case 1 :
										$rech2 = "SELECT age_nom FROM ".TBAGE;
										$rech2.= " WHERE age_code='".$coloc_codecli."'";
										break;
									// Technicien agence
									case 2 :
									// Technicien Sous-traitant
									case 4 :
										$rech2 = "SELECT tec_nom,tec_prenom FROM ".TBTEC;
										$rech2.= " WHERE tec_code='".$coloc_codecli."'";
										break;
									// Sous-traitant
									case 3 :
										$rech2 = "SELECT st_nom FROM ".TBST;
										$rech2.= " WHERE st_code='".$coloc_codecli."'";
										break;
								}
								$rs2 = mysql_query($rech2) or die(mysql_error());
								if ($row2 = mysql_fetch_array($rs2))
									extract($row2);
								switch ($coloc_typcli)
								{
									// Client
									case 0 :
										if (trim($cli_ste)<>"")
											$txtcli=$cli_ste;
										else
											$txtcli=$cli_nom." ".$cli_prenom;
										break;
									// Agence
									case 1 :
										$txtcli=$age_nom;
										break;
									// Technicien agence
									case 2 :
									// Technicien Sous-traitant
									case 4 :
											$txtcli=$tec_nom." ".$tec_prenom;
										break;
									// Sous-traitant
									case 3 :
										$txtcli=$st_nom;
										break;
								}
								$txtrat=$coloc_code." du ".formatedate($coloc_datecrea)." (".$txtcli.")";
								break;
							// Dossier de suivi
							case 4 :
								$coderat=$dos_code;
								$txtcli="";
								$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
								$rech2.= " WHERE cli_code='".$dos_codecli."'";
								$rs2 = mysql_query($rech2) or die(mysql_error());
								if ($row2 = mysql_fetch_array($rs2))
									extract($row2);
								if (trim($cli_ste)<>"")
									$txtcli=$cli_ste;
								else
									$txtcli=$cli_nom." ".$cli_prenom;
								$txtrat=$dos_code." du ".formatedate($dos_datecrea)." (".$txtcli.")";
								break;
							// Relevé de parc
							case 5 :
								$coderat=$rel_code;
								$txtcli="";
								$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
								$rech2.= " WHERE cli_code='".$rel_codecli."'";
								$rs2 = mysql_query($rech2) or die(mysql_error());
								if ($row2 = mysql_fetch_array($rs2))
									extract($row2);
								if (trim($cli_ste)<>"")
									$txtcli=$cli_ste;
								else
									$txtcli=$cli_nom." ".$cli_prenom;
								$txtrat=$rel_code." du ".formatedate($rel_datecrea)." (".$txtcli.")";
								break;
							// Bon de travail
							case 6 :
								$coderat=$ot_code;
								$rech2 = "SELECT int_codecli FROM ".TBINT;
								$rech2.= " WHERE int_code='".$ot_codeint."'";
								$rs2 = mysql_query($rech2) or die(mysql_error());
								if ($row2 = mysql_fetch_array($rs2))
									extract($row2);
								$txtcli="";
								$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
								$rech2.= " WHERE cli_code='".$int_codecli."'";
								$rs2 = mysql_query($rech2) or die(mysql_error());
								if ($row2 = mysql_fetch_array($rs2))
									extract($row2);
								if (trim($cli_ste)<>"")
									$txtcli=$cli_ste;
								else
									$txtcli=$cli_nom." ".$cli_prenom;
								$txtrat=$ot_code." du ".formatedate($ot_datedde)." (".$txtcli.")";
								break;
						}
						echo '<option value="'.$coderat.'"';
						if ($tac_coderat == $coderat)
							echo ' selected';
						echo '>'.$txtrat.'</option>';
					}
				}
				mysql_free_result($rs);
				mysql_close();
			}
			echo '</select>';
			echo '<img src="../img/oblig.png" align="absmiddle" alt="'.$alt_chp_oblig.'">';
		?>
		 <span id="attn2"></span><span id="msg2" style="background-color:#FF0000; color:#FFFF00; font-weight:bold"><?PHP echo htmlspecialchars($msg1_err_trat);?></span>
		<?PHP
		}
		else
		{
			echo '<input name="rat" type="hidden" id="rat" value="'.$tac_coderat.'" readonly="readonly">';
			$rech="";
			switch ($tac_typrat)
			{
				// Rien
				case -1 :
					break;
				// Interventions
				case 1 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
						case 5 :
						case 9 :
							$rech = "SELECT * FROM ".TBINT;
							$rech.= " WHERE int_code='".$tac_coderat."'";
							break;
						default :
							break;
					}
					break;
				// Contrat de maintenance
				case 2 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
						case 5 :
						case 9 :
							$rech = "SELECT * FROM ".TBCOCL;
							$rech.= " WHERE cocl_code='".$tac_coderat."'";
							break;
						default :
							break;
					}
					break;
				// Contrat de location
				case 3 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
						case 5 :
						case 9 :
							$rech = "SELECT * FROM ".TBCOLOC;
							$rech.= " WHERE coloc_code='".$tac_code."'";
							break;
						default :
							break;
					}
					break;
				// Dossier de suivi
				case 4 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
						case 5 :
						case 9 :
							$rech = "SELECT * FROM ".TBDOS;
							$rech.= " WHERE dos_code='".$tac_coderat."'";
							break;
						default :
							break;
					}
					break;
				// Relevé de parc
				case 5 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
							$rech = "SELECT * FROM ".TBREL;
							$rech.= " WHERE rel_code='".$tac_coderat."'";
							break;
						default :
							break;
					}
					break;
				// Bon de travail
				case 6 :
					switch (@$_SESSION["niv_log"])
					{
						case 3 :
						case 4 :
						case 5 :
						case 9 :
						case 10 :
						case 11 :
							$rech = "SELECT * FROM ".TBOT;
							$rech.= " WHERE ot_code='".$tac_coderat."'";
							break;
						default :
							break;
					}
					break;
			}
			$txtrat="";
			if ($rech<>"")
			{
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query($rech) or die(mysql_error());
				if (mysql_num_rows($rs) <> 0)
				{
					if ($row = mysql_fetch_array($rs))
						extract($row);
					$rech2="";
					switch ($tac_typrat)
					{
						// Rien
						case -1 :
							break;
						// Interventions
						case 1 :
							$txtcli="";
							$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
							$rech2.= " WHERE cli_code='".$int_codecli."'";
							$rs2 = mysql_query($rech2) or die(mysql_error());
							if ($row2 = mysql_fetch_array($rs2))
								extract($row2);
							if (trim($cli_ste)<>"")
								$txtcli=$cli_ste;
							else
								$txtcli=$cli_nom." ".$cli_prenom;
							$txtrat=$int_code." du ".formatedate($int_datedde)." (".$txtcli.")";
							break;
						// Contrat de maintenance
						case 2 :
							$txtcli="";
							$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
							$rech2.= " WHERE cli_code='".$cocl_codecli."'";
							$rs2 = mysql_query($rech2) or die(mysql_error());
							if ($row2 = mysql_fetch_array($rs2))
								extract($row2);
							if (trim($cli_ste)<>"")
								$txtcli=$cli_ste;
							else
								$txtcli=$cli_nom." ".$cli_prenom;
							$txtrat=$cocl_code." du ".formatedate($cocl_datecrea)." (".$txtcli.")";
							break;
						// Contrat de location
						case 3 :
							$txtcli="";
							switch ($coloc_typcli)
							{
								// Client
								case 0 :
									$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
									$rech2.= " WHERE cli_code='".$coloc_codecli."'";
									break;
								// Agence
								case 1 :
									$rech2 = "SELECT age_nom FROM ".TBAGE;
									$rech2.= " WHERE age_code='".$coloc_codecli."'";
									break;
								// Technicien agence
								case 2 :
								// Technicien Sous-traitant
								case 4 :
									$rech2 = "SELECT tec_nom,tec_prenom FROM ".TBTEC;
									$rech2.= " WHERE tec_code='".$coloc_codecli."'";
									break;
								// Sous-traitant
								case 3 :
									$rech2 = "SELECT st_nom FROM ".TBST;
									$rech2.= " WHERE st_code='".$coloc_codecli."'";
									break;
							}
							$rs2 = mysql_query($rech2) or die(mysql_error());
							if ($row2 = mysql_fetch_array($rs2))
								extract($row2);
							switch ($coloc_typcli)
							{
								// Client
								case 0 :
									if (trim($cli_ste)<>"")
										$txtcli=$cli_ste;
									else
										$txtcli=$cli_nom." ".$cli_prenom;
									break;
								// Agence
								case 1 :
									$txtcli=$age_nom;
									break;
								// Technicien agence
								case 2 :
								// Technicien Sous-traitant
								case 4 :
										$txtcli=$tec_nom." ".$tec_prenom;
									break;
								// Sous-traitant
								case 3 :
									$txtcli=$st_nom;
									break;
							}
							$txtrat=$coloc_code." du ".formatedate($coloc_datecrea)." (".$txtcli.")";
							break;
						// Dossier de suivi
						case 4 :
							$txtcli="";
							$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
							$rech2.= " WHERE cli_code='".$dos_codecli."'";
							$rs2 = mysql_query($rech2) or die(mysql_error());
							if ($row2 = mysql_fetch_array($rs2))
								extract($row2);
							if (trim($cli_ste)<>"")
								$txtcli=$cli_ste;
							else
								$txtcli=$cli_nom." ".$cli_prenom;
							$txtrat=$dos_code." du ".formatedate($dos_datecrea)." (".$txtcli.")";
							break;
						// Relevé de parc
						case 5 :
							$txtcli="";
							$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
							$rech2.= " WHERE cli_code='".$rel_codecli."'";
							$rs2 = mysql_query($rech2) or die(mysql_error());
							if ($row2 = mysql_fetch_array($rs2))
								extract($row2);
							if (trim($cli_ste)<>"")
								$txtcli=$cli_ste;
							else
								$txtcli=$cli_nom." ".$cli_prenom;
							$txtrat=$rel_code." du ".formatedate($rel_datecrea)." (".$txtcli.")";
							break;
						// Bon de travail
						case 6 :
							$rech2 = "SELECT int_codecli FROM ".TBINT;
							$rech2.= " WHERE int_code='".$ot_codeint."'";
							$rs2 = mysql_query($rech2) or die(mysql_error());
							if ($row2 = mysql_fetch_array($rs2))
								extract($row2);
							$txtcli="";
							$rech2 = "SELECT cli_ste,cli_nom,cli_prenom FROM ".TBCLI;
							$rech2.= " WHERE cli_code='".$int_codecli."'";
							$rs2 = mysql_query($rech2) or die(mysql_error());
							if ($row2 = mysql_fetch_array($rs2))
								extract($row2);
							if (trim($cli_ste)<>"")
								$txtcli=$cli_ste;
							else
								$txtcli=$cli_nom." ".$cli_prenom;
							$txtrat=$ot_code." du ".formatedate($ot_datedde)." (".$txtcli.")";
							break;
					}
					if ($rech2<>"")
						mysql_free_result($rs2);
					mysql_close();
				}
			}
			echo '<input name="nrat" type="text" id="nrat" value="'.$txtrat.'" size="50" readonly="readonly">';
		}
		?>
	</td>
	</tr>
<?PHP if ($td <> "add") { ?>  
  <tr>
    <td class="rubfrm" id="f_ave" align="right">Etat avancement</td>
    <td>
		<?PHP
		if ($td=="edit")
		{
		?>
		<select name="ave" id="ave" onChange="verif_pour(this.value,'nivave','2');">
		<option value="" selected><?PHP echo $sel_lst_makechx; ?></option>';
		<?PHP
		
		// Création des niveaux d'avancement
		for ($i=0; $i<110; $i+=10)
		{
			if (($tac_avance <> "") AND ($tac_avance == $i))
				echo '<option value="'.$i.'" selected>'.$i.'%</option>';
			else
				echo '<option value="'.$i.'">'.$i.'%</option>';
		}
		?>
		</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 niveau d'avancement
		{
		?>
	        <input name="ave" type="text" id="ave" value="<?PHP echo $tac_avance; ?>" size="3" readonly="1">%
        <?PHP
		}
		?>
		<span id="nivave"></span>
		<br /><span class="annot_petit_it">(Niveau d'avancement du dossier)</span>
		</td>
	</tr>
<?PHP } ?>
</table>

<?PHP if ($td <> "add") { ?>  
<!-- Date de clôture de la tâche -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_datefinf" align="right">T&acirc;che termin&eacute;e le </td>
	<td>
	<table width="100%"  border="0">
	<tr>
		<td>
			<input name="datefinf" type="text" id="datefinf" value="<?PHP echo $tac_datefinf ?>" size="10" readonly="1">
			<?PHP if ($td=="edit") { ?>
			<img src="../img/calendar.png" align="absmiddle" id="f_img_datefinf" title="<?PHP echo $alt_chxdate; ?>">
			<a href="javascript:;" onclick="document.tac_maj.datefinf.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a> <span class="annot_petit_it">(Si vous saisissez une date, la t&acirc;che sera close.) </span>
			<?PHP } ?>
		</td>
	</tr>
	</table>
	</td>
</tr>
</table>
<?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; ?>">
<?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     :    "datecreaf",     // id of the input field
		ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
		button         :    "f_img_datecreaf",  // trigger for the calendar (button ID)
		align          :    "Br",           // alignment (defaults to "Bl")
		electric	   :	false,
		singleClick    :    true

	});
	<?PHP
	}

	if ($modif_ok==TRUE)
	{
	?>
	Calendar.setup({
		inputField     :    "datefinpf",     // id of the input field
		ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
		button         :    "f_img_datefinpf",  // trigger for the calendar (button ID)
		align          :    "Br",           // alignment (defaults to "Bl")
		electric	   :	false,
		singleClick    :    true
	});
	<?PHP
	}
	
	if ($td=="edit")
	{
	?>
	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
}

}
else
{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('tacc_lst.php');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Il faut au moins une cat&eacute;gorie pour la t&acirc;che ...</p>
<?PHP
}

}
else
{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('tac_lst.php?ord=DES&tri=Code');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Probl&ecirc;me dans les param&egrave;tres...</p>
<?PHP
}
include_once("pied.php");
?>
