<?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/fic_age.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_pw.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_tec.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("geoip.inc.php");
Archivelog(@$_SESSION["code_log"]);

$td = strip_tags(trim($_GET['td']));
$tl = strip_tags(trim($_GET['tl']));
$coderech = strip_tags(trim($_GET['code']));
$tec_dep = strip_tags(trim($_GET['dep']));

$nbinterventions = 0;
$pbm_tec = FALSE;

$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";

if (($tl<1) OR ($tl>3))
	$pbm_tec=TRUE;
	
if (@$_SESSION["niv_log"] == 4)
	$tl=1;

if (@$_SESSION["niv_log"] == 6)
	$tl=2;

if (@$_SESSION["niv_log"] == 10)
	$tl=3;

if ($coderech <> "")
{
	// Vérification qu'il existe bien des interventions et nombre de celles-ci
	$nbinterventions = nb_int_tec($coderech);

	// Récupération des informations technicien
	$row = lit_enr_tec($coderech);
	if (is_array($row))
	{
		extract ($row);

		if (@$_SESSION["niv_log"] == 4)
		{
			if ($tec_codeage<>$_SESSION["code_age"])
				$pbm_tec=TRUE;
		}

		if (@$_SESSION["niv_log"] == 6)
		{
			if ($tec_codedo<>$_SESSION["code_do"])
				$pbm_tec=TRUE;
		}

		if (@$_SESSION["niv_log"] == 10)
		{
			if ($tec_codest<>$_SESSION["code_st"])
				$pbm_tec=TRUE;
		}

		if ($pbm_tec==FALSE)
		{
			$tec_datecreaf = formatedate($tec_datecrea);
			$tec_congdf = formatedate($tec_congd);
			$tec_congff = formatedate($tec_congf);
			$tec_dateoutf = formatedate($tec_dateout);
			
			if (($tec_out==TRUE) AND ($td<>"del"))
				$td="view";
		}
	}
	else
		$pbm_tec=TRUE;
}
else
{
	if ($td == "add")
	{
		if (@$_SESSION["niv_log"] == 4)
			$tec_codeage = (@$_SESSION["code_log"]);
		if (@$_SESSION["niv_log"] == 6)
			$tec_codedo = (@$_SESSION["code_do"]);
		if (@$_SESSION["niv_log"] == 10)
			$tec_codest = (@$_SESSION["code_st"]);
		$tec_codepays = pays_connect_code($_SERVER['REMOTE_ADDR']);
		$tec_out=FALSE;
	}
	else
		$pbm_tec=TRUE;
}

switch ($td)
{
	case "add" :
		$titre = "CREATION COMPTE TECHNICIEN";
		break;
	case "edit" :
		$titre = "MISE A JOUR COMPTE TECHNICIEN";
		break;
	case "del" :
		$titre = "SUPPRESSION COMPTE TECHNICIEN";
		break;
	case "view" :
		$titre = "VISUALISATION COMPTE TECHNICIEN";
		break;
	default :
		$pbm_tec=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 : Fiche Technicien</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>

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

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

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

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscript/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="../jscript/jscal/calendar-setup.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(
<?PHP
	if (@$_SESSION["niv_log"] <> 4)
	{
		if ($tec_out == FALSE) 
		{
?>
	"nom:empl ; format:liste ; req:Y ; txt:Employeur ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
		}
		else
		{
?>
	"nom:empl ; format:txt ; req:Y ; txt:Employeur ; stok:frmok ; stbad:frmbad",
<?PHP
		}
	}
	else
	{
?>
	"nom:empl ; format:txt ; req:Y ; txt:Employeur ; stok:frmok ; stbad:frmbad",
<?PHP
	}
?>
	"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 ; 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:telp ; format:telp ; req:Y ; txt:Téléphone portable ; stok:frmok ; stbad:frmbad",
	"nom:email ; format:mail ; req:Y ; txt:Email ; stok:frmok ; stbad:frmbad",
	"nom:mess ; format:mail ; req:N ; txt:Mesagerie ; stok:frmok ; stbad:frmbad",
	"nom:nota ; format:txt ; req:N ; txt:Notes ; stok:frmok ; stbad:frmbad");
</script>

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/verif_form.js"></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_tec==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 } ?>

<?PHP if ($td == "del"){ ?>
<body onLoad="warndeltec();metReadonly();">
<?PHP } 
if ($td == "view"){ ?>
<body onLoad="metReadonly();">
<?PHP } 
if (($td == "add") OR ($td == "edit")) { ?>
<body onLoad="metFocus();updateDep(document.tec_maj.pays.value);updateVille(document.tec_maj.dep.value);">
<?PHP 
}
include_once("entete.inc.php");
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center"><span class="annot_std_it">
<?PHP 
switch ($tl)
{
	case 1 :
		echo "(Agence)";
		break;
	case 2 :
		echo "(Donneur d'ordres)";
		break;
	case 3 :
		echo "(Sous-traitant)";
		break;
	default :
		break;
}
?>
</span></p>
<?PHP
if ($pbm_tec == FALSE)
{
if (nb_civ() <> 0)
{
?>
<!-- Affiché uniquement s'il y a au moins une civilité -->
<table width="100%"  border="0">
<tr>
	<td width="33%"><strong><em><a href="tec_lst.php?td=<?PHP echo $tl; ?>">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 align="right">
	<?PHP
	if ($td == "edit")
	{
		$urlimp = "tec_maji.php?code=".$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="31%">&nbsp;</td>
	<td width="39%" valign="top">
		<div id="oblig" align="center" class="annot_gras_it">
		(<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"> : Saisie obligatoire)
		</div>
	</td>
	<td width="30%" align="right">
	<?PHP
	if (($td == "edit") AND ($nbinterventions <> 0))
	{
		$url_inter = "int_lst.php?ord=DES&tri=Code&search=".$tec_code."&rech=Rechercher";
	?>
		<a href="javascript:;" onclick="self.location.href=('<?PHP echo $url_inter; ?>');")> Voir ses interventions (<?PHP echo sprintf ("%'03s",$nbinterventions);?>)</a>
	<?PHP
	}
	else 
		echo "&nbsp;";
	?>
	</td>
</tr>
</table>
</div>
<form name="tec_maj" method="post" action="tec_enr.php" onSubmit="javascript:; return (verif_tec(this,tab1_champ,document.tec_maj.pays.value,''));">
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="tl" type="hidden" id="tl" value="<?PHP echo $tl ?>">
<?PHP if ($td == "add") { ?>
<input name="code" type="hidden" id="code" value="<?PHP echo $tec_code ?>">
<input name="salarie" type="hidden" id="salarie" value="Oui">
<?PHP }
if ($td <> "add") {?>
<table width="100%"  border="0">
<tr>
	<td width="20%" class="rubfrm" id="f_codetec"><div align="right">Code Technicien</div></td>
	<td><input name="code" type="text" id="code" value="<?PHP echo $tec_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") OR ($td=="view"))
	{ 
		if ($tec_out == FALSE)
		{
	?>
		<select name="salarie" size="1" id="salarie">
		<option value="Oui" selected>Oui</option>
		<option value="Non">Non</option>
		</select> 
		<span class="annot_std_it">
	<?PHP
		echo "  (Embauche le : ".$tec_datecreaf.")";
		echo "</span>";
		}
		else
		{
	?>
	    <input name="salarie" type="text" id="salarie" value="Non" size="3"  style="background : red; color : yellow; font-weight:bold;" readonly="1">
		<span class="annot_std_it">
	<?PHP
		echo "  (Embauche le : ".$tec_datecreaf.", départ le : ".$tec_dateoutf.")";
		echo "</span>";
		}
	}
	?>			
	<br>
	<span class="annot_petit_it">(Si vous passez en 'Non', le technicien sera consid&eacute;r&eacute; comme licenci&eacute;</span>
	</td>
</tr>
</table>
<?PHP 
}
?>
<table width="100%"  border="0">
<?PHP
if (($td <> "add") AND ($td<>"view"))
{
?>
<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 $tec_congdf; ?>" size="10"  readonly="1">
		<img src="../img/calendar.png" id="f_img_dconges" title="Choisir votre date" width="16" height="16">
		<span class="annot_petit_gras"> au </span>
		<input name="fconges" type="text" id="fconges" value="<?PHP echo $tec_congff; ?>" size="10"  readonly="1">
		<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.tec_maj.dconges.value='';document.tec_maj.fconges.value='';"><img src="../img/raz.gif" width="12" height="12" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="document.tec_maj.dconges.value='';document.tec_maj.fconges.value='';")> Annuler)</a></span>
	</td>
</tr>
<?PHP
}
?>
<tr>
<td width="20%" class="rubfrm" id="f_agence"><div align="right">
<?PHP
	switch ($tl)
	{
		case 1 :
			echo "Agence";
			break;
		case 2 :
			echo "Donneur d'ordres";
			break;
		case 3 :
			echo "Sous-traitant";
			break;
		default :
			break;
	}
?>
</div></td>
<td width="83%" colspan="3">
<?PHP
if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 6) AND (@$_SESSION["niv_log"] <> 10))
{
	if ($tec_out == FALSE) 
	{
	?>
	<select name="empl" size="1" id="empl">
	<?PHP
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	switch ($tl)
	{
		// Création de la liste des agences
		case 1 :
			echo "<option>-- Choisissez une agence --</option>";
			$rech="SELECT * FROM ".TBAGE.", ".TBPW." WHERE ".TBAGE.".age_code=".TBPW.".pw_code AND ".TBPW.".pw_actif='1' ORDER BY age_code";
			$rs = mysql_query($rech) or die(mysql_error());
			
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				
				if ($tec_codeage == $age_code)
				{
					echo '<option value="'.$age_code.'" selected>'.$age_nom." (Agence ".$age_code.")".'</option>';
				}
				else
				{
					echo '<option value="'.$age_code.'">'.$age_nom." (Agence ".$age_code.")".'</option>';
				}
			}
			break;
			
		// Création de la liste des donneurs d'ordres
		case 2 :
			echo "<option>-- Choisissez un donneur d'ordres --</option>";
			$rech="SELECT * FROM ".TBDO.", ".TBPW." WHERE ".TBDO.".do_code=".TBPW.".pw_code AND ".TBPW.".pw_actif='1' ORDER BY do_code";
			$rs = mysql_query($rech) or die(mysql_error());
			
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				
				if ($tec_codedo == $do_code)
				{
					echo '<option value="'.$do_code.'" selected>'.$do_nom." (Donneur d'ordres ".$do_code.")".'</option>';
				}
				else
				{
					echo '<option value="'.$do_code.'">'.$do_nom." (Donneur d'ordres ".$do_code.")".'</option>';
				}
			}
			break;

		// Création de la liste des sous-traitants
		case 3 :
			echo "<option>-- Choisissez un sous-traitant --</option>";
			$rech="SELECT * FROM ".TBST.", ".TBPW." WHERE ".TBST.".st_code=".TBPW.".pw_code AND ".TBPW.".pw_actif='1' ORDER BY st_code";
			$rs = mysql_query($rech) or die(mysql_error());
			
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				
				if ($tec_codest == $st_code)
				{
					echo '<option value="'.$st_code.'" selected>'.$st_nom." (Sous-traitant ".$st_code.")".'</option>';
				}
				else
				{
					echo '<option value="'.$st_code.'">'.$st_nom." (Sous-traitant ".$st_code.")".'</option>';
				}
			}
			break;
		default :
			break;
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	</select>
	<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	<?PHP 
	} 
	else  // Technicien licencié = zone non modifiable (affichage seul)
	{
	if ((@$_SESSION["niv_log"] == 4) OR ($tec_codeage<>""))
	{
		$row = lit_enr_age($tec_codeage);
		if (is_array($row))
			extract ($row);
		$empl=$tec_codeage;
	}
	if ((@$_SESSION["niv_log"] == 6) OR ($tec_codedo<>""))
	{
		$row = lit_enr_do($tec_codedo);
		if (is_array($row))
			extract ($row);
		$empl=$tec_codedo;
	}
	if ((@$_SESSION["niv_log"] == 10) OR ($tec_codest<>""))
	{
		$row = lit_enr_st($tec_codest);
		if (is_array($row))
			extract ($row);
		$empl=$tec_codest;
	}
	?>
	<input name="empl" type="hidden" id="empl" value="<?PHP echo $empl; ?>">
	<?PHP if ((@$_SESSION["niv_log"] == 4) OR ($tec_codeage<>"")) { ?>
	<input name="nagence" type="text" id="nagence" value="<?PHP echo $age_nom; ?>" readonly="1"> (Agence)
	<?PHP }
		if ((@$_SESSION["niv_log"] == 6) OR ($tec_codedo<>"")) { ?>
	<input name="ndo" type="text" id="ndo" value="<?PHP echo $do_nom; ?>" readonly="1"> (Donneur d'ordres)
	<?PHP }
		if ((@$_SESSION["niv_log"] == 10) OR ($tec_codest<>"")) { ?>
	<input name="nst" type="text" id="nst" value="<?PHP echo $st_nom; ?>" readonly="1"> (Sous-traitant)
	<?PHP }
	}
}
else
{
	if ((@$_SESSION["niv_log"] == 4) OR ($tec_codeage<>""))
	{
		$row = lit_enr_age($tec_codeage);
		if (is_array($row))
			extract ($row);
		$empl=$tec_codeage;
	}
	if ((@$_SESSION["niv_log"] == 6) OR ($tec_codedo<>""))
	{
		$row = lit_enr_do($tec_codedo);
		if (is_array($row))
			extract ($row);
		$empl=$tec_codedo;
	}
	if ((@$_SESSION["niv_log"] == 10) OR ($tec_codest<>""))
	{
		$row = lit_enr_st($tec_codest);
		if (is_array($row))
			extract ($row);
		$empl=$tec_codest;
	}
?>
	<input name="empl" type="hidden" id="empl" value="<?PHP echo $empl; ?>">
	<?PHP if (@$_SESSION["niv_log"] == 4) { ?>
	<input name="nagence" type="text" id="nagence" value="<?PHP echo $age_nom; ?>" readonly="1">
	<?PHP }
		if (@$_SESSION["niv_log"] == 6) { ?>
	<input name="ndo" type="text" id="ndo" value="<?PHP echo $do_nom; ?>" readonly="1">
<?PHP }
		if (@$_SESSION["niv_log"] == 10) { ?>
	<input name="nst" type="text" id="nst" value="<?PHP echo $st_nom; ?>" readonly="1">
<?PHP }
}
?>
</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_civil"><div align="right">Civilit&eacute;</div></td>
	<td>
	<?PHP if ($tec_out == FALSE) 
	{
	?>
	<select name="civil" size="1" id="civil">
	<?PHP
	// 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");
	
	echo "<option value=\"\"";
	if ($tec_civilite == "")
		echo " selected";
	echo ">-- Choisissez une civilité --</option>";

	while ($resultat = mysql_fetch_array($rs)) 
	{
		extract($resultat);
	
		echo "<option value=\"".$civ_code."\"";
		if ($tec_civilite == $civ_code)
			echo " selected";
		echo ">".$civ_desc."</option>";
	}
	mysql_free_result($rs);
	mysql_close($conn);
	?>
	</select>
	  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	<?PHP 
	} 
	else  // Licencié = zone non modifiable (affichage seul)
	{
		$row = lit_enr_civ($tec_civilite);
		extract($row);
	?>
	<input name="civil" type="hidden" id="civil" value="<?PHP echo $civ_code ?>" size="5" >
	<input name="civilite" type="text" id="civilite" value="<?PHP echo $civ_desc ?>" size="50"  readonly="1">
	<?PHP 
	} 
	?>
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_prenom"><div align="right">Pr&eacute;nom</div></td>
	<td>
	<?PHP if ($tec_out == FALSE) 
	{
	?>
	<input name="prenom" type="text" id="prenom" value="<?PHP echo htmlspecialchars($tec_prenom) ?>" size="50"  onChange="javascript:this.value=ucWords(this.value,true);">
	 <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	<?PHP
	}
	else
	{
	?>
	<input name="prenom" type="text" id="prenom" value="<?PHP echo htmlspecialchars($tec_prenom) ?>" size="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_nom"><div align="right">Nom</div></td>
	<td>
	<?PHP if ($tec_out == FALSE) 
	{
	?>
	<input name="nom" type="text" id="nom" value="<?PHP echo htmlspecialchars($tec_nom) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
	  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	<?PHP
	}
	else
	{
	?>
	<input name="nom" type="text" id="nom" value="<?PHP echo htmlspecialchars($tec_nom) ?>" size="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_adr1"><div align="right">Adresse(1)</div></td>
	<td>
	<?PHP if ($tec_out == FALSE) 
	{
	?>
	<input name="adr1" type="text" id="adr1" value="<?PHP echo htmlspecialchars($tec_adr1) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
	  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	<?PHP
	}
	else
	{
	?>
	<input name="adr1" type="text" id="adr1" value="<?PHP echo htmlspecialchars($tec_adr1) ?>" size="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_adr2"><div align="right">Adresse(2)</div></td>
	<td>
	<?PHP if ($tec_out == FALSE) 
	{
	?>
	<input name="adr2" type="text" id="adr2" value="<?PHP echo htmlspecialchars($tec_adr2) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
	<?PHP
	}
	else
	{
	?>
	<input name="adr2" type="text" id="adr2" value="<?PHP echo htmlspecialchars($tec_adr2) ?>" size="50" readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_pays"><div align="right">Pays</div></td>
	<td>
	<?PHP
	if ($tec_out == FALSE) 
	{
		$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 ($tec_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);
	}
	else
	{
		$pays = Retournepays_open($tec_codepays,TRUE);
	?>
		<input name="pays" type="hidden" id="pays" value="<?PHP echo $tec_codepays ?>">
		<input name="pays_nom" type="text" id="pays_nom" value="<?PHP echo $pays ?>" size="50"  readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_dep"><div align="right">D&eacute;partement ou R&eacute;gion/Etat</div></td>
	<td>
	<?PHP
	if ($tec_out == FALSE) 
	{
		// 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`='".$tec_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 ($tec_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);
	}
	else
	{
		$dept=Retournedep_open($tec_dep,$tec_codepays,TRUE);
		if ($tec_dep<>$dept)
			$dep=$tec_dep." (".$dept.")";
		else
			$dep=$dept;
	?>
		<input name="dep" type="hidden" id="dep" value="<?PHP echo $tec_dep ?>">
		<input name="dep_nom" type="text" id="dep_nom" value="<?PHP echo $dep ?>" size="40"  readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_ville"><div align="right">Ville</div></td>
	<td>
	<?PHP
	if ($tec_out == FALSE) 
	{
		// Création de la liste des villes
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);

		$rech="";
		if ($tec_dep<>"")
		{
			if ($tec_dep<>"-1")
			{
				$filtre=$tec_dep;
				if (($filtre == "2A") OR ($filtre == "2B"))
					$filtre = "20";
				$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_dep` = '".str_majuscules($filtre)."' AND `villes_codepays`='".str_majuscules($tec_codepays)."' ORDER BY villes_nom";
			}
			else
			{
				$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_codepays`='".str_majuscules($tec_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 ($tec_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);
	}
	else
	{
		$ville = Retourneville_openId($tec_ville,TRUE);
	?>
		<input name="ville" type="hidden" id="ville" value="<?PHP echo $tec_ville ?>">
		<input name="ville_nom" type="text" id="ville_nom" value="<?PHP echo $ville ?>" size="40"  readonly="1">
	<?PHP
	}
	?>
	</td>
</tr>
<tr>
	<td width="20%" 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 $tec_telf ?>" size="20"  >
	  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</td>
</tr>
<tr>
	<td width="20%" 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 $tec_fax ?>" size="20" >
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_telp"><div align="right">Portable</div></td>
	<td>
	<input name="telp" type="text" id="telp" value="<?PHP echo $tec_telp ?>" size="20" >
	  <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</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 $tec_email ?>" size="50"  onChange="javascript:this.value=this.value.toLowerCase();">
	<?PHP if ($td == "edit") { ?>
	<a href="mailto:<?PHP echo $tec_email ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="absmiddle"></a>
	<?PHP } ?>
	<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_mess"><div align="right">Messagerie</div></td>
	<td>
	<input name="mess" type="text" id="mess" value="<?PHP echo $tec_mess ?>" size="50"  onChange="javascript:this.value=this.value.toLowerCase();">
	</td>
</tr>
<tr>
	<td width="20%" class="rubfrm" id="f_nota"><div align="right">Notes</div></td>
	<td>
	<textarea name="nota" cols="90" rows="5" id="nota"><?PHP echo htmlspecialchars($tec_nota) ?></textarea>
	</td>
</tr>
</table>
<?PHP if ($tec_out == FALSE) 
{
?>
<p align="center">
<?PHP if (($td == "edit") or ($td == "add")) { ?>
<input name="RAZ" type="reset" class="bton_fmarr_std" id="RAZ" value="R&eacute;initialiser">
<input name="submit" type="submit" class="bton_fmarr_std" id="submit" value="Enregistrer">
<?PHP } if ($td == "del") { ?>
<input name="del" type="submit" class="bton_fmarr_std" id="del" value="Supprimer">
<input name="annul" type="button" class="bton_fmarr_std" id="annul" value="Annuler" onclick="javascript:; history.back();">
<?PHP } ?>
</p>
<?PHP 
} 
?>
</form>
	<?PHP 
	if ($td == "edit")
	{
	?>
	<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")
			electric	   :	false,
			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")
			electric	   :	false,
			singleClick    :    true
		});
	</script>
<?PHP 
	}

	if ($td == "add") 
	{
?>
	<script type="text/javascript">
	warnnbage(<?PHP echo nb_age_actives(); ?>,"tec");
	</script>
<?PHP
	}
?>
<!-- Fin affiché uniquement s'il y a au moins une une civilité -->
<?PHP
}
else
{
?>
	<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=('tec_lst.php?td=<?PHP echo $tl; ?>');",2000)
	</script>
	<p align="center" class="annot_std_it">Probl&egrave;me sur les param&egrave;tres...</p>
<?PHP 
}
include_once("pied.php");
?>
