dolibarr 24.0.0-beta
selectfield.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
3 * Copyright (C) 2026 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
25require_once DOL_DOCUMENT_ROOT . '/core/class/fields/commonselectfield.class.php';
26
27
32{
36 public $emptyValues = array('');
37
38
51 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
52 {
53 global $conf;
54
55 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
56 $moreAttrib = trim((string) $moreAttrib);
57 if (empty($moreAttrib)) {
58 $moreAttrib = ' ' . $moreAttrib;
59 }
60 $htmlName = $keyPrefix . $key . $keySuffix;
61 $value = $this->isEmptyValue($fieldInfos, $value) ? array() : (is_string($value) ? explode(',', $value) : (is_array($value) ? $value : array($value)));
62
63 $optionsList = array();
64 $options = $this->getOptions($fieldInfos, $key);
65 foreach ($options as $optionKey => $optionInfos) {
66 $options[$optionKey] = $optionInfos['label'];
67 }
68
69 return self::$form->multiselectarray($htmlName, $optionsList, $value, 0, 0, $moreCss, 0, 0, $moreAttrib, '', '', (int) (!empty($conf->use_javascript_ajax) && !getDolGlobalString('MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
70 }
71
84 public function printInputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
85 {
86 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
87 $moreAttrib = trim((string) $moreAttrib);
88 if (empty($moreAttrib)) {
89 $moreAttrib = ' ' . $moreAttrib;
90 }
91 $placeHolder = $fieldInfos->inputPlaceholder;
92 if (!empty($placeHolder)) {
93 $placeHolder = ' placeholder="' . dolPrintHTMLForAttribute($placeHolder) . '"';
94 }
95 $autoFocus = $fieldInfos->inputAutofocus ? ' autofocus' : '';
96 $htmlName = $keyPrefix . $key . $keySuffix;
97
98 $selectedValue = is_null($value) || $this->isEmptyValue($fieldInfos, $value) ? '' : (string) $value;
99
100 $options = $this->getOptions($fieldInfos, $key, true);
101
102 return self::$form->selectarray($htmlName, $options, $selectedValue, 0, 0, 0, $moreAttrib . $placeHolder . $autoFocus, 0, 0, 0, '', $moreCss);
103 }
104
117 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
118 {
119 $value = (string) $value;
120
121 if (!$this->isEmptyValue($fieldInfos, $value)) {
122 $options = $this->getOptions($fieldInfos, $key);
123 foreach ($options as $optionKey => $optionInfos) {
124 if (((string) $optionKey) == $value) {
125 $value = $optionInfos['label'];
126 break;
127 }
128 }
129 }
130
131 return $value;
132 }
133
143 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
144 {
145 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss : 'minwidth400');
146 }
147
157 public function verifyFieldValue($fieldInfos, $key, $value)
158 {
159 global $langs;
160 $value = (string) $value;
161
162 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
163 if ($result && !$this->isEmptyValue($fieldInfos, $value)) {
164 $options = $this->getOptions($fieldInfos, $key);
165 if (!isset($options[$value])) {
166 self::$validator->error = $langs->trans('RequireValidValue');
167 return false;
168 }
169
170 $result = true;
171 }
172
173 return $result;
174 }
175
186 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
187 {
188 $htmlName = $keyPrefix . $key . $keySuffix;
189 $value = GETPOST($htmlName, 'restricthtml');
190 $value = trim($value);
191
192 return $this->verifyFieldValue($fieldInfos, $key, $value);
193 }
194
206 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
207 {
208 $htmlName = $keyPrefix . $key . $keySuffix;
209
210 if (GETPOSTISSET($htmlName)) {
211 $value = GETPOST($htmlName, 'alphanohtml');
212 } else {
213 $value = $defaultValue;
214 }
215
216 return $this->isEmptyValue($fieldInfos, $value) ? '' : $value;
217 }
218
230 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
231 {
232 $htmlName = $keyPrefix . $key . $keySuffix;
233
234 if (GETPOSTISSET($htmlName)) {
235 $value = GETPOST($htmlName, 'array');
236 } else {
237 $value = $defaultValue;
238 }
239
240 return $value;
241 }
242
252 public function sqlFilterSearchField($fieldInfos, $key, $value)
253 {
254 if (!$this->isEmptyValue($fieldInfos, $value) && is_array($value)) {
255 $alias = $fieldInfos->sqlAlias ?? 't.';
256 $field = $this->db->sanitize($alias . ($fieldInfos->nameInTable ?? $key));
257
258 $sanitizedSqlIn = "'" . implode("','", array_map(array($this->db, 'escape'), $value)) . "'";
259 $sqlPartialCond = " AND " . $field . " IN (" . $sanitizedSqlIn . ")";
260 return $sqlPartialCond;
261 }
262
263 return '';
264 }
265
275 public function getOptions($fieldInfos, $key, $addEmptyValue = false, $reload = false)
276 {
277 return parent::getOptions($fieldInfos, $key, $addEmptyValue, $reload);
278 }
279}
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to common select field.
Class to select field.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
getOptions($fieldInfos, $key, $addEmptyValue=false, $reload=false)
Get list of options.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php