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

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_date.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['typ']));
	$coderech = strip_tags(trim($_GET['code']));
	$ope_dep = strip_tags(trim($_GET['dep']));
	
	if ($coderech <> "")
	{
		$row = lit_enr_ope($coderech);
		extract ($row);

		$ope_congd = formatedate($ope_congd);
		$ope_congf = formatedate($ope_congf);

		if ($td == "edit")
			$titre = "MISE A JOUR COMPTE OPERATEUR";

		if ($td == "del")
			$titre = "SUPPRESSION COMPTE OPERATEUR";
	}
	else
	{
		if ($td == "add")
		{
			$ope_code = crecodesession("O");
			$ope_pass = cremdp(TRUE);
			$ope_pays = pays_connect($_SERVER['REMOTE_ADDR']);

			$titre = "CREATION COMPTE OPERATEUR";
		}
	}
?>

<!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 Op&eacute;rateur</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>

<!-- Définition Javascript pour calendrier popup -->

  <!-- Feuille de Style -->
  <link rel="stylesheet" type="text/css" media="all" href="../jscal/skins/aqua/theme.css" title="Aqua" />

  <!-- Script Javascript Principal -->
  <script type="text/javascript" src="../jscal/calendar.js"></script>

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscal/lang/calendar-fr.js"></script>

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="../jscal/calendar-setup.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>

<!-- 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(
	"nom:civil ; format:liste ; req:Y ; txt:Civilité ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:prenom ; format:txt ; req:Y ; txt:Prénom ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:nom ; format:txt ; req:Y ; txt:Nom ; 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:telp ; format:telp_fr ; req:N ; txt:Téléphone portable ; stok:frmok ; stbad:frmbad",
	"nom:email ; format:mail ; req:Y ; txt:Email ; stok:frmok ; stbad:frmbad",
	"nom:nota ; format:txt ; req:N ; txt:Notes ; stok:frmok ; stbad:frmbad");
</script>

</head>

<body>

<?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 civilité -->
<?PHP
if (nb_civ() <> 0)
{
?>
<!-- Formulaire de demande du numéro de département (uniquement si n'existe pas) -->
<?PHP if ($ope_dep == "") { ?>
<form name="dde_dep" id="dde_dep" method="GET" action="ope_maj.php" onSubmit="javascript:; return (VForm(this,tab1_champ,''));">
<p>
	  <input name="typ" type="hidden" id="typ" value="<?PHP echo $td ?>">
	  <input name="code" type="hidden" id="code" value="<?PHP echo $coderech ?>">
</p>
	<p align="center">Merci de choisir le d&eacute;partement dans lequel habite cet opérateur.</p>
	<table width="100%"  border="0">
<tr>
	<td width="20%" class="rubfrm" id="f_ouvert"><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);
			$chaine_dep = $dep_num." (".$dep_nom.")";
			echo "<option value=\"".$dep_num."\">".$chaine_dep."</option>";
		}
		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>

<?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 ($ope_dep <> "") { ?>
<table width="100%"  border="0">
  <tr>
    <td width="33%"><strong><em><a href="ope_lst.php">Retour &agrave; la liste</a></em></strong></td>
    <td width="33%" bgcolor="#FF0000"><div align="center"><span class="titrerubrique1">Coordonn&eacute;es</span></div></td>
    <td width="33%"><div align="right">
      </div>
	</td>
  </tr>
</table>
<div align="center">
    <span class="annot_gras_it">(<img src="../img/oblig.gif" width="10" height="11"> : Saisie obligatoire)</span>
</div>
<form name="ope_maj" method="post" action="ope_enr.php" onSubmit="javascript:; return (VForm(this,tab2_champ,''));">
  <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
  <input name="typdde" type="hidden" id="typdde" value="<?PHP echo $td ?>">
  <input name="pass" type="hidden" id="pass" value="<?PHP echo $ope_pass ?>">
  <?PHP if ($td == "add") { ?>
 	<input name="code" type="hidden" id="code" value="<?PHP echo $ope_code ?>">
	<input name="salarie" type="hidden" id="salarie" value="Oui">
  <?PHP } ?>
  <div align="right"></div>
  <div align="center"></div>
  <?PHP if ($td <> "add") {?>
  <table width="100%"  border="0">
    <tr>
	  <td width="20%" class="rubfrm" id="f_codetec"><div align="right">Code Op&eacute;rateur </div></td>
      <td><input name="code" type="text" id="code" value="<?PHP echo $ope_code ?>" readonly="1"></td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_salarie"><div align="right">Salari&eacute;</div></td>
      <td>
		<?PHP 
		if (($td == "edit") OR ($td == "del"))
		{ 
			if ($ope_out == FALSE)
			{
		?>
		
		    <select name="salarie" size="1" id="salarie">
        	<option value="Oui" selected>Oui</option>
        	<option value="Non">Non</option>
	      	</select> 

		<?PHP
			}
		}
		
		if (($td == "edit") OR ($td == "del"))
		{ 
			if ($ope_out == TRUE)
			{
		?>
		    <input name="salarie" type="text" id="salarie" value="Non" size="3" maxlength="3" readonly="1">
		<?PHP 
			}
		}
		?>
			<span class="annot_std_it">
		<?PHP

		if (($td == "edit") OR ($td == "del"))
		{ 
			if ($ope_out == false)
				echo "  (Embauche le : ".formatedate($ope_datecrea).")";
			else
				echo "  (Embauche le : ".formatedate($ope_datecrea).", départ le : ".formatedate($ope_dateout).")";
		}
		?>
			</span>
	  </td>
    </tr>
  </table>
  <?PHP }  ?>
  <table width="100%"  border="0">
  <?PHP if ($td <> "add") {?>
    <tr>
      <td width="20%" class="rubfrm" id="f_conges"><div align="right">Cong&eacute;s </div></td>
      <td colspan="3">
	    <span class="annot_petit_gras">du</span>
	    <input name="dconges" type="text" id="dconges" value="<?PHP echo $ope_congd; ?>" size="10" maxlength="10" readonly="1">
		<?PHP
		if ($ope_out == FALSE)
		{
		?>
        <img src="../img/calendar.png" id="f_img_dconges" title="Choisir votre date" width="16" height="16">
		<?PHP
		}
		?>
		<span class="annot_petit_gras"> au </span>
        <input name="fconges" type="text" id="fconges" value="<?PHP echo $ope_congf; ?>" size="10" maxlength="10" readonly="1">
		<?PHP
		if ($ope_out == FALSE)
		{
		?>
      <img src="../img/calendar.png" id="f_img_fconges" title="Choisir votre date" width="16" height="16"> 
	  <span class="annot_std_it">(Prochains cong&eacute;s ou cong&eacute;s en cours) ... (
	  <a href="javascript:;" onClick="document.ope_maj.dconges.value='';document.ope_maj.fconges.value='';"><img src="../img/raz.gif" width="22" height="22" border="0" align="absmiddle"></a>
	  <a href="javascript:;" onclick="document.ope_maj.dconges.value='';document.ope_maj.fconges.value='';")> Annuler)</a></span> 
	  	<?PHP
		}
		?>
	  </td>
    </tr>
	<?PHP } ?>
    <tr>
      <td width="20%" class="rubfrm" id="f_civil"><div align="right">Civilit&eacute;</div></td>
      <td width="83%" colspan="3">
		<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 ($ope_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 width="20%" class="rubfrm" id="f_prenom"><div align="right">Pr&eacute;nom</div></td>
      <td colspan="3"><input name="prenom" type="text" id="prenom" value="<?PHP echo $ope_prenom ?>" size="50" maxlength="50">
          <img src="../img/oblig.gif" width="10" height="11"></td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_nom"><div align="right">Nom</div></td>
      <td colspan="3"><input name="nom" type="text" id="nom" value="<?PHP echo $ope_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 width="20%" class="rubfrm" id="f_adr1"><div align="right">Adresse(1)</div></td>
      <td colspan="3"><input name="adr1" type="text" id="adr1" value="<?PHP echo $ope_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 width="20%" class="rubfrm" id="f_adr2"><div align="right">Adresse(2)</div></td>
      <td colspan="3"><input name="adr2" type="text" id="adr2" value="<?PHP echo $ope_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 colspan="3">
	  	<input name="dep" type="text" id="dep" value="<?PHP echo $ope_dep ?>" size="3" maxlength="3" readonly="1">
	  </td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_ville"><div align="right">Ville</div></td>
      <td colspan="3">
		<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);
		$rs = mysql_query("SELECT * FROM ".TBVILLES." WHERE `villes_cp` LIKE '".$ope_dep."%' ORDER BY villes_nom");
		
		$i=0;
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);

			if ($i == 0)
			{
				if ($ope_ville <> "")
					echo "<option value=\"\">-- Choisissez une ville --</option>";
				else
					echo "<option value=\"\" selected>-- Choisissez une ville --</option>";
			}

			if ($ope_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>';
			}

			$i++;
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
	  
          <img src="../img/oblig.gif" width="10" height="11"></td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_pays"><div align="right">Pays</div></td>
      <td colspan="3">
		<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");
		
		$i=0;
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);

			if ($i == 0)
			{
				if ($ope_pays <> "")
					echo "<option value=\"\">-- Choisissez un pays --</option>";
				else
					echo "<option value=\"\" selected>-- Choisissez un pays --</option>";
			}

			if ($ope_pays == $pays_nom)
			{
				echo '<option value="'.$pays_nom.'" selected>'.$pays_nom.'</option>';
			}
			else
			{
				echo '<option value="'.$pays_nom.'">'.$pays_nom.'</option>';
			}

			$i++;
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		<img src="../img/oblig.gif" width="10" height="11">
      </td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_telf"><div align="right">T&eacute;l&eacute;phone Fixe</div></td>
      <td colspan="3"><input name="telf" type="text" id="telf" value="<?PHP echo $ope_telf ?>" size="20" maxlength="20" >
          <img src="../img/oblig.gif" width="10" height="11"></td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_telp"><div align="right">Portable</div></td>
      <td colspan="3"><input name="telp" type="text" id="telp" value="<?PHP echo $ope_telp ?>" size="20" maxlength="20"></td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_email"><div align="right">Email</div></td>
	  <td>
		<input name="email" type="text" id="email" value="<?PHP echo $ope_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") {
			if ($ope_email <> "")
			{ ?>
			<a href="mailto:<?PHP echo $ope_email ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border="0" align="absmiddle"></a>
		<?PHP } } ?>
	</td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_nota"><div align="right">Notes</div></td>
      <td colspan="3"><textarea name="nota" cols="90" id="nota"><?PHP echo $ope_nota ?></textarea></td>
    </tr>
  </table>
  <p align="center">
    <?PHP if (($td == "edit") or ($td == "add")) 
	{
		if ($ope_out == TRUE)
		{
	?>
	    <input name="annul" type="button" id="annul" value="Retour Liste" onclick="javascript:; history.back();">
	<?PHP
		}
		else
		{
	?>
    <input name="RAZ" type="reset" id="RAZ" value="R&eacute;initialiser">
    <input name="submit" type="submit" id="submit" value="Enregistrer">
    <?PHP } 
	}
	?>
    <?PHP if ($td == "del") { ?>
    <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 <> "add") {?>
		<script type="text/javascript">
			Calendar.setup({
				inputField     :    "dconges",     // id of the input field
				ifFormat       :    "%d-%m-%Y",      // format of the input field
				button         :    "f_img_dconges",  // trigger for the calendar (button ID)
				align          :    "Ll",           // alignment (defaults to "Bl")
				singleClick    :    true
			});
			Calendar.setup({
				inputField     :    "fconges",     // id of the input field
				ifFormat       :    "%d-%m-%Y",      // format of the input field
				button         :    "f_img_fconges",  // trigger for the calendar (button ID)
				align          :    "Ll",           // alignment (defaults to "Bl")
				singleClick    :    true
			});
		</script>
<?PHP } ?>
<p>
<?PHP if ($td == "del") 
{
?>
	<script>
	warndelope();
	</script>
<?PHP
}
?>
<?PHP } ?>
<!-- Fin affichage uniquement si numéro de département saisi -->
<!-- Fin affiché uniquement s'il y a au moins une catégorie agence et au moins une civilité -->
<?PHP
}
else
{
	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
	}
}
?>
<?php 
	include_once ("pied.php")
?>
