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

Version 0.9.9

Copyright (C) 2006-2009  Sylvain FATOME
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr

Web : http://smitst.homelinux.com
****************************************************************************************/


// Vérification des tentatives de hack
$pos=strpos($_SERVER['PHP_SELF'],"inc.php");
if ($pos===FALSE)
	$ok_inc=TRUE;
else
	$ok_inc=FALSE;
if ($ok_inc==FALSE) header("Location: ../index.php");

include_once("../inc/fic_dos.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_mque.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.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['cm']))
	$coderlpma = strip_tags(trim(@$_GET['cm']));
else
{
	$coderlpma="";
	if ((strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_enr)) OR (strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_del)))
		$coderlpma = strip_tags(trim(@$_POST['cm']));
}

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

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

if (isset($_GET['is']))
	$is = strip_tags(trim(@$_GET['is']));
else
{
	if (isset($_POST['is']))
		$is = strip_tags(trim(@$_POST['is']));
}
$pbm_rlpma=FALSE;
$cmque_prop="";
$cmquen_nota="";
$msg1_err_type=$ajx_nodeppays;
$msg2_err_type=$ajx_novildep;
$msg3_err_type=$ajx_nodeppays;
$codeuser=@$_SESSION["code_log"];

if (@$_SESSION["niv_log"]==3)
	$codeuser=@$_SESSION["code_age"];

if (($td<>"add") AND ($tx=="dosd_cmque"))
	$pbm_rlpma=TRUE;

if ($coderlpma <> "")
{
	$row = lit_enr_mque($coderlpma,TRUE);
	if (is_array($row))
	{
		extract ($row);
		
		$totalcmque=nb_cmque_in_mque($coderlpma);
		if ($totalcmque==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)))
		{
			$idcmque = strip_tags(trim(@$_POST["icm"]));
			$prop = strip_tags(trim(@$_POST["prop"]));
			$code = strip_tags(trim(@$_POST["cm"]));
			$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"])));
			$notaa = str_escape(trim(@$_POST["notaa"]));
			$notat = str_escape(trim(@$_POST["notat"]));
			$notap = str_escape(trim(@$_POST["notap"]));

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

			// Fiche contact Marque
			switch ($td)
			{
				case "add" :
					$rech = "INSERT INTO " .TBCMQUE;
					$rech .= " (cmque_codemque,cmque_codefonc,cmque_civilite,cmque_prenom,cmque_nom,";
					$rech.="cmque_adr1,cmque_adr2,cmque_dep,cmque_ville,cmque_codepays,";
					$rech.="cmque_telf,cmque_fax,cmque_telp,cmque_email,cmque_mess,cmque_notaa,cmque_notat,cmque_prop) VALUES";
					$rech .= " ('$code','$fonction','$civil','$prenom','$nom',";
					$rech .= " '$adr1','$adr2','$dep','$ville','$pays',";
					$rech.="'$telf','$fax','$telp','$email','$mess','$notaa','$notat','$prop')";
					break;
				case "edit" :
					if (@$_SESSION["niv_log"]>=5)
					{
						$rech = "UPDATE `" .TBCMQUE. "` SET `cmque_codemque`='".$code."', `cmque_codefonc`='".$fonction."',";
						$rech.= " `cmque_civilite`='".$civil."', `cmque_prenom`='".$prenom."', `cmque_nom`='".$nom."', `cmque_telf`='".$telf."', ";
						$rech.= " `cmque_adr1`='".$adr1."', `cmque_adr2`='".$adr2."', `cmque_dep`='".$dep."', `cmque_ville`='".$ville."', `cmque_codepays`='".$pays."', ";
						$rech.= " `cmque_fax`='".$fax."', `cmque_telp`='".$telp."', `cmque_email`='".$email."', `cmque_mess`='".$mess."', ";
						$rech.= " `cmque_notaa`='".$notaa."', `cmque_notat`='".$notat."', `cmque_prop`='".$prop."'";
						$rech.= "  WHERE `cmque_id` = '".$idcmque."'";
					}
					else
					{
						$rech = "UPDATE `" .TBCMQUE. "` SET `cmque_codemque`='".$code."', `cmque_codefonc`='".$fonction."',";
						$rech.= " `cmque_civilite`='".$civil."', `cmque_prenom`='".$prenom."', `cmque_nom`='".$nom."', `cmque_telf`='".$telf."', ";
						$rech.= " `cmque_adr1`='".$adr1."', `cmque_adr2`='".$adr2."', `cmque_dep`='".$dep."', `cmque_ville`='".$ville."', `cmque_codepays`='".$pays."', ";
						$rech.= " `cmque_fax`='".$fax."', `cmque_telp`='".$telp."', `cmque_email`='".$email."', `cmque_mess`='".$mess."', ";
						$rech.= " `cmque_notat`='".$notat."', `cmque_prop`='".$prop."'";
						$rech.= "  WHERE `cmque_id` = '".$idcmque."'";
					}
					break;
				case "del" :
					$rech = "DELETE FROM `" .TBCMQUE. "` WHERE `cmque_id` = '$idcmque'";
					break;
				default :
					break;
			}
			if ($rech<>"")
			{
				$rs = mysql_query($rech) or die(mysql_error());

				$rech="";
				// Notes privées
				switch ($td)
				{
					case "add" :
						$id=mysql_insert_id();
						$rech ="INSERT INTO " .TBCMQUEN. "(cmquen_idcmque,cmquen_codeu,cmquen_nota)";
						$rech.=" VALUES ('$id','$codeuser','$notap')";
						break;
					case "edit" :
						$rech = "SELECT * FROM `" .TBCMQUEN. "` WHERE `cmquen_idcmque` = '$idcmque' AND `cmquen_codeu` = '$codeuser'";
						$rs = mysql_query($rech) or die(mysql_error());
						if (mysql_num_rows($rs)>0)
						{
							$rech ="UPDATE `" .TBCMQUEN. "`";
							$rech.= " SET `cmquen_nota`='".$notap."'";
							$rech.= " WHERE (`cmquen_idcmque` = '".$idcmque."' AND `cmquen_codeu` = '".$codeuser."')";
						}
						else
						{
							$rech ="INSERT INTO " .TBCMQUEN. "(cmquen_idcmque,cmquen_codeu,cmquen_nota)";
							$rech.=" VALUES ('$idcmque','$codeuser','$notap')";
						}
						break;
					case "del" :
						$rech = "DELETE FROM `" .TBCMQUEN. "` WHERE `cmquen_idcmque` = '$idcmque'";
						break;
					default :
						break;
				}
				if ($rech<>"")
					$rs = mysql_query($rech) or die(mysql_error());
				$retourliste=TRUE;
			}
			mysql_close($conn);
			// On recalcule le total contacts
			$totalcmque=nb_cmque_in_mque($coderlpma);
		}
	}
	else
		$pbm_rlpma=TRUE;

	switch ($td)
	{
		case "add" :
			$titre = "CREATION CONTACT";
			$cmque_adr1=$mque_adr1;
			$cmque_adr2=$mque_adr2;
			$cmque_dep=$mque_dep;
			$cmque_ville=$mque_ville;
			$cmque_codepays=$mque_codepays;
			$cmque_telf=$mque_telf;
			$cmque_fax=$mque_fax;
			break;
		case "edit" :
		case "del" :
			if ($td=="edit")
				$titre = "EDITION CONTACT";
			if ($td=="del")
				$titre = "SUPPRESSION CONTACT";
			$row=lit_enr_cmque_id_in_mque($idcmque,$coderlpma);
			if (is_array($row))
			{
				extract ($row);
				$row=lit_enr_CMqueNPriv($cmque_id,$codeuser);
				if (is_array($row))
					extract ($row);
			}
			else
				$pbm_rlpma=TRUE;
			break;
		case "lst" :
			$titre = "LISTE CONTACTS";
			break;
		default :
			$pbm_rlpma=TRUE;
			break;
	}
	
}
else
	$pbm_rlpma=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 Marque</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(
<?PHP
$affliste=TRUE;
if (((@$_SESSION["niv_log"]==3) OR (@$_SESSION["niv_log"]==4)) AND ($cmque_prop=="*"))
	$retourliste=TRUE;
if ($affliste==TRUE)
{
?>
	"nom:prop ; format:liste ; req:Y ; txt:Type de contact ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP } else { ?>
	"nom:prop ; format:txt ; req:Y ; txt:Type de contact ; stok:frmok ; stbad:frmbad",
<?PHP } ?>
	"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",
	"nom:mess; format:mail ; req:N ; txt:Messagerie; stok:frmok ; stbad:frmbad",
<?PHP if (@$_SESSION["niv_log"] >= 5)
{ 
?>
	"nom:notaa; format:txt ; req:N ; txt:<?PHP echo html_entity_decode($txt_chp_notes); ?> Administration; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:notat; format:txt ; req:N ; txt:<?PHP echo html_entity_decode($txt_chp_notes); ?> Agences; 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_rlpma==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" :
		echo "<body onLoad=\"verif_contacts('1','ctact','".$totalcmque."');warndel();metReadonly();\">";
		break;
	case "add" :
	case "edit" :
		echo "<body onLoad=\"verif_contacts('1','ctact','".$totalcmque."');updateDep();updateVille();metFocus();\">";
		break;
	case "lst" :
		echo "<body onLoad=\"verif_contacts('1','ctact','".$totalcmque."');metFocus();\">";
		break;
}

if ($pbm_rlpma==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center"><span class="titre_gras">Pour la marque : <?php echo $mque_ste; ?> </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('fscomp');">
	<?PHP if (($totalcmque>0) AND ($td<>"lst") AND ($tx<>"dosd_cmque")) { ?>
     <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=('cmque_maj.php?cm=<?PHP echo $coderlpma; ?>&td=lst');">
    <?PHP } ?>
	</div>
	</td>
</tr>
</table>
<?PHP
if ($retourliste==FALSE)
{
	switch ($td)
	{
		case "add" :
		case "edit" :
		case "del" :
			if ($td=="del")
			{
?>
<form name="cmque_maj" method="post" action="cmque_maj.php">
<?PHP 		} else { ?>
<form name="cmque_maj" method="post" action="cmque_maj.php" onSubmit="javascript:; return (VForm(this,tab_champ,document.cmque_maj.pays.value,'<?PHP echo $_SESSION["lng"]; ?>'));">
<?PHP 		} ?>
<input name="icm" type="hidden" id="icm" value="<?PHP echo $cmque_id ?>">
<input name="cm" type="hidden" id="cm" value="<?PHP echo $coderlpma ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="tx" type="hidden" id="tx" value="<?PHP echo $tx ?>">
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_prop" align="right">Type de contact</td>
	<td>
<?PHP
if ($affliste==TRUE)
{
	echo "<select name=\"prop\" size=\"1\" id=\"prop\">";
	echo '<option>-- Choisir un type de contact --</option>';

	// Création de la liste des types de contact
	echo '<option value="*"';
	if ($cmque_prop == "*")
		echo ' selected';
	echo '>Public</option>';
	echo '<option value="'.$codeuser.'"';
	if ($cmque_prop <> "*")
	{
		if (($cmque_prop == $codeuser) OR (@$_SESSION["niv_log"]>=5))
			echo ' selected';
	}
	echo '>Privé</option>';
	echo "</select>";
	echo '<img src="../img/oblig.png" align="absmiddle" alt="'.$alt_chp_oblig.'">';
	echo "<br>";
	echo "<span class=\"annot_petit_it\">";
	if (($_SESSION["niv_log"]<>3) AND ($_SESSION["niv_log"]<>4))
		echo "'Priv&eacute;' signifie que vous seul pourrez voir cette fiche.";
	else
		echo "'Priv&eacute;' signifie que seule l'agence pourra voir cette fiche.";
	echo "<br />Si vous passez ce contact en 'public', il le restera (sauf modification de l'administrateur).";
	echo "</span>";
}
else
{
	if ($cmque_prop == "*")
		$nprop="Public";
	else
		$nprop="Privé";
	echo "<input name=\"prop\" type=\"hidden\" id=\"prop\" value=\"".$cmque_prop."\">";
	echo "<input name=\"nprop\" type=\"text\" id=\"nprop\" value=\"".$nprop."\" size=\"10\" readonly=\"1\">";
}
?>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_civil" align="right"><?PHP echo $txt_chp_civil; ?></td>
	<td>
	<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 ($cmque_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 $cmque_prenom ?>" size="50" maxlength="50">
	  <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 $cmque_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>
	<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 ($cmque_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($cmque_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($cmque_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
		$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 ($cmque_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);
		?>
		</td>
	</tr>
	<tr>
		<td class="rubfrm" id="f_dep" align="right"><?PHP echo $txt_chp_dep; ?></td>
		<td>
		<?PHP
			// 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`='".$cmque_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 ($cmque_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);
		?>
		</td>
	</tr>
	<tr>
		<td class="rubfrm" id="f_ville" align="right"><?PHP echo $txt_chp_ville; ?></td>
		<td>
		<?PHP
			// Création de la liste des villes
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
	
			$rech="";
			if ($cmque_dep<>"")
			{
				if ($cmque_dep<>"-1")
				{
					$filtre=$cmque_dep;
					if (($filtre == "2A") OR ($filtre == "2B"))
						$filtre = "20";
					$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_dep` = '".str_majuscules($filtre)."' AND `villes_codepays`='".str_majuscules($cmque_codepays)."' ORDER BY villes_nom";
				}
				else
				{
					$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_codepays`='".str_majuscules($cmque_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 ($cmque_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);
		?>
		</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 $cmque_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 $cmque_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 $cmque_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 $cmque_email ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
	<?PHP if ($td == "edit") { ?>
	<a href="mailto:<?PHP echo $cmque_email ?>"><img src="../img/mail.png" title="<?PHP echo $alt_envemail; ?>" border ="0" align="absmiddle"></a>
	<?PHP } ?>
	</td>
</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 $cmque_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_notaa" align="right">Notes Administration</td>
	<td><textarea name="notaa" id="notaa"><?PHP echo $cmque_notaa ?></textarea></td>
</tr>
<?PHP } ?>
<tr>
	<td width="160" class="rubfrm" id="f_notat" align="right">Notes publiques Agences<br><span class="annot_petit_it">(Saisies par l'administrateur ou<br>le centre de gestion)</span></td>
	<td><textarea name="notat" id="notat"><?PHP echo $cmque_notat ?></textarea></td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_notap">
	<div align="right">Notes Personnelles<br><span class="annot_petit_it">(Pour les techniciens ce sont<br>celles de leur agence)</span></div>
	</td>
	<td>
		<textarea name="notap" rows="5" id="notap"><?PHP echo htmlspecialchars($cmquen_nota) ?></textarea>
		<span class="annot_petit_it">Vous seul pourrez voir ces notes</span>
	</td>
</tr>
</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=('cmque_maj.php?cm=<?PHP echo $coderlpma; ?>&td=add');">
    <?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 marques
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM `" .TBCMQUE. "` WHERE `cmque_codemque` = '".$coderlpma."'";
		switch (@$_SESSION["niv_log"])
		{
			case 3 :
			case 4 :
				$rech.= " AND (`cmque_prop` = '*' OR `cmque_prop` = '".$codeuser."')";
				break;
			default :
				break;
		}
		$rech.= " ORDER BY 'cmque_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 marques
			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["cmque_nom"]." ".$row["cmque_prenom"];
				echo "<div class=\"annot_petit_it\" align=\"right\">";
				if ($row["cmque_prop"]=="*")
					echo "Contact public";
				else
				{
					echo "Contact priv&eacute;";
					if  ($row["cmque_prop"]<>$codeuser) echo " (".$row["cmque_prop"].")";
				}
				echo "</div>";
				echo "</td>\n";
				echo "<td>\n";
				$txtfonc="&nbsp;";
				$rech2 = "SELECT * FROM `" .TBFONC. "` WHERE `fonc_code` = '".$row["cmque_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["cmque_telf"];
				echo "</td>\n";
				echo "<td align=\"center\">\n";
				echo "<a href=\"mailto:".$row["cmque_email"]."\">".$row["cmque_email"]."</a>";
				echo "</td>\n";
		
				echo "<td align=\"center\">\n";
				$lst_maj=TRUE;
				echo "<a href=\"cmque_maj.php?td=edit&cm=".$row["cmque_codemque"]."&icm=".$row["cmque_id"]."&tx=".$tx."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\"></a>";
				$lst_del=TRUE;
				echo " <a href=\"cmque_maj.php?td=del&cm=".$row["cmque_codemque"]."&icm=".$row["cmque_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 marques
			$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=('cmque_maj.php?cm=<?PHP echo $coderlpma; ?>&td=add');">
		</p>
		<?PHP
		}
		break;
		
	default :
		break;
	}
}
else
{
	switch ($tx)
	{
		case "dosd_cmque" :
			cre_js_cmque($coderlpma,"window.opener."); 
?>
	<script type="text/javascript">
	<!--
	updatcmque();
	self.close('fscomp2');
	//-->
	</script>
<?PHP
			break;
		default :
?>
	
	<script type="text/javascript">
	<!--
	window.location=('cmque_maj.php?cm=<?PHP echo $coderlpma; ?>&td=lst');
	//-->
	</script>
<?PHP
			break;
	}
}
}
else
{
?>
	<script type="text/javascript">
	<!--
	self.close();
	//-->
	</script>
<?PHP
}
?>
</body>
</html>
