<?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_age.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_ope.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

$orig = strip_tags(trim($_GET['ori'])); // Récupération origine ('Public / Privé')

$ddeok = TRUE;

// Si origine de la demande est "privée", on récupère le code du département du connecté et les données du demandeur
if ($orig == "pr")
{
	switch (@$_SESSION["niv_log"])
	{
		// Sous-traitant
		case 10 : 
			$row = lit_enr_st(@$_SESSION["code_log"]);
			if (is_array($row))
			{					
				 extract($row);
				 
				 $ste = $st_nom;
				 $adr1 = $st_adr1;
				 $adr2 = $st_adr2;
				 $dep = $st_dep;
				 $ville = $st_ville;
				 $pays = $st_codepays;
				 $telf = ereg_replace(" ","",$st_telf);
				 $fax = ereg_replace(" ","",$st_fax);
				 $email = $st_emaild;
			}
			else
				$ddeok=FALSE;
			break;

		// Donneur d'ordres
		case 6 : 
			$row = lit_enr_do(@$_SESSION["code_log"]);
			if (is_array($row))
			{					
				 extract($row);
				 
				 $ste = $do_nom;
				 $adr1 = $do_adr1;
				 $adr2 = $do_adr2;
				 $dep = $do_dep;
				 $ville = $do_ville;
				 $pays = $do_codepays;
				 $telf = ereg_replace(" ","",$do_telf);
				 $fax = ereg_replace(" ","",$do_fax);
				 $email = $do_emaild;
			}
			else
				$ddeok=FALSE;
			break;

		//Centre de gestion
		case 5 : 
			$row = lit_enr_cdg();
			if (is_array($row))
			{					
				 extract($row);
				 
				 $ste = $cge_nom;
				 $adr1 = $cge_adr1;
				 $adr2 = $cge_adr2;
				 $dep = $cge_dep;
				 $ville = $cge_ville;
				 $pays = $cge_codepays;
				 $telf = ereg_replace(" ","",$cge_telf);
				 $fax = ereg_replace(" ","",$cge_fax);
				 $email = $cge_emaild;
			}
			else
				$ddeok=FALSE;
			break;

		//Agence
		case 4 : 
			$row = lit_enr_age(@$_SESSION["code_log"]);
			if (is_array($row))
			{					
				 extract($row);
				 
				 $ste = $age_nom;
				 $adr1 = $age_adr1;
				 $adr2 = $age_adr2;
				 $dep = $age_dep;
				 $ville = $age_ville;
				 $pays = $age_codepays;
				 $telf = ereg_replace(" ","",$age_telf);
				 $fax = ereg_replace(" ","",$age_fax);
				 $email = $age_emaild;
			}
			else
				$ddeok=FALSE;
			break;

		// Technicien agence/sous-traitant/donneur d'ordres
		case 3 : 
		case 11 : 
		case 7 : 
			$row = lit_enr_tec(@$_SESSION["code_log"]);
			if (is_array($row))
			{					
				 extract($row);
				 
				 $civilite = $tec_civilite;
				 $prenom = $tec_prenom;
				 $nom = $tec_nom;
				 $adr1 = $tec_adr1;
				 $adr2 = $tec_adr2;
				 $dep = $tec_dep;
				 $ville = $tec_ville;
				 $pays = $tec_codepays;
				 $telf = ereg_replace(" ","",$tec_telf);
				 $telp = ereg_replace(" ","",$tec_telp);
				 $fax = ereg_replace(" ","",$tec_fax);
				 $email = $tec_email;
			}
			else
				$ddeok=FALSE;
			break;

		//Opérateur
		case 2 : 
			$row = lit_enr_ope(@$_SESSION["code_log"]);
			if (is_array($row))
			{					
				 extract($row);
				 
				 $civilite = $ope_civilite;
				 $prenom = $ope_prenom;
				 $nom = $ope_nom;
				 $adr1 = $ope_adr1;
				 $adr2 = $ope_adr2;
				 $dep = $ope_dep;
				 $ville = $ope_ville;
				 $pays = $ope_codepays;
				 $telf = ereg_replace(" ","",$ope_telf);
				 $telp = ereg_replace(" ","",$ope_telfp);
				 $email = $ope_email;
			}
			else
				$ddeok=FALSE;
			break;

		//Client
		case 1 : 
			$row = lit_enr_cli(@$_SESSION["code_log"]);
			if (is_array($row))
			{					
				 extract($row);
				 
				 $ste = $cli_ste;
				 $civilite = $cli_civilite;
				 $prenom = $cli_prenom;
				 $nom = $cli_nom;
				 $adr1 = $cli_adr1;
				 $adr2 = $cli_adr2;
				 $dep = $cli_dep;
				 $ville = $cli_ville;
				 $pays = $cli_codepays;
				 $telf = ereg_replace(" ","",$cli_telf);
				 $fax = ereg_replace(" ","",$cli_fax);
				 $telp = ereg_replace(" ","",$cli_telfp);
				 $email = $cli_email;
			}
			else
				$ddeok=FALSE;
			break;
				
		default : 
			$ddeok = FALSE;
			break;
	}
}
$titre = "MESSAGES & DEMANDES";
?>
<!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 : Demande</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>

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/vform/vform.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 // Espace Publique
if (@$_SESSION["niv_log"] == "") { ?>
<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 = "";
		}
	}
}

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 = "";
		}
	}
}
</script>
<?PHP } ?>

</head>

<body onLoad="metFocus();">
<?php 
include_once("entete.inc.php"); 
?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<?PHP 
if ($ddeok == TRUE)
{
?>
<!-- Affiché uniquement si demande cohérente -->
<script language="javascript">
var tab1_champ=new Array(
	"nom:objet ; format:liste ; req:Y ; txt:Objet de la demande ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:dest ; format:liste ; req:Y ; txt:Destinataire ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:ste ; format:txt ; req:N ; txt:Société ; stok:frmok ; stbad:frmbad",
	"nom:civilite ; format:liste ; req:Y ; txt:Civilité ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:prenom ; format:txt ; req:Y ; txt:Prénom ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:nom ; format:txt ; req:Y ; txt:Prénom ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:adr1 ; format:txt ; req:Y ; txt:Adresse(1) ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:adr2 ; format:txt ; req:N ; txt:Adresse(2) ; lmx:50 ; stok:frmok ; stbad:frmbad",
<?PHP
// Espace privé
if (@$_SESSION["niv_log"] <> "")
{
?>
	"nom:pays ; format:txt ; req:Y ; txt:Ville ; stok:frmok ; stbad:frmbad",
	"nom:dep ; format:ltxt ; req:Y ; txt:Département ; stok:frmok ; stbad:frmbad",
	"nom:ville ; format:txt ; req:Y ; txt:Ville ; stok:frmok ; stbad:frmbad",
<?PHP
} else {
?>
	"nom:pays ; format:liste ; req:Y ; txt:Pays ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:dep ; format:liste ; req:Y ; txt:Département ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:ville ; format:liste ; req:Y ; txt:Ville ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:telf ; format:tel ; req:Y ; txt:Téléphone fixe ; stok:frmok ; stbad:frmbad",
	"nom:fax ; format:tel ; req:N ; txt:Télécopieur ; stok:frmok ; stbad:frmbad",
	"nom:telp ; format:telp ; req:N ; txt:Téléphone portable ; stok:frmok ; stbad:frmbad",
	"nom:email ; format:mail ; req:Y ; txt:Email ; stok:frmok ; stbad:frmbad",
	"nom:txtdde ; format:txt ; req:Y ; txt:Votre demande ; stok:frmok ; stbad:frmbad");
</script>
<br>
<form name="dde_maj" method="post" action="dde_enr.php" onSubmit="javascript:; return (VForm(this,tab1_champ,document.dde_maj.pays.value,''));">
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="ori" type="hidden" id="ori" value="<?PHP echo $orig ?>">

<!-- Objet -->
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_obj"><div align="right">Objet</div></td>
	<td>
	<select name="objet" id="objet">
	<option>-- Choisissez pourquoi vous expédiez ce message --</option>
	<?PHP
		// Création de la liste des type de demandes
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		if (@$_SESSION["niv_log"] <> "") // Espace privé
		{
			switch (@$_SESSION["niv_log"])
			{
				// Si Demandeur = Technicien sous-traitant
				case 11 :
					$rech = "SELECT * FROM ".TBDDET." WHERE `ddet_stt` = '1' ORDER BY ddet_desc";
					break;

				// Si Demandeur = Sous-traitant
				case 10 :
					$rech = "SELECT * FROM ".TBDDET." WHERE `ddet_st` = '1' ORDER BY ddet_desc";
					break;

				// Si Demandeur = Technicien donneur d'ordres
				case 7 :
					$rech = "SELECT * FROM ".TBDDET." WHERE `ddet_dot` = '1' ORDER BY ddet_desc";
					break;

				// Si Demandeur = Donneur d'ordres
				case 6 :
					$rech = "SELECT * FROM ".TBDDET." WHERE `ddet_do` = '1' ORDER BY ddet_desc";
					break;

				// Si Demandeur = Centre de gestion
				case 5 : 
					$rech = "SELECT * FROM ".TBDDET." WHERE `ddet_cge` = '1' ORDER BY ddet_desc";
					break;

				// Si Demandeur = Agence
				case 4 : 
					$rech = "SELECT * FROM ".TBDDET." WHERE `ddet_age` = '1' ORDER BY ddet_desc";
					break;

				// Si Demandeur = Client
				case 1 : 
					$rech = "SELECT * FROM ".TBDDET." WHERE `ddet_cli` = '1' ORDER BY ddet_desc";
					break;

				// Si Demandeur = Opérateur
				case 2 : 
					$rech = "SELECT * FROM ".TBDDET." WHERE `ddet_ope` = '1' ORDER BY ddet_desc";
					break;

				// Si Demandeur = Technicien
				case 3 : 
					$rech = "SELECT * FROM ".TBDDET." WHERE `ddet_tec` = '1' ORDER BY ddet_desc";
					break;
			}
		}
		else
		{
			$rech = "SELECT * FROM ".TBDDET." WHERE `ddet_pub` = '1' ORDER BY ddet_desc";
		}
		$rs = mysql_query($rech);
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			echo '<option value="'.$ddet_code.'">'.$ddet_desc.'</option>';
		}
		mysql_free_result($rs);
		mysql_close($conn);
	?>
	</select>
	<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</td>
</tr>
</table>

<!-- Destinataire -->
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_dest"><div align="right">Destinataire</div></td>
	<td>
	<select name="dest" id="dest">
	<option>-- Choisissez à qui vous expédiez ce message --</option>
	<?PHP
		// Création de la liste des destinataires demandes
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		if (@$_SESSION["niv_log"] <> "") // Espace privé
		{
			switch (@$_SESSION["niv_log"])
			{
				// Si Demandeur = Technicien sous-traitant
				case 11 :
					$rech = "SELECT * FROM ".TBDDED." WHERE `dded_stt` = '1' ORDER BY dded_desc";
					break;

				// Si Demandeur = Sous-traitant
				case 10 :
					$rech = "SELECT * FROM ".TBDDED." WHERE `dded_st` = '1' ORDER BY dded_desc";
					break;

				// Si Demandeur = Technicien donneur d'ordres
				case 7 :
					$rech = "SELECT * FROM ".TBDDED." WHERE `dded_dot` = '1' ORDER BY dded_desc";
					break;

				// Si Demandeur = Donneur d'ordres
				case 6 :
					$rech = "SELECT * FROM ".TBDDED." WHERE `dded_do` = '1' ORDER BY dded_desc";
					break;

				// Si Demandeur = Centre de gestion
				case 5 :
					$rech = "SELECT * FROM ".TBDDED." WHERE `dded_cge` = '1' ORDER BY dded_desc";
					break;

				// Si Demandeur = Agence
				case 4 :
					$rech = "SELECT * FROM ".TBDDED." WHERE `dded_age` = '1' ORDER BY dded_desc";
					break;

				// Si Demandeur = Client
				case 1 :
					$rech = "SELECT * FROM ".TBDDED." WHERE `dded_cli` = '1' ORDER BY dded_desc";
					break;

				// Si Demandeur = Opérateur
				case 2 :
					$rech = "SELECT * FROM ".TBDDED." WHERE `dded_ope` = '1' ORDER BY dded_desc";
					break;

				// Si Demandeur = Technicien agence
				case 3 :
					$rech = "SELECT * FROM ".TBDDED." WHERE `dded_tec` = '1' ORDER BY dded_desc";
					break;
			}
		}
		else
		{
			$rech = "SELECT * FROM ".TBDDED." WHERE `dded_pub` = '1' ORDER BY dded_desc";
		}
		$rs = mysql_query($rech);
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			echo '<option value="'.$dded_code.'">'.$dded_desc.'</option>';
		}
		mysql_free_result($rs);
		mysql_close($conn);
	?>
	</select>
	<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</td>
</tr>
</table>
<br>

<!-- Détails expéditeur-->
<table width="800"  border="0">
<tr>
	<td class="rubfrm">
		<div align="center">Vos coordonn&eacute;es </div>
	</td>
</tr>
</table>

<!-- Catégorie -->
<?PHP
// Espace privé
 if (@$_SESSION["niv_log"] <> "")
{
?>
<input name="cat" type="hidden" id="cat" value="<?PHP echo str_majuscules($ddeur); ?>">
<?PHP
}
else
{
?>
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_cat"><div align="right">Vous &ecirc;tes</div></td>
	<td>
		<select name="cat" id="cat">
		<option>-- Choisissez une cat&eacute;gorie --</option>
		<?PHP
			// Création de la liste des catégories de demandeurs (espace privé uniquement)
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBDDEC." WHERE `ddec_pub` = '0' ORDER BY ddec_desc";
			$rs = mysql_query($rech);
			
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				echo '<option value="'.$ddec_code.'">'.$ddec_desc.'</option>';
			}
			mysql_free_result($rs);
			mysql_close($conn);
		?>
		</select>
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</td>
</tr>
</table>
<?PHP
}
?>

<!-- Coordonnées -->
<table width="800"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_ste"><div align="right">Soci&eacute;t&eacute;</div></td>
	<td>
		<input name="ste" type="text" id="ste" value="<?PHP echo $ste ?>" size="50" maxlength="50">
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_civilite"><div align="right">Civilit&eacute;</div></td>
	<td>
	<select name="civilite" size="1" id="civilite">
	<?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 ($civilite == $civ_code)
		{
			echo '<option value="'.$civ_code.'" selected>'.$civ_desc.'</option>';
		}
		else
		{
			echo '<option value="'.$civ_code.'">'.$civ_desc.'</option>';
		}

		$i++;
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	</select>
	<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_prenom"><div align="right">Pr&eacute;nom</div></td>
	<td>
		<input name="prenom" type="text" id="prenom" value="<?PHP echo htmlspecialchars($prenom,ENT_NOQUOTES) ?>" 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 width="160" class="rubfrm" id="f_nom"><div align="right">Nom</div></td>
	<td>
		<input name="nom" type="text" id="nom" value="<?PHP echo htmlspecialchars($nom,ENT_NOQUOTES) ?>" 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 width="160" class="rubfrm" id="f_adr1"><div align="right">Adresse (1) </div></td>
	<td>
		<input name="adr1" type="text" id="adr1" value="<?PHP echo htmlspecialchars($adr1,ENT_NOQUOTES) ?>" 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 width="160" class="rubfrm" id="f_adr2"><div align="right">Adresse (2) </div></td>
	<td>
		<input name="adr2" type="text" id="adr2" value="<?PHP echo htmlspecialchars($adr2,ENT_NOQUOTES) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_pays"><div align="right">Pays</div></td>
	<td>
	<?PHP
	if (@$_SESSION["niv_log"] == "") // Espace publique
	{
		$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 ($pays == $pays_code)
				echo '<option value="'.$pays_code.'" selected>'.$pays_nom.'</option>\n';
			else
				echo '<option value="'.$pays_code.'">'.$pays_nom.'</option>\n';
		}
	?>
	</select>
	<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	<?PHP
		mysql_close($conn);
	}
	else
	{
	?>
	<input name="pays" type="hidden" id="pays" value="<?PHP echo $pays ?>">
	<input name="npays" type="text" id="npays" value="<?PHP echo str_majuscules(Retournepays_open($pays,TRUE)); ?>" 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 (@$_SESSION["niv_log"] == "") // Espace publique
	{
		// 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`='".$pays."' 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 ($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>
	<br>
	 <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_close($conn);
	}
	else
	{
		$dep_nom=Retournedep_open($dep,$pays,TRUE);
		if ($dep_code<>$dep_nom)
			$ndep=$dep." (".$dep_nom.")";
		else
			$ndep=$dep_nom;
	?>
	<input name="dep" type="hidden" id="dep" value="<?PHP echo $dep ?>">
	<input name="ndep" type="text" id="ndep" value="<?PHP echo str_majuscules($ndep); ?>" size="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_ville"><div align="right">Ville</div></td>
	<td>
	<?PHP
	if (@$_SESSION["niv_log"] == "") // Espace publique
	{
		// Création de la liste des villes
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	
		$rech="";
		if ($dep<>"")
		{
			if ($dep<>"-1")
			{
				$filtre=$cli_dep;
				if (($filtre == "2A") OR ($filtre == "2B"))
					$filtre = "20";
				$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_dep` = '".str_majuscules($filtre)."' AND `villes_codepays`='".str_majuscules($pays)."' ORDER BY villes_nom";
			}
			else
			{
				$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_codepays`='".str_majuscules($pays)."' 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 ($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
	{
	?>
	<input name="ville" type="hidden" id="ville" value="<?PHP echo $ville ?>">
	<input name="nville" type="text" id="nville" value="<?PHP echo Retourneville_openId($ville,TRUE)." (".Retournecp_openId($ville,TRUE).")"; ?>" size="40" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_telf"><div align="right">T&eacute;l&eacute;phone Fixe </div></td>
	<td>
		<input name="telf" type="text" id="telf" value="<?PHP echo $telf ?>" size="20" maxlength="20">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_fax"><div align="right">T&eacute;l&eacute;copieur</div></td>
	<td>
		<input name="fax" type="text" id="fax" value="<?PHP echo $fax ?>" size="20" maxlength="20">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_telp"><div align="right">Portable</div></td>
	<td>
		<input name="telp" type="text" id="telp" value="<?PHP echo $telp ?>" size="20" maxlength="20">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_email"><div align="right">Email</div></td>
	<td>
		<input name="email" type="text" id="email" value="<?PHP echo $email ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</td>
</tr>
</table>
<br>

<!-- Texte de la demande -->
<table width="800"  border="0">
<tr>
	<td class="rubfrm" id="f_txtdde">
		<div align="center">Votre message </div>
	</td>
</tr>
</table>
<table width="800"  border="0">
<tr>
	<td>
		<textarea name="txtdde" cols="125" rows="5" id="txtdde"><?PHP echo $txtdde ?></textarea>
		<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</td>
</tr>
</table>

<p align="center">
<input name="RAZ" type="reset" class="bton_fmarr_std" id="RAZ" value="R&eacute;initialiser">
<input name="enr" type="submit" class="bton_fmarr_std" id="enr" value="Envoyer">
</p>
</form>
<!-- Fin Affiché uniquement si demande cohérente -->
<?PHP
}
else
{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('index.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Il y a un prob&egrave;me dans la demande...</p>
<?PHP
}
include_once("pied.php");
?>
