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