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

Copyright (C) 2006  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
****************************************************************************************/

include ("../inc/config.inc.php");
?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	 	// Variables Formulaire + Contrôler action à effectuer
		if (strip_tags(trim(@$_POST["enr"])) == "Enregistrer")
			$typaction = "add";
		if (strip_tags(trim(@$_POST["mod"])) == "Modifier")
			$typaction = "edit";
		if (strip_tags(trim(@$_POST["del"])) == "Supprimer")
			$typaction = "del";

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

		$idccli = strip_tags(trim(@$_POST["idccli"]));
		$code = strip_tags(trim(@$_POST["code"]));
		$fonction = str_majuscules(strip_tags(trim(@$_POST["fonction"])));
		$civil = str_majuscules(strip_tags(trim(@$_POST["civil"])));
		$prenom = ucwords(strtolower(strip_tags(trim(@$_POST["prenom"]))));
		$nom = str_majuscules(strip_tags(trim(@$_POST["nom"])));
		$telf = strip_tags(trim(@$_POST["telf"]));
		$fax = strip_tags(trim(@$_POST["fax"]));
		$telp = strip_tags(trim(@$_POST["telp"]));
		$email = strtolower(strip_tags(trim(@$_POST["email"])));
		$mess = strtolower(strip_tags(trim(@$_POST["mess"])));
		$nota = strip_tags(trim(@$_POST["nota"]));
		$mailc = 0;
		if (strtolower(strip_tags(trim(@$_POST["cpta"]))) == "cpta")
			$mailc = 1;
		$maild = 0;
		if (strtolower(strip_tags(trim(@$_POST["dir"]))) == "dir")
			$maild = 1;
		$mailt = 0;
		if (strtolower(strip_tags(trim(@$_POST["tec"]))) == "tec")
			$mailt = 1;

		if ($typaction == "add")
		{

			// Ajout de la fiche Contact

			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "INSERT INTO " .TBCCLI;
			$rech .= " (ccli_datecrea,ccli_datemod,ccli_codecli,ccli_func,ccli_civilite,ccli_prenom,ccli_nom,ccli_telf,ccli_fax,ccli_telp,ccli_email,ccli_mess,ccli_nota,ccli_mailc,ccli_maild,ccli_mailt) VALUES";
			$rech .= " ('$datea','$datea','$code','$fonction','$civil','$prenom','$nom','$telf','$fax','$telp','$email','$mess','$nota','$mailc','$maild','$mailt')";
			$rs = mysql_query($rech) or die(mysql_error());
			mysql_close($conn);
			
			$msg = "Fiche enregistrée avec succès !";
			$retourfiche = TRUE;
		}

		if ($typaction == "edit")
		{
			// MAJ de la fiche Contact
		
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "UPDATE `" .TBCCLI. "` SET `ccli_datemod`='".$datea."', `ccli_codecli`='".$code."', `ccli_func`='".$fonction."', `ccli_civilite`='".$civil."', `ccli_prenom`='".$prenom."', `ccli_nom`='".$nom."', `ccli_telf`='".$telf."', `ccli_fax`='".$fax."', `ccli_telp`='".$telp."', `ccli_email`='".$email."', `ccli_mess`='".$mess."', `ccli_nota`='".$nota."', `ccli_maild`='".$maild."', `ccli_mailc`='".$mailc."', `ccli_mailt`='".$mailt."'  WHERE `ccli_id` = '".$idccli."'";
			$rs = mysql_query($rech) or die(mysql_error());
			mysql_close($conn);

			$msg = "Fiche modifiée avec succès !";
			$retourfiche = TRUE;
		}
		
		if ($typaction == "del")
		{
			// SUPPRESSION de la fiche Contact
			
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);

			$rech = "DELETE FROM `" .TBCCLI. "` WHERE `ccli_id` = '$idccli'";
			$rs = mysql_query($rech) or die(mysql_error());
			mysql_close($conn);

			$msg = "Fiche supprimée avec succès !";
			$retourfiche = TRUE;
		}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Contact Client</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../inc/smi.css" rel="stylesheet" type="text/css">

<!-- Feuille de style & Script pour le menu -->
<link href="../inc/menu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="../coolmenus/coolmenus4.js"></script>

</head>
<body>

<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 ($retourfiche == FALSE) 
{ 
?>
		<p align="center" class="annot_std_it">Retour à la fiche client dans 2 secondes...</p>
		<!-- Fermeture temporisée -->
		<script type="text/javascript">
			window.opener.location.reload();
			setTimeout("self.close('fscomp');",2000)
		</script>
		<p align="center">Sinon, <a href="javascript:void(0)" onClick="javascript:; window.opener.location.reload(); self.close('fscomp');">cliquez ici</a> </p>
<?PHP 
} 
else 
{
	if (($typaction == "add") OR ($typaction == "edit"))
	{
?>
		<p align="center" class="annot_std_it">Retour à la saisie dans 2 secondes...</p>
		<!-- Raffraichissement temporisée -->
		<script type="text/javascript">
		window.opener.location.reload();
		window.setTimeout("location=('ccli_maj.php?cc=<?PHP echo $code; ?>&td=<?PHP echo $typaction; ?>&page=1');",2000)
		</script>
<?PHP 
	}
	else
	{
?>
		<p align="center" class="annot_std_it">Retour à la fiche client dans 2 secondes...</p>
		<!-- Fermeture temporisée -->
		<script type="text/javascript">
			window.opener.location.reload();
			setTimeout("self.close('fscomp');",2000)
		</script>
		<p align="center">Sinon, <a href="javascript:void(0)" onClick="javascript:; window.opener.location.reload(); self.close('fscomp');">cliquez ici</a> </p>
<?PHP
	}
}
?>
</body>
</html>
