htmlecm.form.class.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /* Copyright (C) 2008-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/ecm/class/htmlecm.form.class.php
  19. * \brief File of class to manage HTML component for ECM and generic filemanager
  20. */
  21. require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
  22. /**
  23. * Class to manage HTML component for ECM and generic filemanager
  24. */
  25. class FormEcm
  26. {
  27. /**
  28. * @var DoliDB Database handler.
  29. */
  30. public $db;
  31. /**
  32. * @var string Error code (or message)
  33. */
  34. public $error = '';
  35. /**
  36. * Constructor
  37. *
  38. * @param DoliDB $db Database handler
  39. */
  40. public function __construct($db)
  41. {
  42. $this->db = $db;
  43. }
  44. /**
  45. * Return list of sections
  46. *
  47. * @param int $selected Id of preselected section
  48. * @param string $select_name Name of HTML select component
  49. * @param string $module Module ('ecm', 'medias', ...)
  50. * @param array $ids_to_ignore Array of id to ignore
  51. * @return string String with HTML select
  52. */
  53. public function selectAllSections($selected = 0, $select_name = '', $module = 'ecm', $ids_to_ignore = array())
  54. {
  55. global $conf, $langs;
  56. $langs->load("ecm");
  57. if ($select_name == '') {
  58. $select_name = "catParent";
  59. }
  60. if (!is_array($ids_to_ignore)) {
  61. $ids_to_ignore = array($ids_to_ignore);
  62. }
  63. $cate_arbo = null;
  64. if ($module == 'ecm') {
  65. $cat = new EcmDirectory($this->db);
  66. $cate_arbo = $cat->get_full_arbo();
  67. } elseif ($module == 'medias') {
  68. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  69. $path = $conf->medias->multidir_output[$conf->entity];
  70. $cate_arbo = dol_dir_list($path, 'directories', 1, '', array('(\.meta|_preview.*\.png)$', '^\.'), 'relativename', SORT_ASC);
  71. }
  72. $output = '<select class="flat minwidth100 maxwidth500" id="'.$select_name.'" name="'.$select_name.'">';
  73. if (is_array($cate_arbo)) {
  74. if (!count($cate_arbo)) {
  75. $output .= '<option value="-1" disabled>'.$langs->trans("NoDirectoriesFound").'</option>';
  76. } else {
  77. $output .= '<option value="-1">&nbsp;</option>';
  78. foreach ($cate_arbo as $key => $value) {
  79. if (!in_array($cate_arbo[$key]['id'], $ids_to_ignore)) {
  80. $valueforoption = empty($cate_arbo[$key]['id']) ? $cate_arbo[$key]['relativename'] : $cate_arbo[$key]['id'];
  81. if ($selected && $valueforoption == $selected) {
  82. $add = 'selected ';
  83. } else {
  84. $add = '';
  85. }
  86. $output .= '<option '.$add.'value="'.dol_escape_htmltag($valueforoption).'">'.(empty($cate_arbo[$key]['fulllabel']) ? $cate_arbo[$key]['relativename'] : $cate_arbo[$key]['fulllabel']).'</option>';
  87. }
  88. }
  89. }
  90. }
  91. $output .= '</select>';
  92. $output .= ajax_combobox($select_name);
  93. $output .= "\n";
  94. return $output;
  95. }
  96. }