<?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/fic_age.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

$pbm_intf = FALSE;

$tx = strip_tags(trim($_GET['tx'])); // Récupération origine ('m' : menu  / 'i' : intervention)
$td = strip_tags(trim($_GET['td'])); // Récupération type demande
$ci = strip_tags(trim($_GET['ci'])); // Récupération code Intervention

if (($tx<>"m") AND ($tx<>"i"))
	$pbm_intf=TRUE;
	
if ($pbm_intf==FALSE)
{
	if ($ci <> "")
	{
		// Récupération des informations intervention
		$row = lit_enr_int($ci);
		if (is_array($row))
		{
			extract ($row);
	
			switch ($_SESSION["niv_log"])
			{
				// Contrôle qu'une agence n'essaye pas de "hacker" une intervention
				case 4 :
					if ($int_codeage == @$_SESSION["code_age"])
					{
						$row = lit_enr_age($int_codeage,TRUE);
						if (is_array($row))
						{
							extract ($row);
							
							if (intval($age_fact)==0)
								$pbm_intf=TRUE;
						}
						else
							$pbm_intf=TRUE;
					}
					else
						$pbm_intf=TRUE;
					break;
			}
			
			if ($td<>"add")
			{
				if ($pbm_intf==FALSE)
				{
					$row = lit_enr_intf($ci,TRUE);
					if (is_array($row))
					{
						extract($row);
						
						// Formatage des dates en français
						$intf_datefacf = formatedate($intf_datefac);
					}
					else
						$pbm_intf=TRUE;
				}
			}
			else
				$intf_datecreaf = $datef;
		}
		else
			$pbm_intf = TRUE;
	}
	else
		$pbm_intf = TRUE;
}

switch ($td)
{
	case "add" :
	case "edit" :
		$titre = "SUIVI FACTURATION (";
		$titre.=$int_code.")";
		break;
	case "view" :
		$titre = "VISUALISATION FACTURATION (";
		$titre.=$int_code.")";
		break;
	default:
		$titre = "PROBLEME";
		$pbm_intf=TRUE;
		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>

<!-- Définition Javascript pour calendrier popup -->
  <!-- Feuille de Style -->
  <link rel="stylesheet" type="text/css" media="all" href="../jscript/jscal/skins/aqua/theme.css" title="Aqua" />

  <!-- Script Javascript Principal -->
  <script type="text/javascript" src="../jscript/jscal/calendar.js"></script>

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscript/jscal/lang/calendar-<?PHP echo $_SESSION["lng"]; ?>.js"></script>

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="../jscript/jscal/calendar-setup.js"></script>
<!-- Fin de la définition Javascript pour calendrier popup -->

<!-- Scripts Javascript pour vérifications formulaires -->
<script language="JavaScript" src="../jscript/verif_form.js"></script>

<!-- Scripts Javascript pour vérifications -->
<script language="JavaScript" src="../jscript/verif_field.js"></script>

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/vform/vform.js"></script>

<script language="javascript">
<!--
var tab_champ=new Array(
	"nom:datefacf ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:N ; txt:Date facturation ; stok:frmok ; stbad:frmbad",
	"nom:numf; format:txt ; req:N ; txt:Numéro facture ; lmx:20 ; stok:frmok ; stbad:frmbad",
	"nom:nomf; format:txt ; req:N ; txt:Facturé par ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:codeme; format:liste ; req:N ; txt:Mode envoi ; stok:frmok ; stbad:frmbad");
//-->
</script>

</head>

<body onLoad="verif_aff_oblsf();">
<?PHP
if ($tx=="m")
	include_once("../inc/entete.inc.php"); 
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<?PHP
if ($pbm_intf == FALSE)
{
?>
<table width="100%"  border="0">
<tr>
	<td width="40%">
	<strong><em><a href="intf_lst.php?tx=<?PHP echo $tx; ?>&ci=<?PHP echo $ci; ?>&ord=ASC&tri=Facture"><?PHP echo $txt_lnk_ret_liste; ?></a></em></strong>
	</td>
	<td width="160" valign="top">
	<div id="oblig" align="center" class="annot_petit_it">(<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> : <?PHP echo $txt_div_saisoblg; ?>)</div>
	</td>
	<td width="40%">&nbsp;
    </td>
</tr>
</table>
<br /><br />
<form name="intf_maj" method="post" action="intf_enr.php" onSubmit="javascript:; return (verif_intf(this,tab_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="tx" type="hidden" id="tx" value="<?PHP echo $tx ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="ci" type="hidden" id="ci" value="<?PHP echo $ci ?>">
<table border="0" align="center">
<tr>
	<td width="160" class="rubfrm" id="f_fnulle" align="right">Facture nulle</td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
			echo '<select name="fnulle" id="fnulle" onChange="verif_aff_oblsf();">';
			foreach ($non_oui as $key=>$value)
			{
				echo '<option value="'.$key.'"'; 
				if ($intf_fnulle == $key)
					echo ' selected';
				echo '>';
				echo $value."</option>";
			}
			echo '</select>';
			echo '<img src="../img/oblig.png" align="absmiddle" alt="'.$alt_chp_oblig.'">';
		}
		else
		{
			echo '<input name="fnulle" type="hidden" id="fnulle" value="'.intval($intf_fnulle).'" readonly="readonly">';
			echo '<input name="nfnulle" type="text" id="nfnulle" value="'.$non_oui[intval($intf_fnulle)].'" size="3" readonly="readonly">';
		}
		?>
		<div class="annot_petit_it">'Non' : La facture a &eacute;t&eacute; &eacute;mise. L'intervention sera &eacute;galement not&eacute;e comme factur&eacute;e</div>
		<div class="annot_petit_it">'Oui' : La facture n'a pas &eacute;t&eacute; &eacute;mise. Seule l'intervention sera not&eacute;e comme factur&eacute;e</div>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_dateddef" align="right">Date facturation</td>
	<td>
		<input name="datefacf" type="text" id="datefacf" value="<?PHP echo $intf_datefacf ?>" size="10" maxlength="10" readonly="1">
		<?PHP if (($td == "add") OR ($td=="edit")) { ?>
		<span id="obl1"><img src="../img/calendar.png" align="absmiddle" id="f_img_datefacf" title="<?PHP echo $alt_chxdate; ?>">
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"></span>
		<?PHP } ?>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_numf" align="right">Num&eacute;ro facture</td>
	<td>
		<input name="numf" type="text" id="numf" value="<?PHP echo $intf_numf ?>" size="20" maxlength="20" <?PHP if ($td<>"add") echo 'readonly="1"'; ?>>
		<?PHP if ($td=="add") { ?>
		<span id="obl2"><img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"></span>
		<?PHP } ?>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_nomf" align="right">Factur&eacute; par</td>
	<td>
		<input name="nomf" type="text" id="nomf" value="<?PHP echo $intf_nomf ?>" size="50" maxlength="50">
		<span id="obl3"><img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"></span>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_codeme" align="right">Mode d'envoi</td>
	<td>
		<?PHP
		if (($td =="add") OR ($td=="edit"))  // Ajout/Edition = zone modifiable (on peut choisir un mode)
		{ 
			// Création de la liste des mode d'envoi
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBME." ORDER BY me_nom";
			$rs = mysql_query($rech) or die(mysql_error());

			echo '<select name="codeme" id="codeme">';
			echo '<option value="">-- Choisissez un mode --</option>';
			if (mysql_num_rows($rs) <> 0)
			{
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
	
					echo '<option value="'.$me_code.'"';
					if ($intf_codeme == $me_code)
						echo ' selected';
					echo '>'.$me_nom.'</option>';
				}
			}
			echo '</select>';
			echo '<span id="obl4"><img src="../img/oblig.png" align="absmiddle" alt="'.$alt_chp_oblig.'"></span>';
			mysql_free_result($rs);
			mysql_close($conn);
			$urlcreeme = "me_maj.php?td=add&tx=f";
		?>
		<span id="creme">
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $urlcreeme; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/add.png" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="fensaisie('<?PHP echo $urlcreeme; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Ajouter un mode</a>
		</span>
		<?PHP
		} 
		else  // Edition ou suppression = zone non modifiable (affichage seul)
		{
			$row = lit_enr_me($intf_codeme,TRUE);
			if (is_array($row))
				extract($row);
		?>
		<input name="codeme" type="hidden" id="codeme" value="<?PHP echo $intf_codeme ?>">	
		<input name="nomme" type="text" id="nomme" value="<?PHP echo $me_nom ?>" size="50" maxlength="50" readonly="1">
		<?PHP 
		} 
		?>
	</td>
</tr>
<tr>
	<td class="rubfrm" id="f_notaa" align="right">Notes</td>
	<td>
		<textarea name="nota" rows="5" id="nota"><?PHP echo htmlspecialchars($intf_nota) ?></textarea>
	</td>
</tr>
</table>
<br /><br />
<p align="center">
<input name="create" type="submit" class="bton_std" id="create" value="<?PHP echo $but_valider; ?>">
<input name="init" type="reset" class="bton_std" id="init" value="<?PHP echo $but_reinit; ?>">
<?PHP if ($td=="edit") { ?>
<input name="del" type="submit" class="bton_std" id="del" value="<?PHP echo $but_del; ?>">
<?PHP } ?>
</p>
</form>

<script type="text/javascript">
<!--
<?PHP
if (($td=="add") OR ($td=="edit"))
{
?>
Calendar.setup({
	inputField     :    "datefacf",     // id of the input field
	ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
	button         :    "f_img_datefacf",  // trigger for the calendar (button ID)
	align          :    "Br",           // alignment (defaults to "Bl")
	electric	   :	false,
	singleClick    :    true
});
<?PHP
}
?>
</script>
<?PHP
}
else
{
	switch ($tx)
	{
		case "i" :
?>
	<script type="text/javascript">
	<!--
	self.close();
	//-->
	</script>
<?PHP
			break;
		default :
?>
	<script type="text/javascript">
	<!--
	setTimeout("self.location.href=('index.php');",2000)
	//-->
	</script>
	<p align="center" class="annot_std_it">Probl&egrave;me de param&egrave;tres</p>
<?PHP
		break;
	}
}
if ($tx=="m")
	include_once("pied.php");
?>
