dolibarr  16.0.5
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  print ' - <a class="trforrunsqlshowhide'.$keyforsql.'" href="#">'.$langs->trans("ShowHideDetails").'</a>';
527  //}
528 
529  print '</td></tr>'."\n";
530  }
531 
532  if ($error == 0) {
533  $ok = 1;
534  } else {
535  $ok = 0;
536  }
537 
538  return $ok;
539 }
540 
541 
552 function dolibarr_del_const($db, $name, $entity = 1)
553 {
554  global $conf;
555 
556  if (empty($name)) {
557  dol_print_error('', 'Error call dolibar_del_const with parameter name empty');
558  return -1;
559  }
560 
561  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
562  $sql .= " WHERE (".$db->decrypt('name')." = '".$db->escape($name)."'";
563  if (is_numeric($name)) {
564  $sql .= " OR rowid = ".((int) $name);
565  }
566  $sql .= ")";
567  if ($entity >= 0) {
568  $sql .= " AND entity = ".((int) $entity);
569  }
570 
571  dol_syslog("admin.lib::dolibarr_del_const", LOG_DEBUG);
572  $resql = $db->query($sql);
573  if ($resql) {
574  $conf->global->$name = '';
575  return 1;
576  } else {
577  dol_print_error($db);
578  return -1;
579  }
580 }
581 
592 function dolibarr_get_const($db, $name, $entity = 1)
593 {
594  $value = '';
595 
596  $sql = "SELECT ".$db->decrypt('value')." as value";
597  $sql .= " FROM ".MAIN_DB_PREFIX."const";
598  $sql .= " WHERE name = ".$db->encrypt($name);
599  $sql .= " AND entity = ".((int) $entity);
600 
601  dol_syslog("admin.lib::dolibarr_get_const", LOG_DEBUG);
602  $resql = $db->query($sql);
603  if ($resql) {
604  $obj = $db->fetch_object($resql);
605  if ($obj) {
606  $value = $obj->value;
607  }
608  }
609  return $value;
610 }
611 
612 
627 function dolibarr_set_const($db, $name, $value, $type = 'chaine', $visible = 0, $note = '', $entity = 1)
628 {
629  global $conf;
630 
631  // Clean parameters
632  $name = trim($name);
633 
634  // Check parameters
635  if (empty($name)) {
636  dol_print_error($db, "Error: Call to function dolibarr_set_const with wrong parameters", LOG_ERR);
637  exit;
638  }
639 
640  //dol_syslog("dolibarr_set_const name=$name, value=$value type=$type, visible=$visible, note=$note entity=$entity");
641 
642  $db->begin();
643 
644  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
645  $sql .= " WHERE name = ".$db->encrypt($name);
646  if ($entity >= 0) {
647  $sql .= " AND entity = ".((int) $entity);
648  }
649 
650  dol_syslog("admin.lib::dolibarr_set_const", LOG_DEBUG);
651  $resql = $db->query($sql);
652 
653  if (strcmp($value, '')) { // true if different. Must work for $value='0' or $value=0
654  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity)";
655  $sql .= " VALUES (";
656  $sql .= $db->encrypt($name);
657  $sql .= ", ".$db->encrypt($value);
658  $sql .= ",'".$db->escape($type)."',".((int) $visible).",'".$db->escape($note)."',".((int) $entity).")";
659 
660  //print "sql".$value."-".pg_escape_string($value)."-".$sql;exit;
661  //print "xx".$db->escape($value);
662  dol_syslog("admin.lib::dolibarr_set_const", LOG_DEBUG);
663  $resql = $db->query($sql);
664  }
665 
666  if ($resql) {
667  $db->commit();
668  $conf->global->$name = $value;
669  return 1;
670  } else {
671  $error = $db->lasterror();
672  $db->rollback();
673  return -1;
674  }
675 }
676 
677 
678 
679 
687 function modules_prepare_head($nbofactivatedmodules, $nboftotalmodules)
688 {
689  global $langs, $conf, $user, $form;
690 
691  $desc = $langs->trans("ModulesDesc", '{picto}');
692  $desc = str_replace('{picto}', img_picto('', 'switch_off'), $desc);
693 
694  $h = 0;
695  $head = array();
696  $mode = empty($conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT) ? 'commonkanban' : 'common';
697  $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$mode;
698  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)
699  //$head[$h][1] = $form->textwithpicto($langs->trans("AvailableModules"), $desc);
700  $head[$h][1] = $langs->trans("AvailableModules");
701  $head[$h][1] .= $form->textwithpicto('', $langs->trans("YouMustEnableOneModule").'.<br><br><span class="opacitymedium">'.$desc.'</span>', 1, 'warning');
702  } else {
703  //$head[$h][1] = $langs->trans("AvailableModules").$form->textwithpicto('<span class="badge marginleftonly">'.$nbofactivatedmodules.' / '.$nboftotalmodules.'</span>', $desc, 1, 'help', '', 1, 3);
704  $head[$h][1] = $langs->trans("AvailableModules").'<span class="badge marginleftonly">'.$nbofactivatedmodules.' / '.$nboftotalmodules.'</span>';
705  }
706  $head[$h][2] = 'modules';
707  $h++;
708 
709  $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=marketplace";
710  $head[$h][1] = $langs->trans("ModulesMarketPlaces");
711  $head[$h][2] = 'marketplace';
712  $h++;
713 
714  $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=deploy";
715  $head[$h][1] = $langs->trans("AddExtensionThemeModuleOrOther");
716  $head[$h][2] = 'deploy';
717  $h++;
718 
719  $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=develop";
720  $head[$h][1] = $langs->trans("ModulesDevelopYourModule");
721  $head[$h][2] = 'develop';
722  $h++;
723 
724  return $head;
725 }
726 
733 {
734  global $langs, $conf, $user;
735  $h = 0;
736  $head = array();
737 
738  $head[$h][0] = DOL_URL_ROOT."/admin/ihm.php?mode=other";
739  $head[$h][1] = $langs->trans("LanguageAndPresentation");
740  $head[$h][2] = 'other';
741  $h++;
742 
743  $head[$h][0] = DOL_URL_ROOT."/admin/ihm.php?mode=template";
744  $head[$h][1] = $langs->trans("SkinAndColors");
745  $head[$h][2] = 'template';
746  $h++;
747 
748  $head[$h][0] = DOL_URL_ROOT."/admin/ihm.php?mode=dashboard";
749  $head[$h][1] = $langs->trans("Dashboard");
750  $head[$h][2] = 'dashboard';
751  $h++;
752 
753  $head[$h][0] = DOL_URL_ROOT."/admin/ihm.php?mode=login";
754  $head[$h][1] = $langs->trans("LoginPage");
755  $head[$h][2] = 'login';
756  $h++;
757 
758  complete_head_from_modules($conf, $langs, null, $head, $h, 'ihm_admin');
759 
760  complete_head_from_modules($conf, $langs, null, $head, $h, 'ihm_admin', 'remove');
761 
762 
763  return $head;
764 }
765 
766 
773 {
774  global $db, $langs, $conf, $user;
775  $h = 0;
776  $head = array();
777 
778  $head[$h][0] = DOL_URL_ROOT."/admin/security_other.php";
779  $head[$h][1] = $langs->trans("Miscellaneous");
780  $head[$h][2] = 'misc';
781  $h++;
782 
783  $head[$h][0] = DOL_URL_ROOT."/admin/security.php";
784  $head[$h][1] = $langs->trans("Passwords");
785  $head[$h][2] = 'passwords';
786  $h++;
787 
788  $head[$h][0] = DOL_URL_ROOT."/admin/security_file.php";
789  $head[$h][1] = $langs->trans("Files").' ('.$langs->trans("Upload").')';
790  $head[$h][2] = 'file';
791  $h++;
792 
793  /*
794  $head[$h][0] = DOL_URL_ROOT."/admin/security_file_download.php";
795  $head[$h][1] = $langs->trans("Files").' ('.$langs->trans("Download").')';
796  $head[$h][2] = 'filedownload';
797  $h++;
798  */
799 
800  $head[$h][0] = DOL_URL_ROOT."/admin/proxy.php";
801  $head[$h][1] = $langs->trans("ExternalAccess");
802  $head[$h][2] = 'proxy';
803  $h++;
804 
805  $head[$h][0] = DOL_URL_ROOT."/admin/events.php";
806  $head[$h][1] = $langs->trans("Audit");
807  $head[$h][2] = 'audit';
808  $h++;
809 
810 
811  // Show permissions lines
812  $nbPerms = 0;
813  $sql = "SELECT COUNT(r.id) as nb";
814  $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
815  $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
816  $sql .= " AND entity = ".((int) $conf->entity);
817  $sql .= " AND bydefault = 1";
818  if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
819  $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
820  }
821  $resql = $db->query($sql);
822  if ($resql) {
823  $obj = $db->fetch_object($resql);
824  if ($obj) {
825  $nbPerms = $obj->nb;
826  }
827  } else {
828  dol_print_error($db);
829  }
830 
831  $head[$h][0] = DOL_URL_ROOT."/admin/perms.php";
832  $head[$h][1] = $langs->trans("DefaultRights");
833  if ($nbPerms > 0) {
834  $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbPerms.'</span>' : '');
835  }
836  $head[$h][2] = 'default';
837  $h++;
838 
839  return $head;
840 }
841 
847 function modulehelp_prepare_head($object)
848 {
849  global $langs, $conf, $user;
850  $h = 0;
851  $head = array();
852 
853  // FIX for compatibity habitual tabs
854  $object->id = $object->numero;
855 
856  $head[$h][0] = DOL_URL_ROOT."/admin/modulehelp.php?id=".$object->id.'&mode=desc';
857  $head[$h][1] = $langs->trans("Description");
858  $head[$h][2] = 'desc';
859  $h++;
860 
861  $head[$h][0] = DOL_URL_ROOT."/admin/modulehelp.php?id=".$object->id.'&mode=feature';
862  $head[$h][1] = $langs->trans("TechnicalServicesProvided");
863  $head[$h][2] = 'feature';
864  $h++;
865 
866  if ($object->isCoreOrExternalModule() == 'external') {
867  $head[$h][0] = DOL_URL_ROOT."/admin/modulehelp.php?id=".$object->id.'&mode=changelog';
868  $head[$h][1] = $langs->trans("ChangeLog");
869  $head[$h][2] = 'changelog';
870  $h++;
871  }
872 
873  complete_head_from_modules($conf, $langs, $object, $head, $h, 'modulehelp_admin');
874 
875  complete_head_from_modules($conf, $langs, $object, $head, $h, 'modulehelp_admin', 'remove');
876 
877 
878  return $head;
879 }
886 {
887  global $langs, $conf, $user;
888  $h = 0;
889  $head = array();
890 
891  $head[$h][0] = DOL_URL_ROOT."/admin/translation.php?mode=searchkey";
892  $head[$h][1] = $langs->trans("TranslationKeySearch");
893  $head[$h][2] = 'searchkey';
894  $h++;
895 
896  $head[$h][0] = DOL_URL_ROOT."/admin/translation.php?mode=overwrite";
897  $head[$h][1] = '<span class="valignmiddle">'.$langs->trans("TranslationOverwriteKey").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
898  $head[$h][2] = 'overwrite';
899  $h++;
900 
901  complete_head_from_modules($conf, $langs, null, $head, $h, 'translation_admin');
902 
903  complete_head_from_modules($conf, $langs, null, $head, $h, 'translation_admin', 'remove');
904 
905 
906  return $head;
907 }
908 
909 
916 {
917  global $langs, $conf, $user;
918  $h = 0;
919  $head = array();
920 
921  $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=createform";
922  $head[$h][1] = $langs->trans("DefaultCreateForm");
923  $head[$h][2] = 'createform';
924  $h++;
925 
926  $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=filters";
927  $head[$h][1] = $langs->trans("DefaultSearchFilters");
928  $head[$h][2] = 'filters';
929  $h++;
930 
931  $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=sortorder";
932  $head[$h][1] = $langs->trans("DefaultSortOrder");
933  $head[$h][2] = 'sortorder';
934  $h++;
935 
936  if (!empty($conf->use_javascript_ajax)) {
937  $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=focus";
938  $head[$h][1] = $langs->trans("DefaultFocus");
939  $head[$h][2] = 'focus';
940  $h++;
941 
942  $head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=mandatory";
943  $head[$h][1] = $langs->trans("DefaultMandatory");
944  $head[$h][2] = 'mandatory';
945  $h++;
946  }
947 
948  /*$head[$h][0] = DOL_URL_ROOT."/admin/translation.php?mode=searchkey";
949  $head[$h][1] = $langs->trans("TranslationKeySearch");
950  $head[$h][2] = 'searchkey';
951  $h++;*/
952 
953  complete_head_from_modules($conf, $langs, null, $head, $h, 'defaultvalues_admin');
954 
955  complete_head_from_modules($conf, $langs, null, $head, $h, 'defaultvalues_admin', 'remove');
956 
957 
958  return $head;
959 }
960 
961 
967 function listOfSessions()
968 {
969  global $conf;
970 
971  $arrayofSessions = array();
972  // session.save_path can be returned empty so we set a default location and work from there
973  $sessPath = '/tmp';
974  $iniPath = ini_get("session.save_path");
975  if ($iniPath) {
976  $sessPath = $iniPath;
977  }
978  $sessPath .= '/'; // We need the trailing slash
979  dol_syslog('admin.lib:listOfSessions sessPath='.$sessPath);
980 
981  $dh = @opendir(dol_osencode($sessPath));
982  if ($dh) {
983  while (($file = @readdir($dh)) !== false) {
984  if (preg_match('/^sess_/i', $file) && $file != "." && $file != "..") {
985  $fullpath = $sessPath.$file;
986  if (!@is_dir($fullpath) && is_readable($fullpath)) {
987  $sessValues = file_get_contents($fullpath); // get raw session data
988  // Example of possible value
989  //$sessValues = 'newtoken|s:32:"1239f7a0c4b899200fe9ca5ea394f307";dol_loginmesg|s:0:"";newtoken|s:32:"1236457104f7ae0f328c2928973f3cb5";dol_loginmesg|s:0:"";token|s:32:"123615ad8d650c5cc4199b9a1a76783f";
990  // 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";
991  // 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";';
992 
993  if (preg_match('/dol_login/i', $sessValues) && // limit to dolibarr session
994  (preg_match('/dol_entity\|i:'.$conf->entity.';/i', $sessValues) || preg_match('/dol_entity\|s:([0-9]+):"'.$conf->entity.'"/i', $sessValues)) && // limit to current entity
995  preg_match('/dol_company\|s:([0-9]+):"('.getDolGlobalString('MAIN_INFO_SOCIETE_NOM').')"/i', $sessValues)) { // limit to company name
996  $tmp = explode('_', $file);
997  $idsess = $tmp[1];
998  $regs = array();
999  $loginfound = preg_match('/dol_login\|s:[0-9]+:"([A-Za-z0-9]+)"/i', $sessValues, $regs);
1000  if ($loginfound) {
1001  $arrayofSessions[$idsess]["login"] = $regs[1];
1002  }
1003  $arrayofSessions[$idsess]["age"] = time() - filectime($fullpath);
1004  $arrayofSessions[$idsess]["creation"] = filectime($fullpath);
1005  $arrayofSessions[$idsess]["modification"] = filemtime($fullpath);
1006  $arrayofSessions[$idsess]["raw"] = $sessValues;
1007  }
1008  }
1009  }
1010  }
1011  @closedir($dh);
1012  }
1013 
1014  return $arrayofSessions;
1015 }
1016 
1023 function purgeSessions($mysessionid)
1024 {
1025  global $conf;
1026 
1027  $sessPath = ini_get("session.save_path")."/";
1028  dol_syslog('admin.lib:purgeSessions mysessionid='.$mysessionid.' sessPath='.$sessPath);
1029 
1030  $error = 0;
1031 
1032  $dh = @opendir(dol_osencode($sessPath));
1033  if ($dh) {
1034  while (($file = @readdir($dh)) !== false) {
1035  if ($file != "." && $file != "..") {
1036  $fullpath = $sessPath.$file;
1037  if (!@is_dir($fullpath)) {
1038  $sessValues = file_get_contents($fullpath); // get raw session data
1039 
1040  if (preg_match('/dol_login/i', $sessValues) && // limit to dolibarr session
1041  preg_match('/dol_entity\|s:([0-9]+):"('.$conf->entity.')"/i', $sessValues) && // limit to current entity
1042  preg_match('/dol_company\|s:([0-9]+):"('.$conf->global->MAIN_INFO_SOCIETE_NOM.')"/i', $sessValues)) { // limit to company name
1043  $tmp = explode('_', $file);
1044  $idsess = $tmp[1];
1045  // We remove session if it's not ourself
1046  if ($idsess != $mysessionid) {
1047  $res = @unlink($fullpath);
1048  if (!$res) {
1049  $error++;
1050  }
1051  }
1052  }
1053  }
1054  }
1055  }
1056  @closedir($dh);
1057  }
1058 
1059  if (!$error) {
1060  return 1;
1061  } else {
1062  return -$error;
1063  }
1064 }
1065 
1066 
1067 
1075 function activateModule($value, $withdeps = 1)
1076 {
1077  global $db, $langs, $conf, $mysoc;
1078 
1079  $ret = array();
1080 
1081  // Check parameters
1082  if (empty($value)) {
1083  $ret['errors'][] = 'ErrorBadParameter';
1084  return $ret;
1085  }
1086 
1087  $ret = array('nbmodules'=>0, 'errors'=>array(), 'nbperms'=>0);
1088  $modName = $value;
1089  $modFile = $modName.".class.php";
1090 
1091  // Loop on each directory to fill $modulesdir
1092  $modulesdir = dolGetModulesDirs();
1093 
1094  // Loop on each modulesdir directories
1095  $found = false;
1096  foreach ($modulesdir as $dir) {
1097  if (file_exists($dir.$modFile)) {
1098  $found = @include_once $dir.$modFile;
1099  if ($found) {
1100  break;
1101  }
1102  }
1103  }
1104 
1105  $objMod = new $modName($db);
1106 
1107  // Test if PHP version ok
1108  $verphp = versionphparray();
1109  $vermin = isset($objMod->phpmin) ? $objMod->phpmin : 0;
1110  if (is_array($vermin) && versioncompare($verphp, $vermin) < 0) {
1111  $ret['errors'][] = $langs->trans("ErrorModuleRequirePHPVersion", versiontostring($vermin));
1112  return $ret;
1113  }
1114 
1115  // Test if Dolibarr version ok
1116  $verdol = versiondolibarrarray();
1117  $vermin = isset($objMod->need_dolibarr_version) ? $objMod->need_dolibarr_version : 0;
1118  //print 'version: '.versioncompare($verdol,$vermin).' - '.join(',',$verdol).' - '.join(',',$vermin);exit;
1119  if (is_array($vermin) && versioncompare($verdol, $vermin) < 0) {
1120  $ret['errors'][] = $langs->trans("ErrorModuleRequireDolibarrVersion", versiontostring($vermin));
1121  return $ret;
1122  }
1123 
1124  // Test if javascript requirement ok
1125  if (!empty($objMod->need_javascript_ajax) && empty($conf->use_javascript_ajax)) {
1126  $ret['errors'][] = $langs->trans("ErrorModuleRequireJavascript");
1127  return $ret;
1128  }
1129 
1130  $const_name = $objMod->const_name;
1131  if (!empty($conf->global->$const_name)) {
1132  return $ret;
1133  }
1134 
1135  $result = $objMod->init(); // Enable module
1136 
1137  if ($result <= 0) {
1138  $ret['errors'][] = $objMod->error;
1139  } else {
1140  if ($withdeps) {
1141  if (isset($objMod->depends) && is_array($objMod->depends) && !empty($objMod->depends)) {
1142  // Activation of modules this module depends on
1143  // this->depends may be array('modModule1', 'mmodModule2') or array('always1'=>"modModule1", 'FR'=>'modModule2')
1144  foreach ($objMod->depends as $key => $modulestring) {
1145  //var_dump((! is_numeric($key)) && ! preg_match('/^always/', $key) && $mysoc->country_code && ! preg_match('/^'.$mysoc->country_code.'/', $key));exit;
1146  if ((!is_numeric($key)) && !preg_match('/^always/', $key) && $mysoc->country_code && !preg_match('/^'.$mysoc->country_code.'/', $key)) {
1147  dol_syslog("We are not concerned by dependency with key=".$key." because our country is ".$mysoc->country_code);
1148  continue;
1149  }
1150  $activate = false;
1151  foreach ($modulesdir as $dir) {
1152  if (file_exists($dir.$modulestring.".class.php")) {
1153  $resarray = activateModule($modulestring);
1154  if (empty($resarray['errors'])) {
1155  $activate = true;
1156  } else {
1157  foreach ($resarray['errors'] as $errorMessage) {
1158  dol_syslog($errorMessage, LOG_ERR);
1159  }
1160  }
1161  break;
1162  }
1163  }
1164 
1165  if ($activate) {
1166  $ret['nbmodules'] += $resarray['nbmodules'];
1167  $ret['nbperms'] += $resarray['nbperms'];
1168  } else {
1169  $ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $modulestring);
1170  }
1171  }
1172  }
1173 
1174  if (isset($objMod->conflictwith) && is_array($objMod->conflictwith) && !empty($objMod->conflictwith)) {
1175  // Desactivation des modules qui entrent en conflit
1176  $num = count($objMod->conflictwith);
1177  for ($i = 0; $i < $num; $i++) {
1178  foreach ($modulesdir as $dir) {
1179  if (file_exists($dir.$objMod->conflictwith[$i].".class.php")) {
1180  unActivateModule($objMod->conflictwith[$i], 0);
1181  }
1182  }
1183  }
1184  }
1185  }
1186  }
1187 
1188  if (!count($ret['errors'])) {
1189  $ret['nbmodules']++;
1190  $ret['nbperms'] += (is_array($objMod->rights)?count($objMod->rights):0);
1191  }
1192 
1193  return $ret;
1194 }
1195 
1196 
1204 function unActivateModule($value, $requiredby = 1)
1205 {
1206  global $db, $modules, $conf;
1207 
1208  // Check parameters
1209  if (empty($value)) {
1210  return 'ErrorBadParameter';
1211  }
1212 
1213  $ret = '';
1214  $modName = $value;
1215  $modFile = $modName.".class.php";
1216 
1217  // Loop on each directory to fill $modulesdir
1218  $modulesdir = dolGetModulesDirs();
1219 
1220  // Loop on each modulesdir directories
1221  $found = false;
1222  foreach ($modulesdir as $dir) {
1223  if (file_exists($dir.$modFile)) {
1224  $found = @include_once $dir.$modFile;
1225  if ($found) {
1226  break;
1227  }
1228  }
1229  }
1230 
1231  if ($found) {
1232  $objMod = new $modName($db);
1233  $result = $objMod->remove();
1234  if ($result <= 0) {
1235  $ret = $objMod->error;
1236  }
1237  } else // We come here when we try to unactivate a module when module does not exists anymore in sources
1238  {
1239  //print $dir.$modFile;exit;
1240  // 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
1241  include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
1242  $genericMod = new DolibarrModules($db);
1243  $genericMod->name = preg_replace('/^mod/i', '', $modName);
1244  $genericMod->rights_class = strtolower(preg_replace('/^mod/i', '', $modName));
1245  $genericMod->const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', $modName));
1246  dol_syslog("modules::unActivateModule Failed to find module file, we use generic function with name ".$modName);
1247  $genericMod->remove('');
1248  }
1249 
1250  // Disable modules that depends on module we disable
1251  if (!$ret && $requiredby && is_object($objMod) && is_array($objMod->requiredby)) {
1252  $countrb = count($objMod->requiredby);
1253  for ($i = 0; $i < $countrb; $i++) {
1254  //var_dump($objMod->requiredby[$i]);
1255  unActivateModule($objMod->requiredby[$i]);
1256  }
1257  }
1258 
1259  return $ret;
1260 }
1261 
1262 
1281 function complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabcomplete)
1282 {
1283  global $db, $modules, $conf, $langs;
1284 
1285  dol_syslog("complete_dictionary_with_modules Search external modules to complete the list of dictionnary tables", LOG_DEBUG, 1);
1286 
1287  // Search modules
1288  $modulesdir = dolGetModulesDirs();
1289  $i = 0; // is a sequencer of modules found
1290  $j = 0; // j is module number. Automatically affected if module number not defined.
1291 
1292  foreach ($modulesdir as $dir) {
1293  // Load modules attributes in arrays (name, numero, orders) from dir directory
1294  //print $dir."\n<br>";
1295  dol_syslog("Scan directory ".$dir." for modules");
1296  $handle = @opendir(dol_osencode($dir));
1297  if (is_resource($handle)) {
1298  while (($file = readdir($handle)) !== false) {
1299  //print "$i ".$file."\n<br>";
1300  if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
1301  $modName = substr($file, 0, dol_strlen($file) - 10);
1302 
1303  if ($modName) {
1304  include_once $dir.$file;
1305  $objMod = new $modName($db);
1306 
1307  if ($objMod->numero > 0) {
1308  $j = $objMod->numero;
1309  } else {
1310  $j = 1000 + $i;
1311  }
1312 
1313  $modulequalified = 1;
1314 
1315  // We discard modules according to features level (PS: if module is activated we always show it)
1316  $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
1317  if ($objMod->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2 && empty(getDolGlobalString($const_name))) {
1318  $modulequalified = 0;
1319  }
1320  if ($objMod->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1 && empty(getDolGlobalString($const_name))) {
1321  $modulequalified = 0;
1322  }
1323  //If module is not activated disqualified
1324  if (empty(getDolGlobalString($const_name))) {
1325  $modulequalified = 0;
1326  }
1327 
1328  if ($modulequalified) {
1329  // Load languages files of module
1330  if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
1331  foreach ($objMod->langfiles as $langfile) {
1332  $langs->load($langfile);
1333  }
1334  }
1335 
1336  // Complete the arrays &$tabname,&$tablib,&$tabsql,&$tabsqlsort,&$tabfield,&$tabfieldvalue,&$tabfieldinsert,&$tabrowid,&$tabcond
1337  if (empty($objMod->dictionaries) && !empty($objMod->dictionnaries)) {
1338  $objMod->dictionaries = $objMod->dictionnaries; // For backward compatibility
1339  }
1340 
1341  if (!empty($objMod->dictionaries)) {
1342  //var_dump($objMod->dictionaries['tabname']);
1343  $nbtabname = $nbtablib = $nbtabsql = $nbtabsqlsort = $nbtabfield = $nbtabfieldvalue = $nbtabfieldinsert = $nbtabrowid = $nbtabcond = $nbtabfieldcheck = $nbtabhelp = 0;
1344  $tabnamerelwithkey = array();
1345  foreach ($objMod->dictionaries['tabname'] as $key => $val) {
1346  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $val);
1347  $nbtabname++;
1348  $taborder[] = max($taborder) + 1;
1349  $tabname[] = $val;
1350  $tabnamerelwithkey[$key] = $val;
1351  $tabcomplete[$tmptablename]['picto'] = $objMod->picto;
1352  } // Position
1353  foreach ($objMod->dictionaries['tablib'] as $key => $val) {
1354  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1355  $nbtablib++;
1356  $tablib[] = $val;
1357  $tabcomplete[$tmptablename]['lib'] = $val;
1358  }
1359  foreach ($objMod->dictionaries['tabsql'] as $key => $val) {
1360  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1361  $nbtabsql++;
1362  $tabsql[] = $val;
1363  $tabcomplete[$tmptablename]['sql'] = $val;
1364  }
1365  foreach ($objMod->dictionaries['tabsqlsort'] as $key => $val) {
1366  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1367  $nbtabsqlsort++;
1368  $tabsqlsort[] = $val;
1369  $tabcomplete[$tmptablename]['sqlsort'] = $val;
1370  }
1371  foreach ($objMod->dictionaries['tabfield'] as $key => $val) {
1372  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1373  $nbtabfield++;
1374  $tabfield[] = $val;
1375  $tabcomplete[$tmptablename]['field'] = $val;
1376  }
1377  foreach ($objMod->dictionaries['tabfieldvalue'] as $key => $val) {
1378  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1379  $nbtabfieldvalue++;
1380  $tabfieldvalue[] = $val;
1381  $tabcomplete[$tmptablename]['value'] = $val;
1382  }
1383  foreach ($objMod->dictionaries['tabfieldinsert'] as $key => $val) {
1384  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1385  $nbtabfieldinsert++;
1386  $tabfieldinsert[] = $val;
1387  $tabcomplete[$tmptablename]['fieldinsert'] = $val;
1388  }
1389  foreach ($objMod->dictionaries['tabrowid'] as $key => $val) {
1390  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1391  $nbtabrowid++;
1392  $tabrowid[] = $val;
1393  $tabcomplete[$tmptablename]['rowid'] = $val;
1394  }
1395  foreach ($objMod->dictionaries['tabcond'] as $key => $val) {
1396  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1397  $nbtabcond++;
1398  $tabcond[] = $val;
1399  $tabcomplete[$tmptablename]['rowid'] = $val;
1400  }
1401  if (!empty($objMod->dictionaries['tabhelp'])) {
1402  foreach ($objMod->dictionaries['tabhelp'] as $key => $val) {
1403  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1404  $nbtabhelp++;
1405  $tabhelp[] = $val;
1406  $tabcomplete[$tmptablename]['help'] = $val;
1407  }
1408  }
1409  if (!empty($objMod->dictionaries['tabfieldcheck'])) {
1410  foreach ($objMod->dictionaries['tabfieldcheck'] as $key => $val) {
1411  $tmptablename = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabnamerelwithkey[$key]);
1412  $nbtabfieldcheck++;
1413  $tabcomplete[$tmptablename]['fieldcheck'] = $val;
1414  }
1415  }
1416 
1417  if ($nbtabname != $nbtablib || $nbtablib != $nbtabsql || $nbtabsql != $nbtabsqlsort) {
1418  print 'Error in descriptor of module '.$const_name.'. Array ->dictionaries has not same number of record for key "tabname", "tablib", "tabsql" and "tabsqlsort"';
1419  //print "$const_name: $nbtabname=$nbtablib=$nbtabsql=$nbtabsqlsort=$nbtabfield=$nbtabfieldvalue=$nbtabfieldinsert=$nbtabrowid=$nbtabcond=$nbtabfieldcheck=$nbtabhelp\n";
1420  } else {
1421  $taborder[] = 0; // Add an empty line
1422  }
1423  }
1424 
1425  $j++;
1426  $i++;
1427  } else {
1428  dol_syslog("Module ".get_class($objMod)." not qualified");
1429  }
1430  }
1431  }
1432  }
1433  closedir($handle);
1434  } else {
1435  dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
1436  }
1437  }
1438 
1439  dol_syslog("", LOG_DEBUG, -1);
1440 
1441  return 1;
1442 }
1443 
1450 function activateModulesRequiredByCountry($country_code)
1451 {
1452  global $db, $conf, $langs;
1453 
1454  $modulesdir = dolGetModulesDirs();
1455 
1456  foreach ($modulesdir as $dir) {
1457  // Load modules attributes in arrays (name, numero, orders) from dir directory
1458  dol_syslog("Scan directory ".$dir." for modules");
1459  $handle = @opendir(dol_osencode($dir));
1460  if (is_resource($handle)) {
1461  while (($file = readdir($handle)) !== false) {
1462  if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
1463  $modName = substr($file, 0, dol_strlen($file) - 10);
1464 
1465  if ($modName) {
1466  include_once $dir.$file;
1467  $objMod = new $modName($db);
1468 
1469  $modulequalified = 1;
1470 
1471  // We discard modules according to features level (PS: if module is activated we always show it)
1472  $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
1473 
1474  if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
1475  $modulequalified = 0;
1476  }
1477  if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
1478  $modulequalified = 0;
1479  }
1480  if (!empty($conf->global->$const_name)) {
1481  $modulequalified = 0; // already activated
1482  }
1483 
1484  if ($modulequalified) {
1485  // Load languages files of module
1486  if (isset($objMod->automatic_activation) && is_array($objMod->automatic_activation) && isset($objMod->automatic_activation[$country_code])) {
1487  activateModule($modName);
1488 
1489  setEventMessages($objMod->automatic_activation[$country_code], null, 'warnings');
1490  }
1491  } else {
1492  dol_syslog("Module ".get_class($objMod)." not qualified");
1493  }
1494  }
1495  }
1496  }
1497  closedir($handle);
1498  } else {
1499  dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
1500  }
1501  }
1502 
1503  return 1;
1504 }
1505 
1512 function complete_elementList_with_modules(&$elementList)
1513 {
1514  global $db, $modules, $conf, $langs;
1515 
1516  // Search modules
1517  $filename = array();
1518  $modules = array();
1519  $orders = array();
1520  $categ = array();
1521  $dirmod = array();
1522 
1523  $i = 0; // is a sequencer of modules found
1524  $j = 0; // j is module number. Automatically affected if module number not defined.
1525 
1526  dol_syslog("complete_elementList_with_modules Search external modules to complete the list of contact element", LOG_DEBUG, 1);
1527 
1528  $modulesdir = dolGetModulesDirs();
1529 
1530  foreach ($modulesdir as $dir) {
1531  // Load modules attributes in arrays (name, numero, orders) from dir directory
1532  //print $dir."\n<br>";
1533  dol_syslog("Scan directory ".$dir." for modules");
1534  $handle = @opendir(dol_osencode($dir));
1535  if (is_resource($handle)) {
1536  while (($file = readdir($handle)) !== false) {
1537  //print "$i ".$file."\n<br>";
1538  if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
1539  $modName = substr($file, 0, dol_strlen($file) - 10);
1540 
1541  if ($modName) {
1542  include_once $dir.$file;
1543  $objMod = new $modName($db);
1544 
1545  if ($objMod->numero > 0) {
1546  $j = $objMod->numero;
1547  } else {
1548  $j = 1000 + $i;
1549  }
1550 
1551  $modulequalified = 1;
1552 
1553  // We discard modules according to features level (PS: if module is activated we always show it)
1554  $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
1555  if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && getDolGlobalString($const_name)) {
1556  $modulequalified = 0;
1557  }
1558  if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && getDolGlobalString($const_name)) {
1559  $modulequalified = 0;
1560  }
1561  //If module is not activated disqualified
1562  if (empty($conf->global->$const_name)) {
1563  $modulequalified = 0;
1564  }
1565 
1566  if ($modulequalified) {
1567  // Load languages files of module
1568  if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
1569  foreach ($objMod->langfiles as $langfile) {
1570  $langs->load($langfile);
1571  }
1572  }
1573 
1574  $modules[$i] = $objMod;
1575  $filename[$i] = $modName;
1576  $orders[$i] = $objMod->family."_".$j; // Sort on family then module number
1577  $dirmod[$i] = $dir;
1578  //print "x".$modName." ".$orders[$i]."\n<br>";
1579 
1580  if (!empty($objMod->module_parts['contactelement'])) {
1581  if (is_array($objMod->module_parts['contactelement'])) {
1582  foreach ($objMod->module_parts['contactelement'] as $elem => $title) {
1583  $elementList[$elem] = $langs->trans($title);
1584  }
1585  } else {
1586  $elementList[$objMod->name] = $langs->trans($objMod->name);
1587  }
1588  }
1589 
1590  $j++;
1591  $i++;
1592  } else {
1593  dol_syslog("Module ".get_class($objMod)." not qualified");
1594  }
1595  }
1596  }
1597  }
1598  closedir($handle);
1599  } else {
1600  dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
1601  }
1602  }
1603 
1604  dol_syslog("", LOG_DEBUG, -1);
1605 
1606  return 1;
1607 }
1608 
1619 function form_constantes($tableau, $strictw3c = 0, $helptext = '', $text = 'Value')
1620 {
1621  global $db, $langs, $conf, $user;
1622  global $_Avery_Labels;
1623 
1624  $form = new Form($db);
1625 
1626  if (empty($strictw3c)) {
1627  dol_syslog("Warning: Function form_constantes is calle with parameter strictw3c = 0, this is deprecated. Value must be 2 now.", LOG_DEBUG);
1628  }
1629  if (!empty($strictw3c) && $strictw3c == 1) {
1630  print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1631  print '<input type="hidden" name="token" value="'.newToken().'">';
1632  print '<input type="hidden" name="action" value="updateall">';
1633  }
1634 
1635  print '<div class="div-table-responsive-no-min">';
1636  print '<table class="noborder centpercent">';
1637  print '<tr class="liste_titre">';
1638  print '<td class="">'.$langs->trans("Description").'</td>';
1639  print '<td>';
1640  $text = $langs->trans($text);
1641  print $form->textwithpicto($text, $helptext, 1, 'help', '', 0, 2, 'idhelptext');
1642  print '</td>';
1643  if (empty($strictw3c)) {
1644  print '<td class="center" width="80">'.$langs->trans("Action").'</td>';
1645  }
1646  print "</tr>\n";
1647 
1648  $label = '';
1649  foreach ($tableau as $key => $const) { // Loop on each param
1650  $label = '';
1651  // $const is a const key like 'MYMODULE_ABC'
1652  if (is_numeric($key)) { // Very old behaviour
1653  $type = 'string';
1654  } else {
1655  if (is_array($const)) {
1656  $type = $const['type'];
1657  $label = $const['label'];
1658  $const = $key;
1659  } else {
1660  $type = $const;
1661  $const = $key;
1662  }
1663  }
1664 
1665  $sql = "SELECT ";
1666  $sql .= "rowid";
1667  $sql .= ", ".$db->decrypt('name')." as name";
1668  $sql .= ", ".$db->decrypt('value')." as value";
1669  $sql .= ", type";
1670  $sql .= ", note";
1671  $sql .= " FROM ".MAIN_DB_PREFIX."const";
1672  $sql .= " WHERE ".$db->decrypt('name')." = '".$db->escape($const)."'";
1673  $sql .= " AND entity IN (0, ".$conf->entity.")";
1674  $sql .= " ORDER BY name ASC, entity DESC";
1675  $result = $db->query($sql);
1676 
1677  dol_syslog("List params", LOG_DEBUG);
1678  if ($result) {
1679  $obj = $db->fetch_object($result); // Take first result of select
1680 
1681  if (empty($obj)) { // If not yet into table
1682  $obj = (object) array('rowid'=>'', 'name'=>$const, 'value'=>'', 'type'=>$type, 'note'=>'');
1683  }
1684 
1685  if (empty($strictw3c)) {
1686  print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1687  print '<input type="hidden" name="token" value="'.newToken().'">';
1688  print '<input type="hidden" name="page_y" value="'.newToken().'">';
1689  }
1690 
1691  print '<tr class="oddeven">';
1692 
1693  // Show constant
1694  print '<td>';
1695  if (empty($strictw3c)) {
1696  print '<input type="hidden" name="action" value="update">';
1697  }
1698  print '<input type="hidden" name="rowid'.(empty($strictw3c) ? '' : '[]').'" value="'.$obj->rowid.'">';
1699  print '<input type="hidden" name="constname'.(empty($strictw3c) ? '' : '[]').'" value="'.$const.'">';
1700  print '<input type="hidden" name="constnote_'.$obj->name.'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
1701  print '<input type="hidden" name="consttype_'.$obj->name.'" value="'.($obj->type ? $obj->type : 'string').'">';
1702 
1703  print ($label ? $label : $langs->trans('Desc'.$const));
1704 
1705  if ($const == 'ADHERENT_MAILMAN_URL') {
1706  print '. '.$langs->trans("Example").': <a href="#" id="exampleclick1">'.img_down().'</a><br>';
1707  //print 'http://lists.exampe.com/cgi-bin/mailman/admin/%LISTE%/members?adminpw=%MAILMAN_ADMINPW%&subscribees=%EMAIL%&send_welcome_msg_to_this_batch=1';
1708  print '<div id="example1" class="hidden">';
1709  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';
1710  print '</div>';
1711  } elseif ($const == 'ADHERENT_MAILMAN_UNSUB_URL') {
1712  print '. '.$langs->trans("Example").': <a href="#" id="exampleclick2">'.img_down().'</a><br>';
1713  print '<div id="example2" class="hidden">';
1714  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';
1715  print '</div>';
1716  //print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%';
1717  } elseif ($const == 'ADHERENT_MAILMAN_LISTS') {
1718  print '. '.$langs->trans("Example").': <a href="#" id="exampleclick3">'.img_down().'</a><br>';
1719  print '<div id="example3" class="hidden">';
1720  print 'mymailmanlist<br>';
1721  print 'mymailmanlist1,mymailmanlist2<br>';
1722  print 'TYPE:Type1:mymailmanlist1,TYPE:Type2:mymailmanlist2<br>';
1723  if (isModEnabled('categorie')) {
1724  print 'CATEG:Categ1:mymailmanlist1,CATEG:Categ2:mymailmanlist2<br>';
1725  }
1726  print '</div>';
1727  //print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%';
1728  } elseif ($const == 'ADHERENT_MAIL_FROM') {
1729  print ' '.img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
1730  }
1731 
1732  print "</td>\n";
1733 
1734  // Value
1735  if ($const == 'ADHERENT_CARD_TYPE' || $const == 'ADHERENT_ETIQUETTE_TYPE') {
1736  print '<td>';
1737  // List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
1738  require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
1739  $arrayoflabels = array();
1740  foreach (array_keys($_Avery_Labels) as $codecards) {
1741  $arrayoflabels[$codecards] = $_Avery_Labels[$codecards]['name'];
1742  }
1743  print $form->selectarray('constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')), $arrayoflabels, ($obj->value ? $obj->value : 'CARD'), 1, 0, 0);
1744  print '<input type="hidden" name="consttype" value="yesno">';
1745  print '<input type="hidden" name="constnote'.(empty($strictw3c) ? '' : '[]').'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
1746  print '</td>';
1747  } else {
1748  print '<td>';
1749  print '<input type="hidden" name="consttype'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')).'" value="'.($obj->type ? $obj->type : 'string').'">';
1750  print '<input type="hidden" name="constnote'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')).'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
1751  if ($obj->type == 'textarea' || in_array($const, array('ADHERENT_CARD_TEXT', 'ADHERENT_CARD_TEXT_RIGHT', 'ADHERENT_ETIQUETTE_TEXT'))) {
1752  print '<textarea class="flat" name="constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')).'" cols="50" rows="5" wrap="soft">'."\n";
1753  print $obj->value;
1754  print "</textarea>\n";
1755  } elseif ($obj->type == 'html') {
1756  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1757  $doleditor = new DolEditor('constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')), $obj->value, '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
1758  $doleditor->Create();
1759  } elseif ($obj->type == 'yesno') {
1760  print $form->selectyesno('constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')), $obj->value, 1);
1761  } elseif (preg_match('/emailtemplate/', $obj->type)) {
1762  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1763  $formmail = new FormMail($db);
1764 
1765  $tmp = explode(':', $obj->type);
1766 
1767  $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, -1); // We set lang=null to get in priority record with no lang
1768  //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
1769  $arrayofmessagename = array();
1770  if (is_array($formmail->lines_model)) {
1771  foreach ($formmail->lines_model as $modelmail) {
1772  //var_dump($modelmail);
1773  $moreonlabel = '';
1774  if (!empty($arrayofmessagename[$modelmail->label])) {
1775  $moreonlabel = ' <span class="opacitymedium">('.$langs->trans("SeveralLangugeVariatFound").')</span>';
1776  }
1777  // The 'label' is the key that is unique if we exclude the language
1778  $arrayofmessagename[$modelmail->label.':'.$tmp[1]] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->label)).$moreonlabel;
1779  }
1780  }
1781  //var_dump($arraydefaultmessage);
1782  //var_dump($arrayofmessagename);
1783  print $form->selectarray('constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')), $arrayofmessagename, $obj->value.':'.$tmp[1], 'None', 0, 0, '', 0, 0, 0, '', '', 1);
1784  } elseif (preg_match('/MAIL_FROM$/i', $const)) {
1785  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).'">';
1786  } else { // type = 'string' ou 'chaine'
1787  print '<input type="text" class="flat minwidth300" name="constvalue'.(empty($strictw3c) ? '' : ($strictw3c == 3 ? '_'.$const : '[]')).'" value="'.dol_escape_htmltag($obj->value).'">';
1788  }
1789  print '</td>';
1790  }
1791 
1792  // Submit
1793  if (empty($strictw3c)) {
1794  print '<td class="center">';
1795  print '<input type="submit" class="button small reposition" value="'.$langs->trans("Update").'" name="update">';
1796  print "</td>";
1797  }
1798 
1799  print "</tr>\n";
1800 
1801  if (empty($strictw3c)) {
1802  print "</form>\n";
1803  }
1804  }
1805  }
1806  print '</table>';
1807  print '</div>';
1808 
1809  if (!empty($strictw3c) && $strictw3c == 1) {
1810  print '<div align="center"><input type="submit" class="button small reposition" value="'.$langs->trans("Update").'" name="update"></div>';
1811  print "</form>\n";
1812  }
1813 }
1814 
1815 
1823 {
1824  global $conf, $langs;
1825 
1826  $text = $langs->trans("OnlyFollowingModulesAreOpenedToExternalUsers");
1827  $listofmodules = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
1828  $i = 0;
1829  if (!empty($modules)) {
1830  foreach ($modules as $module) {
1831  $moduleconst = $module->const_name;
1832  $modulename = strtolower($module->name);
1833  //print 'modulename='.$modulename;
1834 
1835  //if (empty($conf->global->$moduleconst)) continue;
1836  if (!in_array($modulename, $listofmodules)) {
1837  continue;
1838  }
1839  //var_dump($modulename.' - '.$langs->trans('Module'.$module->numero.'Name'));
1840 
1841  if ($i > 0) {
1842  $text .= ', ';
1843  } else {
1844  $text .= ' ';
1845  }
1846  $i++;
1847  $text .= $langs->trans('Module'.$module->numero.'Name');
1848  }
1849  }
1850  return $text;
1851 }
1852 
1853 
1863 function addDocumentModel($name, $type, $label = '', $description = '')
1864 {
1865  global $db, $conf;
1866 
1867  $db->begin();
1868 
1869  $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
1870  $sql .= " VALUES ('".$db->escape($name)."','".$db->escape($type)."',".((int) $conf->entity).", ";
1871  $sql .= ($label ? "'".$db->escape($label)."'" : 'null').", ";
1872  $sql .= (!empty($description) ? "'".$db->escape($description)."'" : "null");
1873  $sql .= ")";
1874 
1875  dol_syslog("admin.lib::addDocumentModel", LOG_DEBUG);
1876  $resql = $db->query($sql);
1877  if ($resql) {
1878  $db->commit();
1879  return 1;
1880  } else {
1881  dol_print_error($db);
1882  $db->rollback();
1883  return -1;
1884  }
1885 }
1886 
1894 function delDocumentModel($name, $type)
1895 {
1896  global $db, $conf;
1897 
1898  $db->begin();
1899 
1900  $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
1901  $sql .= " WHERE nom = '".$db->escape($name)."'";
1902  $sql .= " AND type = '".$db->escape($type)."'";
1903  $sql .= " AND entity = ".((int) $conf->entity);
1904 
1905  dol_syslog("admin.lib::delDocumentModel", LOG_DEBUG);
1906  $resql = $db->query($sql);
1907  if ($resql) {
1908  $db->commit();
1909  return 1;
1910  } else {
1911  dol_print_error($db);
1912  $db->rollback();
1913  return -1;
1914  }
1915 }
1916 
1917 
1923 function phpinfo_array()
1924 {
1925  ob_start();
1926  phpinfo();
1927  $phpinfostring = ob_get_contents();
1928  ob_end_clean();
1929 
1930  $info_arr = array();
1931  $info_lines = explode("\n", strip_tags($phpinfostring, "<tr><td><h2>"));
1932  $cat = "General";
1933  foreach ($info_lines as $line) {
1934  // new cat?
1935  $title = array();
1936  preg_match("~<h2>(.*)</h2>~", $line, $title) ? $cat = $title[1] : null;
1937  $val = array();
1938  if (preg_match("~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val)) {
1939  $info_arr[trim($cat)][trim($val[1])] = $val[2];
1940  } elseif (preg_match("~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val)) {
1941  $info_arr[trim($cat)][trim($val[1])] = array("local" => $val[2], "master" => $val[3]);
1942  }
1943  }
1944  return $info_arr;
1945 }
1946 
1953 {
1954  global $langs, $conf;
1955 
1956  $h = 0;
1957  $head = array();
1958 
1959  $head[$h][0] = DOL_URL_ROOT."/admin/company.php";
1960  $head[$h][1] = $langs->trans("Company");
1961  $head[$h][2] = 'company';
1962  $h++;
1963 
1964  $head[$h][0] = DOL_URL_ROOT."/admin/openinghours.php";
1965  $head[$h][1] = $langs->trans("OpeningHours");
1966  $head[$h][2] = 'openinghours';
1967  $h++;
1968 
1969  $head[$h][0] = DOL_URL_ROOT."/admin/accountant.php";
1970  $head[$h][1] = $langs->trans("Accountant");
1971  $head[$h][2] = 'accountant';
1972  $h++;
1973 
1974  $head[$h][0] = DOL_URL_ROOT."/admin/company_socialnetworks.php";
1975  $head[$h][1] = $langs->trans("SocialNetworksInformation");
1976  $head[$h][2] = 'socialnetworks';
1977  $h++;
1978 
1979  complete_head_from_modules($conf, $langs, null, $head, $h, 'mycompany_admin', 'add');
1980 
1981  complete_head_from_modules($conf, $langs, null, $head, $h, 'mycompany_admin', 'remove');
1982 
1983  return $head;
1984 }
1985 
1992 {
1993  global $langs, $conf, $user;
1994 
1995  $h = 0;
1996  $head = array();
1997 
1998  if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
1999  $head[$h][0] = DOL_URL_ROOT."/admin/mails.php";
2000  $head[$h][1] = $langs->trans("OutGoingEmailSetup");
2001  $head[$h][2] = 'common';
2002  $h++;
2003 
2004  if (isModEnabled('mailing')) {
2005  $head[$h][0] = DOL_URL_ROOT."/admin/mails_emailing.php";
2006  $head[$h][1] = $langs->trans("OutGoingEmailSetupForEmailing", $langs->transnoentitiesnoconv("EMailing"));
2007  $head[$h][2] = 'common_emailing';
2008  $h++;
2009  }
2010 
2011  if (isModEnabled('ticket')) {
2012  $head[$h][0] = DOL_URL_ROOT."/admin/mails_ticket.php";
2013  $head[$h][1] = $langs->trans("OutGoingEmailSetupForEmailing", $langs->transnoentitiesnoconv("Ticket"));
2014  $head[$h][2] = 'common_ticket';
2015  $h++;
2016  }
2017  }
2018 
2019  // admin and non admin can view this menu entry, but it is not shown yet when we on user menu "Email templates"
2020  if (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates') {
2021  $head[$h][0] = DOL_URL_ROOT."/admin/mails_senderprofile_list.php";
2022  $head[$h][1] = $langs->trans("EmailSenderProfiles");
2023  $head[$h][2] = 'senderprofiles';
2024  $h++;
2025  }
2026 
2027  $head[$h][0] = DOL_URL_ROOT."/admin/mails_templates.php";
2028  $head[$h][1] = $langs->trans("EMailTemplates");
2029  $head[$h][2] = 'templates';
2030  $h++;
2031 
2032  complete_head_from_modules($conf, $langs, null, $head, $h, 'email_admin', 'remove');
2033 
2034  return $head;
2035 }
dol_escape_htmltag
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.
Definition: functions.lib.php:1468
versioncompare
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Definition: admin.lib.php:66
security_prepare_head
security_prepare_head()
Prepare array with list of tabs.
Definition: admin.lib.php:772
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
dol_osencode
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
Definition: functions.lib.php:8499
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
complete_dictionary_with_modules
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:1281
phpinfo_array
phpinfo_array()
Return the php_info into an array.
Definition: admin.lib.php:1923
activateModulesRequiredByCountry
activateModulesRequiredByCountry($country_code)
Activate external modules mandatory when country is country_code.
Definition: admin.lib.php:1450
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
defaultvalues_prepare_head
defaultvalues_prepare_head()
Prepare array with list of tabs.
Definition: admin.lib.php:915
modules_prepare_head
modules_prepare_head($nbofactivatedmodules, $nboftotalmodules)
Prepare array with list of tabs.
Definition: admin.lib.php:687
activateModule
activateModule($value, $withdeps=1)
Enable a module.
Definition: admin.lib.php:1075
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
versionphparray
versionphparray()
Return version PHP.
Definition: admin.lib.php:128
delDocumentModel
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1894
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dolibarr_get_const
dolibarr_get_const($db, $name, $entity=1)
Get the value of a setup constant from database.
Definition: admin.lib.php:592
complete_elementList_with_modules
complete_elementList_with_modules(&$elementList)
Search external modules to complete the list of contact element.
Definition: admin.lib.php:1512
unActivateModule
unActivateModule($value, $requiredby=1)
Disable a module.
Definition: admin.lib.php:1204
img_down
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
Definition: functions.lib.php:4596
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
versiondolibarrarray
versiondolibarrarray()
Return version Dolibarr.
Definition: admin.lib.php:139
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
dolGetModulesDirs
dolGetModulesDirs($subdir='')
Return list of modules directories.
Definition: functions2.lib.php:80
listOfSessions
listOfSessions()
Return list of session.
Definition: admin.lib.php:967
dolibarr_set_const
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:627
purgeSessions
purgeSessions($mysessionid)
Purge existing sessions.
Definition: admin.lib.php:1023
email_admin_prepare_head
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:1991
addDocumentModel
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1863
modulehelp_prepare_head
modulehelp_prepare_head($object)
Prepare array with list of tabs.
Definition: admin.lib.php:847
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
form_constantes
form_constantes($tableau, $strictw3c=0, $helptext='', $text='Value')
Show array with constants to edit.
Definition: admin.lib.php:1619
run_sql
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
showModulesExludedForExternal
showModulesExludedForExternal($modules)
Show array with constants to edit.
Definition: admin.lib.php:1822
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
versiontostring
versiontostring($versionarray)
Renvoi une version en chaine depuis une version en tableau.
Definition: admin.lib.php:36
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30
translation_prepare_head
translation_prepare_head()
Prepare array with list of tabs.
Definition: admin.lib.php:885
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37
dol_htmlentities
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
Definition: functions.lib.php:7075
company_admin_prepare_head
company_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:1952
ihm_prepare_head
ihm_prepare_head()
Prepare array with list of tabs.
Definition: admin.lib.php:732