<?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"]);

// Variables Formulaire
$titre = stripslashes(strip_tags(trim(@$_POST["titre"])));
$tx = strip_tags(trim(@$_POST["tx"]));
$td = strip_tags(trim(@$_POST["td"]));
$ci = strip_tags(trim(@$_POST["ci"]));

$fnulle= strip_tags(trim(@$_POST["fnulle"]));
$datefac = datefrang(strip_tags(trim(@$_POST["datefacf"])));
$numf = strip_tags(trim(@$_POST["numf"]));
$nomf = strip_tags(trim(@$_POST["nomf"]));
$codeme = str_majuscules(strip_tags(trim(@$_POST["codeme"])));
$nota = strip_tags(str_escape(trim(@$_POST["nota"])));

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

$msg="";
$retourliste = FALSE;
if (strip_tags(trim(@$_POST["del"])) == html_entity_decode($but_del))
	$td="del";
switch ($td)
{
	// Ajout de la fiche suivi facturation
	case "add" :
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM " .TBINTF. " WHERE `intf_codeint` = '$ci' AND `intf_numf` = '$numf'";
		$rs = mysql_query($rech) or die(mysql_error());
		if (mysql_num_rows($rs) == 0)
		{
			$rech2 = "INSERT INTO " .TBINTF;
			$rech2.=" (intf_datecrea,intf_codecrea,intf_datemod,intf_codemod,intf_fnulle,intf_datefac,intf_numf,intf_nomf,";
			$rech2.="intf_codeint,intf_codeme,intf_nota)";
			$rech2.=" VALUES";
			$rech2.=" ('$datea','$codeuser','$datea','$codeuser','$fnulle','$datefac','$numf','$nomf',";
			$rech2.="'$ci','$codeme','$nota')";
			$rs2 = mysql_query($rech2) or die(mysql_error());
	
			// MAJ de la fiche intervention
			$rech2 = "UPDATE `" .TBINT. "` SET `int_fact`='1'";
			$rech2.=" WHERE `int_code` = '".$ci."'";
			$rs2 = mysql_query($rech2) or die(mysql_error());
			
			$msg = $txt_fiche_add;
			$retourliste = TRUE;
		}
		else
			$msg = $txt_fiche_exist;
	
		mysql_free_result($rs);
		mysql_close($conn);
	
		break;
		
	// MAJ de la fiche suivi facturation
	case "edit" :
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "UPDATE `" .TBINTF. "` SET `intf_datemod`='".$datea."', `intf_codemod`='".$codeuser."', `intf_fnulle`='".$fnulle."',";
		$rech .=" `intf_datefac`='".$datefac."', `intf_numf`='".$numf."', `intf_nomf`='".$nomf."', `intf_codeme`='".$codeme."',";
		$rech .="  `intf_nota`='".$nota."'";
		$rech .=" WHERE `intf_codeint` = '$ci' AND `intf_numf` = '$numf'";
		$rs = mysql_query($rech) or die(mysql_error());
		mysql_close($conn);
		
		$msg = $txt_fiche_mod;
		$retourliste = TRUE;

		break;		


	// Suppression de la fiche suivi facturation
	case "del" :
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "DELETE FROM `" .TBINTF. "` WHERE `intf_codeint` = '$ci' AND `intf_numf` = '$numf'";
		$rs = mysql_query($rech) or die(mysql_error());
			
		// MAJ de la fiche intervention
		$rexist = "SELECT * FROM `" .TBINTF. "` WHERE `intf_codeint` = '$code'";
		$rs2 = mysql_query($rexist) or die(mysql_error());
		if (mysql_num_rows($rs2) <> 0)
		{
			$rech2 = "UPDATE `" .TBINT. "` SET `int_fact`='1'";
			$rech2.=" WHERE `int_code` = '".$ci."'";
		}
		else
		{
			$rech2 = "UPDATE `" .TBINT. "` SET `int_fact`='0'";
			$rech2.=" WHERE `int_code` = '".$ci."'";
		}
		$rs2 = mysql_query($rech2) or die(mysql_error());

		mysql_close($conn);
		
		$msg = $txt_fiche_del;
		$retourliste = TRUE;
		
		break;
		
	default :
		break;
}
?>
<!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; ?> : Suivi facturation</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 
if ($tx=="m")
	include_once("../inc/entete.inc.php"); 
?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></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">';
echo $msg;
?>
</span>
</p>
<br />
<?PHP 
if ($tx=="i")
{
?>
	<script type="text/javascript">
	<!--
	var objet=window.opener.document.getElementById("imgsfact");
	var objet1=window.opener.document.getElementById("txtsfact");
	if ((objet) && (objet1))
	{
		<?PHP 
		$nb_intf=nb_intf_int($ci,TRUE);
		if ($nb_intf==0) { ?>
		objet.src='../img/sfact_add.png';
		objet.title='Suivi facturation';
		objet1.innerHTML='Non factur&eacute;';
		<?PHP } else {
		$txt_inner="Factur&eacute; (".$nb_intf.")";
		 ?>
		objet.src='../img/sfact.png';
		objet.title='Suivi facturation';
		objet1.innerHTML='<?PHP echo $txt_inner; ?>';
		<?PHP } ?>
	}
	//-->
	</script>
<?PHP
}
if ($retourliste == FALSE) 
	aff_ret_idx_man($td,"intf_lst.php?tx=".$tx."&ci=".$ci."&ord=ASC&tri=Facture",$txt_lnk_ret_liste,FALSE);
else 
	aff_ret_lst_auto("intf_lst.php?tx=".$tx."&ci=".$ci."&ord=ASC&tri=Facture",2000);

if ($tx=="m")
	include_once("pied.php");
?>
