<?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_cli.inc.php");
include_once("../inc/fic_dos.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_loc.inc.php");
include_once("../inc/fic_ot.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['cc']))
	$codecli = strip_tags(trim(@$_GET['cc']));
else
{
	$codecli="";
	if ((strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_enr)) OR (strip_tags(trim(@$_POST["val"])) == html_entity_decode($but_del)))
		$codecli = strip_tags(trim(@$_POST['cc']));
}

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

$pbm_cli=FALSE;
$totalccli=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_cli=TRUE;
}

if (isset($_GET['is']))
	$is = strip_tags(trim(@$_GET['is']));
else
{
	if (isset($_POST['is']))
		$is = strip_tags(trim(@$_POST['is']));
}
if (($td<>"add") AND ($tx=="int") AND ($tx=="ot"))
	$pbm_cli=TRUE;

if ($codecli <> "")
{
	// Contrôle qu'un client n'essaye pas de "hacker" un autre compte
	if (@$_SESSION["niv_log"] == 1)
	{
		$tab_cli=give_tab_rcli($_SESSION["code_log"],TRUE);
		if (in_array($codecli,$tab_cli)==FALSE)
			$pbm_cli=TRUE;
	}

	if ($pbm_cli==FALSE)
	{
		$row = lit_enr_cli($codecli,TRUE);
		if (is_array($row))
		{
			extract ($row);
			
			$totalccli=nb_ccli_in_cli($codecli);
			if ($totalccli==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)))
			{
				$idccli = strip_tags(trim(@$_POST["icc"]));
				$code = strip_tags(trim(@$_POST["cc"]));
				$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"]));
				$mailc = 0;
				if (strtolower(strip_tags(trim(@$_POST["cpta"]))) == "cpta")
					$mailc = 1;
				$maild = 0;
				if (strtolower(strip_tags(trim(@$_POST["dir"]))) == "dir")
					$maild = 1;
				$mailt = 0;
				if (strtolower(strip_tags(trim(@$_POST["tec"]))) == "tec")
					$mailt = 1;
	
				$rech="";
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
	
				switch ($td)
				{
					case "add" :
						$rech = "INSERT INTO " .TBCCLI;
						$rech .= " (ccli_datecrea,ccli_datemod,ccli_codecli,ccli_codefonc,ccli_civilite,ccli_prenom,ccli_nom,ccli_telf,";
						$rech.="ccli_adr1,ccli_adr2,ccli_dep,ccli_ville,ccli_codepays,";
						$rech.="ccli_fax,ccli_telp,ccli_email,ccli_mess,ccli_nota,ccli_mailc,ccli_maild,ccli_mailt) VALUES";
						$rech .= " ('$datea','$datea','$code','$fonction','$civil','$prenom','$nom','$telf',";
						$rech .= " '$adr1','$adr2','$dep','$ville','$pays',";
						$rech.="'$fax','$telp','$email','$mess','$nota','$mailc','$maild','$mailt')";
						break;
					case "edit" :
						if (@$_SESSION["niv_log"]>=5)
						{
							$rech = "UPDATE `" .TBCCLI. "` SET `ccli_datemod`='".$datea."', `ccli_codecli`='".$code."', `ccli_codefonc`='".$fonction."',";
							$rech.= " `ccli_civilite`='".$civil."', `ccli_prenom`='".$prenom."', `ccli_nom`='".$nom."', `ccli_telf`='".$telf."', ";
							$rech.= " `ccli_adr1`='".$adr1."', `ccli_adr2`='".$adr2."', `ccli_dep`='".$dep."', `ccli_ville`='".$ville."', `ccli_codepays`='".$pays."', ";
							$rech.= " `ccli_fax`='".$fax."', `ccli_telp`='".$telp."', `ccli_email`='".$email."', `ccli_mess`='".$mess."', ";
							$rech.= " `ccli_nota`='".$nota."', `ccli_maild`='".$maild."', `ccli_mailc`='".$mailc."', `ccli_mailt`='".$mailt."'";
							$rech.= "  WHERE `ccli_id` = '".$idccli."'";
						}
						else
						{
							$rech = "UPDATE `" .TBCCLI. "` SET `ccli_datemod`='".$datea."', `ccli_codecli`='".$code."', `ccli_codefonc`='".$fonction."',";
							$rech.= " `ccli_civilite`='".$civil."', `ccli_prenom`='".$prenom."', `ccli_nom`='".$nom."', `ccli_telf`='".$telf."', ";
							$rech.= " `ccli_adr1`='".$adr1."', `ccli_adr2`='".$adr2."', `ccli_dep`='".$dep."', `ccli_ville`='".$ville."', `ccli_codepays`='".$pays."', ";
							$rech.= " `ccli_fax`='".$fax."', `ccli_telp`='".$telp."', `ccli_email`='".$email."', `ccli_mess`='".$mess."', ";
							$rech.= " `ccli_maild`='".$maild."', `ccli_mailc`='".$mailc."', `ccli_mailt`='".$mailt."'";
							$rech.= "  WHERE `ccli_id` = '".$idccli."'";
						}
						break;
					case "del" :
						$rech = "DELETE FROM `" .TBCCLI. "` WHERE `ccli_id` = '$idccli'";
						break;
					default :
						break;
				}
				if ($rech<>"")
				{
					$rs = mysql_query($rech) or die(mysql_error());
					$retourliste=TRUE;
				}
				mysql_close($conn);
				switch ($td)
				{
					case "add" :
						$titre = "CREATION CONTACT";
						break;
					case "edit" :
					case "del" :
						if ($td=="edit")
							$titre = "EDITION CONTACT";
						else
							$titre = "SUPPRESSION CONTACT";
						break;
					case "lst" :
						$titre = "LISTE CONTACTS";
						break;
					default :
						$pbm_cli=TRUE;
						break;
				}
			}
			else
			{
				switch ($td)
				{
					case "add" :
						$titre = "CREATION CONTACT";
						$ccli_adr1=$cli_adr1;
						$ccli_adr2=$cli_adr2;
						$ccli_dep=$cli_dep;
						$ccli_ville=$cli_ville;
						$ccli_codepays=$cli_codepays;
						$ccli_telf=$cli_telf;
						$ccli_fax=$cli_fax;
						break;
					case "edit" :
					case "del" :
						if ($td=="edit")
							$titre = "EDITION CONTACT";
						else
							$titre = "SUPPRESSION CONTACT";
						$row=lit_enr_ccli_id_in_cli($idccli,$codecli);
						if (is_array($row))
							extract ($row);
						else
							$pbm_cli=TRUE;
						break;
					case "lst" :
						$titre = "LISTE CONTACTS";
						break;
					default :
						$pbm_cli=TRUE;
						break;
				}
			}
			// On recalcule le total contacts
			$totalccli=nb_ccli_in_cli($codecli);
		}
		else
			$pbm_cli=TRUE;
	}
}
else
	$pbm_cli=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 Client</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" :
		echo "<body onLoad=\"verif_contacts('1','ctact','".$totalccli."');warndel();metReadonly();\">";
		break;
	case "add" :
	case "edit" :
		echo "<body onLoad=\"verif_contacts('1','ctact','".$totalccli."');updateDep();updateVille();metFocus();\">";
		break;
	case "lst" :
		echo "<body onLoad=\"verif_contacts('1','ctact','".$totalccli."');metFocus();\">";
		break;
}

if ($pbm_cli==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center"><span class="titre_gras">Pour le client : <?php echo $cli_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 (($totalccli>0) AND ($td<>"lst") AND ($tx=="cli")) { ?>
     <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=('ccli_maj.php?cc=<?PHP echo $codecli; ?>&td=lst&tx=<?PHP echo $tx; ?>');">
    <?PHP } ?>
	</div>
	</td>
</tr>
</table>
<?PHP
if ($retourliste==FALSE)
{
	switch ($td)
	{
		case "add" :
		case "edit" :
		case "del" :
			if ($td=="del")
			{
?>
<form name="ccli_maj" method="post" action="ccli_maj.php">
<?PHP 		} else { ?>
<form name="ccli_maj" method="post" action="ccli_maj.php" onSubmit="javascript:; return (VForm(this,tab_champ,document.ccli_maj.pays.value,'<?PHP echo $_SESSION["lng"]; ?>'));">
<?PHP 		} ?>
<input name="icc" type="hidden" id="icc" value="<?PHP echo $ccli_id ?>">
<input name="cc" type="hidden" id="cc" value="<?PHP echo $codecli ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="tx" type="hidden" id="tx" value="<?PHP echo $tx ?>">
<input name="is" type="hidden" id="is" value="<?PHP echo $is ?>">
  <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 ($ccli_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 $ccli_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 $ccli_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 ($ccli_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($ccli_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($ccli_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 ($ccli_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`='".$ccli_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 ($ccli_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 ($ccli_dep<>"")
			{
				if ($ccli_dep<>"-1")
				{
					$filtre=$ccli_dep;
					if (($filtre == "2A") OR ($filtre == "2B"))
						$filtre = "20";
					$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_dep` = '".str_majuscules($filtre)."' AND `villes_codepays`='".str_majuscules($ccli_codepays)."' ORDER BY villes_nom";
				}
				else
				{
					$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_codepays`='".str_majuscules($ccli_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 ($ccli_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 $ccli_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 $ccli_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 $ccli_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 $ccli_email ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
      	<a href="mailto:<?PHP echo $ccli_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 $ccli_mess ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();"></td>
    </tr>
    <tr>
      <td class="rubfrm" id="f_mess" align="right">Accepte les emails... </td>
      <td>
	  <?PHP if ($ccli_mailc == "0") {
	  ?>
        <input type="checkbox" name="cpta" style="background : #FFFFFF;" value="cpta">Comptabilité 
	  <?PHP } else { ?>
        <input type="checkbox" name="cpta" style="background : #FFFFFF;" checked value="cpta">Comptabilité 
	  <?PHP }
		if ($ccli_maild == "0") {
	  ?>
        <input type="checkbox" name="dir" style="background : #FFFFFF;" value="dir">Direction 
	  <?PHP } else { ?>
        <input type="checkbox" name="dir" style="background : #FFFFFF;" checked value="dir">Direction 
	  <?PHP }
		if ($ccli_mailt == "0") {
	  ?>
        <input type="checkbox" name="tec" style="background : #FFFFFF;" value="tec">Technique 
	  <?PHP } else { ?>
        <input type="checkbox" name="tec" style="background : #FFFFFF;" checked value="tec">Technique 
	  <?PHP } ?>
	    <br>
        <span class="annot_std_it">(Vous pouvez choisir plusieurs possibilit&eacute;s pour recevoir les emails...ou aucune)</span></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 $ccli_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=('ccli_maj.php?cc=<?PHP echo $codecli; ?>&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 clients
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM `" .TBCCLI. "` WHERE `ccli_codecli` = '".$codecli."' ORDER BY 'ccli_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["ccli_nom"]." ".$row["ccli_prenom"];
				echo "</td>\n";
				echo "<td>\n";
				$txtfonc="&nbsp;";
				$rech2 = "SELECT * FROM `" .TBFONC. "` WHERE `fonc_code` = '".$row["ccli_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["ccli_telf"];
				echo "</td>\n";
				echo "<td align=\"center\">\n";
				echo "<a href=\"mailto:".$row["ccli_email"]."\">".$row["ccli_email"]."</a>";
				echo "</td>\n";
		
				echo "<td align=\"center\">\n";
				$lst_maj=TRUE;
				echo "<a href=\"ccli_maj.php?td=edit&cc=".$row["ccli_codecli"]."&icc=".$row["ccli_id"]."&tx=".$tx."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\"></a>";
				$lst_del=TRUE;
				echo " <a href=\"ccli_maj.php?td=del&cc=".$row["ccli_codecli"]."&icc=".$row["ccli_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 clients
			$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=('ccli_maj.php?cc=<?PHP echo $codecli; ?>&td=add&tx=<?PHP echo $tx; ?>');">
		</p>
		<?PHP
		}
		break;
		
	default :
		break;
	}
}
else
{
?>
<?PHP
	switch ($tx)
	{
		case "cli" :
?>
	<script type="text/javascript">
	<!--
	window.location=('ccli_maj.php?cc=<?PHP echo $codecli; ?>&td=lst&tx=<?PHP echo $tx; ?>');
	//-->
	</script>
<?PHP
			break;

		case "int" :
			cre_js_ddeurs($codecli,$is,"window.opener."); 
?>
	<script type="text/javascript">
	<!--
	updatddeurs();
	self.close('fscomp');
	//-->
	</script>
<?PHP
			break;
		case "loc" :
			cre_js_ddeursloc($codecli,$is,"window.opener."); 
?>
	<script type="text/javascript">
	<!--
	updatddeurs();
	self.close('fscomp');
	//-->
	</script>
<?PHP
			break;
		case "ot" :
			cre_js_ccliot($codecli,$is,"window.opener."); 
?>
	<script type="text/javascript">
	<!--
	updatcclis();
	self.close('fscomp');
	//-->
	</script>
<?PHP
			break;
		case "dosd_ccli" :
			cre_js_ccli($codecli,"window.opener."); 
?>
	<script type="text/javascript">
	<!--
	updatccli();
	self.close('fscomp2');
	//-->
	</script>
<?PHP
			break;
		default :
			break;
	}
?>
<?PHP
}
}
else
{
?>
	<script type="text/javascript">
	<!--
	self.close('fscomp');
	//-->
	</script>
<?PHP
}
?>
</body>
</html>
