1059 global
$conf,$hookmanager;
1061 if (empty($elementtype)) {
1062 dol_syslog(__METHOD__.
'::empty elementtype', LOG_DEBUG);
1066 if ($elementtype ==
'thirdparty') {
1067 $elementtype =
'societe';
1069 if ($elementtype ==
'contact') {
1070 $elementtype =
'socpeople';
1072 if ($elementtype ==
'order_supplier') {
1073 $elementtype =
'commande_fournisseur';
1076 if ($elementtype !=
'all' && isset($this->attributes[$elementtype]) && $this->attributes[$elementtype][
'loaded'] == 1 && !$forceload && isset($this->attributes[$elementtype][
'label'])) {
1077 return $this->attributes[$elementtype][
'label'];
1080 $array_name_label = array();
1083 $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";
1084 $sql .=
" , css, cssview, csslist, personal_data";
1085 $sql .=
" FROM ".$this->db->prefix().
"extrafields";
1087 if ($elementtype && $elementtype !=
'all') {
1088 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1090 if ($attrname && $elementtype && $elementtype !=
'all') {
1091 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1093 $sql .=
" ORDER BY pos";
1095 $resql = $this->db->query($sql);
1098 if ($this->db->num_rows($resql)) {
1099 while ($tab = $this->db->fetch_object($resql)) {
1100 if ($tab->entity != 0 && $tab->entity !=
$conf->entity) {
1102 if ($tab->fieldrequired && is_null($tab->fielddefault)) {
1103 $this->attributes[$tab->elementtype][
'mandatoryfieldsofotherentities'][$tab->name] = $tab->type;
1109 if ($tab->type !=
'separate') {
1110 $array_name_label[$tab->name] = $tab->label;
1112 $array_name_label[$tab->name] = $tab->type;
1116 $this->attributes[$tab->elementtype][
'type'][$tab->name] = $tab->type;
1117 $this->attributes[$tab->elementtype][
'label'][$tab->name] = $tab->label;
1118 $this->attributes[$tab->elementtype][
'size'][$tab->name] = $tab->size;
1119 $this->attributes[$tab->elementtype][
'elementtype'][$tab->name] = $tab->elementtype;
1120 $this->attributes[$tab->elementtype][
'default'][$tab->name] = $tab->fielddefault;
1121 $this->attributes[$tab->elementtype][
'computed'][$tab->name] = $tab->fieldcomputed;
1122 $this->attributes[$tab->elementtype][
'unique'][$tab->name] = $tab->fieldunique;
1123 $this->attributes[$tab->elementtype][
'required'][$tab->name] = $tab->fieldrequired;
1124 $this->attributes[$tab->elementtype][
'param'][$tab->name] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1125 $this->attributes[$tab->elementtype][
'pos'][$tab->name] = $tab->pos;
1126 $this->attributes[$tab->elementtype][
'alwayseditable'][$tab->name] = $tab->alwayseditable;
1127 $this->attributes[$tab->elementtype][
'emptyonclone'][$tab->name] = $tab->emptyonclone;
1128 $this->attributes[$tab->elementtype][
'perms'][$tab->name] = $tab->perms;
1129 $this->attributes[$tab->elementtype][
'langfile'][$tab->name] = $tab->langs;
1130 $this->attributes[$tab->elementtype][
'list'][$tab->name] = $tab->list;
1131 $this->attributes[$tab->elementtype][
'printable'][$tab->name] = $tab->printable;
1132 $this->attributes[$tab->elementtype][
'showintooltip'][$tab->name] = $tab->showintooltip;
1133 $this->attributes[$tab->elementtype][
'totalizable'][$tab->name] = ($tab->totalizable ? 1 : 0);
1134 $this->attributes[$tab->elementtype][
'entityid'][$tab->name] = $tab->entity;
1135 $this->attributes[$tab->elementtype][
'enabled'][$tab->name] = $tab->enabled;
1136 $this->attributes[$tab->elementtype][
'help'][$tab->name] = $tab->help;
1137 $this->attributes[$tab->elementtype][
'aiprompt'][$tab->name] = $tab->aiprompt;
1138 $this->attributes[$tab->elementtype][
'css'][$tab->name] = $tab->css;
1139 $this->attributes[$tab->elementtype][
'cssview'][$tab->name] = $tab->cssview;
1140 $this->attributes[$tab->elementtype][
'csslist'][$tab->name] = $tab->csslist;
1141 $this->attributes[$tab->elementtype][
'personal_data'][$tab->name] = $tab->personal_data;
1143 $this->attributes[$tab->elementtype][
'loaded'] = 1;
1148 $this->attributes[$elementtype][
'loaded'] = 1;
1149 $this->attributes[$elementtype][
'count'] = $count;
1152 $this->error = $this->db->lasterror();
1153 dol_syslog(get_class($this).
"::fetch_name_optionals_label ".$this->error, LOG_ERR);
1157 if (is_object($hookmanager)) {
1158 $parameters = array(
1159 'elementtype' => $elementtype,
1160 'attrname' => $attrname,
1161 'forceload' => $forceload,
1163 $reshook = $hookmanager->executeHooks(
'completeFetchNameOptionalsLabel', $parameters, $this);
1164 if ($reshook > 0 && is_array($hookmanager->resArray)) {
1166 foreach ($hookmanager->resArray as $key => $val) {
1167 $array_name_label[$key] = $val;
1172 return $array_name_label;
1191 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'',
$object = 0, $extrafieldsobjectkey =
'', $mode = 0)
1193 global
$conf, $langs, $form, $hookmanager;
1195 if (!is_object($form)) {
1196 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
1197 $form =
new Form($this->db);
1201 $morecss =
'maxwidth125';
1204 $parameters = array(
1207 'moreparam' => $moreparam,
1208 'keysuffix' => $keysuffix,
1209 'keyprefix' => $keyprefix,
1210 'morecss' => $morecss,
1212 'extrafieldsobjectkey' => $extrafieldsobjectkey,
1217 $reshook = $hookmanager->executeHooks(
'showInputExtraField', $parameters, $this, $action);
1219 return $hookmanager->resPrint;
1226 if (!preg_match(
'/options_$/', $keyprefix)) {
1227 $keyprefix .=
'options_';
1230 if (empty($extrafieldsobjectkey)) {
1231 dol_syslog(get_class($this).
'::showInputField extrafieldsobjectkey required', LOG_ERR);
1232 return 'BadValueForParamExtraFieldsObjectKey';
1235 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1236 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1237 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1238 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1239 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1240 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1241 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1242 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1243 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
1244 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1245 $list = (
string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
1246 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
1247 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1248 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
1249 $hidden = (empty($list) ? 1 : 0);
1255 if (!preg_match(
'/^search_/', $keyprefix)) {
1256 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
1264 if (empty($morecss)) {
1266 if ($type ==
'date') {
1267 $morecss =
'minwidth100imp';
1268 } elseif ($type ==
'datetime' || $type ==
'datetimegmt' || $type ==
'link') {
1269 $morecss =
'minwidth200imp';
1270 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
1271 $morecss =
'maxwidth75';
1272 } elseif ($type ==
'password') {
1273 $morecss =
'maxwidth100';
1274 } elseif ($type ==
'url') {
1275 $morecss =
'minwidth400';
1276 } elseif ($type ==
'boolean') {
1278 } elseif ($type ==
'radio') {
1279 $morecss =
'width25';
1281 if (empty($size) || round((
float) $size) < 12) {
1282 $morecss =
'minwidth100';
1283 } elseif (round((
float) $size) <= 48) {
1284 $morecss =
'minwidth200';
1286 $morecss =
'minwidth400';
1290 if (!empty($this->attributes[$extrafieldsobjectkey][
'css'][$key])) {
1291 $morecss = $this->attributes[$extrafieldsobjectkey][
'css'][$key];
1295 if (in_array($type, array(
'date'))) {
1296 $tmp = explode(
',', $size);
1301 if (!$required && $value ==
'') {
1308 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1309 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1311 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1312 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"));
1313 $out .=
'</div><div class="nowrap">';
1314 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"));
1315 $out .=
'</div></div>';
1319 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required ? 0 : 2,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1321 } elseif (in_array($type, array(
'datetime',
'datetimegmt'))) {
1322 $tmp = explode(
',', $size);
1327 if (!$required && $value ==
'') {
1334 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1335 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1337 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1338 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"),
'tzuserrel');
1339 $out .=
'</div><div class="nowrap">';
1340 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
1341 $out .=
'</div></div>';
1345 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required ? 0 : 2,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1347 } elseif (in_array($type, array(
'int',
'integer'))) {
1348 $tmp = explode(
',', $size);
1350 $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 :
'').
'>';
1351 } elseif (preg_match(
'/varchar/', $type)) {
1352 $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 :
'').
'>';
1353 } elseif (in_array($type, array(
'email',
'mail',
'ip',
'phone',
'url'))) {
1354 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1355 } elseif ($type ==
'icon') {
1361 $out .=
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat '.$morecss.
' maxwidthonsmartphone"';
1362 $out .=
' name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1365 $options =
"{ title: '<b>".$langs->trans(
"IconFieldSelector").
"</b>', placement: 'right', showFooter: false, templates: {";
1366 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
1367 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
1370 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
1371 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"".$langs->trans(
"TypeToFilter").
"\" />',";
1372 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
1373 $options .=
" <div class=\"arrow\" ></div>";
1374 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
1375 $options .=
" <div class=\"popover-content \" ></div>";
1376 $options .=
"</div>'}}";
1377 $out .=
"$('#".$keyprefix.$key.$keysuffix.
"').iconpicker(".$options.
");";
1378 $out .=
'</script>';
1380 } elseif ($type ==
'text') {
1381 if (!preg_match(
'/search_/', $keyprefix)) {
1382 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1383 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1384 $out = (
string) $doleditor->Create(1);
1386 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1388 } elseif ($type ==
'html') {
1389 if (!preg_match(
'/search_/', $keyprefix)) {
1390 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1391 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
1392 $out = (
string) $doleditor->Create(1);
1394 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1396 } elseif ($type ==
'boolean') {
1399 if (!empty($value)) {
1400 $checked =
' checked value="1" ';
1402 $checked =
' value="1" ';
1404 $out =
'<input type="checkbox" class="flat valignmiddle'.($morecss ?
' '.$morecss :
'').
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1406 $out = $form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1, 1,
'width75 yesno');
1408 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_boolean" value="1">';
1409 } elseif ($type ==
'price') {
1410 if (!empty($value)) {
1411 $value =
price($value);
1413 $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).
'">';
1414 } elseif ($type ==
'pricecy') {
1415 $currency =
$conf->currency;
1416 if (!empty($value)) {
1418 $pricetmp = explode(
':', $value);
1419 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
1420 $value =
price($pricetmp[0]);
1422 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1423 $out .= $form->selectCurrency($currency, $keyprefix.$key.$keysuffix.
'currency_id');
1424 } elseif ($type ==
'duration') {
1425 $value = intval($value);
1426 $out = $form->select_duration($keyprefix . $key, $value, 0,
'text', 0, 1);
1427 } elseif ($type ==
'double') {
1428 if (!empty($value)) {
1429 $value =
price($value);
1431 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1432 } elseif ($type ==
'select') {
1436 foreach ($param[
'options'] as $okey => $val) {
1437 if ((
string) $okey ==
'') {
1441 $valarray = explode(
'|', $val);
1442 $val = $valarray[0];
1444 if ($langfile && $val) {
1445 $options[$okey] = $langs->trans($val);
1447 $options[$okey] = $val;
1450 $selected = array();
1451 if (!is_array($value)) {
1452 $selected = explode(
',', $value);
1455 $out .= $form->multiselectarray($keyprefix.$key.$keysuffix, $options, $selected, 0, 0, $morecss, 0, 0,
'',
'',
'', (
int) (!empty(
$conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
1458 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1459 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1462 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1463 $out .=
'<option value="0"> </option>';
1464 foreach ($param[
'options'] as $key2 => $val2) {
1465 if ((
string) $key2 ==
'') {
1468 $valarray = explode(
'|', $val2);
1469 $val2 = $valarray[0];
1471 if (!empty($valarray[1])) {
1472 $parent = $valarray[1];
1474 $out .=
'<option value="'.$key2.
'"';
1475 $out .= (((
string) $value == (
string) $key2) ?
' selected' :
'');
1476 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1478 if ($langfile && $val2) {
1479 $out .= $langs->trans($val2);
1483 $out .=
'</option>';
1485 $out .=
'</select>';
1487 } elseif ($type ==
'sellist') {
1489 if (!empty(
$conf->use_javascript_ajax)) {
1494 $(document).ready(function () {
1495 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1497 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1499 delay: 250, // wait 250 milliseconds before triggering the request
1500 data: function (params) {
1502 search: params.term,
1503 page: params.page || 1,
1504 objecttype: '".dol_escape_js($extrafieldsobjectkey).
"',
1507 mode: '".((int) $mode).
"',
1516 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1517 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1518 $out .=
'</select>';
1520 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1521 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1526 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1527 if (is_array($param[
'options'])) {
1530 $tmpparamoptions = array_keys($param[
'options']);
1531 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1533 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1545 if (! empty($InfoFieldList[4])) {
1547 $parenthesisopen = 0;
1548 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1549 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1552 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1557 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1558 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1560 $InfoFieldList[4] = $tmpbefore;
1561 if ($tmpafter !==
'') {
1562 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1567 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1568 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1578 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1580 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1581 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1582 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1584 $keyList = $InfoFieldList[2].
' as rowid';
1587 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1588 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1589 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1590 $keyList .=
', main.'.$parentField;
1592 $keyList .=
', '.$parentField;
1595 if (!empty($parentField)) {
1596 $keyList .=
', '.$parentField;
1600 $filter_categorie =
false;
1601 if (count($InfoFieldList) > 5) {
1602 if ($InfoFieldList[0] ==
'categorie') {
1603 $filter_categorie =
true;
1607 if (!$filter_categorie) {
1608 $fields_label = isset($InfoFieldList[1]) ? explode(
'|', $InfoFieldList[1]) : array();
1609 if (!empty($fields_label)) {
1611 $keyList .= implode(
', ', $fields_label);
1617 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
1618 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
1621 if (!empty($InfoFieldList[4])) {
1623 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1624 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1627 global $dolibarr_allow_unsecured_select_in_extrafields_filter;
1628 if (!empty($dolibarr_allow_unsecured_select_in_extrafields_filter)) {
1629 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1630 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1634 if (strpos($InfoFieldList[4],
'$MODE$') !==
false) {
1635 $InfoFieldList[4] = str_replace(
'$MODE$', preg_replace(
'/[^a-z0-9_]/i',
'', (
string) $mode), $InfoFieldList[4]);
1639 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1640 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1641 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1646 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1647 $InfoFieldList[4] = preg_replace($word,
'1:=:1', $InfoFieldList[4]);
1649 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1650 $InfoFieldList[4] = preg_replace($word,
'1:=:1', $InfoFieldList[4]);
1652 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *: *[<>!=]?= *: *\$ID\$#';
1653 $InfoFieldList[4] = preg_replace($word,
'1:=:1', $InfoFieldList[4]);
1655 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1661 preg_match_all(
'/\$(.*?)\$/', $InfoFieldList[4], $tags);
1662 foreach ($tags[0] as $keytag => $valuetag) {
1663 $property = preg_replace(
'/[^a-z0-9_]/',
'', strtolower($tags[1][$keytag]));
1664 if (strpos($property,
'options_') === 0) {
1665 if (strpos($InfoFieldList[4], $valuetag) !==
false && isset(
$object->array_options[$property]) && !empty(
$object->array_options[$property])) {
1666 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->array_options[$property], $InfoFieldList[4]);
1668 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1671 if (strpos($InfoFieldList[4], $valuetag) !==
false && property_exists(
$object, $property) && !empty(
$object->$property)) {
1672 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->$property, $InfoFieldList[4]);
1674 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1682 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1683 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1684 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1690 $sqlwhere .=
' WHERE 1=1';
1707 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1708 $sqlwhere .=
' AND entity = '.((int)
$conf->entity);
1712 $sql .= $this->db->order(implode(
', ', $fields_label));
1713 $sql .=
' LIMIT ' .
getDolGlobalInt(
'MAIN_EXTRAFIELDS_LIMIT_SELLIST_SQL', 1000);
1716 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1717 $resql = $this->db->query($sql);
1719 $out .=
'<option value="0"> </option>';
1720 $num = $this->db->num_rows($resql);
1724 $obj = $this->db->fetch_object($resql);
1726 $nameFields = $InfoFieldList[1];
1728 $nameFields = preg_replace(
'/[a-z_]+\([^\)]*\) as ([\w]+)/i',
'\1', $nameFields);
1730 $nameFields = preg_replace(
'/[^0-9a-z_\.\|]/i',
'', $nameFields);
1734 $fields_label = explode(
'|', $nameFields);
1735 if (is_array($fields_label) && count($fields_label) > 1) {
1737 foreach ($fields_label as $field_toshow) {
1738 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
1739 $labeltoshow .= $obj->$field_toshow.
' ';
1742 $labeltoshow = $obj->$nameFields;
1745 if ($value == $obj->rowid) {
1747 foreach ($fields_label as $field_toshow) {
1748 $translabel = $langs->trans($obj->$field_toshow);
1749 $labeltoshow = $translabel.
' ';
1752 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1755 $translabel = $langs->trans($obj->$nameFields);
1756 $labeltoshow = $translabel;
1758 if (empty($labeltoshow)) {
1759 $labeltoshow =
'(not defined)';
1762 if (!empty($InfoFieldList[3]) && $parentField) {
1764 $parentField = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $parentField);
1765 $parent = $parentName.
':'.$obj->{$parentField};
1768 $out .=
'<option value="'.$obj->rowid.
'"';
1769 $out .= ($value == $obj->rowid ?
' selected' :
'');
1770 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1771 $out .=
'>'.$labeltoshow.
'</option>';
1776 $this->db->free($resql);
1778 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1781 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1782 $categcode = $InfoFieldList[5];
1783 if (is_numeric($categcode)) {
1784 $tmpcategory =
new Categorie($this->db);
1785 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
1786 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
1789 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1790 $out .=
'<option value="0"> </option>';
1791 if (is_array($data)) {
1792 foreach ($data as $data_key => $data_value) {
1793 $out .=
'<option value="'.$data_key.
'"';
1794 $out .= ($value == $data_key ?
' selected' :
'');
1795 $out .=
'>'.$data_value.
'</option>';
1800 $out .=
'</select>';
1802 } elseif ($type ==
'checkbox') {
1803 $value_arr = $value;
1804 if (!is_array($value)) {
1805 $value_arr = explode(
',', $value);
1807 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0,
'', 0,
'100%');
1808 } elseif ($type ==
'radio') {
1810 $selectedvalue = ((
string) $value !==
'' ? $value : $default);
1811 foreach ($param[
'options'] as $keyopt => $val) {
1812 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1813 $out .=
' value="'.$keyopt.
'"';
1814 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1815 $out .= ((
string) $selectedvalue == (
string) $keyopt ?
' checked' :
'');
1816 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1818 } elseif ($type ==
'chkbxlst') {
1821 if (is_array($value)) {
1822 $value_arr = $value;
1824 $value_arr = explode(
',', $value);
1829 $(document).ready(function () {
1830 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1832 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1835 delay: 250, // wait 250 milliseconds before triggering the request
1836 data: function (params) {
1838 search: params.term,
1839 page: params.page || 1,
1840 objecttype: '".dol_escape_js($extrafieldsobjectkey).
"',
1843 mode: '".((int) $mode).
"',
1855 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_multiselect" value="1">';
1856 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'[]" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
' multiple="multiple">';
1857 foreach ($value_arr as $value) {
1858 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1860 $out .=
'</select>';
1862 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1863 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1866 if (is_array($value)) {
1867 $value_arr = $value;
1869 $value_arr = explode(
',', $value);
1872 if (is_array($param[
'options'])) {
1873 $tmpparamoptions = array_keys($param[
'options']);
1874 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1876 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1897 if (! empty($InfoFieldList[4])) {
1899 $parenthesisopen = 0;
1900 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1901 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1904 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1909 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1910 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1912 $InfoFieldList[4] = $tmpbefore;
1913 if ($tmpafter !==
'') {
1914 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1919 if (preg_match(
'/^\(?([a-z0-9_]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1920 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1928 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1930 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1931 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1932 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1934 $keyList = $InfoFieldList[2].
' as rowid';
1937 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1938 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1939 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1940 $keyList .=
', main.'.$parentField;
1942 $keyList .=
', '.$parentField;
1945 if (!empty($parentField)) {
1946 $keyList .=
', '.$parentField;
1950 $InfoFieldList[5] = (
string) ($InfoFieldList[5]??
'');
1952 $filter_categorie =
false;
1953 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
1954 if ($InfoFieldList[0] ==
'categorie') {
1955 $filter_categorie =
true;
1957 $filter_categorie =
false;
1962 if (!$filter_categorie) {
1963 $fields_label = explode(
'|', $InfoFieldList[1]);
1964 if (is_array($fields_label)) {
1966 $keyList .= implode(
', ', $fields_label);
1970 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
1971 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
1974 if (!empty($InfoFieldList[4])) {
1976 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1977 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1980 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1981 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1985 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1986 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1987 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1991 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1992 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1994 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1995 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1997 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
2002 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2003 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
2004 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
2010 $sqlwhere .=
' WHERE 1=1';
2013 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
2015 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2016 $tmpcategory =
new Categorie($this->db);
2017 $tablesuffixcategory = empty($tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]];
2018 $fksuffixcategory = empty($tmpcategory->MAP_CAT_FK[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_FK[$InfoFieldList[5]];
2020 $sqlwhere .=
' AND EXISTS (SELECT fk_categorie as categid FROM '.MAIN_DB_PREFIX.
'categorie_'.$this->db->sanitize($tablesuffixcategory);
2021 $sqlwhere .=
' WHERE fk_categorie IN ('.$this->db->sanitize($InfoFieldList[6]).
')';
2022 $sqlwhere .=
' AND fk_'.$this->db->sanitize($fksuffixcategory).
' = rowid)';
2040 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
2041 $sqlwhere .=
" AND entity = ".((int)
$conf->entity);
2047 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
2049 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
2051 $resql = $this->db->query($sql);
2053 $num = $this->db->num_rows($resql);
2060 $obj = $this->db->fetch_object($resql);
2064 $fields_label = explode(
'|', $InfoFieldList[1]);
2065 if (is_array($fields_label)) {
2067 foreach ($fields_label as $field_toshow) {
2068 $labeltoshow .= $obj->$field_toshow.
' ';
2071 $labeltoshow = $obj->{$InfoFieldList[1]};
2073 $labeltoshow =
dol_trunc($labeltoshow, 45);
2075 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2077 foreach ($fields_label as $field_toshow) {
2078 $translabel = $langs->trans($obj->$field_toshow);
2079 if ($translabel != $obj->$field_toshow) {
2080 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
2082 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
2085 $data[$obj->rowid] = $labeltoshow;
2088 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
2089 if ($translabel != $obj->{$InfoFieldList[1]}) {
2090 $labeltoshow =
dol_trunc($translabel, 18);
2092 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
2095 if (empty($labeltoshow)) {
2096 $labeltoshow =
'(not defined)';
2099 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2100 $data[$obj->rowid] = $labeltoshow;
2103 if (!empty($InfoFieldList[3]) && $parentField) {
2104 $parent = $parentName.
':'.$obj->{$parentField};
2107 $data[$obj->rowid] = $labeltoshow;
2112 $this->db->free($resql);
2114 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2116 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
2119 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2120 $categcode = $InfoFieldList[5];
2121 if (is_numeric($categcode)) {
2122 $tmpcategory =
new Categorie($this->db);
2123 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
2124 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
2127 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
2128 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2132 } elseif ($type ==
'link') {
2133 $param_list = array_keys($param[
'options']);
2140 $showempty = (($required && $default !=
'') ? 0 : 1);
2142 $tmparray = explode(
':', $param_list[0]);
2144 $element = $extrafieldsobjectkey;
2145 if ($element ==
'socpeople') {
2146 $element =
'contact';
2147 } elseif ($element ==
'projet') {
2148 $element =
'project';
2152 $objectdesc = $tmparray[0].(empty($tmparray[1]) ?
"" :
":".$tmparray[1]);
2153 $objectfield = $element.
':options_'.$key;
2155 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, (
int) $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
2156 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
2157 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2161 if (!empty($value)) {
2162 $tmparray = $dolgeophp->parseGeoString($value);
2163 $geojson = $tmparray[
'geojson'];
2164 $centroidjson = $tmparray[
'centroidjson'];
2166 if (!preg_match(
'/search_/', $keyprefix)) {
2167 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
2169 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
2174 } elseif ($type ==
'password') {
2176 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
2177 $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 :
'').
'>';
2178 } elseif ($type ==
'stars') {
2179 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2180 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
2182 while ($i <= $size) {
2183 $out .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2188 jQuery(function($) { /* extrafields.class.php 1 */
2189 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
2190 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
2191 container.find(".star").each(function() {
2192 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2194 container.find(".star").on("mouseover", function() {
2195 let selectedStar = $(this).data("value");
2196 container.find(".star").each(function() {
2197 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2200 container.on("mouseout", function() {
2201 container.find(".star").each(function() {
2202 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2205 container.find(".star").off("click").on("click", function() {
2206 selectedStars = $(this).data("value");
2207 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
2210 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
2211 container.find(".star").each(function() {
2212 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2218 if (!empty($hidden)) {
2219 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
2224 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2225 $out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey,
null,
$object);
2250 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null,
$object =
null, $mode =
'')
2252 global
$conf, $langs, $hookmanager;
2254 if (is_null($outputlangs) || !is_object($outputlangs)) {
2255 $outputlangs = $langs;
2258 if (empty($extrafieldsobjectkey)) {
2259 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
2260 return 'BadValueForParamExtraFieldsObjectKey';
2263 $parameters = array(
2266 'moreparam' => $moreparam,
2267 'extrafieldsobjectkey' => $extrafieldsobjectkey,
2268 'outputlangs' => $outputlangs,
2273 $reshook = $hookmanager->executeHooks(
'showOutputExtraField', $parameters, $this, $action);
2275 return $hookmanager->resPrint;
2278 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
2279 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2280 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
2281 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
2282 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
2283 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
2284 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
2285 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
2286 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
2287 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
2288 $list = (
string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
2289 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
2290 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
2291 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
2294 $showValueInsteadOfInputField = 0;
2296 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2297 $showValueInsteadOfInputField = 1;
2300 $hidden = (empty($list) ? 1 : 0);
2309 if ($type ==
'date') {
2311 if ($value !==
'') {
2314 } elseif ($type ==
'datetime') {
2316 if ($value !==
'') {
2319 } elseif ($type ==
'duration') {
2321 if ($value !==
'') {
2322 $value = intval($value);
2325 } elseif ($type ==
'datetimegmt') {
2327 if ($value !==
'') {
2330 } elseif ($type ==
'int') {
2332 } elseif ($type ==
'double') {
2333 if (!empty($value)) {
2337 $value =
price($value, 0, $outputlangs, 0, 0, -2,
'');
2339 } elseif ($type ==
'boolean') {
2341 if (!empty($value)) {
2342 $checked =
' checked ';
2345 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
2347 $value =
yn($value ? 1 : 0);
2349 } elseif ($type ==
'mail' || $type ==
'email') {
2351 } elseif ($type ==
'ip') {
2353 } elseif ($type ==
'icon') {
2354 $value =
'<span class="'.$value.
'"></span>';
2355 } elseif ($type ==
'url') {
2357 } elseif ($type ==
'phone') {
2359 } elseif ($type ==
'price') {
2361 if ($value || $value ==
'0') {
2362 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol(
$conf->currency);
2364 } elseif ($type ==
'pricecy') {
2365 $currency =
$conf->currency;
2366 if (!empty($value)) {
2368 $pricetmp = explode(
':', $value);
2369 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
2370 $value = $pricetmp[0];
2372 if ($value || $value ==
'0') {
2373 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
2375 } elseif ($type ==
'select') {
2376 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2377 if (($pos = strpos($valstr,
"|")) !==
false) {
2378 $valstr = substr($valstr, 0, $pos);
2380 if ($langfile && $valstr) {
2381 $value = $outputlangs->trans($valstr);
2385 } elseif ($type ==
'sellist') {
2386 $param_list = array_keys($param[
'options']);
2387 $InfoFieldList = explode(
":", $param_list[0]);
2389 $selectkey =
"rowid";
2392 if (count($InfoFieldList) >= 3) {
2393 $selectkey = $InfoFieldList[2];
2394 $keyList = $InfoFieldList[2].
' as rowid';
2397 $fields_label = explode(
'|', $InfoFieldList[1]);
2398 if (is_array($fields_label)) {
2400 $keyList .= implode(
', ', $fields_label);
2403 $filter_categorie =
false;
2404 if (count($InfoFieldList) > 5) {
2405 if ($InfoFieldList[0] ==
'categorie') {
2406 $filter_categorie =
true;
2410 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2411 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2412 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2415 if ($selectkey ==
'rowid' && empty($value)) {
2416 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = 0";
2417 } elseif ($selectkey ==
'rowid') {
2418 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = ".((int) $value);
2420 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = '".$this->db->escape($value).
"'";
2424 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2426 $resql = $this->db->query($sql);
2428 if (!$filter_categorie) {
2431 $obj = $this->db->fetch_object($resql);
2434 $fields_label = explode(
'|', $InfoFieldList[1]);
2436 if (is_array($fields_label) && count($fields_label) > 1) {
2437 foreach ($fields_label as $field_toshow) {
2439 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
2440 if (!empty($obj->$field_toshow)) {
2441 $translabel = $outputlangs->trans($obj->$field_toshow);
2443 if ($translabel != $obj->$field_toshow) {
2444 $value .=
dol_trunc($translabel, 24) .
' ';
2446 $value .= $obj->$field_toshow .
' ';
2452 $tmppropname = $InfoFieldList[1];
2454 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2455 $translabel = $outputlangs->trans($obj->$tmppropname);
2457 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2460 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2465 $obj = $this->db->fetch_object($resql);
2467 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2469 $result =
$c->fetch($obj->rowid);
2471 $ways =
$c->print_all_ways();
2472 foreach ($ways as $way) {
2473 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
2477 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2480 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2482 } elseif ($type ==
'radio') {
2483 if ($required && !isset($param[
'options'][$value])) {
2484 $outputlangs->load(
'errors');
2485 $value =
'<span class="opacitymedium">'.$outputlangs->trans(
'ErrorNoValueForRadioType').
'</span>';
2487 if (isset($param[
'options'][$value])) {
2488 $value = $outputlangs->trans($param[
'options'][$value]);
2493 } elseif ($type ==
'checkbox') {
2494 $value_arr = explode(
',', $value);
2497 if (is_array($value_arr)) {
2498 foreach ($value_arr as $keyval => $valueval) {
2499 if (!empty($valueval)) {
2500 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2504 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2505 } elseif ($type ==
'chkbxlst') {
2507 if (!is_null($value) && $value !=
'') {
2508 $value_arr = explode(
',', $value);
2510 $param_list = array_keys($param[
'options']);
2511 $InfoFieldList = explode(
":", $param_list[0]);
2513 $selectkey =
"rowid";
2516 if (count($InfoFieldList) >= 3) {
2517 $selectkey = $InfoFieldList[2];
2518 $keyList = $InfoFieldList[2].
' as rowid';
2521 $fields_label = explode(
'|', $InfoFieldList[1]);
2522 if (is_array($fields_label)) {
2524 $keyList .= implode(
', ', $fields_label);
2527 $filter_categorie =
false;
2528 if (count($InfoFieldList) > 5 && ((
string) $InfoFieldList[5] !=
'')) {
2529 if ($InfoFieldList[0] ==
'categorie') {
2530 $filter_categorie =
true;
2534 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2535 $sql .=
" FROM ".$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2536 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2539 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" IN (".$this->db->sanitize(implode(
',', $value_arr)).
")";
2541 dol_syslog(get_class($this).
':showOutputField type=chkbxlst', LOG_DEBUG);
2543 $resql = $this->db->query($sql);
2546 if (!$filter_categorie) {
2549 $numOfElem = $this->db->num_rows($resql);
2550 while ($obj = $this->db->fetch_object($resql)) {
2552 $fields_label = explode(
'|', $InfoFieldList[1]);
2555 if (count($fields_label) > 0) {
2556 if ($InfoFieldList[0] ==
'societe' && $InfoFieldList[1] ==
'nom' && $InfoFieldList[2] ==
'rowid') {
2558 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
2559 $tmpthirdpartystatic =
new Societe($this->db);
2560 $tmpthirdpartystatic->id = $obj->rowid;
2561 $tmpthirdpartystatic->name = $obj->nom;
2562 if ($numOfElem >= 3) {
2563 $tmpthirdpartystatic->name = $obj->nom;
2564 $label = $tmpthirdpartystatic->getNomUrl(2);
2565 } elseif ($numOfElem >= 2) {
2566 $tmpthirdpartystatic->name =
dol_trunc($obj->nom, 5);
2567 $label = $tmpthirdpartystatic->getNomUrl(1);
2569 $tmpthirdpartystatic->name = $obj->nom;
2570 $label = $tmpthirdpartystatic->getNomUrl(1);
2573 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: '.$txtcolor.
'">';
2574 foreach ($fields_label as $field_toshow) {
2576 if (!empty($obj->$field_toshow)) {
2577 $translabel = $outputlangs->trans($obj->$field_toshow);
2579 if ($translabel != $field_toshow) {
2580 $label .=
' '.dol_trunc($translabel, 18);
2582 $label .=
' '.$obj->$field_toshow;
2587 $toprint[] = $label;
2591 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2594 $numElem = $this->db->num_rows($resql);
2595 while ($obj = $this->db->fetch_object($resql)) {
2597 $c->fetch($obj->rowid);
2598 if ((
string) $mode !=
'list') {
2599 $ways =
$c->print_all_ways();
2600 foreach ($ways as $way) {
2601 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
2605 $forced_color =
'categtextwhite';
2608 $forced_color =
'categtextblack';
2613 $s =
'<li class="select2-search-choice-dolibarr noborderoncategories '.$forced_color.
' list"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>';
2614 if ($numElem >= 2) {
2615 $s .=
img_object(
$c->label,
'category',
'class="small"');
2617 $s .=
img_object(
$c->label,
'category',
'class="small"').
' '.
$c->label;
2624 if (!empty($toprint)) {
2625 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2628 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2631 } elseif ($type ==
'link') {
2634 $param_list = array_keys($param[
'options']);
2636 $InfoFieldList = explode(
":", $param_list[0]);
2637 $classname = $InfoFieldList[0];
2638 $classpath = $InfoFieldList[1];
2639 if (!empty($classpath)) {
2641 if (!$classname || !class_exists($classname)) {
2644 dol_syslog(
'Extrafields::showOutputField the class '.$classname.
' of the link field '.$key.
' could not be loaded from '.$classpath.
', check the extrafield definition', LOG_WARNING);
2646 if ($classname && class_exists($classname)) {
2647 $tmpobject =
new $classname($this->db);
2648 '@phan-var-force CommonObject $tmpobject';
2649 $tmpobject->fetch($value);
2651 if (get_class($tmpobject) ==
'Categorie') {
2653 $color = $tmpobject->color;
2654 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2655 $sfortag .= $tmpobject->getNomUrl(3);
2656 $sfortag .=
'</span>';
2659 $value = $tmpobject->getNomUrl(3);
2663 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2664 return 'Error bad setup of extrafield';
2667 } elseif ($type ==
'point') {
2668 if (!empty($value)) {
2669 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2671 $value = $dolgeophp->getXYString($value);
2675 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2676 if (!empty($value)) {
2677 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2679 $value = $dolgeophp->getPointString($value);
2683 } elseif ($type ==
'text') {
2684 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2685 } elseif ($type ==
'html') {
2687 } elseif ($type ==
'password') {
2688 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2689 } elseif ($type ==
'stars') {
2690 $objectid = (int)
$object->id;
2691 $nbstars = (int) $value;
2692 if ($showValueInsteadOfInputField == 1) {
2693 $value =
'<span style="display:none;" id="'.$key.$object->id.
'">'.
dol_escape_htmltag($value).
'</span>';
2695 $value =
'<input type="hidden" class="flat" name="'.$key.
'" id="'.$key.$objectid.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2698 $value .=
'<div class="star-selection" id="'.$key.$objectid.
'_selection">';
2700 while ($i <= $size) {
2701 $value .=
'<span class="star'.($i <= $nbstars ?
' active' :
'').
'" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2706 $(document).ready(function() { /* extrafields.class.php 2 */
2707 let container = $("#'.$key.$objectid.
'_selection");
2708 let selectedStars = parseInt($("#'.$key.$objectid.
'").val() || $("#'.$key.$objectid.
'").text()) || 0;
2710 if ($showValueInsteadOfInputField == 0) {
2712 container.find(".star").on("mouseover", function() {
2713 console.log("Mouse over a star");
2714 let selectedStar = $(this).data("value");
2715 container.find(".star").each(function() {
2716 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2719 container.on("mouseout", function() {
2720 console.log("Mouse out of star");
2721 container.find(".star").each(function() {
2722 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2725 container.find(".star").off("click").on("click", function() {
2726 console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
2727 selectedStars = $(this).data("value");
2728 if (selectedStars == 1 && $("#'.$key.$objectid.
'").val() == 1) {
2731 container.find("#'.$key.$objectid.
'").val(selectedStars);
2732 container.find(".star").each(function() {
2733 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2736 url: "'.DOL_URL_ROOT.
'/core/ajax/updateextrafield.php",
2740 objectId:
'.((int) $objectid).',
2741 field: \
''.dol_escape_js($key).
'\',
2742 value: selectedStars,
2743 token: \
''.currentToken().
'\'
2745 success:
function(response) {
2746 var res = JSON.parse(response);
2747 console[res.status ===
"success" ?
"log" :
"error"](res.message);
2749 error:
function(xhr,
status, error) {
2750 console.log(
"Ajax request failed while updating '.$key.':", error);
2759 $showsize = round((float) $size);
2760 if ($showsize > 48) {
2765 //print $type.'-
'.$size;