<?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/func.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_mail.inc.php");
include_once("../classes/phpmailer/class.phpmailer.php");
include_once("mail.inc.php");
Archivelog(@$_SESSION["code_log"]);

$codecocl = strip_tags(trim($_GET['co']));	// Récupération code Contrat
$codeuser = @$_SESSION["code_log"];

$retourliste=FALSE;

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 !
	{
		if ($row = mysql_fetch_array($rs))
		{
			extract ($row);
			
			$cocl_nivrel++;
			
			$upd = "UPDATE `" .TBCOCL;
			$upd .= "` SET `cocl_datemod`='".$datea."', `cocl_codemod`='".$codeuser."', `cocl_daterel`='".$datea."' ,";
			$upd .="  `cocl_nivrel`='".$cocl_nivrel."' WHERE `cocl_code` = '".$codecocl."'";
			$rs2 = mysql_query($upd) or die(mysql_error());

			// Envoi d'email vers le client
			envoi_mail("","Renouvellement de votre contrat","con","ren","xxx","cli",$codecocl,"","",FALSE);
			// Envoi d'email vers l'agence
			if (@$_SESSION["niv_log"] <> 4)
				envoi_mail("","proposition de renouvellement de contrat","con","ren","xxx","age",$codecocl,"","",FALSE);
			// Envoi d'email vers le centre de gestion
			envoi_mail("","Proposition de renouvellement de contrat","con","ren","xxx","cdg",$codecocl,"","",TRUE);

			$msg = "Renouvellement effectu&eacute;.";
		}
	else
		{
			$msg = "Contrat inconnu.";
			$retourliste=FALSE;
		}
	}
	else
	{
		$msg = "Contrat inconnu.";
		$retourliste=FALSE;
	}
	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 - <?PHP echo $title_esp_prive; ?> : Renouvellement de 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("../inc/entete.inc.php"); 
?>


<p align="center"><span class="titrepage">RENOUVELLEMENT DE CONTRAT </span></p>
<div align="center">Contrat N&deg;<?PHP echo $codecocl?></div>
<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,"coclenv_maj.php",$txt_lnk_ret_liste,FALSE);
else 
{ 
	// Envoi d'email vers le client
	envoi_mail("","Renouvellement d'un de vos contrats","con","ren","xxx","cli",$codecocl,"","",TRUE);

	aff_ret_lst_auto("coclren_lst.php",2000);
}
include_once("pied.php")
?>
