1064 global
$conf,$hookmanager;
1066 if (empty($elementtype)) {
1067 dol_syslog(__METHOD__.
'::empty elementtype', LOG_DEBUG);
1071 if ($elementtype ==
'thirdparty') {
1072 $elementtype =
'societe';
1074 if ($elementtype ==
'contact') {
1075 $elementtype =
'socpeople';
1077 if ($elementtype ==
'order_supplier') {
1078 $elementtype =
'commande_fournisseur';
1081 if ($elementtype !=
'all' && isset($this->attributes[$elementtype]) && $this->attributes[$elementtype][
'loaded'] == 1 && !$forceload && isset($this->attributes[$elementtype][
'label'])) {
1082 return $this->attributes[$elementtype][
'label'];
1085 $array_name_label = array();
1088 $sql =
"SELECT rowid, name, label, type, size, elementtype, fieldunique, fieldrequired, param, pos, alwayseditable, emptyonclone, perms, langs, list, printable, showintooltip, totalizable, fielddefault, fieldcomputed, entity, enabled, help, aiprompt";
1089 $sql .=
" , css, cssview, csslist, personal_data";
1090 $sql .=
" FROM ".$this->db->prefix().
"extrafields";
1092 if ($elementtype && $elementtype !=
'all') {
1093 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1095 if ($attrname && $elementtype && $elementtype !=
'all') {
1096 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1098 $sql .=
" ORDER BY pos";
1100 $resql = $this->db->query($sql);
1103 if ($this->db->num_rows($resql)) {
1104 while ($tab = $this->db->fetch_object($resql)) {
1105 if ($tab->entity != 0 && $tab->entity !=
$conf->entity) {
1107 if ($tab->fieldrequired && is_null($tab->fielddefault)) {
1108 $this->attributes[$tab->elementtype][
'mandatoryfieldsofotherentities'][$tab->name] = $tab->type;
1114 if ($tab->type !=
'separate') {
1115 $array_name_label[$tab->name] = $tab->label;
1117 $array_name_label[$tab->name] = $tab->type;
1121 $this->attributes[$tab->elementtype][
'type'][$tab->name] = $tab->type;
1122 $this->attributes[$tab->elementtype][
'label'][$tab->name] = $tab->label;
1123 $this->attributes[$tab->elementtype][
'size'][$tab->name] = $tab->size;
1124 $this->attributes[$tab->elementtype][
'elementtype'][$tab->name] = $tab->elementtype;
1125 $this->attributes[$tab->elementtype][
'default'][$tab->name] = $tab->fielddefault;
1126 $this->attributes[$tab->elementtype][
'computed'][$tab->name] = $tab->fieldcomputed;
1127 $this->attributes[$tab->elementtype][
'unique'][$tab->name] = $tab->fieldunique;
1128 $this->attributes[$tab->elementtype][
'required'][$tab->name] = $tab->fieldrequired;
1129 $this->attributes[$tab->elementtype][
'param'][$tab->name] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1130 $this->attributes[$tab->elementtype][
'pos'][$tab->name] = $tab->pos;
1131 $this->attributes[$tab->elementtype][
'alwayseditable'][$tab->name] = $tab->alwayseditable;
1132 $this->attributes[$tab->elementtype][
'emptyonclone'][$tab->name] = $tab->emptyonclone;
1133 $this->attributes[$tab->elementtype][
'perms'][$tab->name] = $tab->perms;
1134 $this->attributes[$tab->elementtype][
'langfile'][$tab->name] = $tab->langs;
1135 $this->attributes[$tab->elementtype][
'list'][$tab->name] = $tab->list;
1136 $this->attributes[$tab->elementtype][
'printable'][$tab->name] = $tab->printable;
1137 $this->attributes[$tab->elementtype][
'showintooltip'][$tab->name] = $tab->showintooltip;
1138 $this->attributes[$tab->elementtype][
'totalizable'][$tab->name] = ($tab->totalizable ? 1 : 0);
1139 $this->attributes[$tab->elementtype][
'entityid'][$tab->name] = $tab->entity;
1140 $this->attributes[$tab->elementtype][
'enabled'][$tab->name] = $tab->enabled;
1141 $this->attributes[$tab->elementtype][
'help'][$tab->name] = $tab->help;
1142 $this->attributes[$tab->elementtype][
'aiprompt'][$tab->name] = $tab->aiprompt;
1143 $this->attributes[$tab->elementtype][
'css'][$tab->name] = $tab->css;
1144 $this->attributes[$tab->elementtype][
'cssview'][$tab->name] = $tab->cssview;
1145 $this->attributes[$tab->elementtype][
'csslist'][$tab->name] = $tab->csslist;
1146 $this->attributes[$tab->elementtype][
'personal_data'][$tab->name] = $tab->personal_data;
1148 $this->attributes[$tab->elementtype][
'loaded'] = 1;
1153 $this->attributes[$elementtype][
'loaded'] = 1;
1154 $this->attributes[$elementtype][
'count'] = $count;
1157 $this->error = $this->db->lasterror();
1158 dol_syslog(get_class($this).
"::fetch_name_optionals_label ".$this->error, LOG_ERR);
1162 if (is_object($hookmanager)) {
1163 $parameters = array(
1164 'elementtype' => $elementtype,
1165 'attrname' => $attrname,
1166 'forceload' => $forceload,
1168 $reshook = $hookmanager->executeHooks(
'completeFetchNameOptionalsLabel', $parameters, $this);
1169 if ($reshook > 0 && is_array($hookmanager->resArray)) {
1171 foreach ($hookmanager->resArray as $key => $val) {
1172 $array_name_label[$key] = $val;
1177 return $array_name_label;
1197 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'',
$object = 0, $extrafieldsobjectkey =
'', $mode = 0, $filteronparentvalue = 0)
1199 global
$conf, $langs, $form, $hookmanager;
1201 if (!is_object($form)) {
1202 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
1203 $form =
new Form($this->db);
1207 $morecss =
'maxwidth125';
1210 $parameters = array(
1213 'moreparam' => $moreparam,
1214 'keysuffix' => $keysuffix,
1215 'keyprefix' => $keyprefix,
1216 'morecss' => $morecss,
1218 'extrafieldsobjectkey' => $extrafieldsobjectkey,
1223 $reshook = $hookmanager->executeHooks(
'showInputExtraField', $parameters, $this, $action);
1225 return $hookmanager->resPrint;
1232 if (!preg_match(
'/options_$/', $keyprefix)) {
1233 $keyprefix .=
'options_';
1236 if (empty($extrafieldsobjectkey)) {
1237 dol_syslog(get_class($this).
'::showInputField extrafieldsobjectkey required', LOG_ERR);
1238 return 'BadValueForParamExtraFieldsObjectKey';
1241 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1242 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1243 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1244 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1245 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1246 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1247 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1248 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1249 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
1250 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1251 $list = (
string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
1252 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
1253 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1254 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
1255 $hidden = (empty($list) ? 1 : 0);
1261 if (!preg_match(
'/^search_/', $keyprefix)) {
1262 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
1270 if (empty($morecss)) {
1272 if ($type ==
'date') {
1273 $morecss =
'minwidth100imp';
1274 } elseif ($type ==
'datetime' || $type ==
'datetimegmt' || $type ==
'link') {
1275 $morecss =
'minwidth200imp';
1276 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
1277 $morecss =
'maxwidth75';
1278 } elseif ($type ==
'password') {
1279 $morecss =
'maxwidth100';
1280 } elseif ($type ==
'url') {
1281 $morecss =
'minwidth400';
1282 } elseif ($type ==
'boolean') {
1284 } elseif ($type ==
'radio') {
1285 $morecss =
'width25';
1287 if (empty($size) || round((
float) $size) < 12) {
1288 $morecss =
'minwidth100';
1289 } elseif (round((
float) $size) <= 48) {
1290 $morecss =
'minwidth200';
1292 $morecss =
'minwidth400';
1296 if (!empty($this->attributes[$extrafieldsobjectkey][
'css'][$key])) {
1297 $morecss = $this->attributes[$extrafieldsobjectkey][
'css'][$key];
1301 if (in_array($type, array(
'date'))) {
1302 $tmp = explode(
',', $size);
1307 if (!$required && $value ==
'') {
1314 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1315 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1317 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1318 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"));
1319 $out .=
'</div><div class="nowrap">';
1320 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"));
1321 $out .=
'</div></div>';
1325 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required ? 0 : 2,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1327 } elseif (in_array($type, array(
'datetime',
'datetimegmt'))) {
1328 $tmp = explode(
',', $size);
1333 if (!$required && $value ==
'') {
1340 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1341 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1343 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1344 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"),
'tzuserrel');
1345 $out .=
'</div><div class="nowrap">';
1346 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
1347 $out .=
'</div></div>';
1351 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required ? 0 : 2,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1353 } elseif (in_array($type, array(
'int',
'integer'))) {
1354 $tmp = explode(
',', $size);
1356 $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 :
'').
'>';
1357 } elseif (preg_match(
'/varchar/', $type)) {
1358 $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 :
'').
'>';
1359 } elseif (in_array($type, array(
'email',
'mail',
'ip',
'phone',
'url'))) {
1360 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1361 } elseif ($type ==
'icon') {
1367 $out .=
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat '.$morecss.
' maxwidthonsmartphone"';
1368 $out .=
' name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1371 $options =
"{ title: '<b>".$langs->trans(
"IconFieldSelector").
"</b>', placement: 'right', showFooter: false, templates: {";
1372 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
1373 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
1376 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
1377 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"".$langs->trans(
"TypeToFilter").
"\" />',";
1378 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
1379 $options .=
" <div class=\"arrow\" ></div>";
1380 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
1381 $options .=
" <div class=\"popover-content \" ></div>";
1382 $options .=
"</div>'}}";
1383 $out .=
"$('#".$keyprefix.$key.$keysuffix.
"').iconpicker(".$options.
");";
1384 $out .=
'</script>';
1386 } elseif ($type ==
'text') {
1387 if (!preg_match(
'/search_/', $keyprefix)) {
1388 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1389 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1390 $out = (
string) $doleditor->Create(1);
1392 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1394 } elseif ($type ==
'html') {
1395 if (!preg_match(
'/search_/', $keyprefix)) {
1396 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1397 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
1398 $out = (
string) $doleditor->Create(1);
1400 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1402 } elseif ($type ==
'boolean') {
1405 if (!empty($value)) {
1406 $checked =
' checked value="1" ';
1408 $checked =
' value="1" ';
1410 $out =
'<input type="checkbox" class="flat valignmiddle'.($morecss ?
' '.$morecss :
'').
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1412 $out = $form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1, 1,
'width75 yesno');
1414 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_boolean" value="1">';
1415 } elseif ($type ==
'price') {
1416 if (!empty($value)) {
1417 $value =
price($value);
1419 $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).
'">';
1420 } elseif ($type ==
'pricecy') {
1421 $currency =
$conf->currency;
1422 if (!empty($value)) {
1424 $pricetmp = explode(
':', $value);
1425 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
1426 $value =
price($pricetmp[0]);
1428 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1429 $out .= $form->selectCurrency($currency, $keyprefix.$key.$keysuffix.
'currency_id');
1430 } elseif ($type ==
'duration') {
1431 $value = intval($value);
1432 $out = $form->select_duration($keyprefix . $key, $value, 0,
'text', 0, 1);
1433 } elseif ($type ==
'double') {
1434 if (!empty($value)) {
1435 $value =
price($value);
1437 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1438 } elseif ($type ==
'select') {
1442 foreach ($param[
'options'] as $okey => $val) {
1443 if ((
string) $okey ==
'') {
1447 $valarray = explode(
'|', $val);
1448 $val = $valarray[0];
1450 if ($langfile && $val) {
1451 $options[$okey] = $langs->trans($val);
1453 $options[$okey] = $val;
1456 $selected = array();
1457 if (!is_array($value)) {
1458 $selected = explode(
',', $value);
1461 $out .= $form->multiselectarray($keyprefix.$key.$keysuffix, $options, $selected, 0, 0, $morecss, 0, 0,
'',
'',
'', (
int) (!empty(
$conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
1464 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1465 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1468 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1469 $out .=
'<option value="0"> </option>';
1470 foreach ($param[
'options'] as $key2 => $val2) {
1471 if ((
string) $key2 ==
'') {
1474 $valarray = explode(
'|', $val2);
1475 $val2 = $valarray[0];
1477 if (!empty($valarray[1])) {
1478 $parent = $valarray[1];
1484 if ($filteronparentvalue && !empty($parent) && (
string) $value != (
string) $key2) {
1485 $tmpparent = explode(
':', $parent, 2);
1486 if (!empty($tmpparent[1]) && is_object(
$object)) {
1487 $parentvalue = isset(
$object->array_options[
'options_'.$tmpparent[0]]) ?
$object->array_options[
'options_'.$tmpparent[0]] :
'';
1488 if ((
string) $parentvalue !==
'' && (
string) $parentvalue !== (
string) $tmpparent[1]) {
1493 $out .=
'<option value="'.$key2.
'"';
1494 $out .= (((
string) $value == (
string) $key2) ?
' selected' :
'');
1495 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1497 if ($langfile && $val2) {
1498 $out .= $langs->trans($val2);
1502 $out .=
'</option>';
1504 $out .=
'</select>';
1506 } elseif ($type ==
'sellist') {
1508 if (!empty(
$conf->use_javascript_ajax)) {
1513 $(document).ready(function () {
1514 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1516 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1518 delay: 250, // wait 250 milliseconds before triggering the request
1519 data: function (params) {
1521 search: params.term,
1522 page: params.page || 1,
1523 objecttype: '".$extrafieldsobjectkey.
"',
1525 objectkey: '".$key.
"',
1535 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1536 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1537 $out .=
'</select>';
1539 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1540 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1545 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1546 if (is_array($param[
'options'])) {
1549 $tmpparamoptions = array_keys($param[
'options']);
1550 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1552 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1564 if (! empty($InfoFieldList[4])) {
1566 $parenthesisopen = 0;
1567 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1568 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1571 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1576 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1577 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1579 $InfoFieldList[4] = $tmpbefore;
1580 if ($tmpafter !==
'') {
1581 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1586 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1587 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1597 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1599 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1600 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1601 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1603 $keyList = $InfoFieldList[2].
' as rowid';
1606 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1607 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1608 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1609 $keyList .=
', main.'.$parentField;
1611 $keyList .=
', '.$parentField;
1615 $filter_categorie =
false;
1616 if (count($InfoFieldList) > 5) {
1617 if ($InfoFieldList[0] ==
'categorie') {
1618 $filter_categorie =
true;
1622 if (!$filter_categorie) {
1623 $fields_label = isset($InfoFieldList[1]) ? explode(
'|', $InfoFieldList[1]) : array();
1624 if (!empty($fields_label)) {
1626 $keyList .= implode(
', ', $fields_label);
1632 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
1633 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
1636 if (!empty($InfoFieldList[4])) {
1638 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1639 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1642 global $dolibarr_allow_unsecured_select_in_extrafields_filter;
1643 if (!empty($dolibarr_allow_unsecured_select_in_extrafields_filter)) {
1644 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1645 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1649 if (strpos($InfoFieldList[4],
'$MODE$') !==
false) {
1650 $InfoFieldList[4] = str_replace(
'$MODE$', preg_replace(
'/[^a-z0-9_]/i',
'', (
string) $mode), $InfoFieldList[4]);
1654 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1655 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1656 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1660 $word =
'#([a-zA-Z0-9._-]+):=:\$([A-Za-z0-9_]+)\$#';
1661 $InfoFieldList[4] = preg_replace($word,
'1:=:1', $InfoFieldList[4]);
1663 $word =
'#\$([A-Za-z0-9_]+)\$:=:([A-Za-z0-9._-]+)#';
1664 $InfoFieldList[4] = preg_replace($word,
'1:=:1', $InfoFieldList[4]);
1666 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1672 preg_match_all(
'/\$(.*?)\$/', $InfoFieldList[4], $tags);
1673 foreach ($tags[0] as $keytag => $valuetag) {
1674 $property = preg_replace(
'/[^a-z0-9_]/',
'', strtolower($tags[1][$keytag]));
1675 if (strpos($property,
'options_') === 0) {
1676 if (strpos($InfoFieldList[4], $valuetag) !==
false && isset(
$object->array_options[$property]) && !empty(
$object->array_options[$property])) {
1677 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->array_options[$property], $InfoFieldList[4]);
1679 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1682 if (strpos($InfoFieldList[4], $valuetag) !==
false && property_exists(
$object, $property) && !empty(
$object->$property)) {
1683 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->$property, $InfoFieldList[4]);
1685 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1693 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1694 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1695 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1701 $sqlwhere .=
' WHERE 1=1';
1718 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1719 $sqlwhere .=
' AND entity = '.((int)
$conf->entity);
1723 $sql .= $this->db->order(implode(
', ', $fields_label));
1724 $sql .=
' LIMIT ' .
getDolGlobalInt(
'MAIN_EXTRAFIELDS_LIMIT_SELLIST_SQL', 1000);
1727 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1728 $resql = $this->db->query($sql);
1730 $out .=
'<option value="0"> </option>';
1731 $num = $this->db->num_rows($resql);
1735 $obj = $this->db->fetch_object($resql);
1737 $nameFields = $InfoFieldList[1];
1739 $nameFields = preg_replace(
'/[a-z_]+\([^\)]*\) as ([\w]+)/i',
'\1', $nameFields);
1741 $nameFields = preg_replace(
'/[^0-9a-z_\.\|]/i',
'', $nameFields);
1745 $fields_label = explode(
'|', $nameFields);
1746 if (is_array($fields_label) && count($fields_label) > 1) {
1748 foreach ($fields_label as $field_toshow) {
1749 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
1750 $labeltoshow .= $obj->$field_toshow.
' ';
1753 $labeltoshow = $obj->$nameFields;
1756 if ($value == $obj->rowid) {
1758 foreach ($fields_label as $field_toshow) {
1759 $translabel = $langs->trans($obj->$field_toshow);
1760 $labeltoshow = $translabel.
' ';
1763 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1766 $translabel = $langs->trans($obj->$nameFields);
1767 $labeltoshow = $translabel;
1769 if (empty($labeltoshow)) {
1770 $labeltoshow =
'(not defined)';
1773 if (!empty($InfoFieldList[3]) && $parentField) {
1775 $parentField = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $parentField);
1776 $parent = $parentName.
':'.$obj->{$parentField};
1779 $out .=
'<option value="'.$obj->rowid.
'"';
1780 $out .= ($value == $obj->rowid ?
' selected' :
'');
1781 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1782 $out .=
'>'.$labeltoshow.
'</option>';
1787 $this->db->free($resql);
1789 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1792 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1793 $categcode = $InfoFieldList[5];
1794 if (is_numeric($categcode)) {
1795 $tmpcategory =
new Categorie($this->db);
1796 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
1797 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
1800 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1801 $out .=
'<option value="0"> </option>';
1802 if (is_array($data)) {
1803 foreach ($data as $data_key => $data_value) {
1804 $out .=
'<option value="'.$data_key.
'"';
1805 $out .= ($value == $data_key ?
' selected' :
'');
1806 $out .=
'>'.$data_value.
'</option>';
1811 $out .=
'</select>';
1813 } elseif ($type ==
'checkbox') {
1814 $value_arr = $value;
1815 if (!is_array($value)) {
1816 $value_arr = explode(
',', $value);
1818 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0,
'', 0,
'100%');
1819 } elseif ($type ==
'radio') {
1821 $selectedvalue = ((
string) $value !==
'' ? $value : $default);
1822 foreach ($param[
'options'] as $keyopt => $val) {
1823 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1824 $out .=
' value="'.$keyopt.
'"';
1825 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1826 $out .= ((
string) $selectedvalue == (
string) $keyopt ?
' checked' :
'');
1827 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1829 } elseif ($type ==
'chkbxlst') {
1832 if (is_array($value)) {
1833 $value_arr = $value;
1835 $value_arr = explode(
',', $value);
1839 $(document).ready(function () {
1840 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1842 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1845 delay: 250, // wait 250 milliseconds before triggering the request
1846 data: function (params) {
1848 search: params.term,
1849 page: params.page || 1,
1850 objecttype: '".$extrafieldsobjectkey.
"',
1852 objectkey: '".$key.
"',
1865 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_multiselect" value="1">';
1866 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'[]" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
' multiple="multiple">';
1867 foreach ($value_arr as $value) {
1868 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1870 $out .=
'</select>';
1872 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1873 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1876 if (is_array($value)) {
1877 $value_arr = $value;
1879 $value_arr = explode(
',', $value);
1882 if (is_array($param[
'options'])) {
1883 $tmpparamoptions = array_keys($param[
'options']);
1884 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1886 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1907 if (! empty($InfoFieldList[4])) {
1909 $parenthesisopen = 0;
1910 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1911 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1914 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1919 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1920 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1922 $InfoFieldList[4] = $tmpbefore;
1923 if ($tmpafter !==
'') {
1924 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1929 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1930 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1938 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1940 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1941 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1942 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1944 $keyList = $InfoFieldList[2].
' as rowid';
1947 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1948 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1949 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1950 $keyList .=
', main.'.$parentField;
1952 $keyList .=
', '.$parentField;
1957 $filter_categorie =
false;
1958 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
1959 $InfoFieldList[5] = (
string) $InfoFieldList[5];
1960 if ($InfoFieldList[0] ==
'categorie') {
1961 $filter_categorie =
true;
1963 $filter_categorie =
false;
1968 if (!$filter_categorie) {
1969 $fields_label = explode(
'|', $InfoFieldList[1]);
1970 if (is_array($fields_label)) {
1972 $keyList .= implode(
', ', $fields_label);
1976 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
1977 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
1980 if (!empty($InfoFieldList[4])) {
1982 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1983 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1986 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1987 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1991 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1992 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1993 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1997 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1998 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
2000 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
2001 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
2003 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
2008 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2009 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
2010 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
2016 $sqlwhere .=
' WHERE 1=1';
2019 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
2021 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2022 $tmpcategory =
new Categorie($this->db);
2023 $tablesuffixcategory = empty($tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]];
2024 $fksuffixcategory = empty($tmpcategory->MAP_CAT_FK[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_FK[$InfoFieldList[5]];
2026 $sqlwhere .=
' AND EXISTS (SELECT fk_categorie as categid FROM '.MAIN_DB_PREFIX.
'categorie_'.$this->db->sanitize($tablesuffixcategory);
2027 $sqlwhere .=
' WHERE fk_categorie IN ('.$this->db->sanitize($InfoFieldList[6]).
')';
2028 $sqlwhere .=
' AND fk_'.$this->db->sanitize($fksuffixcategory).
' = rowid)';
2046 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
2047 $sqlwhere .=
" AND entity = ".((int)
$conf->entity);
2053 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
2055 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
2057 $resql = $this->db->query($sql);
2059 $num = $this->db->num_rows($resql);
2066 $obj = $this->db->fetch_object($resql);
2070 $fields_label = explode(
'|', $InfoFieldList[1]);
2071 if (is_array($fields_label)) {
2073 foreach ($fields_label as $field_toshow) {
2074 $labeltoshow .= $obj->$field_toshow.
' ';
2077 $labeltoshow = $obj->{$InfoFieldList[1]};
2079 $labeltoshow =
dol_trunc($labeltoshow, 45);
2081 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2083 foreach ($fields_label as $field_toshow) {
2084 $translabel = $langs->trans($obj->$field_toshow);
2085 if ($translabel != $obj->$field_toshow) {
2086 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
2088 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
2091 $data[$obj->rowid] = $labeltoshow;
2094 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
2095 if ($translabel != $obj->{$InfoFieldList[1]}) {
2096 $labeltoshow =
dol_trunc($translabel, 18);
2098 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
2101 if (empty($labeltoshow)) {
2102 $labeltoshow =
'(not defined)';
2105 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2106 $data[$obj->rowid] = $labeltoshow;
2109 if (!empty($InfoFieldList[3]) && $parentField) {
2110 $parent = $parentName.
':'.$obj->{$parentField};
2113 $data[$obj->rowid] = $labeltoshow;
2118 $this->db->free($resql);
2120 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2122 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
2125 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2126 $categcode = $InfoFieldList[5];
2127 if (is_numeric($categcode)) {
2128 $tmpcategory =
new Categorie($this->db);
2129 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
2130 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
2133 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
2134 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2138 } elseif ($type ==
'link') {
2139 $param_list = array_keys($param[
'options']);
2146 $showempty = (($required && $default !=
'') ? 0 : 1);
2148 $tmparray = explode(
':', $param_list[0]);
2150 $element = $extrafieldsobjectkey;
2151 if ($element ==
'socpeople') {
2152 $element =
'contact';
2153 } elseif ($element ==
'projet') {
2154 $element =
'project';
2158 $objectdesc = $tmparray[0].(empty($tmparray[1]) ?
"" :
":".$tmparray[1]);
2159 $objectfield = $element.
':options_'.$key;
2161 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, (
int) $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
2162 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
2163 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2167 if (!empty($value)) {
2168 $tmparray = $dolgeophp->parseGeoString($value);
2169 $geojson = $tmparray[
'geojson'];
2170 $centroidjson = $tmparray[
'centroidjson'];
2172 if (!preg_match(
'/search_/', $keyprefix)) {
2173 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
2175 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
2180 } elseif ($type ==
'password') {
2182 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
2183 $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 :
'').
'>';
2184 } elseif ($type ==
'stars') {
2185 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2186 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
2188 while ($i <= $size) {
2189 $out .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2194 jQuery(function($) { /* extrafields.class.php 1 */
2195 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
2196 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
2197 container.find(".star").each(function() {
2198 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2200 container.find(".star").on("mouseover", function() {
2201 let selectedStar = $(this).data("value");
2202 container.find(".star").each(function() {
2203 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2206 container.on("mouseout", function() {
2207 container.find(".star").each(function() {
2208 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2211 container.find(".star").off("click").on("click", function() {
2212 selectedStars = $(this).data("value");
2213 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
2216 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
2217 container.find(".star").each(function() {
2218 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2224 if (!empty($hidden)) {
2225 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
2230 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2231 $out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey,
null,
$object);
2256 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null,
$object =
null, $mode =
'')
2258 global
$conf, $langs, $hookmanager;
2260 if (is_null($outputlangs) || !is_object($outputlangs)) {
2261 $outputlangs = $langs;
2264 if (empty($extrafieldsobjectkey)) {
2265 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
2266 return 'BadValueForParamExtraFieldsObjectKey';
2269 $parameters = array(
2272 'moreparam' => $moreparam,
2273 'extrafieldsobjectkey' => $extrafieldsobjectkey,
2274 'outputlangs' => $outputlangs,
2279 $reshook = $hookmanager->executeHooks(
'showOutputExtraField', $parameters, $this, $action);
2281 return $hookmanager->resPrint;
2284 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
2285 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2286 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
2287 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
2288 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
2289 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
2290 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
2291 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
2292 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
2293 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
2294 $list = (
string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
2295 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
2296 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
2297 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
2300 $showValueInsteadOfInputField = 0;
2302 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2303 $showValueInsteadOfInputField = 1;
2306 $hidden = (empty($list) ? 1 : 0);
2315 if ($type ==
'date') {
2317 if ($value !==
'') {
2320 } elseif ($type ==
'datetime') {
2322 if ($value !==
'') {
2325 } elseif ($type ==
'duration') {
2327 if ($value !==
'') {
2328 $value = intval($value);
2331 } elseif ($type ==
'datetimegmt') {
2333 if ($value !==
'') {
2336 } elseif ($type ==
'int') {
2338 } elseif ($type ==
'double') {
2339 if (!empty($value)) {
2343 $value =
price($value, 0, $outputlangs, 0, 0, -2,
'');
2345 } elseif ($type ==
'boolean') {
2347 if (!empty($value)) {
2348 $checked =
' checked ';
2351 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
2353 $value =
yn($value ? 1 : 0);
2355 } elseif ($type ==
'mail' || $type ==
'email') {
2357 } elseif ($type ==
'ip') {
2359 } elseif ($type ==
'icon') {
2360 $value =
'<span class="'.$value.
'"></span>';
2361 } elseif ($type ==
'url') {
2363 } elseif ($type ==
'phone') {
2365 } elseif ($type ==
'price') {
2367 if ($value || $value ==
'0') {
2368 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol(
$conf->currency);
2370 } elseif ($type ==
'pricecy') {
2371 $currency =
$conf->currency;
2372 if (!empty($value)) {
2374 $pricetmp = explode(
':', $value);
2375 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
2376 $value = $pricetmp[0];
2378 if ($value || $value ==
'0') {
2379 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
2381 } elseif ($type ==
'select') {
2382 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2383 if (($pos = strpos($valstr,
"|")) !==
false) {
2384 $valstr = substr($valstr, 0, $pos);
2386 if ($langfile && $valstr) {
2387 $value = $outputlangs->trans($valstr);
2391 } elseif ($type ==
'sellist') {
2392 $param_list = array_keys($param[
'options']);
2393 $InfoFieldList = explode(
":", $param_list[0]);
2395 $selectkey =
"rowid";
2398 if (count($InfoFieldList) >= 3) {
2399 $selectkey = $InfoFieldList[2];
2400 $keyList = $InfoFieldList[2].
' as rowid';
2403 $fields_label = explode(
'|', $InfoFieldList[1]);
2404 if (is_array($fields_label)) {
2406 $keyList .= implode(
', ', $fields_label);
2409 $filter_categorie =
false;
2410 if (count($InfoFieldList) > 5) {
2411 if ($InfoFieldList[0] ==
'categorie') {
2412 $filter_categorie =
true;
2416 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2417 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2418 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2421 if ($selectkey ==
'rowid' && empty($value)) {
2422 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = 0";
2423 } elseif ($selectkey ==
'rowid') {
2424 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = ".((int) $value);
2426 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = '".$this->db->escape($value).
"'";
2430 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2432 $resql = $this->db->query($sql);
2434 if (!$filter_categorie) {
2437 $obj = $this->db->fetch_object($resql);
2440 $fields_label = explode(
'|', $InfoFieldList[1]);
2442 if (is_array($fields_label) && count($fields_label) > 1) {
2443 foreach ($fields_label as $field_toshow) {
2445 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
2446 if (!empty($obj->$field_toshow)) {
2447 $translabel = $outputlangs->trans($obj->$field_toshow);
2449 if ($translabel != $obj->$field_toshow) {
2450 $value .=
dol_trunc($translabel, 24) .
' ';
2452 $value .= $obj->$field_toshow .
' ';
2458 $tmppropname = $InfoFieldList[1];
2460 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2461 $translabel = $outputlangs->trans($obj->$tmppropname);
2463 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2466 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2471 $obj = $this->db->fetch_object($resql);
2473 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2475 $result =
$c->fetch($obj->rowid);
2477 $ways =
$c->print_all_ways();
2478 foreach ($ways as $way) {
2479 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
2483 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2486 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2488 } elseif ($type ==
'radio') {
2489 if ($required && !isset($param[
'options'][$value])) {
2490 $outputlangs->load(
'errors');
2491 $value =
'<span class="opacitymedium">'.$outputlangs->trans(
'ErrorNoValueForRadioType').
'</span>';
2493 if (isset($param[
'options'][$value])) {
2494 $value = $outputlangs->trans($param[
'options'][$value]);
2499 } elseif ($type ==
'checkbox') {
2500 $value_arr = explode(
',', $value);
2503 if (is_array($value_arr)) {
2504 foreach ($value_arr as $keyval => $valueval) {
2505 if (!empty($valueval)) {
2506 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2510 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2511 } elseif ($type ==
'chkbxlst') {
2513 if (!is_null($value) && $value !=
'') {
2514 $value_arr = explode(
',', $value);
2516 $param_list = array_keys($param[
'options']);
2517 $InfoFieldList = explode(
":", $param_list[0]);
2519 $selectkey =
"rowid";
2522 if (count($InfoFieldList) >= 3) {
2523 $selectkey = $InfoFieldList[2];
2524 $keyList = $InfoFieldList[2].
' as rowid';
2527 $fields_label = explode(
'|', $InfoFieldList[1]);
2528 if (is_array($fields_label)) {
2530 $keyList .= implode(
', ', $fields_label);
2533 $filter_categorie =
false;
2534 if (count($InfoFieldList) > 5 && ((
string) $InfoFieldList[5] !=
'')) {
2535 if ($InfoFieldList[0] ==
'categorie') {
2536 $filter_categorie =
true;
2540 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2541 $sql .=
" FROM ".$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2542 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2545 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" IN (".$this->db->sanitize(implode(
',', $value_arr)).
")";
2547 dol_syslog(get_class($this).
':showOutputField type=chkbxlst', LOG_DEBUG);
2549 $resql = $this->db->query($sql);
2552 if (!$filter_categorie) {
2555 $numOfElem = $this->db->num_rows($resql);
2556 while ($obj = $this->db->fetch_object($resql)) {
2558 $fields_label = explode(
'|', $InfoFieldList[1]);
2561 if (count($fields_label) > 0) {
2562 if ($InfoFieldList[0] ==
'societe' && $InfoFieldList[1] ==
'nom' && $InfoFieldList[2] ==
'rowid') {
2564 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
2565 $tmpthirdpartystatic =
new Societe($this->db);
2566 $tmpthirdpartystatic->id = $obj->rowid;
2567 $tmpthirdpartystatic->name = $obj->nom;
2568 if ($numOfElem >= 3) {
2569 $tmpthirdpartystatic->name = $obj->nom;
2570 $label = $tmpthirdpartystatic->getNomUrl(2);
2571 } elseif ($numOfElem >= 2) {
2572 $tmpthirdpartystatic->name =
dol_trunc($obj->nom, 5);
2573 $label = $tmpthirdpartystatic->getNomUrl(1);
2575 $tmpthirdpartystatic->name = $obj->nom;
2576 $label = $tmpthirdpartystatic->getNomUrl(1);
2579 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: '.$txtcolor.
'">';
2580 foreach ($fields_label as $field_toshow) {
2582 if (!empty($obj->$field_toshow)) {
2583 $translabel = $outputlangs->trans($obj->$field_toshow);
2585 if ($translabel != $field_toshow) {
2586 $label .=
' '.dol_trunc($translabel, 18);
2588 $label .=
' '.$obj->$field_toshow;
2593 $toprint[] = $label;
2597 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2600 $numElem = $this->db->num_rows($resql);
2601 while ($obj = $this->db->fetch_object($resql)) {
2603 $c->fetch($obj->rowid);
2604 if ((
string) $mode !=
'list') {
2605 $ways =
$c->print_all_ways();
2606 foreach ($ways as $way) {
2607 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
2611 $forced_color =
'categtextwhite';
2614 $forced_color =
'categtextblack';
2619 $s =
'<li class="select2-search-choice-dolibarr noborderoncategories '.$forced_color.
' list"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>';
2620 if ($numElem >= 2) {
2621 $s .=
img_object(
$c->label,
'category',
'class="small"');
2623 $s .=
img_object(
$c->label,
'category',
'class="small"').
' '.
$c->label;
2630 if (!empty($toprint)) {
2631 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2634 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2637 } elseif ($type ==
'link') {
2640 $param_list = array_keys($param[
'options']);
2642 $InfoFieldList = explode(
":", $param_list[0]);
2643 $classname = $InfoFieldList[0];
2644 $classpath = $InfoFieldList[1];
2645 if (!empty($classpath)) {
2647 if ($classname && class_exists($classname)) {
2648 $tmpobject =
new $classname($this->db);
2649 '@phan-var-force CommonObject $tmpobject';
2650 $tmpobject->fetch($value);
2652 if (get_class($tmpobject) ==
'Categorie') {
2654 $color = $tmpobject->color;
2655 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2656 $sfortag .= $tmpobject->getNomUrl(3);
2657 $sfortag .=
'</span>';
2660 $value = $tmpobject->getNomUrl(3);
2664 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2665 return 'Error bad setup of extrafield';
2668 } elseif ($type ==
'point') {
2669 if (!empty($value)) {
2670 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2672 $value = $dolgeophp->getXYString($value);
2676 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2677 if (!empty($value)) {
2678 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2680 $value = $dolgeophp->getPointString($value);
2684 } elseif ($type ==
'text') {
2685 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2686 } elseif ($type ==
'html') {
2688 } elseif ($type ==
'password') {
2689 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2690 } elseif ($type ==
'stars') {
2691 $objectid = (int)
$object->id;
2692 $nbstars = (int) $value;
2693 if ($showValueInsteadOfInputField == 1) {
2694 $value =
'<span style="display:none;" id="'.$key.$object->id.
'">'.
dol_escape_htmltag($value).
'</span>';
2696 $value =
'<input type="hidden" class="flat" name="'.$key.
'" id="'.$key.$objectid.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2699 $value .=
'<div class="star-selection" id="'.$key.$objectid.
'_selection">';
2701 while ($i <= $size) {
2702 $value .=
'<span class="star'.($i <= $nbstars ?
' active' :
'').
'" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2707 $(document).ready(function() { /* extrafields.class.php 2 */
2708 let container = $("#'.$key.$objectid.
'_selection");
2709 let selectedStars = parseInt($("#'.$key.$objectid.
'").val() || $("#'.$key.$objectid.
'").text()) || 0;
2711 if ($showValueInsteadOfInputField == 0) {
2713 container.find(".star").on("mouseover", function() {
2714 console.log("Mouse over a star");
2715 let selectedStar = $(this).data("value");
2716 container.find(".star").each(function() {
2717 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2720 container.on("mouseout", function() {
2721 console.log("Mouse out of star");
2722 container.find(".star").each(function() {
2723 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2726 container.find(".star").off("click").on("click", function() {
2727 console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
2728 selectedStars = $(this).data("value");
2729 if (selectedStars == 1 && $("#'.$key.$objectid.
'").val() == 1) {
2732 container.find("#'.$key.$objectid.
'").val(selectedStars);
2733 container.find(".star").each(function() {
2734 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2737 url: "'.DOL_URL_ROOT.
'/core/ajax/updateextrafield.php",
2741 objectId:
'.((int) $objectid).',
2742 field: \
''.dol_escape_js($key).
'\',
2743 value: selectedStars,
2744 token: \
''.currentToken().
'\'
2746 success:
function(response) {
2747 var res = JSON.parse(response);
2748 console[res.status ===
"success" ?
"log" :
"error"](res.message);
2750 error:
function(xhr,
status, error) {
2751 console.log(
"Ajax request failed while updating '.$key.':", error);
2760 $showsize = round((float) $size);
2761 if ($showsize > 48) {
2766 //print $type.'-
'.$size;