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