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://ping.dolibarr.org/modules-blacklist.txt';
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();
213 public $lastVersion =
'';
219 public $needUpdate =
false;
234 public $descriptionlong;
239 public $dictionaries = array();
256 public $export_label;
266 public $export_enabled;
270 public $export_permission;
274 public $export_fields_array;
278 public $export_TypeFields_array;
282 public $export_entities_array;
286 public $export_aggregate_array;
290 public $export_examplevalues_array;
294 public $export_help_array;
301 public $export_special_array;
308 public $export_dependencies_array;
312 public $export_sql_start;
316 public $export_sql_end;
320 public $export_sql_order;
333 public $import_label;
342 public $import_entities_array;
346 public $import_tables_array;
350 public $import_tables_creator_array;
354 public $import_fields_array;
358 public $import_fieldshidden_array;
362 public $import_convertvalue_array;
366 public $import_regex_array;
370 public $import_examplevalues_array;
374 public $import_updatekeys_array;
378 public $import_run_sql_after_array;
382 public $import_TypeFields_array;
386 public $import_help_array;
396 public $always_enabled;
406 public $core_enabled;
422 public $config_page_url;
445 public $conflictwith;
457 public $warnings_activation;
464 public $warnings_activation_ext;
471 public $warnings_unactivation;
488 public $need_dolibarr_version;
494 public $max_dolibarr_version;
499 public $need_javascript_ajax;
504 public $enabled_bydefault;
509 public $hidden =
false;
514 public $url_last_version;
543 protected function _init($array_sql, $options =
'')
567 if (!$err && !preg_match(
'/newboxdefonly/', $options)) {
572 if (!$err && !preg_match(
'/noboxes/', $options)) {
597 $num = count($array_sql);
598 for ($i = 0; $i < $num; $i++) {
600 $val = $array_sql[$i];
603 if (is_array($val)) {
605 $ignoreerror = $val[
'ignoreerror'] ?? 0;
608 $sql = str_replace(
'__ENTITY__', (
string)
$conf->entity, $sql);
610 dol_syslog(get_class($this).
"::_init ignoreerror=".$ignoreerror, LOG_DEBUG);
611 $result = $this->db->query($sql, $ignoreerror);
614 $this->error = $this->db->lasterror();
617 dol_syslog(get_class($this).
"::_init Warning ".$this->db->lasterror(), LOG_WARNING);
627 $moduleNameInConf = strtolower(preg_replace(
'/^MAIN_MODULE_/',
'', $this->const_name));
629 if ($moduleNameInConf ===
'propale') {
630 $moduleNameInConf =
'propal';
631 } elseif ($moduleNameInConf ===
'supplierproposal') {
632 $moduleNameInConf =
'supplier_proposal';
635 $conf->modules[$moduleNameInConf] = $moduleNameInConf;
639 $this->db->rollback();
653 protected function _remove($array_sql, $options =
'')
682 if (!$err && !preg_match(
'/(newboxdefonly|noboxes)/', $options)) {
707 $num = count((array) $array_sql);
708 for ($i = 0; $i < $num; $i++) {
710 dol_syslog(get_class($this).
"::_remove", LOG_DEBUG);
711 $result = $this->db->query($array_sql[$i]);
713 $this->error = $this->db->error();
724 $moduleNameInConf = strtolower(preg_replace(
'/^MAIN_MODULE_/',
'', $this->const_name));
726 if ($moduleNameInConf ===
'propale') {
727 $moduleNameInConf =
'propal';
728 } elseif ($moduleNameInConf ===
'supplierproposal') {
729 $moduleNameInConf =
'supplier_proposal';
732 unset(
$conf->modules[$moduleNameInConf]);
736 $this->db->rollback();
751 $langs->load(
"admin");
753 if ($langs->transnoentitiesnoconv(
"Module".$this->numero.
"Name") !=
"Module".$this->numero.
"Name") {
755 return $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Name");
758 if (is_array($this->langfiles)) {
759 foreach ($this->langfiles as $val) {
766 if ($langs->trans(
"Module".$this->name.
"Name") !=
"Module".$this->name.
"Name") {
768 return $langs->transnoentitiesnoconv(
"Module".$this->
name.
"Name");
772 return $langs->transnoentitiesnoconv($this->
name);
785 $langs->load(
"admin");
787 if ($langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc") !=
"Module".$this->numero.
"Desc") {
789 return $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc");
792 if (is_array($this->langfiles)) {
793 foreach ($this->langfiles as $val) {
800 if ($langs->transnoentitiesnoconv(
"Module".$this->name.
"Desc") !=
"Module".$this->name.
"Desc") {
802 return $langs->trans(
"Module".$this->
name.
"Desc");
819 $langs->load(
"admin");
821 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
822 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
828 $content = file_get_contents($pathoffile,
false,
null, 0, 1024 * 1024);
830 if ((
float) DOL_VERSION >= 6.0) {
831 @include_once DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
843 $content = preg_replace(
'/<a href="/',
'<a target="_blank" rel="noopener noreferrer" href="', $content);
845 $content = nl2br($content);
849 if (!empty($this->descriptionlong)) {
850 if (is_array($this->langfiles)) {
851 foreach ($this->langfiles as $val) {
858 $content = $langs->transnoentitiesnoconv($this->descriptionlong);
862 return '<div class="moduledesclong">'.$content.
'</div>';
878 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/README-'.$langs->defaultlang.
'.md', 0);
883 $tmp = explode(
'_', $langs->defaultlang);
884 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/README-'.$tmp[0].
'.md', 0);
896 return ($filefound ? $pathoffile :
'');
908 $langs->load(
"admin");
910 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
911 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
917 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/ChangeLog-'.$langs->defaultlang.
'.md', 0);
929 $content = file_get_contents($pathoffile);
931 if ((
float) DOL_VERSION >= 6.0) {
932 @include_once DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
936 $content = nl2br($content);
952 return $this->editor_name;
962 return $this->editor_url;
976 $langs->load(
"admin");
980 $newversion = preg_replace(
'/_deprecated/',
'', $this->version);
981 if ($newversion ==
'experimental') {
982 $ret = ($translated ? $langs->transnoentitiesnoconv(
"VersionExperimental") : $newversion);
983 } elseif ($newversion ==
'development') {
984 $ret = ($translated ? $langs->transnoentitiesnoconv(
"VersionDevelopment") : $newversion);
985 } elseif ($newversion ==
'dolibarr') {
987 } elseif ($newversion) {
990 $ret = ($translated ? $langs->transnoentitiesnoconv(
"VersionUnknown") :
'unknown');
993 if (preg_match(
'/_deprecated/', $this->version)) {
994 $ret .= ($translated ?
' ('.$langs->transnoentitiesnoconv(
"Deprecated").
')' : $this->version);
1006 if (in_array($this->version, array(
'dolibarr',
'dolibarr_deprecated',
'experimental',
'development'))) {
1007 return $this->module_position;
1009 if ($this->module_position >= 100000) {
1010 return $this->module_position;
1012 $position = intval($this->module_position) + 100000;
1013 return strval($position);
1026 if ($this->version ==
'dolibarr' || $this->version ==
'dolibarr_deprecated') {
1029 if (!empty($this->version) && !in_array($this->version, array(
'experimental',
'development'))) {
1032 if (!empty($this->editor_name) || !empty($this->editor_url)) {
1035 if ($this->numero >= 100000) {
1049 return $this->langfiles;
1063 $langstring =
"ExportDataset_".$this->export_code[$r];
1064 if ($langs->trans($langstring) == $langstring) {
1066 return $langs->trans($this->export_label[$r]);
1069 return $langs->trans($langstring);
1085 $langstring =
"ImportDataset_".$this->import_code[$r];
1087 if ($langs->trans($langstring) == $langstring) {
1089 return $langs->transnoentitiesnoconv($this->import_label[$r]);
1092 return $langs->transnoentitiesnoconv($langstring);
1108 $sql =
"SELECT tms FROM ".MAIN_DB_PREFIX.
"const";
1109 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1110 $sql .=
" AND entity IN (0, ".((int)
$conf->entity).
")";
1112 dol_syslog(get_class($this).
"::getLastActiveDate", LOG_DEBUG);
1113 $resql = $this->db->query($sql);
1117 $obj = $this->db->fetch_object($resql);
1119 return $this->db->jdate($obj->tms);
1138 $sql =
"SELECT tms, note FROM ".MAIN_DB_PREFIX.
"const";
1139 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1140 $sql .=
" AND entity IN (0, ".$conf->entity.
")";
1142 dol_syslog(get_class($this).
"::getLastActiveDate", LOG_DEBUG);
1143 $resql = $this->db->query($sql);
1147 $obj = $this->db->fetch_object($resql);
1151 $tmp = json_decode($obj->note,
true);
1154 'authorid' => empty($tmp[
'authorid']) ?
'' : (int) $tmp[
'authorid'],
1155 'ip' => empty($tmp[
'ip']) ?
'' : (string) $tmp[
'ip'],
1156 'lastactivationdate' => $this->db->jdate($obj->tms),
1157 'lastactivationversion' => (!empty($tmp[
'lastactivationversion']) ? (string) $tmp[
'lastactivationversion'] :
'unknown'),
1175 global
$conf, $user;
1180 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 :
$conf->entity);
1182 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1183 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1184 $sql .=
" AND entity IN (0, ".$entity.
")";
1186 dol_syslog(get_class($this).
"::_active delete activation constant", LOG_DEBUG);
1187 $resql = $this->db->query($sql);
1192 $note = json_encode(
1194 'authorid' => (is_object($user) ? $user->id : 0),
1195 'ip' => (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']),
1196 'lastactivationversion' => $this->version,
1200 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name, value, visible, entity, note) VALUES";
1201 $sql .=
" (".$this->db->encrypt($this->const_name);
1202 $sql .=
", ".$this->db->encrypt(
'1');
1203 $sql .=
", 0, ".((int) $entity);
1204 $sql .=
", '".$this->db->escape($note).
"')";
1206 dol_syslog(get_class($this).
"::_active insert activation constant", LOG_DEBUG);
1207 $resql = $this->db->query($sql);
1230 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 :
$conf->entity);
1232 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1233 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1234 $sql .=
" AND entity IN (0, ".$entity.
")";
1236 dol_syslog(get_class($this).
"::_unactive", LOG_DEBUG);
1237 $this->db->query($sql);
1268 if (empty($reldir)) {
1272 include_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
1274 foreach (
$conf->file->dol_document_root as $dirroot) {
1276 $dirsql = $dirroot.$reldir;
1280 $listofsubdir = array(
'',
'tables/',
'data/');
1281 if ($this->db->type ==
'pgsql') {
1282 $listofsubdir[] =
'../pgsql/functions/';
1285 foreach ($listofsubdir as $subdir) {
1286 $dir = $dirsql.$subdir;
1288 $handle = @opendir($dir);
1289 if (is_resource($handle)) {
1294 while (($file = readdir($handle)) !==
false) {
1298 foreach ($files as $file) {
1299 if ($onlywithsuffix) {
1300 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1307 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'llx_') {
1319 while (($file = readdir($handle)) !==
false) {
1323 foreach ($files as $file) {
1324 if ($onlywithsuffix) {
1325 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1332 if (preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'llx_') {
1344 while (($file = readdir($handle)) !==
false) {
1348 foreach ($files as $file) {
1349 if ($onlywithsuffix) {
1350 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1357 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 9) ==
'functions') {
1369 while (($file = readdir($handle)) !==
false) {
1373 foreach ($files as $file) {
1374 if ($onlywithsuffix) {
1375 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1382 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'data') {
1394 while (($file = readdir($handle)) !==
false) {
1398 foreach ($files as $file) {
1399 if ($onlywithsuffix) {
1400 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1407 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 6) ==
'update') {
1426 dol_syslog(
"A module wants to load sql files from ".$reldir.
" but this directory was not found.", LOG_WARNING);
1443 include_once DOL_DOCUMENT_ROOT.
'/core/class/infobox.class.php';
1449 if (is_array($this->boxes)) {
1450 dol_syslog(get_class($this).
"::insert_boxes", LOG_DEBUG);
1454 foreach ($this->boxes as $key => $value) {
1455 $file = isset($this->boxes[$key][
'file']) ? $this->boxes[$key][
'file'] :
'';
1456 $note = isset($this->boxes[$key][
'note']) ? $this->boxes[$key][
'note'] :
'';
1457 $enabledbydefaulton = isset($this->boxes[$key][
'enabledbydefaulton']) ? $this->boxes[$key][
'enabledbydefaulton'] :
'Home';
1460 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] :
'';
1463 $note = isset($this->boxes[$key][2]) ? $this->boxes[$key][2] :
'';
1467 $sql =
"SELECT count(*) as nb FROM ".MAIN_DB_PREFIX.
"boxes_def";
1468 $sql .=
" WHERE file = '".$this->db->escape($file).
"'";
1469 $sql .=
" AND entity = ".$conf->entity;
1471 $sql .=
" AND note ='".$this->db->escape($note).
"'";
1474 $result = $this->db->query($sql);
1476 $obj = $this->db->fetch_object($result);
1477 if ($obj->nb == 0) {
1481 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes_def (file, entity, note)";
1482 $sql .=
" VALUES ('".$this->db->escape($file).
"', ";
1483 $sql .=
$conf->entity.
", ";
1484 $sql .= $note ?
"'".$this->db->escape($note).
"'" :
"null";
1487 dol_syslog(get_class($this).
"::insert_boxes", LOG_DEBUG);
1488 $resql = $this->db->query($sql);
1493 if (!$err && !preg_match(
'/newboxdefonly/', $option)) {
1494 $lastid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"boxes_def",
"rowid");
1496 foreach ($pos_name as $key2 => $val2) {
1498 if ($enabledbydefaulton && $val2 != $enabledbydefaulton) {
1502 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes (box_id, position, box_order, fk_user, entity)";
1503 $sql .=
" VALUES (".((int) $lastid).
", ".((int) $key2).
", '0', 0, ".((int)
$conf->entity).
")";
1505 dol_syslog(get_class($this).
"::insert_boxes onto page ".$key2.
"=".$val2, LOG_DEBUG);
1506 $resql = $this->db->query($sql);
1514 $this->db->commit();
1516 $this->error = $this->db->lasterror();
1517 $this->db->rollback();
1522 $this->error = $this->db->lasterror();
1545 if (is_array($this->boxes)) {
1546 foreach ($this->boxes as $key => $value) {
1548 if (empty($this->boxes[$key][
'file'])) {
1549 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] :
'';
1551 $file = $this->boxes[$key][
'file'];
1559 if ($file ==
'box_graph_product_distribution.php') {
1560 if (isModEnabled(
"product") || isModEnabled(
"service")) {
1561 dol_syslog(
"We discard deleting module ".$file.
" because another module still active requires it.");
1566 if ($this->db->type ==
'sqlite3') {
1569 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes ";
1570 $sql .=
"WHERE ".MAIN_DB_PREFIX.
"boxes.box_id IN (";
1571 $sql .=
"SELECT ".MAIN_DB_PREFIX.
"boxes_def.rowid ";
1572 $sql .=
"FROM ".MAIN_DB_PREFIX.
"boxes_def ";
1573 $sql .=
"WHERE ".MAIN_DB_PREFIX.
"boxes_def.file = '".$this->db->escape($file).
"') ";
1574 $sql .=
"AND ".MAIN_DB_PREFIX.
"boxes.entity = ".
$conf->entity;
1576 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes";
1577 $sql .=
" USING ".MAIN_DB_PREFIX.
"boxes, ".MAIN_DB_PREFIX.
"boxes_def";
1578 $sql .=
" WHERE ".MAIN_DB_PREFIX.
"boxes.box_id = ".MAIN_DB_PREFIX.
"boxes_def.rowid";
1579 $sql .=
" AND ".MAIN_DB_PREFIX.
"boxes_def.file = '".$this->db->escape($file).
"'";
1580 $sql .=
" AND ".MAIN_DB_PREFIX.
"boxes.entity = ".
$conf->entity;
1583 dol_syslog(get_class($this).
"::delete_boxes", LOG_DEBUG);
1584 $resql = $this->db->query($sql);
1586 $this->error = $this->db->lasterror();
1590 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes_def";
1591 $sql .=
" WHERE file = '".$this->db->escape($file).
"'";
1592 $sql .=
" AND entity = ".$conf->entity;
1594 dol_syslog(get_class($this).
"::delete_boxes", LOG_DEBUG);
1595 $resql = $this->db->query($sql);
1597 $this->error = $this->db->lasterror();
1615 include_once DOL_DOCUMENT_ROOT .
'/core/class/infobox.class.php';
1616 include_once DOL_DOCUMENT_ROOT .
'/cron/class/cronjob.class.php';
1617 include_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
1619 global
$conf, $user;
1622 $user =
new User($this->db);
1627 if (is_array($this->cronjobs)) {
1628 dol_syslog(get_class($this) .
"::insert_cronjobs", LOG_DEBUG);
1630 foreach ($this->cronjobs as $key => $value) {
1633 $entity = isset($value[
'entity']) ? $value[
'entity'] :
$conf->entity;
1634 $label = isset($value[
'label']) ? $value[
'label'] :
'';
1635 $jobtype = isset($value[
'jobtype']) ? $value[
'jobtype'] :
'';
1636 $classesname = isset($value[
'class']) ? $value[
'class'] :
'';
1637 $objectname = isset($value[
'objectname']) ? $value[
'objectname'] :
'';
1638 $methodename = isset($value[
'method']) ? $value[
'method'] :
'';
1639 $command = isset($value[
'command']) ? $value[
'command'] :
'';
1640 $params = isset($value[
'parameters']) ? $value[
'parameters'] :
'';
1641 $md5params = isset($value[
'md5params']) ? $value[
'md5params'] :
'';
1642 $comment = isset($value[
'comment']) ? $value[
'comment'] :
'';
1643 $frequency = isset($value[
'frequency']) ? $value[
'frequency'] :
'';
1644 $unitfrequency = isset($value[
'unitfrequency']) ? $value[
'unitfrequency'] :
'';
1645 $priority = isset($value[
'priority']) ? $value[
'priority'] :
'';
1646 $datestart = isset($value[
'datestart']) ? $value[
'datestart'] :
'';
1647 $dateend = isset($value[
'dateend']) ? $value[
'dateend'] :
'';
1648 $datenextrun = isset($value[
'datenextrun']) ? $value[
'datenextrun'] : $now;
1649 $status = isset($value[
'status']) ? $value[
'status'] :
'';
1650 $maxrun = isset($value[
'maxrun']) ? $value[
'maxrun'] : 0;
1651 $libname = isset($value[
'libname']) ? $value[
'libname'] :
'';
1652 $test = isset($value[
'test']) ? $value[
'test'] :
'';
1655 $sql =
"SELECT count(*) as nb FROM " . MAIN_DB_PREFIX .
"cronjob";
1657 $sql .=
" WHERE label = '".$this->db->escape($label).
"'";
1675 $sql .=
" AND entity = " . ((int) $entity);
1677 $result = $this->db->query($sql);
1679 $this->error = $this->db->lasterror();
1685 $obj = $this->db->fetch_object($result);
1690 $cronjob =
new Cronjob($this->db);
1692 $cronjob->entity = $entity;
1693 $cronjob->label = $label;
1694 $cronjob->jobtype = $jobtype;
1695 $cronjob->classesname = $classesname;
1696 $cronjob->objectname = $objectname;
1697 $cronjob->methodename = $methodename;
1698 $cronjob->command = $command;
1699 $cronjob->params = $params;
1700 $cronjob->md5params = $md5params;
1701 $cronjob->note_private = $comment;
1702 $cronjob->frequency = $frequency;
1703 $cronjob->unitfrequency = $unitfrequency;
1704 $cronjob->priority = $priority;
1705 $cronjob->datestart = $datestart;
1706 $cronjob->dateend = $dateend;
1707 $cronjob->datenextrun = $datenextrun;
1708 $cronjob->maxrun = $maxrun;
1709 $cronjob->status = $status;
1710 $cronjob->test = $test;
1711 $cronjob->libname = $libname;
1712 $cronjob->module_name = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
1714 $retCreate = $cronjob->create($user);
1716 if ($retCreate < 0) {
1717 $this->error = implode(
"\n", array_merge([$cronjob->error], $cronjob->errors));
1739 if (is_array($this->cronjobs)) {
1740 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"cronjob";
1741 $sql .=
" WHERE module_name = '".$this->db->escape(empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class).
"'";
1742 $sql .=
" AND entity = ".$conf->entity;
1743 $sql .=
" AND test = '1'";
1746 dol_syslog(get_class($this).
"::delete_cronjobs", LOG_DEBUG);
1747 $resql = $this->db->query($sql);
1749 $this->error = $this->db->lasterror();
1770 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1771 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" LIKE '".$this->db->escape($this->const_name).
"_TABS_%'";
1772 $sql .=
" AND entity = ".((int)
$conf->entity);
1774 dol_syslog(get_class($this).
"::delete_tabs", LOG_DEBUG);
1775 if (!$this->db->query($sql)) {
1776 $this->error = $this->db->lasterror();
1796 if (!empty($this->tabs)) {
1797 dol_syslog(get_class($this).
"::insert_tabs", LOG_DEBUG);
1800 foreach ($this->tabs as $key => $value) {
1801 if (is_array($value) && count($value) == 0) {
1805 $entity =
$conf->entity;
1808 if (is_array($value)) {
1809 $newvalue = $value[
'data'];
1810 if (isset($value[
'entity'])) {
1811 $entity = $value[
'entity'];
1816 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (";
1821 $sql .=
", visible";
1824 $sql .=
" VALUES (";
1825 $sql .= $this->db->encrypt($this->const_name.
"_TABS_".$i);
1826 $sql .=
", 'chaine'";
1827 $sql .=
", ".$this->db->encrypt($newvalue);
1830 $sql .=
", ".((int) $entity);
1833 $resql = $this->db->query($sql);
1836 if ($this->db->lasterrno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1837 $this->error = $this->db->lasterror();
1838 $this->errors[] = $this->db->lasterror();
1863 if (empty($this->
const)) {
1869 foreach ($this->
const as $key => $value) {
1870 $name = $this->
const[$key][0];
1871 $type = $this->
const[$key][1];
1872 $val = $this->
const[$key][2];
1873 $note = isset($this->
const[$key][3]) ? $this->
const[$key][3] :
'';
1874 $visible = isset($this->
const[$key][4]) ? $this->
const[$key][4] : 0;
1875 $entity = (!empty($this->
const[$key][5]) && $this->
const[$key][5] !=
'current') ? 0 :
$conf->entity;
1878 if (empty($visible)) {
1881 if (empty($val) && $val !=
'0') {
1885 if (!empty($name)) {
1886 $sql =
"SELECT count(*) as nb";
1887 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const";
1888 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($name).
"'";
1889 $sql .=
" AND entity = ".((int) $entity);
1891 $result = $this->db->query($sql);
1893 $row = $this->db->fetch_row($result);
1896 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name, type, value, note, visible, entity)";
1897 $sql .=
" VALUES (";
1898 $sql .= $this->db->encrypt($name);
1899 $sql .=
", '".$this->db->escape($type).
"'";
1900 $sql .=
", ".(($val !=
'') ? $this->db->encrypt($val) :
"''");
1901 $sql .=
", ".($note ?
"'".$this->db->escape($note).
"'" :
"null");
1902 $sql .=
", '".$this->db->escape($visible).
"'";
1903 $sql .=
", ".((int) $entity);
1906 if (!$this->db->query($sql)) {
1910 $conf->global->$name = $val;
1913 dol_syslog(__METHOD__.
" constant '".$name.
"' already exists", LOG_DEBUG);
1937 if (empty($this->
const)) {
1941 foreach ($this->
const as $key => $value) {
1942 $name = $this->
const[$key][0];
1943 $deleteonunactive = (!empty($this->
const[$key][6])) ? 1 : 0;
1945 if ($deleteonunactive) {
1946 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1947 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($name).
"'";
1948 $sql .=
" AND entity in (0, ".$conf->entity.
")";
1949 dol_syslog(get_class($this).
"::delete_const", LOG_DEBUG);
1950 if (!$this->db->query($sql)) {
1951 $this->error = $this->db->lasterror();
1972 global
$conf, $user;
1975 $entity = (!empty($force_entity) ? $force_entity :
$conf->entity);
1977 dol_syslog(get_class($this).
"::insert_permissions", LOG_DEBUG);
1980 $sql_del =
"SELECT ".$this->db->decrypt(
'value').
" as value";
1981 $sql_del .=
" FROM ".MAIN_DB_PREFIX.
"const";
1982 $sql_del .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1983 $sql_del .=
" AND entity IN (0,".((int) $entity).
")";
1985 $resql = $this->db->query($sql_del);
1988 $obj = $this->db->fetch_object($resql);
1990 if ($obj !==
null && !empty($obj->value) && !empty($this->rights)) {
1991 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
2005 foreach ($this->rights as $key => $value) {
2006 $r_id = $this->rights[$key][self::KEY_ID];
2007 $r_label = $this->rights[$key][self::KEY_LABEL];
2008 $r_type = $this->rights[$key][self::KEY_TYPE] ??
'w';
2009 $r_default = $this->rights[$key][self::KEY_DEFAULT] ?? 0;
2010 $r_perms = $this->rights[$key][self::KEY_FIRST_LEVEL] ??
'';
2011 $r_subperms = $this->rights[$key][self::KEY_SECOND_LEVEL] ??
'';
2014 if (empty($r_perms)) {
2019 $r_module = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2022 $r_module_origin =
'';
2024 if (isset($this->rights[$key][self::KEY_MODULE])) {
2026 $r_module = $this->rights[$key][self::KEY_MODULE];
2028 $r_module_origin = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2032 $r_enabled = $this->rights[$key][self::KEY_ENABLED] ??
'1';
2035 $sql =
"SELECT count(*) as nb FROM ".MAIN_DB_PREFIX.
"rights_def";
2036 $sql .=
" WHERE entity = ".((int) $entity);
2037 $sql .=
" AND id = ".((int) $r_id);
2039 $resqlselect = $this->db->query($sql);
2041 $objcount = $this->db->fetch_object($resqlselect);
2042 if ($objcount && $objcount->nb == 0) {
2043 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"rights_def (";
2046 $sql .=
", libelle";
2048 $sql .=
", module_origin";
2050 $sql .=
", bydefault";
2052 $sql .=
", subperms";
2053 $sql .=
", enabled";
2054 $sql .=
") VALUES (";
2055 $sql .= ((int) $r_id);
2056 $sql .=
", ".((int) $entity);
2057 $sql .=
", '".$this->db->escape($r_label).
"'";
2058 $sql .=
", '".$this->db->escape($r_module).
"'";
2059 $sql .=
", '".$this->db->escape($r_module_origin).
"'";
2060 $sql .=
", '".$this->db->escape($r_type).
"'";
2061 $sql .=
", ".((int) $r_default);
2062 $sql .=
", '".$this->db->escape($r_perms).
"'";
2063 $sql .=
", '".$this->db->escape($r_subperms).
"'";
2064 $sql .=
", '".$this->db->escape($r_enabled).
"'";
2067 $resqlinsert = $this->db->query($sql, 1);
2069 if (!$resqlinsert) {
2070 if ($this->db->errno() !=
"DB_ERROR_RECORD_ALREADY_EXISTS") {
2071 $this->error = $this->db->lasterror();
2075 dol_syslog(get_class($this).
"::insert_permissions record already exists", LOG_INFO);
2079 $this->db->free($resqlinsert);
2082 $this->db->free($resqlselect);
2086 if (!empty($reinitadminperms)) {
2087 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"user WHERE admin = 1";
2088 dol_syslog(get_class($this).
"::insert_permissions Search all admin users", LOG_DEBUG);
2090 $resqlseladmin = $this->db->query($sql, 1);
2092 if ($resqlseladmin) {
2093 $num = $this->db->num_rows($resqlseladmin);
2096 $obj2 = $this->db->fetch_object($resqlseladmin);
2097 dol_syslog(get_class($this).
"::insert_permissions Add permission id ".$r_id.
" to user id=".$obj2->rowid);
2099 $tmpuser =
new User($this->db);
2100 $result = $tmpuser->fetch($obj2->rowid);
2102 $tmpuser->addrights($r_id,
'',
'', 0, 1);
2104 dol_syslog(get_class($this).
"::insert_permissions Failed to add the permission to user because fetch return an error", LOG_ERR);
2114 if (!empty($reinitadminperms) && !empty($user->admin)) {
2116 $user->clearrights();
2117 $user->loadRights();
2120 $this->db->free($resql);
2122 $this->error = $this->db->lasterror();
2143 $module = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
2145 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"rights_def";
2146 $sql .=
" WHERE (module = '".$this->db->escape($module).
"' OR module_origin = '".$this->db->escape($module).
"')";
2149 if (empty($this->core_enabled)) {
2150 $sql .=
" AND entity = ".((int)
$conf->entity);
2153 dol_syslog(get_class($this).
"::delete_permissions", LOG_DEBUG);
2154 if (!$this->db->query($sql)) {
2155 $this->error = $this->db->lasterror();
2172 global
$conf, $user;
2174 if (!is_array($this->menu) || empty($this->menu)) {
2178 include_once DOL_DOCUMENT_ROOT.
'/core/class/menubase.class.php';
2180 dol_syslog(get_class($this).
"::insert_menus", LOG_DEBUG);
2185 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 :
$conf->entity);
2189 foreach ($this->menu as $key => $value) {
2191 $menu->menu_handler =
'all';
2194 $menu->module = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2196 if (!$this->menu[$key][
'fk_menu']) {
2200 $fk_parent = $this->menu[$key][
'fk_menu'];
2202 if (preg_match(
'/^r=/', $fk_parent)) {
2203 $fk_parent = str_replace(
'r=',
'', $fk_parent);
2204 if (isset($this->menu[$fk_parent][
'rowid'])) {
2205 $menu->fk_menu = $this->menu[$fk_parent][
'rowid'];
2208 } elseif (preg_match(
'/^fk_mainmenu=([a-zA-Z0-9_]+),fk_leftmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
2209 $menu->fk_menu = -1;
2210 $menu->fk_mainmenu = $reg[1];
2211 $menu->fk_leftmenu = $reg[2];
2213 } elseif (preg_match(
'/^fk_mainmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
2214 $menu->fk_menu = -1;
2215 $menu->fk_mainmenu = $reg[1];
2216 $menu->fk_leftmenu =
'';
2219 if (!$foundparent) {
2220 $this->error =
"ErrorBadDefinitionOfMenuArrayInModuleDescriptor";
2221 dol_syslog(get_class($this).
"::insert_menus ".$this->error.
" ".$this->menu[$key][
'fk_menu'], LOG_ERR);
2225 $menu->type = $this->menu[$key][
'type'];
2226 $menu->mainmenu = isset($this->menu[$key][
'mainmenu']) ? $this->menu[$key][
'mainmenu'] : (isset($menu->fk_mainmenu) ? $menu->fk_mainmenu :
'');
2227 $menu->leftmenu = isset($this->menu[$key][
'leftmenu']) ? $this->menu[$key][
'leftmenu'] :
'';
2228 $menu->title = $this->menu[$key][
'titre'];
2229 $menu->prefix = isset($this->menu[$key][
'prefix']) ? $this->menu[$key][
'prefix'] :
'';
2230 $menu->url = $this->menu[$key][
'url'];
2231 $menu->langs = isset($this->menu[$key][
'langs']) ? $this->menu[$key][
'langs'] :
'';
2232 $menu->position = $this->menu[$key][
'position'];
2233 $menu->perms = $this->menu[$key][
'perms'];
2234 $menu->target = isset($this->menu[$key][
'target']) ? $this->menu[$key][
'target'] :
'';
2235 $menu->user = $this->menu[$key][
'user'];
2236 $menu->enabled = isset($this->menu[$key][
'enabled']) ? $this->menu[$key][
'enabled'] : 0;
2237 $menu->position = $this->menu[$key][
'position'];
2238 $menu->entity = $entity;
2241 $result = $menu->create($user);
2243 $this->menu[$key][
'rowid'] = $result;
2245 $this->error = $menu->error;
2246 dol_syslog(get_class($this).
'::insert_menus result='.$result.
" ".$this->error, LOG_ERR);
2254 $this->db->commit();
2256 dol_syslog(get_class($this).
"::insert_menus ".$this->error, LOG_ERR);
2257 $this->db->rollback();
2278 $module = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
2280 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"menu";
2281 $sql .=
" WHERE module = '".$this->db->escape($module).
"'";
2282 $sql .=
" AND menu_handler = 'all'";
2283 $sql .=
" AND entity IN (0, ".$conf->entity.
")";
2285 dol_syslog(get_class($this).
"::delete_menus", LOG_DEBUG);
2286 $resql = $this->db->query($sql);
2288 $this->error = $this->db->lasterror();
2304 global $langs,
$conf;
2309 if (isset($this->dirs) && is_array($this->dirs)) {
2310 foreach ($this->dirs as $key => $value) {
2313 if (!is_array($value)) {
2316 $constname = $this->const_name.
"_DIR_";
2317 $dir = $this->dirs[$key][1];
2318 $addtodatabase = empty($this->dirs[$key][2]) ?
'' : $this->dirs[$key][2];
2319 $subname = empty($this->dirs[$key][3]) ?
'' : strtoupper($this->dirs[$key][3]);
2320 $forcename = empty($this->dirs[$key][4]) ?
'' : strtoupper($this->dirs[$key][4]);
2322 if (!empty($forcename)) {
2323 $constname =
'MAIN_MODULE_'.$forcename.
"_DIR_";
2325 if (!empty($subname)) {
2326 $constname = $constname.$subname.
"_";
2329 $name = $constname.strtoupper($this->dirs[$key][0]);
2334 $fulldir = DOL_DATA_ROOT.$dir;
2336 $fulldir = DOL_DATA_ROOT.
"/".
$conf->entity.$dir;
2339 if (!empty($fulldir) && !file_exists($fulldir)) {
2340 if (
dol_mkdir($fulldir, DOL_DATA_ROOT) < 0) {
2341 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $fulldir);
2342 dol_syslog(get_class($this).
"::_init ".$this->error, LOG_ERR);
2348 if (!empty($addtodatabase) && !empty($name)) {
2377 $sql =
"SELECT count(*)";
2378 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const";
2379 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($name).
"'";
2380 $sql .=
" AND entity = ".$conf->entity;
2382 dol_syslog(get_class($this).
"::insert_dirs", LOG_DEBUG);
2383 $result = $this->db->query($sql);
2385 $row = $this->db->fetch_row($result);
2388 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name, type, value, note, visible, entity)";
2389 $sql .=
" VALUES (".$this->db->encrypt($name).
", 'chaine', ".$this->db->encrypt($dir).
", '".$this->db->escape(
"Directory for module ".$this->
name).
"', '0', ".((int)
$conf->entity).
")";
2391 dol_syslog(get_class($this).
"::insert_dirs", LOG_DEBUG);
2392 $this->db->query($sql);
2395 $this->error = $this->db->lasterror();
2416 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
2417 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" LIKE '".$this->db->escape($this->const_name).
"_DIR_%'";
2418 $sql .=
" AND entity = ".$conf->entity;
2420 dol_syslog(get_class($this).
"::delete_dirs", LOG_DEBUG);
2421 if (!$this->db->query($sql)) {
2422 $this->error = $this->db->lasterror();
2439 global
$conf, $langs;
2443 if (is_array($this->module_parts)) {
2444 if (empty($this->module_parts[
'icon']) && !empty($this->picto) && preg_match(
'/^fa\-/', $this->picto)) {
2445 $this->module_parts[
'icon'] = $this->picto;
2448 foreach ($this->module_parts as $key => $value) {
2449 if (is_array($value) && count($value) == 0) {
2454 if ($key ==
'websitetemplates' && $value == 1) {
2458 $docs =
dol_dir_list($srcroot,
'directories', 0,
'website_.*$');
2459 foreach ($docs as $cursorfile) {
2460 $src = $srcroot.
'/'.$cursorfile[
'name'];
2461 $dest = DOL_DATA_ROOT.
'/doctemplates/websites/'.$cursorfile[
'name'];
2468 $result = dol_compress_dir($src, $dest.
'.zip',
'zip');
2471 $this->error = ($errormsg ? $errormsg : $langs->trans(
'ErrorFailToCreateZip', $dest));
2472 $this->errors[] = ($errormsg ? $errormsg : $langs->trans(
'ErrorFailToCreateZip', $dest));
2477 $docs =
dol_dir_list($srcroot,
'files', 0,
'website_.*\.jpg$');
2478 foreach ($docs as $cursorfile) {
2479 $src = $srcroot.
'/'.$cursorfile[
'name'];
2480 $dest = DOL_DATA_ROOT.
'/doctemplates/websites/'.$cursorfile[
'name'];
2486 $entity =
$conf->entity;
2490 if (is_array($value)) {
2493 if (isset($value[
'data']) && is_array($value[
'data'])) {
2494 $newvalue = json_encode($value[
'data']);
2495 if (isset($value[
'entity'])) {
2496 $entity = $value[
'entity'];
2498 } elseif (isset($value[
'data']) && !is_array($value[
'data'])) {
2499 $newvalue = $value[
'data'];
2500 if (isset($value[
'entity'])) {
2501 $entity = $value[
'entity'];
2504 $newvalue = json_encode($value);
2508 if (!empty($newvalue)) {
2509 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (";
2514 $sql .=
", visible";
2517 $sql .=
" VALUES (";
2518 $sql .=
" ".$this->db->encrypt($this->const_name.
"_".strtoupper($key), 1);
2519 $sql .=
", 'chaine'";
2520 $sql .=
", ".$this->db->encrypt($newvalue, 1);
2523 $sql .=
", ".((int) $entity);
2526 dol_syslog(get_class($this).
"::insert_module_parts for key=".$this->const_name.
"_".strtoupper($key), LOG_DEBUG);
2528 $resql = $this->db->query($sql, 1);
2530 if ($this->db->lasterrno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2532 $this->error = $this->db->lasterror();
2534 dol_syslog(get_class($this).
"::insert_module_parts for ".$this->const_name.
"_".strtoupper($key).
" Record already exists.", LOG_WARNING);
2556 if (is_array($this->module_parts)) {
2557 dol_syslog(get_class($this).
"::delete_module_parts", LOG_DEBUG);
2559 if (empty($this->module_parts[
'icon']) && !empty($this->picto) && preg_match(
'/^fa\-/', $this->picto)) {
2560 $this->module_parts[
'icon'] = $this->picto;
2563 foreach ($this->module_parts as $key => $value) {
2565 if (is_array($value) && isset($value[
'entity'])) {
2566 $entity = $value[
'entity'];
2568 $entity =
$conf->entity;
2571 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
2572 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" LIKE '".$this->db->escape($this->const_name).
"_".strtoupper($key).
"'";
2573 $sql .=
" AND entity = ".((int) $entity);
2575 if (!$this->db->query($sql)) {
2576 $this->error = $this->db->lasterror();
2593 public function init($options =
'')
2595 return $this->
_init(array(), $options);
2606 public function remove($options =
'')
2608 return $this->
_remove(array(), $options);
2626 $imginfo =
"info_black";
2629 $const_name =
'MAIN_MODULE_'.strtoupper(preg_replace(
'/^mod/i',
'', get_class($this)));
2633 if (preg_match(
'/development/i', $version)) {
2634 $versiontrans .=
'warning';
2636 if (preg_match(
'/experimental/i', $version)) {
2637 $versiontrans .=
'warning';
2639 if (preg_match(
'/deprecated/i', $version)) {
2640 $versiontrans .=
'warning';
2644 <div class="box-flex-item info-box-module'
2645 .(getDolGlobalString($const_name) ?
'' :
' --disabled')
2647 .($this->needUpdate ?
' --need-update' :
'')
2649 <div class="info-box info-box-sm info-box-module">
2650 <div class="info-box-icon'.(!
getDolGlobalString($const_name) ?
'' :
' info-box-icon-module-enabled'.($versiontrans ?
' info-box-icon-module-warning' :
'')).
'">';
2655 if (!empty($this->picto)) {
2656 if (preg_match(
'/^\//i', $this->picto)) {
2657 $return .=
img_picto($alttext, $this->picto,
'class="inline-block valignmiddle"', 1);
2659 $return .=
img_object($alttext, $this->picto,
'class="inline-block valignmiddle"');
2662 $return .=
img_object($alttext,
'generic',
'class="inline-block valignmiddle"');
2665 if ($this->
isCoreOrExternalModule() ==
'external' || preg_match(
'/development|experimental|deprecated/i', $version)) {
2666 $versionTitle = $langs->trans(
"Version").
' '.$this->
getVersion(1);
2667 if ($this->needUpdate) {
2668 $versionTitle .=
'<br>'.$langs->trans(
'ModuleUpdateAvailable').
' : '.$this->lastVersion;
2671 $return .=
'<span class="info-box-icon-version'.($versiontrans ?
' '.$versiontrans :
'').
' classfortooltip" title="'.
dol_escape_js($versionTitle).
'" >';
2673 $return .=
'</span>';
2677 <div class="info-box-content info-box-text-module'.(!
getDolGlobalString($const_name) ?
'' :
' info-box-module-enabled'.($versiontrans ?
' info-box-content-warning' :
'')).
'">
2678 <span class="info-box-title">'.$this->
getName().
'</span>
2681 $return .=
'<div class="valignmiddle inline-block info-box-more">';
2683 $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>';
2684 $return .= '</div><br>';
2686 $return .= '<div class="valignmiddle
inline-block info-box-actions
">';
2687 $return .= '<div class="valignmiddle
inline-block info-box-setup
">';
2688 $return .= $codetoconfig;
2689 $return .= '</div>';
2690 $return .= '<div class="valignmiddle
inline-block marginleftonly marginrightonly
">';
2691 $return .= $codeenabledisable;
2692 $return .= '</div>';
2693 $return .= '</div>';
2696 </div><!-- /.info-box-content -->
2697 </div><!-- /.info-box -->
2711 public function checkForUpdate()
2713 require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
2714 if (!empty($this->url_last_version)) {
2715 $lastVersion = getURLContent($this->url_last_version, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only
2716 if (isset($lastVersion['content']) && strlen($lastVersion['content']) < 30) {
2717 // 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 _ . -
2718 $this->lastVersion = preg_replace("/[^a-zA-Z0-9_\.\-]+/
", "", $lastVersion['content']);
2719 if (version_compare($this->lastVersion, $this->version) > 0) {
2720 $this->needUpdate = true;
2723 $this->needUpdate = false;
2740 public function checkForCompliance($nametocheck = '')
2742 global $conf, $langs;
2744 if (empty($nametocheck)) {
2745 $nametocheck = $this->name;
2748 // Get list of illegal modules name or ID
2749 if (empty($conf->cache['noncompliantmodules'])) {
2750 require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
2752 $result = getURLContent(self::URL_FOR_BLACKLISTED_MODULES, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only
2753 if (isset($result['content']) && $result['http_code'] == 200) {
2754 $langs->load("errors
");
2756 // 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 _ . -
2757 $arrayoflines = preg_split("/[\n,]/
", $result['content']);
2758 foreach ($arrayoflines as $line) {
2759 $tmpfieldsofline = explode(';', $line);
2760 $modulekey = strtolower($tmpfieldsofline[0]);
2761 $conf->cache['noncompliantmodules'][$modulekey]['name'] = $tmpfieldsofline[0];
2762 $conf->cache['noncompliantmodules'][$modulekey]['id'] = (isset($tmpfieldsofline[1]) ? $tmpfieldsofline[1] : '');
2763 $conf->cache['noncompliantmodules'][$modulekey]['signature'] = (isset($tmpfieldsofline[2]) ? $tmpfieldsofline[2] : '');
2764 $conf->cache['noncompliantmodules'][$modulekey]['message'] = $langs->trans(empty($tmpfieldsofline[3]) ? 'WarningModuleAffiliatedToAReportedCompany' : $tmpfieldsofline[3]);
2765 if (!empty($tmpfieldsofline[4])) {
2766 $message2 = $langs->trans("WarningModuleAffiliatedToAPiratPlatform
", '{s}');
2767 $listofillegalurl = '';
2768 foreach (explode(" ", $tmpfieldsofline[4]) as $illegalurl) {
2769 $listofillegalurl .= ($listofillegalurl ? ' '.$langs->trans("or
").' ' : '').'<b>'.preg_replace('/[^a-z0-9\.\-]/', '', $illegalurl).'</b>';
2771 $message2 = str_replace('{s}', $listofillegalurl, $message2);
2772 $conf->cache['noncompliantmodules'][$modulekey]['message2'] = $message2;
2778 if (!empty($conf->cache['noncompliantmodules'])) {
2779 $modulekey = strtolower($nametocheck);
2780 if (in_array($modulekey, array_keys($conf->cache['noncompliantmodules']))) {
2781 $answer = trim($conf->cache['noncompliantmodules'][$modulekey]['message']);
2782 if (!empty($conf->cache['noncompliantmodules'][$modulekey]['message2'])) {
2783 $answer .= '<br>'.$conf->cache['noncompliantmodules'][$modulekey]['message2'];
2810 protected function declareNewDictionary($dictionaryArray, $langs = '')
2812 $fields = array('name', 'lib', 'sql', 'sqlsort', 'field', 'fieldvalue', 'fieldinsert', 'rowid', 'cond', 'help', 'fieldcheck');
2814 foreach ($fields as $field) {
2815 if (isset($dictionaryArray[$field])) {
2816 // @phan-suppress-next-line PhanTypeMismatchProperty
2817 $this->dictionaries['tab'.$field][] = $dictionaryArray[$field];
2820 if ($langs && !in_array($langs, $this->dictionaries[$langs])) {
2821 $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.
insert_permissions($reinitadminperms=0, $force_entity=null, $notrigger=0)
Adds access rights.
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.
getPublisher()
Gives the publisher name.
getChangeLog()
Gives the changelog.
insert_cronjobs()
Adds cronjobs.
create_dirs()
Creates directories.
delete_module_parts()
Removes generic parts.
getVersion($translated=1)
Gives module version (translated if param $translated is on) For 'experimental' modules,...
_unactive()
Module deactivation.
getDesc()
Gives the translated module description if translation exists in admin.lang or the default module des...
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.
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_now($mode='auto')
Return date for now.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.