64 public $editor_squarred_logo;
92 public $module_position =
'50';
109 public $dirs = array();
114 public $boxes = array();
120 public $const = array();
125 public $cronjobs = array();
135 public $rights_admin_allowed;
140 public $rights_class;
142 const URL_FOR_BLACKLISTED_MODULES =
'https://www.dolibarr.org/modules-blacklist.php';
147 const KEY_DEFAULT = 3;
148 const KEY_FIRST_LEVEL = 4;
149 const KEY_SECOND_LEVEL = 5;
150 const KEY_MODULE = 6;
151 const KEY_ENABLED = 7;
156 public $menu = array();
185 public $module_parts = array();
212 public $version_if_core = 0;
218 public $lastVersion =
'';
224 public $needUpdate =
false;
239 public $descriptionlong;
244 public $dictionaries = array();
261 public $export_label;
271 public $export_enabled;
275 public $export_permission;
279 public $export_fields_array;
283 public $export_TypeFields_array;
287 public $export_entities_array;
291 public $export_aggregate_array;
295 public $export_examplevalues_array;
299 public $export_help_array;
306 public $export_special_array;
313 public $export_dependencies_array;
317 public $export_sql_start;
321 public $export_sql_end;
325 public $export_sql_order;
338 public $import_label;
347 public $import_entities_array;
351 public $import_tables_array;
355 public $import_tables_creator_array;
359 public $import_fields_array;
363 public $import_fieldshidden_array;
367 public $import_convertvalue_array;
371 public $import_regex_array;
375 public $import_examplevalues_array;
379 public $import_updatekeys_array;
383 public $import_run_sql_after_array;
387 public $import_TypeFields_array;
391 public $import_help_array;
401 public $always_enabled;
411 public $automatic_activation = array();
416 public $core_enabled;
432 public $config_page_url;
455 public $conflictwith;
467 public $warnings_activation;
474 public $warnings_activation_ext;
481 public $warnings_unactivation;
498 public $need_dolibarr_version;
504 public $max_dolibarr_version;
509 public $need_javascript_ajax;
514 public $enabled_bydefault;
519 public $hidden =
false;
524 public $url_last_version;
553 protected function _init($array_sql, $options =
'')
577 if (!$err && !preg_match(
'/newboxdefonly/', $options)) {
582 if (!$err && !preg_match(
'/noboxes/', $options)) {
607 $num = count($array_sql);
608 for ($i = 0; $i < $num; $i++) {
610 $sql = $array_sql[$i];
613 if (is_array($val)) {
615 $ignoreerror = $val[
'ignoreerror'] ?? 0;
618 $sql = str_replace(
'__ENTITY__', (
string) ((
int)
$conf->entity), $sql);
620 dol_syslog(get_class($this).
"::_init ignoreerror=".$ignoreerror, LOG_DEBUG);
621 $result = $this->db->query($sql, $ignoreerror);
624 $this->error = $this->db->lasterror();
627 dol_syslog(get_class($this).
"::_init Warning ".$this->db->lasterror(), LOG_WARNING);
637 $moduleNameInConf = strtolower(preg_replace(
'/^MAIN_MODULE_/',
'', $this->const_name));
639 if ($moduleNameInConf ===
'propale') {
640 $moduleNameInConf =
'propal';
641 } elseif ($moduleNameInConf ===
'supplierproposal') {
642 $moduleNameInConf =
'supplier_proposal';
645 $conf->modules[$moduleNameInConf] = $moduleNameInConf;
649 $this->db->rollback();
663 protected function _remove($array_sql, $options =
'')
692 if (!$err && !preg_match(
'/(newboxdefonly|noboxes)/', $options)) {
717 $num = count((array) $array_sql);
718 for ($i = 0; $i < $num; $i++) {
720 dol_syslog(get_class($this).
"::_remove", LOG_DEBUG);
721 $result = $this->db->query($array_sql[$i]);
723 $this->error = $this->db->error();
734 $moduleNameInConf = strtolower(preg_replace(
'/^MAIN_MODULE_/',
'', $this->const_name));
736 if ($moduleNameInConf ===
'propale') {
737 $moduleNameInConf =
'propal';
738 } elseif ($moduleNameInConf ===
'supplierproposal') {
739 $moduleNameInConf =
'supplier_proposal';
742 unset(
$conf->modules[$moduleNameInConf]);
746 $this->db->rollback();
761 $langs->load(
"admin");
763 if ($langs->transnoentitiesnoconv(
"Module".$this->numero.
"Name") !=
"Module".$this->numero.
"Name") {
765 return $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Name");
768 if (is_array($this->langfiles)) {
769 foreach ($this->langfiles as $val) {
776 if ($langs->trans(
"Module".$this->name.
"Name") !=
"Module".$this->name.
"Name") {
778 return $langs->transnoentitiesnoconv(
"Module".$this->
name.
"Name");
782 return $langs->transnoentitiesnoconv($this->
name);
793 public function getDesc($foruseinpopupdesc = 0)
796 $langs->load(
"admin");
798 if ($langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc") !=
"Module".$this->numero.
"Desc") {
800 return $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc");
803 if (is_array($this->langfiles)) {
804 foreach ($this->langfiles as $val) {
811 if ($langs->transnoentitiesnoconv(
"Module".$this->name.
"Desc") !=
"Module".$this->name.
"Desc") {
813 return $langs->trans(
"Module".$this->
name.
"Desc");
830 $langs->load(
"admin");
832 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
833 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
839 $content = file_get_contents($pathoffile,
false,
null, 0, 1024 * 1024);
841 if ((
float) DOL_VERSION >= 6.0) {
842 @include_once DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
854 $content = preg_replace(
'/<a href="/',
'<a target="_blank" rel="noopener noreferrer" href="', $content);
856 $content = nl2br($content);
860 if (!empty($this->descriptionlong)) {
861 if (is_array($this->langfiles)) {
862 foreach ($this->langfiles as $val) {
869 $content = $langs->transnoentitiesnoconv($this->descriptionlong);
873 return '<div class="moduledesclong">'.$content.
'</div>';
889 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/README-'.$langs->defaultlang.
'.md', 0);
894 $tmp = explode(
'_', $langs->defaultlang);
895 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/README-'.$tmp[0].
'.md', 0);
907 return ($filefound ? $pathoffile :
'');
919 $langs->load(
"admin");
921 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
922 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
928 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/ChangeLog-'.$langs->defaultlang.
'.md', 0);
940 $content = file_get_contents($pathoffile);
942 if ((
float) DOL_VERSION >= 6.0) {
943 @include_once DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
947 $content = nl2br($content);
963 return $this->editor_name;
973 return $this->editor_url;
987 $langs->load(
"admin");
991 $newversion = preg_replace(
'/_deprecated/',
'', $this->version);
992 if ($newversion ==
'experimental') {
993 $ret = ($translated ? $langs->transnoentitiesnoconv(
"VersionExperimental") : $newversion);
994 } elseif ($newversion ==
'development') {
995 $ret = ($translated ? $langs->transnoentitiesnoconv(
"VersionDevelopment") : $newversion);
996 } elseif ($newversion ==
'dolibarr') {
998 } elseif ($newversion) {
1001 $ret = ($translated ? $langs->transnoentitiesnoconv(
"VersionUnknown") :
'unknown');
1004 if (preg_match(
'/_deprecated/', $this->version)) {
1005 $ret .= ($translated ?
' ('.$langs->transnoentitiesnoconv(
"Deprecated").
')' : $this->version);
1017 if (in_array($this->version, array(
'dolibarr',
'dolibarr_deprecated',
'experimental',
'development'))) {
1018 return $this->module_position;
1020 if ($this->module_position >= 100000) {
1021 return $this->module_position;
1023 $position = intval($this->module_position) + 100000;
1024 return strval($position);
1037 if ($this->version ==
'dolibarr' || $this->version ==
'dolibarr_deprecated') {
1040 if (!empty($this->version) && !in_array($this->version, array(
'experimental',
'development')) && empty($this->version_if_core)) {
1043 if (!empty($this->editor_name) || !empty($this->editor_url) && empty($this->version_if_core)) {
1046 if ($this->numero >= 100000) {
1060 return $this->langfiles;
1074 $langstring =
"ExportDataset_".$this->export_code[$r];
1075 if ($langs->trans($langstring) == $langstring) {
1077 return $langs->trans($this->export_label[$r]);
1080 return $langs->trans($langstring);
1096 $langstring =
"ImportDataset_".$this->import_code[$r];
1098 if ($langs->trans($langstring) == $langstring) {
1100 return $langs->transnoentitiesnoconv($this->import_label[$r]);
1103 return $langs->transnoentitiesnoconv($langstring);
1119 $sql =
"SELECT tms FROM ".MAIN_DB_PREFIX.
"const";
1120 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1121 $sql .=
" AND entity IN (0, ".((int)
$conf->entity).
")";
1123 dol_syslog(get_class($this).
"::getLastActiveDate", LOG_DEBUG);
1124 $resql = $this->db->query($sql);
1128 $obj = $this->db->fetch_object($resql);
1130 return $this->db->jdate($obj->tms);
1149 $sql =
"SELECT tms, note FROM ".MAIN_DB_PREFIX.
"const";
1150 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1151 $sql .=
" AND entity IN (0, ".((int)
$conf->entity).
")";
1153 dol_syslog(get_class($this).
"::getLastActiveDate", LOG_DEBUG);
1154 $resql = $this->db->query($sql);
1158 $obj = $this->db->fetch_object($resql);
1162 $tmp = json_decode($obj->note,
true);
1165 'authorid' => empty($tmp[
'authorid']) ?
'' : (int) $tmp[
'authorid'],
1166 'ip' => empty($tmp[
'ip']) ?
'' : (
string) $tmp[
'ip'],
1167 'lastactivationdate' => $this->db->jdate($obj->tms),
1168 'lastactivationversion' => (!empty($tmp[
'lastactivationversion']) ? (
string) $tmp[
'lastactivationversion'] :
'unknown'),
1186 global
$conf, $user;
1191 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 :
$conf->entity);
1193 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1194 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1195 $sql .=
" AND entity IN (0, ".((int) $entity).
")";
1197 dol_syslog(get_class($this).
"::_active delete activation constant", LOG_DEBUG);
1198 $resql = $this->db->query($sql);
1203 $note = json_encode(
1205 'authorid' => (is_object($user) ? $user->id : 0),
1206 'ip' => (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']),
1207 'lastactivationversion' => $this->version,
1211 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name, value, visible, entity, note) VALUES";
1212 $sql .=
" (".$this->db->encrypt($this->const_name);
1213 $sql .=
", ".$this->db->encrypt(
'1');
1214 $sql .=
", 0, ".((int) $entity);
1215 $sql .=
", '".$this->db->escape($note).
"')";
1217 dol_syslog(get_class($this).
"::_active insert activation constant", LOG_DEBUG);
1218 $resql = $this->db->query($sql);
1241 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 :
$conf->entity);
1243 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1244 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1245 $sql .=
" AND entity IN (0, ".((int) $entity).
")";
1247 dol_syslog(get_class($this).
"::_unactive", LOG_DEBUG);
1248 $this->db->query($sql);
1282 if (empty($reldir)) {
1286 include_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
1288 foreach (
$conf->file->dol_document_root as $dirroot) {
1290 $dirsql = $dirroot.$reldir;
1294 $listofsubdir = array(
'',
'tables/',
'data/');
1295 if ($this->db->type ==
'pgsql') {
1296 $listofsubdir[] =
'../pgsql/functions/';
1299 foreach ($listofsubdir as $subdir) {
1300 $dir = $dirsql.$subdir;
1302 $handle = @opendir($dir);
1303 if (is_resource($handle)) {
1308 while (($file = readdir($handle)) !==
false) {
1312 foreach ($files as $file) {
1313 if ($onlywithsuffix) {
1314 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1321 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'llx_') {
1333 while (($file = readdir($handle)) !==
false) {
1337 foreach ($files as $file) {
1338 if ($onlywithsuffix) {
1339 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1346 if (preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'llx_') {
1358 while (($file = readdir($handle)) !==
false) {
1362 foreach ($files as $file) {
1363 if ($onlywithsuffix) {
1364 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1371 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 9) ==
'functions') {
1383 while (($file = readdir($handle)) !==
false) {
1387 foreach ($files as $file) {
1388 if ($onlywithsuffix) {
1389 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1396 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'data') {
1408 while (($file = readdir($handle)) !==
false) {
1412 foreach ($files as $file) {
1413 if ($onlywithsuffix) {
1414 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1422 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 6) ==
'update') {
1441 dol_syslog(
"A module wants to load sql files from ".$reldir.
" but this directory was not found.", LOG_WARNING);
1458 include_once DOL_DOCUMENT_ROOT.
'/core/class/infobox.class.php';
1464 if (is_array($this->boxes)) {
1465 dol_syslog(get_class($this).
"::insert_boxes", LOG_DEBUG);
1469 foreach ($this->boxes as $key => $value) {
1470 $file = isset($this->boxes[$key][
'file']) ? $this->boxes[$key][
'file'] :
'';
1471 $note = isset($this->boxes[$key][
'note']) ? $this->boxes[$key][
'note'] :
'';
1472 $enabledbydefaulton = isset($this->boxes[$key][
'enabledbydefaulton']) ? $this->boxes[$key][
'enabledbydefaulton'] :
'Home';
1475 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] :
'';
1478 $note = isset($this->boxes[$key][2]) ? $this->boxes[$key][2] :
'';
1482 $sql =
"SELECT count(*) as nb FROM ".MAIN_DB_PREFIX.
"boxes_def";
1483 $sql .=
" WHERE file = '".$this->db->escape($file).
"'";
1484 $sql .=
" AND entity = ".((int)
$conf->entity);
1486 $sql .=
" AND note ='".$this->db->escape($note).
"'";
1489 $result = $this->db->query($sql);
1491 $obj = $this->db->fetch_object($result);
1492 if ($obj->nb == 0) {
1496 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes_def (file, entity, note)";
1497 $sql .=
" VALUES ('".$this->db->escape($file).
"', ";
1498 $sql .= ((int)
$conf->entity).
", ";
1499 $sql .= $note ?
"'".$this->db->escape($note).
"'" :
"null";
1502 dol_syslog(get_class($this).
"::insert_boxes", LOG_DEBUG);
1503 $resql = $this->db->query($sql);
1508 if (!$err && !preg_match(
'/newboxdefonly/', $option)) {
1509 $lastid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"boxes_def",
"rowid");
1511 foreach ($pos_name as $key2 => $val2) {
1513 if ($enabledbydefaulton && $val2 != $enabledbydefaulton) {
1517 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes (box_id, position, box_order, fk_user, entity)";
1518 $sql .=
" VALUES (".((int) $lastid).
", ".((int) $key2).
", '0', 0, ".((int)
$conf->entity).
")";
1520 dol_syslog(get_class($this).
"::insert_boxes onto page ".$key2.
"=".$val2, LOG_DEBUG);
1521 $resql = $this->db->query($sql);
1529 $this->db->commit();
1531 $this->error = $this->db->lasterror();
1532 $this->db->rollback();
1537 $this->error = $this->db->lasterror();
1560 if (is_array($this->boxes)) {
1561 foreach ($this->boxes as $key => $value) {
1563 if (empty($this->boxes[$key][
'file'])) {
1564 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] :
'';
1566 $file = $this->boxes[$key][
'file'];
1574 if ($file ==
'box_graph_product_distribution.php') {
1576 dol_syslog(
"We discard deleting module ".$file.
" because another module still active requires it.");
1581 if ($this->db->type ==
'sqlite3') {
1584 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes ";
1585 $sql .=
"WHERE ".MAIN_DB_PREFIX.
"boxes.box_id IN (";
1586 $sql .=
"SELECT ".MAIN_DB_PREFIX.
"boxes_def.rowid ";
1587 $sql .=
"FROM ".MAIN_DB_PREFIX.
"boxes_def ";
1588 $sql .=
"WHERE ".MAIN_DB_PREFIX.
"boxes_def.file = '".$this->db->escape($file).
"') ";
1589 $sql .=
"AND ".MAIN_DB_PREFIX.
"boxes.entity = ".((int)
$conf->entity);
1591 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes";
1592 $sql .=
" USING ".MAIN_DB_PREFIX.
"boxes, ".MAIN_DB_PREFIX.
"boxes_def";
1593 $sql .=
" WHERE ".MAIN_DB_PREFIX.
"boxes.box_id = ".MAIN_DB_PREFIX.
"boxes_def.rowid";
1594 $sql .=
" AND ".MAIN_DB_PREFIX.
"boxes_def.file = '".$this->db->escape($file).
"'";
1595 $sql .=
" AND ".MAIN_DB_PREFIX.
"boxes.entity = ".((int)
$conf->entity);
1598 dol_syslog(get_class($this).
"::delete_boxes", LOG_DEBUG);
1599 $resql = $this->db->query($sql);
1601 $this->error = $this->db->lasterror();
1605 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes_def";
1606 $sql .=
" WHERE file = '".$this->db->escape($file).
"'";
1607 $sql .=
" AND entity = ".((int)
$conf->entity);
1609 dol_syslog(get_class($this).
"::delete_boxes", LOG_DEBUG);
1610 $resql = $this->db->query($sql);
1612 $this->error = $this->db->lasterror();
1630 include_once DOL_DOCUMENT_ROOT .
'/core/class/infobox.class.php';
1631 include_once DOL_DOCUMENT_ROOT .
'/cron/class/cronjob.class.php';
1632 include_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
1634 global
$conf, $user;
1637 $user =
new User($this->db);
1642 if (is_array($this->cronjobs)) {
1643 dol_syslog(get_class($this) .
"::insert_cronjobs", LOG_DEBUG);
1645 foreach ($this->cronjobs as $key => $value) {
1648 $entity = isset($value[
'entity']) ? $value[
'entity'] :
$conf->entity;
1649 $label = isset($value[
'label']) ? $value[
'label'] :
'';
1650 $jobtype = isset($value[
'jobtype']) ? $value[
'jobtype'] :
'';
1651 $classesname = isset($value[
'class']) ? $value[
'class'] :
'';
1652 $objectname = isset($value[
'objectname']) ? $value[
'objectname'] :
'';
1653 $methodename = isset($value[
'method']) ? $value[
'method'] :
'';
1654 $command = isset($value[
'command']) ? $value[
'command'] :
'';
1655 $params = isset($value[
'parameters']) ? $value[
'parameters'] :
'';
1656 $md5params = isset($value[
'md5params']) ? $value[
'md5params'] :
'';
1657 $comment = isset($value[
'comment']) ? $value[
'comment'] :
'';
1658 $frequency = isset($value[
'frequency']) ? $value[
'frequency'] :
'';
1659 $unitfrequency = isset($value[
'unitfrequency']) ? $value[
'unitfrequency'] :
'';
1660 $priority = isset($value[
'priority']) ? $value[
'priority'] :
'';
1661 $datestart = isset($value[
'datestart']) ? $value[
'datestart'] :
'';
1662 $dateend = isset($value[
'dateend']) ? $value[
'dateend'] :
'';
1663 $datenextrun = isset($value[
'datenextrun']) ? $value[
'datenextrun'] : $now;
1664 $status = isset($value[
'status']) ? $value[
'status'] :
'';
1665 $maxrun = isset($value[
'maxrun']) ? $value[
'maxrun'] : 0;
1666 $libname = isset($value[
'libname']) ? $value[
'libname'] :
'';
1667 $test = isset($value[
'test']) ? $value[
'test'] :
'';
1670 $sql =
"SELECT count(*) as nb FROM " . MAIN_DB_PREFIX .
"cronjob";
1672 $sql .=
" WHERE label = '".$this->db->escape($label).
"'";
1690 $sql .=
" AND entity = " . ((int) $entity);
1692 $result = $this->db->query($sql);
1694 $this->error = $this->db->lasterror();
1700 $obj = $this->db->fetch_object($result);
1705 $cronjob =
new Cronjob($this->db);
1707 $cronjob->entity = $entity;
1708 $cronjob->label = $label;
1709 $cronjob->jobtype = $jobtype;
1710 $cronjob->classesname = $classesname;
1711 $cronjob->objectname = $objectname;
1712 $cronjob->methodename = $methodename;
1713 $cronjob->command = $command;
1714 $cronjob->params = $params;
1715 $cronjob->md5params = $md5params;
1716 $cronjob->note_private = $comment;
1717 $cronjob->frequency = $frequency;
1718 $cronjob->unitfrequency = $unitfrequency;
1719 $cronjob->priority = $priority;
1720 $cronjob->datestart = $datestart;
1721 $cronjob->dateend = $dateend;
1722 $cronjob->datenextrun = $datenextrun;
1723 $cronjob->maxrun = $maxrun;
1724 $cronjob->status = $status;
1725 $cronjob->test = $test;
1726 $cronjob->libname = $libname;
1727 $cronjob->module_name = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
1729 $retCreate = $cronjob->create($user);
1731 if ($retCreate < 0) {
1732 $this->error = implode(
"\n", array_merge([$cronjob->error], $cronjob->errors));
1754 if (is_array($this->cronjobs)) {
1755 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"cronjob";
1756 $sql .=
" WHERE module_name = '".$this->db->escape(empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class).
"'";
1757 $sql .=
" AND entity = ".((int)
$conf->entity);
1758 $sql .=
" AND test = '1'";
1761 dol_syslog(get_class($this).
"::delete_cronjobs", LOG_DEBUG);
1762 $resql = $this->db->query($sql);
1764 $this->error = $this->db->lasterror();
1785 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1786 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" LIKE '".$this->db->escape($this->const_name).
"_TABS_%'";
1787 $sql .=
" AND entity = ".((int)
$conf->entity);
1789 dol_syslog(get_class($this).
"::delete_tabs", LOG_DEBUG);
1790 if (!$this->db->query($sql)) {
1791 $this->error = $this->db->lasterror();
1811 if (!empty($this->tabs)) {
1812 dol_syslog(get_class($this).
"::insert_tabs", LOG_DEBUG);
1815 foreach ($this->tabs as $key => $value) {
1816 if (is_array($value) && count($value) == 0) {
1820 $entity =
$conf->entity;
1823 if (is_array($value)) {
1824 $newvalue = $value[
'data'];
1825 if (isset($value[
'entity'])) {
1826 $entity = $value[
'entity'];
1831 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (";
1836 $sql .=
", visible";
1839 $sql .=
" VALUES (";
1840 $sql .= $this->db->encrypt($this->const_name.
"_TABS_".$i);
1841 $sql .=
", 'chaine'";
1842 $sql .=
", ".$this->db->encrypt($newvalue);
1845 $sql .=
", ".((int) $entity);
1848 $resql = $this->db->query($sql);
1851 if ($this->db->lasterrno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1852 $this->error = $this->db->lasterror();
1853 $this->errors[] = $this->db->lasterror();
1878 if (empty($this->
const)) {
1884 foreach ($this->
const as $key => $value) {
1886 $name = $this->
const[$key][0];
1887 $entity = (!empty($this->
const[$key][5]) && $this->
const[$key][5] !=
'current') ? 0 :
$conf->entity;
1890 $type = $this->
const[$key][1];
1891 $val = $this->
const[$key][2];
1892 $note = isset($this->
const[$key][3]) ? $this->
const[$key][3] :
'';
1893 $visible = isset($this->
const[$key][4]) ? $this->
const[$key][4] : 0;
1896 if (empty($visible)) {
1899 if (empty($val) && $val !=
'0') {
1903 if (!empty($name)) {
1904 $sql =
"SELECT count(*) as nb";
1905 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const";
1906 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($name).
"'";
1907 $sql .=
" AND entity = ".((int) $entity);
1909 $result = $this->db->query($sql);
1911 $row = $this->db->fetch_row($result);
1914 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name, type, value, note, visible, entity)";
1915 $sql .=
" VALUES (";
1916 $sql .= $this->db->encrypt($name);
1917 $sql .=
", '".$this->db->escape($type).
"'";
1918 $sql .=
", ".(($val !=
'') ? $this->db->encrypt($val) :
"''");
1919 $sql .=
", ".($note ?
"'".$this->db->escape($note).
"'" :
"null");
1920 $sql .=
", '".$this->db->escape($visible).
"'";
1921 $sql .=
", ".((int) $entity);
1924 if (!$this->db->query($sql)) {
1928 $conf->global->$name = $val;
1931 dol_syslog(__METHOD__.
" constant '".$name.
"' already exists", LOG_DEBUG);
1955 if (empty($this->
const)) {
1959 foreach ($this->
const as $key => $value) {
1960 $name = $this->
const[$key][0];
1961 $deleteonunactive = (!empty($this->
const[$key][6])) ? 1 : 0;
1963 if ($deleteonunactive) {
1964 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1965 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($name).
"'";
1966 $sql .=
" AND entity in (0, ".((int)
$conf->entity).
")";
1967 dol_syslog(get_class($this).
"::delete_const", LOG_DEBUG);
1968 if (!$this->db->query($sql)) {
1969 $this->error = $this->db->lasterror();
1991 public function insert_permissions($reinitadminperms = 0, $force_entity =
null, $notrigger = 0, $existingrightsdefids =
null)
1994 global
$conf, $user;
1997 $entity = (!empty($force_entity) ? $force_entity :
$conf->entity);
1999 dol_syslog(get_class($this).
"::insert_permissions", LOG_DEBUG);
2002 $sql_del =
"SELECT ".$this->db->decrypt(
'value').
" as value";
2003 $sql_del .=
" FROM ".MAIN_DB_PREFIX.
"const";
2004 $sql_del .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
2005 $sql_del .=
" AND entity IN (0,".((int) $entity).
")";
2007 $resql = $this->db->query($sql_del);
2010 $obj = $this->db->fetch_object($resql);
2012 if ($obj !==
null && !empty($obj->value) && !empty($this->rights)) {
2013 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
2016 foreach ($this->rights as $key => $value) {
2017 $r_id = $this->rights[$key][self::KEY_ID];
2018 $r_label = $this->rights[$key][self::KEY_LABEL];
2019 $r_type = $this->rights[$key][self::KEY_TYPE] ??
'w';
2020 $r_default = $this->rights[$key][self::KEY_DEFAULT] ?? 0;
2021 $r_perms = $this->rights[$key][self::KEY_FIRST_LEVEL] ??
'';
2022 $r_subperms = $this->rights[$key][self::KEY_SECOND_LEVEL] ??
'';
2025 if (empty($r_perms)) {
2030 $r_module = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2033 $r_module_origin =
'';
2035 if (isset($this->rights[$key][self::KEY_MODULE])) {
2037 $r_module = $this->rights[$key][self::KEY_MODULE];
2039 $r_module_origin = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2042 if (!empty($r_module_origin) && $r_module !== $r_module_origin) {
2048 $r_module_position = $r_targetmoduleinfo[
'position'];
2049 $r_family = $r_targetmoduleinfo[
'family'];
2052 $r_family = $this->family;
2054 $r_family_position = 0;
2057 $r_enabled = $this->rights[$key][self::KEY_ENABLED] ??
'1';
2060 if ($existingrightsdefids !==
null) {
2061 $rightalreadyexists = !empty($existingrightsdefids[$r_id]);
2063 $sql =
"SELECT count(*) as nb FROM ".MAIN_DB_PREFIX.
"rights_def";
2064 $sql .=
" WHERE entity = ".((int) $entity);
2065 $sql .=
" AND id = ".((int) $r_id);
2067 $rightalreadyexists =
true;
2068 $resqlselect = $this->db->query($sql);
2070 $objcount = $this->db->fetch_object($resqlselect);
2071 $rightalreadyexists = !($objcount && $objcount->nb == 0);
2072 $this->db->free($resqlselect);
2076 if (!$rightalreadyexists) {
2077 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"rights_def (";
2080 $sql .=
", libelle";
2082 $sql .=
", module_origin";
2083 $sql .=
", module_position";
2085 $sql .=
", family_position";
2087 $sql .=
", bydefault";
2089 $sql .=
", subperms";
2090 $sql .=
", enabled";
2091 $sql .=
") VALUES (";
2092 $sql .= ((int) $r_id);
2093 $sql .=
", ".((int) $entity);
2094 $sql .=
", '".$this->db->escape($r_label).
"'";
2095 $sql .=
", '".$this->db->escape($r_module).
"'";
2096 $sql .=
", '".$this->db->escape($r_module_origin).
"'";
2097 $sql .=
", '".$this->db->escape((
string) $r_module_position).
"'";
2098 $sql .=
", '".$this->db->escape($r_family).
"'";
2099 $sql .=
", '".$this->db->escape((
string) $r_family_position).
"'";
2100 $sql .=
", '".$this->db->escape($r_type).
"'";
2101 $sql .=
", ".((int) $r_default);
2102 $sql .=
", '".$this->db->escape($r_perms).
"'";
2103 $sql .=
", '".$this->db->escape($r_subperms).
"'";
2104 $sql .=
", '".$this->db->escape($r_enabled).
"'";
2107 $resqlinsert = $this->db->query($sql, 1);
2109 if (!$resqlinsert) {
2110 if ($this->db->errno() !=
"DB_ERROR_RECORD_ALREADY_EXISTS") {
2111 $this->error = $this->db->lasterror();
2115 dol_syslog(get_class($this).
"::insert_permissions record already exists", LOG_INFO);
2119 $this->db->free($resqlinsert);
2123 if (!empty($reinitadminperms)) {
2124 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"user WHERE admin = 1";
2125 dol_syslog(get_class($this).
"::insert_permissions Search all admin users", LOG_DEBUG);
2127 $resqlseladmin = $this->db->query($sql, 1);
2129 if ($resqlseladmin) {
2130 $num = $this->db->num_rows($resqlseladmin);
2133 $obj2 = $this->db->fetch_object($resqlseladmin);
2134 dol_syslog(get_class($this).
"::insert_permissions Add permission id ".$r_id.
" to user id=".$obj2->rowid);
2136 $tmpuser =
new User($this->db);
2137 $result = $tmpuser->fetch($obj2->rowid);
2139 $tmpuser->addrights($r_id,
'',
'', 0, 1);
2141 dol_syslog(get_class($this).
"::insert_permissions Failed to add the permission to user because fetch return an error", LOG_ERR);
2151 if (!empty($reinitadminperms) && !empty($user->admin)) {
2153 $user->clearrights();
2154 $user->loadRights();
2157 $this->db->free($resql);
2159 $this->error = $this->db->lasterror();
2181 if (isset(
$conf->cache[
'keyModuleInfoCache'][$rightsclass])) {
2182 return $conf->cache[
'keyModuleInfoCache'][$rightsclass];
2187 $result = array(
'family' => $this->family,
'position' => (
int) $this->
getModulePosition());
2190 foreach ($modulesdir as $dir) {
2192 if (is_resource($handle)) {
2193 while (($file = readdir($handle)) !==
false) {
2194 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php') {
2195 $modName = substr($file, 0,
dol_strlen($file) - 10);
2196 if ($modName && $modName != get_class($this)) {
2197 include_once $dir.$file;
2198 if (class_exists($modName)) {
2199 '@phan-var-force class-string<DolibarrModules> $modName';
2200 $objMod =
new $modName(
$db);
2201 '@phan-var-force DolibarrModules $objMod';
2202 if (!empty($objMod->rights_class) && $objMod->rights_class === $rightsclass) {
2203 $result = array(
'family' => $objMod->family,
'position' => (
int) $objMod->getModulePosition());
2214 $conf->cache[
'keyModuleInfoCache'][$rightsclass] = $result;
2233 $module = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
2235 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"rights_def";
2236 $sql .=
" WHERE (module = '".$this->db->escape($module).
"' OR module_origin = '".$this->db->escape($module).
"')";
2239 if (empty($this->core_enabled)) {
2240 $sql .=
" AND entity = ".((int)
$conf->entity);
2243 dol_syslog(get_class($this).
"::delete_permissions", LOG_DEBUG);
2244 if (!$this->db->query($sql)) {
2245 $this->error = $this->db->lasterror();
2262 global
$conf, $user;
2264 if (!is_array($this->menu) || empty($this->menu)) {
2268 include_once DOL_DOCUMENT_ROOT.
'/core/class/menubase.class.php';
2270 dol_syslog(get_class($this).
"::insert_menus", LOG_DEBUG);
2275 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 :
$conf->entity);
2279 foreach ($this->menu as $key => $value) {
2281 $menu->menu_handler =
'all';
2284 $menu->module = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2286 if (!$this->menu[$key][
'fk_menu']) {
2290 $fk_parent = $this->menu[$key][
'fk_menu'];
2292 if (preg_match(
'/^r=/', $fk_parent)) {
2293 $fk_parent = str_replace(
'r=',
'', $fk_parent);
2294 if (isset($this->menu[$fk_parent][
'rowid'])) {
2295 $menu->fk_menu = $this->menu[$fk_parent][
'rowid'];
2298 } elseif (preg_match(
'/^fk_mainmenu=([a-zA-Z0-9_]+),fk_leftmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
2299 $menu->fk_menu = -1;
2300 $menu->fk_mainmenu = $reg[1];
2301 $menu->fk_leftmenu = $reg[2];
2303 } elseif (preg_match(
'/^fk_mainmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
2304 $menu->fk_menu = -1;
2305 $menu->fk_mainmenu = $reg[1];
2306 $menu->fk_leftmenu =
'';
2309 if (!$foundparent) {
2310 $this->error =
"ErrorBadDefinitionOfMenuArrayInModuleDescriptor";
2311 dol_syslog(get_class($this).
"::insert_menus ".$this->error.
" ".$this->menu[$key][
'fk_menu'], LOG_ERR);
2315 $menu->type = $this->menu[$key][
'type'];
2316 $menu->mainmenu = isset($this->menu[$key][
'mainmenu']) ? $this->menu[$key][
'mainmenu'] : (isset($menu->fk_mainmenu) ? $menu->fk_mainmenu :
'');
2317 $menu->leftmenu = isset($this->menu[$key][
'leftmenu']) ? $this->menu[$key][
'leftmenu'] :
'';
2318 $menu->title = $this->menu[$key][
'titre'];
2319 $menu->prefix = isset($this->menu[$key][
'prefix']) ? $this->menu[$key][
'prefix'] :
'';
2320 $menu->url = $this->menu[$key][
'url'];
2321 $menu->langs = isset($this->menu[$key][
'langs']) ? $this->menu[$key][
'langs'] :
'';
2322 $menu->position = $this->menu[$key][
'position'];
2323 $menu->perms = $this->menu[$key][
'perms'];
2324 $menu->target = isset($this->menu[$key][
'target']) ? $this->menu[$key][
'target'] :
'';
2325 $menu->user = $this->menu[$key][
'user'];
2326 $menu->enabled = isset($this->menu[$key][
'enabled']) ? $this->menu[$key][
'enabled'] : 0;
2327 $menu->position = $this->menu[$key][
'position'];
2328 $menu->entity = $entity;
2331 $result = $menu->create($user);
2333 $this->menu[$key][
'rowid'] = $result;
2335 $this->error = $menu->error;
2336 dol_syslog(get_class($this).
'::insert_menus result='.$result.
" ".$this->error, LOG_ERR);
2344 $this->db->commit();
2346 dol_syslog(get_class($this).
"::insert_menus ".$this->error, LOG_ERR);
2347 $this->db->rollback();
2368 $module = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
2370 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"menu";
2371 $sql .=
" WHERE module = '".$this->db->escape($module).
"'";
2372 $sql .=
" AND menu_handler = 'all'";
2373 $sql .=
" AND entity IN (0, ".((int)
$conf->entity).
")";
2375 dol_syslog(get_class($this).
"::delete_menus", LOG_DEBUG);
2376 $resql = $this->db->query($sql);
2378 $this->error = $this->db->lasterror();
2394 global $langs,
$conf;
2399 if (isset($this->dirs) && is_array($this->dirs)) {
2400 foreach ($this->dirs as $key => $value) {
2403 if (!is_array($value)) {
2406 $constname = $this->const_name.
"_DIR_";
2407 $dir = $this->dirs[$key][1];
2408 $addtodatabase = empty($this->dirs[$key][2]) ?
'' : $this->dirs[$key][2];
2409 $subname = empty($this->dirs[$key][3]) ?
'' : strtoupper($this->dirs[$key][3]);
2410 $forcename = empty($this->dirs[$key][4]) ?
'' : strtoupper($this->dirs[$key][4]);
2412 if (!empty($forcename)) {
2413 $constname =
'MAIN_MODULE_'.$forcename.
"_DIR_";
2415 if (!empty($subname)) {
2416 $constname = $constname.$subname.
"_";
2419 $name = $constname.strtoupper($this->dirs[$key][0]);
2424 $fulldir = DOL_DATA_ROOT.$dir;
2426 $fulldir = DOL_DATA_ROOT.
"/".
$conf->entity.$dir;
2429 if (!empty($fulldir) && !file_exists($fulldir)) {
2430 if (
dol_mkdir($fulldir, DOL_DATA_ROOT) < 0) {
2431 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $fulldir);
2432 dol_syslog(get_class($this).
"::_init ".$this->error, LOG_ERR);
2438 if (!empty($addtodatabase) && !empty($name)) {
2467 $sql =
"SELECT count(*)";
2468 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const";
2469 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($name).
"'";
2470 $sql .=
" AND entity = ".((int)
$conf->entity);
2472 dol_syslog(get_class($this).
"::insert_dirs", LOG_DEBUG);
2473 $result = $this->db->query($sql);
2475 $row = $this->db->fetch_row($result);
2478 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name, type, value, note, visible, entity)";
2479 $sql .=
" VALUES (".$this->db->encrypt($name).
", 'chaine', ".$this->db->encrypt($dir).
", '".$this->db->escape(
"Directory for module ".$this->
name).
"', '0', ".((int)
$conf->entity).
")";
2481 dol_syslog(get_class($this).
"::insert_dirs", LOG_DEBUG);
2482 $this->db->query($sql);
2485 $this->error = $this->db->lasterror();
2506 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
2507 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" LIKE '".$this->db->escape($this->const_name).
"_DIR_%'";
2508 $sql .=
" AND entity = ".((int)
$conf->entity);
2510 dol_syslog(get_class($this).
"::delete_dirs", LOG_DEBUG);
2511 if (!$this->db->query($sql)) {
2512 $this->error = $this->db->lasterror();
2529 global
$conf, $langs;
2533 if (is_array($this->module_parts)) {
2534 if (empty($this->module_parts[
'icon']) && !empty($this->picto) && preg_match(
'/^fa\-/', $this->picto)) {
2535 $this->module_parts[
'icon'] = $this->picto;
2538 foreach ($this->module_parts as $key => $value) {
2539 if (is_array($value) && count($value) == 0) {
2544 if ($key ==
'websitetemplates' && $value == 1) {
2548 $docs =
dol_dir_list($srcroot,
'directories', 0,
'website_.*$');
2549 foreach ($docs as $cursorfile) {
2550 $src = $srcroot.
'/'.$cursorfile[
'name'];
2551 $dest = DOL_DATA_ROOT.
'/doctemplates/websites/'.$cursorfile[
'name'];
2558 $result = dol_compress_dir($src, $dest.
'.zip',
'zip');
2561 $this->error = ($errormsg ? $errormsg : $langs->trans(
'ErrorFailToCreateZip', $dest));
2562 $this->errors[] = ($errormsg ? $errormsg : $langs->trans(
'ErrorFailToCreateZip', $dest));
2567 $docs =
dol_dir_list($srcroot,
'files', 0,
'website_.*\.jpg$');
2568 foreach ($docs as $cursorfile) {
2569 $src = $srcroot.
'/'.$cursorfile[
'name'];
2570 $dest = DOL_DATA_ROOT.
'/doctemplates/websites/'.$cursorfile[
'name'];
2576 $entity =
$conf->entity;
2580 if (is_array($value)) {
2583 if (isset($value[
'data']) && is_array($value[
'data'])) {
2584 $newvalue = json_encode($value[
'data']);
2585 if (isset($value[
'entity'])) {
2586 $entity = $value[
'entity'];
2588 } elseif (isset($value[
'data']) && !is_array($value[
'data'])) {
2589 $newvalue = $value[
'data'];
2590 if (isset($value[
'entity'])) {
2591 $entity = $value[
'entity'];
2594 $newvalue = json_encode($value);
2598 if (!empty($newvalue)) {
2599 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (";
2604 $sql .=
", visible";
2607 $sql .=
" VALUES (";
2608 $sql .=
" ".$this->db->encrypt($this->const_name.
"_".strtoupper($key), 1);
2609 $sql .=
", 'chaine'";
2610 $sql .=
", ".$this->db->encrypt($newvalue, 1);
2613 $sql .=
", ".((int) $entity);
2616 dol_syslog(get_class($this).
"::insert_module_parts for key=".$this->const_name.
"_".strtoupper($key), LOG_DEBUG);
2618 $resql = $this->db->query($sql, 1);
2620 if ($this->db->lasterrno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2622 $this->error = $this->db->lasterror();
2624 dol_syslog(get_class($this).
"::insert_module_parts for ".$this->const_name.
"_".strtoupper($key).
" Record already exists.", LOG_WARNING);
2646 if (is_array($this->module_parts)) {
2647 dol_syslog(get_class($this).
"::delete_module_parts", LOG_DEBUG);
2649 if (empty($this->module_parts[
'icon']) && !empty($this->picto) && preg_match(
'/^fa\-/', $this->picto)) {
2650 $this->module_parts[
'icon'] = $this->picto;
2653 foreach ($this->module_parts as $key => $value) {
2655 if (is_array($value) && isset($value[
'entity'])) {
2656 $entity = $value[
'entity'];
2658 $entity =
$conf->entity;
2661 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
2662 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" LIKE '".$this->db->escape($this->const_name).
"_".strtoupper($key).
"'";
2663 $sql .=
" AND entity = ".((int) $entity);
2665 if (!$this->db->query($sql)) {
2666 $this->error = $this->db->lasterror();
2683 public function init($options =
'')
2685 return $this->
_init(array(), $options);
2696 public function remove($options =
'')
2698 return $this->
_remove(array(), $options);
2716 $imginfo =
"info_black";
2719 $const_name =
'MAIN_MODULE_'.strtoupper(preg_replace(
'/^mod/i',
'', get_class($this)));
2723 if (preg_match(
'/development/i', $version)) {
2724 $versiontrans .=
'warning';
2726 if (preg_match(
'/experimental/i', $version)) {
2727 $versiontrans .=
'warning';
2729 if (preg_match(
'/deprecated/i', $version)) {
2730 $versiontrans .=
'warning';
2734 <div class="box-flex-item info-box-module'
2735 .(getDolGlobalString($const_name) ?
'' :
' --disabled')
2737 .($this->needUpdate ?
' --need-update' :
'')
2739 <div class="info-box info-box-sm info-box-module">
2740 <div class="info-box-icon'.(!
getDolGlobalString($const_name) ?
'' :
' info-box-icon-module-enabled'.($versiontrans ?
' info-box-icon-module-warning' :
'')).
'">';
2745 if (!empty($this->picto)) {
2746 if (preg_match(
'/^\//i', $this->picto)) {
2747 $return .=
img_picto($alttext, $this->picto,
'class="inline-block valignmiddle"', 1);
2749 $return .=
img_object($alttext, $this->picto,
'class="inline-block valignmiddle"');
2752 $return .=
img_object($alttext,
'generic',
'class="inline-block valignmiddle"');
2755 if ($this->
isCoreOrExternalModule() ==
'external' || preg_match(
'/development|experimental|deprecated/i', $version)) {
2756 $versionTitle = $langs->trans(
"Version").
' '.$this->
getVersion(1);
2757 if ($this->needUpdate) {
2758 $versionTitle .=
'<br>'.$langs->trans(
'ModuleUpdateAvailable').
' : '.$this->lastVersion;
2761 $return .=
'<span class="info-box-icon-version'.($versiontrans ?
' '.$versiontrans :
'').
' classfortooltip" title="'.
dol_escape_js($versionTitle).
'" >';
2763 $return .=
'</span>';
2767 <div class="info-box-content info-box-text-module'.(!
getDolGlobalString($const_name) ?
'' :
' info-box-module-enabled'.($versiontrans ?
' info-box-content-warning' :
'')).
'">
2768 <span class="info-box-title noopacity">'.$this->
getName().
'</span>
2771 $return .=
'<div class="valignmiddle inline-block info-box-more">';
2773 $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>';
2774 $return .= '</div><br>';
2776 $return .= '<div class="valignmiddle
inline-block info-box-actions
">';
2777 $return .= '<div class="valignmiddle
inline-block info-box-setup
">';
2778 $return .= $codetoconfig;
2779 $return .= '</div>';
2780 $return .= '<div class="valignmiddle
inline-block marginleftonly marginrightonly
">';
2781 $return .= $codeenabledisable;
2782 $return .= '</div>';
2783 $return .= '</div>';
2786 </div><!-- /.info-box-content -->
2787 </div><!-- /.info-box -->
2801 public function checkForUpdate()
2803 require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
2804 if (!empty($this->url_last_version)) {
2805 $lastVersion = getURLContent($this->url_last_version, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only
2806 if (isset($lastVersion['content']) && strlen($lastVersion['content']) < 30) {
2807 // 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 _ . -
2808 $this->lastVersion = preg_replace("/[^a-zA-Z0-9_\.\-]+/
", "", $lastVersion['content']);
2809 if (version_compare($this->lastVersion, $this->version) > 0) {
2810 $this->needUpdate = true;
2813 $this->needUpdate = false;
2830 public function checkForCompliance($nametocheck = '')
2832 global $conf, $langs;
2834 if (empty($nametocheck)) {
2835 $nametocheck = $this->name;
2838 // Get list of illegal modules name or ID
2839 if (empty($conf->cache['noncompliantmodules'])) {
2840 require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
2842 $result = getURLContent(self::URL_FOR_BLACKLISTED_MODULES, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only
2843 if (isset($result['content']) && $result['http_code'] == 200) {
2844 $langs->load("errors
");
2846 // 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 _ . -
2847 $arrayoflines = preg_split("/[\n,]/
", $result['content']);
2848 foreach ($arrayoflines as $line) {
2849 $tmpfieldsofline = explode(';', $line);
2850 $modulekey = strtolower(trim($tmpfieldsofline[0]));
2851 if (empty($modulekey)) {
2854 $conf->cache['noncompliantmodules'][$modulekey]['name'] = trim($tmpfieldsofline[0]);
2855 $conf->cache['noncompliantmodules'][$modulekey]['id'] = (isset($tmpfieldsofline[1]) ? trim($tmpfieldsofline[1]) : '');
2856 $conf->cache['noncompliantmodules'][$modulekey]['signature'] = (isset($tmpfieldsofline[2]) ? trim($tmpfieldsofline[2]) : '');
2857 $conf->cache['noncompliantmodules'][$modulekey]['message'] = $langs->trans(empty(isset($tmpfieldsofline[3]) ? trim($tmpfieldsofline[3]) : '') ? 'WarningModuleAffiliatedToAReportedCompany' : trim($tmpfieldsofline[3]));
2858 if (!empty($tmpfieldsofline[4])) {
2859 $message2 = $langs->trans("WarningModuleAffiliatedToAPiratPlatform
", '{s}');
2860 $listofillegalurl = '';
2861 foreach (explode(" ", $tmpfieldsofline[4]) as $illegalurl) {
2862 $listofillegalurl .= ($listofillegalurl ? ' '.$langs->trans("or
").' ' : '').'<b>'.preg_replace('/[^a-z0-9\.\-]/', '', $illegalurl).'</b>';
2864 $message2 = str_replace('{s}', $listofillegalurl, $message2);
2865 $conf->cache['noncompliantmodules'][$modulekey]['message2'] = $message2;
2871 if (!empty($conf->cache['noncompliantmodules'])) {
2872 $modulekey = strtolower($nametocheck);
2873 if (in_array($modulekey, array_keys($conf->cache['noncompliantmodules']))) {
2874 $answer = trim($conf->cache['noncompliantmodules'][$modulekey]['message']);
2875 if (!empty($conf->cache['noncompliantmodules'][$modulekey]['message2'])) {
2876 $answer .= '<br>'.$conf->cache['noncompliantmodules'][$modulekey]['message2'];
2903 protected function declareNewDictionary($dictionaryArray, $langs = '')
2905 $fields = array('name', 'lib', 'sql', 'sqlsort', 'field', 'fieldvalue', 'fieldinsert', 'rowid', 'cond', 'help', 'fieldcheck');
2907 foreach ($fields as $field) {
2908 if (isset($dictionaryArray[$field])) {
2909 // @phan-suppress-next-line PhanTypeMismatchProperty
2910 $this->dictionaries['tab'.$field][] = $dictionaryArray[$field];
2913 if ($langs && !in_array($langs, $this->dictionaries[$langs])) {
2914 $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.
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,...
_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.
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_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
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)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
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.