dolibarr 25.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-2024 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) 2024 Lenin Rivas <lenin.rivas777@gmail.com>
11 * Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
39class DolibarrModules // Can not be abstract, because we need to instantiate it into unActivateModule to be able to disable a module whose files were removed.
40{
44 public $db;
45
50 public $numero;
51
55 public $id;
56
60 public $editor_name;
61
65 public $editor_url;
66
70 public $editor_squarred_logo;
71
79 public $family;
80
93 public $familyinfo;
94
98 public $module_position = '50';
99
108 public $name;
109
115 public $dirs = array();
116
120 public $boxes = array();
121
126 public $const = array();
127
131 public $overwrite_translation = array();
132
136 public $cronjobs = array();
137
141 public $rights;
142
146 public $rights_admin_allowed;
147
151 public $rights_class;
152
153 const URL_FOR_BLACKLISTED_MODULES = 'https://www.dolibarr.org/modules-blacklist.php';
154
155 const KEY_ID = 0;
156 const KEY_LABEL = 1;
157 const KEY_TYPE = 2; // deprecated
158 const KEY_DEFAULT = 3;
159 const KEY_FIRST_LEVEL = 4;
160 const KEY_SECOND_LEVEL = 5;
161 const KEY_MODULE = 6;
162 const KEY_ENABLED = 7;
163
167 public $menu = array();
168
196 public $module_parts = array();
197
201 public $error;
202
206 public $errors;
207
218 public $version;
219
223 public $version_if_core = 0;
224
229 public $lastVersion = '';
230
235 public $needUpdate = false;
236
242 public $description;
243
250 public $descriptionlong;
251
255 public $dictionaries = array();
256
260 public $tabs;
261
262 // For exports
263
267 public $export_code;
268
272 public $export_label;
273
277 public $export_icon;
278
282 public $export_enabled;
286 public $export_permission;
290 public $export_fields_array;
294 public $export_TypeFields_array; // Array of key=>type where type can be 'Numeric', 'Date', 'Text', 'Boolean', 'Status', 'List:xxx:fieldlabel:rowid'
298 public $export_entities_array;
302 public $export_aggregate_array;
306 public $export_examplevalues_array;
310 public $export_help_array;
317 public $export_special_array; // special or computed field
324 public $export_dependencies_array;
328 public $export_sql_start;
332 public $export_sql_end;
336 public $export_sql_order;
337
338
339 // For import
340
344 public $import_code;
345
349 public $import_label;
350
354 public $import_icon;
358 public $import_entities_array;
362 public $import_tables_array;
366 public $import_tables_creator_array;
370 public $import_fields_array;
374 public $import_fieldshidden_array;
378 public $import_convertvalue_array;
382 public $import_regex_array;
386 public $import_examplevalues_array;
390 public $import_updatekeys_array;
394 public $import_preselected_updatekeys_array;
398 public $import_run_sql_after_array;
402 public $import_TypeFields_array;
406 public $import_help_array;
407
411 public $const_name;
412
416 public $always_enabled;
417
421 public $disabled;
422
426 public $automatic_activation = array();
427
431 public $core_enabled;
432
439 public $picto;
440
447 public $config_page_url;
448
449
458 public $depends;
459
464 public $requiredby;
465
470 public $conflictwith;
471
475 public $langfiles;
476
482 public $warnings_activation;
483
489 public $warnings_activation_ext;
490
496 public $warnings_unactivation;
497
502 public $phpmin;
503
507 public $phpmax;
508
513 public $need_dolibarr_version;
514
519 public $max_dolibarr_version;
520
524 public $need_javascript_ajax;
525
529 public $enabled_bydefault;
530
534 public $hidden = false;
535
539 public $url_last_version;
540
541
547 public function __construct($db)
548 {
549 $this->db = $db;
550 }
551 // We should but can't set this as abstract because this will make dolibarr hang
552 // after migration due to old module not implementing. We must wait PHP is able to make
553 // a try catch on Fatal error to manage this correctly.
554 // We need constructor into function unActivateModule into admin.lib.php
555
556
557 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
568 protected function _init($array_sql, $options = '')
569 {
570 // phpcs:enable
571 global $conf;
572 $err = 0;
573
574 $this->db->begin();
575
576 // Insert activation module constant
577 if (!$err) {
578 $err += $this->_active();
579 }
580
581 // Insert new pages for tabs (into llx_const)
582 if (!$err) {
583 $err += $this->insert_tabs();
584 }
585
586 // Insert activation of module's parts. Copy website templates into doctemplates.
587 if (!$err) {
588 $err += $this->insert_module_parts();
589 }
590
591 // Insert constant defined by modules (into llx_const) if no existing yet
592 if (!$err && !preg_match('/newboxdefonly/', $options)) {
593 $err += $this->insert_const(); // Test on newboxdefonly to avoid to erase value during upgrade
594 }
595
596 // Insert overwrite trans defined by modules (into llx_overwrite_trans)
597 if (!$err && !preg_match('/newboxdefonly/', $options)) {
598 $err += $this->insert_overwrite_translation(); // Test on newboxdefonly to avoid to erase value during upgrade
599 }
600
601 // Insert boxes def (into llx_boxes_def) and boxes setup (into llx_boxes)
602 if (!$err && !preg_match('/noboxes/', $options)) {
603 $err += $this->insert_boxes($options);
604 }
605
606 // Insert cron job entries (entry in llx_cronjobs)
607 if (!$err) {
608 $err += $this->insert_cronjobs();
609 }
610
611 // Insert permission definitions of module into llx_rights_def. If user is admin, grant this permission to user.
612 if (!$err) {
613 $err += $this->insert_permissions(1, null, 1);
614 }
615
616 // Insert specific menus entries into database
617 if (!$err) {
618 $err += $this->insert_menus();
619 }
620
621 // Create module's directories
622 if (!$err) {
623 $err += $this->create_dirs();
624 }
625
626 // Execute addons requests
627 $num = count($array_sql);
628 for ($i = 0; $i < $num; $i++) {
629 if (!$err) {
630 $sql = $array_sql[$i];
631 $val = $sql;
632 $ignoreerror = 0;
633 if (is_array($val)) {
634 $sql = $val['sql'];
635 $ignoreerror = $val['ignoreerror'] ?? 0;
636 }
637 // Add current entity id
638 $sql = str_replace('__ENTITY__', (string) ((int) $conf->entity), $sql);
639
640 dol_syslog(get_class($this)."::_init ignoreerror=".$ignoreerror, LOG_DEBUG);
641 $result = $this->db->query($sql, $ignoreerror);
642 if (!$result) {
643 if (!$ignoreerror) {
644 $this->error = $this->db->lasterror();
645 $err++;
646 } else {
647 dol_syslog(get_class($this)."::_init Warning ".$this->db->lasterror(), LOG_WARNING);
648 }
649 }
650 }
651 }
652
653 // Return code
654 if (!$err) {
655 $this->db->commit();
656
657 $moduleNameInConf = strtolower(preg_replace('/^MAIN_MODULE_/', '', $this->const_name));
658 // two exceptions to handle
659 if ($moduleNameInConf === 'propale') {
660 $moduleNameInConf = 'propal';
661 } elseif ($moduleNameInConf === 'supplierproposal') {
662 $moduleNameInConf = 'supplier_proposal';
663 }
664
665 $conf->modules[$moduleNameInConf] = $moduleNameInConf; // Add this module in list of enabled modules so isModEnabled() will work (conf->module->enabled must no more be used)
666
667 return 1;
668 } else {
669 $this->db->rollback();
670 return 0;
671 }
672 }
673
674 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
683 protected function _remove($array_sql, $options = '')
684 {
685 global $conf;
686 // phpcs:enable
687 $err = 0;
688
689 $this->db->begin();
690
691 // Remove activation module line (constant MAIN_MODULE_MYMODULE in llx_const)
692 if (!$err) {
693 $err += $this->_unactive();
694 }
695
696 // Remove activation of module's new tabs (MAIN_MODULE_MYMODULE_TABS_XXX in llx_const)
697 if (!$err) {
698 $err += $this->delete_tabs();
699 }
700
701 // Remove activation of module's parts (MAIN_MODULE_MYMODULE_XXX in llx_const)
702 if (!$err) {
703 $err += $this->delete_module_parts();
704 }
705
706 // Remove constants defined by modules
707 if (!$err) {
708 $err += $this->delete_const();
709 }
710
711 // Remove list of module's available boxes (entry in llx_boxes)
712 if (!$err && !preg_match('/(newboxdefonly|noboxes)/', $options)) {
713 $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
714 }
715
716 // Remove list of module's cron job entries (entry in llx_cronjobs)
717 if (!$err) {
718 $err += $this->delete_cronjobs();
719 }
720
721 // Remove module's permissions from list of available permissions (entries in llx_rights_def)
722 if (!$err) {
723 $err += $this->delete_permissions();
724 }
725
726 // Remove module's menus (entries in llx_menu)
727 if (!$err) {
728 $err += $this->delete_menus();
729 }
730
731 // Remove module's directories
732 if (!$err) {
733 $err += $this->delete_dirs();
734 }
735
736 // Run complementary sql requests
737 $num = count((array) $array_sql);
738 for ($i = 0; $i < $num; $i++) {
739 if (!$err) {
740 dol_syslog(get_class($this)."::_remove", LOG_DEBUG);
741 $result = $this->db->query($array_sql[$i]);
742 if (!$result) {
743 $this->error = $this->db->error();
744 $err++;
745 }
746 }
747 }
748
749 // Return code
750 if (!$err) {
751 $this->db->commit();
752
753 // Disable modules
754 $moduleNameInConf = strtolower(preg_replace('/^MAIN_MODULE_/', '', $this->const_name));
755 // two exceptions to handle
756 if ($moduleNameInConf === 'propale') {
757 $moduleNameInConf = 'propal';
758 } elseif ($moduleNameInConf === 'supplierproposal') {
759 $moduleNameInConf = 'supplier_proposal';
760 }
761
762 unset($conf->modules[$moduleNameInConf]); // Add this module in list of enabled modules so isModEnabled() will work (conf->module->enabled must no more be used)
763
764 return 1;
765 } else {
766 $this->db->rollback();
767 return 0;
768 }
769 }
770
771
778 public function getName()
779 {
780 global $langs;
781 $langs->load("admin");
782
783 if ($langs->transnoentitiesnoconv("Module".$this->numero."Name") != "Module".$this->numero."Name") {
784 // If module name translation exists
785 return $langs->transnoentitiesnoconv("Module".$this->numero."Name");
786 } else {
787 // If module name translation using it's unique id does not exist, we try to use its name to find translation
788 if (is_array($this->langfiles)) {
789 foreach ($this->langfiles as $val) {
790 if ($val) {
791 $langs->load($val);
792 }
793 }
794 }
795
796 if ($langs->trans("Module".$this->name."Name") != "Module".$this->name."Name") {
797 // If module name translation exists
798 return $langs->transnoentitiesnoconv("Module".$this->name."Name");
799 }
800
801 // Last chance with simple label
802 return $langs->transnoentitiesnoconv($this->name);
803 }
804 }
805
806
813 public function getDesc($foruseinpopupdesc = 0)
814 {
815 global $langs;
816 $langs->load("admin");
817
818 if ($langs->transnoentitiesnoconv("Module".$this->numero."Desc") != "Module".$this->numero."Desc") {
819 // If module description translation exists
820 return $langs->transnoentitiesnoconv("Module".$this->numero."Desc");
821 } else {
822 // If module description translation does not exist using its unique id, we can use its name to find translation
823 if (is_array($this->langfiles)) {
824 foreach ($this->langfiles as $val) {
825 if ($val) {
826 $langs->load($val);
827 }
828 }
829 }
830
831 if ($langs->transnoentitiesnoconv("Module".$this->name."Desc") != "Module".$this->name."Desc") {
832 // If module name translation exists
833 return $langs->trans("Module".$this->name."Desc");
834 }
835
836 // Last chance with simple label
837 return $langs->trans($this->description);
838 }
839 }
840
847 public function getDescLong()
848 {
849 global $langs;
850 $langs->load("admin");
851
852 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
853 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
854
855 $content = '';
856 $pathoffile = $this->getDescLongReadmeFound();
857
858 if ($pathoffile) { // Mostly for external modules
859 $content = file_get_contents($pathoffile, false, null, 0, 1024 * 1024); // Max size loaded 1Mb
860
861 if ((float) DOL_VERSION >= 6.0) { // @phpstan-ignore-line
862 @include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
863
864 $content = dolMd2Html(
865 $content,
866 'parsedown',
867 array(
868 'doc/' => dol_buildpath(strtolower($this->name).'/doc/', 1),
869 'img/' => dol_buildpath(strtolower($this->name).'/img/', 1),
870 'images/' => dol_buildpath(strtolower($this->name).'/images/', 1),
871 )
872 );
873
874 $content = preg_replace('/<a href="/', '<a target="_blank" rel="noopener noreferrer" href="', $content);
875 } else {
876 $content = nl2br($content);
877 }
878 } else {
879 // Mostly for internal modules
880 if (!empty($this->descriptionlong)) {
881 if (is_array($this->langfiles)) {
882 foreach ($this->langfiles as $val) {
883 if ($val) {
884 $langs->load($val);
885 }
886 }
887 }
888
889 $content = $langs->transnoentitiesnoconv($this->descriptionlong);
890 }
891 }
892
893 return '<div class="moduledesclong">'.$content.'</div>';
894 }
895
901 public function getDescLongReadmeFound()
902 {
903 global $langs;
904
905 $filefound = false;
906
907 // Define path to file README.md.
908 // First check README-la_LA.md then README-la.md then README.md
909 $pathoffile = dol_buildpath(strtolower($this->name).'/README-'.$langs->defaultlang.'.md', 0);
910 if (dol_is_file($pathoffile)) {
911 $filefound = true;
912 }
913 if (!$filefound) {
914 $tmp = explode('_', $langs->defaultlang);
915 $pathoffile = dol_buildpath(strtolower($this->name).'/README-'.$tmp[0].'.md', 0);
916 if (dol_is_file($pathoffile)) {
917 $filefound = true;
918 }
919 }
920 if (!$filefound) {
921 $pathoffile = dol_buildpath(strtolower($this->name).'/README.md', 0);
922 if (dol_is_file($pathoffile)) {
923 $filefound = true;
924 }
925 }
926
927 return ($filefound ? $pathoffile : '');
928 }
929
930
936 public function getChangeLog()
937 {
938 global $langs;
939 $langs->load("admin");
940
941 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
942 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
943
944 $filefound = false;
945
946 // Define path to file README.md.
947 // First check ChangeLog-la_LA.md then ChangeLog.md
948 $pathoffile = dol_buildpath(strtolower($this->name).'/ChangeLog-'.$langs->defaultlang.'.md', 0);
949 if (dol_is_file($pathoffile)) {
950 $filefound = true;
951 }
952 if (!$filefound) {
953 $pathoffile = dol_buildpath(strtolower($this->name).'/ChangeLog.md', 0);
954 if (dol_is_file($pathoffile)) {
955 $filefound = true;
956 }
957 }
958
959 if ($filefound) { // Mostly for external modules
960 $content = file_get_contents($pathoffile);
961
962 if ((float) DOL_VERSION >= 6.0) { // @phpstan-ignore-line
963 @include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
964
965 $content = dolMd2Html($content, 'parsedown', array('doc/' => dol_buildpath(strtolower($this->name).'/doc/', 1)));
966 } else {
967 $content = nl2br($content);
968 }
969 } else {
970 $content = '';
971 }
972
973 return $content;
974 }
975
981 public function getPublisher()
982 {
983 return $this->editor_name;
984 }
985
991 public function getPublisherUrl()
992 {
993 return $this->editor_url;
994 }
995
1004 public function getVersion($translated = 1)
1005 {
1006 global $langs;
1007 $langs->load("admin");
1008
1009 $ret = '';
1010
1011 $newversion = preg_replace('/_deprecated/', '', $this->version);
1012 if ($newversion == 'experimental') {
1013 $ret = ($translated ? $langs->transnoentitiesnoconv("VersionExperimental") : $newversion);
1014 } elseif ($newversion == 'development') {
1015 $ret = ($translated ? $langs->transnoentitiesnoconv("VersionDevelopment") : $newversion);
1016 } elseif ($newversion == 'dolibarr') {
1017 $ret = DOL_VERSION;
1018 } elseif ($newversion) {
1019 $ret = $newversion;
1020 } else {
1021 $ret = ($translated ? $langs->transnoentitiesnoconv("VersionUnknown") : 'unknown');
1022 }
1023
1024 if (preg_match('/_deprecated/', $this->version)) {
1025 $ret .= ($translated ? ' ('.$langs->transnoentitiesnoconv("Deprecated").')' : $this->version);
1026 }
1027 return $ret;
1028 }
1029
1035 public function getModulePosition()
1036 {
1037 if (in_array($this->version, array('dolibarr', 'dolibarr_deprecated', 'experimental', 'development'))) { // core module
1038 return $this->module_position;
1039 } else { // external module
1040 if ($this->module_position >= 100000) {
1041 return $this->module_position;
1042 } else {
1043 $position = intval($this->module_position) + 100000;
1044 return strval($position);
1045 }
1046 }
1047 }
1048
1055 public function isCoreOrExternalModule()
1056 {
1057 if ($this->version == 'dolibarr' || $this->version == 'dolibarr_deprecated') {
1058 return 'core';
1059 }
1060 if (!empty($this->version) && !in_array($this->version, array('experimental', 'development')) && empty($this->version_if_core)) {
1061 return 'external';
1062 }
1063 if (!empty($this->editor_name) || !empty($this->editor_url) && empty($this->version_if_core)) {
1064 return 'external';
1065 }
1066 if ($this->numero >= 100000) {
1067 return 'external';
1068 }
1069 return 'unknown';
1070 }
1071
1072
1078 public function getLangFilesArray()
1079 {
1080 return $this->langfiles;
1081 }
1082
1090 public function getExportDatasetLabel($r)
1091 {
1092 global $langs;
1093
1094 $langstring = "ExportDataset_".$this->export_code[$r];
1095 if ($langs->trans($langstring) == $langstring) {
1096 // Translation not found
1097 return $langs->trans($this->export_label[$r]);
1098 } else {
1099 // Translation found
1100 return $langs->trans($langstring);
1101 }
1102 }
1103
1104
1112 public function getImportDatasetLabel($r)
1113 {
1114 global $langs;
1115
1116 $langstring = "ImportDataset_".$this->import_code[$r];
1117 //print "x".$langstring;
1118 if ($langs->trans($langstring) == $langstring) {
1119 // Translation not found
1120 return $langs->transnoentitiesnoconv($this->import_label[$r]);
1121 } else {
1122 // Translation found
1123 return $langs->transnoentitiesnoconv($langstring);
1124 }
1125 }
1126
1127
1133 public function getLastActivationDate()
1134 {
1135 global $conf;
1136
1137 $err = 0;
1138
1139 $sql = "SELECT tms FROM ".MAIN_DB_PREFIX."const";
1140 $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
1141 $sql .= " AND entity IN (0, ".((int) $conf->entity).")";
1142
1143 dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG);
1144 $resql = $this->db->query($sql);
1145 if (!$resql) {
1146 $err++;
1147 } else {
1148 $obj = $this->db->fetch_object($resql);
1149 if ($obj) {
1150 return $this->db->jdate($obj->tms);
1151 }
1152 }
1153
1154 return '';
1155 }
1156
1157
1163 public function getLastActivationInfo()
1164 {
1165 global $conf;
1166
1167 $err = 0;
1168
1169 $sql = "SELECT tms, note FROM ".MAIN_DB_PREFIX."const";
1170 $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
1171 $sql .= " AND entity IN (0, ".((int) $conf->entity).")";
1172
1173 dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG);
1174 $resql = $this->db->query($sql);
1175 if (!$resql) {
1176 $err++;
1177 } else {
1178 $obj = $this->db->fetch_object($resql);
1179 if ($obj) {
1180 $tmp = array();
1181 if ($obj->note) {
1182 $tmp = json_decode($obj->note, true);
1183 }
1184 return array(
1185 'authorid' => empty($tmp['authorid']) ? '' : (int) $tmp['authorid'],
1186 'ip' => empty($tmp['ip']) ? '' : (string) $tmp['ip'],
1187 'lastactivationdate' => $this->db->jdate($obj->tms),
1188 'lastactivationversion' => (!empty($tmp['lastactivationversion']) ? (string) $tmp['lastactivationversion'] : 'unknown'),
1189 );
1190 }
1191 }
1192
1193 return array();
1194 }
1195
1196
1197 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1203 protected function _active()
1204 {
1205 // phpcs:enable
1206 global $conf, $user;
1207
1208 $err = 0;
1209
1210 // Common module
1211 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity);
1212
1213 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1214 $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
1215 $sql .= " AND entity IN (0, ".((int) $entity).")";
1216
1217 dol_syslog(get_class($this)."::_active delete activation constant", LOG_DEBUG);
1218 $resql = $this->db->query($sql);
1219 if (!$resql) {
1220 $err++;
1221 }
1222
1223 $note = json_encode(
1224 array(
1225 'authorid' => (is_object($user) ? $user->id : 0),
1226 'ip' => (empty($_SERVER['REMOTE_ADDR']) ? '' : $_SERVER['REMOTE_ADDR']),
1227 'lastactivationversion' => $this->version,
1228 )
1229 );
1230
1231 $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name, value, visible, entity, note) VALUES";
1232 $sql .= " (".$this->db->encrypt($this->const_name);
1233 $sql .= ", ".$this->db->encrypt('1');
1234 $sql .= ", 0, ".((int) $entity);
1235 $sql .= ", '".$this->db->escape($note)."')";
1236
1237 dol_syslog(get_class($this)."::_active insert activation constant", LOG_DEBUG);
1238 $resql = $this->db->query($sql);
1239 if (!$resql) {
1240 $err++;
1241 }
1242
1243 return $err;
1244 }
1245
1246
1247 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1253 protected function _unactive()
1254 {
1255 // phpcs:enable
1256 global $conf;
1257
1258 $err = 0;
1259
1260 // Common module
1261 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity);
1262
1263 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1264 $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
1265 $sql .= " AND entity IN (0, ".((int) $entity).")";
1266
1267 dol_syslog(get_class($this)."::_unactive", LOG_DEBUG);
1268 $this->db->query($sql);
1269
1270 return $err;
1271 }
1272
1273
1274 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps,PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1293 protected function _load_tables($reldir, $onlywithsuffix = '')
1294 {
1295 // phpcs:enable
1296 global $conf;
1297
1298 $error = 0;
1299 $dirfound = 0;
1300 $ok = 1;
1301
1302 if (empty($reldir)) {
1303 return 1;
1304 }
1305
1306 include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
1307
1308 foreach ($conf->file->dol_document_root as $dirroot) {
1309 if ($ok == 1) {
1310 $dirsql = $dirroot.$reldir; // Not sql, just sql file @phan-suppress-current-line SqlInjection
1311 $ok = 0;
1312
1313 // We will loop on xxx/, xxx/tables/, xxx/data/
1314 $listofsubdir = array('', 'tables/', 'data/');
1315 if ($this->db->type == 'pgsql') {
1316 $listofsubdir[] = '../pgsql/functions/';
1317 }
1318
1319 foreach ($listofsubdir as $subdir) {
1320 $dir = $dirsql.$subdir;
1321
1322 $handle = @opendir($dir); // Dir may not exists
1323 if (is_resource($handle)) {
1324 $dirfound++;
1325
1326 // Run llx_mytable.sql files, then llx_mytable_*.sql
1327 $files = array();
1328 while (($file = readdir($handle)) !== false) {
1329 $files[] = $file;
1330 }
1331 sort($files);
1332 foreach ($files as $file) {
1333 if ($onlywithsuffix) {
1334 if (!preg_match('/\-'.preg_quote($onlywithsuffix, '/').'\./i', $file)) {
1335 //print 'File '.$file.' does not match suffix '.$onlywithsuffix.' so it is discarded<br>'."\n";
1336 continue;
1337 } else {
1338 //print 'File '.$file.' match suffix '.$onlywithsuffix.' so we keep it<br>'."\n";
1339 }
1340 }
1341 if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && dol_substr($file, 0, 4) == 'llx_') {
1342 $result = run_sql($dir.$file, !getDolGlobalString('MAIN_DISPLAY_SQL_INSTALL_LOG') ? 1 : 0, 0, 1);
1343 if ($result <= 0) {
1344 $error++;
1345 }
1346 }
1347 }
1348
1349 rewinddir($handle);
1350
1351 // Run llx_mytable.key.sql files (Must be done after llx_mytable.sql) then then llx_mytable_*.key.sql
1352 $files = array();
1353 while (($file = readdir($handle)) !== false) {
1354 $files[] = $file;
1355 }
1356 sort($files);
1357 foreach ($files as $file) {
1358 if ($onlywithsuffix) {
1359 if (!preg_match('/\-'.preg_quote($onlywithsuffix, '/').'\./i', $file)) {
1360 //print 'File '.$file.' does not match suffix '.$onlywithsuffix.' so it is discarded<br>'."\n";
1361 continue;
1362 } else {
1363 //print 'File '.$file.' match suffix '.$onlywithsuffix.' so we keep it<br>'."\n";
1364 }
1365 }
1366 if (preg_match('/\.key\.sql$/i', $file) && dol_substr($file, 0, 4) == 'llx_') {
1367 $result = run_sql($dir.$file, !getDolGlobalString('MAIN_DISPLAY_SQL_INSTALL_LOG') ? 1 : 0, 0, 1);
1368 if ($result <= 0) {
1369 $error++;
1370 }
1371 }
1372 }
1373
1374 rewinddir($handle);
1375
1376 // Run functions-xxx.sql files (Must be done after llx_mytable.key.sql)
1377 $files = array();
1378 while (($file = readdir($handle)) !== false) {
1379 $files[] = $file;
1380 }
1381 sort($files);
1382 foreach ($files as $file) {
1383 if ($onlywithsuffix) {
1384 if (!preg_match('/\-'.preg_quote($onlywithsuffix, '/').'\./i', $file)) {
1385 //print 'File '.$file.' does not match suffix '.$onlywithsuffix.' so it is discarded<br>'."\n";
1386 continue;
1387 } else {
1388 //print 'File '.$file.' match suffix '.$onlywithsuffix.' so we keep it<br>'."\n";
1389 }
1390 }
1391 if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && dol_substr($file, 0, 9) == 'functions') {
1392 $result = run_sql($dir.$file, !getDolGlobalString('MAIN_DISPLAY_SQL_INSTALL_LOG') ? 1 : 0, 0, 1);
1393 if ($result <= 0) {
1394 $error++;
1395 }
1396 }
1397 }
1398
1399 rewinddir($handle);
1400
1401 // Run data_xxx.sql files (Must be done after llx_mytable.key.sql)
1402 $files = array();
1403 while (($file = readdir($handle)) !== false) {
1404 $files[] = $file;
1405 }
1406 sort($files);
1407 foreach ($files as $file) {
1408 if ($onlywithsuffix) {
1409 if (!preg_match('/\-'.preg_quote($onlywithsuffix, '/').'\./i', $file)) {
1410 //print 'File '.$file.' does not match suffix '.$onlywithsuffix.' so it is discarded<br>'."\n";
1411 continue;
1412 } else {
1413 //print 'File '.$file.' match suffix '.$onlywithsuffix.' so we keep it<br>'."\n";
1414 }
1415 }
1416 if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && dol_substr($file, 0, 4) == 'data') {
1417 $result = run_sql($dir.$file, !getDolGlobalString('MAIN_DISPLAY_SQL_INSTALL_LOG') ? 1 : 0, 0, 1);
1418 if ($result <= 0) {
1419 $error++;
1420 }
1421 }
1422 }
1423
1424 rewinddir($handle);
1425
1426 // Run update_xxx.sql files (sorted by name)
1427 $files = array();
1428 while (($file = readdir($handle)) !== false) {
1429 $files[] = $file;
1430 }
1431 sort($files);
1432 foreach ($files as $file) {
1433 if ($onlywithsuffix) {
1434 if (!preg_match('/\-'.preg_quote($onlywithsuffix, '/').'\./i', $file)) {
1435 //print 'File '.$file.' does not match suffix '.$onlywithsuffix.' so it is discarded<br>'."\n";
1436 continue;
1437 } else {
1438 //print 'File '.$file.' match suffix '.$onlywithsuffix.' so we keep it<br>'."\n";
1439 }
1440 }
1441
1442 if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && dol_substr($file, 0, 6) == 'update') {
1443 $result = run_sql($dir.$file, !getDolGlobalString('MAIN_DISPLAY_SQL_INSTALL_LOG') ? 1 : 0, 0, 1);
1444 if ($result <= 0) {
1445 $error++;
1446 }
1447 }
1448 }
1449
1450 closedir($handle);
1451 }
1452 }
1453
1454 if ($error == 0) {
1455 $ok = 1;
1456 }
1457 }
1458 }
1459
1460 if (!$dirfound) {
1461 dol_syslog("A module wants to load sql files from ".$reldir." but this directory was not found.", LOG_WARNING);
1462 }
1463 return $ok;
1464 }
1465
1466
1467 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1475 public function insert_boxes($option = '')
1476 {
1477 // phpcs:enable
1478 include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1479
1480 global $conf;
1481
1482 $err = 0;
1483
1484 if (is_array($this->boxes)) {
1485 dol_syslog(get_class($this)."::insert_boxes", LOG_DEBUG);
1486
1487 $pos_name = InfoBox::getListOfPagesForBoxes();
1488
1489 foreach ($this->boxes as $key => $value) {
1490 $file = isset($this->boxes[$key]['file']) ? $this->boxes[$key]['file'] : '';
1491 $note = isset($this->boxes[$key]['note']) ? $this->boxes[$key]['note'] : '';
1492 $enabledbydefaulton = isset($this->boxes[$key]['enabledbydefaulton']) ? $this->boxes[$key]['enabledbydefaulton'] : 'Home';
1493
1494 if (empty($file)) {
1495 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] : ''; // For backward compatibility
1496 }
1497 if (empty($note)) {
1498 $note = isset($this->boxes[$key][2]) ? $this->boxes[$key][2] : ''; // For backward compatibility
1499 }
1500
1501 // Search if boxes def already present
1502 $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."boxes_def";
1503 $sql .= " WHERE file = '".$this->db->escape($file)."'";
1504 $sql .= " AND entity = ".((int) $conf->entity);
1505 if ($note) {
1506 $sql .= " AND note ='".$this->db->escape($note)."'";
1507 }
1508
1509 $result = $this->db->query($sql);
1510 if ($result) {
1511 $obj = $this->db->fetch_object($result);
1512 if ($obj->nb == 0) {
1513 $this->db->begin();
1514
1515 if (!$err) {
1516 $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes_def (file, entity, note)";
1517 $sql .= " VALUES ('".$this->db->escape($file)."', ";
1518 $sql .= ((int) $conf->entity).", ";
1519 $sql .= $note ? "'".$this->db->escape($note)."'" : "null";
1520 $sql .= ")";
1521
1522 dol_syslog(get_class($this)."::insert_boxes", LOG_DEBUG);
1523 $resql = $this->db->query($sql);
1524 if (!$resql) {
1525 $err++;
1526 }
1527 }
1528 if (!$err && !preg_match('/newboxdefonly/', $option)) {
1529 $lastid = $this->db->last_insert_id(MAIN_DB_PREFIX."boxes_def", "rowid");
1530
1531 foreach ($pos_name as $key2 => $val2) {
1532 //print 'key2='.$key2.'-val2='.$val2."<br>\n";
1533 if ($enabledbydefaulton && $val2 != $enabledbydefaulton) {
1534 continue; // Not enabled by default onto this page.
1535 }
1536
1537 $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes (box_id, position, box_order, fk_user, entity)";
1538 $sql .= " VALUES (".((int) $lastid).", ".((int) $key2).", '0', 0, ".((int) $conf->entity).")";
1539
1540 dol_syslog(get_class($this)."::insert_boxes onto page ".$key2."=".$val2, LOG_DEBUG);
1541 $resql = $this->db->query($sql);
1542 if (!$resql) {
1543 $err++;
1544 }
1545 }
1546 }
1547
1548 if (!$err) {
1549 $this->db->commit();
1550 } else {
1551 $this->error = $this->db->lasterror();
1552 $this->db->rollback();
1553 }
1554 }
1555 // else box already registered into database
1556 } else {
1557 $this->error = $this->db->lasterror();
1558 $err++;
1559 }
1560 }
1561 }
1562
1563 return $err;
1564 }
1565
1566
1567 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1573 public function delete_boxes()
1574 {
1575 // phpcs:enable
1576 global $conf;
1577
1578 $err = 0;
1579
1580 if (is_array($this->boxes)) {
1581 foreach ($this->boxes as $key => $value) {
1582 //$titre = $this->boxes[$key][0];
1583 if (empty($this->boxes[$key]['file'])) {
1584 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] : ''; // For backward compatibility
1585 } else {
1586 $file = $this->boxes[$key]['file'];
1587 }
1588
1589 //$note = $this->boxes[$key][2];
1590
1591 // TODO If the box is also included by another module and the other module is still on, we should not remove it.
1592 // For the moment, we manage this with hard coded exception
1593 //print "Remove box ".$file.'<br>';
1594 if ($file == 'box_graph_product_distribution.php') {
1595 if (isModEnabled("product") || isModEnabled("service")) {
1596 dol_syslog("We discard deleting module ".$file." because another module still active requires it.");
1597 continue;
1598 }
1599 }
1600
1601 if ($this->db->type == 'sqlite3') {
1602 // sqlite doesn't support "USING" syntax.
1603 // TODO: remove this dependency.
1604 $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes ";
1605 $sql .= "WHERE ".MAIN_DB_PREFIX."boxes.box_id IN (";
1606 $sql .= "SELECT ".MAIN_DB_PREFIX."boxes_def.rowid ";
1607 $sql .= "FROM ".MAIN_DB_PREFIX."boxes_def ";
1608 $sql .= "WHERE ".MAIN_DB_PREFIX."boxes_def.file = '".$this->db->escape($file)."') ";
1609 $sql .= "AND ".MAIN_DB_PREFIX."boxes.entity = ".((int) $conf->entity);
1610 } else {
1611 $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes";
1612 $sql .= " USING ".MAIN_DB_PREFIX."boxes, ".MAIN_DB_PREFIX."boxes_def";
1613 $sql .= " WHERE ".MAIN_DB_PREFIX."boxes.box_id = ".MAIN_DB_PREFIX."boxes_def.rowid";
1614 $sql .= " AND ".MAIN_DB_PREFIX."boxes_def.file = '".$this->db->escape($file)."'";
1615 $sql .= " AND ".MAIN_DB_PREFIX."boxes.entity = ".((int) $conf->entity);
1616 }
1617
1618 dol_syslog(get_class($this)."::delete_boxes", LOG_DEBUG);
1619 $resql = $this->db->query($sql);
1620 if (!$resql) {
1621 $this->error = $this->db->lasterror();
1622 $err++;
1623 }
1624
1625 $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes_def";
1626 $sql .= " WHERE file = '".$this->db->escape($file)."'";
1627 $sql .= " AND entity = ".((int) $conf->entity); // Do not use getEntity here, we want to delete only in current company
1628
1629 dol_syslog(get_class($this)."::delete_boxes", LOG_DEBUG);
1630 $resql = $this->db->query($sql);
1631 if (!$resql) {
1632 $this->error = $this->db->lasterror();
1633 $err++;
1634 }
1635 }
1636 }
1637
1638 return $err;
1639 }
1640
1641 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1647 public function insert_cronjobs()
1648 {
1649 // phpcs:enable
1650 include_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php';
1651 include_once DOL_DOCUMENT_ROOT . '/cron/class/cronjob.class.php';
1652 include_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
1653
1654 global $conf, $user;
1655
1656 if (empty($user)) {
1657 $user = new User($this->db);
1658 }
1659
1660 $err = 0;
1661
1662 if (is_array($this->cronjobs)) {
1663 dol_syslog(get_class($this) . "::insert_cronjobs", LOG_DEBUG);
1664
1665 foreach ($this->cronjobs as $key => $value) {
1666 $now = dol_now();
1667
1668 $entity = isset($value['entity']) ? $value['entity'] : $conf->entity;
1669 $label = isset($value['label']) ? $value['label'] : '';
1670 $jobtype = isset($value['jobtype']) ? $value['jobtype'] : '';
1671 $classesname = isset($value['class']) ? $value['class'] : '';
1672 $objectname = isset($value['objectname']) ? $value['objectname'] : '';
1673 $methodename = isset($value['method']) ? $value['method'] : '';
1674 $command = isset($value['command']) ? $value['command'] : '';
1675 $params = isset($value['parameters']) ? $value['parameters'] : '';
1676 $md5params = isset($value['md5params']) ? $value['md5params'] : '';
1677 $comment = isset($value['comment']) ? $value['comment'] : '';
1678 $frequency = isset($value['frequency']) ? $value['frequency'] : '';
1679 $unitfrequency = isset($value['unitfrequency']) ? $value['unitfrequency'] : '';
1680 $priority = isset($value['priority']) ? $value['priority'] : '';
1681 $datestart = isset($value['datestart']) ? $value['datestart'] : '';
1682 $dateend = isset($value['dateend']) ? $value['dateend'] : '';
1683 $datenextrun = isset($value['datenextrun']) ? $value['datenextrun'] : $now;
1684 $status = isset($value['status']) ? $value['status'] : '';
1685 $maxrun = isset($value['maxrun']) ? $value['maxrun'] : 0;
1686 $libname = isset($value['libname']) ? $value['libname'] : '';
1687 $test = isset($value['test']) ? $value['test'] : ''; // Line must be enabled or not (so visible or not)
1688
1689 // Search if cron entry already present
1690 $sql = "SELECT count(*) as nb FROM " . MAIN_DB_PREFIX . "cronjob";
1691 //$sql .= " WHERE module_name = '" . $this->db->escape(empty($this->rights_class) ? strtolower($this->name) : $this->rights_class) . "'";
1692 $sql .= " WHERE label = '".$this->db->escape($label)."'";
1693 /* unique key is on label,entity so no need for this test
1694 if ($classesname) {
1695 $sql .= " AND classesname = '" . $this->db->escape($classesname) . "'";
1696 }
1697 if ($objectname) {
1698 $sql .= " AND objectname = '" . $this->db->escape($objectname) . "'";
1699 }
1700 if ($methodename) {
1701 $sql .= " AND methodename = '" . $this->db->escape($methodename) . "'";
1702 }
1703 if ($command) {
1704 $sql .= " AND command = '" . $this->db->escape($command) . "'";
1705 }
1706 if ($params) {
1707 $sql .= " AND params = '" . $this->db->escape($params) . "'";
1708 }
1709 */
1710 $sql .= " AND entity = " . ((int) $entity); // Must be exact entity
1711
1712 $result = $this->db->query($sql);
1713 if (!$result) {
1714 $this->error = $this->db->lasterror();
1715 $err++;
1716 break;
1717 // else box already registered into database
1718 }
1719
1720 $obj = $this->db->fetch_object($result);
1721 if ($obj->nb > 0) {
1722 continue;
1723 }
1724
1725 $cronjob = new Cronjob($this->db);
1726
1727 $cronjob->entity = $entity;
1728 $cronjob->label = $label;
1729 $cronjob->jobtype = $jobtype;
1730 $cronjob->classesname = $classesname;
1731 $cronjob->objectname = $objectname;
1732 $cronjob->methodename = $methodename;
1733 $cronjob->command = $command;
1734 $cronjob->params = $params;
1735 $cronjob->md5params = $md5params;
1736 $cronjob->note_private = $comment;
1737 $cronjob->frequency = $frequency;
1738 $cronjob->unitfrequency = $unitfrequency;
1739 $cronjob->priority = $priority;
1740 $cronjob->datestart = $datestart;
1741 $cronjob->dateend = $dateend;
1742 $cronjob->datenextrun = $datenextrun;
1743 $cronjob->maxrun = $maxrun;
1744 $cronjob->status = $status;
1745 $cronjob->test = $test;
1746 $cronjob->libname = $libname;
1747 $cronjob->module_name = empty($this->rights_class) ? strtolower($this->name) : $this->rights_class;
1748
1749 $retCreate = $cronjob->create($user);
1750
1751 if ($retCreate < 0) {
1752 $this->error = implode("\n", array_merge([$cronjob->error], $cronjob->errors));
1753 return -1;
1754 }
1755 }
1756 }
1757
1758 return $err;
1759 }
1760
1761 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1767 public function delete_cronjobs()
1768 {
1769 // phpcs:enable
1770 global $conf;
1771
1772 $err = 0;
1773
1774 if (is_array($this->cronjobs)) {
1775 $sql = "DELETE FROM ".MAIN_DB_PREFIX."cronjob";
1776 $sql .= " WHERE module_name = '".$this->db->escape(empty($this->rights_class) ? strtolower($this->name) : $this->rights_class)."'";
1777 $sql .= " AND entity = ".((int) $conf->entity);
1778 $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.
1779 // 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.
1780
1781 dol_syslog(get_class($this)."::delete_cronjobs", LOG_DEBUG);
1782 $resql = $this->db->query($sql);
1783 if (!$resql) {
1784 $this->error = $this->db->lasterror();
1785 $err++;
1786 }
1787 }
1788
1789 return $err;
1790 }
1791
1792 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1798 public function delete_tabs()
1799 {
1800 // phpcs:enable
1801 global $conf;
1802
1803 $err = 0;
1804
1805 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1806 $sql .= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->db->escape($this->const_name)."_TABS_%'";
1807 $sql .= " AND entity = ".((int) $conf->entity);
1808
1809 dol_syslog(get_class($this)."::delete_tabs", LOG_DEBUG);
1810 if (!$this->db->query($sql)) {
1811 $this->error = $this->db->lasterror();
1812 $err++;
1813 }
1814
1815 return $err;
1816 }
1817
1818 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1824 public function insert_tabs()
1825 {
1826 // phpcs:enable
1827 global $conf;
1828
1829 $err = 0;
1830
1831 if (!empty($this->tabs)) {
1832 dol_syslog(get_class($this)."::insert_tabs", LOG_DEBUG);
1833
1834 $i = 0;
1835 foreach ($this->tabs as $key => $value) {
1836 if (is_array($value) && count($value) == 0) {
1837 continue; // Discard empty arrays
1838 }
1839
1840 $entity = $conf->entity;
1841 $newvalue = $value;
1842
1843 if (is_array($value)) {
1844 $newvalue = $value['data'];
1845 if (isset($value['entity'])) {
1846 $entity = $value['entity'];
1847 }
1848 }
1849
1850 if ($newvalue) {
1851 $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (";
1852 $sql .= "name";
1853 $sql .= ", type";
1854 $sql .= ", value";
1855 $sql .= ", note";
1856 $sql .= ", visible";
1857 $sql .= ", entity";
1858 $sql .= ")";
1859 $sql .= " VALUES (";
1860 $sql .= $this->db->encrypt($this->const_name."_TABS_".$i);
1861 $sql .= ", 'chaine'";
1862 $sql .= ", ".$this->db->encrypt($newvalue);
1863 $sql .= ", null";
1864 $sql .= ", '0'";
1865 $sql .= ", ".((int) $entity);
1866 $sql .= ")";
1867
1868 $resql = $this->db->query($sql);
1869 if (!$resql) {
1870 dol_syslog($this->db->lasterror(), LOG_ERR);
1871 if ($this->db->lasterrno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1872 $this->error = $this->db->lasterror();
1873 $this->errors[] = $this->db->lasterror();
1874 $err++;
1875 break;
1876 }
1877 }
1878 }
1879 $i++;
1880 }
1881 }
1882 return $err;
1883 }
1884
1885 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1891 public function insert_const()
1892 {
1893 // phpcs:enable
1894 global $conf;
1895
1896 $err = 0;
1897
1898 if (empty($this->const)) {
1899 return 0;
1900 }
1901
1902 dol_syslog(__METHOD__, LOG_DEBUG);
1903
1904 foreach ($this->const as $key => $value) {
1905 // Property to search if entry exists
1906 $name = $this->const[$key][0];
1907 $entity = (!empty($this->const[$key][5]) && $this->const[$key][5] != 'current') ? 0 : $conf->entity;
1908
1909 // Property to update if it does not exists
1910 $type = $this->const[$key][1];
1911 $val = $this->const[$key][2];
1912 $note = isset($this->const[$key][3]) ? $this->const[$key][3] : '';
1913 $visible = isset($this->const[$key][4]) ? $this->const[$key][4] : 0;
1914
1915 // Clean
1916 if (empty($visible)) {
1917 $visible = '0';
1918 }
1919 if (empty($val) && $val != '0') {
1920 $val = '';
1921 }
1922
1923 if (!empty($name)) {
1924 $sql = "SELECT count(*) as nb";
1925 $sql .= " FROM ".MAIN_DB_PREFIX."const";
1926 $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'";
1927 $sql .= " AND entity = ".((int) $entity);
1928
1929 $result = $this->db->query($sql);
1930 if ($result) {
1931 $row = $this->db->fetch_row($result);
1932
1933 if ($row[0] == 0) { // If not found
1934 $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name, type, value, note, visible, entity)";
1935 $sql .= " VALUES (";
1936 $sql .= $this->db->encrypt($name); // Note: encrypt returns SQL expression or quoted string
1937 $sql .= ", '".$this->db->escape($type)."'";
1938 $sql .= ", ".(($val != '') ? $this->db->encrypt($val) : "''"); // Note: encrypt returns SQL expression or quoted string
1939 $sql .= ", ".($note ? "'".$this->db->escape($note)."'" : "null");
1940 $sql .= ", '".$this->db->escape($visible)."'";
1941 $sql .= ", ".((int) $entity);
1942 $sql .= ")";
1943
1944 if (!$this->db->query($sql)) {
1945 $err++;
1946 } else {
1947 // Set also the variable in running environment
1948 $conf->global->$name = $val;
1949 }
1950 } else {
1951 dol_syslog(__METHOD__." constant '".$name."' already exists", LOG_DEBUG);
1952 }
1953 } else {
1954 $err++;
1955 }
1956 }
1957 }
1958
1959 return $err;
1960 }
1961
1962 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1968 public function delete_const()
1969 {
1970 // phpcs:enable
1971 global $conf;
1972
1973 $err = 0;
1974
1975 if (empty($this->const)) {
1976 return 0;
1977 }
1978
1979 foreach ($this->const as $key => $value) {
1980 $name = $this->const[$key][0];
1981 $deleteonunactive = (!empty($this->const[$key][6])) ? 1 : 0;
1982
1983 if ($deleteonunactive) {
1984 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1985 $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'";
1986 $sql .= " AND entity in (0, ".((int) $conf->entity).")";
1987 dol_syslog(get_class($this)."::delete_const", LOG_DEBUG);
1988 if (!$this->db->query($sql)) {
1989 $this->error = $this->db->lasterror();
1990 $err++;
1991 }
1992 }
1993 }
1994
1995 return $err;
1996 }
1997
1998 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2005 {
2006 // phpcs:enable
2007 global $conf;
2008
2009 $err = 0;
2010
2011 if (empty($this->overwrite_translation)) {
2012 return 0;
2013 }
2014
2015 dol_syslog(get_class($this)."::insert_overwrite_translation", LOG_DEBUG);
2016
2017 foreach ($this->overwrite_translation as $key => $value) {
2018 $arkey = explode(':', $key);
2019 $lang = $arkey[0];
2020 $transkey = $arkey[1];
2021 $transvalue = $value;
2022 $entity = (!empty($arkey[3]) && $arkey[3] != 'current') ? 0 : $conf->entity;
2023
2024 // valid
2025 if (empty($lang) || empty($transkey) || empty($transvalue)) {
2026 continue;
2027 }
2028
2029 $sql = "SELECT count(*) as nb";
2030 $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
2031 $sql .= " WHERE ".$this->db->decrypt("transkey")." = '".$this->db->escape($transkey)."'";
2032 $sql .= " AND entity = ".((int) $entity);
2033
2034 $result = $this->db->query($sql);
2035 if ($result) {
2036 $row = $this->db->fetch_row($result);
2037
2038 if ($row[0] == 0) { // If not found
2039 $sql = "INSERT INTO ".MAIN_DB_PREFIX."overwrite_trans (entity,lang,transkey,transvalue)";
2040 $sql .= " VALUES (";
2041 $sql .= (int) $entity;
2042 $sql .= ",'".$this->db->escape($lang)."'";
2043 $sql .= ",'".$this->db->escape($transkey)."'";
2044 $sql .= ",'".$this->db->escape($transvalue)."'";
2045 $sql .= ")";
2046
2047 if (!$this->db->query($sql)) {
2048 $err++;
2049 }
2050 } else {
2051 dol_syslog(get_class($this)."::insert_overwrite_translation overwrite trans for key $transkey already exists", LOG_DEBUG);
2052 }
2053 } else {
2054 $err++;
2055 }
2056 }
2057
2058 return $err;
2059 }
2060
2061 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2074 public function insert_permissions($reinitadminperms = 0, $force_entity = null, $notrigger = 0, $existingrightsdefids = null)
2075 {
2076 // phpcs:enable
2077 global $conf, $langs, $user;
2078
2079 $err = 0;
2080 $skippedperms = array(); // Permission ids not inserted because already used
2081 $entity = (!empty($force_entity) ? $force_entity : $conf->entity);
2082
2083 dol_syslog(get_class($this)."::insert_permissions", LOG_DEBUG);
2084
2085 // Test if module is activated
2086 $sql_del = "SELECT ".$this->db->decrypt('value')." as value";
2087 $sql_del .= " FROM ".MAIN_DB_PREFIX."const";
2088 $sql_del .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
2089 $sql_del .= " AND entity IN (0,".((int) $entity).")";
2090
2091 $resql = $this->db->query($sql_del);
2092
2093 if ($resql) {
2094 $obj = $this->db->fetch_object($resql);
2095
2096 if ($obj !== null && !empty($obj->value) && !empty($this->rights)) {
2097 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
2098
2099 // If the module is active
2100 foreach ($this->rights as $key => $value) {
2101 $r_id = $this->rights[$key][self::KEY_ID]; // permission id in llx_rights_def (not unique because primary key is couple id-entity)
2102 $r_label = $this->rights[$key][self::KEY_LABEL];
2103 $r_type = $this->rights[$key][self::KEY_TYPE] ?? 'w'; // TODO deprecated
2104 $r_default = $this->rights[$key][self::KEY_DEFAULT] ?? 0;
2105 $r_perms = $this->rights[$key][self::KEY_FIRST_LEVEL] ?? '';
2106 $r_subperms = $this->rights[$key][self::KEY_SECOND_LEVEL] ?? '';
2107
2108 // KEY_FIRST_LEVEL (perms) must not be empty
2109 if (empty($r_perms)) {
2110 continue;
2111 }
2112
2113 // name of module (default: current module name)
2114 $r_module = (empty($this->rights_class) ? strtolower($this->name) : $this->rights_class);
2115
2116 // name of the module from which the right comes (default: empty means same module the permission is for)
2117 $r_module_origin = '';
2118
2119 if (isset($this->rights[$key][self::KEY_MODULE])) {
2120 // name of the module to which the right must be applied
2121 $r_module = $this->rights[$key][self::KEY_MODULE];
2122 // name of the module from which the right comes
2123 $r_module_origin = (empty($this->rights_class) ? strtolower($this->name) : $this->rights_class);
2124 }
2125
2126 if (!empty($r_module_origin) && $r_module !== $r_module_origin) {
2127 // This right is filed under a different module's section of the permission
2128 // grid (KEY_MODULE) than the one declaring it: use that target module's own
2129 // family/position so it appears grouped with its native rights instead of
2130 // opening a second, misplaced section for the same module.
2131 $r_targetmoduleinfo = $this->getModuleInfoByRightsClass($r_module);
2132 $r_module_position = $r_targetmoduleinfo['position'];
2133 $r_family = $r_targetmoduleinfo['family'];
2134 } else {
2135 $r_module_position = $this->getModulePosition();
2136 $r_family = $this->family;
2137 }
2138 $r_family_position = 0;
2139
2140 // condition to show or hide a user right (default: 1) (eg isModEnabled('anothermodule') or ($conf->global->MAIN_FEATURES_LEVEL > 0) or etc..)
2141 $r_enabled = $this->rights[$key][self::KEY_ENABLED] ?? '1';
2142
2143 // Search if perm already present
2144 if ($existingrightsdefids !== null) {
2145 $rightalreadyexists = !empty($existingrightsdefids[$r_id]);
2146 } else {
2147 $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."rights_def";
2148 $sql .= " WHERE entity = ".((int) $entity);
2149 $sql .= " AND id = ".((int) $r_id);
2150
2151 $rightalreadyexists = true; // Assume it exists if the select fails, so we never try to insert on a query error
2152 $resqlselect = $this->db->query($sql);
2153 if ($resqlselect) {
2154 $objcount = $this->db->fetch_object($resqlselect);
2155 $rightalreadyexists = !($objcount && $objcount->nb == 0);
2156 $this->db->free($resqlselect);
2157 }
2158 }
2159
2160 if (!$rightalreadyexists) {
2161 $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def (";
2162 $sql .= "id";
2163 $sql .= ", entity";
2164 $sql .= ", libelle";
2165 $sql .= ", module";
2166 $sql .= ", module_origin";
2167 $sql .= ", module_position"; // Not that module_position can be fixed eynamically when accessing page user/perms.php
2168 $sql .= ", family";
2169 $sql .= ", family_position";
2170 $sql .= ", type"; // Not used yet
2171 $sql .= ", bydefault";
2172 $sql .= ", perms";
2173 $sql .= ", subperms";
2174 $sql .= ", enabled";
2175 $sql .= ") VALUES (";
2176 $sql .= ((int) $r_id);
2177 $sql .= ", ".((int) $entity);
2178 $sql .= ", '".$this->db->escape($r_label)."'";
2179 $sql .= ", '".$this->db->escape($r_module)."'";
2180 $sql .= ", '".$this->db->escape($r_module_origin)."'";
2181 $sql .= ", '".$this->db->escape((string) $r_module_position)."'";
2182 $sql .= ", '".$this->db->escape($r_family)."'";
2183 $sql .= ", '".$this->db->escape((string) $r_family_position)."'";
2184 $sql .= ", '".$this->db->escape($r_type)."'"; // Not used yet
2185 $sql .= ", ".((int) $r_default);
2186 $sql .= ", '".$this->db->escape($r_perms)."'";
2187 $sql .= ", '".$this->db->escape($r_subperms)."'";
2188 $sql .= ", '".$this->db->escape($r_enabled)."'";
2189 $sql .= ")";
2190
2191 $resqlinsert = $this->db->query($sql, 1);
2192
2193 if (!$resqlinsert) {
2194 if ($this->db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS") {
2195 $this->error = $this->db->lasterror();
2196 $err++;
2197 break;
2198 } else {
2199 dol_syslog(get_class($this)."::insert_permissions record already exists", LOG_INFO);
2200 }
2201 }
2202
2203 $this->db->free($resqlinsert);
2204 } else {
2205 // Id already used, possibly by another module: the permission is silently
2206 // not inserted, which leaves the module half installed. Collected to warn once.
2207 $sql = "SELECT module FROM ".MAIN_DB_PREFIX."rights_def";
2208 $sql .= " WHERE entity = ".((int) $entity);
2209 $sql .= " AND id = ".((int) $r_id);
2210 $sql .= " AND module <> '".$this->db->escape($r_module)."'";
2211
2212 $resqlowner = $this->db->query($sql);
2213 if ($resqlowner) {
2214 $objowner = $this->db->fetch_object($resqlowner);
2215 if ($objowner) {
2216 $skippedperms[$r_id] = $r_perms.($r_subperms ? "->".$r_subperms : "");
2217 dol_syslog(get_class($this)."::insert_permissions permission id ".$r_id." of module ".$r_module." already used by module ".$objowner->module.", permission not added", LOG_WARNING);
2218 }
2219 $this->db->free($resqlowner);
2220 }
2221 }
2222
2223 // If we want to init permissions on admin users
2224 if (!empty($reinitadminperms)) {
2225 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."user WHERE admin = 1";
2226 dol_syslog(get_class($this)."::insert_permissions Search all admin users", LOG_DEBUG);
2227
2228 $resqlseladmin = $this->db->query($sql, 1);
2229
2230 if ($resqlseladmin) {
2231 $num = $this->db->num_rows($resqlseladmin);
2232 $i = 0;
2233 while ($i < $num) {
2234 $obj2 = $this->db->fetch_object($resqlseladmin);
2235 dol_syslog(get_class($this)."::insert_permissions Add permission id ".$r_id." to user id=".$obj2->rowid);
2236
2237 $tmpuser = new User($this->db);
2238 $result = $tmpuser->fetch($obj2->rowid);
2239 if ($result > 0) {
2240 $tmpuser->addrights($r_id, '', '', 0, 1);
2241 } else {
2242 dol_syslog(get_class($this)."::insert_permissions Failed to add the permission to user because fetch return an error", LOG_ERR);
2243 }
2244 $i++;
2245 }
2246 } else {
2247 dol_print_error($this->db);
2248 }
2249 }
2250 }
2251
2252 if (!empty($reinitadminperms) && !empty($user->admin)) { // Reload permission for current user if defined
2253 // We reload permissions
2254 $user->clearrights();
2255 $user->loadRights();
2256 }
2257 }
2258 if (!empty($skippedperms)) {
2259 $langs->load("admin");
2260 $listofperms = array();
2261 foreach ($skippedperms as $tmpid => $tmpperm) {
2262 $listofperms[] = $tmpid." (".$tmpperm.")";
2263 }
2264 setEventMessages($langs->trans("WarningPermissionIdsAlreadyUsed", $this->name, implode(", ", $listofperms)), null, "warnings");
2265 }
2266
2267 $this->db->free($resql);
2268 } else {
2269 $this->error = $this->db->lasterror();
2270 $err++;
2271 }
2272
2273 return $err;
2274 }
2275
2287 protected function getModuleInfoByRightsClass($rightsclass)
2288 {
2289 global $conf, $db;
2290
2291 if (isset($conf->cache['keyModuleInfoCache'][$rightsclass])) {
2292 return $conf->cache['keyModuleInfoCache'][$rightsclass];
2293 }
2294
2295 // Fallback: if no module with this rights_class is found (typo, or module removed from disk),
2296 // still register something under its own family/position rather than leaving it undefined.
2297 $result = array('family' => $this->family, 'position' => (int) $this->getModulePosition());
2298
2299 $modulesdir = dolGetModulesDirs();
2300 foreach ($modulesdir as $dir) {
2301 $handle = @opendir(dol_osencode($dir));
2302 if (is_resource($handle)) {
2303 while (($file = readdir($handle)) !== false) {
2304 if (is_readable($dir.$file) && dol_substr($file, 0, 3) == 'mod' && dol_substr($file, dol_strlen($file) - 10) == '.class.php') {
2305 $modName = dol_substr($file, 0, dol_strlen($file) - 10);
2306 if ($modName && $modName != get_class($this)) {
2307 include_once $dir.$file;
2308 if (class_exists($modName)) {
2309 '@phan-var-force class-string<DolibarrModules> $modName';
2310 $objMod = new $modName($db);
2311 '@phan-var-force DolibarrModules $objMod';
2312 if (!empty($objMod->rights_class) && $objMod->rights_class === $rightsclass) {
2313 $result = array('family' => $objMod->family, 'position' => (int) $objMod->getModulePosition());
2314 break 2;
2315 }
2316 }
2317 }
2318 }
2319 }
2320 closedir($handle);
2321 }
2322 }
2323
2324 $conf->cache['keyModuleInfoCache'][$rightsclass] = $result;
2325
2326 return $result;
2327 }
2328
2329
2330 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2336 public function delete_permissions()
2337 {
2338 // phpcs:enable
2339 global $conf;
2340
2341 $err = 0;
2342
2343 $module = empty($this->rights_class) ? strtolower($this->name) : $this->rights_class;
2344
2345 $sql = "DELETE FROM ".MAIN_DB_PREFIX."rights_def";
2346 $sql .= " WHERE (module = '".$this->db->escape($module)."' OR module_origin = '".$this->db->escape($module)."')";
2347
2348 // Delete all entities if core module
2349 if (empty($this->core_enabled)) {
2350 $sql .= " AND entity = ".((int) $conf->entity);
2351 }
2352
2353 dol_syslog(get_class($this)."::delete_permissions", LOG_DEBUG);
2354 if (!$this->db->query($sql)) {
2355 $this->error = $this->db->lasterror();
2356 $err++;
2357 }
2358
2359 return $err;
2360 }
2361
2362
2363 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2369 public function insert_menus()
2370 {
2371 // phpcs:enable
2372 global $conf, $user;
2373
2374 if (!is_array($this->menu) || empty($this->menu)) {
2375 return 0;
2376 }
2377
2378 include_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
2379
2380 dol_syslog(get_class($this)."::insert_menus", LOG_DEBUG);
2381
2382 $err = 0;
2383
2384 // Common module
2385 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity);
2386
2387 $this->db->begin();
2388
2389 foreach ($this->menu as $key => $value) {
2390 $menu = new Menubase($this->db);
2391 $menu->menu_handler = 'all';
2392
2393 //$menu->module=strtolower($this->name); TODO When right_class will be same than module name
2394 $menu->module = (empty($this->rights_class) ? strtolower($this->name) : $this->rights_class);
2395
2396 if (!$this->menu[$key]['fk_menu']) {
2397 $menu->fk_menu = 0;
2398 } else {
2399 $foundparent = 0;
2400 $fk_parent = $this->menu[$key]['fk_menu'];
2401 $reg = array();
2402 if (preg_match('/^r=/', $fk_parent)) { // old deprecated method
2403 $fk_parent = str_replace('r=', '', $fk_parent);
2404 if (isset($this->menu[$fk_parent]['rowid'])) {
2405 $menu->fk_menu = $this->menu[$fk_parent]['rowid'];
2406 $foundparent = 1;
2407 }
2408 } elseif (preg_match('/^fk_mainmenu=([a-zA-Z0-9_]+),fk_leftmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
2409 $menu->fk_menu = -1;
2410 $menu->fk_mainmenu = $reg[1];
2411 $menu->fk_leftmenu = $reg[2];
2412 $foundparent = 1;
2413 } elseif (preg_match('/^fk_mainmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
2414 $menu->fk_menu = -1;
2415 $menu->fk_mainmenu = $reg[1];
2416 $menu->fk_leftmenu = '';
2417 $foundparent = 1;
2418 }
2419 if (!$foundparent) {
2420 $this->error = "ErrorBadDefinitionOfMenuArrayInModuleDescriptor";
2421 dol_syslog(get_class($this)."::insert_menus ".$this->error." ".$this->menu[$key]['fk_menu'], LOG_ERR);
2422 $err++;
2423 }
2424 }
2425 $menu->type = $this->menu[$key]['type'];
2426 $menu->mainmenu = isset($this->menu[$key]['mainmenu']) ? $this->menu[$key]['mainmenu'] : (isset($menu->fk_mainmenu) ? $menu->fk_mainmenu : '');
2427 $menu->leftmenu = isset($this->menu[$key]['leftmenu']) ? $this->menu[$key]['leftmenu'] : '';
2428 $menu->title = $this->menu[$key]['titre'];
2429 $menu->prefix = isset($this->menu[$key]['prefix']) ? $this->menu[$key]['prefix'] : '';
2430 $menu->url = $this->menu[$key]['url'];
2431 $menu->langs = isset($this->menu[$key]['langs']) ? $this->menu[$key]['langs'] : '';
2432 $menu->position = $this->menu[$key]['position'];
2433 $menu->perms = $this->menu[$key]['perms'];
2434 $menu->target = isset($this->menu[$key]['target']) ? $this->menu[$key]['target'] : '';
2435 $menu->user = $this->menu[$key]['user'];
2436 $menu->enabled = isset($this->menu[$key]['enabled']) ? $this->menu[$key]['enabled'] : 0;
2437 $menu->position = $this->menu[$key]['position'];
2438 $menu->entity = $entity;
2439
2440 if (!$err) {
2441 $result = $menu->create($user); // Save menu entry into table llx_menu
2442 if ($result > 0) {
2443 $this->menu[$key]['rowid'] = $result;
2444 } else {
2445 $this->error = $menu->error;
2446 dol_syslog(get_class($this).'::insert_menus result='.$result." ".$this->error, LOG_ERR);
2447 $err++;
2448 break;
2449 }
2450 }
2451 }
2452
2453 if (!$err) {
2454 $this->db->commit();
2455 } else {
2456 dol_syslog(get_class($this)."::insert_menus ".$this->error, LOG_ERR);
2457 $this->db->rollback();
2458 }
2459
2460 return $err;
2461 }
2462
2463
2464 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2470 public function delete_menus()
2471 {
2472 // phpcs:enable
2473 global $conf;
2474
2475 $err = 0;
2476
2477 //$module=strtolower($this->name); TODO When right_class will be same than module name
2478 $module = empty($this->rights_class) ? strtolower($this->name) : $this->rights_class;
2479
2480 $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
2481 $sql .= " WHERE module = '".$this->db->escape($module)."'";
2482 $sql .= " AND menu_handler = 'all'"; // We delete only lines that were added manually or by the module activation. We keep entry added by menuhandler like 'auguria'
2483 $sql .= " AND entity IN (0, ".((int) $conf->entity).")";
2484
2485 dol_syslog(get_class($this)."::delete_menus", LOG_DEBUG);
2486 $resql = $this->db->query($sql);
2487 if (!$resql) {
2488 $this->error = $this->db->lasterror();
2489 $err++;
2490 }
2491
2492 return $err;
2493 }
2494
2495 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2501 public function create_dirs()
2502 {
2503 // phpcs:enable
2504 global $langs, $conf;
2505
2506 $err = 0;
2507 $name = '';
2508
2509 if (isset($this->dirs) && is_array($this->dirs)) {
2510 foreach ($this->dirs as $key => $value) {
2511 $addtodatabase = 0;
2512
2513 if (!is_array($value)) {
2514 $dir = $value; // Default simple mode
2515 } else {
2516 $constname = $this->const_name."_DIR_";
2517 $dir = $this->dirs[$key][1];
2518 $addtodatabase = empty($this->dirs[$key][2]) ? '' : $this->dirs[$key][2]; // Create constante in llx_const
2519 $subname = empty($this->dirs[$key][3]) ? '' : strtoupper($this->dirs[$key][3]); // Add submodule name (ex: $conf->module->submodule->dir_output)
2520 $forcename = empty($this->dirs[$key][4]) ? '' : strtoupper($this->dirs[$key][4]); // Change the module name if different
2521
2522 if (!empty($forcename)) {
2523 $constname = 'MAIN_MODULE_'.$forcename."_DIR_";
2524 }
2525 if (!empty($subname)) {
2526 $constname = $constname.$subname."_";
2527 }
2528
2529 $name = $constname.strtoupper($this->dirs[$key][0]);
2530 }
2531
2532 // Define directory full path ($dir must start with "/")
2533 if (!getDolGlobalString('MAIN_MODULE_MULTICOMPANY') || $conf->entity == 1) {
2534 $fulldir = DOL_DATA_ROOT.$dir;
2535 } else {
2536 $fulldir = DOL_DATA_ROOT."/".$conf->entity.$dir;
2537 }
2538 // Create dir if it does not exists
2539 if (!empty($fulldir) && !file_exists($fulldir)) {
2540 if (dol_mkdir($fulldir, DOL_DATA_ROOT) < 0) {
2541 $this->error = $langs->trans("ErrorCanNotCreateDir", $fulldir);
2542 dol_syslog(get_class($this)."::_init ".$this->error, LOG_ERR);
2543 $err++;
2544 }
2545 }
2546
2547 // Define the constant in database if requested (not the default mode)
2548 if (!empty($addtodatabase) && !empty($name)) {
2549 $result = $this->insert_dirs($name, $dir);
2550 if ($result) {
2551 $err++;
2552 }
2553 }
2554 }
2555 }
2556
2557 return $err;
2558 }
2559
2560
2561 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2570 public function insert_dirs($name, $dir)
2571 {
2572 // phpcs:enable
2573 global $conf;
2574
2575 $err = 0;
2576
2577 $sql = "SELECT count(*)";
2578 $sql .= " FROM ".MAIN_DB_PREFIX."const";
2579 $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'";
2580 $sql .= " AND entity = ".((int) $conf->entity);
2581
2582 dol_syslog(get_class($this)."::insert_dirs", LOG_DEBUG);
2583 $result = $this->db->query($sql);
2584 if ($result) {
2585 $row = $this->db->fetch_row($result);
2586
2587 if ($row[0] == 0) {
2588 $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name, type, value, note, visible, entity)";
2589 $sql .= " VALUES (".$this->db->encrypt($name).", 'chaine', ".$this->db->encrypt($dir).", '".$this->db->escape("Directory for module ".$this->name)."', '0', ".((int) $conf->entity).")";
2590
2591 dol_syslog(get_class($this)."::insert_dirs", LOG_DEBUG);
2592 $this->db->query($sql);
2593 }
2594 } else {
2595 $this->error = $this->db->lasterror();
2596 $err++;
2597 }
2598
2599 return $err;
2600 }
2601
2602
2603 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2609 public function delete_dirs()
2610 {
2611 // phpcs:enable
2612 global $conf;
2613
2614 $err = 0;
2615
2616 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
2617 $sql .= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->db->escape($this->const_name)."_DIR_%'";
2618 $sql .= " AND entity = ".((int) $conf->entity);
2619
2620 dol_syslog(get_class($this)."::delete_dirs", LOG_DEBUG);
2621 if (!$this->db->query($sql)) {
2622 $this->error = $this->db->lasterror();
2623 $err++;
2624 }
2625
2626 return $err;
2627 }
2628
2629 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2636 public function insert_module_parts()
2637 {
2638 // phpcs:enable
2639 global $conf, $langs;
2640
2641 $error = 0;
2642
2643 if (is_array($this->module_parts)) {
2644 if (empty($this->module_parts['icon']) && !empty($this->picto) && preg_match('/^fa\-/', $this->picto)) {
2645 $this->module_parts['icon'] = $this->picto;
2646 }
2647
2648 foreach ($this->module_parts as $key => $value) {
2649 if (is_array($value) && count($value) == 0) {
2650 continue; // Discard empty arrays
2651 }
2652
2653 // If module brings website templates, we must generate the zip like we do whenenabling the website module
2654 if ($key == 'websitetemplates' && $value == 1) {
2655 $srcroot = dol_buildpath('/'.strtolower($this->name).'/doctemplates/websites');
2656
2657 // Copy templates in dir format (recommended) into zip file
2658 $docs = dol_dir_list($srcroot, 'directories', 0, 'website_.*$');
2659 foreach ($docs as $cursorfile) {
2660 $src = $srcroot.'/'.$cursorfile['name'];
2661 $dest = DOL_DATA_ROOT.'/doctemplates/websites/'.$cursorfile['name'];
2662
2663 dol_delete_file($dest.'.zip');
2664
2665 // Compress it
2666 global $errormsg; // Used by dol_compress_dir
2667 $errormsg = '';
2668 $result = dol_compress_dir($src, $dest.'.zip', 'zip');
2669 if ($result < 0) {
2670 $error++;
2671 $this->error = ($errormsg ? $errormsg : $langs->trans('ErrorFailToCreateZip', $dest));
2672 $this->errors[] = ($errormsg ? $errormsg : $langs->trans('ErrorFailToCreateZip', $dest));
2673 }
2674 }
2675
2676 // Copy also the preview website_xxx.jpg file
2677 $docs = dol_dir_list($srcroot, 'files', 0, 'website_.*\.jpg$');
2678 foreach ($docs as $cursorfile) {
2679 $src = $srcroot.'/'.$cursorfile['name'];
2680 $dest = DOL_DATA_ROOT.'/doctemplates/websites/'.$cursorfile['name'];
2681
2682 dol_copy($src, $dest);
2683 }
2684 }
2685
2686 $entity = $conf->entity; // Reset the current entity
2687 $newvalue = $value;
2688
2689 // Serialize array parameters
2690 if (is_array($value)) {
2691 // Can defined other parameters
2692 // Example when $key='hooks', then $value is an array('data'=>array('hookcontext1','hookcontext2'), 'entity'=>X)
2693 if (isset($value['data']) && is_array($value['data'])) {
2694 $newvalue = json_encode($value['data']);
2695 if (isset($value['entity'])) {
2696 $entity = $value['entity'];
2697 }
2698 } elseif (isset($value['data']) && !is_array($value['data'])) {
2699 $newvalue = $value['data'];
2700 if (isset($value['entity'])) {
2701 $entity = $value['entity'];
2702 }
2703 } else { // when hook is declared with syntax 'hook'=>array('hookcontext1','hookcontext2',...)
2704 $newvalue = json_encode($value);
2705 }
2706 }
2707
2708 if (!empty($newvalue)) {
2709 $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (";
2710 $sql .= "name";
2711 $sql .= ", type";
2712 $sql .= ", value";
2713 $sql .= ", note";
2714 $sql .= ", visible";
2715 $sql .= ", entity";
2716 $sql .= ")";
2717 $sql .= " VALUES (";
2718 $sql .= " ".$this->db->encrypt($this->const_name."_".strtoupper($key), 1);
2719 $sql .= ", 'chaine'";
2720 $sql .= ", ".$this->db->encrypt($newvalue, 1);
2721 $sql .= ", null";
2722 $sql .= ", '0'";
2723 $sql .= ", ".((int) $entity);
2724 $sql .= ")";
2725
2726 dol_syslog(get_class($this)."::insert_module_parts for key=".$this->const_name."_".strtoupper($key), LOG_DEBUG);
2727
2728 $resql = $this->db->query($sql, 1);
2729 if (!$resql) {
2730 if ($this->db->lasterrno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') {
2731 $error++;
2732 $this->error = $this->db->lasterror();
2733 } else {
2734 dol_syslog(get_class($this)."::insert_module_parts for ".$this->const_name."_".strtoupper($key)." Record already exists.", LOG_WARNING);
2735 }
2736 }
2737 }
2738 }
2739 }
2740 return $error;
2741 }
2742
2743 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2749 public function delete_module_parts()
2750 {
2751 // phpcs:enable
2752 global $conf;
2753
2754 $err = 0;
2755
2756 if (is_array($this->module_parts)) {
2757 dol_syslog(get_class($this)."::delete_module_parts", LOG_DEBUG);
2758
2759 if (empty($this->module_parts['icon']) && !empty($this->picto) && preg_match('/^fa\-/', $this->picto)) {
2760 $this->module_parts['icon'] = $this->picto;
2761 }
2762
2763 foreach ($this->module_parts as $key => $value) {
2764 // If entity is defined
2765 if (is_array($value) && isset($value['entity'])) {
2766 $entity = $value['entity'];
2767 } else {
2768 $entity = $conf->entity;
2769 }
2770
2771 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
2772 $sql .= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->db->escape($this->const_name)."_".strtoupper($key)."'";
2773 $sql .= " AND entity = ".((int) $entity);
2774
2775 if (!$this->db->query($sql)) {
2776 $this->error = $this->db->lasterror();
2777 $err++;
2778 }
2779 }
2780 }
2781 return $err;
2782 }
2783
2793 public function init($options = '')
2794 {
2795 return $this->_init(array(), $options);
2796 }
2797
2806 public function remove($options = '')
2807 {
2808 return $this->_remove(array(), $options);
2809 }
2810
2811
2819 public function getKanbanView($codeenabledisable = '', $codetoconfig = '')
2820 {
2821 global $langs;
2822
2823 // Define imginfo
2824 $imginfo = "info";
2825 if ($this->isCoreOrExternalModule() == 'external') {
2826 $imginfo = "info_black";
2827 }
2828
2829 $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($this)));
2830
2831 $version = $this->getVersion(0);
2832 $versiontrans = '';
2833 if (preg_match('/development/i', $version)) {
2834 $versiontrans .= 'warning';
2835 }
2836 if (preg_match('/experimental/i', $version)) {
2837 $versiontrans .= 'warning';
2838 }
2839 if (preg_match('/deprecated/i', $version)) {
2840 $versiontrans .= 'warning';
2841 }
2842
2843 $return = '
2844 <div class="box-flex-item info-box-module'
2845 .(getDolGlobalString($const_name) ? '' : ' --disabled')
2846 .($this->isCoreOrExternalModule() == 'external' ? ' --external' : '')
2847 .($this->needUpdate ? ' --need-update' : '')
2848 .'">
2849 <div class="info-box info-box-sm info-box-module">
2850 <div class="info-box-icon'.(!getDolGlobalString($const_name) ? '' : ' info-box-icon-module-enabled'.($versiontrans ? ' info-box-icon-module-warning' : '')).'">';
2851
2852 $alttext = '';
2853 //if (is_array($objMod->need_dolibarr_version)) $alttext.=($alttext?' - ':'').'Dolibarr >= '.join('.',$objMod->need_dolibarr_version);
2854 //if (is_array($objMod->phpmin)) $alttext.=($alttext?' - ':'').'PHP >= '.join('.',$objMod->phpmin);
2855 if (!empty($this->picto)) {
2856 if (preg_match('/^\//i', $this->picto)) {
2857 $return .= img_picto($alttext, $this->picto, 'class="inline-block valignmiddle"', 1);
2858 } else {
2859 $return .= img_object($alttext, $this->picto, 'class="inline-block valignmiddle"');
2860 }
2861 } else {
2862 $return .= img_object($alttext, 'generic', 'class="inline-block valignmiddle"');
2863 }
2864
2865 if ($this->isCoreOrExternalModule() == 'external' || preg_match('/development|experimental|deprecated/i', $version)) {
2866 $versionTitle = $langs->trans("Version").' '.$this->getVersion(1);
2867 if ($this->needUpdate) {
2868 $versionTitle .= '<br>'.$langs->trans('ModuleUpdateAvailable').' : '.$this->lastVersion;
2869 }
2870
2871 $return .= '<span class="info-box-icon-version'.($versiontrans ? ' '.$versiontrans : '').' classfortooltip" title="'.dolPrintHTMLForAttribute($versionTitle).'" >';
2872 $return .= $this->getVersion(1);
2873 $return .= '</span>';
2874 }
2875
2876 $return .= '</div>
2877 <div class="info-box-content info-box-text-module'.(!getDolGlobalString($const_name) ? '' : ' info-box-module-enabled'.($versiontrans ? ' info-box-content-warning' : '')).'">
2878 <span class="info-box-title noopacity">'.$this->getName().'</span>
2879 <span class="info-box-desc twolinesmax opacitymedium" title="'.dol_escape_htmltag($this->getDesc()).'">'.nl2br($this->getDesc()).'</span>';
2880
2881 $return .= '<div class="valignmiddle inline-block info-box-more">';
2882 //if ($versiontrans) print img_warning($langs->trans("Version").' '.$this->getVersion(1)).' ';
2883 $return .= '<a class="valignmiddle inline-block" href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.((int) $this->numero).'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto(($this->isCoreOrExternalModule() == 'external' ? $langs->trans("ExternalModule").' - ' : '').$langs->trans("ClickToShowDescription"), $imginfo).'</a>';
2884 $return .= '</div><br>';
2885
2886 $return .= '<div class="valignmiddle inline-block info-box-actions">';
2887 $return .= '<div class="valignmiddle inline-block info-box-setup">';
2888 $return .= $codetoconfig;
2889 $return .= '</div>';
2890 $return .= '<div class="valignmiddle inline-block marginleftonly marginrightonly">';
2891 $return .= $codeenabledisable;
2892 $return .= '</div>';
2893 $return .= '</div>';
2894
2895 $return .= '
2896 </div><!-- /.info-box-content -->
2897 </div><!-- /.info-box -->
2898 </div>';
2899
2900 return $return;
2901 }
2902
2911 public function checkForUpdate()
2912 {
2913 require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
2914 if (!empty($this->url_last_version)) {
2915 $lastVersion = getURLContent($this->url_last_version, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only
2916 if (isset($lastVersion['content']) && strlen($lastVersion['content']) < 30) {
2917 // 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 _ . -
2918 $this->lastVersion = preg_replace("/[^a-zA-Z0-9_\.\-]+/", "", $lastVersion['content']);
2919 if (version_compare($this->lastVersion, $this->version) > 0) {
2920 $this->needUpdate = true;
2921 return 1;
2922 } else {
2923 $this->needUpdate = false;
2924 return 0;
2925 }
2926 } else {
2927 return -1;
2928 }
2929 }
2930 return 0;
2931 }
2932
2940 public function checkForCompliance($nametocheck = '')
2941 {
2942 global $conf, $langs;
2943
2944 if (empty($nametocheck)) {
2945 $nametocheck = $this->name;
2946 }
2947
2948 // Get list of illegal modules name or ID
2949 if (empty($conf->cache['noncompliantmodules'])) {
2950 require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
2951
2952 $result = getURLContent(self::URL_FOR_BLACKLISTED_MODULES, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only
2953 if (isset($result['content']) && $result['http_code'] == 200) {
2954 $langs->load("errors");
2955
2956 // 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 _ . -
2957 $arrayoflines = preg_split("/[\n,]/", $result['content']);
2958 foreach ($arrayoflines as $line) {
2959 $tmpfieldsofline = explode(';', $line);
2960 $modulekey = strtolower(trim($tmpfieldsofline[0]));
2961 if (empty($modulekey)) {
2962 continue;
2963 }
2964 $conf->cache['noncompliantmodules'][$modulekey]['name'] = trim($tmpfieldsofline[0]);
2965 $conf->cache['noncompliantmodules'][$modulekey]['id'] = (isset($tmpfieldsofline[1]) ? trim($tmpfieldsofline[1]) : '');
2966 $conf->cache['noncompliantmodules'][$modulekey]['signature'] = (isset($tmpfieldsofline[2]) ? trim($tmpfieldsofline[2]) : '');
2967 $conf->cache['noncompliantmodules'][$modulekey]['message'] = $langs->trans(empty(isset($tmpfieldsofline[3]) ? trim($tmpfieldsofline[3]) : '') ? 'WarningModuleAffiliatedToAReportedCompany' : trim($tmpfieldsofline[3]));
2968 if (!empty($tmpfieldsofline[4])) {
2969 $message2 = $langs->trans("WarningModuleAffiliatedToAPiratPlatform", '{s}');
2970 $listofillegalurl = '';
2971 foreach (explode(" ", $tmpfieldsofline[4]) as $illegalurl) {
2972 $listofillegalurl .= ($listofillegalurl ? ' '.$langs->trans("or").' ' : '').'<b>'.preg_replace('/[^a-z0-9\.\-]/', '', $illegalurl).'</b>';
2973 }
2974 $message2 = str_replace('{s}', $listofillegalurl, $message2);
2975 $conf->cache['noncompliantmodules'][$modulekey]['message2'] = $message2;
2976 }
2977 }
2978 }
2979 }
2980
2981 if (!empty($conf->cache['noncompliantmodules'])) {
2982 $modulekey = strtolower($nametocheck);
2983 if (in_array($modulekey, array_keys($conf->cache['noncompliantmodules']))) {
2984 $answer = trim($conf->cache['noncompliantmodules'][$modulekey]['message']);
2985 if (!empty($conf->cache['noncompliantmodules'][$modulekey]['message2'])) {
2986 $answer .= '<br>'.$conf->cache['noncompliantmodules'][$modulekey]['message2'];
2987 }
2988 return $answer;
2989 }
2990 }
2991
2992 return 0;
2993 }
2994
3013 protected function declareNewDictionary($dictionaryArray, $langs = '')
3014 {
3015 $fields = array('name', 'lib', 'sql', 'sqlsort', 'field', 'fieldvalue', 'fieldinsert', 'rowid', 'cond', 'help', 'fieldcheck');
3016
3017 foreach ($fields as $field) {
3018 if (isset($dictionaryArray[$field])) {
3019 // @phan-suppress-next-line PhanTypeMismatchProperty
3020 $this->dictionaries['tab'.$field][] = $dictionaryArray[$field];
3021 }
3022 }
3023 if ($langs && !in_array($langs, $this->dictionaries[$langs])) {
3024 $this->dictionaries['langs'][] = $langs;
3025 }
3026 }
3027}
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Cron Job class.
Class DolibarrModules.
delete_permissions()
Removes access rights.
getImportDatasetLabel($r)
Gives translated label of an import dataset.
_init($array_sql, $options='')
Enables a module.
getLastActivationDate()
Gives the last date of activation.
delete_cronjobs()
Removes boxes.
getKanbanView($codeenabledisable='', $codetoconfig='')
Return Kanban view of a module.
getModulePosition()
Gives the module position.
insert_const()
Adds constants.
__construct($db)
Constructor.
delete_boxes()
Removes boxes.
isCoreOrExternalModule()
Tells if module is core or external.
getDescLongReadmeFound()
Return path of file if a README file was found.
delete_menus()
Removes menu entries.
delete_const()
Removes constants tagged 'deleteonunactive'.
_active()
Insert constants for module activation.
_remove($array_sql, $options='')
Disable function.
getDescLong()
Gives the long description of a module.
insert_boxes($option='')
Adds boxes.
getDesc($foruseinpopupdesc=0)
Gives the translated module description if translation exists in admin.lang or the default module des...
getModuleInfoByRightsClass($rightsclass)
Look up the family and module_position of another module by its rights_class, so a right filed under ...
getPublisher()
Gives the publisher name.
getChangeLog()
Gives the changelog.
insert_cronjobs()
Adds cronjobs.
create_dirs()
Creates directories.
delete_module_parts()
Removes generic parts.
insert_permissions($reinitadminperms=0, $force_entity=null, $notrigger=0, $existingrightsdefids=null)
Adds access rights.
getVersion($translated=1)
Gives module version (translated if param $translated is on) For 'experimental' modules,...
insert_overwrite_translation()
Adds overwrite translations.
_unactive()
Module deactivation.
getExportDatasetLabel($r)
Gives translated label of an export dataset.
getName()
Gives the translated module name if translation exists in admin.lang or into language files of module...
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
insert_dirs($name, $dir)
Adds directories definitions.
getLangFilesArray()
Gives module related language files list.
insert_menus()
Adds menu entries.
insert_module_parts()
Save configuration for generic features.
getPublisherUrl()
Gives the publisher url.
getLastActivationInfo()
Gives the last author of activation.
delete_dirs()
Removes directories.
init($options='')
Function called when module is enabled.
static getListOfPagesForBoxes()
Name of positions (See below)
Class to manage menu entries.
Class to manage Dolibarr users.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:66
dolGetModulesDirs($subdir='')
Return list of directories that contain modules.
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
$conf browser version
Definition main.inc.php:229
dolMd2Html($content, $parser='parsedown', $replaceimagepath=null)
Function to parse MD content into HTML.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165