[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/ -> main.inc.php (source)

   1  <?php
   2  /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 
   3   * Copyright (C) 2003      Xavier Dutoit        <doli@sydesy.com>
   4   * Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   5   * Copyright (C) 2004      Sebastien Di Cintio  <sdicintio@ressource-toi.org>
   6   * Copyright (C) 2004      Benoit Mortier       <benoit.mortier@opensides.be>
   7   *
   8   * This program is free software; you can redistribute it and/or modify
   9   * it under the terms of the GNU General Public License as published by
  10   * the Free Software Foundation; either version 2 of the License, or
  11   * (at your option) any later version.
  12   *
  13   * This program is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16   * GNU General Public License for more details.
  17   *
  18   * You should have received a copy of the GNU General Public License
  19   * along with this program; if not, write to the Free Software
  20   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21   *
  22   * $Id: main.inc.php,v 1.172 2005/12/03 20:55:15 eldy Exp $
  23   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/main.inc.php,v $
  24   */
  25  
  26  /**
  27          \file       htdocs/main.inc.php
  28          \brief      Fichier de formatage générique des écrans Dolibarr
  29          \version    $Revision: 1.172 $
  30  */
  31  
  32  // Pour le tuning optionnel. Activer si la variable d'environnement DOL_TUNING
  33  // est positionnée. A appeler avant tout.
  34  if (isset($_SERVER['DOL_TUNING'])) $micro_start_time=microtime(true);
  35  
  36  
  37  // Forcage du parametrage PHP magic_quots_gpc (Sinon il faudrait a chaque POST, conditionner
  38  // la lecture de variable par stripslashes selon etat de get_magic_quotes).
  39  // En mode off (recommandé), il faut juste fait addslashes au moment d'un insert/update.
  40  function stripslashes_deep($value)
  41  {
  42     return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value));
  43  }
  44  if (get_magic_quotes_gpc())
  45  {
  46     $_GET    = array_map('stripslashes_deep', $_GET);
  47     $_POST  = array_map('stripslashes_deep', $_POST);
  48     $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
  49     $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
  50  }
  51  @set_magic_quotes_runtime(0);
  52  
  53  
  54  require_once ("master.inc.php");
  55  
  56  
  57  // Verification du login.
  58  // Cette verification est faite pour chaque accès. Après l'authentification,
  59  // l'objet $user est initialisée. Notament $user->id, $user->login et $user->nom, $user->prenom
  60  // \todo Stocker les infos de $user en session persistente php et ajouter recup dans le fetch
  61  //       depuis la sessions pour ne pas avoir a acceder a la base a chaque acces de page.
  62  
  63  // MODE 1: Pas d'identification car forcé
  64  if (! empty($dolibarr_auto_user))
  65  {
  66      // Mode forcé sur un utilisateur (pour debug, demo, ...), on initialise la session
  67      if (! session_id()) {
  68          session_name("DOLSESSID_".$dolibarr_main_db_name);
  69          session_start();
  70      }
  71  
  72      $user->fetch($dolibarr_auto_user);
  73      dolibarr_syslog ("Authentification ok (en mode force)");
  74  }
  75  // MODE 2: Identification HTTP Basic
  76  elseif (! empty($_SERVER["REMOTE_USER"]))
  77  {
  78      // Authentification Apache OK, on initialise la session
  79      if (! session_id()) {
  80          session_name("DOLSESSID_".$dolibarr_main_db_name);
  81          session_start();
  82      }
  83  
  84      if (isset($_SESSION["dol_user"]))
  85      {
  86          // Session existante pour ce login
  87          $user->fetch($_SERVER["REMOTE_USER"]);
  88  //        $user=$_SESSION["session_user"];
  89          dolibarr_syslog ("Authentification ok (en mode Basic)");
  90      }
  91      else
  92      {
  93          // Nouvelle session pour ce login
  94          $user->fetch($_SERVER["REMOTE_USER"]);
  95          dolibarr_syslog ("Authentification ok (en mode Basic) - nouvelle session");
  96          $user->update_last_login_date();
  97          $_SESSION["dol_user"]=$user;
  98      }
  99  }
 100  // MODE 3: Identification depuis base de donnée
 101  else
 102  {
 103      // Authentification Apache KO ou non active, pas de mode forcé, on demande le login
 104      require_once (DOL_DOCUMENT_ROOT."/includes/pear/Auth/Auth.php");
 105  
 106      $pear = $dolibarr_main_db_type.'://'.$dolibarr_main_db_user.':'.$dolibarr_main_db_pass.'@'.$dolibarr_main_db_host.'/'.$dolibarr_main_db_name;
 107  
 108      $params = array(
 109      "dsn" =>$pear,
 110      "table" => MAIN_DB_PREFIX."user",
 111      "usernamecol" => "login",
 112      "passwordcol" => "pass",
 113      "cryptType" => "none",
 114      );
 115  
 116      $aDol = new DOLIAuth("DB", $params, "loginfunction");
 117      $aDol->setSessionName("DOLSESSID_".$dolibarr_main_db_name);
 118      $aDol->start();
 119      $result = $aDol->getAuth();
 120      if ($result)
 121      {
 122          // Authentification Auth OK, on va chercher les infos du user
 123          $user->fetch($aDol->getUsername());
 124          dolibarr_syslog ("Authentification ok (en mode Pear)");
 125          if (isset($_POST["loginfunction"]))
 126          {
 127              // Si phase de login initial
 128              $user->update_last_login_date();
 129          }
 130      }
 131      else
 132      {
 133          if (isset($_POST["loginfunction"]))
 134          {
 135              // Echec authentification
 136              dolibarr_syslog("Authentification ko (en mode Pear) pour '".$_POST["username"]."'");
 137          }
 138          else 
 139          {
 140              // Non authentifié
 141              dolibarr_syslog("Authentification non réalisé");
 142          }
 143          // Le début de la page a été affiché par loginfunction. On ferme juste la page
 144          print "</div>\n</div>\n</body>\n</html>";
 145          exit;
 146      }
 147  }
 148  
 149  // Si user admin, on force droits sur les modules base
 150  if ($user->admin)
 151  {
 152      $user->rights->user->user->lire=1;
 153      $user->rights->user->user->creer=1;
 154      $user->rights->user->user->password=1;
 155      $user->rights->user->user->supprimer=1;
 156      $user->rights->user->self->creer=1;
 157      $user->rights->user->self->password=1;
 158  }
 159  
 160  /**
 161   * Overwrite configs global par configs perso
 162   * ------------------------------------------
 163   */
 164  if (isset($user->conf->SIZE_LISTE_LIMIT) && $user->conf->SIZE_LISTE_LIMIT > 0)
 165  {
 166      $conf->liste_limit = $user->conf->SIZE_LISTE_LIMIT;
 167  }
 168  if (isset($user->conf->PRODUIT_LIMIT_SIZE))
 169  {
 170      $conf->produit->limit_size = $user->conf->PRODUIT_LIMIT_SIZE;
 171  }
 172  if (isset($user->conf->MAIN_LANG_DEFAULT) && $user->conf->MAIN_LANG_DEFAULT)
 173  {
 174      if ($langs->getDefaultLang() != $user->conf->MAIN_LANG_DEFAULT)
 175      {
 176          // Si on a un langage perso différent du langage courant global
 177          $langs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT);
 178          $langs->setPhpLang($user->conf->MAIN_LANG_DEFAULT);
 179      }
 180  }
 181  
 182  // Remplace conf->css par valeur personnalisée
 183  if (isset($user->conf->MAIN_THEME) && $user->conf->MAIN_THEME)
 184  {
 185      $conf->theme=$user->conf->MAIN_THEME;
 186      $conf->css  = "theme/".$conf->theme."/".$conf->theme.".css";
 187  }
 188  // Si feuille de style en php existe
 189  if (file_exists(DOL_DOCUMENT_ROOT.'/'.$conf->css.".php")) $conf->css.=".php";
 190  
 191  if (isset($user->conf->MAIN_DISABLE_JAVASCRIPT) && $user->conf->MAIN_DISABLE_JAVASCRIPT)
 192  {
 193      $conf->use_javascript=! $user->conf->MAIN_DISABLE_JAVASCRIPT;
 194  }
 195  
 196  // Défini gestionnaire de menu à utiliser
 197  if (! $user->societe_id)    // Si utilisateur interne
 198  {
 199      $conf->top_menu=$conf->global->MAIN_MENU_BARRETOP;
 200      $conf->left_menu=$conf->global->MAIN_MENU_BARRELEFT;
 201      // Pour compatibilité
 202      if ($conf->top_menu == 'eldy.php') $conf->top_menu='eldy_backoffice.php';
 203      if ($conf->left_menu == 'eldy.php') $conf->left_menu='eldy_backoffice.php';
 204  }
 205  else                        // Si utilisateur externe
 206  {
 207      $conf->top_menu=$conf->global->MAIN_MENUFRONT_BARRETOP;
 208      $conf->left_menu=$conf->global->MAIN_MENUFRONT_BARRELEFT;
 209  }
 210  
 211  // Si le login n'a pu être récupéré, on est identifié avec un compte qui n'existe pas.
 212  // Tentative de hacking ?
 213  if (! $user->login) accessforbidden();
 214  
 215  
 216  dolibarr_syslog("Access to ".$_SERVER["PHP_SELF"]);
 217  
 218  
 219  if (! defined('MAIN_INFO_SOCIETE_PAYS'))
 220  {
 221    define('MAIN_INFO_SOCIETE_PAYS','1');
 222  }
 223  
 224  // On charge le fichier lang principal
 225  $langs->load("main");
 226  
 227  /*
 228   *
 229   */
 230  if (defined("MAIN_NOT_INSTALLED"))
 231  {
 232      Header("Location: ".DOL_URL_ROOT."/install/index.php");
 233      exit;
 234  }
 235  
 236  // Constantes utilisées pour définir le nombre de lignes des textarea
 237  if (! eregi("firefox",$_SERVER["HTTP_USER_AGENT"]))
 238  {
 239      define('ROWS_1',1);
 240      define('ROWS_2',2);
 241      define('ROWS_3',3);
 242  }
 243  else
 244  {
 245      define('ROWS_1',0);
 246      define('ROWS_2',1);
 247      define('ROWS_3',2);
 248  }
 249  
 250  
 251  
 252  /**
 253   *  \brief      Affiche en-tête html
 254   *  \param      head    lignes d'en-tete head
 255   *  \param      title   titre page web
 256   *  \param      target  target du menu Accueil
 257   */
 258  function top_htmlhead($head, $title="", $target="") 
 259  {
 260      global $user, $conf, $langs, $db;
 261  
 262      print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
 263      print "\n<html>";
 264  
 265      print $langs->lang_header();
 266      print $head;
 267  
 268      // Affiche meta
 269      print '<meta name="robots" content="noindex,nofollow">'."\n";      // Evite indexation par robots
 270      print '<meta name="author" content="'.$langs->trans("DevelopmentTeam").'">'."\n";
 271  
 272      // Affiche title
 273      if (strlen($title) > 0)
 274      {
 275          print '<title>Dolibarr - '.$title.'</title>';
 276      }
 277      else
 278      {
 279          if (defined("MAIN_TITLE"))
 280          {
 281              print "<title>".MAIN_TITLE."</title>";
 282          }
 283          else
 284          {
 285              print '<title>Dolibarr</title>';
 286          }
 287      }
 288      print "\n";
 289  
 290      // Affiche style sheets et link
 291      print '<link rel="stylesheet" type="text/css" title="default" href="'.DOL_URL_ROOT.'/'.$conf->css.'">'."\n";
 292      print '<link rel="stylesheet" type="text/css" media="print" HREF="'.DOL_URL_ROOT.'/theme/print.css">'."\n";
 293  
 294      // Definition en alternate style sheet des feuilles de styles les plus maintenues
 295      // Les navigateurs qui supportent sont rares.
 296      print '<link rel="alternate stylesheet" type="text/css" title="Eldy" href="'.DOL_URL_ROOT.'/theme/eldy/eldy.css.php">'."\n";
 297      print '<link rel="alternate stylesheet" type="text/css" title="Freelug" href="'.DOL_URL_ROOT.'/theme/freelug/freelug.css">'."\n";
 298      print '<link rel="alternate stylesheet" type="text/css" title="Yellow" href="'.DOL_URL_ROOT.'/theme/yellow/yellow.css">'."\n";
 299  
 300      print '<link rel="top" title="'.$langs->trans("Home").'" href="'.DOL_URL_ROOT.'/">'."\n";
 301      print '<link rel="help" title="'.$langs->trans("Help").'" href="http://www.dolibarr.com/aide.fr.html">'."\n";
 302      print '<link rel="copyright" title="GNU General Public License" href="http://www.gnu.org/copyleft/gpl.html#SEC1">'."\n";
 303      print '<link rel="author" title="'.$langs->trans("DevelopmentTeam").'" href="http://www.dolibarr.com/dev.fr.html">'."\n";
 304  
 305      if ($conf->use_javascript)
 306      {
 307          print '<script language="javascript" type="text/javascript" src="'.DOL_URL_ROOT.'/lib/lib_head.js"></script>';
 308      }
 309      
 310      print "</head>\n";
 311  }
 312    
 313  /**
 314   *  \brief      Affiche en-tête html + la barre de menu supérieure
 315   *  \param      head    lignes d'en-tete head
 316   *  \param      title   titre page web
 317   *  \param      target  target du menu Accueil
 318   */
 319  function top_menu($head, $title="", $target="") 
 320  {
 321      global $user, $conf, $langs, $db;
 322  
 323      top_htmlhead($head, $title, $target);
 324  
 325      print '<body><div id="dhtmltooltip"></div>';
 326  
 327      /*
 328       * Si la constante MAIN_NEED_UPDATE est définie (par le script de migration sql en général), c'est que
 329       * les données ont besoin d'un remaniement. Il faut passer le update.php
 330       */
 331      if ($conf->global->MAIN_NEED_UPDATE)
 332      {
 333          $langs->load("admin");
 334          print '<div class="fiche">'."\n";
 335          print '<table class="noborder" width="100%">';
 336          print '<tr><td>';
 337          print $langs->trans("UpdateRequired",DOL_URL_ROOT.'/install/index.php');
 338          print '</td></tr>';
 339          print "</table>";
 340          llxFooter();
 341          exit;
 342      }
 343  
 344  
 345      /*
 346       * Barre de menu supérieure
 347       */
 348      print '<div class="tmenu">'."\n";
 349  
 350      // Charge le gestionnaire des entrées de menu du haut
 351      require_once(DOL_DOCUMENT_ROOT ."/includes/menus/barre_top/".$conf->top_menu);
 352      $menutop = new MenuTop($db);
 353      $menutop->atarget=$target;
 354  
 355      // Affiche le menu
 356      $menutop->showmenu();
 357  
 358      // Lien sur fiche du login
 359      print '<a class="login" href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$user->id.'"';
 360      print $menutop->atarget?(' target="'.$menutop->atarget.'"'):'';
 361      print '>'.$user->login.'</a>';
 362  
 363      // Lien logout
 364      if (! isset($_SERVER["REMOTE_USER"]) || ! $_SERVER["REMOTE_USER"])
 365      {
 366          print '<a href="'.DOL_URL_ROOT.'/user/logout.php"';
 367          print $menutop->atarget?(' target="'.$menutop->atarget.'"'):'';
 368          print '>';
 369          print '<img class="login" border="0" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/logout.png"';
 370          print ' alt="'.$langs->trans("Logout").'" title="'.$langs->trans("Logout").'"';
 371          print '>';
 372          print '</a>';
 373      }
 374  
 375      print "</div><!-- class=tmenu -->\n";
 376  
 377  }
 378  
 379  
 380  /**
 381   *  \brief      Affiche barre de menu gauche
 382   *  \param      menu_array      Tableau des entrée de menu
 383   *  \param      help_url        Url pour le lien aide ('' par defaut)
 384   *  \param      form_search     Formulaire de recherche permanant supplémentaire
 385   */
 386  function left_menu($menu_array, $help_url='', $form_search='')
 387  {
 388      global $user, $conf, $langs, $db;
 389  
 390      print '<div class="vmenuplusfiche">'."\n";
 391      print "\n";
 392  
 393      // Colonne de gauche
 394      print '<!-- Debut left vertical menu -->'."\n";
 395      print '<div class="vmenu">'."\n";
 396  
 397  
 398      // Autres entrées du menu par le gestionnaire
 399      require_once(DOL_DOCUMENT_ROOT ."/includes/menus/barre_left/".$conf->left_menu);
 400      $menu=new MenuLeft($db,$menu_array);
 401      $menu->showmenu();
 402  
 403  
 404      // Affichage des zones de recherche permanantes
 405      $addzonerecherche=0;
 406      if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_SOCIETE) $addzonerecherche=1;
 407      if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_CONTACT) $addzonerecherche=1;
 408      if (($conf->produit->enabled || $conf->service->enabled) && $conf->global->MAIN_SEARCHFORM_PRODUITSERVICE) $addzonerecherche=1;
 409  
 410      if ($addzonerecherche  && ($user->rights->societe->lire || $user->rights->produit->lire))
 411      {
 412          print '<div class="blockvmenupair">';
 413  
 414          if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_SOCIETE && $user->rights->societe->lire)
 415          {
 416              $langs->load("companies");
 417              printSearchForm(DOL_URL_ROOT.'/societe.php',DOL_URL_ROOT.'/societe.php',
 418                  img_object($langs->trans("List"),'company').' '.$langs->trans("Companies"),'soc','socname');
 419          }
 420  
 421          if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_CONTACT && $user->rights->societe->lire)
 422          {
 423              $langs->load("companies");
 424              printSearchForm(DOL_URL_ROOT.'/contact/index.php',DOL_URL_ROOT.'/contact/index.php',
 425                  img_object($langs->trans("List"),'contact').' '.$langs->trans("Contacts"),'contact','contactname','contact');
 426          }
 427  
 428          if (($conf->produit->enabled || $conf->service->enabled) && $conf->global->MAIN_SEARCHFORM_PRODUITSERVICE && $user->rights->produit->lire)
 429          {
 430              $langs->load("products");
 431              printSearchForm(DOL_URL_ROOT.'/product/liste.php',DOL_URL_ROOT.'/product/index.php',
 432                  img_object($langs->trans("List"),'product').' '.$langs->trans("Products")."/".$langs->trans("Services"),'products','sall','product');
 433          }
 434  
 435          /*
 436          if ($conf->categorie->enabled)
 437          {
 438          $langs->load("categories");
 439          printSearchForm(DOL_URL_ROOT.'/categories/search.php',DOL_URL_ROOT.'/categories/',$langs->trans("Categories"),'categories','catname');
 440          }
 441          */
 442  
 443          print '</div>';
 444      }
 445  
 446      // Zone de recherche supplémentaire
 447      if ($form_search)
 448      {
 449          print $form_search;
 450      }
 451  
 452      // Lien vers l'aide en ligne (uniquement si langue fr_FR)
 453      if ($help_url)
 454      {
 455          $helpbaseurl='';
 456          if ($langs->defaultlang == "fr_FR") $helpbaseurl='http://www.dolibarr.com/wikidev/index.php/%s';
 457  
 458          if ($helpbaseurl) print '<div class="help"><a class="help" target="_blank" href="'.sprintf($helpbaseurl,$help_url).'">'.$langs->trans("Help").'</a></div>';
 459      }
 460  
 461      if (MAIN_SHOW_BUGTRACK_LINK == 1)
 462      {
 463          // Lien vers le bugtrack
 464          $bugbaseurl='http://savannah.nongnu.org/bugs/?';
 465          $bugbaseurl.='func=additem&group=dolibarr&privacy=1&';
 466          $bugbaseurl.="&details=";
 467          $bugbaseurl.=urlencode("\n\n\n\n\n-------------\n");
 468          $bugbaseurl.=urlencode($langs->trans("Version").": ".DOL_VERSION."\n");
 469          $bugbaseurl.=urlencode($langs->trans("Server").": ".$_SERVER["SERVER_SOFTWARE"]."\n");
 470          $bugbaseurl.=urlencode($langs->trans("Url").": ".$_SERVER["REQUEST_URI"]."\n");
 471          print '<div class="help"><a class="help" target="_blank" href="'.$bugbaseurl.'">'.$langs->trans("FindBug").'</a></div>';
 472      }
 473      print "\n";
 474      print "</div>\n";
 475      print "<!-- Fin left vertical menu -->\n";
 476  
 477      print "\n";
 478      print '</div>'."\n";
 479      print '<div class="vmenuplusfiche">'."\n";
 480      print "\n";
 481      
 482      print '<!-- fiche -->'."\n";
 483      print '<div class="fiche">'."\n";
 484  
 485  }
 486  
 487  
 488  
 489  /**
 490   *  \brief   Affiche une zone de recherche
 491   *  \param   urlaction          Url du post
 492   *  \param   urlobject          Url du lien sur titre de la zone de recherche
 493   *  \param   title              Titre de la zone de recherche
 494   *  \param   htmlmodesearch     'search'
 495   *  \param   htmlinputname      Nom du champ input du formulaire
 496   */
 497   
 498  function printSearchForm($urlaction,$urlobject,$title,$htmlmodesearch='search',$htmlinputname)
 499  {
 500      global $langs;
 501      print '<form action="'.$urlaction.'" method="post">';
 502      print '<a class="vmenu" href="'.$urlobject.'">';
 503      print $title.'</a><br>';
 504      print '<input type="hidden" name="mode" value="search">';
 505      print '<input type="hidden" name="mode-search" value="'.$htmlmodesearch.'">';
 506      print '<input type="text" class="flat" name="'.$htmlinputname.'" size="10">&nbsp;';
 507      print '<input type="submit" class="button" value="'.$langs->trans("Go").'">';
 508      print "</form>";
 509  }
 510  
 511  
 512  /**
 513   * \brief   Impression du pied de page
 514   * \param   foot    Non utilisé
 515   */
 516   
 517  function llxFooter($foot='') 
 518  {
 519      global $conf, $dolibarr_auto_user, $micro_start_time;
 520      
 521      print "\n</div>\n".'<!-- end div class="fiche" -->'."\n";
 522      print "\n</div>\n".'<!-- end div class="vmenuplusfiche" -->';
 523      
 524      if (isset($_SERVER['DOL_TUNING']))
 525      {
 526          print '<script language="javascript" type="text/javascript">window.status="Build time: '.ceil(1000*(microtime(true)-$micro_start_time)).' ms"</script>';
 527          print "\n";
 528      } 
 529  
 530      if ($conf->use_javascript)
 531      {
 532          print '<script language="javascript" type="text/javascript" src="'.DOL_URL_ROOT.'/lib/lib_foot.js"></script>';
 533      }
 534  
 535      // Juste pour éviter bug IE qui réorganise mal div précédents si celui-ci absent
 536      print "\n".'<div class="tabsAction">&nbsp;</div>'."\n";
 537      
 538      print "</body>\n";
 539      print "</html>\n";
 540  }
 541  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics