PageRenderTime 55ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/main.inc.php

https://github.com/asterix14/dolibarr
PHP | 1616 lines | 1230 code | 149 blank | 237 comment | 225 complexity | eb717a7f7df4043b49304157eeea19f2 MD5 | raw file
Possible License(s): LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
  4. * Copyright (C) 2004-2011 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. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  8. * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
  9. * Copyright (C) 2008 Matteli
  10. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/main.inc.php
  27. * \ingroup core
  28. * \brief File that defines environment for Dolibarr pages only (variables not required by scripts)
  29. */
  30. //@ini_set('memory_limit', '64M'); // This may be useless if memory is hard limited by your PHP
  31. // For optionnal tuning. Enabled if environment variable DOL_TUNING is defined.
  32. // A call first. Is the equivalent function dol_microtime_float not yet loaded.
  33. $micro_start_time=0;
  34. if (! empty($_SERVER['DOL_TUNING']))
  35. {
  36. list($usec, $sec) = explode(" ", microtime());
  37. $micro_start_time=((float) $usec + (float) $sec);
  38. // Add Xdebug code coverage
  39. //define('XDEBUGCOVERAGE',1);
  40. if (defined('XDEBUGCOVERAGE')) { xdebug_start_code_coverage(); }
  41. }
  42. // Removed magic_quotes
  43. if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* removed in PHP6
  44. {
  45. if (get_magic_quotes_gpc())
  46. {
  47. // Forcing parameter setting magic_quotes_gpc and cleaning parameters
  48. // (Otherwise he would have for each position, condition
  49. // Reading stripslashes variable according to state get_magic_quotes_gpc).
  50. // Off mode (recommended, you just do $db->escape when an insert / update.
  51. function stripslashes_deep($value)
  52. {
  53. return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value));
  54. }
  55. $_GET = array_map('stripslashes_deep', $_GET);
  56. $_POST = array_map('stripslashes_deep', $_POST);
  57. //$_COOKIE = array_map('stripslashes_deep', $_COOKIE); // Useless because a cookie should never be outputed on screen nor used into sql
  58. @set_magic_quotes_runtime(0);
  59. }
  60. }
  61. /**
  62. * Security: SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST, PHP_SELF)
  63. *
  64. * @param string $val Value
  65. * @param string $type 1=GET, 0=POST, 2=PHP_SELF
  66. * @return boolean true if there is an injection
  67. */
  68. function test_sql_and_script_inject($val, $type)
  69. {
  70. $sql_inj = 0;
  71. // For SQL Injection (only GET and POST are used to be included into bad escaped SQL requests)
  72. if ($type != 2)
  73. {
  74. $sql_inj += preg_match('/delete[\s]+from/i', $val);
  75. $sql_inj += preg_match('/create[\s]+table/i', $val);
  76. $sql_inj += preg_match('/update.+set.+=/i', $val);
  77. $sql_inj += preg_match('/insert[\s]+into/i', $val);
  78. $sql_inj += preg_match('/select.+from/i', $val);
  79. $sql_inj += preg_match('/union.+select/i', $val);
  80. $sql_inj += preg_match('/(\.\.%2f)+/i', $val);
  81. }
  82. // For XSS Injection done by adding javascript with script
  83. // This is all cases a browser consider text is javascript:
  84. // When it found '<script', 'javascript:', '<style', 'onload\s=' on body tag, '="&' on a tag size with old browsers
  85. // All examples on page: http://ha.ckers.org/xss.html#XSScalc
  86. $sql_inj += preg_match('/<script/i', $val);
  87. $sql_inj += preg_match('/<style/i', $val);
  88. $sql_inj += preg_match('/base[\s]+href/i', $val);
  89. if ($type == 1)
  90. {
  91. $sql_inj += preg_match('/javascript:/i', $val);
  92. $sql_inj += preg_match('/vbscript:/i', $val);
  93. }
  94. // For XSS Injection done by adding javascript closing html tags like with onmousemove, etc... (closing a src or href tag with not cleaned param)
  95. if ($type == 1) $sql_inj += preg_match('/"/i', $val); // We refused " in GET parameters value
  96. if ($type == 2) $sql_inj += preg_match('/[\s;"]/', $val); // PHP_SELF is an url and must match url syntax
  97. return $sql_inj;
  98. }
  99. /**
  100. * Security: Return true if OK, false otherwise
  101. *
  102. * @param string &$var Variable name
  103. * @param string $type 1=GET, 0=POST, 2=PHP_SELF
  104. * @return boolean true if ther is an injection
  105. */
  106. function analyse_sql_and_script(&$var, $type)
  107. {
  108. if (is_array($var))
  109. {
  110. foreach ($var as $key => $value)
  111. {
  112. if (analyse_sql_and_script($value,$type))
  113. {
  114. $var[$key] = $value;
  115. }
  116. else
  117. {
  118. print 'Access refused by SQL/Script injection protection in main.inc.php';
  119. exit;
  120. }
  121. }
  122. return true;
  123. }
  124. else
  125. {
  126. return (test_sql_and_script_inject($var,$type) <= 0);
  127. }
  128. }
  129. // Sanity check on URL
  130. if (! empty($_SERVER["PHP_SELF"]))
  131. {
  132. $morevaltochecklikepost=array($_SERVER["PHP_SELF"]);
  133. analyse_sql_and_script($morevaltochecklikepost,2);
  134. }
  135. // Sanity check on GET parameters
  136. if (! empty($_SERVER["QUERY_STRING"]))
  137. {
  138. $morevaltochecklikeget=array($_SERVER["QUERY_STRING"]);
  139. analyse_sql_and_script($morevaltochecklikeget,1);
  140. }
  141. // Sanity check on POST
  142. analyse_sql_and_script($_POST,0);
  143. // This is to make Dolibarr working with Plesk
  144. if (! empty($_SERVER['DOCUMENT_ROOT'])) set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
  145. // Include the conf.php and functions.lib.php
  146. require_once("filefunc.inc.php");
  147. // Init session. Name of session is specific to Dolibarr instance.
  148. $prefix=dol_getprefix();
  149. $sessionname='DOLSESSID_'.$prefix;
  150. $sessiontimeout='DOLSESSTIMEOUT_'.$prefix;
  151. if (! empty($_COOKIE[$sessiontimeout])) ini_set('session.gc_maxlifetime',$_COOKIE[$sessiontimeout]);
  152. session_name($sessionname);
  153. session_start();
  154. // Init the 5 global objects
  155. // This include will set: $conf, $db, $langs, $user, $mysoc objects
  156. require_once("master.inc.php");
  157. // Activate end of page function
  158. register_shutdown_function('dol_shutdown');
  159. // Detection browser
  160. if (isset($_SERVER["HTTP_USER_AGENT"]))
  161. {
  162. // If phone/smartphone, we set phone os name.
  163. if (preg_match('/android/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->phone='android';
  164. elseif (preg_match('/blackberry/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->phone='blackberry';
  165. elseif (preg_match('/iphone/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->phone='iphone';
  166. elseif (preg_match('/ipod/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->phone='iphone';
  167. elseif (preg_match('/palm/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->phone='palm';
  168. elseif (preg_match('/symbian/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->phone='symbian';
  169. elseif (preg_match('/webos/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->phone='webos';
  170. elseif (preg_match('/maemo/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->phone='maemo';
  171. // MS products at end
  172. elseif (preg_match('/iemobile/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->phone='windowsmobile';
  173. elseif (preg_match('/windows ce/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->phone='windowsmobile';
  174. // Name
  175. if (preg_match('/firefox/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->name='firefox';
  176. elseif (preg_match('/chrome/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->name='chrome';
  177. elseif (preg_match('/iceweasel/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->name='iceweasel';
  178. elseif ((empty($conf->browser->phone) || preg_match('/iphone/i',$_SERVER["HTTP_USER_AGENT"])) && preg_match('/safari/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->name='safari'; // Safari is often present in string but its not.
  179. elseif (preg_match('/opera/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->name='opera';
  180. // MS products at end
  181. elseif (preg_match('/msie/i',$_SERVER["HTTP_USER_AGENT"])) $conf->browser->name='ie';
  182. else $conf->browser->name='unknown';
  183. // Other
  184. if (in_array($conf->browser->name,array('firefox','iceweasel'))) $conf->browser->firefox=1;
  185. //$conf->browser->phone='android';
  186. }
  187. // Force HTTPS if required ($conf->file->main_force_https is 0/1 or https dolibarr root url)
  188. if (! empty($conf->file->main_force_https))
  189. {
  190. $newurl='';
  191. if ($conf->file->main_force_https == '1')
  192. {
  193. if (! empty($_SERVER["SCRIPT_URI"])) // If SCRIPT_URI supported by server
  194. {
  195. if (preg_match('/^http:/i',$_SERVER["SCRIPT_URI"]) && ! preg_match('/^https:/i',$_SERVER["SCRIPT_URI"])) // If link is http
  196. {
  197. $newurl=preg_replace('/^http:/i','https:',$_SERVER["SCRIPT_URI"]);
  198. }
  199. }
  200. else // Check HTTPS environment variable (Apache/mod_ssl only)
  201. {
  202. // $_SERVER["HTTPS"] is 'on' when link is https, otherwise $_SERVER["HTTPS"] is empty or 'off'
  203. if (empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on') // If link is http
  204. {
  205. $newurl=preg_replace('/^http:/i','https:',DOL_MAIN_URL_ROOT).$_SERVER["REQUEST_URI"];
  206. }
  207. }
  208. }
  209. else
  210. {
  211. $newurl=$conf->file->main_force_https.$_SERVER["REQUEST_URI"];
  212. }
  213. // Start redirect
  214. if ($newurl)
  215. {
  216. dol_syslog("main.inc: dolibarr_main_force_https is on, we make a redirect to ".$newurl);
  217. header("Location: ".$newurl);
  218. exit;
  219. }
  220. else
  221. {
  222. dol_syslog("main.inc: dolibarr_main_force_https is on but we failed to forge new https url so no redirect is done", LOG_WARNING);
  223. }
  224. }
  225. // Chargement des includes complementaires de presentation
  226. if (! defined('NOREQUIREMENU')) require_once(DOL_DOCUMENT_ROOT ."/core/class/menu.class.php"); // Need 10ko memory (11ko in 2.2)
  227. if (! defined('NOREQUIREHTML')) require_once(DOL_DOCUMENT_ROOT ."/core/class/html.form.class.php"); // Need 660ko memory (800ko in 2.2)
  228. if (! defined('NOREQUIREAJAX') && $conf->use_javascript_ajax) require_once(DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'); // Need 22ko memory
  229. // If install or upgrade process not done or not completely finished, we call the install page.
  230. if (! empty($conf->global->MAIN_NOT_INSTALLED) || ! empty($conf->global->MAIN_NOT_UPGRADED))
  231. {
  232. dol_syslog("main.inc: A previous install or upgrade was not complete. Redirect to install page.", LOG_WARNING);
  233. Header("Location: ".DOL_URL_ROOT."/install/index.php");
  234. exit;
  235. }
  236. // If an upgrade process is required, we call the install page.
  237. if ((! empty($conf->global->MAIN_VERSION_LAST_UPGRADE) && ($conf->global->MAIN_VERSION_LAST_UPGRADE != DOL_VERSION))
  238. || (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) && ! empty($conf->global->MAIN_VERSION_LAST_INSTALL) && ($conf->global->MAIN_VERSION_LAST_INSTALL != DOL_VERSION)))
  239. {
  240. $versiontocompare=empty($conf->global->MAIN_VERSION_LAST_UPGRADE)?$conf->global->MAIN_VERSION_LAST_INSTALL:$conf->global->MAIN_VERSION_LAST_UPGRADE;
  241. require_once(DOL_DOCUMENT_ROOT ."/core/lib/admin.lib.php");
  242. $dolibarrversionlastupgrade=preg_split('/[.-]/',$versiontocompare);
  243. $dolibarrversionprogram=preg_split('/[.-]/',DOL_VERSION);
  244. $rescomp=versioncompare($dolibarrversionprogram,$dolibarrversionlastupgrade);
  245. if ($rescomp > 0) // Programs have a version higher than database. We did not add "&& $rescomp < 3" because we want upgrade process for build upgrades
  246. {
  247. dol_syslog("main.inc: database version ".$versiontocompare." is lower than programs version ".DOL_VERSION.". Redirect to install page.", LOG_WARNING);
  248. Header("Location: ".DOL_URL_ROOT."/install/index.php");
  249. exit;
  250. }
  251. }
  252. // Creation of a token against CSRF vulnerabilities
  253. if (! defined('NOTOKENRENEWAL'))
  254. {
  255. $token = dol_hash(uniqid(mt_rand(),TRUE)); // Genere un hash d'un nombre aleatoire
  256. // roulement des jetons car cree a chaque appel
  257. if (isset($_SESSION['newtoken'])) $_SESSION['token'] = $_SESSION['newtoken'];
  258. $_SESSION['newtoken'] = $token;
  259. }
  260. if (! empty($conf->global->MAIN_SECURITY_CSRF)) // Check validity of token, only if option enabled (this option breaks some features sometimes)
  261. {
  262. if (isset($_POST['token']) && isset($_SESSION['token']))
  263. {
  264. if (($_POST['token'] != $_SESSION['token']))
  265. {
  266. dol_syslog("Invalid token in ".$_SERVER['HTTP_REFERER'].", action=".$_POST['action'].", _POST['token']=".$_POST['token'].", _SESSION['token']=".$_SESSION['token'],LOG_WARNING);
  267. //print 'Unset POST by CSRF protection in main.inc.php.'; // Do not output anything because this create problems when using the BACK button on browsers.
  268. unset($_POST);
  269. }
  270. }
  271. }
  272. // Disable modules (this must be after session_start and after conf has been loaded)
  273. if (GETPOST('disablemodules')) $_SESSION["disablemodules"]=GETPOST('disablemodules');
  274. if (! empty($_SESSION["disablemodules"]))
  275. {
  276. $disabled_modules=explode(',',$_SESSION["disablemodules"]);
  277. foreach($disabled_modules as $module)
  278. {
  279. if ($module) $conf->$module->enabled=false;
  280. }
  281. }
  282. /*
  283. * Phase authentication / login
  284. */
  285. $login='';
  286. if (! defined('NOLOGIN'))
  287. {
  288. // $authmode lists the different means of identification to be tested in order of preference.
  289. // Example: 'http'
  290. // Example: 'dolibarr'
  291. // Example: 'ldap'
  292. // Example: 'http,forceuser'
  293. // Authentication mode
  294. if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='http,dolibarr';
  295. // Authentication mode: forceuser
  296. if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user='auto';
  297. // Set authmode
  298. $authmode=explode(',',$dolibarr_main_authentication);
  299. // No authentication mode
  300. if (! count($authmode) && empty($conf->login_method_modules))
  301. {
  302. $langs->load('main');
  303. dol_print_error('',$langs->trans("ErrorConfigParameterNotDefined",'dolibarr_main_authentication'));
  304. exit;
  305. }
  306. // If requested by the login has already occurred, it is retrieved from the session
  307. // Call module if not realized that his request.
  308. // At the end of this phase, the variable $login is defined.
  309. $resultFetchUser='';
  310. $test=true;
  311. if (! isset($_SESSION["dol_login"]))
  312. {
  313. // It is not already authenticated, it requests the login / password
  314. // If in demo mode, we check we go to home page through the public/demo/index.php page
  315. if ($dolibarr_main_demo && $_SERVER['PHP_SELF'] == DOL_URL_ROOT.'/index.php') // We ask index page
  316. {
  317. if (! preg_match('/public/',$_SERVER['HTTP_REFERER']))
  318. {
  319. dol_syslog("Call index page from another url than demo page");
  320. header("Location: ".DOL_URL_ROOT.'/public/demo/index.php');
  321. exit;
  322. }
  323. }
  324. // Verification security graphic code
  325. if (GETPOST("username","alpha",2) && ! empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA))
  326. {
  327. require_once(ARTICHOW_PATH.'Artichow.cfg.php');
  328. require_once(ARTICHOW.'/AntiSpam.class.php');
  329. $object = new AntiSpam();
  330. // Verifie code
  331. if (! $object->check('dol_antispam_value',$_POST['code'],true))
  332. {
  333. dol_syslog('Bad value for code, connexion refused');
  334. $langs->load('main');
  335. $langs->load('errors');
  336. $user->trigger_mesg='ErrorBadValueForCode - login='.GETPOST("username","alpha",2);
  337. $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadValueForCode");
  338. $test=false;
  339. // Appel des triggers
  340. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  341. $interface=new Interfaces($db);
  342. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf,GETPOST('entity'));
  343. if ($result < 0) { $error++; }
  344. // Fin appel triggers
  345. }
  346. }
  347. $usertotest = (! empty($_COOKIE['login_dolibarr']) ? $_COOKIE['login_dolibarr'] : GETPOST("username","alpha",2));
  348. $passwordtotest = (! empty($_COOKIE['password_dolibarr']) ? $_COOKIE['password_dolibarr'] : $_POST["password"]);
  349. $entitytotest = (! empty($_POST["entity"]) ? $_POST["entity"] : 1);
  350. // Validation of login/pass/entity
  351. // If ok, the variable login will be returned
  352. // If error, we will put error message in session under the name dol_loginmesg
  353. $goontestloop=false;
  354. if (isset($_SERVER["REMOTE_USER"]) && in_array('http',$authmode)) $goontestloop=true;
  355. if (GETPOST("username","alpha",2) || ! empty($_COOKIE['login_dolibarr']) || GETPOST('openid_mode','alpha',1)) $goontestloop=true;
  356. if ($test && $goontestloop)
  357. {
  358. $login = checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmode);
  359. if ($login)
  360. {
  361. $dol_authmode=$conf->authmode; // This properties is defined only when logged to say what mode was successfully used
  362. $dol_tz=$_POST["tz"];
  363. $dol_dst=0;
  364. if (isset($_POST["dst_first"]) && isset($_POST["dst_second"]))
  365. {
  366. $datenow=dol_now();
  367. $datefirst=dol_stringtotime($_POST["dst_first"]);
  368. $datesecond=dol_stringtotime($_POST["dst_second"]);
  369. if ($datenow >= $datefirst && $datenow < $datesecond) $dol_dst=1;
  370. }
  371. //print $datefirst.'-'.$datesecond.'-'.$datenow; exit;
  372. $dol_dst_observed=$_POST["dst_observed"];
  373. $dol_dst_first=$_POST["dst_first"];
  374. $dol_dst_second=$_POST["dst_second"];
  375. $dol_screenwidth=$_POST["screenwidth"];
  376. $dol_screenheight=$_POST["screenheight"];
  377. }
  378. if (! $login)
  379. {
  380. dol_syslog('Bad password, connexion refused',LOG_DEBUG);
  381. $langs->load('main');
  382. $langs->load('errors');
  383. // Bad password. No authmode has found a good password.
  384. $user->trigger_mesg=$langs->trans("ErrorBadLoginPassword").' - login='.GETPOST("username","alpha",2);
  385. $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword");
  386. // Appel des triggers
  387. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  388. $interface=new Interfaces($db);
  389. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf,GETPOST("username","alpha",2));
  390. if ($result < 0) { $error++; }
  391. // Fin appel triggers
  392. }
  393. }
  394. // End test login / passwords
  395. if (! $login)
  396. {
  397. // We show login page
  398. if (! is_object($langs)) // This can occurs when calling page with NOREQUIRETRAN defined
  399. {
  400. include_once(DOL_DOCUMENT_ROOT."/core/class/translate.class.php");
  401. $langs=new Translate("",$conf);
  402. }
  403. dol_loginfunction($langs,$conf,$mysoc);
  404. exit;
  405. }
  406. $resultFetchUser=$user->fetch('',$login);
  407. if ($resultFetchUser <= 0)
  408. {
  409. dol_syslog('User not found, connexion refused');
  410. session_destroy();
  411. session_name($sessionname);
  412. session_start();
  413. if ($resultFetchUser == 0)
  414. {
  415. $langs->load('main');
  416. $langs->load('errors');
  417. $user->trigger_mesg='ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
  418. $_SESSION["dol_loginmesg"]=$langs->trans("ErrorCantLoadUserFromDolibarrDatabase",$login);
  419. }
  420. if ($resultFetchUser < 0)
  421. {
  422. $user->trigger_mesg=$user->error;
  423. $_SESSION["dol_loginmesg"]=$user->error;
  424. }
  425. // Call triggers
  426. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  427. $interface=new Interfaces($db);
  428. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf,$_POST["entity"]);
  429. if ($result < 0) { $error++; }
  430. // End call triggers
  431. header('Location: '.DOL_URL_ROOT.'/index.php');
  432. exit;
  433. }
  434. }
  435. else
  436. {
  437. // We are already into an authenticated session
  438. $login=$_SESSION["dol_login"];
  439. dol_syslog("This is an already logged session. _SESSION['dol_login']=".$login);
  440. $resultFetchUser=$user->fetch('',$login);
  441. if ($resultFetchUser <= 0)
  442. {
  443. // Account has been removed after login
  444. dol_syslog("Can't load user even if session logged. _SESSION['dol_login']=".$login, LOG_WARNING);
  445. session_destroy();
  446. session_name($sessionname);
  447. session_start();
  448. if ($resultFetchUser == 0)
  449. {
  450. $langs->load('main');
  451. $langs->load('errors');
  452. $user->trigger_mesg='ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
  453. $_SESSION["dol_loginmesg"]=$langs->trans("ErrorCantLoadUserFromDolibarrDatabase",$login);
  454. }
  455. if ($resultFetchUser < 0)
  456. {
  457. $user->trigger_mesg=$user->error;
  458. $_SESSION["dol_loginmesg"]=$user->error;
  459. }
  460. // Call triggers
  461. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  462. $interface=new Interfaces($db);
  463. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf,(isset($_POST["entity"])?$_POST["entity"]:0));
  464. if ($result < 0) { $error++; }
  465. // End call triggers
  466. header('Location: '.DOL_URL_ROOT.'/index.php');
  467. exit;
  468. }
  469. else
  470. {
  471. if (! empty($conf->global->MAIN_ACTIVATE_UPDATESESSIONTRIGGER)) // We do not execute such trigger at each page load by default
  472. {
  473. // Call triggers
  474. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  475. $interface=new Interfaces($db);
  476. $result=$interface->run_triggers('USER_UPDATE_SESSION',$user,$user,$langs,$conf,$conf->entity);
  477. if ($result < 0) { $error++; }
  478. // End call triggers
  479. }
  480. }
  481. }
  482. // Is it a new session that has started ?
  483. // If we are here, this means authentication was successfull.
  484. if (! isset($_SESSION["dol_login"]))
  485. {
  486. $error=0;
  487. // New session for this login
  488. $_SESSION["dol_login"]=$user->login;
  489. $_SESSION["dol_authmode"]=isset($dol_authmode)?$dol_authmode:'';
  490. $_SESSION["dol_tz"]=isset($dol_tz)?$dol_tz:'';
  491. $_SESSION["dol_dst"]=isset($dol_dst)?$dol_dst:'';
  492. $_SESSION["dol_dst_observed"]=isset($dol_dst_observed)?$dol_dst_observed:'';
  493. $_SESSION["dol_dst_first"]=isset($dol_dst_first)?$dol_dst_first:'';
  494. $_SESSION["dol_dst_second"]=isset($dol_dst_second)?$dol_dst_second:'';
  495. $_SESSION["dol_screenwidth"]=isset($dol_screenwidth)?$dol_screenwidth:'';
  496. $_SESSION["dol_screenheight"]=isset($dol_screenheight)?$dol_screenheight:'';
  497. $_SESSION["dol_company"]=$conf->global->MAIN_INFO_SOCIETE_NOM;
  498. if (! empty($conf->multicompany->enabled)) $_SESSION["dol_entity"]=$conf->entity;
  499. dol_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"].' Session id='.session_id());
  500. $db->begin();
  501. $user->update_last_login_date();
  502. // Call triggers
  503. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  504. $interface=new Interfaces($db);
  505. $result=$interface->run_triggers('USER_LOGIN',$user,$user,$langs,$conf,$_POST["entity"]);
  506. if ($result < 0) { $error++; }
  507. // End call triggers
  508. if ($error)
  509. {
  510. $db->rollback();
  511. session_destroy();
  512. dol_print_error($db,'Error in some triggers on action USER_LOGIN',LOG_ERR);
  513. exit;
  514. }
  515. else
  516. {
  517. $db->commit();
  518. }
  519. // Create entity cookie, just used for login page
  520. if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY) && !empty($conf->global->MAIN_MULTICOMPANY_COOKIE) && isset($_POST["entity"]))
  521. {
  522. include_once(DOL_DOCUMENT_ROOT."/core/class/cookie.class.php");
  523. $entity = $_SESSION["dol_login"].'|'.$_POST["entity"];
  524. $prefix=dol_getprefix();
  525. $entityCookieName = 'DOLENTITYID_'.$prefix;
  526. // TTL : is defined in the config page multicompany
  527. $ttl = (! empty($conf->global->MAIN_MULTICOMPANY_COOKIE_TTL) ? $conf->global->MAIN_MULTICOMPANY_COOKIE_TTL : time()+60*60*8 );
  528. // Cryptkey : will be created randomly in the config page multicompany
  529. $cryptkey = (! empty($conf->file->cookie_cryptkey) ? $conf->file->cookie_cryptkey : '' );
  530. $entityCookie = new DolCookie($cryptkey);
  531. $entityCookie->_setCookie($entityCookieName, $entity, $ttl);
  532. }
  533. // Hooks on successfull login
  534. $action='';
  535. include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
  536. $hookmanager=new HookManager($db);
  537. $hookmanager->callHooks(array('login'));
  538. $parameters=array('dol_authmode'=>$dol_authmode);
  539. $reshook=$hookmanager->executeHooks('afterLogin',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  540. if ($reshook < 0) $error++;
  541. }
  542. // If user admin, we force the rights-based modules
  543. if ($user->admin)
  544. {
  545. $user->rights->user->user->lire=1;
  546. $user->rights->user->user->creer=1;
  547. $user->rights->user->user->password=1;
  548. $user->rights->user->user->supprimer=1;
  549. $user->rights->user->self->creer=1;
  550. $user->rights->user->self->password=1;
  551. }
  552. /*
  553. * Overwrite configs global by peronal configs
  554. */
  555. // Set liste_limit
  556. if (isset($user->conf->MAIN_SIZE_LISTE_LIMIT)) // Can be 0
  557. {
  558. $conf->liste_limit = $user->conf->MAIN_SIZE_LISTE_LIMIT;
  559. }
  560. if (isset($user->conf->PRODUIT_LIMIT_SIZE)) // Can be 0
  561. {
  562. $conf->product->limit_size = $user->conf->PRODUIT_LIMIT_SIZE;
  563. }
  564. // Replace conf->css by personalized value
  565. if (isset($user->conf->MAIN_THEME) && $user->conf->MAIN_THEME)
  566. {
  567. $conf->theme=$user->conf->MAIN_THEME;
  568. $conf->css = "/theme/".$conf->theme."/style.css.php";
  569. }
  570. // If theme support optim like flip-hide left menu and we use a smartphone, we force it
  571. if (! empty($conf->global->MAIN_SMARTPHONE_OPTIM) && $conf->browser->phone && $conf->theme == 'eldy') $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT='forced';
  572. // Set javascript option
  573. if (! GETPOST('nojs')) // If javascript was not disabled on URL
  574. {
  575. if (! empty($user->conf->MAIN_DISABLE_JAVASCRIPT))
  576. {
  577. $conf->use_javascript_ajax=! $user->conf->MAIN_DISABLE_JAVASCRIPT;
  578. }
  579. }
  580. else $conf->use_javascript_ajax=0;
  581. }
  582. if (! defined('NOREQUIRETRAN'))
  583. {
  584. if (! GETPOST('lang')) // If language was not forced on URL
  585. {
  586. // If user has chosen its own language
  587. if (! empty($user->conf->MAIN_LANG_DEFAULT))
  588. {
  589. // If different than current language
  590. //print ">>>".$langs->getDefaultLang()."-".$user->conf->MAIN_LANG_DEFAULT;
  591. if ($langs->getDefaultLang() != $user->conf->MAIN_LANG_DEFAULT)
  592. {
  593. $langs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT);
  594. }
  595. }
  596. }
  597. else // If language was forced on URL
  598. {
  599. $langs->setDefaultLang(GETPOST('lang','alpha',1));
  600. }
  601. }
  602. // Case forcing style from url
  603. if (GETPOST('theme'))
  604. {
  605. $conf->theme=GETPOST('theme','alpha',1);
  606. $conf->css = "/theme/".$conf->theme."/style.css.php";
  607. }
  608. if (! defined('NOLOGIN'))
  609. {
  610. // If the login is not recovered, it is identified with an account that does not exist.
  611. // Hacking attempt?
  612. if (! $user->login) accessforbidden();
  613. // Check if user is active
  614. if ($user->statut < 1)
  615. {
  616. // If not active, we refuse the user
  617. $langs->load("other");
  618. dol_syslog("Authentification ko as login is disabled");
  619. accessforbidden($langs->trans("ErrorLoginDisabled"));
  620. exit;
  621. }
  622. // Load permissions
  623. $user->getrights();
  624. }
  625. dol_syslog("--- Access to ".$_SERVER["PHP_SELF"]);
  626. //Another call for easy debugg
  627. //dol_syslog("Access to ".$_SERVER["PHP_SELF"].' GET='.join(',',array_keys($_GET)).'->'.join(',',$_GET).' POST:'.join(',',array_keys($_POST)).'->'.join(',',$_POST));
  628. // Load main languages files
  629. if (! defined('NOREQUIRETRAN'))
  630. {
  631. $langs->load("main");
  632. $langs->load("dict");
  633. }
  634. // Define some constants used for style of arrays
  635. $bc=array(0=>'class="impair"',1=>'class="pair"');
  636. $bcdd=array(0=>'class="impair drag drop"',1=>'class="pair drag drop"');
  637. $bcnd=array(0=>'class="impair nodrag nodrop"',1=>'class="pair nodrag nodrop"');
  638. // Constants used to defined number of lines in textarea
  639. if (empty($conf->browser->firefox))
  640. {
  641. define('ROWS_1',1);
  642. define('ROWS_2',2);
  643. define('ROWS_3',3);
  644. define('ROWS_4',4);
  645. define('ROWS_5',5);
  646. define('ROWS_6',6);
  647. define('ROWS_7',7);
  648. define('ROWS_8',8);
  649. define('ROWS_9',9);
  650. }
  651. else
  652. {
  653. define('ROWS_1',0);
  654. define('ROWS_2',1);
  655. define('ROWS_3',2);
  656. define('ROWS_4',3);
  657. define('ROWS_5',4);
  658. define('ROWS_6',5);
  659. define('ROWS_7',6);
  660. define('ROWS_8',7);
  661. define('ROWS_9',8);
  662. }
  663. $heightforframes=48;
  664. // Switch to another entity
  665. if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY))
  666. {
  667. if (GETPOST('action') == 'switchentity')
  668. {
  669. $res = @dol_include_once("/multicompany/class/actions_multicompany.class.php");
  670. if ($res)
  671. {
  672. $mc = new ActionsMulticompany($db);
  673. if($mc->switchEntity(GETPOST('entity')) >= 0)
  674. {
  675. Header("Location: ".DOL_URL_ROOT.'/');
  676. exit;
  677. }
  678. }
  679. }
  680. }
  681. // Functions
  682. if (! function_exists("llxHeader"))
  683. {
  684. /**
  685. * Show HTML header HTML + BODY + Top menu + left menu + DIV
  686. *
  687. * @param string $head Optionnal head lines
  688. * @param string $title HTML title
  689. * @param string $help_url Url links to help page
  690. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  691. * For other external page: http://server/url
  692. * @param string $target Target to use on links
  693. * @param int $disablejs More content into html header
  694. * @param int $disablehead More content into html header
  695. * @param array $arrayofjs Array of complementary js files
  696. * @param array $arrayofcss Array of complementary css files
  697. * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails)
  698. * @return void
  699. */
  700. function llxHeader($head = '', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='')
  701. {
  702. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
  703. top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring);
  704. left_menu('', $help_url, '', '', 1, $title);
  705. main_area($title);
  706. }
  707. }
  708. /**
  709. * Show HTTP header
  710. *
  711. * @return void
  712. */
  713. function top_httphead()
  714. {
  715. global $conf;
  716. //header("Content-type: text/html; charset=UTF-8");
  717. header("Content-type: text/html; charset=".$conf->file->character_set_client);
  718. // On the fly GZIP compression for all pages (if browser support it). Must set the bit 3 of constant to 1.
  719. if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x04)) { ob_start("ob_gzhandler"); }
  720. }
  721. /**
  722. * Replace the default llxHeader function
  723. *
  724. * @param string $head Optionnal head lines
  725. * @param string $title HTML title
  726. * @param int $disablejs More content into html header
  727. * @param int $disablehead More content into html header
  728. * @param array $arrayofjs Array of complementary js files
  729. * @param array $arrayofcss Array of complementary css files
  730. * @return void
  731. */
  732. function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='')
  733. {
  734. global $user, $conf, $langs, $db;
  735. top_httphead();
  736. if (empty($conf->css)) $conf->css = '/theme/eldy/style.css.php'; // If not defined, eldy by default
  737. print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
  738. //print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">';
  739. //print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
  740. //print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  741. //print '<!DOCTYPE html>';
  742. print "\n";
  743. if (! empty($conf->global->MAIN_USE_CACHE_MANIFEST)) print '<html manifest="cache.manifest">'."\n";
  744. else print '<html>'."\n";
  745. //print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">'."\n";
  746. if (empty($disablehead))
  747. {
  748. print "<head>\n";
  749. print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".$conf->file->character_set_client."\">\n";
  750. // Displays meta
  751. print '<meta name="robots" content="noindex,nofollow">'."\n"; // Evite indexation par robots
  752. print '<meta name="author" content="Dolibarr Development Team">'."\n";
  753. $favicon=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/favicon.ico';
  754. print '<link rel="shortcut icon" type="image/x-icon" href="'.$favicon.'"/>'."\n";
  755. // Displays title
  756. $appli='Dolibarr';
  757. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli=$conf->global->MAIN_APPLICATION_TITLE;
  758. if ($title) print '<title>'.$appli.' - '.$title.'</title>';
  759. else print "<title>".$appli."</title>";
  760. print "\n";
  761. if (! defined('DISABLE_JQUERY') && ! $disablejs && $conf->use_javascript_ajax)
  762. {
  763. print '<!-- Includes for JQuery (Ajax library) -->'."\n";
  764. $jquerytheme = 'smoothness';
  765. if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
  766. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/css/'.$jquerytheme.'/jquery-ui-latest.custom.css" />'."\n"; // JQuery
  767. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/tiptip/tipTip.css" />'."\n"; // Tooltip
  768. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jnotify/jquery.jnotify-alt.min.css" />'."\n"; // JNotify
  769. //print '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/lightbox/css/jquery.lightbox-0.5.css" media="screen" />'."\n"; // Lightbox
  770. if (! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD)) // jQuery fileupload
  771. {
  772. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/fileupload/jquery.fileupload-ui.css" />'."\n";
  773. }
  774. if (! empty($conf->global->MAIN_USE_JQUERY_DATATABLES)) // jQuery datatables
  775. {
  776. //print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/datatables/css/jquery.dataTables.css" />'."\n";
  777. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/datatables/css/jquery.dataTables_jui.css" />'."\n";
  778. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/datatables/extras/ColReorder/css/ColReorder.css" />'."\n";
  779. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/datatables/extras/ColVis/css/ColVis.css" />'."\n";
  780. //print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/datatables/extras/ColVis/css/ColVisAlt.css" />'."\n";
  781. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/datatables/extras/TableTools/css/TableTools.css" />'."\n";
  782. }
  783. }
  784. print '<!-- Includes for Dolibarr, modules or specific pages-->'."\n";
  785. // Output style sheets (optioncss='print' or '')
  786. $themepath=dol_buildpath((empty($conf->global->MAIN_FORCETHEMEDIR)?'':$conf->global->MAIN_FORCETHEMEDIR).$conf->css,1);
  787. //print 'themepath='.$themepath;exit;
  788. print '<link rel="stylesheet" type="text/css" title="default" href="'.$themepath.'?lang='.$langs->defaultlang.'&theme='.$conf->theme.(GETPOST('optioncss')?'&optioncss='.GETPOST('optioncss','alpha',1):'').'">'."\n";
  789. // CSS forced by modules (relative url starting with /)
  790. if (is_array($conf->css_modules))
  791. {
  792. foreach($conf->css_modules as $cssfile)
  793. { // cssfile is an absolute path
  794. print '<link rel="stylesheet" type="text/css" title="default" href="'.dol_buildpath($cssfile,1);
  795. // We add params only if page is not static, because some web server setup does not return content type text/css if url has parameters and browser cache is not used.
  796. if (!preg_match('/\.css$/i',$cssfile)) print '?lang='.$langs->defaultlang.'&theme='.$conf->theme.(GETPOST('optioncss')?'&optioncss='.GETPOST('optioncss','alpha',1):'');
  797. print '">'."\n";
  798. }
  799. }
  800. // CSS forced by page in top_htmlhead call (relative url starting with /)
  801. if (is_array($arrayofcss))
  802. {
  803. foreach($arrayofcss as $cssfile)
  804. {
  805. print '<link rel="stylesheet" type="text/css" title="default" href="'.dol_buildpath($cssfile,1);
  806. // We add params only if page is not static, because some web server setup does not return content type text/css if url has parameters and browser cache is not used.
  807. if (!preg_match('/\.css$/i',$cssfile)) print '?lang='.$langs->defaultlang.'&theme='.$conf->theme.(GETPOST('optioncss')?'&optioncss='.GETPOST('optioncss','alpha',1):'');
  808. print '">'."\n";
  809. }
  810. }
  811. if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="top" title="'.$langs->trans("Home").'" href="'.(DOL_URL_ROOT?DOL_URL_ROOT:'/').'">'."\n";
  812. if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="copyright" title="GNU General Public License" href="http://www.gnu.org/copyleft/gpl.html#SEC1">'."\n";
  813. if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="author" title="Dolibarr Development Team" href="http://www.dolibarr.org">'."\n";
  814. // Output standard javascript links
  815. if (! $disablejs && $conf->use_javascript_ajax)
  816. {
  817. // Other external js
  818. require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  819. $ext='.js';
  820. if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x01)) { $ext='.jgz'; } // mini='_mini', ext='.gz'
  821. // JQuery. Must be before other includes
  822. print '<!-- Includes JS for JQuery -->'."\n";
  823. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery-latest.min'.$ext.'"></script>'."\n";
  824. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery-ui-latest.custom.min'.$ext.'"></script>'."\n";
  825. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/tablednd/jquery.tablednd_0_5'.$ext.'"></script>'."\n";
  826. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/tiptip/jquery.tipTip.min'.$ext.'"></script>'."\n";
  827. //print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/lightbox/js/jquery.lightbox-0.5.min'.$ext.'"></script>'."\n";
  828. // jQuery Layout
  829. if (! empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) || defined('REQUIRE_JQUERY_LAYOUT'))
  830. {
  831. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/layout/jquery.layout-latest'.$ext.'"></script>'."\n";
  832. }
  833. // jQuery jnotify
  834. if (empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY))
  835. {
  836. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jnotify/jquery.jnotify.min.js"></script>'."\n";
  837. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/jnotify.js"></script>'."\n";
  838. }
  839. // Flot
  840. if (empty($conf->global->MAIN_DISABLE_JQUERY_FLOT))
  841. {
  842. print '<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/flot/excanvas.min.js"></script><![endif]-->'."\n";
  843. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/flot/jquery.flot.min.js"></script>'."\n";
  844. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/flot/jquery.flot.pie.min.js"></script>'."\n";
  845. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/flot/jquery.flot.stack.min.js"></script>'."\n";
  846. }
  847. // CKEditor
  848. if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_EDITORNAME) && $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor')
  849. {
  850. print '<!-- Includes JS for CKEditor -->'."\n";
  851. print '<script type="text/javascript">var CKEDITOR_BASEPATH = \''.DOL_URL_ROOT.'/includes/ckeditor/\';</script>'."\n";
  852. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/ckeditor/ckeditor_basic.js"></script>'."\n";
  853. }
  854. // jQuery jeditable
  855. if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE))
  856. {
  857. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.min'.$ext.'"></script>'."\n";
  858. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ui-datepicker.js"></script>'."\n";
  859. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ui-autocomplete.js"></script>'."\n";
  860. print '<script type="text/javascript">'."\n";
  861. print 'var urlSaveInPlace = \''.DOL_URL_ROOT.'/core/ajax/saveinplace.php\';'."\n";
  862. print 'var urlLoadInPlace = \''.DOL_URL_ROOT.'/core/ajax/loadinplace.php\';'."\n";
  863. print 'var tooltipInPlace = \''.$langs->transnoentities('ClickToEdit').'\';'."\n";
  864. print 'var placeholderInPlace = \''.$langs->trans('ClickToEdit').'\';'."\n";
  865. print 'var cancelInPlace = \''.$langs->trans('Cancel').'\';'."\n";
  866. print 'var submitInPlace = \''.$langs->trans('Ok').'\';'."\n";
  867. print 'var indicatorInPlace = \'<img src="'.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'">\';'."\n";
  868. print 'var ckeditorConfig = \''.dol_buildpath('/theme/'.$conf->theme.'/ckeditor/config.js',1).'\';'."\n";
  869. print '</script>'."\n";
  870. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/editinplace.js"></script>'."\n";
  871. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js"></script>'."\n";
  872. }
  873. // File Upload
  874. if (! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD))
  875. {
  876. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/fileupload/jquery.tmpl.min.js"></script>'."\n";
  877. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/fileupload/jquery.iframe-transport.js"></script>'."\n";
  878. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/fileupload/jquery.fileupload.js"></script>'."\n";
  879. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/fileupload/jquery.fileupload-ui.js"></script>'."\n";
  880. }
  881. // DataTables
  882. if (! empty($conf->global->MAIN_USE_JQUERY_DATATABLES))
  883. {
  884. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/datatables/js/jquery.dataTables.min'.$ext.'"></script>'."\n";
  885. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/datatables/extras/ColReorder/js/ColReorder.min'.$ext.'"></script>'."\n";
  886. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/datatables/extras/ColVis/js/ColVis.min'.$ext.'"></script>'."\n";
  887. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/datatables/extras/TableTools/js/TableTools.min'.$ext.'"></script>'."\n";
  888. }
  889. // Global js function
  890. print '<!-- Includes JS of Dolibarr -->'."\n";
  891. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/lib_head.js"></script>'."\n";
  892. // Add datepicker default options
  893. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/datepicker.js.php?lang='.$langs->defaultlang.'"></script>'."\n";
  894. // Output module javascript
  895. if (is_array($arrayofjs))
  896. {
  897. print '<!-- Includes JS specific to page -->'."\n";
  898. foreach($arrayofjs as $jsfile)
  899. {
  900. if (preg_match('/^http/i',$jsfile))
  901. {
  902. print '<script type="text/javascript" src="'.$jsfile.'"></script>'."\n";
  903. }
  904. else
  905. {
  906. if (! preg_match('/^\//',$jsfile)) $jsfile='/'.$jsfile; // For backward compatibility
  907. print '<script type="text/javascript" src="'.dol_buildpath($jsfile,1).'"></script>'."\n";
  908. }
  909. }
  910. }
  911. }
  912. if (! empty($head)) print $head."\n";
  913. if (! empty($conf->global->MAIN_HTML_HEADER)) print $conf->global->MAIN_HTML_HEADER."\n";
  914. print "</head>\n\n";
  915. }
  916. $conf->headerdone=1; // To tell header was output
  917. }
  918. /**
  919. * Show an HTML header + a BODY + The top menu bar
  920. *
  921. * @param string $head Lines in the HEAD
  922. * @param string $title Title of web page
  923. * @param string $target Target to use in menu links
  924. * @param int $disablejs Do not output links to js (Ex: qd fonction utilisee par sous formulaire Ajax)
  925. * @param int $disablehead Do not output head section
  926. * @param array $arrayofjs Array of js files to add in header
  927. * @param array $arrayofcss Array of css files to add in header
  928. * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails)
  929. * @return void
  930. */
  931. function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='')
  932. {
  933. global $user, $conf, $langs, $db, $dolibarr_main_authentication;
  934. $form=new Form($db);
  935. if (! $conf->top_menu) $conf->top_menu ='eldy_backoffice.php';
  936. // For backward compatibility with old modules
  937. if (empty($conf->headerdone)) top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  938. print '<body id="mainbody">';
  939. if ($conf->use_javascript_ajax)
  940. {
  941. if ($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)
  942. {
  943. print '<script type="text/javascript">
  944. jQuery(document).ready(function () {
  945. jQuery("body").layout(layoutSettings);
  946. });
  947. var layoutSettings = {
  948. name: "mainlayout",
  949. defaults: {
  950. useStateCookie: true,
  951. size: "auto",
  952. resizable: false,
  953. //paneClass: "none",
  954. //resizerClass: "resizer",
  955. //togglerClass: "toggler",
  956. //buttonClass: "button",
  957. //contentSelector: ".content",
  958. //contentIgnoreSelector: "span",
  959. togglerTip_open: "Close This Pane",
  960. togglerTip_closed: "Open This Pane",
  961. resizerTip: "Resize This Pane",
  962. fxSpeed: "fast"
  963. },
  964. west: {
  965. paneClass: "leftContent",
  966. //spacing_closed: 14,
  967. //togglerLength_closed: 14,
  968. //togglerAlign_closed: "auto",
  969. //togglerLength_open: 0,
  970. // effect defaults - overridden on some panes
  971. //slideTrigger_open: "mouseover",
  972. initClosed: '.(empty($conf->browser->phone)?'false':'true').',
  973. fxName: "drop",
  974. fxSpeed: "fast",
  975. fxSettings: { easing: "" }
  976. },
  977. north: {
  978. paneClass: "none",
  979. resizerClass: "none",
  980. togglerClass: "none",
  981. spacing_open: 0,
  982. togglerLength_open: 0,
  983. togglerLength_closed: -1,
  984. slidable: false,
  985. fxName: "none",
  986. fxSpeed: "fast"
  987. },
  988. center: {
  989. paneSelector: "#mainContent"
  990. }
  991. }
  992. </script>';
  993. }
  994. if (! empty($conf->global->MAIN_MENU_USE_JQUERY_ACCORDION))
  995. {
  996. print "\n".'<script type="text/javascript">
  997. jQuery(document).ready(function () {
  998. jQuery( ".vmenu" ).accordion({
  999. autoHeight: false,
  1000. event: "mouseover",
  1001. //collapsible: true,
  1002. //active: 2,
  1003. header: "> .blockvmenupair > .menu_titre"
  1004. });
  1005. });
  1006. </script>';
  1007. }
  1008. // Wrapper to show tooltips
  1009. print "\n".'<script type="text/javascript">
  1010. jQuery(document).ready(function () {
  1011. jQuery(function() {
  1012. jQuery(".classfortooltip").tipTip({maxWidth: "'.dol_size(600,'width').'px", edgeOffset: 10, delay: 50, fadeIn: 50, fadeOut: 50});
  1013. });
  1014. });
  1015. </script>';
  1016. }
  1017. /*
  1018. * Top menu
  1019. */
  1020. $top_menu=isset($conf->browser->phone)?$conf->smart_menu:$conf->top_menu;
  1021. if (GETPOST('menu')) $top_menu=GETPOST('menu'); // menu=eldy_backoffice.php
  1022. // Load the top menu manager
  1023. $result=dol_include_once("/core/menus/standard/".$top_menu);
  1024. if (! $result) // If failed to include, we try with standard
  1025. {
  1026. $top_menu='eldy_backoffice.php';
  1027. include_once(DOL_DOCUMENT_ROOT."/core/menus/standard/".$top_menu);
  1028. }
  1029. print "\n".'<!-- Start top horizontal menu '.$top_menu.' -->'."\n";
  1030. if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print '<div class="ui-layout-north"> <!-- Begin top layout -->'."\n";
  1031. print '<div id="tmenu_tooltip" class="tmenu">'."\n";
  1032. // Show menu
  1033. $menutop = new MenuTop($db);
  1034. $menutop->atarget=$target;
  1035. $menutop->showmenu(); // This contains a \n
  1036. print "</div>\n";
  1037. // Link to login card
  1038. $loginhtmltext=''; $logintext='';
  1039. if ($user->societe_id)
  1040. {
  1041. $thirdpartystatic=new Societe($db);
  1042. $thirdpartystatic->fetch($user->societe_id);
  1043. $companylink=' ('.$thirdpartystatic->getNomUrl('','').')';
  1044. $company=' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')';
  1045. }
  1046. $logintext='<div class="login"><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$user->id.'"';
  1047. $logintext.=$menutop->atarget?(' target="'.$menutop->atarget.'"'):'';
  1048. $logintext.='>'.$user->login.'</a>';
  1049. if ($user->societe_id) $logintext.=$companylink;
  1050. $logintext.='</div>';
  1051. $loginhtmltext.='<u>'.$langs->trans("User").'</u>';
  1052. $loginhtmltext.='<br><b>'.$langs->trans("Name").'</b>: '.$user->getFullName($langs);
  1053. $loginhtmltext.='<br><b>'.$langs->trans("Login").'</b>: '.$user->login;
  1054. $loginhtmltext.='<br><b>'.$langs->trans("Administrator").'</b>: '.yn($user->admin);
  1055. $type=($user->societe_id?$langs->trans("External").$company:$langs->trans("Internal"));
  1056. $loginhtmltext.='<br><b>'.$langs->trans("Type").'</b>: '.$type;
  1057. $loginhtmltext.='<br><b>'.$langs->trans("IPAddress").'</b>: '.$_SERVER["REMOTE_ADDR"];
  1058. $loginhtmltext.='<br>';
  1059. $loginhtmltext.='<br><u>'.$langs->trans("Connection").'</u>';
  1060. if ($conf->global->MAIN_MODULE_MULTICOMPANY) $loginhtmltext.='<br><b>'.$langs->trans("ConnectedOnMultiCompany").'</b>: '.$conf->entity.' (user entity '.$user->entity.')';
  1061. $loginhtmltext.='<br><b>'.$langs->trans("ConnectedSince").'</b>: '.dol_print_date($user->datelastlogin,"dayhour");
  1062. $loginhtmltext.='<br><b>'.$langs->trans

Large files files are truncated, but you can click here to view the full file