70 public $editor_squarred_logo;
98 public $module_position =
'50';
115 public $dirs = array();
120 public $boxes = array();
126 public $const = array();
131 public $overwrite_translation = array();
136 public $cronjobs = array();
146 public $rights_admin_allowed;
151 public $rights_class;
153 const URL_FOR_BLACKLISTED_MODULES =
'https://www.dolibarr.org/modules-blacklist.php';
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;
167 public $menu = array();
196 public $module_parts = array();
223 public $version_if_core = 0;
229 public $lastVersion =
'';
235 public $needUpdate =
false;
250 public $descriptionlong;
255 public $dictionaries = array();
272 public $export_label;
282 public $export_enabled;
286 public $export_permission;
290 public $export_fields_array;
294 public $export_TypeFields_array;
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;
324 public $export_dependencies_array;
328 public $export_sql_start;
332 public $export_sql_end;
336 public $export_sql_order;
349 public $import_label;
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;
416 public $always_enabled;
426 public $automatic_activation = array();
431 public $core_enabled;
447 public $config_page_url;
470 public $conflictwith;
482 public $warnings_activation;
489 public $warnings_activation_ext;
496 public $warnings_unactivation;
513 public $need_dolibarr_version;
519 public $max_dolibarr_version;
524 public $need_javascript_ajax;
529 public $enabled_bydefault;
534 public $hidden =
false;
539 public $url_last_version;
568 protected function _init($array_sql, $options =
'')
592 if (!$err && !preg_match(
'/newboxdefonly/', $options)) {
597 if (!$err && !preg_match(
'/newboxdefonly/', $options)) {
602 if (!$err && !preg_match(
'/noboxes/', $options)) {
627 $num = count($array_sql);
628 for ($i = 0; $i < $num; $i++) {
630 $sql = $array_sql[$i];
633 if (is_array($val)) {
635 $ignoreerror = $val[
'ignoreerror'] ?? 0;
638 $sql = str_replace(
'__ENTITY__', (
string) ((
int)
$conf->entity), $sql);
640 dol_syslog(get_class($this).
"::_init ignoreerror=".$ignoreerror, LOG_DEBUG);
641 $result = $this->db->query($sql, $ignoreerror);
644 $this->error = $this->db->lasterror();
647 dol_syslog(get_class($this).
"::_init Warning ".$this->db->lasterror(), LOG_WARNING);
657 $moduleNameInConf = strtolower(preg_replace(
'/^MAIN_MODULE_/',
'', $this->const_name));
659 if ($moduleNameInConf ===
'propale') {
660 $moduleNameInConf =
'propal';
661 } elseif ($moduleNameInConf ===
'supplierproposal') {
662 $moduleNameInConf =
'supplier_proposal';
665 $conf->modules[$moduleNameInConf] = $moduleNameInConf;
669 $this->db->rollback();
683 protected function _remove($array_sql, $options =
'')
712 if (!$err && !preg_match(
'/(newboxdefonly|noboxes)/', $options)) {
737 $num = count((array) $array_sql);
738 for ($i = 0; $i < $num; $i++) {
740 dol_syslog(get_class($this).
"::_remove", LOG_DEBUG);
741 $result = $this->db->query($array_sql[$i]);
743 $this->error = $this->db->error();
754 $moduleNameInConf = strtolower(preg_replace(
'/^MAIN_MODULE_/',
'', $this->const_name));
756 if ($moduleNameInConf ===
'propale') {
757 $moduleNameInConf =
'propal';
758 } elseif ($moduleNameInConf ===
'supplierproposal') {
759 $moduleNameInConf =
'supplier_proposal';
762 unset(
$conf->modules[$moduleNameInConf]);
766 $this->db->rollback();
781 $langs->load(
"admin");
783 if ($langs->transnoentitiesnoconv(
"Module".$this->numero.
"Name") !=
"Module".$this->numero.
"Name") {
785 return $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Name");
788 if (is_array($this->langfiles)) {
789 foreach ($this->langfiles as $val) {
796 if ($langs->trans(
"Module".$this->name.
"Name") !=
"Module".$this->name.
"Name") {
798 return $langs->transnoentitiesnoconv(
"Module".$this->
name.
"Name");
802 return $langs->transnoentitiesnoconv($this->
name);
813 public function getDesc($foruseinpopupdesc = 0)
816 $langs->load(
"admin");
818 if ($langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc") !=
"Module".$this->numero.
"Desc") {
820 return $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc");
823 if (is_array($this->langfiles)) {
824 foreach ($this->langfiles as $val) {
831 if ($langs->transnoentitiesnoconv(
"Module".$this->name.
"Desc") !=
"Module".$this->name.
"Desc") {
833 return $langs->trans(
"Module".$this->
name.
"Desc");
850 $langs->load(
"admin");
852 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
853 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
859 $content = file_get_contents($pathoffile,
false,
null, 0, 1024 * 1024);
861 if ((
float) DOL_VERSION >= 6.0) {
862 @include_once DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
874 $content = preg_replace(
'/<a href="/',
'<a target="_blank" rel="noopener noreferrer" href="', $content);
876 $content = nl2br($content);
880 if (!empty($this->descriptionlong)) {
881 if (is_array($this->langfiles)) {
882 foreach ($this->langfiles as $val) {
889 $content = $langs->transnoentitiesnoconv($this->descriptionlong);
893 return '<div class="moduledesclong">'.$content.
'</div>';
909 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/README-'.$langs->defaultlang.
'.md', 0);
914 $tmp = explode(
'_', $langs->defaultlang);
915 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/README-'.$tmp[0].
'.md', 0);
927 return ($filefound ? $pathoffile :
'');
939 $langs->load(
"admin");
941 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
942 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
948 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/ChangeLog-'.$langs->defaultlang.
'.md', 0);
960 $content = file_get_contents($pathoffile);
962 if ((
float) DOL_VERSION >= 6.0) {
963 @include_once DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
967 $content = nl2br($content);
983 return $this->editor_name;
993 return $this->editor_url;
1007 $langs->load(
"admin");
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') {
1018 } elseif ($newversion) {
1021 $ret = ($translated ? $langs->transnoentitiesnoconv(
"VersionUnknown") :
'unknown');
1024 if (preg_match(
'/_deprecated/', $this->
version)) {
1025 $ret .= ($translated ?
' ('.$langs->transnoentitiesnoconv(
"Deprecated").
')' : $this->version);
1037 if (in_array($this->
version, array(
'dolibarr',
'dolibarr_deprecated',
'experimental',
'development'))) {
1038 return $this->module_position;
1040 if ($this->module_position >= 100000) {
1041 return $this->module_position;
1043 $position = intval($this->module_position) + 100000;
1044 return strval($position);
1057 if ($this->
version ==
'dolibarr' || $this->
version ==
'dolibarr_deprecated') {
1060 if (!empty($this->
version) && !in_array($this->
version, array(
'experimental',
'development')) && empty($this->version_if_core)) {
1063 if (!empty($this->editor_name) || !empty($this->editor_url) && empty($this->version_if_core)) {
1066 if ($this->numero >= 100000) {
1080 return $this->langfiles;
1094 $langstring =
"ExportDataset_".$this->export_code[$r];
1095 if ($langs->trans($langstring) == $langstring) {
1097 return $langs->trans($this->export_label[$r]);
1100 return $langs->trans($langstring);
1116 $langstring =
"ImportDataset_".$this->import_code[$r];
1118 if ($langs->trans($langstring) == $langstring) {
1120 return $langs->transnoentitiesnoconv($this->import_label[$r]);
1123 return $langs->transnoentitiesnoconv($langstring);
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).
")";
1143 dol_syslog(get_class($this).
"::getLastActiveDate", LOG_DEBUG);
1144 $resql = $this->db->query($sql);
1148 $obj = $this->db->fetch_object($resql);
1150 return $this->db->jdate($obj->tms);
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).
")";
1173 dol_syslog(get_class($this).
"::getLastActiveDate", LOG_DEBUG);
1174 $resql = $this->db->query($sql);
1178 $obj = $this->db->fetch_object($resql);
1182 $tmp = json_decode($obj->note,
true);
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'),
1206 global
$conf, $user;
1211 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 :
$conf->entity);
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).
")";
1217 dol_syslog(get_class($this).
"::_active delete activation constant", LOG_DEBUG);
1218 $resql = $this->db->query($sql);
1223 $note = json_encode(
1225 'authorid' => (is_object($user) ? $user->id : 0),
1226 'ip' => (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']),
1227 'lastactivationversion' => $this->
version,
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).
"')";
1237 dol_syslog(get_class($this).
"::_active insert activation constant", LOG_DEBUG);
1238 $resql = $this->db->query($sql);
1261 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 :
$conf->entity);
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).
")";
1267 dol_syslog(get_class($this).
"::_unactive", LOG_DEBUG);
1268 $this->db->query($sql);
1302 if (empty($reldir)) {
1306 include_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
1308 foreach (
$conf->file->dol_document_root as $dirroot) {
1310 $dirsql = $dirroot.$reldir;
1314 $listofsubdir = array(
'',
'tables/',
'data/');
1315 if ($this->db->type ==
'pgsql') {
1316 $listofsubdir[] =
'../pgsql/functions/';
1319 foreach ($listofsubdir as $subdir) {
1320 $dir = $dirsql.$subdir;
1322 $handle = @opendir($dir);
1323 if (is_resource($handle)) {
1328 while (($file = readdir($handle)) !==
false) {
1332 foreach ($files as $file) {
1333 if ($onlywithsuffix) {
1334 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1341 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) &&
dol_substr($file, 0, 4) ==
'llx_') {
1353 while (($file = readdir($handle)) !==
false) {
1357 foreach ($files as $file) {
1358 if ($onlywithsuffix) {
1359 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1366 if (preg_match(
'/\.key\.sql$/i', $file) &&
dol_substr($file, 0, 4) ==
'llx_') {
1378 while (($file = readdir($handle)) !==
false) {
1382 foreach ($files as $file) {
1383 if ($onlywithsuffix) {
1384 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1391 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) &&
dol_substr($file, 0, 9) ==
'functions') {
1403 while (($file = readdir($handle)) !==
false) {
1407 foreach ($files as $file) {
1408 if ($onlywithsuffix) {
1409 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1416 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) &&
dol_substr($file, 0, 4) ==
'data') {
1428 while (($file = readdir($handle)) !==
false) {
1432 foreach ($files as $file) {
1433 if ($onlywithsuffix) {
1434 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1442 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) &&
dol_substr($file, 0, 6) ==
'update') {
1461 dol_syslog(
"A module wants to load sql files from ".$reldir.
" but this directory was not found.", LOG_WARNING);
1478 include_once DOL_DOCUMENT_ROOT.
'/core/class/infobox.class.php';
1484 if (is_array($this->boxes)) {
1485 dol_syslog(get_class($this).
"::insert_boxes", LOG_DEBUG);
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';
1495 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] :
'';
1498 $note = isset($this->boxes[$key][2]) ? $this->boxes[$key][2] :
'';
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);
1506 $sql .=
" AND note ='".$this->db->escape($note).
"'";
1509 $result = $this->db->query($sql);
1511 $obj = $this->db->fetch_object($result);
1512 if ($obj->nb == 0) {
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";
1522 dol_syslog(get_class($this).
"::insert_boxes", LOG_DEBUG);
1523 $resql = $this->db->query($sql);
1528 if (!$err && !preg_match(
'/newboxdefonly/', $option)) {
1529 $lastid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"boxes_def",
"rowid");
1531 foreach ($pos_name as $key2 => $val2) {
1533 if ($enabledbydefaulton && $val2 != $enabledbydefaulton) {
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).
")";
1540 dol_syslog(get_class($this).
"::insert_boxes onto page ".$key2.
"=".$val2, LOG_DEBUG);
1541 $resql = $this->db->query($sql);
1549 $this->db->commit();
1551 $this->error = $this->db->lasterror();
1552 $this->db->rollback();
1557 $this->error = $this->db->lasterror();
1580 if (is_array($this->boxes)) {
1581 foreach ($this->boxes as $key => $value) {
1583 if (empty($this->boxes[$key][
'file'])) {
1584 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] :
'';
1586 $file = $this->boxes[$key][
'file'];
1594 if ($file ==
'box_graph_product_distribution.php') {
1596 dol_syslog(
"We discard deleting module ".$file.
" because another module still active requires it.");
1601 if ($this->db->type ==
'sqlite3') {
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);
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);
1618 dol_syslog(get_class($this).
"::delete_boxes", LOG_DEBUG);
1619 $resql = $this->db->query($sql);
1621 $this->error = $this->db->lasterror();
1625 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes_def";
1626 $sql .=
" WHERE file = '".$this->db->escape($file).
"'";
1627 $sql .=
" AND entity = ".((int)
$conf->entity);
1629 dol_syslog(get_class($this).
"::delete_boxes", LOG_DEBUG);
1630 $resql = $this->db->query($sql);
1632 $this->error = $this->db->lasterror();
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';
1654 global
$conf, $user;
1657 $user =
new User($this->db);
1662 if (is_array($this->cronjobs)) {
1663 dol_syslog(get_class($this) .
"::insert_cronjobs", LOG_DEBUG);
1665 foreach ($this->cronjobs as $key => $value) {
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'] :
'';
1690 $sql =
"SELECT count(*) as nb FROM " . MAIN_DB_PREFIX .
"cronjob";
1692 $sql .=
" WHERE label = '".$this->db->escape($label).
"'";
1710 $sql .=
" AND entity = " . ((int) $entity);
1712 $result = $this->db->query($sql);
1714 $this->error = $this->db->lasterror();
1720 $obj = $this->db->fetch_object($result);
1725 $cronjob =
new Cronjob($this->db);
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;
1749 $retCreate = $cronjob->create($user);
1751 if ($retCreate < 0) {
1752 $this->error = implode(
"\n", array_merge([$cronjob->error], $cronjob->errors));
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'";
1781 dol_syslog(get_class($this).
"::delete_cronjobs", LOG_DEBUG);
1782 $resql = $this->db->query($sql);
1784 $this->error = $this->db->lasterror();
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);
1809 dol_syslog(get_class($this).
"::delete_tabs", LOG_DEBUG);
1810 if (!$this->db->query($sql)) {
1811 $this->error = $this->db->lasterror();
1831 if (!empty($this->tabs)) {
1832 dol_syslog(get_class($this).
"::insert_tabs", LOG_DEBUG);
1835 foreach ($this->tabs as $key => $value) {
1836 if (is_array($value) && count($value) == 0) {
1840 $entity =
$conf->entity;
1843 if (is_array($value)) {
1844 $newvalue = $value[
'data'];
1845 if (isset($value[
'entity'])) {
1846 $entity = $value[
'entity'];
1851 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (";
1856 $sql .=
", visible";
1859 $sql .=
" VALUES (";
1860 $sql .= $this->db->encrypt($this->const_name.
"_TABS_".$i);
1861 $sql .=
", 'chaine'";
1862 $sql .=
", ".$this->db->encrypt($newvalue);
1865 $sql .=
", ".((int) $entity);
1868 $resql = $this->db->query($sql);
1871 if ($this->db->lasterrno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1872 $this->error = $this->db->lasterror();
1873 $this->errors[] = $this->db->lasterror();
1898 if (empty($this->
const)) {
1904 foreach ($this->
const as $key => $value) {
1906 $name = $this->
const[$key][0];
1907 $entity = (!empty($this->
const[$key][5]) && $this->
const[$key][5] !=
'current') ? 0 :
$conf->entity;
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;
1916 if (empty($visible)) {
1919 if (empty($val) && $val !=
'0') {
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);
1929 $result = $this->db->query($sql);
1931 $row = $this->db->fetch_row($result);
1934 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name, type, value, note, visible, entity)";
1935 $sql .=
" VALUES (";
1936 $sql .= $this->db->encrypt($name);
1937 $sql .=
", '".$this->db->escape($type).
"'";
1938 $sql .=
", ".(($val !=
'') ? $this->db->encrypt($val) :
"''");
1939 $sql .=
", ".($note ?
"'".$this->db->escape($note).
"'" :
"null");
1940 $sql .=
", '".$this->db->escape($visible).
"'";
1941 $sql .=
", ".((int) $entity);
1944 if (!$this->db->query($sql)) {
1948 $conf->global->$name = $val;
1951 dol_syslog(__METHOD__.
" constant '".$name.
"' already exists", LOG_DEBUG);
1975 if (empty($this->
const)) {
1979 foreach ($this->
const as $key => $value) {
1980 $name = $this->
const[$key][0];
1981 $deleteonunactive = (!empty($this->
const[$key][6])) ? 1 : 0;
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();
2011 if (empty($this->overwrite_translation)) {
2015 dol_syslog(get_class($this).
"::insert_overwrite_translation", LOG_DEBUG);
2017 foreach ($this->overwrite_translation as $key => $value) {
2018 $arkey = explode(
':', $key);
2020 $transkey = $arkey[1];
2021 $transvalue = $value;
2022 $entity = (!empty($arkey[3]) && $arkey[3] !=
'current') ? 0 :
$conf->entity;
2025 if (empty($lang) || empty($transkey) || empty($transvalue)) {
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);
2034 $result = $this->db->query($sql);
2036 $row = $this->db->fetch_row($result);
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).
"'";
2047 if (!$this->db->query($sql)) {
2051 dol_syslog(get_class($this).
"::insert_overwrite_translation overwrite trans for key $transkey already exists", LOG_DEBUG);
2074 public function insert_permissions($reinitadminperms = 0, $force_entity =
null, $notrigger = 0, $existingrightsdefids =
null)
2077 global
$conf, $langs, $user;
2080 $skippedperms = array();
2081 $entity = (!empty($force_entity) ? $force_entity :
$conf->entity);
2083 dol_syslog(get_class($this).
"::insert_permissions", LOG_DEBUG);
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).
")";
2091 $resql = $this->db->query($sql_del);
2094 $obj = $this->db->fetch_object($resql);
2096 if ($obj !==
null && !empty($obj->value) && !empty($this->rights)) {
2097 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
2100 foreach ($this->rights as $key => $value) {
2101 $r_id = $this->rights[$key][self::KEY_ID];
2102 $r_label = $this->rights[$key][self::KEY_LABEL];
2103 $r_type = $this->rights[$key][self::KEY_TYPE] ??
'w';
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] ??
'';
2109 if (empty($r_perms)) {
2114 $r_module = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2117 $r_module_origin =
'';
2119 if (isset($this->rights[$key][self::KEY_MODULE])) {
2121 $r_module = $this->rights[$key][self::KEY_MODULE];
2123 $r_module_origin = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2126 if (!empty($r_module_origin) && $r_module !== $r_module_origin) {
2132 $r_module_position = $r_targetmoduleinfo[
'position'];
2133 $r_family = $r_targetmoduleinfo[
'family'];
2136 $r_family = $this->family;
2138 $r_family_position = 0;
2141 $r_enabled = $this->rights[$key][self::KEY_ENABLED] ??
'1';
2144 if ($existingrightsdefids !==
null) {
2145 $rightalreadyexists = !empty($existingrightsdefids[$r_id]);
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);
2151 $rightalreadyexists =
true;
2152 $resqlselect = $this->db->query($sql);
2154 $objcount = $this->db->fetch_object($resqlselect);
2155 $rightalreadyexists = !($objcount && $objcount->nb == 0);
2156 $this->db->free($resqlselect);
2160 if (!$rightalreadyexists) {
2161 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"rights_def (";
2164 $sql .=
", libelle";
2166 $sql .=
", module_origin";
2167 $sql .=
", module_position";
2169 $sql .=
", family_position";
2171 $sql .=
", bydefault";
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).
"'";
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).
"'";
2191 $resqlinsert = $this->db->query($sql, 1);
2193 if (!$resqlinsert) {
2194 if ($this->db->errno() !=
"DB_ERROR_RECORD_ALREADY_EXISTS") {
2195 $this->error = $this->db->lasterror();
2199 dol_syslog(get_class($this).
"::insert_permissions record already exists", LOG_INFO);
2203 $this->db->free($resqlinsert);
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).
"'";
2212 $resqlowner = $this->db->query($sql);
2214 $objowner = $this->db->fetch_object($resqlowner);
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);
2219 $this->db->free($resqlowner);
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);
2228 $resqlseladmin = $this->db->query($sql, 1);
2230 if ($resqlseladmin) {
2231 $num = $this->db->num_rows($resqlseladmin);
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);
2237 $tmpuser =
new User($this->db);
2238 $result = $tmpuser->fetch($obj2->rowid);
2240 $tmpuser->addrights($r_id,
'',
'', 0, 1);
2242 dol_syslog(get_class($this).
"::insert_permissions Failed to add the permission to user because fetch return an error", LOG_ERR);
2247 dol_print_error($this->db);
2252 if (!empty($reinitadminperms) && !empty($user->admin)) {
2254 $user->clearrights();
2255 $user->loadRights();
2258 if (!empty($skippedperms)) {
2259 $langs->load(
"admin");
2260 $listofperms = array();
2261 foreach ($skippedperms as $tmpid => $tmpperm) {
2262 $listofperms[] = $tmpid.
" (".$tmpperm.
")";
2264 setEventMessages($langs->trans(
"WarningPermissionIdsAlreadyUsed", $this->name, implode(
", ", $listofperms)),
null,
"warnings");
2267 $this->db->free($resql);
2269 $this->error = $this->db->lasterror();
2291 if (isset(
$conf->cache[
'keyModuleInfoCache'][$rightsclass])) {
2292 return $conf->cache[
'keyModuleInfoCache'][$rightsclass];
2297 $result = array(
'family' => $this->family,
'position' => (
int) $this->
getModulePosition());
2300 foreach ($modulesdir as $dir) {
2302 if (is_resource($handle)) {
2303 while (($file = readdir($handle)) !==
false) {
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());
2324 $conf->cache[
'keyModuleInfoCache'][$rightsclass] = $result;
2343 $module = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
2345 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"rights_def";
2346 $sql .=
" WHERE (module = '".$this->db->escape(
$module).
"' OR module_origin = '".$this->db->escape(
$module).
"')";
2349 if (empty($this->core_enabled)) {
2350 $sql .=
" AND entity = ".((int)
$conf->entity);
2353 dol_syslog(get_class($this).
"::delete_permissions", LOG_DEBUG);
2354 if (!$this->db->query($sql)) {
2355 $this->error = $this->db->lasterror();
2372 global
$conf, $user;
2374 if (!is_array($this->menu) || empty($this->menu)) {
2378 include_once DOL_DOCUMENT_ROOT.
'/core/class/menubase.class.php';
2380 dol_syslog(get_class($this).
"::insert_menus", LOG_DEBUG);
2385 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 :
$conf->entity);
2389 foreach ($this->menu as $key => $value) {
2391 $menu->menu_handler =
'all';
2394 $menu->module = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2396 if (!$this->menu[$key][
'fk_menu']) {
2400 $fk_parent = $this->menu[$key][
'fk_menu'];
2402 if (preg_match(
'/^r=/', $fk_parent)) {
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'];
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];
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 =
'';
2419 if (!$foundparent) {
2420 $this->error =
"ErrorBadDefinitionOfMenuArrayInModuleDescriptor";
2421 dol_syslog(get_class($this).
"::insert_menus ".$this->error.
" ".$this->menu[$key][
'fk_menu'], LOG_ERR);
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;
2441 $result = $menu->create($user);
2443 $this->menu[$key][
'rowid'] = $result;
2445 $this->error = $menu->error;
2446 dol_syslog(get_class($this).
'::insert_menus result='.$result.
" ".$this->error, LOG_ERR);
2454 $this->db->commit();
2456 dol_syslog(get_class($this).
"::insert_menus ".$this->error, LOG_ERR);
2457 $this->db->rollback();
2478 $module = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
2480 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"menu";
2481 $sql .=
" WHERE module = '".$this->db->escape(
$module).
"'";
2482 $sql .=
" AND menu_handler = 'all'";
2483 $sql .=
" AND entity IN (0, ".((int)
$conf->entity).
")";
2485 dol_syslog(get_class($this).
"::delete_menus", LOG_DEBUG);
2486 $resql = $this->db->query($sql);
2488 $this->error = $this->db->lasterror();
2504 global $langs,
$conf;
2509 if (isset($this->dirs) && is_array($this->dirs)) {
2510 foreach ($this->dirs as $key => $value) {
2513 if (!is_array($value)) {
2516 $constname = $this->const_name.
"_DIR_";
2517 $dir = $this->dirs[$key][1];
2518 $addtodatabase = empty($this->dirs[$key][2]) ?
'' : $this->dirs[$key][2];
2519 $subname = empty($this->dirs[$key][3]) ?
'' : strtoupper($this->dirs[$key][3]);
2520 $forcename = empty($this->dirs[$key][4]) ?
'' : strtoupper($this->dirs[$key][4]);
2522 if (!empty($forcename)) {
2523 $constname =
'MAIN_MODULE_'.$forcename.
"_DIR_";
2525 if (!empty($subname)) {
2526 $constname = $constname.$subname.
"_";
2529 $name = $constname.strtoupper($this->dirs[$key][0]);
2534 $fulldir = DOL_DATA_ROOT.$dir;
2536 $fulldir = DOL_DATA_ROOT.
"/".
$conf->entity.$dir;
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);
2548 if (!empty($addtodatabase) && !empty($name)) {
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);
2582 dol_syslog(get_class($this).
"::insert_dirs", LOG_DEBUG);
2583 $result = $this->db->query($sql);
2585 $row = $this->db->fetch_row($result);
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).
")";
2591 dol_syslog(get_class($this).
"::insert_dirs", LOG_DEBUG);
2592 $this->db->query($sql);
2595 $this->error = $this->db->lasterror();
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);
2620 dol_syslog(get_class($this).
"::delete_dirs", LOG_DEBUG);
2621 if (!$this->db->query($sql)) {
2622 $this->error = $this->db->lasterror();
2639 global
$conf, $langs;
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;
2648 foreach ($this->module_parts as $key => $value) {
2649 if (is_array($value) && count($value) == 0) {
2654 if ($key ==
'websitetemplates' && $value == 1) {
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'];
2668 $result = dol_compress_dir($src, $dest.
'.zip',
'zip');
2671 $this->error = ($errormsg ? $errormsg : $langs->trans(
'ErrorFailToCreateZip', $dest));
2672 $this->errors[] = ($errormsg ? $errormsg : $langs->trans(
'ErrorFailToCreateZip', $dest));
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'];
2686 $entity =
$conf->entity;
2690 if (is_array($value)) {
2693 if (isset($value[
'data']) && is_array($value[
'data'])) {
2694 $newvalue = json_encode($value[
'data']);
2695 if (isset($value[
'entity'])) {
2696 $entity = $value[
'entity'];
2698 } elseif (isset($value[
'data']) && !is_array($value[
'data'])) {
2699 $newvalue = $value[
'data'];
2700 if (isset($value[
'entity'])) {
2701 $entity = $value[
'entity'];
2704 $newvalue = json_encode($value);
2708 if (!empty($newvalue)) {
2709 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (";
2714 $sql .=
", visible";
2717 $sql .=
" VALUES (";
2718 $sql .=
" ".$this->db->encrypt($this->const_name.
"_".strtoupper($key), 1);
2719 $sql .=
", 'chaine'";
2720 $sql .=
", ".$this->db->encrypt($newvalue, 1);
2723 $sql .=
", ".((int) $entity);
2726 dol_syslog(get_class($this).
"::insert_module_parts for key=".$this->const_name.
"_".strtoupper($key), LOG_DEBUG);
2728 $resql = $this->db->query($sql, 1);
2730 if ($this->db->lasterrno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2732 $this->error = $this->db->lasterror();
2734 dol_syslog(get_class($this).
"::insert_module_parts for ".$this->const_name.
"_".strtoupper($key).
" Record already exists.", LOG_WARNING);
2756 if (is_array($this->module_parts)) {
2757 dol_syslog(get_class($this).
"::delete_module_parts", LOG_DEBUG);
2759 if (empty($this->module_parts[
'icon']) && !empty($this->picto) && preg_match(
'/^fa\-/', $this->picto)) {
2760 $this->module_parts[
'icon'] = $this->picto;
2763 foreach ($this->module_parts as $key => $value) {
2765 if (is_array($value) && isset($value[
'entity'])) {
2766 $entity = $value[
'entity'];
2768 $entity =
$conf->entity;
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);
2775 if (!$this->db->query($sql)) {
2776 $this->error = $this->db->lasterror();
2793 public function init($options =
'')
2795 return $this->
_init(array(), $options);
2806 public function remove($options =
'')
2808 return $this->
_remove(array(), $options);
2826 $imginfo =
"info_black";
2829 $const_name =
'MAIN_MODULE_'.strtoupper(preg_replace(
'/^mod/i',
'', get_class($this)));
2833 if (preg_match(
'/development/i', $version)) {
2834 $versiontrans .=
'warning';
2836 if (preg_match(
'/experimental/i', $version)) {
2837 $versiontrans .=
'warning';
2839 if (preg_match(
'/deprecated/i', $version)) {
2840 $versiontrans .=
'warning';
2844 <div class="box-flex-item info-box-module'
2845 .(getDolGlobalString($const_name) ?
'' :
' --disabled')
2847 .($this->needUpdate ?
' --need-update' :
'')
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' :
'')).
'">';
2855 if (!empty($this->picto)) {
2856 if (preg_match(
'/^\//i', $this->picto)) {
2857 $return .= img_picto($alttext, $this->picto,
'class="inline-block valignmiddle"', 1);
2859 $return .= img_object($alttext, $this->picto,
'class="inline-block valignmiddle"');
2862 $return .= img_object($alttext,
'generic',
'class="inline-block valignmiddle"');
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;
2871 $return .=
'<span class="info-box-icon-version'.($versiontrans ?
' '.$versiontrans :
'').
' classfortooltip" title="'.dolPrintHTMLForAttribute($versionTitle).
'" >';
2873 $return .=
'</span>';
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>
2881 $return .=
'<div class="valignmiddle inline-block info-box-more">';
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>';
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>';
2896 </div><!-- /.info-box-content -->
2897 </div><!-- /.info-box -->
2911 public function checkForUpdate()
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;
2923 $this->needUpdate = false;
2940 public function checkForCompliance($nametocheck = '')
2942 global $conf, $langs;
2944 if (empty($nametocheck)) {
2945 $nametocheck = $this->name;
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';
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
");
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)) {
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>';
2974 $message2 = str_replace('{s}', $listofillegalurl, $message2);
2975 $conf->cache['noncompliantmodules'][$modulekey]['message2'] = $message2;
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'];
3013 protected function declareNewDictionary($dictionaryArray, $langs = '')
3015 $fields = array('name', 'lib', 'sql', 'sqlsort', 'field', 'fieldvalue', 'fieldinsert', 'rowid', 'cond', 'help', 'fieldcheck');
3017 foreach ($fields as $field) {
3018 if (isset($dictionaryArray[$field])) {
3019 // @phan-suppress-next-line PhanTypeMismatchProperty
3020 $this->dictionaries['tab'.$field][] = $dictionaryArray[$field];
3023 if ($langs && !in_array($langs, $this->dictionaries[$langs])) {
3024 $this->dictionaries['langs'][] = $langs;
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:
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.
delete_tabs()
Removes tabs.
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 Dolibarr users.
if(! $sortfield) if(! $sortorder) $module
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.
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)
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.