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.
"',
1453 objectid: '".$objectid.
"',
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;
1543 if (!empty($parentField)) {
1544 $keyList .=
', '.$parentField;
1548 $filter_categorie =
false;
1549 if (count($InfoFieldList) > 5) {
1550 if ($InfoFieldList[0] ==
'categorie') {
1551 $filter_categorie =
true;
1555 if (!$filter_categorie) {
1556 $fields_label = isset($InfoFieldList[1]) ? explode(
'|', $InfoFieldList[1]) : array();
1557 if (!empty($fields_label)) {
1559 $keyList .= implode(
', ', $fields_label);
1565 $sql =
"SELECT ".$keyList;
1566 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1569 if (!empty($InfoFieldList[4])) {
1571 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1572 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string) $conf->entity, $InfoFieldList[4]);
1576 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1577 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1581 if (strpos($InfoFieldList[4],
'$MODE$') !==
false) {
1582 $InfoFieldList[4] = str_replace(
'$MODE$', preg_replace(
'/[^a-z0-9_]/i',
'', (
string) $mode), $InfoFieldList[4]);
1586 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1587 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1588 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1592 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1593 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1595 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1596 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1598 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *: *[<>!=]?= *: *\$ID\$#';
1599 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1601 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1607 preg_match_all(
'/\$(.*?)\$/', $InfoFieldList[4], $tags);
1608 foreach ($tags[0] as $keytag => $valuetag) {
1609 $property = preg_replace(
'/[^a-z0-9_]/',
'', strtolower($tags[1][$keytag]));
1610 if (strpos($InfoFieldList[4], $valuetag) !==
false && property_exists(
$object, $property) && !empty(
$object->$property)) {
1611 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->$property, $InfoFieldList[4]);
1613 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1620 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1621 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1622 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1628 $sqlwhere .=
' WHERE 1=1';
1645 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1646 $sqlwhere .=
' AND entity = '.((int) $conf->entity);
1650 $sql .= $this->db->order(implode(
', ', $fields_label));
1651 $sql .=
' LIMIT ' .
getDolGlobalInt(
'MAIN_EXTRAFIELDS_LIMIT_SELLIST_SQL', 1000);
1654 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1655 $resql = $this->db->query($sql);
1657 $out .=
'<option value="0"> </option>';
1658 $num = $this->db->num_rows($resql);
1662 $obj = $this->db->fetch_object($resql);
1664 $nameFields = $InfoFieldList[1];
1666 $nameFields = preg_replace(
'/[a-z_]+\([^\)]*\) as ([\w]+)/i',
'\1', $nameFields);
1668 $nameFields = preg_replace(
'/[^0-9a-z_\.\|]/i',
'', $nameFields);
1672 $fields_label = explode(
'|', $nameFields);
1673 if (is_array($fields_label) && count($fields_label) > 1) {
1675 foreach ($fields_label as $field_toshow) {
1676 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
1677 $labeltoshow .= $obj->$field_toshow.
' ';
1680 $labeltoshow = $obj->$nameFields;
1683 if ($value == $obj->rowid) {
1685 foreach ($fields_label as $field_toshow) {
1686 $translabel = $langs->trans($obj->$field_toshow);
1687 $labeltoshow = $translabel.
' ';
1690 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1693 $translabel = $langs->trans($obj->$nameFields);
1694 $labeltoshow = $translabel;
1696 if (empty($labeltoshow)) {
1697 $labeltoshow =
'(not defined)';
1700 if (!empty($InfoFieldList[3]) && $parentField) {
1702 $parentField = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $parentField);
1703 $parent = $parentName.
':'.$obj->{$parentField};
1706 $out .=
'<option value="'.$obj->rowid.
'"';
1707 $out .= ($value == $obj->rowid ?
' selected' :
'');
1708 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1709 $out .=
'>'.$labeltoshow.
'</option>';
1714 $this->db->free($resql);
1716 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1719 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1720 $categcode = $InfoFieldList[5];
1721 if (is_numeric($categcode)) {
1722 $tmpcategory =
new Categorie($this->db);
1723 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
1724 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
1727 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1728 $out .=
'<option value="0"> </option>';
1729 if (is_array($data)) {
1730 foreach ($data as $data_key => $data_value) {
1731 $out .=
'<option value="'.$data_key.
'"';
1732 $out .= ($value == $data_key ?
' selected' :
'');
1733 $out .=
'>'.$data_value.
'</option>';
1738 $out .=
'</select>';
1740 } elseif ($type ==
'checkbox') {
1741 $value_arr = $value;
1742 if (!is_array($value)) {
1743 $value_arr = explode(
',', $value);
1745 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0,
'', 0,
'100%');
1746 } elseif ($type ==
'radio') {
1748 foreach ($param[
'options'] as $keyopt => $val) {
1749 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1750 $out .=
' value="'.$keyopt.
'"';
1751 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1752 $out .= ($value == $keyopt ?
'checked' :
'');
1753 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1755 } elseif ($type ==
'chkbxlst') {
1756 if (is_array($value)) {
1757 $value_arr = $value;
1759 $value_arr = explode(
',', $value);
1762 if (is_array($param[
'options'])) {
1763 $tmpparamoptions = array_keys($param[
'options']);
1764 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1766 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1787 if (! empty($InfoFieldList[4])) {
1789 $parenthesisopen = 0;
1790 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1791 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1794 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1799 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1800 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1802 $InfoFieldList[4] = $tmpbefore;
1803 if ($tmpafter !==
'') {
1804 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1809 if (preg_match(
'/^\(?([a-z0-9_]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1810 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1821 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1823 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1824 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1825 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1827 $keyList = $InfoFieldList[2].
' as rowid';
1830 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1831 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1832 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1833 $keyList .=
', main.'.$parentField;
1835 $keyList .=
', '.$parentField;
1838 if (!empty($parentField)) {
1839 $keyList .=
', '.$parentField;
1843 $InfoFieldList[5] = (string) ($InfoFieldList[5]??
'');
1845 $filter_categorie =
false;
1846 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
1847 if ($InfoFieldList[0] ==
'categorie') {
1848 $filter_categorie =
true;
1850 $filter_categorie =
false;
1855 if (!$filter_categorie) {
1856 $fields_label = explode(
'|', $InfoFieldList[1]);
1857 if (is_array($fields_label)) {
1859 $keyList .= implode(
', ', $fields_label);
1863 $sql =
"SELECT ".$keyList;
1864 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1867 if (!empty($InfoFieldList[4])) {
1869 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1870 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string) $conf->entity, $InfoFieldList[4]);
1873 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1874 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1878 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1879 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1880 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1884 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1885 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1887 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1888 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1890 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *: *[<>!=]?= *: *\$ID\$#';
1891 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1893 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1898 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1899 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1900 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1906 $sqlwhere .=
' WHERE 1=1';
1910 if ($InfoFieldList[5] !=
'') {
1912 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1913 $tmpcategory =
new Categorie($this->db);
1914 $tablesuffixcategory = empty($tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]];
1915 $fksuffixcategory = empty($tmpcategory->MAP_CAT_FK[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_FK[$InfoFieldList[5]];
1917 $sqlwhere .=
' AND EXISTS (SELECT fk_categorie as categid FROM '.MAIN_DB_PREFIX.
'categorie_'.$this->db->sanitize($tablesuffixcategory);
1918 $sqlwhere .=
' WHERE fk_categorie IN ('.$this->db->sanitize($InfoFieldList[6]).
')';
1919 $sqlwhere .=
' AND fk_'.$this->db->sanitize($fksuffixcategory).
' = rowid)';
1937 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1938 $sqlwhere .=
" AND entity = ".((int) $conf->entity);
1944 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1946 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
1948 $resql = $this->db->query($sql);
1950 $num = $this->db->num_rows($resql);
1957 $obj = $this->db->fetch_object($resql);
1961 $fields_label = explode(
'|', $InfoFieldList[1]);
1962 if (is_array($fields_label)) {
1964 foreach ($fields_label as $field_toshow) {
1965 $labeltoshow .= $obj->$field_toshow.
' ';
1968 $labeltoshow = $obj->{$InfoFieldList[1]};
1970 $labeltoshow =
dol_trunc($labeltoshow, 45);
1972 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1974 foreach ($fields_label as $field_toshow) {
1975 $translabel = $langs->trans($obj->$field_toshow);
1976 if ($translabel != $obj->$field_toshow) {
1977 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
1979 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
1982 $data[$obj->rowid] = $labeltoshow;
1985 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1986 if ($translabel != $obj->{$InfoFieldList[1]}) {
1987 $labeltoshow =
dol_trunc($translabel, 18);
1989 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
1992 if (empty($labeltoshow)) {
1993 $labeltoshow =
'(not defined)';
1996 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1997 $data[$obj->rowid] = $labeltoshow;
2000 if (!empty($InfoFieldList[3]) && $parentField) {
2001 $parent = $parentName.
':'.$obj->{$parentField};
2004 $data[$obj->rowid] = $labeltoshow;
2009 $this->db->free($resql);
2011 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2013 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
2016 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2017 $categcode = $InfoFieldList[5];
2018 if (is_numeric($categcode)) {
2019 $tmpcategory =
new Categorie($this->db);
2020 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
2021 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
2024 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
2025 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2028 } elseif ($type ==
'link') {
2029 $param_list = array_keys($param[
'options']);
2036 $showempty = (($required && $default !=
'') ? 0 : 1);
2038 $tmparray = explode(
':', $param_list[0]);
2040 $element = $extrafieldsobjectkey;
2041 if ($element ==
'socpeople') {
2042 $element =
'contact';
2043 } elseif ($element ==
'projet') {
2044 $element =
'project';
2048 $objectdesc = $tmparray[0].(empty($tmparray[1]) ?
"" :
":".$tmparray[1]);
2049 $objectfield = $element.
':options_'.$key;
2051 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
2052 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
2053 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2057 if (!empty($value)) {
2058 $tmparray = $dolgeophp->parseGeoString($value);
2059 $geojson = $tmparray[
'geojson'];
2060 $centroidjson = $tmparray[
'centroidjson'];
2062 if (!preg_match(
'/search_/', $keyprefix)) {
2063 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
2065 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
2070 } elseif ($type ==
'password') {
2072 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
2073 $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 :
'').
'>';
2074 } elseif ($type ==
'stars') {
2075 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2076 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
2078 while ($i <= $size) {
2079 $out .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2084 jQuery(function($) { /* extrafields.class.php 1 */
2085 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
2086 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
2087 container.find(".star").each(function() {
2088 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2090 container.find(".star").on("mouseover", function() {
2091 let selectedStar = $(this).data("value");
2092 container.find(".star").each(function() {
2093 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2096 container.on("mouseout", function() {
2097 container.find(".star").each(function() {
2098 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2101 container.find(".star").off("click").on("click", function() {
2102 selectedStars = $(this).data("value");
2103 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
2106 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
2107 container.find(".star").each(function() {
2108 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2114 if (!empty($hidden)) {
2115 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
2120 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2121 $out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey,
null,
$object);
2146 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null,
$object =
null, $mode =
'')
2148 global $conf, $langs, $hookmanager;
2150 if (is_null($outputlangs) || !is_object($outputlangs)) {
2151 $outputlangs = $langs;
2154 if (empty($extrafieldsobjectkey)) {
2155 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
2156 return 'BadValueForParamExtraFieldsObjectKey';
2159 $parameters = array(
2162 'moreparam' => $moreparam,
2163 'extrafieldsobjectkey' => $extrafieldsobjectkey,
2164 'outputlangs' => $outputlangs,
2169 $reshook = $hookmanager->executeHooks(
'showOutputExtraField', $parameters, $this, $action);
2171 return $hookmanager->resPrint;
2174 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
2175 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2176 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
2177 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
2178 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
2179 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
2180 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
2181 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
2182 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
2183 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
2184 $list = (string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
2185 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
2186 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
2187 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
2190 $showValueInsteadOfInputField = 0;
2192 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2193 $showValueInsteadOfInputField = 1;
2196 $hidden = (empty($list) ? 1 : 0);
2205 if ($type ==
'date') {
2207 if ($value !==
'') {
2210 } elseif ($type ==
'datetime') {
2212 if ($value !==
'') {
2215 } elseif ($type ==
'duration') {
2217 if ($value !==
'') {
2218 $value = intval($value);
2221 } elseif ($type ==
'datetimegmt') {
2223 if ($value !==
'') {
2226 } elseif ($type ==
'int') {
2228 } elseif ($type ==
'double') {
2229 if (!empty($value)) {
2233 $value =
price($value, 0, $outputlangs, 0, 0, -2,
'');
2235 } elseif ($type ==
'boolean') {
2237 if (!empty($value)) {
2238 $checked =
' checked ';
2241 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
2243 $value =
yn($value ? 1 : 0);
2245 } elseif ($type ==
'mail' || $type ==
'email') {
2247 } elseif ($type ==
'ip') {
2249 } elseif ($type ==
'icon') {
2250 $value =
'<span class="'.$value.
'"></span>';
2251 } elseif ($type ==
'url') {
2253 } elseif ($type ==
'phone') {
2255 } elseif ($type ==
'price') {
2257 if ($value || $value ==
'0') {
2258 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol($conf->currency);
2260 } elseif ($type ==
'pricecy') {
2261 $currency = $conf->currency;
2262 if (!empty($value)) {
2264 $pricetmp = explode(
':', $value);
2265 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
2266 $value = $pricetmp[0];
2268 if ($value || $value ==
'0') {
2269 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
2271 } elseif ($type ==
'select') {
2272 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2273 if (($pos = strpos($valstr,
"|")) !==
false) {
2274 $valstr = substr($valstr, 0, $pos);
2276 if ($langfile && $valstr) {
2277 $value = $outputlangs->trans($valstr);
2281 } elseif ($type ==
'sellist') {
2282 $param_list = array_keys($param[
'options']);
2283 $InfoFieldList = explode(
":", $param_list[0]);
2285 $selectkey =
"rowid";
2288 if (count($InfoFieldList) >= 3) {
2289 $selectkey = $InfoFieldList[2];
2290 $keyList = $InfoFieldList[2].
' as rowid';
2293 $fields_label = explode(
'|', $InfoFieldList[1]);
2294 if (is_array($fields_label)) {
2296 $keyList .= implode(
', ', $fields_label);
2299 $filter_categorie =
false;
2300 if (count($InfoFieldList) > 5) {
2301 if ($InfoFieldList[0] ==
'categorie') {
2302 $filter_categorie =
true;
2306 $sql =
"SELECT ".$keyList;
2307 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
2308 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2311 if ($selectkey ==
'rowid' && empty($value)) {
2312 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = 0";
2313 } elseif ($selectkey ==
'rowid') {
2314 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = ".((int) $value);
2316 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = '".$this->db->escape($value).
"'";
2320 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2322 $resql = $this->db->query($sql);
2324 if (!$filter_categorie) {
2327 $obj = $this->db->fetch_object($resql);
2330 $fields_label = explode(
'|', $InfoFieldList[1]);
2332 if (is_array($fields_label) && count($fields_label) > 1) {
2333 foreach ($fields_label as $field_toshow) {
2335 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
2336 if (!empty($obj->$field_toshow)) {
2337 $translabel = $outputlangs->trans($obj->$field_toshow);
2339 if ($translabel != $obj->$field_toshow) {
2340 $value .=
dol_trunc($translabel, 24) .
' ';
2342 $value .= $obj->$field_toshow .
' ';
2348 $tmppropname = $InfoFieldList[1];
2350 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2351 $translabel = $outputlangs->trans($obj->$tmppropname);
2353 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2356 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2361 $obj = $this->db->fetch_object($resql);
2363 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2365 $result =
$c->fetch($obj->rowid);
2367 $ways =
$c->print_all_ways();
2368 foreach ($ways as $way) {
2369 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
2373 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2376 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2378 } elseif ($type ==
'radio') {
2379 if ($required && !isset($param[
'options'][$value])) {
2380 $outputlangs->load(
'errors');
2381 $value =
'<span class="opacitymedium">'.$outputlangs->trans(
'ErrorNoValueForRadioType').
'</span>';
2383 if (isset($param[
'options'][$value])) {
2384 $value = $outputlangs->trans($param[
'options'][$value]);
2389 } elseif ($type ==
'checkbox') {
2390 $value_arr = explode(
',', $value);
2393 if (is_array($value_arr)) {
2394 foreach ($value_arr as $keyval => $valueval) {
2395 if (!empty($valueval)) {
2396 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2400 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2401 } elseif ($type ==
'chkbxlst') {
2403 if (!is_null($value) && $value !=
'') {
2404 $value_arr = explode(
',', $value);
2406 $param_list = array_keys($param[
'options']);
2407 $InfoFieldList = explode(
":", $param_list[0]);
2409 $selectkey =
"rowid";
2412 if (count($InfoFieldList) >= 3) {
2413 $selectkey = $InfoFieldList[2];
2414 $keyList = $InfoFieldList[2].
' as rowid';
2417 $fields_label = explode(
'|', $InfoFieldList[1]);
2418 if (is_array($fields_label)) {
2420 $keyList .= implode(
', ', $fields_label);
2423 $filter_categorie =
false;
2424 if (count($InfoFieldList) > 5 && ((
string) $InfoFieldList[5] !=
'')) {
2425 if ($InfoFieldList[0] ==
'categorie') {
2426 $filter_categorie =
true;
2430 $sql =
"SELECT ".$keyList;
2431 $sql .=
" FROM ".$this->db->prefix().$InfoFieldList[0];
2432 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2435 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" IN (".$this->db->sanitize(implode(
',', $value_arr)).
")";
2437 dol_syslog(get_class($this).
':showOutputField type=chkbxlst', LOG_DEBUG);
2439 $resql = $this->db->query($sql);
2442 if (!$filter_categorie) {
2445 $numOfElem = $this->db->num_rows($resql);
2446 while ($obj = $this->db->fetch_object($resql)) {
2448 $fields_label = explode(
'|', $InfoFieldList[1]);
2451 if (count($fields_label) > 0) {
2452 if ($InfoFieldList[0] ==
'societe' && $InfoFieldList[1] ==
'nom' && $InfoFieldList[2] ==
'rowid') {
2454 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
2455 $tmpthirdpartystatic =
new Societe($this->db);
2456 $tmpthirdpartystatic->id = $obj->rowid;
2457 $tmpthirdpartystatic->name = $obj->nom;
2458 if ($numOfElem >= 3) {
2459 $tmpthirdpartystatic->name = $obj->nom;
2460 $label = $tmpthirdpartystatic->getNomUrl(2);
2461 } elseif ($numOfElem >= 2) {
2462 $tmpthirdpartystatic->name =
dol_trunc($obj->nom, 5);
2463 $label = $tmpthirdpartystatic->getNomUrl(1);
2465 $tmpthirdpartystatic->name = $obj->nom;
2466 $label = $tmpthirdpartystatic->getNomUrl(1);
2469 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: '.$txtcolor.
'">';
2470 foreach ($fields_label as $field_toshow) {
2472 if (!empty($obj->$field_toshow)) {
2473 $translabel = $outputlangs->trans($obj->$field_toshow);
2475 if ($translabel != $field_toshow) {
2476 $label .=
' '.dol_trunc($translabel, 18);
2478 $label .=
' '.$obj->$field_toshow;
2483 $toprint[] = $label;
2487 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2490 $numElem = $this->db->num_rows($resql);
2491 while ($obj = $this->db->fetch_object($resql)) {
2493 $c->fetch($obj->rowid);
2494 if ((
string) $mode !=
'list') {
2495 $ways =
$c->print_all_ways();
2496 foreach ($ways as $way) {
2497 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
2501 $forced_color =
'categtextwhite';
2504 $forced_color =
'categtextblack';
2508 $s =
'<li class="select2-search-choice-dolibarr noborderoncategories '.$forced_color.
' list"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>';
2509 if ($numElem >= 2) {
2510 $s .=
img_object(
$c->label,
'category',
'class="small"');
2512 $s .=
img_object(
$c->label,
'category',
'class="small"').
' '.
$c->label;
2519 if (!empty($toprint)) {
2520 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2523 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2526 } elseif ($type ==
'link') {
2529 $param_list = array_keys($param[
'options']);
2531 $InfoFieldList = explode(
":", $param_list[0]);
2532 $classname = $InfoFieldList[0];
2533 $classpath = $InfoFieldList[1];
2534 if (!empty($classpath)) {
2536 if (!$classname || !class_exists($classname)) {
2539 dol_syslog(
'Extrafields::showOutputField the class '.$classname.
' of the link field '.$key.
' could not be loaded from '.$classpath.
', check the extrafield definition', LOG_WARNING);
2541 if ($classname && class_exists($classname)) {
2542 $tmpobject =
new $classname($this->db);
2543 '@phan-var-force CommonObject $tmpobject';
2544 $tmpobject->fetch($value);
2546 if (get_class($tmpobject) ==
'Categorie') {
2548 $color = $tmpobject->color;
2549 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2550 $sfortag .= $tmpobject->getNomUrl(3);
2551 $sfortag .=
'</span>';
2554 $value = $tmpobject->getNomUrl(3);
2558 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2559 return 'Error bad setup of extrafield';
2562 } elseif ($type ==
'point') {
2563 if (!empty($value)) {
2564 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2566 $value = $dolgeophp->getXYString($value);
2570 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2571 if (!empty($value)) {
2572 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2574 $value = $dolgeophp->getPointString($value);
2578 } elseif ($type ==
'text') {
2579 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2580 } elseif ($type ==
'html') {
2582 } elseif ($type ==
'password') {
2583 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2584 } elseif ($type ==
'stars') {
2585 $objectid = (int)
$object->id;
2586 $nbstars = (int) $value;
2587 if ($showValueInsteadOfInputField == 1) {
2588 $value =
'<span style="display:none;" id="'.$key.$object->id.
'">'.
dol_escape_htmltag($value).
'</span>';
2590 $value =
'<input type="hidden" class="flat" name="'.$key.
'" id="'.$key.$objectid.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2593 $value .=
'<div class="star-selection" id="'.$key.$objectid.
'_selection">';
2595 while ($i <= $size) {
2596 $value .=
'<span class="star'.($i <= $nbstars ?
' active' :
'').
'" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2601 $(document).ready(function() { /* extrafields.class.php 2 */
2602 let container = $("#'.$key.$objectid.
'_selection");
2603 let selectedStars = parseInt($("#'.$key.$objectid.
'").val() || $("#'.$key.$objectid.
'").text()) || 0;
2605 if ($showValueInsteadOfInputField == 0) {
2607 container.find(".star").on("mouseover", function() {
2608 console.log("Mouse over a star");
2609 let selectedStar = $(this).data("value");
2610 container.find(".star").each(function() {
2611 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2614 container.on("mouseout", function() {
2615 console.log("Mouse out of star");
2616 container.find(".star").each(function() {
2617 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2620 container.find(".star").off("click").on("click", function() {
2621 console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
2622 selectedStars = $(this).data("value");
2623 if (selectedStars == 1 && $("#'.$key.$objectid.
'").val() == 1) {
2626 container.find("#'.$key.$objectid.
'").val(selectedStars);
2627 container.find(".star").each(function() {
2628 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2631 url: "'.DOL_URL_ROOT.
'/core/ajax/updateextrafield.php",
2635 objectId:
'.((int) $objectid).',
2636 field: \
''.dol_escape_js($key).
'\',
2637 value: selectedStars,
2638 token: \
''.newToken().
'\'
2640 success:
function(response) {
2641 var res = JSON.parse(response);
2642 console[res.status ===
"success" ?
"log" :
"error"](res.message);
2644 error:
function(xhr,
status, error) {
2645 console.log(
"Ajax request failed while updating '.$key.':", error);
2654 $showsize = round((float) $size);
2655 if ($showsize > 48) {
2660 //print $type.'-
'.$size;