<?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("../inc/fic_age.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_co.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_txt.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_mail.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_txtcm.inc.php");
include_once("../classes/phpmailer/class.phpmailer.php");
include_once("../inc/mail.inc.php");
Archivelog(@$_SESSION["code_log"]);

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

$codecocl = str_majuscules(strip_tags(trim(@$_POST["codecocl"])));
$datesigf = strip_tags(trim(@$_POST["datesigf"]));
if ($datesigf <> "")
	$datesig = datefrang($datesigf);
else
	$datesig = $datesigf;
$signataire = strip_tags(trim(@$_POST["signataire"]));

$codeuser = @$_SESSION["code_log"];

$retourliste = TRUE;

if ($codecocl<>"")
{
	// MAJ de la fiche contrat client
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech = "SELECT * FROM " .TBCOCL." WHERE `cocl_code` =  '".$codecocl."'";
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) == 1) // Uniquement UN SEUL enregistrement !
	{
		$upd = "UPDATE `" .TBCOCL;
		$upd .= "` SET `cocl_datemod`='".$datea."', `cocl_codemod`='".$codeuser."', `cocl_datesig`='".$datesig."',";
		$upd .="  `cocl_daterec`='".$datea."', `cocl_signe`='".$signataire."'";
		$upd .=" WHERE `cocl_code` = '".$codecocl."'";
		$rs2 = mysql_query($upd) or die(mysql_error());
	
		/* Vérification du type de client et MAJ si nécessaire */
		$rech2 = "SELECT * FROM " .TBCOCL. " WHERE `cocl_code` = '".$codecocl."'";
		$rs2 = mysql_query($rech2) or die(mysql_error());
		if ($row = mysql_fetch_array($rs2))
		{
			extract ($row);

			$rech3 = "SELECT * FROM " .TBCLI. " WHERE `cli_code` = '".$cocl_codecli."'";
			$rs3 = mysql_query($rech3) or die(mysql_error());
			if ($row = mysql_fetch_array($rs3))
			{
				extract ($row);
			
				$rech4 = "UPDATE `" .TBCLI. "` SET `cli_datemod`='".$datea."', `cli_codemod`='".$codeuser."', `cli_prop`='".$cocl_codeage."', `cli_type`='2'  WHERE `cli_code` = '".$cocl_codecli."'";
				$rs4 = mysql_query($rech4) or die(mysql_error());
			}
			mysql_free_result($rs3);
		}
		mysql_free_result($rs2);
	
		$msg = "R&eacute;ception contrat ".$codecocl." effectu&eacute;e.";
	}
	else
	{
		$msg = "Contrat inconnu.";
		$retourliste=FALSE;
	}
	mysql_free_result($rs);
	mysql_close($conn);
}
else
{
	$msg = "Contrat inconnu.";
	$retourliste=FALSE;
}
?>
<!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 : Accus&eacute; r&eacute;ception contrat</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("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="coclrec_maj.php"><img src="../img/liste.gif" width="33" height="34" border="0" align="absmiddle"></a> <a href="coclrec_maj.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 { 
		// Envoi d'email vers le client
		envoi_mail("Accusé de réception de votre contrat","con","ar","xxx","cli",$codecocl,"","",FALSE);
		// Envoi d'email vers l'agence
		envoi_mail("Accusé de réception de contrat","con","ar","xxx","age",$codecocl,"","",FALSE);
		// Envoi d'email vers le centre de gestion
		envoi_mail("Accusé de réception de contrat","con","ar","xxx","cdg",$codecocl,"","",TRUE);
?>
	<script type="text/javascript">
	window.setTimeout("location=('coclrec_maj.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Retour à la saisie dans 2 secondes...</p>
	
<?PHP } 
include_once("pied.php");
?>
