<?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(TRUE)==FALSE) header("Location: ../index.php");
if (CheckNivLog("5-9")==FALSE) header("Location: ../index.php");
include_once("../inc/fic_txt.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_txtcm.inc.php");
include_once("../inc/func_mail.inc.php");
include_once("../classes/phpmailer/class.phpmailer.php");
include_once("../inc/mail.inc.php");

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

// Variables Formulaire
$titre = stripslashes(strip_tags(trim(@$_POST["titre"])));
$creation = strip_tags(trim(@$_POST["creation"]));

$code = strip_tags(str_escape(trim(@$_POST["code"])));
$pass = strip_tags(str_escape(trim(@$_POST["pass"])));
				
$nom = str_majuscules(str_escape(trim(@$_POST["nom"])));
$rcs = str_majuscules(str_escape(trim(@$_POST["rcs"])));
$ape = str_majuscules(str_escape(trim(@$_POST["ape"])));
$tvai = str_majuscules(str_escape(trim(@$_POST["tvai"])));
$tcom = str_majuscules(str_escape(trim(@$_POST["tcom"])));
$adr1 = str_majuscules(str_escape(trim(@$_POST["adr1"])));
$adr2 = str_majuscules(str_escape(trim(@$_POST["adr2"])));
$dep = strip_tags(trim(@$_POST["dep"]));
$ville = str_majuscules(strip_tags(trim(@$_POST["ville"])));
$pays = str_majuscules(strip_tags(trim(@$_POST["pays"])));
$telf = strip_tags(trim(@$_POST["telf"]));
$txttelf = strip_tags(str_escape(trim(@$_POST["txttelf"])));
$fax = strip_tags(trim(@$_POST["fax"]));
$txtfax = strip_tags(str_escape(trim(@$_POST["txtfax"])));
$web = strip_tags(trim(@$_POST["web"]));
$heures = str_escape(trim(@$_POST["heures"]));
$email = strtolower(strip_tags(trim(@$_POST["email"])));
$emaild = strtolower(strip_tags(trim(@$_POST["emaild"])));
$emailc = strtolower(strip_tags(trim(@$_POST["emailc"])));
$emailt = strtolower(strip_tags(trim(@$_POST["emailt"])));
$emailf = strtolower(strip_tags(trim(@$_POST["emailf"])));
$emaili = strtolower(strip_tags(trim(@$_POST["emaili"])));
$emailrh = strtolower(strip_tags(trim(@$_POST["emailrh"])));
$nota = str_escape(trim(@$_POST["nota"]));

$retourliste = FALSE;
$cree = FALSE;

// MAJ de la fiche centre de gestion

$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);
$rsge = "SELECT * FROM " .TBCG;
$rssge = mysql_query($rsge) or die(mysql_error());

if (mysql_num_rows($rssge) == 1) // Uniquement UN SEUL enregistrement !
{
	if ($row = mysql_fetch_array($rssge)) 
	{
		$rech = "UPDATE `" .TBCG. "` SET `cge_datemod`='".$datea."',`cge_nom`='".$nom."', `cge_rcs`='".$rcs."',";
		$rech.= " `cge_ape`='".$ape."', `cge_tvai`='".$tvai."', `cge_tcom`='".$tcom."', `cge_adr1`='".$adr1."',";
		$rech.= " `cge_adr2`='".$adr2."', `cge_dep`='".$dep."', `cge_ville`='".$ville."', `cge_codepays`='".$pays."',";
		$rech.= " `cge_telf`='".$telf."', `cge_txttelf`='".$txttelf."', `cge_fax`='".$fax."', `cge_txtfax`='".$txtfax."',";
		$rech.= " `cge_email`='".$email."', `cge_emaild`='".$emaild."', `cge_emailc`='".$emailc."', `cge_emailt`='".$emailt."',";
		$rech.= " `cge_emailf`='".$emailf."', `cge_emaili`='".$emaili."',`cge_emailrh`='".$emailrh."', `cge_heures`='".$heures."',";
		$rech.= " `cge_web`='".$web."', `cge_nota`='".$nota."'  WHERE `cge_id` = '".$row["cge_id"]."'";
		$rs = mysql_query($rech) or die(mysql_error());
		$msg = $txt_fiche_mod;
		$retourliste = TRUE;
	}
}

if (mysql_num_rows($rssge) == 0) // N'existe pas, donc créé
{
	$passcrypt = md5($pass);

	$rech = "INSERT INTO " .TBCG;
	$rech.= " (cge_datemod,cge_code,cge_pass,cge_nom,cge_rcs,cge_ape,cge_tvai,cge_tcom,cge_adr1,cge_adr2,cge_dep,cge_ville,cge_codepays,";
	$rech.= "cge_telf,cge_txttelf,cge_fax,cge_txtfax,cge_email,cge_emaild,cge_emailc,cge_emailt,cge_emailf,cge_emaili,cge_emailrh,";
	$rech.= "cge_heures,cge_web,cge_nota) VALUES";
	$rech.= " ('$datea','$code','$passcrypt','$nom','$rcs','$ape','$tvai','$tcom','$adr1','$adr2','$dep','$ville','$pays','$telf',";
	$rech.= "'$txttelf','$fax','$txtfax','$email','$emaild','$emailc','$emailt','$emailf','$emaili','$emailrh','$heures','$web','$nota')";
	$rs = mysql_query($rech) or die(mysql_error());
	$msg = $txt_fiche_add;
	$retourliste = TRUE;

	// Ajout du compte pour connexion
	// Niveau par défaut : 5
	// Actif par défaut
		
	$log_ip = $_SERVER['REMOTE_ADDR']; // Récupération adresse IP
	$rech2 = "INSERT INTO " .TBPW. "(pw_code,pw_pass,pw_level,pw_lastsuccess,pw_lastip,pw_actif) VALUES ('$code','$passcrypt','5','$datehcrea','$log_ip','1')";
	$rs2 = mysql_query($rech2) or die(mysql_error());

	$cree = TRUE;
}

mysql_free_result($rssge);
mysql_close($conn);

if ($cree == TRUE)
{
	// Envoi d'email vers l'agence
	envoi_mail("","Création du siège","cdg","cre","xxx","cdg",$codea,$pass,"",TRUE);
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - <?PHP echo $title_esp_prive; ?> : <?PHP echo $title_cge_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>

</head>
<body>

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


<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">&nbsp;</p>
<p align="center">
<?PHP if ($retourliste==FALSE)
	echo '<span class="alerte1">';
else
	echo '<span class="annot_std_gras">';
?>
<?PHP echo $msg ?>
</span>
</p>


<?PHP 
if ($retourliste == FALSE)
	aff_ret_idx_man($td,"cge_maj.php",$txt_lnk_ret_saisie,FALSE);
else 
{
	$url_retour="index.php";
	if ($creation == 1)
	{
		$url_retour="logo_maj.php?td=cge";
		echo '<p align="center" class="annot_gras_it">Merci de t&eacute;l&eacute;charger le logo du centre de gestion</p>';
		aff_ret_auto($url_retour,2000);
	}
	else
		aff_ret_idx_auto($url_retour,2000);
}
include_once("pied.php");
?>

