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

if (!isset($_SESSION["lng"])) $_SESSION["lng"]="fr";
include_once("../lng/".$_SESSION["lng"].".inc.php"); // Paramètres de language
include_once("../inc/config.inc.php");
include_once("../inc/fic_pdt.inc.php");
include_once("../inc/fic_taxes.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

$td = strip_tags(trim(@$_GET['td']));
$codepdt = strip_tags(trim(@$_GET['cp']));
$codetpf = strip_tags(trim(@$_GET['tpf']));
	
$pbm_tpf=FALSE;

if (($codepdt <> "") AND ($codetpf<> ""))
{
	// Récupération des données de la fiche article
	$row = lit_enr_pdt($codepdt);
	if (is_array($row))
	{
		extract ($row);
	
		$row = lit_enr_tpf($codetpf);

		if (is_array($row))
		{
			extract($row);

			if ($tpf_global==FALSE)
			{
				if ($td == "add")
				{
					$tpfa_codetpf = $codetpf;
					$tpfa_codepdt = $pdt_code;
					$tpfa_mt = $tpf_valeur;
				}
		
				if ($td == "edit")
				{
					$row = lit_enr_tpf_in_pdt($codetpf,$codepdt);
					if (is_array($row))
						extract ($row);
					else
						$pbm_tpf=TRUE;
				}
		
				if ($td == "del")
				{
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					$rech = "SELECT * FROM `" .TBTPFA. "` WHERE `tpfa_codepdt` = '$codepdt' AND `tpfa_codetpf` = '$codetpf'";
					$rs = mysql_query($rech)or die(mysql_error());
					if (mysql_num_rows($rs) == 0)
						$pbm_tpf=TRUE;
					else
					{
						if ($row = mysql_fetch_array($rs))
							extract ($row);
						else
							$pbm_tpf=TRUE;
					}
					mysql_free_result($rs);
					mysql_close($conn);
				}
			}
			else
				$pbm_tpf=TRUE;
		}
		else
			$pbm_tpf=TRUE;
	}
	else
		$pbm_tpf=TRUE;
}			
else
	$pbm_tpf=TRUE;

switch ($td)
{
	case "add" :
		$titre = "SAISIE TAXE";
		break;
	case "edit" :
		$titre = "EDITION TAXE";
		break;
	case "del" :
		$titre = "SUPPRESSION TAXE";
		break;
	default :
		$pbm_tpf=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; ?> : Taxes Produit</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>

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

<?PHP if ($tpf_asaisir==TRUE) { ?>
<script language="javascript">
<!--
var tab1_champ=new Array(
	"nom:valeur; format:reel_ns ; req:Y ; txt:Valeur ; vmn:0.01 ; stok:frmok ; stbad:frmbad");
//-->
</script>
<?PHP } ?>

<!-- Scripts Javascript divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

<!-- Scripts Javascript sur les champs -->
<script language="JavaScript" src="../jscript/verif_field.js"></script>

</head>

<body onLoad="metFocus();">

<?PHP
if ($pbm_tpf==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">Pour le produit : <br><span class="titre_gras"><?php echo $pdt_des; ?> </span></p>

<form name="tpfa_maj" method="post" action="tpfa_enr.php" <?PHP if ($tpf_asaisir==TRUE) { ?>onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));" <?PHP } ?>>
	<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
    <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
    <input name="codepdt" type="hidden" id="codepdt" value="<?PHP echo $tpfa_codepdt ?>">
  <table width="600"  border="0">
    <tr>
      <td width="160" class="rubfrm" id="f_code"><?PHP echo $txt_chp_code; ?></td>
      <td width="84%">
		  <input name="code" type="text" id="code" value="<?PHP echo $tpf_code ?>" size="10" maxlength="10" readonly="1">
	  </td> 
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_des"><?PHP echo $txt_chp_lib; ?></td>
      <td>
	  	<input name="des" type="text" id="des" value="<?PHP echo htmlspecialchars($tpf_desc); ?>" size="40" maxlength="40" readonly="1">
	  </td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_valeur">Valeur TTC</td>
      <td>
	  	<input name="valeur" type="text" id="valeur" style="text-align:right" value="<?PHP echo format_num($tpfa_mt,2) ?>" size="10" <?PHP if ($tpf_asaisir==FALSE) { ?>onChange="formatedeci(this.id,2);" readonly="1"<?PHP } ?>>
        <?PHP if ($tpf_pour==TRUE) 
			echo "%";
		else
			echo "&nbsp;";
		?>
        <?PHP if ($tpf_asaisir==TRUE) { ?>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"><br>
		<span class="annot_petit_it">(La d&eacute;cimale doit &ecirc;tre '.' et pas la virgule)</span>
		<?PHP } 
		if ($tpf_typmt==TRUE) {
		?>
		<br><span class="annot_petit_it">La valeur saisie ou calcul&eacute;e sera unique</span>
		<?PHP } else { ?>
		<br><span class="annot_petit_it">La valeur saisie ou calcul&eacute;e sera proportionnelle au nombre d'unit&eacute;s vendues</span>
		<?PHP }
		if ($tpf_asaisir==FALSE) {
		?>
		<br><span class="annot_petit_it">Cette valeur n'est pas modifiable</span>
		<?PHP } ?>
	  </td>
    </tr>
  </table>
  <p align="center">
    <?PHP if ($td == "add") {
    if ($tpf_asaisir==TRUE) { ?>
    <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
	<?PHP } ?>
    <input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_add; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp');">
    <?PHP } if ($td == "edit") {
    if ($tpf_asaisir==TRUE) { ?>
    <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
	<?PHP } ?>
    <input name="mod" type="submit" class="bton_std" id="mod" value="<?PHP echo $but_modif; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp');">
    <?PHP } if ($td == "del") { ?>
    <input name="del" type="submit" class="bton_std" id="del" value="<?PHP echo $but_del; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp');">
    <?PHP } ?>
  </p>
</form>
<?PHP
}
else
{
?>
	<script type="text/javascript">
	<!--
	self.close('fscomp');
	//-->
	</script>
<?PHP
}
?>
</body>
</html>
