dolibarr  16.0.5
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  *
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 
22 require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
23 
24 
28 class FormEcm
29 {
33  public $db;
34 
38  public $error = '';
39 
40 
46  public function __construct($db)
47  {
48  $this->db = $db;
49  }
50 
51 
61  public function selectAllSections($selected = 0, $select_name = '', $module = 'ecm', $ids_to_ignore = array())
62  {
63  global $conf, $langs;
64  $langs->load("ecm");
65 
66  if ($select_name == '') {
67  $select_name = "catParent";
68  }
69  if (!is_array($ids_to_ignore)) {
70  $ids_to_ignore = array($ids_to_ignore);
71  }
72 
73  $cate_arbo = null;
74  if ($module == 'ecm') {
75  $cat = new EcmDirectory($this->db);
76  $cate_arbo = $cat->get_full_arbo();
77  } elseif ($module == 'medias') {
78  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
79  $path = $conf->medias->multidir_output[$conf->entity];
80  $cate_arbo = dol_dir_list($path, 'directories', 1, '', array('(\.meta|_preview.*\.png)$', '^\.'), 'relativename', SORT_ASC);
81  }
82 
83  $output = '<select class="flat minwidth100 maxwidth500" id="'.$select_name.'" name="'.$select_name.'">';
84  if (is_array($cate_arbo)) {
85  if (!count($cate_arbo)) {
86  $output .= '<option value="-1" disabled>'.$langs->trans("NoDirectoriesFound").'</option>';
87  } else {
88  $output .= '<option value="-1">&nbsp;</option>';
89  foreach ($cate_arbo as $key => $value) {
90  if (!in_array($cate_arbo[$key]['id'], $ids_to_ignore)) {
91  $valueforoption = empty($cate_arbo[$key]['id']) ? $cate_arbo[$key]['relativename'] : $cate_arbo[$key]['id'];
92  if ($selected && $valueforoption == $selected) {
93  $add = 'selected ';
94  } else {
95  $add = '';
96  }
97  $output .= '<option '.$add.'value="'.dol_escape_htmltag($valueforoption).'">'.(empty($cate_arbo[$key]['fulllabel']) ? $cate_arbo[$key]['relativename'] : $cate_arbo[$key]['fulllabel']).'</option>';
98  }
99  }
100  }
101  }
102  $output .= '</select>';
103  $output .= ajax_combobox($select_name);
104  $output .= "\n";
105  return $output;
106  }
107 }
FormEcm\selectAllSections
selectAllSections($selected=0, $select_name='', $module='ecm', $ids_to_ignore=array())
Return list of sections.
Definition: htmlecm.form.class.php:61
ajax_combobox
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:438
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
FormEcm\__construct
__construct($db)
Constructor.
Definition: htmlecm.form.class.php:46
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
FormEcm
Class to manage HTML component for ECM and generic filemanager.
Definition: htmlecm.form.class.php:28
EcmDirectory
Class to manage ECM directories.
Definition: ecmdirectory.class.php:28