dolibarr  13.0.2
DolibarrModules.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
6  * Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
7  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
8  * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9  * Copyright (C) 2018 Josep Lluís Amador <joseplluis@lliuretic.cat>
10  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
37 class DolibarrModules // Can not be abstract, because we need to instantiate it into unActivateModule to be able to disable a module whose files were removed.
38 {
42  public $db;
43 
48  public $numero;
49 
54  public $editor_name;
55 
60  public $editor_url;
61 
69  public $family;
70 
83  public $familyinfo;
84 
88  public $module_position = '50';
89 
98  public $name;
99 
105  public $dirs = array();
106 
110  public $boxes = array();
111 
115  public $const = array();
116 
120  public $cronjobs = array();
121 
125  public $rights;
126 
130  public $rights_class;
131 
135  public $menu = array();
136 
164  public $module_parts = array();
165 
170  public $docs;
171 
176  public $dbversion = "-";
177 
181  public $error;
182 
193  public $version;
194 
200  public $description;
201 
208  public $descriptionlong;
209 
210 
211  // For exports
212 
216  public $export_code;
217 
221  public $export_label;
222 
223  public $export_permission;
224  public $export_fields_array;
225  public $export_TypeFields_array; // Array of key=>type where type can be 'Numeric', 'Date', 'Text', 'Boolean', 'Status', 'List:xxx:login:rowid'
226  public $export_entities_array;
227  public $export_special_array; // special or computed field
228  public $export_dependencies_array;
229  public $export_sql_start;
230  public $export_sql_end;
231  public $export_sql_order;
232 
233 
234  // For import
235 
239  public $import_code;
240 
244  public $import_label;
245 
246 
250  public $const_name;
251 
255  public $always_enabled;
256 
260  public $core_enabled;
261 
268  public $picto;
269 
276  public $config_page_url;
277 
278 
283  public $depends;
284 
289  public $requiredby;
290 
295  public $conflictwith;
296 
300  public $langfiles;
301 
307  public $warnings_activation;
308 
314  public $warnings_activation_ext;
315 
316 
321  public $phpmin;
322 
327  public $need_dolibarr_version;
328 
332  public $hidden = false;
333 
334 
335 
336 
337 
343  public function __construct($db)
344  {
345  $this->db = $db;
346  }
347  // We should but can't set this as abstract because this will make dolibarr hang
348  // after migration due to old module not implementing. We must wait PHP is able to make
349  // a try catch on Fatal error to manage this correctly.
350  // We need constructor into function unActivateModule into admin.lib.php
351 
352 
353  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
366  protected function _init($array_sql, $options = '')
367  {
368  // phpcs:enable
369  global $conf;
370  $err = 0;
371 
372  $this->db->begin();
373 
374  // Insert activation module constant
375  if (!$err) {
376  $err += $this->_active();
377  }
378 
379  // Insert new pages for tabs (into llx_const)
380  if (!$err) {
381  $err += $this->insert_tabs();
382  }
383 
384  // Insert activation of module's parts
385  if (!$err) {
386  $err += $this->insert_module_parts();
387  }
388 
389  // Insert constant defined by modules (into llx_const)
390  if (!$err && !preg_match('/newboxdefonly/', $options)) {
391  $err += $this->insert_const(); // Test on newboxdefonly to avoid to erase value during upgrade
392  }
393 
394  // Insert boxes def into llx_boxes_def and boxes setup (into llx_boxes)
395  if (!$err && !preg_match('/noboxes/', $options)) {
396  $err += $this->insert_boxes($options);
397  }
398 
399  // Insert cron job entries (entry in llx_cronjobs)
400  if (!$err) {
401  $err += $this->insert_cronjobs();
402  }
403 
404  // Insert permission definitions of module into llx_rights_def. If user is admin, grant this permission to user.
405  if (!$err) {
406  $err += $this->insert_permissions(1, null, 1);
407  }
408 
409  // Insert specific menus entries into database
410  if (!$err) {
411  $err += $this->insert_menus();
412  }
413 
414  // Create module's directories
415  if (!$err) {
416  $err += $this->create_dirs();
417  }
418 
419  // Execute addons requests
420  $num = count($array_sql);
421  for ($i = 0; $i < $num; $i++)
422  {
423  if (!$err) {
424  $val = $array_sql[$i];
425  $sql = $val;
426  $ignoreerror = 0;
427  if (is_array($val)) {
428  $sql = $val['sql'];
429  $ignoreerror = $val['ignoreerror'];
430  }
431  // Add current entity id
432  $sql = str_replace('__ENTITY__', $conf->entity, $sql);
433 
434  dol_syslog(get_class($this)."::_init ignoreerror=".$ignoreerror."", LOG_DEBUG);
435  $result = $this->db->query($sql, $ignoreerror);
436  if (!$result) {
437  if (!$ignoreerror) {
438  $this->error = $this->db->lasterror();
439  $err++;
440  } else {
441  dol_syslog(get_class($this)."::_init Warning ".$this->db->lasterror(), LOG_WARNING);
442  }
443  }
444  }
445  }
446 
447  // Return code
448  if (!$err) {
449  $this->db->commit();
450  return 1;
451  } else {
452  $this->db->rollback();
453  return 0;
454  }
455  }
456 
457  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
466  protected function _remove($array_sql, $options = '')
467  {
468  // phpcs:enable
469  $err = 0;
470 
471  $this->db->begin();
472 
473  // Remove activation module line (constant MAIN_MODULE_MYMODULE in llx_const)
474  if (!$err) {
475  $err += $this->_unactive();
476  }
477 
478  // Remove activation of module's new tabs (MAIN_MODULE_MYMODULE_TABS_XXX in llx_const)
479  if (!$err) {
480  $err += $this->delete_tabs();
481  }
482 
483  // Remove activation of module's parts (MAIN_MODULE_MYMODULE_XXX in llx_const)
484  if (!$err) {
485  $err += $this->delete_module_parts();
486  }
487 
488  // Remove constants defined by modules
489  if (!$err) {
490  $err += $this->delete_const();
491  }
492 
493  // Remove list of module's available boxes (entry in llx_boxes)
494  if (!$err && !preg_match('/(newboxdefonly|noboxes)/', $options)) {
495  $err += $this->delete_boxes(); // We don't have to delete if option ask to keep boxes safe or ask to add new box def only
496  }
497 
498  // Remove list of module's cron job entries (entry in llx_cronjobs)
499  if (!$err) {
500  $err += $this->delete_cronjobs();
501  }
502 
503  // Remove module's permissions from list of available permissions (entries in llx_rights_def)
504  if (!$err) {
505  $err += $this->delete_permissions();
506  }
507 
508  // Remove module's menus (entries in llx_menu)
509  if (!$err) {
510  $err += $this->delete_menus();
511  }
512 
513  // Remove module's directories
514  if (!$err) {
515  $err += $this->delete_dirs();
516  }
517 
518  // Run complementary sql requests
519  $num = count($array_sql);
520  for ($i = 0; $i < $num; $i++)
521  {
522  if (!$err) {
523  dol_syslog(get_class($this)."::_remove", LOG_DEBUG);
524  $result = $this->db->query($array_sql[$i]);
525  if (!$result) {
526  $this->error = $this->db->error();
527  $err++;
528  }
529  }
530  }
531 
532  // Return code
533  if (!$err) {
534  $this->db->commit();
535  return 1;
536  } else {
537  $this->db->rollback();
538  return 0;
539  }
540  }
541 
542 
549  public function getName()
550  {
551  global $langs;
552  $langs->load("admin");
553 
554  if ($langs->transnoentitiesnoconv("Module".$this->numero."Name") != ("Module".$this->numero."Name")) {
555  // If module name translation exists
556  return $langs->transnoentitiesnoconv("Module".$this->numero."Name");
557  } else {
558  // If module name translation using it's unique id does not exist, we try to use its name to find translation
559  if (is_array($this->langfiles)) {
560  foreach ($this->langfiles as $val)
561  {
562  if ($val) { $langs->load($val);
563  }
564  }
565  }
566 
567  if ($langs->trans("Module".$this->name."Name") != ("Module".$this->name."Name")) {
568  // If module name translation exists
569  return $langs->transnoentitiesnoconv("Module".$this->name."Name");
570  }
571 
572  // Last chance with simple label
573  return $langs->transnoentitiesnoconv($this->name);
574  }
575  }
576 
577 
583  public function getDesc()
584  {
585  global $langs;
586  $langs->load("admin");
587 
588  if ($langs->transnoentitiesnoconv("Module".$this->numero."Desc") != ("Module".$this->numero."Desc")) {
589  // If module description translation exists
590  return $langs->transnoentitiesnoconv("Module".$this->numero."Desc");
591  } else {
592  // If module description translation does not exist using its unique id, we can use its name to find translation
593  if (is_array($this->langfiles)) {
594  foreach ($this->langfiles as $val)
595  {
596  if ($val) { $langs->load($val);
597  }
598  }
599  }
600 
601  if ($langs->transnoentitiesnoconv("Module".$this->name."Desc") != ("Module".$this->name."Desc")) {
602  // If module name translation exists
603  return $langs->trans("Module".$this->name."Desc");
604  }
605 
606  // Last chance with simple label
607  return $langs->trans($this->description);
608  }
609  }
610 
617  public function getDescLong()
618  {
619  global $langs;
620  $langs->load("admin");
621 
622  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
623  include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
624 
625  $pathoffile = $this->getDescLongReadmeFound();
626 
627  if ($pathoffile) // Mostly for external modules
628  {
629  $content = file_get_contents($pathoffile);
630 
631  if ((float) DOL_VERSION >= 6.0) {
632  @include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
633 
634  $content = dolMd2Html(
635  $content,
636  'parsedown',
637  array(
638  'doc/' => dol_buildpath(strtolower($this->name).'/doc/', 1),
639  'img/' => dol_buildpath(strtolower($this->name).'/img/', 1),
640  'images/' => dol_buildpath(strtolower($this->name).'/images/', 1),
641  )
642  );
643  } else {
644  $content = nl2br($content);
645  }
646  } else {
647  // Mostly for internal modules
648  if (!empty($this->descriptionlong)) {
649  if (is_array($this->langfiles)) {
650  foreach ($this->langfiles as $val)
651  {
652  if ($val) { $langs->load($val);
653  }
654  }
655  }
656 
657  $content = $langs->transnoentitiesnoconv($this->descriptionlong);
658  }
659  }
660 
661  return $content;
662  }
663 
669  public function getDescLongReadmeFound()
670  {
671  global $langs;
672 
673  $filefound = false;
674 
675  // Define path to file README.md.
676  // First check README-la_LA.md then README-la.md then README.md
677  $pathoffile = dol_buildpath(strtolower($this->name).'/README-'.$langs->defaultlang.'.md', 0);
678  if (dol_is_file($pathoffile)) {
679  $filefound = true;
680  }
681  if (!$filefound) {
682  $tmp = explode('_', $langs->defaultlang);
683  $pathoffile = dol_buildpath(strtolower($this->name).'/README-'.$tmp[0].'.md', 0);
684  if (dol_is_file($pathoffile)) {
685  $filefound = true;
686  }
687  }
688  if (!$filefound) {
689  $pathoffile = dol_buildpath(strtolower($this->name).'/README.md', 0);
690  if (dol_is_file($pathoffile)) {
691  $filefound = true;
692  }
693  }
694 
695  return ($filefound ? $pathoffile : '');
696  }
697 
698 
704  public function getChangeLog()
705  {
706  global $langs;
707  $langs->load("admin");
708 
709  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
710  include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
711 
712  $filefound = false;
713 
714  // Define path to file README.md.
715  // First check ChangeLog-la_LA.md then ChangeLog.md
716  $pathoffile = dol_buildpath(strtolower($this->name).'/ChangeLog-'.$langs->defaultlang.'.md', 0);
717  if (dol_is_file($pathoffile)) {
718  $filefound = true;
719  }
720  if (!$filefound) {
721  $pathoffile = dol_buildpath(strtolower($this->name).'/ChangeLog.md', 0);
722  if (dol_is_file($pathoffile)) {
723  $filefound = true;
724  }
725  }
726 
727  if ($filefound) // Mostly for external modules
728  {
729  $content = file_get_contents($pathoffile);
730 
731  if ((float) DOL_VERSION >= 6.0) {
732  @include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
733  $content = dolMd2Html($content, 'parsedown', array('doc/'=>dol_buildpath(strtolower($this->name).'/doc/', 1)));
734  } else {
735  $content = nl2br($content);
736  }
737  }
738 
739  return $content;
740  }
741 
747  public function getPublisher()
748  {
749  return $this->editor_name;
750  }
751 
757  public function getPublisherUrl()
758  {
759  return $this->editor_url;
760  }
761 
770  public function getVersion($translated = 1)
771  {
772  global $langs;
773  $langs->load("admin");
774 
775  $ret = '';
776 
777  $newversion = preg_replace('/_deprecated/', '', $this->version);
778  if ($newversion == 'experimental') {
779  $ret = ($translated ? $langs->transnoentitiesnoconv("VersionExperimental") : $newversion);
780  } elseif ($newversion == 'development') {
781  $ret = ($translated ? $langs->transnoentitiesnoconv("VersionDevelopment") : $newversion);
782  } elseif ($newversion == 'dolibarr') {
783  $ret = DOL_VERSION;
784  } elseif ($newversion) {
785  $ret = $newversion;
786  } else {
787  $ret = ($translated ? $langs->transnoentitiesnoconv("VersionUnknown") : 'unknown');
788  }
789 
790  if (preg_match('/_deprecated/', $this->version)) {
791  $ret .= ($translated ? ' ('.$langs->transnoentitiesnoconv("Deprecated").')' : $this->version);
792  }
793  return $ret;
794  }
795 
796 
802  public function isCoreOrExternalModule()
803  {
804  if ($this->version == 'dolibarr' || $this->version == 'dolibarr_deprecated') {
805  return 'core';
806  }
807  if (!empty($this->version) && !in_array($this->version, array('experimental', 'development'))) {
808  return 'external';
809  }
810  if (!empty($this->editor_name) || !empty($this->editor_url)) {
811  return 'external';
812  }
813  if ($this->numero >= 100000) {
814  return 'external';
815  }
816  return 'unknown';
817  }
818 
819 
825  public function getLangFilesArray()
826  {
827  return $this->langfiles;
828  }
829 
837  public function getExportDatasetLabel($r)
838  {
839  global $langs;
840 
841  $langstring = "ExportDataset_".$this->export_code[$r];
842  if ($langs->trans($langstring) == $langstring) {
843  // Translation not found
844  return $langs->trans($this->export_label[$r]);
845  } else {
846  // Translation found
847  return $langs->trans($langstring);
848  }
849  }
850 
851 
859  public function getImportDatasetLabel($r)
860  {
861  global $langs;
862 
863  $langstring = "ImportDataset_".$this->import_code[$r];
864  //print "x".$langstring;
865  if ($langs->trans($langstring) == $langstring) {
866  // Translation not found
867  return $langs->transnoentitiesnoconv($this->import_label[$r]);
868  } else {
869  // Translation found
870  return $langs->transnoentitiesnoconv($langstring);
871  }
872  }
873 
874 
880  public function getLastActivationDate()
881  {
882  global $conf;
883 
884  $err = 0;
885 
886  $sql = "SELECT tms FROM ".MAIN_DB_PREFIX."const";
887  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
888  $sql .= " AND entity IN (0, ".$conf->entity.")";
889 
890  dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG);
891  $resql = $this->db->query($sql);
892  if (!$resql)
893  {
894  $err++;
895  } else {
896  $obj = $this->db->fetch_object($resql);
897  if ($obj) {
898  return $this->db->jdate($obj->tms);
899  }
900  }
901 
902  return '';
903  }
904 
905 
911  public function getLastActivationInfo()
912  {
913  global $conf;
914 
915  $err = 0;
916 
917  $sql = "SELECT tms, note FROM ".MAIN_DB_PREFIX."const";
918  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
919  $sql .= " AND entity IN (0, ".$conf->entity.")";
920 
921  dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG);
922  $resql = $this->db->query($sql);
923  if (!$resql)
924  {
925  $err++;
926  } else {
927  $obj = $this->db->fetch_object($resql);
928  $tmp = array();
929  if ($obj->note) {
930  $tmp = json_decode($obj->note, true);
931  }
932  if ($obj) {
933  return array('authorid'=>$tmp['authorid'], 'ip'=>$tmp['ip'], 'lastactivationdate'=>$this->db->jdate($obj->tms));
934  }
935  }
936 
937  return array();
938  }
939 
940 
941  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
947  protected function _active()
948  {
949  // phpcs:enable
950  global $conf, $user;
951 
952  $err = 0;
953 
954  // Common module
955  $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity);
956 
957  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
958  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
959  $sql .= " AND entity IN (0, ".$entity.")";
960 
961  dol_syslog(get_class($this)."::_active delete activation constant", LOG_DEBUG);
962  $resql = $this->db->query($sql);
963  if (!$resql) {
964  $err++;
965  }
966 
967  $note = json_encode(array('authorid'=>(is_object($user) ? $user->id : 0), 'ip'=>(empty($_SERVER['REMOTE_ADDR']) ? '' : $_SERVER['REMOTE_ADDR'])));
968 
969  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name, value, visible, entity, note) VALUES";
970  $sql .= " (".$this->db->encrypt($this->const_name, 1);
971  $sql .= ", ".$this->db->encrypt('1', 1);
972  $sql .= ", 0, ".$entity;
973  $sql .= ", '".$this->db->escape($note)."')";
974 
975  dol_syslog(get_class($this)."::_active insert activation constant", LOG_DEBUG);
976  $resql = $this->db->query($sql);
977  if (!$resql) { $err++;
978  }
979 
980  return $err;
981  }
982 
983 
984  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
990  protected function _unactive()
991  {
992  // phpcs:enable
993  global $conf;
994 
995  $err = 0;
996 
997  // Common module
998  $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity);
999 
1000  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1001  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
1002  $sql .= " AND entity IN (0, ".$entity.")";
1003 
1004  dol_syslog(get_class($this)."::_unactive", LOG_DEBUG);
1005  $this->db->query($sql);
1006 
1007  return $err;
1008  }
1009 
1010 
1011  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps,PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1021  protected function _load_tables($reldir)
1022  {
1023  // phpcs:enable
1024  global $conf;
1025 
1026  $error = 0;
1027  $dirfound = 0;
1028 
1029  if (empty($reldir)) {
1030  return 1;
1031  }
1032 
1033  include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
1034 
1035  $ok = 1;
1036  foreach ($conf->file->dol_document_root as $dirroot)
1037  {
1038  if ($ok) {
1039  $dir = $dirroot.$reldir;
1040  $ok = 0;
1041 
1042  $handle = @opendir($dir); // Dir may not exists
1043  if (is_resource($handle)) {
1044  $dirfound++;
1045 
1046  // Run llx_mytable.sql files, then llx_mytable_*.sql
1047  $files = array();
1048  while (($file = readdir($handle)) !== false)
1049  {
1050  $files[] = $file;
1051  }
1052  sort($files);
1053  foreach ($files as $file)
1054  {
1055  if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && substr($file, 0, 4) == 'llx_' && substr($file, 0, 4) != 'data') {
1056  $result = run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG) ? 1 : 0, '', 1);
1057  if ($result <= 0) { $error++;
1058  }
1059  }
1060  }
1061 
1062  rewinddir($handle);
1063 
1064  // Run llx_mytable.key.sql files (Must be done after llx_mytable.sql) then then llx_mytable_*.key.sql
1065  $files = array();
1066  while (($file = readdir($handle)) !== false)
1067  {
1068  $files[] = $file;
1069  }
1070  sort($files);
1071  foreach ($files as $file)
1072  {
1073  if (preg_match('/\.key\.sql$/i', $file) && substr($file, 0, 4) == 'llx_' && substr($file, 0, 4) != 'data') {
1074  $result = run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG) ? 1 : 0, '', 1);
1075  if ($result <= 0) { $error++;
1076  }
1077  }
1078  }
1079 
1080  rewinddir($handle);
1081 
1082  // Run data_xxx.sql files (Must be done after llx_mytable.key.sql)
1083  $files = array();
1084  while (($file = readdir($handle)) !== false)
1085  {
1086  $files[] = $file;
1087  }
1088  sort($files);
1089  foreach ($files as $file)
1090  {
1091  if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && substr($file, 0, 4) == 'data') {
1092  $result = run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG) ? 1 : 0, '', 1);
1093  if ($result <= 0) { $error++;
1094  }
1095  }
1096  }
1097 
1098  rewinddir($handle);
1099 
1100  // Run update_xxx.sql files
1101  $files = array();
1102  while (($file = readdir($handle)) !== false)
1103  {
1104  $files[] = $file;
1105  }
1106  sort($files);
1107  foreach ($files as $file)
1108  {
1109  if (preg_match('/\.sql$/i', $file) && !preg_match('/\.key\.sql$/i', $file) && substr($file, 0, 6) == 'update') {
1110  $result = run_sql($dir.$file, empty($conf->global->MAIN_DISPLAY_SQL_INSTALL_LOG) ? 1 : 0, '', 1);
1111  if ($result <= 0) { $error++;
1112  }
1113  }
1114  }
1115 
1116  closedir($handle);
1117  }
1118 
1119  if ($error == 0) {
1120  $ok = 1;
1121  }
1122  }
1123  }
1124 
1125  if (!$dirfound) {
1126  dol_syslog("A module ask to load sql files into ".$reldir." but this directory was not found.", LOG_WARNING);
1127  }
1128  return $ok;
1129  }
1130 
1131 
1132  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1140  public function insert_boxes($option = '')
1141  {
1142  // phpcs:enable
1143  include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1144 
1145  global $conf;
1146 
1147  $err = 0;
1148 
1149  if (is_array($this->boxes)) {
1150  dol_syslog(get_class($this)."::insert_boxes", LOG_DEBUG);
1151 
1152  $pos_name = InfoBox::getListOfPagesForBoxes();
1153 
1154  foreach ($this->boxes as $key => $value)
1155  {
1156  $file = isset($this->boxes[$key]['file']) ? $this->boxes[$key]['file'] : '';
1157  $note = isset($this->boxes[$key]['note']) ? $this->boxes[$key]['note'] : '';
1158  $enabledbydefaulton = isset($this->boxes[$key]['enabledbydefaulton']) ? $this->boxes[$key]['enabledbydefaulton'] : 'Home';
1159 
1160  if (empty($file)) { $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] : ''; // For backward compatibility
1161  }
1162  if (empty($note)) { $note = isset($this->boxes[$key][2]) ? $this->boxes[$key][2] : ''; // For backward compatibility
1163  }
1164 
1165  // Search if boxes def already present
1166  $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."boxes_def";
1167  $sql .= " WHERE file = '".$this->db->escape($file)."'";
1168  $sql .= " AND entity = ".$conf->entity;
1169  if ($note) { $sql .= " AND note ='".$this->db->escape($note)."'";
1170  }
1171 
1172  $result = $this->db->query($sql);
1173  if ($result) {
1174  $obj = $this->db->fetch_object($result);
1175  if ($obj->nb == 0) {
1176  $this->db->begin();
1177 
1178  if (!$err) {
1179  $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes_def (file, entity, note)";
1180  $sql .= " VALUES ('".$this->db->escape($file)."', ";
1181  $sql .= $conf->entity.", ";
1182  $sql .= $note ? "'".$this->db->escape($note)."'" : "null";
1183  $sql .= ")";
1184 
1185  dol_syslog(get_class($this)."::insert_boxes", LOG_DEBUG);
1186  $resql = $this->db->query($sql);
1187  if (!$resql) { $err++;
1188  }
1189  }
1190  if (!$err && !preg_match('/newboxdefonly/', $option)) {
1191  $lastid = $this->db->last_insert_id(MAIN_DB_PREFIX."boxes_def", "rowid");
1192 
1193  foreach ($pos_name as $key2 => $val2)
1194  {
1195  //print 'key2='.$key2.'-val2='.$val2."<br>\n";
1196  if ($enabledbydefaulton && $val2 != $enabledbydefaulton) { continue; // Not enabled by default onto this page.
1197  }
1198 
1199  $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes (box_id,position,box_order,fk_user,entity)";
1200  $sql .= " VALUES (".$lastid.", ".$key2.", '0', 0, ".$conf->entity.")";
1201 
1202  dol_syslog(get_class($this)."::insert_boxes onto page ".$key2."=".$val2."", LOG_DEBUG);
1203  $resql = $this->db->query($sql);
1204  if (!$resql) { $err++;
1205  }
1206  }
1207  }
1208 
1209  if (!$err) {
1210  $this->db->commit();
1211  } else {
1212  $this->error = $this->db->lasterror();
1213  $this->db->rollback();
1214  }
1215  }
1216  // else box already registered into database
1217  } else {
1218  $this->error = $this->db->lasterror();
1219  $err++;
1220  }
1221  }
1222  }
1223 
1224  return $err;
1225  }
1226 
1227 
1228  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1234  public function delete_boxes()
1235  {
1236  // phpcs:enable
1237  global $conf;
1238 
1239  $err = 0;
1240 
1241  if (is_array($this->boxes)) {
1242  foreach ($this->boxes as $key => $value)
1243  {
1244  //$titre = $this->boxes[$key][0];
1245  $file = $this->boxes[$key]['file'];
1246  //$note = $this->boxes[$key][2];
1247 
1248  // TODO If the box is also included by another module and the other module is still on, we should not remove it.
1249  // For the moment, we manage this with hard coded exception
1250  //print "Remove box ".$file.'<br>';
1251  if ($file == 'box_graph_product_distribution.php') {
1252  if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
1253  dol_syslog("We discard deleting module ".$file." because another module still active requires it.");
1254  continue;
1255  }
1256  }
1257 
1258  if (empty($file)) {
1259  $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] : ''; // For backward compatibility
1260  }
1261 
1262  if ($this->db->type == 'sqlite3') {
1263  // sqlite doesn't support "USING" syntax.
1264  // TODO: remove this dependency.
1265  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes ";
1266  $sql .= "WHERE ".MAIN_DB_PREFIX."boxes.box_id IN (";
1267  $sql .= "SELECT ".MAIN_DB_PREFIX."boxes_def.rowid ";
1268  $sql .= "FROM ".MAIN_DB_PREFIX."boxes_def ";
1269  $sql .= "WHERE ".MAIN_DB_PREFIX."boxes_def.file = '".$this->db->escape($file)."') ";
1270  $sql .= "AND ".MAIN_DB_PREFIX."boxes.entity = ".$conf->entity;
1271  } else {
1272  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes";
1273  $sql .= " USING ".MAIN_DB_PREFIX."boxes, ".MAIN_DB_PREFIX."boxes_def";
1274  $sql .= " WHERE ".MAIN_DB_PREFIX."boxes.box_id = ".MAIN_DB_PREFIX."boxes_def.rowid";
1275  $sql .= " AND ".MAIN_DB_PREFIX."boxes_def.file = '".$this->db->escape($file)."'";
1276  $sql .= " AND ".MAIN_DB_PREFIX."boxes.entity = ".$conf->entity;
1277  }
1278 
1279  dol_syslog(get_class($this)."::delete_boxes", LOG_DEBUG);
1280  $resql = $this->db->query($sql);
1281  if (!$resql) {
1282  $this->error = $this->db->lasterror();
1283  $err++;
1284  }
1285 
1286  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes_def";
1287  $sql .= " WHERE file = '".$this->db->escape($file)."'";
1288  $sql .= " AND entity = ".$conf->entity; // Do not use getEntity here, we want to delete only in current company
1289 
1290  dol_syslog(get_class($this)."::delete_boxes", LOG_DEBUG);
1291  $resql = $this->db->query($sql);
1292  if (!$resql) {
1293  $this->error = $this->db->lasterror();
1294  $err++;
1295  }
1296  }
1297  }
1298 
1299  return $err;
1300  }
1301 
1302  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1308  public function insert_cronjobs()
1309  {
1310  // phpcs:enable
1311  include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1312 
1313  global $conf;
1314 
1315  $err = 0;
1316 
1317  if (is_array($this->cronjobs)) {
1318  dol_syslog(get_class($this)."::insert_cronjobs", LOG_DEBUG);
1319 
1320  foreach ($this->cronjobs as $key => $value)
1321  {
1322  $entity = isset($this->cronjobs[$key]['entity']) ? $this->cronjobs[$key]['entity'] : $conf->entity;
1323  $label = isset($this->cronjobs[$key]['label']) ? $this->cronjobs[$key]['label'] : '';
1324  $jobtype = isset($this->cronjobs[$key]['jobtype']) ? $this->cronjobs[$key]['jobtype'] : '';
1325  $class = isset($this->cronjobs[$key]['class']) ? $this->cronjobs[$key]['class'] : '';
1326  $objectname = isset($this->cronjobs[$key]['objectname']) ? $this->cronjobs[$key]['objectname'] : '';
1327  $method = isset($this->cronjobs[$key]['method']) ? $this->cronjobs[$key]['method'] : '';
1328  $command = isset($this->cronjobs[$key]['command']) ? $this->cronjobs[$key]['command'] : '';
1329  $parameters = isset($this->cronjobs[$key]['parameters']) ? $this->cronjobs[$key]['parameters'] : '';
1330  $comment = isset($this->cronjobs[$key]['comment']) ? $this->cronjobs[$key]['comment'] : '';
1331  $frequency = isset($this->cronjobs[$key]['frequency']) ? $this->cronjobs[$key]['frequency'] : '';
1332  $unitfrequency = isset($this->cronjobs[$key]['unitfrequency']) ? $this->cronjobs[$key]['unitfrequency'] : '';
1333  $priority = isset($this->cronjobs[$key]['priority']) ? $this->cronjobs[$key]['priority'] : '';
1334  $datestart = isset($this->cronjobs[$key]['datestart']) ? $this->cronjobs[$key]['datestart'] : '';
1335  $dateend = isset($this->cronjobs[$key]['dateend']) ? $this->cronjobs[$key]['dateend'] : '';
1336  $status = isset($this->cronjobs[$key]['status']) ? $this->cronjobs[$key]['status'] : '';
1337  $test = isset($this->cronjobs[$key]['test']) ? $this->cronjobs[$key]['test'] : ''; // Line must be enabled or not (so visible or not)
1338 
1339  // Search if cron entry already present
1340  $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob";
1341  $sql .= " WHERE module_name = '".$this->db->escape(empty($this->rights_class) ?strtolower($this->name) : $this->rights_class)."'";
1342  if ($class) {
1343  $sql .= " AND classesname = '".$this->db->escape($class)."'";
1344  }
1345  if ($objectname) {
1346  $sql .= " AND objectname = '".$this->db->escape($objectname)."'";
1347  }
1348  if ($method) {
1349  $sql .= " AND methodename = '".$this->db->escape($method)."'";
1350  }
1351  if ($command) {
1352  $sql .= " AND command = '".$this->db->escape($command)."'";
1353  }
1354  $sql .= " AND entity = ".$entity; // Must be exact entity
1355 
1356  $now = dol_now();
1357 
1358  $result = $this->db->query($sql);
1359  if ($result) {
1360  $obj = $this->db->fetch_object($result);
1361  if ($obj->nb == 0) {
1362  $this->db->begin();
1363 
1364  if (!$err) {
1365  $sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, datestart, dateend, label, jobtype, classesname, objectname, methodename, command, params, note,";
1366  if (is_int($frequency)) { $sql .= ' frequency,'; }
1367  if (is_int($unitfrequency)) { $sql .= ' unitfrequency,'; }
1368  if (is_int($priority)) { $sql .= ' priority,'; }
1369  if (is_int($status)) { $sql .= ' status,'; }
1370  $sql .= " entity, test)";
1371  $sql .= " VALUES (";
1372  $sql .= "'".$this->db->escape(empty($this->rights_class) ?strtolower($this->name) : $this->rights_class)."', ";
1373  $sql .= "'".$this->db->idate($now)."', ";
1374  $sql .= ($datestart ? "'".$this->db->idate($datestart)."'" : "'".$this->db->idate($now)."'").", ";
1375  $sql .= ($dateend ? "'".$this->db->idate($dateend)."'" : "NULL").", ";
1376  $sql .= "'".$this->db->escape($label)."', ";
1377  $sql .= "'".$this->db->escape($jobtype)."', ";
1378  $sql .= ($class ? "'".$this->db->escape($class)."'" : "null").",";
1379  $sql .= ($objectname ? "'".$this->db->escape($objectname)."'" : "null").",";
1380  $sql .= ($method ? "'".$this->db->escape($method)."'" : "null").",";
1381  $sql .= ($command ? "'".$this->db->escape($command)."'" : "null").",";
1382  $sql .= ($parameters ? "'".$this->db->escape($parameters)."'" : "null").",";
1383  $sql .= ($comment ? "'".$this->db->escape($comment)."'" : "null").",";
1384  if (is_int($frequency)) { $sql .= "'".$this->db->escape($frequency)."', ";
1385  }
1386  if (is_int($unitfrequency)) { $sql .= "'".$this->db->escape($unitfrequency)."', ";
1387  }
1388  if (is_int($priority)) {$sql .= "'".$this->db->escape($priority)."', ";
1389  }
1390  if (is_int($status)) { $sql .= "'".$this->db->escape($status)."', ";
1391  }
1392  $sql .= $entity.",";
1393  $sql .= "'".$this->db->escape($test)."'";
1394  $sql .= ")";
1395 
1396  $resql = $this->db->query($sql);
1397  if (!$resql) { $err++;
1398  }
1399  }
1400 
1401  if (!$err) {
1402  $this->db->commit();
1403  } else {
1404  $this->error = $this->db->lasterror();
1405  $this->db->rollback();
1406  }
1407  }
1408  // else box already registered into database
1409  } else {
1410  $this->error = $this->db->lasterror();
1411  $err++;
1412  }
1413  }
1414  }
1415 
1416  return $err;
1417  }
1418 
1419 
1420  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1426  public function delete_cronjobs()
1427  {
1428  // phpcs:enable
1429  global $conf;
1430 
1431  $err = 0;
1432 
1433  if (is_array($this->cronjobs)) {
1434  $sql = "DELETE FROM ".MAIN_DB_PREFIX."cronjob";
1435  $sql .= " WHERE module_name = '".$this->db->escape(empty($this->rights_class) ?strtolower($this->name) : $this->rights_class)."'";
1436  $sql .= " AND entity = ".$conf->entity;
1437  $sql .= " AND test = '1'"; // We delete on lines that are not set with a complete test that is '$conf->module->enabled' so when module is disabled, the cron is also removed.
1438  // For crons declared with a '$conf->module->enabled', there is no need to delete the line, so we don't loose setup if we reenable module.
1439 
1440  dol_syslog(get_class($this)."::delete_cronjobs", LOG_DEBUG);
1441  $resql = $this->db->query($sql);
1442  if (!$resql) {
1443  $this->error = $this->db->lasterror();
1444  $err++;
1445  }
1446  }
1447 
1448  return $err;
1449  }
1450 
1451  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1457  public function delete_tabs()
1458  {
1459  // phpcs:enable
1460  global $conf;
1461 
1462  $err = 0;
1463 
1464  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1465  $sql .= " WHERE ".$this->db->decrypt('name')." like '".$this->db->escape($this->const_name)."_TABS_%'";
1466  $sql .= " AND entity = ".$conf->entity;
1467 
1468  dol_syslog(get_class($this)."::delete_tabs", LOG_DEBUG);
1469  if (!$this->db->query($sql)) {
1470  $this->error = $this->db->lasterror();
1471  $err++;
1472  }
1473 
1474  return $err;
1475  }
1476 
1477  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1483  public function insert_tabs()
1484  {
1485  // phpcs:enable
1486  global $conf;
1487 
1488  $err = 0;
1489 
1490  if (!empty($this->tabs)) {
1491  dol_syslog(get_class($this)."::insert_tabs", LOG_DEBUG);
1492 
1493  $i = 0;
1494  foreach ($this->tabs as $key => $value)
1495  {
1496  if (is_array($value) && count($value) == 0) { continue; // Discard empty arrays
1497  }
1498 
1499  $entity = $conf->entity;
1500  $newvalue = $value;
1501 
1502  if (is_array($value)) {
1503  $newvalue = $value['data'];
1504  if (isset($value['entity'])) { $entity = $value['entity'];
1505  }
1506  }
1507 
1508  if ($newvalue) {
1509  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (";
1510  $sql .= "name";
1511  $sql .= ", type";
1512  $sql .= ", value";
1513  $sql .= ", note";
1514  $sql .= ", visible";
1515  $sql .= ", entity";
1516  $sql .= ")";
1517  $sql .= " VALUES (";
1518  $sql .= $this->db->encrypt($this->const_name."_TABS_".$i, 1);
1519  $sql .= ", 'chaine'";
1520  $sql .= ", ".$this->db->encrypt($newvalue, 1);
1521  $sql .= ", null";
1522  $sql .= ", '0'";
1523  $sql .= ", ".$entity;
1524  $sql .= ")";
1525 
1526  $resql = $this->db->query($sql);
1527  if (!$resql) {
1528  dol_syslog($this->db->lasterror(), LOG_ERR);
1529  if ($this->db->lasterrno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1530  $this->error = $this->db->lasterror();
1531  $this->errors[] = $this->db->lasterror();
1532  $err++;
1533  break;
1534  }
1535  }
1536  }
1537  $i++;
1538  }
1539  }
1540  return $err;
1541  }
1542 
1543  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1549  public function insert_const()
1550  {
1551  // phpcs:enable
1552  global $conf;
1553 
1554  $err = 0;
1555 
1556  if (empty($this->const)) { return 0;
1557  }
1558 
1559  dol_syslog(get_class($this)."::insert_const", LOG_DEBUG);
1560 
1561  foreach ($this->const as $key => $value)
1562  {
1563  $name = $this->const[$key][0];
1564  $type = $this->const[$key][1];
1565  $val = $this->const[$key][2];
1566  $note = isset($this->const[$key][3]) ? $this->const[$key][3] : '';
1567  $visible = isset($this->const[$key][4]) ? $this->const[$key][4] : 0;
1568  $entity = (!empty($this->const[$key][5]) && $this->const[$key][5] != 'current') ? 0 : $conf->entity;
1569 
1570  // Clean
1571  if (empty($visible)) { $visible = '0';
1572  }
1573  if (empty($val) && $val != '0') { $val = '';
1574  }
1575 
1576  $sql = "SELECT count(*)";
1577  $sql .= " FROM ".MAIN_DB_PREFIX."const";
1578  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'";
1579  $sql .= " AND entity = ".$entity;
1580 
1581  $result = $this->db->query($sql);
1582  if ($result) {
1583  $row = $this->db->fetch_row($result);
1584 
1585  if ($row[0] == 0) // If not found
1586  {
1587  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)";
1588  $sql .= " VALUES (";
1589  $sql .= $this->db->encrypt($name, 1);
1590  $sql .= ",'".$this->db->escape($type)."'";
1591  $sql .= ",".(($val != '') ? $this->db->encrypt($val, 1) : "''");
1592  $sql .= ",".($note ? "'".$this->db->escape($note)."'" : "null");
1593  $sql .= ",'".$this->db->escape($visible)."'";
1594  $sql .= ",".$entity;
1595  $sql .= ")";
1596 
1597  if (!$this->db->query($sql)) {
1598  $err++;
1599  }
1600  } else {
1601  dol_syslog(get_class($this)."::insert_const constant '".$name."' already exists", LOG_WARNING);
1602  }
1603  } else {
1604  $err++;
1605  }
1606  }
1607 
1608  return $err;
1609  }
1610 
1611  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1617  public function delete_const()
1618  {
1619  // phpcs:enable
1620  global $conf;
1621 
1622  $err = 0;
1623 
1624  if (empty($this->const)) { return 0;
1625  }
1626 
1627  foreach ($this->const as $key => $value)
1628  {
1629  $name = $this->const[$key][0];
1630  $deleteonunactive = (!empty($this->const[$key][6])) ? 1 : 0;
1631 
1632  if ($deleteonunactive) {
1633  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
1634  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'";
1635  $sql .= " AND entity in (0, ".$conf->entity.")";
1636  dol_syslog(get_class($this)."::delete_const", LOG_DEBUG);
1637  if (!$this->db->query($sql)) {
1638  $this->error = $this->db->lasterror();
1639  $err++;
1640  }
1641  }
1642  }
1643 
1644  return $err;
1645  }
1646 
1647  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1656  public function insert_permissions($reinitadminperms = 0, $force_entity = null, $notrigger = 0)
1657  {
1658  // phpcs:enable
1659  global $conf, $user;
1660 
1661  $err = 0;
1662  $entity = (!empty($force_entity) ? $force_entity : $conf->entity);
1663 
1664  dol_syslog(get_class($this)."::insert_permissions", LOG_DEBUG);
1665 
1666  // Test if module is activated
1667  $sql_del = "SELECT ".$this->db->decrypt('value')." as value";
1668  $sql_del .= " FROM ".MAIN_DB_PREFIX."const";
1669  $sql_del .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
1670  $sql_del .= " AND entity IN (0,".$entity.")";
1671 
1672  $resql = $this->db->query($sql_del);
1673 
1674  if ($resql) {
1675  $obj = $this->db->fetch_object($resql);
1676  if ($obj !== null && !empty($obj->value) && !empty($this->rights)) {
1677  // If the module is active
1678  foreach ($this->rights as $key => $value)
1679  {
1680  $r_id = $this->rights[$key][0];
1681  $r_desc = $this->rights[$key][1];
1682  $r_type = isset($this->rights[$key][2]) ? $this->rights[$key][2] : '';
1683  $r_def = empty($this->rights[$key][3]) ? 0 : $this->rights[$key][3];
1684  $r_perms = $this->rights[$key][4];
1685  $r_subperms = isset($this->rights[$key][5]) ? $this->rights[$key][5] : '';
1686  $r_modul = empty($this->rights_class) ?strtolower($this->name) : $this->rights_class;
1687 
1688  if (empty($r_type)) { $r_type = 'w'; }
1689 
1690  // Search if perm already present
1691  $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."rights_def";
1692  $sql .= " WHERE id = ".$r_id." AND entity = ".$entity;
1693 
1694  $resqlselect = $this->db->query($sql);
1695  if ($resqlselect) {
1696  $objcount = $this->db->fetch_object($resqlselect);
1697  if ($objcount && $objcount->nb == 0) {
1698  if (dol_strlen($r_perms)) {
1699  if (dol_strlen($r_subperms)) {
1700  $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
1701  $sql .= " (id, entity, libelle, module, type, bydefault, perms, subperms)";
1702  $sql .= " VALUES ";
1703  $sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$this->db->escape($r_modul)."','".$this->db->escape($r_type)."',".$r_def.",'".$this->db->escape($r_perms)."','".$this->db->escape($r_subperms)."')";
1704  } else {
1705  $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
1706  $sql .= " (id, entity, libelle, module, type, bydefault, perms)";
1707  $sql .= " VALUES ";
1708  $sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$this->db->escape($r_modul)."','".$this->db->escape($r_type)."',".$r_def.",'".$this->db->escape($r_perms)."')";
1709  }
1710  } else {
1711  $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def ";
1712  $sql .= " (id, entity, libelle, module, type, bydefault)";
1713  $sql .= " VALUES ";
1714  $sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$this->db->escape($r_modul)."','".$this->db->escape($r_type)."',".$r_def.")";
1715  }
1716 
1717  $resqlinsert = $this->db->query($sql, 1);
1718 
1719  if (!$resqlinsert) {
1720  if ($this->db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS") {
1721  $this->error = $this->db->lasterror();
1722  $err++;
1723  break;
1724  } else { dol_syslog(get_class($this)."::insert_permissions record already exists", LOG_INFO);
1725  }
1726  }
1727 
1728  $this->db->free($resqlinsert);
1729  }
1730 
1731  $this->db->free($resqlselect);
1732  }
1733 
1734  // If we want to init permissions on admin users
1735  if ($reinitadminperms) {
1736  if (!class_exists('User')) {
1737  include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1738  }
1739  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."user WHERE admin = 1";
1740  dol_syslog(get_class($this)."::insert_permissions Search all admin users", LOG_DEBUG);
1741  $resqlseladmin = $this->db->query($sql, 1);
1742  if ($resqlseladmin) {
1743  $num = $this->db->num_rows($resqlseladmin);
1744  $i = 0;
1745  while ($i < $num)
1746  {
1747  $obj2 = $this->db->fetch_object($resqlseladmin);
1748  dol_syslog(get_class($this)."::insert_permissions Add permission to user id=".$obj2->rowid);
1749 
1750  $tmpuser = new User($this->db);
1751  $result = $tmpuser->fetch($obj2->rowid);
1752  if ($result > 0) {
1753  $tmpuser->addrights($r_id, '', '', 0, 1);
1754  } else {
1755  dol_syslog(get_class($this)."::insert_permissions Failed to add the permission to user because fetch return an error", LOG_ERR);
1756  }
1757  $i++;
1758  }
1759  } else {
1760  dol_print_error($this->db);
1761  }
1762  }
1763  }
1764 
1765  if ($reinitadminperms && !empty($user->admin)) // Reload permission for current user if defined
1766  {
1767  // We reload permissions
1768  $user->clearrights();
1769  $user->getrights();
1770  }
1771  }
1772  $this->db->free($resql);
1773  } else {
1774  $this->error = $this->db->lasterror();
1775  $err++;
1776  }
1777 
1778  return $err;
1779  }
1780 
1781 
1782  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1788  public function delete_permissions()
1789  {
1790  // phpcs:enable
1791  global $conf;
1792 
1793  $err = 0;
1794 
1795  $sql = "DELETE FROM ".MAIN_DB_PREFIX."rights_def";
1796  $sql .= " WHERE module = '".$this->db->escape(empty($this->rights_class) ?strtolower($this->name) : $this->rights_class)."'";
1797  $sql .= " AND entity = ".$conf->entity;
1798  dol_syslog(get_class($this)."::delete_permissions", LOG_DEBUG);
1799  if (!$this->db->query($sql)) {
1800  $this->error = $this->db->lasterror();
1801  $err++;
1802  }
1803 
1804  return $err;
1805  }
1806 
1807 
1808  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1814  public function insert_menus()
1815  {
1816  // phpcs:enable
1817  global $user;
1818 
1819  if (!is_array($this->menu) || empty($this->menu)) { return 0;
1820  }
1821 
1822  include_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
1823 
1824  dol_syslog(get_class($this)."::insert_menus", LOG_DEBUG);
1825 
1826  $err = 0;
1827 
1828  $this->db->begin();
1829 
1830  foreach ($this->menu as $key => $value)
1831  {
1832  $menu = new Menubase($this->db);
1833  $menu->menu_handler = 'all';
1834 
1835  //$menu->module=strtolower($this->name); TODO When right_class will be same than module name
1836  $menu->module = empty($this->rights_class) ?strtolower($this->name) : $this->rights_class;
1837 
1838  if (!$this->menu[$key]['fk_menu']) {
1839  $menu->fk_menu = 0;
1840  } else {
1841  $foundparent = 0;
1842  $fk_parent = $this->menu[$key]['fk_menu'];
1843  if (preg_match('/^r=/', $fk_parent)) // old deprecated method
1844  {
1845  $fk_parent = str_replace('r=', '', $fk_parent);
1846  if (isset($this->menu[$fk_parent]['rowid'])) {
1847  $menu->fk_menu = $this->menu[$fk_parent]['rowid'];
1848  $foundparent = 1;
1849  }
1850  } elseif (preg_match('/^fk_mainmenu=([a-zA-Z0-9_]+),fk_leftmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
1851  $menu->fk_menu = -1;
1852  $menu->fk_mainmenu = $reg[1];
1853  $menu->fk_leftmenu = $reg[2];
1854  $foundparent = 1;
1855  } elseif (preg_match('/^fk_mainmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
1856  $menu->fk_menu = -1;
1857  $menu->fk_mainmenu = $reg[1];
1858  $menu->fk_leftmenu = '';
1859  $foundparent = 1;
1860  }
1861  if (!$foundparent) {
1862  $this->error = "ErrorBadDefinitionOfMenuArrayInModuleDescriptor";
1863  dol_syslog(get_class($this)."::insert_menus ".$this->error." ".$this->menu[$key]['fk_menu'], LOG_ERR);
1864  $err++;
1865  }
1866  }
1867  $menu->type = $this->menu[$key]['type'];
1868  $menu->mainmenu = isset($this->menu[$key]['mainmenu']) ? $this->menu[$key]['mainmenu'] : (isset($menu->fk_mainmenu) ? $menu->fk_mainmenu : '');
1869  $menu->leftmenu = isset($this->menu[$key]['leftmenu']) ? $this->menu[$key]['leftmenu'] : '';
1870  $menu->title = $this->menu[$key]['titre'];
1871  $menu->url = $this->menu[$key]['url'];
1872  $menu->langs = $this->menu[$key]['langs'];
1873  $menu->position = $this->menu[$key]['position'];
1874  $menu->perms = $this->menu[$key]['perms'];
1875  $menu->target = isset($this->menu[$key]['target']) ? $this->menu[$key]['target'] : '';
1876  $menu->user = $this->menu[$key]['user'];
1877  $menu->enabled = isset($this->menu[$key]['enabled']) ? $this->menu[$key]['enabled'] : 0;
1878  $menu->position = $this->menu[$key]['position'];
1879 
1880  if (!$err) {
1881  $result = $menu->create($user); // Save menu entry into table llx_menu
1882  if ($result > 0) {
1883  $this->menu[$key]['rowid'] = $result;
1884  } else {
1885  $this->error = $menu->error;
1886  dol_syslog(get_class($this).'::insert_menus result='.$result." ".$this->error, LOG_ERR);
1887  $err++;
1888  break;
1889  }
1890  }
1891  }
1892 
1893  if (!$err) {
1894  $this->db->commit();
1895  } else {
1896  dol_syslog(get_class($this)."::insert_menus ".$this->error, LOG_ERR);
1897  $this->db->rollback();
1898  }
1899 
1900  return $err;
1901  }
1902 
1903 
1904  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1910  public function delete_menus()
1911  {
1912  // phpcs:enable
1913  global $conf;
1914 
1915  $err = 0;
1916 
1917  //$module=strtolower($this->name); TODO When right_class will be same than module name
1918  $module = empty($this->rights_class) ?strtolower($this->name) : $this->rights_class;
1919 
1920  $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
1921  $sql .= " WHERE module = '".$this->db->escape($module)."'";
1922  $sql .= " AND entity = ".$conf->entity;
1923 
1924  dol_syslog(get_class($this)."::delete_menus", LOG_DEBUG);
1925  $resql = $this->db->query($sql);
1926  if (!$resql) {
1927  $this->error = $this->db->lasterror();
1928  $err++;
1929  }
1930 
1931  return $err;
1932  }
1933 
1934  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1940  public function create_dirs()
1941  {
1942  // phpcs:enable
1943  global $langs, $conf;
1944 
1945  $err = 0;
1946 
1947  if (isset($this->dirs) && is_array($this->dirs)) {
1948  foreach ($this->dirs as $key => $value)
1949  {
1950  $addtodatabase = 0;
1951 
1952  if (!is_array($value)) { $dir = $value; // Default simple mode
1953  } else {
1954  $constname = $this->const_name."_DIR_";
1955  $dir = $this->dirs[$key][1];
1956  $addtodatabase = empty($this->dirs[$key][2]) ? '' : $this->dirs[$key][2]; // Create constante in llx_const
1957  $subname = empty($this->dirs[$key][3]) ? '' : strtoupper($this->dirs[$key][3]); // Add submodule name (ex: $conf->module->submodule->dir_output)
1958  $forcename = empty($this->dirs[$key][4]) ? '' : strtoupper($this->dirs[$key][4]); // Change the module name if different
1959 
1960  if (!empty($forcename)) { $constname = 'MAIN_MODULE_'.$forcename."_DIR_";
1961  }
1962  if (!empty($subname)) { $constname = $constname.$subname."_";
1963  }
1964 
1965  $name = $constname.strtoupper($this->dirs[$key][0]);
1966  }
1967 
1968  // Define directory full path ($dir must start with "/")
1969  if (empty($conf->global->MAIN_MODULE_MULTICOMPANY) || $conf->entity == 1) { $fulldir = DOL_DATA_ROOT.$dir;
1970  } else { $fulldir = DOL_DATA_ROOT."/".$conf->entity.$dir;
1971  }
1972  // Create dir if it does not exists
1973  if (!empty($fulldir) && !file_exists($fulldir)) {
1974  if (dol_mkdir($fulldir, DOL_DATA_ROOT) < 0) {
1975  $this->error = $langs->trans("ErrorCanNotCreateDir", $fulldir);
1976  dol_syslog(get_class($this)."::_init ".$this->error, LOG_ERR);
1977  $err++;
1978  }
1979  }
1980 
1981  // Define the constant in database if requested (not the default mode)
1982  if (!empty($addtodatabase)) {
1983  $result = $this->insert_dirs($name, $dir);
1984  if ($result) { $err++;
1985  }
1986  }
1987  }
1988  }
1989 
1990  return $err;
1991  }
1992 
1993 
1994  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2003  public function insert_dirs($name, $dir)
2004  {
2005  // phpcs:enable
2006  global $conf;
2007 
2008  $err = 0;
2009 
2010  $sql = "SELECT count(*)";
2011  $sql .= " FROM ".MAIN_DB_PREFIX."const";
2012  $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'";
2013  $sql .= " AND entity = ".$conf->entity;
2014 
2015  dol_syslog(get_class($this)."::insert_dirs", LOG_DEBUG);
2016  $result = $this->db->query($sql);
2017  if ($result) {
2018  $row = $this->db->fetch_row($result);
2019 
2020  if ($row[0] == 0) {
2021  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)";
2022  $sql .= " VALUES (".$this->db->encrypt($name, 1).",'chaine',".$this->db->encrypt($dir, 1).",'Directory for module ".$this->name."','0',".$conf->entity.")";
2023 
2024  dol_syslog(get_class($this)."::insert_dirs", LOG_DEBUG);
2025  $this->db->query($sql);
2026  }
2027  } else {
2028  $this->error = $this->db->lasterror();
2029  $err++;
2030  }
2031 
2032  return $err;
2033  }
2034 
2035 
2036  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2042  public function delete_dirs()
2043  {
2044  // phpcs:enable
2045  global $conf;
2046 
2047  $err = 0;
2048 
2049  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
2050  $sql .= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->db->escape($this->const_name)."_DIR_%'";
2051  $sql .= " AND entity = ".$conf->entity;
2052 
2053  dol_syslog(get_class($this)."::delete_dirs", LOG_DEBUG);
2054  if (!$this->db->query($sql)) {
2055  $this->error = $this->db->lasterror();
2056  $err++;
2057  }
2058 
2059  return $err;
2060  }
2061 
2062  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2068  public function insert_module_parts()
2069  {
2070  // phpcs:enable
2071  global $conf;
2072 
2073  $error = 0;
2074 
2075  if (is_array($this->module_parts) && !empty($this->module_parts)) {
2076  foreach ($this->module_parts as $key => $value)
2077  {
2078  if (is_array($value) && count($value) == 0) { continue; // Discard empty arrays
2079  }
2080 
2081  $entity = $conf->entity; // Reset the current entity
2082  $newvalue = $value;
2083 
2084  // Serialize array parameters
2085  if (is_array($value)) {
2086  // Can defined other parameters
2087  // Example when $key='hooks', then $value is an array('data'=>array('hookcontext1','hookcontext2'), 'entity'=>X)
2088  if (isset($value['data']) && is_array($value['data'])) {
2089  $newvalue = json_encode($value['data']);
2090  if (isset($value['entity'])) { $entity = $value['entity'];
2091  }
2092  } elseif (isset($value['data']) && !is_array($value['data'])) {
2093  $newvalue = $value['data'];
2094  if (isset($value['entity'])) { $entity = $value['entity'];
2095  }
2096  } else // when hook is declared with syntax 'hook'=>array('hookcontext1','hookcontext2',...)
2097  {
2098  $newvalue = json_encode($value);
2099  }
2100  }
2101 
2102  $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (";
2103  $sql .= "name";
2104  $sql .= ", type";
2105  $sql .= ", value";
2106  $sql .= ", note";
2107  $sql .= ", visible";
2108  $sql .= ", entity";
2109  $sql .= ")";
2110  $sql .= " VALUES (";
2111  $sql .= $this->db->encrypt($this->const_name."_".strtoupper($key), 1);
2112  $sql .= ", 'chaine'";
2113  $sql .= ", ".$this->db->encrypt($newvalue, 1);
2114  $sql .= ", null";
2115  $sql .= ", '0'";
2116  $sql .= ", ".$entity;
2117  $sql .= ")";
2118 
2119  dol_syslog(get_class($this)."::insert_module_parts for key=".$this->const_name."_".strtoupper($key), LOG_DEBUG);
2120 
2121  $resql = $this->db->query($sql, 1);
2122  if (!$resql) {
2123  if ($this->db->lasterrno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') {
2124  $error++;
2125  $this->error = $this->db->lasterror();
2126  } else {
2127  dol_syslog(get_class($this)."::insert_module_parts for ".$this->const_name."_".strtoupper($key)." Record already exists.", LOG_WARNING);
2128  }
2129  }
2130  }
2131  }
2132  return $error;
2133  }
2134 
2135  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2141  public function delete_module_parts()
2142  {
2143  // phpcs:enable
2144  global $conf;
2145 
2146  $err = 0;
2147  $entity = $conf->entity;
2148 
2149  if (is_array($this->module_parts) && !empty($this->module_parts)) {
2150  foreach ($this->module_parts as $key => $value)
2151  {
2152  // If entity is defined
2153  if (is_array($value) && isset($value['entity'])) { $entity = $value['entity'];
2154  }
2155 
2156  $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
2157  $sql .= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->db->escape($this->const_name)."_".strtoupper($key)."'";
2158  $sql .= " AND entity = ".$entity;
2159 
2160  dol_syslog(get_class($this)."::delete_const_".$key."", LOG_DEBUG);
2161  if (!$this->db->query($sql)) {
2162  $this->error = $this->db->lasterror();
2163  $err++;
2164  }
2165  }
2166  }
2167  return $err;
2168  }
2169 
2180  public function init($options = '')
2181  {
2182  return $this->_init(array(), $options);
2183  }
2184 
2193  public function remove($options = '')
2194  {
2195  return $this->_remove(array(), $options);
2196  }
2197 
2198 
2206  public function getKanbanView($codeenabledisable = '', $codetoconfig = '')
2207  {
2208  global $conf, $langs;
2209 
2210  // Define imginfo
2211  $imginfo = "info";
2212  if ($this->isCoreOrExternalModule() == 'external')
2213  {
2214  $imginfo = "info_black";
2215  }
2216 
2217  $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($this)));
2218 
2219  $version = $this->getVersion(0);
2220  $versiontrans = '';
2221  if (preg_match('/development/i', $version)) $versiontrans .= 'warning';
2222  if (preg_match('/experimental/i', $version)) $versiontrans .= 'warning';
2223  if (preg_match('/deprecated/i', $version)) $versiontrans .= 'warning';
2224 
2225  print '
2226  <div class="box-flex-item info-box-module'.(empty($conf->global->$const_name) ? ' info-box-module-disabled' : '').($this->isCoreOrExternalModule() == 'external' ? ' info-box-module-external' : '').'">
2227  <div class="info-box info-box-sm info-box-module">
2228  <div class="info-box-icon'.(empty($conf->global->$const_name) ? '' : ' info-box-icon-module-enabled'.($versiontrans ? ' info-box-icon-module-warning' : '')).'">';
2229 
2230  $alttext = '';
2231  //if (is_array($objMod->need_dolibarr_version)) $alttext.=($alttext?' - ':'').'Dolibarr >= '.join('.',$objMod->need_dolibarr_version);
2232  //if (is_array($objMod->phpmin)) $alttext.=($alttext?' - ':'').'PHP >= '.join('.',$objMod->phpmin);
2233  if (!empty($this->picto))
2234  {
2235  if (preg_match('/^\//i', $this->picto)) print img_picto($alttext, $this->picto, 'class="inline-block valignmiddle"', 1);
2236  else print img_object($alttext, $this->picto, 'class="inline-block valignmiddle"');
2237  } else {
2238  print img_object($alttext, 'generic', 'class="inline-block valignmiddle"');
2239  }
2240 
2241  if ($this->isCoreOrExternalModule() == 'external' || preg_match('/development|experimental|deprecated/i', $version)) {
2242  print '<span class="info-box-icon-version'.($versiontrans ? ' '.$versiontrans : '').'" title="'.$langs->trans("Version").' '.$this->getVersion(1).'">';
2243  print $this->getVersion(1);
2244  print '</span>';
2245  }
2246 
2247  print '</div>
2248  <div class="info-box-content info-box-text-module'.(empty($conf->global->$const_name) ? '' : ' info-box-module-enabled'.($versiontrans ? ' info-box-content-warning' : '')).'">
2249  <span class="info-box-title">'.$this->getName().'</span>
2250  <span class="info-box-desc twolinesmax opacitymedium" title="'.dol_escape_htmltag($this->getDesc()).'">'.nl2br($this->getDesc()).'</span>';
2251 
2252  print '<div class="valignmiddle inline-block info-box-more">';
2253  //if ($versiontrans) print img_warning($langs->trans("Version").' '.$this->getVersion(1)).' ';
2254  print '<a class="valignmiddle inline-block" href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.$this->numero.'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto(($this->isCoreOrExternalModule() == 'external' ? $langs->trans("ExternalModule").' - ' : '').$langs->trans("ClickToShowDescription"), $imginfo).'</a>';
2255  print '</div><br>';
2256 
2257  print '<div class="valignmiddle inline-block info-box-actions">';
2258  print '<div class="valignmiddle inline-block info-box-setup">';
2259  print $codetoconfig;
2260  print '</div>';
2261  print '<div class="valignmiddle inline-block marginleftonly marginrightonly">';
2262  print $codeenabledisable;
2263  print '</div>';
2264  print '</div>';
2265 
2266  print '
2267  </div><!-- /.info-box-content -->
2268  </div><!-- /.info-box -->
2269  </div>';
2270  }
2271 }
getLastActivationInfo()
Gives the last author of activation.
_unactive()
Module deactivation.
Class DolibarrModules.
delete_dirs()
Removes directories.
insert_permissions($reinitadminperms=0, $force_entity=null, $notrigger=0)
Adds access rights.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
delete_permissions()
Removes access rights.
dol_now($mode= 'auto')
Return date for now.
Class to manage menu entries.
static getListOfPagesForBoxes()
Name of positions (See below)
Class to manage Dolibarr users.
Definition: user.class.php:44
getName()
Gives the translated module name if translation exists in admin.lang or into language files of module...
insert_boxes($option= '')
Adds boxes.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
insert_const()
Adds constants.
insert_dirs($name, $dir)
Adds directories definitions.
$conf db
API class for accounts.
Definition: inc.php:54
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.
_remove($array_sql, $options= '')
Disable function.
delete_const()
Removes constants tagged &#39;deleteonunactive&#39;.
delete_boxes()
Removes boxes.
getDescLongReadmeFound()
Return path of file if a README file was found.
insert_cronjobs()
Adds cronjobs.
getPublisher()
Gives the publisher name.
getChangeLog()
Gives the changelog.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
getLangFilesArray()
Gives module related language files list.
delete_tabs()
Removes tabs.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getVersion($translated=1)
Gives module version (translated if param $translated is on) For &#39;experimental&#39; modules, gives &#39;experimental&#39; translation For &#39;dolibarr&#39; modules, gives Dolibarr version.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
run_sql($sqlfile, $silent=1, $entity= '', $usesavepoint=1, $handler= '', $okerror= 'default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0)
Launch a sql file.
Definition: admin.lib.php:161
delete_menus()
Removes menu entries.
delete_cronjobs()
Removes boxes.
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:457
print $_SERVER["PHP_SELF"]
Edit parameters.
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.
print
Draft customers invoices.
Definition: index.php:89
init($options= '')
Function called when module is enabled.
_init($array_sql, $options= '')
Enables a module.
getDesc()
Gives the translated module description if translation exists in admin.lang or the default module des...
dolMd2Html($content, $parser= 'parsedown', $replaceimagepath=null)
Function to parse MD content into HTML.
Definition: parsemd.lib.php:32
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
insert_module_parts()
Adds generic parts.
create_dirs()
Creates directories.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
getKanbanView($codeenabledisable= '', $codetoconfig= '')
Return Kanban view of a module.
__construct($db)
Constructor.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
insert_menus()
Adds menu entries.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
_load_tables($reldir)
Create tables and keys required by module.