24require_once DOL_DOCUMENT_ROOT .
'/core/class/fields/commonselectfield.class.php';
35 public $emptyValues = array(array(),
'');
50 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
52 return $this->
printInputField($fieldInfos, $key, $value, $keyPrefix, $keySuffix, $moreCss, $moreAttrib);
67 public function printInputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
71 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
72 $moreAttrib = trim((
string) $moreAttrib);
73 if (empty($moreAttrib)) $moreAttrib =
' ' . $moreAttrib;
74 $htmlName = $keyPrefix . $key . $keySuffix;
75 $values = $this->
isEmptyValue($fieldInfos, $value) ? array() : (is_string($value) ? explode(
',', $value) : (is_array($value) ? $value: array($value)));
77 $optionsList = array();
78 $options = $this->
getOptions($fieldInfos, $key);
80 return self::$form->multiselectarray($htmlName, $options, $values, 0, 0, $moreCss, 0, 0, $moreAttrib,
'',
'', (
int) (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
95 public function printOutputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
98 $values = $this->
isEmptyValue($fieldInfos, $value) ? array() : (is_string($value) ? explode(
',', $value) : (is_array($value) ? $value: array($value)));
102 $options = $this->
getOptions($fieldInfos, $key);
104 foreach ($values as $val) {
105 $valueToPrint =
null;
106 foreach ($options as $optionKey => $optionInfos) {
107 if (((
string) $optionKey) == $val) {
108 $valueToPrint = $optionInfos[
'label'];
112 if (!isset($valueToPrint)) {
113 $langs->load(
"errors");
114 $valueToPrint = $langs->trans(
'ErrorRecordNotFound') .
' ( ' . $val .
' )';
116 $toPrint[] = $valueToPrint;
118 $out = self::$form->outputMultiValues($toPrint);
133 public function getInputCss($fieldInfos, $moreCss =
'', $defaultCss =
'')
135 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss :
'minwidth400');
150 $values = $this->
isEmptyValue($fieldInfos, $value) ? array() : (is_string($value) ? explode(
',', $value) : (is_array($value) ? $value: array($value)));
152 $result = parent::verifyFieldValue($fieldInfos, $key, $values);
153 if ($result && !$this->
isEmptyValue($fieldInfos, $values)) {
154 $options = $this->
getOptions($fieldInfos, $key);
155 foreach ($values as $val) {
156 $newVal = trim((
string) $val);
157 if (!isset($options[$newVal])) {
158 self::$validator->error = $langs->trans(
'RequireValidValue');
181 $htmlName = $keyPrefix . $key . $keySuffix;
182 $values =
GETPOST($htmlName,
'array');
198 public function getPostFieldValue($fieldInfos, $key, $defaultValue =
null, $keyPrefix =
'', $keySuffix =
'')
200 $htmlName = $keyPrefix . $key . $keySuffix;
202 if (GETPOSTISSET($htmlName)) {
203 $values =
GETPOST($htmlName,
'array');
204 if (is_array($values)) $values = implode(
',', $values);
206 $values = $defaultValue;
225 $htmlName = $keyPrefix . $key . $keySuffix;
227 if (GETPOSTISSET($htmlName)) {
228 $values =
GETPOST($htmlName,
'array');
230 $values = $defaultValue;
247 if (!$this->
isEmptyValue($fieldInfos, $value) && is_array($value)) {
248 $alias = $fieldInfos->sqlAlias ??
't.';
249 $field = $this->db->sanitize($alias . ($fieldInfos->nameInTable ?? $key));
251 $tmp =
"'" . implode(
"','", array_map(array($this->db,
'escape'), $value)) .
"'";
252 return " AND " . $field .
" IN (" . $this->db->sanitize($tmp, 1) .
")";
267 public function getOptions($fieldInfos, $key, $addEmptyValue =
false, $reload =
false)
269 return parent::getOptions($fieldInfos, $key, $addEmptyValue, $reload);
Class to checkbox field (multiselect)
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.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
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.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to common select 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.