dolibarr 25.0.0-alpha
admin.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2016 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2012 J. Fernando Lagrange <fernando@demo-tic.org>
5 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
6 * Copyright (C) 2023 Eric Seigne <eric.seigne@cap-rel.fr>
7 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 * or see https://www.gnu.org/
24 */
25
31require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
32
40function versiontostring($versionarray)
41{
42 $string = '?';
43 if (isset($versionarray[0])) {
44 $string = $versionarray[0];
45 }
46 if (isset($versionarray[1])) {
47 $string .= '.'.$versionarray[1];
48 }
49 if (isset($versionarray[2])) {
50 $string .= '.'.$versionarray[2];
51 }
52 return $string;
53}
54
72function versioncompare($versionarray1, $versionarray2)
73{
74 $ret = 0;
75 $level = 0;
76 $count1 = count($versionarray1);
77 $count2 = count($versionarray2);
78 $maxcount = max($count1, $count2);
79 while ($level < $maxcount) {
80 $operande1 = isset($versionarray1[$level]) ? $versionarray1[$level] : 0;
81 $operande2 = isset($versionarray2[$level]) ? $versionarray2[$level] : 0;
82 if (preg_match('/alpha|dev/i', $operande1)) {
83 $operande1 = -5;
84 }
85 if (preg_match('/alpha|dev/i', $operande2)) {
86 $operande2 = -5;
87 }
88 if (preg_match('/beta$/i', $operande1)) {
89 $operande1 = -4;
90 }
91 if (preg_match('/beta$/i', $operande2)) {
92 $operande2 = -4;
93 }
94 if (preg_match('/beta([0-9])+/i', $operande1)) {
95 $operande1 = -3;
96 }
97 if (preg_match('/beta([0-9])+/i', $operande2)) {
98 $operande2 = -3;
99 }
100 if (preg_match('/rc$/i', $operande1)) {
101 $operande1 = -2;
102 }
103 if (preg_match('/rc$/i', $operande2)) {
104 $operande2 = -2;
105 }
106 if (preg_match('/rc([0-9])+/i', $operande1)) {
107 $operande1 = -1;
108 }
109 if (preg_match('/rc([0-9])+/i', $operande2)) {
110 $operande2 = -1;
111 }
112 $level++;
113 //print 'level '.$level.' '.$operande1.'-'.$operande2.'<br>';
114 if ($operande1 < $operande2) {
115 $ret = -$level;
116 break;
117 }
118 if ($operande1 > $operande2) {
119 $ret = $level;
120 break;
121 }
122 }
123 //print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret.'<br>'."\n";
124 return $ret; // return level=1 if difference is on the main version, level=2 on minor version, level=3 on maintenance version, level=4 on development phase version
125}
126
127
135{
136 return explode('.', PHP_VERSION);
137}
138
146{
147 return preg_split('/[\-\.]/', DOL_VERSION);
148}
149
150
174function run_sql($sqlfile, $silent = 1, $entity = 0, $usesavepoint = 1, $handler = '', $okerror = 'default', $linelengthlimit = 32768, $nocommentremoval = 0, $offsetforchartofaccount = 0, $colspan = 0, $onlysqltoimportwebsite = 0, $database = '')
175{
176 global $db, $conf, $langs;
177
178 dol_syslog("Admin.lib::run_sql run sql file ".$sqlfile." silent=".$silent." entity=".$entity." usesavepoint=".$usesavepoint." handler=".$handler." okerror=".$okerror, LOG_DEBUG);
179
180 if (!is_numeric($linelengthlimit)) {
181 dol_syslog("Admin.lib::run_sql param linelengthlimit is not a numeric", LOG_ERR);
182 return -1;
183 }
184
185 $ok = 0;
186 $error = 0;
187 $i = 0;
188 $buffer = '';
189 $arraysql = array();
190
191 // Get version of database
192 $versionarray = $db->getVersionArray();
193
194 // TODO Restore all sequences "/* new line */\n" into "" in $sqlfile.
195
196 $fp = fopen($sqlfile, "r");
197 if ($fp) {
198 while (!feof($fp)) {
199 // Warning fgets with second parameter that is null or 0 hang.
200 if ($linelengthlimit > 0) {
201 $buf = fgets($fp, $linelengthlimit);
202 } else {
203 $buf = fgets($fp);
204 }
205
206 // Test if request must be ran only for particular database or version (if yes, we must remove the -- comment)
207 $reg = array();
208 if (preg_match('/^--\sV(MYSQL|PGSQL)([^\s]*)/i', $buf, $reg)) {
209 $qualified = 1;
210
211 // restrict on database type
212 if (!empty($reg[1])) {
213 if (!preg_match('/'.preg_quote($reg[1], '/').'/i', $db->type)) {
214 $qualified = 0;
215 }
216 }
217
218 // restrict on version
219 if ($qualified) {
220 if (!empty($reg[2])) {
221 if (is_numeric($reg[2])) { // This is a version
222 $versionrequest = explode('.', $reg[2]);
223 if (!count($versionrequest) || !count($versionarray) || versioncompare($versionrequest, $versionarray) > 0) {
224 $qualified = 0;
225 }
226 } else { // This is a test on a constant. For example when we have -- VMYSQLUTF8UNICODE, we test constant $conf->global->UTF8UNICODE
227 $dbcollation = strtoupper(preg_replace('/_/', '', $conf->db->dolibarr_main_db_collation));
228 if (empty($conf->db->dolibarr_main_db_collation) || ($reg[2] != $dbcollation)) {
229 $qualified = 0;
230 }
231 }
232 }
233 }
234
235 if ($qualified) {
236 // Version qualified, delete SQL comments
237 $buf = preg_replace('/^--\sV(MYSQL|PGSQL)([^\s]*)/i', '', $buf);
238 //print "Line $i qualified by version: ".$buf.'<br>';
239 }
240 }
241
242 // Add line buf to buffer if not a comment
243 if ($nocommentremoval || !preg_match('/^\s*--/', $buf)) {
244 if (empty($nocommentremoval)) {
245 $buf = preg_replace('/([,;ERLT05\‍)])\s+--\s.*$/i', '\1', $buf); // remove comment on lines that does not start with --, like "... -- a comment"
246 $buf = preg_replace('/([,;ERLT05\‍)])\s+--$/i', '\1', $buf); // remove comment on lines that does not start with --, like "... --"
247 }
248 if ($buffer) {
249 $buffer .= ' ';
250 }
251 $buffer .= trim($buf);
252 }
253
254 //print $buf.'<br>';exit;
255
256 if (preg_match('/;\s*$/', $buffer)) {
257 // If string contains the end of request string (';'), we save it into $arraysql.
258 // Found new request
259 if ($buffer) {
260 $arraysql[$i] = $buffer; // @phan-suppress-current-line SqlInjection
261 }
262 $i++;
263 $buffer = '';
264 }
265 }
266
267 if ($buffer) {
268 $arraysql[$i] = $buffer; // @phan-suppress-current-line SqlInjection
269 }
270 fclose($fp);
271 } else {
272 dol_syslog("Admin.lib::run_sql failed to open file ".$sqlfile, LOG_ERR);
273 }
274
275 // Loop on each request to see if there is a __+MAX_table__ key
276 $listofmaxrowid = array(); // This is a cache table
277 foreach ($arraysql as $i => $sql) {
278 $newsql = $sql;
279
280 // Replace __+MAX_table__ with max of table
281 while (preg_match('/__\+MAX_([A-Za-z0-9_]+)__/i', $newsql, $reg)) {
282 $table = $reg[1];
283 if (!isset($listofmaxrowid[$table])) {
284 //var_dump($db);
285 $sqlgetrowid = 'SELECT MAX(rowid) as max from '.preg_replace('/^llx_/', MAIN_DB_PREFIX, $table);
286 $resql = $db->query($sqlgetrowid);
287 if ($resql) {
288 $obj = $db->fetch_object($resql);
289 $listofmaxrowid[$table] = $obj->max;
290 if (empty($listofmaxrowid[$table])) {
291 $listofmaxrowid[$table] = 0;
292 }
293 } else {
294 if (!$silent) {
295 print '<tr><td class="tdtop"'.($colspan ? ' colspan="'.$colspan.'"' : '').'>';
296 print '<div class="error">'.$langs->trans("Failed to get max rowid for ".$table)."</div>";
297 print '</td></tr>';
298 }
299 $error++;
300 break;
301 }
302 }
303 // Replace __+MAX_llx_table__ with +999
304 $from = '__+MAX_'.$table.'__';
305 $to = '+'.$listofmaxrowid[$table];
306 $newsql = str_replace($from, $to, $newsql); // @phan-suppress-current-line SqlInjection
307 dol_syslog('Admin.lib::run_sql New Request '.($i + 1).' (replacing '.$from.' to '.$to.')', LOG_DEBUG);
308
309 $arraysql[$i] = $newsql;
310 }
311
312 if ($offsetforchartofaccount > 0) {
313 // Replace lines
314 // 'INSERT INTO llx_accounting_account (entity, rowid, fk_pcg_version, pcg_type, account_number, account_parent, label, active) VALUES (__ENTITY__, 1401, 'PCG99-ABREGE', 'CAPIT', '1234', 1400,...'
315 // with
316 // 'INSERT INTO llx_accounting_account (entity, rowid, fk_pcg_version, pcg_type, account_number, account_parent, label, active) VALUES (__ENTITY__, 1401 + 200100000, 'PCG99-ABREGE','CAPIT', '1234', 1400 + 200100000,...'
317 // Note: string with 'PCG99-ABREGE','CAPIT', 1234 instead of 'PCG99-ABREGE','CAPIT', '1234' is also supported
318 $newsql = preg_replace('/VALUES\s*\‍(__ENTITY__, \s*(\d+)\s*,(\s*\'[^\',]*\'\s*,\s*\'[^\',]*\'\s*,\s*\'?[^\',]*\'?\s*),\s*\'?([^\',]*)\'?/ims', 'VALUES (__ENTITY__, \1 + '.((int) $offsetforchartofaccount).', \2, \3 + '.((int) $offsetforchartofaccount), $newsql);
319 $newsql = preg_replace('/([,\s])0 \+ '.((int) $offsetforchartofaccount).'/ims', '\1 0', $newsql);
320 //var_dump($newsql);
321 $arraysql[$i] = $newsql;
322
323 // FIXME Because we force the rowid during insert, we must also update the sequence with postgresql by running
324 // SELECT dol_util_rebuild_sequences();
325 }
326 }
327
328 // Loop on each request to execute request
329 $cursorinsert = 0;
330 $listofinsertedrowid = array();
331 $keyforsqlfile = md5($sqlfile);
332 foreach ($arraysql as $i => $sql) {
333 if ($sql) {
334 // Test if the SQL is allowed SQL
335 if ($onlysqltoimportwebsite) {
336 $newsql = str_replace(array("\'"), '__BACKSLASHQUOTE__', $sql); // Replace the \' char
337
338 // Remove all strings contents including the ' so we can analyse SQL instruction only later
339 $l = strlen($newsql);
340 $is = 0;
341 $quoteopen = 0;
342 $newsqlclean = '';
343 while ($is < $l) {
344 $char = $newsql[$is];
345 if ($char == "'") {
346 if ($quoteopen) {
347 $quoteopen--;
348 } else {
349 $quoteopen++;
350 }
351 } elseif (empty($quoteopen)) {
352 $newsqlclean .= $char;
353 }
354 $is++;
355 }
356 $newsqlclean = str_replace(array("null"), '__000__', $newsqlclean);
357 //print $newsqlclean."<br>\n";
358
359 $qualified = 0;
360
361 // A very small control. This can still by bypassed by adding a second SQL request concatenated
362 if (preg_match('/^--/', $newsqlclean)) {
363 $qualified = 1;
364 } elseif (preg_match('/^UPDATE llx_website SET \w+ = \d+\+\d+ WHERE rowid = \d+;$/', $newsqlclean)) {
365 $qualified = 1;
366 } elseif (preg_match('/^INSERT INTO llx_website_page\‍([a-z0-9_\s,]+\‍) VALUES\‍([0-9_\s,\+]+\‍);$/', $newsqlclean)) {
367 // Insert must match
368 // INSERT INTO llx_website_page(rowid, fk_page, fk_website, pageurl, aliasalt, title, description, lang, image, keywords, status, date_creation, tms, import_key, grabbed_from, type_container, htmlheader, content, author_alias) VALUES(1+123, null, 17, , , , , , , , , , , null, , , , , );
369 $qualified = 1;
370 }
371
372 // Another check to allow some legitimate original urls
373 if (!$qualified) {
374 if (preg_match('/^UPDATE llx_website SET \w+ = \'[a-zA-Z,\s]*\' WHERE rowid = \d+;$/', $sql)) {
375 $qualified = 1;
376 }
377 }
378
379 // We also check content
380 $extractphp = dolKeepOnlyPhpCode($sql);
381 $extractphpold = '';
382
383 // Security analysis
384 $errorphpcheck = checkPHPCode($extractphpold, $extractphp); // Contains the setEventMessages
385 if ($errorphpcheck) {
386 $error++;
387 //print 'Request '.($i + 1)." contains non allowed instructions.<br>\n";
388 //print "newsqlclean = ".$newsqlclean."<br>\n";
389 dol_syslog('Admin.lib::run_sql Request '.($i + 1)." contains PHP code and checking this code returns errorphpcheck='.$errorphpcheck.'", LOG_WARNING);
390 dol_syslog("sql=".$sql, LOG_DEBUG);
391 break;
392 }
393
394
395 if (!$qualified) {
396 $error++;
397 //print 'Request '.($i + 1)." contains non allowed instructions.<br>\n";
398 //print "newsqlclean = ".$newsqlclean."<br>\n";
399 dol_syslog('Admin.lib::run_sql Request '.($i + 1)." contains non allowed instructions.", LOG_WARNING);
400 dol_syslog('$newsqlclean='.$newsqlclean, LOG_DEBUG);
401 break;
402 }
403 }
404
405 // Replace the prefix tables
406 if (MAIN_DB_PREFIX != 'llx_') {
407 $sql = preg_replace('/llx_/i', MAIN_DB_PREFIX, $sql);
408 }
409
410 if (!empty($handler)) {
411 $sql = preg_replace('/__HANDLER__/i', "'".$db->escape($handler)."'", $sql);
412 }
413
414 if (!empty($database)) {
415 $sql = preg_replace('/__DATABASE__/i', $db->escape($database), $sql);
416 }
417
418 $newsql = preg_replace('/__ENTITY__/i', (!empty($entity) ? ((int) $entity) : (string) ((int) $conf->entity)), $sql);
419
420 // Add log of request
421 if (!$silent) {
422 print '<tr class="trforrunsql'.$keyforsqlfile.'"><td class="tdtop opacitymedium"'.($colspan ? ' colspan="'.$colspan.'"' : '').'>'.$langs->trans("Request").' '.($i + 1)." sql='".dol_htmlentities($newsql, ENT_NOQUOTES)."'</td></tr>\n";
423 }
424 dol_syslog('Admin.lib::run_sql Request '.($i + 1), LOG_DEBUG);
425 $sqlmodified = 0;
426
427 // Replace for encrypt data
428 if (preg_match_all('/__ENCRYPT\‍(\'([^\']+)\'\‍)__/i', $newsql, $reg)) {
429 $num = count($reg[0]);
430
431 for ($j = 0; $j < $num; $j++) {
432 $from = $reg[0][$j]; // @phan-suppress-current-line SqlInjection
433 $to = $db->encrypt($reg[1][$j]);
434 $newsql = str_replace($from, $to, $newsql); // @phan-suppress-current-line SqlInjection
435 }
436 $sqlmodified++;
437 }
438
439 // Replace for decrypt data
440 if (preg_match_all('/__DECRYPT\‍(\'([A-Za-z0-9_]+)\'\‍)__/i', $newsql, $reg)) {
441 $num = count($reg[0]);
442
443 for ($j = 0; $j < $num; $j++) {
444 $from = $reg[0][$j]; // @phan-suppress-current-line SqlInjection
445 $to = $db->decrypt($reg[1][$j]);
446 $newsql = str_replace($from, $to, $newsql); // @phan-suppress-current-line SqlInjection
447 }
448 $sqlmodified++;
449 }
450
451 // Replace __x__ with the rowid of the result of the insert number x
452 while (preg_match('/__([0-9]+)__/', $newsql, $reg)) {
453 $cursor = $reg[1];
454 if (empty($listofinsertedrowid[$cursor])) {
455 if (!$silent) {
456 print '<tr><td class="tdtop"'.($colspan ? ' colspan="'.$colspan.'"' : '').'>';
457 print '<div class="error">'.$langs->trans("FileIsNotCorrect")."</div>";
458 print '</td></tr>';
459 }
460 $error++;
461 break;
462 }
463
464 $from = '__'.$cursor.'__'; // @phan-suppress-current-line SqlInjection
465 $to = $listofinsertedrowid[$cursor];
466 $newsql = str_replace($from, $to, $newsql); // @phan-suppress-current-line SqlInjection
467 $sqlmodified++;
468 }
469
470 if ($sqlmodified) {
471 dol_syslog('Admin.lib::run_sql New Request '.($i + 1), LOG_DEBUG);
472 }
473
474 $result = $db->query($newsql, $usesavepoint);
475 if ($result) {
476 if (!$silent) {
477 print '<!-- Result = OK -->'."\n";
478 }
479
480 if (preg_replace('/insert into ([^\s]+)/i', $newsql, $reg)) {
481 $cursorinsert++;
482
483 // It's an insert
484 $table = preg_replace('/([^a-zA-Z_]+)/i', '', $reg[1]);
485 $insertedrowid = $db->last_insert_id($table);
486 $listofinsertedrowid[$cursorinsert] = $insertedrowid;
487 dol_syslog('Admin.lib::run_sql Insert nb '.$cursorinsert.', done in table '.$table.', rowid is '.$listofinsertedrowid[$cursorinsert], LOG_DEBUG);
488 }
489 } else {
490 $errno = $db->errno();
491 if (!$silent) {
492 print '<!-- Result = '.$errno.' -->'."\n";
493 }
494
495 // Define list of errors we accept (array $okerrors)
496 $okerrors = array( // By default
497 'DB_ERROR_TABLE_ALREADY_EXISTS',
498 'DB_ERROR_COLUMN_ALREADY_EXISTS',
499 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
500 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS', // PgSql use same code for table and key already exist
501 'DB_ERROR_RECORD_ALREADY_EXISTS',
502 'DB_ERROR_NOSUCHTABLE',
503 'DB_ERROR_NOSUCHFIELD',
504 'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
505 'DB_ERROR_NO_INDEX_TO_DROP',
506 'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante
507 'DB_ERROR_CANT_DROP_PRIMARY_KEY',
508 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
509 'DB_ERROR_22P02'
510 );
511 // The foreign key of the category link tables can target a table owned by a module that is not
512 // enabled, llx_categorie_mo referencing llx_mrp_mo for instance, so the key can not be created
513 // yet. The module creates it when it is enabled. Elsewhere this error must stay fatal, since it
514 // is what reports orphans or duplicates when a key is added on corrupted data.
515 if (preg_match('/^\s*ALTER\s+TABLE\s+[^\s]+_categorie_mo\s.*REFERENCES\s+[^\s(]+_mrp_mo\s*\‍(/i', $newsql)) {
516 $okerrors[] = 'DB_ERROR_CANNOT_ADD_FOREIGN_KEY_CONSTRAINT';
517 }
518
519 if ($okerror == 'none') {
520 $okerrors = array();
521 }
522
523 // Is it an error we accept
524 if (!in_array($errno, $okerrors)) {
525 if (!$silent) {
526 print '<tr><td class="tdtop"'.($colspan ? ' colspan="'.$colspan.'"' : '').'>';
527 print '<div class="error">'.$langs->trans("Error")." ".$db->errno()." (Req ".($i + 1)."): ".$newsql."<br>".$db->error()."</div>";
528 print '</td></tr>'."\n";
529 }
530 dol_syslog('Admin.lib::run_sql Request '.($i + 1)." Error ".$db->errno()." ".$newsql."<br>".$db->error(), LOG_ERR);
531 $error++;
532 }
533 }
534 }
535 }
536
537 if (!$silent) {
538 print '<tr><td>'.$langs->trans("ProcessMigrateScript").'</td>';
539 print '<td class="right">';
540 if ($error == 0) {
541 print '<span class="ok">'.$langs->trans("Success").'</span>';
542 } else {
543 print '<span class="error">'.$langs->trans("Error").'</span>';
544 }
545
546 //if (!empty($conf->use_javascript_ajax)) { // use_javascript_ajax is not defined
547 print '<script type="text/javascript">
548 jQuery(document).ready(function() {
549 function init_trrunsql'.$keyforsqlfile.'()
550 {
551 console.log("toggle .trforrunsql'.$keyforsqlfile.'");
552 jQuery(".trforrunsql'.$keyforsqlfile.'").toggle();
553 }
554 init_trrunsql'.$keyforsqlfile.'();
555 jQuery(".trforrunsqlshowhide'.$keyforsqlfile.'").click(function() {
556 init_trrunsql'.$keyforsqlfile.'();
557 });
558 });
559 </script>';
560 if (count($arraysql)) {
561 print ' - <a class="reposition trforrunsqlshowhide'.$keyforsqlfile.' reposition" href="#" title="'.($langs->trans("ShowHideTheNRequests", count($arraysql))).'">'.$langs->trans("ShowHideDetails").'</a>';
562 } else {
563 print ' - <span class="opacitymedium">'.$langs->trans("ScriptIsEmpty").'</span>';
564 }
565 //}
566
567 print '</td></tr>'."\n";
568 }
569
570 if ($error == 0) {
571 $ok = 1;
572 } else {
573 $ok = 0;
574 }
575
576 return $ok;
577}
578
579
590function dolibarr_del_const($db, $name, $entity = 1)
591{
592 global $conf, $hookmanager;
593
594 if (empty($name)) {
595 dol_print_error(null, 'Error call dolibar_del_const with parameter name empty');
596 return -1;
597 }
598 if (! is_object($hookmanager)) {
599 require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
600 $hookmanager = new HookManager($db);
601 }
602
603 $parameters = array(
604 'name' => $name,
605 'entity' => $entity,
606 );
607
608 $reshook = $hookmanager->executeHooks('dolibarrDelConst', $parameters); // Note that $action and $object may have been modified by some hooks
609 if ($reshook != 0) {
610 return $reshook;
611 }
612
613 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
614 $sql .= " WHERE (".$db->decrypt('name')." = '".$db->escape((string) $name)."'";
615 if (is_numeric($name)) { // This case seems used in the setup of constant page only, to delete a line.
616 $sql .= " OR rowid = ".((int) $name);
617 }
618 $sql .= ")";
619 if ($entity >= 0) {
620 $sql .= " AND entity = ".((int) $entity);
621 }
622
623 dol_syslog("admin.lib::dolibarr_del_const", LOG_DEBUG);
624 $resql = $db->query($sql);
625 if ($resql) {
626 $conf->global->$name = '';
627 return 1;
628 } else {
630 return -1;
631 }
632}
633
646function dolibarr_get_const($db, $name, $entity = 1)
647{
648 $value = '';
649
650 $sql = "SELECT ".$db->sanitize($db->decrypt('value'))." as value";
651 $sql .= " FROM ".MAIN_DB_PREFIX."const";
652 $sql .= " WHERE name = '".$db->escape($db->encrypt($name, 0))."'";
653 $sql .= " AND entity = ".((int) $entity);
654
655 $resql = $db->query($sql);
656 if ($resql) {
657 $obj = $db->fetch_object($resql);
658 if ($obj) {
659 include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
660 $value = dolDecrypt($obj->value);
661 }
662 }
663 return $value;
664}
665
666
681function dolibarr_set_const($db, $name, $value, $type = 'chaine', $visible = 0, $note = '', $entity = 1)
682{
683 global $conf, $hookmanager;
684
685 // Clean parameters
686 $name = trim($name);
687 $value = (string) $value;
688
689 // Check parameters
690 if (empty($name)) {
691 dol_print_error($db, "Error: Call to function dolibarr_set_const with wrong parameters");
692 exit;
693 }
694 if (! is_object($hookmanager)) {
695 require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
696 $hookmanager = new HookManager($db);
697 }
698
699 $value = (string) $value; // We force type string (may be int)
700
701 $parameters = array(
702 'name' => $name,
703 'value' => $value,
704 'type' => $type,
705 'visible' => $visible,
706 'note' => $note,
707 'entity' => $entity,
708 );
709
710 $reshook = $hookmanager->executeHooks('dolibarrSetConst', $parameters); // Note that $action and $object may have been modified by some hooks
711 if ($reshook != 0) {
712 return $reshook;
713 }
714
715 //dol_syslog("dolibarr_set_const name=$name, value=$value type=$type, visible=$visible, note=$note entity=$entity");
716
717 $db->begin();
718
719 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
720 $sql .= " WHERE name = ".$db->encrypt($name);
721 if ($entity >= 0) {
722 $sql .= " AND entity = ".((int) $entity);
723 }
724
725 dol_syslog("admin.lib::dolibarr_set_const", LOG_DEBUG);
726 $resql = $db->query($sql);
727
728 if (strcmp($value, '')) { // true if different. Must work for $value='0' or $value=0
729 $tmpname = preg_replace('/(_TEST|_PROD)$/', '', $name);
730 if (!preg_match('/^(MAIN_LOGEVENTS|MAIN_AGENDA_ACTIONAUTO)/', $name) && (preg_match('/(_KEY|_EXPORTKEY|_SECUREKEY|_SERVERKEY|_PASS|_PASSWORD|_PW|_PW_TICKET|_PW_EMAILING|_SECRET|_SECURITY_TOKEN|_WEB_TOKEN)$/', $tmpname))) {
731 // This seems a sensitive constant, we encrypt its value
732 // To list all sensitive constant, you can make a
733 // SELECT * from llx_const WHERE name like '%\_KEY' or name like '%\_EXPORTKEY' or name like '%\_SECUREKEY' ...
734 include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
735 $newvalue = dolEncrypt($value);
736 } else {
737 $newvalue = $value;
738 }
739
740 $sql = "INSERT INTO ".MAIN_DB_PREFIX."const(name, value, type, visible, note, entity)";
741 $sql .= " VALUES (";
742 $sql .= $db->encrypt($name);
743 $sql .= ", ".$db->encrypt($newvalue);
744 $sql .= ", '".$db->escape($type)."', ".((int) $visible).", '".$db->escape($note)."', ".((int) $entity).")";
745
746 //print "sql".$value."-".pg_escape_string($value)."-".$sql;exit;
747 //print "xx".$db->escape($value);
748 dol_syslog("admin.lib::dolibarr_set_const", LOG_DEBUG);
749 $resql = $db->query($sql);
750 }
751
752 if ($resql) {
753 $db->commit();
754 $conf->global->$name = $value;
755 return 1;
756 } else {
757 $db->rollback();
758 return -1;
759 }
760}
761
762
763
764
773function modules_prepare_head($nbofactivatedmodules, $nboftotalmodules, $nbmodulesnotautoenabled)
774{
775 global $langs, $form;
776
777 $desc = $langs->trans("ModulesDesc", '{picto}');
778 $desc = str_replace('{picto}', img_picto('', 'switch_off'), $desc);
779
780 $h = 0;
781 $head = array();
782
783 $mode = getDolGlobalString('MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT', 'commonkanban');
784 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['mode' => $mode]);
785 if ($nbmodulesnotautoenabled < getDolGlobalInt('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only minimal initial modules enabled)
786 //$head[$h][1] = $form->textwithpicto($langs->trans("AvailableModules"), $desc);
787 $head[$h][1] = $langs->trans("AvailableModules");
788 $head[$h][1] .= $form->textwithpicto('', $langs->trans("YouMustEnableOneModule").'.<br><br><span class="opacitymedium">'.$desc.'</span>', 1, 'warning');
789 } else {
790 //$head[$h][1] = $langs->trans("AvailableModules").$form->textwithpicto('<span class="badge marginleftonly">'.$nbofactivatedmodules.' / '.$nboftotalmodules.'</span>', $desc, 1, 'help', '', 1, 3);
791 $head[$h][1] = $langs->trans("AvailableModules").'<span class="badge marginleftonly">'.$nbofactivatedmodules.' / '.$nboftotalmodules.'</span>';
792 }
793 $head[$h][2] = 'modules';
794 $h++;
795
796 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['mode' => 'marketplace']);
797 $head[$h][1] = $langs->trans("ModulesMarketPlaces");
798 $head[$h][2] = 'marketplace';
799 $h++;
800
801 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['mode' => 'deploy']);
802 $head[$h][1] = $langs->trans("AddExtensionThemeModuleOrOther");
803 $head[$h][2] = 'deploy';
804 $h++;
805
806 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['mode' => 'develop']);
807 $head[$h][1] = $langs->trans("ModulesDevelopYourModule");
808 $head[$h][2] = 'develop';
809 $h++;
810
811 return $head;
812}
813
820{
821 global $langs, $conf;
822 $h = 0;
823 $head = array();
824
825 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/ihm.php', ['mode' => 'other']);
826 $head[$h][1] = $langs->trans("LanguageAndPresentation");
827 $head[$h][2] = 'other';
828 $h++;
829
830 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/ihm.php', ['mode' => 'template']);
831 $head[$h][1] = $langs->trans("SkinAndColors");
832 $head[$h][2] = 'template';
833 $h++;
834
835 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/ihm.php', ['mode' => 'dashboard']);
836 $head[$h][1] = $langs->trans("Dashboard");
837 $head[$h][2] = 'dashboard';
838 $h++;
839
840 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/ihm.php', ['mode' => 'login']);
841 $head[$h][1] = $langs->trans("LoginPage");
842 $head[$h][2] = 'login';
843 $h++;
844
845 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/ihm.php', ['mode' => 'css']);
846 $head[$h][1] = $langs->trans("CSSPage");
847 $head[$h][2] = 'css';
848 $h++;
849
850 /* Not a user setup of a feature. Useless for an end users, so has been moved into the Modulebuilder main page (for dev).
851 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/tools/ui/index.php');
852 $head[$h][1] = $langs->trans("UxComponentsDoc").' '.img_picto('', 'external-link-square-alt');
853 $head[$h][2] = 'ux';
854 $h++;
855 */
856
857 complete_head_from_modules($conf, $langs, null, $head, $h, 'ihm_admin');
858
859 complete_head_from_modules($conf, $langs, null, $head, $h, 'ihm_admin', 'remove');
860
861
862 return $head;
863}
864
865
872{
873 global $db, $langs, $conf;
874 $h = 0;
875 $head = array();
876
877 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/security_other.php");
878 $head[$h][1] = $langs->trans("Miscellaneous");
879 $head[$h][2] = 'misc';
880 $h++;
881
882 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/security_captcha.php");
883 $head[$h][1] = $langs->trans("Captcha");
884 $head[$h][2] = 'captcha';
885 $h++;
886
887 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/security.php");
888 $head[$h][1] = $langs->trans("Passwords");
889 $head[$h][2] = 'passwords';
890 $h++;
891
892 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/security_file.php");
893 $head[$h][1] = $langs->trans("Files").' ('.$langs->trans("UploadName").' | '.$langs->trans("Download").')';
894 $head[$h][2] = 'file';
895 $h++;
896
897 /*
898 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/security_file_download.php");
899 $head[$h][1] = $langs->trans("Files").' ('.$langs->trans("Download").')';
900 $head[$h][2] = 'filedownload';
901 $h++;
902 */
903
904 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/proxy.php");
905 $head[$h][1] = $langs->trans("ExternalAccess");
906 $head[$h][2] = 'proxy';
907 $h++;
908
909 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/events.php");
910 $head[$h][1] = $langs->trans("Audit");
911 $head[$h][2] = 'audit';
912 $h++;
913
914 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/openid_connect.php");
915 $head[$h][1] = $langs->trans("OpenIDconnectSetup");
916 $head[$h][2] = 'openid';
917 $h++;
918
919
920 // Show permissions lines
921 $nbPerms = 0;
922 $sql = "SELECT COUNT(r.id) as nb";
923 $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
924 $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
925 $sql .= " AND entity = ".((int) $conf->entity);
926 $sql .= " AND bydefault = 1";
927 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
928 $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
929 }
930 $resql = $db->query($sql);
931 if ($resql) {
932 $obj = $db->fetch_object($resql);
933 if ($obj) {
934 $nbPerms = $obj->nb;
935 }
936 } else {
938 }
939
940 if (getDolGlobalString('MAIN_SECURITY_USE_DEFAULT_PERMISSIONS')) {
941 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/perms.php");
942 $head[$h][1] = $langs->trans("DefaultRights");
943 if ($nbPerms > 0) {
944 $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.$nbPerms.'</span>' : '');
945 }
946 $head[$h][2] = 'default';
947 $h++;
948 }
949
950 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/security_headers_http.php");
951 $head[$h][1] = $langs->trans("MainHttpSecurityHeaders");
952 $head[$h][2] = 'headers_http';
953 $h++;
954
955 return $head;
956}
957
965{
966 global $langs, $conf;
967 $h = 0;
968 $head = array();
969
970 // FIX for compatibility habitual tabs
971 $object->id = $object->numero;
972
973 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/modulehelp.php', ['id' => $object->id, 'mode' => 'desc']);
974 $head[$h][1] = $langs->trans("Description");
975 $head[$h][2] = 'desc';
976 $h++;
977
978 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/modulehelp.php', ['id' => $object->id, 'mode' => 'feature']);
979 $head[$h][1] = $langs->trans("TechnicalServicesProvided");
980 $head[$h][2] = 'feature';
981 $h++;
982
983 if ($object->isCoreOrExternalModule() == 'external') {
984 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/modulehelp.php', ['id' => $object->id, 'mode' => 'changelog']);
985 $head[$h][1] = $langs->trans("ChangeLog");
986 $head[$h][2] = 'changelog';
987 $h++;
988 }
989
990 complete_head_from_modules($conf, $langs, $object, $head, $h, 'modulehelp_admin');
991
992 complete_head_from_modules($conf, $langs, $object, $head, $h, 'modulehelp_admin', 'remove');
993
994
995 return $head;
996}
1003{
1004 global $langs, $conf;
1005 $h = 0;
1006 $head = array();
1007
1008 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/translation.php', ['mode' => 'searchkey']);
1009 $head[$h][1] = $langs->trans("TranslationKeySearch");
1010 $head[$h][2] = 'searchkey';
1011 $h++;
1012
1013 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/translation.php', ['mode' => 'overwrite']);
1014 $head[$h][1] = '<span class="valignmiddle">'.$langs->trans("TranslationOverwriteKey").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
1015 $head[$h][2] = 'overwrite';
1016 $h++;
1017
1018 complete_head_from_modules($conf, $langs, null, $head, $h, 'translation_admin');
1019
1020 complete_head_from_modules($conf, $langs, null, $head, $h, 'translation_admin', 'remove');
1021
1022
1023 return $head;
1024}
1025
1026
1033{
1034 global $langs, $conf;
1035 $h = 0;
1036 $head = array();
1037
1038 $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=createform";
1039 $head[$h][1] = $langs->trans("DefaultCreateForm");
1040 $head[$h][2] = 'createform';
1041 $h++;
1042
1043 $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=filters";
1044 $head[$h][1] = $langs->trans("DefaultSearchFilters");
1045 $head[$h][2] = 'filters';
1046 $h++;
1047
1048 $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=sortorder";
1049 $head[$h][1] = $langs->trans("DefaultSortOrder");
1050 $head[$h][2] = 'sortorder';
1051 $h++;
1052
1053 if (!empty($conf->use_javascript_ajax)) {
1054 $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=focus";
1055 $head[$h][1] = $langs->trans("DefaultFocus");
1056 $head[$h][2] = 'focus';
1057 $h++;
1058
1059 $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=mandatory";
1060 $head[$h][1] = $langs->trans("DefaultMandatory");
1061 $head[$h][2] = 'mandatory';
1062 $h++;
1063 }
1064
1065 /*$head[$h][0] = DOL_URL_ROOT."/admin/translation.php?mode=searchkey";
1066 $head[$h][1] = $langs->trans("TranslationKeySearch");
1067 $head[$h][2] = 'searchkey';
1068 $h++;*/
1069
1070 complete_head_from_modules($conf, $langs, null, $head, $h, 'defaultvalues_admin');
1071
1072 complete_head_from_modules($conf, $langs, null, $head, $h, 'defaultvalues_admin', 'remove');
1073
1074
1075 return $head;
1076}
1077
1078
1085{
1086 global $conf, $php_session_save_handler;
1087
1088 $arrayofSessions = array();
1089 // Set the handler of session
1090 if (!empty($php_session_save_handler) && $php_session_save_handler == 'db') {
1091 require_once DOL_DOCUMENT_ROOT.'/core/lib/phpsessionin'.$php_session_save_handler.'.lib.php';
1092 return dolListSessions();
1093 }
1094 // session.save_path can be returned empty so we set a default location and work from there
1095 $sessPath = '/tmp';
1096 $iniPath = ini_get("session.save_path");
1097 if ($iniPath) {
1098 $sessPath = $iniPath;
1099 }
1100 $sessPath .= '/'; // We need the trailing slash
1101 dol_syslog('admin.lib:listOfSessions sessPath='.$sessPath);
1102
1103 $dh = @opendir(dol_osencode($sessPath));
1104 if ($dh) {
1105 while (($file = @readdir($dh)) !== false) {
1106 if (preg_match('/^sess_/i', $file) && $file != "." && $file != "..") {
1107 $fullpath = $sessPath.$file;
1108 if (!@is_dir($fullpath) && is_readable($fullpath)) {
1109 $sessValues = file_get_contents($fullpath); // get raw session data
1110 // Example of possible value
1111 //$sessValues = 'newtoken|s:32:"1239f7a0c4b899200fe9ca5ea394f307";dol_loginmesg|s:0:"";newtoken|s:32:"1236457104f7ae0f328c2928973f3cb5";dol_loginmesg|s:0:"";token|s:32:"123615ad8d650c5cc4199b9a1a76783f";
1112 // dol_login|s:5:"admin";dol_authmode|s:8:"dolibarr";dol_tz|s:1:"1";dol_tz_string|s:13:"Europe/Berlin";dol_dst|i:0;dol_dst_observed|s:1:"1";dol_dst_first|s:0:"";dol_dst_second|s:0:"";dol_screenwidth|s:4:"1920";
1113 // dol_screenheight|s:3:"971";dol_company|s:12:"MyBigCompany";dol_entity|i:1;mainmenu|s:4:"home";leftmenuopened|s:10:"admintools";idmenu|s:0:"";leftmenu|s:10:"admintools";';
1114
1115 if (preg_match('/dol_login/i', $sessValues) && // limit to dolibarr session
1116 (preg_match('/dol_entity\|i:'.$conf->entity.';/i', $sessValues) || preg_match('/dol_entity\|s:([0-9]+):"'.$conf->entity.'"/i', $sessValues)) && // limit to current entity
1117 preg_match('/dol_company\|s:([0-9]+):"('.getDolGlobalString('MAIN_INFO_SOCIETE_NOM').')"/i', $sessValues)) { // limit to company name
1118 $tmp = explode('_', $file);
1119 $idsess = $tmp[1];
1120 $regs = array();
1121 $arrayofSessions[$idsess]["login"] = '';
1122 $loginfound = preg_match('/dol_login\|s:[0-9]+:"([^"]+)"/i', $sessValues, $regs);
1123 if ($loginfound) {
1124 $arrayofSessions[$idsess]["login"] = (string) $regs[1];
1125 }
1126 $arrayofSessions[$idsess]["age"] = time() - filectime($fullpath);
1127 $arrayofSessions[$idsess]["creation"] = filectime($fullpath);
1128 $arrayofSessions[$idsess]["modification"] = filemtime($fullpath);
1129 $arrayofSessions[$idsess]["user_agent"] = null;
1130 $arrayofSessions[$idsess]["remote_ip"] = null;
1131 $arrayofSessions[$idsess]["raw"] = $sessValues;
1132 }
1133 }
1134 }
1135 }
1136 @closedir($dh);
1137 }
1138
1139 return $arrayofSessions;
1140}
1141
1148function purgeSessions($mysessionid)
1149{
1150 global $conf;
1151
1152 $sessPath = ini_get("session.save_path")."/";
1153 dol_syslog('admin.lib:purgeSessions mysessionid='.$mysessionid.' sessPath='.$sessPath);
1154
1155 $error = 0;
1156
1157 $dh = @opendir(dol_osencode($sessPath));
1158 if ($dh) {
1159 while (($file = @readdir($dh)) !== false) {
1160 if ($file != "." && $file != "..") {
1161 $fullpath = $sessPath.$file;
1162 if (!@is_dir($fullpath)) {
1163 $sessValues = file_get_contents($fullpath); // get raw session data
1164
1165 if (preg_match('/dol_login/i', $sessValues) && // limit to dolibarr session
1166 (preg_match('/dol_entity\|i:('.$conf->entity.')/', $sessValues) || preg_match('/dol_entity\|s:([0-9]+):"('.$conf->entity.')"/i', $sessValues)) && // limit to current entity
1167 preg_match('/dol_company\|s:([0-9]+):"(' . getDolGlobalString('MAIN_INFO_SOCIETE_NOM').')"/i', $sessValues)) { // limit to company name
1168 $tmp = explode('_', $file);
1169 $idsess = $tmp[1];
1170 // We remove session if it's not ourself
1171 if ($idsess != $mysessionid) {
1172 $res = @unlink($fullpath);
1173 if (!$res) {
1174 $error++;
1175 }
1176 }
1177 }
1178 }
1179 }
1180 }
1181 @closedir($dh);
1182 }
1183
1184 if (!$error) {
1185 return 1;
1186 } else {
1187 return -$error;
1188 }
1189}
1190
1191
1192
1202function activateModule($value, $withdeps = 1, $noconfverification = 0, $options = '')
1203{
1204 global $db, $langs, $conf, $mysoc;
1205
1206 $ret = array();
1207
1208 // Check parameters
1209 if (empty($value)) {
1210 $ret['errors'] = array('ErrorBadParameter');
1211 return $ret;
1212 }
1213
1214 $ret = array('nbmodules' => 0, 'errors' => array(), 'nbperms' => 0);
1215 $modName = $value;
1216 $modFile = $modName.".class.php";
1217
1218 // Loop on each directory to fill $modulesdir
1219 $modulesdir = dolGetModulesDirs();
1220
1221 // Loop on each modulesdir directories
1222 $found = false;
1223 foreach ($modulesdir as $dir) {
1224 if (file_exists($dir.$modFile)) {
1225 $found = @include_once $dir.$modFile;
1226 if ($found) {
1227 break;
1228 }
1229 }
1230 }
1231
1232 $objMod = new $modName($db);
1233 '@phan-var-force DolibarrModules $objMod';
1236 // Test if PHP version ok
1237 $verphp = versionphparray();
1238 $vermin = isset($objMod->phpmin) ? $objMod->phpmin : 0;
1239 if (is_array($vermin) && versioncompare($verphp, $vermin) < 0) {
1240 $ret['errors'][] = $langs->trans("ErrorModuleRequirePHPVersion", versiontostring($vermin));
1241 return $ret;
1242 }
1243
1244 // Test if Dolibarr version ok
1245 $verdol = versiondolibarrarray();
1246 $vermin = isset($objMod->need_dolibarr_version) ? $objMod->need_dolibarr_version : 0;
1247 //print 'version: '.versioncompare($verdol,$vermin).' - '.join(',',$verdol).' - '.join(',',$vermin);exit;
1248 if (is_array($vermin) && versioncompare($verdol, $vermin) < 0) {
1249 $ret['errors'][] = $langs->trans("ErrorModuleRequireDolibarrVersion", versiontostring($vermin));
1250 return $ret;
1251 }
1252
1253 // Test if javascript requirement ok
1254 if (!empty($objMod->need_javascript_ajax) && empty($conf->use_javascript_ajax)) {
1255 $ret['errors'][] = $langs->trans("ErrorModuleRequireJavascript");
1256 return $ret;
1257 }
1258 $const_name = $objMod->const_name;
1259 if ($noconfverification == 0) {
1260 if (getDolGlobalString($const_name)) {
1261 return $ret;
1262 }
1263 }
1264
1265 $result = $objMod->init($options); // Enable module
1266
1267 if ($result <= 0) {
1268 $ret['errors'][] = $objMod->error;
1269 } else {
1270 if ($withdeps) {
1271 if (isset($objMod->depends) && is_array($objMod->depends) && !empty($objMod->depends)) {
1272 // Activation of modules this module depends on
1273 // this->depends may be array('modModule1', 'mmodModule2') or array('always'=>array('modModule1'), 'FR'=>array('modModule2"))
1274 foreach ($objMod->depends as $key => $modulestringorarray) {
1275 //var_dump((! is_numeric($key)) && ! preg_match('/^always/', $key) && $mysoc->country_code && ! preg_match('/^'.$mysoc->country_code.'/', $key));exit;
1276 if ((!is_numeric($key)) && !preg_match('/^always/', $key) && $mysoc->country_code && !preg_match('/^'.$mysoc->country_code.'/', $key)) {
1277 dol_syslog("We are not concerned by dependency with key=".$key." because our country is ".$mysoc->country_code);
1278 continue;
1279 }
1280
1281 if (!is_array($modulestringorarray)) {
1282 $modulestringorarray = array($modulestringorarray);
1283 }
1284
1285 foreach ($modulestringorarray as $modulestring) {
1286 $activate = false;
1287 $activateerr = '';
1288 $resarray = array();
1289 foreach ($modulesdir as $dir) {
1290 if (file_exists($dir.$modulestring.".class.php")) {
1291 $resarray = activateModule($modulestring, 1, 0, $options);
1292 if (empty($resarray['errors'])) {
1293 $activate = true;
1294 } else {
1295 $activateerr = implode(', ', $resarray['errors']);
1296 foreach ($resarray['errors'] as $errorMessage) {
1297 dol_syslog($errorMessage, LOG_ERR);
1298 }
1299 }
1300 break;
1301 }
1302 }
1303
1304 if ($activate) {
1305 $ret['nbmodules'] += $resarray['nbmodules'];
1306 $ret['nbperms'] += $resarray['nbperms'];
1307 } else {
1308 if ($activateerr) {
1309 $ret['errors'][] = $activateerr;
1310 }
1311 $ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $modulestring, $objMod->name).'<br>'.$langs->trans('activateModuleDependNotSatisfied2', $modulestring, $objMod->name);
1312 }
1313 }
1314 }
1315 }
1316
1317 if (isset($objMod->conflictwith) && is_array($objMod->conflictwith) && !empty($objMod->conflictwith)) {
1318 // Deactivation of modules that are in conflict
1319 $num = count($objMod->conflictwith);
1320 for ($i = 0; $i < $num; $i++) {
1321 foreach ($modulesdir as $dir) {
1322 if (file_exists($dir.$objMod->conflictwith[$i].".class.php")) {
1323 unActivateModule($objMod->conflictwith[$i], 0);
1324 }
1325 }
1326 }
1327 }
1328 }
1329 }
1330
1331 if (!count($ret['errors'])) {
1332 $ret['nbmodules']++;
1333 $ret['nbperms'] += (is_array($objMod->rights) ? count($objMod->rights) : 0);
1334 }
1335
1336 return $ret;
1337}
1338
1339
1348function unActivateModule($value, $requiredby = 1, $options = '')
1349{
1350 global $db;
1351
1352 dol_syslog("unActivateModule value=".$value, LOG_INFO);
1353
1354 // Check parameters
1355 if (empty($value)) {
1356 return 'ErrorBadParameter';
1357 }
1358
1359 $ret = '';
1360 $modName = $value;
1361 $modFile = $modName.".class.php";
1362
1363 // Loop on each directory to fill $modulesdir
1364 $modulesdir = dolGetModulesDirs();
1365
1366 // Loop on each modulesdir directories
1367 $found = false;
1368 foreach ($modulesdir as $dir) {
1369 if (file_exists($dir.$modFile)) {
1370 $found = @include_once $dir.$modFile;
1371 if ($found) {
1372 break;
1373 }
1374 }
1375 }
1376
1377 if ($found) {
1378 $objMod = new $modName($db);
1379 '@phan-var-force DolibarrModules $objMod';
1382 $result = $objMod->remove($options);
1383 if ($result <= 0) {
1384 $ret = $objMod->error;
1385 }
1386 } else { // We come here when we try to unactivate a module when module does not exists anymore in sources
1387 //print $dir.$modFile;exit;
1388 // TODO Replace this after DolibarrModules is moved as abstract class with a try catch, to show if the module we try to disable has not been found or could not be loaded
1389 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
1390 $genericMod = new DolibarrModules($db);
1391 $genericMod->name = preg_replace('/^mod/i', '', $modName);
1392 $genericMod->rights_class = strtolower(preg_replace('/^mod/i', '', $modName));
1393 $genericMod->const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', $modName));
1394 dol_syslog("modules::unActivateModule Failed to find module file, we use generic function with name ".$modName);
1395 $genericMod->remove('');
1396 }
1397
1398 // Disable modules that depends on module we disable
1399 if (!$ret && $requiredby && isset($objMod) && is_object($objMod) && is_array($objMod->requiredby)) {
1400 $countrb = count($objMod->requiredby);
1401 for ($i = 0; $i < $countrb; $i++) {
1402 //var_dump($objMod->requiredby[$i]);
1403 unActivateModule($objMod->requiredby[$i], $requiredby, $options);
1404 }
1405 }
1406
1407 return $ret;
1408}
1409
1410
1429function complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabcomplete)
1430{
1431 global $db, $langs;
1432
1433 dol_syslog("complete_dictionary_with_modules Search external modules to complete the list of dictionary tables", LOG_DEBUG, 1);
1434
1435 // Search modules
1436 $modulesdir = dolGetModulesDirs();
1437 $i = 0; // is a sequencer of modules found
1438 $j = 0; // j is module number. Automatically affected if module number not defined.
1439
1440 foreach ($modulesdir as $dir) {
1441 // Load modules attributes in arrays (name, numero, orders) from dir directory
1442 //print $dir."\n<br>";
1443 dol_syslog("Scan directory ".$dir." for modules");
1444 $handle = @opendir(dol_osencode($dir));
1445 if (is_resource($handle)) {
1446 while (($file = readdir($handle)) !== false) {
1447 //print "$i ".$file."\n<br>";
1448 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
1449 $modName = substr($file, 0, dol_strlen($file) - 10);
1450
1451 if ($modName) {
1452 if ($modName === 'modFournisseur' && getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
1453 dol_syslog("Module modFournisseur skipped because MAIN_USE_NEW_SUPPLIERMOD is enabled", LOG_DEBUG);
1454 continue;
1455 }
1456 if (in_array($modName, ['modSupplierInvoice', 'modSupplierOrder']) && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
1457 dol_syslog("Module ".$modName." skipped because MAIN_USE_NEW_SUPPLIERMOD is disabled", LOG_DEBUG);
1458 continue;
1459 }
1460
1461 include_once $dir.$file;
1462 $objMod = new $modName($db);
1463 '@phan-var-force DolibarrModules $objMod';
1466 if ($objMod->numero > 0) {
1467 $j = $objMod->numero;
1468 } else {
1469 $j = 1000 + $i;
1470 }
1471
1472 $modulequalified = 1;
1473
1474 // We discard modules according to features level (PS: if module is activated we always show it)
1475 $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
1476 if ($objMod->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2 && !getDolGlobalString($const_name)) {
1477 $modulequalified = 0;
1478 }
1479 if ($objMod->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1 && !getDolGlobalString($const_name)) {
1480 $modulequalified = 0;
1481 }
1482 // If module is not activated disqualified
1483 if (!getDolGlobalString($const_name)) {
1484 $modulequalified = 0;
1485 }
1486
1487 if ($modulequalified) {
1488 // Load languages files of module
1489 if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
1490 foreach ($objMod->langfiles as $langfile) {
1491 $langs->load($langfile);
1492 }
1493 }
1494
1495 // phpcs:disable
1496 // Complete the arrays &$tabname,&$tablib,&$tabsql,&$tabsqlsort,&$tabfield,&$tabfieldvalue,&$tabfieldinsert,&$tabrowid,&$tabcond
1497 // @phan-suppress-next-line PhanUndeclaredProperty
1498 if (empty($objMod->dictionaries) && !empty($objMod->{"dictionnaries"})) {
1499 // @phan-suppress-next-line PhanUndeclaredProperty
1500 $objMod->dictionaries = $objMod->{"dictionnaries"}; // For backward compatibility
1501 }
1502 // phpcs:enable
1503
1504 if (!empty($objMod->dictionaries)) {
1505 //var_dump($objMod->dictionaries['tabname']);
1506 $nbtabname = $nbtablib = $nbtabsqlsort = $nbtabfield = $nbtabfieldvalue = $nbtabfieldinsert = $nbtabrowid = $nbtabcond = $nbtabfieldcheck = $nbtabhelp = $nbtabsql = 0;
1507 $tabnamerelwithkey = array();
1508 foreach ($objMod->dictionaries['tabname'] as $key => $val) {
1509 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $val);
1510 $nbtabname++;
1511 $taborder[] = max($taborder) + 1;
1512 $tabname[] = $val;
1513 $tabnamerelwithkey[$key] = $val;
1514 $tabcomplete[$tmptablename]['picto'] = $objMod->picto;
1515 } // Position
1516 foreach ($objMod->dictionaries['tablib'] as $key => $val) {
1517 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1518 $nbtablib++;
1519 $tablib[] = $val;
1520 $tabcomplete[$tmptablename]['lib'] = $val;
1521 }
1522 foreach ($objMod->dictionaries['tabsql'] as $key => $val) {
1523 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1524 $nbtabsql++;
1525 $tabsql[] = $val; // @phan-suppress-current-line SqlInjection
1526 $tabcomplete[$tmptablename]['sql'] = $val; // @phan-suppress-current-line SqlInjection
1527 }
1528 foreach ($objMod->dictionaries['tabsqlsort'] as $key => $val) {
1529 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1530 $nbtabsqlsort++;
1531 $tabsqlsort[] = $val; // @phan-suppress-current-line SqlInjection
1532 $tabcomplete[$tmptablename]['sqlsort'] = $val; // @phan-suppress-current-line SqlInjection
1533 }
1534 foreach ($objMod->dictionaries['tabfield'] as $key => $val) {
1535 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1536 $nbtabfield++;
1537 $tabfield[] = $val;
1538 $tabcomplete[$tmptablename]['field'] = $val;
1539 }
1540 foreach ($objMod->dictionaries['tabfieldvalue'] as $key => $val) {
1541 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1542 $nbtabfieldvalue++;
1543 $tabfieldvalue[] = $val;
1544 $tabcomplete[$tmptablename]['value'] = $val;
1545 }
1546 foreach ($objMod->dictionaries['tabfieldinsert'] as $key => $val) {
1547 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1548 $nbtabfieldinsert++;
1549 $tabfieldinsert[] = $val; // @phan-suppress-current-line SqlInjection
1550 $tabcomplete[$tmptablename]['fieldinsert'] = $val; // @phan-suppress-current-line SqlInjection
1551 }
1552 foreach ($objMod->dictionaries['tabrowid'] as $key => $val) {
1553 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1554 $nbtabrowid++;
1555 $tabrowid[] = (int) $val;
1556 $tabcomplete[$tmptablename]['rowid'] = (int) $val;
1557 }
1558 foreach ($objMod->dictionaries['tabcond'] as $key => $val) {
1559 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1560 $nbtabcond++;
1561 $tabcond[] = $val;
1562 $tabcomplete[$tmptablename]['cond'] = $val;
1563 }
1564 if (!empty($objMod->dictionaries['tabhelp'])) {
1565 foreach ($objMod->dictionaries['tabhelp'] as $key => $val) {
1566 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1567 $nbtabhelp++;
1568 $tabhelp[] = $val;
1569 $tabcomplete[$tmptablename]['help'] = $val;
1570 }
1571 }
1572 if (!empty($objMod->dictionaries['tabfieldcheck'])) {
1573 foreach ($objMod->dictionaries['tabfieldcheck'] as $key => $val) {
1574 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1575 $nbtabfieldcheck++;
1576 $tabcomplete[$tmptablename]['fieldcheck'] = $val;
1577 }
1578 }
1579
1580 if ($nbtabname != $nbtablib || $nbtablib != $nbtabsql || $nbtabsql != $nbtabsqlsort) {
1581 print 'Error in descriptor of module '.$const_name.'. Array ->dictionaries has not same number of record for key "tabname", "tablib", "tabsql" and "tabsqlsort"';
1582 //print "$const_name: $nbtabname=$nbtablib=$nbtabsql=$nbtabsqlsort=$nbtabfield=$nbtabfieldvalue=$nbtabfieldinsert=$nbtabrowid=$nbtabcond=$nbtabfieldcheck=$nbtabhelp\n";
1583 } else {
1584 $taborder[] = 0; // Add an empty line
1585 }
1586 }
1587
1588 $j++;
1589 $i++;
1590 } else {
1591 dol_syslog("Module ".get_class($objMod)." not qualified");
1592 }
1593 }
1594 }
1595 }
1596 closedir($handle);
1597 } else {
1598 dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
1599 }
1600 }
1601
1602 dol_syslog("", LOG_DEBUG, -1);
1603
1604 return 1;
1605}
1606
1613function activateModulesRequiredByCountry($country_code)
1614{
1615 global $db;
1616
1617 $modulesdir = dolGetModulesDirs();
1618
1619 foreach ($modulesdir as $dir) {
1620 // Load modules attributes in arrays (name, numero, orders) from dir directory
1621 dol_syslog("Scan directory ".$dir." for modules");
1622 $handle = @opendir(dol_osencode($dir));
1623 if (is_resource($handle)) {
1624 while (($file = readdir($handle)) !== false) {
1625 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
1626 $modName = substr($file, 0, dol_strlen($file) - 10);
1627
1628 if ($modName) {
1629 if ($modName === 'modFournisseur' && getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
1630 dol_syslog("Module modFournisseur skipped because MAIN_USE_NEW_SUPPLIERMOD is enabled", LOG_DEBUG);
1631 continue;
1632 }
1633 if (in_array($modName, ['modSupplierInvoice', 'modSupplierOrder']) && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
1634 dol_syslog("Module ".$modName." skipped because MAIN_USE_NEW_SUPPLIERMOD is disabled", LOG_DEBUG);
1635 continue;
1636 }
1637
1638 include_once $dir.$file;
1639 $objMod = new $modName($db);
1640 '@phan-var-force DolibarrModules $objMod';
1643 $modulequalified = 1;
1644
1645 // We discard modules according to features level (PS: if module is activated we always show it)
1646 $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
1647
1648 if ($objMod->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
1649 $modulequalified = 0;
1650 }
1651 if ($objMod->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
1652 $modulequalified = 0;
1653 }
1654 if (getDolGlobalString($const_name)) {
1655 $modulequalified = 0; // already activated
1656 }
1657
1658 if ($modulequalified) {
1659 // Load languages files of module
1660 if (isset($objMod->automatic_activation[$country_code])) {
1661 activateModule($modName, 1, 0);
1662
1663 setEventMessages($objMod->automatic_activation[$country_code], null, 'warnings');
1664 }
1665 } else {
1666 dol_syslog("Module ".get_class($objMod)." not qualified");
1667 }
1668 }
1669 }
1670 }
1671 closedir($handle);
1672 } else {
1673 dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
1674 }
1675 }
1676
1677 return 1;
1678}
1679
1686function complete_elementList_with_modules(&$elementList)
1687{
1688 global $db, $modules, $conf, $langs;
1689
1690 // Search modules
1691 $filename = array();
1692 $modules = array();
1693 $orders = array();
1694 $categ = array();
1695 $dirmod = array();
1696
1697 $i = 0; // is a sequencer of modules found
1698 $j = 0; // j is module number. Automatically affected if module number not defined.
1699
1700 dol_syslog("complete_elementList_with_modules Search external modules to complete the list of contact element", LOG_DEBUG, 1);
1701
1702 $modulesdir = dolGetModulesDirs();
1703
1704 foreach ($modulesdir as $dir) {
1705 // Load modules attributes in arrays (name, numero, orders) from dir directory
1706 //print $dir."\n<br>";
1707 dol_syslog("Scan directory ".$dir." for modules");
1708 $handle = @opendir(dol_osencode($dir));
1709 if (is_resource($handle)) {
1710 while (($file = readdir($handle)) !== false) {
1711 //print "$i ".$file."\n<br>";
1712 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
1713 $modName = substr($file, 0, dol_strlen($file) - 10);
1714
1715 if ($modName) {
1716 include_once $dir.$file;
1717 $objMod = new $modName($db);
1720 if ($objMod->numero > 0) {
1721 $j = $objMod->numero;
1722 } else {
1723 $j = 1000 + $i;
1724 }
1725
1726 $modulequalified = 1;
1727
1728 // We discard modules according to features level (PS: if module is activated we always show it)
1729 $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
1730 if ($objMod->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2 && getDolGlobalString($const_name)) {
1731 $modulequalified = 0;
1732 }
1733 if ($objMod->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1 && getDolGlobalString($const_name)) {
1734 $modulequalified = 0;
1735 }
1736 // If module is not activated disqualified
1737 if (!getDolGlobalString($const_name)) {
1738 $modulequalified = 0;
1739 }
1740
1741 if ($modulequalified) {
1742 // Load languages files of module
1743 if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
1744 foreach ($objMod->langfiles as $langfile) {
1745 $langs->load($langfile);
1746 }
1747 }
1748
1749 $modules[$i] = $objMod;
1750 $filename[$i] = $modName;
1751 $orders[$i] = $objMod->family."_".$j; // Sort on family then module number
1752 $dirmod[$i] = $dir;
1753 //print "x".$modName." ".$orders[$i]."\n<br>";
1754
1755 if (!empty($objMod->module_parts['contactelement'])) {
1756 if (is_array($objMod->module_parts['contactelement'])) {
1757 foreach ($objMod->module_parts['contactelement'] as $elem => $title) {
1758 $elementList[$elem] = $langs->trans($title);
1759 }
1760 } else {
1761 $elementList[$objMod->name] = $langs->trans($objMod->name);
1762 }
1763 }
1764
1765 $j++;
1766 $i++;
1767 } else {
1768 dol_syslog("Module ".get_class($objMod)." not qualified");
1769 }
1770 }
1771 }
1772 }
1773 closedir($handle);
1774 } else {
1775 dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
1776 }
1777 }
1778
1779 dol_syslog("", LOG_DEBUG, -1);
1780
1781 return 1;
1782}
1783
1794function form_constantes($tableau, $strictw3c = 2, $helptext = '', $text = '')
1795{
1796 global $db, $langs, $conf, $user;
1797 global $_Avery_Labels;
1798
1799 $form = new Form($db);
1800
1801 print '<div class="div-table-responsive-no-min">';
1802 print '<table class="noborder centpercent">';
1803 print '<tr class="liste_titre">';
1804 print '<td class="">'.$langs->trans("Description").'</td>';
1805 print '<td>';
1806 if ($text) {
1807 $text = $langs->trans($text);
1808 print $form->textwithpicto($text, $helptext, 1, 'help', '', 0, 2, 'idhelptext');
1809 }
1810 print '</td>';
1811 print "</tr>\n";
1812
1813 foreach ($tableau as $key => $const) { // Loop on each param
1814 $label = '';
1815 // $const is a const key like 'MYMODULE_ABC'
1816 if (is_array($const)) {
1817 $type = $const['type'];
1818 $label = $const['label'];
1819 $const = $key;
1820 } else {
1821 $type = $const;
1822 $const = $key;
1823 }
1824
1825 $sql = "SELECT ";
1826 $sql .= "rowid";
1827 $sql .= ", ".$db->decrypt('name')." as name";
1828 $sql .= ", ".$db->decrypt('value')." as value";
1829 $sql .= ", type";
1830 $sql .= ", note";
1831 $sql .= " FROM ".MAIN_DB_PREFIX."const";
1832 $sql .= " WHERE ".$db->decrypt('name')." = '".$db->escape($const)."'";
1833 $sql .= " AND entity IN (0, ".((int) $conf->entity).")";
1834 $sql .= " ORDER BY name ASC, entity DESC";
1835 $result = $db->query($sql);
1836
1837 dol_syslog("List params", LOG_DEBUG);
1838
1839 if ($result) {
1840 $obj = $db->fetch_object($result); // Take first result of select
1841
1842 if (empty($obj)) { // If not yet into table
1843 $obj = (object) array('rowid' => '', 'name' => $const, 'value' => '', 'type' => $type, 'note' => '');
1844 }
1845
1846 print '<tr class="oddeven">';
1847
1848 // Show label of parameter
1849 print '<td>';
1850 print '<input type="hidden" name="rowid[]" value="'.$obj->rowid.'">';
1851 print '<input type="hidden" name="constname[]" value="'.$const.'">';
1852 print '<input type="hidden" name="constnote_'.$obj->name.'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
1853 print '<input type="hidden" name="consttype_'.$obj->name.'" value="'.($obj->type ? $obj->type : 'string').'">';
1854
1855 $picto = 'generic';
1856 $tmparray = explode(':', $obj->type);
1857 if (!empty($tmparray[1])) {
1858 $picto = preg_replace('/_send$/', '', $tmparray[1]);
1859 }
1860 print img_picto('', $picto, 'class="pictofixedwidth"');
1861
1862 if (!empty($tableau[$key]['tooltip'])) {
1863 print $form->textwithpicto($label ? $label : $langs->trans('Desc'.$const), $tableau[$key]['tooltip']);
1864 } else {
1865 print($label ? $label : $langs->trans('Desc'.$const));
1866 }
1867
1868 if ($const == 'ADHERENT_MAILMAN_URL') {
1869 print '. '.$langs->trans("Example").': <a href="#" id="exampleclick1">'.img_down().'</a><br>';
1870 //print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members?adminpw=%MAILMAN_ADMINPW%&subscribees=%EMAIL%&send_welcome_msg_to_this_batch=1';
1871 print '<div id="example1" class="hidden">';
1872 print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/add?subscribees_upload=%EMAIL%&amp;adminpw=%MAILMAN_ADMINPW%&amp;subscribe_or_invite=0&amp;send_welcome_msg_to_this_batch=0&amp;notification_to_list_owner=0';
1873 print '</div>';
1874 } elseif ($const == 'ADHERENT_MAILMAN_UNSUB_URL') {
1875 print '. '.$langs->trans("Example").': <a href="#" id="exampleclick2">'.img_down().'</a><br>';
1876 print '<div id="example2" class="hidden">';
1877 print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/remove?unsubscribees_upload=%EMAIL%&amp;adminpw=%MAILMAN_ADMINPW%&amp;send_unsub_ack_to_this_batch=0&amp;send_unsub_notifications_to_list_owner=0';
1878 print '</div>';
1879 //print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%';
1880 } elseif ($const == 'ADHERENT_MAILMAN_LISTS') {
1881 print '. '.$langs->trans("Example").': <a href="#" id="exampleclick3">'.img_down().'</a><br>';
1882 print '<div id="example3" class="hidden">';
1883 print 'mymailmanlist<br>';
1884 print 'mymailmanlist1,mymailmanlist2<br>';
1885 print 'TYPE:Type1:mymailmanlist1,TYPE:Type2:mymailmanlist2<br>';
1886 if (isModEnabled('category')) {
1887 print 'CATEG:Categ1:mymailmanlist1,CATEG:Categ2:mymailmanlist2<br>';
1888 }
1889 print '</div>';
1890 //print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%';
1891 } elseif (in_array($const, ['ADHERENT_MAIL_FROM', 'ADHERENT_CC_MAIL_FROM'])) {
1892 print ' '.img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
1893 }
1894
1895 print "</td>\n";
1896
1897 // Value
1898 if ($const == 'ADHERENT_CARD_TYPE' || $const == 'ADHERENT_ETIQUETTE_TYPE') {
1899 print '<td>';
1900 // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
1901 require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
1902 $arrayoflabels = array();
1903 foreach (array_keys($_Avery_Labels) as $codecards) {
1904 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
1905 }
1906 print $form->selectarray('constvalue'.($strictw3c == 3 ? '_'.$const : '[]'), $arrayoflabels, ($obj->value ? $obj->value : 'CARD'), 1, 0, 0);
1907 print '<input type="hidden" name="consttype" value="yesno">';
1908 print '<input type="hidden" name="constnote[]" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
1909 print '</td>';
1910 } else {
1911 print '<td>';
1912 print '<input type="hidden" name="consttype'.($strictw3c == 3 ? '_'.$const : '[]').'" value="'.($obj->type ? $obj->type : 'string').'">';
1913 print '<input type="hidden" name="constnote'.($strictw3c == 3 ? '_'.$const : '[]').'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
1914 if ($obj->type == 'textarea' || in_array($const, array('ADHERENT_CARD_TEXT', 'ADHERENT_CARD_TEXT_RIGHT', 'ADHERENT_ETIQUETTE_TEXT'))) {
1915 print '<textarea class="flat" name="constvalue'.($strictw3c == 3 ? '_'.$const : '[]').'" cols="50" rows="5" wrap="soft">'."\n";
1916 print $obj->value;
1917 print "</textarea>\n";
1918 } elseif ($obj->type == 'html') {
1919 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1920 $doleditor = new DolEditor('constvalue'.($strictw3c == 3 ? '_'.$const : '[]'), $obj->value, '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
1921 $doleditor->Create();
1922 } elseif ($obj->type == 'yesno') {
1923 print $form->selectyesno('constvalue'.($strictw3c == 3 ? '_'.$const : '[]'), $obj->value, 1, false, 0, 1);
1924 } elseif (preg_match('/emailtemplate/', $obj->type)) {
1925 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1926 $formmail = new FormMail($db);
1927
1928 $tmp = explode(':', $obj->type);
1929
1930 $formmail->fetchAllEMailTemplate($tmp[1], $user, null, -1); // We set lang=null to get in priority record with no lang
1931
1932 $arrayofmessagename = array();
1933 if (is_array($formmail->lines_model)) {
1934 foreach ($formmail->lines_model as $modelmail) {
1935 $moreonlabel = '';
1936 if (!empty($arrayofmessagename[$modelmail->label])) {
1937 $moreonlabel = ' <span class="opacitymedium">('.$langs->trans("SeveralLangugeVariatFound").')</span>';
1938 }
1939 // The 'label' is the key that is unique if we exclude the language
1940 $arrayofmessagename[$modelmail->label.':'.$tmp[1]] = $langs->trans(preg_replace('/\‍(|\‍)/', '', $modelmail->label)).$moreonlabel;
1941 }
1942 }
1943
1944 print $form->selectarray('constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')), $arrayofmessagename, $obj->value.':'.$tmp[1], 'None', 0, 0, '', 0, 0, 0, '', '', 1);
1945
1946 print '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/mails_templates.php', ['action' => 'create', 'type_template' => $tmp[1], 'backtopage' => dolBuildUrl($_SERVER["PHP_SELF"])]).'">'.img_picto('', 'add').'</a>';
1947 } elseif (preg_match('/MAIL_FROM$/i', $const)) {
1948 print img_picto('', 'email', 'class="pictofixedwidth"').'<input type="text" class="flat minwidth300" name="constvalue'.($strictw3c == 3 ? '_'.$const : '[]').'" value="'.dol_escape_htmltag($obj->value).'">';
1949 } else { // type = 'string' ou 'chaine'
1950 print '<input type="text" class="flat minwidth300" name="constvalue'.($strictw3c == 3 ? '_'.$const : '[]').'" value="'.dol_escape_htmltag($obj->value).'">';
1951 }
1952 print '</td>';
1953 }
1954
1955 print "</tr>\n";
1956 }
1957 }
1958 print '</table>';
1959 print '</div>';
1960}
1961
1962
1970{
1971 global $langs;
1972
1973 $text = $langs->transnoentitiesnoconv("OnlyFollowingModulesAreOpenedToExternalUsers");
1974 $listofmodules = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')); // List of modules qualified for external user management
1975
1976 $i = 0;
1977 if (!empty($modules)) {
1978 $tmpmodules = dol_sort_array($modules, 'module_position');
1979 foreach ($tmpmodules as $module) { // Loop on array of modules
1980 $moduleconst = $module->const_name;
1981 $modulename = strtolower($module->name);
1982 //print 'modulename='.$modulename;
1983
1984 //if (empty($conf->global->$moduleconst)) continue;
1985 if (!in_array($modulename, $listofmodules)) {
1986 continue;
1987 }
1988 //var_dump($modulename.' - '.$langs->trans('Module'.$module->numero.'Name'));
1989
1990 if ($i > 0) {
1991 $text .= ', ';
1992 } else {
1993 $text .= ' ';
1994 }
1995 $i++;
1996
1997 $tmptext = $langs->transnoentitiesnoconv('Module'.$module->numero.'Name');
1998 if ($tmptext != 'Module'.$module->numero.'Name') {
1999 $text .= $langs->transnoentitiesnoconv('Module'.$module->numero.'Name');
2000 } else {
2001 $text .= $langs->transnoentitiesnoconv($module->name);
2002 }
2003 }
2004 }
2005
2006 return $text;
2007}
2008
2009
2019function addDocumentModel($name, $type, $label = '', $description = '')
2020{
2021 global $db, $conf;
2022
2023 $db->begin();
2024
2025 $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
2026 $sql .= " VALUES ('".$db->escape($name)."','".$db->escape($type)."',".((int) $conf->entity).", ";
2027 $sql .= ($label ? "'".$db->escape($label)."'" : 'null').", ";
2028 $sql .= (!empty($description) ? "'".$db->escape($description)."'" : "null");
2029 $sql .= ")";
2030
2031 dol_syslog("admin.lib::addDocumentModel", LOG_DEBUG);
2032 $resql = $db->query($sql);
2033 if ($resql) {
2034 $db->commit();
2035 return 1;
2036 } else {
2038 $db->rollback();
2039 return -1;
2040 }
2041}
2042
2050function delDocumentModel($name, $type)
2051{
2052 global $db, $conf;
2053
2054 $db->begin();
2055
2056 $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
2057 $sql .= " WHERE nom = '".$db->escape($name)."'";
2058 $sql .= " AND type = '".$db->escape($type)."'";
2059 $sql .= " AND entity = ".((int) $conf->entity);
2060
2061 dol_syslog("admin.lib::delDocumentModel", LOG_DEBUG);
2062 $resql = $db->query($sql);
2063 if ($resql) {
2064 $db->commit();
2065 return 1;
2066 } else {
2068 $db->rollback();
2069 return -1;
2070 }
2071}
2072
2073
2080{
2081 ob_start();
2082 phpinfo();
2083 $phpinfostring = ob_get_contents();
2084 ob_end_clean();
2085
2086 $info_arr = array();
2087 $info_lines = explode("\n", strip_tags($phpinfostring, "<tr><td><h2>"));
2088 $cat = "General";
2089 foreach ($info_lines as $line) {
2090 // new cat?
2091 $title = array();
2092 preg_match("~<h2>(.*)</h2>~", $line, $title) ? $cat = $title[1] : null;
2093 $val = array();
2094 if (preg_match("~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val)) {
2095 $info_arr[trim($cat)][trim($val[1])] = $val[2];
2096 } elseif (preg_match("~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val)) {
2097 $info_arr[trim($cat)][trim($val[1])] = array("local" => $val[2], "master" => $val[3]);
2098 }
2099 }
2100 return $info_arr;
2101}
2102
2109{
2110 global $langs, $conf;
2111
2112 $h = 0;
2113 $head = array();
2114
2115 $head[$h][0] = DOL_URL_ROOT."/admin/company.php";
2116 $head[$h][1] = $langs->trans("MyOrganization");
2117 $head[$h][2] = 'company';
2118 $h++;
2119
2120 $head[$h][0] = DOL_URL_ROOT."/admin/company_socialnetworks.php";
2121 $head[$h][1] = $langs->trans("SocialNetworksInformation");
2122 $head[$h][2] = 'socialnetworks';
2123
2124 $h++;
2125 $head[$h][0] = DOL_URL_ROOT."/admin/openinghours.php";
2126 $head[$h][1] = $langs->trans("OpeningHours");
2127 $head[$h][2] = 'openinghours';
2128 $h++;
2129
2130 $head[$h][0] = DOL_URL_ROOT."/admin/subcontractors.php";
2131 $head[$h][1] = $langs->trans("Subcontractors");
2132 $head[$h][2] = 'subcontractors';
2133 $h++;
2134
2135 complete_head_from_modules($conf, $langs, null, $head, $h, 'mycompany_admin', 'add');
2136
2137 complete_head_from_modules($conf, $langs, null, $head, $h, 'mycompany_admin', 'remove');
2138
2139 return $head;
2140}
2141
2148{
2149 global $langs, $conf, $user;
2150
2151 $h = 0;
2152 $head = array();
2153
2154 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
2155 $head[$h][0] = DOL_URL_ROOT."/admin/mails.php";
2156 $head[$h][1] = $langs->trans("OutGoingEmailSetup");
2157 $head[$h][2] = 'common';
2158 $h++;
2159
2160 if (isModEnabled('mailing')) {
2161 $head[$h][0] = DOL_URL_ROOT."/admin/mails_emailing.php";
2162 $head[$h][1] = $langs->trans("OutGoingEmailSetupForEmailing", $langs->transnoentitiesnoconv("EMailing"));
2163 $head[$h][2] = 'common_emailing';
2164 $h++;
2165 }
2166
2167 if (isModEnabled('ticket')) {
2168 $head[$h][0] = DOL_URL_ROOT."/admin/mails_ticket.php";
2169 $head[$h][1] = $langs->trans("OutGoingEmailSetupForEmailing", $langs->transnoentitiesnoconv("Ticket"));
2170 $head[$h][2] = 'common_ticket';
2171 $h++;
2172 }
2173
2174 if (!getDolGlobalString('MAIN_MAIL_HIDE_CUSTOM_SENDING_METHOD_FOR_PASSWORD_RESET')) {
2175 $head[$h][0] = DOL_URL_ROOT."/admin/mails_passwordreset.php";
2176 $head[$h][1] = $langs->trans("OutGoingEmailSetupForEmailing", $langs->transnoentitiesnoconv("PasswordReset"));
2177 $head[$h][2] = 'common_passwordreset';
2178 $h++;
2179 }
2180 }
2181
2182 // Admin and non admin can view this menu entry, but it is not shown yet when we on user menu "Email templates"
2183 if (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates') {
2184 $head[$h][0] = DOL_URL_ROOT."/admin/mails_senderprofile_list.php";
2185 $head[$h][1] = $langs->trans("EmailSenderProfiles");
2186 $head[$h][2] = 'senderprofiles';
2187 $h++;
2188 }
2189
2190 $head[$h][0] = DOL_URL_ROOT."/admin/mails_templates.php";
2191 $head[$h][1] = $langs->trans("EMailTemplates");
2192 $head[$h][2] = 'templates';
2193 $h++;
2194
2195 $head[$h][0] = DOL_URL_ROOT."/admin/mails_ingoing.php";
2196 $head[$h][1] = $langs->trans("InGoingEmailSetup", $langs->transnoentitiesnoconv("EMailing"));
2197 $head[$h][2] = 'common_ingoing';
2198 $h++;
2199
2200 complete_head_from_modules($conf, $langs, null, $head, $h, 'email_admin', 'remove');
2201
2202 return $head;
2203}
2204
2211{
2212 return array(
2213 // Fetch directives
2214 "child-src" => array("label" => "child-src", "data-directivetype" => "fetch"),
2215 "connect-src" => array("label" => "connect-src", "data-directivetype" => "fetch"),
2216 "default-src" => array("label" => "default-src", "data-directivetype" => "fetch"),
2217 "fenced-frame-src" => array("label" => "fenced-frame-src", "data-directivetype" => "fetch"),
2218 "font-src" => array("label" => "font-src", "data-directivetype" => "fetch"),
2219 "frame-src" => array("label" => "frame-src", "data-directivetype" => "fetch"),
2220 "img-src" => array("label" => "img-src", "data-directivetype" => "fetch"),
2221 "manifest-src" => array("label" => "manifest-src", "data-directivetype" => "fetch"),
2222 "media-src" => array("label" => "media-src", "data-directivetype" => "fetch"),
2223 "object-src" => array("label" => "object-src", "data-directivetype" => "fetch"),
2224 "prefetch-src" => array("label" => "prefetch-src", "data-directivetype" => "fetch"),
2225 "script-src" => array("label" => "script-src", "data-directivetype" => "fetch"),
2226 "script-src-elem" => array("label" => "script-src-elem", "data-directivetype" => "fetch"),
2227 "script-src-attr" => array("label" => "script-src-attr", "data-directivetype" => "fetch"),
2228 "style-src" => array("label" => "style-src","data-directivetype" => "fetch"),
2229 "style-src-elem" => array("label" => "style-src-elem", "data-directivetype" => "fetch"),
2230 "style-src-attr" => array("label" => "style-src-attr", "data-directivetype" => "fetch"),
2231 "worker-src" => array("label" => "worker-src", "data-directivetype" => "fetch"),
2232 // Document directives
2233 "base-uri" => array("label" => "base-uri", "data-directivetype" => "document"),
2234 "sandbox" => array("label" => "sandbox", "data-directivetype" => "document"),
2235 // Navigation directives
2236 "form-action" => array("label" => "form-action", "data-directivetype" => "navigation"),
2237 "frame-ancestors" => array("label" => "frame-ancestors", "data-directivetype" => "navigation"),
2238 // Reporting directives
2239 "report-to" => array("label" => "report-to", "data-directivetype" => "reporting"),
2240 // Other directives
2241 "require-trusted-types-for" => array("label" => "require-trusted-types-for", "data-directivetype" => "require-trusted-types-for"),
2242 "trusted-types" => array("label" => "trusted-types", "data-directivetype" => "trusted-types"),
2243 "upgrade-insecure-requests" => array("label" => "upgrade-insecure-requests", "data-directivetype" => "none"),
2244 );
2245}
2246
2253{
2254 return array(
2255 // Fetch directives
2256 "fetch" => array(
2257 "*" => array("label" => "*", "data-sourcetype" => "select"),
2258 "blob" => array("label" => "blob:", "data-sourcetype" => "blob"),
2259 "data" => array("label" => "data:", "data-sourcetype" => "data"),
2260 "self" => array("label" => "self", "data-sourcetype" => "quoted"),
2261 "unsafe-eval" => array("label" => "unsafe-eval", "data-sourcetype" => "quoted"),
2262 "wasm-unsafe-eval" => array("label" => "wasm-unsafe-eval", "data-sourcetype" => "quoted"),
2263 "unsafe-inline" => array("label" => "unsafe-inline", "data-sourcetype" => "quoted"),
2264 "unsafe-hashes" => array("label" => "unsafe-hashes", "data-sourcetype" => "quoted"),
2265 "inline-speculation-rules" => array("label" => "inline-speculation-rules", "data-sourcetype" => "quoted"),
2266 "strict-dynamic" => array("label" => "strict-dynamic", "data-sourcetype" => "quoted"),
2267 "report-sample" => array("label" => "report-sample", "data-sourcetype" => "quoted"),
2268 "host-source" => array("label" => "host-source (*.mydomain.com)", "data-sourcetype" => "input"),
2269 "scheme-source" => array("label" => "scheme-source", "data-sourcetype" => "input"),
2270 ),
2271 // Document directives
2272 "document" => array(
2273 "none" => array("label" => "self", "data-sourcetype" => "quoted"),
2274 "self" => array("label" => "self", "data-sourcetype" => "quoted"),
2275 "host-source" => array("label" => "host-source (*.mydomain.com)", "data-sourcetype" => "input"),
2276 "scheme-source" => array("label" => "scheme-source (*.mydomain.com)", "data-sourcetype" => "input"),
2277 ),
2278 // Navigation directives
2279 "navigation" => array(
2280 "none" => array("label" => "self", "data-sourcetype" => "quoted"),
2281 "self" => array("label" => "self", "data-sourcetype" => "quoted"),
2282 "host-source" => array("label" => "host-source (*.mydomain.com)", "data-sourcetype" => "input"),
2283 "scheme-source" => array("label" => "scheme-source", "data-sourcetype" => "input"),
2284 ),
2285 // Reporting directives
2286 "reporting" => array(
2287 "report-to" => array("label" => "report-to", "data-sourcetype" => "input"),
2288 ),
2289 // Other directives
2290 "require-trusted-types-for" => array(
2291 "script" => array("label" => "script", "data-sourcetype" => "select"),
2292 ),
2293 "trusted-types" => array(
2294 "policyName" => array("label" => "policyName", "data-sourcetype" => "input"),
2295 "none" => array("label" => "none", "data-sourcetype" => "quoted"),
2296 "allow-duplicates" => array("label" => "allow-duplicates", "data-sourcetype" => "quoted"),
2297 ),
2298 );
2299}
2300
2307function GetContentPolicyToArray($forceCSP)
2308{
2309 $forceCSPArr = array();
2310 $sourceCSPArr = GetContentPolicySources();
2311 $sourceCSPArrflatten = array();
2312
2313 // We remove a level for sources array
2314 foreach ($sourceCSPArr as $key => $arr) {
2315 $sourceCSPArrflatten = array_merge($sourceCSPArrflatten, array_keys($arr));
2316 }
2317 // Manage the issue where the data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D string is getting split, as well as the issue with the "add" button.
2318 $forceCSP = preg_replace('/;base64,/', "__semicolumnbase64__", $forceCSP);
2319 $securitypolicies = explode(";", $forceCSP);
2320
2321 // Loop on each security policy to create an array
2322 foreach ($securitypolicies as $key => $securitypolicy) {
2323 if ($securitypolicy == "") {
2324 continue;
2325 }
2326 $securitypolicy = preg_replace('/__semicolumnbase64__/', ";base64,", $securitypolicy);
2327 $securitypolicyarr = explode(" ", $securitypolicy);
2328 $directive = array_shift($securitypolicyarr);
2329 // Remove unwanted spaces
2330 while ($directive == "") {
2331 $directive = array_shift($securitypolicyarr);
2332 }
2333 if (empty($directive)) {
2334 continue;
2335 }
2336 $sources = $securitypolicyarr;
2337 if (empty($sources)) {
2338 $forceCSPArr[$directive] = array();
2339 } else {
2340 //Loop on each sources to add to the right directive array key
2341 foreach ($sources as $key2 => $source) {
2342 $source = str_replace("'", "", $source);
2343 if (empty($source)) {
2344 continue;
2345 }
2346 if (empty($forceCSPArr[$directive])) {
2347 $forceCSPArr[$directive] = array($source);
2348 } else {
2349 $forceCSPArr[$directive][] = $source;
2350 }
2351 }
2352 }
2353 }
2354 return $forceCSPArr;
2355}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
versiontostring($versionarray)
Return a version in a string from a version into an array.
Definition admin.lib.php:40
security_prepare_head()
Prepare array with list of tabs.
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
form_constantes($tableau, $strictw3c=2, $helptext='', $text='')
Show array with constants to edit.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
purgeSessions($mysessionid)
Purge existing sessions.
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
versiondolibarrarray()
Return version Dolibarr.
delDocumentModel($name, $type)
Delete document model used by doc generator.
showModulesExludedForExternal($modules)
Show array with constants to edit.
versionphparray()
Return version PHP.
ihm_prepare_head()
Prepare array with list of tabs.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
Definition admin.lib.php:72
modulehelp_prepare_head($object)
Prepare array with list of tabs.
listOfSessions()
Return list of session.
phpinfo_array()
Return the php_info into an array.
dolibarr_get_const($db, $name, $entity=1)
Get the value of a setup constant from database.
modules_prepare_head($nbofactivatedmodules, $nboftotalmodules, $nbmodulesnotautoenabled)
Prepare array with list of tabs.
GetContentPolicySources()
Prepare array of sources for HTTP headers.
GetContentPolicyToArray($forceCSP)
Transform a Content Security Policy to an array.
email_admin_prepare_head()
Return array head with list of tabs to view object information.
translation_prepare_head()
Prepare array with list of tabs.
company_admin_prepare_head()
Return array head with list of tabs to view object information.
defaultvalues_prepare_head()
Prepare array with list of tabs.
GetContentPolicyDirectives()
Prepare array of directives for HTTP headers.
Class to manage a WYSIWYG editor.
Class DolibarrModules.
Class to manage generation of HTML components Only common components must be here.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
Class to manage hooks.
global $mysoc
dolKeepOnlyPhpCode($str)
Keep only PHP code part from a HTML string page.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dolGetModulesDirs($subdir='')
Return list of directories that contain modules.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
Definition html.lib.php:172
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
dolListSessions()
List sessions in db.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.
checkPHPCode(&$phpfullcodestringold, &$phpfullcodestring)
Check that the new string $phpfullcodestring contains only php code (including <php tag)