<?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("fic_hum.inc.php");
include_once("fic_mque.inc.php");
include_once("func.inc.php");
include_once("func_geo.inc.php");
include_once("func_geol.inc.php");
include_once("func_txt.inc.php");
include_once("geoip.inc.php");
Archivelog(@$_SESSION["code_log"]);

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

$pbm_rlpm=FALSE;

if (@$_SESSION["niv_log"]<3)
	$pbm_rlpm=TRUE;

$msg1_err_type="Aucun département, région, ou état pour ce pays";
$msg2_err_type="Aucune ville dans ce département, région, ou état";
$mquen_nota="";
$codeuser=@$_SESSION["code_log"];
if (@$_SESSION["niv_log"]==3)
	$codeuser=@$_SESSION["code_age"];

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

	// Vérification qu'il existe bien des contacts et nombre de ceux-ci
	$nbliens = nb_wmque_in_mque($coderech);

	$row = lit_enr_mque($coderech);
	if (is_array($row))
	{
		extract ($row);
		$row=lit_enr_MqueNPriv($coderech,$codeuser);
		if (is_array($row))
			extract ($row);
	}
	else
		$pbm_rlpm=TRUE;
}
else
{
	if ($td == "add")
	{
		$mque_code = "";
		$mque_ste = "";
		$mque_codepays=pays_connect_code($_SERVER['REMOTE_ADDR']);
	}
	else
		$pbm_rlpm=TRUE;
}
switch ($td)
{
	case "add" :
		$titre = "AJOUT CONSTRUCTEUR/EDITEUR";
		break;
	case "edit" :
		$titre = "MODIFICATION CONSTRUCTEUR/EDITEUR";
		break;
	case "del" :
		$titre = "SUPPRESSION CONSTRUCTEUR/EDITEUR";
		break;
	default :
		$pbm_rlpm=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 : Relev&eacute;s - Fiche Constructeur/Editeur</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>

<!-- 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:type; format:liste ; req:Y ; txt:Type ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:code ; format:alphanum ; req:Y ; txt:Code ; lmx:20 ; stok:frmok ; stbad:frmbad",
	"nom:ste; 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:dep ; format:liste ; req:N ; txt:Département ou Région/Etat; 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",
<?PHP if (@$_SESSION["niv_log"] >= 5)
{ 
?>
	"nom:notaa ; format:txt ; req:N ; txt:Notes administration; stok:frmok ; stbad:frmbad",
<?PHP
}
if (@$_SESSION["niv_log"] >= 3)
{ 
?>
	"nom:notat ; format:txt ; req:N ; txt:Notes techniques; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:fax ; format:tel ; req:N ; txt:Télécopieur; stok:frmok ; stbad:frmbad");
</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_rlpm==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);
				anciencodepays = codepays;
			}
		}
		else
		{
			// Remettre la liste a vide et annuler l'appel eventuel
			depUpdater.reset();
			anciencodepays = "";
		}
	}
}
</script>
<?PHP } ?>

</head>

<?PHP if ($td == "del"){ ?>
<body onload="warndel();metReadonly();">
<?PHP } else { ?>
<body onLoad="metFocus();updateDep(document.mque_maj.pays.value);updateVille(document.mque_maj.dep.value);">
<?PHP }
include_once("entete.inc.php"); 

if ($pbm_rlpm==FALSE)
{
	if (nb_civ() <> 0)
	{
?>

<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<table width="100%"  border="0">
  <tr>
    <td width="33%"><strong><em><a href="../admin/mque_lst.php">Retour &agrave; la liste</a></em></strong></td>
    <td width="33%">&nbsp;
	
	 </td>
    <td width="33%"><div align="right"><strong><em></em> </strong></div></td>
  </tr>
</table>
<table width="100%"  border="0">
<tr>
	<td width="31%">
    <?PHP if ($td == "edit")
	{
		$url_crlpma = "cmque_maj.php?td=add&cm=".$mque_code;
	?>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_crlpma; ?>',950,560,'status=no,scrollbars=yes,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_crlpma; ?>',950,560,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Ajouter un contact </a>
	<?PHP
		if (nb_cmque_in_mque($mque_code) <> 0)
		{
			$url_crlpma = "cmque_maj.php?td=lst&cm=".$mque_code;
    ?>
		/
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_crlpma; ?>',950,560,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Edition contacts (<?PHP echo sprintf ("%'03s",$nbcontacts);?>)</a>
	<?PHP
		}
	}
	?>
	</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")
	{
		$url_wrlpma = "wmque_maj.php?td=add&cm=".$mque_code;
	?>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_wrlpma; ?>',950,560,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/webc.png" width="22" height="22" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_wrlpma; ?>',950,560,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Ajouter un lien </a>
	<?PHP
		if (nb_wmque_in_mque($mque_code) <> 0)
		{
			$url_wrlpma = "wmque_maj.php?td=lst&cm=".$mque_code;
    ?>
		/
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $url_wrlpma; ?>',950,560,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Edition liens (<?PHP echo sprintf ("%'03s",$nbliens);?>)</a>
	<?PHP
		}
	}
	?>
	</td>
</tr>
</table>
<br>
<form name="mque_maj" method="post" action="mque_enr.php" onSubmit="javascript:; return (VForm(this,tab1_champ,document.mque_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 ?>">
  <table width="100%"  border="0">
    <tr>
		<td class="rubfrm" id="f_type">Type</td>
	  <td>
			<select id="type" name="type">
			<option value="">--- Choisissez le type de ce contructeur/&eacute;diteur ---</option>
		<?PHP
			for ($i=0;$i<3;$i++)
			{
				echo "<option value=\"".$i."\"";
				if ($i==$mque_type)
					echo" selected=\"selected\"";
				echo ">".$mques_types[$i]."</option>";
			}
		?>
		</select>
	    <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
		  <br>
		  <span class="annot_petit_it">Le type du constructeur/&eacute;diteur permet de d&eacute;terminer s'il est sp&eacute;cifiquement d&eacute;di&eacute; aux licences, aux mat&eacute;riels, ou aux deux. </span></td>
    </tr>
    <tr>
      <td width="10%" class="rubfrm" id="f_code">Code</td>
	  <td width="47%">
      <?PHP if ($td == "add") { ?>
      <input name="code" type="text" id="code" value="<?PHP echo $mque_code ?>" size="20" maxlength="20">
          <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
      <?PHP } else { ?>
      <input name="code" type="text" id="code" value="<?PHP echo $mque_code ?>" size="20" maxlength="20" readonly="1">
      <?PHP } ?>
	  </td>
    </tr>
    <tr>
      <td class="rubfrm" id="f_desc">Nom</td>
      <td><input name="ste" type="text" id="ste" value="<?PHP echo htmlspecialchars($mque_ste) ?>" size="50">
          <img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire"></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 htmlspecialchars($mque_adr1) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
			<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
		</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 htmlspecialchars($mque_adr2) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
		</td>
	</tr>
	<tr>
		<td class="rubfrm" id="f_pays"><div align="right">Pays</div></td>
		<td>
		<?PHP
			$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 ($mque_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);
		?>		
		</td>
	</tr>
	<tr>
		<td class="rubfrm" id="f_dep"><div align="right">D&eacute;partement ou R&eacute;gion/Etat</div></td>
		<td>
		<?PHP
		// 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`='".$mque_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 ($mque_dep == $dep_code)
					echo "<option value=\"".$dep_code."\" selected>".$dep_code." (".$dep_nom.")</option>";
				else
					echo "<option value=\"".$dep_code."\">".$dep_code." (".$dep_nom.")</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);
		?>
		</td>
	</tr>
	<tr>
		<td class="rubfrm" id="f_ville"><div align="right">Ville</div></td>
		<td>
		<?PHP
		// Création de la liste des villes
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);

		$rech="";
		if ($mque_dep<>"")
		{
			if ($mque_dep<>"-1")
			{
				$filtre=$mque_dep;
				if (($filtre == "2A") OR ($filtre == "2B"))
					$filtre = "20";
				$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_cp` LIKE '".str_majuscules($filtre)."%' AND `villes_codepays`='".str_majuscules($mque_codepays)."' ORDER BY villes_nom";
			}
			else
			{
				$rech = "SELECT * FROM ".TBVILLES." WHERE `villes_codepays`='".str_majuscules($mque_codepays)."' ORDER BY villes_nom";
			}
		}
		if ($rech<>"")
			$rs = mysql_query($rech);
		?>
		<select name="ville" size="1" id="ville">
		<?PHP
		echo "<option>-- Choisissez une ville --</option>";

		if ($rech<>"")
		{
			if (mysql_num_rows($rs)>0)
			{
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($mque_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);
		?>
		</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 $mque_telf ?>" size="20" maxlength="20">
			<img src="../img/oblig.gif" width="10" height="11" alt="Champ obligatoire">
		</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 $mque_fax ?>" size="20" maxlength="20">
		</td>
	</tr>
	<?PHP if (@$_SESSION["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 htmlspecialchars($mque_notaa) ?></textarea>
		</td>
	</tr>
	<?PHP
	}
	?>
	<tr>
		<td height="37" class="rubfrm" id="f_notat"><div align="right">Notes publiques Agences<br><span class="annot_petit_it">(Saisies par l'administrateur ou<br>le centre de gestion)</span></div></td>
		<td>
			<textarea name="notat" cols="90" rows="5" id="notat" <?PHP if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4))	{ echo "readonly=\"readonly\""; } ?>><?PHP echo htmlspecialchars($mque_notat) ?></textarea>
		</td>
	</tr>
	<tr>
		<td height="37" class="rubfrm" id="f_notap">
		<div align="right">Notes Personnelles<br><span class="annot_petit_it">(Pour les techniciens ce sont<br>celles de leur agence)</span></div>
		</td>
		<td>
			<textarea name="notap" cols="90" rows="5" id="notap"><?PHP echo htmlspecialchars($mquen_nota) ?></textarea>
		</td>
	</tr>
  </table>
  <p align="center">
    <?PHP if (($td == "add") OR ($td == "edit")) { ?>
    <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 } ?>
    <?PHP if ($td == "del") { ?>
    <input name="del" type="submit" class="bton_fmarr_std" id="del" value="Supprimer">
    <?PHP } ?>
  </p>
</form>
<?PHP
	}
	else
	{
		if (@$_SESSION["niv_log"] >= 5)
		{
			if (nb_fonc() == 0)
			{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('fonc_lst.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins une fonction...</p>
<?PHP
			}
		}
		else
		{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('index.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Logiciel pas encore param&eacute;tr&eacute;<br>Merci de contacter l'administrateur...</p>
<?PHP
		}
	}
}
else
{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('mque_lst.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Probl&ecirc;me sur les param&egrave;tres...</p>
<?php 
}
include_once("../admin/pied.php")
?>
