* Copyright (C) 2003 Xavier Dutoit * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2011 Philippe Grand * 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, see . */ /** * \file htdocs/main.inc.php * \ingroup core * \brief File that defines environment for Dolibarr pages only (variables not required by scripts) */ @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 code coverage //define('XDEBUGCOVERAGE',1); if (defined('XDEBUGCOVERAGE')) { xdebug_start_code_coverage(); } } // Removed magic_quotes if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* removed in PHP6 { if (get_magic_quotes_gpc()) { // 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 $db->escape when an insert / update. function stripslashes_deep($value) { return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value)); } $_GET = array_map('stripslashes_deep', $_GET); $_POST = array_map('stripslashes_deep', $_POST); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); @set_magic_quotes_runtime(0); } } // Security: SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST) function test_sql_and_script_inject($val,$get) { $sql_inj = 0; // For SQL Injection $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('/union.+select/i', $val); $sql_inj += preg_match('/(\.\.%2f)+/i', $val); // For XSS Injection done by adding javascript with script $sql_inj += preg_match('/'."\n"; print ''."\n"; print ''."\n"; print ''."\n"; //print ''."\n"; // jQuery Layout if (!empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) || defined('REQUIRE_JQUERY_LAYOUT')) { print ''."\n"; } // jQuery jnotify if (empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY)) print ''."\n"; // Flot print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; // CKEditor if (!empty($conf->fckeditor->enabled) && !empty($conf->global->FCKEDITOR_EDITORNAME) && $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor') { print ''."\n"; print ''."\n"; print ''."\n"; } // File Upload if (! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD)) { print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; } // Global js function print ''."\n"; print ''."\n"; } // Output module javascript if (is_array($arrayofjs)) { print ''."\n"; foreach($arrayofjs as $jsfile) { if (preg_match('/^http/i',$jsfile)) { print ''."\n"; } else { 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) 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 } /** * 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 * @param morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails) */ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='') { 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 (! empty($conf->global->MAIN_MENU_USE_JQUERY_ACCORDION)) { print "\n".''; } // Wrapper to show tooltips print "\n".''; } /* * Top menu */ $top_menu=isset($conf->browser->phone)?$conf->smart_menu:$conf->top_menu; if (GETPOST('menu')) $top_menu=GETPOST('menu'); // menu=eldy_backoffice.php // Load the top menu manager $result=dol_include_once("/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(); // This contains a \n print "
\n"; // Link to login card $loginhtmltext=''; $logintext=''; if ($user->societe_id) { $thirdpartystatic=new Societe($db); $thirdpartystatic->fetch($user->societe_id); $companylink=' ('.$thirdpartystatic->getNomUrl('','').')'; $company=' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')'; } $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").$company:$langs->trans("Internal")); $loginhtmltext.='
'.$langs->trans("Type").': '.$type; $loginhtmltext.='
'.$langs->trans("IPAddress").': '.$_SERVER["REMOTE_ADDR"]; $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"])); $appli='Dolibarr'; if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli=$conf->global->MAIN_APPLICATION_TITLE; // Link info $logouttext=''; $logouthtmltext=$appli.' '.DOL_VERSION.'
'; $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 '\n"; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print "
\n"; print "\n"; if (! $conf->use_javascript_ajax || ! $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print ''; } /** * 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 * @param leftmenuwithoutmainarea Must be set to 1. 0 by default for backward compatibility with old modules. * @param title Title of web page */ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $menu_array_after='', $leftmenuwithoutmainarea=0, $title='') { global $user, $conf, $langs, $db; $searchform=''; $bookmarks=''; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print "\n".'
'."\n"; else print '
'; print "\n"; print ''."\n"; print "\n"; print ''."\n"; if (empty($leftmenuwithoutmainarea)) main_area($title); } /** * Begin main area */ function main_area($title='') { global $conf, $langs; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) { print '
'."\n"; print '
'; print "\n"; // Instantiate hooks of thirdparty module include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); $hookmanager=new HookManager($db); $hookmanager->callHooks(array('searchform','leftblock')); // 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/list.php', DOL_URL_ROOT.'/contact/list.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'); } // Execute hook printSearchForm $parameters=array(); $searchform.=$hookmanager->executeHooks('printSearchForm',$parameters); // Note that $action and $object may have been modified by some hooks // 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=isset($conf->browser->phone)?$conf->smart_menu:$conf->top_menu; if (GETPOST('menu')) $left_menu=GETPOST('menu'); // menu=eldy_backoffice.php // Load the left menu manager $result=dol_include_once("/includes/menus/standard/".$left_menu); if (! $result) // If menu manager removed or not found { $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"; // Execute hook printLeftBlock $parameters=array(); $leftblock.=$hookmanager->executeHooks('printLeftBlock',$parameters); // Note that $action and $object may have been modified by some hooks print $leftblock; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print ' '."\n"; else print '
'; } print '
'."\n"; print "\n"; print '
'."\n"; if (preg_match('/^smartphone/',$conf->smart_menu) && isset($conf->browser->phone)) { print '
'; print '
'; print '
'."\n"; $appli='Dolibarr'; if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $appli=$conf->global->MAIN_APPLICATION_TITLE; print $appli; 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)); } /** * 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); } /** * 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 $conf,$langs; $ret=''; $ret.=''; $ret.='
'; $ret.=''; $ret.=''; $ret.=''; $ret.='global->MAIN_HTML5_PLACEHOLDER)) $ret.=' placeholder="'.$langs->trans("SearchOf").''.strip_tags($title).'"'; else $ret.=' title="'.$langs->trans("SearchOf").''.strip_tags($title).'"'; $ret.=' name="'.$htmlinputname.'" size="10" /> '; $ret.=''; $ret.="
\n"; return $ret; } /** * Show HTML footer * Close div /DIV data-role=page + /DIV class=fiche + /DIV /DIV main layout + /BODY + /HTML * @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"; if (preg_match('/^smartphone/',$conf->smart_menu) && isset($conf->browser->phone)) { print '
'."\n"; print '
'."\n"; } print '
'."\n"; print "\n".'
'."\n"; if ($conf->use_javascript_ajax && ! empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) print ' '."\n"; print "\n"; if ($foot) print ''."\n"; if (! empty($conf->global->MAIN_HTML_FOOTER)) print $conf->global->MAIN_HTML_FOOTER."\n"; // If there is some logs in buffer to show if (sizeof($conf->logbuffer)) { print "\n"; print "\n"; } // End of tuning 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()); } } print "\n"; print "\n"; } } ?>