24require_once DOL_DOCUMENT_ROOT .
'/core/class/fields/commonselectfield.class.php';
35 public $emptyValues = array(
'');
50 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
54 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
55 $moreAttrib = trim((
string) $moreAttrib);
56 if (empty($moreAttrib)) $moreAttrib =
' ' . $moreAttrib;
57 $htmlName = $keyPrefix . $key . $keySuffix;
58 $value = $this->
isEmptyValue($fieldInfos, $value) ? array() : (is_string($value) ? explode(
',', $value) : (is_array($value) ? $value: array($value)));
60 $optionsList = array();
61 $options = $this->
getOptions($fieldInfos, $key);
62 foreach ($options as $optionKey => $optionInfos) {
63 $options[$optionKey] = $optionInfos[
'label'];
66 return self::$form->multiselectarray($htmlName, $optionsList, $value, 0, 0, $moreCss, 0, 0, $moreAttrib,
'',
'', (
int) (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
81 public function printInputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
83 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
84 $moreAttrib = trim((
string) $moreAttrib);
85 if (empty($moreAttrib)) $moreAttrib =
' ' . $moreAttrib;
86 $htmlName = $keyPrefix . $key . $keySuffix;
88 $selectedValue = $this->
isEmptyValue($fieldInfos, $value) ?
'' : (string) $value;
90 $options = $this->
getOptions($fieldInfos, $key,
true);
92 foreach ($options as $optionKey => $optionInfos) {
93 $values[$optionKey] = $optionInfos[
'label'];
96 return self::$form->inputRadio($htmlName, $values, $selectedValue, $moreCss, $moreAttrib);
111 public function printOutputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
114 $value = (string) $value;
116 if ($fieldInfos->required && $this->isEmptyValue($fieldInfos, $value)) {
117 $langs->load(
'errors');
118 $value =
'<span class="opacitymedium">' . $langs->trans(
'ErrorNoValueForRadioType') .
'</span>';
120 $options = $this->
getOptions($fieldInfos, $key);
121 foreach ($options as $optionKey => $optionInfos) {
122 if (((
string) $optionKey) == $value) {
123 $value = $optionInfos[
'label'];
141 public function getInputCss($fieldInfos, $moreCss =
'', $defaultCss =
'')
143 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss :
'width25');
158 $value = (string) $value;
160 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
161 if ($result && !$this->
isEmptyValue($fieldInfos, $value)) {
162 $options = $this->
getOptions($fieldInfos, $key);
163 if (!isset($options[$value])) {
164 self::$validator->error = $langs->trans(
'RequireValidValue');
186 $htmlName = $keyPrefix . $key . $keySuffix;
187 $value =
GETPOST($htmlName,
'restricthtml');
188 $value = trim($value);
204 public function getPostFieldValue($fieldInfos, $key, $defaultValue =
null, $keyPrefix =
'', $keySuffix =
'')
206 $htmlName = $keyPrefix . $key . $keySuffix;
208 if (GETPOSTISSET($htmlName)) {
209 $value =
GETPOST($htmlName,
'alphanohtml');
211 $value = $defaultValue;
230 $htmlName = $keyPrefix . $key . $keySuffix;
232 if (GETPOSTISSET($htmlName)) {
233 $value =
GETPOST($htmlName,
'array');
235 $value = $defaultValue;
252 if (!$this->
isEmptyValue($fieldInfos, $value) && is_array($value)) {
253 $alias = $fieldInfos->sqlAlias ??
't.';
254 $field = $this->db->sanitize($alias . ($fieldInfos->nameInTable ?? $key));
256 $tmp =
"'" . implode(
"','", array_map(array($this->db,
'escape'), $value)) .
"'";
257 return " AND " . $field .
" IN (" . $this->db->sanitize($tmp, 1) .
")";
272 public function getOptions($fieldInfos, $key, $addEmptyValue =
false, $reload =
false)
274 return parent::getOptions($fieldInfos, $key, $addEmptyValue, $reload);
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to common select 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.
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.