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