24require_once DOL_DOCUMENT_ROOT .
'/core/class/fields/commonsellistfield.class.php';
35 public $emptyValues = array(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 $values = $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, $values, 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 =
'')
85 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
86 $moreAttrib = trim((
string) $moreAttrib);
87 if (empty($moreAttrib)) $moreAttrib =
' ' . $moreAttrib;
88 $htmlName = $keyPrefix . $key . $keySuffix;
89 $values = $this->
isEmptyValue($fieldInfos, $value) ? array() : (is_string($value) ? explode(
',', $value) : (is_array($value) ? $value: array($value)));
91 $options = $this->
getOptions($fieldInfos, $key);
93 return self::$form->multiselectarray($htmlName, $options, $values, 0, 0, $moreCss, 0, 0, $moreAttrib,
'',
'', (
int) (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
108 public function printOutputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
110 $values = $this->
isEmptyValue($fieldInfos, $value) ? array() : (is_string($value) ? explode(
',', $value) : (is_array($value) ? $value: array($value)));
114 $options = $this->
getOptions($fieldInfos, $key,
false,
false, $values);
116 $isCategory = $optionParams[
'tableName'] ==
'categorie' && !empty($optionParams[
'categoryType']);
119 foreach ($values as $val) {
121 $colorToPrint =
'bbb';
122 if (isset($options[$val])) {
123 $valueToPrint = $options[$val][
'label'];
126 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
129 $colorToPrint =
$c->color ?
$c->color :
'bbb';
130 $valueToPrint =
img_object(
'',
'category') .
' ' . $valueToPrint;
133 $valueToPrint = $val;
135 $toPrint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #' . $colorToPrint .
';">' . $valueToPrint .
'</li>';
137 if (!empty($toPrint)) {
138 $out =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
'', $toPrint) .
'</ul></div>';
154 public function getInputCss($fieldInfos, $moreCss =
'', $defaultCss =
'')
156 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss :
'minwidth400');
170 $values = $this->
isEmptyValue($fieldInfos, $value) ? array() : (is_string($value) ? explode(
',', $value) : (is_array($value) ? $value: array($value)));
172 $result = parent::verifyFieldValue($fieldInfos, $key, $values);
173 if ($result && !$this->
isEmptyValue($fieldInfos, $values)) {
175 if (!self::$validator->isInDb($values, $optionParams[
'tableName'], $optionParams[
'keyField'])) {
197 $htmlName = $keyPrefix . $key . $keySuffix;
198 $values =
GETPOST($htmlName,
'array');
214 public function getPostFieldValue($fieldInfos, $key, $defaultValue =
null, $keyPrefix =
'', $keySuffix =
'')
216 $htmlName = $keyPrefix . $key . $keySuffix;
218 if (GETPOSTISSET($htmlName)) {
219 $values =
GETPOST($htmlName,
'array');
220 if (is_array($values)) $values = implode(
',', $values);
222 $values = $defaultValue;
241 $htmlName = $keyPrefix . $key . $keySuffix;
243 if (GETPOSTISSET($htmlName)) {
244 $value =
GETPOST($htmlName,
'array');
246 $value = $defaultValue;
263 if (!empty($value) && is_array($value)) {
264 $alias = $fieldInfos->sqlAlias ??
't.';
265 $field = $this->db->sanitize($alias . ($fieldInfos->nameInTable ?? $key));
267 $tmp =
"'" . implode(
"','", array_map(array($this->db,
'escape'), $value)) .
"'";
268 return " AND " . $field .
" IN (" . $this->db->sanitize($tmp, 1) .
")";
284 public function getOptions($fieldInfos, $key, $addEmptyValue =
false, $reload =
false, $selectedValues = array())
286 return parent::getOptions($fieldInfos, $key, $addEmptyValue, $reload, $selectedValues);
Class to manage categories.
Class to chkbxlst field (multiselect)
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
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.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
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, $selectedValues=array())
Get list of options.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.