dolibarr 24.0.0-beta
sellistfield.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/commonsellistfield.class.php';
26
27
32{
36 public $emptyValues = array('', 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
62 $optionsList = array();
63 $options = $this->getOptions($fieldInfos, $key);
64 foreach ($options as $optionKey => $optionInfos) {
65 $options[$optionKey] = $optionInfos['label'];
66 }
67
68 return self::$form->multiselectarray($htmlName, $optionsList, $value, 0, 0, $moreCss, 0, 0, $moreAttrib, '', '', (int) (!empty($conf->use_javascript_ajax) && !getDolGlobalString('MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
69 }
70
83 public function printInputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
84 {
85 global $conf;
86
87 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
88 $moreAttrib = trim((string) $moreAttrib);
89 if (empty($moreAttrib)) {
90 $moreAttrib = ' ' . $moreAttrib;
91 }
92 $placeHolder = $fieldInfos->inputPlaceholder;
93 if (!empty($placeHolder)) {
94 $placeHolder = ' placeholder="' . dolPrintHTMLForAttribute($placeHolder) . '"';
95 }
96 $autoFocus = $fieldInfos->inputAutofocus ? ' autofocus' : '';
97 $htmlName = $keyPrefix . $key . $keySuffix;
98 $selectedValue = is_null($value) || $this->isEmptyValue($fieldInfos, $value) ? '' : (string) $value;
99
100 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_EXTRAFIELDS_ENABLE_NEW_SELECT2')) {
101 $objectId = isset($fieldInfos->otherParams['objectId']) ? (int) $fieldInfos->otherParams['objectId'] : (isset($fieldInfos->object) && is_object($fieldInfos->object) ? $fieldInfos->object->id : 0);
102 $objectType = isset($fieldInfos->otherParams['objectType']) ? (int) $fieldInfos->otherParams['objectType'] : (isset($fieldInfos->object) && is_object($fieldInfos->object) ? $fieldInfos->object->element : '');
103 $printMode = empty($fieldInfos->mode) ? 'view' : $fieldInfos->mode;
104 $options = $this->getOptions($fieldInfos, $key, false, false, $selectedValue);
105
106 // TODO add dependency support (set dependencyvalue with dependency field value get by JS)
107 $ajaxData = array(
108 'objecttype' => $objectType,
109 'objectid' => $objectId,
110 'objectkey' => $key,
111 'mode' => $printMode,
112 'value' => $selectedValue,
113 'dependencyvalue' => '',
114 );
115
116 $out = self::$form->inputSelectAjax($htmlName, $options, $selectedValue, self::$ajaxUrl, $ajaxData, $moreCss, $moreAttrib . $placeHolder . $autoFocus);
117 } else {
118 $options = $this->getOptions($fieldInfos, $key, true);
119
120 $out = self::$form->selectarray($htmlName, $options, $selectedValue, 0, 0, 0, $moreAttrib . $placeHolder . $autoFocus, 0, 0, 0, '', $moreCss);
121 }
122
123 return $out;
124 }
125
138 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
139 {
140 $value = (string) $value;
141
142 if (!$this->isEmptyValue($fieldInfos, $value)) {
143 $options = $this->getOptions($fieldInfos, $key, false, false, $value);
144 if (isset($options[$value])) {
145 $out = $options[$value]['label'];
146
147 $optionParams = $this->getOptionsParams($fieldInfos->options);
148 if ($optionParams['tableName'] == 'categorie' && !empty($optionParams['categoryType'])) {
149 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
150 $c = new Categorie($this->db);
151 $c->fetch((int) $value);
152 $color = ' style="background: #' . ($c->color ? $c->color : 'bbb') . ';"';
153 $label = img_object('', 'category') . ' ' . $value;
154 $out = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr"><li class="select2-search-choice-dolibarr noborderoncategories"' . $color . '>' . $label . '</li></ul></div>';
155 }
156
157 $value = $out;
158 }
159 }
160
161 return $value;
162 }
163
173 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
174 {
175 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss : 'minwidth400');
176 }
177
187 public function verifyFieldValue($fieldInfos, $key, $value)
188 {
189 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
190 if ($result && !$this->isEmptyValue($fieldInfos, $value)) {
191 $optionParams = $this->getOptionsParams($fieldInfos->options);
192 if (!self::$validator->isInDb($value, $optionParams['tableName'], $optionParams['keyField'])) {
193 return false;
194 }
195
196 $result = true;
197 }
198
199 return $result;
200 }
201
212 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
213 {
214 $htmlName = $keyPrefix . $key . $keySuffix;
215 $value = GETPOST($htmlName, 'restricthtml');
216 $value = trim($value);
217
218 return $this->verifyFieldValue($fieldInfos, $key, $value);
219 }
220
232 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
233 {
234 $htmlName = $keyPrefix . $key . $keySuffix;
235
236 if (GETPOSTISSET($htmlName)) {
237 $value = GETPOST($htmlName, 'alphanohtml');
238 } else {
239 $value = $defaultValue;
240 }
241
242 return $value;
243 }
244
256 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
257 {
258 $htmlName = $keyPrefix . $key . $keySuffix;
259
260 if (GETPOSTISSET($htmlName)) {
261 $value = GETPOST($htmlName, 'array');
262 } else {
263 $value = $defaultValue;
264 }
265
266 return $value;
267 }
268
278 public function sqlFilterSearchField($fieldInfos, $key, $value)
279 {
280 if (!empty($value) && is_array($value)) {
281 $alias = $fieldInfos->sqlAlias ?? 't.';
282 $field = $this->db->sanitize($alias . ($fieldInfos->nameInTable ?? $key));
283
284 $sanitizedSqlIn = "'" . implode("','", array_map(array($this->db, 'escape'), $value)) . "'";
285 $sqlPartialCond = " AND " . $field . " IN (" . $sanitizedSqlIn . ")";
286 return $sqlPartialCond;
287 }
288
289 return '';
290 }
291
302 public function getOptions($fieldInfos, $key, $addEmptyValue = false, $reload = false, $selectedValues = array())
303 {
304 return parent::getOptions($fieldInfos, $key, $addEmptyValue, $reload, $selectedValues);
305 }
306}
$c
Definition line.php:334
Class to manage categories.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to common sellist field.
getOptionsParams($options)
Get all parameters in the options.
Class to sellist field.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
getOptions($fieldInfos, $key, $addEmptyValue=false, $reload=false, $selectedValues=array())
Get list of options.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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