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;
59 $optionsList = array();
60 $options = $this->
getOptions($fieldInfos, $key);
61 foreach ($options as $optionKey => $optionInfos) {
62 $options[$optionKey] = $optionInfos[
'label'];
65 return self::$form->multiselectarray($htmlName, $optionsList, $value, 0, 0, $moreCss, 0, 0, $moreAttrib,
'',
'', (
int) (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
80 public function printInputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
84 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
85 $moreAttrib = trim((
string) $moreAttrib);
86 if (empty($moreAttrib)) $moreAttrib =
' ' . $moreAttrib;
87 $placeHolder = $fieldInfos->inputPlaceholder;
89 $autoFocus = $fieldInfos->inputAutofocus ?
' autofocus' :
'';
90 $htmlName = $keyPrefix . $key . $keySuffix;
91 $selectedValue = is_null($value) || $this->
isEmptyValue($fieldInfos, $value) ?
'' : (string) $value;
93 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'MAIN_EXTRAFIELDS_ENABLE_NEW_SELECT2')) {
94 $objectId = isset($fieldInfos->otherParams[
'objectId']) ? (int) $fieldInfos->otherParams[
'objectId'] : (isset($fieldInfos->object) && is_object($fieldInfos->object) ? $fieldInfos->object->id : 0);
95 $objectType = isset($fieldInfos->otherParams[
'objectType']) ? (int) $fieldInfos->otherParams[
'objectType'] : (isset($fieldInfos->object) && is_object($fieldInfos->object) ? $fieldInfos->object->element :
'');
96 $printMode = empty($fieldInfos->mode) ?
'view' : $fieldInfos->mode;
97 $options = $this->
getOptions($fieldInfos, $key,
false,
false, $selectedValue);
101 'objecttype' => $objectType,
102 'objectid' => $objectId,
104 'mode' => $printMode,
105 'value' => $selectedValue,
106 'dependencyvalue' =>
'',
109 $out = self::$form->inputSelectAjax($htmlName, $options, $selectedValue, self::$ajaxUrl, $ajaxData, $moreCss, $moreAttrib . $placeHolder . $autoFocus);
111 $options = $this->
getOptions($fieldInfos, $key,
true);
113 $out = self::$form->selectarray($htmlName, $options, $selectedValue, 0, 0, 0, $moreAttrib . $placeHolder . $autoFocus, 0, 0, 0,
'', $moreCss);
131 public function printOutputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
133 $value = (string) $value;
136 $options = $this->
getOptions($fieldInfos, $key,
false,
false, $value);
137 if (isset($options[$value])) {
138 $out = $options[$value][
'label'];
141 if ($optionParams[
'tableName'] ==
'categorie' && !empty($optionParams[
'categoryType'])) {
142 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
144 $c->fetch((
int) $value);
145 $color =
' style="background: #' . (
$c->color ?
$c->color :
'bbb') .
';"';
146 $label =
img_object(
'',
'category') .
' ' . $value;
147 $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>';
166 public function getInputCss($fieldInfos, $moreCss =
'', $defaultCss =
'')
168 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss :
'minwidth400');
182 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
183 if ($result && !$this->
isEmptyValue($fieldInfos, $value)) {
185 if (!self::$validator->isInDb($value, $optionParams[
'tableName'], $optionParams[
'keyField'])) {
207 $htmlName = $keyPrefix . $key . $keySuffix;
208 $value =
GETPOST($htmlName,
'restricthtml');
209 $value = trim($value);
225 public function getPostFieldValue($fieldInfos, $key, $defaultValue =
null, $keyPrefix =
'', $keySuffix =
'')
227 $htmlName = $keyPrefix . $key . $keySuffix;
229 if (GETPOSTISSET($htmlName)) {
230 $value =
GETPOST($htmlName,
'alphanohtml');
232 $value = $defaultValue;
251 $htmlName = $keyPrefix . $key . $keySuffix;
253 if (GETPOSTISSET($htmlName)) {
254 $value =
GETPOST($htmlName,
'array');
256 $value = $defaultValue;
273 if (!empty($value) && is_array($value)) {
274 $alias = $fieldInfos->sqlAlias ??
't.';
275 $field = $this->db->sanitize($alias . ($fieldInfos->nameInTable ?? $key));
277 $tmp =
"'" . implode(
"','", array_map(array($this->db,
'escape'), $value)) .
"'";
278 return " AND " . $field .
" IN (" . $this->db->sanitize($tmp, 1) .
")";
294 public function getOptions($fieldInfos, $key, $addEmptyValue =
false, $reload =
false, $selectedValues = array())
296 return parent::getOptions($fieldInfos, $key, $addEmptyValue, $reload, $selectedValues);
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.
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.
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.