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