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;
145 const KEY_DEFAULT = 3;
146 const KEY_FIRST_LEVEL = 4;
147 const KEY_SECOND_LEVEL = 5;
148 const KEY_MODULE = 6;
149 const KEY_ENABLED = 7;
154 public $menu = array();
183 public $module_parts = array();
232 public $descriptionlong;
237 public $dictionaries = array();
254 public $export_label;
264 public $export_enabled;
268 public $export_permission;
272 public $export_fields_array;
276 public $export_TypeFields_array;
280 public $export_entities_array;
284 public $export_aggregate_array;
288 public $export_examplevalues_array;
292 public $export_help_array;
299 public $export_special_array;
306 public $export_dependencies_array;
310 public $export_sql_start;
314 public $export_sql_end;
318 public $export_sql_order;
331 public $import_label;
340 public $import_entities_array;
344 public $import_tables_array;
348 public $import_tables_creator_array;
352 public $import_fields_array;
356 public $import_fieldshidden_array;
360 public $import_convertvalue_array;
364 public $import_regex_array;
368 public $import_examplevalues_array;
372 public $import_updatekeys_array;
376 public $import_run_sql_after_array;
380 public $import_TypeFields_array;
384 public $import_help_array;
394 public $always_enabled;
404 public $core_enabled;
420 public $config_page_url;
443 public $conflictwith;
455 public $warnings_activation;
462 public $warnings_activation_ext;
469 public $warnings_unactivation;
486 public $need_dolibarr_version;
491 public $need_javascript_ajax;
496 public $enabled_bydefault;
501 public $hidden =
false;
506 public $url_last_version;
535 protected function _init($array_sql, $options =
'')
559 if (!$err && !preg_match(
'/newboxdefonly/', $options)) {
564 if (!$err && !preg_match(
'/noboxes/', $options)) {
589 $num = count($array_sql);
590 for ($i = 0; $i < $num; $i++) {
592 $val = $array_sql[$i];
595 if (is_array($val)) {
597 $ignoreerror = $val[
'ignoreerror'];
600 $sql = str_replace(
'__ENTITY__', (
string) $conf->entity, $sql);
602 dol_syslog(get_class($this).
"::_init ignoreerror=".$ignoreerror, LOG_DEBUG);
603 $result = $this->db->query($sql, $ignoreerror);
606 $this->error = $this->db->lasterror();
609 dol_syslog(get_class($this).
"::_init Warning ".$this->db->lasterror(), LOG_WARNING);
619 $moduleNameInConf = strtolower(preg_replace(
'/^MAIN_MODULE_/',
'', $this->const_name));
621 if ($moduleNameInConf ===
'propale') {
622 $moduleNameInConf =
'propal';
623 } elseif ($moduleNameInConf ===
'supplierproposal') {
624 $moduleNameInConf =
'supplier_proposal';
627 $conf->modules[$moduleNameInConf] = $moduleNameInConf;
631 $this->db->rollback();
645 protected function _remove($array_sql, $options =
'')
674 if (!$err && !preg_match(
'/(newboxdefonly|noboxes)/', $options)) {
699 $num = count((array) $array_sql);
700 for ($i = 0; $i < $num; $i++) {
702 dol_syslog(get_class($this).
"::_remove", LOG_DEBUG);
703 $result = $this->db->query($array_sql[$i]);
705 $this->error = $this->db->error();
716 $moduleNameInConf = strtolower(preg_replace(
'/^MAIN_MODULE_/',
'', $this->const_name));
718 if ($moduleNameInConf ===
'propale') {
719 $moduleNameInConf =
'propal';
720 } elseif ($moduleNameInConf ===
'supplierproposal') {
721 $moduleNameInConf =
'supplier_proposal';
724 unset($conf->modules[$moduleNameInConf]);
728 $this->db->rollback();
743 $langs->load(
"admin");
745 if ($langs->transnoentitiesnoconv(
"Module".$this->numero.
"Name") !=
"Module".$this->numero.
"Name") {
747 return $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Name");
750 if (is_array($this->langfiles)) {
751 foreach ($this->langfiles as $val) {
758 if ($langs->trans(
"Module".$this->name.
"Name") !=
"Module".$this->name.
"Name") {
760 return $langs->transnoentitiesnoconv(
"Module".$this->
name.
"Name");
764 return $langs->transnoentitiesnoconv($this->
name);
777 $langs->load(
"admin");
779 if ($langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc") !=
"Module".$this->numero.
"Desc") {
781 return $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc");
784 if (is_array($this->langfiles)) {
785 foreach ($this->langfiles as $val) {
792 if ($langs->transnoentitiesnoconv(
"Module".$this->name.
"Desc") !=
"Module".$this->name.
"Desc") {
794 return $langs->trans(
"Module".$this->
name.
"Desc");
811 $langs->load(
"admin");
813 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
814 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
820 $content = file_get_contents($pathoffile,
false,
null, 0, 1024 * 1024);
822 if ((
float) DOL_VERSION >= 6.0) {
823 @include_once DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
835 $content = preg_replace(
'/<a href="/',
'<a target="_blank" rel="noopener noreferrer" href="', $content);
837 $content = nl2br($content);
841 if (!empty($this->descriptionlong)) {
842 if (is_array($this->langfiles)) {
843 foreach ($this->langfiles as $val) {
850 $content = $langs->transnoentitiesnoconv($this->descriptionlong);
854 return '<div class="moduledesclong">'.$content.
'</div>';
870 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/README-'.$langs->defaultlang.
'.md', 0);
875 $tmp = explode(
'_', $langs->defaultlang);
876 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/README-'.$tmp[0].
'.md', 0);
888 return ($filefound ? $pathoffile :
'');
900 $langs->load(
"admin");
902 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
903 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
909 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/ChangeLog-'.$langs->defaultlang.
'.md', 0);
921 $content = file_get_contents($pathoffile);
923 if ((
float) DOL_VERSION >= 6.0) {
924 @include_once DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
928 $content = nl2br($content);
944 return $this->editor_name;
954 return $this->editor_url;
968 $langs->load(
"admin");
972 $newversion = preg_replace(
'/_deprecated/',
'', $this->version);
973 if ($newversion ==
'experimental') {
974 $ret = ($translated ? $langs->transnoentitiesnoconv(
"VersionExperimental") : $newversion);
975 } elseif ($newversion ==
'development') {
976 $ret = ($translated ? $langs->transnoentitiesnoconv(
"VersionDevelopment") : $newversion);
977 } elseif ($newversion ==
'dolibarr') {
979 } elseif ($newversion) {
982 $ret = ($translated ? $langs->transnoentitiesnoconv(
"VersionUnknown") :
'unknown');
985 if (preg_match(
'/_deprecated/', $this->version)) {
986 $ret .= ($translated ?
' ('.$langs->transnoentitiesnoconv(
"Deprecated").
')' : $this->version);
998 if (in_array($this->version, array(
'dolibarr',
'dolibarr_deprecated',
'experimental',
'development'))) {
999 return $this->module_position;
1001 if ($this->module_position >= 100000) {
1002 return $this->module_position;
1004 $position = intval($this->module_position) + 100000;
1005 return strval($position);
1018 if ($this->version ==
'dolibarr' || $this->version ==
'dolibarr_deprecated') {
1021 if (!empty($this->version) && !in_array($this->version, array(
'experimental',
'development'))) {
1024 if (!empty($this->editor_name) || !empty($this->editor_url)) {
1027 if ($this->numero >= 100000) {
1041 return $this->langfiles;
1055 $langstring =
"ExportDataset_".$this->export_code[$r];
1056 if ($langs->trans($langstring) == $langstring) {
1058 return $langs->trans($this->export_label[$r]);
1061 return $langs->trans($langstring);
1077 $langstring =
"ImportDataset_".$this->import_code[$r];
1079 if ($langs->trans($langstring) == $langstring) {
1081 return $langs->transnoentitiesnoconv($this->import_label[$r]);
1084 return $langs->transnoentitiesnoconv($langstring);
1100 $sql =
"SELECT tms FROM ".MAIN_DB_PREFIX.
"const";
1101 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1102 $sql .=
" AND entity IN (0, ".((int) $conf->entity).
")";
1104 dol_syslog(get_class($this).
"::getLastActiveDate", LOG_DEBUG);
1105 $resql = $this->db->query($sql);
1109 $obj = $this->db->fetch_object($resql);
1111 return $this->db->jdate($obj->tms);
1130 $sql =
"SELECT tms, note FROM ".MAIN_DB_PREFIX.
"const";
1131 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1132 $sql .=
" AND entity IN (0, ".$conf->entity.
")";
1134 dol_syslog(get_class($this).
"::getLastActiveDate", LOG_DEBUG);
1135 $resql = $this->db->query($sql);
1139 $obj = $this->db->fetch_object($resql);
1143 $tmp = json_decode($obj->note,
true);
1146 'authorid' => empty($tmp[
'authorid']) ?
'' : (int) $tmp[
'authorid'],
1147 'ip' => empty($tmp[
'ip']) ?
'' : (string) $tmp[
'ip'],
1148 'lastactivationdate' => $this->db->jdate($obj->tms),
1149 'lastactivationversion' => (!empty($tmp[
'lastactivationversion']) ? (string) $tmp[
'lastactivationversion'] :
'unknown'),
1167 global $conf, $user;
1172 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity);
1174 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1175 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1176 $sql .=
" AND entity IN (0, ".$entity.
")";
1178 dol_syslog(get_class($this).
"::_active delete activation constant", LOG_DEBUG);
1179 $resql = $this->db->query($sql);
1184 $note = json_encode(
1186 'authorid' => (is_object($user) ? $user->id : 0),
1187 'ip' => (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']),
1188 'lastactivationversion' => $this->version,
1192 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name, value, visible, entity, note) VALUES";
1193 $sql .=
" (".$this->db->encrypt($this->const_name);
1194 $sql .=
", ".$this->db->encrypt(
'1');
1195 $sql .=
", 0, ".((int) $entity);
1196 $sql .=
", '".$this->db->escape($note).
"')";
1198 dol_syslog(get_class($this).
"::_active insert activation constant", LOG_DEBUG);
1199 $resql = $this->db->query($sql);
1222 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity);
1224 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1225 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1226 $sql .=
" AND entity IN (0, ".$entity.
")";
1228 dol_syslog(get_class($this).
"::_unactive", LOG_DEBUG);
1229 $this->db->query($sql);
1260 if (empty($reldir)) {
1264 include_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
1266 foreach ($conf->file->dol_document_root as $dirroot) {
1268 $dirsql = $dirroot.$reldir;
1272 $listofsubdir = array(
'',
'tables/',
'data/');
1273 if ($this->db->type ==
'pgsql') {
1274 $listofsubdir[] =
'../pgsql/functions/';
1277 foreach ($listofsubdir as $subdir) {
1278 $dir = $dirsql.$subdir;
1280 $handle = @opendir($dir);
1281 if (is_resource($handle)) {
1286 while (($file = readdir($handle)) !==
false) {
1290 foreach ($files as $file) {
1291 if ($onlywithsuffix) {
1292 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1299 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'llx_') {
1311 while (($file = readdir($handle)) !==
false) {
1315 foreach ($files as $file) {
1316 if ($onlywithsuffix) {
1317 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1324 if (preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'llx_') {
1336 while (($file = readdir($handle)) !==
false) {
1340 foreach ($files as $file) {
1341 if ($onlywithsuffix) {
1342 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1349 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 9) ==
'functions') {
1361 while (($file = readdir($handle)) !==
false) {
1365 foreach ($files as $file) {
1366 if ($onlywithsuffix) {
1367 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1374 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'data') {
1386 while (($file = readdir($handle)) !==
false) {
1390 foreach ($files as $file) {
1391 if ($onlywithsuffix) {
1392 if (!preg_match(
'/\-'.preg_quote($onlywithsuffix,
'/').
'\./i', $file)) {
1399 if (preg_match(
'/\.sql$/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 6) ==
'update') {
1418 dol_syslog(
"A module wants to load sql files from ".$reldir.
" but this directory was not found.", LOG_WARNING);
1435 include_once DOL_DOCUMENT_ROOT.
'/core/class/infobox.class.php';
1441 if (is_array($this->boxes)) {
1442 dol_syslog(get_class($this).
"::insert_boxes", LOG_DEBUG);
1446 foreach ($this->boxes as $key => $value) {
1447 $file = isset($this->boxes[$key][
'file']) ? $this->boxes[$key][
'file'] :
'';
1448 $note = isset($this->boxes[$key][
'note']) ? $this->boxes[$key][
'note'] :
'';
1449 $enabledbydefaulton = isset($this->boxes[$key][
'enabledbydefaulton']) ? $this->boxes[$key][
'enabledbydefaulton'] :
'Home';
1452 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] :
'';
1455 $note = isset($this->boxes[$key][2]) ? $this->boxes[$key][2] :
'';
1459 $sql =
"SELECT count(*) as nb FROM ".MAIN_DB_PREFIX.
"boxes_def";
1460 $sql .=
" WHERE file = '".$this->db->escape($file).
"'";
1461 $sql .=
" AND entity = ".$conf->entity;
1463 $sql .=
" AND note ='".$this->db->escape($note).
"'";
1466 $result = $this->db->query($sql);
1468 $obj = $this->db->fetch_object($result);
1469 if ($obj->nb == 0) {
1473 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes_def (file, entity, note)";
1474 $sql .=
" VALUES ('".$this->db->escape($file).
"', ";
1475 $sql .= $conf->entity.
", ";
1476 $sql .= $note ?
"'".$this->db->escape($note).
"'" :
"null";
1479 dol_syslog(get_class($this).
"::insert_boxes", LOG_DEBUG);
1480 $resql = $this->db->query($sql);
1485 if (!$err && !preg_match(
'/newboxdefonly/', $option)) {
1486 $lastid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"boxes_def",
"rowid");
1488 foreach ($pos_name as $key2 => $val2) {
1490 if ($enabledbydefaulton && $val2 != $enabledbydefaulton) {
1494 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes (box_id, position, box_order, fk_user, entity)";
1495 $sql .=
" VALUES (".((int) $lastid).
", ".((int) $key2).
", '0', 0, ".((int) $conf->entity).
")";
1497 dol_syslog(get_class($this).
"::insert_boxes onto page ".$key2.
"=".$val2, LOG_DEBUG);
1498 $resql = $this->db->query($sql);
1506 $this->db->commit();
1508 $this->error = $this->db->lasterror();
1509 $this->db->rollback();
1514 $this->error = $this->db->lasterror();
1537 if (is_array($this->boxes)) {
1538 foreach ($this->boxes as $key => $value) {
1540 if (empty($this->boxes[$key][
'file'])) {
1541 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] :
'';
1543 $file = $this->boxes[$key][
'file'];
1551 if ($file ==
'box_graph_product_distribution.php') {
1552 if (isModEnabled(
"product") || isModEnabled(
"service")) {
1553 dol_syslog(
"We discard deleting module ".$file.
" because another module still active requires it.");
1558 if ($this->db->type ==
'sqlite3') {
1561 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes ";
1562 $sql .=
"WHERE ".MAIN_DB_PREFIX.
"boxes.box_id IN (";
1563 $sql .=
"SELECT ".MAIN_DB_PREFIX.
"boxes_def.rowid ";
1564 $sql .=
"FROM ".MAIN_DB_PREFIX.
"boxes_def ";
1565 $sql .=
"WHERE ".MAIN_DB_PREFIX.
"boxes_def.file = '".$this->db->escape($file).
"') ";
1566 $sql .=
"AND ".MAIN_DB_PREFIX.
"boxes.entity = ".$conf->entity;
1568 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes";
1569 $sql .=
" USING ".MAIN_DB_PREFIX.
"boxes, ".MAIN_DB_PREFIX.
"boxes_def";
1570 $sql .=
" WHERE ".MAIN_DB_PREFIX.
"boxes.box_id = ".MAIN_DB_PREFIX.
"boxes_def.rowid";
1571 $sql .=
" AND ".MAIN_DB_PREFIX.
"boxes_def.file = '".$this->db->escape($file).
"'";
1572 $sql .=
" AND ".MAIN_DB_PREFIX.
"boxes.entity = ".$conf->entity;
1575 dol_syslog(get_class($this).
"::delete_boxes", LOG_DEBUG);
1576 $resql = $this->db->query($sql);
1578 $this->error = $this->db->lasterror();
1582 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes_def";
1583 $sql .=
" WHERE file = '".$this->db->escape($file).
"'";
1584 $sql .=
" AND entity = ".$conf->entity;
1586 dol_syslog(get_class($this).
"::delete_boxes", LOG_DEBUG);
1587 $resql = $this->db->query($sql);
1589 $this->error = $this->db->lasterror();
1607 include_once DOL_DOCUMENT_ROOT .
'/core/class/infobox.class.php';
1608 include_once DOL_DOCUMENT_ROOT .
'/cron/class/cronjob.class.php';
1610 global $conf, $user;
1614 if (is_array($this->cronjobs)) {
1615 dol_syslog(get_class($this) .
"::insert_cronjobs", LOG_DEBUG);
1617 foreach ($this->cronjobs as $key => $value) {
1620 $entity = isset($value[
'entity']) ? $value[
'entity'] : $conf->entity;
1621 $label = isset($value[
'label']) ? $value[
'label'] :
'';
1622 $jobtype = isset($value[
'jobtype']) ? $value[
'jobtype'] :
'';
1623 $classesname = isset($value[
'class']) ? $value[
'class'] :
'';
1624 $objectname = isset($value[
'objectname']) ? $value[
'objectname'] :
'';
1625 $methodename = isset($value[
'method']) ? $value[
'method'] :
'';
1626 $command = isset($value[
'command']) ? $value[
'command'] :
'';
1627 $params = isset($value[
'parameters']) ? $value[
'parameters'] :
'';
1628 $md5params = isset($value[
'md5params']) ? $value[
'md5params'] :
'';
1629 $comment = isset($value[
'comment']) ? $value[
'comment'] :
'';
1630 $frequency = isset($value[
'frequency']) ? $value[
'frequency'] :
'';
1631 $unitfrequency = isset($value[
'unitfrequency']) ? $value[
'unitfrequency'] :
'';
1632 $priority = isset($value[
'priority']) ? $value[
'priority'] :
'';
1633 $datestart = isset($value[
'datestart']) ? $value[
'datestart'] :
'';
1634 $dateend = isset($value[
'dateend']) ? $value[
'dateend'] :
'';
1635 $datenextrun = isset($value[
'datenextrun']) ? $value[
'datenextrun'] : $now;
1636 $status = isset($value[
'status']) ? $value[
'status'] :
'';
1637 $maxrun = isset($value[
'maxrun']) ? $value[
'maxrun'] : 0;
1638 $libname = isset($value[
'libname']) ? $value[
'libname'] :
'';
1639 $test = isset($value[
'test']) ? $value[
'test'] :
'';
1642 $sql =
"SELECT count(*) as nb FROM " . MAIN_DB_PREFIX .
"cronjob";
1644 $sql .=
" WHERE label = '".$this->db->escape($label).
"'";
1662 $sql .=
" AND entity = " . ((int) $entity);
1664 $result = $this->db->query($sql);
1666 $this->error = $this->db->lasterror();
1672 $obj = $this->db->fetch_object($result);
1677 $cronjob =
new Cronjob($this->db);
1679 $cronjob->entity = $entity;
1680 $cronjob->label = $label;
1681 $cronjob->jobtype = $jobtype;
1682 $cronjob->classesname = $classesname;
1683 $cronjob->objectname = $objectname;
1684 $cronjob->methodename = $methodename;
1685 $cronjob->command = $command;
1686 $cronjob->params = $params;
1687 $cronjob->md5params = $md5params;
1688 $cronjob->comment = $comment;
1689 $cronjob->frequency = $frequency;
1690 $cronjob->unitfrequency = $unitfrequency;
1691 $cronjob->priority = $priority;
1692 $cronjob->datestart = $datestart;
1693 $cronjob->dateend = $dateend;
1694 $cronjob->datenextrun = $datenextrun;
1695 $cronjob->maxrun = $maxrun;
1696 $cronjob->status = $status;
1697 $cronjob->test = $test;
1698 $cronjob->libname = $libname;
1699 $cronjob->module_name = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
1701 $retCreate = $cronjob->create($user);
1703 if ($retCreate < 0) {
1704 $this->error = implode(
"\n", array_merge([$cronjob->error], $cronjob->errors));
1726 if (is_array($this->cronjobs)) {
1727 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"cronjob";
1728 $sql .=
" WHERE module_name = '".$this->db->escape(empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class).
"'";
1729 $sql .=
" AND entity = ".$conf->entity;
1730 $sql .=
" AND test = '1'";
1733 dol_syslog(get_class($this).
"::delete_cronjobs", LOG_DEBUG);
1734 $resql = $this->db->query($sql);
1736 $this->error = $this->db->lasterror();
1757 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1758 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" like '".$this->db->escape($this->const_name).
"_TABS_%'";
1759 $sql .=
" AND entity = ".$conf->entity;
1761 dol_syslog(get_class($this).
"::delete_tabs", LOG_DEBUG);
1762 if (!$this->db->query($sql)) {
1763 $this->error = $this->db->lasterror();
1783 if (!empty($this->tabs)) {
1784 dol_syslog(get_class($this).
"::insert_tabs", LOG_DEBUG);
1787 foreach ($this->tabs as $key => $value) {
1788 if (is_array($value) && count($value) == 0) {
1792 $entity = $conf->entity;
1795 if (is_array($value)) {
1796 $newvalue = $value[
'data'];
1797 if (isset($value[
'entity'])) {
1798 $entity = $value[
'entity'];
1803 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (";
1808 $sql .=
", visible";
1811 $sql .=
" VALUES (";
1812 $sql .= $this->db->encrypt($this->const_name.
"_TABS_".$i);
1813 $sql .=
", 'chaine'";
1814 $sql .=
", ".$this->db->encrypt($newvalue);
1817 $sql .=
", ".((int) $entity);
1820 $resql = $this->db->query($sql);
1823 if ($this->db->lasterrno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1824 $this->error = $this->db->lasterror();
1825 $this->errors[] = $this->db->lasterror();
1850 if (empty($this->
const)) {
1856 foreach ($this->
const as $key => $value) {
1857 $name = $this->
const[$key][0];
1858 $type = $this->
const[$key][1];
1859 $val = $this->
const[$key][2];
1860 $note = isset($this->
const[$key][3]) ? $this->
const[$key][3] :
'';
1861 $visible = isset($this->
const[$key][4]) ? $this->
const[$key][4] : 0;
1862 $entity = (!empty($this->
const[$key][5]) && $this->
const[$key][5] !=
'current') ? 0 : $conf->entity;
1865 if (empty($visible)) {
1868 if (empty($val) && $val !=
'0') {
1872 $sql =
"SELECT count(*) as nb";
1873 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const";
1874 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($name).
"'";
1875 $sql .=
" AND entity = ".((int) $entity);
1877 $result = $this->db->query($sql);
1879 $row = $this->db->fetch_row($result);
1882 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name,type,value,note,visible,entity)";
1883 $sql .=
" VALUES (";
1884 $sql .= $this->db->encrypt($name);
1885 $sql .=
",'".$this->db->escape($type).
"'";
1886 $sql .=
",".(($val !=
'') ? $this->db->encrypt($val) :
"''");
1887 $sql .=
",".($note ?
"'".$this->db->escape($note).
"'" :
"null");
1888 $sql .=
",'".$this->db->escape($visible).
"'";
1889 $sql .=
",".$entity;
1892 if (!$this->db->query($sql)) {
1896 dol_syslog(__METHOD__.
" constant '".$name.
"' already exists", LOG_DEBUG);
1919 if (empty($this->
const)) {
1923 foreach ($this->
const as $key => $value) {
1924 $name = $this->
const[$key][0];
1925 $deleteonunactive = (!empty($this->
const[$key][6])) ? 1 : 0;
1927 if ($deleteonunactive) {
1928 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1929 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($name).
"'";
1930 $sql .=
" AND entity in (0, ".$conf->entity.
")";
1931 dol_syslog(get_class($this).
"::delete_const", LOG_DEBUG);
1932 if (!$this->db->query($sql)) {
1933 $this->error = $this->db->lasterror();
1954 global $conf, $user;
1957 $entity = (!empty($force_entity) ? $force_entity : $conf->entity);
1959 dol_syslog(get_class($this).
"::insert_permissions", LOG_DEBUG);
1962 $sql_del =
"SELECT ".$this->db->decrypt(
'value').
" as value";
1963 $sql_del .=
" FROM ".MAIN_DB_PREFIX.
"const";
1964 $sql_del .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1965 $sql_del .=
" AND entity IN (0,".((int) $entity).
")";
1967 $resql = $this->db->query($sql_del);
1970 $obj = $this->db->fetch_object($resql);
1972 if ($obj !==
null && !empty($obj->value) && !empty($this->rights)) {
1973 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
1987 foreach ($this->rights as $key => $value) {
1988 $r_id = $this->rights[$key][self::KEY_ID];
1989 $r_label = $this->rights[$key][self::KEY_LABEL];
1990 $r_type = $this->rights[$key][self::KEY_TYPE] ??
'w';
1991 $r_default = $this->rights[$key][self::KEY_DEFAULT] ?? 0;
1992 $r_perms = $this->rights[$key][self::KEY_FIRST_LEVEL] ??
'';
1993 $r_subperms = $this->rights[$key][self::KEY_SECOND_LEVEL] ??
'';
1996 if (empty($r_perms)) {
2001 $r_module = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2004 $r_module_origin =
'';
2006 if (isset($this->rights[$key][self::KEY_MODULE])) {
2008 $r_module = $this->rights[$key][self::KEY_MODULE];
2010 $r_module_origin = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2014 $r_enabled = $this->rights[$key][self::KEY_ENABLED] ??
'1';
2017 $sql =
"SELECT count(*) as nb FROM ".MAIN_DB_PREFIX.
"rights_def";
2018 $sql .=
" WHERE entity = ".((int) $entity);
2019 $sql .=
" AND id = ".((int) $r_id);
2021 $resqlselect = $this->db->query($sql);
2023 $objcount = $this->db->fetch_object($resqlselect);
2024 if ($objcount && $objcount->nb == 0) {
2025 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"rights_def (";
2028 $sql .=
", libelle";
2030 $sql .=
", module_origin";
2032 $sql .=
", bydefault";
2034 $sql .=
", subperms";
2035 $sql .=
", enabled";
2036 $sql .=
") VALUES (";
2037 $sql .= ((int) $r_id);
2038 $sql .=
", ".((int) $entity);
2039 $sql .=
", '".$this->db->escape($r_label).
"'";
2040 $sql .=
", '".$this->db->escape($r_module).
"'";
2041 $sql .=
", '".$this->db->escape($r_module_origin).
"'";
2042 $sql .=
", '".$this->db->escape($r_type).
"'";
2043 $sql .=
", ".((int) $r_default);
2044 $sql .=
", '".$this->db->escape($r_perms).
"'";
2045 $sql .=
", '".$this->db->escape($r_subperms).
"'";
2046 $sql .=
", '".$this->db->escape($r_enabled).
"'";
2049 $resqlinsert = $this->db->query($sql, 1);
2051 if (!$resqlinsert) {
2052 if ($this->db->errno() !=
"DB_ERROR_RECORD_ALREADY_EXISTS") {
2053 $this->error = $this->db->lasterror();
2057 dol_syslog(get_class($this).
"::insert_permissions record already exists", LOG_INFO);
2061 $this->db->free($resqlinsert);
2064 $this->db->free($resqlselect);
2068 if (!empty($reinitadminperms)) {
2069 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"user WHERE admin = 1";
2070 dol_syslog(get_class($this).
"::insert_permissions Search all admin users", LOG_DEBUG);
2072 $resqlseladmin = $this->db->query($sql, 1);
2074 if ($resqlseladmin) {
2075 $num = $this->db->num_rows($resqlseladmin);
2078 $obj2 = $this->db->fetch_object($resqlseladmin);
2079 dol_syslog(get_class($this).
"::insert_permissions Add permission id ".$r_id.
" to user id=".$obj2->rowid);
2081 $tmpuser =
new User($this->db);
2082 $result = $tmpuser->fetch($obj2->rowid);
2084 $tmpuser->addrights($r_id,
'',
'', 0, 1);
2086 dol_syslog(get_class($this).
"::insert_permissions Failed to add the permission to user because fetch return an error", LOG_ERR);
2096 if (!empty($reinitadminperms) && !empty($user->admin)) {
2098 $user->clearrights();
2099 $user->loadRights();
2102 $this->db->free($resql);
2104 $this->error = $this->db->lasterror();
2125 $module = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
2127 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"rights_def";
2128 $sql .=
" WHERE (module = '".$this->db->escape($module).
"' OR module_origin = '".$this->db->escape($module).
"')";
2131 if (empty($this->core_enabled)) {
2132 $sql .=
" AND entity = ".((int) $conf->entity);
2135 dol_syslog(get_class($this).
"::delete_permissions", LOG_DEBUG);
2136 if (!$this->db->query($sql)) {
2137 $this->error = $this->db->lasterror();
2154 global $conf, $user;
2156 if (!is_array($this->menu) || empty($this->menu)) {
2160 include_once DOL_DOCUMENT_ROOT.
'/core/class/menubase.class.php';
2162 dol_syslog(get_class($this).
"::insert_menus", LOG_DEBUG);
2167 $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity);
2171 foreach ($this->menu as $key => $value) {
2173 $menu->menu_handler =
'all';
2176 $menu->module = (empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class);
2178 if (!$this->menu[$key][
'fk_menu']) {
2182 $fk_parent = $this->menu[$key][
'fk_menu'];
2184 if (preg_match(
'/^r=/', $fk_parent)) {
2185 $fk_parent = str_replace(
'r=',
'', $fk_parent);
2186 if (isset($this->menu[$fk_parent][
'rowid'])) {
2187 $menu->fk_menu = $this->menu[$fk_parent][
'rowid'];
2190 } elseif (preg_match(
'/^fk_mainmenu=([a-zA-Z0-9_]+),fk_leftmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
2191 $menu->fk_menu = -1;
2192 $menu->fk_mainmenu = $reg[1];
2193 $menu->fk_leftmenu = $reg[2];
2195 } elseif (preg_match(
'/^fk_mainmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
2196 $menu->fk_menu = -1;
2197 $menu->fk_mainmenu = $reg[1];
2198 $menu->fk_leftmenu =
'';
2201 if (!$foundparent) {
2202 $this->error =
"ErrorBadDefinitionOfMenuArrayInModuleDescriptor";
2203 dol_syslog(get_class($this).
"::insert_menus ".$this->error.
" ".$this->menu[$key][
'fk_menu'], LOG_ERR);
2207 $menu->type = $this->menu[$key][
'type'];
2208 $menu->mainmenu = isset($this->menu[$key][
'mainmenu']) ? $this->menu[$key][
'mainmenu'] : (isset($menu->fk_mainmenu) ? $menu->fk_mainmenu :
'');
2209 $menu->leftmenu = isset($this->menu[$key][
'leftmenu']) ? $this->menu[$key][
'leftmenu'] :
'';
2210 $menu->title = $this->menu[$key][
'titre'];
2211 $menu->prefix = isset($this->menu[$key][
'prefix']) ? $this->menu[$key][
'prefix'] :
'';
2212 $menu->url = $this->menu[$key][
'url'];
2213 $menu->langs = isset($this->menu[$key][
'langs']) ? $this->menu[$key][
'langs'] :
'';
2214 $menu->position = $this->menu[$key][
'position'];
2215 $menu->perms = $this->menu[$key][
'perms'];
2216 $menu->target = isset($this->menu[$key][
'target']) ? $this->menu[$key][
'target'] :
'';
2217 $menu->user = $this->menu[$key][
'user'];
2218 $menu->enabled = isset($this->menu[$key][
'enabled']) ? $this->menu[$key][
'enabled'] : 0;
2219 $menu->position = $this->menu[$key][
'position'];
2220 $menu->entity = $entity;
2223 $result = $menu->create($user);
2225 $this->menu[$key][
'rowid'] = $result;
2227 $this->error = $menu->error;
2228 dol_syslog(get_class($this).
'::insert_menus result='.$result.
" ".$this->error, LOG_ERR);
2236 $this->db->commit();
2238 dol_syslog(get_class($this).
"::insert_menus ".$this->error, LOG_ERR);
2239 $this->db->rollback();
2260 $module = empty($this->rights_class) ? strtolower($this->
name) : $this->rights_class;
2262 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"menu";
2263 $sql .=
" WHERE module = '".$this->db->escape($module).
"'";
2264 $sql .=
" AND menu_handler = 'all'";
2265 $sql .=
" AND entity IN (0, ".$conf->entity.
")";
2267 dol_syslog(get_class($this).
"::delete_menus", LOG_DEBUG);
2268 $resql = $this->db->query($sql);
2270 $this->error = $this->db->lasterror();
2286 global $langs, $conf;
2291 if (isset($this->dirs) && is_array($this->dirs)) {
2292 foreach ($this->dirs as $key => $value) {
2295 if (!is_array($value)) {
2298 $constname = $this->const_name.
"_DIR_";
2299 $dir = $this->dirs[$key][1];
2300 $addtodatabase = empty($this->dirs[$key][2]) ?
'' : $this->dirs[$key][2];
2301 $subname = empty($this->dirs[$key][3]) ?
'' : strtoupper($this->dirs[$key][3]);
2302 $forcename = empty($this->dirs[$key][4]) ?
'' : strtoupper($this->dirs[$key][4]);
2304 if (!empty($forcename)) {
2305 $constname =
'MAIN_MODULE_'.$forcename.
"_DIR_";
2307 if (!empty($subname)) {
2308 $constname = $constname.$subname.
"_";
2311 $name = $constname.strtoupper($this->dirs[$key][0]);
2316 $fulldir = DOL_DATA_ROOT.$dir;
2318 $fulldir = DOL_DATA_ROOT.
"/".$conf->entity.$dir;
2321 if (!empty($fulldir) && !file_exists($fulldir)) {
2322 if (
dol_mkdir($fulldir, DOL_DATA_ROOT) < 0) {
2323 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $fulldir);
2324 dol_syslog(get_class($this).
"::_init ".$this->error, LOG_ERR);
2330 if (!empty($addtodatabase) && !empty($name)) {
2359 $sql =
"SELECT count(*)";
2360 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const";
2361 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($name).
"'";
2362 $sql .=
" AND entity = ".$conf->entity;
2364 dol_syslog(get_class($this).
"::insert_dirs", LOG_DEBUG);
2365 $result = $this->db->query($sql);
2367 $row = $this->db->fetch_row($result);
2370 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name, type, value, note, visible, entity)";
2371 $sql .=
" VALUES (".$this->db->encrypt($name).
", 'chaine', ".$this->db->encrypt($dir).
", '".$this->db->escape(
"Directory for module ".$this->
name).
"', '0', ".((int) $conf->entity).
")";
2373 dol_syslog(get_class($this).
"::insert_dirs", LOG_DEBUG);
2374 $this->db->query($sql);
2377 $this->error = $this->db->lasterror();
2398 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
2399 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" LIKE '".$this->db->escape($this->const_name).
"_DIR_%'";
2400 $sql .=
" AND entity = ".$conf->entity;
2402 dol_syslog(get_class($this).
"::delete_dirs", LOG_DEBUG);
2403 if (!$this->db->query($sql)) {
2404 $this->error = $this->db->lasterror();
2421 global $conf, $langs;
2425 if (is_array($this->module_parts)) {
2426 if (empty($this->module_parts[
'icon']) && !empty($this->picto) && preg_match(
'/^fa\-/', $this->picto)) {
2427 $this->module_parts[
'icon'] = $this->picto;
2430 foreach ($this->module_parts as $key => $value) {
2431 if (is_array($value) && count($value) == 0) {
2436 if ($key ==
'websitetemplates' && $value == 1) {
2440 $docs =
dol_dir_list($srcroot,
'directories', 0,
'website_.*$');
2441 foreach ($docs as $cursorfile) {
2442 $src = $srcroot.
'/'.$cursorfile[
'name'];
2443 $dest = DOL_DATA_ROOT.
'/doctemplates/websites/'.$cursorfile[
'name'];
2450 $result = dol_compress_dir($src, $dest.
'.zip',
'zip');
2453 $this->error = ($errormsg ? $errormsg : $langs->trans(
'ErrorFailToCreateZip', $dest));
2454 $this->errors[] = ($errormsg ? $errormsg : $langs->trans(
'ErrorFailToCreateZip', $dest));
2459 $docs =
dol_dir_list($srcroot,
'files', 0,
'website_.*\.jpg$');
2460 foreach ($docs as $cursorfile) {
2461 $src = $srcroot.
'/'.$cursorfile[
'name'];
2462 $dest = DOL_DATA_ROOT.
'/doctemplates/websites/'.$cursorfile[
'name'];
2468 $entity = $conf->entity;
2472 if (is_array($value)) {
2475 if (isset($value[
'data']) && is_array($value[
'data'])) {
2476 $newvalue = json_encode($value[
'data']);
2477 if (isset($value[
'entity'])) {
2478 $entity = $value[
'entity'];
2480 } elseif (isset($value[
'data']) && !is_array($value[
'data'])) {
2481 $newvalue = $value[
'data'];
2482 if (isset($value[
'entity'])) {
2483 $entity = $value[
'entity'];
2486 $newvalue = json_encode($value);
2490 if (!empty($newvalue)) {
2491 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (";
2496 $sql .=
", visible";
2499 $sql .=
" VALUES (";
2500 $sql .=
" ".$this->db->encrypt($this->const_name.
"_".strtoupper($key), 1);
2501 $sql .=
", 'chaine'";
2502 $sql .=
", ".$this->db->encrypt($newvalue, 1);
2505 $sql .=
", ".((int) $entity);
2508 dol_syslog(get_class($this).
"::insert_module_parts for key=".$this->const_name.
"_".strtoupper($key), LOG_DEBUG);
2510 $resql = $this->db->query($sql, 1);
2512 if ($this->db->lasterrno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2514 $this->error = $this->db->lasterror();
2516 dol_syslog(get_class($this).
"::insert_module_parts for ".$this->const_name.
"_".strtoupper($key).
" Record already exists.", LOG_WARNING);
2538 if (is_array($this->module_parts)) {
2539 dol_syslog(get_class($this).
"::delete_module_parts", LOG_DEBUG);
2541 if (empty($this->module_parts[
'icon']) && !empty($this->picto) && preg_match(
'/^fa\-/', $this->picto)) {
2542 $this->module_parts[
'icon'] = $this->picto;
2545 foreach ($this->module_parts as $key => $value) {
2547 if (is_array($value) && isset($value[
'entity'])) {
2548 $entity = $value[
'entity'];
2550 $entity = $conf->entity;
2553 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
2554 $sql .=
" WHERE ".$this->db->decrypt(
'name').
" LIKE '".$this->db->escape($this->const_name).
"_".strtoupper($key).
"'";
2555 $sql .=
" AND entity = ".((int) $entity);
2557 if (!$this->db->query($sql)) {
2558 $this->error = $this->db->lasterror();
2575 public function init($options =
'')
2577 return $this->
_init(array(), $options);
2588 public function remove($options =
'')
2590 return $this->
_remove(array(), $options);
2608 $imginfo =
"info_black";
2611 $const_name =
'MAIN_MODULE_'.strtoupper(preg_replace(
'/^mod/i',
'', get_class($this)));
2615 if (preg_match(
'/development/i', $version)) {
2616 $versiontrans .=
'warning';
2618 if (preg_match(
'/experimental/i', $version)) {
2619 $versiontrans .=
'warning';
2621 if (preg_match(
'/deprecated/i', $version)) {
2622 $versiontrans .=
'warning';
2626 <div class="box-flex-item info-box-module'
2627 .(getDolGlobalString($const_name) ?
'' :
' --disabled')
2629 .($this->needUpdate ?
' --need-update' :
'')
2631 <div class="info-box info-box-sm info-box-module">
2632 <div class="info-box-icon'.(!
getDolGlobalString($const_name) ?
'' :
' info-box-icon-module-enabled'.($versiontrans ?
' info-box-icon-module-warning' :
'')).
'">';
2637 if (!empty($this->picto)) {
2638 if (preg_match(
'/^\//i', $this->picto)) {
2639 $return .=
img_picto($alttext, $this->picto,
'class="inline-block valignmiddle"', 1);
2641 $return .=
img_object($alttext, $this->picto,
'class="inline-block valignmiddle"');
2644 $return .=
img_object($alttext,
'generic',
'class="inline-block valignmiddle"');
2647 if ($this->
isCoreOrExternalModule() ==
'external' || preg_match(
'/development|experimental|deprecated/i', $version)) {
2648 $versionTitle = $langs->trans(
"Version").
' '.$this->
getVersion(1);
2649 if ($this->needUpdate) {
2650 $versionTitle .=
'<br>'.$langs->trans(
'ModuleUpdateAvailable').
' : '.
$this->lastVersion;
2653 $return .=
'<span class="info-box-icon-version'.($versiontrans ?
' '.$versiontrans :
'').
' classfortooltip" title="'.
dol_escape_js($versionTitle).
'" >';
2655 $return .=
'</span>';
2659 <div class="info-box-content info-box-text-module'.(!
getDolGlobalString($const_name) ?
'' :
' info-box-module-enabled'.($versiontrans ?
' info-box-content-warning' :
'')).
'">
2660 <span class="info-box-title">'.$this->
getName().
'</span>
2663 $return .=
'<div class="valignmiddle inline-block info-box-more">';
2665 $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>';
2666 $return .= '</div><br>';
2668 $return .= '<div class="valignmiddle
inline-block info-box-actions
">';
2669 $return .= '<div class="valignmiddle
inline-block info-box-setup
">';
2670 $return .= $codetoconfig;
2671 $return .= '</div>';
2672 $return .= '<div class="valignmiddle
inline-block marginleftonly marginrightonly
">';
2673 $return .= $codeenabledisable;
2674 $return .= '</div>';
2675 $return .= '</div>';
2678 </div><!-- /.info-box-content -->
2679 </div><!-- /.info-box -->
2693 public function checkForUpdate()
2695 require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
2696 if (!empty($this->url_last_version)) {
2697 $lastVersion = getURLContent($this->url_last_version, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only
2698 if (isset($lastVersion['content']) && strlen($lastVersion['content']) < 30) {
2699 // 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 _ . -
2700 $this->lastVersion = preg_replace("/[^a-zA-Z0-9_\.\-]+/
", "", $lastVersion['content']);
2701 if (version_compare($this->lastVersion, $this->version) > 0) {
2702 $this->needUpdate = true;
2705 $this->needUpdate = false;
2722 public function checkForCompliance($nametocheck = '')
2724 global $conf, $langs;
2726 if (empty($nametocheck)) {
2727 $nametocheck = $this->name;
2730 // Get list of illegal modules name or ID
2731 if (empty($conf->cache['noncompliantmodules'])) {
2732 require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
2734 $urlforblacklistmodules = 'https://ping.dolibarr.org/modules-blacklist.txt';
2736 $result = getURLContent($urlforblacklistmodules, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only
2737 if (isset($result['content']) && $result['http_code'] == 200) {
2738 $langs->load("errors
");
2740 // 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 _ . -
2741 $arrayoflines = preg_split("/[\n,]/
", $result['content']);
2742 foreach ($arrayoflines as $line) {
2743 $tmpfieldsofline = explode(';', $line);
2744 $modulekey = strtolower($tmpfieldsofline[0]);
2745 $conf->cache['noncompliantmodules'][$modulekey]['name'] = $tmpfieldsofline[0];
2746 $conf->cache['noncompliantmodules'][$modulekey]['id'] = $tmpfieldsofline[1];
2747 $conf->cache['noncompliantmodules'][$modulekey]['signature'] = $tmpfieldsofline[2];
2748 $conf->cache['noncompliantmodules'][$modulekey]['message'] = $langs->trans(empty($tmpfieldsofline[3]) ? 'WarningModuleAffiliatedToAReportedCompany' : $tmpfieldsofline[3]);
2749 if (!empty($tmpfieldsofline[4])) {
2750 $message2 = $langs->trans("WarningModuleAffiliatedToAPiratPlatform
", '{s}');
2751 $listofillegalurl = '';
2752 foreach (explode(" ", $tmpfieldsofline[4]) as $illegalurl) {
2753 $listofillegalurl .= ($listofillegalurl ? ' '.$langs->trans("or
").' ' : '').'<b>'.preg_replace('/[^a-z0-9\.\-]/', '', $illegalurl).'</b>';
2755 $message2 = str_replace('{s}', $listofillegalurl, $message2);
2756 $conf->cache['noncompliantmodules'][$modulekey]['message2'] = $message2;
2762 if (!empty($conf->cache['noncompliantmodules'])) {
2763 $modulekey = strtolower($nametocheck);
2764 if (in_array($modulekey, array_keys($conf->cache['noncompliantmodules']))) {
2765 $answer = trim($conf->cache['noncompliantmodules'][$modulekey]['message']);
2766 if (!empty($conf->cache['noncompliantmodules'][$modulekey]['message2'])) {
2767 $answer .= '<br>'.$conf->cache['noncompliantmodules'][$modulekey]['message2'];
2794 protected function declareNewDictionary($dictionaryArray, $langs = '')
2796 $fields = array('name', 'lib', 'sql', 'sqlsort', 'field', 'fieldvalue', 'fieldinsert', 'rowid', 'cond', 'help', 'fieldcheck');
2798 foreach ($fields as $field) {
2799 if (isset($dictionaryArray[$field])) {
2800 // @phan-suppress-next-line PhanTypeMismatchProperty
2801 $this->dictionaries['tab'.$field][] = $dictionaryArray[$field];
2804 if ($langs && !in_array($langs, $this->dictionaries[$langs])) {
2805 $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.
$needUpdate
true indicate this module need update
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,...
$lastVersion
Module last version.
_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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (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...
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.