87 public $module_position=
'50';
104 public $dirs = array();
109 public $boxes = array();
114 public $const = array();
119 public $cronjobs = array();
129 public $rights_class;
134 public $menu = array();
163 public $module_parts = array();
175 public $dbversion =
"-";
207 public $descriptionlong;
220 public $export_label;
222 public $export_permission;
223 public $export_fields_array;
224 public $export_TypeFields_array;
225 public $export_entities_array;
226 public $export_special_array;
227 public $export_dependencies_array;
228 public $export_sql_start;
229 public $export_sql_end;
230 public $export_sql_order;
243 public $import_label;
254 public $always_enabled;
259 public $core_enabled;
266 public $style_sheet =
'';
295 public $config_page_url;
314 public $conflictwith;
326 public $warnings_activation;
333 public $warnings_activation_ext;
346 public $need_dolibarr_version;
351 public $hidden =
false;
384 function _init($array_sql, $options=
'')
392 if (! $err) { $err+=$this->
_active();
404 if (! $err && ! preg_match(
'/newboxdefonly/', $options)) { $err+=$this->
insert_const();
408 if (! $err && ! preg_match(
'/noboxes/', $options)) { $err+=$this->
insert_boxes($options);
428 $num=count($array_sql);
429 for ($i = 0; $i < $num; $i++)
435 if (is_array($val)) {
437 $ignoreerror=$val[
'ignoreerror'];
440 $sql=str_replace(
'__ENTITY__', $conf->entity, $sql);
442 dol_syslog(get_class($this).
"::_init ignoreerror=".$ignoreerror.
"", LOG_DEBUG);
443 $result=$this->db->query($sql, $ignoreerror);
445 if (! $ignoreerror) {
446 $this->error=$this->db->lasterror();
451 dol_syslog(get_class($this).
"::_init Warning ".$this->db->lasterror(), LOG_WARNING);
464 $this->db->rollback();
500 if (! $err && ! preg_match(
'/(newboxdefonly|noboxes)/', $options)) { $err+=$this->
delete_boxes();
520 $num=count($array_sql);
521 for ($i = 0; $i < $num; $i++)
524 dol_syslog(get_class($this).
"::_remove", LOG_DEBUG);
525 $result=$this->db->query($array_sql[$i]);
527 $this->error=$this->db->error();
540 $this->db->rollback();
555 $langs->load(
"admin");
557 if ($langs->transnoentitiesnoconv(
"Module".$this->numero.
"Name") != (
"Module".$this->numero.
"Name")) {
559 return $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Name");
564 if (is_array($this->langfiles)) {
565 foreach($this->langfiles as $val)
567 if ($val) { $langs->load($val);
572 if ($langs->trans(
"Module".$this->name.
"Name") != (
"Module".$this->name.
"Name")) {
574 return $langs->transnoentitiesnoconv(
"Module".$this->
name.
"Name");
578 return $langs->transnoentitiesnoconv($this->
name);
591 $langs->load(
"admin");
593 if ($langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc") != (
"Module".$this->numero.
"Desc")) {
595 return $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc");
600 if (is_array($this->langfiles)) {
601 foreach($this->langfiles as $val)
603 if ($val) { $langs->load($val);
608 if ($langs->transnoentitiesnoconv(
"Module".$this->name.
"Desc") != (
"Module".$this->name.
"Desc")) {
610 return $langs->trans(
"Module".$this->
name.
"Desc");
627 $langs->load(
"admin");
629 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
630 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
636 $content = file_get_contents($pathoffile);
638 if ((
float) DOL_VERSION >= 6.0) {
639 @include_once DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
642 $content,
'parsedown',
652 $content = nl2br($content);
657 if (! empty($this->descriptionlong)) {
658 if (is_array($this->langfiles)) {
659 foreach($this->langfiles as $val)
661 if ($val) { $langs->load($val);
666 $content = $langs->transnoentitiesnoconv($this->descriptionlong);
686 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/README-'.$langs->defaultlang.
'.md', 0);
691 $tmp=explode(
'_', $langs->defaultlang);
692 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/README-'.$tmp[0].
'.md', 0);
704 return ($filefound?$pathoffile:
'');
716 $langs->load(
"admin");
718 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
719 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
725 $pathoffile =
dol_buildpath(strtolower($this->
name).
'/ChangeLog-'.$langs->defaultlang.
'.md', 0);
738 $content = file_get_contents($pathoffile);
740 if ((
float) DOL_VERSION >= 6.0) {
741 @include_once DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
746 $content = nl2br($content);
760 return $this->editor_name;
770 return $this->editor_url;
784 $langs->load(
"admin");
788 $newversion=preg_replace(
'/_deprecated/',
'', $this->version);
789 if ($newversion ==
'experimental') { $ret=($translated?$langs->transnoentitiesnoconv(
"VersionExperimental"):$newversion);
790 } elseif ($newversion ==
'development') { $ret=($translated?$langs->transnoentitiesnoconv(
"VersionDevelopment"):$newversion);
791 } elseif ($newversion ==
'dolibarr') { $ret=DOL_VERSION;
792 } elseif ($newversion) { $ret=$newversion;
793 }
else { $ret=($translated?$langs->transnoentitiesnoconv(
"VersionUnknown"):
'unknown');
796 if (preg_match(
'/_deprecated/', $this->version)) { $ret.=($translated?
' ('.$langs->transnoentitiesnoconv(
"Deprecated").
')':$this->version);
809 if ($this->version ==
'dolibarr' || $this->version ==
'dolibarr_deprecated') {
return 'core';
811 if (! empty($this->version) && ! in_array($this->version, array(
'experimental',
'development'))) {
return 'external';
813 if (! empty($this->editor_name) || ! empty($this->editor_url)) {
return 'external';
815 if ($this->numero >= 100000) {
return 'external';
828 return $this->langfiles;
842 $langstring=
"ExportDataset_".$this->export_code[$r];
843 if ($langs->trans($langstring) == $langstring) {
845 return $langs->trans($this->export_label[$r]);
850 return $langs->trans($langstring);
866 $langstring=
"ImportDataset_".$this->import_code[$r];
868 if ($langs->trans($langstring) == $langstring) {
870 return $langs->transnoentitiesnoconv($this->import_label[$r]);
875 return $langs->transnoentitiesnoconv($langstring);
889 $sql =
"SELECT tms FROM ".MAIN_DB_PREFIX.
"const";
890 $sql.=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
891 $sql.=
" AND entity IN (0, ".$conf->entity.
")";
893 dol_syslog(get_class($this).
"::getLastActiveDate", LOG_DEBUG);
894 $resql=$this->db->query($sql);
898 $obj=$this->db->fetch_object(
$resql);
899 if ($obj) {
return $this->db->jdate($obj->tms);
916 $sql =
"SELECT tms, note FROM ".MAIN_DB_PREFIX.
"const";
917 $sql.=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
918 $sql.=
" AND entity IN (0, ".$conf->entity.
")";
920 dol_syslog(get_class($this).
"::getLastActiveDate", LOG_DEBUG);
921 $resql=$this->db->query($sql);
925 $obj=$this->db->fetch_object(
$resql);
928 $tmp=json_decode($obj->note,
true);
930 if ($obj) {
return array(
'authorid'=>$tmp[
'authorid'],
'ip'=>$tmp[
'ip'],
'lastactivationdate'=>$this->db->jdate($obj->tms));
950 $entity = ((! empty($this->always_enabled) || ! empty($this->core_enabled)) ? 0 : $conf->entity);
952 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
953 $sql.=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
954 $sql.=
" AND entity IN (0, ".$entity.
")";
956 dol_syslog(get_class($this).
"::_active delete activation constant", LOG_DEBUG);
957 $resql=$this->db->query($sql);
961 $note=json_encode(array(
'authorid'=>(is_object($user)?$user->id:0),
'ip'=>(empty($_SERVER[
'REMOTE_ADDR'])?
'':$_SERVER[
'REMOTE_ADDR'])));
963 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name, value, visible, entity, note) VALUES";
964 $sql.=
" (".$this->db->encrypt($this->const_name, 1);
965 $sql.=
", ".$this->db->encrypt(
'1', 1);
966 $sql.=
", 0, ".$entity;
967 $sql.=
", '".$this->db->escape($note).
"')";
969 dol_syslog(get_class($this).
"::_active insert activation constant", LOG_DEBUG);
970 $resql=$this->db->query($sql);
990 $entity = ((! empty($this->always_enabled) || ! empty($this->core_enabled)) ? 0 : $conf->entity);
992 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
993 $sql.=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
994 $sql.=
" AND entity IN (0, ".$entity.
")";
996 dol_syslog(get_class($this).
"::_unactive", LOG_DEBUG);
997 $this->db->query($sql);
1021 if (empty($reldir)) {
return 1;
1024 include_once DOL_DOCUMENT_ROOT .
'/core/lib/admin.lib.php';
1027 foreach($conf->file->dol_document_root as $dirroot)
1030 $dir = $dirroot.$reldir;
1033 $handle=@opendir($dir);
1034 if (is_resource($handle)) {
1039 while (($file = readdir($handle))!==
false)
1044 foreach ($files as $file)
1046 if (preg_match(
'/\.sql$/i', $file) && ! preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'llx_' && substr($file, 0, 4) !=
'data') {
1047 $result=
run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG)?1:0,
'', 1);
1048 if ($result <= 0) { $error++;
1057 while (($file = readdir($handle))!==
false)
1062 foreach ($files as $file)
1064 if (preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'llx_' && substr($file, 0, 4) !=
'data') {
1065 $result=
run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG)?1:0,
'', 1);
1066 if ($result <= 0) { $error++;
1075 while (($file = readdir($handle))!==
false)
1080 foreach ($files as $file)
1082 if (preg_match(
'/\.sql$/i', $file) && ! preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 4) ==
'data') {
1083 $result=
run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG)?1:0,
'', 1);
1084 if ($result <= 0) { $error++;
1093 while (($file = readdir($handle))!==
false)
1098 foreach ($files as $file)
1100 if (preg_match(
'/\.sql$/i', $file) && ! preg_match(
'/\.key\.sql$/i', $file) && substr($file, 0, 6) ==
'update') {
1101 $result=
run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG)?1:0,
'', 1);
1102 if ($result <= 0) { $error++;
1116 if (! $dirfound) {
dol_syslog(
"A module ask to load sql files into ".$reldir.
" but this directory was not found.", LOG_WARNING);
1133 include_once DOL_DOCUMENT_ROOT .
'/core/class/infobox.class.php';
1139 if (is_array($this->boxes)) {
1140 dol_syslog(get_class($this).
"::insert_boxes", LOG_DEBUG);
1144 foreach ($this->boxes as $key => $value)
1146 $file = isset($this->boxes[$key][
'file'])?$this->boxes[$key][
'file']:
'';
1147 $note = isset($this->boxes[$key][
'note'])?$this->boxes[$key][
'note']:
'';
1148 $enabledbydefaulton = isset($this->boxes[$key][
'enabledbydefaulton'])?$this->boxes[$key][
'enabledbydefaulton']:
'Home';
1150 if (empty($file)) { $file = isset($this->boxes[$key][1])?$this->boxes[$key][1]:
'';
1152 if (empty($note)) { $note = isset($this->boxes[$key][2])?$this->boxes[$key][2]:
'';
1156 $sql =
"SELECT count(*) as nb FROM ".MAIN_DB_PREFIX.
"boxes_def";
1157 $sql.=
" WHERE file = '".$this->db->escape($file).
"'";
1158 $sql.=
" AND entity = ".$conf->entity;
1159 if ($note) { $sql.=
" AND note ='".$this->db->escape($note).
"'";
1162 $result=$this->db->query($sql);
1164 $obj = $this->db->fetch_object($result);
1165 if ($obj->nb == 0) {
1169 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes_def (file, entity, note)";
1170 $sql.=
" VALUES ('".$this->db->escape($file).
"', ";
1171 $sql.= $conf->entity.
", ";
1172 $sql.= $note?
"'".$this->db->escape($note).
"'":
"null";
1175 dol_syslog(get_class($this).
"::insert_boxes", LOG_DEBUG);
1176 $resql=$this->db->query($sql);
1180 if (! $err && ! preg_match(
'/newboxdefonly/', $option)) {
1181 $lastid=$this->db->last_insert_id(MAIN_DB_PREFIX.
"boxes_def",
"rowid");
1183 foreach ($pos_name as $key2 => $val2)
1186 if ($enabledbydefaulton && $val2 != $enabledbydefaulton) {
continue;
1189 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes (box_id,position,box_order,fk_user,entity)";
1190 $sql.=
" VALUES (".$lastid.
", ".$key2.
", '0', 0, ".$conf->entity.
")";
1192 dol_syslog(get_class($this).
"::insert_boxes onto page ".$key2.
"=".$val2.
"", LOG_DEBUG);
1193 $resql=$this->db->query($sql);
1200 $this->db->commit();
1204 $this->error=$this->db->lasterror();
1205 $this->db->rollback();
1212 $this->error=$this->db->lasterror();
1235 if (is_array($this->boxes)) {
1236 foreach ($this->boxes as $key => $value)
1239 $file = $this->boxes[$key][
'file'];
1245 if ($file ==
'box_graph_product_distribution.php') {
1246 if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) {
1247 dol_syslog(
"We discard disabling of module ".$file.
" because another module still active require it.");
1252 if (empty($file)) { $file = isset($this->boxes[$key][1])?$this->boxes[$key][1]:
'';
1255 if ($this->db->type ==
'sqlite3') {
1258 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes ";
1259 $sql .=
"WHERE ".MAIN_DB_PREFIX.
"boxes.box_id IN (";
1260 $sql .=
"SELECT ".MAIN_DB_PREFIX.
"boxes_def.rowid ";
1261 $sql .=
"FROM ".MAIN_DB_PREFIX.
"boxes_def ";
1262 $sql .=
"WHERE ".MAIN_DB_PREFIX.
"boxes_def.file = '".$this->db->escape($file).
"') ";
1263 $sql .=
"AND ".MAIN_DB_PREFIX.
"boxes.entity = ".$conf->entity;
1265 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes";
1266 $sql.=
" USING ".MAIN_DB_PREFIX.
"boxes, ".MAIN_DB_PREFIX.
"boxes_def";
1267 $sql.=
" WHERE ".MAIN_DB_PREFIX.
"boxes.box_id = ".MAIN_DB_PREFIX.
"boxes_def.rowid";
1268 $sql.=
" AND ".MAIN_DB_PREFIX.
"boxes_def.file = '".$this->db->escape($file).
"'";
1269 $sql.=
" AND ".MAIN_DB_PREFIX.
"boxes.entity = ".$conf->entity;
1272 dol_syslog(get_class($this).
"::delete_boxes", LOG_DEBUG);
1273 $resql=$this->db->query($sql);
1275 $this->error=$this->db->lasterror();
1279 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes_def";
1280 $sql.=
" WHERE file = '".$this->db->escape($file).
"'";
1281 $sql.=
" AND entity = ".$conf->entity;
1283 dol_syslog(get_class($this).
"::delete_boxes", LOG_DEBUG);
1284 $resql=$this->db->query($sql);
1286 $this->error=$this->db->lasterror();
1304 include_once DOL_DOCUMENT_ROOT .
'/core/class/infobox.class.php';
1310 if (is_array($this->cronjobs)) {
1311 dol_syslog(get_class($this).
"::insert_cronjobs", LOG_DEBUG);
1313 foreach ($this->cronjobs as $key => $value)
1315 $entity = isset($this->cronjobs[$key][
'entity'])?$this->cronjobs[$key][
'entity']:$conf->entity;
1316 $label = isset($this->cronjobs[$key][
'label'])?$this->cronjobs[$key][
'label']:
'';
1317 $jobtype = isset($this->cronjobs[$key][
'jobtype'])?$this->cronjobs[$key][
'jobtype']:
'';
1318 $class = isset($this->cronjobs[$key][
'class'])?$this->cronjobs[$key][
'class']:
'';
1319 $objectname = isset($this->cronjobs[$key][
'objectname'])?$this->cronjobs[$key][
'objectname']:
'';
1320 $method = isset($this->cronjobs[$key][
'method'])?$this->cronjobs[$key][
'method']:
'';
1321 $command = isset($this->cronjobs[$key][
'command'])?$this->cronjobs[$key][
'command']:
'';
1322 $parameters = isset($this->cronjobs[$key][
'parameters'])?$this->cronjobs[$key][
'parameters']:
'';
1323 $comment = isset($this->cronjobs[$key][
'comment'])?$this->cronjobs[$key][
'comment']:
'';
1324 $frequency = isset($this->cronjobs[$key][
'frequency'])?$this->cronjobs[$key][
'frequency']:
'';
1325 $unitfrequency = isset($this->cronjobs[$key][
'unitfrequency'])?$this->cronjobs[$key][
'unitfrequency']:
'';
1326 $priority = isset($this->cronjobs[$key][
'priority'])?$this->cronjobs[$key][
'priority']:
'';
1327 $datestart = isset($this->cronjobs[$key][
'datestart'])?$this->cronjobs[$key][
'datestart']:
'';
1328 $dateend = isset($this->cronjobs[$key][
'dateend'])?$this->cronjobs[$key][
'dateend']:
'';
1329 $status = isset($this->cronjobs[$key][
'status'])?$this->cronjobs[$key][
'status']:
'';
1330 $test = isset($this->cronjobs[$key][
'test'])?$this->cronjobs[$key][
'test']:
'';
1333 $sql =
"SELECT count(*) as nb FROM ".MAIN_DB_PREFIX.
"cronjob";
1334 $sql.=
" WHERE module_name = '".$this->db->escape(empty($this->rights_class)?strtolower($this->
name):$this->rights_class).
"'";
1335 if ($class) { $sql.=
" AND classesname = '".$this->db->escape($class).
"'";
1337 if ($objectname) { $sql.=
" AND objectname = '".$this->db->escape($objectname).
"'";
1339 if ($method) { $sql.=
" AND methodename = '".$this->db->escape($method).
"'";
1341 if ($command) { $sql.=
" AND command = '".$this->db->escape($command).
"'";
1343 $sql.=
" AND entity = ".$entity;
1347 $result=$this->db->query($sql);
1349 $obj = $this->db->fetch_object($result);
1350 if ($obj->nb == 0) {
1354 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"cronjob (module_name, datec, datestart, dateend, label, jobtype, classesname, objectname, methodename, command, params, note,";
1355 if (is_int($frequency)) { $sql.=
' frequency,'; }
1356 if (is_int($unitfrequency)) { $sql.=
' unitfrequency,'; }
1357 if (is_int($priority)) { $sql.=
' priority,'; }
1358 if (is_int($status)) { $sql.=
' status,'; }
1359 $sql.=
" entity, test)";
1361 $sql.=
"'".$this->db->escape(empty($this->rights_class)?strtolower($this->
name):$this->rights_class).
"', ";
1362 $sql.=
"'".$this->db->idate($now).
"', ";
1363 $sql.= ($datestart ?
"'".$this->db->idate($datestart).
"'" :
"'".$this->db->idate($now).
"'").
", ";
1364 $sql.= ($dateend ?
"'".$this->db->idate($dateend).
"'" :
"NULL").
", ";
1365 $sql.=
"'".$this->db->escape($label).
"', ";
1366 $sql.=
"'".$this->db->escape($jobtype).
"', ";
1367 $sql.= ($class?
"'".$this->db->escape($class).
"'":
"null").
",";
1368 $sql.= ($objectname?
"'".$this->db->escape($objectname).
"'":
"null").
",";
1369 $sql.= ($method?
"'".$this->db->escape($method).
"'":
"null").
",";
1370 $sql.= ($command?
"'".$this->db->escape($command).
"'":
"null").
",";
1371 $sql.= ($parameters?
"'".$this->db->escape($parameters).
"'":
"null").
",";
1372 $sql.= ($comment?
"'".$this->db->escape($comment).
"'":
"null").
",";
1373 if(is_int($frequency)) { $sql.=
"'".$this->db->escape($frequency).
"', ";
1375 if(is_int($unitfrequency)) { $sql.=
"'".$this->db->escape($unitfrequency).
"', ";
1377 if(is_int($priority)) {$sql.=
"'".$this->db->escape($priority).
"', ";
1379 if(is_int($status)) { $sql.=
"'".$this->db->escape($status).
"', ";
1382 $sql.=
"'".$this->db->escape($test).
"'";
1385 $resql=$this->db->query($sql);
1391 $this->db->commit();
1395 $this->error=$this->db->lasterror();
1396 $this->db->rollback();
1403 $this->error=$this->db->lasterror();
1426 if (is_array($this->cronjobs)) {
1427 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"cronjob";
1428 $sql.=
" WHERE module_name = '".$this->db->escape(empty($this->rights_class)?strtolower($this->
name):$this->rights_class).
"'";
1429 $sql.=
" AND entity = ".$conf->entity;
1430 $sql.=
" AND test = '1'";
1433 dol_syslog(get_class($this).
"::delete_cronjobs", LOG_DEBUG);
1434 $resql=$this->db->query($sql);
1436 $this->error=$this->db->lasterror();
1457 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1458 $sql.=
" WHERE ".$this->db->decrypt(
'name').
" like '".$this->db->escape($this->const_name).
"_TABS_%'";
1459 $sql.=
" AND entity = ".$conf->entity;
1461 dol_syslog(get_class($this).
"::delete_tabs", LOG_DEBUG);
1462 if (! $this->db->query($sql)) {
1463 $this->error=$this->db->lasterror();
1483 if (! empty($this->tabs)) {
1484 dol_syslog(get_class($this).
"::insert_tabs", LOG_DEBUG);
1487 foreach ($this->tabs as $key => $value)
1489 if (is_array($value) && count($value) == 0) {
continue;
1492 $entity=$conf->entity;
1495 if (is_array($value)) {
1496 $newvalue = $value[
'data'];
1497 if (isset($value[
'entity'])) { $entity = $value[
'entity'];
1502 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (";
1511 $sql.= $this->db->encrypt($this->const_name.
"_TABS_".$i, 1);
1512 $sql.=
", 'chaine'";
1513 $sql.=
", ".$this->db->encrypt($newvalue, 1);
1516 $sql.=
", ".$entity;
1519 $resql = $this->db->query($sql);
1522 if ($this->db->lasterrno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1523 $this->error = $this->db->lasterror();
1524 $this->errors[] = $this->db->lasterror();
1549 if (empty($this->
const)) {
return 0;
1552 dol_syslog(get_class($this).
"::insert_const", LOG_DEBUG);
1554 foreach ($this->
const as $key => $value)
1556 $name = $this->
const[$key][0];
1557 $type = $this->
const[$key][1];
1558 $val = $this->
const[$key][2];
1559 $note = isset($this->
const[$key][3])?$this->
const[$key][3]:
'';
1560 $visible = isset($this->
const[$key][4])?$this->
const[$key][4]:0;
1561 $entity = (! empty($this->
const[$key][5]) && $this->
const[$key][5]!=
'current')?0:$conf->entity;
1564 if (empty($visible)) { $visible=
'0';
1566 if (empty($val) && $val !=
'0') { $val=
'';
1569 $sql =
"SELECT count(*)";
1570 $sql.=
" FROM ".MAIN_DB_PREFIX.
"const";
1571 $sql.=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($name).
"'";
1572 $sql.=
" AND entity = ".$entity;
1574 $result=$this->db->query($sql);
1576 $row = $this->db->fetch_row($result);
1580 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name,type,value,note,visible,entity)";
1582 $sql.= $this->db->encrypt($name, 1);
1583 $sql.=
",'".$type.
"'";
1584 $sql.=
",".(($val !=
'')?$this->db->encrypt($val, 1):
"''");
1585 $sql.=
",".($note?
"'".$this->db->escape($note).
"'":
"null");
1586 $sql.=
",'".$visible.
"'";
1590 if (! $this->db->query($sql) ) {
1596 dol_syslog(get_class($this).
"::insert_const constant '".$name.
"' already exists", LOG_WARNING);
1621 if (empty($this->
const)) {
return 0;
1624 foreach ($this->
const as $key => $value)
1626 $name = $this->
const[$key][0];
1627 $deleteonunactive = (! empty($this->
const[$key][6]))?1:0;
1629 if ($deleteonunactive) {
1630 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1631 $sql.=
" WHERE ".$this->db->decrypt(
'name').
" = '".$name.
"'";
1632 $sql.=
" AND entity in (0, ".$conf->entity.
")";
1633 dol_syslog(get_class($this).
"::delete_const", LOG_DEBUG);
1634 if (! $this->db->query($sql)) {
1635 $this->error=$this->db->lasterror();
1659 $entity=(! empty($force_entity) ? $force_entity : $conf->entity);
1661 dol_syslog(get_class($this).
"::insert_permissions", LOG_DEBUG);
1664 $sql_del =
"SELECT ".$this->db->decrypt(
'value').
" as value";
1665 $sql_del.=
" FROM ".MAIN_DB_PREFIX.
"const";
1666 $sql_del.=
" WHERE ".$this->db->decrypt(
'name').
" = '".$this->db->escape($this->const_name).
"'";
1667 $sql_del.=
" AND entity IN (0,".$entity.
")";
1669 $resql=$this->db->query($sql_del);
1672 $obj=$this->db->fetch_object(
$resql);
1673 if ($obj !== null && ! empty($obj->value) && ! empty($this->rights)) {
1675 foreach ($this->rights as $key => $value)
1677 $r_id = $this->rights[$key][0];
1678 $r_desc = $this->rights[$key][1];
1679 $r_type = isset($this->rights[$key][2])?$this->rights[$key][2]:
'';
1680 $r_def = $this->rights[$key][3];
1681 $r_perms = $this->rights[$key][4];
1682 $r_subperms = isset($this->rights[$key][5])?$this->rights[$key][5]:
'';
1683 $r_modul = empty($this->rights_class)?strtolower($this->
name):$this->rights_class;
1685 if (empty($r_type)) { $r_type=
'w';
1689 $sql =
"SELECT count(*) as nb FROM ".MAIN_DB_PREFIX.
"rights_def";
1690 $sql.=
" WHERE id = ".$r_id.
" AND entity = ".$entity;
1692 $resqlselect=$this->db->query($sql);
1694 $objcount = $this->db->fetch_object($resqlselect);
1695 if ($objcount && $objcount->nb == 0) {
1698 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"rights_def";
1699 $sql.=
" (id, entity, libelle, module, type, bydefault, perms, subperms)";
1701 $sql.=
"(".$r_id.
",".$entity.
",'".$this->db->escape($r_desc).
"','".$r_modul.
"','".$r_type.
"',".$r_def.
",'".$r_perms.
"','".$r_subperms.
"')";
1705 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"rights_def";
1706 $sql.=
" (id, entity, libelle, module, type, bydefault, perms)";
1708 $sql.=
"(".$r_id.
",".$entity.
",'".$this->db->escape($r_desc).
"','".$r_modul.
"','".$r_type.
"',".$r_def.
",'".$r_perms.
"')";
1713 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"rights_def ";
1714 $sql .=
" (id, entity, libelle, module, type, bydefault)";
1716 $sql .=
"(".$r_id.
",".$entity.
",'".$this->db->escape($r_desc).
"','".$r_modul.
"','".$r_type.
"',".$r_def.
")";
1719 $resqlinsert=$this->db->query($sql, 1);
1721 if (! $resqlinsert) {
1722 if ($this->db->errno() !=
"DB_ERROR_RECORD_ALREADY_EXISTS") {
1723 $this->error=$this->db->lasterror();
1727 else {
dol_syslog(get_class($this).
"::insert_permissions record already exists", LOG_INFO);
1731 $this->db->free($resqlinsert);
1734 $this->db->free($resqlselect);
1738 if ($reinitadminperms) {
1739 if (! class_exists(
'User')) {
1740 include_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
1742 $sql=
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"user WHERE admin = 1";
1743 dol_syslog(get_class($this).
"::insert_permissions Search all admin users", LOG_DEBUG);
1744 $resqlseladmin=$this->db->query($sql, 1);
1745 if ($resqlseladmin) {
1746 $num=$this->db->num_rows($resqlseladmin);
1750 $obj2=$this->db->fetch_object($resqlseladmin);
1751 dol_syslog(get_class($this).
"::insert_permissions Add permission to user id=".$obj2->rowid);
1753 $tmpuser=
new User($this->db);
1754 $result = $tmpuser->fetch($obj2->rowid);
1756 $tmpuser->addrights($r_id,
'',
'', 0, 1);
1760 dol_syslog(get_class($this).
"::insert_permissions Failed to add the permission to user because fetch return an error", LOG_ERR);
1772 if ($reinitadminperms && ! empty($user->admin))
1775 $user->clearrights();
1783 $this->error=$this->db->lasterror();
1804 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"rights_def";
1805 $sql.=
" WHERE module = '".$this->db->escape(empty($this->rights_class)?strtolower($this->
name):$this->rights_class).
"'";
1806 $sql.=
" AND entity = ".$conf->entity;
1807 dol_syslog(get_class($this).
"::delete_permissions", LOG_DEBUG);
1808 if (! $this->db->query($sql)) {
1809 $this->error=$this->db->lasterror();
1828 if (! is_array($this->menu) || empty($this->menu)) {
return 0;
1831 include_once DOL_DOCUMENT_ROOT .
'/core/class/menubase.class.php';
1833 dol_syslog(get_class($this).
"::insert_menus", LOG_DEBUG);
1839 foreach ($this->menu as $key => $value)
1842 $menu->menu_handler=
'all';
1845 $menu->module=empty($this->rights_class)?strtolower($this->
name):$this->rights_class;
1847 if (! $this->menu[$key][
'fk_menu']) {
1853 $fk_parent=$this->menu[$key][
'fk_menu'];
1854 if (preg_match(
'/^r=/', $fk_parent))
1856 $fk_parent=str_replace(
'r=',
'', $fk_parent);
1857 if (isset($this->menu[$fk_parent][
'rowid'])) {
1858 $menu->fk_menu=$this->menu[$fk_parent][
'rowid'];
1862 elseif (preg_match(
'/^fk_mainmenu=([a-zA-Z0-9_]+),fk_leftmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
1864 $menu->fk_mainmenu=$reg[1];
1865 $menu->fk_leftmenu=$reg[2];
1868 elseif (preg_match(
'/^fk_mainmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
1870 $menu->fk_mainmenu=$reg[1];
1871 $menu->fk_leftmenu=
'';
1874 if (! $foundparent) {
1875 $this->error=
"ErrorBadDefinitionOfMenuArrayInModuleDescriptor";
1876 dol_syslog(get_class($this).
"::insert_menus ".$this->error.
" ".$this->menu[$key][
'fk_menu'], LOG_ERR);
1880 $menu->type=$this->menu[$key][
'type'];
1881 $menu->mainmenu=isset($this->menu[$key][
'mainmenu'])?$this->menu[$key][
'mainmenu']:(isset($menu->fk_mainmenu)?$menu->fk_mainmenu:
'');
1882 $menu->leftmenu=isset($this->menu[$key][
'leftmenu'])?$this->menu[$key][
'leftmenu']:
'';
1883 $menu->titre=$this->menu[$key][
'titre'];
1884 $menu->url=$this->menu[$key][
'url'];
1885 $menu->langs=$this->menu[$key][
'langs'];
1886 $menu->position=$this->menu[$key][
'position'];
1887 $menu->perms=$this->menu[$key][
'perms'];
1888 $menu->target=isset($this->menu[$key][
'target'])?$this->menu[$key][
'target']:
'';
1889 $menu->user=$this->menu[$key][
'user'];
1890 $menu->enabled=isset($this->menu[$key][
'enabled'])?$this->menu[$key][
'enabled']:0;
1891 $menu->position=$this->menu[$key][
'position'];
1894 $result=$menu->create($user);
1896 $this->menu[$key][
'rowid']=$result;
1900 $this->error=$menu->error;
1901 dol_syslog(get_class($this).
'::insert_menus result='.$result.
" ".$this->error, LOG_ERR);
1909 $this->db->commit();
1913 dol_syslog(get_class($this).
"::insert_menus ".$this->error, LOG_ERR);
1914 $this->db->rollback();
1935 $module=empty($this->rights_class)?strtolower($this->
name):$this->rights_class;
1937 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"menu";
1938 $sql.=
" WHERE module = '".$this->db->escape($module).
"'";
1939 $sql.=
" AND entity = ".$conf->entity;
1941 dol_syslog(get_class($this).
"::delete_menus", LOG_DEBUG);
1942 $resql=$this->db->query($sql);
1944 $this->error=$this->db->lasterror();
1960 global $langs, $conf;
1964 if (isset($this->dirs) && is_array($this->dirs)) {
1965 foreach ($this->dirs as $key => $value)
1969 if (! is_array($value)) { $dir=$value;
1971 $constname = $this->const_name.
"_DIR_";
1972 $dir = $this->dirs[$key][1];
1973 $addtodatabase = empty($this->dirs[$key][2])?
'':$this->dirs[$key][2];
1974 $subname = empty($this->dirs[$key][3])?
'':strtoupper($this->dirs[$key][3]);
1975 $forcename = empty($this->dirs[$key][4])?
'':strtoupper($this->dirs[$key][4]);
1977 if (! empty($forcename)) { $constname =
'MAIN_MODULE_'.$forcename.
"_DIR_";
1979 if (! empty($subname)) { $constname = $constname.$subname.
"_";
1982 $name = $constname.strtoupper($this->dirs[$key][0]);
1986 if (empty($conf->global->MAIN_MODULE_MULTICOMPANY) || $conf->entity == 1) { $fulldir = DOL_DATA_ROOT.$dir;
1987 }
else { $fulldir = DOL_DATA_ROOT.
"/".$conf->entity.$dir;
1990 if (! empty($fulldir) && ! file_exists($fulldir)) {
1991 if (
dol_mkdir($fulldir, DOL_DATA_ROOT) < 0) {
1992 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $fulldir);
1993 dol_syslog(get_class($this).
"::_init ".$this->error, LOG_ERR);
1999 if (! empty($addtodatabase)) {
2001 if ($result) { $err++;
2027 $sql =
"SELECT count(*)";
2028 $sql.=
" FROM ".MAIN_DB_PREFIX.
"const";
2029 $sql.=
" WHERE ".$this->db->decrypt(
'name').
" = '".$name.
"'";
2030 $sql.=
" AND entity = ".$conf->entity;
2032 dol_syslog(get_class($this).
"::insert_dirs", LOG_DEBUG);
2033 $result=$this->db->query($sql);
2035 $row = $this->db->fetch_row($result);
2038 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (name,type,value,note,visible,entity)";
2039 $sql.=
" VALUES (".$this->db->encrypt($name, 1).
",'chaine',".$this->db->encrypt($dir, 1).
",'Directory for module ".$this->
name.
"','0',".$conf->entity.
")";
2041 dol_syslog(get_class($this).
"::insert_dirs", LOG_DEBUG);
2042 $this->db->query($sql);
2047 $this->error=$this->db->lasterror();
2068 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
2069 $sql.=
" WHERE ".$this->db->decrypt(
'name').
" LIKE '".$this->db->escape($this->const_name).
"_DIR_%'";
2070 $sql.=
" AND entity = ".$conf->entity;
2072 dol_syslog(get_class($this).
"::delete_dirs", LOG_DEBUG);
2073 if (! $this->db->query($sql)) {
2074 $this->error=$this->db->lasterror();
2094 if (is_array($this->module_parts) && ! empty($this->module_parts)) {
2095 foreach($this->module_parts as $key => $value)
2097 if (is_array($value) && count($value) == 0) {
continue;
2100 $entity=$conf->entity;
2104 if (is_array($value)) {
2107 if (isset($value[
'data']) && is_array($value[
'data'])) {
2108 $newvalue = json_encode($value[
'data']);
2109 if (isset($value[
'entity'])) { $entity = $value[
'entity'];
2112 else if (isset($value[
'data']) && !is_array($value[
'data'])) {
2113 $newvalue = $value[
'data'];
2114 if (isset($value[
'entity'])) { $entity = $value[
'entity'];
2119 $newvalue = json_encode($value);
2123 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const (";
2132 $sql.= $this->db->encrypt($this->const_name.
"_".strtoupper($key), 1);
2133 $sql.=
", 'chaine'";
2134 $sql.=
", ".$this->db->encrypt($newvalue, 1);
2137 $sql.=
", ".$entity;
2140 dol_syslog(get_class($this).
"::insert_module_parts for key=".$this->const_name.
"_".strtoupper($key), LOG_DEBUG);
2142 $resql=$this->db->query($sql, 1);
2144 if ($this->db->lasterrno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2146 $this->error=$this->db->lasterror();
2150 dol_syslog(get_class($this).
"::insert_module_parts for ".$this->const_name.
"_".strtoupper($key).
" Record already exists.", LOG_WARNING);
2170 $entity=$conf->entity;
2172 if (is_array($this->module_parts) && ! empty($this->module_parts)) {
2173 foreach($this->module_parts as $key => $value)
2176 if (is_array($value) && isset($value[
'entity'])) { $entity = $value[
'entity'];
2179 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
2180 $sql.=
" WHERE ".$this->db->decrypt(
'name').
" LIKE '".$this->db->escape($this->const_name).
"_".strtoupper($key).
"'";
2181 $sql.=
" AND entity = ".$entity;
2183 dol_syslog(get_class($this).
"::delete_const_".$key.
"", LOG_DEBUG);
2184 if (! $this->db->query($sql)) {
2185 $this->error=$this->db->lasterror();
2203 public function init($options =
'')
2205 return $this->
_init(array(), $options);
2216 public function remove($options =
'')
2218 return $this->
_remove(array(), $options);
getLastActivationInfo()
Gives the last author of activation.
_unactive()
Module deactivation.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
delete_dirs()
Removes directories.
insert_permissions($reinitadminperms=0, $force_entity=null, $notrigger=0)
Adds access rights.
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
_remove($array_sql, $options='')
Disable function.
delete_permissions()
Removes access rights.
static getListOfPagesForBoxes()
Name of positions 0=Home, 1=...
Class to manage Dolibarr users.
getName()
Gives the translated module name if translation exists in admin.lang or into language files of module...
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
insert_const()
Adds constants.
insert_dirs($name, $dir)
Adds directories definitions.
getImportDatasetLabel($r)
Gives translated label of an import dataset.
getExportDatasetLabel($r)
Gives translated label of an export dataset.
isCoreOrExternalModule()
Tells if module is core or external.
getLastActivationDate()
Gives the last date of activation.
delete_const()
Removes constants tagged 'deleteonunactive'.
delete_boxes()
Removes boxes.
insert_boxes($option='')
Adds boxes.
getDescLongReadmeFound()
Return path of file if a README file was found.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
insert_cronjobs()
Adds cronjobs.
getPublisher()
Gives the publisher name.
getChangeLog()
Gives the changelog.
getLangFilesArray()
Gives module related language files list.
delete_tabs()
Removes tabs.
getVersion($translated=1)
Gives module version (translated if param $translated is on) For 'experimental' modules, gives 'experimental' translation For 'dolibarr' modules, gives Dolibarr version.
run_sql($sqlfile, $silent=1, $entity='', $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0)
Launch a sql file.
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
dol_now($mode='gmt')
Return date for now.
delete_menus()
Removes menu entries.
delete_cronjobs()
Removes boxes.
dol_is_file($pathoffile)
Return if path is a file.
getPublisherUrl()
Gives the publisher url.
delete_module_parts()
Removes generic parts.
getDescLong()
Gives the long description of a module.
_active()
Insert constants for module activation.
_init($array_sql, $options='')
Enables a module.
getDesc()
Gives the translated module description if translation exists in admin.lang or the default module des...
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
init($options='')
Function called when module is enabled.
insert_module_parts()
Adds generic parts.
create_dirs()
Creates directories.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
__construct($db)
Constructor.
insert_menus()
Adds menu entries.
_load_tables($reldir)
Create tables and keys required by module.