1124 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'',
$object = 0, $extrafieldsobjectkey =
'', $mode = 0)
1126 global
$conf, $langs, $form;
1128 if (!is_object($form)) {
1129 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
1130 $form =
new Form($this->db);
1137 if (!preg_match(
'/options_$/', $keyprefix)) {
1138 $keyprefix .=
'options_';
1141 if (empty($extrafieldsobjectkey)) {
1142 dol_syslog(get_class($this).
'::showInputField extrafieldsobjectkey required', LOG_ERR);
1143 return 'BadValueForParamExtraFieldsObjectKey';
1146 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1147 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1148 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1149 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1150 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1151 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1152 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1153 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1154 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
1155 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1156 $list = (string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
1157 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
1158 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1159 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
1160 $hidden = (empty($list) ? 1 : 0);
1166 if (!preg_match(
'/^search_/', $keyprefix)) {
1167 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
1175 if (empty($morecss)) {
1177 if ($type ==
'date') {
1178 $morecss =
'minwidth100imp';
1179 } elseif ($type ==
'datetime' || $type ==
'datetimegmt' || $type ==
'link') {
1180 $morecss =
'minwidth200imp';
1181 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
1182 $morecss =
'maxwidth75';
1183 } elseif ($type ==
'password') {
1184 $morecss =
'maxwidth100';
1185 } elseif ($type ==
'url') {
1186 $morecss =
'minwidth400';
1187 } elseif ($type ==
'boolean') {
1189 } elseif ($type ==
'radio') {
1190 $morecss =
'width25';
1192 if (empty($size) || round((
float) $size) < 12) {
1193 $morecss =
'minwidth100';
1194 } elseif (round((
float) $size) <= 48) {
1195 $morecss =
'minwidth200';
1197 $morecss =
'minwidth400';
1201 if (!empty($this->attributes[$extrafieldsobjectkey][
'css'][$key])) {
1202 $morecss = $this->attributes[$extrafieldsobjectkey][
'css'][$key];
1206 if (in_array($type, array(
'date'))) {
1207 $tmp = explode(
',', $size);
1212 if (!$required && $value ==
'') {
1219 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1220 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1222 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1223 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"));
1224 $out .=
'</div><div class="nowrap">';
1225 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"));
1226 $out .=
'</div></div>';
1229 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1231 } elseif (in_array($type, array(
'datetime',
'datetimegmt'))) {
1232 $tmp = explode(
',', $size);
1237 if (!$required && $value ==
'') {
1244 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1245 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1247 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1248 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"),
'tzuserrel');
1249 $out .=
'</div><div class="nowrap">';
1250 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
1251 $out .=
'</div></div>';
1254 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1256 } elseif (in_array($type, array(
'int',
'integer'))) {
1257 $tmp = explode(
',', $size);
1259 $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 :
'').
'>';
1260 } elseif (preg_match(
'/varchar/', $type)) {
1261 $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 :
'').
'>';
1262 } elseif (in_array($type, array(
'email',
'mail',
'ip',
'phone',
'url'))) {
1263 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1264 } elseif ($type ==
'icon') {
1270 $out .=
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat '.$morecss.
' maxwidthonsmartphone"';
1271 $out .=
' name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1274 $options =
"{ title: '<b>".$langs->trans(
"IconFieldSelector").
"</b>', placement: 'right', showFooter: false, templates: {";
1275 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
1276 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
1279 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
1280 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"".$langs->trans(
"TypeToFilter").
"\" />',";
1281 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
1282 $options .=
" <div class=\"arrow\" ></div>";
1283 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
1284 $options .=
" <div class=\"popover-content \" ></div>";
1285 $options .=
"</div>'}}";
1286 $out .=
"$('#".$keyprefix.$key.$keysuffix.
"').iconpicker(".$options.
");";
1287 $out .=
'</script>';
1289 } elseif ($type ==
'text') {
1290 if (!preg_match(
'/search_/', $keyprefix)) {
1291 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1292 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1293 $out = (string) $doleditor->Create(1);
1295 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1297 } elseif ($type ==
'html') {
1298 if (!preg_match(
'/search_/', $keyprefix)) {
1299 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1300 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false, isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
1301 $out = (string) $doleditor->Create(1);
1303 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1305 } elseif ($type ==
'boolean') {
1308 if (!empty($value)) {
1309 $checked =
' checked value="1" ';
1311 $checked =
' value="1" ';
1313 $out =
'<input type="checkbox" class="flat valignmiddle'.($morecss ?
' '.$morecss :
'').
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1315 $out = $form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1, 1,
'width75 yesno');
1317 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_boolean" value="1">';
1318 } elseif ($type ==
'price') {
1319 if (!empty($value)) {
1320 $value =
price($value);
1322 $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).
'">';
1323 } elseif ($type ==
'pricecy') {
1324 $currency =
$conf->currency;
1325 if (!empty($value)) {
1327 $pricetmp = explode(
':', $value);
1328 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
1329 $value =
price($pricetmp[0]);
1331 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1332 $out .= $form->selectCurrency($currency, $keyprefix.$key.$keysuffix.
'currency_id');
1333 } elseif ($type ==
'duration') {
1334 $value = intval($value);
1335 $out = $form->select_duration($keyprefix . $key, $value, 0,
'text', 0, 1);
1336 } elseif ($type ==
'double') {
1337 if (!empty($value)) {
1338 $value =
price($value);
1340 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1341 } elseif ($type ==
'select') {
1345 foreach ($param[
'options'] as $okey => $val) {
1346 if ((
string) $okey ==
'') {
1350 $valarray = explode(
'|', $val);
1351 $val = $valarray[0];
1353 if ($langfile && $val) {
1354 $options[$okey] = $langs->trans($val);
1356 $options[$okey] = $val;
1359 $selected = array();
1360 if (!is_array($value)) {
1361 $selected = explode(
',', $value);
1364 $out .= $form->multiselectarray($keyprefix.$key.$keysuffix, $options, $selected, 0, 0, $morecss, 0, 0,
'',
'',
'', (
int) (!empty(
$conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
1367 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1368 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1371 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1372 $out .=
'<option value="0"> </option>';
1373 foreach ($param[
'options'] as $key2 => $val2) {
1374 if ((
string) $key2 ==
'') {
1377 $valarray = explode(
'|', $val2);
1378 $val2 = $valarray[0];
1380 if (!empty($valarray[1])) {
1381 $parent = $valarray[1];
1383 $out .=
'<option value="'.$key2.
'"';
1384 $out .= (((string) $value == (
string) $key2) ?
' selected' :
'');
1385 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1387 if ($langfile && $val2) {
1388 $out .= $langs->trans($val2);
1392 $out .=
'</option>';
1394 $out .=
'</select>';
1396 } elseif ($type ==
'sellist') {
1398 if (!empty(
$conf->use_javascript_ajax)) {
1402 $(document).ready(function () {
1403 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1405 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1407 delay: 250, // wait 250 milliseconds before triggering the request
1408 data: function (params) {
1410 search: params.term,
1411 page: params.page || 1,
1412 objecttype: '".$extrafieldsobjectkey.
"',
1413 objectid: '".$objectid.
"',
1414 objectkey: '".$key.
"',
1424 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1425 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1426 $out .=
'</select>';
1428 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1429 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1434 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1435 if (is_array($param[
'options'])) {
1438 $tmpparamoptions = array_keys($param[
'options']);
1439 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1441 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1453 if (! empty($InfoFieldList[4])) {
1455 $parenthesisopen = 0;
1456 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1457 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1460 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1465 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1466 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1468 $InfoFieldList[4] = $tmpbefore;
1469 if ($tmpafter !==
'') {
1470 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1475 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1476 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1486 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1488 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1489 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1490 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1492 $keyList = $InfoFieldList[2].
' as rowid';
1495 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1496 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1497 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1498 $keyList .=
', main.'.$parentField;
1500 $keyList .=
', '.$parentField;
1503 if (!empty($parentField)) {
1504 $keyList .=
', '.$parentField;
1508 $filter_categorie =
false;
1509 if (count($InfoFieldList) > 5) {
1510 if ($InfoFieldList[0] ==
'categorie') {
1511 $filter_categorie =
true;
1515 if (!$filter_categorie) {
1516 $fields_label = explode(
'|', $InfoFieldList[1]);
1517 if (is_array($fields_label)) {
1519 $keyList .= implode(
', ', $fields_label);
1525 $sql =
"SELECT ".$keyList;
1526 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1529 if (!empty($InfoFieldList[4])) {
1531 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1532 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1536 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1537 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1541 if (strpos($InfoFieldList[4],
'$MODE$') !==
false) {
1542 $InfoFieldList[4] = str_replace(
'$MODE$', preg_replace(
'/[^a-z0-9_]/i',
'', (
string) $mode), $InfoFieldList[4]);
1546 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1547 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1548 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1552 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1553 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1555 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1556 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1558 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *: *[<>!=]?= *: *\$ID\$#';
1559 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1561 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1567 preg_match_all(
'/\$(.*?)\$/', $InfoFieldList[4], $tags);
1568 foreach ($tags[0] as $keytag => $valuetag) {
1569 $property = preg_replace(
'/[^a-z0-9_]/',
'', strtolower($tags[1][$keytag]));
1570 if (strpos($InfoFieldList[4], $valuetag) !==
false && property_exists(
$object, $property) && !empty(
$object->$property)) {
1571 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->$property, $InfoFieldList[4]);
1573 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1580 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1581 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1582 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1588 $sqlwhere .=
' WHERE 1=1';
1605 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1606 $sqlwhere .=
' AND entity = '.((int)
$conf->entity);
1610 $sql .= $this->db->order(implode(
', ', $fields_label));
1611 $sql .=
' LIMIT ' .
getDolGlobalInt(
'MAIN_EXTRAFIELDS_LIMIT_SELLIST_SQL', 1000);
1614 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1615 $resql = $this->db->query($sql);
1617 $out .=
'<option value="0"> </option>';
1618 $num = $this->db->num_rows($resql);
1622 $obj = $this->db->fetch_object($resql);
1624 $nameFields = $InfoFieldList[1];
1626 $nameFields = preg_replace(
'/[a-z_]+\([^\)]*\) as ([\w]+)/i',
'\1', $nameFields);
1628 $nameFields = preg_replace(
'/[^0-9a-z_\.\|]/i',
'', $nameFields);
1632 $fields_label = explode(
'|', $nameFields);
1633 if (is_array($fields_label) && count($fields_label) > 1) {
1635 foreach ($fields_label as $field_toshow) {
1636 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
1637 $labeltoshow .= $obj->$field_toshow.
' ';
1640 $labeltoshow = $obj->$nameFields;
1643 if ($value == $obj->rowid) {
1645 foreach ($fields_label as $field_toshow) {
1646 $translabel = $langs->trans($obj->$field_toshow);
1647 $labeltoshow = $translabel.
' ';
1650 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1653 $translabel = $langs->trans($obj->$nameFields);
1654 $labeltoshow = $translabel;
1656 if (empty($labeltoshow)) {
1657 $labeltoshow =
'(not defined)';
1660 if (!empty($InfoFieldList[3]) && $parentField) {
1662 $parentField = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $parentField);
1663 $parent = $parentName.
':'.$obj->{$parentField};
1666 $out .=
'<option value="'.$obj->rowid.
'"';
1667 $out .= ($value == $obj->rowid ?
' selected' :
'');
1668 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1669 $out .=
'>'.$labeltoshow.
'</option>';
1674 $this->db->free($resql);
1676 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1679 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1680 $categcode = $InfoFieldList[5];
1681 if (is_numeric($categcode)) {
1682 $categcode = Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]];
1684 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1685 $out .=
'<option value="0"> </option>';
1686 if (is_array($data)) {
1687 foreach ($data as $data_key => $data_value) {
1688 $out .=
'<option value="'.$data_key.
'"';
1689 $out .= ($value == $data_key ?
' selected' :
'');
1690 $out .=
'>'.$data_value.
'</option>';
1695 $out .=
'</select>';
1697 } elseif ($type ==
'checkbox') {
1698 $value_arr = $value;
1699 if (!is_array($value)) {
1700 $value_arr = explode(
',', $value);
1702 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0,
'', 0,
'100%');
1703 } elseif ($type ==
'radio') {
1705 foreach ($param[
'options'] as $keyopt => $val) {
1706 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1707 $out .=
' value="'.$keyopt.
'"';
1708 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1709 $out .= ($value == $keyopt ?
'checked' :
'');
1710 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1712 } elseif ($type ==
'chkbxlst') {
1713 if (is_array($value)) {
1714 $value_arr = $value;
1716 $value_arr = explode(
',', $value);
1719 if (is_array($param[
'options'])) {
1720 $tmpparamoptions = array_keys($param[
'options']);
1721 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1723 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1735 if (! empty($InfoFieldList[4])) {
1737 $parenthesisopen = 0;
1738 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1739 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1742 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1747 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1748 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1750 $InfoFieldList[4] = $tmpbefore;
1751 if ($tmpafter !==
'') {
1752 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1757 if (preg_match(
'/^\(?([a-z0-9_]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1758 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1768 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1770 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1771 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1772 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1774 $keyList = $InfoFieldList[2].
' as rowid';
1777 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1778 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1779 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1780 $keyList .=
', main.'.$parentField;
1782 $keyList .=
', '.$parentField;
1785 if (!empty($parentField)) {
1786 $keyList .=
', '.$parentField;
1790 $filter_categorie =
false;
1791 if (count($InfoFieldList) > 5) {
1792 if ($InfoFieldList[0] ==
'categorie') {
1793 $filter_categorie =
true;
1797 if (!$filter_categorie) {
1798 $fields_label = explode(
'|', $InfoFieldList[1]);
1799 if (is_array($fields_label)) {
1801 $keyList .= implode(
', ', $fields_label);
1805 $sql =
"SELECT ".$keyList;
1806 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1809 if (!empty($InfoFieldList[4])) {
1811 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1812 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1815 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1816 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1820 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1821 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1822 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1826 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1827 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1829 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1830 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1832 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *: *[<>!=]?= *: *\$ID\$#';
1833 $InfoFieldList[4] = preg_replace($word,
'1 = 1', $InfoFieldList[4]);
1835 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1840 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1841 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1842 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1848 $sqlwhere .=
' WHERE 1=1';
1865 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1866 $sqlwhere .=
" AND entity = ".((int)
$conf->entity);
1872 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1874 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
1875 $resql = $this->db->query($sql);
1877 $num = $this->db->num_rows($resql);
1884 $obj = $this->db->fetch_object($resql);
1888 $fields_label = explode(
'|', $InfoFieldList[1]);
1889 if (is_array($fields_label)) {
1891 foreach ($fields_label as $field_toshow) {
1892 $labeltoshow .= $obj->$field_toshow.
' ';
1895 $labeltoshow = $obj->{$InfoFieldList[1]};
1897 $labeltoshow =
dol_trunc($labeltoshow, 45);
1899 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1901 foreach ($fields_label as $field_toshow) {
1902 $translabel = $langs->trans($obj->$field_toshow);
1903 if ($translabel != $obj->$field_toshow) {
1904 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
1906 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
1909 $data[$obj->rowid] = $labeltoshow;
1912 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1913 if ($translabel != $obj->{$InfoFieldList[1]}) {
1914 $labeltoshow =
dol_trunc($translabel, 18);
1916 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
1919 if (empty($labeltoshow)) {
1920 $labeltoshow =
'(not defined)';
1923 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1924 $data[$obj->rowid] = $labeltoshow;
1927 if (!empty($InfoFieldList[3]) && $parentField) {
1928 $parent = $parentName.
':'.$obj->{$parentField};
1931 $data[$obj->rowid] = $labeltoshow;
1936 $this->db->free($resql);
1938 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
1940 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1943 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1944 $categcode = $InfoFieldList[5];
1945 if (is_numeric($categcode)) {
1946 $categcode = Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]];
1948 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1949 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
1952 } elseif ($type ==
'link') {
1953 $param_list = array_keys($param[
'options']);
1960 $showempty = (($required && $default !=
'') ? 0 : 1);
1962 $tmparray = explode(
':', $param_list[0]);
1964 $element = $extrafieldsobjectkey;
1965 if ($element ==
'socpeople') {
1966 $element =
'contact';
1967 } elseif ($element ==
'projet') {
1968 $element =
'project';
1972 $objectdesc = $tmparray[0];
1973 $objectfield = $element.
':options_'.$key;
1975 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
1976 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
1977 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
1981 if (!empty($value)) {
1982 $tmparray = $dolgeophp->parseGeoString($value);
1983 $geojson = $tmparray[
'geojson'];
1984 $centroidjson = $tmparray[
'centroidjson'];
1986 if (!preg_match(
'/search_/', $keyprefix)) {
1987 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
1989 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
1994 } elseif ($type ==
'password') {
1996 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
1997 $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 :
'').
'>';
1998 } elseif ($type ==
'stars') {
1999 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2000 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
2002 while ($i <= $size) {
2003 $out .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2008 jQuery(function($) { /* extrafields.class.php 1 */
2009 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
2010 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
2011 container.find(".star").each(function() {
2012 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2014 container.find(".star").on("mouseover", function() {
2015 let selectedStar = $(this).data("value");
2016 container.find(".star").each(function() {
2017 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2020 container.on("mouseout", function() {
2021 container.find(".star").each(function() {
2022 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2025 container.find(".star").off("click").on("click", function() {
2026 selectedStars = $(this).data("value");
2027 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
2030 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
2031 container.find(".star").each(function() {
2032 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2038 if (!empty($hidden)) {
2039 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
2044 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2045 $out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey,
null,
$object);
2069 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null,
$object =
null)
2071 global
$conf, $langs;
2073 if (is_null($outputlangs) || !is_object($outputlangs)) {
2074 $outputlangs = $langs;
2077 if (empty($extrafieldsobjectkey)) {
2078 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
2079 return 'BadValueForParamExtraFieldsObjectKey';
2082 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
2083 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2084 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
2085 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
2086 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
2087 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
2088 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
2089 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
2090 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
2091 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
2092 $list = (string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
2093 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
2094 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
2095 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
2098 $showValueInsteadOfInputField = 0;
2100 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2101 $showValueInsteadOfInputField = 1;
2104 $hidden = (empty($list) ? 1 : 0);
2112 if ($type ==
'date') {
2114 if ($value !==
'') {
2117 } elseif ($type ==
'datetime') {
2119 if ($value !==
'') {
2122 } elseif ($type ==
'duration') {
2124 if ($value !==
'') {
2125 $value = intval($value);
2128 } elseif ($type ==
'datetimegmt') {
2130 if ($value !==
'') {
2133 } elseif ($type ==
'int') {
2135 } elseif ($type ==
'double') {
2136 if (!empty($value)) {
2140 $value =
price($value, 0, $outputlangs, 0, 0, -2,
'');
2142 } elseif ($type ==
'boolean') {
2144 if (!empty($value)) {
2145 $checked =
' checked ';
2148 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
2150 $value =
yn($value ? 1 : 0);
2152 } elseif ($type ==
'mail' || $type ==
'email') {
2154 } elseif ($type ==
'ip') {
2156 } elseif ($type ==
'icon') {
2157 $value =
'<span class="'.$value.
'"></span>';
2158 } elseif ($type ==
'url') {
2160 } elseif ($type ==
'phone') {
2162 } elseif ($type ==
'price') {
2164 if ($value || $value ==
'0') {
2165 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol(
$conf->currency);
2167 } elseif ($type ==
'pricecy') {
2168 $currency =
$conf->currency;
2169 if (!empty($value)) {
2171 $pricetmp = explode(
':', $value);
2172 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
2173 $value = $pricetmp[0];
2175 if ($value || $value ==
'0') {
2176 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
2178 } elseif ($type ==
'select') {
2179 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2180 if (($pos = strpos($valstr,
"|")) !==
false) {
2181 $valstr = substr($valstr, 0, $pos);
2183 if ($langfile && $valstr) {
2184 $value = $outputlangs->trans($valstr);
2188 } elseif ($type ==
'sellist') {
2189 $param_list = array_keys($param[
'options']);
2190 $InfoFieldList = explode(
":", $param_list[0]);
2192 $selectkey =
"rowid";
2195 if (count($InfoFieldList) >= 3) {
2196 $selectkey = $InfoFieldList[2];
2197 $keyList = $InfoFieldList[2].
' as rowid';
2200 $fields_label = explode(
'|', $InfoFieldList[1]);
2201 if (is_array($fields_label)) {
2203 $keyList .= implode(
', ', $fields_label);
2206 $filter_categorie =
false;
2207 if (count($InfoFieldList) > 5) {
2208 if ($InfoFieldList[0] ==
'categorie') {
2209 $filter_categorie =
true;
2213 $sql =
"SELECT ".$keyList;
2214 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
2215 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2218 if ($selectkey ==
'rowid' && empty($value)) {
2219 $sql .=
" WHERE ".$selectkey.
" = 0";
2220 } elseif ($selectkey ==
'rowid') {
2221 $sql .=
" WHERE ".$selectkey.
" = ".((int) $value);
2223 $sql .=
" WHERE ".$selectkey.
" = '".$this->db->escape($value).
"'";
2228 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2229 $resql = $this->db->query($sql);
2231 if (!$filter_categorie) {
2234 $obj = $this->db->fetch_object($resql);
2237 $fields_label = explode(
'|', $InfoFieldList[1]);
2239 if (is_array($fields_label) && count($fields_label) > 1) {
2240 foreach ($fields_label as $field_toshow) {
2242 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
2243 if (!empty($obj->$field_toshow)) {
2244 $translabel = $outputlangs->trans($obj->$field_toshow);
2246 if ($translabel != $obj->$field_toshow) {
2247 $value .=
dol_trunc($translabel, 24) .
' ';
2249 $value .= $obj->$field_toshow .
' ';
2255 $tmppropname = $InfoFieldList[1];
2257 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2258 $translabel = $outputlangs->trans($obj->$tmppropname);
2260 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2263 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2268 $obj = $this->db->fetch_object($resql);
2270 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2272 $result =
$c->fetch($obj->rowid);
2274 $ways =
$c->print_all_ways();
2275 foreach ($ways as $way) {
2276 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
2280 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2283 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2285 } elseif ($type ==
'radio') {
2286 if ($required && !isset($param[
'options'][$value])) {
2287 $outputlangs->load(
'errors');
2288 $value =
'<span class="opacitymedium">'.$outputlangs->trans(
'ErrorNoValueForRadioType').
'</span>';
2290 if (isset($param[
'options'][$value])) {
2291 $value = $outputlangs->trans($param[
'options'][$value]);
2296 } elseif ($type ==
'checkbox') {
2297 $value_arr = explode(
',', $value);
2300 if (is_array($value_arr)) {
2301 foreach ($value_arr as $keyval => $valueval) {
2302 if (!empty($valueval)) {
2303 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2307 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2308 } elseif ($type ==
'chkbxlst') {
2309 $value_arr = explode(
',', $value);
2311 $param_list = array_keys($param[
'options']);
2312 $InfoFieldList = explode(
":", $param_list[0]);
2314 $selectkey =
"rowid";
2317 if (count($InfoFieldList) >= 3) {
2318 $selectkey = $InfoFieldList[2];
2319 $keyList = $InfoFieldList[2].
' as rowid';
2322 $fields_label = explode(
'|', $InfoFieldList[1]);
2323 if (is_array($fields_label)) {
2325 $keyList .= implode(
', ', $fields_label);
2328 $filter_categorie =
false;
2329 if (count($InfoFieldList) > 5) {
2330 if ($InfoFieldList[0] ==
'categorie') {
2331 $filter_categorie =
true;
2335 $sql =
"SELECT ".$keyList;
2336 $sql .=
" FROM ".$this->db->prefix().$InfoFieldList[0];
2337 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2343 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
2344 $resql = $this->db->query($sql);
2346 if (!$filter_categorie) {
2349 while ($obj = $this->db->fetch_object($resql)) {
2351 $fields_label = explode(
'|', $InfoFieldList[1]);
2352 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2353 if (is_array($fields_label) && count($fields_label) > 1) {
2354 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">';
2355 foreach ($fields_label as $field_toshow) {
2357 if (!empty($obj->$field_toshow)) {
2358 $translabel = $outputlangs->trans($obj->$field_toshow);
2360 if ($translabel != $field_toshow) {
2361 $label .=
' '.dol_trunc($translabel, 18);
2363 $label .=
' '.$obj->$field_toshow;
2367 $toprint[] = $label;
2370 if (!empty($obj->{$InfoFieldList[1]})) {
2371 $translabel = $outputlangs->trans($obj->{$InfoFieldList[1]});
2373 if ($translabel != $obj->{$InfoFieldList[1]}) {
2374 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.dol_trunc($translabel, 18).
'</li>';
2376 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$obj->{$InfoFieldList[1]}.
'</li>';
2382 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2385 while ($obj = $this->db->fetch_object($resql)) {
2386 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2388 $c->fetch($obj->rowid);
2389 $ways =
$c->print_all_ways();
2390 foreach ($ways as $way) {
2391 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
2396 if (!empty($toprint)) {
2397 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2400 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2402 } elseif ($type ==
'link') {
2407 $param_list = array_keys($param[
'options']);
2409 $InfoFieldList = explode(
":", $param_list[0]);
2410 $classname = $InfoFieldList[0];
2411 $classpath = $InfoFieldList[1];
2412 if (!empty($classpath)) {
2414 if (!$classname || !class_exists($classname)) {
2417 dol_syslog(
'Extrafields::showOutputField the class '.$classname.
' of the link field '.$key.
' could not be loaded from '.$classpath.
', check the extrafield definition', LOG_WARNING);
2419 if ($classname && class_exists($classname)) {
2420 $tmpobject =
new $classname($this->db);
2421 '@phan-var-force CommonObject $tmpobject';
2422 $tmpobject->fetch($value);
2424 if (get_class($tmpobject) ==
'Categorie') {
2426 $color = $tmpobject->color;
2427 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2428 $sfortag .= $tmpobject->getNomUrl(3);
2429 $sfortag .=
'</span>';
2432 $value = $tmpobject->getNomUrl(3);
2436 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2437 return 'Error bad setup of extrafield';
2440 } elseif ($type ==
'point') {
2441 if (!empty($value)) {
2442 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2444 $value = $dolgeophp->getXYString($value);
2448 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2449 if (!empty($value)) {
2450 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2452 $value = $dolgeophp->getPointString($value);
2456 } elseif ($type ==
'text') {
2457 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2458 } elseif ($type ==
'html') {
2460 } elseif ($type ==
'password') {
2461 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2462 } elseif ($type ==
'stars') {
2463 $objectid = (int)
$object->id;
2464 $nbstars = (int) $value;
2465 if ($showValueInsteadOfInputField == 1) {
2466 $value =
'<span style="display:none;" id="'.$key.$object->id.
'">'.
dol_escape_htmltag($value).
'</span>';
2468 $value =
'<input type="hidden" class="flat" name="'.$key.
'" id="'.$key.$objectid.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2471 $value .=
'<div class="star-selection" id="'.$key.$objectid.
'_selection">';
2473 while ($i <= $size) {
2474 $value .=
'<span class="star'.($i <= $nbstars ?
' active' :
'').
'" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2479 $(document).ready(function() { /* extrafields.class.php 2 */
2480 let container = $("#'.$key.$objectid.
'_selection");
2481 let selectedStars = parseInt($("#'.$key.$objectid.
'").val() || $("#'.$key.$objectid.
'").text()) || 0;
2483 if ($showValueInsteadOfInputField == 0) {
2485 container.find(".star").on("mouseover", function() {
2486 console.log("Mouse over a star");
2487 let selectedStar = $(this).data("value");
2488 container.find(".star").each(function() {
2489 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2492 container.on("mouseout", function() {
2493 console.log("Mouse out of star");
2494 container.find(".star").each(function() {
2495 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2498 container.find(".star").off("click").on("click", function() {
2499 console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
2500 selectedStars = $(this).data("value");
2501 if (selectedStars == 1 && $("#'.$key.$objectid.
'").val() == 1) {
2504 container.find("#'.$key.$objectid.
'").val(selectedStars);
2505 container.find(".star").each(function() {
2506 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2509 url: "'.DOL_URL_ROOT.
'/core/ajax/updateextrafield.php",
2513 objectId:
'.((int) $objectid).',
2514 field: \
''.dol_escape_js($key).
'\',
2515 value: selectedStars,
2516 token: \
''.newToken().
'\'
2518 success:
function(response) {
2519 var res = JSON.parse(response);
2520 console[res.status ===
"success" ?
"log" :
"error"](res.message);
2522 error:
function(xhr,
status, error) {
2523 console.log(
"Ajax request failed while updating '.$key.':", error);
2532 $showsize = round((float) $size);
2533 if ($showsize > 48) {
2538 //print $type.'-
'.$size;