<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.6
Copyright (C) 2006  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
****************************************************************************************/

?>
<?php include ("../inc/config.inc.php") ?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php require ("../inc/func_txt.inc.php") ?>
<?php include ("../inc/fic.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$td = strip_tags(trim($_GET['typ']));
	$coderech = strip_tags(trim($_GET['code']));
	
	if ((@$HTTP_SESSION_VARS["niv_log"] == 4) OR (@$HTTP_SESSION_VARS["niv_log"] == 3))
		$td="view";

	if ($coderech <> "")
	{
		// Récupération des informations produit
		$row = lit_enr_pdt($coderech);
		extract ($row);
	}
	else
	{
		if ($td == "add")
		{
			$pdt_vendu = TRUE;
		}
	}
	switch ($td)
	{
		case "add" :
			$titre = "CREATION ARTICLE";
			break;
		case "edit" :
			$titre = "MISE A JOUR ARTICLE";
			break;
		case "view" :
			$titre = "DETAIL ARTICLE";
			break;
		case "del" :
			$titre = "SUPPRESSION ARTICLE";
			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 - ESPACE PRIVE : Fiche Article</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 -->
<link href="../inc/menu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="../coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour affichages -->
<script language="JavaScript" src="../inc/aff.js"></script>

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

<script language="javascript">
var tab1_champ=new Array(
	"nom:code ; format:alphanum ; req:Y ; txt:Code ; lmx:20 ; stok:frmok ; stbad:frmbad",
<?PHP if (($td == "add") OR ($td == "edit"))
{ 
?>
	"nom:fam ; format:liste ; req:Y ; txt:Famille ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
}
else
{
?>
	"nom:fam ; format:txt ; req:Y ; txt:Famille ; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:des; format:txt ; req:Y ; txt:Désignation ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:det; format:txt ; req:N ; txt:Détail ; lmx:70 ; stok:frmok ; stbad:frmbad",
	"nom:pu; format:reel_ns ; req:Y ; txt:PU TTC ; lmx:10 ; stok:frmok ; stbad:frmbad");
</script>

</head>

<body>

<?php 
	include_once ("../inc/entete.php"); 
?>

<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<!-- Affiché uniquement s'il y a au moins famille -->
<?PHP
if (nb_fam() <> 0)
{
?>
<table width="100%"  border="0">
  <tr>
    <td width="33%"><strong><em><a href="pdt_lst.php?ta=m">Retour &agrave; la liste</a></em></strong></td>
    <td width="33%" bgcolor="#FF0000"><div align="center"><span class="titrerubrique1">Descriptif</span></div></td>
    <td width="33%"><div align="right"><strong><em></em> </strong></div></td>
  </tr>
</table>
<div align="center">
    <span class="annot_gras_it">(<img src="../img/oblig.gif" width="10" height="11"> : Saisie obligatoire)</span>
</div>
<form name="pdt_maj" id="pdt_maj" method="post" action="pdt_enr.php" onSubmit="javascript:; return (VForm(this,tab1_champ,''));">
      <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
      <input name="typdde" type="hidden" id="typdde" value="<?PHP echo $td ?>">

<table width="100%"  border="0">
    <tr>
      <td width="20%" class="rubfrm" id="f_code"><div align="right">Code</div></td>
      <td>
      <?PHP if ($td == "add") { ?>
		  <input name="code" type="text" id="code" value="<?PHP echo $pdt_code ?>" size="20" maxlength="20" onChange="javascript:this.value=this.value.toUpperCase();">
          <img src="../img/oblig.gif" width="10" height="11">
      <?PHP } else { ?>
		  <input name="code" type="text" id="code" value="<?PHP echo $pdt_code ?>" size="20" maxlength="20" readonly="1">
      <?PHP } ?>
	  </td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_fam"><div align="right">Famille</div></td>
      <td>
      <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
	  		<select name="fam" size="1" id="fam">
          <?PHP
				echo "<option>-- Choisissez une famille --</option>";
				
				// Création de la liste des familles
	
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query("SELECT * FROM ".TBFAM." ORDER BY fam_desc");

				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($pdt_fam == $fam_code)
					{
						echo '<option value="'.$fam_code.'" selected>'.$fam_desc.'</option>';
					}
					else
					{
						echo '<option value="'.$fam_code.'">'.$fam_desc.'</option>';
					}
					
					$i++;
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
        	</select>
      		<img src="../img/oblig.gif" width="10" height="11">
	  	<?PHP
		}
		else
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBFAM." WHERE `fam_code`= '".$pdt_fam."'";
			$rs = mysql_query($rech);
			if (mysql_num_rows($rs) == 1) // Uniquement UN SEUL enregistrement !
			{
				if ($row = mysql_fetch_array($rs)) 
				{
					extract ($row);
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);
		?>
			<input name="fam" type="text" id="fam" value="<?PHP echo $fam_desc ?>" size="50" maxlength="50" readonly="1">
		<?PHP
		}
		?>
		</td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_des"><div align="right">D&eacute;signation</div></td>
      <td>
      <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		<input name="des" type="text" id="des" value="<?PHP echo htmlspecialchars($pdt_des) ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();"> <img src="../img/oblig.gif" width="10" height="11">
	  <?PHP
	  }
	  else
	  {
	  ?>
		<input name="des" type="text" id="des" value="<?PHP echo htmlspecialchars($pdt_des) ?>" size="50" maxlength="50" readonly="1"> 
	  <?PHP
	  }
	  ?>
	  </td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_det"><div align="right">D&eacute;tail</div></td>
      <td>
      <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		<input name="det" type="text" id="det" value="<?PHP echo htmlspecialchars($pdt_detail) ?>" size="70" maxlength="70">
	  <?PHP
	  }
	  else
	  {
	  ?>
		<input name="det" type="text" id="det" value="<?PHP echo htmlspecialchars($pdt_detail) ?>" size="70" maxlength="70" readonly="1"> 
	  <?PHP
	  }
	  ?>
	  </td>
    </tr>
    <tr>
      <td width="20%" class="rubfrm" id="f_pu"><div align="right">PU TTC </div></td>
      <td>
      <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		<input name="pu" type="text" id="pu" align="right" value="<?PHP echo $pdt_puttc ?>" size="10" maxlength="10"> 
		<img src="../img/oblig.gif" width="10" height="11"><br>
		<span class="annot_std_it">(la d&eacute;cimale doit &ecirc;tre '</span><span class="annot_gras_it">.</span><span class="annot_std_it">' et pas la virgule !)</span>
	  <?PHP
	  }
	  else
	  {
	  ?>
		<input name="pu" type="text" id="pu" align="right" value="<?PHP echo $pdt_puttc ?>" size="10" maxlength="10" readonly="1"> 
	  <?PHP
	  }
	  ?>
      </td>
    </tr>
    <tr>
      <td class="rubfrm" id="f_vente"><div align="right">Commercialis&eacute;</div></td>
      <td>
	  <?PHP 
		if (($td == "add") OR ($td == "edit"))
		{ 
			if ($td == "add")
			{ 
				echo "<select name=\"vendu\" size=\"1\" id=\"vendu\">";
				echo "<option value=\"Oui\" selected>Oui</option>";
				echo "<option value=\"Non\">Non</option>";
				echo "</select>";
			}
			
			if ($td == "edit")
			{ 
				if ($pdt_vendu == TRUE)
				{
				echo "<select name=\"vendu\" size=\"1\" id=\"vendu\">";
				echo "<option value=\"Oui\" selected>Oui</option>";
				echo "<option value=\"Non\">Non</option>";
				echo "</select>";
				}
				else
				{
				echo "<select name=\"vendu\" size=\"1\" id=\"vendu\">";
				echo "<option value=\"Oui\">Oui</option>";
				echo "<option value=\"Non\" selected>Non</option>";
				echo "</select>";
				}
			}
		?>
			<img src="../img/oblig.gif" width="10" height="11">
	  <?PHP 
	  	}
		
		if (($td == "del") OR ($td == "view"))
		{ 
			if ($pdt_vendu == TRUE)
			{
		?>
				<input name="vendu" type="text" id="vendu" value="Oui" size="3" maxlength="3" readonly="1">
		<?PHP
			}
			else
			{
		?>
				<input name="vendu" type="text" id="vendu" value="Non" size="3" maxlength="3" readonly="1">
		<?PHP
			}
		}
		?>
	</td>
    </tr>
  </table>
  <p align="center">
    <?PHP if (($td == "add") OR ($td == "edit")) { ?>
    <input name="RAZ" type="reset" id="RAZ" value="R&eacute;initialiser">
    <input name="submit" type="submit" id="submit" value="Enregistrer">
    <?PHP } ?>
    <?PHP if ($td == "del") { ?>
    <input name="del" type="submit" id="del" value="Supprimer">
    <input name="annul" type="button" id="annul" value="Annuler" onclick="javascript:; history.back();">
    <?PHP } ?>
    <?PHP if ($td == "view") { ?>
    <input name="annul" type="button" id="annul" value="Retour Liste" onclick="javascript:; history.back();">
    <?PHP } ?>
  </p>
</form>
<p>&nbsp;</p>
<?PHP if ($td == "del") 
{
?>
	<script>
	warndelage();
	</script>
<?PHP
}
?>
<!-- Fin Affiché uniquement s'il y a au moins une famille article -->
<?PHP
}
else
{
?>
	<script type="text/javascript">
	setTimeout("self.location.href=('fam_lst.php');",2000)
	</script>
	<p align="center" class="annot_std_it">Merci de cr&eacute;er au moins une famille...</p>
    <?PHP
}
?>

<?php 
	include_once ("pied.php")
?>
