<?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
****************************************************************************************/

session_start(); 
?>
<?php if ((@$HTTP_SESSION_VARS["etat_log"] <> "connecte") or ((@$HTTP_SESSION_VARS["niv_log"] <> 9) AND (@$HTTP_SESSION_VARS["niv_log"] <> 5))) header("Location: ../index.php") ?>
<?php include ("../inc/config.inc.php") ?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?PHP include("../inc/geoip.inc"); ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$cge_dep = strip_tags(trim($_GET['dep']));

	// Récupération des informations centre de gestion

	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech = "SELECT * FROM " .TBCG;
	$rs = mysql_query($rech)or die(mysql_error());
	if (mysql_num_rows($rs) == 1) // Uniquement UN SEUL enregistrement !
	{
		if ($row = mysql_fetch_array($rs))
		{
			extract ($row);
		}
		$creation = 0;

		$titre = "MODIF. CENTRE DE GESTION";
	}

	if (mysql_num_rows($rs) == 0) // Si pas encore créé
	{
		$creation = 1;
		$cge_pays = pays_connect($_SERVER['REMOTE_ADDR']);

		$titre = "CREATION CENTRE DE GESTION";
	}
	
	mysql_free_result($rs);
	mysql_close($conn);

	$cge_datemod = $datea;

?>

<!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 Centre de Gestion</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>

<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 ("../inc/entete.php"); 
?>

<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 ($cge_dep == "") { ?>
<form name="dde_dep" id="dde_dep" method="GET" action="cge_maj.php">
	<p align="center">Merci de choisir le d&eacute;partement dans lequel est implant&eacute; le centre de gestion.</p>
	<table width="100%"  border="0">
<tr>
	<td width="20%" class="tfvNormal" id="f_ouvert"><div align="right">D&eacute;partement</div></td>
	<td>
		<select name="dep" size="1" id="dep">
		<?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_nom");
		
		$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_nom." (".$dep_num.")";
			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 type="submit" name="Submit" value="Valider">
</p>
</form>

<script>
// form fields description structure
var a_fields = {
	'dep':{'l':'Code','r':true,'f':'integer','t':'f_dep','mx':3}
},

o_config = {
	'to_disable' : ['submit'],
	'alert' : 1
}

// validator constructor call
var v = new validator('cge_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 ($cge_dep <> "") { ?>
<div align="center">
    <span class="annot_gras_it">(<img src="../img/oblig.gif" width="10" height="11"> : Saisie obligatoire)</span>
</div>
<form name="cge_maj" id="cge_maj" method="post" action="cge_enr.php" onsubmit="return v.exec()">
      <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
      <input name="creation" type="hidden" id="creation" value="<?PHP echo $creation ?>">
	<?PHP
	if ($creation == 0)
	{
	?>
	  <input name="code" type="hidden" id="code" value="<?PHP echo $cge_code ?>">
	  <input name="pass" type="hidden" id="pass" value="<?PHP echo $cge_pass ?>">
	<?PHP
	}
	?>
<table width="100%"  border="0">
	<?PHP if ($creation == 0) { ?>
    <tr>
      <td height="21" class="tfvNormal" id="f_logo"><div align="right">Logo</div></td>
      <td>
		<?PHP
		  $url_img = "cge_logo.php";
		?>
	  	<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_img; ?>',500,300,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/view.gif" width="22" height="22" border="0" align="abddle"></a>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_img; ?>',500,300,'status=no,scrollbars=no,menubar=no,statusbar=no,location=no,locationbar=no');")> Voir le logo</a></td>
    </tr>
	<?PHP } ?>
	<?PHP if ($creation == 1) { ?>
    <tr>
      <td class="tfvNormal" id="f_code"><div align="right">Code Connexion </div></td>
      <td>
	  	<input name="code" type="text" id="code" value="<?PHP echo $cge_code ?>" size="10" maxlength="10" onChange="javascript:this.value=this.value.toUpperCase();">
        <img src="../img/oblig.gif" width="10" height="11">
	  </td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_pass"><div align="right">Mot de Passe </div></td>
      <td>
	  	<input name="pass" type="text" id="pass" value="<?PHP echo $cge_pass ?>" size="10" maxlength="10">
        <img src="../img/oblig.gif" width="10" height="11">
	  </td>
    </tr>
	<?PHP } ?>
    <tr>
      <td class="tfvNormal" id="f_nom"><div align="right">Nom</div></td>
      <td><input name="nom" type="text" id="nom" value="<?PHP echo $cge_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="tfvNormal" id="f_rcs"><div align="right">RCS / APE </div></td>
      <td><input name="rcs" type="text" id="rcs" value="<?PHP echo $cge_rcs ?>" 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_tcom"><div align="right">Tribunal com. </div></td>
      <td><input name="tcom" type="text" id="tcom" value="<?PHP echo $cge_tcom ?>" size="70" maxlength="70" onChange="javascript:this.value=this.value.toUpperCase();">
        <img src="../img/oblig.gif" width="10" height="11"></td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_adr1"><div align="right">Adresse (1) </div></td>
      <td><input name="adr1" type="text" id="adr1" value="<?PHP echo $cge_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="tfvNormal" id="f_adr2"><div align="right">Adresse (2) </div></td>
      <td><input name="adr2" type="text" id="adr2" value="<?PHP echo $cge_adr2 ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();"></td>
    </tr>
<tr>
	<td class="tfvNormal" id="f_dep"><div align="right">D&eacute;partement</div></td>
	<td>
		<input name="dep" type="text" id="dep" value="<?PHP echo $cge_dep ?>" size="3" maxlength="3" readonly="1">
	</td>
</tr>
    <tr>
      <td class="tfvNormal" id="f_ville"><div align="right">Ville</div></td>
      <td>
		  <select name="ville" size="1" id="ville">
          <?PHP
				
				// Création de la liste des villes
	
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$filtre = $cge_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 ($cge_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="tfvNormal" id="f_pays"><div align="right">Pays</div></td>
      <td>
		  <select name="pays" size="1" id="pays">
          <?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");
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($cge_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="tfvNormal" id="f_telf"><div align="right">T&eacute;l&eacute;phone Fixe<br>
        (Commentaire) 
      </div></td>
      <td><input name="telf" type="text" id="telf" value="<?PHP echo $cge_telf ?>" size="20" maxlength="20">
      <img src="../img/oblig.gif" width="10" height="11"><br>
      <input name="txttelf" type="text" id="txttelf" value="<?PHP echo $cge_txttelf ?>" size="50" maxlength="50"></td>
    </tr>
    <tr>
      <td width="30%" class="tfvNormal" id="f_fax"><div align="right">T&eacute;l&eacute;copieur<br>
        (Commentaire)
      </div></td>
      <td><input name="fax" type="text" id="fax" value="<?PHP echo $cge_fax ?>" size="20" maxlength="20">
      <img src="../img/oblig.gif" width="10" height="11"><br>
      <input name="txtfax" type="text" id="txtfax" value="<?PHP echo $cge_txtfax ?>" size="50" maxlength="50"></td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_web"><div align="right">Site Web </div></td>
      <td><input name="web" type="text" id="web" value="<?PHP echo $cge_web ?>" size="80" maxlength="200">
      <img src="../img/oblig.gif" width="10" height="11"></td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_heures"><div align="right">Horaires</div></td>
      <td><input name="heures" type="text" id="heures" value="<?PHP echo $cge_heures ?>" size="80" maxlength="200">
        <img src="../img/oblig.gif" width="10" height="11"></td>
    </tr>
    <tr>
      <td colspan="2" class="tfvNormal"><div align="center">Emails</div></td>
      <td>    
    </tr>
    <tr>
      <td class="tfvNormal" id="f_email"><div align="right">G&eacute;n&eacute;ral</div></td>
      <td><input name="email" type="text" id="email" value="<?PHP echo $cge_email ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
	  <?PHP if ($creation == 0) { ?>
      	<a href="mailto:<?PHP echo $cge_email ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
	  <?PHP } ?>
      <img src="../img/oblig.gif" width="10" height="11"> <span class="annot_std_it">(Pour contacts clients)</span> 
	  </td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_emaild"><div align="right">Direction</div></td>
      <td><input name="emaild" type="text" id="emaild" value="<?PHP echo $cge_emaild ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
	  <?PHP if ($creation == 0) { ?>
        <a href="mailto:<?PHP echo $cge_emaild ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
	  <?PHP } ?>
        <img src="../img/oblig.gif" width="10" height="11">
	  </td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_emailc"><div align="right">Comptabilit&eacute; / Finances</div></td>
      <td><input name="emailc" type="text" id="emailc" value="<?PHP echo $cge_emailc ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
	  <?PHP if ($creation == 0) { ?>
        <a href="mailto:<?PHP echo $cge_emailc ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
	  <?PHP } ?>
        <img src="../img/oblig.gif" width="10" height="11">
	  </td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_emailt"><div align="right">Technique</div></td>
      <td><input name="emailt" type="text" id="emailt" value="<?PHP echo $cge_emailt ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
	  <?PHP if ($creation == 0) { ?>
        <a href="mailto:<?PHP echo $cge_emailt ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
	  <?PHP } ?>
        <img src="../img/oblig.gif" width="10" height="11">
	  </td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_emailf"><div align="right">Franchise / Partenariat </div></td>
      <td><input name="emailf" type="text" id="emailf" value="<?PHP echo $cge_emailf ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
	  <?PHP if ($creation == 0) { ?>
        <a href="mailto:<?PHP echo $cge_emailt ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
	  <?PHP } ?>
        <img src="../img/oblig.gif" width="10" height="11">
	  </td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_emaili"><div align="right">Investisseurs</div></td>
      <td><input name="emaili" type="text" id="emaili" value="<?PHP echo $cge_emaili ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
	  <?PHP if ($creation == 0) { ?>
        <a href="mailto:<?PHP echo $cge_emailt ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
	  <?PHP } ?>
        <img src="../img/oblig.gif" width="10" height="11">
	  </td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_emailrh"><div align="right">Ressources Humaines</div></td>
      <td><input name="emailrh" type="text" id="emailrh" value="<?PHP echo $cge_emailrh ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
	  <?PHP if ($creation == 0) { ?>
        <a href="mailto:<?PHP echo $cge_emailrh ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="abddle"></a>
	  <?PHP } ?>
        <img src="../img/oblig.gif" width="10" height="11">
	  </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_nota"><div align="right">Notes</div></td>
      <td><textarea name="nota" cols="110" id="nota"><?PHP echo $cge_nota ?></textarea></td>
    </tr>
  </table>
  <p align="center">
    <input name="RAZ" type="reset" id="RAZ" value="R&eacute;initialiser">
    <input name="submit" type="submit" id="submit" value="Enregistrer">
  </p>
</form>
	
<script>
// form fields description structure
var a_fields = {
<?PHP if ($creation == 1) { ?>
	'code':{'l':'Code de Connexion','r':true,'f':'alphanum','t':'f_code','mn':10,'mx':10},
	'pass':{'l':'Mot de Passe','r':true,'f':'alphanum','t':'f_pass','mn':10,'mx':10},
<?PHP } ?>
	'nom':{'l':'Nom','r':true,'t':'f_nom','mx':50},
	'rcs':{'l':'RCS / APE','r':true,'t':'f_rcs','mx':50},
	'tcom':{'l':'Tribunal de Commerce','r':true,'t':'f_tcom','mx':70},
	'adr1':{'l':'Adresse (1)','r':true,'t':'f_adr1','mx':50},
	'adr2':{'l':'Adresse (2)','r':false,'t':'f_adr2','mx':50},
	'telf':{'l':'Téléphone Fixe','r':true,'t':'f_telf','mx':20},
	'fax':{'l':'Télécopieur','r':true,'t':'f_fax','mx':20},
	'web':{'l':'Site Web','r':true,'t':'f_web','mx':200},
	'heures':{'l':'Détail Horaires','r':true,'t':'f_heures','mx':200},
	'email':{'l':'Email','r':true,'f':'email','t':'f_email','mx':50},
	'emaild':{'l':'Email Direction','r':true,'f':'email','t':'f_emaild','mx':50},
	'emailc':{'l':'Email Service Comptabilité','r':true,'f':'email','t':'f_emailc','mx':50},
	'emailt':{'l':'Email Service Technique','r':true,'f':'email','t':'f_emailt','mx':50},
	'emailf':{'l':'Email Service Franchise','r':true,'f':'email','t':'f_emailf','mx':50},
	'emaili':{'l':'Email Service Investisseurs','r':true,'f':'email','t':'f_emaili','mx':50},
	'emailrh':{'l':'Email Service Ressources Humaines','r':true,'f':'email','t':'f_emailrh','mx':50}
},

o_config = {
	'to_disable' : ['submit', 'RAZ'],
	'alert' : 1
}

// validator constructor call
var v = new validator('cge_maj', a_fields, o_config);

</script>
<?PHP } ?>
<!-- Fin affichage uniquement si numéro de département saisi -->

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