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.
"',
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;
1504 $filter_categorie =
false;
1505 if (count($InfoFieldList) > 5) {
1506 if ($InfoFieldList[0] ==
'categorie') {
1507 $filter_categorie =
true;
1511 if (!$filter_categorie) {
1512 $fields_label = explode(
'|', $InfoFieldList[1]);
1513 if (is_array($fields_label)) {
1515 $keyList .= implode(
', ', $fields_label);
1521 $sql =
"SELECT ".$keyList;
1522 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1525 if (!empty($InfoFieldList[4])) {
1527 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1528 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1532 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1533 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1537 if (strpos($InfoFieldList[4],
'$MODE$') !==
false) {
1538 $InfoFieldList[4] = str_replace(
'$MODE$', preg_replace(
'/[^a-z0-9_]/i',
'', (
string) $mode), $InfoFieldList[4]);
1542 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1543 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1544 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1548 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1549 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1551 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1552 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1554 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1560 preg_match_all(
'/\$(.*?)\$/', $InfoFieldList[4], $tags);
1561 foreach ($tags[0] as $keytag => $valuetag) {
1562 $property = preg_replace(
'/[^a-z0-9_]/',
'', strtolower($tags[1][$keytag]));
1563 if (strpos($InfoFieldList[4], $valuetag) !==
false && property_exists(
$object, $property) && !empty(
$object->$property)) {
1564 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->$property, $InfoFieldList[4]);
1566 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1573 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1574 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1575 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1581 $sqlwhere .=
' WHERE 1=1';
1598 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1599 $sqlwhere .=
' AND entity = '.((int)
$conf->entity);
1603 $sql .= $this->db->order(implode(
', ', $fields_label));
1604 $sql .=
' LIMIT ' .
getDolGlobalInt(
'MAIN_EXTRAFIELDS_LIMIT_SELLIST_SQL', 1000);
1607 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1608 $resql = $this->db->query($sql);
1610 $out .=
'<option value="0"> </option>';
1611 $num = $this->db->num_rows($resql);
1615 $obj = $this->db->fetch_object($resql);
1617 $nameFields = $InfoFieldList[1];
1619 $nameFields = preg_replace(
'/[a-z_]+\([^\)]*\) as ([\w]+)/i',
'\1', $nameFields);
1621 $nameFields = preg_replace(
'/[^0-9a-z_\.\|]/i',
'', $nameFields);
1625 $fields_label = explode(
'|', $nameFields);
1626 if (is_array($fields_label) && count($fields_label) > 1) {
1628 foreach ($fields_label as $field_toshow) {
1629 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
1630 $labeltoshow .= $obj->$field_toshow.
' ';
1633 $labeltoshow = $obj->$nameFields;
1636 if ($value == $obj->rowid) {
1638 foreach ($fields_label as $field_toshow) {
1639 $translabel = $langs->trans($obj->$field_toshow);
1640 $labeltoshow = $translabel.
' ';
1643 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1646 $translabel = $langs->trans($obj->$nameFields);
1647 $labeltoshow = $translabel;
1649 if (empty($labeltoshow)) {
1650 $labeltoshow =
'(not defined)';
1653 if (!empty($InfoFieldList[3]) && $parentField) {
1655 $parentField = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $parentField);
1656 $parent = $parentName.
':'.$obj->{$parentField};
1659 $out .=
'<option value="'.$obj->rowid.
'"';
1660 $out .= ($value == $obj->rowid ?
' selected' :
'');
1661 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1662 $out .=
'>'.$labeltoshow.
'</option>';
1667 $this->db->free($resql);
1669 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1672 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1673 $categcode = $InfoFieldList[5];
1674 if (is_numeric($categcode)) {
1675 $categcode = Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]];
1677 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1678 $out .=
'<option value="0"> </option>';
1679 if (is_array($data)) {
1680 foreach ($data as $data_key => $data_value) {
1681 $out .=
'<option value="'.$data_key.
'"';
1682 $out .= ($value == $data_key ?
' selected' :
'');
1683 $out .=
'>'.$data_value.
'</option>';
1688 $out .=
'</select>';
1690 } elseif ($type ==
'checkbox') {
1691 $value_arr = $value;
1692 if (!is_array($value)) {
1693 $value_arr = explode(
',', $value);
1695 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0,
'', 0,
'100%');
1696 } elseif ($type ==
'radio') {
1698 foreach ($param[
'options'] as $keyopt => $val) {
1699 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1700 $out .=
' value="'.$keyopt.
'"';
1701 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1702 $out .= ($value == $keyopt ?
'checked' :
'');
1703 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1705 } elseif ($type ==
'chkbxlst') {
1706 if (is_array($value)) {
1707 $value_arr = $value;
1709 $value_arr = explode(
',', $value);
1712 if (is_array($param[
'options'])) {
1713 $tmpparamoptions = array_keys($param[
'options']);
1714 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1716 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1728 if (! empty($InfoFieldList[4])) {
1730 $parenthesisopen = 0;
1731 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1732 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1735 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1740 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1741 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1743 $InfoFieldList[4] = $tmpbefore;
1744 if ($tmpafter !==
'') {
1745 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1750 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1751 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1761 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1763 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1764 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1765 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1767 $keyList = $InfoFieldList[2].
' as rowid';
1770 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1771 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1772 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1773 $keyList .=
', main.'.$parentField;
1775 $keyList .=
', '.$parentField;
1779 $filter_categorie =
false;
1780 if (count($InfoFieldList) > 5) {
1781 if ($InfoFieldList[0] ==
'categorie') {
1782 $filter_categorie =
true;
1786 if (!$filter_categorie) {
1787 $fields_label = explode(
'|', $InfoFieldList[1]);
1788 if (is_array($fields_label)) {
1790 $keyList .= implode(
', ', $fields_label);
1794 $sql =
"SELECT ".$keyList;
1795 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1798 if (!empty($InfoFieldList[4])) {
1800 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1801 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1804 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1805 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1809 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1810 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1811 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1815 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1816 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1818 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1819 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1821 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1826 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1827 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1828 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1834 $sqlwhere .=
' WHERE 1=1';
1851 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1852 $sqlwhere .=
" AND entity = ".((int)
$conf->entity);
1858 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1860 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
1861 $resql = $this->db->query($sql);
1863 $num = $this->db->num_rows($resql);
1870 $obj = $this->db->fetch_object($resql);
1874 $fields_label = explode(
'|', $InfoFieldList[1]);
1875 if (is_array($fields_label)) {
1877 foreach ($fields_label as $field_toshow) {
1878 $labeltoshow .= $obj->$field_toshow.
' ';
1881 $labeltoshow = $obj->{$InfoFieldList[1]};
1883 $labeltoshow =
dol_trunc($labeltoshow, 45);
1885 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1887 foreach ($fields_label as $field_toshow) {
1888 $translabel = $langs->trans($obj->$field_toshow);
1889 if ($translabel != $obj->$field_toshow) {
1890 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
1892 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
1895 $data[$obj->rowid] = $labeltoshow;
1898 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1899 if ($translabel != $obj->{$InfoFieldList[1]}) {
1900 $labeltoshow =
dol_trunc($translabel, 18);
1902 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
1905 if (empty($labeltoshow)) {
1906 $labeltoshow =
'(not defined)';
1909 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1910 $data[$obj->rowid] = $labeltoshow;
1913 if (!empty($InfoFieldList[3]) && $parentField) {
1914 $parent = $parentName.
':'.$obj->{$parentField};
1917 $data[$obj->rowid] = $labeltoshow;
1922 $this->db->free($resql);
1924 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
1926 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1929 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1930 $categcode = $InfoFieldList[5];
1931 if (is_numeric($categcode)) {
1932 $categcode = Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]];
1934 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1935 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
1938 } elseif ($type ==
'link') {
1939 $param_list = array_keys($param[
'options']);
1946 $showempty = (($required && $default !=
'') ? 0 : 1);
1948 $tmparray = explode(
':', $param_list[0]);
1950 $element = $extrafieldsobjectkey;
1951 if ($element ==
'socpeople') {
1952 $element =
'contact';
1953 } elseif ($element ==
'projet') {
1954 $element =
'project';
1958 $objectdesc = $tmparray[0];
1959 $objectfield = $element.
':options_'.$key;
1961 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
1962 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
1963 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
1967 if (!empty($value)) {
1968 $tmparray = $dolgeophp->parseGeoString($value);
1969 $geojson = $tmparray[
'geojson'];
1970 $centroidjson = $tmparray[
'centroidjson'];
1972 if (!preg_match(
'/search_/', $keyprefix)) {
1973 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
1975 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
1980 } elseif ($type ==
'password') {
1982 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
1983 $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 :
'').
'>';
1984 } elseif ($type ==
'stars') {
1985 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
1986 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
1988 while ($i <= $size) {
1989 $out .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
1994 jQuery(function($) { /* extrafields.class.php 1 */
1995 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
1996 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
1997 container.find(".star").each(function() {
1998 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2000 container.find(".star").on("mouseover", function() {
2001 let selectedStar = $(this).data("value");
2002 container.find(".star").each(function() {
2003 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2006 container.on("mouseout", function() {
2007 container.find(".star").each(function() {
2008 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2011 container.find(".star").off("click").on("click", function() {
2012 selectedStars = $(this).data("value");
2013 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
2016 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
2017 container.find(".star").each(function() {
2018 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2024 if (!empty($hidden)) {
2025 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
2030 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2031 $out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey,
null,
$object);
2055 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null,
$object =
null)
2057 global
$conf, $langs;
2059 if (is_null($outputlangs) || !is_object($outputlangs)) {
2060 $outputlangs = $langs;
2063 if (empty($extrafieldsobjectkey)) {
2064 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
2065 return 'BadValueForParamExtraFieldsObjectKey';
2068 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
2069 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2070 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
2071 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
2072 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
2073 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
2074 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
2075 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
2076 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
2077 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
2078 $list = (string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
2079 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
2080 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
2081 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
2084 $showValueInsteadOfInputField = 0;
2086 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2087 $showValueInsteadOfInputField = 1;
2090 $hidden = (empty($list) ? 1 : 0);
2098 if ($type ==
'date') {
2100 if ($value !==
'') {
2103 } elseif ($type ==
'datetime') {
2105 if ($value !==
'') {
2108 } elseif ($type ==
'duration') {
2110 if ($value !==
'') {
2111 $value = intval($value);
2114 } elseif ($type ==
'datetimegmt') {
2116 if ($value !==
'') {
2119 } elseif ($type ==
'int') {
2121 } elseif ($type ==
'double') {
2122 if (!empty($value)) {
2126 $value =
price($value, 0, $outputlangs, 0, 0, -2,
'');
2128 } elseif ($type ==
'boolean') {
2130 if (!empty($value)) {
2131 $checked =
' checked ';
2134 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
2136 $value =
yn($value ? 1 : 0);
2138 } elseif ($type ==
'mail' || $type ==
'email') {
2140 } elseif ($type ==
'ip') {
2142 } elseif ($type ==
'icon') {
2143 $value =
'<span class="'.$value.
'"></span>';
2144 } elseif ($type ==
'url') {
2146 } elseif ($type ==
'phone') {
2148 } elseif ($type ==
'price') {
2150 if ($value || $value ==
'0') {
2151 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol(
$conf->currency);
2153 } elseif ($type ==
'pricecy') {
2154 $currency =
$conf->currency;
2155 if (!empty($value)) {
2157 $pricetmp = explode(
':', $value);
2158 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
2159 $value = $pricetmp[0];
2161 if ($value || $value ==
'0') {
2162 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
2164 } elseif ($type ==
'select') {
2165 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2166 if (($pos = strpos($valstr,
"|")) !==
false) {
2167 $valstr = substr($valstr, 0, $pos);
2169 if ($langfile && $valstr) {
2170 $value = $outputlangs->trans($valstr);
2174 } elseif ($type ==
'sellist') {
2175 $param_list = array_keys($param[
'options']);
2176 $InfoFieldList = explode(
":", $param_list[0]);
2178 $selectkey =
"rowid";
2181 if (count($InfoFieldList) >= 3) {
2182 $selectkey = $InfoFieldList[2];
2183 $keyList = $InfoFieldList[2].
' as rowid';
2186 $fields_label = explode(
'|', $InfoFieldList[1]);
2187 if (is_array($fields_label)) {
2189 $keyList .= implode(
', ', $fields_label);
2192 $filter_categorie =
false;
2193 if (count($InfoFieldList) > 5) {
2194 if ($InfoFieldList[0] ==
'categorie') {
2195 $filter_categorie =
true;
2199 $sql =
"SELECT ".$keyList;
2200 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
2201 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2204 if ($selectkey ==
'rowid' && empty($value)) {
2205 $sql .=
" WHERE ".$selectkey.
" = 0";
2206 } elseif ($selectkey ==
'rowid') {
2207 $sql .=
" WHERE ".$selectkey.
" = ".((int) $value);
2209 $sql .=
" WHERE ".$selectkey.
" = '".$this->db->escape($value).
"'";
2214 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2215 $resql = $this->db->query($sql);
2217 if (!$filter_categorie) {
2220 $obj = $this->db->fetch_object($resql);
2223 $fields_label = explode(
'|', $InfoFieldList[1]);
2225 if (is_array($fields_label) && count($fields_label) > 1) {
2226 foreach ($fields_label as $field_toshow) {
2228 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
2229 if (!empty($obj->$field_toshow)) {
2230 $translabel = $outputlangs->trans($obj->$field_toshow);
2232 if ($translabel != $obj->$field_toshow) {
2233 $value .=
dol_trunc($translabel, 24) .
' ';
2235 $value .= $obj->$field_toshow .
' ';
2241 $tmppropname = $InfoFieldList[1];
2243 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2244 $translabel = $outputlangs->trans($obj->$tmppropname);
2246 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2249 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2254 $obj = $this->db->fetch_object($resql);
2256 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2258 $result =
$c->fetch($obj->rowid);
2260 $ways =
$c->print_all_ways();
2261 foreach ($ways as $way) {
2262 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
2266 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2269 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2271 } elseif ($type ==
'radio') {
2272 if ($required && !isset($param[
'options'][$value])) {
2273 $outputlangs->load(
'errors');
2274 $value =
'<span class="opacitymedium">'.$outputlangs->trans(
'ErrorNoValueForRadioType').
'</span>';
2276 if (isset($param[
'options'][$value])) {
2277 $value = $outputlangs->trans($param[
'options'][$value]);
2282 } elseif ($type ==
'checkbox') {
2283 $value_arr = explode(
',', $value);
2286 if (is_array($value_arr)) {
2287 foreach ($value_arr as $keyval => $valueval) {
2288 if (!empty($valueval)) {
2289 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2293 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2294 } elseif ($type ==
'chkbxlst') {
2295 $value_arr = explode(
',', $value);
2297 $param_list = array_keys($param[
'options']);
2298 $InfoFieldList = explode(
":", $param_list[0]);
2300 $selectkey =
"rowid";
2303 if (count($InfoFieldList) >= 3) {
2304 $selectkey = $InfoFieldList[2];
2305 $keyList = $InfoFieldList[2].
' as rowid';
2308 $fields_label = explode(
'|', $InfoFieldList[1]);
2309 if (is_array($fields_label)) {
2311 $keyList .= implode(
', ', $fields_label);
2314 $filter_categorie =
false;
2315 if (count($InfoFieldList) > 5) {
2316 if ($InfoFieldList[0] ==
'categorie') {
2317 $filter_categorie =
true;
2321 $sql =
"SELECT ".$keyList;
2322 $sql .=
" FROM ".$this->db->prefix().$InfoFieldList[0];
2323 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2329 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
2330 $resql = $this->db->query($sql);
2332 if (!$filter_categorie) {
2335 while ($obj = $this->db->fetch_object($resql)) {
2337 $fields_label = explode(
'|', $InfoFieldList[1]);
2338 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2339 if (is_array($fields_label) && count($fields_label) > 1) {
2340 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">';
2341 foreach ($fields_label as $field_toshow) {
2343 if (!empty($obj->$field_toshow)) {
2344 $translabel = $outputlangs->trans($obj->$field_toshow);
2346 if ($translabel != $field_toshow) {
2347 $label .=
' '.dol_trunc($translabel, 18);
2349 $label .=
' '.$obj->$field_toshow;
2353 $toprint[] = $label;
2356 if (!empty($obj->{$InfoFieldList[1]})) {
2357 $translabel = $outputlangs->trans($obj->{$InfoFieldList[1]});
2359 if ($translabel != $obj->{$InfoFieldList[1]}) {
2360 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.dol_trunc($translabel, 18).
'</li>';
2362 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$obj->{$InfoFieldList[1]}.
'</li>';
2368 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2371 while ($obj = $this->db->fetch_object($resql)) {
2372 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2374 $c->fetch($obj->rowid);
2375 $ways =
$c->print_all_ways();
2376 foreach ($ways as $way) {
2377 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
2382 if (!empty($toprint)) {
2383 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2386 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2388 } elseif ($type ==
'link') {
2393 $param_list = array_keys($param[
'options']);
2395 $InfoFieldList = explode(
":", $param_list[0]);
2396 $classname = $InfoFieldList[0];
2397 $classpath = $InfoFieldList[1];
2398 if (!empty($classpath)) {
2400 if ($classname && class_exists($classname)) {
2401 $tmpobject =
new $classname($this->db);
2402 '@phan-var-force CommonObject $tmpobject';
2403 $tmpobject->fetch($value);
2405 if (get_class($tmpobject) ==
'Categorie') {
2407 $color = $tmpobject->color;
2408 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2409 $sfortag .= $tmpobject->getNomUrl(3);
2410 $sfortag .=
'</span>';
2413 $value = $tmpobject->getNomUrl(3);
2417 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2418 return 'Error bad setup of extrafield';
2421 } elseif ($type ==
'point') {
2422 if (!empty($value)) {
2423 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2425 $value = $dolgeophp->getXYString($value);
2429 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2430 if (!empty($value)) {
2431 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2433 $value = $dolgeophp->getPointString($value);
2437 } elseif ($type ==
'text') {
2438 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2439 } elseif ($type ==
'html') {
2441 } elseif ($type ==
'password') {
2442 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2443 } elseif ($type ==
'stars') {
2444 $objectid = (int)
$object->id;
2445 $nbstars = (int) $value;
2446 if ($showValueInsteadOfInputField == 1) {
2447 $value =
'<span style="display:none;" id="'.$key.$object->id.
'">'.
dol_escape_htmltag($value).
'</span>';
2449 $value =
'<input type="hidden" class="flat" name="'.$key.
'" id="'.$key.$objectid.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2452 $value .=
'<div class="star-selection" id="'.$key.$objectid.
'_selection">';
2454 while ($i <= $size) {
2455 $value .=
'<span class="star'.($i <= $nbstars ?
' active' :
'').
'" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2460 $(document).ready(function() { /* extrafields.class.php 2 */
2461 let container = $("#'.$key.$objectid.
'_selection");
2462 let selectedStars = parseInt($("#'.$key.$objectid.
'").val() || $("#'.$key.$objectid.
'").text()) || 0;
2464 if ($showValueInsteadOfInputField == 0) {
2466 container.find(".star").on("mouseover", function() {
2467 console.log("Mouse over a star");
2468 let selectedStar = $(this).data("value");
2469 container.find(".star").each(function() {
2470 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2473 container.on("mouseout", function() {
2474 console.log("Mouse out of star");
2475 container.find(".star").each(function() {
2476 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2479 container.find(".star").off("click").on("click", function() {
2480 console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
2481 selectedStars = $(this).data("value");
2482 if (selectedStars == 1 && $("#'.$key.$objectid.
'").val() == 1) {
2485 container.find("#'.$key.$objectid.
'").val(selectedStars);
2486 container.find(".star").each(function() {
2487 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2490 url: "'.DOL_URL_ROOT.
'/core/ajax/updateextrafield.php",
2494 objectId:
'.((int) $objectid).',
2495 field: \
''.dol_escape_js($key).
'\',
2496 value: selectedStars,
2497 token: \
''.newToken().
'\'
2499 success:
function(response) {
2500 var res = JSON.parse(response);
2501 console[res.status ===
"success" ?
"log" :
"error"](res.message);
2503 error:
function(xhr,
status, error) {
2504 console.log(
"Ajax request failed while updating '.$key.':", error);
2513 $showsize = round((float) $size);
2514 if ($showsize > 48) {
2519 //print $type.'-
'.$size;