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

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 require ("../inc/fic.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$coderech = strip_tags(trim($_GET['cc']));
	$cli_dep = strip_tags(trim($_GET['dep']));
	$cli_ndep = strip_tags(trim($_GET['ndep']));
	
	$nbcontacts = 0;
	$nbcontrats = 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);

		// Récupération des informations clients
		$row = lit_enr_cli($coderech);
		extract ($row);

		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;
			}
		}

		if ($pbm_cli == FALSE)
		{
			$titre = "DEMENAGEMENT DE 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 : D&eacute;m&eacute;nagement Client</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../inc/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 validation des formulaires -->
<script language="JavaScript" src="../inc/validator.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>

<div id="patience" style="position:absolute; width:620px; height:50px; z-index:1; left: 50px; top: 120px;">
  <table width="100%"  border="1" cellspacing="0" bordercolor="#FFFF00">
    <tr>
      <td class="titrerubrique1"><div align="center">
        <p>Merci de patienter pendant le chargement des fichiers Villes et Pays</p>
        <p><img src="../img/baratt.gif" width="350" height="11"></p>
      </div></td>
    </tr>
  </table>
</div>


<script language="JavaScript" type="text/JavaScript">
var nava = (document.layers);
var dom = (document.getElementById);
var iex = (document.all);
if (nava) { cach = document.cache }
else if (dom) { cach = document.getElementById("patience").style }
else if (iex) { cach = cache.style }
largeur = screen.width;
cach.left = Math.round((largeur/2)-200);
cach.visibility = "visible";

function cacheOff()
	{
	cach.visibility = "hidden";
	}
window.onload = cacheOff
</script>

</head>

<body>

<?php 
	include_once ("entete.php"); 
?>
<?PHP
if ($pbm_cli == FALSE)
{
?>
	<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
	
	<!-- Formulaire de demande du numéro de département (uniquement si n'existe pas) -->
	<?PHP if ($cli_ndep == "") { ?>
	<form name="dde_dep" id="dde_dep" method="GET" action="clidem_maj.php">
	<p>
		  <input name="cc" type="hidden" id="cc" value="<?PHP echo $coderech ?>">
		  <input name="dep" type="hidden" id="dep" value="<?PHP echo $cli_dep ?>">
	</p>
		<p align="center">Merci de choisir le d&eacute;partement o&ugrave; ce client a d&eacute;m&eacute;nag&eacute;.</p>
		<table width="100%"  border="0">
	<tr>
		<td width="20%" class="tfvNormal" id="f_ndep"><div align="right">D&eacute;partement</div></td>
		<td>
			<select name="ndep" size="1" id="ndep">
			<?PHP
			
			// 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");
			
			$i=0;
			
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
	
				if ($i == 0)
				{
					echo "<option value=\"\" selected>-- Choisissez un département --</option>";
				}				
				$chaine_dep = $dep_num." (".$dep_nom.")";
				echo "<option value=\"".$dep_num."\">".$chaine_dep."</option>";
				
				$i++;
			}
	
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			</select>
			  <img src="../img/oblig.gif" width="10" height="11">
		</td>
	</tr>
	</table>
	<p align="center">
		<input name="RAZ" type="button" id="RAZ" value="Annuler" onclick="self.location.href='cli_lst.php?ta=m'">
		<input type="submit" name="Submit" value="Valider">
	</p>
	</form>
	
	<script>
	// form fields description structure
	var a_fields = {
		'ndep':{'l':'Département','r':true,'f':'integer','t':'f_ndep','mx':3}
	},
	
	o_config = {
		'to_disable' : ['submit'],
		'alert' : 1
	}
	
	// validator constructor call
	var v = new validator('dde_dep', a_fields, o_config);
	
	</script>
	<?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_ndep <> "") AND ($cli_dep <> ""))
	{ 
		if (exist_age_in_dep($cli_ndep) == TRUE) // Vérificiation si nouveau département couvert par une agence
		{
			$ancienne_liste_age = liste_age_actives_dep($cli_dep);
			$nouvelle_liste_age = liste_age_actives_dep($cli_ndep);
			$diff_entre_listes = diff_txt_in_tabtxt($tabtxt1,$tabtxt2);
			
			$pbm_int_non_close = FALSE;
			$pbm_int_non_close_diff = FALSE;
	
			// On vérifie si on change complètement de zone de chalandise
			if (txt_commun_in_2tabtxt($ancienne_liste_age,$nouvelle_liste_age) == FALSE)
			{
				// Si oui, on vérifie s'il n'y a pas d'intervention non close dans l'ancienne liste d'agences couvrant le client
				if (exist_liste_age_cli_in_int_ouv($ancienne_liste_age,$code) == TRUE)
					$pbm_int_non_close = TRUE;
			}
			else
			{
				// Si non, on vérifie s'il n'y a pas d'intervention non close la liste des agences différentes de la nouvelle liste
				// des agences couvrant le client
				if (exist_liste_age_cli_in_int_ouv($diff_entre_listes,$code) == TRUE)
					$pbm_int_non_close_diff = TRUE;
			}
			
			if (($pbm_int_non_close == FALSE) AND ($pbm_int_non_close_diff == FALSE))
			{
	?>
	<table width="100%"  border="0">
	  <tr>
		<td width="33%">
			<strong><a href="../admin/cli_lst.php?ta=m&ct=&ci=">Retour &agrave; la liste</a> </strong>
		</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%">&nbsp;
		
		</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%">&nbsp;
		
		</td>
	</tr>
	</table>
	
	
	<form name="cli_dem" method="post" action="clidem_enr.php" onsubmit="return v.exec()">
		<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
		<input name="ndep" type="hidden" id="ndep" value="<?PHP echo $cli_ndep ?>">
	
	<table width="800"  border="0">
	<tr>
		<td width="16%" class="tfvNormal" id="f_codecli"><div align="right">Code Client</div></td>
		<td width="84%">
			<input name="code" type="text" id="code" value="<?PHP echo $cli_code ?>" readonly="1">
		</td>
	</tr>
	</table>
	
	<table width="800"  border="0">
	<tr>
		<td width="16%" class="tfvNormal" id="f_ste"><div align="right">Soci&eacute;t&eacute;</div></td>
		<td width="84%">
			<input name="ste" type="text" id="ste" value="<?PHP echo $cli_ste ?>" size="50" readonly="1">
		</td>
	</tr>
	<tr>
	  <td class="tfvNormal" id="f_rcs"><div align="right">RCS</div></td>
	  <td>
		<input name="rcs" type="text" id="rcs" value="<?PHP echo $cli_rcs ?>" size="50" readonly="1">
	  </td>
	</tr>
	<tr>
		<td width="16%" class="tfvNormal" id="f_civil"><div align="right">Civilit&eacute;</div></td>
		<td width="84%">
			<?PHP
			
			// Récupération du libellé civilité
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM `".TBCIV."` WHERE `civ_code` = '".$cli_civilite."'";
			$rs = mysql_query($rech) or die(mysql_error());
			if ($resultat = mysql_fetch_array($rs))
			{
				extract($resultat);
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			<input name="civil" type="text" id="civil" value="<?PHP echo $civ_desc ?>" size="50" readonly="1">
		</td>
	</tr>
	<tr>
		<td class="tfvNormal" 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" readonly="1">
		</td>
	</tr>
	<tr>
		<td class="tfvNormal" id="f_nom"><div align="right">Nom</div></td>
		<td>
			<input name="nom" type="text" id="nom" value="<?PHP echo $cli_nom ?>" size="50" readonly="1">
		</td>
	</tr>
	</table>
	
	<table width="800"  border="0">
	<tr>
		<td class="tfvNormal"><div align="center">Anciennes Coordonn&eacute;es</div></td>
	</tr>
	</table>
	
	<table width="800"  border="0">
	<tr>
		<td width="16%" class="tfvNormal" 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" readonly="1">
		</td>
	</tr>
	<tr>
		<td width="16%" class="tfvNormal" 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" readonly="1">
		</td>
	</tr>
	<tr>
		<td width="16%" class="tfvNormal" 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" readonly="1">
		</td>
	</tr>
	<tr>
		<td width="16%" class="tfvNormal" id="f_ville"><div align="right">Ville</div></td>
		<td>
			<input name="ville" type="text" id="ville" value="<?PHP echo Retourneville($cli_ville)." (".Retournecp($cli_ville).")"; ?>" size="50" readonly="1">
		</td>
	</tr>
	<tr>
		<td width="16%" class="tfvNormal" id="f_pays"><div align="right">Pays</div></td>
		<td>
			<input name="pays" type="text" id="pays" value="<?PHP echo $cli_pays; ?>" size="50" readonly="1">
		</td>
	</tr>
	<tr>
		<td width="16%" class="tfvNormal" 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" readonly="1">
		</td>
	</tr>
	<tr>
		<td width="16%" class="tfvNormal" 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"readonly="1">
		</td>
	</tr>
	<tr>
		<td width="16%" class="tfvNormal" id="f_telp"><div align="right">Portable</div></td>
		<td>
			<input name="telp" type="text" id="telp" value="<?PHP echo $cli_telp ?>" size="20"readonly="1">
		</td>
	</tr>
	</table>
	
	<br>
	<table width="800"  border="0">
	<tr>
		<td class="tfvNormal"><div align="center">Nouvelles Coordonn&eacute;es</div></td>
	</tr>
	</table>
	
	<table width="800"  border="0">
	<tr>
		<td width="16%" class="tfvNormal" id="f_nadr1"><div align="right">Adresse(1)</div></td>
		<td>
			<input name="nadr1" type="text" id="nadr1" 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="tfvNormal" id="f_nadr2"><div align="right">Adresse(2)</div></td>
		<td>
			<input name="nadr2" type="text" id="nadr2" value="" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();">
		</td>
	</tr>
	<tr>
		<td class="tfvNormal" id="f_ndep"><div align="right">D&eacute;partement</div></td>
		<td>
			<input name="ndep" type="text" id="ndep" value="<?PHP echo $cli_ndep ?>" size="3" maxlength="3" readonly="1">
		</td>
	</tr>
	<tr>
		<td class="tfvNormal" id="f_nville"><div align="right">Ville</div></td>
		<td>
			<select name="nville" size="1" id="nville">
			<?PHP
			
			// Création de la liste des villes
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$filtre = $cli_ndep;
			if (($filtre == "2A") OR ($filtre == "2B"))
				$filtre = "20";
			$rs = mysql_query("SELECT * FROM ".TBVILLES." WHERE `villes_cp` LIKE '".$filtre."%' ORDER BY villes_nom");
			
			echo "<option value=\"\" selected>-- Choisissez une ville --</option>";
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
	
				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="tfvNormal" id="f_npays"><div align="right">Pays</div></td>
		<td>
			<select name="npays" size="1" id="npays">
		<?PHP
			
			// 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");
			
			echo "<option value=\"\" selected>-- Choisissez un pays --</option>";
	
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
	
				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="tfvNormal" id="f_ntelf"><div align="right">T&eacute;l&eacute;phone Fixe </div></td>
		<td>
			<input name="ntelf" type="text" id="ntelf" value="" size="20" maxlength="20">
			<img src="../img/oblig.gif" width="10" height="11">
		</td>
	</tr>
	<tr>
		<td class="tfvNormal" id="f_nfax"><div align="right">T&eacute;l&eacute;copieur</div></td>
		<td>
			<input name="nfax" type="text" id="nfax" value="" size="20" maxlength="20">
		</td>
	</tr>
	<tr>
		<td class="tfvNormal" id="f_ntelp"><div align="right">Portable</div></td>
		<td>
			<input name="ntelp" type="text" id="ntelp" value="" size="20" maxlength="20">
		</td>
	</tr>
	</table>
	
	<p align="center">
		<input name="RAZ" type="button" id="RAZ" value="Annuler" onclick="self.location.href='cli_lst.php?ta=m'">
		<input name="submit" type="submit" id="submit" value="Enregistrer">
	</p>
	</form>
	
	<script>
	// form fields description structure
	var a_fields = {
		'ste':{'l':'Société','r':false,'t':'f_ste'},
		'civil':{'l':'Civilité','r':true,'f':'alpha','t':'f_civil'},
		'prenom':{'l':'Prénom','r':true,'t':'f_prenom','mx':50},
		'nom':{'l':'Nom','r': true,'t':'f_nom','mx':50},
		'adr1':{'l':'Adresse(1)','r':true,'t':'f_adr1','mx':50},
		'adr2':{'l':'Adresse(2)','r':false,'t':'f_adr2','mx':50},
		'ville':{'l':'Ville','r':true,'t':'f_ville','mx':50},
		'pays':{'l':'Pays','r':true,'t':'f_pays','mx':50},
		'telf':{'l':'Téléphone','r':true,'f':'unsigned','t':'f_telf','mx':20},
		'fax':{'l':'Télécopie','r':false,'f':'unsigned','t':'f_fax'},
		'telp':{'l':'Portable','r':false,'f':'unsigned','t':'f_telp'},
		'nadr1':{'l':'Nouvelle Adresse(1)','r':true,'t':'f_nadr1','mx':50},
		'nadr2':{'l':'Nouvelle Adresse(2)','r':false,'t':'f_nadr2','mx':50},
		'nville':{'l':'Nouvelle Ville','r':true,'t':'f_nville','mx':20},
		'npays':{'l':'Nouveau Pays','r':true,'t':'f_npays','mx':20},
		'ntelf':{'l':'Nouveau Téléphone','r':true,'f':'unsigned','t':'f_ntelf','mx':20},
		'nfax':{'l':'Nouvelle Télécopie','r':false,'f':'unsigned','t':'f_nfax'},
		'ntelp':{'l':'Nouveau Portable','r':false,'f':'unsigned','t':'f_ntelp'}
	},
	
	o_config = {
		'to_disable' : ['submit', 'RAZ'],
		'alert' : 1
	}
	
	// validator constructor call
	var v = new validator('cli_dem', a_fields, o_config);
	
		</script>
	  
	<script type="text/javascript">
		warnedit(<?PHP echo $cli_cpta; ?>,"client");
	</script>
	<?PHP
			}
			else
			{
				if ($pbm_int_non_close == TRUE)
				{
	?>
				<div align="center">
				<span class="rubNormal">Il faut d'abord clore les interventions en cours car le client change compl&egrave;tement de zone de chalandise. </span>
				</div>
		<?PHP
				}
	
				if ($pbm_int_non_close_diff == TRUE)
				{
		?>
				<div align="center">
				<span class="rubNormal">Il faut d'abord clore les interventions en cours sur les agences ne pouvant plus g&eacute;rer ce client.</span>
				</div>
		<?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 -->
<?PHP
}
else
{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('cli_lst.php?ta=m');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de choisir un de vos clients...</p>
<?PHP
 }
?>
