<?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/func.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_dos.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/lst.inc.php");
Archivelog(@$_SESSION["code_log"]);

if (isset($_GET['td']))
	$td = strip_tags(trim(@$_GET['td']));
else
{
	$td="";
	if ((strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_enr)) OR (strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_del)))
		$td = strip_tags(trim(@$_POST['td']));
}
	
if (isset($_GET['cd']))
	$codedo = strip_tags(trim(@$_GET['cd']));
else
{
	$codedo="";
	if ((strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_enr)) OR (strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_del)))
		$codedo = strip_tags(trim(@$_POST['cd']));
}

if (isset($_GET['icd']))
	$idcdo = strip_tags(trim(@$_GET['icd']));
else
{
	$idcdo=0;
	if ((strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_enr)) OR (strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_del)))
		$idcdo = strip_tags(trim(@$_POST['icd']));
}

$pbm_do=FALSE;
$totalcdo=0;
$msg1_err_type=$ajx_nodeppays;
$msg2_err_type=$ajx_novildep;
$msg3_err_type=$ajx_nodeppays;

if (isset($_GET['tx']))
	$tx = strip_tags(trim(@$_GET['tx']));
else
{
	if (isset($_POST['tx']))
		$tx = strip_tags(trim(@$_POST['tx']));
	else
		$pbm_do=TRUE;
}

if (($td<>"add") AND ($tx=="dosd_cdo"))
	$pbm_do=TRUE;

if ($codedo <> "")
{
	$row = lit_enr_do($codedo);
	if (is_array($row))
	{
		extract ($row);
		
		$totalcdo=nb_cdo_in_do($codedo);
		if ($totalcdo==0)
			$td="add";
		$retourliste=FALSE;
		
		if ((strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_enr)) OR (strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_del)))
		{
			$idcdo = strip_tags(trim(@$_POST["icd"]));
			$code = strip_tags(trim(@$_POST["cd"]));
			$civil = str_majuscules(strip_tags(trim(@$_POST["civil"])));
			$prenom = ucwords(strtolower(str_escape(trim(@$_POST["prenom"]))));
			$nom = str_majuscules(str_escape(trim(@$_POST["nom"])));
			$fonction = str_majuscules(strip_tags(trim(@$_POST["fonction"])));
			$adr1 = str_majuscules(strip_tags(str_escape(trim(@$_POST["adr1"]))));
			$adr2 = str_majuscules(strip_tags(str_escape(trim(@$_POST["adr2"]))));
			$pays = str_majuscules(strip_tags(trim(@$_POST["pays"])));
			$dep = str_majuscules(strip_tags(trim(@$_POST["dep"])));
			$ville = str_majuscules(strip_tags(trim(@$_POST["ville"])));
			$telf = strip_tags(trim(@$_POST["telf"]));
			$fax = strip_tags(trim(@$_POST["fax"]));
			$telp = strip_tags(trim(@$_POST["telp"]));
			$email = strtolower(strip_tags(trim(@$_POST["email"])));
			$mess = strtolower(strip_tags(trim(@$_POST["mess"])));
			$nota = str_escape(trim(@$_POST["nota"]));

			$rech="";
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);

			switch ($td)
			{
				case "add" :
					$rech = "INSERT INTO " .TBCDO;
					$rech .= " (cdo_datecrea,cdo_datemod,cdo_codedo,cdo_codefonc,cdo_civilite,cdo_prenom,cdo_nom,";
					$rech.="cdo_adr1,cdo_adr2,cdo_dep,cdo_ville,cdo_codepays,";
					$rech.="cdo_telf,cdo_fax,cdo_telp,cdo_email,cdo_mess,cdo_nota) VALUES";
					$rech .= " ('$datea','$datea','$code','$fonction','$civil','$prenom','$nom',";
					$rech .= " '$adr1','$adr2','$dep','$ville','$pays',";
					$rech.="'$telf','$fax','$telp','$email','$mess','$nota')";
					break;
				case "edit" :
					if (@$_SESSION["niv_log"]>=5)
					{
						$rech = "UPDATE `" .TBCDO. "` SET `cdo_datemod`='".$datea."', `cdo_codedo`='".$code."', `cdo_codefonc`='".$fonction."',";
						$rech.= " `cdo_civilite`='".$civil."', `cdo_prenom`='".$prenom."', `cdo_nom`='".$nom."', `cdo_telf`='".$telf."', ";
						$rech.= " `cdo_adr1`='".$adr1."', `cdo_adr2`='".$adr2."', `cdo_dep`='".$dep."', `cdo_ville`='".$ville."', `cdo_codepays`='".$pays."', ";
						$rech.= " `cdo_fax`='".$fax."', `cdo_telp`='".$telp."', `cdo_email`='".$email."', `cdo_mess`='".$mess."', ";
						$rech.= " `cdo_nota`='".$nota."'";
						$rech.= "  WHERE `cdo_id` = '".$idcdo."'";
					}
					else
					{
						$rech = "UPDATE `" .TBCDO. "` SET `cdo_datemod`='".$datea."', `cdo_codedo`='".$code."', `cdo_codefonc`='".$fonction."',";
						$rech.= " `cdo_civilite`='".$civil."', `cdo_prenom`='".$prenom."', `cdo_nom`='".$nom."', `cdo_telf`='".$telf."', ";
						$rech.= " `cdo_adr1`='".$adr1."', `cdo_adr2`='".$adr2."', `cdo_dep`='".$dep."', `cdo_ville`='".$ville."', `cdo_codepays`='".$pays."', ";
						$rech.= " `cdo_fax`='".$fax."', `cdo_telp`='".$telp."', `cdo_email`='".$email."', `cdo_mess`='".$mess."' ";
						$rech.= "  WHERE `cdo_id` = '".$idcdo."'";
					}
					break;
				case "del" :
					$rech = "DELETE FROM `" .TBCDO. "` WHERE `cdo_id` = '$idcdo'";
					break;
				default :
					break;
			}
			if ($rech<>"")
			{
				$rs = mysql_query($rech) or die(mysql_error());
				$retourliste=TRUE;
			}
			mysql_close($conn);
		}
		else
		{
			if ($do_ouvert==FALSE)
				$td="view";
			switch ($td)
			{
				case "add" :
					$titre = "CREATION CONTACT";
					$cdo_adr1=$do_adr1;
					$cdo_adr2=$do_adr2;
					$cdo_dep=$do_dep;
					$cdo_ville=$do_ville;
					$cdo_codepays=$do_codepays;
					$cdo_telf=$do_telf;
					$cdo_fax=$do_fax;
					break;
				case "edit" :
				case "del" :
				case "view" :
					if ($td=="edit")
						$titre = "EDITION CONTACT";
					if ($td=="del")
						$titre = "SUPPRESSION CONTACT";
					if ($td=="view")
						$titre = "VISUALISATION CONTACT";
					$row=lit_enr_cdo_id_in_do($idcdo,$codedo);
					if (is_array($row))
						extract ($row);
					else
						$pbm_do=TRUE;
					break;
				case "lst" :
					$titre = "LISTE CONTACTS";
					break;
				default :
					$pbm_do=TRUE;
					break;
			}
		}
		// On recalcule le total contacts
		$totalcdo=nb_cdo_in_do($codedo);
	}
	else
		$pbm_do=TRUE;
}
else
	$pbm_do=TRUE;		
?>
<!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; ?> : Contact Donneur d'Ordres</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../css/smi.css" rel="stylesheet" type="text/css">

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

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

<script language="javascript">
<!--
var tab_champ=new Array(
	"nom:civil ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_civil); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:prenom; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_pnom); ?>; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:nom; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_nom); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:fonction ; format:liste ; req:Y ; txt:Fonction ; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:adr1 ; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_adr1); ?> ; lmn:1 ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:adr2 ; format:txt ; req:N ; txt:<?PHP echo html_entity_decode($txt_chp_adr2); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:ville ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_ville); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:dep ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_dep); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:pays ; format:liste ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_pays); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:telf; format:tel ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_telf); ?>; stok:frmok ; stbad:frmbad",
	"nom:fax; format:tel ; req:N ; txt:<?PHP echo html_entity_decode($txt_chp_fax); ?>; stok:frmok ; stbad:frmbad",
	"nom:telp; format:telp ; req:N ; txt:<?PHP echo html_entity_decode($txt_chp_telp); ?>; stok:frmok ; stbad:frmbad",
	"nom:email; format:mail ; req:N ; txt:<?PHP echo html_entity_decode($txt_chp_email); ?>; stok:frmok ; stbad:frmbad",
	"nom:mess; format:mail ; req:N ; txt:Messagerie; stok:frmok ; stbad:frmbad",
<?PHP if (@$_SESSION["niv_log"] >= 5) { ?>
	"nom:nota; format:txt ; req:N ; txt:<?PHP echo html_entity_decode($txt_chp_notes); ?>; stok:frmok ; stbad:frmbad",
<?PHP } ?>
	"nom:mess; format:mail ; req:N ; txt:Messagerie; 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 Javascript pour vérifications des champs -->
<script language="JavaScript" src="../jscript/verif_field.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_do==FALSE) { ?>
<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);
				document.getElementById("ville").value='';
				var txthtml = "<option><?PHP echo $sel_lst_makechx; ?></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();
			document.getElementById("ville").value='';
			var txthtml = "<option><?PHP echo $sel_lst_makechx; ?></option>\n";
			document.getElementById("ville").innerHTML=txthtml;
			document.getElementById("attn2").innerHTML = "";
			document.getElementById("msg2").innerHTML = "";
			anciencodepays = "";
		}
	}
}
//-->
</script>
<?PHP } ?>

</head>
<?PHP 
switch ($td)
{
	case "del" :
	case "view" :
		echo "<body onLoad=\"verif_contacts('1','ctact','".$totalcdo."');warndel();metReadonly();\">";
		break;
	case "add" :
	case "edit" :
		echo "<body onLoad=\"verif_contacts('1','ctact','".$totalcdo."');updateDep();updateVille();metFocus();\">";
		break;
	case "lst" :
		echo "<body onLoad=\"verif_contacts('1','ctact','".$totalcdo."');metFocus();\">";
		break;
}

if ($pbm_do==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center"><span class="titre_gras">Pour le donneur d'ordres : <?php echo $do_nom; ?> </span></p>
<table width="890"  border="0">
<tr>
	<td width="33%">&nbsp;</td>
	<td width="33%">
	<?PHP if (($td=="add") OR ($td=="edit")) { ?>
	<div align="center"><span class="annot_std_it">(<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> : <?PHP echo $txt_div_saisoblg; ?>) </span></td>
	<?PHP } else { ?>
	&nbsp;
	<?PHP } ?>
	<td width="33%" align="right">
    <input name="quit" type="button" class="bton_std" id="quit" value="<?PHP echo $but_quit; ?>" style="text-decoration: none; font-size: 11px; color:White ;font-weight:bold;background-color: #666666;" onClick="javascript:; self.close();">
	<?PHP if (($totalcdo>0) AND ($td<>"lst")) { ?>
     <input name="lst" type="button" class="bton_std" id="lst" value="Revenir &agrave; la liste" style="text-decoration: none; font-size: 11px; color:White ;font-weight:bold;background-color: #666666;" onClick="javascript:; window.location=('cdo_maj.php?cd=<?PHP echo $codedo; ?>&td=lst');">
    <?PHP } ?>
	</div>
	</td>
</tr>
</table>
<?PHP
if ($retourliste==FALSE)
{
	switch ($td)
	{
		case "add" :
		case "edit" :
		case "del" :
			if ($td=="del")
			{
?>
<form name="cdo_maj" method="post" action="cdo_maj.php">
<?PHP 		} else { ?>
<form name="cdo_maj" method="post" action="cdo_maj.php" onSubmit="javascript:; return (VForm(this,tab_champ,document.cdo_maj.pays.value,'<?PHP echo $_SESSION["lng"]; ?>'));">
<?PHP 		} ?>
<input name="icd" type="hidden" id="icd" value="<?PHP echo $cdo_id ?>">
<input name="cd" type="hidden" id="cd" value="<?PHP echo $codedo ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="tx" type="hidden" id="tx" value="<?PHP echo $tx ?>">
  <table width="890"  border="0">
    <tr>
      <td width="160" class="rubfrm" id="f_civil" align="right"><?PHP echo $txt_chp_civil; ?></td>
      <td width="84%"><select name="civil" size="1" id="civil">
          <?PHP
				echo '<option>-- Choisir 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 ($cdo_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.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	</td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_prenom" align="right"><?PHP echo $txt_chp_pnom; ?></td>
      <td><input name="prenom" type="text" id="prenom" value="<?PHP echo $cdo_prenom ?>" size="50" maxlength="50"  onChange="javascript:this.value=ucWords(this.value,true);">
          <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"></td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_nom" align="right"><?PHP echo $txt_chp_nom; ?></td>
      <td><input name="nom" type="text" id="nom" value="<?PHP echo $cdo_nom ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();">
          <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"></td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_func" align="right">Fonction</td>
      <td width="84%">
	 <select name="fonction" size="1" id="fonction">
          <?PHP
				echo '<option>-- Choisir une fonction --</option>';

				// Création de la liste des fonctions
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query("SELECT * FROM ".TBFONC." ORDER BY fonc_desc");
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($cdo_codefonc == $fonc_code)
					{
						echo '<option value="'.$fonc_code.'" selected>'.$fonc_desc.'</option>';
					}
					else
					{
						echo '<option value="'.$fonc_code.'">'.$fonc_desc.'</option>';
					}
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
        </select>
          <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		</td>
    </tr>
	<tr>
	<td width="160" class="rubfrm" id="f_adr1" align="right"><?PHP echo $txt_chp_adr1; ?></td>
	<td>
	<input name="adr1" type="text" id="adr1" value="<?PHP echo htmlspecialchars($cdo_adr1); ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_adr2" align="right"><?PHP echo $txt_chp_adr2; ?></td>
	<td>
	<input name="adr2" type="text" id="adr2" value="<?PHP echo htmlspecialchars($cdo_adr2); ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
	</td>
</tr>
</tr>
	<tr>
		<td class="rubfrm" id="f_pays" align="right"><?PHP echo $txt_chp_pays; ?></td>
		<td>
		<?PHP
		if ($do_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">
		<?PHP
			echo "<option value=\"\">".$sel_lst_pays."</option>";
	
			// Création de la liste des pays
			
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				if ($cdo_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.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP
			mysql_free_result($rs);
			mysql_close($conn);
		}
		else
		{
			$pays = Retournepays_open($cdo_codepays,TRUE);
		?>
			<input name="pays" type="hidden" id="pays" value="<?PHP echo $cdo_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" align="right"><?PHP echo $txt_chp_dep; ?></td>
		<td>
		<?PHP
		if ($do_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`='".$cdo_codepays."' ORDER BY dep_code";
			$rs = mysql_query($rech) or die(mysql_error());
		?>
		<select name="dep" size="1" id="dep">
		<?PHP
		echo "<option>".$sel_lst_makechx."</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 ($cdo_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>".$sel_lst_unknown."</option>";
		?>
		</select>
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		 <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($cdo_dep,$cdo_codepays,TRUE);
			if ($cdo_dep<>$dept)
				$dep=$cdo_dep." (".$dept.")";
			else
				$dep=$dept;
		?>
			<input name="dep" type="hidden" id="dep" value="<?PHP echo $cdo_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" align="right"><?PHP echo $txt_chp_ville; ?></td>
		<td>
		<?PHP
		if ($do_ouvert == TRUE) 
		{
			// Création de la liste des villes
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
	
			$rech="";
			if ($cdo_dep<>"")
			{
				if ($cdo_dep<>"-1")
				{
					$filtre=$cdo_dep;
					if (($filtre == "2A") OR ($filtre == "2B"))
						$filtre = "20";
					$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_dep` = '".str_majuscules($filtre)."' AND `villes_codepays`='".str_majuscules($cdo_codepays)."' ORDER BY villes_nom";
				}
				else
				{
					$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_codepays`='".str_majuscules($cdo_codepays)."' ORDER BY villes_nom";
				}
			}
			if ($rech<>"")
				$rs = mysql_query($rech) or die(mysql_error());
		?>
		<select name="ville" size="1" id="ville">
		<?PHP
		echo "<option>".$sel_lst_makechx."</option>";

		if ($rech<>"")
		{
			if (mysql_num_rows($rs)>0)
			{
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($cdo_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.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		 <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($cdo_ville,TRUE);
		?>
			<input name="ville" type="hidden" id="ville" value="<?PHP echo $cdo_ville ?>">
			<input name="ville_nom" type="text" id="ville_nom" value="<?PHP echo $ville ?>" size="40"  readonly="1">
		<?PHP
		}
		?>
		</td>
	</tr>
    <tr>
      <td width="160" class="rubfrm" id="f_telf" align="right">T&eacute;l. Fixe </td>
      <td><input name="telf" type="text" id="telf" value="<?PHP echo $cdo_telf ?>" size="20" maxlength="20">
          <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"></td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_fax" align="right"><?PHP echo $txt_chp_fax; ?></td>
      <td><input name="fax" type="text" id="fax" value="<?PHP echo $cdo_fax ?>" size="20" maxlength="20"></td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_telp" align="right"><?PHP echo $txt_chp_telp; ?></td>
      <td><input name="telp" type="text" id="telp" value="<?PHP echo $cdo_telp ?>" size="20" maxlength="20">
      </td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_email" align="right"><?PHP echo $txt_chp_email; ?></td>
      <td><input name="email" type="text" id="email" value="<?PHP echo $cdo_email ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
      	<a href="mailto:<?PHP echo $cdo_email ?>"><img src="../img/mail.png" title="<?PHP echo $alt_envemail; ?>" border ="0" align="absmiddle"></a></td>
		<?PHP } ?>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_mess" align="right">Messagerie</td>
      <td><input name="mess" type="text" id="mess" value="<?PHP echo $cdo_mess ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();"></td>
    </tr>
<?PHP if (@$_SESSION["niv_log"] >= 5)
{ 
?>
    <tr>
      <td width="160" class="rubfrm" id="f_nota" align="right"><?PHP echo $txt_chp_notes; ?></td>
      <td><textarea name="nota" id="nota"><?PHP echo $cdo_nota ?></textarea></td>
    </tr>
<?PHP } ?>
  </table>
  <p align="center">
    <?PHP if ($td == "add") { ?>
    <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
    <input name="val" type="submit" class="bton_std" id="val" value="<?PHP echo $but_enr; ?>">
	<?PHP }
	
	if ($td == "edit") { ?>
    <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
    <input name="val" type="submit" class="bton_std" id="val" value="<?PHP echo $but_enr; ?>">
	<br>
	<br>
    <input name="add" type="button" class="bton_std" id="add" value="Saisir un nouveau contact" onClick="javascript:; window.location=('cdo_maj.php?cd=<?PHP echo $codedo; ?>&td=add&tx=<?PHP echo $tx; ?>');">
    <?PHP }

	if ($td == "del") { ?>
    <input name="val" type="submit" class="bton_std" id="val" value="<?PHP echo $but_del; ?>">
    <?PHP } ?>
  </p>
</form>
<?PHP
		break;
	case "lst" :
		// Création de la liste des contacts donneur d'ordres
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM `" .TBCDO. "` WHERE `cdo_codedo` = '".$codedo."' ORDER BY 'cdo_nom'";
	
		$rs = mysql_query($rech) or die(mysql_error());
		
		if (mysql_num_rows($rs) <> 0)
		{
			echo "<table class=\"MtableD\" border=\"0\" width=\"890\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";
			 
			// Création de l'entête de la table contacts clients
			echo "<th>";
			echo "Nom, Prénom";
			echo "</th>\n";
			echo "<th>";
			echo "Fonction";
			echo "</th>\n";
			echo "<th>";
			echo "T&eacute;l&eacute;phone";
			echo "</th>\n";
			echo "<th>";
			echo "Email";
			echo "</th>\n";
			echo "<th>";
			echo "Choisir";
			echo "</th>\n";
			
			$j = 0;
			
			while ($row = mysql_fetch_assoc($rs)) 
			{         
				// Création de l'entête de ligne (TR)
				creetrlstdet($j);
				
				echo "<td>\n";
				echo $row["cdo_nom"]." ".$row["cdo_prenom"];
				echo "</td>\n";
				echo "<td>\n";
				$txtfonc="&nbsp;";
				$rech2 = "SELECT * FROM `" .TBFONC. "` WHERE `fonc_code` = '".$row["cdo_codefonc"]."'";
				$rs2 = mysql_query($rech2)or die(mysql_error());
				if (mysql_num_rows($rs2) <> 0)
				{
					if ($row2 = mysql_fetch_array($rs2))
						$txtfonc=$row2["fonc_desc"];
				 }
				mysql_free_result($rs2);
				echo $txtfonc;
				echo "</td>\n";
				echo "<td align=\"center\">\n";
				echo $row["cdo_telf"];
				echo "</td>\n";
				echo "<td align=\"center\">\n";
				echo "<a href=\"mailto:".$row["cdo_email"]."\">".$row["cdo_email"]."</a>";
				echo "</td>\n";
		
				echo "<td align=\"center\">\n";
				$lst_maj=TRUE;
				echo "<a href=\"cdo_maj.php?td=edit&cd=".$row["cdo_codedo"]."&icd=".$row["cdo_id"]."&tx=".$tx."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\"></a>";
				$lst_del=TRUE;
				echo " <a href=\"cdo_maj.php?td=del&cd=".$row["cdo_codedo"]."&icd=".$row["cdo_id"]."&tx=".$tx."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\"></a>";
				echo "</tr>\n";
			
				$j++;
			}
			
			echo "</table>\n";
			// Fin affichage table liste contacts donneurs d'ordres
			$taille_piedla="";
			include_once("piedla.inc.php");
		?>
		<p align="center">
    	<input name="add" type="button" class="bton_std" id="add" value="Saisir un nouveau contact" onClick="javascript:; window.location=('cdo_maj.php?cd=<?PHP echo $codedo; ?>&td=add&tx=<?PHP echo $tx; ?>');">
		</p>
		<?PHP
		}
		break;
		
	default :
		break;
	}
}
else
{
	switch ($tx)
	{
		case "dosd_cdo" :
			cre_js_cdo($codedo,"window.opener."); 
?>
	<script type="text/javascript">
	<!--
	updatcdo();
	self.close('fscomp2');
	//-->
	</script>
<?PHP
			break;
		default :
?>
	
	<script type="text/javascript">
	<!--
	window.location=('cdo_maj.php?cd=<?PHP echo $codedo; ?>&td=lst&tx=<?PHP echo $tx; ?>');
	//-->
	</script>
<?PHP
			break;
	}
}
}
else
{
?>
	<script type="text/javascript">
	<!--
	self.close();
	//-->
	</script>
<?PHP
}
?>
</body>
</html>
