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