dolibarr 24.0.0-beta
radiofield.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 $htmlName = $keyPrefix . $key . $keySuffix;
92
93 $selectedValue = $this->isEmptyValue($fieldInfos, $value) ? '' : (string) $value;
94
95 $options = $this->getOptions($fieldInfos, $key, true);
96 $values = array();
97 foreach ($options as $optionKey => $optionInfos) {
98 $values[$optionKey] = $optionInfos['label'];
99 }
100
101 return self::$form->inputRadio($htmlName, $values, $selectedValue, $moreCss, $moreAttrib);
102 }
103
116 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
117 {
118 global $langs;
119 $value = (string) $value;
120
121 if ($fieldInfos->required && $this->isEmptyValue($fieldInfos, $value)) {
122 $langs->load('errors');
123 $value = '<span class="opacitymedium">' . $langs->trans('ErrorNoValueForRadioType') . '</span>';
124 } else {
125 $options = $this->getOptions($fieldInfos, $key);
126 foreach ($options as $optionKey => $optionInfos) {
127 if (((string) $optionKey) == $value) {
128 $value = $optionInfos['label'];
129 break;
130 }
131 }
132 }
133
134 return $value;
135 }
136
146 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
147 {
148 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss : 'width25');
149 }
150
160 public function verifyFieldValue($fieldInfos, $key, $value)
161 {
162 global $langs;
163 $value = (string) $value;
164
165 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
166 if ($result && !$this->isEmptyValue($fieldInfos, $value)) {
167 $options = $this->getOptions($fieldInfos, $key);
168 if (!isset($options[$value])) {
169 self::$validator->error = $langs->trans('RequireValidValue');
170 return false;
171 }
172
173 $result = true;
174 }
175
176 return $result;
177 }
178
189 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
190 {
191 $htmlName = $keyPrefix . $key . $keySuffix;
192 $value = GETPOST($htmlName, 'restricthtml');
193 $value = trim($value);
194
195 return $this->verifyFieldValue($fieldInfos, $key, $value);
196 }
197
209 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
210 {
211 $htmlName = $keyPrefix . $key . $keySuffix;
212
213 if (GETPOSTISSET($htmlName)) {
214 $value = GETPOST($htmlName, 'alphanohtml');
215 } else {
216 $value = $defaultValue;
217 }
218
219 return $value;
220 }
221
233 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
234 {
235 $htmlName = $keyPrefix . $key . $keySuffix;
236
237 if (GETPOSTISSET($htmlName)) {
238 $value = GETPOST($htmlName, 'array');
239 } else {
240 $value = $defaultValue;
241 }
242
243 return $value;
244 }
245
255 public function sqlFilterSearchField($fieldInfos, $key, $value)
256 {
257 if (!$this->isEmptyValue($fieldInfos, $value) && is_array($value)) {
258 $alias = $fieldInfos->sqlAlias ?? 't.';
259 $field = $this->db->sanitize($alias . ($fieldInfos->nameInTable ?? $key));
260
261 $sanitizedSqlIn = "'" . implode("','", array_map(array($this->db, 'escape'), $value)) . "'";
262 $sqlPartialCond = " AND " . $field . " IN (" . $sanitizedSqlIn . ")";
263 return $sqlPartialCond;
264 }
265
266 return '';
267 }
268
278 public function getOptions($fieldInfos, $key, $addEmptyValue = false, $reload = false)
279 {
280 return parent::getOptions($fieldInfos, $key, $addEmptyValue, $reload);
281 }
282}
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to common select field.
Class to radio field.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
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.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
getOptions($fieldInfos, $key, $addEmptyValue=false, $reload=false)
Get list of options.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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