main.inc.php 92 KB

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