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

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
****************************************************************************************/

include ("../inc/config.inc.php");
?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_date.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php require ("../inc/fic.inc.php") ?>
<?php require ("../inc/lst.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$td = strip_tags(trim($_GET['td'])); // Récupération type demande
	$tr = strip_tags(trim($_GET['tr'])); // Récupération type Relevé (1 = Licence, 2 = Matériel)
	$cr = strip_tags(trim($_GET['cr'])); // Récupération code Relevé
	$id = strip_tags(trim($_GET['id'])); // Récupération code ID
	$cap = strip_tags(trim($_GET['cap'])); // Code Appelant (0 = Dossier Relevé, 1 = Fiche Relevé)

	if ($cr <> "")
	{
		if ($tr == 1)
		{
			// Récupération des informations relevé licence
			$row = lit_enr_rlic($cr);
			if (is_array($row))
				extract ($row);
				
			$datecfich = formatedate($rlic_daterel);
			$coderel = $rlic_coderel;
			$code = $rlic_code;
			$daterel = $rlic_daterel;
			$codecli = $rlic_codecli;

			// Récupération de la marque marque et du type de licence
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBRLPMA." WHERE `rlpma_code` = '".$rlic_codema."'";
			$rs = mysql_query($rech)or die(mysql_error());
			if ($row = mysql_fetch_array($rs))
				extract ($row);
			$rech = "SELECT * FROM ".TBRLTL." WHERE `rltl_code` = '".$rlic_codetl."'";
			$rs = mysql_query($rech)or die(mysql_error());
			if ($row = mysql_fetch_array($rs))
				extract ($row);
			mysql_free_result($rs);
			mysql_close($conn);

			$descr = "<b>".$rlpma_desc."</b> : ".$rlic_modele." ".$rlic_version." (".$rltl_desc.")";
		}
		
		if ($tr == 2)
		{
			// Récupération des informations relevé produit
			$row = lit_enr_rpdt($cr);
			if (is_array($row))
				extract ($row);
	
			$datecfich = formatedate($rpdt_daterel);
			$coderel = $rpdt_coderel;
			$code = $rpdt_code;
			$daterel = $rpdt_daterel;
			$codecli = $rpdt_codecli;

			// Récupération de la catégorie et de la marque
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBRPCAT." WHERE `rpcat_code` = '".$rpdt_codecat."'";
			$rs = mysql_query($rech)or die(mysql_error());
			if ($row = mysql_fetch_array($rs))
				extract ($row);
			$rech = "SELECT * FROM ".TBRLPMA." WHERE `rlpma_code` = '".$rpdt_codema."'";
			$rs = mysql_query($rech)or die(mysql_error());
			if ($row = mysql_fetch_array($rs))
				extract ($row);
			mysql_free_result($rs);
			mysql_close($conn);

			$descr = "<b>".$rpcat_desc."</b> : ".$rlpma_desc." / ".$rpdt_modele." <span class=\"annot_std_it\">(".$rpdt_ns.")<br>".$rpdt_codep." - ".$rpdt_empl."</span>";
		}

		$row = lit_enr_rel($coderel);
		if (is_array($row))
			extract ($row);

		$datedrel = formatedate($rel_datecrea);

		$row = lit_enr_rpbm($id);
		if (is_array($row))
			extract ($row);
		$datecreaf = formatedate($rpbm_datecrea);
		$datettf = formatedate($rpbm_datett);

		if ($td == "view")
			$titre = "VOIR DECLARATION DE PROBLEME";

		if ($td == "edit")
			$titre = "MISE A JOUR DECLARATION DE PROBLEME";

		if ($td == "del")
			$titre = "SUPPRESSION DECLARATION DE PROBLEME";

		if ($td == "add")
			$titre = "DECLARATION DE PROBLEME";

	}

	if ($codecli <>"")
	{
			$row = lit_enr_cli($codecli);
			extract ($row);
			
			$rpbm_codecli = $codecli;
	}
?>

<!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 : D&eacute;claration de Probl&egrave;me</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../inc/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 validation des formulaires -->
<script language="JavaScript" src="../inc/validator.js"></script>

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

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

<!-- Définition Javascript pour calendrier popup -->

  <!-- Feuille de Style -->
  <link rel="stylesheet" type="text/css" media="all" href="../jscal/skins/aqua/theme.css" title="Aqua" />

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

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscal/lang/calendar-fr.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="../jscal/calendar-setup.js"></script>

<!-- Fin de la définition Javascript pour calendrier popup -->

<!-- Affichage nouvelle fenêtre pour impression -->
<script type="text/javascript">
	function lanceimp(page)
	{
	  window.open(page,'impression','width='+screen.width+' height='+screen.height);
	}
</script>

<!-- Fonction afficher/cacher un bloc div -->
<script type="text/javascript">
	function display(idobjet,etat)
	{
		var objet = document.getElementById(idobjet);
		etat = objet.style.display;
		if (etat == 'none')
			objet.style.display = 'block';
		else
			objet.style.display = 'none';
	}
</script>

</head>

<?PHP if ($td == "del"){ ?>
<body onload=warndel();>
<?PHP } else { ?>
<body>
<?PHP } ?>

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

<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<table width="100%"  border="0">
<tr>
	<td width="33%">
	<span class="annot_gras_it">
	<?PHP
	if (@$HTTP_SESSION_VARS["niv_log"] <> 1)
	{
	?>
		<a href="rel_maj.php?td=edit&cr=<?PHP echo $coderel; ?>">Retour au dossier de relev&eacute;</a></span> ou 
	<?PHP
	}
	else
	{
	?>
		<a href="rel_maj.php?td=view&cr=<?PHP echo $coderel; ?>">Retour au dossier de relev&eacute;</a></span> ou 
	<?PHP
	}
	?>
	<?PHP if ($tr == 1)
	{
		if (@$HTTP_SESSION_VARS["niv_log"] <> 1)
		{
	?>
			<span class="annot_gras_it"><a href="rlic_maj.php?td=edit&crl=<?PHP echo $code; ?>">&agrave; la fiche licence</a></span>
	<?PHP 
		}
		else
		{
	?>
			<span class="annot_gras_it"><a href="rlic_maj.php?td=view&crl=<?PHP echo $code; ?>">&agrave; la fiche licence</a></span>
	<?PHP
		}
	} 
	else
	{ 
		if (@$HTTP_SESSION_VARS["niv_log"] <> 1)
		{
	?>
			<span class="annot_gras_it"><a href="rpdt_maj.php?td=edit&crp=<?PHP echo $code; ?>">&agrave; la fiche mat&eacute;riel</a></span>
	<?PHP 
		}
		else
		{
	?>
			<span class="annot_gras_it"><a href="rpdt_maj.php?td=view&crp=<?PHP echo $code; ?>">&agrave; la fiche mat&eacute;riel</a></span>
	<?PHP
		}
	} 
	?>
    </td>
	<td width="33%" valign="top"><div align="center"><span class="annot_gras_it">(<img src="../img/oblig.gif" width="10" height="11"> : Saisie obligatoire)</span> </div></td>
	<td width="33%"><div align="right">
		<div align="right">
		<?PHP
			if ($td == "edit")
			{
			$urlimp = "rpbm_pdf.php?code=".$cr;
			?>
			<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")><img src="../img/print.gif" title="Imprimer relev&Eacute;" width="22" height="22" border="0" align="absmiddle"></a> 
			<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")> Imprimer le relev&eacute; </a></div>
		<?PHP } ?>
		</div>
	</td>
</tr>
</table>
<br>

<form name="rpbm_maj" method="post" action="rpbm_enr.php" onsubmit="return v.exec();">
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="typdde" type="hidden" id="typdde" value="<?PHP echo $td ?>">
<input name="typrel" type="hidden" id="typrel" value="<?PHP echo $tr ?>">
<input name="coderel" type="hidden" id="coderel" value="<?PHP echo $coderel ?>">
<input name="id" type="hidden" id="id" value="<?PHP echo $id ?>">
<input name="code" type="hidden" id="code" value="<?PHP echo $code ?>">
<input name="codecli" type="hidden" id="codecli" value="<?PHP echo $rpbm_codecli ?>">
<input name="cap" type="hidden" id="cap" value="<?PHP echo $cap ?>">


<!-- Code du relevé client (affiché uniquement si édition ou suppression) -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_coderlic"><div align="right">Code fiche relev&eacute; </div></td>
	<td>
		<span class="annot_std_gras"><?PHP echo $code; ?></span>
		<span class="annot_petit_it">(Fiche de relev&eacute; cr&eacute;&eacute;e le <?PHP echo $datecfich ?>)</span>
	</td>
</tr>
</table>

<!-- N° Dossier & Date de création -->
<table width="800"  border="0">
<tr>
	<td class="annot_petit_it">
		Appartient au dossier de relev&eacute; <?PHP echo $coderel; ?>, cr&eacute;&eacute; le <?PHP echo $datedrel; ?>
	</td>
</tr>
</table>

<!-- Affichage du client -->
<table width="800"  border="0">
<tr>
	<td width="400" class="tfvNormal" colspan="2"  id="f_codecli">
		<div align="center">Client</div>
	</td>
	</tr>
</table>

<!-- Détails client -->
<table width="800"  border="0">
<tr>
	<td width="400" valign="top" bgcolor="#CCFFCC">
	<?PHP
	if (($cli_ste <>"") OR ($cli_nom <> ""))
		echo "<img src=\"../img/".$ico_cpta[$cli_cpta]."\" title =\"".$mess_cpta[$cli_cpta]."\" width=\"".$hl_vign."\" height=\"".$hl_vign."\" border=\"0\" align=\"absmiddle\">";
	echo "<b>";
	if ($cli_ste <>"") 
	{
		echo $cli_ste."<br>";
		echo "<span class=\"annot_gras_it\">";
	}
	echo $cli_civilite." ".$cli_prenom." ".$cli_nom."<br>";
	if ($cli_ste <>"") 
	{
		echo "</span>";
	}
	echo "</b>";
	echo $cli_adr1."<br>";
	if ($cli_adr2 <>"") 
		echo $cli_adr2."<br>";
	echo Retournecp($cli_ville)." ".Retourneville($cli_ville)."<br>";
	echo "Tel : ".$cli_telf."<br>";
	?>
	</td>
	</tr>
</table>

<!-- Descriptif rapide de la licence ou du produit concerné -->
<table width="800"  border="0">
<tr>
	<td width="400" class="tfvNormal" colspan="2"  id="f_codecli">
		<div align="center">
		<?PHP if ($tr == 1) { ?>
			Licence Concern&eacute;e
		<?PHP }
			if ($tr == 2) { ?>
			Mat&eacute;riel Concern&eacute;
		<?PHP } ?>
		</div>
	</td>
	</tr>
</table>

<table width="800"  border="0">
<tr>
    <td width="160" valign="top" class="tfvNormal">
		<div align="right">
		<?PHP if ($tr == 1) { ?>
			Licence
		<?PHP }
			if ($tr == 2) { ?>
			Mat&eacute;riel (ns)<br>
			Code - empl.
		<?PHP } ?>
		</div>
	</td>
	<td>
		<?PHP echo $descr ?>
	</td>
</tr>
</table>

<!-- Délai du problème rencontré -->
<table width="800"  border="0">
<tr>
	<td width="400" class="tfvNormal" colspan="2">
		<div align="center">D&eacute;tail du probl&egrave;me rencontr&eacute; </div>
	</td>
	</tr>
</table>

<!-- Descriptif du problème -->
<table width="800"  border="0">
  <tr>
    <td width="160" valign="top" class="tfvNormal" id="f_pbm"><div align="right">Probl&egrave;me d&eacute;taill&eacute;</div></td>
    <td>
	<?PHP if ($td <> "view") { ?>
		<textarea name="pbm" cols="95" rows="5" id="pbm"><?PHP echo $rpbm_pbm ?></textarea>
	  <img src="../img/oblig.gif" width="10" height="11"><br>
	  <span class="annot_petit_it">D&eacute;tailler pr&eacute;cis&eacute;mment le probl&egrave;me pour qu'il soit plus facile &agrave; r&eacute;soudre.<br>
	  S'il s'agit d'une licence, indiquer sur quel mat&eacute;riel se produit le probl&egrave;me. </span>
	<?PHP } else { ?>
		<textarea name="pbm" cols="95" rows="5" id="pbm" readonly><?PHP echo $rpbm_pbm ?></textarea>
	<?PHP } ?>
	</td>
  </tr>
</table>

<!-- Date détection -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_datecreaf"><div align="right">D&eacute;tect&eacute; le </div></td>
	<td>
		<input name="datecreaf" type="text" id="datecreaf" value="<?PHP echo $datecreaf ?>" size="10" maxlength="10" readonly="1">
		<?PHP if ($td <> "view") { ?>
		<img src="../img/calendar.png" id="f_img_datecreaf" title="Choisir votre date" width="16" height="16">
		<img src="../img/oblig.gif" width="10" height="11">
		<span class="annot_std_it">(
		<a href="javascript:;" onClick="document.rpbm_maj.datecreaf.value=''"><img src="../img/raz.gif" width="12" height="12" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="document.rpbm_maj.datecreaf.value=''")> Annuler</a> )</span>
		<?PHP } ?>
	</td>
</tr>
</table>

<!-- Qui a détecté le problème ?-->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_signale">
		<div align="right">D&eacute;t&eacute;ct&eacute; par </div>
	</td>
    <td>
	<?PHP if ($td <> "view") { ?>
		<input name="signale" type="text" id="signale" value="<?PHP echo $rpbm_signale ?>" size="50" maxlength="50"> 
	  <img src="../img/oblig.gif" width="10" height="11"><br>
	  <span class="annot_petit_it">Entrer le pr&eacute;nom et le nom de personne ayant d&eacute;tect&eacute; le probl&egrave;me. </span>
	<?PHP } else { ?>
		<input name="signale" type="text" id="signale" value="<?PHP echo $rpbm_signale ?>" size="50" maxlength="50" readonly="1"> 
	<?PHP } ?>
	</td>
</tr>
</table>

<?PHP if ($td <> "add") { ?>
<!-- Détail du traitement -->
<table width="800"  border="0">
<tr>
	<td width="400" class="tfvNormal" colspan="2"  id="f_codecli">
		<div align="center">Pour info : Op&eacute;ration en cours ou effectu&eacute;e</div>
	</td>
	</tr>
</table>


<!-- Date traitement-->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_datettf"><div align="right">Trait&eacute; le </div></td>
	<td>
		<input name="datettf" type="text" id="datettf" value="<?PHP echo $datettf ?>" size="10" maxlength="10" readonly="1">
	</td>
</tr>
</table>

<!-- Travail effectué-->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_fait"><div align="right">Travail effectu&eacute; </div></td>
	<td>
		<textarea name="fait" cols="95" rows="5" id="fait" readonly><?PHP echo $rpbm_fait ?></textarea>
	</td>
</tr>
</table>

<!-- Intervention -->
<table width="800"  border="0">
<tr>
	<td width="160" class="tfvNormal" id="f_codeint"><div align="right">Intervention </div></td>
	<td>
		<input name="codeint" type="text" id="codeint" value="<?PHP echo $rpbm_codeint ?>" size="20" maxlength="20" readonly="1">
	</td>
</tr>
</table>

<?PHP } ?>

<p align="center">
<?PHP 
if (($td == "edit") or ($td == "add")) // Boutons si en édition ou création
{ 
?>
	<input name="RAZ" type="reset" id="RAZ" value="R&eacute;initialiser">
	<input name="enr" type="submit" id="enr" value="Enregistrer">
<?PHP 
} 
?>

<?PHP 
if ($td == "del") // Bouton si en mode suppression
{ 
?>
	<input name="del" type="submit" id="del" value="Supprimer">
<?PHP 
} 
?>
</p>
</form>
<?PHP
if ($td == "add")
{
?>
	  <script type="text/javascript">
		Calendar.setup({
			inputField     :    "datecreaf",     // id of the input field
			ifFormat       :    "%d-%m-%Y",      // format of the input field
			button         :    "f_img_datecreaf",  // trigger for the calendar (button ID)
			align          :    "Ll",           // alignment (defaults to "Bl")
			singleClick    :    true
		});
	</script>
<?PHP
}
?>	
	<script>
	// form fields description structure
	var a_fields = {
		'pbm':{'l':'Problème détaillé','r':true,'t':'f_pbm'},
		'datecreaf':{'l':'Détecté le','r':true,'f':'date','t':'f_datecreaf'},
		'signale':{'l':'Signalé par','r':true,'t':'f_signale'},
	},
	
	o_config = {
		'to_disable' : ['enr', 'RAZ'],
		'alert' : 1
	}
	
	// validator constructor call
	var v = new validator('rpbm_maj', a_fields, o_config);
	</script>

<script type="text/javascript">
warnedit(<?PHP echo $cli_cpta; ?>,"cont");
</script>
