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