main.inc.php 146 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275
  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-2021 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-2021 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. * Copyright (C) 2020 Demarest Maxime <maxime@indelog.fr>
  15. * Copyright (C) 2020 Charlene Benke <charlie@patas-monkey.com>
  16. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  17. * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 3 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  31. */
  32. /**
  33. * \file htdocs/main.inc.php
  34. * \ingroup core
  35. * \brief File that defines environment for Dolibarr GUI pages only (file not required by scripts)
  36. */
  37. //@ini_set('memory_limit', '128M'); // This may be useless if memory is hard limited by your PHP
  38. // For optional tuning. Enabled if environment variable MAIN_SHOW_TUNING_INFO is defined.
  39. $micro_start_time = 0;
  40. if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO'])) {
  41. list($usec, $sec) = explode(" ", microtime());
  42. $micro_start_time = ((float) $usec + (float) $sec);
  43. // Add Xdebug code coverage
  44. //define('XDEBUGCOVERAGE',1);
  45. if (defined('XDEBUGCOVERAGE')) {
  46. xdebug_start_code_coverage();
  47. }
  48. }
  49. /**
  50. * Return the real char for a numeric entities.
  51. * WARNING: This function is required by testSqlAndScriptInject() and the GETPOST 'restricthtml'. Regex calling must be similar.
  52. *
  53. * @param string $matches String of numeric entity
  54. * @return string New value
  55. */
  56. function realCharForNumericEntities($matches)
  57. {
  58. $newstringnumentity = preg_replace('/;$/', '', $matches[1]);
  59. //print ' $newstringnumentity='.$newstringnumentity;
  60. if (preg_match('/^x/i', $newstringnumentity)) {
  61. $newstringnumentity = hexdec(preg_replace('/^x/i', '', $newstringnumentity));
  62. }
  63. // The numeric value we don't want as entities because they encode ascii char, and why using html entities on ascii except for haking ?
  64. if (($newstringnumentity >= 65 && $newstringnumentity <= 90) || ($newstringnumentity >= 97 && $newstringnumentity <= 122)) {
  65. return chr((int) $newstringnumentity);
  66. }
  67. return '&#'.$matches[1]; // Value will be unchanged because regex was /&#( )/
  68. }
  69. /**
  70. * Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST, PHP_SELF).
  71. * Warning: Such a protection can't be enough. It is not reliable as it will always be possible to bypass this. Good protection can
  72. * only be guaranted by escaping data during output.
  73. *
  74. * @param string $val Brut value found into $_GET, $_POST or PHP_SELF
  75. * @param string $type 0=POST, 1=GET, 2=PHP_SELF, 3=GET without sql reserved keywords (the less tolerant test)
  76. * @return int >0 if there is an injection, 0 if none
  77. */
  78. function testSqlAndScriptInject($val, $type)
  79. {
  80. // Decode string first because a lot of things are obfuscated by encoding or multiple encoding.
  81. // So <svg o&#110;load='console.log(&quot;123&quot;)' become <svg onload='console.log(&quot;123&quot;)'
  82. // So "&colon;&apos;" become ":'" (due to ENT_HTML5)
  83. // Loop to decode until no more thing to decode.
  84. //print "before decoding $val\n";
  85. do {
  86. $oldval = $val;
  87. $val = html_entity_decode($val, ENT_QUOTES | ENT_HTML5);
  88. $val = preg_replace_callback('/&#(x?[0-9][0-9a-f]+)/i', 'realCharForNumericEntities', $val); // Sometimes we have entities without the ; at end so html_entity_decode does not work but entities is still interpreted by browser.
  89. } while ($oldval != $val);
  90. //print "after decoding $val\n";
  91. // We clean string because some hacks try to obfuscate evil strings by inserting non printable chars. Example: 'java(ascci09)scr(ascii00)ipt' is processed like 'javascript' (whatever is place of evil ascii char)
  92. // We should use dol_string_nounprintableascii but function is not yet loaded/available
  93. $val = preg_replace('/[\x00-\x1F\x7F]/u', '', $val); // /u operator makes UTF8 valid characters being ignored so are not included into the replace
  94. // We clean html comments because some hacks try to obfuscate evil strings by inserting HTML comments. Example: on<!-- -->error=alert(1)
  95. $val = preg_replace('/<!--[^>]*-->/', '', $val);
  96. $inj = 0;
  97. // For SQL Injection (only GET are used to scan for such injection strings)
  98. if ($type == 1 || $type == 3) {
  99. $inj += preg_match('/delete\s+from/i', $val);
  100. $inj += preg_match('/create\s+table/i', $val);
  101. $inj += preg_match('/insert\s+into/i', $val);
  102. $inj += preg_match('/select\s+from/i', $val);
  103. $inj += preg_match('/into\s+(outfile|dumpfile)/i', $val);
  104. $inj += preg_match('/user\s*\(/i', $val); // avoid to use function user() or mysql_user() that return current database login
  105. $inj += preg_match('/information_schema/i', $val); // avoid to use request that read information_schema database
  106. $inj += preg_match('/<svg/i', $val); // <svg can be allowed in POST
  107. $inj += preg_match('/update.+set.+=/i', $val);
  108. $inj += preg_match('/union.+select/i', $val);
  109. }
  110. if ($type == 3) {
  111. $inj += preg_match('/select|update|delete|truncate|replace|group\s+by|concat|count|from|union/i', $val);
  112. }
  113. if ($type != 2) { // Not common key strings, so we can check them both on GET and POST
  114. $inj += preg_match('/updatexml\(/i', $val);
  115. $inj += preg_match('/(\.\.%2f)+/i', $val);
  116. $inj += preg_match('/\s@@/', $val);
  117. }
  118. // For XSS Injection done by closing textarea to execute content into a textarea field
  119. $inj += preg_match('/<\/textarea/i', $val);
  120. // For XSS Injection done by adding javascript with script
  121. // This is all cases a browser consider text is javascript:
  122. // When it found '<script', 'javascript:', '<style', 'onload\s=' on body tag, '="&' on a tag size with old browsers
  123. // All examples on page: http://ha.ckers.org/xss.html#XSScalc
  124. // More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
  125. $inj += preg_match('/<audio/i', $val);
  126. $inj += preg_match('/<embed/i', $val);
  127. $inj += preg_match('/<iframe/i', $val);
  128. $inj += preg_match('/<object/i', $val);
  129. $inj += preg_match('/<script/i', $val);
  130. $inj += preg_match('/Set\.constructor/i', $val); // ECMA script 6
  131. if (!defined('NOSTYLECHECK')) {
  132. $inj += preg_match('/<style/i', $val);
  133. }
  134. $inj += preg_match('/base\s+href/si', $val);
  135. $inj += preg_match('/=data:/si', $val);
  136. // List of dom events is on https://www.w3schools.com/jsref/dom_obj_event.asp and https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers
  137. $inj += preg_match('/on(mouse|drag|key|load|touch|pointer|select|transition)([a-z]*)\s*=/i', $val); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)>
  138. $inj += preg_match('/on(abort|afterprint|animation|auxclick|beforeprint|beforeunload|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|copy|cut)\s*=/i', $val);
  139. $inj += preg_match('/on(dblclick|drop|durationchange|emptied|ended|error|focus|focusin|focusout|formdata|gotpointercapture|hashchange|input|invalid)\s*=/i', $val);
  140. $inj += preg_match('/on(lostpointercapture|offline|online|pagehide|pageshow)\s*=/i', $val);
  141. $inj += preg_match('/on(paste|pause|play|playing|progress|ratechange|reset|resize|scroll|search|seeked|seeking|show|stalled|start|submit|suspend)\s*=/i', $val);
  142. $inj += preg_match('/on(timeupdate|toggle|unload|volumechange|waiting|wheel)\s*=/i', $val);
  143. // We refuse html into html because some hacks try to obfuscate evil strings by inserting HTML into HTML. Example: <img on<a>error=alert(1) to bypass test on onerror
  144. $tmpval = preg_replace('/<[^<]+>/', '', $val);
  145. // List of dom events is on https://www.w3schools.com/jsref/dom_obj_event.asp and https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers
  146. $inj += preg_match('/on(mouse|drag|key|load|touch|pointer|select|transition)([a-z]*)\s*=/i', $val); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)>
  147. $inj += preg_match('/on(abort|afterprint|animation|auxclick|beforeprint|beforeunload|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|copy|cut)\s*=/i', $tmpval);
  148. $inj += preg_match('/on(dblclick|drop|durationchange|emptied|ended|error|focus|focusin|focusout|formdata|gotpointercapture|hashchange|input|invalid)\s*=/i', $tmpval);
  149. $inj += preg_match('/on(lostpointercapture|offline|online|pagehide|pageshow)\s*=/i', $tmpval);
  150. $inj += preg_match('/on(paste|pause|play|playing|progress|ratechange|reset|resize|scroll|search|seeked|seeking|show|stalled|start|submit|suspend)\s*=/i', $tmpval);
  151. $inj += preg_match('/on(timeupdate|toggle|unload|volumechange|waiting|wheel)\s*=/i', $tmpval);
  152. //$inj += preg_match('/on[A-Z][a-z]+\*=/', $val); // To lock event handlers onAbort(), ...
  153. $inj += preg_match('/&#58;|&#0000058|&#x3A/i', $val); // refused string ':' encoded (no reason to have it encoded) to lock 'javascript:...'
  154. $inj += preg_match('/javascript\s*:/i', $val);
  155. $inj += preg_match('/vbscript\s*:/i', $val);
  156. // For XSS Injection done by adding javascript closing html tags like with onmousemove, etc... (closing a src or href tag with not cleaned param)
  157. if ($type == 1) {
  158. $val = str_replace('enclosure="', 'enclosure=X', $val); // We accept enclosure=" for the export/import module
  159. $inj += preg_match('/"/i', $val); // We refused " in GET parameters value.
  160. }
  161. if ($type == 2) {
  162. $inj += preg_match('/[:;"\'<>\?\(\){}\$%]/', $val); // PHP_SELF is a file system (or url path without parameters). It can contains spaces.
  163. }
  164. return $inj;
  165. }
  166. /**
  167. * Return true if security check on parameters are OK, false otherwise.
  168. *
  169. * @param string $var Variable name
  170. * @param string $type 1=GET, 0=POST, 2=PHP_SELF
  171. * @return boolean|null true if there is no injection. Stop code if injection found.
  172. */
  173. function analyseVarsForSqlAndScriptsInjection(&$var, $type)
  174. {
  175. if (is_array($var)) {
  176. foreach ($var as $key => $value) { // Warning, $key may also be used for attacks
  177. if (analyseVarsForSqlAndScriptsInjection($key, $type) && analyseVarsForSqlAndScriptsInjection($value, $type)) {
  178. //$var[$key] = $value; // This is useless
  179. } else {
  180. // Get remote IP: PS: We do not use getRemoteIP(), function is not yet loaded and we need a value that can't be spoofed
  181. $ip = (empty($_SERVER['REMOTE_ADDR']) ? 'unknown' : $_SERVER['REMOTE_ADDR']);
  182. $errormessage = 'Access refused to '.$ip.' by SQL or Script injection protection in main.inc.php - GETPOST type='.htmlentities($type).' paramkey='.htmlentities($key).' paramvalue='.htmlentities($value).' page='.htmlentities($_SERVER["REQUEST_URI"]);
  183. print $errormessage;
  184. // Add entry into error log
  185. if (function_exists('error_log')) {
  186. error_log($errormessage);
  187. }
  188. // TODO Add entry into security audit table
  189. exit;
  190. }
  191. }
  192. return true;
  193. } else {
  194. return (testSqlAndScriptInject($var, $type) <= 0);
  195. }
  196. }
  197. // Check consistency of NOREQUIREXXX DEFINES
  198. if ((defined('NOREQUIREDB') || defined('NOREQUIRETRAN')) && !defined('NOREQUIREMENU')) {
  199. print 'If define NOREQUIREDB or NOREQUIRETRAN are set, you must also set NOREQUIREMENU or not set them.';
  200. exit;
  201. }
  202. if (defined('NOREQUIREUSER') && !defined('NOREQUIREMENU')) {
  203. print 'If define NOREQUIREUSER is set, you must also set NOREQUIREMENU or not set it.';
  204. exit;
  205. }
  206. // Sanity check on URL
  207. if (!empty($_SERVER["PHP_SELF"])) {
  208. $morevaltochecklikepost = array($_SERVER["PHP_SELF"]);
  209. analyseVarsForSqlAndScriptsInjection($morevaltochecklikepost, 2);
  210. }
  211. // Sanity check on GET parameters
  212. if (!defined('NOSCANGETFORINJECTION') && !empty($_SERVER["QUERY_STRING"])) {
  213. // Note: QUERY_STRING is url encoded, but $_GET and $_POST are already decoded
  214. // Because the analyseVarsForSqlAndScriptsInjection is designed for already url decoded value, we must decode QUERY_STRING
  215. // Another solution is to provide $_GET as parameter
  216. $morevaltochecklikeget = array(urldecode($_SERVER["QUERY_STRING"]));
  217. analyseVarsForSqlAndScriptsInjection($morevaltochecklikeget, 1);
  218. }
  219. // Sanity check on POST
  220. if (!defined('NOSCANPOSTFORINJECTION')) {
  221. analyseVarsForSqlAndScriptsInjection($_POST, 0);
  222. }
  223. // This is to make Dolibarr working with Plesk
  224. if (!empty($_SERVER['DOCUMENT_ROOT']) && substr($_SERVER['DOCUMENT_ROOT'], -6) !== 'htdocs') {
  225. set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
  226. }
  227. // Include the conf.php and functions.lib.php. This defined the constants like DOL_DOCUMENT_ROOT, DOL_DATA_ROOT, DOL_URL_ROOT...
  228. require_once 'filefunc.inc.php';
  229. // If there is a POST parameter to tell to save automatically some POST parameters into cookies, we do it.
  230. // This is used for example by form of boxes to save personalization of some options.
  231. // DOL_AUTOSET_COOKIE=cookiename:val1,val2 and cookiename_val1=aaa cookiename_val2=bbb will set cookie_name with value json_encode(array('val1'=> , ))
  232. if (!empty($_POST["DOL_AUTOSET_COOKIE"])) {
  233. $tmpautoset = explode(':', $_POST["DOL_AUTOSET_COOKIE"], 2);
  234. $tmplist = explode(',', $tmpautoset[1]);
  235. $cookiearrayvalue = array();
  236. foreach ($tmplist as $tmpkey) {
  237. $postkey = $tmpautoset[0].'_'.$tmpkey;
  238. //var_dump('tmpkey='.$tmpkey.' postkey='.$postkey.' value='.$_POST[$postkey]);
  239. if (!empty($_POST[$postkey])) {
  240. $cookiearrayvalue[$tmpkey] = $_POST[$postkey];
  241. }
  242. }
  243. $cookiename = $tmpautoset[0];
  244. $cookievalue = json_encode($cookiearrayvalue);
  245. //var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue);
  246. setcookie($cookiename, empty($cookievalue) ? '' : $cookievalue, empty($cookievalue) ? 0 : (time() + (86400 * 354)), '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // keep cookie 1 year and add tag httponly
  247. if (empty($cookievalue)) {
  248. unset($_COOKIE[$cookiename]);
  249. }
  250. }
  251. // Set the handler of session
  252. if (ini_get('session.save_handler') == 'user') {
  253. require_once 'core/lib/phpsessionindb.lib.php';
  254. }
  255. // Init session. Name of session is specific to Dolibarr instance.
  256. // Must be done after the include of filefunc.inc.php so global variables of conf file are defined (like $dolibarr_main_instance_unique_id or $dolibarr_main_force_https).
  257. // Note: the function dol_getprefix is defined into functions.lib.php but may have been defined to return a different key to manage another area to protect.
  258. $prefix = dol_getprefix('');
  259. $sessionname = 'DOLSESSID_'.$prefix;
  260. $sessiontimeout = 'DOLSESSTIMEOUT_'.$prefix;
  261. if (!empty($_COOKIE[$sessiontimeout])) {
  262. ini_set('session.gc_maxlifetime', $_COOKIE[$sessiontimeout]);
  263. }
  264. // This create lock, released by session_write_close() or end of page.
  265. // We need this lock as long as we read/write $_SESSION ['vars']. We can remove lock when finished.
  266. if (!defined('NOSESSION')) {
  267. session_set_cookie_params(0, '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Add tag secure and httponly on session cookie (same as setting session.cookie_httponly into php.ini). Must be called before the session_start.
  268. session_name($sessionname);
  269. session_start();
  270. }
  271. // Init the 5 global objects, this include will make the 'new Xxx()' and set properties for: $conf, $db, $langs, $user, $mysoc
  272. require_once 'master.inc.php';
  273. // If software has been locked. Only login $conf->global->MAIN_ONLY_LOGIN_ALLOWED is allowed.
  274. if (!empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) {
  275. $ok = 0;
  276. if ((!session_id() || !isset($_SESSION["dol_login"])) && !isset($_POST["username"]) && !empty($_SERVER["GATEWAY_INTERFACE"])) {
  277. $ok = 1; // We let working pages if not logged and inside a web browser (login form, to allow login by admin)
  278. } elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) {
  279. $ok = 1; // We let working pages that is a login submission (login submit, to allow login by admin)
  280. } elseif (defined('NOREQUIREDB')) {
  281. $ok = 1; // We let working pages that don't need database access (xxx.css.php)
  282. } elseif (defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) {
  283. $ok = 1; // We let working pages that ask to work even if only login enabled (logout.php)
  284. } elseif (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) {
  285. $ok = 1; // We let working if user is allowed admin
  286. }
  287. if (!$ok) {
  288. if (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] != $conf->global->MAIN_ONLY_LOGIN_ALLOWED) {
  289. print 'Sorry, your application is offline.'."\n";
  290. print 'You are logged with user "'.$_SESSION["dol_login"].'" and only administrator user "'.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'" is allowed to connect for the moment.'."\n";
  291. $nexturl = DOL_URL_ROOT.'/user/logout.php';
  292. print 'Please try later or <a href="'.$nexturl.'">click here to disconnect and change login user</a>...'."\n";
  293. } else {
  294. print 'Sorry, your application is offline. Only administrator user "'.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'" is allowed to connect for the moment.'."\n";
  295. $nexturl = DOL_URL_ROOT.'/';
  296. print 'Please try later or <a href="'.$nexturl.'">click here to change login user</a>...'."\n";
  297. }
  298. exit;
  299. }
  300. }
  301. // Activate end of page function
  302. register_shutdown_function('dol_shutdown');
  303. // Load debugbar
  304. if (!empty($conf->debugbar->enabled) && !GETPOST('dol_use_jmobile') && empty($_SESSION['dol_use_jmobile'])) {
  305. global $debugbar;
  306. include_once DOL_DOCUMENT_ROOT.'/debugbar/class/DebugBar.php';
  307. $debugbar = new DolibarrDebugBar();
  308. $renderer = $debugbar->getRenderer();
  309. if (empty($conf->global->MAIN_HTML_HEADER)) {
  310. $conf->global->MAIN_HTML_HEADER = '';
  311. }
  312. $conf->global->MAIN_HTML_HEADER .= $renderer->renderHead();
  313. $debugbar['time']->startMeasure('pageaftermaster', 'Page generation (after environment init)');
  314. }
  315. // Detection browser
  316. if (isset($_SERVER["HTTP_USER_AGENT"])) {
  317. $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
  318. $conf->browser->name = $tmp['browsername'];
  319. $conf->browser->os = $tmp['browseros'];
  320. $conf->browser->version = $tmp['browserversion'];
  321. $conf->browser->layout = $tmp['layout']; // 'classic', 'phone', 'tablet'
  322. //var_dump($conf->browser);
  323. if ($conf->browser->layout == 'phone') {
  324. $conf->dol_no_mouse_hover = 1;
  325. }
  326. }
  327. // Set global MAIN_OPTIMIZEFORTEXTBROWSER (must be before login part)
  328. if (GETPOST('textbrowser', 'int') || (!empty($conf->browser->name) && $conf->browser->name == 'lynxlinks')) { // If we must enable text browser
  329. $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER = 1;
  330. }
  331. // Force HTTPS if required ($conf->file->main_force_https is 0/1 or 'https dolibarr root url')
  332. // $_SERVER["HTTPS"] is 'on' when link is https, otherwise $_SERVER["HTTPS"] is empty or 'off'
  333. if (!empty($conf->file->main_force_https) && (empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on')) {
  334. $newurl = '';
  335. if (is_numeric($conf->file->main_force_https)) {
  336. if ($conf->file->main_force_https == '1' && !empty($_SERVER["SCRIPT_URI"])) { // If SCRIPT_URI supported by server
  337. if (preg_match('/^http:/i', $_SERVER["SCRIPT_URI"]) && !preg_match('/^https:/i', $_SERVER["SCRIPT_URI"])) { // If link is http
  338. $newurl = preg_replace('/^http:/i', 'https:', $_SERVER["SCRIPT_URI"]);
  339. }
  340. } else {
  341. // Check HTTPS environment variable (Apache/mod_ssl only)
  342. $newurl = preg_replace('/^http:/i', 'https:', DOL_MAIN_URL_ROOT).$_SERVER["REQUEST_URI"];
  343. }
  344. } else {
  345. // Check HTTPS environment variable (Apache/mod_ssl only)
  346. $newurl = $conf->file->main_force_https.$_SERVER["REQUEST_URI"];
  347. }
  348. // Start redirect
  349. if ($newurl) {
  350. header_remove(); // Clean header already set to be sure to remove any header like "Set-Cookie: DOLSESSID_..." from non HTTPS answers
  351. dol_syslog("main.inc: dolibarr_main_force_https is on, we make a redirect to ".$newurl);
  352. header("Location: ".$newurl);
  353. exit;
  354. } else {
  355. 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);
  356. }
  357. }
  358. if (!defined('NOLOGIN') && !defined('NOIPCHECK') && !empty($dolibarr_main_restrict_ip)) {
  359. $listofip = explode(',', $dolibarr_main_restrict_ip);
  360. $found = false;
  361. foreach ($listofip as $ip) {
  362. $ip = trim($ip);
  363. if ($ip == $_SERVER['REMOTE_ADDR']) {
  364. $found = true;
  365. break;
  366. }
  367. }
  368. if (!$found) {
  369. print 'Access refused by IP protection. Your detected IP is '.$_SERVER['REMOTE_ADDR'];
  370. exit;
  371. }
  372. }
  373. // Loading of additional presentation includes
  374. if (!defined('NOREQUIREHTML')) {
  375. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; // Need 660ko memory (800ko in 2.2)
  376. }
  377. if (!defined('NOREQUIREAJAX')) {
  378. require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; // Need 22ko memory
  379. }
  380. // If install or upgrade process not done or not completely finished, we call the install page.
  381. if (!empty($conf->global->MAIN_NOT_INSTALLED) || !empty($conf->global->MAIN_NOT_UPGRADED)) {
  382. dol_syslog("main.inc: A previous install or upgrade was not complete. Redirect to install page.", LOG_WARNING);
  383. header("Location: ".DOL_URL_ROOT."/install/index.php");
  384. exit;
  385. }
  386. // If an upgrade process is required, we call the install page.
  387. if ((!empty($conf->global->MAIN_VERSION_LAST_UPGRADE) && ($conf->global->MAIN_VERSION_LAST_UPGRADE != DOL_VERSION))
  388. || (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) && !empty($conf->global->MAIN_VERSION_LAST_INSTALL) && ($conf->global->MAIN_VERSION_LAST_INSTALL != DOL_VERSION))) {
  389. $versiontocompare = empty($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_INSTALL : $conf->global->MAIN_VERSION_LAST_UPGRADE;
  390. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  391. $dolibarrversionlastupgrade = preg_split('/[.-]/', $versiontocompare);
  392. $dolibarrversionprogram = preg_split('/[.-]/', DOL_VERSION);
  393. $rescomp = versioncompare($dolibarrversionprogram, $dolibarrversionlastupgrade);
  394. if ($rescomp > 0) { // Programs have a version higher than database. We did not add "&& $rescomp < 3" because we want upgrade process for build upgrades
  395. dol_syslog("main.inc: database version ".$versiontocompare." is lower than programs version ".DOL_VERSION.". Redirect to install page.", LOG_WARNING);
  396. header("Location: ".DOL_URL_ROOT."/install/index.php");
  397. exit;
  398. }
  399. }
  400. // Creation of a token against CSRF vulnerabilities
  401. if (!defined('NOTOKENRENEWAL')) {
  402. // No token renewal on .css.php, .js.php and .json.php
  403. if (!preg_match('/\.(css|js|json)\.php$/', $_SERVER["PHP_SELF"])) {
  404. // Rolling token at each call ($_SESSION['token'] contains token of previous page)
  405. if (isset($_SESSION['newtoken'])) {
  406. $_SESSION['token'] = $_SESSION['newtoken'];
  407. }
  408. // Save in $_SESSION['newtoken'] what will be next token. Into forms, we will add param token = $_SESSION['newtoken']
  409. $token = dol_hash(uniqid(mt_rand(), false), 'md5'); // Generates a hash of a random number. We don't need a secured hash, just a changing random value.
  410. $_SESSION['newtoken'] = $token;
  411. dol_syslog("NEW TOKEN generated by : " . $_SERVER['PHP_SELF'], LOG_DEBUG);
  412. }
  413. }
  414. //dol_syslog("aaaa - ".defined('NOCSRFCHECK')." - ".$dolibarr_nocsrfcheck." - ".$conf->global->MAIN_SECURITY_CSRF_WITH_TOKEN." - ".$_SERVER['REQUEST_METHOD']." - ".GETPOST('token', 'alpha'));
  415. // Check validity of token, only if option MAIN_SECURITY_CSRF_WITH_TOKEN enabled or if constant CSRFCHECK_WITH_TOKEN is set into page
  416. if ((!defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && !empty($conf->global->MAIN_SECURITY_CSRF_WITH_TOKEN)) || defined('CSRFCHECK_WITH_TOKEN')) {
  417. // Array of action code where CSRFCHECK with token will be forced (so token must be provided on url request)
  418. $arrayofactiontoforcetokencheck = array(
  419. 'activate', 'add', 'addrights', 'addtimespent',
  420. 'confirm_create_user', 'confirm_create_thirdparty', 'confirm_delete', 'confirm_deletedir', 'confirm_deletefile', 'confirm_purge', 'confirm_reject_check',
  421. 'delete', 'deletefilter', 'deleteoperation', 'deleteprof', 'deletepayment', 'delrights',
  422. 'disable',
  423. 'doprev', 'donext', 'dvprev', 'dvnext',
  424. 'enable',
  425. 'install',
  426. 'setpricelevel',
  427. 'update'
  428. );
  429. $sensitiveget = false;
  430. if (in_array(GETPOST('action', 'aZ09'), $arrayofactiontoforcetokencheck)) {
  431. $sensitiveget = true;
  432. }
  433. if (preg_match('/^(disable_|enable_|setremise)/', GETPOST('action', 'aZ09'))) {
  434. $sensitiveget = true;
  435. }
  436. // Check a token is provided for all cases that need a mandatory token
  437. // (all POST actions + all login, actions and mass actions on pages with CSRFCHECK_WITH_TOKEN set + all sensitive GET actions)
  438. if (
  439. $_SERVER['REQUEST_METHOD'] == 'POST' ||
  440. $sensitiveget ||
  441. ((GETPOSTISSET('actionlogin') || GETPOSTISSET('action') || GETPOSTISSET('massaction')) && defined('CSRFCHECK_WITH_TOKEN'))
  442. ) {
  443. // If token is not provided or empty, error (we are in case it is mandatory)
  444. if (!GETPOST('token', 'alpha') || GETPOST('token', 'alpha') == 'notrequired') {
  445. if (GETPOST('uploadform', 'int')) {
  446. dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"])?'':$_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"]." refused. File size too large.");
  447. $langs->loadLangs(array("errors", "install"));
  448. print $langs->trans("ErrorFileSizeTooLarge").' ';
  449. print $langs->trans("ErrorGoBackAndCorrectParameters");
  450. die;
  451. } else {
  452. dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"])?'':$_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"]." refused by CSRFCHECK_WITH_TOKEN protection. Token not provided.", LOG_WARNING);
  453. if (defined('CSRFCHECK_WITH_TOKEN')) {
  454. print "Access to a page that needs a token (constant CSRFCHECK_WITH_TOKEN is defined) is refused by CSRF protection in main.inc.php. Token not provided.\n";
  455. } else {
  456. print "Access to this page this way (POST method or GET with a sensible value for 'action' parameter) is refused by CSRF protection in main.inc.php. Token not provided.\n";
  457. print "If you access your server behind a proxy using url rewriting and the parameter is provided by caller, you might check that all HTTP header are propagated (or add the line \$dolibarr_nocsrfcheck=1 into your conf.php file or MAIN_SECURITY_CSRF_WITH_TOKEN to 0 into setup).\n";
  458. }
  459. die;
  460. }
  461. }
  462. }
  463. $sessiontokenforthisurl = (empty($_SESSION['token']) ? '' : $_SESSION['token']);
  464. // TODO Get the sessiontokenforthisurl into the array of session token
  465. if (GETPOSTISSET('token') && GETPOST('token') != 'notrequired' && GETPOST('token', 'alpha') != $sessiontokenforthisurl) {
  466. dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"])?'':$_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"]." refused due to 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);
  467. //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.
  468. setEventMessages('SecurityTokenHasExpiredSoActionHasBeenCanceledPleaseRetry', null, 'warnings');
  469. //if ($conf->global->MAIN_FEATURES_LEVEL >= 1) setEventMessages('Unset POST and GET params by CSRF protection in main.inc.php (Token provided was not generated by the previous page).'."<br>\n".'$_SERVER[REQUEST_URI] = '.$_SERVER['REQUEST_URI'].' $_SERVER[REQUEST_METHOD] = '.$_SERVER['REQUEST_METHOD'].' GETPOST(token) = '.GETPOST('token', 'alpha').' $_SESSION[token] = '.$_SESSION['token'], null, 'warnings');
  470. if (isset($_POST['id'])) $savid = ((int) $_POST['id']);
  471. unset($_POST);
  472. //unset($_POST['action']); unset($_POST['massaction']);
  473. //unset($_POST['confirm']); unset($_POST['confirmmassaction']);
  474. unset($_GET['confirm']);
  475. unset($_GET['action']);
  476. unset($_GET['confirmmassaction']);
  477. unset($_GET['massaction']);
  478. if (isset($savid)) $_POST['id'] = ((int) $savid);
  479. }
  480. // Note: There is another CSRF protection into the filefunc.inc.php
  481. }
  482. // Disable modules (this must be after session_start and after conf has been loaded)
  483. if (GETPOSTISSET('disablemodules')) {
  484. $_SESSION["disablemodules"] = GETPOST('disablemodules', 'alpha');
  485. }
  486. if (!empty($_SESSION["disablemodules"])) {
  487. $modulepartkeys = array('css', 'js', 'tabs', 'triggers', 'login', 'substitutions', 'menus', 'theme', 'sms', 'tpl', 'barcode', 'models', 'societe', 'hooks', 'dir', 'syslog', 'tpllinkable', 'contactelement', 'moduleforexternal');
  488. $disabled_modules = explode(',', $_SESSION["disablemodules"]);
  489. foreach ($disabled_modules as $module) {
  490. if ($module) {
  491. if (empty($conf->$module)) {
  492. $conf->$module = new stdClass(); // To avoid warnings
  493. }
  494. $conf->$module->enabled = false;
  495. foreach ($modulepartkeys as $modulepartkey) {
  496. unset($conf->modules_parts[$modulepartkey][$module]);
  497. }
  498. if ($module == 'fournisseur') { // Special case
  499. $conf->supplier_order->enabled = 0;
  500. $conf->supplier_invoice->enabled = 0;
  501. }
  502. }
  503. }
  504. }
  505. // Set current modulepart
  506. $modulepart = explode("/", $_SERVER["PHP_SELF"]);
  507. if (is_array($modulepart) && count($modulepart) > 0) {
  508. foreach ($conf->modules as $module) {
  509. if (in_array($module, $modulepart)) {
  510. $conf->modulepart = $module;
  511. break;
  512. }
  513. }
  514. }
  515. /*
  516. * Phase authentication / login
  517. */
  518. $login = '';
  519. if (!defined('NOLOGIN')) {
  520. // $authmode lists the different method of identification to be tested in order of preference.
  521. // Example: 'http', 'dolibarr', 'ldap', 'http,forceuser', '...'
  522. if (defined('MAIN_AUTHENTICATION_MODE')) {
  523. $dolibarr_main_authentication = constant('MAIN_AUTHENTICATION_MODE');
  524. } else {
  525. // Authentication mode
  526. if (empty($dolibarr_main_authentication)) {
  527. $dolibarr_main_authentication = 'http,dolibarr';
  528. }
  529. // Authentication mode: forceuser
  530. if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) {
  531. $dolibarr_auto_user = 'auto';
  532. }
  533. }
  534. // Set authmode
  535. $authmode = explode(',', $dolibarr_main_authentication);
  536. // No authentication mode
  537. if (!count($authmode)) {
  538. $langs->load('main');
  539. dol_print_error('', $langs->trans("ErrorConfigParameterNotDefined", 'dolibarr_main_authentication'));
  540. exit;
  541. }
  542. // If login request was already post, we retrieve login from the session
  543. // Call module if not realized that his request.
  544. // At the end of this phase, the variable $login is defined.
  545. $resultFetchUser = '';
  546. $test = true;
  547. if (!isset($_SESSION["dol_login"])) {
  548. // It is not already authenticated and it requests the login / password
  549. include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  550. $dol_dst_observed = GETPOST("dst_observed", 'int', 3);
  551. $dol_dst_first = GETPOST("dst_first", 'int', 3);
  552. $dol_dst_second = GETPOST("dst_second", 'int', 3);
  553. $dol_screenwidth = GETPOST("screenwidth", 'int', 3);
  554. $dol_screenheight = GETPOST("screenheight", 'int', 3);
  555. $dol_hide_topmenu = GETPOST('dol_hide_topmenu', 'int', 3);
  556. $dol_hide_leftmenu = GETPOST('dol_hide_leftmenu', 'int', 3);
  557. $dol_optimize_smallscreen = GETPOST('dol_optimize_smallscreen', 'int', 3);
  558. $dol_no_mouse_hover = GETPOST('dol_no_mouse_hover', 'int', 3);
  559. $dol_use_jmobile = GETPOST('dol_use_jmobile', 'int', 3); // 0=default, 1=to say we use app from a webview app, 2=to say we use app from a webview app and keep ajax
  560. //dol_syslog("POST key=".join(array_keys($_POST),',').' value='.join($_POST,','));
  561. // If in demo mode, we check we go to home page through the public/demo/index.php page
  562. if (!empty($dolibarr_main_demo) && $_SERVER['PHP_SELF'] == DOL_URL_ROOT.'/index.php') { // We ask index page
  563. if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/public/', $_SERVER['HTTP_REFERER'])) {
  564. dol_syslog("Call index page from another url than demo page (call is done from page ".$_SERVER['HTTP_REFERER'].")");
  565. $url = '';
  566. $url .= ($url ? '&' : '').($dol_hide_topmenu ? 'dol_hide_topmenu='.$dol_hide_topmenu : '');
  567. $url .= ($url ? '&' : '').($dol_hide_leftmenu ? 'dol_hide_leftmenu='.$dol_hide_leftmenu : '');
  568. $url .= ($url ? '&' : '').($dol_optimize_smallscreen ? 'dol_optimize_smallscreen='.$dol_optimize_smallscreen : '');
  569. $url .= ($url ? '&' : '').($dol_no_mouse_hover ? 'dol_no_mouse_hover='.$dol_no_mouse_hover : '');
  570. $url .= ($url ? '&' : '').($dol_use_jmobile ? 'dol_use_jmobile='.$dol_use_jmobile : '');
  571. $url = DOL_URL_ROOT.'/public/demo/index.php'.($url ? '?'.$url : '');
  572. header("Location: ".$url);
  573. exit;
  574. }
  575. }
  576. // Hooks for security access
  577. $action = '';
  578. $hookmanager->initHooks(array('login'));
  579. $parameters = array();
  580. $reshook = $hookmanager->executeHooks('beforeLoginAuthentication', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
  581. if ($reshook < 0) {
  582. $test = false;
  583. $error++;
  584. }
  585. // Verification security graphic code
  586. if ($test && GETPOST("username", "alpha", 2) && !empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA) && !isset($_SESSION['dol_bypass_antispam'])) {
  587. $sessionkey = 'dol_antispam_value';
  588. $ok = (array_key_exists($sessionkey, $_SESSION) === true && (strtolower($_SESSION[$sessionkey]) === strtolower(GETPOST('code', 'none'))));
  589. // Check code
  590. if (!$ok) {
  591. dol_syslog('Bad value for code, connexion refused');
  592. // Load translation files required by page
  593. $langs->loadLangs(array('main', 'errors'));
  594. $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadValueForCode");
  595. $test = false;
  596. // Call trigger for the "security events" log
  597. $user->trigger_mesg = 'ErrorBadValueForCode - login='.GETPOST("username", "alpha", 2);
  598. // Call trigger
  599. $result = $user->call_trigger('USER_LOGIN_FAILED', $user);
  600. if ($result < 0) {
  601. $error++;
  602. }
  603. // End call triggers
  604. // Hooks on failed login
  605. $action = '';
  606. $hookmanager->initHooks(array('login'));
  607. $parameters = array('dol_authmode'=>$authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  608. $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
  609. if ($reshook < 0) {
  610. $error++;
  611. }
  612. // Note: exit is done later
  613. }
  614. }
  615. $allowedmethodtopostusername = 2;
  616. if (defined('MAIN_AUTHENTICATION_POST_METHOD')) {
  617. $allowedmethodtopostusername = constant('MAIN_AUTHENTICATION_POST_METHOD');
  618. }
  619. $usertotest = (!empty($_COOKIE['login_dolibarr']) ? preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE['login_dolibarr']) : GETPOST("username", "alpha", $allowedmethodtopostusername));
  620. $passwordtotest = GETPOST('password', 'none', $allowedmethodtopostusername);
  621. $entitytotest = (GETPOST('entity', 'int') ? GETPOST('entity', 'int') : (!empty($conf->entity) ? $conf->entity : 1));
  622. // Define if we received data to test the login.
  623. $goontestloop = false;
  624. if (isset($_SERVER["REMOTE_USER"]) && in_array('http', $authmode)) {
  625. $goontestloop = true;
  626. }
  627. if ($dolibarr_main_authentication == 'forceuser' && !empty($dolibarr_auto_user)) {
  628. $goontestloop = true;
  629. }
  630. if (GETPOST("username", "alpha", $allowedmethodtopostusername) || !empty($_COOKIE['login_dolibarr']) || GETPOST('openid_mode', 'alpha', 1)) {
  631. $goontestloop = true;
  632. }
  633. if (!is_object($langs)) { // This can occurs when calling page with NOREQUIRETRAN defined, however we need langs for error messages.
  634. include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
  635. $langs = new Translate("", $conf);
  636. $langcode = (GETPOST('lang', 'aZ09', 1) ?GETPOST('lang', 'aZ09', 1) : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
  637. if (defined('MAIN_LANG_DEFAULT')) {
  638. $langcode = constant('MAIN_LANG_DEFAULT');
  639. }
  640. $langs->setDefaultLang($langcode);
  641. }
  642. // Validation of login/pass/entity
  643. // If ok, the variable login will be returned
  644. // If error, we will put error message in session under the name dol_loginmesg
  645. if ($test && $goontestloop && (GETPOST('actionlogin', 'aZ09') == 'login' || $dolibarr_main_authentication != 'dolibarr')) {
  646. $login = checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode);
  647. if ($login === '--bad-login-validity--') {
  648. $login = '';
  649. }
  650. if ($login) {
  651. $dol_authmode = $conf->authmode; // This properties is defined only when logged, to say what mode was successfully used
  652. $dol_tz = $_POST["tz"];
  653. $dol_tz_string = $_POST["tz_string"];
  654. $dol_tz_string = preg_replace('/\s*\(.+\)$/', '', $dol_tz_string);
  655. $dol_tz_string = preg_replace('/,/', '/', $dol_tz_string);
  656. $dol_tz_string = preg_replace('/\s/', '_', $dol_tz_string);
  657. $dol_dst = 0;
  658. // Keep $_POST here. Do not use GETPOSTISSET
  659. if (isset($_POST["dst_first"]) && isset($_POST["dst_second"])) {
  660. include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  661. $datenow = dol_now();
  662. $datefirst = dol_stringtotime($_POST["dst_first"]);
  663. $datesecond = dol_stringtotime($_POST["dst_second"]);
  664. if ($datenow >= $datefirst && $datenow < $datesecond) {
  665. $dol_dst = 1;
  666. }
  667. }
  668. //print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst; exit;
  669. }
  670. if (!$login) {
  671. dol_syslog('Bad password, connexion refused', LOG_DEBUG);
  672. // Load translation files required by page
  673. $langs->loadLangs(array('main', 'errors'));
  674. // Bad password. No authmode has found a good password.
  675. // We set a generic message if not defined inside function checkLoginPassEntity or subfunctions
  676. if (empty($_SESSION["dol_loginmesg"])) {
  677. $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadLoginPassword");
  678. }
  679. // Call trigger for the "security events" log
  680. $user->trigger_mesg = $langs->trans("ErrorBadLoginPassword").' - login='.GETPOST("username", "alpha", 2);
  681. // Call trigger
  682. $result = $user->call_trigger('USER_LOGIN_FAILED', $user);
  683. if ($result < 0) {
  684. $error++;
  685. }
  686. // End call triggers
  687. // Hooks on failed login
  688. $action = '';
  689. $hookmanager->initHooks(array('login'));
  690. $parameters = array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  691. $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
  692. if ($reshook < 0) {
  693. $error++;
  694. }
  695. // Note: exit is done in next chapter
  696. }
  697. }
  698. // End test login / passwords
  699. 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.
  700. // No data to test login, so we show the login page.
  701. dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"])?'':$_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"]." - action=".GETPOST('action', 'aZ09')." - actionlogin=".GETPOST('actionlogin', 'aZ09')." - showing the login form and exit", LOG_INFO);
  702. if (defined('NOREDIRECTBYMAINTOLOGIN')) {
  703. return 'ERROR_NOT_LOGGED';
  704. } else {
  705. if ($_SERVER["HTTP_USER_AGENT"] == 'securitytest') {
  706. http_response_code(401); // It makes easier to understand if session was broken during security tests
  707. }
  708. dol_loginfunction($langs, $conf, (!empty($mysoc) ? $mysoc : ''));
  709. }
  710. exit;
  711. }
  712. $resultFetchUser = $user->fetch('', $login, '', 1, ($entitytotest > 0 ? $entitytotest : -1)); // login was retrieved previously when checking password.
  713. if ($resultFetchUser <= 0) {
  714. dol_syslog('User not found, connexion refused');
  715. session_destroy();
  716. session_set_cookie_params(0, '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Add tag secure and httponly on session cookie
  717. session_name($sessionname);
  718. session_start();
  719. if ($resultFetchUser == 0) {
  720. // Load translation files required by page
  721. $langs->loadLangs(array('main', 'errors'));
  722. $_SESSION["dol_loginmesg"] = $langs->trans("ErrorCantLoadUserFromDolibarrDatabase", $login);
  723. $user->trigger_mesg = 'ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
  724. }
  725. if ($resultFetchUser < 0) {
  726. $_SESSION["dol_loginmesg"] = $user->error;
  727. $user->trigger_mesg = $user->error;
  728. }
  729. // Call trigger
  730. $result = $user->call_trigger('USER_LOGIN_FAILED', $user);
  731. if ($result < 0) {
  732. $error++;
  733. }
  734. // End call triggers
  735. // Hooks on failed login
  736. $action = '';
  737. $hookmanager->initHooks(array('login'));
  738. $parameters = array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  739. $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
  740. if ($reshook < 0) {
  741. $error++;
  742. }
  743. $paramsurl = array();
  744. if (GETPOST('textbrowser', 'int')) {
  745. $paramsurl[] = 'textbrowser='.GETPOST('textbrowser', 'int');
  746. }
  747. if (GETPOST('nojs', 'int')) {
  748. $paramsurl[] = 'nojs='.GETPOST('nojs', 'int');
  749. }
  750. if (GETPOST('lang', 'aZ09')) {
  751. $paramsurl[] = 'lang='.GETPOST('lang', 'aZ09');
  752. }
  753. header('Location: '.DOL_URL_ROOT.'/index.php'.(count($paramsurl) ? '?'.implode('&', $paramsurl) : ''));
  754. exit;
  755. } else {
  756. // User is loaded, we may need to change language for him according to its choice
  757. if (!empty($user->conf->MAIN_LANG_DEFAULT)) {
  758. $langs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT);
  759. }
  760. }
  761. } else {
  762. // We are already into an authenticated session
  763. $login = $_SESSION["dol_login"];
  764. $entity = isset($_SESSION["dol_entity"]) ? $_SESSION["dol_entity"] : 0;
  765. dol_syslog("- This is an already logged session. _SESSION['dol_login']=".$login." _SESSION['dol_entity']=".$entity, LOG_DEBUG);
  766. $resultFetchUser = $user->fetch('', $login, '', 1, ($entity > 0 ? $entity : -1));
  767. if ($resultFetchUser <= 0) {
  768. // Account has been removed after login
  769. dol_syslog("Can't load user even if session logged. _SESSION['dol_login']=".$login, LOG_WARNING);
  770. session_destroy();
  771. session_set_cookie_params(0, '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Add tag secure and httponly on session cookie
  772. session_name($sessionname);
  773. session_start();
  774. if ($resultFetchUser == 0) {
  775. // Load translation files required by page
  776. $langs->loadLangs(array('main', 'errors'));
  777. $_SESSION["dol_loginmesg"] = $langs->trans("ErrorCantLoadUserFromDolibarrDatabase", $login);
  778. $user->trigger_mesg = 'ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
  779. }
  780. if ($resultFetchUser < 0) {
  781. $_SESSION["dol_loginmesg"] = $user->error;
  782. $user->trigger_mesg = $user->error;
  783. }
  784. // Call trigger
  785. $result = $user->call_trigger('USER_LOGIN_FAILED', $user);
  786. if ($result < 0) {
  787. $error++;
  788. }
  789. // End call triggers
  790. // Hooks on failed login
  791. $action = '';
  792. $hookmanager->initHooks(array('login'));
  793. $parameters = array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
  794. $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
  795. if ($reshook < 0) {
  796. $error++;
  797. }
  798. $paramsurl = array();
  799. if (GETPOST('textbrowser', 'int')) {
  800. $paramsurl[] = 'textbrowser='.GETPOST('textbrowser', 'int');
  801. }
  802. if (GETPOST('nojs', 'int')) {
  803. $paramsurl[] = 'nojs='.GETPOST('nojs', 'int');
  804. }
  805. if (GETPOST('lang', 'aZ09')) {
  806. $paramsurl[] = 'lang='.GETPOST('lang', 'aZ09');
  807. }
  808. header('Location: '.DOL_URL_ROOT.'/index.php'.(count($paramsurl) ? '?'.implode('&', $paramsurl) : ''));
  809. exit;
  810. } else {
  811. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  812. $hookmanager->initHooks(array('main'));
  813. // Code for search criteria persistence.
  814. if (!empty($_GET['save_lastsearch_values'])) { // We must use $_GET here
  815. $relativepathstring = preg_replace('/\?.*$/', '', $_SERVER["HTTP_REFERER"]);
  816. $relativepathstring = preg_replace('/^https?:\/\/[^\/]*/', '', $relativepathstring); // Get full path except host server
  817. // Clean $relativepathstring
  818. if (constant('DOL_URL_ROOT')) {
  819. $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
  820. }
  821. $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
  822. $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
  823. //var_dump($relativepathstring);
  824. // 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
  825. if (!empty($_SESSION['lastsearch_values_tmp_'.$relativepathstring])) {
  826. $_SESSION['lastsearch_values_'.$relativepathstring] = $_SESSION['lastsearch_values_tmp_'.$relativepathstring];
  827. unset($_SESSION['lastsearch_values_tmp_'.$relativepathstring]);
  828. }
  829. if (!empty($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring])) {
  830. $_SESSION['lastsearch_contextpage_'.$relativepathstring] = $_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring];
  831. unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]);
  832. }
  833. if (!empty($_SESSION['lastsearch_page_tmp_'.$relativepathstring]) && $_SESSION['lastsearch_page_tmp_'.$relativepathstring] > 0) {
  834. $_SESSION['lastsearch_page_'.$relativepathstring] = $_SESSION['lastsearch_page_tmp_'.$relativepathstring];
  835. unset($_SESSION['lastsearch_page_tmp_'.$relativepathstring]);
  836. }
  837. if (!empty($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]) && $_SESSION['lastsearch_limit_tmp_'.$relativepathstring] != $conf->liste_limit) {
  838. $_SESSION['lastsearch_limit_'.$relativepathstring] = $_SESSION['lastsearch_limit_tmp_'.$relativepathstring];
  839. unset($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]);
  840. }
  841. }
  842. $action = '';
  843. $reshook = $hookmanager->executeHooks('updateSession', array(), $user, $action);
  844. if ($reshook < 0) {
  845. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  846. }
  847. }
  848. }
  849. // Is it a new session that has started ?
  850. // If we are here, this means authentication was successfull.
  851. if (!isset($_SESSION["dol_login"])) {
  852. // New session for this login has started.
  853. $error = 0;
  854. // Store value into session (values always stored)
  855. $_SESSION["dol_login"] = $user->login;
  856. $_SESSION["dol_authmode"] = isset($dol_authmode) ? $dol_authmode : '';
  857. $_SESSION["dol_tz"] = isset($dol_tz) ? $dol_tz : '';
  858. $_SESSION["dol_tz_string"] = isset($dol_tz_string) ? $dol_tz_string : '';
  859. $_SESSION["dol_dst"] = isset($dol_dst) ? $dol_dst : '';
  860. $_SESSION["dol_dst_observed"] = isset($dol_dst_observed) ? $dol_dst_observed : '';
  861. $_SESSION["dol_dst_first"] = isset($dol_dst_first) ? $dol_dst_first : '';
  862. $_SESSION["dol_dst_second"] = isset($dol_dst_second) ? $dol_dst_second : '';
  863. $_SESSION["dol_screenwidth"] = isset($dol_screenwidth) ? $dol_screenwidth : '';
  864. $_SESSION["dol_screenheight"] = isset($dol_screenheight) ? $dol_screenheight : '';
  865. $_SESSION["dol_company"] = getDolGlobalString("MAIN_INFO_SOCIETE_NOM");
  866. $_SESSION["dol_entity"] = $conf->entity;
  867. // Store value into session (values stored only if defined)
  868. if (!empty($dol_hide_topmenu)) {
  869. $_SESSION['dol_hide_topmenu'] = $dol_hide_topmenu;
  870. }
  871. if (!empty($dol_hide_leftmenu)) {
  872. $_SESSION['dol_hide_leftmenu'] = $dol_hide_leftmenu;
  873. }
  874. if (!empty($dol_optimize_smallscreen)) {
  875. $_SESSION['dol_optimize_smallscreen'] = $dol_optimize_smallscreen;
  876. }
  877. if (!empty($dol_no_mouse_hover)) {
  878. $_SESSION['dol_no_mouse_hover'] = $dol_no_mouse_hover;
  879. }
  880. if (!empty($dol_use_jmobile)) {
  881. $_SESSION['dol_use_jmobile'] = $dol_use_jmobile;
  882. }
  883. dol_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"]." Session id=".session_id());
  884. $db->begin();
  885. $user->update_last_login_date();
  886. $loginfo = 'TZ='.$_SESSION["dol_tz"].';TZString='.$_SESSION["dol_tz_string"].';Screen='.$_SESSION["dol_screenwidth"].'x'.$_SESSION["dol_screenheight"];
  887. // Call triggers for the "security events" log
  888. $user->trigger_mesg = $loginfo;
  889. // Call trigger
  890. $result = $user->call_trigger('USER_LOGIN', $user);
  891. if ($result < 0) {
  892. $error++;
  893. }
  894. // End call triggers
  895. // Hooks on successfull login
  896. $action = '';
  897. $hookmanager->initHooks(array('login'));
  898. $parameters = array('dol_authmode'=>$dol_authmode, 'dol_loginfo'=>$loginfo);
  899. $reshook = $hookmanager->executeHooks('afterLogin', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
  900. if ($reshook < 0) {
  901. $error++;
  902. }
  903. if ($error) {
  904. $db->rollback();
  905. session_destroy();
  906. dol_print_error($db, 'Error in some triggers USER_LOGIN or in some hooks afterLogin');
  907. exit;
  908. } else {
  909. $db->commit();
  910. }
  911. // Change landing page if defined.
  912. $landingpage = (empty($user->conf->MAIN_LANDING_PAGE) ? (empty($conf->global->MAIN_LANDING_PAGE) ? '' : $conf->global->MAIN_LANDING_PAGE) : $user->conf->MAIN_LANDING_PAGE);
  913. if (!empty($landingpage)) { // Example: /index.php
  914. $newpath = dol_buildpath($landingpage, 1);
  915. if ($_SERVER["PHP_SELF"] != $newpath) { // not already on landing page (avoid infinite loop)
  916. header('Location: '.$newpath);
  917. exit;
  918. }
  919. }
  920. }
  921. // If user admin, we force the rights-based modules
  922. if ($user->admin) {
  923. $user->rights->user->user->lire = 1;
  924. $user->rights->user->user->creer = 1;
  925. $user->rights->user->user->password = 1;
  926. $user->rights->user->user->supprimer = 1;
  927. $user->rights->user->self->creer = 1;
  928. $user->rights->user->self->password = 1;
  929. }
  930. /*
  931. * Overwrite some configs globals (try to avoid this and have code to use instead $user->conf->xxx)
  932. */
  933. // Set liste_limit
  934. if (isset($user->conf->MAIN_SIZE_LISTE_LIMIT)) {
  935. $conf->liste_limit = $user->conf->MAIN_SIZE_LISTE_LIMIT; // Can be 0
  936. }
  937. if (isset($user->conf->PRODUIT_LIMIT_SIZE)) {
  938. $conf->product->limit_size = $user->conf->PRODUIT_LIMIT_SIZE; // Can be 0
  939. }
  940. // Replace conf->css by personalized value if theme not forced
  941. if (empty($conf->global->MAIN_FORCETHEME) && !empty($user->conf->MAIN_THEME)) {
  942. $conf->theme = $user->conf->MAIN_THEME;
  943. $conf->css = "/theme/".$conf->theme."/style.css.php";
  944. }
  945. }
  946. // Case forcing style from url
  947. if (GETPOST('theme', 'alpha')) {
  948. $conf->theme = GETPOST('theme', 'alpha', 1);
  949. $conf->css = "/theme/".$conf->theme."/style.css.php";
  950. }
  951. // Set javascript option
  952. if (GETPOST('nojs', 'int')) { // If javascript was not disabled on URL
  953. $conf->use_javascript_ajax = 0;
  954. } else {
  955. if (!empty($user->conf->MAIN_DISABLE_JAVASCRIPT)) {
  956. $conf->use_javascript_ajax = !$user->conf->MAIN_DISABLE_JAVASCRIPT;
  957. }
  958. }
  959. // Set MAIN_OPTIMIZEFORTEXTBROWSER for user (must be after login part)
  960. if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && !empty($user->conf->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  961. $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER = $user->conf->MAIN_OPTIMIZEFORTEXTBROWSER;
  962. }
  963. // set MAIN_OPTIMIZEFORCOLORBLIND for user
  964. $conf->global->MAIN_OPTIMIZEFORCOLORBLIND = empty($user->conf->MAIN_OPTIMIZEFORCOLORBLIND) ? '' : $user->conf->MAIN_OPTIMIZEFORCOLORBLIND;
  965. // Set terminal output option according to conf->browser.
  966. if (GETPOST('dol_hide_leftmenu', 'int') || !empty($_SESSION['dol_hide_leftmenu'])) {
  967. $conf->dol_hide_leftmenu = 1;
  968. }
  969. if (GETPOST('dol_hide_topmenu', 'int') || !empty($_SESSION['dol_hide_topmenu'])) {
  970. $conf->dol_hide_topmenu = 1;
  971. }
  972. if (GETPOST('dol_optimize_smallscreen', 'int') || !empty($_SESSION['dol_optimize_smallscreen'])) {
  973. $conf->dol_optimize_smallscreen = 1;
  974. }
  975. if (GETPOST('dol_no_mouse_hover', 'int') || !empty($_SESSION['dol_no_mouse_hover'])) {
  976. $conf->dol_no_mouse_hover = 1;
  977. }
  978. if (GETPOST('dol_use_jmobile', 'int') || !empty($_SESSION['dol_use_jmobile'])) {
  979. $conf->dol_use_jmobile = 1;
  980. }
  981. if (!empty($conf->browser->layout) && $conf->browser->layout != 'classic') {
  982. $conf->dol_no_mouse_hover = 1;
  983. }
  984. if ((!empty($conf->browser->layout) && $conf->browser->layout == 'phone')
  985. || (!empty($_SESSION['dol_screenwidth']) && $_SESSION['dol_screenwidth'] < 400)
  986. || (!empty($_SESSION['dol_screenheight']) && $_SESSION['dol_screenheight'] < 400)
  987. ) {
  988. $conf->dol_optimize_smallscreen = 1;
  989. }
  990. // Replace themes bugged with jmobile with eldy
  991. if (!empty($conf->dol_use_jmobile) && in_array($conf->theme, array('bureau2crea', 'cameleo', 'amarok'))) {
  992. $conf->theme = 'eldy';
  993. $conf->css = "/theme/".$conf->theme."/style.css.php";
  994. }
  995. if (!defined('NOREQUIRETRAN')) {
  996. if (!GETPOST('lang', 'aZ09')) { // If language was not forced on URL
  997. // If user has chosen its own language
  998. if (!empty($user->conf->MAIN_LANG_DEFAULT)) {
  999. // If different than current language
  1000. //print ">>>".$langs->getDefaultLang()."-".$user->conf->MAIN_LANG_DEFAULT;
  1001. if ($langs->getDefaultLang() != $user->conf->MAIN_LANG_DEFAULT) {
  1002. $langs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT);
  1003. }
  1004. }
  1005. }
  1006. }
  1007. if (!defined('NOLOGIN')) {
  1008. // If the login is not recovered, it is identified with an account that does not exist.
  1009. // Hacking attempt?
  1010. if (!$user->login) {
  1011. accessforbidden();
  1012. }
  1013. // Check if user is active
  1014. if ($user->statut < 1) {
  1015. // If not active, we refuse the user
  1016. $langs->load("other");
  1017. dol_syslog("Authentication KO as login is disabled", LOG_NOTICE);
  1018. accessforbidden($langs->trans("ErrorLoginDisabled"));
  1019. exit;
  1020. }
  1021. // Load permissions
  1022. $user->getrights();
  1023. }
  1024. dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"])?'':$_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"].' - action='.GETPOST('action', 'aZ09').', massaction='.GETPOST('massaction', 'aZ09').(defined('NOTOKENRENEWAL') ? ' NOTOKENRENEWAL='.constant('NOTOKENRENEWAL') : ''), LOG_NOTICE);
  1025. //Another call for easy debugg
  1026. //dol_syslog("Access to ".$_SERVER["PHP_SELF"].' '.$_SERVER["HTTP_REFERER"].' GET='.join(',',array_keys($_GET)).'->'.join(',',$_GET).' POST:'.join(',',array_keys($_POST)).'->'.join(',',$_POST));
  1027. // Load main languages files
  1028. if (!defined('NOREQUIRETRAN')) {
  1029. // Load translation files required by page
  1030. $langs->loadLangs(array('main', 'dict'));
  1031. }
  1032. // Define some constants used for style of arrays
  1033. $bc = array(0=>'class="impair"', 1=>'class="pair"');
  1034. $bcdd = array(0=>'class="drag drop oddeven"', 1=>'class="drag drop oddeven"');
  1035. $bcnd = array(0=>'class="nodrag nodrop nohover"', 1=>'class="nodrag nodrop nohoverpair"'); // Used for tr to add new lines
  1036. $bctag = array(0=>'class="impair tagtr"', 1=>'class="pair tagtr"');
  1037. // Define messages variables
  1038. $mesg = ''; $warning = ''; $error = 0;
  1039. // deprecated, see setEventMessages() and dol_htmloutput_events()
  1040. $mesgs = array(); $warnings = array(); $errors = array();
  1041. // Constants used to defined number of lines in textarea
  1042. if (empty($conf->browser->firefox)) {
  1043. define('ROWS_1', 1);
  1044. define('ROWS_2', 2);
  1045. define('ROWS_3', 3);
  1046. define('ROWS_4', 4);
  1047. define('ROWS_5', 5);
  1048. define('ROWS_6', 6);
  1049. define('ROWS_7', 7);
  1050. define('ROWS_8', 8);
  1051. define('ROWS_9', 9);
  1052. } else {
  1053. define('ROWS_1', 0);
  1054. define('ROWS_2', 1);
  1055. define('ROWS_3', 2);
  1056. define('ROWS_4', 3);
  1057. define('ROWS_5', 4);
  1058. define('ROWS_6', 5);
  1059. define('ROWS_7', 6);
  1060. define('ROWS_8', 7);
  1061. define('ROWS_9', 8);
  1062. }
  1063. $heightforframes = 50;
  1064. // Init menu manager
  1065. if (!defined('NOREQUIREMENU')) {
  1066. if (empty($user->socid)) { // If internal user or not defined
  1067. $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);
  1068. } else {
  1069. // If external user
  1070. $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);
  1071. }
  1072. // Load the menu manager (only if not already done)
  1073. $file_menu = $conf->standard_menu;
  1074. if (GETPOST('menu', 'alpha')) {
  1075. $file_menu = GETPOST('menu', 'alpha'); // example: menu=eldy_menu.php
  1076. }
  1077. if (!class_exists('MenuManager')) {
  1078. $menufound = 0;
  1079. $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
  1080. foreach ($dirmenus as $dirmenu) {
  1081. $menufound = dol_include_once($dirmenu."standard/".$file_menu);
  1082. if (class_exists('MenuManager')) {
  1083. break;
  1084. }
  1085. }
  1086. if (!class_exists('MenuManager')) { // If failed to include, we try with standard eldy_menu.php
  1087. dol_syslog("You define a menu manager '".$file_menu."' that can not be loaded.", LOG_WARNING);
  1088. $file_menu = 'eldy_menu.php';
  1089. include_once DOL_DOCUMENT_ROOT."/core/menus/standard/".$file_menu;
  1090. }
  1091. }
  1092. $menumanager = new MenuManager($db, empty($user->socid) ? 0 : 1);
  1093. $menumanager->loadMenu();
  1094. }
  1095. // Functions
  1096. if (!function_exists("llxHeader")) {
  1097. /**
  1098. * Show HTML header HTML + BODY + Top menu + left menu + DIV
  1099. *
  1100. * @param string $head Optionnal head lines
  1101. * @param string $title HTML title
  1102. * @param string $help_url Url links to help page
  1103. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  1104. * For other external page: http://server/url
  1105. * @param string $target Target to use on links
  1106. * @param int $disablejs More content into html header
  1107. * @param int $disablehead More content into html header
  1108. * @param array|string $arrayofjs Array of complementary js files
  1109. * @param array|string $arrayofcss Array of complementary css files
  1110. * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails)
  1111. * @param string $morecssonbody More CSS on body tag. For example 'classforhorizontalscrolloftabs'.
  1112. * @param string $replacemainareaby Replace call to main_area() by a print of this string
  1113. * @param int $disablenofollow Disable the "nofollow" on page
  1114. * @return void
  1115. */
  1116. function llxHeader($head = '', $title = '', $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $morecssonbody = '', $replacemainareaby = '', $disablenofollow = 0)
  1117. {
  1118. global $conf;
  1119. // html header
  1120. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, $disablenofollow);
  1121. $tmpcsstouse = 'sidebar-collapse'.($morecssonbody ? ' '.$morecssonbody : '');
  1122. // If theme MD and classic layer, we open the menulayer by default.
  1123. if ($conf->theme == 'md' && !in_array($conf->browser->layout, array('phone', 'tablet')) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  1124. global $mainmenu;
  1125. if ($mainmenu != 'website') {
  1126. $tmpcsstouse = $morecssonbody; // We do not use sidebar-collpase by default to have menuhider open by default.
  1127. }
  1128. }
  1129. if (!empty($conf->global->MAIN_OPTIMIZEFORCOLORBLIND)) {
  1130. $tmpcsstouse .= ' colorblind-'.strip_tags($conf->global->MAIN_OPTIMIZEFORCOLORBLIND);
  1131. }
  1132. print '<body id="mainbody" class="'.$tmpcsstouse.'">'."\n";
  1133. // top menu and left menu area
  1134. if (empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) {
  1135. top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring, $help_url);
  1136. }
  1137. if (empty($conf->dol_hide_leftmenu)) {
  1138. left_menu('', $help_url, '', '', 1, $title, 1); // $menumanager is retrieved with a global $menumanager inside this function
  1139. }
  1140. // main area
  1141. if ($replacemainareaby) {
  1142. print $replacemainareaby;
  1143. return;
  1144. }
  1145. main_area($title);
  1146. }
  1147. }
  1148. /**
  1149. * Show HTTP header. Called by top_htmlhead().
  1150. *
  1151. * @param string $contenttype Content type. For example, 'text/html'
  1152. * @param int $forcenocache Force disabling of cache for the page
  1153. * @return void
  1154. */
  1155. function top_httphead($contenttype = 'text/html', $forcenocache = 0)
  1156. {
  1157. global $db, $conf, $hookmanager;
  1158. if ($contenttype == 'text/html') {
  1159. header("Content-Type: text/html; charset=".$conf->file->character_set_client);
  1160. } else {
  1161. header("Content-Type: ".$contenttype);
  1162. }
  1163. // Security options
  1164. 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)
  1165. if (!defined('XFRAMEOPTIONS_ALLOWALL')) {
  1166. header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
  1167. } else {
  1168. header("X-Frame-Options: ALLOWALL");
  1169. }
  1170. //header("X-XSS-Protection: 1"); // XSS filtering protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated.
  1171. if (!defined('FORCECSP')) {
  1172. //if (! isset($conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY))
  1173. //{
  1174. // // A default security policy that keep usage of js external component like ckeditor, stripe, google, working
  1175. // $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';";
  1176. //}
  1177. //else
  1178. $contentsecuritypolicy = empty($conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY) ? '' : $conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY;
  1179. if (!is_object($hookmanager)) {
  1180. $hookmanager = new HookManager($db);
  1181. }
  1182. $hookmanager->initHooks(array("main"));
  1183. $parameters = array('contentsecuritypolicy'=>$contentsecuritypolicy);
  1184. $result = $hookmanager->executeHooks('setContentSecurityPolicy', $parameters); // Note that $action and $object may have been modified by some hooks
  1185. if ($result > 0) {
  1186. $contentsecuritypolicy = $hookmanager->resPrint; // Replace CSP
  1187. } else {
  1188. $contentsecuritypolicy .= $hookmanager->resPrint; // Concat CSP
  1189. }
  1190. if (!empty($contentsecuritypolicy)) {
  1191. // For example, to restrict 'script', 'object', 'frames' or 'img' to some domains:
  1192. // 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
  1193. // For example, to restrict everything to one domain, except 'object', ...:
  1194. // default-src https://cdn.example.net; object-src 'none'
  1195. // For example, to restrict everything to itself except img that can be on other servers:
  1196. // default-src 'self'; img-src *;
  1197. // Pre-existing site that uses too much inline code to fix but wants to ensure resources are loaded only over https and disable plugins:
  1198. // default-src http: https: 'unsafe-eval' 'unsafe-inline'; object-src 'none'
  1199. header("Content-Security-Policy: ".$contentsecuritypolicy);
  1200. }
  1201. } elseif (constant('FORCECSP')) {
  1202. header("Content-Security-Policy: ".constant('FORCECSP'));
  1203. }
  1204. if ($forcenocache) {
  1205. header("Cache-Control: no-cache, no-store, must-revalidate, max-age=0");
  1206. }
  1207. }
  1208. /**
  1209. * Ouput html header of a page. It calls also top_httphead()
  1210. * This code is also duplicated into security2.lib.php::dol_loginfunction
  1211. *
  1212. * @param string $head Optionnal head lines
  1213. * @param string $title HTML title
  1214. * @param int $disablejs Disable js output
  1215. * @param int $disablehead Disable head output
  1216. * @param array $arrayofjs Array of complementary js files
  1217. * @param array $arrayofcss Array of complementary css files
  1218. * @param int $disablejmobile Disable jmobile (No more used)
  1219. * @param int $disablenofollow Disable no follow tag
  1220. * @return void
  1221. */
  1222. function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $disablejmobile = 0, $disablenofollow = 0)
  1223. {
  1224. global $db, $conf, $langs, $user, $mysoc, $hookmanager;
  1225. top_httphead();
  1226. if (empty($conf->css)) {
  1227. $conf->css = '/theme/eldy/style.css.php'; // If not defined, eldy by default
  1228. }
  1229. print '<!doctype html>'."\n";
  1230. if (!empty($conf->global->MAIN_USE_CACHE_MANIFEST)) {
  1231. print '<html lang="'.substr($langs->defaultlang, 0, 2).'" manifest="'.DOL_URL_ROOT.'/cache.manifest">'."\n";
  1232. } else {
  1233. print '<html lang="'.substr($langs->defaultlang, 0, 2).'">'."\n";
  1234. }
  1235. //print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">'."\n";
  1236. if (empty($disablehead)) {
  1237. if (!is_object($hookmanager)) {
  1238. $hookmanager = new HookManager($db);
  1239. }
  1240. $hookmanager->initHooks(array("main"));
  1241. $ext = 'layout='.$conf->browser->layout.'&amp;version='.urlencode(DOL_VERSION);
  1242. print "<head>\n";
  1243. if (GETPOST('dol_basehref', 'alpha')) {
  1244. print '<base href="'.dol_escape_htmltag(GETPOST('dol_basehref', 'alpha')).'">'."\n";
  1245. }
  1246. // Displays meta
  1247. print '<meta charset="utf-8">'."\n";
  1248. print '<meta name="robots" content="noindex'.($disablenofollow ? '' : ',nofollow').'">'."\n"; // Do not index
  1249. print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n"; // Scale for mobile device
  1250. print '<meta name="author" content="Dolibarr Development Team">'."\n";
  1251. // Favicon
  1252. $favicon = DOL_URL_ROOT.'/theme/dolibarr_256x256_color.png';
  1253. if (!empty($mysoc->logo_squarred_mini)) {
  1254. $favicon = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini);
  1255. }
  1256. if (!empty($conf->global->MAIN_FAVICON_URL)) {
  1257. $favicon = $conf->global->MAIN_FAVICON_URL;
  1258. }
  1259. if (empty($conf->dol_use_jmobile)) {
  1260. print '<link rel="shortcut icon" type="image/x-icon" href="'.$favicon.'"/>'."\n"; // Not required into an Android webview
  1261. }
  1262. //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="top" title="'.$langs->trans("Home").'" href="'.(DOL_URL_ROOT?DOL_URL_ROOT:'/').'">'."\n";
  1263. //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="copyright" title="GNU General Public License" href="https://www.gnu.org/copyleft/gpl.html#SEC1">'."\n";
  1264. //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="author" title="Dolibarr Development Team" href="https://www.dolibarr.org">'."\n";
  1265. // Mobile appli like icon
  1266. $manifest = DOL_URL_ROOT.'/theme/'.$conf->theme.'/manifest.json.php';
  1267. if (!empty($manifest)) {
  1268. print '<link rel="manifest" href="'.$manifest.'" />'."\n";
  1269. }
  1270. if (!empty($conf->global->THEME_ELDY_TOPMENU_BACK1)) {
  1271. // TODO: use auto theme color switch
  1272. print '<meta name="theme-color" content="rgb('.$conf->global->THEME_ELDY_TOPMENU_BACK1.')">'."\n";
  1273. }
  1274. // Auto refresh page
  1275. if (GETPOST('autorefresh', 'int') > 0) {
  1276. print '<meta http-equiv="refresh" content="'.GETPOST('autorefresh', 'int').'">';
  1277. }
  1278. // Displays title
  1279. $appli = constant('DOL_APPLICATION_TITLE');
  1280. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  1281. $appli = $conf->global->MAIN_APPLICATION_TITLE;
  1282. }
  1283. print '<title>';
  1284. $titletoshow = '';
  1285. if ($title && !empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/', $conf->global->MAIN_HTML_TITLE)) {
  1286. $titletoshow = dol_htmlentities($title);
  1287. } elseif ($title) {
  1288. $titletoshow = dol_htmlentities($appli.' - '.$title);
  1289. } else {
  1290. $titletoshow = dol_htmlentities($appli);
  1291. }
  1292. $parameters = array('title'=>$titletoshow);
  1293. $result = $hookmanager->executeHooks('setHtmlTitle', $parameters); // Note that $action and $object may have been modified by some hooks
  1294. if ($result > 0) {
  1295. $titletoshow = $hookmanager->resPrint; // Replace Title to show
  1296. } else {
  1297. $titletoshow .= $hookmanager->resPrint; // Concat to Title to show
  1298. }
  1299. print $titletoshow;
  1300. print '</title>';
  1301. print "\n";
  1302. if (GETPOST('version', 'int')) {
  1303. $ext = 'version='.GETPOST('version', 'int'); // usefull to force no cache on css/js
  1304. }
  1305. $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;
  1306. $themeparam .= ($ext ? '&amp;'.$ext : '').'&amp;revision='.getDolGlobalInt("MAIN_IHM_PARAMS_REV");
  1307. if (!empty($_SESSION['dol_resetcache'])) {
  1308. $themeparam .= '&amp;dol_resetcache='.$_SESSION['dol_resetcache'];
  1309. }
  1310. if (GETPOSTISSET('dol_hide_topmenu')) {
  1311. $themeparam .= '&amp;dol_hide_topmenu='.GETPOST('dol_hide_topmenu', 'int');
  1312. }
  1313. if (GETPOSTISSET('dol_hide_leftmenu')) {
  1314. $themeparam .= '&amp;dol_hide_leftmenu='.GETPOST('dol_hide_leftmenu', 'int');
  1315. }
  1316. if (GETPOSTISSET('dol_optimize_smallscreen')) {
  1317. $themeparam .= '&amp;dol_optimize_smallscreen='.GETPOST('dol_optimize_smallscreen', 'int');
  1318. }
  1319. if (GETPOSTISSET('dol_no_mouse_hover')) {
  1320. $themeparam .= '&amp;dol_no_mouse_hover='.GETPOST('dol_no_mouse_hover', 'int');
  1321. }
  1322. if (GETPOSTISSET('dol_use_jmobile')) {
  1323. $themeparam .= '&amp;dol_use_jmobile='.GETPOST('dol_use_jmobile', 'int'); $conf->dol_use_jmobile = GETPOST('dol_use_jmobile', 'int');
  1324. }
  1325. if (GETPOSTISSET('THEME_DARKMODEENABLED')) {
  1326. $themeparam .= '&amp;THEME_DARKMODEENABLED='.GETPOST('THEME_DARKMODEENABLED', 'int');
  1327. }
  1328. if (GETPOSTISSET('THEME_SATURATE_RATIO')) {
  1329. $themeparam .= '&amp;THEME_SATURATE_RATIO='.GETPOST('THEME_SATURATE_RATIO', 'int');
  1330. }
  1331. if (!empty($conf->global->MAIN_ENABLE_FONT_ROBOTO)) {
  1332. print '<link rel="preconnect" href="https://fonts.gstatic.com">'."\n";
  1333. print '<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@200;300;400;500;600&display=swap" rel="stylesheet">'."\n";
  1334. }
  1335. if (!defined('DISABLE_JQUERY') && !$disablejs && $conf->use_javascript_ajax) {
  1336. print '<!-- Includes CSS for JQuery (Ajax library) -->'."\n";
  1337. $jquerytheme = 'base';
  1338. if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) {
  1339. $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
  1340. }
  1341. if (constant('JS_JQUERY_UI')) {
  1342. print '<link rel="stylesheet" type="text/css" href="'.JS_JQUERY_UI.'css/'.$jquerytheme.'/jquery-ui.min.css'.($ext ? '?'.$ext : '').'">'."\n"; // Forced JQuery
  1343. } else {
  1344. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/css/'.$jquerytheme.'/jquery-ui.css'.($ext ? '?'.$ext : '').'">'."\n"; // JQuery
  1345. }
  1346. if (!defined('DISABLE_JQUERY_JNOTIFY')) {
  1347. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jnotify/jquery.jnotify-alt.min.css'.($ext ? '?'.$ext : '').'">'."\n"; // JNotify
  1348. }
  1349. if (!defined('DISABLE_SELECT2') && (!empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT'))) { // jQuery plugin "mutiselect", "multiple-select", "select2"...
  1350. $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ?constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
  1351. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/'.$tmpplugin.'/dist/css/'.$tmpplugin.'.css'.($ext ? '?'.$ext : '').'">'."\n";
  1352. }
  1353. }
  1354. if (!defined('DISABLE_FONT_AWSOME')) {
  1355. print '<!-- Includes CSS for font awesome -->'."\n";
  1356. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/theme/common/fontawesome-5/css/all.min.css'.($ext ? '?'.$ext : '').'">'."\n";
  1357. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/theme/common/fontawesome-5/css/v4-shims.min.css'.($ext ? '?'.$ext : '').'">'."\n";
  1358. }
  1359. print '<!-- Includes CSS for Dolibarr theme -->'."\n";
  1360. // Output style sheets (optioncss='print' or ''). Note: $conf->css looks like '/theme/eldy/style.css.php'
  1361. $themepath = dol_buildpath($conf->css, 1);
  1362. $themesubdir = '';
  1363. if (!empty($conf->modules_parts['theme'])) { // This slow down
  1364. foreach ($conf->modules_parts['theme'] as $reldir) {
  1365. if (file_exists(dol_buildpath($reldir.$conf->css, 0))) {
  1366. $themepath = dol_buildpath($reldir.$conf->css, 1);
  1367. $themesubdir = $reldir;
  1368. break;
  1369. }
  1370. }
  1371. }
  1372. //print 'themepath='.$themepath.' themeparam='.$themeparam;exit;
  1373. print '<link rel="stylesheet" type="text/css" href="'.$themepath.$themeparam.'">'."\n";
  1374. if (!empty($conf->global->MAIN_FIX_FLASH_ON_CHROME)) {
  1375. 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";
  1376. }
  1377. // CSS forced by modules (relative url starting with /)
  1378. if (!empty($conf->modules_parts['css'])) {
  1379. $arraycss = (array) $conf->modules_parts['css'];
  1380. foreach ($arraycss as $modcss => $filescss) {
  1381. $filescss = (array) $filescss; // To be sure filecss is an array
  1382. foreach ($filescss as $cssfile) {
  1383. if (empty($cssfile)) {
  1384. dol_syslog("Warning: module ".$modcss." declared a css path file into its descriptor that is empty.", LOG_WARNING);
  1385. }
  1386. // cssfile is a relative path
  1387. print '<!-- Includes CSS added by module '.$modcss.' -->'."\n".'<link rel="stylesheet" type="text/css" href="'.dol_buildpath($cssfile, 1);
  1388. // 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.
  1389. if (!preg_match('/\.css$/i', $cssfile)) {
  1390. print $themeparam;
  1391. }
  1392. print '">'."\n";
  1393. }
  1394. }
  1395. }
  1396. // CSS forced by page in top_htmlhead call (relative url starting with /)
  1397. if (is_array($arrayofcss)) {
  1398. foreach ($arrayofcss as $cssfile) {
  1399. if (preg_match('/^(http|\/\/)/i', $cssfile)) {
  1400. $urltofile = $cssfile;
  1401. } else {
  1402. $urltofile = dol_buildpath($cssfile, 1);
  1403. }
  1404. print '<!-- Includes CSS added by page -->'."\n".'<link rel="stylesheet" type="text/css" title="default" href="'.$urltofile;
  1405. // 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.
  1406. if (!preg_match('/\.css$/i', $cssfile)) {
  1407. print $themeparam;
  1408. }
  1409. print '">'."\n";
  1410. }
  1411. }
  1412. // Output standard javascript links
  1413. if (!defined('DISABLE_JQUERY') && !$disablejs && !empty($conf->use_javascript_ajax)) {
  1414. // JQuery. Must be before other includes
  1415. print '<!-- Includes JS for JQuery -->'."\n";
  1416. if (defined('JS_JQUERY') && constant('JS_JQUERY')) {
  1417. print '<script src="'.JS_JQUERY.'jquery.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1418. } else {
  1419. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1420. }
  1421. /*if (! empty($conf->global->MAIN_FEATURES_LEVEL) && ! defined('JS_JQUERY_MIGRATE_DISABLED'))
  1422. {
  1423. if (defined('JS_JQUERY_MIGRATE') && constant('JS_JQUERY_MIGRATE')) print '<script src="'.JS_JQUERY_MIGRATE.'jquery-migrate.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1424. else print '<script src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery-migrate.min.js'.($ext?'?'.$ext:'').'"></script>'."\n";
  1425. }*/
  1426. if (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) {
  1427. print '<script src="'.JS_JQUERY_UI.'jquery-ui.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1428. } else {
  1429. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery-ui.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1430. }
  1431. if (!defined('DISABLE_JQUERY_TABLEDND')) {
  1432. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/tablednd/jquery.tablednd.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1433. }
  1434. // jQuery jnotify
  1435. if (empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && !defined('DISABLE_JQUERY_JNOTIFY')) {
  1436. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jnotify/jquery.jnotify.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1437. }
  1438. // Chart
  1439. if ((empty($conf->global->MAIN_JS_GRAPH) || $conf->global->MAIN_JS_GRAPH == 'chart') && !defined('DISABLE_JS_GRAPH')) {
  1440. print '<script src="'.DOL_URL_ROOT.'/includes/nnnick/chartjs/dist/Chart.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1441. }
  1442. // jQuery jeditable for Edit In Place features
  1443. if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !defined('DISABLE_JQUERY_JEDITABLE')) {
  1444. print '<!-- JS to manage editInPlace feature -->'."\n";
  1445. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1446. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ui-datepicker.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1447. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ui-autocomplete.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1448. print '<script>'."\n";
  1449. print 'var urlSaveInPlace = \''.DOL_URL_ROOT.'/core/ajax/saveinplace.php\';'."\n";
  1450. print 'var urlLoadInPlace = \''.DOL_URL_ROOT.'/core/ajax/loadinplace.php\';'."\n";
  1451. print 'var tooltipInPlace = \''.$langs->transnoentities('ClickToEdit').'\';'."\n"; // Added in title attribute of span
  1452. 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 ?
  1453. print 'var cancelInPlace = \''.$langs->trans("Cancel").'\';'."\n";
  1454. print 'var submitInPlace = \''.$langs->trans('Ok').'\';'."\n";
  1455. print 'var indicatorInPlace = \'<img src="'.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'">\';'."\n";
  1456. print 'var withInPlace = 300;'; // width in pixel for default string edit
  1457. print '</script>'."\n";
  1458. print '<script src="'.DOL_URL_ROOT.'/core/js/editinplace.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1459. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1460. }
  1461. // jQuery Timepicker
  1462. if (!empty($conf->global->MAIN_USE_JQUERY_TIMEPICKER) || defined('REQUIRE_JQUERY_TIMEPICKER')) {
  1463. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/timepicker/jquery-ui-timepicker-addon.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1464. print '<script src="'.DOL_URL_ROOT.'/core/js/timepicker.js.php?lang='.$langs->defaultlang.($ext ? '&amp;'.$ext : '').'"></script>'."\n";
  1465. }
  1466. if (!defined('DISABLE_SELECT2') && (!empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT'))) {
  1467. // jQuery plugin "mutiselect", "multiple-select", "select2", ...
  1468. $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ?constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
  1469. 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
  1470. }
  1471. if (!defined('DISABLE_MULTISELECT')) { // jQuery plugin "mutiselect" to select with checkboxes. Can be removed once we have an enhanced search tool
  1472. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/multiselect/jquery.multi-select.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1473. }
  1474. }
  1475. if (!$disablejs && !empty($conf->use_javascript_ajax)) {
  1476. // CKEditor
  1477. if ((!empty($conf->fckeditor->enabled) && (empty($conf->global->FCKEDITOR_EDITORNAME) || $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor') && !defined('DISABLE_CKEDITOR')) || defined('FORCE_CKEDITOR')) {
  1478. print '<!-- Includes JS for CKEditor -->'."\n";
  1479. $pathckeditor = DOL_URL_ROOT.'/includes/ckeditor/ckeditor/';
  1480. $jsckeditor = 'ckeditor.js';
  1481. if (constant('JS_CKEDITOR')) {
  1482. // To use external ckeditor 4 js lib
  1483. $pathckeditor = constant('JS_CKEDITOR');
  1484. }
  1485. print '<script>';
  1486. print '/* enable ckeditor by main.inc.php */';
  1487. print 'var CKEDITOR_BASEPATH = \''.$pathckeditor.'\';'."\n";
  1488. print 'var ckeditorConfig = \''.dol_buildpath($themesubdir.'/theme/'.$conf->theme.'/ckeditor/config.js'.($ext ? '?'.$ext : ''), 1).'\';'."\n"; // $themesubdir='' in standard usage
  1489. print 'var ckeditorFilebrowserBrowseUrl = \''.DOL_URL_ROOT.'/core/filemanagerdol/browser/default/browser.php?Connector='.DOL_URL_ROOT.'/core/filemanagerdol/connectors/php/connector.php\';'."\n";
  1490. 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";
  1491. print '</script>'."\n";
  1492. print '<script src="'.$pathckeditor.$jsckeditor.($ext ? '?'.$ext : '').'"></script>'."\n";
  1493. print '<script>';
  1494. if (GETPOST('mode', 'aZ09') == 'Full_inline') {
  1495. print 'CKEDITOR.disableAutoInline = false;'."\n";
  1496. } else {
  1497. print 'CKEDITOR.disableAutoInline = true;'."\n";
  1498. }
  1499. print '</script>'."\n";
  1500. }
  1501. // Browser notifications (if NOREQUIREMENU is on, it is mostly a page for popup, so we do not enable notif too. We hide also for public pages).
  1502. if (!defined('NOBROWSERNOTIF') && !defined('NOREQUIREMENU') && !defined('NOLOGIN')) {
  1503. $enablebrowsernotif = false;
  1504. if (!empty($conf->agenda->enabled) && !empty($conf->global->AGENDA_REMINDER_BROWSER)) {
  1505. $enablebrowsernotif = true;
  1506. }
  1507. if ($conf->browser->layout == 'phone') {
  1508. $enablebrowsernotif = false;
  1509. }
  1510. if ($enablebrowsernotif) {
  1511. print '<!-- Includes JS of Dolibarr (browser layout = '.$conf->browser->layout.')-->'."\n";
  1512. print '<script src="'.DOL_URL_ROOT.'/core/js/lib_notification.js.php'.($ext ? '?'.$ext : '').'"></script>'."\n";
  1513. }
  1514. }
  1515. // Global js function
  1516. print '<!-- Includes JS of Dolibarr -->'."\n";
  1517. print '<script src="'.DOL_URL_ROOT.'/core/js/lib_head.js.php?lang='.$langs->defaultlang.($ext ? '&amp;'.$ext : '').'"></script>'."\n";
  1518. // JS forced by modules (relative url starting with /)
  1519. if (!empty($conf->modules_parts['js'])) { // $conf->modules_parts['js'] is array('module'=>array('file1','file2'))
  1520. $arrayjs = (array) $conf->modules_parts['js'];
  1521. foreach ($arrayjs as $modjs => $filesjs) {
  1522. $filesjs = (array) $filesjs; // To be sure filejs is an array
  1523. foreach ($filesjs as $jsfile) {
  1524. // jsfile is a relative path
  1525. print '<!-- Include JS added by module '.$modjs.'-->'."\n".'<script src="'.dol_buildpath($jsfile, 1).((strpos($jsfile, '?') === false) ? '?' : '&amp;').'lang='.$langs->defaultlang.'"></script>'."\n";
  1526. }
  1527. }
  1528. }
  1529. // JS forced by page in top_htmlhead (relative url starting with /)
  1530. if (is_array($arrayofjs)) {
  1531. print '<!-- Includes JS added by page -->'."\n";
  1532. foreach ($arrayofjs as $jsfile) {
  1533. if (preg_match('/^(http|\/\/)/i', $jsfile)) {
  1534. print '<script src="'.$jsfile.((strpos($jsfile, '?') === false) ? '?' : '&amp;').'lang='.$langs->defaultlang.'"></script>'."\n";
  1535. } else {
  1536. print '<script src="'.dol_buildpath($jsfile, 1).((strpos($jsfile, '?') === false) ? '?' : '&amp;').'lang='.$langs->defaultlang.'"></script>'."\n";
  1537. }
  1538. }
  1539. }
  1540. }
  1541. if (!empty($head)) {
  1542. print $head."\n";
  1543. }
  1544. if (!empty($conf->global->MAIN_HTML_HEADER)) {
  1545. print $conf->global->MAIN_HTML_HEADER."\n";
  1546. }
  1547. $parameters = array();
  1548. $result = $hookmanager->executeHooks('addHtmlHeader', $parameters); // Note that $action and $object may have been modified by some hooks
  1549. print $hookmanager->resPrint; // Replace Title to show
  1550. print "</head>\n\n";
  1551. }
  1552. $conf->headerdone = 1; // To tell header was output
  1553. }
  1554. /**
  1555. * Show an HTML header + a BODY + The top menu bar
  1556. *
  1557. * @param string $head Lines in the HEAD
  1558. * @param string $title Title of web page
  1559. * @param string $target Target to use in menu links (Example: '' or '_top')
  1560. * @param int $disablejs Do not output links to js (Ex: qd fonction utilisee par sous formulaire Ajax)
  1561. * @param int $disablehead Do not output head section
  1562. * @param array $arrayofjs Array of js files to add in header
  1563. * @param array $arrayofcss Array of css files to add in header
  1564. * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails)
  1565. * @param string $helppagename Name of wiki page for help ('' by default).
  1566. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  1567. * For other external page: http://server/url
  1568. * @return void
  1569. */
  1570. function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $helppagename = '')
  1571. {
  1572. global $user, $conf, $langs, $db;
  1573. global $dolibarr_main_authentication, $dolibarr_main_demo;
  1574. global $hookmanager, $menumanager;
  1575. $searchform = '';
  1576. $bookmarks = '';
  1577. // Instantiate hooks for external modules
  1578. $hookmanager->initHooks(array('toprightmenu'));
  1579. $toprightmenu = '';
  1580. // For backward compatibility with old modules
  1581. if (empty($conf->headerdone)) {
  1582. $disablenofollow = 0;
  1583. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, $disablenofollow);
  1584. print '<body id="mainbody">';
  1585. }
  1586. /*
  1587. * Top menu
  1588. */
  1589. if ((empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) {
  1590. if (!isset($form) || !is_object($form)) {
  1591. include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  1592. $form = new Form($db);
  1593. }
  1594. print "\n".'<!-- Start top horizontal -->'."\n";
  1595. 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.
  1596. // Show menu entries
  1597. print '<div id="tmenu_tooltip'.(empty($conf->global->MAIN_MENU_INVERT) ? '' : 'invert').'" class="tmenu">'."\n";
  1598. $menumanager->atarget = $target;
  1599. $menumanager->showmenu('top', array('searchform'=>$searchform, 'bookmarks'=>$bookmarks)); // This contains a \n
  1600. print "</div>\n";
  1601. // Define link to login card
  1602. $appli = constant('DOL_APPLICATION_TITLE');
  1603. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  1604. $appli = $conf->global->MAIN_APPLICATION_TITLE;
  1605. if (preg_match('/\d\.\d/', $appli)) {
  1606. if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
  1607. $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
  1608. }
  1609. } else {
  1610. $appli .= " ".DOL_VERSION;
  1611. }
  1612. } else {
  1613. $appli .= " ".DOL_VERSION;
  1614. }
  1615. if (!empty($conf->global->MAIN_FEATURES_LEVEL)) {
  1616. $appli .= "<br>".$langs->trans("LevelOfFeature").': '.$conf->global->MAIN_FEATURES_LEVEL;
  1617. }
  1618. $logouttext = '';
  1619. $logouthtmltext = '';
  1620. if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  1621. //$logouthtmltext=$appli.'<br>';
  1622. if ($_SESSION["dol_authmode"] != 'forceuser' && $_SESSION["dol_authmode"] != 'http') {
  1623. $logouthtmltext .= $langs->trans("Logout").'<br>';
  1624. $logouttext .= '<a accesskey="l" href="'.DOL_URL_ROOT.'/user/logout.php">';
  1625. $logouttext .= img_picto($langs->trans('Logout'), 'sign-out', '', false, 0, 0, '', 'atoplogin');
  1626. $logouttext .= '</a>';
  1627. } else {
  1628. $logouthtmltext .= $langs->trans("NoLogoutProcessWithAuthMode", $_SESSION["dol_authmode"]);
  1629. $logouttext .= img_picto($langs->trans('Logout'), 'sign-out', '', false, 0, 0, '', 'atoplogin opacitymedium');
  1630. }
  1631. }
  1632. print '<div class="login_block usedropdown">'."\n";
  1633. $toprightmenu .= '<div class="login_block_other">';
  1634. // Execute hook printTopRightMenu (hooks should output string like '<div class="login"><a href="">mylink</a></div>')
  1635. $parameters = array();
  1636. $result = $hookmanager->executeHooks('printTopRightMenu', $parameters); // Note that $action and $object may have been modified by some hooks
  1637. if (is_numeric($result)) {
  1638. if ($result == 0) {
  1639. $toprightmenu .= $hookmanager->resPrint; // add
  1640. } else {
  1641. $toprightmenu = $hookmanager->resPrint; // replace
  1642. }
  1643. } else {
  1644. $toprightmenu .= $result; // For backward compatibility
  1645. }
  1646. // Link to module builder
  1647. if (!empty($conf->modulebuilder->enabled)) {
  1648. $text = '<a href="'.DOL_URL_ROOT.'/modulebuilder/index.php?mainmenu=home&leftmenu=admintools" target="modulebuilder">';
  1649. //$text.= img_picto(":".$langs->trans("ModuleBuilder"), 'printer_top.png', 'class="printer"');
  1650. $text .= '<span class="fa fa-bug atoplogin valignmiddle"></span>';
  1651. $text .= '</a>';
  1652. $toprightmenu .= $form->textwithtooltip('', $langs->trans("ModuleBuilder"), 2, 1, $text, 'login_block_elem', 2);
  1653. }
  1654. // Link to print main content area
  1655. if (empty($conf->global->MAIN_PRINT_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $conf->browser->layout != 'phone') {
  1656. $qs = dol_escape_htmltag($_SERVER["QUERY_STRING"]);
  1657. if (isset($_POST) && is_array($_POST)) {
  1658. foreach ($_POST as $key => $value) {
  1659. if ($key !== 'action' && $key !== 'password' && !is_array($value)) {
  1660. $qs .= '&'.$key.'='.urlencode($value);
  1661. }
  1662. }
  1663. }
  1664. $qs .= (($qs && $morequerystring) ? '&' : '').$morequerystring;
  1665. $text = '<a href="'.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.$qs.($qs ? '&' : '').'optioncss=print" target="_blank">';
  1666. //$text.= img_picto(":".$langs->trans("PrintContentArea"), 'printer_top.png', 'class="printer"');
  1667. $text .= '<span class="fa fa-print atoplogin valignmiddle"></span>';
  1668. $text .= '</a>';
  1669. $toprightmenu .= $form->textwithtooltip('', $langs->trans("PrintContentArea"), 2, 1, $text, 'login_block_elem', 2);
  1670. }
  1671. // Link to Dolibarr wiki pages
  1672. if (empty($conf->global->MAIN_HELP_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  1673. $langs->load("help");
  1674. $helpbaseurl = '';
  1675. $helppage = '';
  1676. $mode = '';
  1677. $helppresent = '';
  1678. if (empty($helppagename)) {
  1679. $helppagename = 'EN:User_documentation|FR:Documentation_utilisateur|ES:Documentación_usuarios';
  1680. } else {
  1681. $helppresent = 'helppresent';
  1682. }
  1683. // Get helpbaseurl, helppage and mode from helppagename and langs
  1684. $arrayres = getHelpParamFor($helppagename, $langs);
  1685. $helpbaseurl = $arrayres['helpbaseurl'];
  1686. $helppage = $arrayres['helppage'];
  1687. $mode = $arrayres['mode'];
  1688. // Link to help pages
  1689. if ($helpbaseurl && $helppage) {
  1690. $text = '';
  1691. $title = $langs->trans($mode == 'wiki' ? 'GoToWikiHelpPage' : 'GoToHelpPage').'...';
  1692. if ($mode == 'wiki') {
  1693. $title .= '<br>'.$langs->trans("PageWiki").' '.dol_escape_htmltag('"'.strtr($helppage, '_', ' ').'"');
  1694. if ($helppresent) {
  1695. $title .= ' <span class="opacitymedium">('.$langs->trans("DedicatedPageAvailable").')</span>';
  1696. } else {
  1697. $title .= ' <span class="opacitymedium">('.$langs->trans("HomePage").')</span>';
  1698. }
  1699. }
  1700. $text .= '<a class="help" target="_blank" rel="noopener" href="';
  1701. if ($mode == 'wiki') {
  1702. $text .= sprintf($helpbaseurl, urlencode(html_entity_decode($helppage)));
  1703. } else {
  1704. $text .= sprintf($helpbaseurl, $helppage);
  1705. }
  1706. $text .= '">';
  1707. $text .= '<span class="fa fa-question-circle atoplogin valignmiddle'.($helppresent ? ' '.$helppresent : '').'"></span>';
  1708. $text .= '<span class="fa fa-circle helppresentcircle'.($helppresent ? '' : ' unvisible').'"></span>';
  1709. $text .= '</a>';
  1710. $toprightmenu .= $form->textwithtooltip('', $title, 2, 1, $text, 'login_block_elem', 2);
  1711. }
  1712. // Version
  1713. if (!empty($conf->global->MAIN_SHOWDATABASENAMEINHELPPAGESLINK)) {
  1714. $langs->load('admin');
  1715. $appli .= '<br>'.$langs->trans("Database").': '.$db->database_name;
  1716. }
  1717. }
  1718. if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  1719. $text = '<span class="aversion"><span class="hideonsmartphone small">'.DOL_VERSION.'</span></span>';
  1720. $toprightmenu .= $form->textwithtooltip('', $appli, 2, 1, $text, 'login_block_elem', 2);
  1721. }
  1722. // Logout link
  1723. $toprightmenu .= $form->textwithtooltip('', $logouthtmltext, 2, 1, $logouttext, 'login_block_elem logout-btn', 2);
  1724. $toprightmenu .= '</div>'; // end div class="login_block_other"
  1725. // Add login user link
  1726. $toprightmenu .= '<div class="login_block_user">';
  1727. // Login name with photo and tooltip
  1728. $mode = -1;
  1729. $toprightmenu .= '<div class="inline-block nowrap"><div class="inline-block login_block_elem login_block_elem_name" style="padding: 0px;">';
  1730. if (!empty($conf->global->MAIN_USE_TOP_MENU_SEARCH_DROPDOWN)) {
  1731. // Add search dropdown
  1732. $toprightmenu .= top_menu_search();
  1733. }
  1734. if (!empty($conf->global->MAIN_USE_TOP_MENU_QUICKADD_DROPDOWN)) {
  1735. // Add search dropdown
  1736. $toprightmenu .= top_menu_quickadd();
  1737. }
  1738. // Add bookmark dropdown
  1739. $toprightmenu .= top_menu_bookmark();
  1740. // Add user dropdown
  1741. $toprightmenu .= top_menu_user();
  1742. $toprightmenu .= '</div></div>';
  1743. $toprightmenu .= '</div>'."\n";
  1744. print $toprightmenu;
  1745. print "</div>\n"; // end div class="login_block"
  1746. print '</div></div>';
  1747. print '<div style="clear: both;"></div>';
  1748. print "<!-- End top horizontal menu -->\n\n";
  1749. }
  1750. if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) {
  1751. print '<!-- Begin div id-container --><div id="id-container" class="id-container">';
  1752. }
  1753. }
  1754. /**
  1755. * Build the tooltip on user login
  1756. *
  1757. * @param int $hideloginname Hide login name. Show only the image.
  1758. * @param string $urllogout URL for logout
  1759. * @return string HTML content
  1760. */
  1761. function top_menu_user($hideloginname = 0, $urllogout = '')
  1762. {
  1763. global $langs, $conf, $db, $hookmanager, $user, $mysoc;
  1764. global $dolibarr_main_authentication, $dolibarr_main_demo;
  1765. global $menumanager;
  1766. $userImage = $userDropDownImage = '';
  1767. if (!empty($user->photo)) {
  1768. $userImage = Form::showphoto('userphoto', $user, 0, 0, 0, 'photouserphoto userphoto', 'small', 0, 1);
  1769. $userDropDownImage = Form::showphoto('userphoto', $user, 0, 0, 0, 'dropdown-user-image', 'small', 0, 1);
  1770. } else {
  1771. $nophoto = '/public/theme/common/user_anonymous.png';
  1772. if ($user->gender == 'man') {
  1773. $nophoto = '/public/theme/common/user_man.png';
  1774. }
  1775. if ($user->gender == 'woman') {
  1776. $nophoto = '/public/theme/common/user_woman.png';
  1777. }
  1778. $userImage = '<img class="photo photouserphoto userphoto" alt="No photo" src="'.DOL_URL_ROOT.$nophoto.'">';
  1779. $userDropDownImage = '<img class="photo dropdown-user-image" alt="No photo" src="'.DOL_URL_ROOT.$nophoto.'">';
  1780. }
  1781. $dropdownBody = '';
  1782. $dropdownBody .= '<span id="topmenulogincompanyinfo-btn"><i class="fa fa-caret-right"></i> '.$langs->trans("ShowCompanyInfos").'</span>';
  1783. $dropdownBody .= '<div id="topmenulogincompanyinfo" >';
  1784. if ($langs->transcountry("ProfId1", $mysoc->country_code) != '-') {
  1785. $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId1", $mysoc->country_code).'</b>: <span>'.showValueWithClipboardCPButton($conf->global->MAIN_INFO_SIREN).'</span>';
  1786. }
  1787. if ($langs->transcountry("ProfId2", $mysoc->country_code) != '-') {
  1788. $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId2", $mysoc->country_code).'</b>: <span>'.showValueWithClipboardCPButton($conf->global->MAIN_INFO_SIRET).'</span>';
  1789. }
  1790. if ($langs->transcountry("ProfId3", $mysoc->country_code) != '-') {
  1791. $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId3", $mysoc->country_code).'</b>: <span>'.showValueWithClipboardCPButton($conf->global->MAIN_INFO_APE).'</span>';
  1792. }
  1793. if ($langs->transcountry("ProfId4", $mysoc->country_code) != '-') {
  1794. $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId4", $mysoc->country_code).'</b>: <span>'.showValueWithClipboardCPButton($conf->global->MAIN_INFO_RCS).'</span>';
  1795. }
  1796. if ($langs->transcountry("ProfId5", $mysoc->country_code) != '-') {
  1797. $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId5", $mysoc->country_code).'</b>: <span>'.showValueWithClipboardCPButton($conf->global->MAIN_INFO_PROFID5).'</span>';
  1798. }
  1799. if ($langs->transcountry("ProfId6", $mysoc->country_code) != '-') {
  1800. $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId6", $mysoc->country_code).'</b>: <span>'.showValueWithClipboardCPButton($conf->global->MAIN_INFO_PROFID6).'</span>';
  1801. }
  1802. $dropdownBody .= '<br><b>'.$langs->trans("VATIntraShort").'</b>: <span>'.showValueWithClipboardCPButton($conf->global->MAIN_INFO_TVAINTRA).'</span>';
  1803. $dropdownBody .= '</div>';
  1804. $dropdownBody .= '<br>';
  1805. $dropdownBody .= '<span id="topmenuloginmoreinfo-btn"><i class="fa fa-caret-right"></i> '.$langs->trans("ShowMoreInfos").'</span>';
  1806. $dropdownBody .= '<div id="topmenuloginmoreinfo" >';
  1807. // login infos
  1808. if (!empty($user->admin)) {
  1809. $dropdownBody .= '<br><b>'.$langs->trans("Administrator").'</b>: '.yn($user->admin);
  1810. }
  1811. if (!empty($user->socid)) { // Add thirdparty for external users
  1812. $thirdpartystatic = new Societe($db);
  1813. $thirdpartystatic->fetch($user->socid);
  1814. $companylink = ' '.$thirdpartystatic->getNomUrl(2); // picto only of company
  1815. $company = ' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')';
  1816. }
  1817. $type = ($user->socid ? $langs->trans("External").$company : $langs->trans("Internal"));
  1818. $dropdownBody .= '<br><b>'.$langs->trans("Type").':</b> '.$type;
  1819. $dropdownBody .= '<br><b>'.$langs->trans("Status").'</b>: '.$user->getLibStatut(0);
  1820. $dropdownBody .= '<br>';
  1821. $dropdownBody .= '<br><u>'.$langs->trans("Session").'</u>';
  1822. $dropdownBody .= '<br><b>'.$langs->trans("IPAddress").'</b>: '.dol_escape_htmltag($_SERVER["REMOTE_ADDR"]);
  1823. if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
  1824. $dropdownBody .= '<br><b>'.$langs->trans("ConnectedOnMultiCompany").':</b> '.$conf->entity.' (user entity '.$user->entity.')';
  1825. }
  1826. $dropdownBody .= '<br><b>'.$langs->trans("AuthenticationMode").':</b> '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo) ? '' : ' (demo)');
  1827. $dropdownBody .= '<br><b>'.$langs->trans("ConnectedSince").':</b> '.dol_print_date($user->datelastlogin, "dayhour", 'tzuser');
  1828. $dropdownBody .= '<br><b>'.$langs->trans("PreviousConnexion").':</b> '.dol_print_date($user->datepreviouslogin, "dayhour", 'tzuser');
  1829. $dropdownBody .= '<br><b>'.$langs->trans("CurrentTheme").':</b> '.$conf->theme;
  1830. $dropdownBody .= '<br><b>'.$langs->trans("CurrentMenuManager").':</b> '.(isset($menumanager) ? $menumanager->name : 'unknown');
  1831. $langFlag = picto_from_langcode($langs->getDefaultLang());
  1832. $dropdownBody .= '<br><b>'.$langs->trans("CurrentUserLanguage").':</b> '.($langFlag ? $langFlag.' ' : '').$langs->getDefaultLang();
  1833. $tz = (int) $_SESSION['dol_tz'] + (int) $_SESSION['dol_dst'];
  1834. $dropdownBody .= '<br><b>'.$langs->trans("ClientTZ").':</b> '.($tz ? ($tz >= 0 ? '+' : '').$tz : '');
  1835. $dropdownBody .= ' ('.$_SESSION['dol_tz_string'].')';
  1836. //$dropdownBody .= ' &nbsp; &nbsp; &nbsp; '.$langs->trans("DaylingSavingTime").': ';
  1837. //if ($_SESSION['dol_dst'] > 0) $dropdownBody .= yn(1);
  1838. //else $dropdownBody .= yn(0);
  1839. $dropdownBody .= '<br><b>'.$langs->trans("Browser").':</b> '.$conf->browser->name.($conf->browser->version ? ' '.$conf->browser->version : '').' ('.dol_escape_htmltag($_SERVER['HTTP_USER_AGENT']).')';
  1840. $dropdownBody .= '<br><b>'.$langs->trans("Layout").':</b> '.$conf->browser->layout;
  1841. $dropdownBody .= '<br><b>'.$langs->trans("Screen").':</b> '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight'];
  1842. if ($conf->browser->layout == 'phone') {
  1843. $dropdownBody .= '<br><b>'.$langs->trans("Phone").':</b> '.$langs->trans("Yes");
  1844. }
  1845. if (!empty($_SESSION["disablemodules"])) {
  1846. $dropdownBody .= '<br><b>'.$langs->trans("DisabledModules").':</b> <br>'.join(', ', explode(',', $_SESSION["disablemodules"]));
  1847. }
  1848. $dropdownBody .= '</div>';
  1849. // Execute hook
  1850. $parameters = array('user'=>$user, 'langs' => $langs);
  1851. $result = $hookmanager->executeHooks('printTopRightMenuLoginDropdownBody', $parameters); // Note that $action and $object may have been modified by some hooks
  1852. if (is_numeric($result)) {
  1853. if ($result == 0) {
  1854. $dropdownBody .= $hookmanager->resPrint; // add
  1855. } else {
  1856. $dropdownBody = $hookmanager->resPrint; // replace
  1857. }
  1858. }
  1859. if (empty($urllogout)) {
  1860. $urllogout = DOL_URL_ROOT.'/user/logout.php';
  1861. }
  1862. $logoutLink = '<a accesskey="l" href="'.$urllogout.'" class="button-top-menu-dropdown" ><i class="fa fa-sign-out-alt"></i> '.$langs->trans("Logout").'</a>';
  1863. $profilLink = '<a accesskey="l" href="'.DOL_URL_ROOT.'/user/card.php?id='.$user->id.'" class="button-top-menu-dropdown" ><i class="fa fa-user"></i> '.$langs->trans("Card").'</a>';
  1864. $profilName = $user->getFullName($langs).' ('.$user->login.')';
  1865. if (!empty($user->admin)) {
  1866. $profilName = '<i class="far fa-star classfortooltip" title="'.$langs->trans("Administrator").'" ></i> '.$profilName;
  1867. }
  1868. // Define version to show
  1869. $appli = constant('DOL_APPLICATION_TITLE');
  1870. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  1871. $appli = $conf->global->MAIN_APPLICATION_TITLE;
  1872. if (preg_match('/\d\.\d/', $appli)) {
  1873. if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
  1874. $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
  1875. }
  1876. } else {
  1877. $appli .= " ".DOL_VERSION;
  1878. }
  1879. } else {
  1880. $appli .= " ".DOL_VERSION;
  1881. }
  1882. if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  1883. $btnUser = '<!-- div for user link -->
  1884. <div id="topmenu-login-dropdown" class="userimg atoplogin dropdown user user-menu inline-block">
  1885. <a href="'.DOL_URL_ROOT.'/user/card.php?id='.$user->id.'" class="dropdown-toggle login-dropdown-a" data-toggle="dropdown">
  1886. '.$userImage.'<span class="hidden-xs maxwidth200 atoploginusername hideonsmartphone paddingleft">'.dol_trunc($user->firstname ? $user->firstname : $user->login, 10).'</span>
  1887. </a>
  1888. <div class="dropdown-menu">
  1889. <!-- User image -->
  1890. <div class="user-header">
  1891. '.$userDropDownImage.'
  1892. <p>
  1893. '.$profilName.'<br>';
  1894. if ($user->datelastlogin) {
  1895. $title = $langs->trans("ConnectedSince").' : '.dol_print_date($user->datelastlogin, "dayhour", 'tzuser');
  1896. if ($user->datepreviouslogin) {
  1897. $title .= '<br>'.$langs->trans("PreviousConnexion").' : '.dol_print_date($user->datepreviouslogin, "dayhour", 'tzuser');
  1898. }
  1899. }
  1900. $btnUser .= '<small class="classfortooltip" title="'.dol_escape_htmltag($title).'" ><i class="fa fa-user-clock"></i> '.dol_print_date($user->datelastlogin, "dayhour", 'tzuser').'</small><br>';
  1901. if ($user->datepreviouslogin) {
  1902. $btnUser .= '<small class="classfortooltip" title="'.dol_escape_htmltag($title).'" ><i class="fa fa-user-clock opacitymedium"></i> '.dol_print_date($user->datepreviouslogin, "dayhour", 'tzuser').'</small><br>';
  1903. }
  1904. //$btnUser .= '<small class="classfortooltip"><i class="fa fa-cog"></i> '.$langs->trans("Version").' '.$appli.'</small>';
  1905. $btnUser .= '
  1906. </p>
  1907. </div>
  1908. <!-- Menu Body -->
  1909. <div class="user-body">'.$dropdownBody.'</div>
  1910. <!-- Menu Footer-->
  1911. <div class="user-footer">
  1912. <div class="pull-left">
  1913. '.$profilLink.'
  1914. </div>
  1915. <div class="pull-right">
  1916. '.$logoutLink.'
  1917. </div>
  1918. <div style="clear:both;"></div>
  1919. </div>
  1920. </div>
  1921. </div>';
  1922. } else {
  1923. $btnUser = '<!-- div for user link -->
  1924. <div id="topmenu-login-dropdown" class="userimg atoplogin dropdown user user-menu inline-block">
  1925. <a href="'.DOL_URL_ROOT.'/user/card.php?id='.$user->id.'">
  1926. '.$userImage.'
  1927. <span class="hidden-xs maxwidth200 atoploginusername hideonsmartphone">'.dol_trunc($user->firstname ? $user->firstname : $user->login, 10).'</span>
  1928. </a>
  1929. </div>';
  1930. }
  1931. if (!defined('JS_JQUERY_DISABLE_DROPDOWN') && !empty($conf->use_javascript_ajax)) { // This may be set by some pages that use different jquery version to avoid errors
  1932. $btnUser .= '
  1933. <!-- Code to show/hide the user drop-down -->
  1934. <script>
  1935. $( document ).ready(function() {
  1936. $(document).on("click", function(event) {
  1937. if (!$(event.target).closest("#topmenu-login-dropdown").length) {
  1938. //console.log("close login dropdown");
  1939. // Hide the menus.
  1940. $("#topmenu-login-dropdown").removeClass("open");
  1941. }
  1942. });
  1943. ';
  1944. if ($conf->theme != 'md') {
  1945. $btnUser .= '
  1946. $("#topmenu-login-dropdown .dropdown-toggle").on("click", function(event) {
  1947. console.log("toggle login dropdown");
  1948. event.preventDefault();
  1949. $("#topmenu-login-dropdown").toggleClass("open");
  1950. });
  1951. $("#topmenulogincompanyinfo-btn").on("click", function() {
  1952. $("#topmenulogincompanyinfo").slideToggle();
  1953. });
  1954. $("#topmenuloginmoreinfo-btn").on("click", function() {
  1955. $("#topmenuloginmoreinfo").slideToggle();
  1956. });';
  1957. }
  1958. $btnUser .= '
  1959. });
  1960. </script>
  1961. ';
  1962. }
  1963. return $btnUser;
  1964. }
  1965. /**
  1966. * Build the tooltip on top menu quick add
  1967. *
  1968. * @return string HTML content
  1969. */
  1970. function top_menu_quickadd()
  1971. {
  1972. global $langs, $conf, $db, $hookmanager, $user;
  1973. global $menumanager;
  1974. $html = '';
  1975. // Define $dropDownQuickAddHtml
  1976. $dropDownQuickAddHtml = '<div class="dropdown-header bookmark-header center">';
  1977. $dropDownQuickAddHtml .= $langs->trans('QuickAdd');
  1978. $dropDownQuickAddHtml .= '</div>';
  1979. $dropDownQuickAddHtml .= '<div class="quickadd-body dropdown-body">';
  1980. $dropDownQuickAddHtml .= '<div class="quickadd">';
  1981. if (!empty($conf->societe->enabled) && $user->rights->societe->creer) {
  1982. $langs->load("companies");
  1983. $dropDownQuickAddHtml .= '
  1984. <!-- Thirdparty link -->
  1985. <div class="quickaddblock center">
  1986. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/societe/card.php?action=create" title="'.$langs->trans("MenuNewThirdParty").'">
  1987. '. img_picto('', 'object_company') .'<br>'. $langs->trans("ThirdParty") .'</a>
  1988. </div>
  1989. ';
  1990. }
  1991. if (!empty($conf->societe->enabled) && $user->rights->societe->contact->creer) {
  1992. $langs->load("companies");
  1993. $dropDownQuickAddHtml .= '
  1994. <!-- Contact link -->
  1995. <div class="quickaddblock center">
  1996. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/contact/card.php?action=create" title="'.$langs->trans("NewContactAddress").'">
  1997. '. img_picto('', 'object_contact') .'<br>'. $langs->trans("Contact") .'</a>
  1998. </div>
  1999. ';
  2000. }
  2001. if (!empty($conf->propal->enabled) && $user->rights->propale->creer) {
  2002. $langs->load("propal");
  2003. $dropDownQuickAddHtml .= '
  2004. <!-- Propal link -->
  2005. <div class="quickaddblock center">
  2006. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/comm/propal/card.php?action=create" title="'.$langs->trans("NewPropal").'">
  2007. '. img_picto('', 'object_propal') .'<br>'. $langs->trans("Proposal") .'</a>
  2008. </div>
  2009. ';
  2010. }
  2011. if (!empty($conf->commande->enabled) && $user->rights->commande->creer) {
  2012. $langs->load("orders");
  2013. $dropDownQuickAddHtml .= '
  2014. <!-- Order link -->
  2015. <div class="quickaddblock center">
  2016. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/commande/card.php?action=create" title="'.$langs->trans("NewOrder").'">
  2017. '. img_picto('', 'object_order') .'<br>'. $langs->trans("Order") .'</a>
  2018. </div>
  2019. ';
  2020. }
  2021. if (!empty($conf->facture->enabled) && $user->rights->facture->creer) {
  2022. $langs->load("bills");
  2023. $dropDownQuickAddHtml .= '
  2024. <!-- Invoice link -->
  2025. <div class="quickaddblock center">
  2026. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create" title="'.$langs->trans("NewBill").'">
  2027. '. img_picto('', 'object_bill') .'<br>'. $langs->trans("Bill") .'</a>
  2028. </div>
  2029. ';
  2030. }
  2031. if (!empty($conf->contrat->enabled) && $user->rights->contrat->creer) {
  2032. $langs->load("contracts");
  2033. $dropDownQuickAddHtml .= '
  2034. <!-- Contract link -->
  2035. <div class="quickaddblock center">
  2036. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create" title="'.$langs->trans("NewContractSubscription").'">
  2037. '. img_picto('', 'object_contract') .'<br>'. $langs->trans("Contract") .'</a>
  2038. </div>
  2039. ';
  2040. }
  2041. if (!empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->creer) {
  2042. $langs->load("supplier_proposal");
  2043. $dropDownQuickAddHtml .= '
  2044. <!-- Supplier proposal link -->
  2045. <div class="quickaddblock center">
  2046. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/supplier_proposal/card.php?action=create" title="'.$langs->trans("NewAskPrice").'">
  2047. '. img_picto('', 'object_propal') .'<br>'. $langs->trans("AskPrice") .'</a>
  2048. </div>
  2049. ';
  2050. }
  2051. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->commande->creer) || (!empty($conf->supplier_order->enabled) && $user->rights->supplier_order->creer)) {
  2052. $langs->load("orders");
  2053. $dropDownQuickAddHtml .= '
  2054. <!-- Supplier order link -->
  2055. <div class="quickaddblock center">
  2056. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create" title="'.$langs->trans("NewSupplierOrderShort").'">
  2057. '. img_picto('', 'object_order') .'<br>'. $langs->trans("SupplierOrder") .'</a>
  2058. </div>
  2059. ';
  2060. }
  2061. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->creer) || (!empty($conf->supplier_invoice->enabled) && $user->rights->supplier_invoice->creer)) {
  2062. $langs->load("bills");
  2063. $dropDownQuickAddHtml .= '
  2064. <!-- Supplier invoice link -->
  2065. <div class="quickaddblock center">
  2066. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create" title="'.$langs->trans("NewBill").'">
  2067. '. img_picto('', 'object_bill') .'<br>'. $langs->trans("SupplierBill") .'</a>
  2068. </div>
  2069. ';
  2070. }
  2071. if (!empty($conf->product->enabled) && $user->rights->produit->creer) {
  2072. $langs->load("products");
  2073. $dropDownQuickAddHtml .= '
  2074. <!-- Product link -->
  2075. <div class="quickaddblock center">
  2076. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/product/card.php?action=create&amp;type=0" title="'.$langs->trans("NewProduct").'">
  2077. '. img_picto('', 'object_product') .'<br>'. $langs->trans("Product") .'</a>
  2078. </div>
  2079. ';
  2080. }
  2081. if (!empty($conf->service->enabled) && $user->rights->service->creer) {
  2082. $langs->load("products");
  2083. $dropDownQuickAddHtml .= '
  2084. <!-- Service link -->
  2085. <div class="quickaddblock center">
  2086. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/product/card.php?action=create&amp;type=1" title="'.$langs->trans("NewService").'">
  2087. '. img_picto('', 'object_service') .'<br>'. $langs->trans("Service") .'</a>
  2088. </div>
  2089. ';
  2090. }
  2091. if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->creer) {
  2092. $langs->load("trips");
  2093. $dropDownQuickAddHtml .= '
  2094. <!-- Expense report link -->
  2095. <div class="quickaddblock center">
  2096. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/expensereport/card.php?action=create&fk_user_author='.$user->id.'" title="'.$langs->trans("AddTrip").'">
  2097. '. img_picto('', 'object_trip') .'<br>'. $langs->trans("ExpenseReport") .'</a>
  2098. </div>
  2099. ';
  2100. }
  2101. if (!empty($conf->holiday->enabled) && $user->rights->holiday->write) {
  2102. $langs->load("holiday");
  2103. $dropDownQuickAddHtml .= '
  2104. <!-- Holiday link -->
  2105. <div class="quickaddblock center">
  2106. <a class="quickadddropdown-icon-link" href="'.DOL_URL_ROOT.'/holiday/card.php?action=create&fuserid='.$user->id.'" title="'.$langs->trans("AddCP").'">
  2107. '. img_picto('', 'object_holiday') .'<br>'. $langs->trans("Holidays") .'</a>
  2108. </div>
  2109. ';
  2110. }
  2111. // Execute hook printTopRightMenu (hooks should output string like '<div class="login"><a href="">mylink</a></div>')
  2112. $parameters = array();
  2113. $result = $hookmanager->executeHooks('printQuickAddBlock', $parameters); // Note that $action and $object may have been modified by some hooks
  2114. if (is_numeric($result)) {
  2115. if ($result == 0) {
  2116. $dropDownQuickAddHtml .= $hookmanager->resPrint; // add
  2117. } else {
  2118. $dropDownQuickAddHtml = $hookmanager->resPrint; // replace
  2119. }
  2120. } else {
  2121. $dropDownQuickAddHtml .= $result; // For backward compatibility
  2122. }
  2123. $dropDownQuickAddHtml .= '</div>';
  2124. $dropDownQuickAddHtml .= '</div>';
  2125. $html .= '<!-- div for quick add link -->
  2126. <div id="topmenu-quickadd-dropdown" class="atoplogin dropdown inline-block">
  2127. <a class="dropdown-toggle login-dropdown-a" data-toggle="dropdown" href="#" title="'.$langs->trans('QuickAdd').' ('.$langs->trans('QuickAddMenuShortCut').')">
  2128. <i class="fa fa-plus-circle" ></i>
  2129. </a>
  2130. <div class="dropdown-menu">
  2131. '.$dropDownQuickAddHtml.'
  2132. </div>
  2133. </div>';
  2134. $html .= '
  2135. <!-- Code to show/hide the user drop-down -->
  2136. <script>
  2137. $( document ).ready(function() {
  2138. $(document).on("click", function(event) {
  2139. if (!$(event.target).closest("#topmenu-quickadd-dropdown").length) {
  2140. // Hide the menus.
  2141. $("#topmenu-quickadd-dropdown").removeClass("open");
  2142. }
  2143. });
  2144. $("#topmenu-quickadd-dropdown .dropdown-toggle").on("click", function(event) {
  2145. openQuickAddDropDown();
  2146. });
  2147. // Key map shortcut
  2148. $(document).keydown(function(e){
  2149. if( e.which === 76 && e.ctrlKey && e.shiftKey ){
  2150. console.log(\'control + shift + l : trigger open quick add dropdown\');
  2151. openQuickAddDropDown();
  2152. }
  2153. });
  2154. var openQuickAddDropDown = function() {
  2155. event.preventDefault();
  2156. $("#topmenu-quickadd-dropdown").toggleClass("open");
  2157. //$("#top-quickadd-search-input").focus();
  2158. }
  2159. });
  2160. </script>
  2161. ';
  2162. return $html;
  2163. }
  2164. /**
  2165. * Build the tooltip on top menu bookmark
  2166. *
  2167. * @return string HTML content
  2168. */
  2169. function top_menu_bookmark()
  2170. {
  2171. global $langs, $conf, $db, $user;
  2172. $html = '';
  2173. // Define $bookmarks
  2174. if (empty($conf->bookmark->enabled) || empty($user->rights->bookmark->lire)) {
  2175. return $html;
  2176. }
  2177. if (!defined('JS_JQUERY_DISABLE_DROPDOWN') && !empty($conf->use_javascript_ajax)) { // This may be set by some pages that use different jquery version to avoid errors
  2178. include_once DOL_DOCUMENT_ROOT.'/bookmarks/bookmarks.lib.php';
  2179. $langs->load("bookmarks");
  2180. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  2181. $html .= '<div id="topmenu-bookmark-dropdown" class="dropdown inline-block">';
  2182. $html .= printDropdownBookmarksList();
  2183. $html .= '</div>';
  2184. } else {
  2185. $html .= '<!-- div for bookmark link -->
  2186. <div id="topmenu-bookmark-dropdown" class="dropdown inline-block">
  2187. <a class="dropdown-toggle login-dropdown-a" data-toggle="dropdown" href="#" title="'.$langs->trans('Bookmarks').' ('.$langs->trans('BookmarksMenuShortCut').')">
  2188. <i class="fa fa-star" ></i>
  2189. </a>
  2190. <div class="dropdown-menu">
  2191. '.printDropdownBookmarksList().'
  2192. </div>
  2193. </div>';
  2194. $html .= '
  2195. <!-- Code to show/hide the bookmark drop-down -->
  2196. <script>
  2197. $( document ).ready(function() {
  2198. $(document).on("click", function(event) {
  2199. if (!$(event.target).closest("#topmenu-bookmark-dropdown").length) {
  2200. //console.log("close bookmark dropdown - we click outside");
  2201. // Hide the menus.
  2202. $("#topmenu-bookmark-dropdown").removeClass("open");
  2203. }
  2204. });
  2205. $("#topmenu-bookmark-dropdown .dropdown-toggle").on("click", function(event) {
  2206. console.log("toggle bookmark dropdown");
  2207. openBookMarkDropDown();
  2208. });
  2209. // Key map shortcut
  2210. $(document).keydown(function(e){
  2211. if( e.which === 77 && e.ctrlKey && e.shiftKey ){
  2212. console.log(\'control + shift + m : trigger open bookmark dropdown\');
  2213. openBookMarkDropDown();
  2214. }
  2215. });
  2216. var openBookMarkDropDown = function() {
  2217. event.preventDefault();
  2218. $("#topmenu-bookmark-dropdown").toggleClass("open");
  2219. $("#top-bookmark-search-input").focus();
  2220. }
  2221. });
  2222. </script>
  2223. ';
  2224. }
  2225. }
  2226. return $html;
  2227. }
  2228. /**
  2229. * Build the tooltip on top menu tsearch
  2230. *
  2231. * @return string HTML content
  2232. */
  2233. function top_menu_search()
  2234. {
  2235. global $langs, $conf, $db, $user, $hookmanager;
  2236. $html = '';
  2237. $usedbyinclude = 1;
  2238. $arrayresult = null;
  2239. include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php'; // This set $arrayresult
  2240. $defaultAction = '';
  2241. $buttonList = '<div class="dropdown-global-search-button-list" >';
  2242. // Menu with all searchable items
  2243. foreach ($arrayresult as $keyItem => $item) {
  2244. if (empty($defaultAction)) {
  2245. $defaultAction = $item['url'];
  2246. }
  2247. $buttonList .= '<button class="dropdown-item global-search-item" data-target="'.dol_escape_htmltag($item['url']).'" >';
  2248. $buttonList .= $item['text'];
  2249. $buttonList .= '</button>';
  2250. }
  2251. $buttonList .= '</div>';
  2252. $searchInput = '<input name="sall" id="top-global-search-input" class="dropdown-search-input" placeholder="'.$langs->trans('Search').'" autocomplete="off" >';
  2253. $dropDownHtml = '<form id="top-menu-action-search" name="actionsearch" method="GET" action="'.$defaultAction.'" >';
  2254. $dropDownHtml .= '
  2255. <!-- search input -->
  2256. <div class="dropdown-header search-dropdown-header">
  2257. ' . $searchInput.'
  2258. </div>
  2259. ';
  2260. $dropDownHtml .= '
  2261. <!-- Menu Body -->
  2262. <div class="dropdown-body search-dropdown-body">
  2263. '.$buttonList.'
  2264. </div>
  2265. ';
  2266. $dropDownHtml .= '</form>';
  2267. $html .= '<!-- div for Global Search -->
  2268. <div id="topmenu-global-search-dropdown" class="atoplogin dropdown inline-block">
  2269. <a class="dropdown-toggle login-dropdown-a" data-toggle="dropdown" href="#" title="'.$langs->trans('Search').' ('.$langs->trans('SearchMenuShortCut').')">
  2270. <i class="fa fa-search" ></i>
  2271. </a>
  2272. <div class="dropdown-menu dropdown-search">
  2273. '.$dropDownHtml.'
  2274. </div>
  2275. </div>';
  2276. $html .= '
  2277. <!-- Code to show/hide the user drop-down -->
  2278. <script>
  2279. $( document ).ready(function() {
  2280. // prevent submiting form on press ENTER
  2281. $("#top-global-search-input").keydown(function (e) {
  2282. if (e.keyCode == 13) {
  2283. var inputs = $(this).parents("form").eq(0).find(":button");
  2284. if (inputs[inputs.index(this) + 1] != null) {
  2285. inputs[inputs.index(this) + 1].focus();
  2286. }
  2287. e.preventDefault();
  2288. return false;
  2289. }
  2290. });
  2291. // arrow key nav
  2292. $(document).keydown(function(e) {
  2293. // Get the focused element:
  2294. var $focused = $(":focus");
  2295. if($focused.length && $focused.hasClass("global-search-item")){
  2296. // UP - move to the previous line
  2297. if (e.keyCode == 38) {
  2298. e.preventDefault();
  2299. $focused.prev().focus();
  2300. }
  2301. // DOWN - move to the next line
  2302. if (e.keyCode == 40) {
  2303. e.preventDefault();
  2304. $focused.next().focus();
  2305. }
  2306. }
  2307. });
  2308. // submit form action
  2309. $(".dropdown-global-search-button-list .global-search-item").on("click", function(event) {
  2310. $("#top-menu-action-search").attr("action", $(this).data("target"));
  2311. $("#top-menu-action-search").submit();
  2312. });
  2313. // close drop down
  2314. $(document).on("click", function(event) {
  2315. if (!$(event.target).closest("#topmenu-global-search-dropdown").length) {
  2316. console.log("click close search - we click outside");
  2317. // Hide the menus.
  2318. $("#topmenu-global-search-dropdown").removeClass("open");
  2319. }
  2320. });
  2321. // Open drop down
  2322. $("#topmenu-global-search-dropdown .dropdown-toggle").on("click", function(event) {
  2323. console.log("toggle search dropdown");
  2324. openGlobalSearchDropDown();
  2325. });
  2326. // Key map shortcut
  2327. $(document).keydown(function(e){
  2328. if( e.which === 70 && e.ctrlKey && e.shiftKey ){
  2329. console.log(\'control + shift + f : trigger open global-search dropdown\');
  2330. openGlobalSearchDropDown();
  2331. }
  2332. });
  2333. var openGlobalSearchDropDown = function() {
  2334. $("#topmenu-global-search-dropdown").toggleClass("open");
  2335. $("#top-global-search-input").focus();
  2336. }
  2337. });
  2338. </script>
  2339. ';
  2340. return $html;
  2341. }
  2342. /**
  2343. * Show left menu bar
  2344. *
  2345. * @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 ''.
  2346. * @param string $helppagename Name of wiki page for help ('' by default).
  2347. * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
  2348. * For other external page: http://server/url
  2349. * @param string $notused Deprecated. Used in past to add content into left menu. Hooks can be used now.
  2350. * @param array $menu_array_after Table of menu entries to show after entries of menu handler
  2351. * @param int $leftmenuwithoutmainarea Must be set to 1. 0 by default for backward compatibility with old modules.
  2352. * @param string $title Title of web page
  2353. * @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)
  2354. * @return void
  2355. */
  2356. function left_menu($menu_array_before, $helppagename = '', $notused = '', $menu_array_after = '', $leftmenuwithoutmainarea = 0, $title = '', $acceptdelayedhtml = 0)
  2357. {
  2358. global $user, $conf, $langs, $db, $form;
  2359. global $hookmanager, $menumanager;
  2360. $searchform = '';
  2361. $bookmarks = '';
  2362. if (!empty($menu_array_before)) {
  2363. 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);
  2364. }
  2365. if (empty($conf->dol_hide_leftmenu) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) {
  2366. // Instantiate hooks for external modules
  2367. $hookmanager->initHooks(array('searchform', 'leftblock'));
  2368. print "\n".'<!-- Begin side-nav id-left -->'."\n".'<div class="side-nav"><div id="id-left">'."\n";
  2369. if ($conf->browser->layout == 'phone') {
  2370. $conf->global->MAIN_USE_OLD_SEARCH_FORM = 1; // Select into select2 is awfull on smartphone. TODO Is this still true with select2 v4 ?
  2371. }
  2372. print "\n";
  2373. if (!is_object($form)) {
  2374. $form = new Form($db);
  2375. }
  2376. $selected = -1;
  2377. if (empty($conf->global->MAIN_USE_TOP_MENU_SEARCH_DROPDOWN)) {
  2378. $usedbyinclude = 1;
  2379. $arrayresult = null;
  2380. include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php'; // This set $arrayresult
  2381. if ($conf->use_javascript_ajax && empty($conf->global->MAIN_USE_OLD_SEARCH_FORM)) {
  2382. $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);
  2383. } else {
  2384. if (is_array($arrayresult)) {
  2385. foreach ($arrayresult as $key => $val) {
  2386. $searchform .= printSearchForm($val['url'], $val['url'], $val['label'], 'maxwidth125', 'sall', $val['shortcut'], 'searchleft'.$key, $val['img']);
  2387. }
  2388. }
  2389. }
  2390. // Execute hook printSearchForm
  2391. $parameters = array('searchform' => $searchform);
  2392. $reshook = $hookmanager->executeHooks('printSearchForm', $parameters); // Note that $action and $object may have been modified by some hooks
  2393. if (empty($reshook)) {
  2394. $searchform .= $hookmanager->resPrint;
  2395. } else {
  2396. $searchform = $hookmanager->resPrint;
  2397. }
  2398. // Force special value for $searchform
  2399. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) || empty($conf->use_javascript_ajax)) {
  2400. $urltosearch = DOL_URL_ROOT.'/core/search_page.php?showtitlebefore=1';
  2401. $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>';
  2402. } elseif ($conf->use_javascript_ajax && !empty($conf->global->MAIN_USE_OLD_SEARCH_FORM)) {
  2403. $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>';
  2404. $searchform .= '<script>
  2405. jQuery(document).ready(function () {
  2406. jQuery("#divsearchforms1").click(function(){
  2407. jQuery("#divsearchforms2").toggle();
  2408. });
  2409. });
  2410. </script>' . "\n";
  2411. $searchform .= '</div>';
  2412. }
  2413. }
  2414. // Left column
  2415. print '<!-- Begin left menu -->'."\n";
  2416. print '<div class="vmenu"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '' : ' title="Left menu"').'>'."\n\n";
  2417. // Show left menu with other forms
  2418. $menumanager->menu_array = $menu_array_before;
  2419. $menumanager->menu_array_after = $menu_array_after;
  2420. $menumanager->showmenu('left', array('searchform'=>$searchform, 'bookmarks'=>$bookmarks)); // output menu_array and menu found in database
  2421. // Dolibarr version + help + bug report link
  2422. print "\n";
  2423. print "<!-- Begin Help Block-->\n";
  2424. print '<div id="blockvmenuhelp" class="blockvmenuhelp">'."\n";
  2425. // Version
  2426. if (!empty($conf->global->MAIN_SHOW_VERSION)) { // Version is already on help picto and on login page.
  2427. $doliurl = 'https://www.dolibarr.org';
  2428. //local communities
  2429. if (preg_match('/fr/i', $langs->defaultlang)) {
  2430. $doliurl = 'https://www.dolibarr.fr';
  2431. }
  2432. if (preg_match('/es/i', $langs->defaultlang)) {
  2433. $doliurl = 'https://www.dolibarr.es';
  2434. }
  2435. if (preg_match('/de/i', $langs->defaultlang)) {
  2436. $doliurl = 'https://www.dolibarr.de';
  2437. }
  2438. if (preg_match('/it/i', $langs->defaultlang)) {
  2439. $doliurl = 'https://www.dolibarr.it';
  2440. }
  2441. if (preg_match('/gr/i', $langs->defaultlang)) {
  2442. $doliurl = 'https://www.dolibarr.gr';
  2443. }
  2444. $appli = constant('DOL_APPLICATION_TITLE');
  2445. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  2446. $appli = $conf->global->MAIN_APPLICATION_TITLE; $doliurl = '';
  2447. if (preg_match('/\d\.\d/', $appli)) {
  2448. if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
  2449. $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
  2450. }
  2451. } else {
  2452. $appli .= " ".DOL_VERSION;
  2453. }
  2454. } else {
  2455. $appli .= " ".DOL_VERSION;
  2456. }
  2457. print '<div id="blockvmenuhelpapp" class="blockvmenuhelp">';
  2458. if ($doliurl) {
  2459. print '<a class="help" target="_blank" rel="noopener" href="'.$doliurl.'">';
  2460. } else {
  2461. print '<span class="help">';
  2462. }
  2463. print $appli;
  2464. if ($doliurl) {
  2465. print '</a>';
  2466. } else {
  2467. print '</span>';
  2468. }
  2469. print '</div>'."\n";
  2470. }
  2471. // Link to bugtrack
  2472. if (!empty($conf->global->MAIN_BUGTRACK_ENABLELINK)) {
  2473. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  2474. if ($conf->global->MAIN_BUGTRACK_ENABLELINK == 'github') {
  2475. $bugbaseurl = 'https://github.com/Dolibarr/dolibarr/issues/new?labels=Bug';
  2476. $bugbaseurl .= '&title=';
  2477. $bugbaseurl .= urlencode("Bug: ");
  2478. $bugbaseurl .= '&body=';
  2479. $bugbaseurl .= urlencode("# Instructions\n");
  2480. $bugbaseurl .= urlencode("*This is a template to help you report good issues. You may use [Github Markdown](https://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/) syntax to format your issue report.*\n");
  2481. $bugbaseurl .= urlencode("*Please:*\n");
  2482. $bugbaseurl .= urlencode("- *replace the bracket enclosed texts with meaningful information*\n");
  2483. $bugbaseurl .= urlencode("- *remove any unused sub-section*\n");
  2484. $bugbaseurl .= urlencode("\n");
  2485. $bugbaseurl .= urlencode("\n");
  2486. $bugbaseurl .= urlencode("# Bug\n");
  2487. $bugbaseurl .= urlencode("[*Short description*]\n");
  2488. $bugbaseurl .= urlencode("\n");
  2489. $bugbaseurl .= urlencode("## Environment\n");
  2490. $bugbaseurl .= urlencode("- **Version**: " . DOL_VERSION . "\n");
  2491. $bugbaseurl .= urlencode("- **OS**: " . php_uname('s') . "\n");
  2492. $bugbaseurl .= urlencode("- **Web server**: " . $_SERVER["SERVER_SOFTWARE"] . "\n");
  2493. $bugbaseurl .= urlencode("- **PHP**: " . php_sapi_name() . ' ' . phpversion() . "\n");
  2494. $bugbaseurl .= urlencode("- **Database**: " . $db::LABEL . ' ' . $db->getVersion() . "\n");
  2495. $bugbaseurl .= urlencode("- **URL(s)**: " . $_SERVER["REQUEST_URI"] . "\n");
  2496. $bugbaseurl .= urlencode("\n");
  2497. $bugbaseurl .= urlencode("## Expected and actual behavior\n");
  2498. $bugbaseurl .= urlencode("[*Verbose description*]\n");
  2499. $bugbaseurl .= urlencode("\n");
  2500. $bugbaseurl .= urlencode("## Steps to reproduce the behavior\n");
  2501. $bugbaseurl .= urlencode("[*Verbose description*]\n");
  2502. $bugbaseurl .= urlencode("\n");
  2503. $bugbaseurl .= urlencode("## [Attached files](https://help.github.com/articles/issue-attachments) (Screenshots, screencasts, dolibarr.log, debugging informations…)\n");
  2504. $bugbaseurl .= urlencode("[*Files*]\n");
  2505. $bugbaseurl .= urlencode("\n");
  2506. $bugbaseurl .= urlencode("\n");
  2507. $bugbaseurl .= urlencode("## Report\n");
  2508. } elseif (!empty($conf->global->MAIN_BUGTRACK_ENABLELINK)) {
  2509. $bugbaseurl = $conf->global->MAIN_BUGTRACK_ENABLELINK;
  2510. } else {
  2511. $bugbaseurl = "";
  2512. }
  2513. // Execute hook printBugtrackInfo
  2514. $parameters = array('bugbaseurl' => $bugbaseurl);
  2515. $reshook = $hookmanager->executeHooks('printBugtrackInfo', $parameters); // Note that $action and $object may have been modified by some hooks
  2516. if (empty($reshook)) {
  2517. $bugbaseurl .= $hookmanager->resPrint;
  2518. } else {
  2519. $bugbaseurl = $hookmanager->resPrint;
  2520. }
  2521. print '<div id="blockvmenuhelpbugreport" class="blockvmenuhelp">';
  2522. print '<a class="help" target="_blank" rel="noopener" href="'.$bugbaseurl.'">'.$langs->trans("FindBug").'</a>';
  2523. print '</div>';
  2524. }
  2525. print "</div>\n";
  2526. print "<!-- End Help Block-->\n";
  2527. print "\n";
  2528. print "</div>\n";
  2529. print "<!-- End left menu -->\n";
  2530. print "\n";
  2531. // Execute hook printLeftBlock
  2532. $parameters = array();
  2533. $reshook = $hookmanager->executeHooks('printLeftBlock', $parameters); // Note that $action and $object may have been modified by some hooks
  2534. print $hookmanager->resPrint;
  2535. print '</div></div> <!-- End side-nav id-left -->'; // End div id="side-nav" div id="id-left"
  2536. }
  2537. print "\n";
  2538. print '<!-- Begin right area -->'."\n";
  2539. if (empty($leftmenuwithoutmainarea)) {
  2540. main_area($title);
  2541. }
  2542. }
  2543. /**
  2544. * Begin main area
  2545. *
  2546. * @param string $title Title
  2547. * @return void
  2548. */
  2549. function main_area($title = '')
  2550. {
  2551. global $conf, $langs;
  2552. if (empty($conf->dol_hide_leftmenu)) {
  2553. print '<div id="id-right">';
  2554. }
  2555. print "\n";
  2556. print '<!-- Begin div class="fiche" -->'."\n".'<div class="fiche">'."\n";
  2557. if (!empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) {
  2558. print info_admin($langs->trans("WarningYouAreInMaintenanceMode", $conf->global->MAIN_ONLY_LOGIN_ALLOWED), 0, 0, 1, 'warning maintenancemode');
  2559. }
  2560. // Permit to add user company information on each printed document by setting SHOW_SOCINFO_ON_PRINT
  2561. if (!empty($conf->global->SHOW_SOCINFO_ON_PRINT) && GETPOST('optioncss', 'aZ09') == 'print' && empty(GETPOST('disable_show_socinfo_on_print', 'az09'))) {
  2562. global $hookmanager;
  2563. $hookmanager->initHooks(array('main'));
  2564. $parameters = array();
  2565. $reshook = $hookmanager->executeHooks('showSocinfoOnPrint', $parameters);
  2566. if (empty($reshook)) {
  2567. print '<!-- Begin show mysoc info header -->'."\n";
  2568. print '<div id="mysoc-info-header">'."\n";
  2569. print '<table class="centpercent div-table-responsive">'."\n";
  2570. print '<tbody>';
  2571. print '<tr><td rowspan="0" class="width20p">';
  2572. if ($conf->global->MAIN_SHOW_LOGO && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && !empty($conf->global->MAIN_INFO_SOCIETE_LOGO)) {
  2573. print '<img id="mysoc-info-header-logo" style="max-width:100%" alt="" src="'.DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_LOGO)).'">';
  2574. }
  2575. print '</td><td rowspan="0" class="width50p"></td></tr>'."\n";
  2576. print '<tr><td class="titre bold">'.dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_NOM).'</td></tr>'."\n";
  2577. print '<tr><td>'.dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_ADDRESS).'<br>'.dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_ZIP).' '.dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_TOWN).'</td></tr>'."\n";
  2578. if (!empty($conf->global->MAIN_INFO_SOCIETE_TEL)) {
  2579. print '<tr><td style="padding-left: 1em" class="small">'.$langs->trans("Phone").' : '.dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_TEL).'</td></tr>';
  2580. }
  2581. if (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL)) {
  2582. print '<tr><td style="padding-left: 1em" class="small">'.$langs->trans("Email").' : '.dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_MAIL).'</td></tr>';
  2583. }
  2584. if (!empty($conf->global->MAIN_INFO_SOCIETE_WEB)) {
  2585. print '<tr><td style="padding-left: 1em" class="small">'.$langs->trans("Web").' : '.dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_WEB).'</td></tr>';
  2586. }
  2587. print '</tbody>';
  2588. print '</table>'."\n";
  2589. print '</div>'."\n";
  2590. print '<!-- End show mysoc info header -->'."\n";
  2591. }
  2592. }
  2593. }
  2594. /**
  2595. * Return helpbaseurl, helppage and mode
  2596. *
  2597. * @param string $helppagename Page name ('EN:xxx,ES:eee,FR:fff...' or 'http://localpage')
  2598. * @param Translate $langs Language
  2599. * @return array Array of help urls
  2600. */
  2601. function getHelpParamFor($helppagename, $langs)
  2602. {
  2603. $helpbaseurl = '';
  2604. $helppage = '';
  2605. $mode = '';
  2606. if (preg_match('/^http/i', $helppagename)) {
  2607. // If complete URL
  2608. $helpbaseurl = '%s';
  2609. $helppage = $helppagename;
  2610. $mode = 'local';
  2611. } else {
  2612. // If WIKI URL
  2613. $reg = array();
  2614. if (preg_match('/^es/i', $langs->defaultlang)) {
  2615. $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
  2616. if (preg_match('/ES:([^|]+)/i', $helppagename, $reg)) {
  2617. $helppage = $reg[1];
  2618. }
  2619. }
  2620. if (preg_match('/^fr/i', $langs->defaultlang)) {
  2621. $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
  2622. if (preg_match('/FR:([^|]+)/i', $helppagename, $reg)) {
  2623. $helppage = $reg[1];
  2624. }
  2625. }
  2626. if (empty($helppage)) { // If help page not already found
  2627. $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
  2628. if (preg_match('/EN:([^|]+)/i', $helppagename, $reg)) {
  2629. $helppage = $reg[1];
  2630. }
  2631. }
  2632. $mode = 'wiki';
  2633. }
  2634. return array('helpbaseurl'=>$helpbaseurl, 'helppage'=>$helppage, 'mode'=>$mode);
  2635. }
  2636. /**
  2637. * Show a search area.
  2638. * Used when the javascript quick search is not used.
  2639. *
  2640. * @param string $urlaction Url post
  2641. * @param string $urlobject Url of the link under the search box
  2642. * @param string $title Title search area
  2643. * @param string $htmlmorecss Add more css
  2644. * @param string $htmlinputname Field Name input form
  2645. * @param string $accesskey Accesskey
  2646. * @param string $prefhtmlinputname Complement for id to avoid multiple same id in the page
  2647. * @param string $img Image to use
  2648. * @param string $showtitlebefore Show title before input text instead of into placeholder. This can be set when output is dedicated for text browsers.
  2649. * @param string $autofocus Set autofocus on field
  2650. * @return string
  2651. */
  2652. function printSearchForm($urlaction, $urlobject, $title, $htmlmorecss, $htmlinputname, $accesskey = '', $prefhtmlinputname = '', $img = '', $showtitlebefore = 0, $autofocus = 0)
  2653. {
  2654. global $conf, $langs, $user;
  2655. $ret = '';
  2656. $ret .= '<form action="'.$urlaction.'" method="post" class="searchform nowraponall tagtr">';
  2657. $ret .= '<input type="hidden" name="token" value="'.newToken().'">';
  2658. $ret .= '<input type="hidden" name="mode" value="search">';
  2659. $ret .= '<input type="hidden" name="savelogin" value="'.dol_escape_htmltag($user->login).'">';
  2660. if ($showtitlebefore) {
  2661. $ret .= '<div class="tagtd left">'.$title.'</div> ';
  2662. }
  2663. $ret .= '<div class="tagtd">';
  2664. $ret .= img_picto('', $img, '', false, 0, 0, '', 'paddingright width20');
  2665. $ret .= '<input type="text" class="flat '.$htmlmorecss.'"';
  2666. $ret .= ' style="background-repeat: no-repeat; background-position: 3px;"';
  2667. $ret .= ($accesskey ? ' accesskey="'.$accesskey.'"' : '');
  2668. $ret .= ' placeholder="'.strip_tags($title).'"';
  2669. $ret .= ($autofocus ? ' autofocus' : '');
  2670. $ret .= ' name="'.$htmlinputname.'" id="'.$prefhtmlinputname.$htmlinputname.'" />';
  2671. $ret .= '<button type="submit" class="button bordertransp" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">';
  2672. $ret .= '<span class="fa fa-search"></span>';
  2673. $ret .= '</button>';
  2674. $ret .= '</div>';
  2675. $ret .= "</form>\n";
  2676. return $ret;
  2677. }
  2678. if (!function_exists("llxFooter")) {
  2679. /**
  2680. * Show HTML footer
  2681. * Close div /DIV class=fiche + /DIV id-right + /DIV id-container + /BODY + /HTML.
  2682. * If global var $delayedhtmlcontent was filled, we output it just before closing the body.
  2683. *
  2684. * @param string $comment A text to add as HTML comment into HTML generated page
  2685. * @param string $zone 'private' (for private pages) or 'public' (for public pages)
  2686. * @param int $disabledoutputofmessages Clear all messages stored into session without diplaying them
  2687. * @return void
  2688. */
  2689. function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0)
  2690. {
  2691. global $conf, $db, $langs, $user, $mysoc, $object;
  2692. global $delayedhtmlcontent;
  2693. global $contextpage, $page, $limit;
  2694. global $dolibarr_distrib;
  2695. $ext = 'layout='.$conf->browser->layout.'&version='.urlencode(DOL_VERSION);
  2696. // Global html output events ($mesgs, $errors, $warnings)
  2697. dol_htmloutput_events($disabledoutputofmessages);
  2698. // Code for search criteria persistence.
  2699. // $user->lastsearch_values was set by the GETPOST when form field search_xxx exists
  2700. if (is_object($user) && !empty($user->lastsearch_values_tmp) && is_array($user->lastsearch_values_tmp)) {
  2701. // Clean and save data
  2702. foreach ($user->lastsearch_values_tmp as $key => $val) {
  2703. unset($_SESSION['lastsearch_values_tmp_'.$key]); // Clean array to rebuild it just after
  2704. if (count($val) && empty($_POST['button_removefilter'])) { // If there is search criteria to save and we did not click on 'Clear filter' button
  2705. if (empty($val['sortfield'])) {
  2706. unset($val['sortfield']);
  2707. }
  2708. if (empty($val['sortorder'])) {
  2709. unset($val['sortorder']);
  2710. }
  2711. dol_syslog('Save lastsearch_values_tmp_'.$key.'='.json_encode($val, 0)." (systematic recording of last search criterias)");
  2712. $_SESSION['lastsearch_values_tmp_'.$key] = json_encode($val);
  2713. unset($_SESSION['lastsearch_values_'.$key]);
  2714. }
  2715. }
  2716. }
  2717. $relativepathstring = $_SERVER["PHP_SELF"];
  2718. // Clean $relativepathstring
  2719. if (constant('DOL_URL_ROOT')) {
  2720. $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
  2721. }
  2722. $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
  2723. $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
  2724. if (preg_match('/list\.php$/', $relativepathstring)) {
  2725. unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]);
  2726. unset($_SESSION['lastsearch_page_tmp_'.$relativepathstring]);
  2727. unset($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]);
  2728. if (!empty($contextpage)) {
  2729. $_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring] = $contextpage;
  2730. }
  2731. if (!empty($page) && $page > 0) {
  2732. $_SESSION['lastsearch_page_tmp_'.$relativepathstring] = $page;
  2733. }
  2734. if (!empty($limit) && $limit != $conf->liste_limit) {
  2735. $_SESSION['lastsearch_limit_tmp_'.$relativepathstring] = $limit;
  2736. }
  2737. unset($_SESSION['lastsearch_contextpage_'.$relativepathstring]);
  2738. unset($_SESSION['lastsearch_page_'.$relativepathstring]);
  2739. unset($_SESSION['lastsearch_limit_'.$relativepathstring]);
  2740. }
  2741. // Core error message
  2742. if (!empty($conf->global->MAIN_CORE_ERROR)) {
  2743. // Ajax version
  2744. if ($conf->use_javascript_ajax) {
  2745. $title = img_warning().' '.$langs->trans('CoreErrorTitle');
  2746. print ajax_dialog($title, $langs->trans('CoreErrorMessage'));
  2747. } else {
  2748. // html version
  2749. $msg = img_warning().' '.$langs->trans('CoreErrorMessage');
  2750. print '<div class="error">'.$msg.'</div>';
  2751. }
  2752. //define("MAIN_CORE_ERROR",0); // Constant was defined and we can't change value of a constant
  2753. }
  2754. print "\n\n";
  2755. print '</div> <!-- End div class="fiche" -->'."\n"; // End div fiche
  2756. if (empty($conf->dol_hide_leftmenu)) {
  2757. print '</div> <!-- End div id-right -->'."\n"; // End div id-right
  2758. }
  2759. if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) {
  2760. print '</div> <!-- End div id-container -->'."\n"; // End div container
  2761. }
  2762. print "\n";
  2763. if ($comment) {
  2764. print '<!-- '.$comment.' -->'."\n";
  2765. }
  2766. printCommonFooter($zone);
  2767. if (!empty($delayedhtmlcontent)) {
  2768. print $delayedhtmlcontent;
  2769. }
  2770. if (!empty($conf->use_javascript_ajax)) {
  2771. print "\n".'<!-- Includes JS Footer of Dolibarr -->'."\n";
  2772. print '<script src="'.DOL_URL_ROOT.'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.($ext ? '&'.$ext : '').'"></script>'."\n";
  2773. }
  2774. // Wrapper to add log when clicking on download or preview
  2775. if (!empty($conf->blockedlog->enabled) && is_object($object) && !empty($object->id) && $object->id > 0 && $object->statut > 0) {
  2776. if (in_array($object->element, array('facture'))) { // Restrict for the moment to element 'facture'
  2777. print "\n<!-- JS CODE TO ENABLE log when making a download or a preview of a document -->\n";
  2778. ?>
  2779. <script>
  2780. jQuery(document).ready(function () {
  2781. $('a.documentpreview').click(function() {
  2782. $.post('<?php echo DOL_URL_ROOT."/blockedlog/ajax/block-add.php" ?>'
  2783. , {
  2784. id:<?php echo $object->id; ?>
  2785. , element:'<?php echo $object->element ?>'
  2786. , action:'DOC_PREVIEW'
  2787. }
  2788. );
  2789. });
  2790. $('a.documentdownload').click(function() {
  2791. $.post('<?php echo DOL_URL_ROOT."/blockedlog/ajax/block-add.php" ?>'
  2792. , {
  2793. id:<?php echo $object->id; ?>
  2794. , element:'<?php echo $object->element ?>'
  2795. , action:'DOC_DOWNLOAD'
  2796. }
  2797. );
  2798. });
  2799. });
  2800. </script>
  2801. <?php
  2802. }
  2803. }
  2804. // A div for the address popup
  2805. print "\n<!-- A div to allow dialog popup -->\n";
  2806. print '<div id="dialogforpopup" style="display: none;"></div>'."\n";
  2807. // Add code for the asynchronous anonymous first ping (for telemetry)
  2808. // You can use &forceping=1 in parameters to force the ping if the ping was already sent.
  2809. $forceping = GETPOST('forceping', 'alpha');
  2810. if (($_SERVER["PHP_SELF"] == DOL_URL_ROOT.'/index.php') || $forceping) {
  2811. //print '<!-- instance_unique_id='.$conf->file->instance_unique_id.' MAIN_FIRST_PING_OK_ID='.$conf->global->MAIN_FIRST_PING_OK_ID.' -->';
  2812. $hash_unique_id = md5('dolibarr'.$conf->file->instance_unique_id);
  2813. if (empty($conf->global->MAIN_FIRST_PING_OK_DATE)
  2814. || (!empty($conf->file->instance_unique_id) && ($hash_unique_id != $conf->global->MAIN_FIRST_PING_OK_ID) && ($conf->global->MAIN_FIRST_PING_OK_ID != 'disabled'))
  2815. || $forceping) {
  2816. // No ping done if we are into an alpha version
  2817. if (strpos('alpha', DOL_VERSION) > 0 && !$forceping) {
  2818. print "\n<!-- NO JS CODE TO ENABLE the anonymous Ping. It is an alpha version -->\n";
  2819. } elseif (empty($_COOKIE['DOLINSTALLNOPING_'.$hash_unique_id]) || $forceping) { // Cookie is set when we uncheck the checkbox in the installation wizard.
  2820. // MAIN_LAST_PING_KO_DATE
  2821. // Disable ping if MAIN_LAST_PING_KO_DATE is set and is recent
  2822. if (!empty($conf->global->MAIN_LAST_PING_KO_DATE) && substr($conf->global->MAIN_LAST_PING_KO_DATE, 0, 6) == dol_print_date(dol_now(), '%Y%m') && !$forceping) {
  2823. print "\n<!-- NO JS CODE TO ENABLE the anonymous Ping. An error already occured this month, we will try later. -->\n";
  2824. } else {
  2825. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  2826. print "\n".'<!-- Includes JS for Ping of Dolibarr forceping='.$forceping.' MAIN_FIRST_PING_OK_DATE='.getDolGlobalString("MAIN_FIRST_PING_OK_DATE").' MAIN_FIRST_PING_OK_ID='.getDolGlobalString("MAIN_FIRST_PING_OK_ID").' MAIN_LAST_PING_KO_DATE='.getDolGlobalString("MAIN_LAST_PING_KO_DATE").' -->'."\n";
  2827. print "\n<!-- JS CODE TO ENABLE the anonymous Ping -->\n";
  2828. $url_for_ping = (empty($conf->global->MAIN_URL_FOR_PING) ? "https://ping.dolibarr.org/" : $conf->global->MAIN_URL_FOR_PING);
  2829. // Try to guess the distrib used
  2830. $distrib = 'standard';
  2831. if ($_SERVER["SERVER_ADMIN"] == 'doliwamp@localhost') {
  2832. $distrib = 'doliwamp';
  2833. }
  2834. if (!empty($dolibarr_distrib)) {
  2835. $distrib = $dolibarr_distrib;
  2836. }
  2837. ?>
  2838. <script>
  2839. jQuery(document).ready(function (tmp) {
  2840. $.ajax({
  2841. method: "POST",
  2842. url: "<?php echo $url_for_ping ?>",
  2843. timeout: 500, // timeout milliseconds
  2844. cache: false,
  2845. data: {
  2846. hash_algo: 'md5',
  2847. hash_unique_id: '<?php echo dol_escape_js($hash_unique_id); ?>',
  2848. action: 'dolibarrping',
  2849. version: '<?php echo (float) DOL_VERSION; ?>',
  2850. entity: '<?php echo (int) $conf->entity; ?>',
  2851. dbtype: '<?php echo dol_escape_js($db->type); ?>',
  2852. country_code: '<?php echo $mysoc->country_code ? dol_escape_js($mysoc->country_code) : 'unknown'; ?>',
  2853. php_version: '<?php echo dol_escape_js(phpversion()); ?>',
  2854. os_version: '<?php echo dol_escape_js(version_os('smr')); ?>',
  2855. distrib: '<?php echo $distrib ? dol_escape_js($distrib) : 'unknown'; ?>',
  2856. token: 'notrequired'
  2857. },
  2858. success: function (data, status, xhr) { // success callback function (data contains body of response)
  2859. console.log("Ping ok");
  2860. $.ajax({
  2861. method: 'GET',
  2862. url: '<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>',
  2863. timeout: 500, // timeout milliseconds
  2864. cache: false,
  2865. data: { hash_algo: 'md5', hash_unique_id: '<?php echo dol_escape_js($hash_unique_id); ?>', action: 'firstpingok', token: 'notrequired' }, // for update
  2866. });
  2867. },
  2868. error: function (data,status,xhr) { // error callback function
  2869. console.log("Ping ko: " + data);
  2870. $.ajax({
  2871. method: 'GET',
  2872. url: '<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>',
  2873. timeout: 500, // timeout milliseconds
  2874. cache: false,
  2875. data: { hash_algo: 'md5', hash_unique_id: '<?php echo dol_escape_js($hash_unique_id); ?>', action: 'firstpingko', token: 'notrequired' },
  2876. });
  2877. }
  2878. });
  2879. });
  2880. </script>
  2881. <?php
  2882. }
  2883. } else {
  2884. $now = dol_now();
  2885. print "\n<!-- NO JS CODE TO ENABLE the anonymous Ping. It was disabled -->\n";
  2886. include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  2887. dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_DATE', dol_print_date($now, 'dayhourlog', 'gmt'), 'chaine', 0, '', $conf->entity);
  2888. dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_ID', 'disabled', 'chaine', 0, '', $conf->entity);
  2889. }
  2890. }
  2891. }
  2892. print "</body>\n";
  2893. print "</html>\n";
  2894. }
  2895. }