* Copyright (C) 2003 Xavier Dutoit * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2008 Matteli * * 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. */ /** * \file htdocs/main.inc.php * \ingroup core * \brief File that defines environment for Dolibarr pages only (variables not required by scripts) * \version $Id$ */ @ini_set('memory_limit', '48M'); // This may be useless if memory is hard limited by your PHP // For optionnal tuning. Enabled if environment variable DOL_TUNING is defined. // A call first. Is the equivalent function dol_microtime_float not yet loaded. $micro_start_time=0; if (! empty($_SERVER['DOL_TUNING'])) { list($usec, $sec) = explode(" ", microtime()); $micro_start_time=((float)$usec + (float)$sec); // Add Xdebug coverage of code //define('XDEBUGCOVERAGE',1); if (defined('XDEBUGCOVERAGE')) { xdebug_start_code_coverage(); } } // Forcing parameter setting magic_quotes_gpc and cleaning parameters // (Otherwise he would have for each position, condition // Reading stripslashes variable according to state get_magic_quotes_gpc). // Off mode (recommended, you just do addslashes when an insert / update. function stripslashes_deep($value) { return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value)); } if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* removed in PHP6 { if (get_magic_quotes_gpc()) { $_GET = array_map('stripslashes_deep', $_GET); $_POST = array_map('stripslashes_deep', $_POST); $_REQUEST = array_map('stripslashes_deep', $_REQUEST); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); } @set_magic_quotes_runtime(0); } // Security: SQL and Script Injection protection (Filters on GET, POST) function test_sql_and_script_inject($val) { $sql_inj = 0; $sql_inj += preg_match('/delete[\s]+from/i', $val); $sql_inj += preg_match('/create[\s]+table/i', $val); $sql_inj += preg_match('/update.+set.+=/i', $val); $sql_inj += preg_match('/insert[\s]+into/i', $val); $sql_inj += preg_match('/select.+from/i', $val); $sql_inj += preg_match('/'."\n"; // Other external js require_once DOL_DOCUMENT_ROOT.'/lib/ajax.lib.php'; $mini='';$ext='.js'; if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x01)) { $mini='_mini'; $ext='.jgz'; } // mini='_mini', ext='.gz' // This one is required for all Ajax features if (! defined('DISABLE_PROTOTYPE') && ! $conf->global->MAIN_USE_JQUERY) { print ''."\n"; print ''."\n"; } // This one is required for boxes if (! defined('DISABLE_SCRIPTACULOUS') && ! $conf->global->MAIN_USE_JQUERY) { print ''."\n"; //print ''."\n"; //print ''."\n"; $listofscripts='effects,dragdrop'; if ($conf->global->COMPANY_USE_SEARCH_TO_SELECT) $listofscripts.=',controls'; // For Ajax.Autocompleter print ''."\n"; } // Those ones are required only with option "confirm by ajax popup" if (! defined('DISABLE_PWC') && ! $conf->global->MAIN_USE_JQUERY && $conf->global->MAIN_CONFIRM_AJAX) { print ''."\n"; // PWC js print ''."\n"; } if ($conf->global->MAIN_USE_JQUERY) { print ''."\n"; print ''."\n"; print ''."\n"; } } // Output module javascript if (is_array($arrayofjs)) { print ''."\n"; foreach($arrayofjs as $jsfile) { print ''."\n"; } } // Define tradMonths javascript array (we define this in datapicker AND in parent page to avoid errors with IE8) $tradTemp=array($langs->trans("January"), $langs->trans("February"), $langs->trans("March"), $langs->trans("April"), $langs->trans("May"), $langs->trans("June"), $langs->trans("July"), $langs->trans("August"), $langs->trans("September"), $langs->trans("October"), $langs->trans("November"), $langs->trans("December") ); print ''."\n"; if (! empty($conf->global->MAIN_HTML_HEADER)) print $conf->global->MAIN_HTML_HEADER."\n"; print "\n\n"; } } /** * \brief Show left menu bar * \param menu_array Table menu entries * \param helppagename Name of wiki page for help ('' by default). * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage * For other external page: http://server/url * \param moresearchform Search Form Permanent Supplemental */ function left_menu($menu_array, $helppagename='', $moresearchform='') { global $user, $conf, $langs, $db; $searchform=''; $bookmarks=''; // print '
'."\n"; print '
'; print "\n"; // Define $searchform if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_SOCIETE && $user->rights->societe->lire) { $langs->load("companies"); $searchform.=printSearchForm(DOL_URL_ROOT.'/societe.php', DOL_URL_ROOT.'/societe.php', img_object('','company').' '.$langs->trans("Companies"), 'soc', 'socname'); } if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_CONTACT && $user->rights->societe->lire) { $langs->load("companies"); $searchform.=printSearchForm(DOL_URL_ROOT.'/contact/index.php', DOL_URL_ROOT.'/contact/index.php', img_object('','contact').' '.$langs->trans("Contacts"), 'contact', 'contactname'); } if ((($conf->produit->enabled && $user->rights->produit->lire) || ($conf->service->enabled && $user->rights->service->lire)) && $conf->global->MAIN_SEARCHFORM_PRODUITSERVICE) { $langs->load("products"); $searchform.=printSearchForm(DOL_URL_ROOT.'/product/liste.php', DOL_URL_ROOT.'/product/index.php', img_object('','product').' '.$langs->trans("Products")."/".$langs->trans("Services"), 'products', 'sall'); } if ($conf->adherent->enabled && $conf->global->MAIN_SEARCHFORM_ADHERENT && $user->rights->adherent->lire) { $langs->load("members"); $searchform.=printSearchForm(DOL_URL_ROOT.'/adherents/liste.php', DOL_URL_ROOT.'/adherents/liste.php', img_object('','user').' '.$langs->trans("Members"), 'member', 'sall'); } // Define $bookmarks if ($conf->bookmark->enabled && $user->rights->bookmark->lire) { include_once (DOL_DOCUMENT_ROOT.'/bookmarks/bookmarks.lib.php'); $langs->load("bookmarks"); $bookmarks=printBookmarksList($db, $langs); } // Left column print ''."\n"; print '
'."\n"; // Load the left menu manager $result=@include_once(DOL_DOCUMENT_ROOT ."/includes/menus/barre_left/".$conf->left_menu); if (! $result) { $conf->left_menu='eldy_backoffice.php'; include_once(DOL_DOCUMENT_ROOT ."/includes/menus/barre_left/".$conf->left_menu); } $menuleft=new MenuLeft($db,$menu_array); $menuleft->showmenu(); if ($searchform) { print "\n"; print "\n"; print '
'."\n"; print $searchform; print '
'."\n"; print "\n"; } if ($moresearchform) { print $moresearchform; } if ($bookmarks) { print "\n"; print "\n"; print '
'."\n"; print $bookmarks; print '
'."\n"; print "\n"; } // Link to Dolibarr wiki pages if ($helppagename && empty($conf->global->MAIN_HELP_DISABLELINK)) { $langs->load("help"); $helpbaseurl=''; $helppage=''; $mode=''; // Get helpbaseurl, helppage and mode from helppagename and langs $arrayres=getHelpParamFor($helppagename,$langs); $helpbaseurl=$arrayres['helpbaseurl']; $helppage=$arrayres['helppage']; $mode=$arrayres['mode']; // Link to help pages if ($helpbaseurl && $helppage) { print ''; } } if (! empty($conf->global->MAIN_SHOW_BUGTRACK_LINK)) { // Link to 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"; print '
'."\n"; if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) print info_admin($langs->trans("WarningYouAreInMaintenanceMode",$conf->global->MAIN_ONLY_LOGIN_ALLOWED)); } /** * \brief Return helpbaseurl, helppage and mode * \param helppagename Page name (EN:xxx,ES:eee,FR:fff...) * \param langs Language */ function getHelpParamFor($helppagename,$langs) { if (preg_match('/^http/i',$helppagename)) { // If complete URL $helpbaseurl='%s'; $helppage=$helppagename; $mode='local'; } else { // If WIKI URL if (preg_match('/^es/i',$langs->defaultlang)) { $helpbaseurl='http://wiki.dolibarr.org/index.php/%s'; if (preg_match('/ES:([^|]+)/i',$helppagename,$reg)) $helppage=$reg[1]; } if (preg_match('/^fr/i',$langs->defaultlang)) { $helpbaseurl='http://wiki.dolibarr.org/index.php/%s'; if (preg_match('/FR:([^|]+)/i',$helppagename,$reg)) $helppage=$reg[1]; } if (empty($helppage)) // If help page not already found { $helpbaseurl='http://wiki.dolibarr.org/index.php/%s'; if (preg_match('/EN:([^|]+)/i',$helppagename,$reg)) $helppage=$reg[1]; } $mode='wiki'; } return array('helpbaseurl'=>$helpbaseurl,'helppage'=>$helppage,'mode'=>$mode); } /** * \brief Show a search area * \param urlaction Url post * \param urlobject Url of the link under the search box * \param title Title search area * \param htmlmodesearch 'search' * \param htmlinputname Field Name input form */ function printSearchForm($urlaction,$urlobject,$title,$htmlmodesearch='search',$htmlinputname) { global $langs; $ret=''; $ret.=''; $ret.='
'; $ret.=''; $ret.=''; $ret.=''; $ret.=' '; $ret.=''; $ret.="
\n"; return $ret; } /** * \brief Show HTML footer DIV + BODY + HTML * \remarks Close 2 div * \param foot A text to add in HTML generated page */ if (! function_exists("llxFooter")) { function llxFooter($foot='') { global $conf, $dolibarr_auto_user, $micro_start_time; print "\n\n".'
'."\n"; // print "\n".' '."\n"; print "\n".'
'."\n"; if (! empty($_SERVER['DOL_TUNING'])) { $micro_end_time=dol_microtime_float(true); print "\n".''."\n"; // Add Xdebug coverage of code if (defined('XDEBUGCOVERAGE')) { var_dump(xdebug_get_code_coverage()); } } if ($conf->use_javascript_ajax) { print ''."\n"; } // If there is some logs in buffer to show if (sizeof($conf->logbuffer)) { print "\n"; print "\n"; } print "\n"; if ($foot) print ''."\n"; if (! empty($conf->global->MAIN_HTML_FOOTER)) print $conf->global->MAIN_HTML_FOOTER."\n"; print "\n"; print "\n"; } } ?>