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

session_start(); 
if (!isset($_SESSION["lng"])) $_SESSION["lng"]="fr";
include_once("../lng/".$_SESSION["lng"].".inc.php"); // Paramètres de language
include_once("../inc/config.inc.php");
include_once("../inc/func_log.inc.php");
if (CheckURLLog(TRUE)==FALSE) header("Location: ../index.php");
if (CheckNivLog("5-9")==FALSE) header("Location: ../index.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/fic_dde.inc.php");

Archivelog(@$_SESSION["code_log"]);

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

$code = str_majuscules(strip_tags(trim(@$_POST["code"])));
$desc = str_majuscules(strip_tags(str_escape(trim(@$_POST["desc"]))));

$publique = strip_tags(trim(@$_POST["pub"]));
if ($publique == "Oui")
	$pub = 1;
else
	$pub = 0;
$client = strip_tags(trim(@$_POST["client"]));
if ($client == "Oui")
	$cli = 1;
else
	$cli = 0;
$age = strip_tags(trim(@$_POST["age"]));
if ($age == "Oui")
	$age = 1;
else
	$age = 0;
$tec = strip_tags(trim(@$_POST["tec"]));
if ($tec == "Oui")
	$tec = 1;
else
	$tec = 0;
$ope = strip_tags(trim(@$_POST["ope"]));
if ($ope == "Oui")
	$ope = 1;
else
	$ope = 0;
$cge = strip_tags(trim(@$_POST["cge"]));
if ($cge == "Oui")
	$cge = 1;
else
	$cge = 0;
$stt = strip_tags(trim(@$_POST["stt"]));
if ($stt == "Oui")
	$stt = 1;
else
	$stt = 0;
$st = strip_tags(trim(@$_POST["st"]));
if ($st == "Oui")
	$st = 1;
else
	$st = 0;
$dot = strip_tags(trim(@$_POST["dot"]));
if ($dot == "Oui")
	$dot = 1;
else
	$dot = 0;
$do = strip_tags(trim(@$_POST["do"]));
if ($do == "Oui")
	$do = 1;
else
	$do = 0;

$email = strtolower(strip_tags(trim(@$_POST["email"])));

$retourliste = TRUE;

$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);

switch ($td)
{
	// Ajout de la fiche destinataire de demande
	case "add" :
		$rech = "SELECT * FROM " .TBDDED. " WHERE `dded_code` = '$code'";
		$rs = mysql_query($rech) or die(mysql_error());
		if (mysql_num_rows($rs) == 0)
		{
			$rech = "INSERT INTO " .TBDDED. " (dded_code,dded_desc,dded_pub,dded_cli,dded_age,dded_tec,dded_ope,dded_cge,dded_stt,dded_st,dded_dot,dded_do,dded_email,dded_delok)";
			$rech.= " VALUES ('$code','$desc','$pub','$cli','$age','$tec','$ope','$cge','$stt','$st','$dot','$do','$email','1')";
			$rs = mysql_query($rech) or die(mysql_error());
			$msg = $txt_fiche_add;			
		}
		else
		{
			$msg = $txt_fiche_exist;
			$retourliste = FALSE;
		}
		mysql_close($conn);
		break;
		
	// MAJ de la fiche destinataire de demande
	case "edit" :
		if ($code <> "VA")
		{
			$rech = "UPDATE `" .TBDDED. "` SET `dded_code`='".$code."', `dded_desc`='".$desc."', `dded_pub`='".$pub."',";
			$rech.= "  `dded_cli`='".$cli."', `dded_age`='".$age."',";
			$rech.= " `dded_tec`='".$tec."', `dded_ope`='".$ope."', `dded_cge`='".$cge."',";
			$rech.= " `dded_stt`='".$stt."', `dded_st`='".$st."', `dded_dot`='".$dot."', `dded_do`='".$do."',";
			$rech.=" `dded_email`='".$email."' WHERE `dded_code` = '".$code."'";
			$rs = mysql_query($rech) or die(mysql_error());
			mysql_close($conn);

			$msg = $txt_fiche_mod;
		}
		else
		{
			$msg = $txt_fiche_modnotok;
			$retourliste = FALSE;
		}
		break;
		
	// Suppression de la fiche destinataire de demande
	case "del" :
		if ($code <> "VA")
		{
			mysql_close($conn);

			// Vérifie si utilisé dans une demande
			if (exist_dded_in_dde($code) == TRUE)
			{
				$msg = $txt_dded_used_dde;
				$retourliste = FALSE;
			}
			else
			{
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
	
				// SUPPRESSION de la fiche destinataire de demande
				$rech = "DELETE FROM `" .TBDDED. "` WHERE `dded_code` = '$code'";
				$rs = mysql_query($rech) or die(mysql_error());
				mysql_close($conn);

				$msg = $txt_fiche_del;			
			}
		}
		else
		{
			$msg = $txt_fiche_delnotok;
			$retourliste = FALSE;
		}

	default :
		break;
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - <?PHP echo $title_esp_prive; ?> : <?PHP echo $title_dded_maj; ?></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 
	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 ($retourliste == FALSE)
	aff_ret_idx_man($td,"dded_lst.php",$txt_lnk_ret_liste,TRUE);
else
	aff_ret_lst_auto("dded_lst.php",2000);
include_once("pied.php");
?>
