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

$retourok = TRUE;

if (@$_SESSION["niv_log"]==9)
{
	$msg="";
	
	// Variables Formulaire
	$code = str_majuscules(strip_tags(trim(@$_GET["ci"])));
	$codeuser=@$_GET["code_log"];
	
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech = "SELECT * FROM " .TBINT. " WHERE `int_code` = '$code'";
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) == 1)
	{
		if ($row = mysql_fetch_assoc($rs))
		{
			extract($row);
			
			$reopen_ok=TRUE;
			$cocl_typh=-1;
			
			// Si intervention rattachée à un contrat, manipulations complémentaires
			if ($int_codecocl <> "")
			{
				$rech2 = "SELECT * FROM " .TBCOCL." WHERE `cocl_code` = '".$int_codecocl."'";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if (mysql_num_rows($rs2) <> 0)
				{
					if ($row2 = mysql_fetch_array($rs2))
					{
						extract($row2);

						// Si la date du jour est supérieure à la date de fin du contrat,
						// il n'est pas possible de réouvrir l'intervention
						if (formatedate($cocl_datef)<>"")
						{
							if (comp_date($cocl_datef,$datea) == TRUE)
							{
								$reopen_ok=FALSE;
								$msg = "Le contrat rattach&eacute; &agrave; cette intervention est en &eacute;ch&eacute;ance d&eacute;pass&eacute;e.\nImpossible de r&eacute;ouvrir cette intervention.";
								$retourok = FALSE;
							}
						}
					}
				}
			}
			
			if ($reopen_ok==TRUE)
			{
				// On supprime la date de cloture de cette intervention
				$rech2 = "UPDATE `" .TBINT. "` SET `int_datemod`='".$datea."', `int_codemod`='".$codeuser."',";
				$rech2.= " `int_datefin`='', `int_codestatut`='EC'";
				$rech2.= " WHERE `int_code` = '$code'";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				$msg="Intervention ".$code." r&eacute;ouverte";
		
				// Remise à niveau type client
				upd_nivcli($int_codecli,FALSE);
	
				// Réouverture des problèmes affectés à l'intervention
				$rech2 = "SELECT * FROM " .TBRPBM. " WHERE `rpbm_codeint` = '$code'";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if (mysql_num_rows($rs2) > 0)
				{
					$rech2 = "UPDATE `" .TBRPBM. "` SET `rpbm_datett`= '' WHERE `rpbm_codeint`= '".$code."'";
					$rs2 = mysql_query($rech2) or die(mysql_error());
					$msg.="<br /><br />Probl&egrave;mes attach&eacute;s r&eacute;ouverts";
				}
				
				// Suppression des reports
				$rech2 = "DELETE FROM `" .TBCOCLR. "` WHERE `coclr_codeint` = '$code'";
				$rs2 = mysql_query($rech2) or die(mysql_error());

				// Réouverture du contrat	
				$rech2 = "UPDATE `" .TBCOCL;
				$rech2.= "` SET `cocl_datefin`=''";
				$rech2.= " WHERE `cocl_code` = '".$cocl_code."'";
				$rs2 = mysql_query($rech2) or die(mysql_error());

				if ($cocl_typh == 1) // Contrat 'Quota Horaire'
					$msg.="<br /><br />Solde contrat ".$cocl_code." remis &aacute; jour.<br>(Contrat r&eacute;ouvert)";
				else
					$msg.="<br /><br />Contrat ".$cocl_code." r&eacute;ouvert.";
			}
		}
	}
	else
	{
		$msg = "Cette intervention n'existe pas !";
		$retourok = FALSE;
	}
	mysql_free_result($rs);
	mysql_close();
}
else
{
	$msg = "Vous n'avez pas le droit de r&eacute;ouvrir une intervention";
	$retourok = 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; ?> : R&eacute;ouverture Intervention</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>
<p align="center"><span class="titrepage">R&eacute;ouverture Intervention </span></p>
<p align="center">&nbsp;</p>
<p align="center">
<?PHP if ($retourliste==FALSE)
	echo '<span class="alerte1">';
else
	echo '<span class="annot_std_gras">';
?>
<?PHP echo $msg ?>
</span>
</p>

<br>
<br>
<?PHP if ($retourok == FALSE) 
{ 
?>
	<p align="center" class="annot_std_it"><?PHP echo $txt_lnk_ret_liste; ?> des interventions<?PHP echo ", ".$txt_patience; ?></p>
	<!-- Fermeture temporisée -->
	<script type="text/javascript">
	<!--
		window.opener.location.reload();
		setTimeout("self.close('fscomp');",5000)
	//-->
	</script>
<?PHP 
} 
else 
{
?>
	<p align="center" class="annot_std_it"><?PHP echo $txt_lnk_ret_liste; ?> des interventions<?PHP echo ", ".$txt_patience; ?></p>
	<!-- Fermeture temporisée -->
	<script type="text/javascript">
	<!--
		window.opener.location.reload();
		setTimeout("self.close('fscomp');",2000)
	//-->
	</script>
<?PHP		
}
?>
<p align="center"><?PHP echo $txt_div_sinon; ?>, <a href="javascript:void(0)" onClick="javascript:; window.opener.location.reload(); self.close('fscomp');"><?PHP echo $txt_lnk_clic_ici; ?></a> </p>
</body>
</html>
