* Copyright (C) 2003 Xavier Dutoit * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * * 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; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ */ /** \file htdocs/main.inc.php \brief Fichier de formatage générique des écrans Dolibarr \version $Revision$ */ // Pour le tuning optionnel. Activer si la variable d'environnement DOL_TUNING // est positionnée. A appeler avant tout. if (isset($_SERVER['DOL_TUNING'])) $micro_start_time=microtime(true); // Forcage du parametrage PHP magic_quots_gpc (Sinon il faudrait a chaque POST, conditionner // la lecture de variable par stripslashes selon etat de get_magic_quotes). // En mode off (recommandé), il faut juste fait addslashes au moment d'un insert/update. function stripslashes_deep($value) { return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value)); } if (get_magic_quotes_gpc()) { $_GET = array_map('stripslashes_deep', $_GET); $_POST = array_map('stripslashes_deep', $_POST); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); $_REQUEST = array_map('stripslashes_deep', $_REQUEST); } @set_magic_quotes_runtime(0); require_once("master.inc.php"); // Verification du login. // Cette verification est faite pour chaque accès. Après l'authentification, // l'objet $user est initialisée. Notament $user->id, $user->login et $user->nom, $user->prenom // \todo Stocker les infos de $user en session persistente php et ajouter recup dans le fetch // depuis la sessions pour ne pas avoir a acceder a la base a chaque acces de page. // MODE 1: Pas d'identification car forcé if (! empty($dolibarr_auto_user)) { // Mode forcé sur un utilisateur (pour debug, demo, ...), on initialise la session if (! session_id()) { session_name("DOLSESSID_".$dolibarr_main_db_name); session_start(); } $user->fetch($dolibarr_auto_user); dolibarr_syslog ("Authentification ok (en mode force)"); } // MODE 2: Identification HTTP Basic elseif (! empty($_SERVER["REMOTE_USER"])) { // Authentification Apache OK, on initialise la session if (! session_id()) { session_name("DOLSESSID_".$dolibarr_main_db_name); session_start(); } if (isset($_SESSION["dol_user"])) { // Session existante pour ce login $user->fetch($_SERVER["REMOTE_USER"]); // $user=$_SESSION["session_user"]; dolibarr_syslog ("Authentification ok (en mode Basic)"); } else { // Nouvelle session pour ce login $user->fetch($_SERVER["REMOTE_USER"]); dolibarr_syslog ("Authentification ok (en mode Basic) - nouvelle session"); $user->update_last_login_date(); $_SESSION["dol_user"]=$user; } } // MODE 3: Identification depuis base de donnée else { // Authentification Apache KO ou non active, pas de mode forcé, on demande le login require_once(DOL_DOCUMENT_ROOT."/includes/pear/Auth/Auth.php"); $pear = $dolibarr_main_db_type.'://'.$dolibarr_main_db_user.':'.$dolibarr_main_db_pass.'@'.$dolibarr_main_db_host.'/'.$dolibarr_main_db_name; $params = array( "dsn" =>$pear, "table" => MAIN_DB_PREFIX."user", "usernamecol" => "login", "passwordcol" => "pass", "cryptType" => "none", ); $aDol = new DOLIAuth("DB", $params, "loginfunction"); $aDol->setSessionName("DOLSESSID_".$dolibarr_main_db_name); $aDol->start(); $result = $aDol->getAuth(); if ($result) { // Authentification Auth OK, on va chercher les infos du user $user->fetch($aDol->getUsername()); dolibarr_syslog ("Authentification ok (en mode Pear)"); if (isset($_POST["loginfunction"])) { // Si phase de login initial $user->update_last_login_date(); } } else { if (isset($_POST["loginfunction"])) { // Echec authentification dolibarr_syslog("Authentification ko (en mode Pear) pour '".$_POST["username"]."'"); } else { // Non authentifié dolibarr_syslog("Authentification non réalisé"); } // Le début de la page a été affiché par loginfunction. On ferme juste la page print "\n\n\n"; exit; } } // Si user admin, on force droits sur les modules base if ($user->admin) { $user->rights->user->user->lire=1; $user->rights->user->user->creer=1; $user->rights->user->user->password=1; $user->rights->user->user->supprimer=1; $user->rights->user->self->creer=1; $user->rights->user->self->password=1; } /** * Overwrite configs global par configs perso * ------------------------------------------ */ if (isset($user->conf->SIZE_LISTE_LIMIT) && $user->conf->SIZE_LISTE_LIMIT > 0) { $conf->liste_limit = $user->conf->SIZE_LISTE_LIMIT; } if (isset($user->conf->PRODUIT_LIMIT_SIZE)) { $conf->produit->limit_size = $user->conf->PRODUIT_LIMIT_SIZE; } if (isset($user->conf->MAIN_LANG_DEFAULT) && $user->conf->MAIN_LANG_DEFAULT) { if ($langs->getDefaultLang() != $user->conf->MAIN_LANG_DEFAULT) { // Si on a un langage perso différent du langage courant global $langs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT); $langs->setPhpLang($user->conf->MAIN_LANG_DEFAULT); } } // Remplace conf->css par valeur personnalisée if (isset($user->conf->MAIN_THEME) && $user->conf->MAIN_THEME) { $conf->theme=$user->conf->MAIN_THEME; $conf->css = "theme/".$conf->theme."/".$conf->theme.".css"; } // Si feuille de style en php existe if (file_exists(DOL_DOCUMENT_ROOT.'/'.$conf->css.".php")) $conf->css.=".php"; if (isset($user->conf->MAIN_DISABLE_JAVASCRIPT) && $user->conf->MAIN_DISABLE_JAVASCRIPT) { $conf->use_javascript=! $user->conf->MAIN_DISABLE_JAVASCRIPT; } // Défini gestionnaire de menu à utiliser if (! $user->societe_id) // Si utilisateur interne { $conf->top_menu=$conf->global->MAIN_MENU_BARRETOP; $conf->left_menu=$conf->global->MAIN_MENU_BARRELEFT; // Pour compatibilité if ($conf->top_menu == 'eldy.php') $conf->top_menu='eldy_backoffice.php'; if ($conf->left_menu == 'eldy.php') $conf->left_menu='eldy_backoffice.php'; } else // Si utilisateur externe { $conf->top_menu=$conf->global->MAIN_MENUFRONT_BARRETOP; $conf->left_menu=$conf->global->MAIN_MENUFRONT_BARRELEFT; } // Si le login n'a pu être récupéré, on est identifié avec un compte qui n'existe pas. // Tentative de hacking ? if (! $user->login) accessforbidden(); dolibarr_syslog("Access to ".$_SERVER["PHP_SELF"]); if (! defined('MAIN_INFO_SOCIETE_PAYS')) { define('MAIN_INFO_SOCIETE_PAYS','1'); } // On charge le fichier lang principal $langs->load("main"); /* * */ if (defined("MAIN_NOT_INSTALLED")) { Header("Location: ".DOL_URL_ROOT."/install/index.php"); exit; } // Constantes utilisées pour définir le nombre de lignes des textarea if (! eregi("firefox",$_SERVER["HTTP_USER_AGENT"])) { define('ROWS_1',1); define('ROWS_2',2); define('ROWS_3',3); } else { define('ROWS_1',0); define('ROWS_2',1); define('ROWS_3',2); } /** * \brief Affiche en-tête html * \param head lignes d'en-tete head * \param title titre page web * \param target target du menu Accueil */ function top_htmlhead($head, $title="", $target="") { global $user, $conf, $langs, $db; print ''; print "\n"; print $langs->lang_header(); print $head; // Affiche meta print ''."\n"; // Evite indexation par robots print ''."\n"; // Affiche title if (strlen($title) > 0) { print 'Dolibarr - '.$title.''; } else { if (defined("MAIN_TITLE")) { print "".MAIN_TITLE.""; } else { print 'Dolibarr'; } } print "\n"; // Affiche style sheets et link print ''."\n"; print ''."\n"; // Definition en alternate style sheet des feuilles de styles les plus maintenues // Les navigateurs qui supportent sont rares. print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; if ($conf->use_javascript) { print ''; } print "\n"; } /** * \brief Affiche en-tête html + la barre de menu supérieure * \param head lignes d'en-tete head * \param title titre page web * \param target target du menu Accueil */ function top_menu($head, $title="", $target="") { global $user, $conf, $langs, $db; top_htmlhead($head, $title, $target); print '
'; /* * Si la constante MAIN_NEED_UPDATE est définie (par le script de migration sql en général), c'est que * les données ont besoin d'un remaniement. Il faut passer le update.php */ if ($conf->global->MAIN_NEED_UPDATE) { $langs->load("admin"); print '
'."\n"; print ''; print ''; print "
'; print $langs->trans("UpdateRequired",DOL_URL_ROOT.'/install/index.php'); print '
"; llxFooter(); exit; } /* * Barre de menu supérieure */ print '
'."\n"; // Charge le gestionnaire des entrées de menu du haut require_once(DOL_DOCUMENT_ROOT ."/includes/menus/barre_top/".$conf->top_menu); $menutop = new MenuTop($db); $menutop->atarget=$target; // Affiche le menu $menutop->showmenu(); // Lien sur fiche du login print ''; // Lien logout if (! isset($_SERVER["REMOTE_USER"]) || ! $_SERVER["REMOTE_USER"]) { print 'atarget?(' target="'.$menutop->atarget.'"'):''; print '>'; print ''; print ''; } print "
\n"; } /** * \brief Affiche barre de menu gauche * \param menu_array Tableau des entrée de menu * \param help_url Url pour le lien aide ('' par defaut) * \param form_search Formulaire de recherche permanant supplémentaire */ function left_menu($menu_array, $help_url='', $form_search='') { global $user, $conf, $langs, $db; print '
'."\n"; print "\n"; // Colonne de gauche print ''."\n"; print '
'."\n"; // Autres entrées du menu par le gestionnaire require_once(DOL_DOCUMENT_ROOT ."/includes/menus/barre_left/".$conf->left_menu); $menu=new MenuLeft($db,$menu_array); $menu->showmenu(); // Affichage des zones de recherche permanantes $addzonerecherche=0; if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_SOCIETE) $addzonerecherche=1; if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_CONTACT) $addzonerecherche=1; if (($conf->produit->enabled || $conf->service->enabled) && $conf->global->MAIN_SEARCHFORM_PRODUITSERVICE) $addzonerecherche=1; if ($addzonerecherche && ($user->rights->societe->lire || $user->rights->produit->lire)) { print '
'; if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_SOCIETE && $user->rights->societe->lire) { $langs->load("companies"); printSearchForm(DOL_URL_ROOT.'/societe.php',DOL_URL_ROOT.'/societe.php', img_object($langs->trans("List"),'company').' '.$langs->trans("Companies"),'soc','socname'); } if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_CONTACT && $user->rights->societe->lire) { $langs->load("companies"); printSearchForm(DOL_URL_ROOT.'/contact/index.php',DOL_URL_ROOT.'/contact/index.php', img_object($langs->trans("List"),'contact').' '.$langs->trans("Contacts"),'contact','contactname','contact'); } if (($conf->produit->enabled || $conf->service->enabled) && $conf->global->MAIN_SEARCHFORM_PRODUITSERVICE && $user->rights->produit->lire) { $langs->load("products"); printSearchForm(DOL_URL_ROOT.'/product/liste.php',DOL_URL_ROOT.'/product/index.php', img_object($langs->trans("List"),'product').' '.$langs->trans("Products")."/".$langs->trans("Services"),'products','sall','product'); } /* if ($conf->categorie->enabled) { $langs->load("categories"); printSearchForm(DOL_URL_ROOT.'/categories/search.php',DOL_URL_ROOT.'/categories/',$langs->trans("Categories"),'categories','catname'); } */ print '
'; } // Zone de recherche supplémentaire if ($form_search) { print $form_search; } // Lien vers l'aide en ligne (uniquement si langue fr_FR) if ($help_url) { $helpbaseurl=''; if ($langs->defaultlang == "fr_FR") $helpbaseurl='http://www.dolibarr.com/wikidev/index.php/%s'; if ($helpbaseurl) print ''; } if (MAIN_SHOW_BUGTRACK_LINK == 1) { // Lien vers le bugtrack $bugbaseurl='http://savannah.nongnu.org/bugs/?'; $bugbaseurl.='func=additem&group=dolibarr&privacy=1&'; $bugbaseurl.="&details="; $bugbaseurl.=urlencode("\n\n\n\n\n-------------\n"); $bugbaseurl.=urlencode($langs->trans("Version").": ".DOL_VERSION."\n"); $bugbaseurl.=urlencode($langs->trans("Server").": ".$_SERVER["SERVER_SOFTWARE"]."\n"); $bugbaseurl.=urlencode($langs->trans("Url").": ".$_SERVER["REQUEST_URI"]."\n"); print ''; } print "\n"; print "
\n"; print "\n"; print "\n"; print '
'."\n"; print '
'."\n"; print "\n"; print ''."\n"; print '
'."\n"; } /** * \brief Affiche une zone de recherche * \param urlaction Url du post * \param urlobject Url du lien sur titre de la zone de recherche * \param title Titre de la zone de recherche * \param htmlmodesearch 'search' * \param htmlinputname Nom du champ input du formulaire */ function printSearchForm($urlaction,$urlobject,$title,$htmlmodesearch='search',$htmlinputname) { global $langs; print '
'; print ''; print $title.'
'; print ''; print ''; print ' '; print ''; print "
"; } /** * \brief Impression du pied de page * \param foot Non utilisé */ function llxFooter($foot='') { global $conf, $dolibarr_auto_user, $micro_start_time; print "\n
\n".''."\n"; print "\n
\n".''; if (isset($_SERVER['DOL_TUNING'])) { print ''; print "\n"; } if ($conf->use_javascript) { print ''; } // Juste pour éviter bug IE qui réorganise mal div précédents si celui-ci absent print "\n".'
 
'."\n"; print "\n"; print "\n"; } ?>