main.inc.php 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128
  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. //var_dump(GETPOST('token').' '.$_SESSION['token'].' - '.$_SESSION['newtoken'].' '.$_SERVER['SCRIPT_FILENAME']);
  342. // Creation of a token against CSRF vulnerabilities
  343. if (! defined('NOTOKENRENEWAL'))
  344. {
  345. // Rolling token at each call ($_SESSION['token'] contains token of previous page)
  346. if (isset($_SESSION['newtoken'])) $_SESSION['token'] = $_SESSION['newtoken'];
  347. // Save in $_SESSION['newtoken'] what will be next token. Into forms, we will add param token = $_SESSION['newtoken']
  348. $token = dol_hash(uniqid(mt_rand(), true)); // Generates a hash of a random number
  349. $_SESSION['newtoken'] = $token;
  350. }
  351. //var_dump(GETPOST('token').' '.$_SESSION['token'].' - '.$_SESSION['newtoken'].' '.$_SERVER['SCRIPT_FILENAME']);
  352. // Check token
  353. if ((! defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && ! empty($conf->global->MAIN_SECURITY_CSRF_WITH_TOKEN))
  354. || 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
  355. {
  356. if ($_SERVER['REQUEST_METHOD'] == 'POST' && ! GETPOSTISSET('token')) // Note, offender can still send request by GET
  357. {
  358. print "Access by POST method refused by CSRF protection in main.inc.php. Token not provided.\n";
  359. 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 or MAIN_SECURITY_CSRF_WITH_TOKEN to 0 into setup).\n";
  360. die;
  361. }
  362. //if ($_SERVER['REQUEST_METHOD'] === 'POST') // This test must be after loading $_SESSION['token'].
  363. //{
  364. if (GETPOSTISSET('token') && GETPOST('token', 'alpha') != $_SESSION['token'])
  365. {
  366. dol_syslog("Invalid token, so we disable POST and some GET parameters - referer=".$_SERVER['HTTP_REFERER'].", action=".GETPOST('action','aZ09').", _GET|POST['token']=".GETPOST('token','alpha').", _SESSION['token']=".$_SESSION['token'], LOG_WARNING);
  367. //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.
  368. unset($_POST);
  369. unset($_GET['confirm']);
  370. }
  371. //}
  372. }
  373. // Disable modules (this must be after session_start and after conf has been loaded)
  374. if (GETPOST('disablemodules','alpha')) $_SESSION["disablemodules"]=GETPOST('disablemodules','alpha');
  375. if (! empty($_SESSION["disablemodules"]))
  376. {
  377. $disabled_modules=explode(',',$_SESSION["disablemodules"]);
  378. foreach($disabled_modules as $module)
  379. {
  380. if ($module)
  381. {
  382. if (empty($conf->$module)) $conf->$module=new stdClass();
  383. $conf->$module->enabled=false;
  384. if ($module == 'fournisseur') // Special case
  385. {
  386. $conf->supplier_order->enabled=0;
  387. $conf->supplier_invoice->enabled=0;
  388. }
  389. }
  390. }
  391. }
  392. /*
  393. * Phase authentication / login
  394. */
  395. $login='';
  396. if (! defined('NOLOGIN'))
  397. {
  398. // $authmode lists the different means of identification to be tested in order of preference.
  399. // Example: 'http', 'dolibarr', 'ldap', 'http,forceuser', '...'
  400. if (defined('MAIN_AUTHENTICATION_MODE'))
  401. {
  402. $dolibarr_main_authentication = constant('MAIN_AUTHENTICATION_MODE');
  403. }
  404. else
  405. {
  406. // Authentication mode
  407. if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='http,dolibarr';
  408. // Authentication mode: forceuser
  409. if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user='auto';
  410. }
  411. // Set authmode
  412. $authmode=explode(',',$dolibarr_main_authentication);
  413. // No authentication mode
  414. if (! count($authmode))
  415. {
  416. $langs->load('main');
  417. dol_print_error('',$langs->trans("ErrorConfigParameterNotDefined",'dolibarr_main_authentication'));
  418. exit;
  419. }
  420. // If login request was already post, we retrieve login from the session
  421. // Call module if not realized that his request.
  422. // At the end of this phase, the variable $login is defined.
  423. $resultFetchUser='';
  424. $test=true;
  425. if (! isset($_SESSION["dol_login"]))
  426. {
  427. // It is not already authenticated and it requests the login / password
  428. include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  429. $dol_dst_observed=GETPOST("dst_observed",'int',3);
  430. $dol_dst_first=GETPOST("dst_first",'int',3);
  431. $dol_dst_second=GETPOST("dst_second",'int',3);
  432. $dol_screenwidth=GETPOST("screenwidth",'int',3);
  433. $dol_screenheight=GETPOST("screenheight",'int',3);
  434. $dol_hide_topmenu=GETPOST('dol_hide_topmenu','int',3);
  435. $dol_hide_leftmenu=GETPOST('dol_hide_leftmenu','int',3);
  436. $dol_optimize_smallscreen=GETPOST('dol_optimize_smallscreen','int',3);
  437. $dol_no_mouse_hover=GETPOST('dol_no_mouse_hover','int',3);
  438. $dol_use_jmobile=GETPOST('dol_use_jmobile','int',3);
  439. //dol_syslog("POST key=".join(array_keys($_POST),',').' value='.join($_POST,','));
  440. // If in demo mode, we check we go to home page through the public/demo/index.php page
  441. if (! empty($dolibarr_main_demo) && $_SERVER['PHP_SELF'] == DOL_URL_ROOT.'/index.php') // We ask index page
  442. {
  443. if (empty($_SERVER['HTTP_REFERER']) || ! preg_match('/public/',$_SERVER['HTTP_REFERER']))
  444. {
  445. dol_syslog("Call index page from another url than demo page (call is done from page ".$_SERVER['HTTP_REFERER'].")");
  446. $url='';
  447. $url.=($url?'&':'').($dol_hide_topmenu?'dol_hide_topmenu='.$dol_hide_topmenu:'');
  448. $url.=($url?'&':'').($dol_hide_leftmenu?'dol_hide_leftmenu='.$dol_hide_leftmenu:'');
  449. $url.=($url?'&':'').($dol_optimize_smallscreen?'dol_optimize_smallscreen='.$dol_optimize_smallscreen:'');
  450. $url.=($url?'&':'').($dol_no_mouse_hover?'dol_no_mouse_hover='.$dol_no_mouse_hover:'');
  451. $url.=($url?'&':'').($dol_use_jmobile?'dol_use_jmobile='.$dol_use_jmobile:'');
  452. $url=DOL_URL_ROOT.'/public/demo/index.php'.($url?'?'.$url:'');
  453. header("Location: ".$url);
  454. exit;
  455. }
  456. }
  457. // Verification security graphic code
  458. if (GETPOST("username","alpha",2) && ! empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA))
  459. {
  460. $sessionkey = 'dol_antispam_value';
  461. $ok=(array_key_exists($sessionkey, $_SESSION) === true && (strtolower($_SESSION[$sessionkey]) == strtolower($_POST['code'])));
  462. // Check code
  463. if (! $ok)
  464. {
  465. dol_syslog('Bad value for code, connexion refused');
  466. // Load translation files required by page
  467. $langs->loadLangs(array('main', 'errors'));
  468. $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadValueForCode");
  469. $test=false;
  470. // Call trigger for the "security events" log
  471. $user->trigger_mesg='ErrorBadValueForCode - login='.GETPOST("username","alpha",2);
  472. // Call of triggers
  473. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  474. $interface=new Interfaces($db);
  475. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf);
  476. if ($result < 0) {
  477. $error++;
  478. }
  479. // End Call of triggers
  480. // Hooks on failed login
  481. $action='';
  482. $hookmanager->initHooks(array('login'));
  483. $parameters=array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  484. $reshook=$hookmanager->executeHooks('afterLoginFailed',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  485. if ($reshook < 0) $error++;
  486. // Note: exit is done later
  487. }
  488. }
  489. $allowedmethodtopostusername = 2;
  490. if (defined('MAIN_AUTHENTICATION_POST_METHOD')) $allowedmethodtopostusername = constant('MAIN_AUTHENTICATION_POST_METHOD');
  491. $usertotest = (! empty($_COOKIE['login_dolibarr']) ? $_COOKIE['login_dolibarr'] : GETPOST("username","alpha",$allowedmethodtopostusername));
  492. $passwordtotest = GETPOST('password','none',$allowedmethodtopostusername);
  493. $entitytotest = (GETPOST('entity','int') ? GETPOST('entity','int') : (!empty($conf->entity) ? $conf->entity : 1));
  494. // Define if we received data to test the login.
  495. $goontestloop=false;
  496. if (isset($_SERVER["REMOTE_USER"]) && in_array('http',$authmode)) $goontestloop=true;
  497. if ($dolibarr_main_authentication == 'forceuser' && ! empty($dolibarr_auto_user)) $goontestloop=true;
  498. if (GETPOST("username","alpha",$allowedmethodtopostusername) || ! empty($_COOKIE['login_dolibarr']) || GETPOST('openid_mode','alpha',1)) $goontestloop=true;
  499. if (! is_object($langs)) // This can occurs when calling page with NOREQUIRETRAN defined, however we need langs for error messages.
  500. {
  501. include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
  502. $langs=new Translate("",$conf);
  503. $langcode=(GETPOST('lang','aZ09',1)?GETPOST('lang','aZ09',1):(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT));
  504. if (defined('MAIN_LANG_DEFAULT')) $langcode=constant('MAIN_LANG_DEFAULT');
  505. $langs->setDefaultLang($langcode);
  506. }
  507. // Validation of login/pass/entity
  508. // If ok, the variable login will be returned
  509. // If error, we will put error message in session under the name dol_loginmesg
  510. if ($test && $goontestloop)
  511. {
  512. $login = checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmode);
  513. if ($login)
  514. {
  515. $dol_authmode=$conf->authmode; // This properties is defined only when logged, to say what mode was successfully used
  516. $dol_tz=$_POST["tz"];
  517. $dol_tz_string=$_POST["tz_string"];
  518. $dol_tz_string=preg_replace('/\s*\(.+\)$/','',$dol_tz_string);
  519. $dol_tz_string=preg_replace('/,/','/',$dol_tz_string);
  520. $dol_tz_string=preg_replace('/\s/','_',$dol_tz_string);
  521. $dol_dst=0;
  522. if (isset($_POST["dst_first"]) && isset($_POST["dst_second"]))
  523. {
  524. include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  525. $datenow=dol_now();
  526. $datefirst=dol_stringtotime($_POST["dst_first"]);
  527. $datesecond=dol_stringtotime($_POST["dst_second"]);
  528. if ($datenow >= $datefirst && $datenow < $datesecond) $dol_dst=1;
  529. }
  530. //print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst; exit;
  531. }
  532. if (! $login)
  533. {
  534. dol_syslog('Bad password, connexion refused',LOG_DEBUG);
  535. // Load translation files required by page
  536. $langs->loadLangs(array('main', 'errors'));
  537. // Bad password. No authmode has found a good password.
  538. // We set a generic message if not defined inside function checkLoginPassEntity or subfunctions
  539. if (empty($_SESSION["dol_loginmesg"])) $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword");
  540. // Call trigger for the "security events" log
  541. $user->trigger_mesg=$langs->trans("ErrorBadLoginPassword").' - login='.GETPOST("username","alpha",2);
  542. // Call of triggers
  543. include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
  544. $interface=new Interfaces($db);
  545. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf,GETPOST("username","alpha",2));
  546. if ($result < 0) {
  547. $error++;
  548. }
  549. // End Call of triggers
  550. // Hooks on failed login
  551. $action='';
  552. $hookmanager->initHooks(array('login'));
  553. $parameters=array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  554. $reshook=$hookmanager->executeHooks('afterLoginFailed',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  555. if ($reshook < 0) $error++;
  556. // Note: exit is done in next chapter
  557. }
  558. }
  559. // End test login / passwords
  560. 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.
  561. {
  562. // No data to test login, so we show the login page
  563. dol_syslog("--- Access to ".$_SERVER["PHP_SELF"]." showing the login form and exit");
  564. if (defined('NOREDIRECTBYMAINTOLOGIN')) return 'ERROR_NOT_LOGGED';
  565. else dol_loginfunction($langs,$conf,(! empty($mysoc)?$mysoc:''));
  566. exit;
  567. }
  568. $resultFetchUser=$user->fetch('', $login, '', 1, ($entitytotest > 0 ? $entitytotest : -1));
  569. if ($resultFetchUser <= 0)
  570. {
  571. dol_syslog('User not found, connexion refused');
  572. session_destroy();
  573. session_name($sessionname);
  574. session_set_cookie_params(0, '/', null, false, true); // Add tag httponly on session cookie
  575. session_start(); // Fixing the bug of register_globals here is useless since session is empty
  576. if ($resultFetchUser == 0)
  577. {
  578. // Load translation files required by page
  579. $langs->loadLangs(array('main', 'errors'));
  580. $_SESSION["dol_loginmesg"]=$langs->trans("ErrorCantLoadUserFromDolibarrDatabase",$login);
  581. $user->trigger_mesg='ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
  582. }
  583. if ($resultFetchUser < 0)
  584. {
  585. $_SESSION["dol_loginmesg"]=$user->error;
  586. $user->trigger_mesg=$user->error;
  587. }
  588. // Call triggers for the "security events" log
  589. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  590. $interface=new Interfaces($db);
  591. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf);
  592. if ($result < 0) {
  593. $error++;
  594. }
  595. // End call triggers
  596. // Hooks on failed login
  597. $action='';
  598. $hookmanager->initHooks(array('login'));
  599. $parameters=array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  600. $reshook=$hookmanager->executeHooks('afterLoginFailed',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  601. if ($reshook < 0) $error++;
  602. $paramsurl=array();
  603. if (GETPOST('textbrowser','int')) $paramsurl[]='textbrowser='.GETPOST('textbrowser','int');
  604. if (GETPOST('nojs','int')) $paramsurl[]='nojs='.GETPOST('nojs','int');
  605. if (GETPOST('lang','aZ09')) $paramsurl[]='lang='.GETPOST('lang','aZ09');
  606. header('Location: '.DOL_URL_ROOT.'/index.php'.(count($paramsurl)?'?'.implode('&',$paramsurl):''));
  607. exit;
  608. }
  609. }
  610. else
  611. {
  612. // We are already into an authenticated session
  613. $login=$_SESSION["dol_login"];
  614. $entity=$_SESSION["dol_entity"];
  615. dol_syslog("- This is an already logged session. _SESSION['dol_login']=".$login." _SESSION['dol_entity']=".$entity, LOG_DEBUG);
  616. $resultFetchUser=$user->fetch('', $login, '', 1, ($entity > 0 ? $entity : -1));
  617. if ($resultFetchUser <= 0)
  618. {
  619. // Account has been removed after login
  620. dol_syslog("Can't load user even if session logged. _SESSION['dol_login']=".$login, LOG_WARNING);
  621. session_destroy();
  622. session_name($sessionname);
  623. session_set_cookie_params(0, '/', null, false, true); // Add tag httponly on session cookie
  624. session_start(); // Fixing the bug of register_globals here is useless since session is empty
  625. if ($resultFetchUser == 0)
  626. {
  627. // Load translation files required by page
  628. $langs->loadLangs(array('main', 'errors'));
  629. $_SESSION["dol_loginmesg"]=$langs->trans("ErrorCantLoadUserFromDolibarrDatabase",$login);
  630. $user->trigger_mesg='ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
  631. }
  632. if ($resultFetchUser < 0)
  633. {
  634. $_SESSION["dol_loginmesg"]=$user->error;
  635. $user->trigger_mesg=$user->error;
  636. }
  637. // Call triggers for the "security events" log
  638. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  639. $interface=new Interfaces($db);
  640. $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf);
  641. if ($result < 0) {
  642. $error++;
  643. }
  644. // End call triggers
  645. // Hooks on failed login
  646. $action='';
  647. $hookmanager->initHooks(array('login'));
  648. $parameters=array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  649. $reshook=$hookmanager->executeHooks('afterLoginFailed',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  650. if ($reshook < 0) $error++;
  651. $paramsurl=array();
  652. if (GETPOST('textbrowser','int')) $paramsurl[]='textbrowser='.GETPOST('textbrowser','int');
  653. if (GETPOST('nojs','int')) $paramsurl[]='nojs='.GETPOST('nojs','int');
  654. if (GETPOST('lang','aZ09')) $paramsurl[]='lang='.GETPOST('lang','aZ09');
  655. header('Location: '.DOL_URL_ROOT.'/index.php'.(count($paramsurl)?'?'.implode('&',$paramsurl):''));
  656. exit;
  657. }
  658. else
  659. {
  660. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  661. $hookmanager->initHooks(array('main'));
  662. // Code for search criteria persistence.
  663. if (! empty($_GET['save_lastsearch_values'])) // We must use $_GET here
  664. {
  665. $relativepathstring = preg_replace('/\?.*$/','',$_SERVER["HTTP_REFERER"]);
  666. $relativepathstring = preg_replace('/^https?:\/\/[^\/]*/','',$relativepathstring); // Get full path except host server
  667. // Clean $relativepathstring
  668. if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
  669. $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
  670. $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
  671. //var_dump($relativepathstring);
  672. // 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
  673. if (! empty($_SESSION['lastsearch_values_tmp_'.$relativepathstring]))
  674. {
  675. $_SESSION['lastsearch_values_'.$relativepathstring]=$_SESSION['lastsearch_values_tmp_'.$relativepathstring];
  676. unset($_SESSION['lastsearch_values_tmp_'.$relativepathstring]);
  677. }
  678. if (! empty($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]))
  679. {
  680. $_SESSION['lastsearch_contextpage_'.$relativepathstring]=$_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring];
  681. unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]);
  682. }
  683. if (! empty($_SESSION['lastsearch_page_tmp_'.$relativepathstring]) && $_SESSION['lastsearch_page_tmp_'.$relativepathstring] > 1)
  684. {
  685. $_SESSION['lastsearch_page_'.$relativepathstring]=$_SESSION['lastsearch_page_tmp_'.$relativepathstring];
  686. unset($_SESSION['lastsearch_page_tmp_'.$relativepathstring]);
  687. }
  688. if (! empty($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]) && $_SESSION['lastsearch_limit_tmp_'.$relativepathstring] != $conf->liste_limit)
  689. {
  690. $_SESSION['lastsearch_limit_'.$relativepathstring]=$_SESSION['lastsearch_limit_tmp_'.$relativepathstring];
  691. unset($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]);
  692. }
  693. }
  694. $action = '';
  695. $reshook = $hookmanager->executeHooks('updateSession', array(), $user, $action);
  696. if ($reshook < 0) {
  697. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  698. }
  699. }
  700. }
  701. // Is it a new session that has started ?
  702. // If we are here, this means authentication was successfull.
  703. if (! isset($_SESSION["dol_login"]))
  704. {
  705. // New session for this login has started.
  706. $error=0;
  707. // Store value into session (values always stored)
  708. $_SESSION["dol_login"]=$user->login;
  709. $_SESSION["dol_authmode"]=isset($dol_authmode)?$dol_authmode:'';
  710. $_SESSION["dol_tz"]=isset($dol_tz)?$dol_tz:'';
  711. $_SESSION["dol_tz_string"]=isset($dol_tz_string)?$dol_tz_string:'';
  712. $_SESSION["dol_dst"]=isset($dol_dst)?$dol_dst:'';
  713. $_SESSION["dol_dst_observed"]=isset($dol_dst_observed)?$dol_dst_observed:'';
  714. $_SESSION["dol_dst_first"]=isset($dol_dst_first)?$dol_dst_first:'';
  715. $_SESSION["dol_dst_second"]=isset($dol_dst_second)?$dol_dst_second:'';
  716. $_SESSION["dol_screenwidth"]=isset($dol_screenwidth)?$dol_screenwidth:'';
  717. $_SESSION["dol_screenheight"]=isset($dol_screenheight)?$dol_screenheight:'';
  718. $_SESSION["dol_company"]=$conf->global->MAIN_INFO_SOCIETE_NOM;
  719. $_SESSION["dol_entity"]=$conf->entity;
  720. // Store value into session (values stored only if defined)
  721. if (! empty($dol_hide_topmenu)) $_SESSION['dol_hide_topmenu']=$dol_hide_topmenu;
  722. if (! empty($dol_hide_leftmenu)) $_SESSION['dol_hide_leftmenu']=$dol_hide_leftmenu;
  723. if (! empty($dol_optimize_smallscreen)) $_SESSION['dol_optimize_smallscreen']=$dol_optimize_smallscreen;
  724. if (! empty($dol_no_mouse_hover)) $_SESSION['dol_no_mouse_hover']=$dol_no_mouse_hover;
  725. if (! empty($dol_use_jmobile)) $_SESSION['dol_use_jmobile']=$dol_use_jmobile;
  726. dol_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"]." Session id=".session_id());
  727. $db->begin();
  728. $user->update_last_login_date();
  729. $loginfo = 'TZ='.$_SESSION["dol_tz"].';TZString='.$_SESSION["dol_tz_string"].';Screen='.$_SESSION["dol_screenwidth"].'x'.$_SESSION["dol_screenheight"];
  730. // Call triggers for the "security events" log
  731. $user->trigger_mesg = $loginfo;
  732. // Call triggers
  733. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  734. $interface=new Interfaces($db);
  735. $result=$interface->run_triggers('USER_LOGIN',$user,$user,$langs,$conf);
  736. if ($result < 0) {
  737. $error++;
  738. }
  739. // End call triggers
  740. // Hooks on successfull login
  741. $action='';
  742. $hookmanager->initHooks(array('login'));
  743. $parameters=array('dol_authmode'=>$dol_authmode, 'dol_loginfo'=>$loginfo);
  744. $reshook=$hookmanager->executeHooks('afterLogin',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks
  745. if ($reshook < 0) $error++;
  746. if ($error)
  747. {
  748. $db->rollback();
  749. session_destroy();
  750. dol_print_error($db,'Error in some triggers USER_LOGIN or in some hooks afterLogin');
  751. exit;
  752. }
  753. else
  754. {
  755. $db->commit();
  756. }
  757. // Change landing page if defined.
  758. $landingpage=(empty($user->conf->MAIN_LANDING_PAGE)?(empty($conf->global->MAIN_LANDING_PAGE)?'':$conf->global->MAIN_LANDING_PAGE):$user->conf->MAIN_LANDING_PAGE);
  759. if (! empty($landingpage)) // Example: /index.php
  760. {
  761. $newpath=dol_buildpath($landingpage, 1);
  762. if ($_SERVER["PHP_SELF"] != $newpath) // not already on landing page (avoid infinite loop)
  763. {
  764. header('Location: '.$newpath);
  765. exit;
  766. }
  767. }
  768. }
  769. // If user admin, we force the rights-based modules
  770. if ($user->admin)
  771. {
  772. $user->rights->user->user->lire=1;
  773. $user->rights->user->user->creer=1;
  774. $user->rights->user->user->password=1;
  775. $user->rights->user->user->supprimer=1;
  776. $user->rights->user->self->creer=1;
  777. $user->rights->user->self->password=1;
  778. }
  779. /*
  780. * Overwrite some configs globals (try to avoid this and have code to use instead $user->conf->xxx)
  781. */
  782. // Set liste_limit
  783. if (isset($user->conf->MAIN_SIZE_LISTE_LIMIT)) $conf->liste_limit = $user->conf->MAIN_SIZE_LISTE_LIMIT; // Can be 0
  784. if (isset($user->conf->PRODUIT_LIMIT_SIZE)) $conf->product->limit_size = $user->conf->PRODUIT_LIMIT_SIZE; // Can be 0
  785. // Replace conf->css by personalized value if theme not forced
  786. if (empty($conf->global->MAIN_FORCETHEME) && ! empty($user->conf->MAIN_THEME))
  787. {
  788. $conf->theme=$user->conf->MAIN_THEME;
  789. $conf->css = "/theme/".$conf->theme."/style.css.php";
  790. }
  791. }
  792. // Case forcing style from url
  793. if (GETPOST('theme','alpha'))
  794. {
  795. $conf->theme=GETPOST('theme','alpha',1);
  796. $conf->css = "/theme/".$conf->theme."/style.css.php";
  797. }
  798. // Set javascript option
  799. if (! GETPOST('nojs','int')) // If javascript was not disabled on URL
  800. {
  801. if (! empty($user->conf->MAIN_DISABLE_JAVASCRIPT))
  802. {
  803. $conf->use_javascript_ajax=! $user->conf->MAIN_DISABLE_JAVASCRIPT;
  804. }
  805. }
  806. else $conf->use_javascript_ajax=0;
  807. // Set MAIN_OPTIMIZEFORTEXTBROWSER
  808. if (GETPOST('textbrowser','int') || (! empty($conf->browser->name) && $conf->browser->name == 'lynxlinks') || ! empty($user->conf->MAIN_OPTIMIZEFORTEXTBROWSER)) // If we must enable text browser
  809. {
  810. $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER=1;
  811. }
  812. elseif (! empty($user->conf->MAIN_OPTIMIZEFORTEXTBROWSER))
  813. {
  814. $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER=$user->conf->MAIN_OPTIMIZEFORTEXTBROWSER;
  815. }
  816. // Set terminal output option according to conf->browser.
  817. if (GETPOST('dol_hide_leftmenu','int') || ! empty($_SESSION['dol_hide_leftmenu'])) $conf->dol_hide_leftmenu=1;
  818. if (GETPOST('dol_hide_topmenu','int') || ! empty($_SESSION['dol_hide_topmenu'])) $conf->dol_hide_topmenu=1;
  819. if (GETPOST('dol_optimize_smallscreen','int') || ! empty($_SESSION['dol_optimize_smallscreen'])) $conf->dol_optimize_smallscreen=1;
  820. if (GETPOST('dol_no_mouse_hover','int') || ! empty($_SESSION['dol_no_mouse_hover'])) $conf->dol_no_mouse_hover=1;
  821. if (GETPOST('dol_use_jmobile','int') || ! empty($_SESSION['dol_use_jmobile'])) $conf->dol_use_jmobile=1;
  822. if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $conf->dol_no_mouse_hover=1;
  823. if ((! empty($conf->browser->layout) && $conf->browser->layout == 'phone')
  824. || (! empty($_SESSION['dol_screenwidth']) && $_SESSION['dol_screenwidth'] < 400)
  825. || (! empty($_SESSION['dol_screenheight']) && $_SESSION['dol_screenheight'] < 400)
  826. )
  827. {
  828. $conf->dol_optimize_smallscreen=1;
  829. }
  830. // If we force to use jmobile, then we reenable javascript
  831. if (! empty($conf->dol_use_jmobile)) $conf->use_javascript_ajax=1;
  832. // Replace themes bugged with jmobile with eldy
  833. if (! empty($conf->dol_use_jmobile) && in_array($conf->theme, array('bureau2crea','cameleo','amarok')))
  834. {
  835. $conf->theme='eldy';
  836. $conf->css = "/theme/".$conf->theme."/style.css.php";
  837. }
  838. if (! defined('NOREQUIRETRAN'))
  839. {
  840. if (! GETPOST('lang','aZ09')) // If language was not forced on URL
  841. {
  842. // If user has chosen its own language
  843. if (! empty($user->conf->MAIN_LANG_DEFAULT))
  844. {
  845. // If different than current language
  846. //print ">>>".$langs->getDefaultLang()."-".$user->conf->MAIN_LANG_DEFAULT;
  847. if ($langs->getDefaultLang() != $user->conf->MAIN_LANG_DEFAULT)
  848. {
  849. $langs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT);
  850. }
  851. }
  852. }
  853. }
  854. if (! defined('NOLOGIN'))
  855. {
  856. // If the login is not recovered, it is identified with an account that does not exist.
  857. // Hacking attempt?
  858. if (! $user->login) accessforbidden();
  859. // Check if user is active
  860. if ($user->statut < 1)
  861. {
  862. // If not active, we refuse the user
  863. $langs->load("other");
  864. dol_syslog("Authentification ko as login is disabled");
  865. accessforbidden($langs->trans("ErrorLoginDisabled"));
  866. exit;
  867. }
  868. // Load permissions
  869. $user->getrights();
  870. }
  871. dol_syslog("--- Access to ".$_SERVER["PHP_SELF"].' - action='.GETPOST('action','az09').', massaction='.GETPOST('massaction','az09'));
  872. //Another call for easy debugg
  873. //dol_syslog("Access to ".$_SERVER["PHP_SELF"].' GET='.join(',',array_keys($_GET)).'->'.join(',',$_GET).' POST:'.join(',',array_keys($_POST)).'->'.join(',',$_POST));
  874. // Load main languages files
  875. if (! defined('NOREQUIRETRAN'))
  876. {
  877. // Load translation files required by page
  878. $langs->loadLangs(array('main', 'dict'));
  879. }
  880. // Define some constants used for style of arrays
  881. $bc=array(0=>'class="impair"',1=>'class="pair"');
  882. $bcdd=array(0=>'class="drag drop oddeven"',1=>'class="drag drop oddeven"');
  883. $bcnd=array(0=>'class="nodrag nodrop nohover"',1=>'class="nodrag nodrop nohoverpair"'); // Used for tr to add new lines
  884. $bctag=array(0=>'class="impair tagtr"',1=>'class="pair tagtr"');
  885. // Define messages variables
  886. $mesg=''; $warning=''; $error=0;
  887. // deprecated, see setEventMessages() and dol_htmloutput_events()
  888. $mesgs=array(); $warnings=array(); $errors=array();
  889. // Constants used to defined number of lines in textarea
  890. if (empty($conf->browser->firefox))
  891. {
  892. define('ROWS_1',1);
  893. define('ROWS_2',2);
  894. define('ROWS_3',3);
  895. define('ROWS_4',4);
  896. define('ROWS_5',5);
  897. define('ROWS_6',6);
  898. define('ROWS_7',7);
  899. define('ROWS_8',8);
  900. define('ROWS_9',9);
  901. }
  902. else
  903. {
  904. define('ROWS_1',0);
  905. define('ROWS_2',1);
  906. define('ROWS_3',2);
  907. define('ROWS_4',3);
  908. define('ROWS_5',4);
  909. define('ROWS_6',5);
  910. define('ROWS_7',6);
  911. define('ROWS_8',7);
  912. define('ROWS_9',8);
  913. }
  914. $heightforframes=50;
  915. // Init menu manager
  916. if (! defined('NOREQUIREMENU'))
  917. {
  918. if (empty($user->societe_id)) // If internal user or not defined
  919. {
  920. $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);
  921. }
  922. else // If external user
  923. {
  924. $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);
  925. }
  926. // Load the menu manager (only if not already done)
  927. $file_menu=$conf->standard_menu;
  928. if (GETPOST('menu','alpha')) $file_menu=GETPOST('menu','alpha'); // example: menu=eldy_menu.php
  929. if (! class_exists('MenuManager'))
  930. {
  931. $menufound=0;
  932. $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
  933. foreach($dirmenus as $dirmenu)
  934. {
  935. $menufound=dol_include_once($dirmenu."standard/".$file_menu);
  936. if (class_exists('MenuManager')) break;
  937. }
  938. if (! class_exists('MenuManager')) // If failed to include, we try with standard eldy_menu.php
  939. {
  940. dol_syslog("You define a menu manager '".$file_menu."' that can not be loaded.", LOG_WARNING);
  941. $file_menu='eldy_menu.php';
  942. include_once DOL_DOCUMENT_ROOT."/core/menus/standard/".$file_menu;
  943. }
  944. }
  945. $menumanager = new MenuManager($db, empty($user->societe_id)?0:1);
  946. $menumanager->loadMenu();
  947. }
  948. // Functions
  949. if (! function_exists("llxHeader"))
  950. {
  951. /**
  952. * Show HTML header HTML + BODY + Top menu + left menu + DIV
  953. *
  954. * @param string $head Optionnal head lines
  955. * @param string $title HTML title
  956. * @param string $help_url Url links to help page
  957. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  958. * For other external page: http://server/url
  959. * @param string $target Target to use on links
  960. * @param int $disablejs More content into html header
  961. * @param int $disablehead More content into html header
  962. * @param array $arrayofjs Array of complementary js files
  963. * @param array $arrayofcss Array of complementary css files
  964. * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails)
  965. * @param string $morecssonbody More CSS on body tag.
  966. * @param string $replacemainareaby Replace call to main_area() by a print of this string
  967. * @return void
  968. */
  969. function llxHeader($head = '', $title = '', $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $morecssonbody = '', $replacemainareaby = '')
  970. {
  971. global $conf;
  972. // html header
  973. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  974. print '<body id="mainbody"'.($morecssonbody?' class="'.$morecssonbody.'"':'').'>' . "\n";
  975. // top menu and left menu area
  976. if (empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu','int'))
  977. {
  978. top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring, $help_url);
  979. }
  980. if (empty($conf->dol_hide_leftmenu))
  981. {
  982. left_menu('', $help_url, '', '', 1, $title, 1); // $menumanager is retreived with a global $menumanager inside this function
  983. }
  984. // main area
  985. if ($replacemainareaby)
  986. {
  987. print $replacemainareaby;
  988. return;
  989. }
  990. main_area($title);
  991. }
  992. }
  993. /**
  994. * Show HTTP header
  995. *
  996. * @param string $contenttype Content type. For example, 'text/html'
  997. * @param int $forcenocache Force disabling of cache for the page
  998. * @return void
  999. */
  1000. function top_httphead($contenttype = 'text/html', $forcenocache = 0)
  1001. {
  1002. global $db, $conf, $hookmanager;
  1003. if ($contenttype == 'text/html' ) header("Content-Type: text/html; charset=".$conf->file->character_set_client);
  1004. else header("Content-Type: ".$contenttype);
  1005. // Security options
  1006. 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)
  1007. if (! defined('XFRAMEOPTIONS_ALLOWALL')) header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
  1008. else header("X-Frame-Options: ALLOWALL");
  1009. //header("X-XSS-Protection: 1"); // XSS protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated.
  1010. if (! defined('FORCECSP'))
  1011. {
  1012. //if (! isset($conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY))
  1013. //{
  1014. // // A default security policy that keep usage of js external component like ckeditor, stripe, google, working
  1015. // $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';";
  1016. //}
  1017. //else $contentsecuritypolicy = $conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY;
  1018. $contentsecuritypolicy = $conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY;
  1019. if (! is_object($hookmanager)) $hookmanager = new HookManager($db);
  1020. $hookmanager->initHooks("main");
  1021. $parameters=array('contentsecuritypolicy'=>$contentsecuritypolicy);
  1022. $result=$hookmanager->executeHooks('setContentSecurityPolicy',$parameters); // Note that $action and $object may have been modified by some hooks
  1023. if ($result > 0) $contentsecuritypolicy = $hookmanager->resPrint; // Replace CSP
  1024. else $contentsecuritypolicy .= $hookmanager->resPrint; // Concat CSP
  1025. if (! empty($contentsecuritypolicy))
  1026. {
  1027. // For example, to restrict 'script', 'object', 'frames' or 'img' to some domains:
  1028. // 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
  1029. // For example, to restrict everything to one domain, except 'object', ...:
  1030. // default-src https://cdn.example.net; object-src 'none'
  1031. // For example, to restrict everything to itself except img that can be on other servers:
  1032. // default-src 'self'; img-src *;
  1033. // Pre-existing site that uses too much inline code to fix but wants to ensure resources are loaded only over https and disable plugins:
  1034. // default-src http: https: 'unsafe-eval' 'unsafe-inline'; object-src 'none'
  1035. header("Content-Security-Policy: ".$contentsecuritypolicy);
  1036. }
  1037. }
  1038. elseif (constant('FORCECSP'))
  1039. {
  1040. header("Content-Security-Policy: ".constant('FORCECSP'));
  1041. }
  1042. if ($forcenocache)
  1043. {
  1044. header("Cache-Control: no-cache, no-store, must-revalidate, max-age=0");
  1045. }
  1046. }
  1047. /**
  1048. * Ouput html header of a page.
  1049. * This code is also duplicated into security2.lib.php::dol_loginfunction
  1050. *
  1051. * @param string $head Optionnal head lines
  1052. * @param string $title HTML title
  1053. * @param int $disablejs Disable js output
  1054. * @param int $disablehead Disable head output
  1055. * @param array $arrayofjs Array of complementary js files
  1056. * @param array $arrayofcss Array of complementary css files
  1057. * @param int $disablejmobile Disable jmobile (No more used)
  1058. * @param int $disablenofollow Disable no follow tag
  1059. * @return void
  1060. */
  1061. function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $disablejmobile = 0, $disablenofollow = 0)
  1062. {
  1063. global $db, $conf, $langs, $user, $hookmanager;
  1064. top_httphead();
  1065. if (empty($conf->css)) $conf->css = '/theme/eldy/style.css.php'; // If not defined, eldy by default
  1066. print '<!doctype html>'."\n";
  1067. if (! empty($conf->global->MAIN_USE_CACHE_MANIFEST)) print '<html lang="'.substr($langs->defaultlang,0,2).'" manifest="'.DOL_URL_ROOT.'/cache.manifest">'."\n";
  1068. else print '<html lang="'.substr($langs->defaultlang,0,2).'">'."\n";
  1069. //print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">'."\n";
  1070. if (empty($disablehead))
  1071. {
  1072. if (! is_object($hookmanager)) $hookmanager = new HookManager($db);
  1073. $hookmanager->initHooks("main");
  1074. $ext='layout='.$conf->browser->layout.'&version='.urlencode(DOL_VERSION);
  1075. print "<head>\n";
  1076. if (GETPOST('dol_basehref','alpha')) print '<base href="'.dol_escape_htmltag(GETPOST('dol_basehref','alpha')).'">'."\n";
  1077. // Displays meta
  1078. print '<meta charset="UTF-8">'."\n";
  1079. print '<meta name="robots" content="noindex'.($disablenofollow?'':',nofollow').'">'."\n"; // Do not index
  1080. print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n"; // Scale for mobile device
  1081. print '<meta name="author" content="Dolibarr Development Team">'."\n";
  1082. // Favicon
  1083. $favicon=dol_buildpath('/theme/'.$conf->theme.'/img/favicon.ico',1);
  1084. if (! empty($conf->global->MAIN_FAVICON_URL)) $favicon=$conf->global->MAIN_FAVICON_URL;
  1085. if (empty($conf->dol_use_jmobile)) print '<link rel="shortcut icon" type="image/x-icon" href="'.$favicon.'"/>'."\n"; // Not required into an Android webview
  1086. //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="top" title="'.$langs->trans("Home").'" href="'.(DOL_URL_ROOT?DOL_URL_ROOT:'/').'">'."\n";
  1087. //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";
  1088. //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="author" title="Dolibarr Development Team" href="https://www.dolibarr.org">'."\n";
  1089. // Auto refresh page
  1090. if (GETPOST('autorefresh','int') > 0) print '<meta http-equiv="refresh" content="'.GETPOST('autorefresh','int').'">';
  1091. // Displays title
  1092. $appli=constant('DOL_APPLICATION_TITLE');
  1093. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli=$conf->global->MAIN_APPLICATION_TITLE;
  1094. print '<title>';
  1095. $titletoshow='';
  1096. if ($title && ! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/',$conf->global->MAIN_HTML_TITLE)) $titletoshow = dol_htmlentities($title);
  1097. elseif ($title) $titletoshow = dol_htmlentities($appli.' - '.$title);
  1098. else $titletoshow = dol_htmlentities($appli);
  1099. $parameters=array('title'=>$titletoshow);
  1100. $result=$hookmanager->executeHooks('setHtmlTitle',$parameters); // Note that $action and $object may have been modified by some hooks
  1101. if ($result > 0) $titletoshow = $hookmanager->resPrint; // Replace Title to show
  1102. else $titletoshow .= $hookmanager->resPrint; // Concat to Title to show
  1103. print $titletoshow;
  1104. print '</title>';
  1105. print "\n";
  1106. if (GETPOST('version','int')) $ext='version='.GETPOST('version','int'); // usefull to force no cache on css/js
  1107. if (GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)) $ext.='&testmenuhider='.(GETPOST('testmenuhider','int')?GETPOST('testmenuhider','int'):$conf->global->MAIN_TESTMENUHIDER);
  1108. $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;
  1109. $themeparam.=($ext?'&amp;'.$ext:'');
  1110. if (! empty($_SESSION['dol_resetcache'])) $themeparam.='&amp;dol_resetcache='.$_SESSION['dol_resetcache'];
  1111. if (GETPOST('dol_hide_topmenu','int')) { $themeparam.='&amp;dol_hide_topmenu='.GETPOST('dol_hide_topmenu','int'); }
  1112. if (GETPOST('dol_hide_leftmenu','int')) { $themeparam.='&amp;dol_hide_leftmenu='.GETPOST('dol_hide_leftmenu','int'); }
  1113. if (GETPOST('dol_optimize_smallscreen','int')) { $themeparam.='&amp;dol_optimize_smallscreen='.GETPOST('dol_optimize_smallscreen','int'); }
  1114. if (GETPOST('dol_no_mouse_hover','int')) { $themeparam.='&amp;dol_no_mouse_hover='.GETPOST('dol_no_mouse_hover','int'); }
  1115. 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'); }
  1116. if (! defined('DISABLE_JQUERY') && ! $disablejs && $conf->use_javascript_ajax)
  1117. {
  1118. print '<!-- Includes CSS for JQuery (Ajax library) -->'."\n";
  1119. $jquerytheme = 'base';
  1120. if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
  1121. 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"; // Forced JQuery
  1122. else print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/css/'.$jquerytheme.'/jquery-ui.css'.($ext?'?'.$ext:'').'">'."\n"; // JQuery
  1123. 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
  1124. if (! defined('DISABLE_SELECT2') && (! empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT'))) // jQuery plugin "mutiselect", "multiple-select", "select2"...
  1125. {
  1126. $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT'):$conf->global->MAIN_USE_JQUERY_MULTISELECT;
  1127. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/'.$tmpplugin.'/dist/css/'.$tmpplugin.'.css'.($ext?'?'.$ext:'').'">'."\n";
  1128. }
  1129. }
  1130. if (! defined('DISABLE_FONT_AWSOME'))
  1131. {
  1132. print '<!-- Includes CSS for font awesome -->'."\n";
  1133. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/theme/common/fontawesome/css/font-awesome.min.css'.($ext?'?'.$ext:'').'">'."\n";
  1134. if (! empty($conf->global->MAIN_USE_FONT_AWESOME_5))
  1135. {
  1136. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/theme/common/fontawesome-5/css/all.min.css'.($ext?'?'.$ext:'').'">'."\n";
  1137. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/theme/common/fontawesome-5/css/v4-shims.min.css'.($ext?'?'.$ext:'').'">'."\n";
  1138. }
  1139. }
  1140. print '<!-- Includes CSS for Dolibarr theme -->'."\n";
  1141. // Output style sheets (optioncss='print' or ''). Note: $conf->css looks like '/theme/eldy/style.css.php'
  1142. $themepath=dol_buildpath($conf->css,1);
  1143. $themesubdir='';
  1144. if (! empty($conf->modules_parts['theme'])) // This slow down
  1145. {
  1146. foreach($conf->modules_parts['theme'] as $reldir)
  1147. {
  1148. if (file_exists(dol_buildpath($reldir.$conf->css, 0)))
  1149. {
  1150. $themepath=dol_buildpath($reldir.$conf->css, 1);
  1151. $themesubdir=$reldir;
  1152. break;
  1153. }
  1154. }
  1155. }
  1156. //print 'themepath='.$themepath.' themeparam='.$themeparam;exit;
  1157. print '<link rel="stylesheet" type="text/css" href="'.$themepath.$themeparam.'">'."\n";
  1158. 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";
  1159. // CSS forced by modules (relative url starting with /)
  1160. if (! empty($conf->modules_parts['css']))
  1161. {
  1162. $arraycss=(array) $conf->modules_parts['css'];
  1163. foreach($arraycss as $modcss => $filescss)
  1164. {
  1165. $filescss=(array) $filescss; // To be sure filecss is an array
  1166. foreach($filescss as $cssfile)
  1167. {
  1168. if (empty($cssfile)) dol_syslog("Warning: module ".$modcss." declared a css path file into its descriptor that is empty.", LOG_WARNING);
  1169. // cssfile is a relative path
  1170. print '<!-- Includes CSS added by module '.$modcss. ' -->'."\n".'<link rel="stylesheet" type="text/css" href="'.dol_buildpath($cssfile,1);
  1171. // 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.
  1172. if (!preg_match('/\.css$/i',$cssfile)) print $themeparam;
  1173. print '">'."\n";
  1174. }
  1175. }
  1176. }
  1177. // CSS forced by page in top_htmlhead call (relative url starting with /)
  1178. if (is_array($arrayofcss))
  1179. {
  1180. foreach($arrayofcss as $cssfile)
  1181. {
  1182. print '<!-- Includes CSS added by page -->'."\n".'<link rel="stylesheet" type="text/css" title="default" href="'.dol_buildpath($cssfile,1);
  1183. // 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.
  1184. if (!preg_match('/\.css$/i',$cssfile)) print $themeparam;
  1185. print '">'."\n";
  1186. }
  1187. }
  1188. // Output standard javascript links
  1189. if (! defined('DISABLE_JQUERY') && ! $disablejs && ! empty($conf->use_javascript_ajax))
  1190. {
  1191. // JQuery. Must be before other includes
  1192. print '<!-- Includes JS for JQuery -->'."\n";
  1193. if (defined('JS_JQUERY') && constant('JS_JQUERY')) print '<script src="'.JS_JQUERY.'jquery.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1194. else print '<script src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1195. if (! empty($conf->global->MAIN_FEATURES_LEVEL) && ! defined('JS_JQUERY_MIGRATE_DISABLED'))
  1196. {
  1197. if (defined('JS_JQUERY_MIGRATE') && constant('JS_JQUERY_MIGRATE')) print '<script src="'.JS_JQUERY_MIGRATE.'jquery-migrate.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1198. else print '<script src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery-migrate.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1199. }
  1200. if (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) print '<script src="'.JS_JQUERY_UI.'jquery-ui.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1201. else print '<script src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery-ui.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1202. if (! defined('DISABLE_JQUERY_TABLEDND')) print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/tablednd/jquery.tablednd.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1203. // jQuery jnotify
  1204. if (empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && ! defined('DISABLE_JQUERY_JNOTIFY'))
  1205. {
  1206. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jnotify/jquery.jnotify.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1207. }
  1208. // Flot
  1209. if (empty($conf->global->MAIN_DISABLE_JQUERY_FLOT) && ! defined('DISABLE_JQUERY_FLOT'))
  1210. {
  1211. if (constant('JS_JQUERY_FLOT'))
  1212. {
  1213. print '<script src="'.JS_JQUERY_FLOT.'jquery.flot.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1214. print '<script src="'.JS_JQUERY_FLOT.'jquery.flot.pie.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1215. print '<script src="'.JS_JQUERY_FLOT.'jquery.flot.stack.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1216. }
  1217. else
  1218. {
  1219. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/flot/jquery.flot.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1220. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/flot/jquery.flot.pie.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1221. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/flot/jquery.flot.stack.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1222. }
  1223. }
  1224. // jQuery jeditable
  1225. if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && ! defined('DISABLE_JQUERY_JEDITABLE'))
  1226. {
  1227. print '<!-- JS to manage editInPlace feature -->'."\n";
  1228. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1229. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ui-datepicker.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1230. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ui-autocomplete.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1231. print '<script>'."\n";
  1232. print 'var urlSaveInPlace = \''.DOL_URL_ROOT.'/core/ajax/saveinplace.php\';'."\n";
  1233. print 'var urlLoadInPlace = \''.DOL_URL_ROOT.'/core/ajax/loadinplace.php\';'."\n";
  1234. print 'var tooltipInPlace = \''.$langs->transnoentities('ClickToEdit').'\';'."\n"; // Added in title attribute of span
  1235. 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 ?
  1236. print 'var cancelInPlace = \''.$langs->trans('Cancel').'\';'."\n";
  1237. print 'var submitInPlace = \''.$langs->trans('Ok').'\';'."\n";
  1238. print 'var indicatorInPlace = \'<img src="'.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'">\';'."\n";
  1239. print 'var withInPlace = 300;'; // width in pixel for default string edit
  1240. print '</script>'."\n";
  1241. print '<script src="'.DOL_URL_ROOT.'/core/js/editinplace.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1242. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1243. }
  1244. // jQuery Timepicker
  1245. if (! empty($conf->global->MAIN_USE_JQUERY_TIMEPICKER) || defined('REQUIRE_JQUERY_TIMEPICKER'))
  1246. {
  1247. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/timepicker/jquery-ui-timepicker-addon.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1248. print '<script src="'.DOL_URL_ROOT.'/core/js/timepicker.js.php?lang='.$langs->defaultlang.($ext?'&amp;'.$ext:'').'"></script>'."\n";
  1249. }
  1250. if (! defined('DISABLE_SELECT2') && (! empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT'))) // jQuery plugin "mutiselect", "multiple-select", "select2", ...
  1251. {
  1252. $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT'):$conf->global->MAIN_USE_JQUERY_MULTISELECT;
  1253. print '<script 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
  1254. }
  1255. if (! defined('DISABLE_MULTISELECT')) // jQuery plugin "mutiselect" to select with checkboxes
  1256. {
  1257. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/multiselect/jquery.multi-select.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1258. }
  1259. }
  1260. if (! $disablejs && ! empty($conf->use_javascript_ajax))
  1261. {
  1262. // CKEditor
  1263. if (! empty($conf->fckeditor->enabled) && (empty($conf->global->FCKEDITOR_EDITORNAME) || $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor') && ! defined('DISABLE_CKEDITOR'))
  1264. {
  1265. print '<!-- Includes JS for CKEditor -->'."\n";
  1266. $pathckeditor = DOL_URL_ROOT . '/includes/ckeditor/ckeditor/';
  1267. $jsckeditor='ckeditor.js';
  1268. if (constant('JS_CKEDITOR')) // To use external ckeditor 4 js lib
  1269. {
  1270. $pathckeditor=constant('JS_CKEDITOR');
  1271. }
  1272. print '<script>';
  1273. print 'var CKEDITOR_BASEPATH = \''.$pathckeditor.'\';'."\n";
  1274. print 'var ckeditorConfig = \''.dol_buildpath($themesubdir.'/theme/'.$conf->theme.'/ckeditor/config.js'.($ext?'?'.$ext:''),1).'\';'."\n"; // $themesubdir='' in standard usage
  1275. print 'var ckeditorFilebrowserBrowseUrl = \''.DOL_URL_ROOT.'/core/filemanagerdol/browser/default/browser.php?Connector='.DOL_URL_ROOT.'/core/filemanagerdol/connectors/php/connector.php\';'."\n";
  1276. 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";
  1277. print '</script>'."\n";
  1278. print '<script src="'.$pathckeditor.$jsckeditor.($ext?'?'.$ext:'').'"></script>'."\n";
  1279. }
  1280. // Browser notifications
  1281. if (! defined('DISABLE_BROWSER_NOTIF'))
  1282. {
  1283. $enablebrowsernotif=false;
  1284. if (! empty($conf->agenda->enabled) && ! empty($conf->global->AGENDA_REMINDER_BROWSER)) $enablebrowsernotif=true;
  1285. if ($conf->browser->layout == 'phone') $enablebrowsernotif=false;
  1286. if ($enablebrowsernotif)
  1287. {
  1288. print '<!-- Includes JS of Dolibarr (brwoser layout = '.$conf->browser->layout.')-->'."\n";
  1289. print '<script src="'.DOL_URL_ROOT.'/core/js/lib_notification.js.php'.($ext?'?'.$ext:'').'"></script>'."\n";
  1290. }
  1291. }
  1292. // Global js function
  1293. print '<!-- Includes JS of Dolibarr -->'."\n";
  1294. print '<script src="'.DOL_URL_ROOT.'/core/js/lib_head.js.php?lang='.$langs->defaultlang.($ext?'&'.$ext:'').'"></script>'."\n";
  1295. // JS forced by modules (relative url starting with /)
  1296. if (! empty($conf->modules_parts['js'])) // $conf->modules_parts['js'] is array('module'=>array('file1','file2'))
  1297. {
  1298. $arrayjs=(array) $conf->modules_parts['js'];
  1299. foreach($arrayjs as $modjs => $filesjs)
  1300. {
  1301. $filesjs=(array) $filesjs; // To be sure filejs is an array
  1302. foreach($filesjs as $jsfile)
  1303. {
  1304. // jsfile is a relative path
  1305. print '<!-- Include JS added by module '.$modjs. '-->'."\n".'<script src="'.dol_buildpath($jsfile,1).'"></script>'."\n";
  1306. }
  1307. }
  1308. }
  1309. // JS forced by page in top_htmlhead (relative url starting with /)
  1310. if (is_array($arrayofjs))
  1311. {
  1312. print '<!-- Includes JS added by page -->'."\n";
  1313. foreach($arrayofjs as $jsfile)
  1314. {
  1315. if (preg_match('/^http/i',$jsfile))
  1316. {
  1317. print '<script src="'.$jsfile.'"></script>'."\n";
  1318. }
  1319. else
  1320. {
  1321. print '<script src="'.dol_buildpath($jsfile,1).'"></script>'."\n";
  1322. }
  1323. }
  1324. }
  1325. }
  1326. if (! empty($head)) print $head."\n";
  1327. if (! empty($conf->global->MAIN_HTML_HEADER)) print $conf->global->MAIN_HTML_HEADER."\n";
  1328. $parameters=array();
  1329. $result=$hookmanager->executeHooks('addHtmlHeader',$parameters); // Note that $action and $object may have been modified by some hooks
  1330. print $hookmanager->resPrint; // Replace Title to show
  1331. print "</head>\n\n";
  1332. }
  1333. $conf->headerdone=1; // To tell header was output
  1334. }
  1335. /**
  1336. * Show an HTML header + a BODY + The top menu bar
  1337. *
  1338. * @param string $head Lines in the HEAD
  1339. * @param string $title Title of web page
  1340. * @param string $target Target to use in menu links (Example: '' or '_top')
  1341. * @param int $disablejs Do not output links to js (Ex: qd fonction utilisee par sous formulaire Ajax)
  1342. * @param int $disablehead Do not output head section
  1343. * @param array $arrayofjs Array of js files to add in header
  1344. * @param array $arrayofcss Array of css files to add in header
  1345. * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails)
  1346. * @param string $helppagename Name of wiki page for help ('' by default).
  1347. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  1348. * For other external page: http://server/url
  1349. * @return void
  1350. */
  1351. function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $helppagename = '')
  1352. {
  1353. global $user, $conf, $langs, $db;
  1354. global $dolibarr_main_authentication, $dolibarr_main_demo;
  1355. global $hookmanager,$menumanager;
  1356. $searchform='';
  1357. $bookmarks='';
  1358. // Instantiate hooks of thirdparty module
  1359. $hookmanager->initHooks(array('toprightmenu'));
  1360. $toprightmenu='';
  1361. // For backward compatibility with old modules
  1362. if (empty($conf->headerdone))
  1363. {
  1364. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  1365. print '<body id="mainbody">';
  1366. }
  1367. /*
  1368. * Top menu
  1369. */
  1370. if ((empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu','int')) && (! defined('NOREQUIREMENU') || ! constant('NOREQUIREMENU')))
  1371. {
  1372. print "\n".'<!-- Start top horizontal -->'."\n";
  1373. 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.
  1374. // Show menu entries
  1375. print '<div id="tmenu_tooltip'.(empty($conf->global->MAIN_MENU_INVERT)?'':'invert').'" class="tmenu">'."\n";
  1376. $menumanager->atarget=$target;
  1377. $menumanager->showmenu('top', array('searchform'=>$searchform, 'bookmarks'=>$bookmarks)); // This contains a \n
  1378. print "</div>\n";
  1379. // Define link to login card
  1380. $appli=constant('DOL_APPLICATION_TITLE');
  1381. if (! empty($conf->global->MAIN_APPLICATION_TITLE))
  1382. {
  1383. $appli=$conf->global->MAIN_APPLICATION_TITLE;
  1384. if (preg_match('/\d\.\d/', $appli))
  1385. {
  1386. if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core
  1387. }
  1388. else $appli.=" ".DOL_VERSION;
  1389. }
  1390. else $appli.=" ".DOL_VERSION;
  1391. if (! empty($conf->global->MAIN_FEATURES_LEVEL)) $appli.="<br>".$langs->trans("LevelOfFeature").': '.$conf->global->MAIN_FEATURES_LEVEL;
  1392. $logouttext='';
  1393. if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  1394. {
  1395. //$logouthtmltext=$appli.'<br>';
  1396. if ($_SESSION["dol_authmode"] != 'forceuser' && $_SESSION["dol_authmode"] != 'http')
  1397. {
  1398. $logouthtmltext.=$langs->trans("Logout").'<br>';
  1399. $logouttext .='<a accesskey="l" href="'.DOL_URL_ROOT.'/user/logout.php">';
  1400. //$logouttext .= img_picto($langs->trans('Logout').":".$langs->trans('Logout'), 'logout_top.png', 'class="login"', 0, 0, 1);
  1401. $logouttext .='<span class="fa fa-sign-out atoplogin"></span>';
  1402. $logouttext .='</a>';
  1403. }
  1404. else
  1405. {
  1406. $logouthtmltext.=$langs->trans("NoLogoutProcessWithAuthMode",$_SESSION["dol_authmode"]);
  1407. $logouttext .= img_picto($langs->trans('Logout').":".$langs->trans('Logout'), 'logout_top.png', 'class="login"', 0, 0, 1);
  1408. }
  1409. }
  1410. print '<div class="login_block">'."\n";
  1411. // Add login user link
  1412. $toprightmenu.='<div class="login_block_user">';
  1413. // Login name with photo and tooltip
  1414. $mode=-1;
  1415. $toprightmenu.='<div class="inline-block nowrap"><div class="inline-block login_block_elem login_block_elem_name" style="padding: 0px;">';
  1416. $toprightmenu.=$user->getNomUrl($mode, '', 1, 0, 11, 0, ($user->firstname ? 'firstname' : -1),'atoplogin');
  1417. $toprightmenu.='</div></div>';
  1418. $toprightmenu.='</div>'."\n";
  1419. $toprightmenu.='<div class="login_block_other">';
  1420. // Execute hook printTopRightMenu (hooks should output string like '<div class="login"><a href="">mylink</a></div>')
  1421. $parameters=array();
  1422. $result=$hookmanager->executeHooks('printTopRightMenu',$parameters); // Note that $action and $object may have been modified by some hooks
  1423. if (is_numeric($result))
  1424. {
  1425. if ($result == 0)
  1426. $toprightmenu.=$hookmanager->resPrint; // add
  1427. else
  1428. $toprightmenu=$hookmanager->resPrint; // replace
  1429. }
  1430. else
  1431. {
  1432. $toprightmenu.=$result; // For backward compatibility
  1433. }
  1434. // Link to module builder
  1435. if (! empty($conf->modulebuilder->enabled))
  1436. {
  1437. $text ='<a href="'.DOL_URL_ROOT.'/modulebuilder/index.php?mainmenu=home&leftmenu=admintools" target="_modulebuilder">';
  1438. //$text.= img_picto(":".$langs->trans("ModuleBuilder"), 'printer_top.png', 'class="printer"');
  1439. $text.='<span class="fa fa-bug atoplogin"></span>';
  1440. $text.='</a>';
  1441. $toprightmenu.=@Form::textwithtooltip('',$langs->trans("ModuleBuilder"),2,1,$text,'login_block_elem',2);
  1442. }
  1443. // Link to print main content area
  1444. if (empty($conf->global->MAIN_PRINT_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $conf->browser->layout != 'phone')
  1445. {
  1446. $qs=dol_escape_htmltag($_SERVER["QUERY_STRING"]);
  1447. if (is_array($_POST))
  1448. {
  1449. foreach($_POST as $key=>$value) {
  1450. if ($key!=='action' && $key!=='password' && !is_array($value)) $qs.='&'.$key.'='.urlencode($value);
  1451. }
  1452. }
  1453. $qs.=(($qs && $morequerystring)?'&':'').$morequerystring;
  1454. $text ='<a href="'.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.$qs.($qs?'&':'').'optioncss=print" target="_blank">';
  1455. //$text.= img_picto(":".$langs->trans("PrintContentArea"), 'printer_top.png', 'class="printer"');
  1456. $text.='<span class="fa fa-print atoplogin"></span>';
  1457. $text.='</a>';
  1458. $toprightmenu.=@Form::textwithtooltip('',$langs->trans("PrintContentArea"),2,1,$text,'login_block_elem',2);
  1459. }
  1460. // Link to Dolibarr wiki pages
  1461. if (empty($conf->global->MAIN_HELP_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  1462. {
  1463. $langs->load("help");
  1464. $helpbaseurl='';
  1465. $helppage='';
  1466. $mode='';
  1467. if (empty($helppagename)) $helppagename='EN:User_documentation|FR:Documentation_utilisateur|ES:Documentación_usuarios';
  1468. // Get helpbaseurl, helppage and mode from helppagename and langs
  1469. $arrayres=getHelpParamFor($helppagename,$langs);
  1470. $helpbaseurl=$arrayres['helpbaseurl'];
  1471. $helppage=$arrayres['helppage'];
  1472. $mode=$arrayres['mode'];
  1473. // Link to help pages
  1474. if ($helpbaseurl && $helppage)
  1475. {
  1476. $text='';
  1477. if(!empty($conf->global->MAIN_SHOWDATABASENAMEINHELPPAGESLINK)) {
  1478. $langs->load('admin');
  1479. $appli .= '<br>' . $langs->trans("Database") . ': ' . $db->database_name;
  1480. }
  1481. $title=$appli.'<br>';
  1482. $title.=$langs->trans($mode == 'wiki' ? 'GoToWikiHelpPage': 'GoToHelpPage');
  1483. if ($mode == 'wiki') $title.=' - '.$langs->trans("PageWiki").' &quot;'.dol_escape_htmltag(strtr($helppage,'_',' ')).'&quot;';
  1484. $text.='<a class="help" target="_blank" rel="noopener" href="';
  1485. if ($mode == 'wiki') $text.=sprintf($helpbaseurl,urlencode(html_entity_decode($helppage)));
  1486. else $text.=sprintf($helpbaseurl,$helppage);
  1487. $text.='">';
  1488. //$text.=img_picto('', 'helpdoc_top').' ';
  1489. $text.='<span class="fa fa-question-circle atoplogin"></span>';
  1490. //$toprightmenu.=$langs->trans($mode == 'wiki' ? 'OnlineHelp': 'Help');
  1491. //if ($mode == 'wiki') $text.=' ('.dol_trunc(strtr($helppage,'_',' '),8).')';
  1492. $text.='</a>';
  1493. //$toprightmenu.='</div>'."\n";
  1494. $toprightmenu.=@Form::textwithtooltip('',$title,2,1,$text,'login_block_elem',2);
  1495. }
  1496. }
  1497. // Logout link
  1498. $toprightmenu.=@Form::textwithtooltip('',$logouthtmltext,2,1,$logouttext,'login_block_elem',2);
  1499. $toprightmenu.='</div>';
  1500. print $toprightmenu;
  1501. print "</div>\n"; // end div class="login_block"
  1502. print '</div></div>';
  1503. print '<div style="clear: both;"></div>';
  1504. print "<!-- End top horizontal menu -->\n\n";
  1505. }
  1506. 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:'').'">';
  1507. }
  1508. /**
  1509. * Show left menu bar
  1510. *
  1511. * @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 ''.
  1512. * @param string $helppagename Name of wiki page for help ('' by default).
  1513. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  1514. * For other external page: http://server/url
  1515. * @param string $notused Deprecated. Used in past to add content into left menu. Hooks can be used now.
  1516. * @param array $menu_array_after Table of menu entries to show after entries of menu handler
  1517. * @param int $leftmenuwithoutmainarea Must be set to 1. 0 by default for backward compatibility with old modules.
  1518. * @param string $title Title of web page
  1519. * @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)
  1520. * @return void
  1521. */
  1522. function left_menu($menu_array_before, $helppagename = '', $notused = '', $menu_array_after = '', $leftmenuwithoutmainarea = 0, $title = '', $acceptdelayedhtml = 0)
  1523. {
  1524. global $user, $conf, $langs, $db, $form;
  1525. global $hookmanager, $menumanager;
  1526. $searchform='';
  1527. $bookmarks='';
  1528. 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);
  1529. if (empty($conf->dol_hide_leftmenu) && (! defined('NOREQUIREMENU') || ! constant('NOREQUIREMENU')))
  1530. {
  1531. // Instantiate hooks of thirdparty module
  1532. $hookmanager->initHooks(array('searchform','leftblock'));
  1533. print "\n".'<!-- Begin side-nav id-left -->'."\n".'<div class="side-nav"><div id="id-left">'."\n";
  1534. 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 ?
  1535. print "\n";
  1536. if (! is_object($form)) $form=new Form($db);
  1537. $selected=-1;
  1538. $usedbyinclude=1;
  1539. include_once DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php'; // This set $arrayresult
  1540. if ($conf->use_javascript_ajax && empty($conf->global->MAIN_USE_OLD_SEARCH_FORM))
  1541. {
  1542. //$searchform.=$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'vmenusearchselectcombo', 1, $langs->trans("Search"), 1);
  1543. $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);
  1544. }
  1545. else
  1546. {
  1547. foreach($arrayresult as $key => $val)
  1548. {
  1549. //$searchform.=printSearchForm($val['url'], $val['url'], $val['label'], 'maxwidth100', 'sall', $val['shortcut'], 'searchleft', img_picto('',$val['img']));
  1550. $searchform.=printSearchForm($val['url'], $val['url'], $val['label'], 'maxwidth125', 'sall', $val['shortcut'], 'searchleft', img_picto('', $val['img'], '', false, 1, 1));
  1551. }
  1552. }
  1553. // Execute hook printSearchForm
  1554. $parameters=array('searchform'=>$searchform);
  1555. $reshook=$hookmanager->executeHooks('printSearchForm',$parameters); // Note that $action and $object may have been modified by some hooks
  1556. if (empty($reshook))
  1557. {
  1558. $searchform.=$hookmanager->resPrint;
  1559. }
  1560. else $searchform=$hookmanager->resPrint;
  1561. // Force special value for $searchform
  1562. if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) || empty($conf->use_javascript_ajax))
  1563. {
  1564. $urltosearch=DOL_URL_ROOT.'/core/search_page.php?showtitlebefore=1';
  1565. $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>';
  1566. }
  1567. elseif ($conf->use_javascript_ajax && ! empty($conf->global->MAIN_USE_OLD_SEARCH_FORM))
  1568. {
  1569. $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>';
  1570. $searchform.='<script>
  1571. jQuery(document).ready(function () {
  1572. jQuery("#divsearchforms1").click(function(){
  1573. jQuery("#divsearchforms2").toggle();
  1574. });
  1575. });
  1576. </script>' . "\n";
  1577. $searchform.='</div>';
  1578. }
  1579. // Define $bookmarks
  1580. if (! empty($conf->bookmark->enabled) && $user->rights->bookmark->lire)
  1581. {
  1582. include_once DOL_DOCUMENT_ROOT.'/bookmarks/bookmarks.lib.php';
  1583. $langs->load("bookmarks");
  1584. $bookmarks=printBookmarksList($db, $langs);
  1585. }
  1586. // Left column
  1587. print '<!-- Begin left menu -->'."\n";
  1588. print '<div class="vmenu"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)?'':' title="Left menu"').'>'."\n\n";
  1589. // Show left menu with other forms
  1590. $menumanager->menu_array = $menu_array_before;
  1591. $menumanager->menu_array_after = $menu_array_after;
  1592. $menumanager->showmenu('left', array('searchform'=>$searchform, 'bookmarks'=>$bookmarks)); // output menu_array and menu found in database
  1593. // Dolibarr version + help + bug report link
  1594. print "\n";
  1595. print "<!-- Begin Help Block-->\n";
  1596. print '<div id="blockvmenuhelp" class="blockvmenuhelp">'."\n";
  1597. // Version
  1598. if (empty($conf->global->MAIN_HIDE_VERSION)) // Version is already on help picto and on login page.
  1599. {
  1600. $doliurl='https://www.dolibarr.org';
  1601. //local communities
  1602. if (preg_match('/fr/i',$langs->defaultlang)) $doliurl='https://www.dolibarr.fr';
  1603. if (preg_match('/es/i',$langs->defaultlang)) $doliurl='https://www.dolibarr.es';
  1604. if (preg_match('/de/i',$langs->defaultlang)) $doliurl='https://www.dolibarr.de';
  1605. if (preg_match('/it/i',$langs->defaultlang)) $doliurl='https://www.dolibarr.it';
  1606. if (preg_match('/gr/i',$langs->defaultlang)) $doliurl='https://www.dolibarr.gr';
  1607. $appli=constant('DOL_APPLICATION_TITLE');
  1608. if (! empty($conf->global->MAIN_APPLICATION_TITLE))
  1609. {
  1610. $appli=$conf->global->MAIN_APPLICATION_TITLE; $doliurl='';
  1611. if (preg_match('/\d\.\d/', $appli))
  1612. {
  1613. if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core
  1614. }
  1615. else $appli.=" ".DOL_VERSION;
  1616. }
  1617. else $appli.=" ".DOL_VERSION;
  1618. print '<div id="blockvmenuhelpapp" class="blockvmenuhelp">';
  1619. if ($doliurl) print '<a class="help" target="_blank" rel="noopener" href="'.$doliurl.'">';
  1620. else print '<span class="help">';
  1621. print $appli;
  1622. if ($doliurl) print '</a>';
  1623. else print '</span>';
  1624. print '</div>'."\n";
  1625. }
  1626. // Link to bugtrack
  1627. if (! empty($conf->global->MAIN_BUGTRACK_ENABLELINK))
  1628. {
  1629. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1630. $bugbaseurl = 'https://github.com/Dolibarr/dolibarr/issues/new';
  1631. $bugbaseurl.= '?title=';
  1632. $bugbaseurl.= urlencode("Bug: ");
  1633. $bugbaseurl.= '&body=';
  1634. $bugbaseurl.= urlencode("# Bug\n");
  1635. $bugbaseurl.= urlencode("\n");
  1636. $bugbaseurl.= urlencode("## Environment\n");
  1637. $bugbaseurl.= urlencode("- **Version**: " . DOL_VERSION . "\n");
  1638. $bugbaseurl.= urlencode("- **OS**: " . php_uname('s') . "\n");
  1639. $bugbaseurl.= urlencode("- **Web server**: " . $_SERVER["SERVER_SOFTWARE"] . "\n");
  1640. $bugbaseurl.= urlencode("- **PHP**: " . php_sapi_name() . ' ' . phpversion() . "\n");
  1641. $bugbaseurl.= urlencode("- **Database**: " . $db::LABEL . ' ' . $db->getVersion() . "\n");
  1642. $bugbaseurl.= urlencode("- **URL**: " . $_SERVER["REQUEST_URI"] . "\n");
  1643. $bugbaseurl.= urlencode("\n");
  1644. $bugbaseurl.= urlencode("## Report\n");
  1645. print '<div id="blockvmenuhelpbugreport" class="blockvmenuhelp">';
  1646. print '<a class="help" target="_blank" rel="noopener" href="'.$bugbaseurl.'">'.$langs->trans("FindBug").'</a>';
  1647. print '</div>';
  1648. }
  1649. print "</div>\n";
  1650. print "<!-- End Help Block-->\n";
  1651. print "\n";
  1652. print "</div>\n";
  1653. print "<!-- End left menu -->\n";
  1654. print "\n";
  1655. // Execute hook printLeftBlock
  1656. $parameters=array();
  1657. $reshook=$hookmanager->executeHooks('printLeftBlock',$parameters); // Note that $action and $object may have been modified by some hooks
  1658. print $hookmanager->resPrint;
  1659. print '</div></div> <!-- End side-nav id-left -->'; // End div id="side-nav" div id="id-left"
  1660. }
  1661. print "\n";
  1662. print '<!-- Begin right area -->'."\n";
  1663. if (empty($leftmenuwithoutmainarea)) main_area($title);
  1664. }
  1665. /**
  1666. * Begin main area
  1667. *
  1668. * @param string $title Title
  1669. * @return void
  1670. */
  1671. function main_area($title = '')
  1672. {
  1673. global $conf, $langs;
  1674. if (empty($conf->dol_hide_leftmenu)) print '<div id="id-right">';
  1675. print "\n";
  1676. print '<!-- Begin div class="fiche" -->'."\n".'<div class="fiche">'."\n";
  1677. if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) print info_admin($langs->trans("WarningYouAreInMaintenanceMode",$conf->global->MAIN_ONLY_LOGIN_ALLOWED));
  1678. }
  1679. /**
  1680. * Return helpbaseurl, helppage and mode
  1681. *
  1682. * @param string $helppagename Page name ('EN:xxx,ES:eee,FR:fff...' or 'http://localpage')
  1683. * @param Translate $langs Language
  1684. * @return array Array of help urls
  1685. */
  1686. function getHelpParamFor($helppagename, $langs)
  1687. {
  1688. $helpbaseurl='';
  1689. $helppage='';
  1690. $mode='';
  1691. if (preg_match('/^http/i',$helppagename))
  1692. {
  1693. // If complete URL
  1694. $helpbaseurl='%s';
  1695. $helppage=$helppagename;
  1696. $mode='local';
  1697. }
  1698. else
  1699. {
  1700. // If WIKI URL
  1701. if (preg_match('/^es/i',$langs->defaultlang))
  1702. {
  1703. $helpbaseurl='http://wiki.dolibarr.org/index.php/%s';
  1704. if (preg_match('/ES:([^|]+)/i',$helppagename,$reg)) $helppage=$reg[1];
  1705. }
  1706. if (preg_match('/^fr/i',$langs->defaultlang))
  1707. {
  1708. $helpbaseurl='http://wiki.dolibarr.org/index.php/%s';
  1709. if (preg_match('/FR:([^|]+)/i',$helppagename,$reg)) $helppage=$reg[1];
  1710. }
  1711. if (empty($helppage)) // If help page not already found
  1712. {
  1713. $helpbaseurl='http://wiki.dolibarr.org/index.php/%s';
  1714. if (preg_match('/EN:([^|]+)/i',$helppagename,$reg)) $helppage=$reg[1];
  1715. }
  1716. $mode='wiki';
  1717. }
  1718. return array('helpbaseurl'=>$helpbaseurl,'helppage'=>$helppage,'mode'=>$mode);
  1719. }
  1720. /**
  1721. * Show a search area.
  1722. * Used when the javascript quick search is not used.
  1723. *
  1724. * @param string $urlaction Url post
  1725. * @param string $urlobject Url of the link under the search box
  1726. * @param string $title Title search area
  1727. * @param string $htmlmorecss Add more css
  1728. * @param string $htmlinputname Field Name input form
  1729. * @param string $accesskey Accesskey
  1730. * @param string $prefhtmlinputname Complement for id to avoid multiple same id in the page
  1731. * @param string $img Image to use
  1732. * @param string $showtitlebefore Show title before input text instead of into placeholder. This can be set when output is dedicated for text browsers.
  1733. * @param string $autofocus Set autofocus on field
  1734. * @return string
  1735. */
  1736. function printSearchForm($urlaction, $urlobject, $title, $htmlmorecss, $htmlinputname, $accesskey = '', $prefhtmlinputname = '', $img = '', $showtitlebefore = 0, $autofocus = 0)
  1737. {
  1738. global $conf,$langs,$user;
  1739. $ret='';
  1740. $ret.='<form action="'.$urlaction.'" method="post" class="searchform">';
  1741. $ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1742. $ret.='<input type="hidden" name="mode" value="search">';
  1743. $ret.='<input type="hidden" name="savelogin" value="'.dol_escape_htmltag($user->login).'">';
  1744. if ($showtitlebefore) $ret.=$title.' ';
  1745. $ret.='<input type="text" class="flat '.$htmlmorecss.'"';
  1746. $ret.=' style="text-indent: 22px; background-image: url(\''.$img.'\'); background-repeat: no-repeat; background-position: 3px;"';
  1747. $ret.=($accesskey?' accesskey="'.$accesskey.'"':'');
  1748. $ret.=' placeholder="'.strip_tags($title).'"';
  1749. $ret.=($autofocus?' autofocus':'');
  1750. $ret.=' name="'.$htmlinputname.'" id="'.$prefhtmlinputname.$htmlinputname.'" />';
  1751. //$ret.='<input type="submit" class="button" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px" value="'.$langs->trans("Go").'">';
  1752. $ret.='<button type="submit" class="button" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">';
  1753. $ret.='<span class="fa fa-search"></span>';
  1754. $ret.='</button>';
  1755. $ret.="</form>\n";
  1756. return $ret;
  1757. }
  1758. if (! function_exists("llxFooter"))
  1759. {
  1760. /**
  1761. * Show HTML footer
  1762. * Close div /DIV class=fiche + /DIV id-right + /DIV id-container + /BODY + /HTML.
  1763. * If global var $delayedhtmlcontent was filled, we output it just before closing the body.
  1764. *
  1765. * @param string $comment A text to add as HTML comment into HTML generated page
  1766. * @param string $zone 'private' (for private pages) or 'public' (for public pages)
  1767. * @param int $disabledoutputofmessages Clear all messages stored into session without diplaying them
  1768. * @return void
  1769. */
  1770. function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0)
  1771. {
  1772. global $conf, $langs, $user, $object;
  1773. global $delayedhtmlcontent;
  1774. global $contextpage, $page, $limit;
  1775. $ext='layout='.$conf->browser->layout.'&version='.urlencode(DOL_VERSION);
  1776. // Global html output events ($mesgs, $errors, $warnings)
  1777. dol_htmloutput_events($disabledoutputofmessages);
  1778. // Code for search criteria persistence.
  1779. // $user->lastsearch_values was set by the GETPOST when form field search_xxx exists
  1780. if (is_object($user) && ! empty($user->lastsearch_values_tmp) && is_array($user->lastsearch_values_tmp))
  1781. {
  1782. // Clean and save data
  1783. foreach($user->lastsearch_values_tmp as $key => $val)
  1784. {
  1785. unset($_SESSION['lastsearch_values_tmp_'.$key]); // Clean array to rebuild it just after
  1786. if (count($val) && empty($_POST['button_removefilter'])) // If there is search criteria to save and we did not click on 'Clear filter' button
  1787. {
  1788. if (empty($val['sortfield'])) unset($val['sortfield']);
  1789. if (empty($val['sortorder'])) unset($val['sortorder']);
  1790. dol_syslog('Save lastsearch_values_tmp_'.$key.'='.json_encode($val, 0)." (systematic recording of last search criterias)");
  1791. $_SESSION['lastsearch_values_tmp_'.$key]=json_encode($val);
  1792. unset($_SESSION['lastsearch_values_'.$key]);
  1793. }
  1794. }
  1795. }
  1796. $relativepathstring = $_SERVER["PHP_SELF"];
  1797. // Clean $relativepathstring
  1798. if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
  1799. $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
  1800. $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
  1801. if (preg_match('/list\.php$/', $relativepathstring))
  1802. {
  1803. unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]);
  1804. unset($_SESSION['lastsearch_page_tmp_'.$relativepathstring]);
  1805. unset($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]);
  1806. if (! empty($contextpage)) $_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]=$contextpage;
  1807. if (! empty($page) && $page > 1) $_SESSION['lastsearch_page_tmp_'.$relativepathstring]=$page;
  1808. if (! empty($limit) && $limit != $conf->limit) $_SESSION['lastsearch_limit_tmp_'.$relativepathstring]=$limit;
  1809. unset($_SESSION['lastsearch_contextpage_'.$relativepathstring]);
  1810. unset($_SESSION['lastsearch_page_'.$relativepathstring]);
  1811. unset($_SESSION['lastsearch_limit_'.$relativepathstring]);
  1812. }
  1813. // Core error message
  1814. if (! empty($conf->global->MAIN_CORE_ERROR))
  1815. {
  1816. // Ajax version
  1817. if ($conf->use_javascript_ajax)
  1818. {
  1819. $title = img_warning().' '.$langs->trans('CoreErrorTitle');
  1820. print ajax_dialog($title, $langs->trans('CoreErrorMessage'));
  1821. }
  1822. // html version
  1823. else
  1824. {
  1825. $msg = img_warning().' '.$langs->trans('CoreErrorMessage');
  1826. print '<div class="error">'.$msg.'</div>';
  1827. }
  1828. //define("MAIN_CORE_ERROR",0); // Constant was defined and we can't change value of a constant
  1829. }
  1830. print "\n\n";
  1831. print '</div> <!-- End div class="fiche" -->'."\n"; // End div fiche
  1832. if (empty($conf->dol_hide_leftmenu)) print '</div> <!-- End div id-right -->'."\n"; // End div id-right
  1833. if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) print '</div> <!-- End div id-container -->'."\n"; // End div container
  1834. print "\n";
  1835. if ($comment) print '<!-- '.$comment.' -->'."\n";
  1836. printCommonFooter($zone);
  1837. if (! empty($delayedhtmlcontent)) print $delayedhtmlcontent;
  1838. if (! empty($conf->use_javascript_ajax))
  1839. {
  1840. print "\n".'<!-- Includes JS Footer of Dolibarr -->'."\n";
  1841. print '<script src="'.DOL_URL_ROOT.'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.($ext?'&'.$ext:'').'"></script>'."\n";
  1842. }
  1843. // Wrapper to add log when clicking on download or preview
  1844. if (! empty($conf->blockedlog->enabled) && is_object($object) && $object->id > 0 && $object->statut > 0)
  1845. {
  1846. if (in_array($object->element, array('facture'))) // Restrict for the moment to element 'facture'
  1847. {
  1848. print "\n<!-- JS CODE TO ENABLE log when making a download or a preview of a document -->\n";
  1849. ?>
  1850. <script>
  1851. jQuery(document).ready(function () {
  1852. $('a.documentpreview').click(function() {
  1853. $.post('<?php echo DOL_URL_ROOT."/blockedlog/ajax/block-add.php" ?>'
  1854. , {
  1855. id:<?php echo $object->id; ?>
  1856. , element:'<?php echo $object->element ?>'
  1857. , action:'DOC_PREVIEW'
  1858. }
  1859. );
  1860. });
  1861. $('a.documentdownload').click(function() {
  1862. $.post('<?php echo DOL_URL_ROOT."/blockedlog/ajax/block-add.php" ?>'
  1863. , {
  1864. id:<?php echo $object->id; ?>
  1865. , element:'<?php echo $object->element ?>'
  1866. , action:'DOC_DOWNLOAD'
  1867. }
  1868. );
  1869. });
  1870. });
  1871. </script>
  1872. <?php
  1873. }
  1874. }
  1875. // A div for the address popup
  1876. print "\n<!-- A div to allow dialog popup -->\n";
  1877. print '<div id="dialogforpopup" style="display: none;"></div>'."\n";
  1878. print "</body>\n";
  1879. print "</html>\n";
  1880. }
  1881. }