* 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', '64M'); // 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' // JQuery. Must be before other includes (prototype/scriptaculous) print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; if ($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT || defined('REQUIRE_JQUERY_LAYOUT')) { print ''."\n"; } // This one is required for some Ajax features if (! defined('DISABLE_PROTOTYPE') && $conf->global->MAIN_USE_PROTOTYPE) { print ''."\n"; print ''."\n"; } } // Output module javascript if (is_array($arrayofjs)) { print ''."\n"; foreach($arrayofjs as $jsfile) { if (! preg_match('/^\//',$jsfile)) $jsfile='/'.$jsfile; // For backward compatibility 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($head)) print $head."\n"; if (! empty($conf->global->MAIN_HTML_HEADER)) print $conf->global->MAIN_HTML_HEADER."\n"; print "\n\n"; } $conf->headerdone=1; // To tell header was output } /** * \brief Show an HTML header + a BODY + The top menu bar * \param head Lines in the HEAD * \param title Title of web page * \param target Target to use in menu links * \param disablejs Do not output links to js (Ex: qd fonction utilisee par sous formulaire Ajax) * \param disablehead Do not output head section * \param arrayofjs Array of js files to add in header * \param arrayofcss Array of css files to add in header */ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='') { global $user, $conf, $langs, $db, $dolibarr_main_authentication; $html=new Form($db); if (! $conf->top_menu) $conf->top_menu ='eldy_backoffice.php'; // For backward compatibility with old modules if (empty($conf->headerdone)) top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); print ''; if ($conf->use_javascript_ajax) { if ($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) { print ''; } if ($conf->global->MAIN_MENU_USE_JQUERY_ACCORDION) { print "\n".''; } // Wrapper to show tooltips print "\n".''; } /* * Top menu */ $top_menu=$conf->top_menu; if (GETPOST('top_menu')) $top_menu=GETPOST('top_menu'); // Load the top menu manager $result=@include_once(DOL_DOCUMENT_ROOT ."/includes/menus/standard/".$top_menu); if (! $result) // If failed to include, we try with standard { $top_menu='eldy_backoffice.php'; include_once(DOL_DOCUMENT_ROOT ."/includes/menus/standard/".$top_menu); } print "\n".''."\n"; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print '
'."\n"; print '
'."\n"; // Show menu $menutop = new MenuTop($db); $menutop->atarget=$target; $menutop->showmenu(); // Select entity if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY)) { if ($user->admin && ! $user->entity) { $res=@include_once(DOL_DOCUMENT_ROOT.'/multicompany/class/actions_multicompany.class.php'); if ($res) { //$mc = new ActionsMulticompany($db); $entitytext = img_object('', 'globe','entity'); $entityhtmltext = 'EntityName'; print $html->textwithtooltip('',$entityhtmltext,2,1,$entitytext); //$select_entity = '
'.$mc->select_entities($conf->entity).'
'; //if ($mc->numEntity >= 1) print $select_entity; } } } // Link to login card $loginhtmltext=''; $logintext=''; $logintext=''; $loginhtmltext.=''.$langs->trans("User").''; $loginhtmltext.='
'.$langs->trans("Name").': '.$user->getFullName($langs); $loginhtmltext.='
'.$langs->trans("Login").': '.$user->login; $loginhtmltext.='
'.$langs->trans("Administrator").': '.yn($user->admin); $type=($user->societe_id?$langs->trans("External"):$langs->trans("Internal")); if ($user->societe_id) { $thirdpartystatic=new Societe($db); $thirdpartystatic->fetch($user->societe_id); $type.=' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')'; } $loginhtmltext.='
'.$langs->trans("Type").': '.$type; $loginhtmltext.='
'; $loginhtmltext.='
'.$langs->trans("Connection").''; if ($conf->global->MAIN_MODULE_MULTICOMPANY) $loginhtmltext.='
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$user->entity.')'; $loginhtmltext.='
'.$langs->trans("ConnectedSince").': '.dol_print_date($user->datelastlogin,"dayhour"); $loginhtmltext.='
'.$langs->trans("PreviousConnexion").': '.dol_print_date($user->datepreviouslogin,"dayhour"); $loginhtmltext.='
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"]; $loginhtmltext.='
'.$langs->trans("CurrentTheme").': '.$conf->theme; $s=picto_from_langcode($langs->getDefaultLang()); $loginhtmltext.='
'.$langs->trans("CurrentUserLanguage").': '.($s?$s.' ':'').$langs->getDefaultLang(); $loginhtmltext.='
'.$langs->trans("Browser").': '.$conf->browser->name.' ('.$_SERVER['HTTP_USER_AGENT'].')'; if (! empty($conf->browser->phone)) $loginhtmltext.='
'.$langs->trans("Phone").': '.$conf->browser->phone; if (! empty($_SESSION["disablemodules"])) $loginhtmltext.='
'.$langs->trans("DisabledModules").':
'.join('
',explode(',',$_SESSION["disablemodules"])); // Link info $logouthtmltext=''; $logouttext=''; $logouthtmltext=$langs->trans("Logout").'
'; //$logouthtmltext.="
"; if ($_SESSION["dol_authmode"] != 'forceuser' && $_SESSION["dol_authmode"] != 'http') { $logouttext.='atarget?(' target="'.$menutop->atarget.'"'):''; $logouttext.='>'; $logouttext.='trans("Logout")).'" title=""'; $logouttext.='>'; $logouttext.=''; } else { $logouttext.='trans("Logout")).'" title=""'; $logouttext.='>'; } print $html->textwithtooltip('',$loginhtmltext,2,1,$logintext); print $html->textwithtooltip('',$logouthtmltext,2,1,$logouttext); // Link to print main content area if (empty($conf->global->MAIN_PRINT_DISABLELINK) && empty($conf->browser->phone)) { $text =''; $text.='textwithtooltip('',$langs->trans("PrintContentArea"),2,1,$text); } print "\n
\n\n"; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print "
\n"; else print ''; } /** * \brief Show left menu bar * \param menu_array_before Table of menu entries to show before entries of menu handler * \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 * \param menu_array_after Table of menu entries to show after entries of menu handler */ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $menu_array_after='') { global $user, $conf, $langs, $db; $searchform=''; $bookmarks=''; // print '
'."\n"; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print "\n".'
'."\n"; if (! $conf->use_javascript_ajax || ! $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print '
'; print ''."\n"; // print ''."\n"; // print '
'."\n"; } /** * Begin main area */ function main_area() { global $conf, $langs; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print '
'."\n"; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) 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/societe.php', DOL_URL_ROOT.'/societe/societe.php', img_object('','company').' '.$langs->trans("ThirdParties"), '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->product->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/liste.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_menu=$conf->left_menu; $left_menu=$conf->top_menu; if (GETPOST('left_menu')) $left_menu=GETPOST('left_menu'); // Load the left menu manager $result=@include_once(DOL_DOCUMENT_ROOT ."/includes/menus/standard/".$left_menu); if (! $result) { $left_menu='eldy_backoffice.php'; include_once(DOL_DOCUMENT_ROOT ."/includes/menus/standard/".$left_menu); } // Left column print ''."\n"; print '
'."\n"; $menuleft=new MenuLeft($db,$menu_array_before,$menu_array_after); $menuleft->showmenu(); // output menu_array and menu found in database // Show other forms if ($searchform) { print "\n"; print "\n"; print '
'."\n"; print $searchform; print '
'."\n"; print "\n"; } // More search form if ($moresearchform) { print $moresearchform; } // Bookmarks 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 ''; } } // Link to bugtrack if (! empty($conf->global->MAIN_SHOW_BUGTRACK_LINK)) { $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"; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print ' '."\n"; else print '
'; 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; } /** * Return list of login method of third party module. * @return array */ function getLoginMethod() { global $conf,$langs; $login = ''; foreach($conf->login_method_modules as $dir) { // Check if directory exists if (!is_dir($dir)) continue; $handle=opendir($dir); while (($file = readdir($handle))!==false) { if (is_readable($dir.'/'.$file) && preg_match('/^functions_([^_]+)\.php/',$file,$reg)) { $authfile = $dir.'/'.$file; $mode = $reg[1]; $result=include_once($authfile); if ($result) { // Call function to check user/password $usertotest=$_POST["username"]; $passwordtotest=$_POST["password"]; $function='check_user_password_'.$mode; $login=$function($usertotest,$passwordtotest); if ($login) { $conf->authmode=$mode; // This properties is defined only when logged } } else { dol_syslog("Authentification ko - failed to load file '".$authfile."'",LOG_ERR); sleep(1); $langs->load('main'); $langs->load('other'); $_SESSION["dol_loginmesg"]=$langs->trans("ErrorFailedToLoadLoginFileForMode",$mode); } } } closedir($handle); } return $login; } /** * \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, $langs, $dolibarr_auto_user, $micro_start_time; // Core error message if (defined("MAIN_CORE_ERROR") && constant("MAIN_CORE_ERROR") == 1) { // Ajax version if ($conf->use_javascript_ajax) { $title = img_warning().' '.$langs->trans('CoreErrorTitle'); print ajax_dialog($title, $langs->trans('CoreErrorMessage')); } // html version else { $msg = img_warning().' '.$langs->trans('CoreErrorMessage'); print '
'.$msg.'
'; } define("MAIN_CORE_ERROR",0); } print "\n\n".'
'."\n"; // print "\n".' '."\n"; print "\n".'
'."\n"; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print ' '."\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 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"; } } ?>