dolibarr 21.0.0-beta
htmlecm.form.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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 */
18
23require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
24
25
30{
34 public $db;
35
39 public $error = '';
40
41
47 public function __construct($db)
48 {
49 $this->db = $db;
50 }
51
52
62 public function selectAllSections($selected = 0, $select_name = '', $module = 'ecm', $ids_to_ignore = array())
63 {
64 global $conf, $langs;
65 $langs->load("ecm");
66
67 if ($select_name == '') {
68 $select_name = "catParent";
69 }
70 if (!is_array($ids_to_ignore)) {
71 $ids_to_ignore = array($ids_to_ignore);
72 }
73
74 $cate_arbo = null;
75 if ($module == 'ecm') {
76 $cat = new EcmDirectory($this->db);
77 $cate_arbo = $cat->get_full_arbo();
78 } elseif ($module == 'medias') {
79 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
80 $path = $conf->medias->multidir_output[$conf->entity];
81 $cate_arbo = dol_dir_list($path, 'directories', 1, '', array('(\.meta|_preview.*\.png)$', '^\.'), 'relativename', SORT_ASC);
82 }
83
84 $output = '<select class="flat minwidth100 maxwidth500" id="'.$select_name.'" name="'.$select_name.'">';
85 if (is_array($cate_arbo)) {
86 if (!count($cate_arbo)) {
87 $output .= '<option value="-1" disabled>'.$langs->trans("NoDirectoriesFound").'</option>';
88 } else {
89 $output .= '<option value="-1">&nbsp;</option>';
90 foreach ($cate_arbo as $key => $value) {
91 if (!in_array($cate_arbo[$key]['id'], $ids_to_ignore)) {
92 $valueforoption = empty($cate_arbo[$key]['id']) ? $cate_arbo[$key]['relativename'] : $cate_arbo[$key]['id'];
93 if ($selected && $valueforoption == $selected) {
94 $add = 'selected ';
95 } else {
96 $add = '';
97 }
98 $output .= '<option '.$add.'value="'.dol_escape_htmltag($valueforoption).'">'.(empty($cate_arbo[$key]['fulllabel']) ? $cate_arbo[$key]['relativename'] : $cate_arbo[$key]['fulllabel']).'</option>';
99 }
100 }
101 }
102 }
103 $output .= '</select>';
104 $output .= ajax_combobox($select_name);
105 $output .= "\n";
106 return $output;
107 }
108}
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:459
Class to manage ECM directories.
Class to manage HTML component for ECM and generic filemanager.
__construct($db)
Constructor.
selectAllSections($selected=0, $select_name='', $module='ecm', $ids_to_ignore=array())
Return list of sections.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79