<?php include_once ("../inc/config.inc.php") ?>
<?php include_once ("../inc/func.inc.php") ?>
<?php include_once ("../inc/func_date.inc.php") ?>
<?php include_once ("../inc/func_log.inc.php") ?>
<?php include_once ("../inc/fic.inc.php") ?>
<?php require_once ("../classes/xpm/smtp.php"); ?>
<?php include_once ("../inc/mail.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
		$codecocl = strip_tags(trim($_GET['co']));	// Récupération code Contrat

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

		if ($codecocl <> "")
		{
			$codeco = crecode("CO");

			// Mise à jour fiche contrat client et récupération informations
			$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);

					$renouv = 1; // Contrat passé en mode "renouvelé"
	
					$upd = "UPDATE `" .TBCOCL;
					$upd .= "` SET `cocl_datemod`='".$datea."', `cocl_codemod`='".$codeuser."', `cocl_renouv`='".$renouv."',";
					$upd .="  `cocl_rnum`='".$codeco."' WHERE `cocl_code` = '".$codecocl."'";
					
					$rs2 = mysql_query($upd) or die(mysql_error());
				}

			}
			mysql_close($conn);

			// Création d'un nouveau contrat sur la base de l'ancien
			$cocl_dated = ajoute_un_jour_date($cocl_datef);
			$cocl_datef = "";

			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "INSERT INTO " .TBCOCL;
			$rech.= " (cocl_datecrea,cocl_codecrea,cocl_datemod,cocl_codemod,cocl_dateenv,cocl_daterec,cocl_code,cocl_codeco,cocl_codecope,";
			$rech.= "cocl_codeage,cocl_codecli,cocl_delai,cocl_nbs,cocl_typh,cocl_dated,cocl_datef,cocl_preavis,cocl_daterel,cocl_nivrel,";
			$rech.= "cocl_renouv,cocl_rnum,cocl_datefin,cocl_signe,cocl_soldes,cocl_matos,cocl_pvht)";
			$rech.= " VALUES";
			$rech.= " ('$datea','$codeuser','$datea','$codeuser','$datea','','$codeco','$cocl_codeco','$cocl_codecope',";
			$rech.= "'$cocl_codeage','$cocl_codecli','$cocl_delai','$cocl_nbs','$cocl_typh','$cocl_dated','$cocl_datef','$cocl_preavis','','',";
			$rech.= "'','','','','$cocl_nbs','$cocl_matos','$cocl_pvht')";
			$rs = mysql_query($rech) or die(mysql_error());
			mysql_close($conn);
					
			$msg = "Nouveau contrat (N°".$codeco.") créé avec succès.";
			$retourliste = TRUE;
		}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Renouvellement de contrat</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>

<!-- Scripts Javascript pour affichages -->
<script language="JavaScript" src="../inc/aff.js"></script>

</head>
<body>

<?php 
	include_once ("entete.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" 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="coclenv_maj.php"><img src="../img/liste.gif" width="33" height="34" border="0" align="absmiddle"></a> <a href="coclenv_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 
{ 
	$url_cocl = "cocl_maj.php?td=edit&co=".$codeco."&cc=".$cocl_codecli;
?>
	<script>
	warncoclren();
	</script>
	<script type="text/javascript">
	window.setTimeout("location=('<?PHP echo $url_cocl; ?>');",2000)
	</script>
	<p align="center" class="annot_std_it">Passage en mode édition dans 2 secondes...</p>
	
<?PHP 
} 
?>

<?php 
	include_once ("pied.php")
?>
