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

session_start(); 
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 = 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;

$retourliste = TRUE;

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

switch ($td)
{
	// Ajout de la fiche type de demande
	case "add" :
		$rech = "SELECT * FROM " .TBDDET. " WHERE `ddet_code` = '$code'";
		$rs = mysql_query($rech) or die(mysql_error());
		if (mysql_num_rows($rs) == 0)
		{
			$rech = "INSERT INTO " .TBDDET. " (ddet_code,ddet_desc,ddet_pub,ddet_cli,ddet_age,ddet_tec,ddet_ope,ddet_cge,ddet_stt,ddet_st,ddet_dot,ddet_do,ddet_delok)";
			$rech.= " VALUES ('$code','$desc','$pub','$cli','$age','$tec','$ope','$cge','$stt','$st','$dot','$do','1')";
			$rs = mysql_query($rech) or die(mysql_error());
			$msg = "Fiche ajoutée";			
		}
		else
		{
			$msg = "Ce code existe déjà !";
			$retourliste = FALSE;
		}
		mysql_close($conn);
		break;
		
	// MAJ de la fiche Type de demande
	case "edit" :
		$rech = "UPDATE `" .TBDDET. "` SET `ddet_code`='".$code."', `ddet_desc`='".$desc."', `ddet_pub`='".$pub."',";
		$rech.= "  `ddet_cli`='".$cli."', `ddet_age`='".$age."',";
		$rech.= " `ddet_tec`='".$tec."', `ddet_ope`='".$ope."', `ddet_cge`='".$cge."',";
		$rech.= " `ddet_stt`='".$stt."', `ddet_st`='".$st."', `ddet_dot`='".$dot."', `ddet_do`='".$do."'";
		$rech.= " WHERE `ddet_code` = '".$code."'";
		$rs = mysql_query($rech) or die(mysql_error());
		mysql_close($conn);

		$msg = "Fiche modifiée";
		break;
		
	// Suppression de la fiche type de demande
	case "del" :
		mysql_close($conn);
		
		// Vérifie si utilisé dans une demande
		if (exist_ddet_in_dde($code) == TRUE)
		{
			$msg = "Ce type de demande a déjà été utilisé dans une demande.";
			$retourliste = FALSE;
		}
		else		
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);

			// SUPPRESSION de la fiche type de demande
			$rech = "DELETE FROM `" .TBDDET. "` WHERE `ddet_code` = '$code'";
			$rs = mysql_query($rech) or die(mysql_error());
			mysql_close($conn);

			$msg = "Fiche supprimée";			
		}
		break;

	default :
		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 Type de Demande</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" class="annot_gras_it"><?PHP echo $msg ?></p>
<?PHP if ($retourliste == FALSE) { ?>
	<table width="100%"  border="0">
	  <tr>
		<td width="3%">&nbsp;</td>
		<td width="44%"><div align="right"><a href="ddet_lst.php"><img src="../img/liste.gif" width="33" height="34" border="0" align="absmiddle"></a> <a href="ddet_lst.php" class="annot_gras_it">Retour &agrave; la liste</a></div></td>
		<td width="7%">&nbsp;</td>
		<td width="43%"><a href="index.php"><em><img src="../img/index.gif" width="48" height="48" border="0" align="absmiddle"> </em><span class="annot_gras_it">Revenir &agrave; l'accueil</span> </a></td>
		<td width="3%">&nbsp;</td>
	  </tr>
	</table>
<?PHP } else { ?>
	<script type="text/javascript">
	window.setTimeout("location=('ddet_lst.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Retour à la liste dans 2 secondes...</p>
<?PHP }
include_once("pied.php")
?>

