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

Version 0.9.6
Copyright (C) 2006  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
****************************************************************************************/

include ("../inc/config.inc.php");
?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php include ("../inc/func_txt.inc.php") ?>
<?php require ("../inc/fic.inc.php") ?>
<?PHP include("../inc/geoip.inc"); ?>

<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$td = strip_tags(trim($_GET['td']));
	$coderech = strip_tags(trim($_GET['cc']));
	$cli_dep = strip_tags(trim($_GET['dep']));
	
	// Un client ne peux qu'éditer son propre compte
	if (@$HTTP_SESSION_VARS["niv_log"] == 1)
	{
		$td="edit";
		$coderech=@$HTTP_SESSION_VARS["code_log"];
	}

	$nbcontacts = 0;
	$nbcontrats = 0;
	$nbinterventions = 0;
	$pbm_cli = FALSE;

	if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
	{
		$row = lit_enr_age($HTTP_SESSION_VARS["code_age"]);
		extract ($row);
		$zc_couverte = $age_zone;
	}
	else
		$zc_couverte = zc_age_actives();

	if ($coderech <> "")
	{
		// Vérification qu'il existe bien des contacts et nombre de ceux-ci
		$nbcontacts = nb_ccli_in_cli($coderech);

		// Vérification qu'il existe bien des contrats et nombre de ceux-ci
		$nbcontrats = nb_cocl_in_cli($coderech);

		// Vérification qu'il existe bien des interventions et nombre de celles-ci
		$nbinterventions = nb_int_cli($coderech);

		// Récupération des informations clients
		$row = lit_enr_cli($coderech);
		if (is_array($row)==TRUE)
		{
			extract ($row);
	
			// Contrôle qu'une agence n'essaye pas de "hacker" un client
			if ($td <> "add")
			{
				if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
				{
					if (dep_in_zc($cli_dep,$zc_couverte) == TRUE) 
					{
						if (($cli_prop <> @$HTTP_SESSION_VARS["code_age"]) AND ($cli_prop <> NULL))
						{
							$pbm_cli = TRUE;
						}
					}
					else
					{
						$pbm_cli = TRUE;
					}
				}
			}
		}
		else
		{
			$pbm_cli = TRUE;
		}

		if ($pbm_cli == FALSE)
		{
			if ($td == "edit")
				$titre = "MISE A JOUR COMPTE CLIENT";
	
			if ($td == "del")
				$titre = "SUPPRESSION COMPTE CLIENT";
		}
	}
	else
	{
		if ($td == "add")
		{
			$cli_code = crecodesession("C");
			$cli_cpta = 0;

			$cli_pays = pays_connect($_SERVER['REMOTE_ADDR']);
			
			$titre = "CREATION COMPTE CLIENT";
		}
	}
?>

<!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 : Fiche 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 -->
<link href="../inc/menu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="../coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour affichages -->
<script language="JavaScript" src="../inc/aff.js"></script>

<!-- Affichage nouvelle fenêtre pour impression -->
<script type="text/javascript">
	function lanceimp(page)
	{
	  window.open(page,'impression','width='+screen.width+' height='+screen.height);
	}
</script>

<!-- Fonction afficher/cacher un bloc div -->
<script type="text/javascript">
function display(idobjet,etat)
{
	var objet = document.getElementById(idobjet);
	// etat = objet.style.display;
	if ((etat == 'none') || (etat == 'block'))
	{
		if (etat == 'none')
		{
			objet.style.display = 'none';
		}
		else
		{
			objet.style.display = 'block';
		}
	}
}
</script>

<!-- Fonction pour vérifier si une icône pour les sites doit être affichée -->
<script type="text/javascript">
function tst_sites_client(texte)
{
	if (texte!="")
	{
		display('site','block');
		display('pas_site','none');
	}
	else
	{
		display('site','none');
		display('pas_site','block');
	}
}
</script>

<!-- Fonction pour ouvrir une fenêtre de gestion des sites en fonction de la zone de texte "nom de société" -->
<script type="text/javascript">
function fen_sites_client(codeclient)
{
	if ((codeclient) && (codeclient!=''))
	{
		fensaisie('scli_maj.php?cc='+codeclient,910,650,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');
	}
}
</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:dep ; format:liste ; req:Y ; txt:Département ; vmn:1 ; stok:frmok ; stbad:frmbad");
var tab2_champ=new Array(
<?PHP
if (@$HTTP_SESSION_VARS["niv_log"] >= 2)
{
	if ($td=="add")
	{
?>
	"nom:typ ; format:liste ; req:Y ; txt:Type; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
	}
	else
	{
?>
	"nom:typ ; format:txt ; req:Y ; txt:Type; stok:frmok ; stbad:frmbad",
<?PHP
	}
?>
	"nom:cat ; format:liste ; req:Y ; txt:Catégorie ; vmn:1; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:ste ; format:txt ; req:N ; txt:Société; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:rcs ; format:txt ; req:N ; txt:RCS; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:civil ; format:liste ; req:Y ; txt:Civilité ; vmn:1; stok:frmok ; stbad:frmbad",
	"nom:prenom ; format:txt ; req:Y ; txt:Civilité ; lmx:50; stok:frmok ; stbad:frmbad",
	"nom:nom ; format:txt ; req:Y ; txt:Civilité ; 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_fr ; req:Y ; txt:Téléphone Fixe; stok:frmok ; stbad:frmbad",
	"nom:fax ; format:tel_fr ; req:N ; txt:Télécopieur; stok:frmok ; stbad:frmbad",
	"nom:telp ; format:telp_fr ; req:N ; txt:Téléphone portable; stok:frmok ; stbad:frmbad",
	"nom:email ; format:mail ; req:Y ; txt:Email ; lmx:50; stok:frmok ; stbad:frmbad",
<?PHP if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
{ 
?>
	"nom:notaa ; format:txt ; req:N ; txt:Notes administration; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
<?PHP if (@$HTTP_SESSION_VARS["niv_log"] >= 3)
{ 
?>
	"nom:notat ; format:txt ; req:N ; txt:Notes techniques; stok:frmok ; stbad:frmbad",
	"nom:cpta ; format:unsigned ; req:Y ; txt:Comptabilité; vmn:0 ; vmx:3 ; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:mess ; format:mail ; req:N ; txt:Messagerie ; lmx:50; stok:frmok ; stbad:frmbad");
</script>
</head>

<?PHP
if ((@$HTTP_SESSION_VARS["niv_log"] <> 2) AND ($td=="edit"))
{ 
?>
	<body onLoad="javscript:; tst_sites_client(document.cli_maj.ste.value);">
<?PHP
}
else
{
?>
	<body>
<?PHP
}
?>

<?php 
	include_once ("../inc/entete.php"); 
?>

<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>

<!-- Affiché uniquement s'il y a au moins une catégorie de client et une civilité -->
<?PHP
if ($pbm_cli == FALSE)
{
if ((nb_ccat() <> 0) AND (nb_civ() <> 0))
{
?>
<!-- Formulaire de demande du numéro de département (uniquement si n'existe pas) -->
<?PHP if ($cli_dep == "") { ?>
<form name="dde_dep" id="dde_dep" method="GET" action="cli_maj.php" onSubmit="javascript:; return (VForm(this,tab1_champ,''));">
<p>
	  <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
	  <input name="cc" type="hidden" id="cc" value="<?PHP echo $coderech ?>">
</p>
	<p align="center">Merci de choisir le d&eacute;partement o&ugrave; r&eacute;side ce client.</p>
	<table width="100%"  border="0">
<tr>
	<td width="20%" class="rubfrm" id="f_dep"><div align="right">D&eacute;partement</div></td>
	<td>
		<select name="dep" size="1" id="dep">
		<?PHP
		
		echo "<option>-- Choisissez un département --</option>";

		// Création de la liste des départements
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBDEP." ORDER BY dep_num");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			if (dep_in_zc($dep_num,$zc_couverte) == TRUE)
			{
				$chaine_dep = $dep_num." (".$dep_nom.")";
				echo "<option value=\"".$dep_num."\">".$chaine_dep."</option>";
			}
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		<?PHP 
		if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
		{
		?>
          <span class="annot_petit_it">(D&eacute;partements couverts par votre agence)</span> <img src="../img/oblig.gif" width="10" height="11">
		<?PHP
		}
		else
		{
		?>
	        <span class="annot_petit_it">(D&eacute;partements couverts par les agences)</span> <img src="../img/oblig.gif" width="10" height="11">
		<?PHP
		}
		?>
	</td>
</tr>
</table>
<p align="center">
	<input type="submit" name="Submit" value="Valider">
</p>
</form>

<?PHP } ?>
<!-- Fin de formulaire de demande du numéro de département (uniquement si n'existe pas) -->

<!-- Affichage uniquement si numéro de département saisi -->
<?PHP 
if ($cli_dep <> "") 
{ 
	if (exist_age_in_dep($cli_dep) == TRUE)
	{
?>
<table width="100%"  border="0">
  <tr>
    <td width="33%">
	<a href="cli_lst.php">Retour &agrave; la liste</a></div>
	</td>
    <td width="33%" bgcolor="#FF0000"><div align="center"><span class="titrerubrique1">Coordonn&eacute;es</span></div></td>
    <td width="33%">&nbsp;</td>
  </tr>
</table>
<table width="100%"  border="0">
<tr>
	<td width="31%">
    <?PHP if (($td == "edit") AND ($cli_ste <> "") AND (@$HTTP_SESSION_VARS["niv_log"]<>2))
	{
		$url_ccli = "ccli_maj.php?td=add&cc=".$cli_code."&page=1";
	?>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_ccli; ?>',600,560,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/ctacts.gif" width="22" height="22" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_ccli; ?>',600,560,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")> Ajouter un contact </a>
	<?PHP
		if (($nbcontacts <> 0) AND (@$HTTP_SESSION_VARS["niv_log"]<>2))
		{
			$url_ccli = "ccli_maj.php?td=edit&cc=".$cli_code."&page=1";
    ?>
		/
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_ccli; ?>',600,560,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")> Edition contacts (<?PHP echo sprintf ("%'03s",$nbcontacts);?>) </a>
	<?PHP
		}
	}
	?>
	</td>
	<td width="39%" valign="top">
		<div align="center">
		<span class="annot_gras_it">
		(<img src="../img/oblig.gif" width="10" height="11"> : Saisie obligatoire)
		</span>
		</div>
	</td>
	<td width="30%">
		<div align="right">
		<?PHP
		if (($td == "edit") AND (@$HTTP_SESSION_VARS["niv_log"]<>2))
		{
			$urlimp = "cli_maji.php?cc=".$coderech;
		?>	    
			<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")><img src="../img/print.gif" title="Imprimer la fiche" width="22" height="22" border="0" align="absmiddle"></a> <a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")> Imprimer la fiche </a></div>
		<?PHP } ?>
		</div>
	</td>
</tr>
</table>

<table width="100%"  border="0">
<tr>
	<td width="40%">
	<?PHP if (($td == "edit") AND ($nbcontrats <> 0) AND (@$HTTP_SESSION_VARS["niv_log"]<>2))
	{
		$url_coclh = "coclhd_lst.php?or=cli&cc=".$cli_code;
	?>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_coclh; ?>',800,560,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/view.gif" width="22" height="22" border="0" align="absmiddle"></a> <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_coclh; ?>',800,560,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Historiques contrats (<?PHP echo sprintf ("%'03s",$nbcontrats);?>) </a>
	<?PHP
	}
	?>
	</td>
	<td width="20%" valign="top">&nbsp;</td>
	<td width="40%" align="right">
	<?PHP if (($td == "edit") AND (@$HTTP_SESSION_VARS["niv_log"]>=3))
	{
		if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
		{
			$url_addint = "int_maj.php?td=add&cc=".$cli_code."&ca=".@$HTTP_SESSION_VARS["code_age"];
		}
		else
		{
			$url_addint = "int_maj.php?td=add&cc=".$cli_code."&ca=".$cli_prop;
		}
	?>
		<img src="../img/int.gif" width="22" height="22" align="absmiddle">
		<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_addint; ?>');")> Saisir une intervention </a>
	<?PHP
		if (($nbinterventions <> 0)  AND (@$HTTP_SESSION_VARS["niv_log"]<>2))
		{
			$url_inter = "int_lst.php?ord=DES&tri=Code&search=".$cli_code."&rech=Rechercher";
	?>
		/
		<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_inter; ?>');")> Voir les interventions (<?PHP echo sprintf ("%'03s",$nbinterventions);?>)</a>
	<?PHP
		}
	}
	?>	</td>
</tr>
</table>

<table width="100%"  border="0">
<tr>
	<td width="31%" align="left" valign="top">
	<?PHP if (($td == "edit") AND (@$HTTP_SESSION_VARS["niv_log"]>=3))
	{
		if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
		{
			$url_addcocl ="cocl_maj.php?td=add&co=&cc=".$cli_code."&ca=".@$HTTP_SESSION_VARS["code_age"];
		}
		else
		{
			$url_addcocl ="cocl_maj.php?td=add&co=&cc=".$cli_code."&ca=".$cli_prop;
		}
	?>
		<img src="../img/contrat.gif" width="22" height="22" align="absmiddle">
		<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_addcocl; ?>');")> Saisir un contrat </a>
	<?PHP
		if (($nbcontrats <> 0) AND (@$HTTP_SESSION_VARS["niv_log"]<>2))
		{
			$url_cocl = "cocl_lst.php?ord=DES&tri=Code&search=".$cli_code."&rech=Rechercher";
	?>
		/
		<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_cocl; ?>');")> Voir les contrats (<?PHP echo sprintf ("%'03s",$nbcontrats); ?>)</a>
	<?PHP
		}
	}
	?>
	</td>
	<td width="39%" valign="top" align="center">
	<?PHP 
	if ((@$HTTP_SESSION_VARS["niv_log"] >= 3) AND ($td == "edit"))
	{
	  $url_repcli = "fic_down.php?dir=clients/".strtolower($cli_code);
	?>
		 <a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_repcli; ?>');")><img src="../img/rep_priv.gif" title="Aller dans le r&eacute;pertoire priv&eacute;" width="22" height="22" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_repcli; ?>');")> Aller dans le r&eacute;pertoire priv&eacute;</a>
	<?PHP
	}
	else
		echo "&nbsp;";
	?>
	</td>
	<td width="30%" align="right">
	<?PHP if (($td == "edit") AND (@$HTTP_SESSION_VARS["niv_log"]<>2))
	{
		if (exist_rel_cli($coderech) == TRUE)
		{
			$url_rel = "rel_maj.php?td=edit&cr=".num_rel_cli($cli_code);
	?>
			<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_rel; ?>');")><img src="../img/relexist.gif" title="Voir le relev&eacute; de parc" width="22" height="22" border="0" align="absmiddle"></a>
			<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_rel; ?>');")> Voir le relev&eacute; de parc </a>
	<?PHP
		}
		else
		{
			if (@$HTTP_SESSION_VARS["niv_log"]<>2)
			{
				$url_rel = "rel_maj.php?td=add&cc=".$cli_code;
	?>
			<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_rel; ?>');")><img src="../img/rel.gif" title="Saisir le relev&eacute; de parc" width="22" height="22" border="0" align="absmiddle"></a>
			<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_rel; ?>');")> Saisir le relev&eacute; de parc </a>
	<?PHP
			}
		}
	}
	?>

	</td>
</tr>
</table>

<form name="cli_maj" method="post" action="cli_enr.php" onSubmit="javascript:; return (VForm(this,tab2_champ,''));">
	<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
	<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<?PHP if ($td == "add") {?>
		<input name="codecli" type="hidden" id="codecli" value="<?PHP echo $cli_code ?>">
<?PHP } ?>
<?PHP if ($td <> "add") {?>
<table width="800"  border="0">
<tr>
	<td width="16%" class="rubfrm" id="f_codecli"><div align="right">Code Client</div></td>
	<td width="84%">
		<input name="codecli" type="text" id="codecli" value="<?PHP echo $cli_code ?>" readonly="1">
	</td>
</tr>
</table>
<?PHP }  ?>

<table width="800"  border="0">
<?PHP
if (@$HTTP_SESSION_VARS["niv_log"] >= 2)
{
?>
<tr>
	<td class="rubfrm" id="f_typ"><div align="right">Type</div></td>
	<td>
		<?PHP 
		if ($td == "add")
		{ 
			echo "<select name=\"typ\" size=\"1\" id=\"typ\">";
			echo "<option value=\"\" selected>-- Choisissez pourquoi vous créez ce client --</option>";
			for ($i=0; $i<3; $i++)
			{
				echo "<option value=\"".$i."\">".$typ_client[$i]."</option>";
			}
			echo "</select>";
		?>
			<img src="../img/oblig.gif" width="10" height="11">
		<?PHP
		}

		if (($td == "edit") OR ($td == "del"))
		{ 
			if ($cli_type <> 2)
			{
				echo "<select name=\"typ\" size=\"1\" id=\"typ\">";
				echo "<option value=\"\">-- Choisissez pourquoi vous créez ce client --</option>";
				for ($i=0; $i<3; $i++)
				{
					if ($i == $cli_type)
						echo "<option value=\"".$i."\" selected>".$typ_client[$i]."</option>";
					else
						echo "<option value=\"".$i."\">".$typ_client[$i]."</option>";
				}
				echo "</select>";
			?>
				<img src="../img/oblig.gif" width="10" height="11">
			<?PHP
			}
			else
			{
			?>
				<input name="typ" type="text" id="type" value="<?PHP echo $typ_client[$cli_type] ?>" readonly="1">		
			<?PHP
			}
		}
		?>
	</td>
</tr>
<tr>
	<td width="16%" class="rubfrm" id="f_cat"><div align="right">Cat&eacute;gorie</span></div></td>
	<td width="84%">
		<select name="cat" size="1" id="cat">
		<?PHP
		
		echo "<option>-- Choisissez une catégorie --</option>";

		// Création de la liste des catégories
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBCCAT." ORDER BY cat_desc");

		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			if ($cli_cat == $cat_code)
			{
				echo '<option value="'.$cat_code.'" selected>'.$cat_desc.'</option>';
			}
			else
			{
				echo '<option value="'.$cat_code.'">'.$cat_desc.'</option>';
			}
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<?PHP
}
?>
<tr>
	<td width="16%" class="rubfrm" id="f_ste"><div align="right">Soci&eacute;t&eacute;</div></td>
	<td width="84%">
		<table width="100%" border="0">
		<tr>
		<td width="200">
		<?PHP 
		if ($td <> "add") 
		{
			if ((@$HTTP_SESSION_VARS["niv_log"] <> 2) AND ($td=="edit"))
			{ 
		?>
			<input name="ste" type="text" id="ste" value="<?PHP echo $cli_ste ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase(); tst_sites_client(this.value);">
		<?PHP
			}
			else
			{
		?>
			<input name="ste" type="text" id="ste" value="<?PHP echo $cli_ste ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<?PHP
			}
		}
		else
		{
		?>
			<input name="ste" type="text" id="ste" value="<?PHP echo $cli_ste ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<?PHP
		}
		?>
		</td>
		<td align="left">
		<?PHP 
		if ($td <> "add") 
		{
		?>
			<div id="site" style="display:none" align="left">
				<a href="javascript:;" onclick="javascript:; fen_sites_client(document.cli_maj.codecli.value);")><img src="../img/sites.gif" title="G&eacute;rer les sites" width="16" height="16" border="0" align="bottom"></a>
				<a href="javascript:;" onclick="javascript:; fen_sites_client(document.cli_maj.codecli.value);")> G&eacute;rer les sites secondaires</a>
			</div>
			<div id="pas_site"  style="display:block" align="left">
				&nbsp;
			</div>
		<?PHP
		}
		else
		{
		?>
			&nbsp;
		<?PHP
		}
		?>
		</td>
		</tr>
		</table>
	</td>
</tr>
<tr>
  <td class="rubfrm" id="f_rcs"><div align="right">RCS</div></td>
  <td><input name="rcs" type="text" id="rcs" value="<?PHP echo $cli_rcs ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();"></td>
</tr>
<tr>
	<td width="16%" class="rubfrm" id="f_civil"><div align="right">Civilit&eacute;</div></td>
	<td width="84%">
		<select name="civil" size="1" id="civil">
		<?PHP
		
		echo "<option>-- Choisissez une civilité --</option>";

		// Création de la liste des civilités
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBCIV." ORDER BY civ_desc");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			if ($cli_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.gif" width="10" height="11">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_prenom"><div align="right">Pr&eacute;nom</div></td>
	<td>
		<input name="prenom" type="text" id="prenom" value="<?PHP echo $cli_prenom ?>" size="50" maxlength="50">
		<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_nom"><div align="right">Nom</div></td>
	<td>
		<input name="nom" type="text" id="nom" value="<?PHP echo $cli_nom ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11">
	</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 $cli_adr1 ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.gif" width="10" height="11">
	</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 $cli_adr2 ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_dep"><div align="right">D&eacute;partement</div></td>
	<td>
		<input name="dep" type="text" id="dep" value="<?PHP echo $cli_dep ?>" size="3" maxlength="3" readonly="1">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_ville"><div align="right">Ville</div></td>
	<td>
		<select name="ville" size="1" id="ville">
		<?PHP
		
		echo "<option>-- Choisissez une ville --</option>";

		// Création de la liste des villes
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$filtre = $cli_dep;
		if (($filtre == "2A") OR ($filtre == "2B"))
			$filtre = "20";
		$rs = mysql_query("SELECT * FROM ".TBVILLES." WHERE `villes_cp` LIKE '".$filtre."%' ORDER BY villes_nom");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			if ($cli_ville == $villes_insee)
			{
				echo '<option value="'.$villes_insee.'" selected>'.str_majuscules($villes_nom).' ('.$villes_cp.')</option>';
			}
			else
			{
				echo '<option value="'.$villes_insee.'">'.str_majuscules($villes_nom).' ('.$villes_cp.')</option>';
			}
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		<img src="../img/oblig.gif" width="10" height="11">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_pays"><div align="right">Pays</div></td>
	<td>
		<select name="pays" size="1" id="pays">
	<?PHP
		
		echo "<option>-- Choisissez un pays --</option>";

		// Création de la liste des pays
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBPAYS." ORDER BY pays_nom");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			if ($cli_pays == $pays_nom)
			{
				echo '<option value="'.$pays_nom.'" selected>'.$pays_nom.'</option>';
			}
			else
			{
				echo '<option value="'.$pays_nom.'">'.$pays_nom.'</option>';
			}
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		<img src="../img/oblig.gif" width="10" height="11">
	</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 $cli_telf ?>" size="20" maxlength="20">
		<img src="../img/oblig.gif" width="10" height="11">
	</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 $cli_fax ?>" size="20" maxlength="20">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_telp"><div align="right">Portable</div></td>
	<td>
		<input name="telp" type="text" id="telp" value="<?PHP echo $cli_telp ?>" size="20" maxlength="20">
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_email"><div align="right">Email</div></td>
	<td>
		<input name="email" type="text" id="email" value="<?PHP echo $cli_email ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<img src="../img/oblig.gif" width="10" height="11">
		<?PHP 
		if (($td == "edit") AND (@$HTTP_SESSION_VARS["niv_log"] >= 3))
		{ ?>
			<a href="mailto:<?PHP echo $cli_email ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border="0" align="absmiddle"></a>
		<?PHP } ?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_mess"><div align="right">Messagerie</div></td>
	<td>
		<input name="mess" type="text" id="mess" value="<?PHP echo $cli_mess ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
	</td>
</tr>
<?PHP if (@$HTTP_SESSION_VARS["niv_log"] >= 5)
{ 
?>
<tr>
	<td class="rubfrm" id="f_notaa"><div align="right">Notes Administration</div></td>
	<td>
		<textarea name="notaa" cols="90" rows="5" id="notaa"><?PHP echo $cli_notaa ?></textarea>
	</td>
</tr>
<?PHP
}

if (@$HTTP_SESSION_VARS["niv_log"] >= 3)
{ 
?>
<tr>
	<td height="37" class="rubfrm" id="f_notat"><div align="right">Notes Techniciens </div></td>
	<td>
		<textarea name="notat" cols="90" rows="5" id="notat"><?PHP echo $cli_notat ?></textarea>
	</td>
</tr>
<tr>
	<td height="37" class="rubfrm" id="f_cpta"><div align="right">Comptabilit&eacute;</div></td>
	<td>
		<?php if (@$HTTP_SESSION_VARS["niv_log"] <5)
		{
			if (@$HTTP_SESSION_VARS["niv_log"] == 4)
			{
				if (mod_fact_age(@$HTTP_SESSION_VARS["code_log"]) == 1) // Seules les agences gérant leurs factures peuvent modifier ce paramètre
				{
		?>
					<input name="cpta" type="text" id="cpta" value="<?PHP echo $cli_cpta ?>" size="2" maxlength="2">
					<img src="../img/oblig.gif" width="10" height="11">
		<?PHP
				} 
				else 
				{ 
		?>
					<input name="cpta" type="text" id="cpta" value="<?PHP echo $cli_cpta ?>" size="2" maxlength="2" readonly="1">
		<?PHP 
				}
			} 
			else
			{
		?>
				<input name="cpta" type="text" id="cpta" value="<?PHP echo $cli_cpta ?>" size="2" maxlength="2" readonly="1">
		<?PHP
			}
		}
		else
		{
		?>
			<input name="cpta" type="text" id="cpta" value="<?PHP echo $cli_cpta ?>" size="2" maxlength="2">
			<img src="../img/oblig.gif" width="10" height="11">
		<?PHP
		}
		?>
		<br>
		<span class="annot_std_it"><em>0 : Aucun probl&egrave;me / 1 : A surveiller / 2 : Relanc&eacute; / 3 : Bloqu&eacute; </em></span>
	</td>
</tr>
<?PHP
}
?>
</table>

<p align="center">
	<?PHP if (($td == "edit") or ($td == "add")) 
	{ ?>
		<input name="RAZ" type="reset" id="RAZ" value="R&eacute;initialiser">
		<input name="submit" type="submit" id="submit" value="Enregistrer">
		<?PHP 
		if (($cli_cpta <> 3) AND (@$HTTP_SESSION_VARS["niv_log"] >= 3))
		{
		?>
			<input name="int" type="submit" id="int" value="Enregistrer & Saisir Intervention">
		<?PHP
		} 
	} ?>
	<?PHP if (($td == "del") AND (@$HTTP_SESSION_VARS["niv_log"] >= 3)) { ?>
	<input name="del" type="submit" id="del" value="Supprimer">
	<input name="annul" type="button" id="annul" value="Annuler" onclick="javascript:; history.back();">
	<?PHP } ?>
</p>
</form>

		<?PHP if ($td == "del") 
		{
		?>
			<script>
				warndelcli();
			</script>
		<?PHP
		}
		
		// On n'alerte sur le client que si on est en niveau "technicien" ou supérieur
		if (@$HTTP_SESSION_VARS["niv_log"] >= 3)
		{
		?>
		<script type="text/javascript">
			warnedit(<?PHP echo $cli_cpta; ?>,"client");
		</script>
<?PHP
		}
	}
	else
	{
?>
	<div align="center">
	<span class="rubNormal">Pas d'agence g&eacute;rant ce d&eacute;partement</span>
	</div>
<?PHP 
	} 
}?>
<!-- Fin affichage uniquement si numéro de département saisi -->
<!-- Fin affiché uniquement s'il y a au moins une catégorie de client et au moins une civilité -->
<?PHP
}
else
{
	if (nb_ccat() == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('cat_lst.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins une cat&eacute;gorie de client...</p>
<?PHP
	}

	if (nb_civ() == 0)
	{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('civ_lst.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins une civilit&eacute;...</p>
    <?PHP
	}
}
}
else
{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('cli_lst.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de choisir un client...</p>
<?PHP
 }
?>

  
<?php 
	include_once ("pied.php")
?>
