<?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_co.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/fic_taxes.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
$co = strip_tags(trim($_GET['co'])); // Récupération code Contrat
$cc = strip_tags(trim($_GET['cc'])); // Récupération code Client
$ca = strip_tags(trim($_GET['ca'])); // Récupération code Agence
$_SESSION["scli_choisis"] = "";
$_SESSION["rlp_choisis"] = "";

$nbcontrats = 0;
$pbm_cocl = FALSE;
$pbm_cli=FALSE;
$preavis_mini = preavis_min();
$pv_ttc=0;
$pxrevient = 0;
$tab_cli = array();

// Niveau <=3 ne peut que voir les contrats
if (@$_SESSION["niv_log"] <= 3)
	$td = "view";

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

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

		// Contrôle des hacks
		switch(@$_SESSION["niv_log"])
		{
			// Contrôle qu'un agence n'essaye pas de "hacker" un contrat
			case 1 :
				$tab_cli=give_tab_rcli($_SESSION["code_log"],TRUE);
				if (in_array($cc,$tab_cli)==FALSE)
					$pbm_cli=TRUE;
				break;
			// Contrôle qu'une agence n'essaye pas de "hacker" un contrat
			case 3 :
			case 4 :
				if (client_age_ok($cc,@$_SESSION["code_age"],TRUE)==FALSE)
					$pbm_cli = TRUE;
				break;
			default :
				break;
		}
	}
	else
		$pbm_cli = TRUE;
}
if ($co <> "")
{
	// Récupération des informations contrat client
	$row = lit_enr_cocl($co);
	if (is_array($row))
	{
		extract ($row);
		
		// Récupération des informations TVA
		$row = lit_enr_tva($cocl_codetva,TRUE);
		if (is_array($row))
			extract ($row);
	
		$txtva=$tva_tx/100;
		$pvttc=round(($cocl_pvht*(1+$txtva))*100)/100;

		// Si contrat terminé, force le mode "view"
		if (formatedate($cocl_datefin) <> "")
			$td="view";
		
		if ($td <> "add")
		{
			// Contrôle qu'un client n'essaye pas de "hacker" un contrat
			if (@$_SESSION["niv_log"] == 1)
			{
				$tab_cli=give_tab_rcli($_SESSION["code_log"],TRUE);
				if (in_array($cocl_codecli,$tab_cli)==FALSE)
					$pbm_cocl=TRUE;
			}
			
			// Contrôle qu'une agence n'essaye pas de "hacker" un contrat
			if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($cocl_codeage <> @$_SESSION["code_age"]))
				$pbm_cocl = TRUE;
		}

		// Calcul du prix de revient du contrat
		if (($td == "edit") OR ($td == "view") OR ($td == "del"))
			$pxrevient=px_revient_cocl($co,TRUE);

		// Construction de la chaîne des sites sélectionnés
		$lstsites = cree_str_lstsites_cocl($co,TRUE);
		$_SESSION["scli_choisis"] = $lstsites;
		$txtmat="";
		if ($cocl_coderlp<>"")
		{
			$txtmat=htmlspecialchars(cree_txt_matos_cocl($cocl_coderlp),ENT_QUOTES);
		}
		$_SESSION["rlp_choisis"] = $cocl_coderlp;
		$_SESSION["txtmatlst"] = $txtmat;
		
		// Vérification qu'il existe bien des contrats et nombre de ceux-ci
		$nbcontrats = nb_cocl_in_cli($cocl_codecli);

		// Vérification si ce contrat a été signé
		// Si oui, on ne peut plus rien modifier
		$signe = cocl_signed($co);
		if ($signe==TRUE)
			$td="view";

		$cocl_datecreaf = formatedate($cocl_datecrea);
		$cocl_datemodf = formatedate($cocl_datemod);
		$cocl_dateenvf = formatedate($cocl_dateenv);
		$cocl_daterecf = formatedate($cocl_daterec);
		$cocl_datesigf = formatedate($cocl_datesig);
		$cocl_datedf = formatedate($cocl_dated);
		$cocl_dateff = formatedate($cocl_datef);
		$cocl_daterelf = formatedate($cocl_daterel);
		$cocl_datefinf = formatedate($cocl_datefin);

		if ($td == "edit")
		{
			$cc=$cocl_codecli;
			$ca=$cocl_codeage;
		}

		if ($td == "view")
		{
			$cc=$cocl_codecli;
			$ca=$cocl_codeage;
		}

		if ($td == "add")
		{
			$cocl_datecreaf = $datef;
			$cocl_dateenvf = $datef;
			$cocl_daterecf = $datef;
			$cocl_code = $co;
			$cocl_codecli = $cc;
			$cocl_codeage = $ca;
			$cocl_nbs = 3600; // 1 heure...en secondes
			$cocl_nbsnc = 0;
			$cocl_renauto = 1;
			$cocl_preavis = preavis_max();
			$cocl_datedf = $datef;
			$cocl_renouv = 0;
			$cocl_sitep = 1;
		}
	}
	else
		$pbm_cocl = TRUE;
}
else
{
	if ($td == "add")
	{
		$cocl_datecreaf = $datef;
		$cocl_dateenvf = $datef;
		$cocl_code = crecodesession("CO");
		$cocl_daterecf = $datef;
		$co = $cocl_code;
		$cocl_nbs = 3600; // 1 heure...en secondes
		$cocl_nbsnc = 0;
		$cocl_renauto = 1;
		$cocl_preavis = preavis_max();
		$cocl_datedf = $datef;
		$cocl_renouv = 0;
		$cocl_sitep = 1;
		$_SESSION["scli_choisis"] = "0";
		$_SESSION["rlp_choisis"] = "";
		$_SESSION["txtmatlst"] = "";
	}
	else
		$pbm_cocl=TRUE;
}

if (($pbm_cli==FALSE) AND ($pbm_cocl==FALSE))
{
	$nbh = heure_to_hhmm(sec_heure($cocl_nbs,3,TRUE));
	$soldes=soldes_contrat($co,TRUE);
	$soldeh = heure_to_hhmm(sec_heure(soldes_contrat($co,TRUE),3,TRUE));
	// Si le délai d'intervention est nul on n'affiche rien
	if ($cocl_delai == 0)
		$cocl_delai = "";
}

switch ($td)
{
	case "add" :
		$titre = "CREATION CONTRAT CLIENT";
		break;
	case "edit" :
		$titre = "MISE A JOUR CONTRAT CLIENT";
		break;
	case "del" :
		$titre = "SUPPRESSION CONTRAT CLIENT";
		break;
	case "view" :
		if (@$_SESSION["niv_log"] == 1)
			$titre = "VISUALISATION CONTRAT";
		else
			$titre = "VISUALISATION CONTRAT CLIENT";
		break;
	default :
		$pbm_cocl=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 Contrat Client</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 == "add") OR ($td == "edit"))
{
?>
<script language="javascript">
var tab1_champ=new Array(
<?PHP
	if ($td == "add")
	{
?>
	"nom:datecreaf ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date création ; stok:frmok ; stbad:frmbad",
<?PHP
		if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
		{
			if ($cli_prop == NULL) // On affiche la liste uniquement si le client est non affecté
			{
?>
	"nom:codeage ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
			}
			else
			{
?>
	"nom:codeage ; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; stok:frmok ; stbad:frmbad",
<?PHP
			}
		}
		else
		{
?>
	"nom:codeage ; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; stok:frmok ; stbad:frmbad",
<?PHP
		}
?>
	"nom:co ; format:liste ; req:Y ; txt:Contrat type ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:cope ; format:liste ; req:Y ; txt:Fréquence ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:delai ; format:unsigned ; req:N ; txt:Délai intervention ; lmx:2 ; stok:frmok ; stbad:frmbad",
	"nom:nbh ; format:dureehhmm ; req:Y ; txt:Nombre d'heures ; stok:frmok ; stbad:frmbad",
	"nom:datedf ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date début ; stok:frmok ; stbad:frmbad",
	"nom:dateff ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:N ; txt:Date fin ; stok:frmok ; stbad:frmbad",
	"nom:preavis ; format:unsigned ; req:Y ; txt:Préavis ; lmx:3; stok:frmok ; stbad:frmbad",
	"nom:matos ; format:txt ; req:Y ; txt:Matériel; stok:frmok ; stbad:frmbad",
	"nom:pu ; format:reel_ns ; req:Y ; txt:Prix de vente hors taxes ; lmx:10 ; stok:frmok ; stbad:frmbad");
<?PHP
	}

	if ($td == "edit")
	{
?>
	"nom:datecreaf ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date création ; stok:frmok ; stbad:frmbad",
	"nom:codeage ; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_age); ?> ; stok:frmok ; stbad:frmbad",
	"nom:co ; format:txt ; req:Y ; txt:Contrat type ; stok:frmok ; stbad:frmbad",
	"nom:cope ; format:liste ; req:Y ; txt:Fréquence ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:delai ; format:unsigned ; req:N ; txt:Délai intervention ; lmx:2 ; stok:frmok ; stbad:frmbad",
	"nom:nbh ; format:dureehhmm ; req:Y ; txt:Nombre d'heures ; stok:frmok ; stbad:frmbad",
	"nom:datedf ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date début ; stok:frmok ; stbad:frmbad",
	"nom:dateff ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:N ; txt:Date fin ; stok:frmok ; stbad:frmbad",
	"nom:preavis ; format:unsigned ; req:Y ; txt:Préavis ; lmx:3; stok:frmok ; stbad:frmbad",
	"nom:matos ; format:txt ; req:Y ; txt:Matériel; stok:frmok ; stbad:frmbad",
	"nom:tva; format:liste ; req:Y ; txt:TVA ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:pu ; format:reel_ns ; req:Y ; txt:Prix de vente hors taxes ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:datesig ; format:date ; masque jj-mm-aaa ; req:N ; txt:Signé le ; stok:frmok ; stbad:frmbad",
	"nom:signe ; format:txt ; req:N ; txt:Signé par ; lmx:70 ; stok:frmok ; stbad:frmbad");
<?PHP
	}
?>	
</script>
<?PHP
}
?>

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/verif_form.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>

</head>

<?PHP if ($td == "del"){ ?>
<body onload="warndel();metReadonly();">
<?PHP }
	if ($td == "view"){ ?>
<body onload="metReadonly();">
<?PHP }
	if (($td == "edit") OR ($td == "add")){ ?>
<body onLoad="metFocus();">
<?PHP }
include_once("../inc/entete.inc.php"); 
?>

<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<!-- Affiché uniquement s'il y a un code client -->
<?PHP
if (($pbm_cocl==FALSE) AND ($pbm_cli==FALSE))
{
if ($cc <> "")
{
?>
<table width="100%"  border="0">
<tr>
	<td width="33%">
	<p><strong><em><a href="cocl_lst.php?ord=DES&tri=Code"><?PHP echo $txt_lnk_ret_liste; ?></a></em></strong></p>
    </td>
	<td width="33%" 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; ?>)</td>
	<td width="33%" align="right">&nbsp;</td>
</tr>
<tr>
	<td width="33%">
	<?PHP
	if (($td == "edit") OR ($td == "view"))
	{
		$url_coclh = "coclhd_lst.php?or=con&cc=".$cocl_codecli."&search=".$cocl_code;
	?>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_coclh; ?>',800,560,'directories=no,status=no,scrollbars=yes,menubar=no,location=no,toolbar=no');")><img src="../img/hcon.png" border="0" align="absmiddle"></a> <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_coclh; ?>',800,560,'directories=no,status=no,scrollbars=yes,menubar=no,location=no,toolbar=no');")> Historique contrat</a><?PHP
	}
	else
		echo "&nbsp;";
	?>
    </td>
	<td width="33%" valign="top">&nbsp;</td>
	<td width="33%" align="right">
		<?PHP
		if (($td == "edit") OR ($td == "view"))
		{
		?>
		<select name="etats" size="1" id="etats" onChange="javascript:; lanceimp(this.value); this.value='';" class="annot_petit">
		<option value="" selected>&raquo; Etats &laquo;</option>
		<?PHP
		if (@$_SESSION["niv_log"]<>2)
		{
			$urlimp = "cocl_pdf.php?code=".$co;
			echo "<option value=\"".$urlimp."\"  class=\"icone\" style=\"background-image: url(../img/sel_con.gif);\">Contrat</option>\n";

			$urlhisto = "cocls_pdf.php?co=".$co;
			echo "<option value=\"".$urlhisto."\"  class=\"icone\" style=\"background-image: url(../img/sel_cons.gif);\">Synthèse</option>\n";
		}
		?>		
		</select>
		<?PHP } else { ?>
		&nbsp;
		<?PHP } ?>
	</td>
</tr>
</table>

<form name="cocl_maj" method="post" action="cocl_enr.php" onSubmit="javascript:; return (verif_cocl(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>',document.cocl_maj.delai.value));">
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="codecli" type="hidden" id="codecli" value="<?PHP echo $cocl_codecli ?>">
<input name="prev" type="hidden" id="prev" value="<?PHP echo $cli_prev ?>">
<?PHP if ($td == "add") { ?>
	<input name="code" type="hidden" id="code" value="<?PHP echo $cocl_code ?>">
	<input name="renouv" type="hidden" id="renouv" value="<?PHP echo $cocl_renouv ?>">
	<input name="num" type="hidden" id="num" value="">
	<input name="datefinf" type="hidden" id="datefinf" value="">
<?PHP } ?>

<!-- Détails internes de la fiche contrat -->
<table width="100%"  border="0">
<tr>
	<td width="33%">
	<?PHP if ((($td == "edit") OR ($td == "view")) AND (@$_SESSION["niv_log"] >= 3))
	{
		$url_detcocl = "cocld_maj.php?co=".$co;
	?>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_detcocl; ?>',800,300,'directories=no,status=no,scrollbars=no,menubar=no,location=no,toolbar=no');")><img src="../img/eye.png" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_detcocl; ?>',800,300,'directories=no,status=no,scrollbars=no,menubar=no,location=no,toolbar=no');")> Détails</a>
	<?PHP
	}
	else
	{
	?>
		&nbsp;
	<?PHP
	}
	?>
    </td>
	<td width="33%" valign="top">&nbsp;</td>
	<td width="33%">
	<div align="right">
	<?PHP 
	 $echeance_ok = TRUE;
	 if ($cocl_dateff <> "")
	 {
		if (echeance_depassee_date($datea,$cocl_datef) == TRUE)
			$echeance_ok = FALSE;
	 }
	if ((($td == "edit") OR ($td == "view")) AND ($cocl_datefinf == "") AND ($cocl_datesigf <> "") AND ($echeance_ok == TRUE) AND (@$_SESSION["niv_log"] >= 3))
	{
		$url_int = "int_maj.php?td=add&ci=&cc=".$cc."&ca=".$ca."&co=".$co;
	?>
	  <a href="javascript:;" onclick="javascript:; window.location=('<?PHP echo $url_int; ?>');"><img src="../img/int.png" border="0" align="absmiddle"></a>
	  <a href="javascript:;" onclick="javascript:; window.location=('<?PHP echo $url_int; ?>');")> Saisir intervention</a>
	<?PHP
	}
	else
	{
	?>
		&nbsp;
	<?PHP
	}
	?>
	</div>
	</td>
</tr>
</table>

<!-- Date de création -->
<table width="100%"  border="0">
<tr>
	<td width="250" class="rubfrm" id="f_datecreaf" align="right">Date Cr&eacute;ation </td>
	<td>
		<input name="datecreaf" type="text" id="datecreaf" value="<?PHP echo $cocl_datecreaf ?>" size="10" maxlength="10" readonly="1">
		<?PHP if ($td == "add") { ?>
		<img src="../img/calendar.png" align="absmiddle" id="f_img_datecreaf" 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(2,$cocl_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(2,$cocl_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=4&search=".$cocl_code;?>" class="annot_petit">Voir les tâches</option>
		<?PHP } ?>
		<option value="<?PHP echo "tac_maj.php?td=add&tr=2&cr=".$cocl_code;?>" class="annot_petit">Ajouter tâche</option>
		</select>
	<?PHP
	}
	else
		echo "&nbsp;";
	?>
	</td>
</tr>
</table>

<!-- Code du contrat client (affiché uniquement si édition ou suppression) -->
<?PHP if ($td <> "add") {?>
<table width="100%"  border="0">
<tr>
	<td width="250" class="rubfrm" id="f_codecocl" align="right">Code </td>
	<td>
		<input name="code" type="text" id="code" value="<?PHP echo $cocl_code ?>" size="20" maxlength="20" readonly="1">
		<?PHP
		 $echeance_ok = TRUE;
		 if ($cocl_dateff <> "")
		 {
			if (echeance_depassee_date($datea,$cocl_datef) == TRUE)
				$echeance_ok = FALSE;
		 }
		if (($cocl_datesigf == "") OR ($cocl_datefinf <> "") OR ($echeance_ok == FALSE))
		{
			if ($cocl_datesigf == "")
			{
				echo '<span class="alerte1">';
				echo 'Non Sign&eacute;';
				echo '</span>';
				if (($cocl_datefinf <> "") OR ($echeance_ok == FALSE))
				{
					echo "<strong><em>";
					echo " / ";
					echo "</strong></em>";
				}
			}
			if (($cocl_datefinf <> "") OR ($echeance_ok == FALSE))
			{
				echo '<span class="alerte1">';
				echo 'Termin&eacute;';
				echo '</span>';
			}
		}
		?>
	</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>
	<td width="280" 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,'directories=no,status=no,scrollbars=no,menubar=no,location=no,toolbar=no');")><img src="../img/eye.png" border="0" align="absmiddle"></a>
		  <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_affnotesc; ?>',930,380,'directories=no,status=no,scrollbars=no,menubar=no,location=no,toolbar=no');")> Notes</a>
   <?PHP
   }
	if (nb_scli_actifs($cc,"",TRUE)>0)
  {
	  $url_modsitep = "sitep_maj.php?cc=".$cc."&co=".$cocl_code."&td=".$td;
	  $url_choixsitesc = "sites_lst.php?cc=".$cc."&co=".$cocl_code."&td=".$td;
  ?>
		<br>
		<input type="checkbox" name="sitep" value="sitep" onclick="fensaisie('<?PHP echo $url_modsitep; ?>',300,50,'directories=no,status=no,scrollbars=no,menubar=no,location=no,toolbar=no');" style="background : #FFFFFF;" <?PHP if ($cocl_sitep==1) echo "checked=\"checked\"";
if (($signe == TRUE) OR ($td == "view")) echo "disabled=\"disabled\""; ?>>
		<span class="annot_std_gras">Site principal inclus dans le contrat</span>
	    <br>
		<input name="sitesec" type="hidden" id="sitesec" value="<?PHP echo $_SESSION["scli_choisis"]; ?>">
	  	<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_choixsitesc; ?>',920,500,'directories=no,status=no,scrollbars=yes,menubar=no,location=no,toolbar=no');")><img src="../img/sites.png" border="0" align="bottom"></a>
	    <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_choixsitesc; ?>',920,500,'directories=no,status=no,scrollbars=yes,menubar=no,location=no,toolbar=no');")> Sites secondaires couverts</a>
   <?PHP
	}
	else
	{
	?>
		<br>
		<input type="hidden" name="sitep" value="sitep">
		<input type="checkbox" name="sitepc" value="sitepc" style="background : #FFFFFF;" checked="checked" disabled="disabled">
		<span class="annot_std_gras">Site principal inclus dans le contrat</span>
	<?PHP
	}
	?>
        </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="250" 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"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
			{
				if ($cli_prop == NULL) // On affiche la liste uniquement si le client est non affecté
				{
					// Création de la liste des agences ouvertes et couvrant le client
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					$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);
								if (dep_in_zcc_age_open($cli_dep,$cli_codepays,$age_code,FALSE))
								{
									$age_nomcode = $age_nom." (".$age_code.")";
									if ($cocl_codeage == $age_code)
										echo '<option value="'.$age_code.'" selected>'.$age_nomcode.'</option>';
									else
										echo '<option value="'.$age_code.'">'.$age_nomcode.'</option>';
								}
							}
						?>
						</select>
					<?PHP
					}
					else
					{
					?>
						<select name="codeage" id="codeage">
						<option>-- Pas d'agence --</option>
						</select>
					<?PHP
					}
					mysql_free_result($rs);
					mysql_close($conn);
					?>
					<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
				<?PHP
				}
				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 ?>">
					<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 $age_code ?>">
				<input name="nomage" type="text" id="nomage" 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($cocl_codeage,TRUE);
			extract($row);
			$age_nomcode = $age_nom." (".$age_code.")";
		?>
		<input name="codeage" type="hidden" id="codeage" value="<?PHP echo $age_code ?>">
		<input name="nomage" type="text" id="nomage" value="<?PHP echo $age_nomcode ?>" size="50" maxlength="50" readonly="1">
		<?PHP 
		} 
		?>
	</td>
</tr>
</table>

<!-- Type de contrat -->
<table width="100%"  border="0">
  <tr>
    <td width="250" class="rubfrm" id="f_co" align="right">Contrat Type </td>
    <td><?PHP
		if ($td =="add")  // Ajout = zone modifiable (on peut choisir un type de contrat)
		{
			// Création de la liste des types de contrats actifs
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBCO."  WHERE co_actif = '1' ORDER BY co_nom";
			$rs = mysql_query($rech) or die(mysql_error());

			if (mysql_num_rows($rs) <> 0)
			{
			?>
        <select name="co" id="co">
          <?PHP
				echo "<option>-- Choisissez un contrat type --</option>";

				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
	
					if ($cocl_codeco == $co_code)
						echo '<option value="'.$co_code.'" selected>'.$co_nom.'</option>';
					else
						echo '<option value="'.$co_code.'">'.$co_nom.'</option>';
				}
			?>
        </select>
        <?PHP
			}
			else
			{
		?>
				<select name="co" id="co">
				<option>-- Pas de contrat type actif --</option>
				</select>
		<?PHP
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
        <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
        <?PHP 
		} 
		else  // Edition ou suppression = zone non modifiable (affichage seul)
		{
			$row = lit_enr_co($cocl_codeco);
			extract($row);
		?>
        <input name="co" type="hidden" id="co" value="<?PHP echo $cocl_codeco ?>" size="20">
        <input name="nomco" type="text" id="nomco" value="<?PHP echo $co_nom ?>" size="50" maxlength="50" readonly="1">
        <?PHP 
		} 
		?>
    </td>
  </tr>
</table>

<!-- Périodicité du contrat -->
<table width="100%"  border="0">
  <tr>
    <td width="250" class="rubfrm" id="f_cope" align="right">Fr&eacute;quence</td>
    <td>
		<?PHP
		if (($signe == FALSE) AND ($td <> "view")) // Affichage du choix de périodicité uniquement si pas encore signé
		{ 
			// Création de la liste des types des périodicités
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBPER." ORDER BY per_nbj";
			$rs = mysql_query($rech) or die(mysql_error());

			if (mysql_num_rows($rs) <> 0)
			{
		?>
        		<select name="cope" id="cope" onChange="verif_delai()">
		<?PHP
				echo "<option value=\"0\">-- Choisissez une fréquence --</option>";

				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
	
					if ($per_nbj <> 0)
						$txt_nbj = " (tous les ".$per_nbj." jours)";
					else
						$txt_nbj = " (à la demande)";

					if ($cocl_codeper == $per_code)
						echo '<option value="'.$per_code.'" selected>'.$per_desc.$txt_nbj.'</option>';
					else
						echo '<option value="'.$per_code.'">'.$per_desc.$txt_nbj.'</option>';
				}
		?>
        		</select>
        <?PHP
			}
			else
			{
		?>
        		<select name="cope" id="cope">
				<option>-- Pas de fr&eacute;quence à choisir --</option>
        		</select>
		<?PHP
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
        	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP
		} 
		else 
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBPER." WHERE `per_code` = '".$cocl_codeper."'";
			$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="cope" type="hidden" id="cope" value="<?PHP echo $cocl_codeper ?>">
        <input name="tcope" type="text" id="tcope" value="<?PHP echo htmlspecialchars($per_desc); ?>" size="20" maxlength="20" readonly="1">
		<?PHP 
		} 
		?>
	 </td>
  </tr>
</table>

<!-- Délai d'intervention -->
<table width="100%"  border="0">
<tr>
	<td width="250" class="rubfrm" id="f_delai" align="right">
		D&eacute;lai Interv.
	</td>
    <td>
		<?PHP
		if (($signe == FALSE) AND ($td <> "view")) // Affichage du choix de périodicité uniquement si pas encore signé
		{
		?>
			<input name="delai" type="text" id="delai" value="<?PHP echo $cocl_delai ?>" size="2" maxlength="2" align="right">
			<span class="annot_petit_it">heures ouvr&eacute;es(obligatoire seulement si &agrave; la demande) </span>
		<?PHP
		}
		else // Si c'est signé, on se contente d'afficher le délai d'intervention
		{
		?>
	        <input name="delai" type="text" id="delai" value="<?PHP echo $cocl_delai ?>" size="2" maxlength="2" align="right" readonly="1">
			<span class="annot_petit_it">heures ouvr&eacute;es </span>
		<?PHP
		}
		?> 
	</td>
</tr>
</table>

<!-- Nombre d'heures par contrat -->
<table width="100%"  border="0">
<tr>
    <td width="250" class="rubfrm" id="f_nbheures" align="right">Nb heures</td>
    <td>
		<?PHP
		if (($signe == FALSE) AND ($td <> "view")) // Affichage du choix de périodicité uniquement si pas encore signé
		{
		?>
			<select name="nbh" id="nbh">
			<?PHP
			// Création de la liste des heures
			for ($i=0; $i<3600000 ;$i+=900)
			{
				$heure=heure_to_hhmm(sec_heure($i,3,TRUE));

				if ($nbh == $heure)
					echo '<option value="'.$heure.'" selected>'.$heure.'</option>';
				else
					echo '<option value="'.$heure.'">'.$heure.'</option>';
			}
			?>
			</select>
			<span class="annot_std_gras">,</span>
			<select name="typh" id="typh">
			<option value="0" <?PHP if ($cocl_typh == 0) echo "selected"; ?>>Par intervention</option>
			<option value="1" <?PHP if ($cocl_typh == 1) echo "selected"; ?>>Quota d'heures</option>
			</select>
		<?PHP
		}
		else // Si c'est signé, on se contente d'afficher le détail horaire
		{
		?>
	        <input name="nbh" type="text" id="nbh" value="<?PHP echo $nbh ?>" size="6" maxlength="6" readonly="1">
			<span class="annot_std_gras">,</span>
	        <input name="typh" type="text" id="typh" value="<?PHP echo $typ_horaire[$cocl_typh]; ?>" size="20" maxlength="20" readonly="1">
		<?PHP
			if ((($td == "edit") OR ($td == "del") OR ($td == "view")) AND ($cocl_typh == 1))
			{
		?> 
			<br>
			<span class="annot_std_it">Solde :</span>		
			<input name="soldeh" type="text" id="soldeh" value="<?PHP echo $soldeh ?>" size="6" maxlength="6" readonly="1">
			 <span class="annot_petit_it">(Heures &agrave; sortir : <?PHP echo heure_to_hhmm(sec_heure(tps_trav_non_clot($cocl_code,TRUE),3,TRUE)); ?>. Voir historique)</span>
		<?PHP
			}
		}
		?>
	</td>
</tr>
<tr>
    <td width="250" class="rubfrm" id="f_nbsnc" align="right">Report heures non consomm&eacute;es ?</td>
    <td>
	<?PHP
	if (($td == "edit") OR ($td == "add"))
	{
	?> 
	<select name="nbsnc" id="nbsnc">
	<?PHP
	echo '<option value="">--- Choisissez ---</option>';
	echo '<option value="0"';
	if ($cocl_nbsnc == 0)
		echo ' selected';
	echo '>'.$sel_lst_non.'</option>';
	echo '<option value="1"';
	if ($cocl_nbsnc == 1)
		echo ' selected';
	echo '>'.$sel_lst_oui.'</option>';
	?>
	</select>
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP } else { ?>
	<input name="nbsnc" type="hidden" id="nbsnc" value="<?PHP echo $cocl_nbsnc; ?>">
	<input name="txtnbsnc" type="text" id="txtnbsnc" value="<?PHP echo $non_oui[$cocl_nbsnc]; ?>" size="3" maxlength="3" readonly="1">
	<?PHP } ?>
	<br>
	<span class="annot_petit_it">Si 'Oui' : &agrave; la cl&ocirc;ture, si la date d'&eacute;ch&eacute;ance est d&eacute;pass&eacute;e, les heures non consomm&eacute;es seront rajout&eacute;es sur un autre contrat. Param&egrave;tre pris en compte uniquement pour les 'Quotas Horaires'.</span>
  </tr>
  <tr>
    <td width="250" class="rubfrm" id="f_nbsdep" align="right">Report heures d&eacute;pass&eacute;es ?</td>
    <td>
	<?PHP
	if (($td == "edit") OR ($td == "add"))
	{
	?> 
	<select name="nbsdep" id="nbsdep">
	<?PHP
	echo '<option value="">--- Choisissez ---</option>';
	echo '<option value="0"';
	if ($cocl_nbsdep == 0)
		echo ' selected';
	echo '>'.$sel_lst_non.'</option>';
	echo '<option value="1"';
	if ($cocl_nbsdep == 1)
		echo ' selected';
	echo '>'.$sel_lst_oui.'</option>';
	?>
	</select>
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP } else { ?>
	<input name="nbsdep" type="hidden" id="nbsdep" value="<?PHP echo $cocl_nbsdep; ?>">
	<input name="txtnbsdep" type="text" id="txtnbsdep" value="<?PHP echo $non_oui[$cocl_nbsdep]; ?>" size="3" maxlength="3" readonly="1">
	<?PHP } ?>
	<br>
	<span class="annot_petit_it">Si 'Oui' : &agrave; la cl&ocirc;ture, les heures d&eacute;passant le quota seront d&eacute;duites d'un autre contrat.  Param&egrave;tre pris en compte uniquement pour les 'Quotas Horaires'.</span>
  </tr>
</table>

<!-- Dates de "vie" du contrat -->
<table width="100%"  border="0">
  <tr>
    <td width="250" class="rubfrm" id="f_validite" align="right">Validit&eacute;</td>
    <td>
		<span class="annot_petit_gras">Du</span>      
		<input name="datedf" type="text" id="datedf" value="<?PHP echo $cocl_datedf ?>" size="10" maxlength="10" readonly="1">
		<?PHP if (($signe == FALSE) AND ($td <> "view")) { // On peut modifier la date de départ uniquement si pas signé ?>
        <img src="../img/calendar.png" align="absmiddle" id="f_img_datedf" title="<?PHP echo $alt_chxdate; ?>"> 
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } ?>
		 <span class="annot_petit_gras">au</span>	    
		 <input name="dateff" type="text" id="dateff" value="<?PHP echo $cocl_dateff ?>" size="10" maxlength="10" readonly="1">
		<?PHP if (($signe == FALSE) AND ($td <> "view")) { // On peut modifier la date de fin uniquement si pas signé ?>
        <img src="../img/calendar.png" align="absmiddle" id="f_img_dateff" title="<?PHP echo $alt_chxdate; ?>"> 
		<a href="javascript:;" onclick="document.cocl_maj.dateff.value=''"><img src="../img/raz.png" border="0" align="absmiddle"></a> 
        <span class="annot_petit_it">(ne pas mettre de date de fin pour un contrat 'illimit&eacute;') </span>
		<?PHP } ?>
	</td>
  </tr>
  <tr>
    <td width="250" class="rubfrm" id="f_renauto" align="right">Renouvellement automatique ?</td>
    <td>
	<?PHP
	if (($td == "edit") OR ($td == "add"))
	{
	?> 
	<select name="renauto" id="renauto">
	<?PHP
	echo '<option value="">--- Choisissez ---</option>';
	echo '<option value="0"';
	if ($cocl_renauto == 0)
		echo ' selected';
	echo '>'.$sel_lst_non.'</option>';
	echo '<option value="1"';
	if ($cocl_renauto == 1)
		echo ' selected';
	echo '>'.$sel_lst_oui.'</option>';
	?>
	</select>
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP } else { ?>
	<input name="renauto" type="hidden" id="renauto" value="<?PHP echo $cocl_nbsdep; ?>">
	<input name="txtrenauto" type="text" id="txtrenauto" value="<?PHP echo $non_oui[$cocl_renauto]; ?>" size="3" maxlength="3" readonly="1">
	<?PHP } ?>
	<br />
	<span class="annot_petit_it">Si 'Oui' : &agrave; la cl&ocirc;ture, le contrat sera automatiquement renouvel&eacute;, avec validation directe de l'accord client. </span>
  </tr>
</table>

<!-- Nombre de jours de préavis -->
<table width="100%"  border="0">
  <tr>
    <td width="250" class="rubfrm" id="f_preavis" align="right">Pr&eacute;avis</td>
    <td>
		<?PHP if (($signe == FALSE) AND ($td <> "view")) { // On peut modifier le préavis uniquement si pas signé ?>
		<input name="preavis" type="text" id="preavis" value="<?PHP echo $cocl_preavis ?>" size="3" maxlength="3" align="right"> 
		<span class="annot_std_gras">jours avant date d'&eacute;ch&eacute;ance</span> 
		<?PHP 
			echo "<span class=\"annot_petit_it\">";
			echo "(La valeur doit se trouver entre ".preavis_max()." et ".preavis_min()." jours)";
			echo "</span>";
		?>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP		
		} 
		else 
		{?>
		<input name="preavis" type="text" id="preavis" value="<?PHP echo $cocl_preavis ?>" size="3" maxlength="3" align="right" readonly="1"> 
		<span class="annot_std_gras">jours avant date d'&eacute;ch&eacute;ance</span> 
		<?PHP } ?>
	</td>
  </tr>
</table>

<!-- Détail matériel concerné -->
<table width="100%"  border="0">
  <tr>
	<td class="rubfrm" colspan="2" id="f_matos">
		<div align="center">Mat&eacute;riel Concern&eacute;</div>
	</td>
  </tr>
  <tr>
	<td colspan="2">
	<?PHP 
	// On peut modifier le matériel uniquement si pas signé 
	if (($signe == FALSE) AND ($td <> "view")) 
	{
		$url_recuplp = "rlp_lst.php?td=".$td."&cc=".$cocl_codecli."&co=".$cocl_code;
		
		$exist_rlp=FALSE;
		if ((exist_rlic_actif($cocl_codecli) == TRUE) OR (exist_rpdt_actif($cocl_codecli) == TRUE))
			$exist_rlp=TRUE;
	?>
		<div id="boutmat">
		<table width="100%" border="0">
		<tr>
			<td width="50%">
				<input name="addrlp" type="button" class="bton_std" id="addrlp" value="Choisir Mat&eacute;riel/Licences" style="background-color:#FF0000; color:#FFFF00; font-weight:bold;" onClick="fenchoixrel('<?PHP echo $url_recuplp; ?>',1024,600,'directories=no,status=no,scrollbars=yes,menubar=no,location=no,toolbar=no');">
				<span class="annot_petit_it">(Cliquer)</span>
			</td>
			<td align="right">
				<input name="modmat" type="button" class="bton_std" id="modmat" value="Modifier saisie" onClick="document.cocl_maj.matos.readOnly = false; document.cocl_maj.matos.focus(); this.style.backgroundColor='#00FFFF';">
			</td>
		</tr>
		</table>
		</div>
	<?PHP
		if ($exist_rlp == TRUE)
		{
	?>
		<textarea name="matos" rows="20" id="matos" onBlur="document.cocl_maj.matos.readOnly=true; document.cocl_maj.modmat.style.backgroundColor='#CCCCCC';"><?PHP echo htmlspecialchars($cocl_matos,ENT_QUOTES); ?></textarea>
	<?PHP
		}
		else
		{
	?>
		<textarea name="matos" rows="20" id="matos"><?PHP echo htmlspecialchars($cocl_matos,ENT_QUOTES); ?></textarea>
	<?PHP
		}
	?>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<div id="notamat" class="annot_petit_it">Si vous avez choisi des mat&eacute;riels, ne saisissez pas de texte compl&eacute;mentaire dans celui g&eacute;n&eacute;r&eacute; par SMI, mais avant ou apr&egrave;s.</div>
	<?PHP
		if ($exist_rlp == FALSE)
		{
	?>
		<script type="text/javascript">
		<!--
		display('boutmat','none');
		display('notamat','none');
		//-->
		</script>
	<?PHP
		}
	} 
	else
	{
	?>
		<textarea name="matos" rows="20" id="matos" readonly="readonly"><?PHP echo htmlspecialchars($cocl_matos,ENT_QUOTES); ?></textarea>
	<?PHP 
	} 
	?>
	</td>
  </tr>
</table>

<?PHP if ($td <> "add") { ?>  <!-- Début de zone exclue si création -->
<!-- Signataire du contrat -->
<table width="100%"  border="0">
<tr>
	<td width="250" class="rubfrm" id="f_datesig" align="right">Sign&eacute; le </td>
	<td>
		<input name="datesig" type="text" id="datesig" value="<?PHP echo $cocl_datesigf ?>" size="10" maxlength="10" readonly="1">
	</td>
</tr>
<tr>
	<td width="250" class="rubfrm" id="f_signe" align="right">Sign&eacute; par </td>
	<td>
		<input name="signe" type="text" id="signe" value="<?PHP echo htmlspecialchars($cocl_signe) ?>" size="70" readonly="1">
	</td>
</tr>
</table>

<br>

<!-- Affichage uniquement si le client a été relancé -->
<?PHP if ($cocl_daterelf <> "") { ?>  
<!-- Date de relance du contrat -->
<table width="100%"  border="0">
  <tr>
    <td width="250" class="rubfrm" id="f_daterelf" align="right">Relanc&eacute; le </td>
    <td>
		<input name="daterelf" type="text" id="daterelf" value="<?PHP echo $cocl_daterelf ?>" size="10" maxlength="10" readonly="1">
        <span class="annot_petit_it">
		<?PHP 
			echo "(".$cocl_nivrel." fois)";
		?>
		</span>
	</td>
  </tr>
</table>
<?PHP } ?>

<!-- Affiché uniquement si contrat signé -->
<?PHP if ($cocl_datesigf <> "") { ?>  

<!-- Contrat renouvelé ou pas ? -->
<table width="100%"  border="0">
<tr>
	<td width="250" class="rubfrm" id="f_renouv" align="right">Renouvel&eacute;</td>
	<td>
		<input name="renouv" type="text" id="renouv" value="<?PHP echo $non_oui[$cocl_renouv]; ?>" size="3" maxlength="3" readonly="1">
		<span class="annot_std_gras">Nouveau contrat :</span>
		<input name="num" type="text" id="num" value="<?PHP echo $cocl_rnum; ?>" size="20" maxlength="20" readonly="1">
		<?PHP
		if (@$_SESSION["niv_log"] >= 4)
		{
			if ($cocl_renouv==0)
			{
				if (formatedate($cocl_datesig) <> "") // Uniquement si signé
				{
					$url_rencocl="coclren_maj.php?co=".$cocl_code;
			?>
			<a href="<?PHP echo $url_rencocl ?>"><img src="../img/renouv.png" title="Renouveler le contrat" border="0" align="absmiddle"></a>
			<a href="<?PHP echo $url_rencocl ?>"> Renouveler le contrat </a>
			<?PHP
					if (formatedate($cocl_datef) <> "") // Uniquement si date de fin
					{
						$datemin = nouv_date_moins_jours($cocl_datef,$preavis_mini);
						$datebut = nouv_date_moins_jours($cocl_datef,$cocl_preavis);
						
						// Si c'est trop tôt (date mini de préavis < aujourd'hui) on affiche une icône complémentaire
						if (comp_date($datemin,$datea) == FALSE)
						{
							$lst_ttot = TRUE;
							
							echo " ";
							echo "<img src=\"../img/tot.png\" title=\"Trop tôt (à partir du ".formatedate($datemin).")\" border=\"0\" align=\"absmiddle\">";
						}
						
						// Si c'est trop tard (aujourd'hui > date butoir) on affiche une icône complémentaire
						if (comp_date($datea,$datebut) == FALSE)
						{
							$lst_ttard = TRUE;
							
							echo " ";
							echo "<img src=\"../img/tard.png\" title=\"Trop tard (depuis le ".formatedate($datebut).")\" border=\"0\" align=\"absmiddle\">";
						}
					}
				}
			}
		}
	?>				
	</td>
</tr>
</table>

<!-- Date de clôture du contrat -->
<table width="100%"  border="0">
<tr>
	<td width="250" class="rubfrm" id="f_datefinf" align="right">Contrat cl&ocirc;t le </td>
	<td>
		<input name="datefinf" type="text" id="datefinf" value="<?PHP echo $cocl_datefinf ?>" size="10" maxlength="10" readonly="1">
		<?PHP
		if (($cocl_datefinf=="") AND (tps_trav_non_clot($cocl_code,TRUE)==0) AND ((@$_SESSION["niv_log"]==9) OR (@$_SESSION["niv_log"]==5) OR (@$_SESSION["niv_log"]==4)))
			echo' <a href="coclclos_maj.php?co='.$cocl_code.'"><img src="../img/clore.png" border="0" align="absmiddle"> Clore manuellement</a>';
		?>
	</td>
</tr>
<!-- Fin affiché uniquement si contrat signé -->
<?PHP 
} 
?>  
</table>


<?PHP } ?>  <!-- Fin de zone exclue si création -->

<!-- Montant du contrat -->
<table width="100%"  border="0">
<tr>
    <tr>
		<td width="250" class="rubfrm" id="f_pu" align="right">PV HT</td>
		<td>
		<table width="100%"  border="0">
		<tr>
		<td>
	<?PHP if (($signe == FALSE) AND ($td <> "view")) { // On peut modifier le prix uniquement si pas signé ?>
          <input name="pu" type="text" id="pu" style="text-align:right" value="<?PHP echo format_num($cocl_pvht,2); ?>" size="10" onChange="formatedeci(this.id,2);ttc_from_ht(this.value,'tva','puttc',2);">
      <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"><br>
      <span class="annot_petit_it">(La d&eacute;cimale doit &ecirc;tre '.' et pas la virgule)</span> </p>
	<?PHP } else { ?>
          <input name="pu" type="text" id="pu" style="text-align:right" value="<?PHP echo $cocl_pvht ?>" size="10" readonly="1"> 
	<?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 '&agrave; sortir') : 
	<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>
    <tr>
      <td width="250" class="rubfrm" id="f_tva" align="right">TVA</td>
      <td>
      <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		<select name="tva" size="1" id="tva" onChange="ttc_from_ht(document.getElementById('pu').value,this.id,'puttc',2);">
	  <?PHP
		echo "<option value=\"\">-- Choisissez une TVA --</option>";
		
		// Création de la liste des TVA
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBTVA." WHERE tva_actif=1 ORDER BY tva_desc");

		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			echo '<option value="'.$tva_code.'"';
			if ($cocl_codetva == $tva_code)
				echo ' selected';
			echo '>'.$tva_desc.'</option>';
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	  <?PHP
		// Création des taux de TVA (champs cachés)
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBTVA." WHERE tva_actif=1 ORDER BY tva_desc");

		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			echo '<input name="'.$tva_code.'" type="hidden" id="'.$tva_code.'" value="'.$tva_tx.'">';
		}
		mysql_free_result($rs);
		mysql_close($conn);
	  }
	  else
	  {
		$row=lit_enr_tva($cocl_codetva,TRUE);
		if (is_array($row))
			extract($row);
	  ?>
		<input name="tva" type="hidden" id="tva" value="<?PHP echo $cocl_codetva ?>"> 
		<input name="ntva" type="text" id="ntva" align="right" value="<?PHP echo $tva_desc ?>" size="40" readonly="1"> 
	  <?PHP
	  }
	  ?>
	</td>
    </tr>
    <tr>
      <td width="250" class="rubfrm" id="f_puttc" align="right">PV TTC</td>
      <td>
      <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		<input name="puttc" type="text" id="puttc" style="text-align:right" value="<?PHP echo format_num($pvttc,2); ?>" size="10" onChange="formatedeci(this.id,2);ht_from_ttc(this.value,'tva','pu',2);"><br>
		<span class="annot_petit_it">(La d&eacute;cimale doit &ecirc;tre '.' et pas la virgule)</span>
	  <?PHP
	  }
	  else
	  {
	  ?>
		<input name="pu" type="text" id="pu" style="text-align:right" value="<?PHP echo format_num($pvttc,2); ?>" size="10" maxlength="10" readonly="1"> 
	  <?PHP
	  }
	  ?>
      </td>
    </tr>
</table>


<p align="center">
<?PHP 
if (($td == "edit") or ($td == "add")) // Boutons si en édition ou création
{ 
?>
	<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="<?PHP echo $but_enrimp; ?>">
<?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")
{
	if (($td == "edit") OR ($td == "del"))
	{
		if ($signe == "")
		{
?>
			<script type="text/javascript">
			<!--
				Calendar.setup({
					inputField     :    "datedf",     // id of the input field
					ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
					button         :    "f_img_datedf",  // trigger for the calendar (button ID)
					align          :    "Br",           // alignment (defaults to "Bl")
					electric	   :	false,
					singleClick    :    true
				});
				Calendar.setup({
					inputField     :    "dateff",     // id of the input field
					ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
					button         :    "f_img_dateff",  // trigger for the calendar (button ID)
					align          :    "Br",           // alignment (defaults to "Bl")
					electric	   :	false,
					singleClick    :    true
				});
			//-->
			</script>
<?PHP
		} 
	} 
	else 
	{ 
?>
	<script type="text/javascript">
	<!--
		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
		});
		Calendar.setup({
			inputField     :    "datedf",     // id of the input field
			ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
			button         :    "f_img_datedf",  // trigger for the calendar (button ID)
			align          :    "Br",           // alignment (defaults to "Bl")
			electric	   :	false,
			singleClick    :    true
		});
		Calendar.setup({
			inputField     :    "dateff",     // id of the input field
			ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
			button         :    "f_img_dateff",  // trigger for the calendar (button ID)
			align          :    "Br",           // alignment (defaults to "Bl")
			electric	   :	false,
			singleClick    :    true
		});
	//-->
	</script>
<?PHP 
	}
}
if ($td == "add") 
{
?>
	<script type="text/javascript">
	<!--
	warnnbage(<?PHP echo nb_age_actives(); ?>,"cont");
	warnnbtec(<?PHP echo nb_tec_actifs() ?>);
	//-->
	</script>
<?PHP
}
else
{
	if ($td == "edit")
	{
?>
	<script type="text/javascript">
	<!--
	warncpta(<?PHP echo $cli_cpta; ?>,"cont");
	//-->
	</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
}
}
else
{
	if ($pbm_cocl==TRUE) 
	{
?>
		<script type="text/javascript">
		<!--
		setTimeout("self.location.href=('cocl_lst.php?ord=DES&tri=Code');",2000)
		//-->
		</script>
		<p align="center" class="annot_std_it">Merci de choisir un de vos contrats...</p>
<?PHP
	}
	else
	{
		if (@$_SESSION["niv_log"] == 1)
		{
?>
			<script type="text/javascript">
			<!--
			setTimeout("self.location.href=('index.php');",2000)
			//-->
			</script>
			<p align="center" class="annot_std_it">Ce n'est pas votre compte...</p>
<?PHP
		}
		if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
		{
?>
			<script type="text/javascript">
			<!--
			setTimeout("self.location.href=('cli_lst.php');",2000)
			//-->
			</script>
			<p align="center" class="annot_std_it">Merci de choisir un de vos clients...</p>
<?PHP
		}
	}
}
include_once("pied.php");
?>
