<?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_dos.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
$cd = strip_tags(trim($_GET['cd'])); // Récupération code Dossier
$cc = strip_tags(trim($_GET['cc'])); // Récupération code Client
$ca = strip_tags(trim($_GET['ca'])); // Récupération code Agence

$pbm_dos = FALSE;
$nbligdos = 0;

$msg_err_co="Aucun contrat";

if ($ca<> "")
{
	// Contrôle qu'une agence n'essaye pas de "hacker" un dossier
	if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($ca <> @$_SESSION["code_age"]))
		$pbm_dos = TRUE;
	$dos_codeage=$ca;
}

if ($cd <> "")
{
	// Vérification qu'il existe bien des saisies dans le dossier
	// $nbligdos = nb_lig_in_dos($cd);

	// Récupération des informations dossier
	$row = lit_enr_dos($cd);
	if (is_array($row))
	{
		extract ($row);

		if ($td <> "add")
		{
			// Contrôle qu'une agence n'essaye pas de "hacker" un dossier
			if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($dos_codeage <> @$_SESSION["code_age"]))
				$pbm_dos = TRUE;
		}

		// Formatage des dates en français
		$dos_datecreaf = formatedate($dos_datecrea);
		$dos_datemodf = formatedate($dos_datemod);
		$dos_dateddef = formatedate($dos_datedde);
		$dos_datefinpf = formatedate($dos_datefinp);
		$dos_datefinf = formatedate($dos_datefin);
		
		// Si dossier terminé, on force le mode "view"
		if ($dos_datefinf <> "")
			$td="view";

		if ($td == "edit")
		{
			$cc=$dos_codecli;
			$ca=$dos_codeage;
		}

		if ($td == "add")
		{
			$dos_dateddef = $datef;
			$dos_code = $cd;
			$dos_codecli = $cc;
			$dos_codeage = $ca;
		}

		if (($td == "edit") OR ($td == "view") OR ($td == "del"))
		{
			// Calcul du prix de revient du contrat
			$pxrevient=px_revient_dos($cd,TRUE);
		}
	}
	else
		$pbm_dos = TRUE;

	
}
else
{
	if ($td == "add")
	{
		$dos_dateddef = $datef;
		$dos_code = crecodesession("DS");
		$cd = $dos_code;
	}
	else
		$pbm_dos=TRUE;
}

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

		extract ($row);

		// Contrôle qu'une agence n'essaye pas de "hacker" une intervention
		switch(@$_SESSION["niv_log"])
		{
			case 3 :
			case 4 :
				if (client_age_ok($cli_code,@$_SESSION["code_age"],TRUE)==FALSE)
					$pbm_cli = TRUE;
				break;
			default :
				break;
		}
	}
	else
	{
		$pbm_cli = TRUE;
	}
}
else
{
	if (($td=="edit") OR ($td=="view") OR ($td=="del"))
		$pbm_cli=TRUE;
}

switch ($td)
{
	case "add" :
		$titre = "SAISIE DOSSIER";
		$dos_proba="";
		break;
	case "edit" :
		$titre = "MISE A JOUR DOSSIER";
		break;
	case "view" :
		$titre = "VISUALISATION DOSSIER";
		break;
	case "del":
		$titre = "SUPPRESSION DOSSIER";
		break;
	default:
			$titre = "PROBLEME";
			$pbm_dos=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 Dossier</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:datefinpf ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date fin prévue ; stok:frmok ; stbad:frmbad",
<?PHP
	if ($td=="add")
	{
		if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
		{
			if ($cli_prop == NULL)
			{
?>
	"nom:codeage; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
			}
		}
	}
	if ($td=="add")
	{
?>		
	"nom:codecat; format:liste ; req:Y ; txt:Catégorie ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:codestatut; format:liste ; req:Y ; txt:Statut ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP } else { ?>
	"nom:codesuiv; format:liste ; req:Y ; txt:Responsable dossier ; vmn:1; stok:frmok ; stbad:frmbad",
<?PHP
	}
?>
	"nom:titred; format:txt ; req:Y ; txt:Titre ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:resum; format:txt ; req:Y ; txt:Résumé ; 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_detindos($td,$cd,""); ?>

</head>

<?PHP
switch ($td)
{
	case "del" :
		echo "<body onload=\"detindos();verif_pour(document.getElementById('proba').value,'nivproba','1');verif_pour(document.getElementById('ave').value,'nivave','2');metReadonly();warndel();\">";
		break;
	case "view" :
		echo "<body onload=\"detindos();verif_pour(document.getElementById('proba').value,'nivproba','1');verif_pour(document.getElementById('ave').value,'nivave','2');metReadonly();\">";
		break;
	case "add" :
		echo "<body onLoad=\"verif_pour(document.getElementById('proba').value,'nivproba','1');metFocus();\">";
		break;
	case "edit" :
		echo "<body onLoad=\"detindos();verif_pour(document.getElementById('proba').value,'nivproba','1');verif_pour(document.getElementById('ave').value,'nivave','2');metFocus();\">";
		break;
}

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, une origine, un statut, un lieu, une civilité, un technicien dans l'agence, et un mode de règlement -->
<?PHP
if (($pbm_dos == FALSE) AND ($pbm_cli==FALSE))
{
if ((nb_cli("") <>0) AND (nb_age_actives() <> 0) AND (nb_doss() <> 0) AND (nb_dosc() <> 0) AND nb_tec(""))
{
?>
<!-- Affiché uniquement s'il y a un code client -->
<?PHP
if ($cc <> "")
{
?>
<table width="100%"  border="0">
<tr>
	<td width="40%"><strong><em><a href="dos_lst.php?ord=ASC&tri=Fin"><?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%" align="right">
	<?PHP
	if (($td == "edit") OR ($td == "view"))
	{
	$urlimp1 = "dos_pdf.php?cd=".$cd;
	?>
	<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 }
	else
		echo "&nbsp;";
	?>
    </td>
</tr>
</table>
<form name="dos_maj" method="post" action="dos_enr.php" <?PHP if (($td=="edit") OR ($td=="add")) { ?> onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));" <?PHP } ?>>
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="codecli" type="hidden" id="codecli" value="<?PHP echo $dos_codecli ?>">
<?PHP if ($td == "add") { ?>
	<input name="code" type="hidden" id="code" value="<?PHP echo $dos_code ?>">
<?PHP } if (($td == "edit") OR ($td == "del")) { ?>
	<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $dos_codeage ?>">	
<?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 $dos_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"))
	{
		echo '<span id="strtac" style="visibility:visible">';
		$nb_tac=nb_tac(4,$dos_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(4,$dos_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=6&search=".$dos_code;?>" class="annot_petit">Voir les tâches</option>
		<?PHP } ?>
		<option value="<?PHP echo "tac_maj.php?td=add&tr=4&cr=".$dos_code;?>" class="annot_petit">Ajouter tâche</option>
		</select>
	<?PHP
	}
	else
		echo "&nbsp;";
	?>
	</td>
</tr>
</table>

<!-- Date de fin prévue -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_datefinpf" align="right">Date fin pr&eacute;vue</td>
	<td>
		<input name="datefinpf" type="text" id="datefinpf" value="<?PHP echo $dos_datefinpf ?>" size="10" maxlength="10" readonly="1">
		<?PHP if ($td == "add") { ?>
		<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>

<!-- Code du dossier (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 $dos_code ?>" size="20" maxlength="20" readonly="1">
	</td>
</tr>
</table>
<?PHP }  ?>

<!-- Affichage du client -->
<table width="100%" border="0">
<tr>
	<td class="rubfrm" id="f_codecli" align="center">Client
	<?PHP
	if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
		echo " <img src=\"../img/".$ico_cpta[$cli_cpta]."\" title =\"".$mess_cpta[$cli_cpta]."\" border=\"0\" align=\"absmiddle\">";
	?>
	</td>
</tr>
</table>

<!-- Détails client -->
<table width="100%" border="0">
<tr>
	<td 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 />";
	$chemin_imagesco = $chemin_images."/telc.png"; 
	echo "<img src=\"".$chemin_imagesco."\" align=\"bottom\">";
	echo " ".$cli_telf."<br>";
	?>
	<td width="60" valign="top">
	<?PHP 
	if (@$_SESSION["niv_log"] >= 3)
	{
	  $url_affnotesc = "aff_notesc.php?cc=".$cc;
	?>
	  <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_affnotesc; ?>',930,380,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/eye.png" border="0" align="absmiddle"></a>
	  <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_affnotesc; ?>',930,380,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")> Notes</a>
	<?PHP
	}
	else
		echo "&nbsp;";
	?>
	</td>
	</td>
</tr>
</table>

<!-- Code de l'agence (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_agence" align="right">Agence</td>
	<td>
		<?PHP
		if ($td =="add")  // Ajout = zone modifiable (on peut choisir une agence)
		{ 
			if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
			{
				if ($cli_prop == NULL) // On affiche la liste uniquement si le client est non affecté
				{
					// Création de la liste des agences ouvertes et couvrant le département du client
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					// Filtre sur agences ouvertes
					$rech = "SELECT * FROM ".TBAGE." WHERE `age_ouvert` = '1' AND `age_codepays` = '".$cli_codepays."' ORDER BY age_nom";
					$rs = mysql_query($rech) or die(mysql_error());
		
					if (mysql_num_rows($rs) <> 0)
					{
					?>
						<select name="codeage" id="codeage">
						<?PHP
							echo "<option value=\"\">".$sel_lst_age."</option>";

							while ($resultat = mysql_fetch_array($rs)) 
							{
								extract($resultat);
				
								// Vérifie zone de chalandise
								if (dep_in_zcc_age_open($cli_dep,$cli_codepays,$age_code,FALSE))
								{
									$age_nomcode = $age_nom." (".$age_code.")";
									if ($dos_codeage == $age_code)
										echo '<option value="'.$age_code.'" selected>'.$age_nomcode.'</option>';
									else
										echo '<option value="'.$age_code.'">'.$age_nomcode.'</option>';
								}
							}
						?>
						</select>
						<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				<?PHP
					}
					else
					{
				?>
						<select name="codeage" id="codeage">
						<option>-- Pas d'agence active --</option>
						</select>
				<?PHP
					}
					mysql_free_result($rs);
					mysql_close($conn);
				}
				else
				{
					$row = lit_enr_age($cli_prop,TRUE);
					extract($row);
					$age_nomcode = $age_nom." (".$age_code.")";
				?>
					<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $age_code ?>" readonly="1">
					<input name="nomage" type="text" id="nomage" value="<?PHP echo $age_nomcode ?>" size="50" maxlength="50" readonly="1">
				<?PHP
				}
			}
			else
			{
				$row = lit_enr_age($_SESSION["code_age"],TRUE);
				extract ($row);
				$age_nomcode = $age_nom." (".$age_code.")";
			?>
				<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $_SESSION["code_age"]; ?>" readonly="1">
				<input name="nagence" type="text" id="nagence" value="<?PHP echo $age_nomcode; ?>" size="50" maxlength="50" readonly="1">
			<?PHP
			}	
		} 
		else  // Edition ou suppression = zone non modifiable (affichage seul)
		{
			$row = lit_enr_age($dos_codeage,TRUE);
			extract($row);
			$age_nomcode = $age_nom." (".$age_code.")";
		?>
		<input name="nomage" type="text" id="nomage" value="<?PHP echo $age_nomcode ?>" size="50" maxlength="50" readonly="1">
		<?PHP 
		} 
		?>
	</td>
</tr>
</table>

<!-- Paramètres du dossier -->
<table width="100%"  border="0">
  <tr>
    <td width="160" class="rubfrm" id="f_cat" align="right">Cat&eacute;gorie</td>
    <td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
        	<select name="codecat" id="codecat">
        <?PHP
			
			echo "<option value=\"\">-- Choisissez une catégorie --</option>";

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

			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				if ($dos_codedosc == $dosc_code)
					echo '<option value="'.$dosc_code.'" selected>'.$dosc_desc.'</option>';
				else
					echo '<option value="'.$dosc_code.'">'.$dosc_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 ($dos_codedosc <> "")
			{
				$row = lit_enr_dosc($dos_codedosc);
				if (is_array($row))
				{
					extract($row);
					$txt_statut = $dosc_desc;
				}
			}
			if ($txt_statut<>"")
			{
		?>
			<input name="codecat" type="hidden" id="codecat" value="<?PHP echo $dos_codedosc ?>" 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 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 ".TBDOSS." ORDER BY doss_desc");

			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				if ($doss_code <> "CLOT") // Pour clore, il faut remplir la date de cloture
				{
					if ($dos_codedoss == $doss_code)
						echo '<option value="'.$doss_code.'" selected>'.$doss_desc.'</option>';
					else
						echo '<option value="'.$doss_code.'">'.$doss_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 ($dos_codedoss <> "")
			{
				$row = lit_enr_doss($dos_codedoss);
				if (is_array($row))
				{
					extract($row);
					$txt_statut = $doss_desc;
				}
			}
			if ($txt_statut<>"")
			{
		?>
			<input name="codestatut" type="hidden" id="codestatut" value="<?PHP echo $dos_codedoss ?>" readonly="1">
			<input name="nstatut" type="text" id="nstatut" value="<?PHP echo $txt_statut ?>" size="50" readonly="1">
		<?PHP
			}
			else
			{
		?>
				<span class="annot_gras_it">
				Pas de statut affect&eacute; &agrave; cette intervention
				</span>
		<?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 ($dos_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 $dos_urg ?>" readonly="1">
	        <input name="urg" type="text" id="urg" value="<?PHP echo $niv_urgence[$dos_urg] ?>" size="20" readonly="1">
        <?PHP
		}
		?>	</td>
  </tr>
  <tr>
    <td class="rubfrm" id="f_proba" align="right">Probabilit&eacute;</td>
    <td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{
		?>
			<select name="proba" id="proba" onChange="verif_pour(this.value,'nivproba','1');">
			<option value="" selected><?PHP echo $sel_lst_makechx; ?></option>';
		  <?PHP
			
			// Création des niveaux de probabilité
			
			for ($i=0; $i<110; $i+=10)
			{
				if (($dos_proba <> "") AND ($dos_proba == $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 de probabilité
		{
		?>
	        <input name="proba" type="text" id="proba" value="<?PHP echo $dos_proba; ?>" size="3" readonly="1">%
        <?PHP
		}
		?>
		<span id="nivproba"></span>
		<br /><span class="annot_petit_it">(Pourcentage de chances d'aboutir pour ce dossier)</span>
		</td>
  </tr>
<?PHP if ($td <> "add") { ?>  
  <tr>
    <td class="rubfrm" id="f_ave" align="right">Etat avancement</td>
    <td>
		<?PHP
		if (($td == "add") OR ($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 (($dos_avance <> "") AND ($dos_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 $dos_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>

<!-- Titre et résumé du dossier -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_titred" align="right">Titre</td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
			<input name="titred" type="text" id="titred" value="<?PHP echo htmlspecialchars($dos_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($dos_titre) ?>" size="50" readonly="1">
		<?PHP } ?>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_resum" align="right">R&eacute;sum&eacute;</td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
			<textarea name="resum" rows="5" id="resum" style="width:95%;"><?PHP echo htmlspecialchars($dos_res,ENT_QUOTES); ?></textarea>
			<img src="../img/oblig.png" align="top" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } else { ?>
			<textarea name="resum" rows="5" id="resum" readonly="readonly"><?PHP echo htmlspecialchars($dos_res,ENT_QUOTES); ?></textarea>
		<?PHP } ?>
	</td>
</tr>
</table>

<?PHP if ($td <> "add") { ?>  
<!-- Technicien Responsable -->
<table width="100%"  border="0">
  <tr>
    <td width="160" class="rubfrm" id="f_codesuiv" align="right">Responsable dossier</td>
    <td>
		<?PHP
		if ($td == "edit")
		{ 
			// Création de la liste des Techniciens de l'agence
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBTEC." WHERE `tec_codeage` = '$dos_codeage' AND `tec_out` = '0' ORDER BY tec_nom";
			$rs = mysql_query($rech) or die(mysql_error());
	
			if (mysql_num_rows($rs) <> 0)
			{
			?>
				<select name="codesuiv" id="codesuiv">
			<?PHP
				echo '<option value="">'.$sel_lst_tec.'</option>';
				if ($dos_codesuiv == "-1")
					echo "<option value=\"-1\" selected>-- Dossier non affecté --</option>";
				else
					echo "<option value=\"-1\">-- Dossier non affecté --</option>";

				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($dos_codesuiv == $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="codesuiv" id="codesuiv">
				<option>-- Pas de technicien actif sur cette agence --</option>
				</select>
			<?PHP
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
		else
		{
			$row = lit_enr_tec($dos_codesuiv,TRUE);
			if (is_array($row))
			{
				extract($row);
				$txt_tec = $tec_nom." ".$tec_prenom;
			}
			else
				$txt_tec="Pas de technicien affecté";
		?>
	        <input name="codesuiv" type="hidden" id="codesuiv" value="<?PHP echo $dos_codesuiv ?>" 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>

<!-- 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>
	<table width="100%"  border="0">
	<tr>
		<td>
			<input name="datefinf" type="text" id="datefinf" value="<?PHP echo $dos_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.dos_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. Saisissez tous vos d&eacute;tails AVANT de cl&ocirc;re) </span>
			<?PHP } ?>
		</td>
		<td align="right" class="annot_petit_it">
		<?PHP if ((($td == "edit") OR ($td == "view")) AND ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))) { ?>
		Prix de revient (inclus actions non closes) : 
		<span id="pxr"><?PHP echo format_num($pxrevient,2); ?></span>
		<?PHP echo " ".$lang['symbole_monnaie']; ?>
		 HT
		<?PHP } else echo "&nbsp;"; ?>
		</td>
	</tr>
	</table>
	</td>
</tr>
</table>
<?PHP } ?> <!-- Fin de zone exclue si création -->
<?PHP
if (($td == "edit") OR ($td == "del") OR ($td == "view"))
{
?>
	<table border="0" width="100%">
	<tr>
		<td class="rubfrm">
		<div align="left">Historique des actions effectu&eacute;es</div>
		</td>
	</tr>
	</table>
	<div id="detdosd">
	</div>

	<!-- Lien d'ajout de détail-->
	<?PHP
	if ($td <> "del")
	{
		if ($td == "edit")
		{
		$urlchoixdosd = "dosd_maj.php?td=add&cd=".$cd."&nd=";
	
	?>
		<table border="0" width="100%">
		<tr>
			<td width="50%">
			<?PHP 
			if (exist_dosd_open_dos($cd,TRUE)==TRUE)
				echo '<span id="chxdetdosd" style="display:none;">';
			else
				echo '<span id="chxdetdosd" style="display:inline;">';
			?>
				<a href="javascript:;" onclick="fensaisie('<?PHP echo $urlchoixdosd; ?>',900,650,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/add.png" border="0" align="absmiddle"></a>
				<a href="javascript:;" onclick="fensaisie('<?PHP echo $urlchoixdosd; ?>',900,650,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Ajouter un d&eacute;tail</a>
			<?PHP echo '</span>'; ?>
			</td>
			<td width="50%">&nbsp;
			
			</td>
		</tr>
		</table>			
	<?PHP
		}
	}
}
?>
  
<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     :    "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

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

if ($td == "add") 
{
?>
	<script type="text/javascript">
	<!--
	warnnbage(<?PHP echo nb_age_actives(); ?>,"interv");
	warnnbcli(<?PHP echo nb_cli(""); ?>,"interv");
	warnnbtec(<?PHP echo nb_tec_actifs() ?>);
	warncpta(<?PHP echo $cli_cpta; ?>,"interv");
	//-->
	</script>
<?PHP
}
else
{
	if ($dos_codestatut <> "CLOT") // Si pas encore clot, on peut tester le statut comptable
	{
?>
		<script type="text/javascript">
		<!--
		warncpta(<?PHP echo $cli_cpta; ?>,"interv");
		//-->
		</script>
<?PHP
	}
}
?>  
<!-- Fin Affiché uniquement s'il y a un code client -->
<?PHP
}
else
{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('cli_lst.php');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Merci de choisir un client...</p>
<?PHP
}
?>
<!-- Affiché uniquement s'il y a au moins un client, une agence active, une origine, un statut, un lieu, une civilité, un technicien dans l'agence, et un mode de règlement -->
<?PHP
}
else
{
	if (nb_cli("") == 0)
	{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('cli_lst.php');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins un client...</p>
<?PHP
	}

	if (nb_age_actives() == 0)
	{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('age_lst.php');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Il faut au moins une agence active ...</p>
<?PHP
	}

	if (nb_dosc() == 0) 
	{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('dosc_lst.php');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Il faut au moins une cat&eacute;gorie pour le dossier ...</p>
<?PHP
	}

	if (nb_doss() == 0) 
	{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('doss_lst.php');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Il faut au moins un statut pour le dossier ...</p>
<?PHP
	}

	if (nb_tec("") == 0)
	{
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('tec_lst.php?td=std&tl=1');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins un technicien...</p>
<?PHP
	}

}
}
else
{
	if ($pbm_dos==TRUE) 
	{
?>
		<script type="text/javascript">
		<!--
		setTimeout("self.location.href=('dos_lst.php?ord=DES&tri=Code');",2000)
		//-->
		</script>
		<p align="center" class="annot_std_it">Merci de choisir un de vos dossiers...</p>
<?PHP
	}
	else
	{
		if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
		{
?>
			<script type="text/javascript">
			<!--
			setTimeout("self.location.href=('cli_lst.php');",2000)
			//-->
			</script>
			<p align="center" class="annot_std_it">Merci de choisir un de vos clients...</p>
<?PHP
		}
	}
}
include_once("pied.php");
?>
