1140 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'',
$object = 0, $extrafieldsobjectkey =
'', $mode = 0)
1142 global $conf, $langs, $form, $hookmanager;
1144 if (!is_object($form)) {
1145 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
1146 $form =
new Form($this->db);
1150 $morecss =
'maxwidth125';
1153 $parameters = array(
1156 'moreparam' => $moreparam,
1157 'keysuffix' => $keysuffix,
1158 'keyprefix' => $keyprefix,
1159 'morecss' => $morecss,
1161 'extrafieldsobjectkey' => $extrafieldsobjectkey,
1166 $reshook = $hookmanager->executeHooks(
'showInputExtraField', $parameters, $this, $action);
1168 return $hookmanager->resPrint;
1175 if (!preg_match(
'/options_$/', $keyprefix)) {
1176 $keyprefix .=
'options_';
1179 if (empty($extrafieldsobjectkey)) {
1180 dol_syslog(get_class($this).
'::showInputField extrafieldsobjectkey required', LOG_ERR);
1181 return 'BadValueForParamExtraFieldsObjectKey';
1184 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1185 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1186 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1187 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1188 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1189 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1190 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1191 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1192 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
1193 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1194 $list = (string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
1195 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
1196 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1197 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
1198 $hidden = (empty($list) ? 1 : 0);
1204 if (!preg_match(
'/^search_/', $keyprefix)) {
1205 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
1213 if (empty($morecss)) {
1215 if ($type ==
'date') {
1216 $morecss =
'minwidth100imp';
1217 } elseif ($type ==
'datetime' || $type ==
'datetimegmt' || $type ==
'link') {
1218 $morecss =
'minwidth200imp';
1219 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
1220 $morecss =
'maxwidth75';
1221 } elseif ($type ==
'password') {
1222 $morecss =
'maxwidth100';
1223 } elseif ($type ==
'url') {
1224 $morecss =
'minwidth400';
1225 } elseif ($type ==
'boolean') {
1227 } elseif ($type ==
'radio') {
1228 $morecss =
'width25';
1230 if (empty($size) || round((
float) $size) < 12) {
1231 $morecss =
'minwidth100';
1232 } elseif (round((
float) $size) <= 48) {
1233 $morecss =
'minwidth200';
1235 $morecss =
'minwidth400';
1239 if (!empty($this->attributes[$extrafieldsobjectkey][
'css'][$key])) {
1240 $morecss = $this->attributes[$extrafieldsobjectkey][
'css'][$key];
1244 if (in_array($type, array(
'date'))) {
1245 $tmp = explode(
',', $size);
1250 if (!$required && $value ==
'') {
1257 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1258 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1260 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1261 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"));
1262 $out .=
'</div><div class="nowrap">';
1263 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"));
1264 $out .=
'</div></div>';
1268 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required ? 0 : 2,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1270 } elseif (in_array($type, array(
'datetime',
'datetimegmt'))) {
1271 $tmp = explode(
',', $size);
1276 if (!$required && $value ==
'') {
1283 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1284 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1286 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1287 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"),
'tzuserrel');
1288 $out .=
'</div><div class="nowrap">';
1289 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
1290 $out .=
'</div></div>';
1294 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required ? 0 : 2,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1296 } elseif (in_array($type, array(
'int',
'integer'))) {
1297 $tmp = explode(
',', $size);
1299 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" maxlength="'.$newsize.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
1300 } elseif (preg_match(
'/varchar/', $type)) {
1301 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" maxlength="'.$size.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
1302 } elseif (in_array($type, array(
'email',
'mail',
'ip',
'phone',
'url'))) {
1303 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1304 } elseif ($type ==
'icon') {
1310 $out .=
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat '.$morecss.
' maxwidthonsmartphone"';
1311 $out .=
' name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1314 $options =
"{ title: '<b>".$langs->trans(
"IconFieldSelector").
"</b>', placement: 'right', showFooter: false, templates: {";
1315 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
1316 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
1319 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
1320 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"".$langs->trans(
"TypeToFilter").
"\" />',";
1321 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
1322 $options .=
" <div class=\"arrow\" ></div>";
1323 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
1324 $options .=
" <div class=\"popover-content \" ></div>";
1325 $options .=
"</div>'}}";
1326 $out .=
"$('#".$keyprefix.$key.$keysuffix.
"').iconpicker(".$options.
");";
1327 $out .=
'</script>';
1329 } elseif ($type ==
'text') {
1330 if (!preg_match(
'/search_/', $keyprefix)) {
1331 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1332 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1333 $out = (string) $doleditor->Create(1);
1335 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1337 } elseif ($type ==
'html') {
1338 if (!preg_match(
'/search_/', $keyprefix)) {
1339 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1340 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
1341 $out = (string) $doleditor->Create(1);
1343 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1345 } elseif ($type ==
'boolean') {
1348 if (!empty($value)) {
1349 $checked =
' checked value="1" ';
1351 $checked =
' value="1" ';
1353 $out =
'<input type="checkbox" class="flat valignmiddle'.($morecss ?
' '.$morecss :
'').
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1355 $out = $form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1, 1,
'width75 yesno');
1357 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_boolean" value="1">';
1358 } elseif ($type ==
'price') {
1359 if (!empty($value)) {
1360 $value =
price($value);
1362 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone right" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
' placeholder="'.$langs->getCurrencySymbol($conf->currency).
'">';
1363 } elseif ($type ==
'pricecy') {
1364 $currency = $conf->currency;
1365 if (!empty($value)) {
1367 $pricetmp = explode(
':', $value);
1368 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
1369 $value =
price($pricetmp[0]);
1371 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1372 $out .= $form->selectCurrency($currency, $keyprefix.$key.$keysuffix.
'currency_id');
1373 } elseif ($type ==
'duration') {
1374 $value = intval($value);
1375 $out = $form->select_duration($keyprefix . $key, $value, 0,
'text', 0, 1);
1376 } elseif ($type ==
'double') {
1377 if (!empty($value)) {
1378 $value =
price($value);
1380 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1381 } elseif ($type ==
'select') {
1385 foreach ($param[
'options'] as $okey => $val) {
1386 if ((
string) $okey ==
'') {
1390 $valarray = explode(
'|', $val);
1391 $val = $valarray[0];
1393 if ($langfile && $val) {
1394 $options[$okey] = $langs->trans($val);
1396 $options[$okey] = $val;
1399 $selected = array();
1400 if (!is_array($value)) {
1401 $selected = explode(
',', $value);
1404 $out .= $form->multiselectarray($keyprefix.$key.$keysuffix, $options, $selected, 0, 0, $morecss, 0, 0,
'',
'',
'', (
int) (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
1406 if (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')) {
1407 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1408 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1411 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1412 $out .=
'<option value="0"> </option>';
1413 foreach ($param[
'options'] as $key2 => $val2) {
1414 if ((
string) $key2 ==
'') {
1417 $valarray = explode(
'|', $val2);
1418 $val2 = $valarray[0];
1420 if (!empty($valarray[1])) {
1421 $parent = $valarray[1];
1423 $out .=
'<option value="'.$key2.
'"';
1424 $out .= (((string) $value == (
string) $key2) ?
' selected' :
'');
1425 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1427 if ($langfile && $val2) {
1428 $out .= $langs->trans($val2);
1432 $out .=
'</option>';
1434 $out .=
'</select>';
1436 } elseif ($type ==
'sellist') {
1438 if (!empty($conf->use_javascript_ajax)) {
1442 $(document).ready(function () {
1443 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1445 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1447 delay: 250, // wait 250 milliseconds before triggering the request
1448 data: function (params) {
1450 search: params.term,
1451 page: params.page || 1,
1452 objecttype: '".$extrafieldsobjectkey.
"',
1454 objectkey: '".$key.
"',
1464 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1465 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1466 $out .=
'</select>';
1468 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1469 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1474 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1475 if (is_array($param[
'options'])) {
1478 $tmpparamoptions = array_keys($param[
'options']);
1479 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1481 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1493 if (! empty($InfoFieldList[4])) {
1495 $parenthesisopen = 0;
1496 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1497 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1500 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1505 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1506 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1508 $InfoFieldList[4] = $tmpbefore;
1509 if ($tmpafter !==
'') {
1510 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1515 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1516 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1526 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1528 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1529 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1530 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1532 $keyList = $InfoFieldList[2].
' as rowid';
1535 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1536 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1537 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1538 $keyList .=
', main.'.$parentField;
1540 $keyList .=
', '.$parentField;
1544 $filter_categorie =
false;
1545 if (count($InfoFieldList) > 5) {
1546 if ($InfoFieldList[0] ==
'categorie') {
1547 $filter_categorie =
true;
1551 if (!$filter_categorie) {
1552 $fields_label = isset($InfoFieldList[1]) ? explode(
'|', $InfoFieldList[1]) : array();
1553 if (!empty($fields_label)) {
1555 $keyList .= implode(
', ', $fields_label);
1561 $sql =
"SELECT ".$keyList;
1562 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1565 if (!empty($InfoFieldList[4])) {
1567 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1568 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string) $conf->entity, $InfoFieldList[4]);
1572 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1573 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1577 if (strpos($InfoFieldList[4],
'$MODE$') !==
false) {
1578 $InfoFieldList[4] = str_replace(
'$MODE$', preg_replace(
'/[^a-z0-9_]/i',
'', (
string) $mode), $InfoFieldList[4]);
1582 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1583 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1584 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1588 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1589 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1591 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1592 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1594 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1600 preg_match_all(
'/\$(.*?)\$/', $InfoFieldList[4], $tags);
1601 foreach ($tags[0] as $keytag => $valuetag) {
1602 $property = preg_replace(
'/[^a-z0-9_]/',
'', strtolower($tags[1][$keytag]));
1603 if (strpos($InfoFieldList[4], $valuetag) !==
false && property_exists(
$object, $property) && !empty(
$object->$property)) {
1604 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->$property, $InfoFieldList[4]);
1606 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1613 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1614 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1615 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1621 $sqlwhere .=
' WHERE 1=1';
1638 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1639 $sqlwhere .=
' AND entity = '.((int) $conf->entity);
1643 $sql .= $this->db->order(implode(
', ', $fields_label));
1644 $sql .=
' LIMIT ' .
getDolGlobalInt(
'MAIN_EXTRAFIELDS_LIMIT_SELLIST_SQL', 1000);
1647 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1648 $resql = $this->db->query($sql);
1650 $out .=
'<option value="0"> </option>';
1651 $num = $this->db->num_rows($resql);
1655 $obj = $this->db->fetch_object($resql);
1657 $nameFields = $InfoFieldList[1];
1659 $nameFields = preg_replace(
'/[a-z_]+\([^\)]*\) as ([\w]+)/i',
'\1', $nameFields);
1661 $nameFields = preg_replace(
'/[^0-9a-z_\.\|]/i',
'', $nameFields);
1665 $fields_label = explode(
'|', $nameFields);
1666 if (is_array($fields_label) && count($fields_label) > 1) {
1668 foreach ($fields_label as $field_toshow) {
1669 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
1670 $labeltoshow .= $obj->$field_toshow.
' ';
1673 $labeltoshow = $obj->$nameFields;
1676 if ($value == $obj->rowid) {
1678 foreach ($fields_label as $field_toshow) {
1679 $translabel = $langs->trans($obj->$field_toshow);
1680 $labeltoshow = $translabel.
' ';
1683 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1686 $translabel = $langs->trans($obj->$nameFields);
1687 $labeltoshow = $translabel;
1689 if (empty($labeltoshow)) {
1690 $labeltoshow =
'(not defined)';
1693 if (!empty($InfoFieldList[3]) && $parentField) {
1695 $parentField = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $parentField);
1696 $parent = $parentName.
':'.$obj->{$parentField};
1699 $out .=
'<option value="'.$obj->rowid.
'"';
1700 $out .= ($value == $obj->rowid ?
' selected' :
'');
1701 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1702 $out .=
'>'.$labeltoshow.
'</option>';
1707 $this->db->free($resql);
1709 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1712 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1713 $categcode = $InfoFieldList[5];
1714 if (is_numeric($categcode)) {
1715 $tmpcategory =
new Categorie($this->db);
1716 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
1717 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
1720 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1721 $out .=
'<option value="0"> </option>';
1722 if (is_array($data)) {
1723 foreach ($data as $data_key => $data_value) {
1724 $out .=
'<option value="'.$data_key.
'"';
1725 $out .= ($value == $data_key ?
' selected' :
'');
1726 $out .=
'>'.$data_value.
'</option>';
1731 $out .=
'</select>';
1733 } elseif ($type ==
'checkbox') {
1734 $value_arr = $value;
1735 if (!is_array($value)) {
1736 $value_arr = explode(
',', $value);
1738 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0,
'', 0,
'100%');
1739 } elseif ($type ==
'radio') {
1741 foreach ($param[
'options'] as $keyopt => $val) {
1742 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1743 $out .=
' value="'.$keyopt.
'"';
1744 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1745 $out .= ($value == $keyopt ?
'checked' :
'');
1746 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1748 } elseif ($type ==
'chkbxlst') {
1749 if (is_array($value)) {
1750 $value_arr = $value;
1752 $value_arr = explode(
',', $value);
1755 if (is_array($param[
'options'])) {
1756 $tmpparamoptions = array_keys($param[
'options']);
1757 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1759 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1780 if (! empty($InfoFieldList[4])) {
1782 $parenthesisopen = 0;
1783 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1784 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1787 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1792 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1793 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1795 $InfoFieldList[4] = $tmpbefore;
1796 if ($tmpafter !==
'') {
1797 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1802 if (preg_match(
'/^\(?([a-z0-9_]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1803 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1814 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1816 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1817 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1818 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1820 $keyList = $InfoFieldList[2].
' as rowid';
1823 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1824 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1825 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1826 $keyList .=
', main.'.$parentField;
1828 $keyList .=
', '.$parentField;
1832 $InfoFieldList[5] = (string) ($InfoFieldList[5]??
'');
1834 $filter_categorie =
false;
1835 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
1836 if ($InfoFieldList[0] ==
'categorie') {
1837 $filter_categorie =
true;
1839 $filter_categorie =
false;
1844 if (!$filter_categorie) {
1845 $fields_label = explode(
'|', $InfoFieldList[1]);
1846 if (is_array($fields_label)) {
1848 $keyList .= implode(
', ', $fields_label);
1852 $sql =
"SELECT ".$keyList;
1853 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1856 if (!empty($InfoFieldList[4])) {
1858 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1859 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string) $conf->entity, $InfoFieldList[4]);
1862 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1863 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1867 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1868 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1869 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1873 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1874 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1876 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1877 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1879 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1884 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1885 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1886 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1892 $sqlwhere .=
' WHERE 1=1';
1896 if ($InfoFieldList[5] !=
'') {
1898 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1899 $tmpcategory =
new Categorie($this->db);
1900 $tablesuffixcategory = empty($tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]];
1901 $fksuffixcategory = empty($tmpcategory->MAP_CAT_FK[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_FK[$InfoFieldList[5]];
1903 $sqlwhere .=
' AND EXISTS (SELECT fk_categorie as categid FROM '.MAIN_DB_PREFIX.
'categorie_'.$this->db->sanitize($tablesuffixcategory);
1904 $sqlwhere .=
' WHERE fk_categorie IN ('.$this->db->sanitize($InfoFieldList[6]).
')';
1905 $sqlwhere .=
' AND fk_'.$this->db->sanitize($fksuffixcategory).
' = rowid)';
1923 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1924 $sqlwhere .=
" AND entity = ".((int) $conf->entity);
1930 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1932 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
1934 $resql = $this->db->query($sql);
1936 $num = $this->db->num_rows($resql);
1943 $obj = $this->db->fetch_object($resql);
1947 $fields_label = explode(
'|', $InfoFieldList[1]);
1948 if (is_array($fields_label)) {
1950 foreach ($fields_label as $field_toshow) {
1951 $labeltoshow .= $obj->$field_toshow.
' ';
1954 $labeltoshow = $obj->{$InfoFieldList[1]};
1956 $labeltoshow =
dol_trunc($labeltoshow, 45);
1958 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1960 foreach ($fields_label as $field_toshow) {
1961 $translabel = $langs->trans($obj->$field_toshow);
1962 if ($translabel != $obj->$field_toshow) {
1963 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
1965 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
1968 $data[$obj->rowid] = $labeltoshow;
1971 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1972 if ($translabel != $obj->{$InfoFieldList[1]}) {
1973 $labeltoshow =
dol_trunc($translabel, 18);
1975 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
1978 if (empty($labeltoshow)) {
1979 $labeltoshow =
'(not defined)';
1982 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1983 $data[$obj->rowid] = $labeltoshow;
1986 if (!empty($InfoFieldList[3]) && $parentField) {
1987 $parent = $parentName.
':'.$obj->{$parentField};
1990 $data[$obj->rowid] = $labeltoshow;
1995 $this->db->free($resql);
1997 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
1999 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
2002 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2003 $categcode = $InfoFieldList[5];
2004 if (is_numeric($categcode)) {
2005 $tmpcategory =
new Categorie($this->db);
2006 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
2007 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
2010 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
2011 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2014 } elseif ($type ==
'link') {
2015 $param_list = array_keys($param[
'options']);
2022 $showempty = (($required && $default !=
'') ? 0 : 1);
2024 $tmparray = explode(
':', $param_list[0]);
2026 $element = $extrafieldsobjectkey;
2027 if ($element ==
'socpeople') {
2028 $element =
'contact';
2029 } elseif ($element ==
'projet') {
2030 $element =
'project';
2034 $objectdesc = $tmparray[0].(empty($tmparray[1]) ?
"" :
":".$tmparray[1]);
2035 $objectfield = $element.
':options_'.$key;
2037 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
2038 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
2039 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2043 if (!empty($value)) {
2044 $tmparray = $dolgeophp->parseGeoString($value);
2045 $geojson = $tmparray[
'geojson'];
2046 $centroidjson = $tmparray[
'centroidjson'];
2048 if (!preg_match(
'/search_/', $keyprefix)) {
2049 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
2051 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
2056 } elseif ($type ==
'password') {
2058 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
2059 $out .=
'<input autocomplete="new-password" type="'.($keyprefix ==
'search_' ?
'text' :
'password').
'" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'>';
2060 } elseif ($type ==
'stars') {
2061 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2062 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
2064 while ($i <= $size) {
2065 $out .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2070 jQuery(function($) { /* extrafields.class.php 1 */
2071 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
2072 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
2073 container.find(".star").each(function() {
2074 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2076 container.find(".star").on("mouseover", function() {
2077 let selectedStar = $(this).data("value");
2078 container.find(".star").each(function() {
2079 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2082 container.on("mouseout", function() {
2083 container.find(".star").each(function() {
2084 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2087 container.find(".star").off("click").on("click", function() {
2088 selectedStars = $(this).data("value");
2089 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
2092 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
2093 container.find(".star").each(function() {
2094 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2100 if (!empty($hidden)) {
2101 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
2106 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2107 $out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey,
null,
$object);
2132 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null,
$object =
null, $mode =
'')
2134 global $conf, $langs, $hookmanager;
2136 if (is_null($outputlangs) || !is_object($outputlangs)) {
2137 $outputlangs = $langs;
2140 if (empty($extrafieldsobjectkey)) {
2141 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
2142 return 'BadValueForParamExtraFieldsObjectKey';
2145 $parameters = array(
2148 'moreparam' => $moreparam,
2149 'extrafieldsobjectkey' => $extrafieldsobjectkey,
2150 'outputlangs' => $outputlangs,
2155 $reshook = $hookmanager->executeHooks(
'showOutputExtraField', $parameters, $this, $action);
2157 return $hookmanager->resPrint;
2160 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
2161 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2162 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
2163 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
2164 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
2165 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
2166 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
2167 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
2168 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
2169 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
2170 $list = (string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
2171 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
2172 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
2173 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
2176 $showValueInsteadOfInputField = 0;
2178 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2179 $showValueInsteadOfInputField = 1;
2182 $hidden = (empty($list) ? 1 : 0);
2191 if ($type ==
'date') {
2193 if ($value !==
'') {
2196 } elseif ($type ==
'datetime') {
2198 if ($value !==
'') {
2201 } elseif ($type ==
'duration') {
2203 if ($value !==
'') {
2204 $value = intval($value);
2207 } elseif ($type ==
'datetimegmt') {
2209 if ($value !==
'') {
2212 } elseif ($type ==
'int') {
2214 } elseif ($type ==
'double') {
2215 if (!empty($value)) {
2219 $value =
price($value, 0, $outputlangs, 0, 0, -2,
'');
2221 } elseif ($type ==
'boolean') {
2223 if (!empty($value)) {
2224 $checked =
' checked ';
2227 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
2229 $value =
yn($value ? 1 : 0);
2231 } elseif ($type ==
'mail' || $type ==
'email') {
2233 } elseif ($type ==
'ip') {
2235 } elseif ($type ==
'icon') {
2236 $value =
'<span class="'.$value.
'"></span>';
2237 } elseif ($type ==
'url') {
2239 } elseif ($type ==
'phone') {
2241 } elseif ($type ==
'price') {
2243 if ($value || $value ==
'0') {
2244 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol($conf->currency);
2246 } elseif ($type ==
'pricecy') {
2247 $currency = $conf->currency;
2248 if (!empty($value)) {
2250 $pricetmp = explode(
':', $value);
2251 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
2252 $value = $pricetmp[0];
2254 if ($value || $value ==
'0') {
2255 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
2257 } elseif ($type ==
'select') {
2258 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2259 if (($pos = strpos($valstr,
"|")) !==
false) {
2260 $valstr = substr($valstr, 0, $pos);
2262 if ($langfile && $valstr) {
2263 $value = $outputlangs->trans($valstr);
2267 } elseif ($type ==
'sellist') {
2268 $param_list = array_keys($param[
'options']);
2269 $InfoFieldList = explode(
":", $param_list[0]);
2271 $selectkey =
"rowid";
2274 if (count($InfoFieldList) >= 3) {
2275 $selectkey = $InfoFieldList[2];
2276 $keyList = $InfoFieldList[2].
' as rowid';
2279 $fields_label = explode(
'|', $InfoFieldList[1]);
2280 if (is_array($fields_label)) {
2282 $keyList .= implode(
', ', $fields_label);
2285 $filter_categorie =
false;
2286 if (count($InfoFieldList) > 5) {
2287 if ($InfoFieldList[0] ==
'categorie') {
2288 $filter_categorie =
true;
2292 $sql =
"SELECT ".$keyList;
2293 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
2294 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2297 if ($selectkey ==
'rowid' && empty($value)) {
2298 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = 0";
2299 } elseif ($selectkey ==
'rowid') {
2300 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = ".((int) $value);
2302 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = '".$this->db->escape($value).
"'";
2306 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2308 $resql = $this->db->query($sql);
2310 if (!$filter_categorie) {
2313 $obj = $this->db->fetch_object($resql);
2316 $fields_label = explode(
'|', $InfoFieldList[1]);
2318 if (is_array($fields_label) && count($fields_label) > 1) {
2319 foreach ($fields_label as $field_toshow) {
2321 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
2322 if (!empty($obj->$field_toshow)) {
2323 $translabel = $outputlangs->trans($obj->$field_toshow);
2325 if ($translabel != $obj->$field_toshow) {
2326 $value .=
dol_trunc($translabel, 24) .
' ';
2328 $value .= $obj->$field_toshow .
' ';
2334 $tmppropname = $InfoFieldList[1];
2336 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2337 $translabel = $outputlangs->trans($obj->$tmppropname);
2339 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2342 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2347 $obj = $this->db->fetch_object($resql);
2349 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2351 $result =
$c->fetch($obj->rowid);
2353 $ways =
$c->print_all_ways();
2354 foreach ($ways as $way) {
2355 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
2359 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2362 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2364 } elseif ($type ==
'radio') {
2365 if ($required && !isset($param[
'options'][$value])) {
2366 $outputlangs->load(
'errors');
2367 $value =
'<span class="opacitymedium">'.$outputlangs->trans(
'ErrorNoValueForRadioType').
'</span>';
2369 if (isset($param[
'options'][$value])) {
2370 $value = $outputlangs->trans($param[
'options'][$value]);
2375 } elseif ($type ==
'checkbox') {
2376 $value_arr = explode(
',', $value);
2379 if (is_array($value_arr)) {
2380 foreach ($value_arr as $keyval => $valueval) {
2381 if (!empty($valueval)) {
2382 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2386 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2387 } elseif ($type ==
'chkbxlst') {
2389 if (!is_null($value) && $value !=
'') {
2390 $value_arr = explode(
',', $value);
2392 $param_list = array_keys($param[
'options']);
2393 $InfoFieldList = explode(
":", $param_list[0]);
2395 $selectkey =
"rowid";
2398 if (count($InfoFieldList) >= 3) {
2399 $selectkey = $InfoFieldList[2];
2400 $keyList = $InfoFieldList[2].
' as rowid';
2403 $fields_label = explode(
'|', $InfoFieldList[1]);
2404 if (is_array($fields_label)) {
2406 $keyList .= implode(
', ', $fields_label);
2409 $filter_categorie =
false;
2410 if (count($InfoFieldList) > 5 && ((
string) $InfoFieldList[5] !=
'')) {
2411 if ($InfoFieldList[0] ==
'categorie') {
2412 $filter_categorie =
true;
2416 $sql =
"SELECT ".$keyList;
2417 $sql .=
" FROM ".$this->db->prefix().$InfoFieldList[0];
2418 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2421 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" IN (".$this->db->sanitize(implode(
',', $value_arr)).
")";
2423 dol_syslog(get_class($this).
':showOutputField type=chkbxlst', LOG_DEBUG);
2425 $resql = $this->db->query($sql);
2428 if (!$filter_categorie) {
2431 $numOfElem = $this->db->num_rows($resql);
2432 while ($obj = $this->db->fetch_object($resql)) {
2434 $fields_label = explode(
'|', $InfoFieldList[1]);
2437 if (count($fields_label) > 0) {
2438 if ($InfoFieldList[0] ==
'societe' && $InfoFieldList[1] ==
'nom' && $InfoFieldList[2] ==
'rowid') {
2440 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
2441 $tmpthirdpartystatic =
new Societe($this->db);
2442 $tmpthirdpartystatic->id = $obj->rowid;
2443 $tmpthirdpartystatic->name = $obj->nom;
2444 if ($numOfElem >= 3) {
2445 $tmpthirdpartystatic->name = $obj->nom;
2446 $label = $tmpthirdpartystatic->getNomUrl(2);
2447 } elseif ($numOfElem >= 2) {
2448 $tmpthirdpartystatic->name =
dol_trunc($obj->nom, 5);
2449 $label = $tmpthirdpartystatic->getNomUrl(1);
2451 $tmpthirdpartystatic->name = $obj->nom;
2452 $label = $tmpthirdpartystatic->getNomUrl(1);
2455 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: '.$txtcolor.
'">';
2456 foreach ($fields_label as $field_toshow) {
2458 if (!empty($obj->$field_toshow)) {
2459 $translabel = $outputlangs->trans($obj->$field_toshow);
2461 if ($translabel != $field_toshow) {
2462 $label .=
' '.dol_trunc($translabel, 18);
2464 $label .=
' '.$obj->$field_toshow;
2469 $toprint[] = $label;
2473 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2476 $numElem = $this->db->num_rows($resql);
2477 while ($obj = $this->db->fetch_object($resql)) {
2479 $c->fetch($obj->rowid);
2480 if ((
string) $mode !=
'list') {
2481 $ways =
$c->print_all_ways();
2482 foreach ($ways as $way) {
2483 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
2487 $forced_color =
'categtextwhite';
2490 $forced_color =
'categtextblack';
2494 $s =
'<li class="select2-search-choice-dolibarr noborderoncategories '.$forced_color.
' list"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>';
2495 if ($numElem >= 2) {
2496 $s .=
img_object(
$c->label,
'category',
'class="small"');
2498 $s .=
img_object(
$c->label,
'category',
'class="small"').
' '.
$c->label;
2505 if (!empty($toprint)) {
2506 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2509 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2512 } elseif ($type ==
'link') {
2515 $param_list = array_keys($param[
'options']);
2517 $InfoFieldList = explode(
":", $param_list[0]);
2518 $classname = $InfoFieldList[0];
2519 $classpath = $InfoFieldList[1];
2520 if (!empty($classpath)) {
2522 if ($classname && class_exists($classname)) {
2523 $tmpobject =
new $classname($this->db);
2524 '@phan-var-force CommonObject $tmpobject';
2525 $tmpobject->fetch($value);
2527 if (get_class($tmpobject) ==
'Categorie') {
2529 $color = $tmpobject->color;
2530 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2531 $sfortag .= $tmpobject->getNomUrl(3);
2532 $sfortag .=
'</span>';
2535 $value = $tmpobject->getNomUrl(3);
2539 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2540 return 'Error bad setup of extrafield';
2543 } elseif ($type ==
'point') {
2544 if (!empty($value)) {
2545 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2547 $value = $dolgeophp->getXYString($value);
2551 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2552 if (!empty($value)) {
2553 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2555 $value = $dolgeophp->getPointString($value);
2559 } elseif ($type ==
'text') {
2560 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2561 } elseif ($type ==
'html') {
2563 } elseif ($type ==
'password') {
2564 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2565 } elseif ($type ==
'stars') {
2566 $objectid = (int)
$object->id;
2567 $nbstars = (int) $value;
2568 if ($showValueInsteadOfInputField == 1) {
2569 $value =
'<span style="display:none;" id="'.$key.$object->id.
'">'.
dol_escape_htmltag($value).
'</span>';
2571 $value =
'<input type="hidden" class="flat" name="'.$key.
'" id="'.$key.$objectid.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2574 $value .=
'<div class="star-selection" id="'.$key.$objectid.
'_selection">';
2576 while ($i <= $size) {
2577 $value .=
'<span class="star'.($i <= $nbstars ?
' active' :
'').
'" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2582 $(document).ready(function() { /* extrafields.class.php 2 */
2583 let container = $("#'.$key.$objectid.
'_selection");
2584 let selectedStars = parseInt($("#'.$key.$objectid.
'").val() || $("#'.$key.$objectid.
'").text()) || 0;
2586 if ($showValueInsteadOfInputField == 0) {
2588 container.find(".star").on("mouseover", function() {
2589 console.log("Mouse over a star");
2590 let selectedStar = $(this).data("value");
2591 container.find(".star").each(function() {
2592 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2595 container.on("mouseout", function() {
2596 console.log("Mouse out of star");
2597 container.find(".star").each(function() {
2598 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2601 container.find(".star").off("click").on("click", function() {
2602 console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
2603 selectedStars = $(this).data("value");
2604 if (selectedStars == 1 && $("#'.$key.$objectid.
'").val() == 1) {
2607 container.find("#'.$key.$objectid.
'").val(selectedStars);
2608 container.find(".star").each(function() {
2609 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2612 url: "'.DOL_URL_ROOT.
'/core/ajax/updateextrafield.php",
2616 objectId:
'.((int) $objectid).',
2617 field: \
''.dol_escape_js($key).
'\',
2618 value: selectedStars,
2619 token: \
''.newToken().
'\'
2621 success:
function(response) {
2622 var res = JSON.parse(response);
2623 console[res.status ===
"success" ?
"log" :
"error"](res.message);
2625 error:
function(xhr,
status, error) {
2626 console.log(
"Ajax request failed while updating '.$key.':", error);
2635 $showsize = round((float) $size);
2636 if ($showsize > 48) {
2641 //print $type.'-
'.$size;