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