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