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