dolibarr  18.0.0-alpha
DolibarrModules.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
6  * Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
7  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
8  * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9  * Copyright (C) 2018 Josep Lluís Amador <joseplluis@lliuretic.cat>
10  * Copyright (C) 2019-2022 Frédéric France <frederic.france@netlogic.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
37 class DolibarrModules // Can not be abstract, because we need to instantiate it into unActivateModule to be able to disable a module whose files were removed.
38 {
42  public $db;
43 
48  public $numero;
49 
54  public $editor_name;
55 
60  public $editor_url;
61 
69  public $family;
70 
83  public $familyinfo;
84 
88  public $module_position = '50';
89 
98  public $name;
99 
105  public $dirs = array();
106 
110  public $boxes = array();
111 
115  public $const = array();
116 
120  public $cronjobs = array();
121 
125  public $rights;
126 
130  public $rights_class;
131 
135  public $menu = array();
136 
164  public $module_parts = array();
165 
170  public $docs;
171 
176  public $dbversion = "-";
177 
181  public $error;
182 
186  public $errors;
187 
198  public $version;
199 
204  public $lastVersion = '';
205 
210  public $needUpdate = false;
211 
217  public $description;
218 
225  public $descriptionlong;
226 
230  public $dictionaries;
231 
235  public $tabs;
236 
237  // For exports
238 
242  public $export_code;
243 
247  public $export_label;
248 
249  public $export_icon;
250 
251  public $export_permission;
252  public $export_fields_array;
253  public $export_TypeFields_array; // Array of key=>type where type can be 'Numeric', 'Date', 'Text', 'Boolean', 'Status', 'List:xxx:login:rowid'
254  public $export_entities_array;
255  public $export_help_array;
256  public $export_special_array; // special or computed field
257  public $export_dependencies_array;
258  public $export_sql_start;
259  public $export_sql_end;
260  public $export_sql_order;
261 
262 
263  // For import
264 
268  public $import_code;
269 
273  public $import_label;
274 
275  public $import_icon;
276 
277  public $import_entities_array;
278  public $import_tables_array;
279  public $import_fields_array;
280  public $import_fieldshidden_array;
281  public $import_convertvalue_array;
282  public $import_regex_array;
283  public $import_examplevalues_array;
284  public $import_updatekeys_array;
285 
286 
290  public $const_name;
291 
295  public $always_enabled;
296 
300  public $disabled;
301 
305  public $core_enabled;
306 
313  public $picto;
314 
321  public $config_page_url;
322 
323 
328  public $depends;
329 
334  public $requiredby;
335 
340  public $conflictwith;
341 
345  public $langfiles;
346 
352  public $warnings_activation;
353 
359  public $warnings_activation_ext;
360 
361 
366  public $phpmin;
367 
368  public $phpmax;
369 
374  public $need_dolibarr_version;
375 
376  public $enabled_bydefault;
377 
381  public $hidden = false;
382 
386  public $url_last_version;
387 
388 
394  public function __construct($db)
395  {
396  $this->db = $db;
397  }
398  // We should but can't set this as abstract because this will make dolibarr hang
399  // after migration due to old module not implementing. We must wait PHP is able to make
400  // a try catch on Fatal error to manage this correctly.
401  // We need constructor into function unActivateModule into admin.lib.php
402 
403 
404  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
415  protected function _init($array_sql, $options = '')
416  {
417  // phpcs:enable
418  global $conf;
419  $err = 0;
420 
421  $this->db->begin();
422 
423  // Insert activation module constant
424  if (!$err) {
425  $err += $this->_active();
426  }
427 
428  // Insert new pages for tabs (into llx_const)
429  if (!$err) {
430  $err += $this->insert_tabs();
431  }
432 
433  // Insert activation of module's parts
434  if (!$err) {
435  $err += $this->insert_module_parts();
436  }
437 
438  // Insert constant defined by modules (into llx_const)
439  if (!$err && !preg_match('/newboxdefonly/', $options)) {
440  $err += $this->insert_const(); // Test on newboxdefonly to avoid to erase value during upgrade
441  }
442 
443  // Insert boxes def (into llx_boxes_def) and boxes setup (into llx_boxes)
444  if (!$err && !preg_match('/noboxes/', $options)) {
445  $err += $this->insert_boxes($options);
446  }
447 
448  // Insert cron job entries (entry in llx_cronjobs)
449  if (!$err) {
450  $err += $this->insert_cronjobs();
451  }
452 
453  // Insert permission definitions of module into llx_rights_def. If user is admin, grant this permission to user.
454  if (!$err) {
455  $err += $this->insert_permissions(1, null, 1);
456  }
457 
458  // Insert specific menus entries into database
459  if (!$err) {
460  $err += $this->insert_menus();
461  }
462 
463  // Create module's directories
464  if (!$err) {
465  $err += $this->create_dirs();
466  }
467 
468  // Execute addons requests
469  $num = count($array_sql);
470  for ($i = 0; $i < $num; $i++) {
471  if (!$err) {
472  $val = $array_sql[$i];
473  $sql = $val;
474  $ignoreerror = 0;
475  if (is_array($val)) {
476  $sql = $val['sql'];
477  $ignoreerror = $val['ignoreerror'];
478  }
479  // Add current entity id
480  $sql = str_replace('__ENTITY__', $conf->entity, $sql);
481 
482  dol_syslog(get_class($this)."::_init ignoreerror=".$ignoreerror, LOG_DEBUG);
483  $result = $this->db->query($sql, $ignoreerror);
484  if (!$result) {
485  if (!$ignoreerror) {
486  $this->error = $this->db->lasterror();
487  $err++;
488  } else {
489  dol_syslog(get_class($this)."::_init Warning ".$this->db->lasterror(), LOG_WARNING);
490  }
491  }
492  }
493  }
494 
495  // Return code
496  if (!$err) {
497  $this->db->commit();
498  return 1;
499  } else {
500  $this->db->rollback();
501  return 0;
502  }
503  }
504 
505  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
514  protected function _remove($array_sql, $options = '')
515  {
516  // phpcs:enable
517  $err = 0;
518 
519  $this->db->begin();
520 
521  // Remove activation module line (constant MAIN_MODULE_MYMODULE in llx_const)
522  if (!$err) {
523  $err += $this->_unactive();
524  }
525 
526  // Remove activation of module's new tabs (MAIN_MODULE_MYMODULE_TABS_XXX in llx_const)
527  if (!$err) {
528  $err += $this->delete_tabs();
529  }
530 
531  // Remove activation of module's parts (MAIN_MODULE_MYMODULE_XXX in llx_const)
532  if (!$err) {
533  $err += $this->delete_module_parts();
534  }
535 
536  // Remove constants defined by modules
537  if (!$err) {
538  $err += $this->delete_const();
539  }
540 
541  // Remove list of module's available boxes (entry in llx_boxes)
542  if (!$err && !preg_match('/(newboxdefonly|noboxes)/', $options)) {
543  $err += $this->delete_boxes(); // We don't have to delete if option ask to keep boxes safe or ask to add new box def only
544  }
545 
546  // Remove list of module's cron job entries (entry in llx_cronjobs)
547  if (!$err) {
548  $err += $this->delete_cronjobs();
549  }
550 
551  // Remove module's permissions from list of available permissions (entries in llx_rights_def)
552  if (!$err) {
553  $err += $this->delete_permissions();
554  }
555 
556  // Remove module's menus (entries in llx_menu)
557  if (!$err) {
558  $err += $this->delete_menus();
559  }
560 
561  // Remove module's directories
562  if (!$err) {
563  $err += $this->delete_dirs();
564  }
565 
566  // Run complementary sql requests
567  $num = count($array_sql);
568  for ($i = 0; $i < $num; $i++) {
569  if (!$err) {
570  dol_syslog(get_class($this)."::_remove", LOG_DEBUG);
571  $result = $this->db->query($array_sql[$i]);
572  if (!$result) {
573  $this->error = $this->db->error();
574  $err++;
575  }
576  }
577  }
578 
579  // Return code
580  if (!$err) {
581  $this->db->commit();
582  return 1;
583  } else {
584  $this->db->rollback();
585  return 0;
586  }
587  }
588 
589 
596  public function getName()
597  {
598  global $langs;
599  $langs->load("admin");
600 
601  if ($langs->transnoentitiesnoconv("Module".$this->numero."Name") != ("Module".$this->numero."Name")) {
602  // If module name translation exists
603  return $langs->transnoentitiesnoconv("Module".$this->numero."Name");
604  } else {
605  // If module name translation using it's unique id does not exist, we try to use its name to find translation
606  if (is_array($this->langfiles)) {
607  foreach ($this->langfiles as $val) {
608  if ($val) {
609  $langs->load($val);
610  }
611  }
612  }
613 
614  if ($langs->trans("Module".$this->name."Name") != ("Module".$this->name."Name")) {
615  // If module name translation exists
616  return $langs->transnoentitiesnoconv("Module".$this->name."Name");
617  }
618 
619  // Last chance with simple label
620  return $langs->transnoentitiesnoconv($this->name);
621  }
622  }
623 
624 
630  public function getDesc()
631  {
632  global $langs;
633  $langs->load("admin");
634 
635  if ($langs->transnoentitiesnoconv("Module".$this->numero."Desc") != ("Module".$this->numero."Desc")) {
636  // If module description translation exists
637  return $langs->transnoentitiesnoconv("Module".$this->numero."Desc");
638  } else {
639  // If module description translation does not exist using its unique id, we can use its name to find translation
640  if (is_array($this->langfiles)) {
641  foreach ($this->langfiles as $val) {
642  if ($val) {
643  $langs->load($val);
644  }
645  }
646  }
647 
648  if ($langs->transnoentitiesnoconv("Module".$this->name."Desc") != ("Module".$this->name."Desc")) {
649  // If module name translation exists
650  return $langs->trans("Module".$this->name."Desc");
651  }
652 
653  // Last chance with simple label
654  return $langs->trans($this->description);
655  }
656  }
657 
664  public function getDescLong()
665  {
666  global $langs;
667  $langs->load("admin");
668 
669  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
670  include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
671 
672  $content='';
673  $pathoffile = $this->getDescLongReadmeFound();
674 
675  if ($pathoffile) { // Mostly for external modules
676  $content = file_get_contents($pathoffile);
677 
678  if ((float) DOL_VERSION >= 6.0) {
679  @include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
680 
681  $content = dolMd2Html(
682  $content,
683  'parsedown',
684  array(
685  'doc/' => dol_buildpath(strtolower($this->name).'/doc/', 1),
686  'img/' => dol_buildpath(strtolower($this->name).'/img/', 1),
687  'images/' => dol_buildpath(strtolower($this->name).'/images/', 1),
688  )
689  );
690  } else {
691  $content = nl2br($content);
692  }
693  } else {
694  // Mostly for internal modules
695  if (!empty($this->descriptionlong)) {
696  if (is_array($this->langfiles)) {
697  foreach ($this->langfiles as $val) {
698  if ($val) {
699  $langs->load($val);
700  }
701  }
702  }
703 
704  $content = $langs->transnoentitiesnoconv($this->descriptionlong);
705  }
706  }
707 
708  return $content;
709  }
710 
716  public function getDescLongReadmeFound()
717  {
718  global $langs;
719 
720  $filefound = false;
721 
722  // Define path to file README.md.
723  // First check README-la_LA.md then README-la.md then README.md
724  $pathoffile = dol_buildpath(strtolower($this->name).'/README-'.$langs->defaultlang.'.md', 0);
725  if (dol_is_file($pathoffile)) {
726  $filefound = true;
727  }
728  if (!$filefound) {
729  $tmp = explode('_', $langs->defaultlang);
730  $pathoffile = dol_buildpath(strtolower($this->name).'/README-'.$tmp[0].'.md', 0);
731  if (dol_is_file($pathoffile)) {
732  $filefound = true;
733  }
734  }
735  if (!$filefound) {
736  $pathoffile = dol_buildpath(strtolower($this->name).'/README.md', 0);
737  if (dol_is_file($pathoffile)) {
738  $filefound = true;
739  }
740  }
741 
742  return ($filefound ? $pathoffile : '');
743  }
744 
745 
751  public function getChangeLog()
752  {
753  global $langs;
754  $langs->load("admin");
755 
756  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
757  include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
758 
759  $filefound = false;
760 
761  // Define path to file README.md.
762  // First check ChangeLog-la_LA.md then ChangeLog.md
763  $pathoffile = dol_buildpath(strtolower($this->name).'/ChangeLog-'.$langs->defaultlang.'.md', 0);
764  if (dol_is_file($pathoffile)) {
765  $filefound = true;
766  }
767  if (!$filefound) {
768  $pathoffile = dol_buildpath(strtolower($this->name).'/ChangeLog.md', 0);
769  if (dol_is_file($pathoffile)) {
770  $filefound = true;
771  }
772  }
773 
774  if ($filefound) { // Mostly for external modules
775  $content = file_get_contents($pathoffile);
776 
777  if ((float) DOL_VERSION >= 6.0) {
778  @include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
779  $content = dolMd2Html($content, 'parsedown', array('doc/'=>dol_buildpath(strtolower($this->name).'/doc/', 1)));
780  } else {
781  $content = nl2br($content);
782  }
783  }
784 
785  return $content;
786  }
787 
793  public function getPublisher()
794  {
795  return $this->editor_name;
796  }
797 
803  public function getPublisherUrl()
804  {
805  return $this->editor_url;
806  }
807 
816  public function getVersion($translated = 1)
817  {
818  global $langs;
819  $langs->load("admin");
820 
821  $ret = '';
822 
823  $newversion = preg_replace('/_deprecated/', '', $this->version);
824  if ($newversion == 'experimental') {
825  $ret = ($translated ? $langs->transnoentitiesnoconv("VersionExperimental") : $newversion);
826  } elseif ($newversion == 'development') {
827  $ret = ($translated ? $langs->transnoentitiesnoconv("VersionDevelopment") : $newversion);
828  } elseif ($newversion == 'dolibarr') {
829  $ret = DOL_VERSION;
830  } elseif ($newversion) {
831  $ret = $newversion;
832  } else {
833  $ret = ($translated ? $langs->transnoentitiesnoconv("VersionUnknown") : 'unknown');
834  }
835 
836  if (preg_match('/_deprecated/', $this->version)) {
837  $ret .= ($translated ? ' ('.$langs->transnoentitiesnoconv("Deprecated").')' : $this->version);
838  }
839  return $ret;
840  }
841 
847  public function getModulePosition()
848  {
849  if (in_array($this->version, array('dolibarr', 'experimental', 'development'))) { // core module
850  return $this->module_position;
851  } else { // external module
852  if ($this->module_position >= 100000) {
853  return $this->module_position;
854  } else {
855  return $this->module_position + 100000;
856  }
857  }
858  }
859 
867  public function isCoreOrExternalModule()
868  {
869  if ($this->version == 'dolibarr' || $this->version == 'dolibarr_deprecated') {
870  return 'core';
871  }
872  if (!empty($this->version) && !in_array($this->version, array('experimental', 'development'))) {
873  return 'external';
874  }
875  if (!empty($this->editor_name) || !empty($this->editor_url)) {
876  return 'external';
877  }
878  if ($this->numero >= 100000) {
879  return 'external';
880  }
881  return 'unknown';
882  }
883 
884 
890  public function getLangFilesArray()
891  {
892  return $this->langfiles;
893  }
894 
902  public function getExportDatasetLabel($r)
903  {
904  global $langs;
905 
906  $langstring = "ExportDataset_".$this->export_code[$r];
907  if ($langs->trans($langstring) == $langstring) {
908  // Translation not found
909  return $langs->trans($this->export_label[$r]);
910  } else {
911  // Translation found
912  return $langs->trans($langstring);
913  }
914  }
915 
916 
924  public function getImportDatasetLabel($r)
925  {
926  global $langs;
927 
928  $langstring = "ImportDataset_".$this->import_code[$r];
929  //print "x".$langstring;
930  if ($langs->trans($langstring) == $langstring) {
931  // Translation not found
932  return $langs->transnoentitiesnoconv($this->import_label[$r]);
933  } else {
934  // Translation found
935  return $langs->transnoentitiesnoconv($langstring);
936  }
937  }
938 
939 
945  public function getLastActivationDate()
946  {
947  global $conf;
948 
949  $err = 0;
950 
951  $sql = "SELECT tms FROM ".MAIN_DB_PREFIX."const";
952  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
953  $sql .= " AND entity IN (0, ".$conf->entity.")";
954 
955  dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG);
956  $resql = $this->db->query($sql);
957  if (!$resql) {
958  $err++;
959  } else {
960  $obj = $this->db->fetch_object($resql);
961  if ($obj) {
962  return $this->db->jdate($obj->tms);
963  }
964  }
965 
966  return '';
967  }
968 
969 
975  public function getLastActivationInfo()
976  {
977  global $conf;
978 
979  $err = 0;
980 
981  $sql = "SELECT tms, note FROM ".MAIN_DB_PREFIX."const";
982  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
983  $sql .= " AND entity IN (0, ".$conf->entity.")";
984 
985  dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG);
986  $resql = $this->db->query($sql);
987  if (!$resql) {
988  $err++;
989  } else {
990  $obj = $this->db->fetch_object($resql);
991  if ($obj) {
992  $tmp = array();
993  if ($obj->note) {
994  $tmp = json_decode($obj->note, true);
995  }
996  return array(
997  'authorid' => empty($tmp['authorid']) ? '' : $tmp['authorid'],
998  'ip' => empty($tmp['ip']) ? '' : $tmp['ip'],
999  'lastactivationdate' => $this->db->jdate($obj->tms),
1000  'lastactivationversion' => (!empty($tmp['lastactivationversion']) ? $tmp['lastactivationversion'] : 'unknown'),
1001  );
1002  }
1003  }
1004 
1005  return array();
1006  }
1007 
1008 
1009  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1015  protected function _active()
1016  {
1017  // phpcs:enable
1018  global $conf, $user;
1019 
1020  $err = 0;
1021 
1022  // Common module
1023  $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity);
1024 
1025  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1026  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
1027  $sql .= " AND entity IN (0, ".$entity.")";
1028 
1029  dol_syslog(get_class($this)."::_active delete activation constant", LOG_DEBUG);
1030  $resql = $this->db->query($sql);
1031  if (!$resql) {
1032  $err++;
1033  }
1034 
1035  $note = json_encode(
1036  array(
1037  'authorid' => (is_object($user) ? $user->id : 0),
1038  'ip' => (empty($_SERVER['REMOTE_ADDR']) ? '' : $_SERVER['REMOTE_ADDR']),
1039  'lastactivationversion' => $this->version,
1040  )
1041  );
1042 
1043  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name, value, visible, entity, note) VALUES";
1044  $sql .= " (".$this->db->encrypt($this->const_name);
1045  $sql .= ", ".$this->db->encrypt('1');
1046  $sql .= ", 0, ".((int) $entity);
1047  $sql .= ", '".$this->db->escape($note)."')";
1048 
1049  dol_syslog(get_class($this)."::_active insert activation constant", LOG_DEBUG);
1050  $resql = $this->db->query($sql);
1051  if (!$resql) {
1052  $err++;
1053  }
1054 
1055  return $err;
1056  }
1057 
1058 
1059  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1065  protected function _unactive()
1066  {
1067  // phpcs:enable
1068  global $conf;
1069 
1070  $err = 0;
1071 
1072  // Common module
1073  $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity);
1074 
1075  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1076  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
1077  $sql .= " AND entity IN (0, ".$entity.")";
1078 
1079  dol_syslog(get_class($this)."::_unactive", LOG_DEBUG);
1080  $this->db->query($sql);
1081 
1082  return $err;
1083  }
1084 
1085 
1086  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps,PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1102  protected function _load_tables($reldir, $onlywithsuffix = '')
1103  {
1104  // phpcs:enable
1105  global $conf;
1106 
1107  $error = 0;
1108  $dirfound = 0;
1109 
1110  if (empty($reldir)) {
1111  return 1;
1112  }
1113 
1114  include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
1115 
1116  $ok = 1;
1117  foreach ($conf->file->dol_document_root as $dirroot) {
1118  if ($ok) {
1119  $dirsql = $dirroot.$reldir;
1120  $ok = 0;
1121 
1122  // We will loop on xxx/, xxx/tables/, xxx/data/
1123  $listofsubdir = array('', 'tables/', 'data/');
1124  if ($this->db->type == 'pgsql') {
1125  $listofsubdir[] = '../pgsql/functions/';
1126  }
1127 
1128  foreach ($listofsubdir as $subdir) {
1129  $dir = $dirsql.$subdir;
1130 
1131  $handle = @opendir($dir); // Dir may not exists
1132  if (is_resource($handle)) {
1133  $dirfound++;
1134 
1135  // Run llx_mytable.sql files, then llx_mytable_*.sql
1136  $files = array();
1137  while (($file = readdir($handle)) !== false) {
1138  $files[] = $file;
1139  }
1140  sort($files);
1141  foreach ($files as $file) {
1142  if ($onlywithsuffix) {
1143  if (!preg_match('/\-'.preg_quote($onlywithsuffix, '/').'\./i', $file)) {
1144  //print 'File '.$file.' does not match suffix '.$onlywithsuffix.' so it is discarded<br>'."\n";
1145  continue;
1146  } else {
1147  //print 'File '.$file.' match suffix '.$onlywithsuffix.' so we keep it<br>'."\n";
1148  }
1149  }
1150  if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && substr($file, 0, 4) == 'llx_') {
1151  $result = run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG) ? 1 : 0, '', 1);
1152  if ($result <= 0) {
1153  $error++;
1154  }
1155  }
1156  }
1157 
1158  rewinddir($handle);
1159 
1160  // Run llx_mytable.key.sql files (Must be done after llx_mytable.sql) then then llx_mytable_*.key.sql
1161  $files = array();
1162  while (($file = readdir($handle)) !== false) {
1163  $files[] = $file;
1164  }
1165  sort($files);
1166  foreach ($files as $file) {
1167  if ($onlywithsuffix) {
1168  if (!preg_match('/\-'.preg_quote($onlywithsuffix, '/').'\./i', $file)) {
1169  //print 'File '.$file.' does not match suffix '.$onlywithsuffix.' so it is discarded<br>'."\n";
1170  continue;
1171  } else {
1172  //print 'File '.$file.' match suffix '.$onlywithsuffix.' so we keep it<br>'."\n";
1173  }
1174  }
1175  if (preg_match('/\.key\.sql$/i', $file) && substr($file, 0, 4) == 'llx_') {
1176  $result = run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG) ? 1 : 0, '', 1);
1177  if ($result <= 0) {
1178  $error++;
1179  }
1180  }
1181  }
1182 
1183  rewinddir($handle);
1184 
1185  // Run functions-xxx.sql files (Must be done after llx_mytable.key.sql)
1186  $files = array();
1187  while (($file = readdir($handle)) !== false) {
1188  $files[] = $file;
1189  }
1190  sort($files);
1191  foreach ($files as $file) {
1192  if ($onlywithsuffix) {
1193  if (!preg_match('/\-'.preg_quote($onlywithsuffix, '/').'\./i', $file)) {
1194  //print 'File '.$file.' does not match suffix '.$onlywithsuffix.' so it is discarded<br>'."\n";
1195  continue;
1196  } else {
1197  //print 'File '.$file.' match suffix '.$onlywithsuffix.' so we keep it<br>'."\n";
1198  }
1199  }
1200  if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && substr($file, 0, 9) == 'functions') {
1201  $result = run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG) ? 1 : 0, '', 1);
1202  if ($result <= 0) {
1203  $error++;
1204  }
1205  }
1206  }
1207 
1208  rewinddir($handle);
1209 
1210  // Run data_xxx.sql files (Must be done after llx_mytable.key.sql)
1211  $files = array();
1212  while (($file = readdir($handle)) !== false) {
1213  $files[] = $file;
1214  }
1215  sort($files);
1216  foreach ($files as $file) {
1217  if ($onlywithsuffix) {
1218  if (!preg_match('/\-'.preg_quote($onlywithsuffix, '/').'\./i', $file)) {
1219  //print 'File '.$file.' does not match suffix '.$onlywithsuffix.' so it is discarded<br>'."\n";
1220  continue;
1221  } else {
1222  //print 'File '.$file.' match suffix '.$onlywithsuffix.' so we keep it<br>'."\n";
1223  }
1224  }
1225  if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && substr($file, 0, 4) == 'data') {
1226  $result = run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG) ? 1 : 0, '', 1);
1227  if ($result <= 0) {
1228  $error++;
1229  }
1230  }
1231  }
1232 
1233  rewinddir($handle);
1234 
1235  // Run update_xxx.sql files
1236  $files = array();
1237  while (($file = readdir($handle)) !== false) {
1238  $files[] = $file;
1239  }
1240  sort($files);
1241  foreach ($files as $file) {
1242  if ($onlywithsuffix) {
1243  if (!preg_match('/\-'.preg_quote($onlywithsuffix, '/').'\./i', $file)) {
1244  //print 'File '.$file.' does not match suffix '.$onlywithsuffix.' so it is discarded<br>'."\n";
1245  continue;
1246  } else {
1247  //print 'File '.$file.' match suffix '.$onlywithsuffix.' so we keep it<br>'."\n";
1248  }
1249  }
1250  if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && substr($file, 0, 6) == 'update') {
1251  $result = run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG) ? 1 : 0, '', 1);
1252  if ($result <= 0) {
1253  $error++;
1254  }
1255  }
1256  }
1257 
1258  closedir($handle);
1259  }
1260  }
1261 
1262  if ($error == 0) {
1263  $ok = 1;
1264  }
1265  }
1266  }
1267 
1268  if (!$dirfound) {
1269  dol_syslog("A module ask to load sql files into ".$reldir." but this directory was not found.", LOG_WARNING);
1270  }
1271  return $ok;
1272  }
1273 
1274 
1275  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1283  public function insert_boxes($option = '')
1284  {
1285  // phpcs:enable
1286  include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1287 
1288  global $conf;
1289 
1290  $err = 0;
1291 
1292  if (is_array($this->boxes)) {
1293  dol_syslog(get_class($this)."::insert_boxes", LOG_DEBUG);
1294 
1295  $pos_name = InfoBox::getListOfPagesForBoxes();
1296 
1297  foreach ($this->boxes as $key => $value) {
1298  $file = isset($this->boxes[$key]['file']) ? $this->boxes[$key]['file'] : '';
1299  $note = isset($this->boxes[$key]['note']) ? $this->boxes[$key]['note'] : '';
1300  $enabledbydefaulton = isset($this->boxes[$key]['enabledbydefaulton']) ? $this->boxes[$key]['enabledbydefaulton'] : 'Home';
1301 
1302  if (empty($file)) {
1303  $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] : ''; // For backward compatibility
1304  }
1305  if (empty($note)) {
1306  $note = isset($this->boxes[$key][2]) ? $this->boxes[$key][2] : ''; // For backward compatibility
1307  }
1308 
1309  // Search if boxes def already present
1310  $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."boxes_def";
1311  $sql .= " WHERE file = '".$this->db->escape($file)."'";
1312  $sql .= " AND entity = ".$conf->entity;
1313  if ($note) {
1314  $sql .= " AND note ='".$this->db->escape($note)."'";
1315  }
1316 
1317  $result = $this->db->query($sql);
1318  if ($result) {
1319  $obj = $this->db->fetch_object($result);
1320  if ($obj->nb == 0) {
1321  $this->db->begin();
1322 
1323  if (!$err) {
1324  $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes_def (file, entity, note)";
1325  $sql .= " VALUES ('".$this->db->escape($file)."', ";
1326  $sql .= $conf->entity.", ";
1327  $sql .= $note ? "'".$this->db->escape($note)."'" : "null";
1328  $sql .= ")";
1329 
1330  dol_syslog(get_class($this)."::insert_boxes", LOG_DEBUG);
1331  $resql = $this->db->query($sql);
1332  if (!$resql) {
1333  $err++;
1334  }
1335  }
1336  if (!$err && !preg_match('/newboxdefonly/', $option)) {
1337  $lastid = $this->db->last_insert_id(MAIN_DB_PREFIX."boxes_def", "rowid");
1338 
1339  foreach ($pos_name as $key2 => $val2) {
1340  //print 'key2='.$key2.'-val2='.$val2."<br>\n";
1341  if ($enabledbydefaulton && $val2 != $enabledbydefaulton) {
1342  continue; // Not enabled by default onto this page.
1343  }
1344 
1345  $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes (box_id, position, box_order, fk_user, entity)";
1346  $sql .= " VALUES (".((int) $lastid).", ".((int) $key2).", '0', 0, ".((int) $conf->entity).")";
1347 
1348  dol_syslog(get_class($this)."::insert_boxes onto page ".$key2."=".$val2, LOG_DEBUG);
1349  $resql = $this->db->query($sql);
1350  if (!$resql) {
1351  $err++;
1352  }
1353  }
1354  }
1355 
1356  if (!$err) {
1357  $this->db->commit();
1358  } else {
1359  $this->error = $this->db->lasterror();
1360  $this->db->rollback();
1361  }
1362  }
1363  // else box already registered into database
1364  } else {
1365  $this->error = $this->db->lasterror();
1366  $err++;
1367  }
1368  }
1369  }
1370 
1371  return $err;
1372  }
1373 
1374 
1375  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1381  public function delete_boxes()
1382  {
1383  // phpcs:enable
1384  global $conf;
1385 
1386  $err = 0;
1387 
1388  if (is_array($this->boxes)) {
1389  foreach ($this->boxes as $key => $value) {
1390  //$titre = $this->boxes[$key][0];
1391  if (empty($this->boxes[$key]['file'])) {
1392  $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] : ''; // For backward compatibility
1393  } else {
1394  $file = $this->boxes[$key]['file'];
1395  }
1396 
1397  //$note = $this->boxes[$key][2];
1398 
1399  // TODO If the box is also included by another module and the other module is still on, we should not remove it.
1400  // For the moment, we manage this with hard coded exception
1401  //print "Remove box ".$file.'<br>';
1402  if ($file == 'box_graph_product_distribution.php') {
1403  if (isModEnabled("product") || isModEnabled("service")) {
1404  dol_syslog("We discard deleting module ".$file." because another module still active requires it.");
1405  continue;
1406  }
1407  }
1408 
1409  if ($this->db->type == 'sqlite3') {
1410  // sqlite doesn't support "USING" syntax.
1411  // TODO: remove this dependency.
1412  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes ";
1413  $sql .= "WHERE ".MAIN_DB_PREFIX."boxes.box_id IN (";
1414  $sql .= "SELECT ".MAIN_DB_PREFIX."boxes_def.rowid ";
1415  $sql .= "FROM ".MAIN_DB_PREFIX."boxes_def ";
1416  $sql .= "WHERE ".MAIN_DB_PREFIX."boxes_def.file = '".$this->db->escape($file)."') ";
1417  $sql .= "AND ".MAIN_DB_PREFIX."boxes.entity = ".$conf->entity;
1418  } else {
1419  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes";
1420  $sql .= " USING ".MAIN_DB_PREFIX."boxes, ".MAIN_DB_PREFIX."boxes_def";
1421  $sql .= " WHERE ".MAIN_DB_PREFIX."boxes.box_id = ".MAIN_DB_PREFIX."boxes_def.rowid";
1422  $sql .= " AND ".MAIN_DB_PREFIX."boxes_def.file = '".$this->db->escape($file)."'";
1423  $sql .= " AND ".MAIN_DB_PREFIX."boxes.entity = ".$conf->entity;
1424  }
1425 
1426  dol_syslog(get_class($this)."::delete_boxes", LOG_DEBUG);
1427  $resql = $this->db->query($sql);
1428  if (!$resql) {
1429  $this->error = $this->db->lasterror();
1430  $err++;
1431  }
1432 
1433  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes_def";
1434  $sql .= " WHERE file = '".$this->db->escape($file)."'";
1435  $sql .= " AND entity = ".$conf->entity; // Do not use getEntity here, we want to delete only in current company
1436 
1437  dol_syslog(get_class($this)."::delete_boxes", LOG_DEBUG);
1438  $resql = $this->db->query($sql);
1439  if (!$resql) {
1440  $this->error = $this->db->lasterror();
1441  $err++;
1442  }
1443  }
1444  }
1445 
1446  return $err;
1447  }
1448 
1449  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1455  public function insert_cronjobs()
1456  {
1457  // phpcs:enable
1458  include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1459 
1460  global $conf;
1461 
1462  $err = 0;
1463 
1464  if (is_array($this->cronjobs)) {
1465  dol_syslog(get_class($this)."::insert_cronjobs", LOG_DEBUG);
1466 
1467  foreach ($this->cronjobs as $key => $value) {
1468  $entity = isset($this->cronjobs[$key]['entity']) ? $this->cronjobs[$key]['entity'] : $conf->entity;
1469  $label = isset($this->cronjobs[$key]['label']) ? $this->cronjobs[$key]['label'] : '';
1470  $jobtype = isset($this->cronjobs[$key]['jobtype']) ? $this->cronjobs[$key]['jobtype'] : '';
1471  $class = isset($this->cronjobs[$key]['class']) ? $this->cronjobs[$key]['class'] : '';
1472  $objectname = isset($this->cronjobs[$key]['objectname']) ? $this->cronjobs[$key]['objectname'] : '';
1473  $method = isset($this->cronjobs[$key]['method']) ? $this->cronjobs[$key]['method'] : '';
1474  $command = isset($this->cronjobs[$key]['command']) ? $this->cronjobs[$key]['command'] : '';
1475  $parameters = isset($this->cronjobs[$key]['parameters']) ? $this->cronjobs[$key]['parameters'] : '';
1476  $comment = isset($this->cronjobs[$key]['comment']) ? $this->cronjobs[$key]['comment'] : '';
1477  $frequency = isset($this->cronjobs[$key]['frequency']) ? $this->cronjobs[$key]['frequency'] : '';
1478  $unitfrequency = isset($this->cronjobs[$key]['unitfrequency']) ? $this->cronjobs[$key]['unitfrequency'] : '';
1479  $priority = isset($this->cronjobs[$key]['priority']) ? $this->cronjobs[$key]['priority'] : '';
1480  $datestart = isset($this->cronjobs[$key]['datestart']) ? $this->cronjobs[$key]['datestart'] : '';
1481  $dateend = isset($this->cronjobs[$key]['dateend']) ? $this->cronjobs[$key]['dateend'] : '';
1482  $status = isset($this->cronjobs[$key]['status']) ? $this->cronjobs[$key]['status'] : '';
1483  $test = isset($this->cronjobs[$key]['test']) ? $this->cronjobs[$key]['test'] : ''; // Line must be enabled or not (so visible or not)
1484 
1485  // Search if cron entry already present
1486  $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob";
1487  //$sql .= " WHERE module_name = '".$this->db->escape(empty($this->rights_class) ?strtolower($this->name) : $this->rights_class)."'";
1488  $sql .= " WHERE label = '".$this->db->escape($label)."'";
1489  /*if ($class) {
1490  $sql .= " AND classesname = '".$this->db->escape($class)."'";
1491  }
1492  if ($objectname) {
1493  $sql .= " AND objectname = '".$this->db->escape($objectname)."'";
1494  }
1495  if ($method) {
1496  $sql .= " AND methodename = '".$this->db->escape($method)."'";
1497  }
1498  if ($command) {
1499  $sql .= " AND command = '".$this->db->escape($command)."'";
1500  }
1501  if ($parameters) {
1502  $sql .= " AND params = '".$this->db->escape($parameters)."'";
1503  }*/
1504  $sql .= " AND entity = ".((int) $entity); // Must be exact entity
1505 
1506  $now = dol_now();
1507 
1508  $result = $this->db->query($sql);
1509  if ($result) {
1510  $obj = $this->db->fetch_object($result);
1511  if ($obj->nb == 0) {
1512  $this->db->begin();
1513 
1514  if (!$err) {
1515  $sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, datestart, dateend, label, jobtype, classesname, objectname, methodename, command, params, note,";
1516  if (is_int($frequency)) {
1517  $sql .= ' frequency,';
1518  }
1519  if (is_int($unitfrequency)) {
1520  $sql .= ' unitfrequency,';
1521  }
1522  if (is_int($priority)) {
1523  $sql .= ' priority,';
1524  }
1525  if (is_int($status)) {
1526  $sql .= ' status,';
1527  }
1528  $sql .= " entity, test)";
1529  $sql .= " VALUES (";
1530  $sql .= "'".$this->db->escape(empty($this->rights_class) ?strtolower($this->name) : $this->rights_class)."', ";
1531  $sql .= "'".$this->db->idate($now)."', ";
1532  $sql .= ($datestart ? "'".$this->db->idate($datestart)."'" : "'".$this->db->idate($now)."'").", ";
1533  $sql .= ($dateend ? "'".$this->db->idate($dateend)."'" : "NULL").", ";
1534  $sql .= "'".$this->db->escape($label)."', ";
1535  $sql .= "'".$this->db->escape($jobtype)."', ";
1536  $sql .= ($class ? "'".$this->db->escape($class)."'" : "null").",";
1537  $sql .= ($objectname ? "'".$this->db->escape($objectname)."'" : "null").",";
1538  $sql .= ($method ? "'".$this->db->escape($method)."'" : "null").",";
1539  $sql .= ($command ? "'".$this->db->escape($command)."'" : "null").",";
1540  $sql .= ($parameters ? "'".$this->db->escape($parameters)."'" : "null").",";
1541  $sql .= ($comment ? "'".$this->db->escape($comment)."'" : "null").",";
1542  if (is_int($frequency)) {
1543  $sql .= "'".$this->db->escape($frequency)."', ";
1544  }
1545  if (is_int($unitfrequency)) {
1546  $sql .= "'".$this->db->escape($unitfrequency)."', ";
1547  }
1548  if (is_int($priority)) {
1549  $sql .= "'".$this->db->escape($priority)."', ";
1550  }
1551  if (is_int($status)) {
1552  $sql .= ((int) $status).", ";
1553  }
1554  $sql .= $entity.",";
1555  $sql .= "'".$this->db->escape($test)."'";
1556  $sql .= ")";
1557 
1558  $resql = $this->db->query($sql);
1559  if (!$resql) {
1560  $err++;
1561  }
1562  }
1563 
1564  if (!$err) {
1565  $this->db->commit();
1566  } else {
1567  $this->error = $this->db->lasterror();
1568  $this->db->rollback();
1569  }
1570  }
1571  // else box already registered into database
1572  } else {
1573  $this->error = $this->db->lasterror();
1574  $err++;
1575  }
1576  }
1577  }
1578 
1579  return $err;
1580  }
1581 
1582 
1583  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1589  public function delete_cronjobs()
1590  {
1591  // phpcs:enable
1592  global $conf;
1593 
1594  $err = 0;
1595 
1596  if (is_array($this->cronjobs)) {
1597  $sql = "DELETE FROM ".MAIN_DB_PREFIX."cronjob";
1598  $sql .= " WHERE module_name = '".$this->db->escape(empty($this->rights_class) ?strtolower($this->name) : $this->rights_class)."'";
1599  $sql .= " AND entity = ".$conf->entity;
1600  $sql .= " AND test = '1'"; // We delete on lines that are not set with a complete test that is '$conf->module->enabled' so when module is disabled, the cron is also removed.
1601  // For crons declared with a '$conf->module->enabled', there is no need to delete the line, so we don't loose setup if we reenable module.
1602 
1603  dol_syslog(get_class($this)."::delete_cronjobs", LOG_DEBUG);
1604  $resql = $this->db->query($sql);
1605  if (!$resql) {
1606  $this->error = $this->db->lasterror();
1607  $err++;
1608  }
1609  }
1610 
1611  return $err;
1612  }
1613 
1614  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1620  public function delete_tabs()
1621  {
1622  // phpcs:enable
1623  global $conf;
1624 
1625  $err = 0;
1626 
1627  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1628  $sql .= " WHERE ".$this->db->decrypt('name')." like '".$this->db->escape($this->const_name)."_TABS_%'";
1629  $sql .= " AND entity = ".$conf->entity;
1630 
1631  dol_syslog(get_class($this)."::delete_tabs", LOG_DEBUG);
1632  if (!$this->db->query($sql)) {
1633  $this->error = $this->db->lasterror();
1634  $err++;
1635  }
1636 
1637  return $err;
1638  }
1639 
1640  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1646  public function insert_tabs()
1647  {
1648  // phpcs:enable
1649  global $conf;
1650 
1651  $err = 0;
1652 
1653  if (!empty($this->tabs)) {
1654  dol_syslog(get_class($this)."::insert_tabs", LOG_DEBUG);
1655 
1656  $i = 0;
1657  foreach ($this->tabs as $key => $value) {
1658  if (is_array($value) && count($value) == 0) {
1659  continue; // Discard empty arrays
1660  }
1661 
1662  $entity = $conf->entity;
1663  $newvalue = $value;
1664 
1665  if (is_array($value)) {
1666  $newvalue = $value['data'];
1667  if (isset($value['entity'])) {
1668  $entity = $value['entity'];
1669  }
1670  }
1671 
1672  if ($newvalue) {
1673  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (";
1674  $sql .= "name";
1675  $sql .= ", type";
1676  $sql .= ", value";
1677  $sql .= ", note";
1678  $sql .= ", visible";
1679  $sql .= ", entity";
1680  $sql .= ")";
1681  $sql .= " VALUES (";
1682  $sql .= $this->db->encrypt($this->const_name."_TABS_".$i);
1683  $sql .= ", 'chaine'";
1684  $sql .= ", ".$this->db->encrypt($newvalue);
1685  $sql .= ", null";
1686  $sql .= ", '0'";
1687  $sql .= ", ".((int) $entity);
1688  $sql .= ")";
1689 
1690  $resql = $this->db->query($sql);
1691  if (!$resql) {
1692  dol_syslog($this->db->lasterror(), LOG_ERR);
1693  if ($this->db->lasterrno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1694  $this->error = $this->db->lasterror();
1695  $this->errors[] = $this->db->lasterror();
1696  $err++;
1697  break;
1698  }
1699  }
1700  }
1701  $i++;
1702  }
1703  }
1704  return $err;
1705  }
1706 
1707  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1713  public function insert_const()
1714  {
1715  // phpcs:enable
1716  global $conf;
1717 
1718  $err = 0;
1719 
1720  if (empty($this->const)) {
1721  return 0;
1722  }
1723 
1724  dol_syslog(get_class($this)."::insert_const", LOG_DEBUG);
1725 
1726  foreach ($this->const as $key => $value) {
1727  $name = $this->const[$key][0];
1728  $type = $this->const[$key][1];
1729  $val = $this->const[$key][2];
1730  $note = isset($this->const[$key][3]) ? $this->const[$key][3] : '';
1731  $visible = isset($this->const[$key][4]) ? $this->const[$key][4] : 0;
1732  $entity = (!empty($this->const[$key][5]) && $this->const[$key][5] != 'current') ? 0 : $conf->entity;
1733 
1734  // Clean
1735  if (empty($visible)) {
1736  $visible = '0';
1737  }
1738  if (empty($val) && $val != '0') {
1739  $val = '';
1740  }
1741 
1742  $sql = "SELECT count(*)";
1743  $sql .= " FROM ".MAIN_DB_PREFIX."const";
1744  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'";
1745  $sql .= " AND entity = ".((int) $entity);
1746 
1747  $result = $this->db->query($sql);
1748  if ($result) {
1749  $row = $this->db->fetch_row($result);
1750 
1751  if ($row[0] == 0) { // If not found
1752  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)";
1753  $sql .= " VALUES (";
1754  $sql .= $this->db->encrypt($name);
1755  $sql .= ",'".$this->db->escape($type)."'";
1756  $sql .= ",".(($val != '') ? $this->db->encrypt($val) : "''");
1757  $sql .= ",".($note ? "'".$this->db->escape($note)."'" : "null");
1758  $sql .= ",'".$this->db->escape($visible)."'";
1759  $sql .= ",".$entity;
1760  $sql .= ")";
1761 
1762  if (!$this->db->query($sql)) {
1763  $err++;
1764  }
1765  } else {
1766  dol_syslog(get_class($this)."::insert_const constant '".$name."' already exists", LOG_WARNING);
1767  }
1768  } else {
1769  $err++;
1770  }
1771  }
1772 
1773  return $err;
1774  }
1775 
1776  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1782  public function delete_const()
1783  {
1784  // phpcs:enable
1785  global $conf;
1786 
1787  $err = 0;
1788 
1789  if (empty($this->const)) {
1790  return 0;
1791  }
1792 
1793  foreach ($this->const as $key => $value) {
1794  $name = $this->const[$key][0];
1795  $deleteonunactive = (!empty($this->const[$key][6])) ? 1 : 0;
1796 
1797  if ($deleteonunactive) {
1798  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1799  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'";
1800  $sql .= " AND entity in (0, ".$conf->entity.")";
1801  dol_syslog(get_class($this)."::delete_const", LOG_DEBUG);
1802  if (!$this->db->query($sql)) {
1803  $this->error = $this->db->lasterror();
1804  $err++;
1805  }
1806  }
1807  }
1808 
1809  return $err;
1810  }
1811 
1812  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1821  public function insert_permissions($reinitadminperms = 0, $force_entity = null, $notrigger = 0)
1822  {
1823  // phpcs:enable
1824  global $conf, $user;
1825 
1826  $err = 0;
1827  $entity = (!empty($force_entity) ? $force_entity : $conf->entity);
1828 
1829  dol_syslog(get_class($this)."::insert_permissions", LOG_DEBUG);
1830 
1831  // Test if module is activated
1832  $sql_del = "SELECT ".$this->db->decrypt('value')." as value";
1833  $sql_del .= " FROM ".MAIN_DB_PREFIX."const";
1834  $sql_del .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
1835  $sql_del .= " AND entity IN (0,".$entity.")";
1836 
1837  $resql = $this->db->query($sql_del);
1838 
1839  if ($resql) {
1840  $obj = $this->db->fetch_object($resql);
1841 
1842  if ($obj !== null && !empty($obj->value) && !empty($this->rights)) {
1843  include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1844 
1845  // If the module is active
1846  foreach ($this->rights as $key => $value) {
1847  $r_id = $this->rights[$key][0]; // permission id in llx_rights_def (not unique because primary key is couple id-entity)
1848  $r_desc = $this->rights[$key][1];
1849  $r_type = isset($this->rights[$key][2]) ? $this->rights[$key][2] : '';
1850  $r_def = empty($this->rights[$key][3]) ? 0 : $this->rights[$key][3];
1851  $r_perms = $this->rights[$key][4];
1852  $r_subperms = isset($this->rights[$key][5]) ? $this->rights[$key][5] : '';
1853  $r_modul = empty($this->rights_class) ? strtolower($this->name) : $this->rights_class;
1854 
1855  if (empty($r_type)) {
1856  $r_type = 'w';
1857  }
1858 
1859  // Search if perm already present
1860  $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."rights_def";
1861  $sql .= " WHERE id = ".((int) $r_id)." AND entity = ".((int) $entity);
1862 
1863  $resqlselect = $this->db->query($sql);
1864  if ($resqlselect) {
1865  $objcount = $this->db->fetch_object($resqlselect);
1866  if ($objcount && $objcount->nb == 0) {
1867  if (dol_strlen($r_perms)) {
1868  if (dol_strlen($r_subperms)) {
1869  $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
1870  $sql .= " (id, entity, libelle, module, type, bydefault, perms, subperms)";
1871  $sql .= " VALUES ";
1872  $sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$this->db->escape($r_modul)."','".$this->db->escape($r_type)."',".$r_def.",'".$this->db->escape($r_perms)."','".$this->db->escape($r_subperms)."')";
1873  } else {
1874  $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
1875  $sql .= " (id, entity, libelle, module, type, bydefault, perms)";
1876  $sql .= " VALUES ";
1877  $sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$this->db->escape($r_modul)."','".$this->db->escape($r_type)."',".$r_def.",'".$this->db->escape($r_perms)."')";
1878  }
1879  } else {
1880  $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def ";
1881  $sql .= " (id, entity, libelle, module, type, bydefault)";
1882  $sql .= " VALUES ";
1883  $sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$this->db->escape($r_modul)."','".$this->db->escape($r_type)."',".$r_def.")";
1884  }
1885 
1886  $resqlinsert = $this->db->query($sql, 1);
1887 
1888  if (!$resqlinsert) {
1889  if ($this->db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS") {
1890  $this->error = $this->db->lasterror();
1891  $err++;
1892  break;
1893  } else {
1894  dol_syslog(get_class($this)."::insert_permissions record already exists", LOG_INFO);
1895  }
1896  }
1897 
1898  $this->db->free($resqlinsert);
1899  }
1900 
1901  $this->db->free($resqlselect);
1902  }
1903 
1904  // If we want to init permissions on admin users
1905  if ($reinitadminperms) {
1906  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."user WHERE admin = 1";
1907  dol_syslog(get_class($this)."::insert_permissions Search all admin users", LOG_DEBUG);
1908 
1909  $resqlseladmin = $this->db->query($sql, 1);
1910 
1911  if ($resqlseladmin) {
1912  $num = $this->db->num_rows($resqlseladmin);
1913  $i = 0;
1914  while ($i < $num) {
1915  $obj2 = $this->db->fetch_object($resqlseladmin);
1916  dol_syslog(get_class($this)."::insert_permissions Add permission id ".$r_id." to user id=".$obj2->rowid);
1917 
1918  $tmpuser = new User($this->db);
1919  $result = $tmpuser->fetch($obj2->rowid);
1920  if ($result > 0) {
1921  $tmpuser->addrights($r_id, '', '', 0, 1);
1922  } else {
1923  dol_syslog(get_class($this)."::insert_permissions Failed to add the permission to user because fetch return an error", LOG_ERR);
1924  }
1925  $i++;
1926  }
1927  } else {
1928  dol_print_error($this->db);
1929  }
1930  }
1931  }
1932 
1933  if ($reinitadminperms && !empty($user->admin)) { // Reload permission for current user if defined
1934  // We reload permissions
1935  $user->clearrights();
1936  $user->getrights();
1937  }
1938  }
1939  $this->db->free($resql);
1940  } else {
1941  $this->error = $this->db->lasterror();
1942  $err++;
1943  }
1944 
1945  return $err;
1946  }
1947 
1948 
1949  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1955  public function delete_permissions()
1956  {
1957  // phpcs:enable
1958  global $conf;
1959 
1960  $err = 0;
1961 
1962  $sql = "DELETE FROM ".MAIN_DB_PREFIX."rights_def";
1963  $sql .= " WHERE module = '".$this->db->escape(empty($this->rights_class) ?strtolower($this->name) : $this->rights_class)."'";
1964  $sql .= " AND entity = ".$conf->entity;
1965  dol_syslog(get_class($this)."::delete_permissions", LOG_DEBUG);
1966  if (!$this->db->query($sql)) {
1967  $this->error = $this->db->lasterror();
1968  $err++;
1969  }
1970 
1971  return $err;
1972  }
1973 
1974 
1975  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1981  public function insert_menus()
1982  {
1983  // phpcs:enable
1984  global $user;
1985 
1986  if (!is_array($this->menu) || empty($this->menu)) {
1987  return 0;
1988  }
1989 
1990  include_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
1991 
1992  dol_syslog(get_class($this)."::insert_menus", LOG_DEBUG);
1993 
1994  $err = 0;
1995 
1996  $this->db->begin();
1997 
1998  foreach ($this->menu as $key => $value) {
1999  $menu = new Menubase($this->db);
2000  $menu->menu_handler = 'all';
2001 
2002  //$menu->module=strtolower($this->name); TODO When right_class will be same than module name
2003  $menu->module = (empty($this->rights_class) ? strtolower($this->name) : $this->rights_class);
2004 
2005  if (!$this->menu[$key]['fk_menu']) {
2006  $menu->fk_menu = 0;
2007  } else {
2008  $foundparent = 0;
2009  $fk_parent = $this->menu[$key]['fk_menu'];
2010  $reg = array();
2011  if (preg_match('/^r=/', $fk_parent)) { // old deprecated method
2012  $fk_parent = str_replace('r=', '', $fk_parent);
2013  if (isset($this->menu[$fk_parent]['rowid'])) {
2014  $menu->fk_menu = $this->menu[$fk_parent]['rowid'];
2015  $foundparent = 1;
2016  }
2017  } elseif (preg_match('/^fk_mainmenu=([a-zA-Z0-9_]+),fk_leftmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
2018  $menu->fk_menu = -1;
2019  $menu->fk_mainmenu = $reg[1];
2020  $menu->fk_leftmenu = $reg[2];
2021  $foundparent = 1;
2022  } elseif (preg_match('/^fk_mainmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
2023  $menu->fk_menu = -1;
2024  $menu->fk_mainmenu = $reg[1];
2025  $menu->fk_leftmenu = '';
2026  $foundparent = 1;
2027  }
2028  if (!$foundparent) {
2029  $this->error = "ErrorBadDefinitionOfMenuArrayInModuleDescriptor";
2030  dol_syslog(get_class($this)."::insert_menus ".$this->error." ".$this->menu[$key]['fk_menu'], LOG_ERR);
2031  $err++;
2032  }
2033  }
2034  $menu->type = $this->menu[$key]['type'];
2035  $menu->mainmenu = isset($this->menu[$key]['mainmenu']) ? $this->menu[$key]['mainmenu'] : (isset($menu->fk_mainmenu) ? $menu->fk_mainmenu : '');
2036  $menu->leftmenu = isset($this->menu[$key]['leftmenu']) ? $this->menu[$key]['leftmenu'] : '';
2037  $menu->title = $this->menu[$key]['titre'];
2038  $menu->prefix = isset($this->menu[$key]['prefix']) ? $this->menu[$key]['prefix'] : '';
2039  $menu->url = $this->menu[$key]['url'];
2040  $menu->langs = isset($this->menu[$key]['langs']) ? $this->menu[$key]['langs'] : '';
2041  $menu->position = $this->menu[$key]['position'];
2042  $menu->perms = $this->menu[$key]['perms'];
2043  $menu->target = isset($this->menu[$key]['target']) ? $this->menu[$key]['target'] : '';
2044  $menu->user = $this->menu[$key]['user'];
2045  $menu->enabled = isset($this->menu[$key]['enabled']) ? $this->menu[$key]['enabled'] : 0;
2046  $menu->position = $this->menu[$key]['position'];
2047 
2048  if (!$err) {
2049  $result = $menu->create($user); // Save menu entry into table llx_menu
2050  if ($result > 0) {
2051  $this->menu[$key]['rowid'] = $result;
2052  } else {
2053  $this->error = $menu->error;
2054  dol_syslog(get_class($this).'::insert_menus result='.$result." ".$this->error, LOG_ERR);
2055  $err++;
2056  break;
2057  }
2058  }
2059  }
2060 
2061  if (!$err) {
2062  $this->db->commit();
2063  } else {
2064  dol_syslog(get_class($this)."::insert_menus ".$this->error, LOG_ERR);
2065  $this->db->rollback();
2066  }
2067 
2068  return $err;
2069  }
2070 
2071 
2072  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2078  public function delete_menus()
2079  {
2080  // phpcs:enable
2081  global $conf;
2082 
2083  $err = 0;
2084 
2085  //$module=strtolower($this->name); TODO When right_class will be same than module name
2086  $module = empty($this->rights_class) ?strtolower($this->name) : $this->rights_class;
2087 
2088  $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
2089  $sql .= " WHERE module = '".$this->db->escape($module)."'";
2090  $sql .= " AND entity = ".$conf->entity;
2091 
2092  dol_syslog(get_class($this)."::delete_menus", LOG_DEBUG);
2093  $resql = $this->db->query($sql);
2094  if (!$resql) {
2095  $this->error = $this->db->lasterror();
2096  $err++;
2097  }
2098 
2099  return $err;
2100  }
2101 
2102  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2108  public function create_dirs()
2109  {
2110  // phpcs:enable
2111  global $langs, $conf;
2112 
2113  $err = 0;
2114 
2115  if (isset($this->dirs) && is_array($this->dirs)) {
2116  foreach ($this->dirs as $key => $value) {
2117  $addtodatabase = 0;
2118 
2119  if (!is_array($value)) {
2120  $dir = $value; // Default simple mode
2121  } else {
2122  $constname = $this->const_name."_DIR_";
2123  $dir = $this->dirs[$key][1];
2124  $addtodatabase = empty($this->dirs[$key][2]) ? '' : $this->dirs[$key][2]; // Create constante in llx_const
2125  $subname = empty($this->dirs[$key][3]) ? '' : strtoupper($this->dirs[$key][3]); // Add submodule name (ex: $conf->module->submodule->dir_output)
2126  $forcename = empty($this->dirs[$key][4]) ? '' : strtoupper($this->dirs[$key][4]); // Change the module name if different
2127 
2128  if (!empty($forcename)) {
2129  $constname = 'MAIN_MODULE_'.$forcename."_DIR_";
2130  }
2131  if (!empty($subname)) {
2132  $constname = $constname.$subname."_";
2133  }
2134 
2135  $name = $constname.strtoupper($this->dirs[$key][0]);
2136  }
2137 
2138  // Define directory full path ($dir must start with "/")
2139  if (empty($conf->global->MAIN_MODULE_MULTICOMPANY) || $conf->entity == 1) {
2140  $fulldir = DOL_DATA_ROOT.$dir;
2141  } else {
2142  $fulldir = DOL_DATA_ROOT."/".$conf->entity.$dir;
2143  }
2144  // Create dir if it does not exists
2145  if (!empty($fulldir) && !file_exists($fulldir)) {
2146  if (dol_mkdir($fulldir, DOL_DATA_ROOT) < 0) {
2147  $this->error = $langs->trans("ErrorCanNotCreateDir", $fulldir);
2148  dol_syslog(get_class($this)."::_init ".$this->error, LOG_ERR);
2149  $err++;
2150  }
2151  }
2152 
2153  // Define the constant in database if requested (not the default mode)
2154  if (!empty($addtodatabase)) {
2155  $result = $this->insert_dirs($name, $dir);
2156  if ($result) {
2157  $err++;
2158  }
2159  }
2160  }
2161  }
2162 
2163  return $err;
2164  }
2165 
2166 
2167  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2176  public function insert_dirs($name, $dir)
2177  {
2178  // phpcs:enable
2179  global $conf;
2180 
2181  $err = 0;
2182 
2183  $sql = "SELECT count(*)";
2184  $sql .= " FROM ".MAIN_DB_PREFIX."const";
2185  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'";
2186  $sql .= " AND entity = ".$conf->entity;
2187 
2188  dol_syslog(get_class($this)."::insert_dirs", LOG_DEBUG);
2189  $result = $this->db->query($sql);
2190  if ($result) {
2191  $row = $this->db->fetch_row($result);
2192 
2193  if ($row[0] == 0) {
2194  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name, type, value, note, visible, entity)";
2195  $sql .= " VALUES (".$this->db->encrypt($name).", 'chaine', ".$this->db->encrypt($dir).", '".$this->db->escape("Directory for module ".$this->name)."', '0', ".((int) $conf->entity).")";
2196 
2197  dol_syslog(get_class($this)."::insert_dirs", LOG_DEBUG);
2198  $this->db->query($sql);
2199  }
2200  } else {
2201  $this->error = $this->db->lasterror();
2202  $err++;
2203  }
2204 
2205  return $err;
2206  }
2207 
2208 
2209  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2215  public function delete_dirs()
2216  {
2217  // phpcs:enable
2218  global $conf;
2219 
2220  $err = 0;
2221 
2222  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
2223  $sql .= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->db->escape($this->const_name)."_DIR_%'";
2224  $sql .= " AND entity = ".$conf->entity;
2225 
2226  dol_syslog(get_class($this)."::delete_dirs", LOG_DEBUG);
2227  if (!$this->db->query($sql)) {
2228  $this->error = $this->db->lasterror();
2229  $err++;
2230  }
2231 
2232  return $err;
2233  }
2234 
2235  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2241  public function insert_module_parts()
2242  {
2243  // phpcs:enable
2244  global $conf;
2245 
2246  $error = 0;
2247 
2248  if (is_array($this->module_parts) && !empty($this->module_parts)) {
2249  foreach ($this->module_parts as $key => $value) {
2250  if (is_array($value) && count($value) == 0) {
2251  continue; // Discard empty arrays
2252  }
2253 
2254  $entity = $conf->entity; // Reset the current entity
2255  $newvalue = $value;
2256 
2257  // Serialize array parameters
2258  if (is_array($value)) {
2259  // Can defined other parameters
2260  // Example when $key='hooks', then $value is an array('data'=>array('hookcontext1','hookcontext2'), 'entity'=>X)
2261  if (isset($value['data']) && is_array($value['data'])) {
2262  $newvalue = json_encode($value['data']);
2263  if (isset($value['entity'])) {
2264  $entity = $value['entity'];
2265  }
2266  } elseif (isset($value['data']) && !is_array($value['data'])) {
2267  $newvalue = $value['data'];
2268  if (isset($value['entity'])) {
2269  $entity = $value['entity'];
2270  }
2271  } else { // when hook is declared with syntax 'hook'=>array('hookcontext1','hookcontext2',...)
2272  $newvalue = json_encode($value);
2273  }
2274  }
2275 
2276  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (";
2277  $sql .= "name";
2278  $sql .= ", type";
2279  $sql .= ", value";
2280  $sql .= ", note";
2281  $sql .= ", visible";
2282  $sql .= ", entity";
2283  $sql .= ")";
2284  $sql .= " VALUES (";
2285  $sql .= " ".$this->db->encrypt($this->const_name."_".strtoupper($key));
2286  $sql .= ", 'chaine'";
2287  $sql .= ", ".$this->db->encrypt($newvalue);
2288  $sql .= ", null";
2289  $sql .= ", '0'";
2290  $sql .= ", ".((int) $entity);
2291  $sql .= ")";
2292 
2293  dol_syslog(get_class($this)."::insert_module_parts for key=".$this->const_name."_".strtoupper($key), LOG_DEBUG);
2294 
2295  $resql = $this->db->query($sql, 1);
2296  if (!$resql) {
2297  if ($this->db->lasterrno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') {
2298  $error++;
2299  $this->error = $this->db->lasterror();
2300  } else {
2301  dol_syslog(get_class($this)."::insert_module_parts for ".$this->const_name."_".strtoupper($key)." Record already exists.", LOG_WARNING);
2302  }
2303  }
2304  }
2305  }
2306  return $error;
2307  }
2308 
2309  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2315  public function delete_module_parts()
2316  {
2317  // phpcs:enable
2318  global $conf;
2319 
2320  $err = 0;
2321  $entity = $conf->entity;
2322 
2323  if (is_array($this->module_parts) && !empty($this->module_parts)) {
2324  dol_syslog(get_class($this)."::delete_module_parts", LOG_DEBUG);
2325 
2326  foreach ($this->module_parts as $key => $value) {
2327  // If entity is defined
2328  if (is_array($value) && isset($value['entity'])) {
2329  $entity = $value['entity'];
2330  }
2331 
2332  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
2333  $sql .= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->db->escape($this->const_name)."_".strtoupper($key)."'";
2334  $sql .= " AND entity = ".((int) $entity);
2335 
2336  if (!$this->db->query($sql)) {
2337  $this->error = $this->db->lasterror();
2338  $err++;
2339  }
2340  }
2341  }
2342  return $err;
2343  }
2344 
2354  public function init($options = '')
2355  {
2356  return $this->_init(array(), $options);
2357  }
2358 
2367  public function remove($options = '')
2368  {
2369  return $this->_remove(array(), $options);
2370  }
2371 
2372 
2380  public function getKanbanView($codeenabledisable = '', $codetoconfig = '')
2381  {
2382  global $conf, $langs;
2383 
2384  // Define imginfo
2385  $imginfo = "info";
2386  if ($this->isCoreOrExternalModule() == 'external') {
2387  $imginfo = "info_black";
2388  }
2389 
2390  $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($this)));
2391 
2392  $version = $this->getVersion(0);
2393  $versiontrans = '';
2394  if (preg_match('/development/i', $version)) {
2395  $versiontrans .= 'warning';
2396  }
2397  if (preg_match('/experimental/i', $version)) {
2398  $versiontrans .= 'warning';
2399  }
2400  if (preg_match('/deprecated/i', $version)) {
2401  $versiontrans .= 'warning';
2402  }
2403 
2404  print '
2405  <div class="box-flex-item info-box-module'
2406  .(empty($conf->global->$const_name) ? ' --disabled' : '')
2407  .($this->isCoreOrExternalModule() == 'external' ? ' --external' : '')
2408  .($this->needUpdate ? ' --need-update' : '')
2409  .'">
2410  <div class="info-box info-box-sm info-box-module">
2411  <div class="info-box-icon'.(empty($conf->global->$const_name) ? '' : ' info-box-icon-module-enabled'.($versiontrans ? ' info-box-icon-module-warning' : '')).'">';
2412 
2413  $alttext = '';
2414  //if (is_array($objMod->need_dolibarr_version)) $alttext.=($alttext?' - ':'').'Dolibarr >= '.join('.',$objMod->need_dolibarr_version);
2415  //if (is_array($objMod->phpmin)) $alttext.=($alttext?' - ':'').'PHP >= '.join('.',$objMod->phpmin);
2416  if (!empty($this->picto)) {
2417  if (preg_match('/^\//i', $this->picto)) {
2418  print img_picto($alttext, $this->picto, 'class="inline-block valignmiddle"', 1);
2419  } else {
2420  print img_object($alttext, $this->picto, 'class="inline-block valignmiddle"');
2421  }
2422  } else {
2423  print img_object($alttext, 'generic', 'class="inline-block valignmiddle"');
2424  }
2425 
2426  if ($this->isCoreOrExternalModule() == 'external' || preg_match('/development|experimental|deprecated/i', $version)) {
2427  $versionTitle = $langs->trans("Version").' '.$this->getVersion(1);
2428  if ($this->needUpdate) {
2429  $versionTitle.= '<br>'.$langs->trans('ModuleUpdateAvailable').' : '.$this->lastVersion;
2430  }
2431 
2432  print '<span class="info-box-icon-version'.($versiontrans ? ' '.$versiontrans : '').' classfortooltip" title="'.dol_escape_js($versionTitle).'" >';
2433  print $this->getVersion(1);
2434  print '</span>';
2435  }
2436 
2437  print '</div>
2438  <div class="info-box-content info-box-text-module'.(empty($conf->global->$const_name) ? '' : ' info-box-module-enabled'.($versiontrans ? ' info-box-content-warning' : '')).'">
2439  <span class="info-box-title">'.$this->getName().'</span>
2440  <span class="info-box-desc twolinesmax opacitymedium" title="'.dol_escape_htmltag($this->getDesc()).'">'.nl2br($this->getDesc()).'</span>';
2441 
2442  print '<div class="valignmiddle inline-block info-box-more">';
2443  //if ($versiontrans) print img_warning($langs->trans("Version").' '.$this->getVersion(1)).' ';
2444  print '<a class="valignmiddle inline-block" href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.$this->numero.'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto(($this->isCoreOrExternalModule() == 'external' ? $langs->trans("ExternalModule").' - ' : '').$langs->trans("ClickToShowDescription"), $imginfo).'</a>';
2445  print '</div><br>';
2446 
2447  print '<div class="valignmiddle inline-block info-box-actions">';
2448  print '<div class="valignmiddle inline-block info-box-setup">';
2449  print $codetoconfig;
2450  print '</div>';
2451  print '<div class="valignmiddle inline-block marginleftonly marginrightonly">';
2452  print $codeenabledisable;
2453  print '</div>';
2454  print '</div>';
2455 
2456  print '
2457  </div><!-- /.info-box-content -->
2458  </div><!-- /.info-box -->
2459  </div>';
2460  }
2461 
2469  public function checkForUpdate()
2470  {
2471  require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
2472  if (!empty($this->url_last_version)) {
2473  $lastVersion = getURLContent($this->url_last_version, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only
2474  if (isset($lastVersion['content']) && strlen($lastVersion['content']) < 30) {
2475  // Security warning : be careful with remote data content, the module editor could be hacked (or evil) so limit to a-z A-Z 0-9 _ . -
2476  $this->lastVersion = preg_replace("/[^a-zA-Z0-9_\.\-]+/", "", $lastVersion['content']);
2477  if (version_compare($this->lastVersion, $this->version) > 0) {
2478  $this->needUpdate = true;
2479  return 1;
2480  } else {
2481  $this->needUpdate = false;
2482  return 0;
2483  }
2484  } else {
2485  return -1;
2486  }
2487  }
2488  return 0;
2489  }
2490 }
DolibarrModules\_unactive
_unactive()
Module deactivation.
Definition: DolibarrModules.class.php:1065
DolibarrModules\__construct
__construct($db)
Constructor.
Definition: DolibarrModules.class.php:394
db
$conf db
API class for accounts.
Definition: inc.php:41
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:1504
DolibarrModules\insert_module_parts
insert_module_parts()
Adds generic parts.
Definition: DolibarrModules.class.php:2241
DolibarrModules\create_dirs
create_dirs()
Creates directories.
Definition: DolibarrModules.class.php:2108
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
$sql
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)) $sql
Social contributions to pay.
Definition: index.php:745
DolibarrModules\insert_tabs
insert_tabs()
Adds tabs.
Definition: DolibarrModules.class.php:1646
DolibarrModules\getModulePosition
getModulePosition()
Gives the module position.
Definition: DolibarrModules.class.php:847
DolibarrModules\getKanbanView
getKanbanView($codeenabledisable='', $codetoconfig='')
Return Kanban view of a module.
Definition: DolibarrModules.class.php:2380
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:4994
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1072
DolibarrModules\getName
getName()
Gives the translated module name if translation exists in admin.lang or into language files of module...
Definition: DolibarrModules.class.php:596
DolibarrModules\_load_tables
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Definition: DolibarrModules.class.php:1102
DolibarrModules\delete_dirs
delete_dirs()
Removes directories.
Definition: DolibarrModules.class.php:2215
DolibarrModules\getExportDatasetLabel
getExportDatasetLabel($r)
Gives translated label of an export dataset.
Definition: DolibarrModules.class.php:902
DolibarrModules\delete_permissions
delete_permissions()
Removes access rights.
Definition: DolibarrModules.class.php:1955
DolibarrModules\isCoreOrExternalModule
isCoreOrExternalModule()
Tells if module is core or external.
Definition: DolibarrModules.class.php:867
Menubase
Class to manage menu entries.
Definition: menubase.class.php:30
name
$conf db name
Definition: repair.php:122
DolibarrModules\insert_permissions
insert_permissions($reinitadminperms=0, $force_entity=null, $notrigger=0)
Adds access rights.
Definition: DolibarrModules.class.php:1821
DolibarrModules\insert_boxes
insert_boxes($option='')
Adds boxes.
Definition: DolibarrModules.class.php:1283
DolibarrModules\_remove
_remove($array_sql, $options='')
Disable function.
Definition: DolibarrModules.class.php:514
DolibarrModules\insert_cronjobs
insert_cronjobs()
Adds cronjobs.
Definition: DolibarrModules.class.php:1455
dol_is_file
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:481
DolibarrModules\getPublisher
getPublisher()
Gives the publisher name.
Definition: DolibarrModules.class.php:793
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:4025
DolibarrModules\getImportDatasetLabel
getImportDatasetLabel($r)
Gives translated label of an import dataset.
Definition: DolibarrModules.class.php:924
DolibarrModules\getVersion
getVersion($translated=1)
Gives module version (translated if param $translated is on) For 'experimental' modules,...
Definition: DolibarrModules.class.php:816
dol_escape_js
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
Definition: functions.lib.php:1455
DolibarrModules\delete_const
delete_const()
Removes constants tagged 'deleteonunactive'.
Definition: DolibarrModules.class.php:1782
DolibarrModules\delete_tabs
delete_tabs()
Removes tabs.
Definition: DolibarrModules.class.php:1620
DolibarrModules\getDescLongReadmeFound
getDescLongReadmeFound()
Return path of file if a README file was found.
Definition: DolibarrModules.class.php:716
DolibarrModules\insert_const
insert_const()
Adds constants.
Definition: DolibarrModules.class.php:1713
DolibarrModules\insert_dirs
insert_dirs($name, $dir)
Adds directories definitions.
Definition: DolibarrModules.class.php:2176
DolibarrModules\getChangeLog
getChangeLog()
Gives the changelog.
Definition: DolibarrModules.class.php:751
DolibarrModules\getLastActivationDate
getLastActivationDate()
Gives the last date of activation.
Definition: DolibarrModules.class.php:945
DolibarrModules\getDescLong
getDescLong()
Gives the long description of a module.
Definition: DolibarrModules.class.php:664
DolibarrModules\_active
_active()
Insert constants for module activation.
Definition: DolibarrModules.class.php:1015
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1639
dolMd2Html
dolMd2Html($content, $parser='parsedown', $replaceimagepath=null)
Function to parse MD content into HTML.
Definition: parsemd.lib.php:32
DolibarrModules\delete_menus
delete_menus()
Removes menu entries.
Definition: DolibarrModules.class.php:2078
DolibarrModules\delete_boxes
delete_boxes()
Removes boxes.
Definition: DolibarrModules.class.php:1381
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:415
DolibarrModules\getDesc
getDesc()
Gives the translated module description if translation exists in admin.lang or the default module des...
Definition: DolibarrModules.class.php:630
DolibarrModules\getPublisherUrl
getPublisherUrl()
Gives the publisher url.
Definition: DolibarrModules.class.php:803
DolibarrModules\delete_module_parts
delete_module_parts()
Removes generic parts.
Definition: DolibarrModules.class.php:2315
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3888
DolibarrModules\$needUpdate
$needUpdate
true indicate this module need update
Definition: DolibarrModules.class.php:210
DolibarrModules\getLangFilesArray
getLangFilesArray()
Gives module related language files list.
Definition: DolibarrModules.class.php:890
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:147
User
Class to manage Dolibarr users.
Definition: user.class.php:44
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4361
DolibarrModules\$lastVersion
$lastVersion
Module last version.
Definition: DolibarrModules.class.php:204
DolibarrModules\delete_cronjobs
delete_cronjobs()
Removes boxes.
Definition: DolibarrModules.class.php:1589
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:168
DolibarrModules\insert_menus
insert_menus()
Adds menu entries.
Definition: DolibarrModules.class.php:1981
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2947
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6811
InfoBox\getListOfPagesForBoxes
static getListOfPagesForBoxes()
Name of positions (See below)
Definition: infobox.class.php:36
DolibarrModules\init
init($options='')
Function called when module is enabled.
Definition: DolibarrModules.class.php:2354
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37
DolibarrModules\getLastActivationInfo
getLastActivationInfo()
Gives the last author of activation.
Definition: DolibarrModules.class.php:975
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25