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

Version 0.9.6
Copyright (C) 2006  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
****************************************************************************************/

?>
<?PHP include ("../inc/config.inc.php") ?>
<?PHP require ("../inc/func.inc.php") ?>
<?PHP require ("../inc/func_date.inc.php") ?>
<?PHP require ("../inc/func_log.inc.php") ?>
<?php include ("../inc/func_txt.inc.php") ?>
<?PHP require ("../inc/fic.inc.php") ?>
<?PHP include("../inc/geoip.inc"); ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?PHP
	$td = strip_tags(trim(@$_GET['typ']));
	$coderech = strip_tags(trim(@$_GET['code']));
	$age_dep = strip_tags(trim(@$_GET['dep']));

	if (@$HTTP_SESSION_VARS["niv_log"] == 4)
	{
		$coderech = @$HTTP_SESSION_VARS["code_log"];
		$td = "edit";
	}

	if ($coderech <> "")
	{
		$row = lit_enr_age($coderech);
		extract ($row);
	}
	else
	{
		if ($td == "add")
		{
			$age_ouvert = TRUE;
			$age_pays = pays_connect($_SERVER['REMOTE_ADDR']);
		}
	}
	switch ($td)
	{
		case "add" :
			$titre = "CREATION AGENCE";
			break;
		case "edit" :
			$titre = "MISE A JOUR AGENCE";
			break;
		case "del" :
			$titre = "SUPPRESSION AGENCE";
			break;
	}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Fiche Agence</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 -->
<link href="../inc/menu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="../coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour affichages -->
<script language="JavaScript" src="../inc/aff.js"></script>

<!-- Affichage nouvelle fenêtre pour impression -->
<script type="text/javascript">
	function lanceimp(page)
	{
	  window.open(page,'impression','width='+screen.width+' height='+screen.height);
	}
</script>

<script language="JavaScript" type="text/JavaScript">
function aff_zone()
{
	var selectedList = new Array();
	var selectBox = document.age_maj.zone; 
	var txtzone = "";
	var txtzonefinal = "";
	for (var i=1; i<selectBox.options.length; i++) { 
	  if (selectBox.options[i].selected) 
	  {
		txtzone += selectBox.options[i].value+"-";
	  } 
	}
	txtzonefinal = txtzone.substring(0,txtzone.length-1);
	window.document.age_maj.zonetxt.value=txtzonefinal;
}
</script>

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

<script language="javascript">
var tab1_champ=new Array(
	"nom:dep ; format:liste ; req:Y ; txt:Département ; vmn:1 ; stok:frmok ; stbad:frmbad");
var tab2_champ=new Array(
<?PHP
if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
{
?>
	"nom:acat ; format:liste ; req:Y ; txt:Catégorie; vmn:1; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:code ; format:alphanum ; req:Y ; txt:Code ; lmn:1 ; lmx:10; stok:frmok ; stbad:frmbad",
	"nom:nom ; format:txt ; req:Y ; txt:Code; lmn:1 ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:rcs ; format:txt ; req:Y ; txt:RCS /APE; lmn:1 ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:tcom ; format:txt ; req:Y ; txt:CodeTribunal de commerce; lmn:1 ; lmx:70; stok:frmok ; stbad:frmbad",
	"nom:adr1 ; format:txt ; req:Y ; txt:Adresse(1); lmn:1 ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:adr2 ; format:txt ; req:N ; txt:Adresse(2); lmx:50; stok:frmok ; stbad:frmbad",
	"nom:ville ; format:liste ; req:Y ; txt:Ville; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:pays ; format:liste ; req:Y ; txt:Pays; vmn:1; stok:frmok ; stbad:frmbad",
<?PHP
if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
{
?>
	"nom:zone[] ; format:listem ; req:Y ; txt:Zone de Chalandise; vmn:1; stok:frmok ; stbad:frmbad",
<?PHP
}
else
{
?>
	"nom:zone ; format:txt ; req:Y ; txt:Zone de Chalandise; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:telf ; format:tel_fr ; req:Y ; txt:Téléphone Fixe; stok:frmok ; stbad:frmbad",
	"nom:txttelf ; format:txt ; req:N ; txt:Commentaire téléphone fixe; lmx:100 ; stok:frmok ; stbad:frmbad",
	"nom:fax ; format:tel_fr ; req:Y ; txt:Télécopieur; stok:frmok ; stbad:frmbad",
	"nom:txtfax ; format:txt ; req:N ; txt:Commentaire télécopieur; lmx:100 ; stok:frmok ; stbad:frmbad",
	"nom:web ; format:url_pref ; req:N ; txt:Adresse site web; lmx:200; stok:frmok ; stbad:frmbad",
	"nom:heures ; format:txt ; req:Y ; txt:Horaires; lmx:200; stok:frmok ; stbad:frmbad",
	"nom:txtent ; format:txt ; req:N ; txt:Texte d'entête; stok:frmok ; stbad:frmbad",
	"nom:rcivil ; format:liste ; req:Y ; txt:Civilité responsable d'agence; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:rprenom ; format:txt ; req:Y ; txt:Prénom responsable d'agence; lmn:1; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:rnom ; format:txt ; req:Y ; txt:Nom responsable d'agence; lmn:1; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:rtelf ; format:tel_fr ; req:Y ; txt:N° tel fixe responsable d'agence; stok:frmok ; stbad:frmbad",
	"nom:email ; format:mail ; req:Y ; txt:Email général ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:emaild ; format:mail ; req:Y ; txt:Email direction ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:emailc ; format:mail ; req:Y ; txt:Email comptabilité ; lmx:50; stok:frmok ; stbad:frmbad",
<?PHP
if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
{
?>
	"nom:nota ; format:txt ; req:N ; txt:Notes; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:emailt ; format:mail ; req:Y ; txt:Email technique ; lmx:50; stok:frmok ; stbad:frmbad");
</script>

</head>

<body>

<?PHP 
	include_once ("../inc/entete.php"); 
?>

<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>

<!-- Affiché uniquement s'il y a au moins une catégorie agence et au moins une civilité -->
<?PHP
if ((nb_acat() <> 0) AND (nb_civ() <> 0))
{
?>
<!-- Formulaire de demande du numéro de département (uniquement si n'existe pas) -->
<?PHP if ($age_dep == "") { ?>
<form name="dde_dep" id="dde_dep" method="GET" action="age_maj.php" onSubmit="javascript:; return (VForm(this,tab1_champ,''));">
	<p>
	  <input name="typ" type="hidden" id="typ" value="<?PHP echo $td ?>">
	  <input name="code" type="hidden" id="code" value="<?PHP echo $coderech ?>">
</p>
	<p align="center">Merci de choisir le d&eacute;partement auquel appartiendra cette agence.</p>
	<table width="100%"  border="0">
<tr>
	<td width="20%" class="rubfrm" id="f_ouvert"><div align="right">D&eacute;partement</div></td>
	<td>
		<select name="dep" size="1" id="dep">
		<?PHP
		
		// Création de la liste des départements
		
		echo "<option>-- Choisissez un département --</option>";

		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBDEP." ORDER BY dep_num");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			$chaine_dep = $dep_num." (".$dep_nom.")";
			echo "<option value=\"".$dep_num."\">".$chaine_dep."</option>";
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
          <img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
</table>
<p align="center">
	<input type="submit" name="Submit" value="Valider">
</p>
</form>

<?PHP } ?>
<!-- Fin de formulaire de demande du numéro de département (uniquement si n'existe pas) -->

<!-- Affichage uniquement si numéro de département saisi -->
<?PHP if ($age_dep <> "") { ?>
<table width="100%"  border="0">
  <tr>
    <td width="33%"><strong><em><a href="age_lst.php">Retour &agrave; la liste</a></em></strong></td>
    <td width="33%" bgcolor="#FF0000"><div align="center"><span class="titrerubrique1">Coordonn&eacute;es</span></div></td>
    <td width="33%"><div align="right">
      <div align="right">
        <?PHP
		if ($td == "edit")
		{
		$urlimp = "age_maji.php?ca=".$coderech;
		?>
        <a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")><img src="../img/print.gif" title="Imprimer la fiche" width="22" height="22" border="0" align="abddle"></a> <a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")> Imprimer la fiche </a></div>
      <?PHP } ?>
	  </div>
	</td>
  </tr>
  <tr>
    <td width="33%">&nbsp;</td>
    <td width="33%" align="center">
    <span class="annot_gras_it">(<img src="../img/oblig.gif" width="10" height="11"> : Saisie obligatoire)</span>
	</td>
	<td width="33%" align="right">
	<?PHP 
	if ((@$HTTP_SESSION_VARS["niv_log"] >= 3) AND ($td == "edit"))
	{
	  $url_repcli = "fic_down.php?dir=agences/".strtolower($age_code);
	?>
		 <a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_repcli; ?>');")><img src="../img/rep_priv.gif" title="Aller dans le r&eacute;pertoire priv&eacute;" width="22" height="22" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_repcli; ?>');")> Aller dans le r&eacute;pertoire priv&eacute;</a>
	<?PHP
	}
	else
		echo "&nbsp;";
	?>
	</td>
  </tr>
</table>

<!-- Formulaire de saisie de la fiche -->
<form name="age_maj" id="age_maj" method="post" action="age_enr.php" onSubmit="javascript:; return (VForm(this,tab2_champ,''));">
	<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
	<input name="typdde" type="hidden" id="typdde" value="<?PHP echo $td ?>">
<?PHP if ($td == "add") { ?>
	<input name="ouvert" type="hidden" id="ouvert" value="Oui">
<?PHP } ?>

<!-- Ouverture (avec dates) de l'agence -->
<?PHP 
if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
{
	if (($td == "edit") OR ($td == "del")) 
	{
?>
	<table width="100%"  border="0">
	<tr>
		<td width="20%" class="rubfrm" id="f_ouvert"><div align="right">Agence Ouverte</div></td>
		<td>
			<?PHP 
			if (($td == "edit") OR ($td == "del"))
			{ 
				if ($age_ouvert == 1)
				{
					echo "<select name=\"ouvert\" size=\"1\" id=\"ouvert\">";
					echo "<option value=\"Oui\" selected>Oui</option>";
					echo "<option value=\"Non\">Non</option>";
					echo "</select>";
					
					echo "<span class=\"annot_std_it\">";
					echo "  (Depuis le : ".formatedate($age_datecrea).")";
					echo "</span>";
				}
				else
				{
					echo "<input name=\"ouvert\" type=\"text\" id=\"ouvert\" value=\"Non\" size=\"3\" maxlength=\"3\" readonly=\"1\">";
					
					echo "<span class=\"annot_std_it\">";
					echo "  (Ouverte le : ".formatedate($age_datecrea).", fermée le : ".formatedate($age_datec).")";
					echo "</span>";
				}
			}
			?>
			<br>
			<span class="annot_std_it">
			Le fait de fermer cette agence implique le licenciement des techniciens y travaillant.<br>
			Faites si besoin les modifications sur les fiches techniciens AVANT de fermer l'agence.
			</span>
		</td>
	</tr>
	</table>
<?PHP }
}
?>

<!-- Fiche principale -->
<table width="100%"  border="0">
<?PHP 
if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
{
?>
<tr>
  <td width="20%" class="rubfrm" id="f_acat"><div align="right">Cat&eacute;gorie</div></td>
  <td>
		<select name="acat" size="1" id="acat">
		<?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 ".TBACAT." ORDER BY acat_desc");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			if ($age_cat == $acat_code)
			{
				echo '<option value="'.$acat_code.'" selected>'.$acat_desc.'</option>';
			}
			else
			{
				echo '<option value="'.$acat_code.'">'.$acat_desc.'</option>';
			}
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		<img src="../img/oblig.gif" width="10" height="11">
  </td>
</tr>
<?PHP
}
?>
<tr>
	<td width="20%" class="rubfrm" id="f_code"><div align="right">Code</div></td>
	<td>
		<?PHP if ($td == "add") { ?>
			<strong>A</strong>
			<input name="code" type="text" id="code" value="<?PHP echo $age_code ?>" size="9" maxlength="9" onChange="javascript:this.value=this.value.toUpperCase();">
			<img src="../img/oblig.gif" width="10" height="11">
		<?PHP } else { ?>
			<input name="code" type="text" id="code" value="<?PHP echo $age_code ?>" size="10" maxlength="10" readonly="1">
		<?PHP } ?>
	</td>
</tr>
	<?PHP if (($td == "edit") OR ($td == "del")) { ?>
<tr>
	<td height="21" class="rubfrm" id="f_logo"><div align="right">Logo</div></td>
	<td>
		<?PHP
			$url_img = "age_logo.php?ca=".$age_code;
		?>
			<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_img; ?>',500,300,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/view.gif" width="22" height="22" border="0" align="abddle"></a>
			<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_img; ?>',500,300,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")> Voir le logo</a>
	</td>
</tr>
<?PHP } ?>
<tr>
	<td width="20%" class="rubfrm" id="f_nom"><div align="right">Nom</div></td>
	<td>
	<?PHP 
	if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
	{
	?>
		<input name="nom" type="text" id="nom" value="<?PHP echo $age_nom ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11">
	<?PHP
	}
	else
	{
	?>
		<input name="nom" type="text" id="nom" value="<?PHP echo $age_nom ?>" size="50" maxlength="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_rcs"><div align="right">RCS / APE </div></td>
	<td>
	<?PHP 
	if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
	{
	?>
		<input name="rcs" type="text" id="rcs" value="<?PHP echo $age_rcs ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11">
	<?PHP
	}
	else
	{
	?>
		<input name="rcs" type="text" id="rcs" value="<?PHP echo $age_rcs ?>" size="50" maxlength="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
  <td class="rubfrm" id="f_tcom"><div align="right">Tribunal com. </div></td>
  <td>
	<?PHP 
	if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
	{
	?>
		<input name="tcom" type="text" id="tcom" value="<?PHP echo $age_tcom ?>" size="70" maxlength="70" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11">
	<?PHP
	}
	else
	{
	?>
	  	<input name="tcom" type="text" id="tcom" value="<?PHP echo $age_tcom ?>" size="70" maxlength="70" readonly="1">
	<?PHP
	}
	?>
  </td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_adr1"><div align="right">Adresse (1) </div></td>
	<td>
	<?PHP 
	if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
	{
	?>
		<input name="adr1" type="text" id="adr1" value="<?PHP echo $age_adr1 ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11">
	<?PHP
	}
	else
	{
	?>
		<input name="adr1" type="text" id="adr1" value="<?PHP echo $age_adr1 ?>" size="50" maxlength="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_adr2"><div align="right">Adresse (2) </div></td>
	<td>
	<?PHP 
	if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
	{
	?>
		<input name="adr2" type="text" id="adr2" value="<?PHP echo $age_adr2 ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();">
	<?PHP
	}
	else
	{
	?>
		<input name="adr2" type="text" id="adr2" value="<?PHP echo $age_adr2 ?>" size="50" maxlength="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_dep"><div align="right">D&eacute;partement</div></td>
	<td>
		<input name="dep" type="text" id="dep" value="<?PHP echo $age_dep ?>" size="3" maxlength="3" readonly="1">
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_ville"><div align="right">Ville</div></td>
	<td>
	<?PHP 
	if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
	{
	?>
		<select name="ville" size="1" id="ville">
		<?PHP
		
		echo "<option>-- Choisissez une ville --</option>";

		// Création de la liste des villes
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$filtre = $age_dep;
		if (($filtre == "2A") OR ($filtre == "2B"))
			$filtre = "20";
		$rs = mysql_query("SELECT * FROM ".TBVILLES." WHERE `villes_cp` LIKE '".$filtre."%' ORDER BY villes_nom");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			if ($age_ville == $villes_insee)
			{
				echo '<option value="'.$villes_insee.'" selected>'.str_majuscules($villes_nom).' ('.$villes_cp.')</option>';
			}
			else
			{
				echo '<option value="'.$villes_insee.'">'.str_majuscules($villes_nom).' ('.$villes_cp.')</option>';
			}
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		<img src="../img/oblig.gif" width="10" height="11">
	<?PHP
	}
	else
	{
		$nville = Retourneville($age_ville). "(".Retournecp($age_ville).")";
	?>
		<input name="ville" type="hidden" id="ville" value="<?PHP echo $age_ville ?>" >
		<input name="nville" type="text" id="nville" value="<?PHP echo $nville ?>" size="100" maxlength="100" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_pays"><div align="right">Pays</div></td>
	<td>
	<?PHP 
	if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
	{
	?>
			<select name="pays" size="1" id="pays">
		<?PHP
			
			echo "<option>-- Choisissez un pays --</option>";
			// Création de la liste des pays
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rs = mysql_query("SELECT * FROM ".TBPAYS." ORDER BY pays_nom");
			
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				if ($age_pays == $pays_nom)
				{
					echo '<option value="'.$pays_nom.'" selected>'.$pays_nom.'</option>';
				}
				else
				{
					echo '<option value="'.$pays_nom.'">'.$pays_nom.'</option>';
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			</select>
			<img src="../img/oblig.gif" width="10" height="11">
	<?PHP
	}
	else
	{
	?>
        <input name="pays" type="text" id="pays" value="<?PHP echo $age_pays ?>" size="40" maxlength="40" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
  <td class="rubfrm" id="f_zone"><div align="right">Zone chalandise</div></td>
  <td>
	<?PHP 
	if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
	{
	?>
		<select name="zone[]" size="5" id="zone" multiple="multiple" onBlur="aff_zone();">
	
		<?PHP
		echo "<option>-- Choisissez un ou des département(s) --</option>";
	
		// Création de la liste des départements
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBDEP." ORDER BY dep_num");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			$chaine_dep = $dep_num." (".$dep_nom.")";
			if (dep_in_zc($dep_num,$age_zone) == TRUE)
				echo "<option value=\"".$dep_num."\" selected>".$chaine_dep."</option>";
			else
				echo "<option value=\"".$dep_num."\">".$chaine_dep."</option>";
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		  <img src="../img/oblig.gif" width="10" height="11">
		 <span class="annot_petit_it">
		  (S&eacute;lectionnez les d&eacute;partements avec Ctrl + clic gauche)
		 <br>
		 D&eacute;partement(s) choisi(s) 
		 <input name="zonetxt" type="text" id="zonetxt" value="<?PHP echo $age_zone ?>" size="50" readonly="1" style="background : #FFFFFF;" onFocus="window.document.age_maj.telf.focus();">
		 </span>
	<?PHP
	}
	else
	{
	?>
	  	<input name="zone" type="text" id="zone" value="<?PHP echo $age_zone ?>" size="50" maxlength="50" readonly="1">
	<?PHP
	}
	?>
  </td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_telf"><div align="right">
		T&eacute;l&eacute;phone Fixe<br>
	    (Commentaire)</div>
	</td>
	<td>
		  <input name="telf" type="text" id="telf" value="<?PHP echo $age_telf ?>" size="20" maxlength="20">
		  <img src="../img/oblig.gif" width="10" height="11"><br>
		  <input name="txttelf" type="text" id="txttelf" value="<?PHP echo $age_txttelf ?>" size="100" maxlength="100">
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_fax"><div align="right">
		T&eacute;l&eacute;copieur<br>
		(Commentaire)</div>
	</td>
	<td>
		<input name="fax" type="text" id="fax" value="<?PHP echo $age_fax ?>" size="20" maxlength="20">
		<img src="../img/oblig.gif" width="10" height="11"><br>
		<input name="txtfax" type="text" id="txtfax" value="<?PHP echo $age_txtfax ?>" size="100" maxlength="100">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_web"><div align="right">Site Web </div></td>
	<td>
		<input name="web" type="text" id="web" value="<?PHP echo $age_web ?>" size="80" maxlength="200">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_heures"><div align="right">Horaires</div></td>
	<td>
		<input name="heures" type="text" id="heures" value="<?PHP echo $age_heures ?>" size="80" maxlength="200">
		<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<tr>
  <td class="rubfrm" id="f_com"><div align="right">Texte d'ent&ecirc;te</div></td>
  <td><textarea name="txtent" cols="90" id="txtent"><?PHP echo $age_txtent ?></textarea></td>
</tr>
<tr>
	<td colspan="2">&nbsp;</td>
</tr>
<tr>
	<td colspan="2" class="rubfrm" id="f_web"><div align="center">Responsable d'agence </div></td>
</tr>
<tr>
	<td class="rubfrm" id="f_rcivil"><div align="right">Civilit&eacute;</div></td>
	<td>
		<select name="rcivil" size="1" id="rcivil">
		<?PHP
		
		echo "<option>-- Choisissez une civilité --</option>";

		// Création de la liste des civilités
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBCIV." ORDER BY civ_desc");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			if ($age_resp_civilite == $civ_code)
			{
				echo '<option value="'.$civ_code.'" selected>'.$civ_desc.'</option>';
			}
			else
			{
				echo '<option value="'.$civ_code.'">'.$civ_desc.'</option>';
			}
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_rprenom"><div align="right">Pr&eacute;nom</div></td>
	<td>
		<input name="rprenom" type="text" id="rprenom" value="<?PHP echo $age_resp_prenom ?>" size="50" maxlength="50">
		<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_rnom"><div align="right">Nom</div></td>
	<td>
		<input name="rnom" type="text" id="rnom" value="<?PHP echo $age_resp_nom ?>" size="50" maxlength="50">
		<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_rtelf"><div align="right">Tel. Fixe </div></td>
	<td>
		<input name="rtelf" type="text" id="rtelf" value="<?PHP echo $age_resp_telf ?>" size="20" maxlength="20">
		<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
</tr>
<tr>
	<td colspan="2" class="rubfrm"><div align="center">Emails</div></td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_email"><div align="right">G&eacute;n&eacute;ral</div></td>
	<td>
		<input name="email" type="text" id="email" value="<?PHP echo $age_email ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
			<a href="mailto:<?PHP echo $age_email ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
		<?PHP } ?>
		<img src="../img/oblig.gif" width="10" height="11"> <span class="annot_std_it">(Pour contacts clients)</span>
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_emaild"><div align="right">Direction</div></td>
	<td>
		<input name="emaild" type="text" id="emaild" value="<?PHP echo $age_emaild ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
			<a href="mailto:<?PHP echo $age_emaild ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
		<?PHP } ?>
		<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_emailc"><div align="right">Comptabilit&eacute;</div></td>
	<td>
		<input name="emailc" type="text" id="emailc" value="<?PHP echo $age_emailc ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
			<a href="mailto:<?PHP echo $age_emailc ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
		<?PHP } ?>
	<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_emailt"><div align="right">Technique</div></td>
	<td>
		<input name="emailt" type="text" id="emailt" value="<?PHP echo $age_emailt ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
			<a href="mailto:<?PHP echo $age_emailt ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
		<?PHP } ?>
		<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<tr>
	<td width="20%">&nbsp;</td>
	<td>&nbsp;</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_nota"><div align="right">Notes</div></td>
	<td><textarea name="nota" cols="90" id="nota"><?PHP echo $age_nota ?></textarea></td>
</tr>
<tr>
	<td width="20%">&nbsp;</td>
	<td>&nbsp;</td>
</tr>
<?PHP
if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
{
?>
<tr>
	<td width="20%" class="rubfrm" id="f_factures"><div align="right">Emet ses factures </div></td>
<td>
	<?PHP 
	if ($td == "add")
	{ 
		echo "<select name=\"factures\" size=\"1\" id=\"factures\">";
		echo "<option value=\"Oui\">Oui</option>";
		echo "<option value=\"Non\" selected>Non</option>";
		echo "</select>";
	}
	
	if (($td == "edit") OR ($td == "del"))
	{ 
		if ($age_fact == TRUE)
		{
			echo "<select name=\"factures\" size=\"1\" id=\"factures\">";
			echo "<option value=\"Oui\" selected>Oui</option>";
			echo "<option value=\"Non\">Non</option>";
			echo "</select>";
		}
		else
		{
			echo "<select name=\"factures\" size=\"1\" id=\"factures\">";
			echo "<option value=\"Oui\">Oui</option>";
			echo "<option value=\"Non\" selected>Non</option>";
			echo "</select>";
		}
	}
	?>
	<img src="../img/oblig.gif" width="10" height="11"> </td>
</tr>
<?PHP
}
?>
</table>

<p align="center">
<?PHP if (($td == "add") OR ($td == "edit")) { ?>
	<input name="RAZ" type="reset" id="RAZ" value="R&eacute;initialiser">
	<input name="submit" type="submit" id="submit" value="Enregistrer">
<?PHP } ?>
<?PHP if ($td == "del") { ?>
	<input name="del" type="submit" id="del" value="Supprimer">
	<input name="annul" type="button" id="annul" value="Annuler" onclick="javascript:; history.back();">
<?PHP } ?>
</p>
</form>
<!-- Fin de formulaire de saisie de la fiche -->

<?PHP if ($td == "del") 
{
?>
	<script>
	warndelage();
	</script>
<?PHP
}
?>
	
<?PHP } ?>
<!-- Fin affichage uniquement si numéro de département saisi -->
<!-- Fin affiché uniquement s'il y a au moins une catégorie agence et au moins une civilité -->
<?PHP
}
else
{
	if (nb_acat() == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('acat_lst.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins une cat&eacute;gorie d'agence...</p>
<?PHP
	}

	if (nb_civ() == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('civ_lst.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins une civilit&eacute;...</p>
    <?PHP
	}
}
?>


<?php 
	include_once ("pied.php")
?>
