dolibarr 20.0.0
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 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 * or see https://www.gnu.org/
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
30
38function versiontostring($versionarray)
39{
40 $string = '?';
41 if (isset($versionarray[0])) {
42 $string = $versionarray[0];
43 }
44 if (isset($versionarray[1])) {
45 $string .= '.'.$versionarray[1];
46 }
47 if (isset($versionarray[2])) {
48 $string .= '.'.$versionarray[2];
49 }
50 return $string;
51}
52
68function versioncompare($versionarray1, $versionarray2)
69{
70 $ret = 0;
71 $level = 0;
72 $count1 = count($versionarray1);
73 $count2 = count($versionarray2);
74 $maxcount = max($count1, $count2);
75 while ($level < $maxcount) {
76 $operande1 = isset($versionarray1[$level]) ? $versionarray1[$level] : 0;
77 $operande2 = isset($versionarray2[$level]) ? $versionarray2[$level] : 0;
78 if (preg_match('/alpha|dev/i', $operande1)) {
79 $operande1 = -5;
80 }
81 if (preg_match('/alpha|dev/i', $operande2)) {
82 $operande2 = -5;
83 }
84 if (preg_match('/beta$/i', $operande1)) {
85 $operande1 = -4;
86 }
87 if (preg_match('/beta$/i', $operande2)) {
88 $operande2 = -4;
89 }
90 if (preg_match('/beta([0-9])+/i', $operande1)) {
91 $operande1 = -3;
92 }
93 if (preg_match('/beta([0-9])+/i', $operande2)) {
94 $operande2 = -3;
95 }
96 if (preg_match('/rc$/i', $operande1)) {
97 $operande1 = -2;
98 }
99 if (preg_match('/rc$/i', $operande2)) {
100 $operande2 = -2;
101 }
102 if (preg_match('/rc([0-9])+/i', $operande1)) {
103 $operande1 = -1;
104 }
105 if (preg_match('/rc([0-9])+/i', $operande2)) {
106 $operande2 = -1;
107 }
108 $level++;
109 //print 'level '.$level.' '.$operande1.'-'.$operande2.'<br>';
110 if ($operande1 < $operande2) {
111 $ret = -$level;
112 break;
113 }
114 if ($operande1 > $operande2) {
115 $ret = $level;
116 break;
117 }
118 }
119 //print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret.'<br>'."\n";
120 return $ret;
121}
122
123
131{
132 return explode('.', PHP_VERSION);
133}
134
142{
143 return explode('.', DOL_VERSION);
144}
145
146
170function run_sql($sqlfile, $silent = 1, $entity = 0, $usesavepoint = 1, $handler = '', $okerror = 'default', $linelengthlimit = 32768, $nocommentremoval = 0, $offsetforchartofaccount = 0, $colspan = 0, $onlysqltoimportwebsite = 0, $database = '')
171{
172 global $db, $conf, $langs, $user;
173
174 dol_syslog("Admin.lib::run_sql run sql file ".$sqlfile." silent=".$silent." entity=".$entity." usesavepoint=".$usesavepoint." handler=".$handler." okerror=".$okerror, LOG_DEBUG);
175
176 if (!is_numeric($linelengthlimit)) {
177 dol_syslog("Admin.lib::run_sql param linelengthlimit is not a numeric", LOG_ERR);
178 return -1;
179 }
180
181 $ok = 0;
182 $error = 0;
183 $i = 0;
184 $buffer = '';
185 $arraysql = array();
186
187 // Get version of database
188 $versionarray = $db->getVersionArray();
189
190 $fp = fopen($sqlfile, "r");
191 if ($fp) {
192 while (!feof($fp)) {
193 // Warning fgets with second parameter that is null or 0 hang.
194 if ($linelengthlimit > 0) {
195 $buf = fgets($fp, $linelengthlimit);
196 } else {
197 $buf = fgets($fp);
198 }
199
200 // Test if request must be ran only for particular database or version (if yes, we must remove the -- comment)
201 $reg = array();
202 if (preg_match('/^--\sV(MYSQL|PGSQL)([^\s]*)/i', $buf, $reg)) {
203 $qualified = 1;
204
205 // restrict on database type
206 if (!empty($reg[1])) {
207 if (!preg_match('/'.preg_quote($reg[1]).'/i', $db->type)) {
208 $qualified = 0;
209 }
210 }
211
212 // restrict on version
213 if ($qualified) {
214 if (!empty($reg[2])) {
215 if (is_numeric($reg[2])) { // This is a version
216 $versionrequest = explode('.', $reg[2]);
217 //var_dump($versionrequest);
218 //var_dump($versionarray);
219 if (!count($versionrequest) || !count($versionarray) || versioncompare($versionrequest, $versionarray) > 0) {
220 $qualified = 0;
221 }
222 } else { // This is a test on a constant. For example when we have -- VMYSQLUTF8UNICODE, we test constant $conf->global->UTF8UNICODE
223 $dbcollation = strtoupper(preg_replace('/_/', '', $conf->db->dolibarr_main_db_collation));
224 //var_dump($reg[2]);
225 //var_dump($dbcollation);
226 if (empty($conf->db->dolibarr_main_db_collation) || ($reg[2] != $dbcollation)) {
227 $qualified = 0;
228 }
229 //var_dump($qualified);
230 }
231 }
232 }
233
234 if ($qualified) {
235 // Version qualified, delete SQL comments
236 $buf = preg_replace('/^--\sV(MYSQL|PGSQL)([^\s]*)/i', '', $buf);
237 //print "Ligne $i qualifi?e par version: ".$buf.'<br>';
238 }
239 }
240
241 // Add line buf to buffer if not a comment
242 if ($nocommentremoval || !preg_match('/^\s*--/', $buf)) {
243 if (empty($nocommentremoval)) {
244 $buf = preg_replace('/([,;ERLT\‍)])\s*--.*$/i', '\1', $buf); //remove comment from a line that not start with -- before add it to the buffer
245 }
246 if ($buffer) {
247 $buffer .= ' ';
248 }
249 $buffer .= trim($buf);
250 }
251
252 //print $buf.'<br>';exit;
253
254 if (preg_match('/;/', $buffer)) { // If string contains ';', it's end of a request string, we save it in arraysql.
255 // Found new request
256 if ($buffer) {
257 $arraysql[$i] = $buffer;
258 }
259 $i++;
260 $buffer = '';
261 }
262 }
263
264 if ($buffer) {
265 $arraysql[$i] = $buffer;
266 }
267 fclose($fp);
268 } else {
269 dol_syslog("Admin.lib::run_sql failed to open file ".$sqlfile, LOG_ERR);
270 }
271
272 // Loop on each request to see if there is a __+MAX_table__ key
273 $listofmaxrowid = array(); // This is a cache table
274 foreach ($arraysql as $i => $sql) {
275 $newsql = $sql;
276
277 // Replace __+MAX_table__ with max of table
278 while (preg_match('/__\+MAX_([A-Za-z0-9_]+)__/i', $newsql, $reg)) {
279 $table = $reg[1];
280 if (!isset($listofmaxrowid[$table])) {
281 //var_dump($db);
282 $sqlgetrowid = 'SELECT MAX(rowid) as max from '.preg_replace('/^llx_/', MAIN_DB_PREFIX, $table);
283 $resql = $db->query($sqlgetrowid);
284 if ($resql) {
285 $obj = $db->fetch_object($resql);
286 $listofmaxrowid[$table] = $obj->max;
287 if (empty($listofmaxrowid[$table])) {
288 $listofmaxrowid[$table] = 0;
289 }
290 } else {
291 if (!$silent) {
292 print '<tr><td class="tdtop"'.($colspan ? ' colspan="'.$colspan.'"' : '').'>';
293 print '<div class="error">'.$langs->trans("Failed to get max rowid for ".$table)."</div>";
294 print '</td></tr>';
295 }
296 $error++;
297 break;
298 }
299 }
300 // Replace __+MAX_llx_table__ with +999
301 $from = '__+MAX_'.$table.'__';
302 $to = '+'.$listofmaxrowid[$table];
303 $newsql = str_replace($from, $to, $newsql);
304 dol_syslog('Admin.lib::run_sql New Request '.($i + 1).' (replacing '.$from.' to '.$to.')', LOG_DEBUG);
305
306 $arraysql[$i] = $newsql;
307 }
308
309 if ($offsetforchartofaccount > 0) {
310 // Replace lines
311 // '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,...'
312 // with
313 // '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,...'
314 // Note: string with 'PCG99-ABREGE','CAPIT', 1234 instead of 'PCG99-ABREGE','CAPIT', '1234' is also supported
315 $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);
316 $newsql = preg_replace('/([,\s])0 \+ '.((int) $offsetforchartofaccount).'/ims', '\1 0', $newsql);
317 //var_dump($newsql);
318 $arraysql[$i] = $newsql;
319
320 // FIXME Because we force the rowid during insert, we must also update the sequence with postgresql by running
321 // SELECT dol_util_rebuild_sequences();
322 }
323 }
324
325 // Loop on each request to execute request
326 $cursorinsert = 0;
327 $listofinsertedrowid = array();
328 $keyforsql = md5($sqlfile);
329 foreach ($arraysql as $i => $sql) {
330 if ($sql) {
331 // Test if the SQL is allowed SQL
332 if ($onlysqltoimportwebsite) {
333 $newsql = str_replace(array("\'"), '__BACKSLASHQUOTE__', $sql); // Replace the \' char
334
335 // Remove all strings contents including the ' so we can analyse SQL instruction only later
336 $l = strlen($newsql);
337 $is = 0;
338 $quoteopen = 0;
339 $newsqlclean = '';
340 while ($is < $l) {
341 $char = $newsql[$is];
342 if ($char == "'") {
343 if ($quoteopen) {
344 $quoteopen--;
345 } else {
346 $quoteopen++;
347 }
348 } elseif (empty($quoteopen)) {
349 $newsqlclean .= $char;
350 }
351 $is++;
352 }
353 $newsqlclean = str_replace(array("null"), '__000__', $newsqlclean);
354 //print $newsqlclean."<br>\n";
355
356 $qualified = 0;
357
358 // A very small control. This can still by bypassed by adding a second SQL request concatenated
359 if (preg_match('/^--/', $newsqlclean)) {
360 $qualified = 1;
361 } elseif (preg_match('/^UPDATE llx_website SET \w+ = \d+\+\d+ WHERE rowid = \d+;$/', $newsqlclean)) {
362 $qualified = 1;
363 } elseif (preg_match('/^INSERT INTO llx_website_page\‍([a-z0-9_\s,]+\‍) VALUES\‍([0-9_\s,\+]+\‍);$/', $newsqlclean)) {
364 // Insert must match
365 // 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, , , , , );
366 $qualified = 1;
367 }
368
369 // Another check to allow some legitimate original urls
370 if (!$qualified) {
371 if (preg_match('/^UPDATE llx_website SET \w+ = \'[a-zA-Z,\s]*\' WHERE rowid = \d+;$/', $sql)) {
372 $qualified = 1;
373 }
374 }
375
376 // We also check content
377 $extractphp = dolKeepOnlyPhpCode($sql);
378 $extractphpold = '';
379
380 // Security analysis
381 $errorphpcheck = checkPHPCode($extractphpold, $extractphp); // Contains the setEventMessages
382 if ($errorphpcheck) {
383 $error++;
384 //print 'Request '.($i + 1)." contains non allowed instructions.<br>\n";
385 //print "newsqlclean = ".$newsqlclean."<br>\n";
386 dol_syslog('Admin.lib::run_sql Request '.($i + 1)." contains PHP code and checking this code returns errorphpcheck='.$errorphpcheck.'", LOG_WARNING);
387 dol_syslog("sql=".$sql, LOG_DEBUG);
388 break;
389 }
390
391
392 if (!$qualified) {
393 $error++;
394 //print 'Request '.($i + 1)." contains non allowed instructions.<br>\n";
395 //print "newsqlclean = ".$newsqlclean."<br>\n";
396 dol_syslog('Admin.lib::run_sql Request '.($i + 1)." contains non allowed instructions.", LOG_WARNING);
397 dol_syslog('$newsqlclean='.$newsqlclean, LOG_DEBUG);
398 break;
399 }
400 }
401
402 // Replace the prefix tables
403 if (MAIN_DB_PREFIX != 'llx_') {
404 $sql = preg_replace('/llx_/i', MAIN_DB_PREFIX, $sql);
405 }
406
407 if (!empty($handler)) {
408 $sql = preg_replace('/__HANDLER__/i', "'".$db->escape($handler)."'", $sql);
409 }
410
411 if (!empty($database)) {
412 $sql = preg_replace('/__DATABASE__/i', $db->escape($database), $sql);
413 }
414
415 $newsql = preg_replace('/__ENTITY__/i', (!empty($entity) ? $entity : (string) $conf->entity), $sql);
416
417 // Add log of request
418 if (!$silent) {
419 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";
420 }
421 dol_syslog('Admin.lib::run_sql Request '.($i + 1), LOG_DEBUG);
422 $sqlmodified = 0;
423
424 // Replace for encrypt data
425 if (preg_match_all('/__ENCRYPT\‍(\'([^\']+)\'\‍)__/i', $newsql, $reg)) {
426 $num = count($reg[0]);
427
428 for ($j = 0; $j < $num; $j++) {
429 $from = $reg[0][$j];
430 $to = $db->encrypt($reg[1][$j]);
431 $newsql = str_replace($from, $to, $newsql);
432 }
433 $sqlmodified++;
434 }
435
436 // Replace for decrypt data
437 if (preg_match_all('/__DECRYPT\‍(\'([A-Za-z0-9_]+)\'\‍)__/i', $newsql, $reg)) {
438 $num = count($reg[0]);
439
440 for ($j = 0; $j < $num; $j++) {
441 $from = $reg[0][$j];
442 $to = $db->decrypt($reg[1][$j]);
443 $newsql = str_replace($from, $to, $newsql);
444 }
445 $sqlmodified++;
446 }
447
448 // Replace __x__ with the rowid of the result of the insert number x
449 while (preg_match('/__([0-9]+)__/', $newsql, $reg)) {
450 $cursor = $reg[1];
451 if (empty($listofinsertedrowid[$cursor])) {
452 if (!$silent) {
453 print '<tr><td class="tdtop"'.($colspan ? ' colspan="'.$colspan.'"' : '').'>';
454 print '<div class="error">'.$langs->trans("FileIsNotCorrect")."</div>";
455 print '</td></tr>';
456 }
457 $error++;
458 break;
459 }
460
461 $from = '__'.$cursor.'__';
462 $to = $listofinsertedrowid[$cursor];
463 $newsql = str_replace($from, $to, $newsql);
464 $sqlmodified++;
465 }
466
467 if ($sqlmodified) {
468 dol_syslog('Admin.lib::run_sql New Request '.($i + 1), LOG_DEBUG);
469 }
470
471 $result = $db->query($newsql, $usesavepoint);
472 if ($result) {
473 if (!$silent) {
474 print '<!-- Result = OK -->'."\n";
475 }
476
477 if (preg_replace('/insert into ([^\s]+)/i', $newsql, $reg)) {
478 $cursorinsert++;
479
480 // It's an insert
481 $table = preg_replace('/([^a-zA-Z_]+)/i', '', $reg[1]);
482 $insertedrowid = $db->last_insert_id($table);
483 $listofinsertedrowid[$cursorinsert] = $insertedrowid;
484 dol_syslog('Admin.lib::run_sql Insert nb '.$cursorinsert.', done in table '.$table.', rowid is '.$listofinsertedrowid[$cursorinsert], LOG_DEBUG);
485 }
486 // print '<td class="right">OK</td>';
487 } else {
488 $errno = $db->errno();
489 if (!$silent) {
490 print '<!-- Result = '.$errno.' -->'."\n";
491 }
492
493 // Define list of errors we accept (array $okerrors)
494 $okerrors = array( // By default
495 'DB_ERROR_TABLE_ALREADY_EXISTS',
496 'DB_ERROR_COLUMN_ALREADY_EXISTS',
497 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
498 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS', // PgSql use same code for table and key already exist
499 'DB_ERROR_RECORD_ALREADY_EXISTS',
500 'DB_ERROR_NOSUCHTABLE',
501 'DB_ERROR_NOSUCHFIELD',
502 'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
503 'DB_ERROR_NO_INDEX_TO_DROP',
504 'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante
505 'DB_ERROR_CANT_DROP_PRIMARY_KEY',
506 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
507 'DB_ERROR_22P02'
508 );
509 if ($okerror == 'none') {
510 $okerrors = array();
511 }
512
513 // Is it an error we accept
514 if (!in_array($errno, $okerrors)) {
515 if (!$silent) {
516 print '<tr><td class="tdtop"'.($colspan ? ' colspan="'.$colspan.'"' : '').'>';
517 print '<div class="error">'.$langs->trans("Error")." ".$db->errno()." (Req ".($i + 1)."): ".$newsql."<br>".$db->error()."</div>";
518 print '</td></tr>'."\n";
519 }
520 dol_syslog('Admin.lib::run_sql Request '.($i + 1)." Error ".$db->errno()." ".$newsql."<br>".$db->error(), LOG_ERR);
521 $error++;
522 }
523 }
524 }
525 }
526
527 if (!$silent) {
528 print '<tr><td>'.$langs->trans("ProcessMigrateScript").'</td>';
529 print '<td class="right">';
530 if ($error == 0) {
531 print '<span class="ok">'.$langs->trans("OK").'</span>';
532 } else {
533 print '<span class="error">'.$langs->trans("Error").'</span>';
534 }
535
536 //if (!empty($conf->use_javascript_ajax)) { // use_javascript_ajax is not defined
537 print '<script type="text/javascript">
538 jQuery(document).ready(function() {
539 function init_trrunsql'.$keyforsql.'()
540 {
541 console.log("toggle .trforrunsql'.$keyforsql.'");
542 jQuery(".trforrunsql'.$keyforsql.'").toggle();
543 }
544 init_trrunsql'.$keyforsql.'();
545 jQuery(".trforrunsqlshowhide'.$keyforsql.'").click(function() {
546 init_trrunsql'.$keyforsql.'();
547 });
548 });
549 </script>';
550 if (count($arraysql)) {
551 print ' - <a class="trforrunsqlshowhide'.$keyforsql.'" href="#" title="'.($langs->trans("ShowHideTheNRequests", count($arraysql))).'">'.$langs->trans("ShowHideDetails").'</a>';
552 } else {
553 print ' - <span class="opacitymedium">'.$langs->trans("ScriptIsEmpty").'</span>';
554 }
555 //}
556
557 print '</td></tr>'."\n";
558 }
559
560 if ($error == 0) {
561 $ok = 1;
562 } else {
563 $ok = 0;
564 }
565
566 return $ok;
567}
568
569
580function dolibarr_del_const($db, $name, $entity = 1)
581{
582 global $conf;
583
584 if (empty($name)) {
585 dol_print_error(null, 'Error call dolibar_del_const with parameter name empty');
586 return -1;
587 }
588
589 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
590 $sql .= " WHERE (".$db->decrypt('name')." = '".$db->escape($name)."'";
591 if (is_numeric($name)) {
592 $sql .= " OR rowid = ".((int) $name);
593 }
594 $sql .= ")";
595 if ($entity >= 0) {
596 $sql .= " AND entity = ".((int) $entity);
597 }
598
599 dol_syslog("admin.lib::dolibarr_del_const", LOG_DEBUG);
600 $resql = $db->query($sql);
601 if ($resql) {
602 $conf->global->$name = '';
603 return 1;
604 } else {
605 dol_print_error($db);
606 return -1;
607 }
608}
609
620function dolibarr_get_const($db, $name, $entity = 1)
621{
622 $value = '';
623
624 $sql = "SELECT ".$db->decrypt('value')." as value";
625 $sql .= " FROM ".MAIN_DB_PREFIX."const";
626 $sql .= " WHERE name = ".$db->encrypt($name);
627 $sql .= " AND entity = ".((int) $entity);
628
629 dol_syslog("admin.lib::dolibarr_get_const", LOG_DEBUG);
630 $resql = $db->query($sql);
631 if ($resql) {
632 $obj = $db->fetch_object($resql);
633 if ($obj) {
634 include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
635 $value = dolDecrypt($obj->value);
636 }
637 }
638 return $value;
639}
640
641
656function dolibarr_set_const($db, $name, $value, $type = 'chaine', $visible = 0, $note = '', $entity = 1)
657{
658 global $conf;
659
660 // Clean parameters
661 $name = trim($name);
662
663 // Check parameters
664 if (empty($name)) {
665 dol_print_error($db, "Error: Call to function dolibarr_set_const with wrong parameters");
666 exit;
667 }
668
669 //dol_syslog("dolibarr_set_const name=$name, value=$value type=$type, visible=$visible, note=$note entity=$entity");
670
671 $db->begin();
672
673 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
674 $sql .= " WHERE name = ".$db->encrypt($name);
675 if ($entity >= 0) {
676 $sql .= " AND entity = ".((int) $entity);
677 }
678
679 dol_syslog("admin.lib::dolibarr_set_const", LOG_DEBUG);
680 $resql = $db->query($sql);
681
682 if (strcmp($value, '')) { // true if different. Must work for $value='0' or $value=0
683 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))) {
684 // This seems a sensitive constant, we encrypt its value
685 // To list all sensitive constant, you can make a
686 // 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'
687 // or name like '%\_SECURITY_TOKEN' or name like '%\WEB_TOKEN'
688 include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
689 $newvalue = dolEncrypt($value);
690 } else {
691 $newvalue = $value;
692 }
693
694 $sql = "INSERT INTO ".MAIN_DB_PREFIX."const(name, value, type, visible, note, entity)";
695 $sql .= " VALUES (";
696 $sql .= $db->encrypt($name);
697 $sql .= ", ".$db->encrypt($newvalue);
698 $sql .= ", '".$db->escape($type)."', ".((int) $visible).", '".$db->escape($note)."', ".((int) $entity).")";
699
700 //print "sql".$value."-".pg_escape_string($value)."-".$sql;exit;
701 //print "xx".$db->escape($value);
702 dol_syslog("admin.lib::dolibarr_set_const", LOG_DEBUG);
703 $resql = $db->query($sql);
704 }
705
706 if ($resql) {
707 $db->commit();
708 $conf->global->$name = $value;
709 return 1;
710 } else {
711 $error = $db->lasterror();
712 $db->rollback();
713 return -1;
714 }
715}
716
717
718
719
728function modules_prepare_head($nbofactivatedmodules, $nboftotalmodules, $nbmodulesnotautoenabled)
729{
730 global $langs, $form;
731
732 $desc = $langs->trans("ModulesDesc", '{picto}');
733 $desc = str_replace('{picto}', img_picto('', 'switch_off'), $desc);
734
735 $h = 0;
736 $head = array();
737 $mode = getDolGlobalString('MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT', 'commonkanban');
738 $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$mode;
739 if ($nbmodulesnotautoenabled <= getDolGlobalInt('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only minimal initial modules enabled)
740 //$head[$h][1] = $form->textwithpicto($langs->trans("AvailableModules"), $desc);
741 $head[$h][1] = $langs->trans("AvailableModules");
742 $head[$h][1] .= $form->textwithpicto('', $langs->trans("YouMustEnableOneModule").'.<br><br><span class="opacitymedium">'.$desc.'</span>', 1, 'warning');
743 } else {
744 //$head[$h][1] = $langs->trans("AvailableModules").$form->textwithpicto('<span class="badge marginleftonly">'.$nbofactivatedmodules.' / '.$nboftotalmodules.'</span>', $desc, 1, 'help', '', 1, 3);
745 $head[$h][1] = $langs->trans("AvailableModules").'<span class="badge marginleftonly">'.$nbofactivatedmodules.' / '.$nboftotalmodules.'</span>';
746 }
747 $head[$h][2] = 'modules';
748 $h++;
749
750 $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=marketplace";
751 $head[$h][1] = $langs->trans("ModulesMarketPlaces");
752 $head[$h][2] = 'marketplace';
753 $h++;
754
755 $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=deploy";
756 $head[$h][1] = $langs->trans("AddExtensionThemeModuleOrOther");
757 $head[$h][2] = 'deploy';
758 $h++;
759
760 $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=develop";
761 $head[$h][1] = $langs->trans("ModulesDevelopYourModule");
762 $head[$h][2] = 'develop';
763 $h++;
764
765 return $head;
766}
767
774{
775 global $langs, $conf, $user;
776 $h = 0;
777 $head = array();
778
779 $head[$h][0] = DOL_URL_ROOT."/admin/ihm.php?mode=other";
780 $head[$h][1] = $langs->trans("LanguageAndPresentation");
781 $head[$h][2] = 'other';
782 $h++;
783
784 $head[$h][0] = DOL_URL_ROOT."/admin/ihm.php?mode=template";
785 $head[$h][1] = $langs->trans("SkinAndColors");
786 $head[$h][2] = 'template';
787 $h++;
788
789 $head[$h][0] = DOL_URL_ROOT."/admin/ihm.php?mode=dashboard";
790 $head[$h][1] = $langs->trans("Dashboard");
791 $head[$h][2] = 'dashboard';
792 $h++;
793
794 $head[$h][0] = DOL_URL_ROOT."/admin/ihm.php?mode=login";
795 $head[$h][1] = $langs->trans("LoginPage");
796 $head[$h][2] = 'login';
797 $h++;
798
799 $head[$h][0] = DOL_URL_ROOT."/admin/ihm.php?mode=css";
800 $head[$h][1] = $langs->trans("CSSPage");
801 $head[$h][2] = 'css';
802 $h++;
803
804 complete_head_from_modules($conf, $langs, null, $head, $h, 'ihm_admin');
805
806 complete_head_from_modules($conf, $langs, null, $head, $h, 'ihm_admin', 'remove');
807
808
809 return $head;
810}
811
812
819{
820 global $db, $langs, $conf, $user;
821 $h = 0;
822 $head = array();
823
824 $head[$h][0] = DOL_URL_ROOT."/admin/security_other.php";
825 $head[$h][1] = $langs->trans("Miscellaneous");
826 $head[$h][2] = 'misc';
827 $h++;
828
829 $head[$h][0] = DOL_URL_ROOT."/admin/security.php";
830 $head[$h][1] = $langs->trans("Passwords");
831 $head[$h][2] = 'passwords';
832 $h++;
833
834 $head[$h][0] = DOL_URL_ROOT."/admin/security_file.php";
835 $head[$h][1] = $langs->trans("Files").' ('.$langs->trans("Upload").')';
836 $head[$h][2] = 'file';
837 $h++;
838
839 /*
840 $head[$h][0] = DOL_URL_ROOT."/admin/security_file_download.php";
841 $head[$h][1] = $langs->trans("Files").' ('.$langs->trans("Download").')';
842 $head[$h][2] = 'filedownload';
843 $h++;
844 */
845
846 $head[$h][0] = DOL_URL_ROOT."/admin/proxy.php";
847 $head[$h][1] = $langs->trans("ExternalAccess");
848 $head[$h][2] = 'proxy';
849 $h++;
850
851 $head[$h][0] = DOL_URL_ROOT."/admin/events.php";
852 $head[$h][1] = $langs->trans("Audit");
853 $head[$h][2] = 'audit';
854 $h++;
855
856
857 // Show permissions lines
858 $nbPerms = 0;
859 $sql = "SELECT COUNT(r.id) as nb";
860 $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
861 $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
862 $sql .= " AND entity = ".((int) $conf->entity);
863 $sql .= " AND bydefault = 1";
864 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
865 $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
866 }
867 $resql = $db->query($sql);
868 if ($resql) {
869 $obj = $db->fetch_object($resql);
870 if ($obj) {
871 $nbPerms = $obj->nb;
872 }
873 } else {
874 dol_print_error($db);
875 }
876
877 if (getDolGlobalString('MAIN_SECURITY_USE_DEFAULT_PERMISSIONS')) {
878 $head[$h][0] = DOL_URL_ROOT."/admin/perms.php";
879 $head[$h][1] = $langs->trans("DefaultRights");
880 if ($nbPerms > 0) {
881 $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.$nbPerms.'</span>' : '');
882 }
883 $head[$h][2] = 'default';
884 $h++;
885 }
886
887 return $head;
888}
889
897{
898 global $langs, $conf;
899 $h = 0;
900 $head = array();
901
902 // FIX for compatibility habitual tabs
903 $object->id = $object->numero;
904
905 $head[$h][0] = DOL_URL_ROOT."/admin/modulehelp.php?id=".$object->id.'&mode=desc';
906 $head[$h][1] = $langs->trans("Description");
907 $head[$h][2] = 'desc';
908 $h++;
909
910 $head[$h][0] = DOL_URL_ROOT."/admin/modulehelp.php?id=".$object->id.'&mode=feature';
911 $head[$h][1] = $langs->trans("TechnicalServicesProvided");
912 $head[$h][2] = 'feature';
913 $h++;
914
915 if ($object->isCoreOrExternalModule() == 'external') {
916 $head[$h][0] = DOL_URL_ROOT."/admin/modulehelp.php?id=".$object->id.'&mode=changelog';
917 $head[$h][1] = $langs->trans("ChangeLog");
918 $head[$h][2] = 'changelog';
919 $h++;
920 }
921
922 complete_head_from_modules($conf, $langs, $object, $head, $h, 'modulehelp_admin');
923
924 complete_head_from_modules($conf, $langs, $object, $head, $h, 'modulehelp_admin', 'remove');
925
926
927 return $head;
928}
935{
936 global $langs, $conf;
937 $h = 0;
938 $head = array();
939
940 $head[$h][0] = DOL_URL_ROOT."/admin/translation.php?mode=searchkey";
941 $head[$h][1] = $langs->trans("TranslationKeySearch");
942 $head[$h][2] = 'searchkey';
943 $h++;
944
945 $head[$h][0] = DOL_URL_ROOT."/admin/translation.php?mode=overwrite";
946 $head[$h][1] = '<span class="valignmiddle">'.$langs->trans("TranslationOverwriteKey").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
947 $head[$h][2] = 'overwrite';
948 $h++;
949
950 complete_head_from_modules($conf, $langs, null, $head, $h, 'translation_admin');
951
952 complete_head_from_modules($conf, $langs, null, $head, $h, 'translation_admin', 'remove');
953
954
955 return $head;
956}
957
958
965{
966 global $langs, $conf, $user;
967 $h = 0;
968 $head = array();
969
970 $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=createform";
971 $head[$h][1] = $langs->trans("DefaultCreateForm");
972 $head[$h][2] = 'createform';
973 $h++;
974
975 $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=filters";
976 $head[$h][1] = $langs->trans("DefaultSearchFilters");
977 $head[$h][2] = 'filters';
978 $h++;
979
980 $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=sortorder";
981 $head[$h][1] = $langs->trans("DefaultSortOrder");
982 $head[$h][2] = 'sortorder';
983 $h++;
984
985 if (!empty($conf->use_javascript_ajax)) {
986 $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=focus";
987 $head[$h][1] = $langs->trans("DefaultFocus");
988 $head[$h][2] = 'focus';
989 $h++;
990
991 $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=mandatory";
992 $head[$h][1] = $langs->trans("DefaultMandatory");
993 $head[$h][2] = 'mandatory';
994 $h++;
995 }
996
997 /*$head[$h][0] = DOL_URL_ROOT."/admin/translation.php?mode=searchkey";
998 $head[$h][1] = $langs->trans("TranslationKeySearch");
999 $head[$h][2] = 'searchkey';
1000 $h++;*/
1001
1002 complete_head_from_modules($conf, $langs, null, $head, $h, 'defaultvalues_admin');
1003
1004 complete_head_from_modules($conf, $langs, null, $head, $h, 'defaultvalues_admin', 'remove');
1005
1006
1007 return $head;
1008}
1009
1010
1017{
1018 global $conf;
1019
1020 $arrayofSessions = array();
1021 // session.save_path can be returned empty so we set a default location and work from there
1022 $sessPath = '/tmp';
1023 $iniPath = ini_get("session.save_path");
1024 if ($iniPath) {
1025 $sessPath = $iniPath;
1026 }
1027 $sessPath .= '/'; // We need the trailing slash
1028 dol_syslog('admin.lib:listOfSessions sessPath='.$sessPath);
1029
1030 $dh = @opendir(dol_osencode($sessPath));
1031 if ($dh) {
1032 while (($file = @readdir($dh)) !== false) {
1033 if (preg_match('/^sess_/i', $file) && $file != "." && $file != "..") {
1034 $fullpath = $sessPath.$file;
1035 if (!@is_dir($fullpath) && is_readable($fullpath)) {
1036 $sessValues = file_get_contents($fullpath); // get raw session data
1037 // Example of possible value
1038 //$sessValues = 'newtoken|s:32:"1239f7a0c4b899200fe9ca5ea394f307";dol_loginmesg|s:0:"";newtoken|s:32:"1236457104f7ae0f328c2928973f3cb5";dol_loginmesg|s:0:"";token|s:32:"123615ad8d650c5cc4199b9a1a76783f";
1039 // 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";
1040 // 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";';
1041
1042 if (preg_match('/dol_login/i', $sessValues) && // limit to dolibarr session
1043 (preg_match('/dol_entity\|i:'.$conf->entity.';/i', $sessValues) || preg_match('/dol_entity\|s:([0-9]+):"'.$conf->entity.'"/i', $sessValues)) && // limit to current entity
1044 preg_match('/dol_company\|s:([0-9]+):"('.getDolGlobalString('MAIN_INFO_SOCIETE_NOM').')"/i', $sessValues)) { // limit to company name
1045 $tmp = explode('_', $file);
1046 $idsess = $tmp[1];
1047 $regs = array();
1048 $loginfound = preg_match('/dol_login\|s:[0-9]+:"([A-Za-z0-9]+)"/i', $sessValues, $regs);
1049 if ($loginfound) {
1050 $arrayofSessions[$idsess]["login"] = $regs[1];
1051 }
1052 $arrayofSessions[$idsess]["age"] = time() - filectime($fullpath);
1053 $arrayofSessions[$idsess]["creation"] = filectime($fullpath);
1054 $arrayofSessions[$idsess]["modification"] = filemtime($fullpath);
1055 $arrayofSessions[$idsess]["raw"] = $sessValues;
1056 }
1057 }
1058 }
1059 }
1060 @closedir($dh);
1061 }
1062
1063 return $arrayofSessions;
1064}
1065
1072function purgeSessions($mysessionid)
1073{
1074 global $conf;
1075
1076 $sessPath = ini_get("session.save_path")."/";
1077 dol_syslog('admin.lib:purgeSessions mysessionid='.$mysessionid.' sessPath='.$sessPath);
1078
1079 $error = 0;
1080
1081 $dh = @opendir(dol_osencode($sessPath));
1082 if ($dh) {
1083 while (($file = @readdir($dh)) !== false) {
1084 if ($file != "." && $file != "..") {
1085 $fullpath = $sessPath.$file;
1086 if (!@is_dir($fullpath)) {
1087 $sessValues = file_get_contents($fullpath); // get raw session data
1088
1089 if (preg_match('/dol_login/i', $sessValues) && // limit to dolibarr session
1090 preg_match('/dol_entity\|s:([0-9]+):"('.$conf->entity.')"/i', $sessValues) && // limit to current entity
1091 preg_match('/dol_company\|s:([0-9]+):"(' . getDolGlobalString('MAIN_INFO_SOCIETE_NOM').')"/i', $sessValues)) { // limit to company name
1092 $tmp = explode('_', $file);
1093 $idsess = $tmp[1];
1094 // We remove session if it's not ourself
1095 if ($idsess != $mysessionid) {
1096 $res = @unlink($fullpath);
1097 if (!$res) {
1098 $error++;
1099 }
1100 }
1101 }
1102 }
1103 }
1104 }
1105 @closedir($dh);
1106 }
1107
1108 if (!$error) {
1109 return 1;
1110 } else {
1111 return -$error;
1112 }
1113}
1114
1115
1116
1125function activateModule($value, $withdeps = 1, $noconfverification = 0)
1126{
1127 global $db, $langs, $conf, $mysoc;
1128
1129 $ret = array();
1130
1131 // Check parameters
1132 if (empty($value)) {
1133 $ret['errors'] = array('ErrorBadParameter');
1134 return $ret;
1135 }
1136
1137 $ret = array('nbmodules' => 0, 'errors' => array(), 'nbperms' => 0);
1138 $modName = $value;
1139 $modFile = $modName.".class.php";
1140
1141 // Loop on each directory to fill $modulesdir
1142 $modulesdir = dolGetModulesDirs();
1143
1144 // Loop on each modulesdir directories
1145 $found = false;
1146 foreach ($modulesdir as $dir) {
1147 if (file_exists($dir.$modFile)) {
1148 $found = @include_once $dir.$modFile;
1149 if ($found) {
1150 break;
1151 }
1152 }
1153 }
1154
1155 $objMod = new $modName($db);
1156
1157 // Test if PHP version ok
1158 $verphp = versionphparray();
1159 $vermin = isset($objMod->phpmin) ? $objMod->phpmin : 0;
1160 if (is_array($vermin) && versioncompare($verphp, $vermin) < 0) {
1161 $ret['errors'][] = $langs->trans("ErrorModuleRequirePHPVersion", versiontostring($vermin));
1162 return $ret;
1163 }
1164
1165 // Test if Dolibarr version ok
1166 $verdol = versiondolibarrarray();
1167 $vermin = isset($objMod->need_dolibarr_version) ? $objMod->need_dolibarr_version : 0;
1168 //print 'version: '.versioncompare($verdol,$vermin).' - '.join(',',$verdol).' - '.join(',',$vermin);exit;
1169 if (is_array($vermin) && versioncompare($verdol, $vermin) < 0) {
1170 $ret['errors'][] = $langs->trans("ErrorModuleRequireDolibarrVersion", versiontostring($vermin));
1171 return $ret;
1172 }
1173
1174 // Test if javascript requirement ok
1175 if (!empty($objMod->need_javascript_ajax) && empty($conf->use_javascript_ajax)) {
1176 $ret['errors'][] = $langs->trans("ErrorModuleRequireJavascript");
1177 return $ret;
1178 }
1179
1180 $const_name = $objMod->const_name;
1181 if ($noconfverification == 0) {
1182 if (getDolGlobalString($const_name)) {
1183 return $ret;
1184 }
1185 }
1186
1187 $result = $objMod->init(); // Enable module
1188
1189 if ($result <= 0) {
1190 $ret['errors'][] = $objMod->error;
1191 } else {
1192 if ($withdeps) {
1193 if (isset($objMod->depends) && is_array($objMod->depends) && !empty($objMod->depends)) {
1194 // Activation of modules this module depends on
1195 // this->depends may be array('modModule1', 'mmodModule2') or array('always'=>array('modModule1'), 'FR'=>array('modModule2"))
1196 foreach ($objMod->depends as $key => $modulestringorarray) {
1197 //var_dump((! is_numeric($key)) && ! preg_match('/^always/', $key) && $mysoc->country_code && ! preg_match('/^'.$mysoc->country_code.'/', $key));exit;
1198 if ((!is_numeric($key)) && !preg_match('/^always/', $key) && $mysoc->country_code && !preg_match('/^'.$mysoc->country_code.'/', $key)) {
1199 dol_syslog("We are not concerned by dependency with key=".$key." because our country is ".$mysoc->country_code);
1200 continue;
1201 }
1202
1203 if (!is_array($modulestringorarray)) {
1204 $modulestringorarray = array($modulestringorarray);
1205 }
1206
1207 foreach ($modulestringorarray as $modulestring) {
1208 $activate = false;
1209 $activateerr = '';
1210 foreach ($modulesdir as $dir) {
1211 if (file_exists($dir.$modulestring.".class.php")) {
1212 $resarray = activateModule($modulestring);
1213 if (empty($resarray['errors'])) {
1214 $activate = true;
1215 } else {
1216 $activateerr = implode(', ', $resarray['errors']);
1217 foreach ($resarray['errors'] as $errorMessage) {
1218 dol_syslog($errorMessage, LOG_ERR);
1219 }
1220 }
1221 break;
1222 }
1223 }
1224
1225 if ($activate) {
1226 $ret['nbmodules'] += $resarray['nbmodules'];
1227 $ret['nbperms'] += $resarray['nbperms'];
1228 } else {
1229 if ($activateerr) {
1230 $ret['errors'][] = $activateerr;
1231 }
1232 $ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $modulestring);
1233 }
1234 }
1235 }
1236 }
1237
1238 if (isset($objMod->conflictwith) && is_array($objMod->conflictwith) && !empty($objMod->conflictwith)) {
1239 // Deactivation des modules qui entrent en conflict
1240 $num = count($objMod->conflictwith);
1241 for ($i = 0; $i < $num; $i++) {
1242 foreach ($modulesdir as $dir) {
1243 if (file_exists($dir.$objMod->conflictwith[$i].".class.php")) {
1244 unActivateModule($objMod->conflictwith[$i], 0);
1245 }
1246 }
1247 }
1248 }
1249 }
1250 }
1251
1252 if (!count($ret['errors'])) {
1253 $ret['nbmodules']++;
1254 $ret['nbperms'] += (is_array($objMod->rights) ? count($objMod->rights) : 0);
1255 }
1256
1257 return $ret;
1258}
1259
1260
1268function unActivateModule($value, $requiredby = 1)
1269{
1270 global $db, $modules, $conf;
1271
1272 // Check parameters
1273 if (empty($value)) {
1274 return 'ErrorBadParameter';
1275 }
1276
1277 $ret = '';
1278 $modName = $value;
1279 $modFile = $modName.".class.php";
1280
1281 // Loop on each directory to fill $modulesdir
1282 $modulesdir = dolGetModulesDirs();
1283
1284 // Loop on each modulesdir directories
1285 $found = false;
1286 foreach ($modulesdir as $dir) {
1287 if (file_exists($dir.$modFile)) {
1288 $found = @include_once $dir.$modFile;
1289 if ($found) {
1290 break;
1291 }
1292 }
1293 }
1294
1295 if ($found) {
1296 $objMod = new $modName($db);
1297 $result = $objMod->remove();
1298 if ($result <= 0) {
1299 $ret = $objMod->error;
1300 }
1301 } else { // We come here when we try to unactivate a module when module does not exists anymore in sources
1302 //print $dir.$modFile;exit;
1303 // TODO Replace this after DolibarrModules is moved as abstract class with a try catch to show module we try to disable has not been found or could not be loaded
1304 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
1305 $genericMod = new DolibarrModules($db);
1306 $genericMod->name = preg_replace('/^mod/i', '', $modName);
1307 $genericMod->rights_class = strtolower(preg_replace('/^mod/i', '', $modName));
1308 $genericMod->const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', $modName));
1309 dol_syslog("modules::unActivateModule Failed to find module file, we use generic function with name ".$modName);
1310 $genericMod->remove('');
1311 }
1312
1313 // Disable modules that depends on module we disable
1314 if (!$ret && $requiredby && isset($objMod) && is_object($objMod) && is_array($objMod->requiredby)) {
1315 $countrb = count($objMod->requiredby);
1316 for ($i = 0; $i < $countrb; $i++) {
1317 //var_dump($objMod->requiredby[$i]);
1318 unActivateModule($objMod->requiredby[$i]);
1319 }
1320 }
1321
1322 return $ret;
1323}
1324
1325
1344function complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabcomplete)
1345{
1346 global $db, $langs;
1347
1348 dol_syslog("complete_dictionary_with_modules Search external modules to complete the list of dictionary tables", LOG_DEBUG, 1);
1349
1350 // Search modules
1351 $modulesdir = dolGetModulesDirs();
1352 $i = 0; // is a sequencer of modules found
1353 $j = 0; // j is module number. Automatically affected if module number not defined.
1354
1355 foreach ($modulesdir as $dir) {
1356 // Load modules attributes in arrays (name, numero, orders) from dir directory
1357 //print $dir."\n<br>";
1358 dol_syslog("Scan directory ".$dir." for modules");
1359 $handle = @opendir(dol_osencode($dir));
1360 if (is_resource($handle)) {
1361 while (($file = readdir($handle)) !== false) {
1362 //print "$i ".$file."\n<br>";
1363 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
1364 $modName = substr($file, 0, dol_strlen($file) - 10);
1365
1366 if ($modName) {
1367 include_once $dir.$file;
1368 $objMod = new $modName($db);
1369
1370 if ($objMod->numero > 0) {
1371 $j = $objMod->numero;
1372 } else {
1373 $j = 1000 + $i;
1374 }
1375
1376 $modulequalified = 1;
1377
1378 // We discard modules according to features level (PS: if module is activated we always show it)
1379 $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
1380 if ($objMod->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2 && !getDolGlobalString($const_name)) {
1381 $modulequalified = 0;
1382 }
1383 if ($objMod->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1 && !getDolGlobalString($const_name)) {
1384 $modulequalified = 0;
1385 }
1386 // If module is not activated disqualified
1387 if (!getDolGlobalString($const_name)) {
1388 $modulequalified = 0;
1389 }
1390
1391 if ($modulequalified) {
1392 // Load languages files of module
1393 if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
1394 foreach ($objMod->langfiles as $langfile) {
1395 $langs->load($langfile);
1396 }
1397 }
1398
1399 // phpcs:disable
1400 // Complete the arrays &$tabname,&$tablib,&$tabsql,&$tabsqlsort,&$tabfield,&$tabfieldvalue,&$tabfieldinsert,&$tabrowid,&$tabcond
1401 if (empty($objMod->dictionaries) && !empty($objMod->{"dictionnaries"})) {
1402 $objMod->dictionaries = $objMod->{"dictionnaries"}; // For backward compatibility
1403 }
1404 // phpcs:enable
1405
1406 if (!empty($objMod->dictionaries)) {
1407 //var_dump($objMod->dictionaries['tabname']);
1408 $nbtabname = $nbtablib = $nbtabsql = $nbtabsqlsort = $nbtabfield = $nbtabfieldvalue = $nbtabfieldinsert = $nbtabrowid = $nbtabcond = $nbtabfieldcheck = $nbtabhelp = 0;
1409 $tabnamerelwithkey = array();
1410 foreach ($objMod->dictionaries['tabname'] as $key => $val) {
1411 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $val);
1412 $nbtabname++;
1413 $taborder[] = max($taborder) + 1;
1414 $tabname[] = $val;
1415 $tabnamerelwithkey[$key] = $val;
1416 $tabcomplete[$tmptablename]['picto'] = $objMod->picto;
1417 } // Position
1418 foreach ($objMod->dictionaries['tablib'] as $key => $val) {
1419 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1420 $nbtablib++;
1421 $tablib[] = $val;
1422 $tabcomplete[$tmptablename]['lib'] = $val;
1423 }
1424 foreach ($objMod->dictionaries['tabsql'] as $key => $val) {
1425 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1426 $nbtabsql++;
1427 $tabsql[] = $val;
1428 $tabcomplete[$tmptablename]['sql'] = $val;
1429 }
1430 foreach ($objMod->dictionaries['tabsqlsort'] as $key => $val) {
1431 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1432 $nbtabsqlsort++;
1433 $tabsqlsort[] = $val;
1434 $tabcomplete[$tmptablename]['sqlsort'] = $val;
1435 }
1436 foreach ($objMod->dictionaries['tabfield'] as $key => $val) {
1437 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1438 $nbtabfield++;
1439 $tabfield[] = $val;
1440 $tabcomplete[$tmptablename]['field'] = $val;
1441 }
1442 foreach ($objMod->dictionaries['tabfieldvalue'] as $key => $val) {
1443 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1444 $nbtabfieldvalue++;
1445 $tabfieldvalue[] = $val;
1446 $tabcomplete[$tmptablename]['value'] = $val;
1447 }
1448 foreach ($objMod->dictionaries['tabfieldinsert'] as $key => $val) {
1449 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1450 $nbtabfieldinsert++;
1451 $tabfieldinsert[] = $val;
1452 $tabcomplete[$tmptablename]['fieldinsert'] = $val;
1453 }
1454 foreach ($objMod->dictionaries['tabrowid'] as $key => $val) {
1455 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1456 $nbtabrowid++;
1457 $tabrowid[] = $val;
1458 $tabcomplete[$tmptablename]['rowid'] = $val;
1459 }
1460 foreach ($objMod->dictionaries['tabcond'] as $key => $val) {
1461 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1462 $nbtabcond++;
1463 $tabcond[] = $val;
1464 $tabcomplete[$tmptablename]['cond'] = $val;
1465 }
1466 if (!empty($objMod->dictionaries['tabhelp'])) {
1467 foreach ($objMod->dictionaries['tabhelp'] as $key => $val) {
1468 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1469 $nbtabhelp++;
1470 $tabhelp[] = $val;
1471 $tabcomplete[$tmptablename]['help'] = $val;
1472 }
1473 }
1474 if (!empty($objMod->dictionaries['tabfieldcheck'])) {
1475 foreach ($objMod->dictionaries['tabfieldcheck'] as $key => $val) {
1476 $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1477 $nbtabfieldcheck++;
1478 $tabcomplete[$tmptablename]['fieldcheck'] = $val;
1479 }
1480 }
1481
1482 if ($nbtabname != $nbtablib || $nbtablib != $nbtabsql || $nbtabsql != $nbtabsqlsort) {
1483 print 'Error in descriptor of module '.$const_name.'. Array ->dictionaries has not same number of record for key "tabname", "tablib", "tabsql" and "tabsqlsort"';
1484 //print "$const_name: $nbtabname=$nbtablib=$nbtabsql=$nbtabsqlsort=$nbtabfield=$nbtabfieldvalue=$nbtabfieldinsert=$nbtabrowid=$nbtabcond=$nbtabfieldcheck=$nbtabhelp\n";
1485 } else {
1486 $taborder[] = 0; // Add an empty line
1487 }
1488 }
1489
1490 $j++;
1491 $i++;
1492 } else {
1493 dol_syslog("Module ".get_class($objMod)." not qualified");
1494 }
1495 }
1496 }
1497 }
1498 closedir($handle);
1499 } else {
1500 dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
1501 }
1502 }
1503
1504 dol_syslog("", LOG_DEBUG, -1);
1505
1506 return 1;
1507}
1508
1516{
1517 global $db, $conf, $langs;
1518
1519 $modulesdir = dolGetModulesDirs();
1520
1521 foreach ($modulesdir as $dir) {
1522 // Load modules attributes in arrays (name, numero, orders) from dir directory
1523 dol_syslog("Scan directory ".$dir." for modules");
1524 $handle = @opendir(dol_osencode($dir));
1525 if (is_resource($handle)) {
1526 while (($file = readdir($handle)) !== false) {
1527 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
1528 $modName = substr($file, 0, dol_strlen($file) - 10);
1529
1530 if ($modName) {
1531 include_once $dir.$file;
1532 $objMod = new $modName($db);
1533
1534 $modulequalified = 1;
1535
1536 // We discard modules according to features level (PS: if module is activated we always show it)
1537 $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
1538
1539 if ($objMod->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
1540 $modulequalified = 0;
1541 }
1542 if ($objMod->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
1543 $modulequalified = 0;
1544 }
1545 if (getDolGlobalString($const_name)) {
1546 $modulequalified = 0; // already activated
1547 }
1548
1549 if ($modulequalified) {
1550 // Load languages files of module
1551 if (isset($objMod->automatic_activation) && is_array($objMod->automatic_activation) && isset($objMod->automatic_activation[$country_code])) {
1552 activateModule($modName);
1553
1554 setEventMessages($objMod->automatic_activation[$country_code], null, 'warnings');
1555 }
1556 } else {
1557 dol_syslog("Module ".get_class($objMod)." not qualified");
1558 }
1559 }
1560 }
1561 }
1562 closedir($handle);
1563 } else {
1564 dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
1565 }
1566 }
1567
1568 return 1;
1569}
1570
1578{
1579 global $db, $modules, $conf, $langs;
1580
1581 // Search modules
1582 $filename = array();
1583 $modules = array();
1584 $orders = array();
1585 $categ = array();
1586 $dirmod = array();
1587
1588 $i = 0; // is a sequencer of modules found
1589 $j = 0; // j is module number. Automatically affected if module number not defined.
1590
1591 dol_syslog("complete_elementList_with_modules Search external modules to complete the list of contact element", LOG_DEBUG, 1);
1592
1593 $modulesdir = dolGetModulesDirs();
1594
1595 foreach ($modulesdir as $dir) {
1596 // Load modules attributes in arrays (name, numero, orders) from dir directory
1597 //print $dir."\n<br>";
1598 dol_syslog("Scan directory ".$dir." for modules");
1599 $handle = @opendir(dol_osencode($dir));
1600 if (is_resource($handle)) {
1601 while (($file = readdir($handle)) !== false) {
1602 //print "$i ".$file."\n<br>";
1603 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
1604 $modName = substr($file, 0, dol_strlen($file) - 10);
1605
1606 if ($modName) {
1607 include_once $dir.$file;
1608 $objMod = new $modName($db);
1609
1610 if ($objMod->numero > 0) {
1611 $j = $objMod->numero;
1612 } else {
1613 $j = 1000 + $i;
1614 }
1615
1616 $modulequalified = 1;
1617
1618 // We discard modules according to features level (PS: if module is activated we always show it)
1619 $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
1620 if ($objMod->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2 && getDolGlobalString($const_name)) {
1621 $modulequalified = 0;
1622 }
1623 if ($objMod->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1 && getDolGlobalString($const_name)) {
1624 $modulequalified = 0;
1625 }
1626 // If module is not activated disqualified
1627 if (!getDolGlobalString($const_name)) {
1628 $modulequalified = 0;
1629 }
1630
1631 if ($modulequalified) {
1632 // Load languages files of module
1633 if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
1634 foreach ($objMod->langfiles as $langfile) {
1635 $langs->load($langfile);
1636 }
1637 }
1638
1639 $modules[$i] = $objMod;
1640 $filename[$i] = $modName;
1641 $orders[$i] = $objMod->family."_".$j; // Sort on family then module number
1642 $dirmod[$i] = $dir;
1643 //print "x".$modName." ".$orders[$i]."\n<br>";
1644
1645 if (!empty($objMod->module_parts['contactelement'])) {
1646 if (is_array($objMod->module_parts['contactelement'])) {
1647 foreach ($objMod->module_parts['contactelement'] as $elem => $title) {
1648 $elementList[$elem] = $langs->trans($title);
1649 }
1650 } else {
1651 $elementList[$objMod->name] = $langs->trans($objMod->name);
1652 }
1653 }
1654
1655 $j++;
1656 $i++;
1657 } else {
1658 dol_syslog("Module ".get_class($objMod)." not qualified");
1659 }
1660 }
1661 }
1662 }
1663 closedir($handle);
1664 } else {
1665 dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
1666 }
1667 }
1668
1669 dol_syslog("", LOG_DEBUG, -1);
1670
1671 return 1;
1672}
1673
1684function form_constantes($tableau, $strictw3c = 2, $helptext = '', $text = 'Value')
1685{
1686 global $db, $langs, $conf, $user;
1687 global $_Avery_Labels;
1688
1689 $form = new Form($db);
1690
1691 if (empty($strictw3c)) {
1692 dol_syslog("Warning: Function 'form_constantes' was called with parameter strictw3c = 0, this is deprecated. Value must be 2 now.", LOG_DEBUG);
1693 }
1694 if (!empty($strictw3c) && $strictw3c == 1) {
1695 print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1696 print '<input type="hidden" name="token" value="'.newToken().'">';
1697 print '<input type="hidden" name="action" value="updateall">';
1698 }
1699
1700 print '<div class="div-table-responsive-no-min">';
1701 print '<table class="noborder centpercent">';
1702 print '<tr class="liste_titre">';
1703 print '<td class="">'.$langs->trans("Description").'</td>';
1704 print '<td>';
1705 $text = $langs->trans($text);
1706 print $form->textwithpicto($text, $helptext, 1, 'help', '', 0, 2, 'idhelptext');
1707 print '</td>';
1708 if (empty($strictw3c)) {
1709 print '<td class="center" width="80">'.$langs->trans("Action").'</td>';
1710 }
1711 print "</tr>\n";
1712
1713 $label = '';
1714 foreach ($tableau as $key => $const) { // Loop on each param
1715 $label = '';
1716 // $const is a const key like 'MYMODULE_ABC'
1717 if (is_numeric($key)) { // Very old behaviour
1718 $type = 'string';
1719 } else {
1720 if (is_array($const)) {
1721 $type = $const['type'];
1722 $label = $const['label'];
1723 $const = $key;
1724 } else {
1725 $type = $const;
1726 $const = $key;
1727 }
1728 }
1729
1730 $sql = "SELECT ";
1731 $sql .= "rowid";
1732 $sql .= ", ".$db->decrypt('name')." as name";
1733 $sql .= ", ".$db->decrypt('value')." as value";
1734 $sql .= ", type";
1735 $sql .= ", note";
1736 $sql .= " FROM ".MAIN_DB_PREFIX."const";
1737 $sql .= " WHERE ".$db->decrypt('name')." = '".$db->escape($const)."'";
1738 $sql .= " AND entity IN (0, ".$conf->entity.")";
1739 $sql .= " ORDER BY name ASC, entity DESC";
1740 $result = $db->query($sql);
1741
1742 dol_syslog("List params", LOG_DEBUG);
1743 if ($result) {
1744 $obj = $db->fetch_object($result); // Take first result of select
1745
1746 if (empty($obj)) { // If not yet into table
1747 $obj = (object) array('rowid' => '', 'name' => $const, 'value' => '', 'type' => $type, 'note' => '');
1748 }
1749
1750 if (empty($strictw3c)) {
1751 print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1752 print '<input type="hidden" name="token" value="'.newToken().'">';
1753 print '<input type="hidden" name="page_y" value="'.newToken().'">';
1754 }
1755
1756 print '<tr class="oddeven">';
1757
1758 // Show label of parameter
1759 print '<td>';
1760 if (empty($strictw3c)) {
1761 print '<input type="hidden" name="action" value="update">';
1762 }
1763 print '<input type="hidden" name="rowid'.(empty($strictw3c) ? '' : '[]').'" value="'.$obj->rowid.'">';
1764 print '<input type="hidden" name="constname'.(empty($strictw3c) ? '' : '[]').'" value="'.$const.'">';
1765 print '<input type="hidden" name="constnote_'.$obj->name.'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
1766 print '<input type="hidden" name="consttype_'.$obj->name.'" value="'.($obj->type ? $obj->type : 'string').'">';
1767 if (!empty($tableau[$key]['tooltip'])) {
1768 print $form->textwithpicto($label ? $label : $langs->trans('Desc'.$const), $tableau[$key]['tooltip']);
1769 } else {
1770 print($label ? $label : $langs->trans('Desc'.$const));
1771 }
1772
1773 if ($const == 'ADHERENT_MAILMAN_URL') {
1774 print '. '.$langs->trans("Example").': <a href="#" id="exampleclick1">'.img_down().'</a><br>';
1775 //print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members?adminpw=%MAILMAN_ADMINPW%&subscribees=%EMAIL%&send_welcome_msg_to_this_batch=1';
1776 print '<div id="example1" class="hidden">';
1777 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';
1778 print '</div>';
1779 } elseif ($const == 'ADHERENT_MAILMAN_UNSUB_URL') {
1780 print '. '.$langs->trans("Example").': <a href="#" id="exampleclick2">'.img_down().'</a><br>';
1781 print '<div id="example2" class="hidden">';
1782 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';
1783 print '</div>';
1784 //print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%';
1785 } elseif ($const == 'ADHERENT_MAILMAN_LISTS') {
1786 print '. '.$langs->trans("Example").': <a href="#" id="exampleclick3">'.img_down().'</a><br>';
1787 print '<div id="example3" class="hidden">';
1788 print 'mymailmanlist<br>';
1789 print 'mymailmanlist1,mymailmanlist2<br>';
1790 print 'TYPE:Type1:mymailmanlist1,TYPE:Type2:mymailmanlist2<br>';
1791 if (isModEnabled('category')) {
1792 print 'CATEG:Categ1:mymailmanlist1,CATEG:Categ2:mymailmanlist2<br>';
1793 }
1794 print '</div>';
1795 //print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%';
1796 } elseif (in_array($const, ['ADHERENT_MAIL_FROM', 'ADHERENT_CC_MAIL_FROM'])) {
1797 print ' '.img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
1798 }
1799
1800 print "</td>\n";
1801
1802 // Value
1803 if ($const == 'ADHERENT_CARD_TYPE' || $const == 'ADHERENT_ETIQUETTE_TYPE') {
1804 print '<td>';
1805 // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
1806 require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
1807 $arrayoflabels = array();
1808 foreach (array_keys($_Avery_Labels) as $codecards) {
1809 $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
1810 }
1811 print $form->selectarray('constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')), $arrayoflabels, ($obj->value ? $obj->value : 'CARD'), 1, 0, 0);
1812 print '<input type="hidden" name="consttype" value="yesno">';
1813 print '<input type="hidden" name="constnote'.(empty($strictw3c) ? '' : '[]').'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
1814 print '</td>';
1815 } else {
1816 print '<td>';
1817 print '<input type="hidden" name="consttype'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')).'" value="'.($obj->type ? $obj->type : 'string').'">';
1818 print '<input type="hidden" name="constnote'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')).'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
1819 if ($obj->type == 'textarea' || in_array($const, array('ADHERENT_CARD_TEXT', 'ADHERENT_CARD_TEXT_RIGHT', 'ADHERENT_ETIQUETTE_TEXT'))) {
1820 print '<textarea class="flat" name="constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')).'" cols="50" rows="5" wrap="soft">'."\n";
1821 print $obj->value;
1822 print "</textarea>\n";
1823 } elseif ($obj->type == 'html') {
1824 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1825 $doleditor = new DolEditor('constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')), $obj->value, '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
1826 $doleditor->Create();
1827 } elseif ($obj->type == 'yesno') {
1828 print $form->selectyesno('constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')), $obj->value, 1, false, 0, 1);
1829 } elseif (preg_match('/emailtemplate/', $obj->type)) {
1830 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1831 $formmail = new FormMail($db);
1832
1833 $tmp = explode(':', $obj->type);
1834
1835 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, -1); // We set lang=null to get in priority record with no lang
1836 //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
1837 $arrayofmessagename = array();
1838 if (is_array($formmail->lines_model)) {
1839 foreach ($formmail->lines_model as $modelmail) {
1840 //var_dump($modelmail);
1841 $moreonlabel = '';
1842 if (!empty($arrayofmessagename[$modelmail->label])) {
1843 $moreonlabel = ' <span class="opacitymedium">('.$langs->trans("SeveralLangugeVariatFound").')</span>';
1844 }
1845 // The 'label' is the key that is unique if we exclude the language
1846 $arrayofmessagename[$modelmail->label.':'.$tmp[1]] = $langs->trans(preg_replace('/\‍(|\‍)/', '', $modelmail->label)).$moreonlabel;
1847 }
1848 }
1849 //var_dump($arraydefaultmessage);
1850 //var_dump($arrayofmessagename);
1851 print $form->selectarray('constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')), $arrayofmessagename, $obj->value.':'.$tmp[1], 'None', 0, 0, '', 0, 0, 0, '', '', 1);
1852 } elseif (preg_match('/MAIL_FROM$/i', $const)) {
1853 print img_picto('', 'email', 'class="pictofixedwidth"').'<input type="text" class="flat minwidth300" name="constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')).'" value="'.dol_escape_htmltag($obj->value).'">';
1854 } else { // type = 'string' ou 'chaine'
1855 print '<input type="text" class="flat minwidth300" name="constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')).'" value="'.dol_escape_htmltag($obj->value).'">';
1856 }
1857 print '</td>';
1858 }
1859
1860 // Submit
1861 if (empty($strictw3c)) {
1862 print '<td class="center">';
1863 print '<input type="submit" class="button small reposition" value="'.$langs->trans("Update").'" name="update">';
1864 print "</td>";
1865 }
1866
1867 print "</tr>\n";
1868
1869 if (empty($strictw3c)) {
1870 print "</form>\n";
1871 }
1872 }
1873 }
1874 print '</table>';
1875 print '</div>';
1876
1877 if (!empty($strictw3c) && $strictw3c == 1) {
1878 print '<div align="center"><input type="submit" class="button small reposition" value="'.$langs->trans("Update").'" name="update"></div>';
1879 print "</form>\n";
1880 }
1881}
1882
1883
1891{
1892 global $conf, $langs;
1893
1894 $text = $langs->trans("OnlyFollowingModulesAreOpenedToExternalUsers");
1895 $listofmodules = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')); // List of modules qualified for external user management
1896
1897 $i = 0;
1898 if (!empty($modules)) {
1899 $tmpmodules = dol_sort_array($modules, 'module_position');
1900 foreach ($tmpmodules as $module) { // Loop on array of modules
1901 $moduleconst = $module->const_name;
1902 $modulename = strtolower($module->name);
1903 //print 'modulename='.$modulename;
1904
1905 //if (empty($conf->global->$moduleconst)) continue;
1906 if (!in_array($modulename, $listofmodules)) {
1907 continue;
1908 }
1909 //var_dump($modulename.' - '.$langs->trans('Module'.$module->numero.'Name'));
1910
1911 if ($i > 0) {
1912 $text .= ', ';
1913 } else {
1914 $text .= ' ';
1915 }
1916 $i++;
1917
1918 $tmptext = $langs->trans('Module'.$module->numero.'Name');
1919 if ($tmptext != 'Module'.$module->numero.'Name') {
1920 $text .= $langs->trans('Module'.$module->numero.'Name');
1921 } else {
1922 $text .= $langs->trans($module->name);
1923 }
1924 }
1925 }
1926
1927 return $text;
1928}
1929
1930
1940function addDocumentModel($name, $type, $label = '', $description = '')
1941{
1942 global $db, $conf;
1943
1944 $db->begin();
1945
1946 $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
1947 $sql .= " VALUES ('".$db->escape($name)."','".$db->escape($type)."',".((int) $conf->entity).", ";
1948 $sql .= ($label ? "'".$db->escape($label)."'" : 'null').", ";
1949 $sql .= (!empty($description) ? "'".$db->escape($description)."'" : "null");
1950 $sql .= ")";
1951
1952 dol_syslog("admin.lib::addDocumentModel", LOG_DEBUG);
1953 $resql = $db->query($sql);
1954 if ($resql) {
1955 $db->commit();
1956 return 1;
1957 } else {
1958 dol_print_error($db);
1959 $db->rollback();
1960 return -1;
1961 }
1962}
1963
1971function delDocumentModel($name, $type)
1972{
1973 global $db, $conf;
1974
1975 $db->begin();
1976
1977 $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
1978 $sql .= " WHERE nom = '".$db->escape($name)."'";
1979 $sql .= " AND type = '".$db->escape($type)."'";
1980 $sql .= " AND entity = ".((int) $conf->entity);
1981
1982 dol_syslog("admin.lib::delDocumentModel", LOG_DEBUG);
1983 $resql = $db->query($sql);
1984 if ($resql) {
1985 $db->commit();
1986 return 1;
1987 } else {
1988 dol_print_error($db);
1989 $db->rollback();
1990 return -1;
1991 }
1992}
1993
1994
2001{
2002 ob_start();
2003 phpinfo();
2004 $phpinfostring = ob_get_contents();
2005 ob_end_clean();
2006
2007 $info_arr = array();
2008 $info_lines = explode("\n", strip_tags($phpinfostring, "<tr><td><h2>"));
2009 $cat = "General";
2010 foreach ($info_lines as $line) {
2011 // new cat?
2012 $title = array();
2013 preg_match("~<h2>(.*)</h2>~", $line, $title) ? $cat = $title[1] : null;
2014 $val = array();
2015 if (preg_match("~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val)) {
2016 $info_arr[trim($cat)][trim($val[1])] = $val[2];
2017 } elseif (preg_match("~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val)) {
2018 $info_arr[trim($cat)][trim($val[1])] = array("local" => $val[2], "master" => $val[3]);
2019 }
2020 }
2021 return $info_arr;
2022}
2023
2030{
2031 global $langs, $conf;
2032
2033 $h = 0;
2034 $head = array();
2035
2036 $head[$h][0] = DOL_URL_ROOT."/admin/company.php";
2037 $head[$h][1] = $langs->trans("Company");
2038 $head[$h][2] = 'company';
2039 $h++;
2040
2041 $head[$h][0] = DOL_URL_ROOT."/admin/openinghours.php";
2042 $head[$h][1] = $langs->trans("OpeningHours");
2043 $head[$h][2] = 'openinghours';
2044 $h++;
2045
2046 $head[$h][0] = DOL_URL_ROOT."/admin/accountant.php";
2047 $head[$h][1] = $langs->trans("Accountant");
2048 $head[$h][2] = 'accountant';
2049 $h++;
2050
2051 $head[$h][0] = DOL_URL_ROOT."/admin/company_socialnetworks.php";
2052 $head[$h][1] = $langs->trans("SocialNetworksInformation");
2053 $head[$h][2] = 'socialnetworks';
2054 $h++;
2055
2056 complete_head_from_modules($conf, $langs, null, $head, $h, 'mycompany_admin', 'add');
2057
2058 complete_head_from_modules($conf, $langs, null, $head, $h, 'mycompany_admin', 'remove');
2059
2060 return $head;
2061}
2062
2069{
2070 global $langs, $conf, $user;
2071
2072 $h = 0;
2073 $head = array();
2074
2075 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
2076 $head[$h][0] = DOL_URL_ROOT."/admin/mails.php";
2077 $head[$h][1] = $langs->trans("OutGoingEmailSetup");
2078 $head[$h][2] = 'common';
2079 $h++;
2080
2081 if (isModEnabled('mailing')) {
2082 $head[$h][0] = DOL_URL_ROOT."/admin/mails_emailing.php";
2083 $head[$h][1] = $langs->trans("OutGoingEmailSetupForEmailing", $langs->transnoentitiesnoconv("EMailing"));
2084 $head[$h][2] = 'common_emailing';
2085 $h++;
2086 }
2087
2088 if (isModEnabled('ticket')) {
2089 $head[$h][0] = DOL_URL_ROOT."/admin/mails_ticket.php";
2090 $head[$h][1] = $langs->trans("OutGoingEmailSetupForEmailing", $langs->transnoentitiesnoconv("Ticket"));
2091 $head[$h][2] = 'common_ticket';
2092 $h++;
2093 }
2094 }
2095
2096 // admin and non admin can view this menu entry, but it is not shown yet when we on user menu "Email templates"
2097 if (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates') {
2098 $head[$h][0] = DOL_URL_ROOT."/admin/mails_senderprofile_list.php";
2099 $head[$h][1] = $langs->trans("EmailSenderProfiles");
2100 $head[$h][2] = 'senderprofiles';
2101 $h++;
2102 }
2103
2104 $head[$h][0] = DOL_URL_ROOT."/admin/mails_templates.php";
2105 $head[$h][1] = $langs->trans("EMailTemplates");
2106 $head[$h][2] = 'templates';
2107 $h++;
2108
2109 $head[$h][0] = DOL_URL_ROOT."/admin/mails_ingoing.php";
2110 $head[$h][1] = $langs->trans("InGoingEmailSetup", $langs->transnoentitiesnoconv("EMailing"));
2111 $head[$h][2] = 'common_ingoing';
2112 $h++;
2113
2114 complete_head_from_modules($conf, $langs, null, $head, $h, 'email_admin', 'remove');
2115
2116 return $head;
2117}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
versiontostring($versionarray)
Renvoi une version en chaine depuis une version en tableau.
Definition admin.lib.php:38
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.
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.
unActivateModule($value, $requiredby=1)
Disable a module.
form_constantes($tableau, $strictw3c=2, $helptext='', $text='Value')
Show array with constants to edit.
activateModule($value, $withdeps=1, $noconfverification=0)
Enable a module.
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabcomplete)
Add external modules to list of dictionaries.
versiondolibarrarray()
Return version Dolibarr.
activateModulesRequiredByCountry($country_code)
Activate external modules mandatory when country is country_code.
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).
Definition admin.lib.php:68
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.
complete_elementList_with_modules(&$elementList)
Search external modules to complete the list of contact element.
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.
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...
dolGetModulesDirs($subdir='')
Return list of directories that contain modules.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 dolibarr global constant string value.
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...
dolEncrypt($chain, $key='', $ciphering='AES-256-CTR', $forceseed='')
Encode a string with a symmetric encryption.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.
checkPHPCode(&$phpfullcodestringold, &$phpfullcodestring)
Check a new string containing only php code (including <php tag)
dolKeepOnlyPhpCode($str)
Keep only PHP code part from a HTML string page.