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

Version 0.9.9

Copyright (C) 2006-2009  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/fic_ret.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

// Variables Formulaire
$titre = stripslashes(strip_tags(trim(@$_POST["titre"])));
$td = strip_tags(trim(@$_POST["td"]));
$tx = strip_tags(trim(@$_POST["tx"]));

$id = intval(strip_tags(str_escape(trim(@$_POST["nville"]))));
$pays= str_majuscules(strip_tags(str_escape(trim(@$_POST["codepays"]))));
$dep= str_majuscules(strip_tags(str_escape(trim(@$_POST["dep"]))));
$cp = strip_tags(trim(@$_POST["cp"]));
$nom = str_majuscules(strip_tags(str_escape(trim(@$_POST["nom"]))));
$lng= str_majuscules(strip_tags(str_escape(trim(@$_POST["lng"]))));

$retourliste = TRUE;

$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);
switch ($td)
{
	// Ajout de la fiche Ville
	case "add" :
		$rech = "SELECT * FROM " .TBVILLES. " WHERE `villes_cp` = '$code' AND `villes_nom` = '$nom'";
		$rech.= " AND `villes_dep` = '$dep' AND `villes_codepays` = '$pays' AND `villes_lng` = '$lng'";
		$rs = mysql_query($rech) or die(mysql_error());
		if (mysql_num_rows($rs) == 0)
		{
			$rs = mysql_query("INSERT INTO " .TBVILLES. "(villes_cp,villes_nom,villes_dep,villes_codepays,villes_lng) VALUES ('$cp','$nom','$dep','$pays','$lng')") or die(mysql_error());
			$msg = $txt_fiche_add;
		}
		else
		{
			$msg = $txt_fiche_exist;
			$retourliste = FALSE;
		}
		break;
		
	// Modification de la fiche Ville
	case "edit" :
		$rech = "SELECT * FROM " .TBVILLES. " WHERE `villes_id` = ".$id."";
		$rs = mysql_query($rech) or die(mysql_error());
		if (mysql_num_rows($rs) == 1)
		{
			$rech = "UPDATE `" .TBVILLES. "` SET `villes_cp`='".$cp."', ` SET `villes_nom`='".$nom."', ` SET `villes_dep`='".$dep."',";
			$rech.= " `villes_codepays`='".$pays."', `villes_lng`='".$lng."' WHERE `villes_id` = '".$id."'";
			$rs = mysql_query($rech) or die(mysql_error());
			$msg = $txt_fiche_mod;
		}
		else
		{
			$msg = $txt_fiche_modnotok;
			$retourliste = FALSE;
		}
		break;

	// Suppression de la fiche Département
	case "del" :
		if (ville_used($id,FALSE)==TRUE)
		{
			$msg = $txt_ville_used;
			$retourliste = FALSE;
		}
		else
		{
			$rech = "SELECT * FROM " .TBVILLES. " WHERE `villes_id` = ".$id."";
			$rs = mysql_query($rech) or die(mysql_error());
			if (mysql_num_rows($rs) == 1)
			{
				// Non - > suppression de la fiche Département
				$rech = "DELETE FROM `" .TBVILLES. "` WHERE `villes_id` = ".$id;
				$rs = mysql_query($rech) or die(mysql_error());
				$msg = $txt_fiche_del;
			}
			else
			{
				$msg = $txt_fiche_delnotok;
				$retourliste = FALSE;
			}
		}
		break;
}
mysql_close($conn);
?>
<!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 - <?PHP echo $title_esp_prive; ?> : Fiche Ville</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>

</head>
<body>
<?PHP
if ($tx<>"f")
	include_once("../inc/entete.inc.php"); 
?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">&nbsp;</p>
<p align="center">
<?PHP if ($retourliste==FALSE)
	echo '<span class="alerte1">';
else
	echo '<span class="annot_std_gras">';
?>
<?PHP echo $msg ?>
</span>
</p>

<?PHP 
if ($tx<>"f")
{
	if ($retourliste == FALSE)
		aff_ret_idx_man($td,"villes_lst.php",$txt_lnk_ret_liste,TRUE);
	else
		aff_ret_lst_auto("villes_lst.php",2000);
} else {
	cre_js_dep("window.opener.");
?>
	<script type="text/javascript">
	<!--
	updatdep();
	self.close('fscomp');
	//-->
	</script>
<?PHP
}
if ($tx<>"f")
	include_once("pied.php")
?>