<?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/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_geol.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/lst.inc.php");
include_once("geoip.inc.php");
Archivelog(@$_SESSION["code_log"]);

$codecli = strip_tags(trim(@$_GET['cc']));
$id = strip_tags(trim(@$_GET['id']));
$td = strip_tags(trim(@$_GET['td']));
$scli_dep = strip_tags(trim($_GET['dep']));
	
$msg1_err_type="Aucun département, région, ou état pour ce pays";
$msg2_err_type="Aucune ville ce pays ou département/région/état";

$pbm_scli=FALSE;
$totalscli=0;

if ($codecli <> "")
{
	// Contrôle qu'un client n'essaye pas de "hacker" un autre compte
	if ((@$_SESSION["niv_log"] == 1) AND ($codecli <> @$_SESSION["code_log"]))
		$pbm_scli = TRUE;

	$row = lit_enr_cli($codecli);
	if (is_array($row))
	{
		extract ($row);
		
		$totalscli=nb_scli($codecli);
		if ($totalscli==0)
			$td="add";
		$retourliste=FALSE;
		
		if (($td<>"add") AND ($td<>"edit") AND ($td<>"del"))
			$td="lst";
		
		// Contrôle qu'une agence n'essaye pas de "hacker" un client
		if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
		{
			if (($cli_prop <> @$_SESSION["code_age"]) AND ($cli_prop <> NULL))
				$pbm_scli = TRUE;
		}
	
		// Contrôle qu'un donneur d'ordres n'essaye pas de "hacker" un client
		if ((@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 6))
		{
			if ($cli_codedo <> @$_SESSION["code_do"])
				$pbm_scli = TRUE;
		}
	
		if ($td == "add")
			$scli_codepays = pays_connect_code($_SERVER['REMOTE_ADDR']);
	
		if ($td == "edit")
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM " .TBSCLI. " WHERE scli_id = '$id' AND scli_codecli='$codecli'";
			$rs = mysql_query($rech)or die(mysql_error());
			if (mysql_num_rows($rs) <> 1)
				$pbm_scli=TRUE;
			else
			{
				if ($row = mysql_fetch_array($rs))
					extract($row);
				else
					$pbm_scli=TRUE;
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
	
		if ($td == "del")
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM " .TBSCLI. " WHERE scli_id = '$id' AND scli_codecli='$codecli'";
			$rs = mysql_query($rech)or die(mysql_error());
			$totalccli = mysql_num_rows($rs);
			if (mysql_num_rows($rs) <> 1)
			{
				$pbm_scli=TRUE;
			}
			else
			{
				if ($row = mysql_fetch_array($rs))
					extract($row);
				else
					$pbm_scli=TRUE;
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}
	}
	else
		$pbm_scli=TRUE;
}
else
	$pbm_scli=TRUE;

switch ($td)
{
	case "add" :
		$titre = "CREATION SITE CLIENT";
		break;
	case "edit" :
		$titre = "EDITER SITE CLIENT";
		break;
	case "del" :
		$titre = "SUPPRIMER SITE CLIENT";
		break;
	case "lst" :
		$titre = "LISTE SITES CLIENT";
		break;
	default :
		$pbm_scli=TRUE;
		break;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Sites Client</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 contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/vform/vform.js"></script>

<script language="javascript">
var tab1_champ=new Array(
	"nom:ste ; format:txt ; req:Y ; txt:Société ; 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",
	"nom:ville ; format:liste ; req:Y ; txt:Ville; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:pays ; format:liste ; req:Y ; txt:Pays; vmn:1; stok:frmok ; stbad:frmbad",
	"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:email ; format:mail ; req:Y ; txt:Email ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:rcivil ; format:liste ; req:Y ; txt:Civilité (Contact) ; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:rprenom ; format:txt ; req:Y ; txt:Prénom (Contact) ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:rnom ; format:txt ; req:Y ; txt:Nom (Contact) ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:rtelf ; format:tel ; req:Y ; txt:Téléphone Fixe (Contact) ; lmx:20 ; stok:frmok ; stbad:frmbad",
	"nom:rfax ; format:tel ; req:N ; txt:Télécopieur (Contact) ; lmx:20 ; stok:frmok ; stbad:frmbad",
	"nom:rtelp ; format:telp ; req:N ; txt:Téléphone Portable (Contact) ; lmx:20 ; stok:frmok ; stbad:frmbad",
	"nom:remail ; format:mail ; req:Y ; txt:Email (Contact) ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:rfunc ; format:liste ; req:Y ; txt:Fonction (Contact) ; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:nota; format:txt ; req:N ; txt:Notes; stok:frmok ; stbad:frmbad");
</script>

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

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

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

<?PHP if ($pbm_scli==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);
				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>

<?PHP if ($td == "del"){ ?>
<body onLoad="warndelscli();metReadonly();">
<?PHP } else { 
	if ($td=="lst") {
?>
<body onLoad="metFocus();">
<?PHP } else {  ?>
<body onLoad="metFocus();updateDep(document.scli_maj.pays.value);updateVille(document.scli_maj.dep.value);">
<?PHP } } 
if ($pbm_scli==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.gif" width="10" height="11" alt="Champ obligatoire"> : Saisie obligatoire) </span></div></td>
	<?PHP } else { ?>
	&nbsp;
	<?PHP } ?>
	<td width="33%"><div align="right">
    <input name="quit" type="button" class="bton_fmarr_std" id="quit" value="Quitter" style="text-decoration: none; font-size: 11px; color:White ;font-weight:bold;background-color: #666666;" onClick="javascript:; window.opener.location.reload(); self.close('fscomp');">
	<?PHP if (($totalscli>0) AND ($td<>"lst")) { ?>
     <input name="lst" type="button" class="bton_fmarr_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=('scli_maj.php?cc=<?PHP echo $codecli; ?>&td=lst');">
    <?PHP } ?>
	</div>
	</td>
</tr>
</table>
	<?PHP if ($td=="lst")
	{
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_codecli`= '".$codecli."' ORDER BY scli_ste";
		
		$rs = mysql_query($rech);
		
		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 "sites secondaires"
			echo "<th>";
			echo "Coordonn&eacute;es";
			echo "</th>\n";
			echo "<th>";
			echo "Tel/Fax";
			echo "</th>\n";
			echo "<th>";
			echo "Contact";
			echo "</th>\n";
			echo "<th>";
			echo "Créé le";
			echo "</th>\n";
			echo "<th>";
			echo "Cliquer";
			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 htmlspecialchars($row["scli_ste"],ENT_NOQUOTES);
				echo "<br>";
				echo htmlspecialchars($row["scli_adr1"],ENT_NOQUOTES);
				echo "<br>";
				if ($row["scli_adr2"]<>"")
				{
					echo htmlspecialchars($row["scli_adr2"],ENT_NOQUOTES);
					echo "<br>";
				}
				echo Retournecp_openId($row["scli_ville"],FALSE)." ".Retourneville_openId($row["scli_ville"],FALSE)."<br>";
				echo "</td>\n";
				echo "<td align=\"center\">\n";
				echo "T.".$row["scli_telf"];
				if ($row["scli_fax"]<>"")
				{
					echo"<br>";
					echo "F.".$row["scli_fax"];
				}
				echo "<td align=\"center\">\n";
				echo htmlspecialchars($row["scli_rcivil"],ENT_NOQUOTES)." ".htmlspecialchars($row["scli_rprenom"],ENT_NOQUOTES)." ".htmlspecialchars($row["scli_rnom"],ENT_NOQUOTES);
				echo "<br>";
				echo "T.".$row["scli_rtelf"];
				if ($row["scli_rfax"]<>"")
				{
					echo "<br>";
					echo "F.".$row["scli_rfax"];
				}
				if ($row["scli_rtelp"]<>"")
				{
					echo "<br>";
					echo "P.".$row["scli_rtelp"];
				}
				echo "</td>\n";
				echo "<td align=\"center\">\n";
				echo formatedate($row["scli_datecrea"]);
				echo "</td>\n";
				echo "<td align=\"center\">\n";
				$lst_maj = TRUE;
		
				echo "<a href=\"scli_maj.php?td=edit&cc=".$codecli."&id=".$row["scli_id"]."&dep=".$row["scli_dep"]."\"><img src=\"../img/edit.png\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
				echo " ";
		
				$lst_del = TRUE;
		
				echo "<a href=\"scli_maj.php?td=del&cc=".$codecli."&id=".$row["scli_id"]."&dep=".$row["scli_dep"]."\"><img src=\"../img/del.gif\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\"></a>";
				echo "</td>\n";
		
				echo "</tr>\n";
			
				$j++;
			}
			
			echo "</table>\n";
			// Fin affichage table liste sites
			
		}
		else
		{
		?>
			<p class="annot_petit_it">Aucun site client enregistr&eacute; </p>
		<?PHP
		}
		mysql_free_result($rs);
		
		$taille_piedla="";
		include_once("piedla.inc.php"); 
	?>
		<p align="center">
    	<input name="add" type="button" class="bton_fmarr_std" id="add" value="Saisir un nouveau site" onClick="javascript:; window.location=('scli_maj.php?cc=<?PHP echo $codecli; ?>&td=add');">
		</p>
	<?PHP
	}
	else
	{
	?>
		<form name="scli_maj" method="post" action="scli_enr.php" onSubmit="javascript:; return (VForm(this,tab1_champ,document.scli_maj.pays.value,''));">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="id" type="hidden" id="idccli" value="<?PHP echo $id ?>">
		<input name="cc" type="hidden" id="cc" value="<?PHP echo $codecli ?>">
		  <table width="890"  border="0" align="center">
			<tr>
				<td width="25%" 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 htmlspecialchars($scli_ste,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 class="rubfrm" id="f_adr1"><div align="right">Adresse(1)</div></td>
				<td>
					<input name="adr1" type="text" id="adr1" value="<?PHP echo htmlspecialchars($scli_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 class="rubfrm" id="f_adr2"><div align="right">Adresse(2)</div></td>
				<td>
					<input name="adr2" type="text" id="adr2" value="<?PHP echo htmlspecialchars($scli_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
				$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 ($scli_codepays == $pays_code)
							echo '<option value="'.$pays_code.'" selected>'.$pays_nom.'</option>';
						else
							echo '<option value="'.$pays_code.'">'.$pays_nom.'</option>';
					}
				?>
					</select>
					<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
				<?PHP
				mysql_free_result($rs);
				mysql_close($conn);
				?>
				</td>
			</tr>
			<tr>
				<td class="rubfrm" id="f_dep"><div align="right">D&eacute;partement ou R&eacute;gion/Etat</div></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`='".$scli_codepays."' ORDER BY dep_code";
				$rs = mysql_query($rech);
				?>
				<select name="dep" size="1" id="dep" onchange="updateVille(this.value)">
				<?PHP
				echo "<option>-- Faites votre choix --</option>";
			
				if (mysql_num_rows($rs)>0)
				{
					while ($resultat = mysql_fetch_array($rs)) 
					{
						extract($resultat);
						if ($dep_code<>$dep_nom)
							$dep=$dep_code." (".$dep_nom.")";
						else
							$dep=$dep_nom;
						if ($scli_dep == $dep_code)
							echo "<option value=\"".$dep_code."\" selected>".$dep."</option>";
						else
							echo "<option value=\"".$dep_code."\">".$dep."</option>";
					}
				}
				else
					echo "<option value=\"-1\" selected>-- Inconnu --</option>";
				?>
				</select>
				 <span id="attn1"></span><span id="msg1" style="background-color:#FF0000; color:#FFFF00; font-weight:bold"><?PHP if ((mysql_num_rows($rs)==0) AND ($td<>"del")) echo htmlspecialchars($msg1_err_type)?></span>
				<?PHP
				mysql_free_result($rs);
				mysql_close($conn);
				?>
				</td>
			</tr>
			<tr>
				<td class="rubfrm" id="f_ville"><div align="right">Ville</div></td>
				<td>
				<?PHP
				// Création de la liste des villes
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
		
				$rech="";
				if ($scli_dep<>"")
				{
					if ($scli_dep<>"-1")
					{
						$filtre=$scli_dep;
						if (($filtre == "2A") OR ($filtre == "2B"))
							$filtre = "20";
						$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_dep` = '".str_majuscules($filtre)."' AND `villes_codepays`='".str_majuscules($scli_codepays)."' ORDER BY villes_nom";
					}
					else
					{
						$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_codepays`='".str_majuscules($scli_codepays)."' ORDER BY villes_nom";
					}
				}
				if ($rech<>"")
					$rs = mysql_query($rech);
				?>
				<select name="ville" size="1" id="ville">
				<?PHP
				echo "<option>-- Faites votre choix --</option>";
			
				if ($rech<>"")
				{
					if (mysql_num_rows($rs)>0)
					{
						while ($resultat = mysql_fetch_array($rs)) 
						{
							extract($resultat);
							if ($scli_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);
				?>
				</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 $scli_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 $scli_fax ?>" 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 $scli_email ?>" size="50" onChange="javascript:this.value=this.value.toLowerCase();">
					<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
					<?PHP if ($td == "edit") { ?>
						<a href="mailto:<?PHP echo $scli_email ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border="0" align="absmiddle"></a>
					<?PHP } ?>
				</td>
			</tr>
			<tr>
				<td colspan="2" class="rubfrm" id="f_resp"><div align="center">Responsable du site</div></td>
			</tr>
			<tr>
			  <td width="20%" class="rubfrm" id="f_rcivil"><div align="right">Civilit&eacute;</div></td>
			  <td width="84%"><select name="rcivil" size="1" id="rcivil">
				  <?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 ($scli_rcivil == $civ_code)
							{
								echo '<option value="'.$civ_code.'" selected>'.$civ_desc.'</option>';
							}
							else
							{
								echo '<option value="'.$civ_code.'">'.$civ_desc.'</option>';
							}
						}
						mysql_free_result($rs);
						mysql_close($conn);
						?>
				</select>
				  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"></td>
			</tr>
			<tr>
			  <td width="20%" class="rubfrm" id="f_rprenom"><div align="right">Pr&eacute;nom</div></td>
			  <td><input name="rprenom" type="text" id="rprenom" value="<?PHP echo htmlspecialchars($scli_rprenom,ENT_NOQUOTES) ?>" size="50">
				  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"></td>
			</tr>
			<tr>
			  <td width="20%" class="rubfrm" id="f_rnom"><div align="right">Nom</div></td>
			  <td><input name="rnom" type="text" id="rnom" value="<?PHP echo htmlspecialchars($scli_rnom,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="20%" class="rubfrm" id="f_rtelf"><div align="right">T&eacute;l. Fixe </div></td>
			  <td><input name="rtelf" type="text" id="rtelf" value="<?PHP echo $scli_rtelf ?>" size="20" maxlength="20">
				  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"></td>
			</tr>
			<tr>
			  <td width="20%" class="rubfrm" id="f_rfax"><div align="right">T&eacute;l&eacute;copieur</div></td>
			  <td><input name="rfax" type="text" id="rfax" value="<?PHP echo $scli_rfax ?>" size="20" maxlength="20"></td>
			</tr>
			<tr>
			  <td width="20%" class="rubfrm" id="f_rtelp"><div align="right">Portable</div></td>
			  <td><input name="rtelp" type="text" id="rtelp" value="<?PHP echo $scli_rtelp ?>" size="20" maxlength="20">
			  </td>
			</tr>
			<tr>
			  <td width="20%" class="rubfrm" id="f_remail"><div align="right">Email</div></td>
			  <td>
				<input name="remail" type="text" id="remail" value="<?PHP echo $scli_remail ?>" size="50" onChange="javascript:this.value=this.value.toLowerCase();">
				<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
				<?PHP if ($td == "edit") { ?>
				<a href="mailto:<?PHP echo $scli_remail ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="absmiddle"></a></td>
				<?PHP } ?>
			</tr>
			<tr>
			  <td width="20%" class="rubfrm" id="f_rfunc"><div align="right">Fonction</div></td>
			  <td>
				<select name="rfunc" size="1" id="rfunc">
				  <?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 ($scli_rcodefonc == $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.gif" width="10" height="11" alt="Champ obligatoire">
			  </td>
			</tr>
			<tr>
			  <td width="20%" class="rubfrm" id="f_nota"><div align="right">Notes</div></td>
			  <td><textarea name="nota" cols="50" id="nota"><?PHP echo htmlspecialchars($scli_nota,ENT_NOQUOTES) ?></textarea></td>
			</tr>
			<tr>
				<td width="20%" class="rubfrm" id="f_ouvert"><div align="right">Ouvert ? </div></td>
				<td>
					<?PHP 
					if ($td == "add")
					{ 
						echo "<select name=\"actif\" size=\"1\" id=\"actif\">";
						echo "<option value=\"Oui\" selected>Oui</option>";
						echo "<option value=\"Non\">Non</option>";
						echo "</select>";
					}
					
					if (($td == "edit") OR ($td == "del"))
					{ 
						if ($scli_actif == TRUE)
						{
							echo "<select name=\"actif\" size=\"1\" id=\"actif\">";
							echo "<option value=\"Oui\" selected>Oui</option>";
							echo "<option value=\"Non\">Non</option>";
							echo "</select>";
						}
						else
						{
							echo "<select name=\"actif\" size=\"1\" id=\"actif\">";
							echo "<option value=\"Oui\">Oui</option>";
							echo "<option value=\"Non\" selected>Non</option>";
							echo "</select>";
						}
					}
					?>
					<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
				</td>
			</tr>
		  </table>
		  <p align="center">
			<?PHP if (($td == "add") OR ($td=="edit")) { ?>
			<input name="RAZ" type="reset" class="bton_fmarr_std" id="RAZ" value="R&eacute;initialiser">
			<?PHP } if ($td == "add") { ?>
				<input name="enr" type="submit" class="bton_fmarr_std" id="enr" value="Enregistrer">
			<?PHP } if ($td == "edit") { ?>
				<input name="mod" type="submit" class="bton_fmarr_std" id="mod" value="Modifier">
			<?PHP } if ($td == "del") { ?>
				<input name="del" type="submit" class="bton_fmarr_std" id="del" value="Supprimer">
			<?PHP } ?>
		  </p>
		</form>
	<?PHP
	}
}
else
{
?>
	<script type="text/javascript">
	self.close('fscomp');
	</script>
<?PHP
}
?>
</body>
</html>