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

session_start(); 
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/func_log.inc.php");
if (CheckURLLog(FALSE)==FALSE) header("Location: ../index.php");
if (CheckNivLog("5-9")==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/fic_co.inc.php");
include_once("../inc/fic_txt.inc.php");
include_once("../classes/fckeditor/fckeditor.php");

Archivelog(@$_SESSION["code_log"]);

$td = strip_tags(trim($_GET['td']));
$coderech = strip_tags(trim($_GET['code']));

$pbm_co=FALSE;

if ($coderech <> "")
{
	// Récupération des informations contrat
	$row = lit_enr_co($coderech);
	if (is_array($row))
	{
		extract ($row);
	
		if ($td == "add")
		{
			$co_code = "(2)".$coderech;
			$co_code = substr($co_code,0,10); // Le code ne doit pas dépasser 10 caractères
			$co_nom = ""; // RAZ du nom pour nouveau nom
		}
	}
	else
		$pbm_co=TRUE;
}
else
{
	if ($td == "add")
	{
		// Récupération du texte "master" des conditions générales de vente pour les contrats
		
		$row = lit_enr_txt("CON_CGV_MASTER");
		extract($row);
		
		$co_cgv = $txt_texte;
	}
	else
		$pbm_co=TRUE;
}

switch ($td)
{
	case "add" :
		$titre = $titlein_co_maj_add;
		break;
	case "edit" :
		$titre = $titlein_co_maj_edit;
		break;
	case "del" :
		$titre = $titlein_co_maj_del;
		break;
	default :
		$pbm_co=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; ?> : <?PHP echo $title_co_maj; ?></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>

<script language="javascript">
<!--
var tab1_champ=new Array(
	"nom:code ; format:alphanum ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_code); ?>; lmx:20 ; stok:frmok ; stbad:frmbad",
	"nom:nom ; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_nom); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:desc ; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_lib); ?>; stok:frmok ; stbad:frmbad");
//-->
</script>

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

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

</head>
<?PHP if ($td == "del") 
{
?>
<body onLoad="warndelco();metReadonly();">
<?PHP
}
else
{
?>
<body onLoad="metFocus();">
<?PHP }
include_once("../inc/entete.inc.php"); 

if ($pbm_co==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<table width="100%"  border="0">
<tr>
	<td width="33%"><strong><em><a href="co_lst.php"><?PHP echo $txt_lnk_ret_liste; ?></a></em></strong></td>
	<td width="33%">&nbsp;</td>
	<td width="33%">
		<div align="right">
		<?PHP
		if ($td == "edit")
		{
			$urlimp = "co_maji.php?code=".$coderech;
		?>
			<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")><img src="../img/print.png" title="<?PHP echo $alt_impfic; ?>" border="0" align="absmiddle"></a> <a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp; ?>');")> <?PHP echo $txt_lnk_imp_fic; ?></a></div>
		<?PHP } ?>
		</div>
	</td>
</tr>
</table>
<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>
<form name="co_maj" id="co_maj" method="post" action="co_enr.php" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
      <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
      <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">

<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_code" align="right"><?PHP echo $txt_chp_code; ?></td>
	<td>
	<?PHP if ($td == "add") { ?>
		<input name="code" type="text" id="code" value="<?PHP echo $co_code ?>" size="10" onChange="javascript:this.value=this.value.toUpperCase();">
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP } else { ?>
		<input name="code" type="text" id="code" value="<?PHP echo $co_code ?>" size="10" readonly="1">
	<?PHP } ?>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_nom" align="right"><?PHP echo $txt_chp_nom; ?></td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{
		?>
			<input name="nom" type="text" id="nom" value="<?PHP echo htmlspecialchars($co_nom) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();"> 
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP
		}
		else
		{
		?>
			<input name="nom" type="text" id="nom" value="<?PHP echo htmlspecialchars($co_nom) ?>" size="50" readonly="1"> 
		<?PHP
		}
		?>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_desc" align="right"><?PHP echo $txt_chp_lib; ?></td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{
		?>
			<textarea name="desc" rows="5" id="desc"><?PHP echo htmlspecialchars($co_desc) ?></textarea>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP
		}
		else
		{
		?>
			<textarea name="desc" rows="5" readonly="readonly" id="desc"><?PHP echo htmlspecialchars($co_desc) ?></textarea>
		<?PHP
		}
		?>
	</td>
</tr>
<tr>
	<td valign="top" class="rubfrm" id="f_cgv" align="right"><?PHP echo $txt_chp_cocgv; ?></td>
	<td valign="top">
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{
			$sBasePath = $_SERVER['PHP_SELF'] ;
			$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "admin" ) ).'classes/fckeditor/' ;
			
			$oFCKeditor = new FCKeditor('FCKeditor1') ;
			$oFCKeditor->BasePath	= $sBasePath;
			$oFCKeditor->Value		= $co_cgv;
			$oFCKeditor->Height 	= '400';
			$oFCKeditor->ToolbarSet = 'SMI';
			$oFCKeditor->Create();
		?>
        <img src="../img/oblig.png" align="absmiddle" align="top"> 
		<?PHP
		}
		else
		{
		?>
			<textarea name="texte" rows="10" readonly="readonly" id="texte"><?PHP echo htmlspecialchars($co_cgv) ?></textarea>
		<?PHP
		}
		?>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_actif" align="right"><?PHP echo $txt_chp_actif; ?></td>
<td>
	<?PHP 
	if ($td == "add")
	{ 
		echo "<select name=\"actif\" size=\"1\" id=\"actif\">";
		echo "<option value=\"1\">".$sel_lst_oui."</option>";
		echo "<option value=\"0\" selected>".$sel_lst_non."</option>";
		echo "</select>";
	}
	
	if (($td == "edit") OR ($td == "del"))
	{ 
		if ($co_actif == TRUE)
		{
			echo "<select name=\"actif\" size=\"1\" id=\"actif\">";
			echo "<option value=\"1\" selected>".$sel_lst_oui."</option>";
			echo "<option value=\"0\">".$sel_lst_non."</option>";
			echo "</select>";
		}
		else
		{
			echo "<select name=\"actif\" size=\"1\" id=\"actif\">";
			echo "<option value=\"1\">".$sel_lst_oui."</option>";
			echo "<option value=\"0\" selected>".$sel_lst_non."</option>";
			echo "</select>";
		}
	}
	?>
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> </td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_actif" align="right"><?PHP echo $txt_chp_spec; ?></td>
<td>
	<?PHP 
	if ($td == "add")
	{ 
		echo "<select name=\"specif\" size=\"1\" id=\"specif\">";
		echo "<option value=\"1\">".$sel_lst_oui."</option>";
		echo "<option value=\"0\" selected>".$sel_lst_non."</option>";
		echo "</select>";
	}
	
	if (($td == "edit") OR ($td == "del"))
	{ 
		if ($co_specif == TRUE)
		{
			echo "<select name=\"specif\" size=\"1\" id=\"specif\">";
			echo "<option value=\"1\" selected>".$sel_lst_oui."</option>";
			echo "<option value=\"0\">".$sel_lst_non."</option>";
			echo "</select>";
		}
		else
		{
			echo "<select name=\"specif\" size=\"1\" id=\"specif\">";
			echo "<option value=\"1\">".$sel_lst_oui."</option>";
			echo "<option value=\"0\" selected>".$sel_lst_non."</option>";
			echo "</select>";
		}
	}
	?>
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> <br>
	<span class="annot_petit_it"><?PHP echo $txt_div_cospec; ?></span></td>
</tr>
</table>
<p align="center">
<?PHP if (($td == "add") OR ($td == "edit")) { ?>
	<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
	<input name="submit" type="submit" class="bton_std" id="submit" value="<?PHP echo $but_enr; ?>">
<?PHP } ?>
<?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:; history.back();">
<?PHP } ?>
</p>
</form>
<?PHP
}
else
	aff_ret_pbm_auto("co_lst.php",2000);
include_once("pied.php")
?>
