main.inc.php 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109
  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-2015 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-2015 Regis Houssin <regis.houssin@inodbox.com>
  8. * Copyright (C) 2011-2014 Philippe Grand <philippe.grand@atoo-net.com>
  9. * Copyright (C) 2008 Matteli
  10. * Copyright (C) 2011-2016 Juanjo Menent <jmenent@2byte.es>
  11. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  12. * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
  13. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. */
  28. /**
  29. * \file htdocs/main.inc.php
  30. * \ingroup core
  31. * \brief File that defines environment for Dolibarr GUI pages only (file not required by scripts)
  32. */
  33. //@ini_set('memory_limit', '128M'); // This may be useless if memory is hard limited by your PHP
  34. // For optional tuning. Enabled if environment variable MAIN_SHOW_TUNING_INFO is defined.
  35. $micro_start_time=0;
  36. if (! empty($_SERVER['MAIN_SHOW_TUNING_INFO']))
  37. {
  38. list($usec, $sec) = explode(" ", microtime());
  39. $micro_start_time=((float) $usec + (float) $sec);
  40. // Add Xdebug code coverage
  41. //define('XDEBUGCOVERAGE',1);
  42. if (defined('XDEBUGCOVERAGE')) {
  43. xdebug_start_code_coverage();
  44. }
  45. }
  46. // Removed magic_quotes
  47. if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* deprecated in PHP 5.0 and removed in PHP 5.5
  48. {
  49. if (get_magic_quotes_gpc())
  50. {
  51. // Forcing parameter setting magic_quotes_gpc and cleaning parameters
  52. // (Otherwise he would have for each position, condition
  53. // Reading stripslashes variable according to state get_magic_quotes_gpc).
  54. // Off mode recommended (just do $db->escape for insert / update).
  55. function stripslashes_deep($value)
  56. {
  57. return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value));
  58. }
  59. $_GET = array_map('stripslashes_deep', $_GET);
  60. $_POST = array_map('stripslashes_deep', $_POST);
  61. $_FILES = array_map('stripslashes_deep', $_FILES);
  62. //$_COOKIE = array_map('stripslashes_deep', $_COOKIE); // Useless because a cookie should never be outputed on screen nor used into sql
  63. @set_magic_quotes_runtime(0);
  64. }
  65. }
  66. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  67. /**
  68. * Security: SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST, PHP_SELF).
  69. *
  70. * @param string $val Value
  71. * @param string $type 1=GET, 0=POST, 2=PHP_SELF, 3=GET without sql reserved keywords (the less tolerant test)
  72. * @return int >0 if there is an injection, 0 if none
  73. * @deprecated use testSqlAndScriptInject
  74. * @see testSqlAndScriptInject($val, $type)
  75. */
  76. function test_sql_and_script_inject($val, $type)
  77. {
  78. // phpcs:enable
  79. return testSqlAndScriptInject($val, $type);
  80. }
  81. /**
  82. * Security: SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST, PHP_SELF).
  83. *
  84. * @param string $val Value
  85. * @param string $type 1=GET, 0=POST, 2=PHP_SELF, 3=GET without sql reserved keywords (the less tolerant test)
  86. * @return int >0 if there is an injection, 0 if none
  87. */
  88. function testSqlAndScriptInject($val, $type)
  89. {
  90. $inj = 0;
  91. // For SQL Injection (only GET are used to be included into bad escaped SQL requests)
  92. if ($type == 1 || $type == 3)
  93. {
  94. $inj += preg_match('/delete\s+from/i', $val);
  95. $inj += preg_match('/create\s+table/i', $val);
  96. $inj += preg_match('/insert\s+into/i', $val);
  97. $inj += preg_match('/select\s+from/i', $val);
  98. $inj += preg_match('/into\s+(outfile|dumpfile)/i', $val);
  99. $inj += preg_match('/user\s*\(/i', $val); // avoid to use function user() that return current database login
  100. $inj += preg_match('/information_schema/i', $val); // avoid to use request that read information_schema database
  101. }
  102. if ($type == 3)
  103. {
  104. $inj += preg_match('/select|update|delete|replace|group\s+by|concat|count|from/i', $val);
  105. }
  106. if ($type != 2) // Not common key strings, so we can check them both on GET and POST
  107. {
  108. $inj += preg_match('/updatexml\(/i', $val);
  109. $inj += preg_match('/update.+set.+=/i', $val);
  110. $inj += preg_match('/union.+select/i', $val);
  111. $inj += preg_match('/(\.\.%2f)+/i', $val);
  112. }
  113. // For XSS Injection done by adding javascript with script
  114. // This is all cases a browser consider text is javascript:
  115. // When it found '<script', 'javascript:', '<style', 'onload\s=' on body tag, '="&' on a tag size with old browsers
  116. // All examples on page: http://ha.ckers.org/xss.html#XSScalc
  117. // More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
  118. $inj += preg_match('/<script/i', $val);
  119. $inj += preg_match('/<iframe/i', $val);
  120. $inj += preg_match('/<audio/i', $val);
  121. $inj += preg_match('/Set\.constructor/i', $val); // ECMA script 6
  122. if (! defined('NOSTYLECHECK')) $inj += preg_match('/<style/i', $val);
  123. $inj += preg_match('/base[\s]+href/si', $val);
  124. $inj += preg_match('/<.*onmouse/si', $val); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)>
  125. $inj += preg_match('/onerror\s*=/i', $val); // onerror can be set on img or any html tag like <img title='...' onerror = alert(1)>
  126. $inj += preg_match('/onfocus\s*=/i', $val); // onfocus can be set on input text html tag like <input type='text' value='...' onfocus = alert(1)>
  127. $inj += preg_match('/onload\s*=/i', $val); // onload can be set on svg tag <svg/onload=alert(1)> or other tag like body <body onload=alert(1)>
  128. $inj += preg_match('/onloadstart\s*=/i', $val); // onload can be set on audio tag <audio onloadstart=alert(1)>
  129. $inj += preg_match('/onclick\s*=/i', $val); // onclick can be set on img text html tag like <img onclick = alert(1)>
  130. $inj += preg_match('/onscroll\s*=/i', $val); // onscroll can be on textarea
  131. //$inj += preg_match('/on[A-Z][a-z]+\*=/', $val); // To lock event handlers onAbort(), ...
  132. $inj += preg_match('/&#58;|&#0000058|&#x3A/i', $val); // refused string ':' encoded (no reason to have it encoded) to lock 'javascript:...'
  133. //if ($type == 1)
  134. //{
  135. $inj += preg_match('/javascript:/i', $val);
  136. $inj += preg_match('/vbscript:/i', $val);
  137. //}
  138. // For XSS Injection done by adding javascript closing html tags like with onmousemove, etc... (closing a src or href tag with not cleaned param)
  139. if ($type == 1) $inj += preg_match('/"/i', $val); // We refused " in GET parameters value
  140. if ($type == 2) $inj += preg_match('/[;"]/', $val); // PHP_SELF is a file system path. It can contains spaces.
  141. return $inj;
  142. }
  143. /**
  144. * Return true if security check on parameters are OK, false otherwise.
  145. *
  146. * @param string $var Variable name
  147. * @param string $type 1=GET, 0=POST, 2=PHP_SELF
  148. * @return boolean|null true if there is no injection. Stop code if injection found.
  149. */
  150. function analyseVarsForSqlAndScriptsInjection(&$var, $type)
  151. {
  152. if (is_array($var))
  153. {
  154. foreach ($var as $key => $value) // Warning, $key may also be used for attacks
  155. {
  156. if (analyseVarsForSqlAndScriptsInjection($key, $type) && analyseVarsForSqlAndScriptsInjection($value, $type))
  157. {
  158. //$var[$key] = $value; // This is useless
  159. }
  160. else
  161. {
  162. print 'Access refused by SQL/Script injection protection in main.inc.php (type='.htmlentities($type).' key='.htmlentities($key).' value='.htmlentities($value).' page='.htmlentities($_SERVER["REQUEST_URI"]).')';
  163. exit;
  164. }
  165. }
  166. return true;
  167. }
  168. else
  169. {
  170. return (testSqlAndScriptInject($var, $type) <= 0);
  171. }
  172. }
  173. // Check consistency of NOREQUIREXXX DEFINES
  174. if ((defined('NOREQUIREDB') || defined('NOREQUIRETRAN')) && ! defined('NOREQUIREMENU'))
  175. {
  176. print 'If define NOREQUIREDB or NOREQUIRETRAN are set, you must also set NOREQUIREMENU or not set them';
  177. exit;
  178. }
  179. // Sanity check on URL
  180. if (! empty($_SERVER["PHP_SELF"]))
  181. {
  182. $morevaltochecklikepost=array($_SERVER["PHP_SELF"]);
  183. analyseVarsForSqlAndScriptsInjection($morevaltochecklikepost,2);
  184. }
  185. // Sanity check on GET parameters
  186. if (! defined('NOSCANGETFORINJECTION') && ! empty($_SERVER["QUERY_STRING"]))
  187. {
  188. $morevaltochecklikeget=array($_SERVER["QUERY_STRING"]);
  189. analyseVarsForSqlAndScriptsInjection($morevaltochecklikeget,1);
  190. }
  191. // Sanity check on POST
  192. if (! defined('NOSCANPOSTFORINJECTION'))
  193. {
  194. analyseVarsForSqlAndScriptsInjection($_POST,0);
  195. }
  196. // This is to make Dolibarr working with Plesk
  197. if (! empty($_SERVER['DOCUMENT_ROOT']) && substr($_SERVER['DOCUMENT_ROOT'], -6) !== 'htdocs')
  198. {
  199. set_include_path($_SERVER['DOCUMENT_ROOT'] . '/htdocs');
  200. }
  201. // Include the conf.php and functions.lib.php
  202. require_once 'filefunc.inc.php';
  203. // If there is a POST parameter to tell to save automatically some POST parameters into cookies, we do it.
  204. // This is used for example by form of boxes to save personalization of some options.
  205. // DOL_AUTOSET_COOKIE=cookiename:val1,val2 and cookiename_val1=aaa cookiename_val2=bbb will set cookie_name with value json_encode(array('val1'=> , ))
  206. if (! empty($_POST["DOL_AUTOSET_COOKIE"]))
  207. {
  208. $tmpautoset=explode(':',$_POST["DOL_AUTOSET_COOKIE"],2);
  209. $tmplist=explode(',',$tmpautoset[1]);
  210. $cookiearrayvalue=array();
  211. foreach ($tmplist as $tmpkey)
  212. {
  213. $postkey=$tmpautoset[0].'_'.$tmpkey;
  214. //var_dump('tmpkey='.$tmpkey.' postkey='.$postkey.' value='.$_POST[$postkey]);
  215. if (! empty($_POST[$postkey])) $cookiearrayvalue[$tmpkey]=$_POST[$postkey];
  216. }
  217. $cookiename=$tmpautoset[0];
  218. $cookievalue=json_encode($cookiearrayvalue);
  219. //var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue);
  220. setcookie($cookiename, empty($cookievalue)?'':$cookievalue, empty($cookievalue)?0:(time()+(86400*354)), '/', null, false, true); // keep cookie 1 year and add tag httponly
  221. if (empty($cookievalue)) unset($_COOKIE[$cookiename]);
  222. }
  223. // Init session. Name of session is specific to Dolibarr instance.
  224. // Note: the function dol_getprefix may have been redefined to return a different key to manage another area to protect.
  225. $prefix=dol_getprefix('');
  226. $sessionname='DOLSESSID_'.$prefix;
  227. $sessiontimeout='DOLSESSTIMEOUT_'.$prefix;
  228. if (! empty($_COOKIE[$sessiontimeout])) ini_set('session.gc_maxlifetime',$_COOKIE[$sessiontimeout]);
  229. session_name($sessionname);
  230. session_set_cookie_params(0, '/', null, false, true); // Add tag httponly on session cookie (same as setting session.cookie_httponly into php.ini). Must be called before the session_start.
  231. // This create lock, released when session_write_close() or end of page.
  232. // We need this lock as long as we read/write $_SESSION ['vars']. We can remove lock when finished.
  233. if (! defined('NOSESSION'))
  234. {
  235. session_start();
  236. /*if (ini_get('register_globals')) // Deprecated in 5.3 and removed in 5.4. To solve bug in using $_SESSION
  237. {
  238. foreach ($_SESSION as $key=>$value)
  239. {
  240. if (isset($GLOBALS[$key])) unset($GLOBALS[$key]);
  241. }
  242. }*/
  243. }
  244. // Init the 5 global objects, this include will make the new and set properties for: $conf, $db, $langs, $user, $mysoc
  245. require_once 'master.inc.php';
  246. // Activate end of page function
  247. register_shutdown_function('dol_shutdown');
  248. // Detection browser
  249. if (isset($_SERVER["HTTP_USER_AGENT"]))
  250. {
  251. $tmp=getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
  252. $conf->browser->name=$tmp['browsername'];
  253. $conf->browser->os=$tmp['browseros'];
  254. $conf->browser->version=$tmp['browserversion'];
  255. $conf->browser->layout=$tmp['layout']; // 'classic', 'phone', 'tablet'
  256. //var_dump($conf->browser);
  257. if ($conf->browser->layout == 'phone') $conf->dol_no_mouse_hover=1;
  258. if ($conf->browser->layout == 'phone') $conf->global->MAIN_TESTMENUHIDER=1;
  259. }
  260. // Force HTTPS if required ($conf->file->main_force_https is 0/1 or https dolibarr root url)
  261. // $_SERVER["HTTPS"] is 'on' when link is https, otherwise $_SERVER["HTTPS"] is empty or 'off'
  262. if (! empty($conf->file->main_force_https) && (empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on'))
  263. {
  264. $newurl='';
  265. if (is_numeric($conf->file->main_force_https))
  266. {
  267. if ($conf->file->main_force_https == '1' && ! empty($_SERVER["SCRIPT_URI"])) // If SCRIPT_URI supported by server
  268. {
  269. if (preg_match('/^http:/i',$_SERVER["SCRIPT_URI"]) && ! preg_match('/^https:/i',$_SERVER["SCRIPT_URI"])) // If link is http
  270. {
  271. $newurl=preg_replace('/^http:/i','https:',$_SERVER["SCRIPT_URI"]);
  272. }
  273. }
  274. else // Check HTTPS environment variable (Apache/mod_ssl only)
  275. {
  276. $newurl=preg_replace('/^http:/i','https:',DOL_MAIN_URL_ROOT).$_SERVER["REQUEST_URI"];
  277. }
  278. }
  279. else
  280. {
  281. // Check HTTPS environment variable (Apache/mod_ssl only)
  282. $newurl=$conf->file->main_force_https.$_SERVER["REQUEST_URI"];
  283. }
  284. // Start redirect
  285. if ($newurl)
  286. {
  287. dol_syslog("main.inc: dolibarr_main_force_https is on, we make a redirect to ".$newurl);
  288. header("Location: ".$newurl);
  289. exit;
  290. }
  291. else
  292. {
  293. 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);
  294. }
  295. }
  296. if (! defined('NOLOGIN') && ! defined('NOIPCHECK') && ! empty($dolibarr_main_restrict_ip))
  297. {
  298. $listofip=explode(',', $dolibarr_main_restrict_ip);
  299. $found = false;
  300. foreach($listofip as $ip)
  301. {
  302. $ip=trim($ip);
  303. if ($ip == $_SERVER['REMOTE_ADDR'])
  304. {
  305. $found = true;
  306. break;
  307. }
  308. }
  309. if (! $found)
  310. {
  311. print 'Access refused by IP protection';
  312. exit;
  313. }
  314. }
  315. // Loading of additional presentation includes
  316. if (! defined('NOREQUIREHTML')) require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php'; // Need 660ko memory (800ko in 2.2)
  317. if (! defined('NOREQUIREAJAX') && $conf->use_javascript_ajax) require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; // Need 22ko memory
  318. // If install or upgrade process not done or not completely finished, we call the install page.
  319. if (! empty($conf->global->MAIN_NOT_INSTALLED) || ! empty($conf->global->MAIN_NOT_UPGRADED))
  320. {
  321. dol_syslog("main.inc: A previous install or upgrade was not complete. Redirect to install page.", LOG_WARNING);
  322. header("Location: ".DOL_URL_ROOT."/install/index.php");
  323. exit;
  324. }
  325. // If an upgrade process is required, we call the install page.
  326. if ((! empty($conf->global->MAIN_VERSION_LAST_UPGRADE) && ($conf->global->MAIN_VERSION_LAST_UPGRADE != DOL_VERSION))
  327. || (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) && ! empty($conf->global->MAIN_VERSION_LAST_INSTALL) && ($conf->global->MAIN_VERSION_LAST_INSTALL != DOL_VERSION)))
  328. {
  329. $versiontocompare=empty($conf->global->MAIN_VERSION_LAST_UPGRADE)?$conf->global->MAIN_VERSION_LAST_INSTALL:$conf->global->MAIN_VERSION_LAST_UPGRADE;
  330. require_once DOL_DOCUMENT_ROOT .'/core/lib/admin.lib.php';
  331. $dolibarrversionlastupgrade=preg_split('/[.-]/',$versiontocompare);
  332. $dolibarrversionprogram=preg_split('/[.-]/',DOL_VERSION);
  333. $rescomp=versioncompare($dolibarrversionprogram,$dolibarrversionlastupgrade);
  334. if ($rescomp > 0) // Programs have a version higher than database. We did not add "&& $rescomp < 3" because we want upgrade process for build upgrades
  335. {
  336. dol_syslog("main.inc: database version ".$versiontocompare." is lower than programs version ".DOL_VERSION.". Redirect to install page.", LOG_WARNING);
  337. header("Location: ".DOL_URL_ROOT."/install/index.php");
  338. exit;
  339. }
  340. }
  341. // Creation of a token against CSRF vulnerabilities
  342. if (! defined('NOTOKENRENEWAL'))
  343. {
  344. // Rolling token at each call ($_SESSION['token'] contains token of previous page)
  345. if (isset($_SESSION['newtoken'])) $_SESSION['token'] = $_SESSION['newtoken'];
  346. // Save in $_SESSION['newtoken'] what will be next token. Into forms, we will add param token = $_SESSION['newtoken']
  347. $token = dol_hash(uniqid(mt_rand(), true)); // Generates a hash of a random number
  348. $_SESSION['newtoken'] = $token;
  349. }
  350. if ((! defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && ! empty($conf->global->MAIN_SECURITY_CSRF_WITH_TOKEN))
  351. || defined('CSRFCHECK_WITH_TOKEN')) // Check validity of token, only if option MAIN_SECURITY_CSRF_WITH_TOKEN enabled or if constant CSRFCHECK_WITH_TOKEN is set
  352. {
  353. if ($_SERVER['REQUEST_METHOD'] == 'POST' && ! GETPOST('token','alpha')) // Note, offender can still send request by GET
  354. {
  355. print "Access refused by CSRF protection in main.inc.php. Token not provided.\n";
  356. print "If you access your server behind a proxy using url rewriting, you might check that all HTTP header is propagated (or add the line \$dolibarr_nocsrfcheck=1 into your conf.php file).\n";
  357. die;
  358. }
  359. if ($_SERVER['REQUEST_METHOD'] === 'POST') // This test must be after loading $_SESSION['token'].
  360. {
  361. if (GETPOST('token', 'alpha') != $_SESSION['token'])
  362. {
  363. dol_syslog("Invalid token in ".$_SERVER['HTTP_REFERER'].", action=".GETPOST('action','aZ09').", _POST['token']=".GETPOST('token','alpha').", _SESSION['token']=".$_SESSION['token'], LOG_WARNING);
  364. //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.
  365. unset($_POST);
  366. }
  367. }
  368. }
  369. // Disable modules (this must be after session_start and after conf has been loaded)
  370. if (GETPOST('disablemodules','alpha')) $_SESSION["disablemodules"]=GETPOST('disablemodules','alpha');
  371. if (! empty($_SESSION["disablemodules"]))
  372. {
  373. $disabled_modules=explode(',',$_SESSION["disablemodules"]);
  374. foreach($disabled_modules as $module)
  375. {
  376. if ($module)
  377. {
  378. if (empty($conf->$module)) $conf->$module=new stdClass();
  379. $conf->$module->enabled=false;
  380. if ($module == 'fournisseur') // Special case
  381. {
  382. $conf->supplier_order->enabled=0;
  383. $conf->supplier_invoice->enabled=0;
  384. }
  385. }
  386. }
  387. }
  388. /*
  389. * Phase authentication / login
  390. */
  391. $login='';
  392. if (! defined('NOLOGIN'))
  393. {
  394. // $authmode lists the different means of identification to be tested in order of preference.
  395. // Example: 'http', 'dolibarr', 'ldap', 'http,forceuser', '...'
  396. if (defined('MAIN_AUTHENTICATION_MODE'))
  397. {
  398. $dolibarr_main_authentication = constant('MAIN_AUTHENTICATION_MODE');
  399. }
  400. else
  401. {
  402. // Authentication mode
  403. if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='http,dolibarr';
  404. // Authentication mode: forceuser
  405. if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user='auto';
  406. }
  407. // Set authmode
  408. $authmode=explode(',',$dolibarr_main_authentication);
  409. // No authentication mode
  410. if (! count($authmode))
  411. {
  412. $langs->load('main');
  413. dol_print_error('',$langs->trans("ErrorConfigParameterNotDefined",'dolibarr_main_authentication'));
  414. exit;
  415. }
  416. // If login request was already post, we retrieve login from the session
  417. // Call module if not realized that his request.
  418. // At the end of this phase, the variable $login is defined.
  419. $resultFetchUser='';
  420. $test=true;
  421. if (! isset($_SESSION["dol_login"]))
  422. {
  423. // It is not already authenticated and it requests the login / password
  424. include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  425. $dol_dst_observed=GETPOST("dst_observed",'int',3);
  426. $dol_dst_first=GETPOST("dst_first",'int',3);
  427. $dol_dst_second=GETPOST("dst_second",'int',3);
  428. $dol_screenwidth=GETPOST("screenwidth",'int',3);
  429. $dol_screenheight=GETPOST("screenheight",'int',3);
  430. $dol_hide_topmenu=GETPOST('dol_hide_topmenu','int',3);
  431. $dol_hide_leftmenu=GETPOST('dol_hide_leftmenu','int',3);
  432. $dol_optimize_smallscreen=GETPOST('dol_optimize_smallscreen','int',3);
  433. $dol_no_mouse_hover=GETPOST('dol_no_mouse_hover','int',3);
  434. $dol_use_jmobile=GETPOST('dol_use_jmobile','int',3);
  435. //dol_syslog("POST key=".join(array_keys($_POST),',').' value='.join($_POST,','));
  436. // If in demo mode, we check we go to home page through the public/demo/index.php page
  437. if (! empty($dolibarr_main_demo) && $_SERVER['PHP_SELF'] == DOL_URL_ROOT.'/index.php') // We ask index page
  438. {
  439. if (empty($_SERVER['HTTP_REFERER']) || ! preg_match('/public/',$_SERVER['HTTP_REFERER']))
  440. {
  441. dol_syslog("Call index page from another url than demo page (call is done from page ".$_SERVER['HTTP_REFERER'].")");
  442. $url='';
  443. $url.=($url?'&':'').($dol_hide_topmenu?'dol_hide_topmenu='.$dol_hide_topmenu:'');
  444. $url.=($url?'&':'').($dol_hide_leftmenu?'dol_hide_leftmenu='.$dol_hide_leftmenu:'');
  445. $url.=($url?'&':'').($dol_optimize_smallscreen?'dol_optimize_smallscreen='.$dol_optimize_smallscreen:'');
  446. $url.=($url?'&':'').($dol_no_mouse_hover?'dol_no_mouse_hover='.$dol_no_mouse_hover:'');
  447. $url.=($url?'&':'').($dol_use_jmobile?'dol_use_jmobile='.$dol_use_jmobile:'');
  448. $url=DOL_URL_ROOT.'/public/demo/index.php'.($url?'?'.$url:'');
  449. header("Location: ".$url);
  450. exit;
  451. }
  452. }
  453. // Verification security graphic code
  454. if (GETPOST("username","alpha",2) && ! empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA))
  455. {
  456. $sessionkey = 'dol_antispam_value';
  457. $ok=(array_key_exists($sessionkey, $_SESSION) === true && (strtolower($_SESSION[$sessionkey]) == strtolower($_POST['code'])));
  458. // Check code
  459. if (! $ok)
  460. {
  461. dol_syslog('Bad value for code, connexion refused');
  462. // Load translation files required by page
  463. $langs->loadLangs(array('main', 'errors'));
  464. $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadValueForCode");
  465. $test=false;
  466. // Call trigger for the "security events" log
  467. $user->trigger_mesg='ErrorBadValueForCode - login='.GETPOST("username","alpha",2);
  468. // Call of triggers
  469. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  470. $interface=new Interfaces($db);
  471. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf);
  472. if ($result < 0) {
  473. $error++;
  474. }
  475. // End Call of triggers
  476. // Hooks on failed login
  477. $action='';
  478. $hookmanager->initHooks(array('login'));
  479. $parameters=array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  480. $reshook=$hookmanager->executeHooks('afterLoginFailed',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  481. if ($reshook < 0) $error++;
  482. // Note: exit is done later
  483. }
  484. }
  485. $allowedmethodtopostusername = 2;
  486. if (defined('MAIN_AUTHENTICATION_POST_METHOD')) $allowedmethodtopostusername = constant('MAIN_AUTHENTICATION_POST_METHOD');
  487. $usertotest = (! empty($_COOKIE['login_dolibarr']) ? $_COOKIE['login_dolibarr'] : GETPOST("username","alpha",$allowedmethodtopostusername));
  488. $passwordtotest = GETPOST('password','none',$allowedmethodtopostusername);
  489. $entitytotest = (GETPOST('entity','int') ? GETPOST('entity','int') : (!empty($conf->entity) ? $conf->entity : 1));
  490. // Define if we received data to test the login.
  491. $goontestloop=false;
  492. if (isset($_SERVER["REMOTE_USER"]) && in_array('http',$authmode)) $goontestloop=true;
  493. if ($dolibarr_main_authentication == 'forceuser' && ! empty($dolibarr_auto_user)) $goontestloop=true;
  494. if (GETPOST("username","alpha",$allowedmethodtopostusername) || ! empty($_COOKIE['login_dolibarr']) || GETPOST('openid_mode','alpha',1)) $goontestloop=true;
  495. if (! is_object($langs)) // This can occurs when calling page with NOREQUIRETRAN defined, however we need langs for error messages.
  496. {
  497. include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
  498. $langs=new Translate("",$conf);
  499. $langcode=(GETPOST('lang','aZ09',1)?GETPOST('lang','aZ09',1):(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT));
  500. if (defined('MAIN_LANG_DEFAULT')) $langcode=constant('MAIN_LANG_DEFAULT');
  501. $langs->setDefaultLang($langcode);
  502. }
  503. // Validation of login/pass/entity
  504. // If ok, the variable login will be returned
  505. // If error, we will put error message in session under the name dol_loginmesg
  506. if ($test && $goontestloop)
  507. {
  508. $login = checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmode);
  509. if ($login)
  510. {
  511. $dol_authmode=$conf->authmode; // This properties is defined only when logged, to say what mode was successfully used
  512. $dol_tz=$_POST["tz"];
  513. $dol_tz_string=$_POST["tz_string"];
  514. $dol_tz_string=preg_replace('/\s*\(.+\)$/','',$dol_tz_string);
  515. $dol_tz_string=preg_replace('/,/','/',$dol_tz_string);
  516. $dol_tz_string=preg_replace('/\s/','_',$dol_tz_string);
  517. $dol_dst=0;
  518. if (isset($_POST["dst_first"]) && isset($_POST["dst_second"]))
  519. {
  520. include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  521. $datenow=dol_now();
  522. $datefirst=dol_stringtotime($_POST["dst_first"]);
  523. $datesecond=dol_stringtotime($_POST["dst_second"]);
  524. if ($datenow >= $datefirst && $datenow < $datesecond) $dol_dst=1;
  525. }
  526. //print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst; exit;
  527. }
  528. if (! $login)
  529. {
  530. dol_syslog('Bad password, connexion refused',LOG_DEBUG);
  531. // Load translation files required by page
  532. $langs->loadLangs(array('main', 'errors'));
  533. // Bad password. No authmode has found a good password.
  534. // We set a generic message if not defined inside function checkLoginPassEntity or subfunctions
  535. if (empty($_SESSION["dol_loginmesg"])) $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword");
  536. // Call trigger for the "security events" log
  537. $user->trigger_mesg=$langs->trans("ErrorBadLoginPassword").' - login='.GETPOST("username","alpha",2);
  538. // Call of triggers
  539. include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
  540. $interface=new Interfaces($db);
  541. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf,GETPOST("username","alpha",2));
  542. if ($result < 0) {
  543. $error++;
  544. }
  545. // End Call of triggers
  546. // Hooks on failed login
  547. $action='';
  548. $hookmanager->initHooks(array('login'));
  549. $parameters=array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  550. $reshook=$hookmanager->executeHooks('afterLoginFailed',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  551. if ($reshook < 0) $error++;
  552. // Note: exit is done in next chapter
  553. }
  554. }
  555. // End test login / passwords
  556. if (! $login || (in_array('ldap',$authmode) && empty($passwordtotest))) // With LDAP we refused empty password because some LDAP are "opened" for anonymous access so connexion is a success.
  557. {
  558. // No data to test login, so we show the login page
  559. dol_syslog("--- Access to ".$_SERVER["PHP_SELF"]." showing the login form and exit");
  560. if (defined('NOREDIRECTBYMAINTOLOGIN')) return 'ERROR_NOT_LOGGED';
  561. else dol_loginfunction($langs,$conf,(! empty($mysoc)?$mysoc:''));
  562. exit;
  563. }
  564. $resultFetchUser=$user->fetch('', $login, '', 1, ($entitytotest > 0 ? $entitytotest : -1));
  565. if ($resultFetchUser <= 0)
  566. {
  567. dol_syslog('User not found, connexion refused');
  568. session_destroy();
  569. session_name($sessionname);
  570. session_set_cookie_params(0, '/', null, false, true); // Add tag httponly on session cookie
  571. session_start(); // Fixing the bug of register_globals here is useless since session is empty
  572. if ($resultFetchUser == 0)
  573. {
  574. // Load translation files required by page
  575. $langs->loadLangs(array('main', 'errors'));
  576. $_SESSION["dol_loginmesg"]=$langs->trans("ErrorCantLoadUserFromDolibarrDatabase",$login);
  577. $user->trigger_mesg='ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
  578. }
  579. if ($resultFetchUser < 0)
  580. {
  581. $_SESSION["dol_loginmesg"]=$user->error;
  582. $user->trigger_mesg=$user->error;
  583. }
  584. // Call triggers for the "security events" log
  585. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  586. $interface=new Interfaces($db);
  587. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf);
  588. if ($result < 0) {
  589. $error++;
  590. }
  591. // End call triggers
  592. // Hooks on failed login
  593. $action='';
  594. $hookmanager->initHooks(array('login'));
  595. $parameters=array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  596. $reshook=$hookmanager->executeHooks('afterLoginFailed',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  597. if ($reshook < 0) $error++;
  598. $paramsurl=array();
  599. if (GETPOST('textbrowser','int')) $paramsurl[]='textbrowser='.GETPOST('textbrowser','int');
  600. if (GETPOST('nojs','int')) $paramsurl[]='nojs='.GETPOST('nojs','int');
  601. if (GETPOST('lang','aZ09')) $paramsurl[]='lang='.GETPOST('lang','aZ09');
  602. header('Location: '.DOL_URL_ROOT.'/index.php'.(count($paramsurl)?'?'.implode('&',$paramsurl):''));
  603. exit;
  604. }
  605. }
  606. else
  607. {
  608. // We are already into an authenticated session
  609. $login=$_SESSION["dol_login"];
  610. $entity=$_SESSION["dol_entity"];
  611. dol_syslog("- This is an already logged session. _SESSION['dol_login']=".$login." _SESSION['dol_entity']=".$entity, LOG_DEBUG);
  612. $resultFetchUser=$user->fetch('', $login, '', 1, ($entity > 0 ? $entity : -1));
  613. if ($resultFetchUser <= 0)
  614. {
  615. // Account has been removed after login
  616. dol_syslog("Can't load user even if session logged. _SESSION['dol_login']=".$login, LOG_WARNING);
  617. session_destroy();
  618. session_name($sessionname);
  619. session_set_cookie_params(0, '/', null, false, true); // Add tag httponly on session cookie
  620. session_start(); // Fixing the bug of register_globals here is useless since session is empty
  621. if ($resultFetchUser == 0)
  622. {
  623. // Load translation files required by page
  624. $langs->loadLangs(array('main', 'errors'));
  625. $_SESSION["dol_loginmesg"]=$langs->trans("ErrorCantLoadUserFromDolibarrDatabase",$login);
  626. $user->trigger_mesg='ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
  627. }
  628. if ($resultFetchUser < 0)
  629. {
  630. $_SESSION["dol_loginmesg"]=$user->error;
  631. $user->trigger_mesg=$user->error;
  632. }
  633. // Call triggers for the "security events" log
  634. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  635. $interface=new Interfaces($db);
  636. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf);
  637. if ($result < 0) {
  638. $error++;
  639. }
  640. // End call triggers
  641. // Hooks on failed login
  642. $action='';
  643. $hookmanager->initHooks(array('login'));
  644. $parameters=array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  645. $reshook=$hookmanager->executeHooks('afterLoginFailed',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  646. if ($reshook < 0) $error++;
  647. $paramsurl=array();
  648. if (GETPOST('textbrowser','int')) $paramsurl[]='textbrowser='.GETPOST('textbrowser','int');
  649. if (GETPOST('nojs','int')) $paramsurl[]='nojs='.GETPOST('nojs','int');
  650. if (GETPOST('lang','aZ09')) $paramsurl[]='lang='.GETPOST('lang','aZ09');
  651. header('Location: '.DOL_URL_ROOT.'/index.php'.(count($paramsurl)?'?'.implode('&',$paramsurl):''));
  652. exit;
  653. }
  654. else
  655. {
  656. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  657. $hookmanager->initHooks(array('main'));
  658. // Code for search criteria persistence.
  659. if (! empty($_GET['save_lastsearch_values'])) // We must use $_GET here
  660. {
  661. $relativepathstring = preg_replace('/\?.*$/','',$_SERVER["HTTP_REFERER"]);
  662. $relativepathstring = preg_replace('/^https?:\/\/[^\/]*/','',$relativepathstring); // Get full path except host server
  663. // Clean $relativepathstring
  664. if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
  665. $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
  666. $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
  667. //var_dump($relativepathstring);
  668. // We click on a link that leave a page we have to save search criteria, contextpage, limit and page. We save them from tmp to no tmp
  669. if (! empty($_SESSION['lastsearch_values_tmp_'.$relativepathstring]))
  670. {
  671. $_SESSION['lastsearch_values_'.$relativepathstring]=$_SESSION['lastsearch_values_tmp_'.$relativepathstring];
  672. unset($_SESSION['lastsearch_values_tmp_'.$relativepathstring]);
  673. }
  674. if (! empty($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]))
  675. {
  676. $_SESSION['lastsearch_contextpage_'.$relativepathstring]=$_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring];
  677. unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]);
  678. }
  679. if (! empty($_SESSION['lastsearch_page_tmp_'.$relativepathstring]) && $_SESSION['lastsearch_page_tmp_'.$relativepathstring] > 1)
  680. {
  681. $_SESSION['lastsearch_page_'.$relativepathstring]=$_SESSION['lastsearch_page_tmp_'.$relativepathstring];
  682. unset($_SESSION['lastsearch_page_tmp_'.$relativepathstring]);
  683. }
  684. if (! empty($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]) && $_SESSION['lastsearch_limit_tmp_'.$relativepathstring] != $conf->liste_limit)
  685. {
  686. $_SESSION['lastsearch_limit_'.$relativepathstring]=$_SESSION['lastsearch_limit_tmp_'.$relativepathstring];
  687. unset($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]);
  688. }
  689. }
  690. $action = '';
  691. $reshook = $hookmanager->executeHooks('updateSession', array(), $user, $action);
  692. if ($reshook < 0) {
  693. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  694. }
  695. }
  696. }
  697. // Is it a new session that has started ?
  698. // If we are here, this means authentication was successfull.
  699. if (! isset($_SESSION["dol_login"]))
  700. {
  701. // New session for this login has started.
  702. $error=0;
  703. // Store value into session (values always stored)
  704. $_SESSION["dol_login"]=$user->login;
  705. $_SESSION["dol_authmode"]=isset($dol_authmode)?$dol_authmode:'';
  706. $_SESSION["dol_tz"]=isset($dol_tz)?$dol_tz:'';
  707. $_SESSION["dol_tz_string"]=isset($dol_tz_string)?$dol_tz_string:'';
  708. $_SESSION["dol_dst"]=isset($dol_dst)?$dol_dst:'';
  709. $_SESSION["dol_dst_observed"]=isset($dol_dst_observed)?$dol_dst_observed:'';
  710. $_SESSION["dol_dst_first"]=isset($dol_dst_first)?$dol_dst_first:'';
  711. $_SESSION["dol_dst_second"]=isset($dol_dst_second)?$dol_dst_second:'';
  712. $_SESSION["dol_screenwidth"]=isset($dol_screenwidth)?$dol_screenwidth:'';
  713. $_SESSION["dol_screenheight"]=isset($dol_screenheight)?$dol_screenheight:'';
  714. $_SESSION["dol_company"]=$conf->global->MAIN_INFO_SOCIETE_NOM;
  715. $_SESSION["dol_entity"]=$conf->entity;
  716. // Store value into session (values stored only if defined)
  717. if (! empty($dol_hide_topmenu)) $_SESSION['dol_hide_topmenu']=$dol_hide_topmenu;
  718. if (! empty($dol_hide_leftmenu)) $_SESSION['dol_hide_leftmenu']=$dol_hide_leftmenu;
  719. if (! empty($dol_optimize_smallscreen)) $_SESSION['dol_optimize_smallscreen']=$dol_optimize_smallscreen;
  720. if (! empty($dol_no_mouse_hover)) $_SESSION['dol_no_mouse_hover']=$dol_no_mouse_hover;
  721. if (! empty($dol_use_jmobile)) $_SESSION['dol_use_jmobile']=$dol_use_jmobile;
  722. dol_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"]." Session id=".session_id());
  723. $db->begin();
  724. $user->update_last_login_date();
  725. $loginfo = 'TZ='.$_SESSION["dol_tz"].';TZString='.$_SESSION["dol_tz_string"].';Screen='.$_SESSION["dol_screenwidth"].'x'.$_SESSION["dol_screenheight"];
  726. // Call triggers for the "security events" log
  727. $user->trigger_mesg = $loginfo;
  728. // Call triggers
  729. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  730. $interface=new Interfaces($db);
  731. $result=$interface->run_triggers('USER_LOGIN',$user,$user,$langs,$conf);
  732. if ($result < 0) {
  733. $error++;
  734. }
  735. // End call triggers
  736. // Hooks on successfull login
  737. $action='';
  738. $hookmanager->initHooks(array('login'));
  739. $parameters=array('dol_authmode'=>$dol_authmode, 'dol_loginfo'=>$loginfo);
  740. $reshook=$hookmanager->executeHooks('afterLogin',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  741. if ($reshook < 0) $error++;
  742. if ($error)
  743. {
  744. $db->rollback();
  745. session_destroy();
  746. dol_print_error($db,'Error in some triggers USER_LOGIN or in some hooks afterLogin');
  747. exit;
  748. }
  749. else
  750. {
  751. $db->commit();
  752. }
  753. // Change landing page if defined.
  754. $landingpage=(empty($user->conf->MAIN_LANDING_PAGE)?(empty($conf->global->MAIN_LANDING_PAGE)?'':$conf->global->MAIN_LANDING_PAGE):$user->conf->MAIN_LANDING_PAGE);
  755. if (! empty($landingpage)) // Example: /index.php
  756. {
  757. $newpath=dol_buildpath($landingpage, 1);
  758. if ($_SERVER["PHP_SELF"] != $newpath) // not already on landing page (avoid infinite loop)
  759. {
  760. header('Location: '.$newpath);
  761. exit;
  762. }
  763. }
  764. }
  765. // If user admin, we force the rights-based modules
  766. if ($user->admin)
  767. {
  768. $user->rights->user->user->lire=1;
  769. $user->rights->user->user->creer=1;
  770. $user->rights->user->user->password=1;
  771. $user->rights->user->user->supprimer=1;
  772. $user->rights->user->self->creer=1;
  773. $user->rights->user->self->password=1;
  774. }
  775. /*
  776. * Overwrite some configs globals (try to avoid this and have code to use instead $user->conf->xxx)
  777. */
  778. // Set liste_limit
  779. if (isset($user->conf->MAIN_SIZE_LISTE_LIMIT)) $conf->liste_limit = $user->conf->MAIN_SIZE_LISTE_LIMIT; // Can be 0
  780. if (isset($user->conf->PRODUIT_LIMIT_SIZE)) $conf->product->limit_size = $user->conf->PRODUIT_LIMIT_SIZE; // Can be 0
  781. // Replace conf->css by personalized value if theme not forced
  782. if (empty($conf->global->MAIN_FORCETHEME) && ! empty($user->conf->MAIN_THEME))
  783. {
  784. $conf->theme=$user->conf->MAIN_THEME;
  785. $conf->css = "/theme/".$conf->theme."/style.css.php";
  786. }
  787. }
  788. // Case forcing style from url
  789. if (GETPOST('theme','alpha'))
  790. {
  791. $conf->theme=GETPOST('theme','alpha',1);
  792. $conf->css = "/theme/".$conf->theme."/style.css.php";
  793. }
  794. // Set javascript option
  795. if (! GETPOST('nojs','int')) // If javascript was not disabled on URL
  796. {
  797. if (! empty($user->conf->MAIN_DISABLE_JAVASCRIPT))
  798. {
  799. $conf->use_javascript_ajax=! $user->conf->MAIN_DISABLE_JAVASCRIPT;
  800. }
  801. }
  802. else $conf->use_javascript_ajax=0;
  803. // Set MAIN_OPTIMIZEFORTEXTBROWSER
  804. if (GETPOST('textbrowser','int') || (! empty($conf->browser->name) && $conf->browser->name == 'lynxlinks') || ! empty($user->conf->MAIN_OPTIMIZEFORTEXTBROWSER)) // If we must enable text browser
  805. {
  806. $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER=1;
  807. }
  808. elseif (! empty($user->conf->MAIN_OPTIMIZEFORTEXTBROWSER))
  809. {
  810. $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER=$user->conf->MAIN_OPTIMIZEFORTEXTBROWSER;
  811. }
  812. // Set terminal output option according to conf->browser.
  813. if (GETPOST('dol_hide_leftmenu','int') || ! empty($_SESSION['dol_hide_leftmenu'])) $conf->dol_hide_leftmenu=1;
  814. if (GETPOST('dol_hide_topmenu','int') || ! empty($_SESSION['dol_hide_topmenu'])) $conf->dol_hide_topmenu=1;
  815. if (GETPOST('dol_optimize_smallscreen','int') || ! empty($_SESSION['dol_optimize_smallscreen'])) $conf->dol_optimize_smallscreen=1;
  816. if (GETPOST('dol_no_mouse_hover','int') || ! empty($_SESSION['dol_no_mouse_hover'])) $conf->dol_no_mouse_hover=1;
  817. if (GETPOST('dol_use_jmobile','int') || ! empty($_SESSION['dol_use_jmobile'])) $conf->dol_use_jmobile=1;
  818. if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $conf->dol_no_mouse_hover=1;
  819. if ((! empty($conf->browser->layout) && $conf->browser->layout == 'phone')
  820. || (! empty($_SESSION['dol_screenwidth']) && $_SESSION['dol_screenwidth'] < 400)
  821. || (! empty($_SESSION['dol_screenheight']) && $_SESSION['dol_screenheight'] < 400)
  822. )
  823. {
  824. $conf->dol_optimize_smallscreen=1;
  825. }
  826. // If we force to use jmobile, then we reenable javascript
  827. if (! empty($conf->dol_use_jmobile)) $conf->use_javascript_ajax=1;
  828. // Replace themes bugged with jmobile with eldy
  829. if (! empty($conf->dol_use_jmobile) && in_array($conf->theme, array('bureau2crea','cameleo','amarok')))
  830. {
  831. $conf->theme='eldy';
  832. $conf->css = "/theme/".$conf->theme."/style.css.php";
  833. }
  834. if (! defined('NOREQUIRETRAN'))
  835. {
  836. if (! GETPOST('lang','aZ09')) // If language was not forced on URL
  837. {
  838. // If user has chosen its own language
  839. if (! empty($user->conf->MAIN_LANG_DEFAULT))
  840. {
  841. // If different than current language
  842. //print ">>>".$langs->getDefaultLang()."-".$user->conf->MAIN_LANG_DEFAULT;
  843. if ($langs->getDefaultLang() != $user->conf->MAIN_LANG_DEFAULT)
  844. {
  845. $langs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT);
  846. }
  847. }
  848. }
  849. }
  850. if (! defined('NOLOGIN'))
  851. {
  852. // If the login is not recovered, it is identified with an account that does not exist.
  853. // Hacking attempt?
  854. if (! $user->login) accessforbidden();
  855. // Check if user is active
  856. if ($user->statut < 1)
  857. {
  858. // If not active, we refuse the user
  859. $langs->load("other");
  860. dol_syslog("Authentification ko as login is disabled");
  861. accessforbidden($langs->trans("ErrorLoginDisabled"));
  862. exit;
  863. }
  864. // Load permissions
  865. $user->getrights();
  866. }
  867. dol_syslog("--- Access to ".$_SERVER["PHP_SELF"].' - action='.GETPOST('action','az09').', massaction='.GETPOST('massaction','az09'));
  868. //Another call for easy debugg
  869. //dol_syslog("Access to ".$_SERVER["PHP_SELF"].' GET='.join(',',array_keys($_GET)).'->'.join(',',$_GET).' POST:'.join(',',array_keys($_POST)).'->'.join(',',$_POST));
  870. // Load main languages files
  871. if (! defined('NOREQUIRETRAN'))
  872. {
  873. // Load translation files required by page
  874. $langs->loadLangs(array('main', 'dict'));
  875. }
  876. // Define some constants used for style of arrays
  877. $bc=array(0=>'class="impair"',1=>'class="pair"');
  878. $bcdd=array(0=>'class="drag drop oddeven"',1=>'class="drag drop oddeven"');
  879. $bcnd=array(0=>'class="nodrag nodrop nohover"',1=>'class="nodrag nodrop nohoverpair"'); // Used for tr to add new lines
  880. $bctag=array(0=>'class="impair tagtr"',1=>'class="pair tagtr"');
  881. // Define messages variables
  882. $mesg=''; $warning=''; $error=0;
  883. // deprecated, see setEventMessages() and dol_htmloutput_events()
  884. $mesgs=array(); $warnings=array(); $errors=array();
  885. // Constants used to defined number of lines in textarea
  886. if (empty($conf->browser->firefox))
  887. {
  888. define('ROWS_1',1);
  889. define('ROWS_2',2);
  890. define('ROWS_3',3);
  891. define('ROWS_4',4);
  892. define('ROWS_5',5);
  893. define('ROWS_6',6);
  894. define('ROWS_7',7);
  895. define('ROWS_8',8);
  896. define('ROWS_9',9);
  897. }
  898. else
  899. {
  900. define('ROWS_1',0);
  901. define('ROWS_2',1);
  902. define('ROWS_3',2);
  903. define('ROWS_4',3);
  904. define('ROWS_5',4);
  905. define('ROWS_6',5);
  906. define('ROWS_7',6);
  907. define('ROWS_8',7);
  908. define('ROWS_9',8);
  909. }
  910. $heightforframes=50;
  911. // Init menu manager
  912. if (! defined('NOREQUIREMENU'))
  913. {
  914. if (empty($user->societe_id)) // If internal user or not defined
  915. {
  916. $conf->standard_menu=(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?(empty($conf->global->MAIN_MENU_STANDARD)?'eldy_menu.php':$conf->global->MAIN_MENU_STANDARD):$conf->global->MAIN_MENU_STANDARD_FORCED);
  917. }
  918. else // If external user
  919. {
  920. $conf->standard_menu=(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?(empty($conf->global->MAIN_MENUFRONT_STANDARD)?'eldy_menu.php':$conf->global->MAIN_MENUFRONT_STANDARD):$conf->global->MAIN_MENUFRONT_STANDARD_FORCED);
  921. }
  922. // Load the menu manager (only if not already done)
  923. $file_menu=$conf->standard_menu;
  924. if (GETPOST('menu','alpha')) $file_menu=GETPOST('menu','alpha'); // example: menu=eldy_menu.php
  925. if (! class_exists('MenuManager'))
  926. {
  927. $menufound=0;
  928. $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
  929. foreach($dirmenus as $dirmenu)
  930. {
  931. $menufound=dol_include_once($dirmenu."standard/".$file_menu);
  932. if (class_exists('MenuManager')) break;
  933. }
  934. if (! class_exists('MenuManager')) // If failed to include, we try with standard eldy_menu.php
  935. {
  936. dol_syslog("You define a menu manager '".$file_menu."' that can not be loaded.", LOG_WARNING);
  937. $file_menu='eldy_menu.php';
  938. include_once DOL_DOCUMENT_ROOT."/core/menus/standard/".$file_menu;
  939. }
  940. }
  941. $menumanager = new MenuManager($db, empty($user->societe_id)?0:1);
  942. $menumanager->loadMenu();
  943. }
  944. // Functions
  945. if (! function_exists("llxHeader"))
  946. {
  947. /**
  948. * Show HTML header HTML + BODY + Top menu + left menu + DIV
  949. *
  950. * @param string $head Optionnal head lines
  951. * @param string $title HTML title
  952. * @param string $help_url Url links to help page
  953. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  954. * For other external page: http://server/url
  955. * @param string $target Target to use on links
  956. * @param int $disablejs More content into html header
  957. * @param int $disablehead More content into html header
  958. * @param array $arrayofjs Array of complementary js files
  959. * @param array $arrayofcss Array of complementary css files
  960. * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails)
  961. * @param string $morecssonbody More CSS on body tag.
  962. * @param string $replacemainareaby Replace call to main_area() by a print of this string
  963. * @return void
  964. */
  965. function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='')
  966. {
  967. global $conf;
  968. // html header
  969. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  970. print '<body id="mainbody"'.($morecssonbody?' class="'.$morecssonbody.'"':'').'>' . "\n";
  971. // top menu and left menu area
  972. if (empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu','int'))
  973. {
  974. top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring, $help_url);
  975. }
  976. if (empty($conf->dol_hide_leftmenu))
  977. {
  978. left_menu('', $help_url, '', '', 1, $title, 1); // $menumanager is retreived with a global $menumanager inside this function
  979. }
  980. // main area
  981. if ($replacemainareaby)
  982. {
  983. print $replacemainareaby;
  984. return;
  985. }
  986. main_area($title);
  987. }
  988. }
  989. /**
  990. * Show HTTP header
  991. *
  992. * @param string $contenttype Content type. For example, 'text/html'
  993. * @param int $forcenocache Force disabling of cache for the page
  994. * @return void
  995. */
  996. function top_httphead($contenttype='text/html', $forcenocache=0)
  997. {
  998. global $db, $conf, $hookmanager;
  999. if ($contenttype == 'text/html' ) header("Content-Type: text/html; charset=".$conf->file->character_set_client);
  1000. else header("Content-Type: ".$contenttype);
  1001. // Security options
  1002. header("X-Content-Type-Options: nosniff"); // With the nosniff option, if the server says the content is text/html, the browser will render it as text/html (note that most browsers now force this option to on)
  1003. header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
  1004. //header("X-XSS-Protection: 1"); // XSS protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated.
  1005. if (! defined('FORCECSP'))
  1006. {
  1007. //if (! isset($conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY))
  1008. //{
  1009. // // A default security policy that keep usage of js external component like ckeditor, stripe, google, working
  1010. // $contentsecuritypolicy = "font-src *; img-src *; style-src * 'unsafe-inline' 'unsafe-eval'; default-src 'self' *.stripe.com 'unsafe-inline' 'unsafe-eval'; script-src 'self' *.stripe.com 'unsafe-inline' 'unsafe-eval'; frame-src 'self' *.stripe.com; connect-src 'self';";
  1011. //}
  1012. //else $contentsecuritypolicy = $conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY;
  1013. $contentsecuritypolicy = $conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY;
  1014. if (! is_object($hookmanager)) $hookmanager = new HookManager($db);
  1015. $hookmanager->initHooks("main");
  1016. $parameters=array('contentsecuritypolicy'=>$contentsecuritypolicy);
  1017. $result=$hookmanager->executeHooks('setContentSecurityPolicy',$parameters); // Note that $action and $object may have been modified by some hooks
  1018. if ($result > 0) $contentsecuritypolicy = $hookmanager->resPrint; // Replace CSP
  1019. else $contentsecuritypolicy .= $hookmanager->resPrint; // Concat CSP
  1020. if (! empty($contentsecuritypolicy))
  1021. {
  1022. // For example, to restrict 'script', 'object', 'frames' or 'img' to some domains:
  1023. // script-src https://api.google.com https://anotherhost.com; object-src https://youtube.com; frame-src https://youtube.com; img-src: https://static.example.com
  1024. // For example, to restrict everything to one domain, except 'object', ...:
  1025. // default-src https://cdn.example.net; object-src 'none'
  1026. // For example, to restrict everything to itself except img that can be on other servers:
  1027. // default-src 'self'; img-src *;
  1028. // Pre-existing site that uses too much inline code to fix but wants to ensure resources are loaded only over https and disable plugins:
  1029. // default-src http: https: 'unsafe-eval' 'unsafe-inline'; object-src 'none'
  1030. header("Content-Security-Policy: ".$contentsecuritypolicy);
  1031. }
  1032. }
  1033. elseif (constant('FORCECSP'))
  1034. {
  1035. header("Content-Security-Policy: ".constant('FORCECSP'));
  1036. }
  1037. if ($forcenocache)
  1038. {
  1039. header("Cache-Control: no-cache, no-store, must-revalidate, max-age=0");
  1040. }
  1041. }
  1042. /**
  1043. * Ouput html header of a page.
  1044. * This code is also duplicated into security2.lib.php::dol_loginfunction
  1045. *
  1046. * @param string $head Optionnal head lines
  1047. * @param string $title HTML title
  1048. * @param int $disablejs Disable js output
  1049. * @param int $disablehead Disable head output
  1050. * @param array $arrayofjs Array of complementary js files
  1051. * @param array $arrayofcss Array of complementary css files
  1052. * @param int $disablejmobile Disable jmobile (No more used)
  1053. * @param int $disablenofollow Disable no follow tag
  1054. * @return void
  1055. */
  1056. function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $disablejmobile=0, $disablenofollow=0)
  1057. {
  1058. global $db, $conf, $langs, $user, $hookmanager;
  1059. top_httphead();
  1060. if (empty($conf->css)) $conf->css = '/theme/eldy/style.css.php'; // If not defined, eldy by default
  1061. print '<!doctype html>'."\n";
  1062. if (! empty($conf->global->MAIN_USE_CACHE_MANIFEST)) print '<html lang="'.substr($langs->defaultlang,0,2).'" manifest="'.DOL_URL_ROOT.'/cache.manifest">'."\n";
  1063. else print '<html lang="'.substr($langs->defaultlang,0,2).'">'."\n";
  1064. //print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">'."\n";
  1065. if (empty($disablehead))
  1066. {
  1067. $ext='layout='.$conf->browser->layout.'&version='.urlencode(DOL_VERSION);
  1068. print "<head>\n";
  1069. if (GETPOST('dol_basehref','alpha')) print '<base href="'.dol_escape_htmltag(GETPOST('dol_basehref','alpha')).'">'."\n";
  1070. // Displays meta
  1071. print '<meta charset="UTF-8">'."\n";
  1072. print '<meta name="robots" content="noindex'.($disablenofollow?'':',nofollow').'">'."\n"; // Do not index
  1073. print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n"; // Scale for mobile device
  1074. print '<meta name="author" content="Dolibarr Development Team">'."\n";
  1075. // Favicon
  1076. $favicon=dol_buildpath('/theme/'.$conf->theme.'/img/favicon.ico',1);
  1077. if (! empty($conf->global->MAIN_FAVICON_URL)) $favicon=$conf->global->MAIN_FAVICON_URL;
  1078. if (empty($conf->dol_use_jmobile)) print '<link rel="shortcut icon" type="image/x-icon" href="'.$favicon.'"/>'."\n"; // Not required into an Android webview
  1079. //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="top" title="'.$langs->trans("Home").'" href="'.(DOL_URL_ROOT?DOL_URL_ROOT:'/').'">'."\n";
  1080. //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";
  1081. //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="author" title="Dolibarr Development Team" href="https://www.dolibarr.org">'."\n";
  1082. // Auto refresh page
  1083. if (GETPOST('autorefresh','int') > 0) print '<meta http-equiv="refresh" content="'.GETPOST('autorefresh','int').'">';
  1084. // Displays title
  1085. $appli=constant('DOL_APPLICATION_TITLE');
  1086. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli=$conf->global->MAIN_APPLICATION_TITLE;
  1087. print '<title>';
  1088. $titletoshow='';
  1089. if ($title && ! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/',$conf->global->MAIN_HTML_TITLE)) $titletoshow = dol_htmlentities($title);
  1090. else if ($title) $titletoshow = dol_htmlentities($appli.' - '.$title);
  1091. else $titletoshow = dol_htmlentities($appli);
  1092. if (! is_object($hookmanager)) $hookmanager = new HookManager($db);
  1093. $hookmanager->initHooks("main");
  1094. $parameters=array('title'=>$titletoshow);
  1095. $result=$hookmanager->executeHooks('setHtmlTitle',$parameters); // Note that $action and $object may have been modified by some hooks
  1096. if ($result > 0) $titletoshow = $hookmanager->resPrint; // Replace Title to show
  1097. else $titletoshow .= $hookmanager->resPrint; // Concat to Title to show
  1098. print $titletoshow;
  1099. print '</title>';
  1100. print "\n";
  1101. if (GETPOST('version','int')) $ext='version='.GETPOST('version','int'); // usefull to force no cache on css/js
  1102. if (GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)) $ext.='&testmenuhider='.(GETPOST('testmenuhider','int')?GETPOST('testmenuhider','int'):$conf->global->MAIN_TESTMENUHIDER);
  1103. $themeparam='?lang='.$langs->defaultlang.'&amp;theme='.$conf->theme.(GETPOST('optioncss','aZ09')?'&amp;optioncss='.GETPOST('optioncss','aZ09',1):'').'&amp;userid='.$user->id.'&amp;entity='.$conf->entity;
  1104. $themeparam.=($ext?'&amp;'.$ext:'');
  1105. if (! empty($_SESSION['dol_resetcache'])) $themeparam.='&amp;dol_resetcache='.$_SESSION['dol_resetcache'];
  1106. if (GETPOST('dol_hide_topmenu','int')) { $themeparam.='&amp;dol_hide_topmenu='.GETPOST('dol_hide_topmenu','int'); }
  1107. if (GETPOST('dol_hide_leftmenu','int')) { $themeparam.='&amp;dol_hide_leftmenu='.GETPOST('dol_hide_leftmenu','int'); }
  1108. if (GETPOST('dol_optimize_smallscreen','int')) { $themeparam.='&amp;dol_optimize_smallscreen='.GETPOST('dol_optimize_smallscreen','int'); }
  1109. if (GETPOST('dol_no_mouse_hover','int')) { $themeparam.='&amp;dol_no_mouse_hover='.GETPOST('dol_no_mouse_hover','int'); }
  1110. if (GETPOST('dol_use_jmobile','int')) { $themeparam.='&amp;dol_use_jmobile='.GETPOST('dol_use_jmobile','int'); $conf->dol_use_jmobile=GETPOST('dol_use_jmobile','int'); }
  1111. if (! defined('DISABLE_JQUERY') && ! $disablejs && $conf->use_javascript_ajax)
  1112. {
  1113. print '<!-- Includes CSS for JQuery (Ajax library) -->'."\n";
  1114. $jquerytheme = 'base';
  1115. if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
  1116. if (constant('JS_JQUERY_UI')) print '<link rel="stylesheet" type="text/css" href="'.JS_JQUERY_UI.'css/'.$jquerytheme.'/jquery-ui.min.css'.($ext?'?'.$ext:'').'">'."\n"; // JQuery
  1117. else print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/css/'.$jquerytheme.'/jquery-ui.css'.($ext?'?'.$ext:'').'">'."\n"; // JQuery
  1118. if (! defined('DISABLE_JQUERY_JNOTIFY')) print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jnotify/jquery.jnotify-alt.min.css'.($ext?'?'.$ext:'').'">'."\n"; // JNotify
  1119. if (! defined('DISABLE_SELECT2') && (! empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT'))) // jQuery plugin "mutiselect", "multiple-select", "select2"...
  1120. {
  1121. $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT'):$conf->global->MAIN_USE_JQUERY_MULTISELECT;
  1122. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/'.$tmpplugin.'/dist/css/'.$tmpplugin.'.css'.($ext?'?'.$ext:'').'">'."\n";
  1123. }
  1124. }
  1125. if (! defined('DISABLE_FONT_AWSOME'))
  1126. {
  1127. print '<!-- Includes CSS for font awesome -->'."\n";
  1128. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/theme/common/fontawesome/css/font-awesome.min.css'.($ext?'?'.$ext:'').'">'."\n";
  1129. }
  1130. print '<!-- Includes CSS for Dolibarr theme -->'."\n";
  1131. // Output style sheets (optioncss='print' or ''). Note: $conf->css looks like '/theme/eldy/style.css.php'
  1132. $themepath=dol_buildpath($conf->css,1);
  1133. $themesubdir='';
  1134. if (! empty($conf->modules_parts['theme'])) // This slow down
  1135. {
  1136. foreach($conf->modules_parts['theme'] as $reldir)
  1137. {
  1138. if (file_exists(dol_buildpath($reldir.$conf->css, 0)))
  1139. {
  1140. $themepath=dol_buildpath($reldir.$conf->css, 1);
  1141. $themesubdir=$reldir;
  1142. break;
  1143. }
  1144. }
  1145. }
  1146. //print 'themepath='.$themepath.' themeparam='.$themeparam;exit;
  1147. print '<link rel="stylesheet" type="text/css" href="'.$themepath.$themeparam.'">'."\n";
  1148. if (! empty($conf->global->MAIN_FIX_FLASH_ON_CHROME)) print '<!-- Includes CSS that does not exists as a workaround of flash bug of chrome -->'."\n".'<link rel="stylesheet" type="text/css" href="filethatdoesnotexiststosolvechromeflashbug">'."\n";
  1149. // CSS forced by modules (relative url starting with /)
  1150. if (! empty($conf->modules_parts['css']))
  1151. {
  1152. $arraycss=(array) $conf->modules_parts['css'];
  1153. foreach($arraycss as $modcss => $filescss)
  1154. {
  1155. $filescss=(array) $filescss; // To be sure filecss is an array
  1156. foreach($filescss as $cssfile)
  1157. {
  1158. if (empty($cssfile)) dol_syslog("Warning: module ".$modcss." declared a css path file into its descriptor that is empty.", LOG_WARNING);
  1159. // cssfile is a relative path
  1160. print '<!-- Includes CSS added by module '.$modcss. ' -->'."\n".'<link rel="stylesheet" type="text/css" href="'.dol_buildpath($cssfile,1);
  1161. // 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, so browser cache is not used.
  1162. if (!preg_match('/\.css$/i',$cssfile)) print $themeparam;
  1163. print '">'."\n";
  1164. }
  1165. }
  1166. }
  1167. // CSS forced by page in top_htmlhead call (relative url starting with /)
  1168. if (is_array($arrayofcss))
  1169. {
  1170. foreach($arrayofcss as $cssfile)
  1171. {
  1172. print '<!-- Includes CSS added by page -->'."\n".'<link rel="stylesheet" type="text/css" title="default" href="'.dol_buildpath($cssfile,1);
  1173. // 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.
  1174. if (!preg_match('/\.css$/i',$cssfile)) print $themeparam;
  1175. print '">'."\n";
  1176. }
  1177. }
  1178. // Output standard javascript links
  1179. if (! defined('DISABLE_JQUERY') && ! $disablejs && ! empty($conf->use_javascript_ajax))
  1180. {
  1181. // JQuery. Must be before other includes
  1182. print '<!-- Includes JS for JQuery -->'."\n";
  1183. if (defined('JS_JQUERY') && constant('JS_JQUERY')) print '<script type="text/javascript" src="'.JS_JQUERY.'jquery.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1184. else print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1185. if (! empty($conf->global->MAIN_FEATURES_LEVEL) && ! defined('JS_JQUERY_MIGRATE_DISABLED'))
  1186. {
  1187. if (defined('JS_JQUERY_MIGRATE') && constant('JS_JQUERY_MIGRATE')) print '<script type="text/javascript" src="'.JS_JQUERY_MIGRATE.'jquery-migrate.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1188. else print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery-migrate.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1189. }
  1190. if (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) print '<script type="text/javascript" src="'.JS_JQUERY_UI.'jquery-ui.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1191. else print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery-ui.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1192. if (! defined('DISABLE_JQUERY_TABLEDND')) print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/tablednd/jquery.tablednd.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1193. // jQuery jnotify
  1194. if (empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && ! defined('DISABLE_JQUERY_JNOTIFY'))
  1195. {
  1196. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jnotify/jquery.jnotify.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1197. }
  1198. // Flot
  1199. if (empty($conf->global->MAIN_DISABLE_JQUERY_FLOT) && ! defined('DISABLE_JQUERY_FLOT'))
  1200. {
  1201. if (constant('JS_JQUERY_FLOT'))
  1202. {
  1203. print '<script type="text/javascript" src="'.JS_JQUERY_FLOT.'jquery.flot.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1204. print '<script type="text/javascript" src="'.JS_JQUERY_FLOT.'jquery.flot.pie.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1205. print '<script type="text/javascript" src="'.JS_JQUERY_FLOT.'jquery.flot.stack.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1206. }
  1207. else
  1208. {
  1209. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/flot/jquery.flot.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1210. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/flot/jquery.flot.pie.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1211. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/flot/jquery.flot.stack.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1212. }
  1213. }
  1214. // jQuery jeditable
  1215. if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && ! defined('DISABLE_JQUERY_JEDITABLE'))
  1216. {
  1217. print '<!-- JS to manage editInPlace feature -->'."\n";
  1218. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1219. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ui-datepicker.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1220. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ui-autocomplete.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1221. print '<script type="text/javascript">'."\n";
  1222. print 'var urlSaveInPlace = \''.DOL_URL_ROOT.'/core/ajax/saveinplace.php\';'."\n";
  1223. print 'var urlLoadInPlace = \''.DOL_URL_ROOT.'/core/ajax/loadinplace.php\';'."\n";
  1224. print 'var tooltipInPlace = \''.$langs->transnoentities('ClickToEdit').'\';'."\n"; // Added in title attribute of span
  1225. print 'var placeholderInPlace = \'&nbsp;\';'."\n"; // If we put another string than $langs->trans("ClickToEdit") here, nothing is shown. If we put empty string, there is error, Why ?
  1226. print 'var cancelInPlace = \''.$langs->trans('Cancel').'\';'."\n";
  1227. print 'var submitInPlace = \''.$langs->trans('Ok').'\';'."\n";
  1228. print 'var indicatorInPlace = \'<img src="'.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'">\';'."\n";
  1229. print 'var withInPlace = 300;'; // width in pixel for default string edit
  1230. print '</script>'."\n";
  1231. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/editinplace.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1232. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1233. }
  1234. // jQuery Timepicker
  1235. if (! empty($conf->global->MAIN_USE_JQUERY_TIMEPICKER) || defined('REQUIRE_JQUERY_TIMEPICKER'))
  1236. {
  1237. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/timepicker/jquery-ui-timepicker-addon.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1238. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/timepicker.js.php?lang='.$langs->defaultlang.($ext?'&amp;'.$ext:'').'"></script>'."\n";
  1239. }
  1240. if (! defined('DISABLE_SELECT2') && (! empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT'))) // jQuery plugin "mutiselect", "multiple-select", "select2", ...
  1241. {
  1242. $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT'):$conf->global->MAIN_USE_JQUERY_MULTISELECT;
  1243. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/'.$tmpplugin.'/dist/js/'.$tmpplugin.'.full.min.js'.($ext?'?'.$ext:'').'"></script>'."\n"; // We include full because we need the support of containerCssClass
  1244. }
  1245. if (! defined('DISABLE_MULTISELECT')) // jQuery plugin "mutiselect" to select with checkboxes
  1246. {
  1247. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/multiselect/jquery.multi-select.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1248. }
  1249. }
  1250. if (! $disablejs && ! empty($conf->use_javascript_ajax))
  1251. {
  1252. // CKEditor
  1253. if (! empty($conf->fckeditor->enabled) && (empty($conf->global->FCKEDITOR_EDITORNAME) || $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor') && ! defined('DISABLE_CKEDITOR'))
  1254. {
  1255. print '<!-- Includes JS for CKEditor -->'."\n";
  1256. $pathckeditor = DOL_URL_ROOT . '/includes/ckeditor/ckeditor/';
  1257. $jsckeditor='ckeditor.js';
  1258. if (constant('JS_CKEDITOR')) // To use external ckeditor 4 js lib
  1259. {
  1260. $pathckeditor=constant('JS_CKEDITOR');
  1261. }
  1262. print '<script type="text/javascript">';
  1263. print 'var CKEDITOR_BASEPATH = \''.$pathckeditor.'\';'."\n";
  1264. print 'var ckeditorConfig = \''.dol_buildpath($themesubdir.'/theme/'.$conf->theme.'/ckeditor/config.js'.($ext?'?'.$ext:''),1).'\';'."\n"; // $themesubdir='' in standard usage
  1265. print 'var ckeditorFilebrowserBrowseUrl = \''.DOL_URL_ROOT.'/core/filemanagerdol/browser/default/browser.php?Connector='.DOL_URL_ROOT.'/core/filemanagerdol/connectors/php/connector.php\';'."\n";
  1266. print 'var ckeditorFilebrowserImageBrowseUrl = \''.DOL_URL_ROOT.'/core/filemanagerdol/browser/default/browser.php?Type=Image&Connector='.DOL_URL_ROOT.'/core/filemanagerdol/connectors/php/connector.php\';'."\n";
  1267. print '</script>'."\n";
  1268. print '<script type="text/javascript" src="'.$pathckeditor.$jsckeditor.($ext?'?'.$ext:'').'"></script>'."\n";
  1269. }
  1270. // Browser notifications
  1271. if (! defined('DISABLE_BROWSER_NOTIF'))
  1272. {
  1273. $enablebrowsernotif=false;
  1274. if (! empty($conf->agenda->enabled) && ! empty($conf->global->AGENDA_REMINDER_BROWSER)) $enablebrowsernotif=true;
  1275. if ($conf->browser->layout == 'phone') $enablebrowsernotif=false;
  1276. if ($enablebrowsernotif)
  1277. {
  1278. print '<!-- Includes JS of Dolibarr (brwoser layout = '.$conf->browser->layout.')-->'."\n";
  1279. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/lib_notification.js.php'.($ext?'?'.$ext:'').'"></script>'."\n";
  1280. }
  1281. }
  1282. // Global js function
  1283. print '<!-- Includes JS of Dolibarr -->'."\n";
  1284. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/lib_head.js.php?lang='.$langs->defaultlang.($ext?'&'.$ext:'').'"></script>'."\n";
  1285. // JS forced by modules (relative url starting with /)
  1286. if (! empty($conf->modules_parts['js'])) // $conf->modules_parts['js'] is array('module'=>array('file1','file2'))
  1287. {
  1288. $arrayjs=(array) $conf->modules_parts['js'];
  1289. foreach($arrayjs as $modjs => $filesjs)
  1290. {
  1291. $filesjs=(array) $filesjs; // To be sure filejs is an array
  1292. foreach($filesjs as $jsfile)
  1293. {
  1294. // jsfile is a relative path
  1295. print '<!-- Include JS added by module '.$modjs. '-->'."\n".'<script type="text/javascript" src="'.dol_buildpath($jsfile,1).'"></script>'."\n";
  1296. }
  1297. }
  1298. }
  1299. // JS forced by page in top_htmlhead (relative url starting with /)
  1300. if (is_array($arrayofjs))
  1301. {
  1302. print '<!-- Includes JS added by page -->'."\n";
  1303. foreach($arrayofjs as $jsfile)
  1304. {
  1305. if (preg_match('/^http/i',$jsfile))
  1306. {
  1307. print '<script type="text/javascript" src="'.$jsfile.'"></script>'."\n";
  1308. }
  1309. else
  1310. {
  1311. print '<script type="text/javascript" src="'.dol_buildpath($jsfile,1).'"></script>'."\n";
  1312. }
  1313. }
  1314. }
  1315. }
  1316. if (! empty($head)) print $head."\n";
  1317. if (! empty($conf->global->MAIN_HTML_HEADER)) print $conf->global->MAIN_HTML_HEADER."\n";
  1318. print "</head>\n\n";
  1319. }
  1320. $conf->headerdone=1; // To tell header was output
  1321. }
  1322. /**
  1323. * Show an HTML header + a BODY + The top menu bar
  1324. *
  1325. * @param string $head Lines in the HEAD
  1326. * @param string $title Title of web page
  1327. * @param string $target Target to use in menu links (Example: '' or '_top')
  1328. * @param int $disablejs Do not output links to js (Ex: qd fonction utilisee par sous formulaire Ajax)
  1329. * @param int $disablehead Do not output head section
  1330. * @param array $arrayofjs Array of js files to add in header
  1331. * @param array $arrayofcss Array of css files to add in header
  1332. * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails)
  1333. * @param string $helppagename Name of wiki page for help ('' by default).
  1334. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  1335. * For other external page: http://server/url
  1336. * @return void
  1337. */
  1338. function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $helppagename='')
  1339. {
  1340. global $user, $conf, $langs, $db;
  1341. global $dolibarr_main_authentication, $dolibarr_main_demo;
  1342. global $hookmanager,$menumanager;
  1343. $searchform='';
  1344. $bookmarks='';
  1345. // Instantiate hooks of thirdparty module
  1346. $hookmanager->initHooks(array('toprightmenu'));
  1347. $toprightmenu='';
  1348. // For backward compatibility with old modules
  1349. if (empty($conf->headerdone))
  1350. {
  1351. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  1352. print '<body id="mainbody">';
  1353. }
  1354. /*
  1355. * Top menu
  1356. */
  1357. if ((empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu','int')) && (! defined('NOREQUIREMENU') || ! constant('NOREQUIREMENU')))
  1358. {
  1359. print "\n".'<!-- Start top horizontal -->'."\n";
  1360. print '<div class="side-nav-vert'.(GETPOST('dol_invisible_topmenu','int')?' hidden':'').'"><div id="id-top">'; // dol_invisible_topmenu differs from dol_hide_topmenu: dol_invisible_topmenu means we output menu but we make it invisible.
  1361. // Show menu entries
  1362. print '<div id="tmenu_tooltip'.(empty($conf->global->MAIN_MENU_INVERT)?'':'invert').'" class="tmenu">'."\n";
  1363. $menumanager->atarget=$target;
  1364. $menumanager->showmenu('top', array('searchform'=>$searchform, 'bookmarks'=>$bookmarks)); // This contains a \n
  1365. print "</div>\n";
  1366. // Define link to login card
  1367. $appli=constant('DOL_APPLICATION_TITLE');
  1368. if (! empty($conf->global->MAIN_APPLICATION_TITLE))
  1369. {
  1370. $appli=$conf->global->MAIN_APPLICATION_TITLE;
  1371. if (preg_match('/\d\.\d/', $appli))
  1372. {
  1373. if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core
  1374. }
  1375. else $appli.=" ".DOL_VERSION;
  1376. }
  1377. else $appli.=" ".DOL_VERSION;
  1378. if (! empty($conf->global->MAIN_FEATURES_LEVEL)) $appli.="<br>".$langs->trans("LevelOfFeature").': '.$conf->global->MAIN_FEATURES_LEVEL;
  1379. $logouttext='';
  1380. if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  1381. {
  1382. //$logouthtmltext=$appli.'<br>';
  1383. if ($_SESSION["dol_authmode"] != 'forceuser' && $_SESSION["dol_authmode"] != 'http')
  1384. {
  1385. $logouthtmltext.=$langs->trans("Logout").'<br>';
  1386. $logouttext .='<a href="'.DOL_URL_ROOT.'/user/logout.php">';
  1387. //$logouttext .= img_picto($langs->trans('Logout').":".$langs->trans('Logout'), 'logout_top.png', 'class="login"', 0, 0, 1);
  1388. $logouttext .='<span class="fa fa-sign-out atoplogin"></span>';
  1389. $logouttext .='</a>';
  1390. }
  1391. else
  1392. {
  1393. $logouthtmltext.=$langs->trans("NoLogoutProcessWithAuthMode",$_SESSION["dol_authmode"]);
  1394. $logouttext .= img_picto($langs->trans('Logout').":".$langs->trans('Logout'), 'logout_top.png', 'class="login"', 0, 0, 1);
  1395. }
  1396. }
  1397. print '<div class="login_block">'."\n";
  1398. // Add login user link
  1399. $toprightmenu.='<div class="login_block_user">';
  1400. // Login name with photo and tooltip
  1401. $mode=-1;
  1402. $toprightmenu.='<div class="inline-block nowrap"><div class="inline-block login_block_elem login_block_elem_name" style="padding: 0px;">';
  1403. $toprightmenu.=$user->getNomUrl($mode, '', 1, 0, 11, 0, ($user->firstname ? 'firstname' : -1),'atoplogin');
  1404. $toprightmenu.='</div></div>';
  1405. $toprightmenu.='</div>'."\n";
  1406. $toprightmenu.='<div class="login_block_other">';
  1407. // Execute hook printTopRightMenu (hooks should output string like '<div class="login"><a href="">mylink</a></div>')
  1408. $parameters=array();
  1409. $result=$hookmanager->executeHooks('printTopRightMenu',$parameters); // Note that $action and $object may have been modified by some hooks
  1410. if (is_numeric($result))
  1411. {
  1412. if ($result == 0)
  1413. $toprightmenu.=$hookmanager->resPrint; // add
  1414. else
  1415. $toprightmenu=$hookmanager->resPrint; // replace
  1416. }
  1417. else
  1418. {
  1419. $toprightmenu.=$result; // For backward compatibility
  1420. }
  1421. // Link to module builder
  1422. if (! empty($conf->modulebuilder->enabled))
  1423. {
  1424. $text ='<a href="'.DOL_URL_ROOT.'/modulebuilder/index.php?mainmenu=home&leftmenu=admintools" target="_modulebuilder">';
  1425. //$text.= img_picto(":".$langs->trans("ModuleBuilder"), 'printer_top.png', 'class="printer"');
  1426. $text.='<span class="fa fa-bug atoplogin"></span>';
  1427. $text.='</a>';
  1428. $toprightmenu.=@Form::textwithtooltip('',$langs->trans("ModuleBuilder"),2,1,$text,'login_block_elem',2);
  1429. }
  1430. // Link to print main content area
  1431. if (empty($conf->global->MAIN_PRINT_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $conf->browser->layout != 'phone')
  1432. {
  1433. $qs=dol_escape_htmltag($_SERVER["QUERY_STRING"]);
  1434. if (is_array($_POST))
  1435. {
  1436. foreach($_POST as $key=>$value) {
  1437. if ($key!=='action' && $key!=='password' && !is_array($value)) $qs.='&'.$key.'='.urlencode($value);
  1438. }
  1439. }
  1440. $qs.=(($qs && $morequerystring)?'&':'').$morequerystring;
  1441. $text ='<a href="'.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.$qs.($qs?'&':'').'optioncss=print" target="_blank">';
  1442. //$text.= img_picto(":".$langs->trans("PrintContentArea"), 'printer_top.png', 'class="printer"');
  1443. $text.='<span class="fa fa-print atoplogin"></span>';
  1444. $text.='</a>';
  1445. $toprightmenu.=@Form::textwithtooltip('',$langs->trans("PrintContentArea"),2,1,$text,'login_block_elem',2);
  1446. }
  1447. // Link to Dolibarr wiki pages
  1448. if (empty($conf->global->MAIN_HELP_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  1449. {
  1450. $langs->load("help");
  1451. $helpbaseurl='';
  1452. $helppage='';
  1453. $mode='';
  1454. if (empty($helppagename)) $helppagename='EN:User_documentation|FR:Documentation_utilisateur|ES:Documentación_usuarios';
  1455. // Get helpbaseurl, helppage and mode from helppagename and langs
  1456. $arrayres=getHelpParamFor($helppagename,$langs);
  1457. $helpbaseurl=$arrayres['helpbaseurl'];
  1458. $helppage=$arrayres['helppage'];
  1459. $mode=$arrayres['mode'];
  1460. // Link to help pages
  1461. if ($helpbaseurl && $helppage)
  1462. {
  1463. $text='';
  1464. if(!empty($conf->global->MAIN_SHOWDATABASENAMEINHELPPAGESLINK)) {
  1465. $langs->load('admin');
  1466. $appli .= '<br>' . $langs->trans("Database") . ': ' . $db->database_name;
  1467. }
  1468. $title=$appli.'<br>';
  1469. $title.=$langs->trans($mode == 'wiki' ? 'GoToWikiHelpPage': 'GoToHelpPage');
  1470. if ($mode == 'wiki') $title.=' - '.$langs->trans("PageWiki").' &quot;'.dol_escape_htmltag(strtr($helppage,'_',' ')).'&quot;';
  1471. $text.='<a class="help" target="_blank" rel="noopener" href="';
  1472. if ($mode == 'wiki') $text.=sprintf($helpbaseurl,urlencode(html_entity_decode($helppage)));
  1473. else $text.=sprintf($helpbaseurl,$helppage);
  1474. $text.='">';
  1475. //$text.=img_picto('', 'helpdoc_top').' ';
  1476. $text.='<span class="fa fa-question-circle atoplogin"></span>';
  1477. //$toprightmenu.=$langs->trans($mode == 'wiki' ? 'OnlineHelp': 'Help');
  1478. //if ($mode == 'wiki') $text.=' ('.dol_trunc(strtr($helppage,'_',' '),8).')';
  1479. $text.='</a>';
  1480. //$toprightmenu.='</div>'."\n";
  1481. $toprightmenu.=@Form::textwithtooltip('',$title,2,1,$text,'login_block_elem',2);
  1482. }
  1483. }
  1484. // Logout link
  1485. $toprightmenu.=@Form::textwithtooltip('',$logouthtmltext,2,1,$logouttext,'login_block_elem',2);
  1486. $toprightmenu.='</div>';
  1487. print $toprightmenu;
  1488. print "</div>\n"; // end div class="login_block"
  1489. print '</div></div>';
  1490. print '<div style="clear: both;"></div>';
  1491. print "<!-- End top horizontal menu -->\n\n";
  1492. }
  1493. if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) print '<!-- Begin div id-container --><div id="id-container" class="id-container'.($morecss?' '.$morecss:'').'">';
  1494. }
  1495. /**
  1496. * Show left menu bar
  1497. *
  1498. * @param array $menu_array_before Table of menu entries to show before entries of menu handler. This param is deprectaed and must be provided to ''.
  1499. * @param string $helppagename Name of wiki page for help ('' by default).
  1500. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  1501. * For other external page: http://server/url
  1502. * @param string $notused Deprecated. Used in past to add content into left menu. Hooks can be used now.
  1503. * @param array $menu_array_after Table of menu entries to show after entries of menu handler
  1504. * @param int $leftmenuwithoutmainarea Must be set to 1. 0 by default for backward compatibility with old modules.
  1505. * @param string $title Title of web page
  1506. * @param string $acceptdelayedhtml 1 if caller request to have html delayed content not returned but saved into global $delayedhtmlcontent (so caller can show it at end of page to avoid flash FOUC effect)
  1507. * @return void
  1508. */
  1509. function left_menu($menu_array_before, $helppagename='', $notused='', $menu_array_after='', $leftmenuwithoutmainarea=0, $title='', $acceptdelayedhtml=0)
  1510. {
  1511. global $user, $conf, $langs, $db, $form;
  1512. global $hookmanager, $menumanager;
  1513. $searchform='';
  1514. $bookmarks='';
  1515. if (! empty($menu_array_before)) dol_syslog("Deprecated parameter menu_array_before was used when calling main::left_menu function. Menu entries of module should now be defined into module descriptor and not provided when calling left_menu.", LOG_WARNING);
  1516. if (empty($conf->dol_hide_leftmenu) && (! defined('NOREQUIREMENU') || ! constant('NOREQUIREMENU')))
  1517. {
  1518. // Instantiate hooks of thirdparty module
  1519. $hookmanager->initHooks(array('searchform','leftblock'));
  1520. print "\n".'<!-- Begin side-nav id-left -->'."\n".'<div class="side-nav"><div id="id-left">'."\n";
  1521. if ($conf->browser->layout == 'phone') $conf->global->MAIN_USE_OLD_SEARCH_FORM=1; // Select into select2 is awfull on smartphone. TODO Is this still true with select2 v4 ?
  1522. print "\n";
  1523. if (! is_object($form)) $form=new Form($db);
  1524. $selected=-1;
  1525. $usedbyinclude=1;
  1526. include_once DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php'; // This set $arrayresult
  1527. if ($conf->use_javascript_ajax && empty($conf->global->MAIN_USE_OLD_SEARCH_FORM))
  1528. {
  1529. //$searchform.=$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'vmenusearchselectcombo', 1, $langs->trans("Search"), 1);
  1530. $searchform.=$form->selectArrayFilter('searchselectcombo', $arrayresult, $selected, '', 1, 0, (empty($conf->global->MAIN_SEARCHBOX_CONTENT_LOADED_BEFORE_KEY)?1:0), 'vmenusearchselectcombo', 1, $langs->trans("Search"), 1);
  1531. }
  1532. else
  1533. {
  1534. foreach($arrayresult as $key => $val)
  1535. {
  1536. //$searchform.=printSearchForm($val['url'], $val['url'], $val['label'], 'maxwidth100', 'sall', $val['shortcut'], 'searchleft', img_picto('',$val['img']));
  1537. $searchform.=printSearchForm($val['url'], $val['url'], $val['label'], 'maxwidth125', 'sall', $val['shortcut'], 'searchleft', img_picto('', $val['img'], '', false, 1, 1));
  1538. }
  1539. }
  1540. // Execute hook printSearchForm
  1541. $parameters=array('searchform'=>$searchform);
  1542. $reshook=$hookmanager->executeHooks('printSearchForm',$parameters); // Note that $action and $object may have been modified by some hooks
  1543. if (empty($reshook))
  1544. {
  1545. $searchform.=$hookmanager->resPrint;
  1546. }
  1547. else $searchform=$hookmanager->resPrint;
  1548. // Force special value for $searchform
  1549. if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) || empty($conf->use_javascript_ajax))
  1550. {
  1551. $urltosearch=DOL_URL_ROOT.'/core/search_page.php?showtitlebefore=1';
  1552. $searchform='<div class="blockvmenuimpair blockvmenusearchphone"><div id="divsearchforms1"><a href="'.$urltosearch.'" accesskey="s" alt="'.dol_escape_htmltag($langs->trans("ShowSearchFields")).'">'.$langs->trans("Search").'...</a></div></div>';
  1553. }
  1554. elseif ($conf->use_javascript_ajax && ! empty($conf->global->MAIN_USE_OLD_SEARCH_FORM))
  1555. {
  1556. $searchform='<div class="blockvmenuimpair blockvmenusearchphone"><div id="divsearchforms1"><a href="#" alt="'.dol_escape_htmltag($langs->trans("ShowSearchFields")).'">'.$langs->trans("Search").'...</a></div><div id="divsearchforms2" style="display: none">'.$searchform.'</div>';
  1557. $searchform.='<script type="text/javascript">
  1558. jQuery(document).ready(function () {
  1559. jQuery("#divsearchforms1").click(function(){
  1560. jQuery("#divsearchforms2").toggle();
  1561. });
  1562. });
  1563. </script>' . "\n";
  1564. $searchform.='</div>';
  1565. }
  1566. // Define $bookmarks
  1567. if (! empty($conf->bookmark->enabled) && $user->rights->bookmark->lire)
  1568. {
  1569. include_once DOL_DOCUMENT_ROOT.'/bookmarks/bookmarks.lib.php';
  1570. $langs->load("bookmarks");
  1571. $bookmarks=printBookmarksList($db, $langs);
  1572. }
  1573. // Left column
  1574. print '<!-- Begin left menu -->'."\n";
  1575. print '<div class="vmenu"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)?'':' title="Left menu"').'>'."\n\n";
  1576. // Show left menu with other forms
  1577. $menumanager->menu_array = $menu_array_before;
  1578. $menumanager->menu_array_after = $menu_array_after;
  1579. $menumanager->showmenu('left', array('searchform'=>$searchform, 'bookmarks'=>$bookmarks)); // output menu_array and menu found in database
  1580. // Dolibarr version + help + bug report link
  1581. print "\n";
  1582. print "<!-- Begin Help Block-->\n";
  1583. print '<div id="blockvmenuhelp" class="blockvmenuhelp">'."\n";
  1584. // Version
  1585. if (empty($conf->global->MAIN_HIDE_VERSION)) // Version is already on help picto and on login page.
  1586. {
  1587. $doliurl='https://www.dolibarr.org';
  1588. //local communities
  1589. if (preg_match('/fr/i',$langs->defaultlang)) $doliurl='https://www.dolibarr.fr';
  1590. if (preg_match('/es/i',$langs->defaultlang)) $doliurl='https://www.dolibarr.es';
  1591. if (preg_match('/de/i',$langs->defaultlang)) $doliurl='https://www.dolibarr.de';
  1592. if (preg_match('/it/i',$langs->defaultlang)) $doliurl='https://www.dolibarr.it';
  1593. if (preg_match('/gr/i',$langs->defaultlang)) $doliurl='https://www.dolibarr.gr';
  1594. $appli=constant('DOL_APPLICATION_TITLE');
  1595. if (! empty($conf->global->MAIN_APPLICATION_TITLE))
  1596. {
  1597. $appli=$conf->global->MAIN_APPLICATION_TITLE; $doliurl='';
  1598. if (preg_match('/\d\.\d/', $appli))
  1599. {
  1600. if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core
  1601. }
  1602. else $appli.=" ".DOL_VERSION;
  1603. }
  1604. else $appli.=" ".DOL_VERSION;
  1605. print '<div id="blockvmenuhelpapp" class="blockvmenuhelp">';
  1606. if ($doliurl) print '<a class="help" target="_blank" rel="noopener" href="'.$doliurl.'">';
  1607. else print '<span class="help">';
  1608. print $appli;
  1609. if ($doliurl) print '</a>';
  1610. else print '</span>';
  1611. print '</div>'."\n";
  1612. }
  1613. // Link to bugtrack
  1614. if (! empty($conf->global->MAIN_BUGTRACK_ENABLELINK))
  1615. {
  1616. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1617. $bugbaseurl = 'https://github.com/Dolibarr/dolibarr/issues/new';
  1618. $bugbaseurl.= '?title=';
  1619. $bugbaseurl.= urlencode("Bug: ");
  1620. $bugbaseurl.= '&body=';
  1621. $bugbaseurl.= urlencode("# Bug\n");
  1622. $bugbaseurl.= urlencode("\n");
  1623. $bugbaseurl.= urlencode("## Environment\n");
  1624. $bugbaseurl.= urlencode("- **Version**: " . DOL_VERSION . "\n");
  1625. $bugbaseurl.= urlencode("- **OS**: " . php_uname('s') . "\n");
  1626. $bugbaseurl.= urlencode("- **Web server**: " . $_SERVER["SERVER_SOFTWARE"] . "\n");
  1627. $bugbaseurl.= urlencode("- **PHP**: " . php_sapi_name() . ' ' . phpversion() . "\n");
  1628. $bugbaseurl.= urlencode("- **Database**: " . $db::LABEL . ' ' . $db->getVersion() . "\n");
  1629. $bugbaseurl.= urlencode("- **URL**: " . $_SERVER["REQUEST_URI"] . "\n");
  1630. $bugbaseurl.= urlencode("\n");
  1631. $bugbaseurl.= urlencode("## Report\n");
  1632. print '<div id="blockvmenuhelpbugreport" class="blockvmenuhelp">';
  1633. print '<a class="help" target="_blank" rel="noopener" href="'.$bugbaseurl.'">'.$langs->trans("FindBug").'</a>';
  1634. print '</div>';
  1635. }
  1636. print "</div>\n";
  1637. print "<!-- End Help Block-->\n";
  1638. print "\n";
  1639. print "</div>\n";
  1640. print "<!-- End left menu -->\n";
  1641. print "\n";
  1642. // Execute hook printLeftBlock
  1643. $parameters=array();
  1644. $reshook=$hookmanager->executeHooks('printLeftBlock',$parameters); // Note that $action and $object may have been modified by some hooks
  1645. print $hookmanager->resPrint;
  1646. print '</div></div> <!-- End side-nav id-left -->'; // End div id="side-nav" div id="id-left"
  1647. }
  1648. print "\n";
  1649. print '<!-- Begin right area -->'."\n";
  1650. if (empty($leftmenuwithoutmainarea)) main_area($title);
  1651. }
  1652. /**
  1653. * Begin main area
  1654. *
  1655. * @param string $title Title
  1656. * @return void
  1657. */
  1658. function main_area($title='')
  1659. {
  1660. global $conf, $langs;
  1661. if (empty($conf->dol_hide_leftmenu)) print '<div id="id-right">';
  1662. print "\n";
  1663. print '<!-- Begin div class="fiche" -->'."\n".'<div class="fiche">'."\n";
  1664. if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) print info_admin($langs->trans("WarningYouAreInMaintenanceMode",$conf->global->MAIN_ONLY_LOGIN_ALLOWED));
  1665. }
  1666. /**
  1667. * Return helpbaseurl, helppage and mode
  1668. *
  1669. * @param string $helppagename Page name ('EN:xxx,ES:eee,FR:fff...' or 'http://localpage')
  1670. * @param Translate $langs Language
  1671. * @return array Array of help urls
  1672. */
  1673. function getHelpParamFor($helppagename,$langs)
  1674. {
  1675. $helpbaseurl='';
  1676. $helppage='';
  1677. $mode='';
  1678. if (preg_match('/^http/i',$helppagename))
  1679. {
  1680. // If complete URL
  1681. $helpbaseurl='%s';
  1682. $helppage=$helppagename;
  1683. $mode='local';
  1684. }
  1685. else
  1686. {
  1687. // If WIKI URL
  1688. if (preg_match('/^es/i',$langs->defaultlang))
  1689. {
  1690. $helpbaseurl='http://wiki.dolibarr.org/index.php/%s';
  1691. if (preg_match('/ES:([^|]+)/i',$helppagename,$reg)) $helppage=$reg[1];
  1692. }
  1693. if (preg_match('/^fr/i',$langs->defaultlang))
  1694. {
  1695. $helpbaseurl='http://wiki.dolibarr.org/index.php/%s';
  1696. if (preg_match('/FR:([^|]+)/i',$helppagename,$reg)) $helppage=$reg[1];
  1697. }
  1698. if (empty($helppage)) // If help page not already found
  1699. {
  1700. $helpbaseurl='http://wiki.dolibarr.org/index.php/%s';
  1701. if (preg_match('/EN:([^|]+)/i',$helppagename,$reg)) $helppage=$reg[1];
  1702. }
  1703. $mode='wiki';
  1704. }
  1705. return array('helpbaseurl'=>$helpbaseurl,'helppage'=>$helppage,'mode'=>$mode);
  1706. }
  1707. /**
  1708. * Show a search area.
  1709. * Used when the javascript quick search is not used.
  1710. *
  1711. * @param string $urlaction Url post
  1712. * @param string $urlobject Url of the link under the search box
  1713. * @param string $title Title search area
  1714. * @param string $htmlmorecss Add more css
  1715. * @param string $htmlinputname Field Name input form
  1716. * @param string $accesskey Accesskey
  1717. * @param string $prefhtmlinputname Complement for id to avoid multiple same id in the page
  1718. * @param string $img Image to use
  1719. * @param string $showtitlebefore Show title before input text instead of into placeholder. This can be set when output is dedicated for text browsers.
  1720. * @param string $autofocus Set autofocus on field
  1721. * @return string
  1722. */
  1723. function printSearchForm($urlaction, $urlobject, $title, $htmlmorecss, $htmlinputname, $accesskey='', $prefhtmlinputname='',$img='', $showtitlebefore=0, $autofocus=0)
  1724. {
  1725. global $conf,$langs,$user;
  1726. $ret='';
  1727. $ret.='<form action="'.$urlaction.'" method="post" class="searchform">';
  1728. $ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1729. $ret.='<input type="hidden" name="mode" value="search">';
  1730. $ret.='<input type="hidden" name="savelogin" value="'.dol_escape_htmltag($user->login).'">';
  1731. if ($showtitlebefore) $ret.=$title.' ';
  1732. $ret.='<input type="text" class="flat '.$htmlmorecss.'"';
  1733. $ret.=' style="text-indent: 22px; background-image: url(\''.$img.'\'); background-repeat: no-repeat; background-position: 3px;"';
  1734. $ret.=($accesskey?' accesskey="'.$accesskey.'"':'');
  1735. $ret.=' placeholder="'.strip_tags($title).'"';
  1736. $ret.=($autofocus?' autofocus':'');
  1737. $ret.=' name="'.$htmlinputname.'" id="'.$prefhtmlinputname.$htmlinputname.'" />';
  1738. //$ret.='<input type="submit" class="button" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px" value="'.$langs->trans("Go").'">';
  1739. $ret.='<button type="submit" class="button" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">';
  1740. $ret.='<span class="fa fa-search"></span>';
  1741. $ret.='</button>';
  1742. $ret.="</form>\n";
  1743. return $ret;
  1744. }
  1745. if (! function_exists("llxFooter"))
  1746. {
  1747. /**
  1748. * Show HTML footer
  1749. * Close div /DIV class=fiche + /DIV id-right + /DIV id-container + /BODY + /HTML.
  1750. * If global var $delayedhtmlcontent was filled, we output it just before closing the body.
  1751. *
  1752. * @param string $comment A text to add as HTML comment into HTML generated page
  1753. * @param string $zone 'private' (for private pages) or 'public' (for public pages)
  1754. * @param int $disabledoutputofmessages Clear all messages stored into session without diplaying them
  1755. * @return void
  1756. */
  1757. function llxFooter($comment='',$zone='private', $disabledoutputofmessages=0)
  1758. {
  1759. global $conf, $langs, $user, $object;
  1760. global $delayedhtmlcontent;
  1761. global $contextpage, $page, $limit;
  1762. $ext='layout='.$conf->browser->layout.'&version='.urlencode(DOL_VERSION);
  1763. // Global html output events ($mesgs, $errors, $warnings)
  1764. dol_htmloutput_events($disabledoutputofmessages);
  1765. // Code for search criteria persistence.
  1766. // $user->lastsearch_values was set by the GETPOST when form field search_xxx exists
  1767. if (is_object($user) && ! empty($user->lastsearch_values_tmp) && is_array($user->lastsearch_values_tmp))
  1768. {
  1769. // Clean and save data
  1770. foreach($user->lastsearch_values_tmp as $key => $val)
  1771. {
  1772. unset($_SESSION['lastsearch_values_tmp_'.$key]); // Clean array to rebuild it just after
  1773. if (count($val) && empty($_POST['button_removefilter'])) // If there is search criteria to save and we did not click on 'Clear filter' button
  1774. {
  1775. if (empty($val['sortfield'])) unset($val['sortfield']);
  1776. if (empty($val['sortorder'])) unset($val['sortorder']);
  1777. dol_syslog('Save lastsearch_values_tmp_'.$key.'='.json_encode($val, 0)." (systematic recording of last search criterias)");
  1778. $_SESSION['lastsearch_values_tmp_'.$key]=json_encode($val);
  1779. unset($_SESSION['lastsearch_values_'.$key]);
  1780. }
  1781. }
  1782. }
  1783. $relativepathstring = $_SERVER["PHP_SELF"];
  1784. // Clean $relativepathstring
  1785. if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
  1786. $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
  1787. $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
  1788. if (preg_match('/list\.php$/', $relativepathstring))
  1789. {
  1790. unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]);
  1791. unset($_SESSION['lastsearch_page_tmp_'.$relativepathstring]);
  1792. unset($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]);
  1793. if (! empty($contextpage)) $_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]=$contextpage;
  1794. if (! empty($page) && $page > 1) $_SESSION['lastsearch_page_tmp_'.$relativepathstring]=$page;
  1795. if (! empty($limit) && $limit != $conf->limit) $_SESSION['lastsearch_limit_tmp_'.$relativepathstring]=$limit;
  1796. unset($_SESSION['lastsearch_contextpage_'.$relativepathstring]);
  1797. unset($_SESSION['lastsearch_page_'.$relativepathstring]);
  1798. unset($_SESSION['lastsearch_limit_'.$relativepathstring]);
  1799. }
  1800. // Core error message
  1801. if (! empty($conf->global->MAIN_CORE_ERROR))
  1802. {
  1803. // Ajax version
  1804. if ($conf->use_javascript_ajax)
  1805. {
  1806. $title = img_warning().' '.$langs->trans('CoreErrorTitle');
  1807. print ajax_dialog($title, $langs->trans('CoreErrorMessage'));
  1808. }
  1809. // html version
  1810. else
  1811. {
  1812. $msg = img_warning().' '.$langs->trans('CoreErrorMessage');
  1813. print '<div class="error">'.$msg.'</div>';
  1814. }
  1815. //define("MAIN_CORE_ERROR",0); // Constant was defined and we can't change value of a constant
  1816. }
  1817. print "\n\n";
  1818. print '</div> <!-- End div class="fiche" -->'."\n"; // End div fiche
  1819. if (empty($conf->dol_hide_leftmenu)) print '</div> <!-- End div id-right -->'."\n"; // End div id-right
  1820. if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) print '</div> <!-- End div id-container -->'."\n"; // End div container
  1821. print "\n";
  1822. if ($comment) print '<!-- '.$comment.' -->'."\n";
  1823. printCommonFooter($zone);
  1824. if (! empty($delayedhtmlcontent)) print $delayedhtmlcontent;
  1825. if (! empty($conf->use_javascript_ajax))
  1826. {
  1827. print "\n".'<!-- Includes JS Footer of Dolibarr -->'."\n";
  1828. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.($ext?'&'.$ext:'').'"></script>'."\n";
  1829. }
  1830. // Wrapper to add log when clicking on download or preview
  1831. if (! empty($conf->blockedlog->enabled) && is_object($object) && $object->id > 0 && $object->statut > 0)
  1832. {
  1833. if (in_array($object->element, array('facture'))) // Restrict for the moment to element 'facture'
  1834. {
  1835. print "\n<!-- JS CODE TO ENABLE log when making a download or a preview of a document -->\n";
  1836. ?>
  1837. <script type="text/javascript">
  1838. jQuery(document).ready(function () {
  1839. $('a.documentpreview').click(function() {
  1840. $.post('<?php echo DOL_URL_ROOT."/blockedlog/ajax/block-add.php" ?>'
  1841. , {
  1842. id:<?php echo $object->id; ?>
  1843. , element:'<?php echo $object->element ?>'
  1844. , action:'DOC_PREVIEW'
  1845. }
  1846. );
  1847. });
  1848. $('a.documentdownload').click(function() {
  1849. $.post('<?php echo DOL_URL_ROOT."/blockedlog/ajax/block-add.php" ?>'
  1850. , {
  1851. id:<?php echo $object->id; ?>
  1852. , element:'<?php echo $object->element ?>'
  1853. , action:'DOC_DOWNLOAD'
  1854. }
  1855. );
  1856. });
  1857. });
  1858. </script>
  1859. <?php
  1860. }
  1861. }
  1862. // A div for the address popup
  1863. print "\n<!-- A div to allow dialog popup -->\n";
  1864. print '<div id="dialogforpopup" style="display: none;"></div>'."\n";
  1865. print "</body>\n";
  1866. print "</html>\n";
  1867. }
  1868. }