modules_printing.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /*
  3. * Copyright (C) 2014-2018 Frederic France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/modules/printing/modules_printing.php
  21. * \ingroup printing
  22. * \brief File with parent class of printing modules
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  26. /**
  27. * Parent class of emailing target selectors modules
  28. */
  29. class PrintingDriver
  30. {
  31. /**
  32. * @var DoliDB Database handler.
  33. */
  34. public $db;
  35. /**
  36. * @var string Error code (or message)
  37. */
  38. public $error = '';
  39. /**
  40. * Constructor
  41. *
  42. * @param DoliDB $db Database handler
  43. */
  44. public function __construct($db)
  45. {
  46. $this->db = $db;
  47. }
  48. /**
  49. * Return list of printing driver
  50. *
  51. * @param DoliDB $db Database handler
  52. * @param integer $maxfilenamelength Max length of value to show
  53. * @return array List of drivers
  54. */
  55. public static function listDrivers($db, $maxfilenamelength = 0)
  56. {
  57. global $conf;
  58. $type = 'printing';
  59. $list = array();
  60. $listoffiles = array();
  61. if (!empty($conf->modules_parts['printing'])) {
  62. $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
  63. } else {
  64. $dirmodels = array('/core/modules/printing/');
  65. }
  66. foreach ($dirmodels as $dir) {
  67. $tmpfiles = dol_dir_list(dol_buildpath($dir, 0), 'all', 0, '\.modules.php', '', 'name', SORT_ASC, 0);
  68. if (!empty($tmpfiles)) {
  69. $listoffiles = array_merge($listoffiles, $tmpfiles);
  70. }
  71. }
  72. foreach ($listoffiles as $record) {
  73. $list[$record['fullname']] = str_replace('.modules.php', '', $record['name']);
  74. }
  75. return $list;
  76. }
  77. /**
  78. * Return description of Printing Module
  79. *
  80. * @return string Return translation of key PrintingModuleDescXXX where XXX is module name, or $this->desc if not exists
  81. */
  82. public function getDesc()
  83. {
  84. global $langs;
  85. $langs->load("printing");
  86. $transstring = "PrintingModuleDesc".$this->name;
  87. if ($langs->trans($transstring) != $transstring) {
  88. return $langs->trans($transstring);
  89. } else {
  90. return $this->desc;
  91. }
  92. }
  93. }