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

Version 0.9.7

Copyright (C) 2006-2007  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/config.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_zoc.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_geol.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("geoip.inc.php");
Archivelog(@$_SESSION["code_log"]);

$td = strip_tags(trim(@$_GET['td']));
$coderech = strip_tags(trim(@$_GET['code']));
$st_dep = strip_tags(trim(@$_GET['dep']));

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

$nbordres = 0;
$pbm_st=FALSE;

$msg1_err_type="Aucun département, région, ou état pour ce pays";
$msg2_err_type="Aucune ville dans ce pays ou département/région/état";
$msg3_err_type="Aucun département, région, ou état pour ce pays";
if ($coderech <> "")
{
	// Vérification qu'il existe bien des interventions et nombre de celles-ci
	$nbordres = nb_ot_st($coderech);

	// Récupération des informations sous-traitant
	$row = lit_enr_st($coderech);
	if (is_array($row))
	{
		extract ($row);
		if (($td<>"del") AND ($st_ouvert==FALSE))
			$td="view";

		if (@$_SESSION["niv_log"] >= 5)
		{
			if (@$_SESSION["niv_log"] == 10)
			{
				if ($coderech<>$_SESSION["code_st"])
					$pbm_st=TRUE;
			}
		}
		else
			$pbm_st=TRUE;
	}
	else
		$pbm_st=TRUE;
}
else
{
	if ($td == "add")
	{
		$st_ouvert = TRUE;
		$st_codepays = pays_connect_code($_SERVER['REMOTE_ADDR']);
	}
	else
		$pbm_st=TRUE;
}

switch ($td)
{
	case "add" :
		$titre = "CREATION SOUS-TRAITANT";
		break;
	case "edit" :
		$titre = "MISE A JOUR SOUS-TRAITANT";
		break;
	case "del" :
		$titre = "SUPPRESSION SOUS-TRAITANT";
		break;
	case "view" :
		$titre = "VISUALISATION SOUS-TRAITANT";
		break;
	default :
		$pbm_st=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 - ESPACE PRIVE : Fiche sous-traitant</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 des champs -->
<script language="JavaScript" src="../jscript/verif_field.js"></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:code ; format:alphanum ; req:Y ; txt:Code ; lmn:1 ; lmx:9; 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 ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
{
?>
	"nom:zone[] ; format:listem ; req:Y ; txt:Zone couverte; 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 ; 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 ; 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_npref ; 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 ; 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 ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
{
?>
	"nom:nota ; format:txt ; req:N ; txt:Notes; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
<?PHP
if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
{
?>
	"nom:spe[] ; format:listem ; req:Y ; txt:Spécialités; vmn:1; stok:frmok ; stbad:frmbad",
<?PHP
}
else
{
?>
	"nom:spe ; format:txt ; req:Y ; txt:Spécialités; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:emailt ; format:mail ; req:Y ; txt:Email technique ; lmx:50; stok:frmok ; stbad:frmbad");
</script>

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

<!-- Scripts Javascript divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

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

<?PHP if (($pbm_st==FALSE) AND ($st_ouvert==1)) { ?>
<script type="text/javascript">        
function updateVille()
{
	villeUpdater = new SelectUpdater("ville", "<?PHP echo $rep_appli.'/ajax/'; ?>recupville.php?dep=", "attn2", "msg2", "<?PHP echo $msg2_err_type; ?>");
	anciendep = "";
	document.getElementById("dep").onchange = function() {
		var listedep = document.getElementById("dep");
		var dep = listedep.options[listedep.selectedIndex].value;
		var listepays = document.getElementById("pays");
		var codepays = listepays.options[listepays.selectedIndex].value;
		if (dep.length > 0)
		{
			if (dep != anciendep)
			{
				// Faire l'appel Ajax
				var prmget=dep+"_"+codepays;
				villeUpdater.run(prmget);
				anciendep = dep;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			villeUpdater.reset();
			anciendep = "";
		}
	}
}

<?PHP if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) { ?>
function updateDep()
{
	depUpdater = new SelectUpdater("dep", "<?PHP echo $rep_appli.'/ajax/'; ?>recupdep.php?pays=", "attn1", "msg1", "<?PHP echo $msg1_err_type; ?>");
	ZCUpdater = new SelectUpdater("zone", "<?PHP echo $rep_appli.'/ajax/'; ?>recupdepzc2.php?pays=", "attn3", "msg3", "<?PHP echo $msg3_err_type; ?>");
	anciencodepays = "";
	anciendep = "";
	document.getElementById("pays").onchange = function() {
		var listepays = document.getElementById("pays");
		var codepays = listepays.options[listepays.selectedIndex].value;
		if (codepays.length > 0)
		{
			if (codepays != anciencodepays)
			{
				// Faire l'appel Ajax
				depUpdater.run(codepays);
				ZCUpdater.run(codepays);
				document.getElementById("zone").value='';
				var txthtml = "<option>-- Faites votre choix --</option>\n";
				document.getElementById("ville").innerHTML=txthtml;
				document.getElementById("attn2").innerHTML = "";
				document.getElementById("msg2").innerHTML = "";
				anciencodepays = codepays;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			depUpdater.reset();
			ZCUpdater.reset();
			anciencodepays = "";
		}
	}
}
<?PHP }

if (@$_SESSION["niv_log"] == 10) { 
?>
function updateDep()
{
	depUpdater = new SelectUpdater("dep", "<?PHP echo $rep_appli.'/ajax/'; ?>recupdep.php?pays=", "attn1", "msg1", "<?PHP echo $msg1_err_type; ?>");
	anciencodepays = "";
	anciendep = "";
	document.getElementById("pays").onchange = function() {
		var listepays = document.getElementById("pays");
		var codepays = listepays.options[listepays.selectedIndex].value;
		if (codepays.length > 0)
		{
			if (codepays != anciencodepays)
			{
				// Faire l'appel Ajax
				depUpdater.run(codepays);
				var txthtml = "<option>-- Faites votre choix --</option>\n";
				document.getElementById("ville").innerHTML=txthtml;
				document.getElementById("attn2").innerHTML = "";
				document.getElementById("msg2").innerHTML = "";
				anciencodepays = codepays;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			depUpdater.reset();
			anciencodepays = "";
		}
	}
}
<?PHP } ?>
</script>
<?PHP } ?>

</head>


<?PHP if ($td == "del"){ ?>
<body onLoad="warndeltec();metReadonly();">
<?PHP } 
if ($td == "view"){ ?>
<body onLoad="metReadonly();">
<?PHP } 

if (($td == "add") OR ($td == "edit")) {
?>
<body onLoad="metFocus();updateDep(document.st_maj.pays.value);updateVille(document.st_maj.dep.value);">
<?PHP 
}
include_once("entete.inc.php"); 
?>

<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<!-- Affiché uniquement s'il y a au moins une civilité -->
<?PHP
if ($pbm_st==FALSE)
{
if (nb_civ() <> 0)
{
?>
<table width="100%"  border="0">
  <tr>
    <td width="33%">
	<?PHP 	if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) { ?>
	<strong><em><a href="st_lst.php">Retour &agrave; la liste</a></em></strong>
	<?PHP } else echo "&nbsp;"; ?>
	</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 = "st_maji.php?cs=".$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="absmiddle"></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%">
    <div id="oblig" align="center" class="annot_gras_it">(<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"> : Saisie obligatoire)</div>
	</td>
	<td width="33%" align="right">
		<?PHP
		if (($td == "edit") AND ($nbordres <> 0) AND (@$_SESSION["niv_log"] <> 6))
		{
			$url_ord = "ot_lst.php?tx=m&ord=DES&tri=Code&search=".$st_code."&rech=Rechercher";
		?>
			<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_ord; ?>');")> Voir ses bons (<?PHP echo sprintf ("%'03s",$nbordres);?>)</a>
		<?PHP
		}
		else 
			echo "&nbsp;";
		?>
	</td>
  </tr>
</table>

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

<!-- activité (avec dates) du donneur d'ordre -->
<?PHP 
if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
{
	if (($td == "edit") OR ($td == "del")) 
	{
?>
	<table width="100%"  border="0">
	<tr>
		<td width="20%" class="rubfrm" id="f_ouvert"><div align="right">Actif</div></td>
		<td>
			<?PHP 
			if (($td == "edit") OR ($td == "del"))
			{ 
				if ($st_ouvert == 1)
				{
					echo "<select name=\"actif\" size=\"1\" id=\"actif\">";
					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($st_datecrea).")";
					echo "</span>";
				}
				else
				{
					echo "<input name=\"actif\" type=\"text\" id=\"actif\" value=\"Non\" size=\"3\" maxlength=\"3\" readonly=\"1\">";
					
					echo "<span class=\"annot_std_it\">";
					echo "  (Ouverte le : ".formatedate($st_datecrea).", fermée le : ".formatedate($st_datec).")";
					echo "</span>";
				}
			}
			?>
		</td>
	</tr>
	</table>
<?PHP }
}
?>

<!-- Fiche principale -->
<table width="100%"  border="0">
<tr>
	<td width="20%" class="rubfrm" id="f_code"><div align="right">Code</div></td>
	<td>
		<?PHP if ($td == "add") { ?>
			<strong>S</strong>
			<input name="code" type="text" id="code" value="<?PHP echo $st_code ?>" size="9" maxlength="9" onChange="javascript:this.value=this.value.toUpperCase();">
			<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
		<?PHP } else { ?>
			<input name="code" type="text" id="code" value="<?PHP echo $st_code ?>" size="10" maxlength="10" readonly="1">
		<?PHP } ?>
	</td>
</tr>
	<?PHP if (($td == "edit") OR ($td == "del") OR ($td == "view")) { ?>
<tr>
	<td height="21" class="rubfrm" id="f_logo"><div align="right">Logo</div></td>
	<td>
		<?PHP
			$url_img = "st_logo.php?cs=".$st_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="absmiddle"></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 ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
	{
	?>
		<input name="nom" type="text" id="nom" value="<?PHP echo htmlspecialchars($st_nom) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	<?PHP
	}
	else
	{
	?>
		<input name="nom" type="text" id="nom" value="<?PHP echo htmlspecialchars($st_nom) ?>" size="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_rcs"><div align="right">RCS / APE </div></td>
	<td>
	<?PHP 
	if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
	{
	?>
		<input name="rcs" type="text" id="rcs" value="<?PHP echo htmlspecialchars($st_rcs) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	<?PHP
	}
	else
	{
	?>
		<input name="rcs" type="text" id="rcs" value="<?PHP echo htmlspecialchars($st_rcs) ?>" size="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
  <td class="rubfrm" id="f_tcom"><div align="right">Tribunal com. </div></td>
  <td>
	<?PHP 
	if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
	{
	?>
		<input name="tcom" type="text" id="tcom" value="<?PHP echo htmlspecialchars($st_tcom) ?>" size="70" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	<?PHP
	}
	else
	{
	?>
	  	<input name="tcom" type="text" id="tcom" value="<?PHP echo htmlspecialchars($st_tcom) ?>" size="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 ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
	{
	?>
		<input name="adr1" type="text" id="adr1" value="<?PHP echo htmlspecialchars($st_adr1) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	<?PHP
	}
	else
	{
	?>
		<input name="adr1" type="text" id="adr1" value="<?PHP echo htmlspecialchars($st_adr1) ?>" size="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 ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
	{
	?>
		<input name="adr2" type="text" id="adr2" value="<?PHP echo htmlspecialchars($st_adr2) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
	<?PHP
	}
	else
	{
	?>
		<input name="adr2" type="text" id="adr2" value="<?PHP echo htmlspecialchars($st_adr2) ?>" size="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
</tr>
	<tr>
		<td class="rubfrm" id="f_pays"><div align="right">Pays</div></td>
		<td>
		<?PHP
		if ($st_ouvert == TRUE)
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rs = mysql_query("SELECT * FROM ".TBPAYS." ORDER BY pays_nom");
		?>			
			<select name="pays" id="pays" onchange="updateDep(this.value);">
		<?PHP
			echo "<option>-- Choisissez un pays --</option>";
	
			// Création de la liste des pays
			
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				if ($st_codepays == $pays_code)
					echo '<option value="'.$pays_code.'" selected>'.$pays_nom.'</option>';
				else
					echo '<option value="'.$pays_code.'">'.$pays_nom.'</option>';
			}
		?>
			</select>
			<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
		<?PHP
			mysql_free_result($rs);
			mysql_close($conn);
		}
		else
		{
			$pays = Retournepays_open($st_codepays,TRUE);
		?>
			<input name="pays" type="hidden" id="pays" value="<?PHP echo $st_codepays ?>">
			<input name="pays_nom" type="text" id="pays_nom" value="<?PHP echo $pays ?>" size="50"  readonly="1">
		<?PHP
		}
		?>
		</td>
	</tr>
	<tr>
		<td class="rubfrm" id="f_dep"><div align="right">D&eacute;partement ou R&eacute;gion/Etat</div></td>
		<td>
		<?PHP
		if ($st_ouvert == TRUE) 
		{
			// Création de la liste des départements
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech="SELECT * FROM ".TBDEP." WHERE `dep_codepays`='".$st_codepays."' ORDER BY dep_code";
			$rs = mysql_query($rech);
		?>
		<select name="dep" size="1" id="dep" onchange="updateVille(this.value)">
		<?PHP
		echo "<option>-- Faites votre choix --</option>";

		if (mysql_num_rows($rs)>0)
		{
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				if ($dep_code<>$dep_nom)
					$dep=$dep_code." (".$dep_nom.")";
				else
					$dep=$dep_nom;
				if ($st_dep == $dep_code)
					echo "<option value=\"".$dep_code."\" selected>".$dep."</option>";
				else
					echo "<option value=\"".$dep_code."\">".$dep."</option>";
			}
		}
		else
			echo "<option value=\"-1\" selected>-- Inconnu --</option>";
		?>
		</select>
		 <span id="attn1"></span><span id="msg1" style="background-color:#FF0000; color:#FFFF00; font-weight:bold"><?PHP if ((mysql_num_rows($rs)==0) AND ($td<>"del")) echo htmlspecialchars($msg1_err_type)?></span>
		<?PHP
			mysql_free_result($rs);
			mysql_close($conn);
		}
		else
		{
			$dept=Retournedep_open($st_dep,$st_codepays,TRUE);
			if ($st_dep<>$dept)
				$dep=$st_dep." (".$dept.")";
			else
				$dep=$dept;
		?>
			<input name="dep" type="hidden" id="dep" value="<?PHP echo $st_dep ?>">
			<input name="dep_nom" type="text" id="dep_nom" value="<?PHP echo $dep ?>" size="40"  readonly="1">
		<?PHP
		}
		?>
		</td>
	</tr>
	<tr>
		<td class="rubfrm" id="f_ville"><div align="right">Ville</div></td>
		<td>
		<?PHP
		if ($st_ouvert == TRUE) 
		{
			// Création de la liste des villes
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
	
			$rech="";
			if ($st_dep<>"")
			{
				if ($st_dep<>"-1")
				{
					$filtre=$st_dep;
					if (($filtre == "2A") OR ($filtre == "2B"))
						$filtre = "20";
					$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_dep` = '".str_majuscules($filtre)."' AND `villes_codepays`='".str_majuscules($st_codepays)."' ORDER BY villes_nom";
				}
				else
				{
					$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_codepays`='".str_majuscules($st_codepays)."' ORDER BY villes_nom";
				}
			}
			if ($rech<>"")
				$rs = mysql_query($rech);
		?>
		<select name="ville" size="1" id="ville">
		<?PHP
		echo "<option>-- Faites votre choix --</option>";

		if ($rech<>"")
		{
			if (mysql_num_rows($rs)>0)
			{
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($st_ville == $villes_id)
						echo '<option value="'.$villes_id.'" selected>'.str_majuscules($villes_nom).' ('.$villes_cp.')</option>';
					else
						echo '<option value="'.$villes_id.'">'.str_majuscules($villes_nom).' ('.$villes_cp.')</option>';
				}
			}
		}
		?>
		</select>
	     <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
		 <span id="attn2"></span><span id="msg2" style="background-color:#FF0000; color:#FFFF00; font-weight:bold"><?PHP if ($rech<>"") {if ((mysql_num_rows($rs)==0) AND ($td<>"del")) echo htmlspecialchars($msg2_err_type);}?></span>
		<?PHP
			mysql_close($conn);
		}
		else
		{
			$ville = Retourneville_openId($st_ville,TRUE);
		?>
			<input name="ville" type="hidden" id="ville" value="<?PHP echo $st_ville ?>">
			<input name="ville_nom" type="text" id="ville_nom" value="<?PHP echo $ville ?>" size="40"  readonly="1">
		<?PHP
		}
		?>
		</td>
	</tr>
<tr>
  <td class="rubfrm" id="f_zone"><div align="right">Zone couverte</div></td>
  <td>
	<?PHP 
	if ((($td=="edit") OR ($td=="add")) AND ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)))
	{
		// Création de la liste des départements
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech="";
		if ($st_codepays<>"")
		{
			$rech = "SELECT * FROM ".TBDEP." WHERE dep_codepays='".str_majuscules($st_codepays)."' ORDER BY dep_code";
			$rs = mysql_query($rech);
		}
		?>
		<span class="annot_petit_it">
		(S&eacute;lectionnez les d&eacute;partements avec Ctrl + clic gauche)
		</span>
		<br>
		<select name="zone[]" size="5" id="zone" multiple="multiple" onChange="utxtfromselm(this.id,'zonetxt');">
		<?PHP
		echo "<option>-- Faites votre choix --</option>";

		if ($rech<>"")
		{
			if (mysql_num_rows($rs)>0)
			{
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					$chaine_dep = $dep_code." (".$dep_nom.")";
					if (dep_in_zoc_st_open($dep_code,$dep_codepays,$st_code,FALSE)==TRUE)
						echo "<option value=\"".$dep_code."\" selected>".$chaine_dep."</option>";
					else
						echo "<option value=\"".$dep_code."\">".$chaine_dep."</option>";
				}
			}
		}
		?>
		</select>
		  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
		 <span id="attn3"></span><span id="msg3" style="background-color:#FF0000; color:#FFFF00; font-weight:bold">
		 <?PHP if ((($rech<>"") AND (mysql_num_rows($rs)==0) AND ($td<>"del")) OR ($rech=="")) echo htmlspecialchars($msg3_err_type);?>
		 </span>
		 <br>
		 <span class="annot_petit_it">
		 D&eacute;partement(s) choisi(s) 
		 <input name="zonetxt" type="text" id="zonetxt" value="<?PHP echo str_zoc_st_open($st_code,FALSE); ?>" size="50" readonly="1" style="background : #FFFFFF;" onFocus="window.document.age_maj.telf.focus();">
		 </span>
	<?PHP
		mysql_close($conn);
	}
	else
	{
	?>
	  	<input name="zone" type="text" id="zone" value="<?PHP echo str_zoc_st_open($st_code,TRUE); ?>" size="50" maxlength="50" readonly="1">
	<?PHP
	}
	?>
  </td>
</tr>
<tr>
  <td class="rubfrm" id="f_spe"><div align="right">Sp&eacute;cialit&eacute;s</div></td>
  <td>
	<?PHP 
	if ((($td=="edit") OR ($td=="add")) AND ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)))
	{
	?>
		<?PHP
		// Création de la liste des spécialités
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech="";
		$rech = "SELECT * FROM ".TBSP." ORDER BY sp_desc";
		$rs = mysql_query($rech);
		?>
		<span class="annot_petit_it">
		(S&eacute;lectionnez les sp&eacute;cialit&eacute;s avec Ctrl + clic gauche)
		</span>
		<br>
		<select name="spe[]" size="5" id="spe" multiple="multiple" onChange="utxtfromselm(this.id,'zonetxt2');">
		<?PHP
		echo "<option>-- Faites votre choix --</option>";

		if ($rech<>"")
		{
			if (mysql_num_rows($rs)>0)
			{
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					$chaine_spe = $sp_desc." (".$sp_code.")";
					$tab_depsp=explode("_",$st_spe);
					if (count(tab_depsp)>0)
					{
						if (in_array($sp_code,$tab_depsp))
							echo "<option value=\"".$sp_code."\" selected>".$chaine_spe."</option>";
						else
							echo "<option value=\"".$sp_code."\">".$chaine_spe."</option>";
					}
					else
						echo "<option value=\"".$sp_code."\">".$chaine_spe."</option>";
				}
			}
		}
		?>
		</select>
		  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
		 <br>
		 <span class="annot_petit_it">
		 Sp&eacute;cialit&eacute;s choisie(s) 
		 <input name="zonetxt2" type="text" id="zonetxt2" value="<?PHP echo $st_spe ?>" size="50" readonly="1" style="background : #FFFFFF;" onFocus="window.document.st_maj.telf.focus();">
		 </span>
	<?PHP
		mysql_close($conn);
	}
	else
	{
	?>
	  	<input name="spe" type="text" id="spe" value="<?PHP echo $st_spe ?>" size="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 $st_telf ?>" size="20" maxlength="20">
		  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"><br>
		  <input name="txttelf" type="text" id="txttelf" value="<?PHP echo htmlspecialchars($st_txttelf) ?>" size="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 $st_fax ?>" size="20" maxlength="20">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"><br>
		<input name="txtfax" type="text" id="txtfax" value="<?PHP echo htmlspecialchars($st_txtfax) ?>" size="100">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_web"><div align="right">Site Web <span class="annot_petit_it">(Sans pr&eacute;fixe)</span></div></td>
	<td>
		<input name="web" type="text" id="web" value="<?PHP echo $st_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 htmlspecialchars($st_heures) ?>" size="80">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</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 htmlspecialchars($st_txtent) ?></textarea></td>
</tr>
<tr>
	<td colspan="2">&nbsp;</td>
</tr>
<tr>
	<td colspan="2" class="rubfrm" id="f_web"><div align="center">Contact principal </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 ($st_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" alt="Champ obligatoire">
	</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 htmlspecialchars($st_resp_prenom) ?>" size="50"  onChange="javascript:this.value=ucWords(this.value,true);">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</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 htmlspecialchars($st_resp_nom )?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</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 $st_resp_telf ?>" size="20" maxlength="20">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</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 $st_email ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
			<a href="mailto:<?PHP echo $st_email ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="absmiddle"></a>
		<?PHP } ?>
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"> <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 $st_emaild ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
			<a href="mailto:<?PHP echo $st_emaild ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="absmiddle"></a>
		<?PHP } ?>
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</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 $st_emailc ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
			<a href="mailto:<?PHP echo $st_emailc ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="absmiddle"></a>
		<?PHP } ?>
	<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</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 $st_emailt ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
			<a href="mailto:<?PHP echo $st_emailt ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="absmiddle"></a>
		<?PHP } ?>
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</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 htmlspecialchars($st_nota) ?></textarea></td>
</tr>
<tr>
	<td width="20%">&nbsp;</td>
	<td>&nbsp;</td>
</tr>
<?PHP
if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
{
?>
<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 ($st_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" alt="Champ obligatoire"> </td>
</tr>
<?PHP
}
?>
</table>

<p align="center">
<?PHP if (($td == "add") OR ($td == "edit")) { ?>
	<input name="RAZ" type="reset" class="bton_fmarr_std" id="RAZ" value="R&eacute;initialiser">
	<input name="submit" type="submit" class="bton_fmarr_std" id="submit" value="Enregistrer">
<?PHP }
if ($td == "del") { ?>
	<input name="del" type="submit" class="bton_fmarr_std" id="del" value="Supprimer">
	<input name="annul" type="button" class="bton_fmarr_std" id="annul" value="Annuler" onclick="javascript:; history.back();">
<?PHP } ?>
</p>
</form>
<!-- Fin affiché uniquement s'il y a au moins une catégorie agence et au moins une civilité -->
<?PHP
}
else
{
?>
<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
}
}
else
{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('index.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Probl&ecirc;me sur les param&egrave;tres...</p>
<?PHP
}
include_once("pied.php");
?>
