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

$ta = strip_tags(trim($_GET['ta'])); // Source de l'appel m:depuis le menu, p:depuis un retour produit
$td = strip_tags(trim($_GET['td'])); // Récupération type demande
$cp = strip_tags(trim($_GET['cp'])); // Récupération code Produit
$ci = strip_tags(trim($_GET['ci'])); // Récupération code Intervention

$pbm_pen=FALSE;

if (($ta<>"p") AND ($ta<>"m"))
	$pbm_pen=TRUE;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<META http-equiv=Content-typee content="text/html; charset=iso-8859-1">
<title>SMI - <?PHP echo $title_esp_prive; ?> : Liste P&eacute;nalit&eacute;s</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 divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

</head>

<body onLoad="metFocus();">

<?php 
if ($ta == "m") 
	include_once("../inc/entete.inc.php");
?>
<p align="center"><span class="titrepage">LISTE DES PENALITES</span></p>
<?PHP 
if ($pbm_pen==FALSE) {


if (($ta=="p") OR ($ta=="i"))
{
?>
	<div align="center">
<?PHP
	switch ($ta)
	{
		case "p" :
		?>
			<span class="titre_gras">Choisissez une taxe pour le produit <?php echo $cp; ?> dans la liste suivante</span><br>
			<span class="annot_petit_it">Hors taxe(s) d&eacute;j&agrave; saisie(s) dans ce produit</span>
		<?PHP
			break;
		default :
			break;
	}
?>
	</div>
	<p align="center">
	<input type="button" class="bton_std" name="Submit" value="Revenir &agrave; la saisie en cours" onClick="javascript:; self.close('fscomp');">
	</p>
<?PHP
}

if (($ta=="m"))
{
	$url_add = "pen_maj.php?td=add&code=";
}

$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);

$rech = cree_strrechlstpen();
switch ($ta)
{
	case "p" :
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE `pen_actif`=1";
		else
			$rech .= " AND `pen_actif`=1";
		break;
	default :
		break;
}

$rech .= crestr_triord($pen_titre_col,"pen_code",FALSE,$limit);

$rs = mysql_query($rech) or die(mysql_error());
$numrows = mysql_num_rows($rs); // Nombre de résultats à la requête

if($numrows == 0)
{
	retpp();
}
else
{
	include_once("../inc/formr.inc.php"); 

	$rech = cree_strrechlstpen();
	switch ($ta)
	{
		case "p" :
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE `pen_actif`=1";
			else
				$rech .= " AND `pen_actif`=1";
			break;
		default :
			break;
	}

	$rech .= crestr_triord($pen_titre_col,"pen_code",TRUE,$limit);

	$rs = mysql_query($rech) or die(mysql_error());

	// *** Pagination de pied
	pagine_lst($numrows,$limit);
	
	// *** Affichage de la table
	echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";     
	
	// Création entête
	titlst($pen_titre_col);
	echo "<th>".ucfirst($txt_ent_lst_clic)."</th>\n";
	
	$i = 0;
	
	while ($row = mysql_fetch_assoc($rs)) 
	{         
		$affok=TRUE;
		switch ($ta)
		{
			case "p" :
				$rech2 = "SELECT * FROM `" .TBPDTLPL. "` WHERE `pdtlpl_codepen` = '".$row["pen_code"]."' AND `pdtlpl_idpdtl` = '".$row["pen_id"]."'";
				$rs2 = mysql_query($rech2)or die(mysql_error());
				if (mysql_num_rows($rs2) <> 0)
					$affok=FALSE;
				break;
			default :
				break;
		}
		
		if ($affok==TRUE)
		{
			// Création de l'entête de ligne (TR)
			creetrlst($i);
			
			echo "<td>".$row["pen_code"]."</td>\n";
			echo "<td>".htmlspecialchars($row["pen_desc"]);
			if ($row["pen_actif"]==0)
				 echo " <img src=\"../img/inactif.png\" border=\"0\" align=\"absmiddle\" title=\"Inactive\">";
			echo "</td>\n";
			echo "<td align=\"center\">";
			echo $lng_tduree[$row["pen_udec"]];
			echo "</td>\n";
			echo "<td align=\"center\">";
			if ($row["pen_tbar"]==0)
			{
				echo $row["pen_valeur"];
				if ($row["pen_pour"]==1)
					echo "%";
				else
					echo $lang['symbole_monnaie_txt'];
			} else {
				echo "Grille de valeurs";
				if ($row["pen_pour"]==1)
					echo " (%)";
				else
					echo " (".$lang['symbole_monnaie_txt'].")";
			}
			echo "</td>\n";
			echo "<td align=\"center\">";
			echo $non_oui[$row["pen_asaisir"]];
			echo "</td>\n";
		
			// CREATION lien dynamique sur icône (édition, suppression, etc...)
			echo "<td>";
			echo "<div align=\"center\">";
			switch ($ta)
			{
				case "m" :
					$lst_maj = TRUE;
					echo "<a href=\"pen_maj.php?td=edit&code=".$row["pen_code"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_edit."\"></a>";
					echo " ";
					$lst_del = TRUE;
					echo "<a href=\"pen_maj.php?td=del&code=".$row["pen_code"]."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\"></a>";
					break;
				case "p" :
					$lst_pen = TRUE;
					echo "<a href=\"pena_maj.php?td=add&cp=".$cp."&tpf=".$row["pen_code"]."\"><img src=\"../img/taxe.png\" border=\"0\" align=\"absmiddle\" title=\"Ajouter\"></a>";
					echo " ";
					break;
				default :
					break;
			}
			echo "</div>";
			echo "</td>\n";
		
			echo "</tr>\n";
			
			$i++;
		}
	}  
	echo "</table>\n";
	// *** Fin affichage de la table
	
	mysql_free_result($rs);
	mysql_close($conn);  
	
	// *** Pagination de pied
	pagine_lst($numrows,$limit);
			
	$taille_piedla="";
	include_once("../inc/piedla.inc.php"); 
}

}
else
{
?>
<script type="text/javascript">
<!--
setTimeout("self.location.href=('index.php');",2000)
//-->
</script>
<p align="center" class="annot_std_it"><?PHP echo $alert_prm; ?>...</p>
<?PHP
}

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