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: '".$extrafieldsobjectkey.
"',
1506 objectkey: '".$key.
"',
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;
1596 $filter_categorie =
false;
1597 if (count($InfoFieldList) > 5) {
1598 if ($InfoFieldList[0] ==
'categorie') {
1599 $filter_categorie =
true;
1603 if (!$filter_categorie) {
1604 $fields_label = isset($InfoFieldList[1]) ? explode(
'|', $InfoFieldList[1]) : array();
1605 if (!empty($fields_label)) {
1607 $keyList .= implode(
', ', $fields_label);
1613 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
1614 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
1617 if (!empty($InfoFieldList[4])) {
1619 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1620 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1623 global $dolibarr_allow_unsecured_select_in_extrafields_filter;
1624 if (!empty($dolibarr_allow_unsecured_select_in_extrafields_filter)) {
1625 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1626 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1630 if (strpos($InfoFieldList[4],
'$MODE$') !==
false) {
1631 $InfoFieldList[4] = str_replace(
'$MODE$', preg_replace(
'/[^a-z0-9_]/i',
'', (
string) $mode), $InfoFieldList[4]);
1635 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1636 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1637 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1641 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1642 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1644 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1645 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1647 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1653 preg_match_all(
'/\$(.*?)\$/', $InfoFieldList[4], $tags);
1654 foreach ($tags[0] as $keytag => $valuetag) {
1655 $property = preg_replace(
'/[^a-z0-9_]/',
'', strtolower($tags[1][$keytag]));
1656 if (strpos($property,
'options_') === 0) {
1657 if (strpos($InfoFieldList[4], $valuetag) !==
false && isset(
$object->array_options[$property]) && !empty(
$object->array_options[$property])) {
1658 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->array_options[$property], $InfoFieldList[4]);
1660 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1663 if (strpos($InfoFieldList[4], $valuetag) !==
false && property_exists(
$object, $property) && !empty(
$object->$property)) {
1664 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->$property, $InfoFieldList[4]);
1666 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1674 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1675 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1676 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1682 $sqlwhere .=
' WHERE 1=1';
1699 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1700 $sqlwhere .=
' AND entity = '.((int)
$conf->entity);
1704 $sql .= $this->db->order(implode(
', ', $fields_label));
1705 $sql .=
' LIMIT ' .
getDolGlobalInt(
'MAIN_EXTRAFIELDS_LIMIT_SELLIST_SQL', 1000);
1708 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1709 $resql = $this->db->query($sql);
1711 $out .=
'<option value="0"> </option>';
1712 $num = $this->db->num_rows($resql);
1716 $obj = $this->db->fetch_object($resql);
1718 $nameFields = $InfoFieldList[1];
1720 $nameFields = preg_replace(
'/[a-z_]+\([^\)]*\) as ([\w]+)/i',
'\1', $nameFields);
1722 $nameFields = preg_replace(
'/[^0-9a-z_\.\|]/i',
'', $nameFields);
1726 $fields_label = explode(
'|', $nameFields);
1727 if (is_array($fields_label) && count($fields_label) > 1) {
1729 foreach ($fields_label as $field_toshow) {
1730 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
1731 $labeltoshow .= $obj->$field_toshow.
' ';
1734 $labeltoshow = $obj->$nameFields;
1737 if ($value == $obj->rowid) {
1739 foreach ($fields_label as $field_toshow) {
1740 $translabel = $langs->trans($obj->$field_toshow);
1741 $labeltoshow = $translabel.
' ';
1744 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1747 $translabel = $langs->trans($obj->$nameFields);
1748 $labeltoshow = $translabel;
1750 if (empty($labeltoshow)) {
1751 $labeltoshow =
'(not defined)';
1754 if (!empty($InfoFieldList[3]) && $parentField) {
1756 $parentField = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $parentField);
1757 $parent = $parentName.
':'.$obj->{$parentField};
1760 $out .=
'<option value="'.$obj->rowid.
'"';
1761 $out .= ($value == $obj->rowid ?
' selected' :
'');
1762 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1763 $out .=
'>'.$labeltoshow.
'</option>';
1768 $this->db->free($resql);
1770 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1773 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1774 $categcode = $InfoFieldList[5];
1775 if (is_numeric($categcode)) {
1776 $tmpcategory =
new Categorie($this->db);
1777 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
1778 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
1781 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1782 $out .=
'<option value="0"> </option>';
1783 if (is_array($data)) {
1784 foreach ($data as $data_key => $data_value) {
1785 $out .=
'<option value="'.$data_key.
'"';
1786 $out .= ($value == $data_key ?
' selected' :
'');
1787 $out .=
'>'.$data_value.
'</option>';
1792 $out .=
'</select>';
1794 } elseif ($type ==
'checkbox') {
1795 $value_arr = $value;
1796 if (!is_array($value)) {
1797 $value_arr = explode(
',', $value);
1799 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0,
'', 0,
'100%');
1800 } elseif ($type ==
'radio') {
1802 $selectedvalue = ((
string) $value !==
'' ? $value : $default);
1803 foreach ($param[
'options'] as $keyopt => $val) {
1804 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1805 $out .=
' value="'.$keyopt.
'"';
1806 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1807 $out .= ((
string) $selectedvalue == (
string) $keyopt ?
' checked' :
'');
1808 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1810 } elseif ($type ==
'chkbxlst') {
1813 if (is_array($value)) {
1814 $value_arr = $value;
1816 $value_arr = explode(
',', $value);
1820 $(document).ready(function () {
1821 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1823 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1826 delay: 250, // wait 250 milliseconds before triggering the request
1827 data: function (params) {
1829 search: params.term,
1830 page: params.page || 1,
1831 objecttype: '".$extrafieldsobjectkey.
"',
1833 objectkey: '".$key.
"',
1846 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_multiselect" value="1">';
1847 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'[]" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
' multiple="multiple">';
1848 foreach ($value_arr as $value) {
1849 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1851 $out .=
'</select>';
1853 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1854 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1857 if (is_array($value)) {
1858 $value_arr = $value;
1860 $value_arr = explode(
',', $value);
1863 if (is_array($param[
'options'])) {
1864 $tmpparamoptions = array_keys($param[
'options']);
1865 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1867 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1888 if (! empty($InfoFieldList[4])) {
1890 $parenthesisopen = 0;
1891 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1892 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1895 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1900 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1901 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1903 $InfoFieldList[4] = $tmpbefore;
1904 if ($tmpafter !==
'') {
1905 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1910 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1911 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1919 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1921 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1922 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1923 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1925 $keyList = $InfoFieldList[2].
' as rowid';
1928 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1929 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1930 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1931 $keyList .=
', main.'.$parentField;
1933 $keyList .=
', '.$parentField;
1938 $filter_categorie =
false;
1939 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
1940 $InfoFieldList[5] = (
string) $InfoFieldList[5];
1941 if ($InfoFieldList[0] ==
'categorie') {
1942 $filter_categorie =
true;
1944 $filter_categorie =
false;
1949 if (!$filter_categorie) {
1950 $fields_label = explode(
'|', $InfoFieldList[1]);
1951 if (is_array($fields_label)) {
1953 $keyList .= implode(
', ', $fields_label);
1957 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
1958 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
1961 if (!empty($InfoFieldList[4])) {
1963 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1964 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1967 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1968 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1972 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1973 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1974 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1978 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1979 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1981 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1982 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1984 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1989 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1990 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1991 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1997 $sqlwhere .=
' WHERE 1=1';
2000 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
2002 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2003 $tmpcategory =
new Categorie($this->db);
2004 $tablesuffixcategory = empty($tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]];
2005 $fksuffixcategory = empty($tmpcategory->MAP_CAT_FK[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_FK[$InfoFieldList[5]];
2007 $sqlwhere .=
' AND EXISTS (SELECT fk_categorie as categid FROM '.MAIN_DB_PREFIX.
'categorie_'.$this->db->sanitize($tablesuffixcategory);
2008 $sqlwhere .=
' WHERE fk_categorie IN ('.$this->db->sanitize($InfoFieldList[6]).
')';
2009 $sqlwhere .=
' AND fk_'.$this->db->sanitize($fksuffixcategory).
' = rowid)';
2027 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
2028 $sqlwhere .=
" AND entity = ".((int)
$conf->entity);
2034 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
2036 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
2038 $resql = $this->db->query($sql);
2040 $num = $this->db->num_rows($resql);
2047 $obj = $this->db->fetch_object($resql);
2051 $fields_label = explode(
'|', $InfoFieldList[1]);
2052 if (is_array($fields_label)) {
2054 foreach ($fields_label as $field_toshow) {
2055 $labeltoshow .= $obj->$field_toshow.
' ';
2058 $labeltoshow = $obj->{$InfoFieldList[1]};
2060 $labeltoshow =
dol_trunc($labeltoshow, 45);
2062 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2064 foreach ($fields_label as $field_toshow) {
2065 $translabel = $langs->trans($obj->$field_toshow);
2066 if ($translabel != $obj->$field_toshow) {
2067 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
2069 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
2072 $data[$obj->rowid] = $labeltoshow;
2075 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
2076 if ($translabel != $obj->{$InfoFieldList[1]}) {
2077 $labeltoshow =
dol_trunc($translabel, 18);
2079 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
2082 if (empty($labeltoshow)) {
2083 $labeltoshow =
'(not defined)';
2086 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2087 $data[$obj->rowid] = $labeltoshow;
2090 if (!empty($InfoFieldList[3]) && $parentField) {
2091 $parent = $parentName.
':'.$obj->{$parentField};
2094 $data[$obj->rowid] = $labeltoshow;
2099 $this->db->free($resql);
2101 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2103 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
2106 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2107 $categcode = $InfoFieldList[5];
2108 if (is_numeric($categcode)) {
2109 $tmpcategory =
new Categorie($this->db);
2110 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
2111 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
2114 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
2115 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2119 } elseif ($type ==
'link') {
2120 $param_list = array_keys($param[
'options']);
2127 $showempty = (($required && $default !=
'') ? 0 : 1);
2129 $tmparray = explode(
':', $param_list[0]);
2131 $element = $extrafieldsobjectkey;
2132 if ($element ==
'socpeople') {
2133 $element =
'contact';
2134 } elseif ($element ==
'projet') {
2135 $element =
'project';
2139 $objectdesc = $tmparray[0].(empty($tmparray[1]) ?
"" :
":".$tmparray[1]);
2140 $objectfield = $element.
':options_'.$key;
2142 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, (
int) $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
2143 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
2144 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2148 if (!empty($value)) {
2149 $tmparray = $dolgeophp->parseGeoString($value);
2150 $geojson = $tmparray[
'geojson'];
2151 $centroidjson = $tmparray[
'centroidjson'];
2153 if (!preg_match(
'/search_/', $keyprefix)) {
2154 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
2156 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
2161 } elseif ($type ==
'password') {
2163 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
2164 $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 :
'').
'>';
2165 } elseif ($type ==
'stars') {
2166 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2167 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
2169 while ($i <= $size) {
2170 $out .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2175 jQuery(function($) { /* extrafields.class.php 1 */
2176 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
2177 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
2178 container.find(".star").each(function() {
2179 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2181 container.find(".star").on("mouseover", function() {
2182 let selectedStar = $(this).data("value");
2183 container.find(".star").each(function() {
2184 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2187 container.on("mouseout", function() {
2188 container.find(".star").each(function() {
2189 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2192 container.find(".star").off("click").on("click", function() {
2193 selectedStars = $(this).data("value");
2194 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
2197 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
2198 container.find(".star").each(function() {
2199 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2205 if (!empty($hidden)) {
2206 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
2211 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2212 $out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey,
null,
$object);
2237 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null,
$object =
null, $mode =
'')
2239 global
$conf, $langs, $hookmanager;
2241 if (is_null($outputlangs) || !is_object($outputlangs)) {
2242 $outputlangs = $langs;
2245 if (empty($extrafieldsobjectkey)) {
2246 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
2247 return 'BadValueForParamExtraFieldsObjectKey';
2250 $parameters = array(
2253 'moreparam' => $moreparam,
2254 'extrafieldsobjectkey' => $extrafieldsobjectkey,
2255 'outputlangs' => $outputlangs,
2260 $reshook = $hookmanager->executeHooks(
'showOutputExtraField', $parameters, $this, $action);
2262 return $hookmanager->resPrint;
2265 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
2266 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2267 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
2268 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
2269 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
2270 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
2271 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
2272 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
2273 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
2274 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
2275 $list = (
string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
2276 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
2277 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
2278 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
2281 $showValueInsteadOfInputField = 0;
2283 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2284 $showValueInsteadOfInputField = 1;
2287 $hidden = (empty($list) ? 1 : 0);
2296 if ($type ==
'date') {
2298 if ($value !==
'') {
2301 } elseif ($type ==
'datetime') {
2303 if ($value !==
'') {
2306 } elseif ($type ==
'duration') {
2308 if ($value !==
'') {
2309 $value = intval($value);
2312 } elseif ($type ==
'datetimegmt') {
2314 if ($value !==
'') {
2317 } elseif ($type ==
'int') {
2319 } elseif ($type ==
'double') {
2320 if (!empty($value)) {
2324 $value =
price($value, 0, $outputlangs, 0, 0, -2,
'');
2326 } elseif ($type ==
'boolean') {
2328 if (!empty($value)) {
2329 $checked =
' checked ';
2332 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
2334 $value =
yn($value ? 1 : 0);
2336 } elseif ($type ==
'mail' || $type ==
'email') {
2338 } elseif ($type ==
'ip') {
2340 } elseif ($type ==
'icon') {
2341 $value =
'<span class="'.$value.
'"></span>';
2342 } elseif ($type ==
'url') {
2344 } elseif ($type ==
'phone') {
2346 } elseif ($type ==
'price') {
2348 if ($value || $value ==
'0') {
2349 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol(
$conf->currency);
2351 } elseif ($type ==
'pricecy') {
2352 $currency =
$conf->currency;
2353 if (!empty($value)) {
2355 $pricetmp = explode(
':', $value);
2356 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
2357 $value = $pricetmp[0];
2359 if ($value || $value ==
'0') {
2360 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
2362 } elseif ($type ==
'select') {
2363 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2364 if (($pos = strpos($valstr,
"|")) !==
false) {
2365 $valstr = substr($valstr, 0, $pos);
2367 if ($langfile && $valstr) {
2368 $value = $outputlangs->trans($valstr);
2372 } elseif ($type ==
'sellist') {
2373 $param_list = array_keys($param[
'options']);
2374 $InfoFieldList = explode(
":", $param_list[0]);
2376 $selectkey =
"rowid";
2379 if (count($InfoFieldList) >= 3) {
2380 $selectkey = $InfoFieldList[2];
2381 $keyList = $InfoFieldList[2].
' as rowid';
2384 $fields_label = explode(
'|', $InfoFieldList[1]);
2385 if (is_array($fields_label)) {
2387 $keyList .= implode(
', ', $fields_label);
2390 $filter_categorie =
false;
2391 if (count($InfoFieldList) > 5) {
2392 if ($InfoFieldList[0] ==
'categorie') {
2393 $filter_categorie =
true;
2397 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2398 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2399 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2402 if ($selectkey ==
'rowid' && empty($value)) {
2403 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = 0";
2404 } elseif ($selectkey ==
'rowid') {
2405 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = ".((int) $value);
2407 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = '".$this->db->escape($value).
"'";
2411 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2413 $resql = $this->db->query($sql);
2415 if (!$filter_categorie) {
2418 $obj = $this->db->fetch_object($resql);
2421 $fields_label = explode(
'|', $InfoFieldList[1]);
2423 if (is_array($fields_label) && count($fields_label) > 1) {
2424 foreach ($fields_label as $field_toshow) {
2426 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
2427 if (!empty($obj->$field_toshow)) {
2428 $translabel = $outputlangs->trans($obj->$field_toshow);
2430 if ($translabel != $obj->$field_toshow) {
2431 $value .=
dol_trunc($translabel, 24) .
' ';
2433 $value .= $obj->$field_toshow .
' ';
2439 $tmppropname = $InfoFieldList[1];
2441 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2442 $translabel = $outputlangs->trans($obj->$tmppropname);
2444 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2447 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2452 $obj = $this->db->fetch_object($resql);
2454 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2456 $result =
$c->fetch($obj->rowid);
2458 $ways =
$c->print_all_ways();
2459 foreach ($ways as $way) {
2460 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
2464 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2467 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2469 } elseif ($type ==
'radio') {
2470 if ($required && !isset($param[
'options'][$value])) {
2471 $outputlangs->load(
'errors');
2472 $value =
'<span class="opacitymedium">'.$outputlangs->trans(
'ErrorNoValueForRadioType').
'</span>';
2474 if (isset($param[
'options'][$value])) {
2475 $value = $outputlangs->trans($param[
'options'][$value]);
2480 } elseif ($type ==
'checkbox') {
2481 $value_arr = explode(
',', $value);
2484 if (is_array($value_arr)) {
2485 foreach ($value_arr as $keyval => $valueval) {
2486 if (!empty($valueval)) {
2487 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2491 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2492 } elseif ($type ==
'chkbxlst') {
2494 if (!is_null($value) && $value !=
'') {
2495 $value_arr = explode(
',', $value);
2497 $param_list = array_keys($param[
'options']);
2498 $InfoFieldList = explode(
":", $param_list[0]);
2500 $selectkey =
"rowid";
2503 if (count($InfoFieldList) >= 3) {
2504 $selectkey = $InfoFieldList[2];
2505 $keyList = $InfoFieldList[2].
' as rowid';
2508 $fields_label = explode(
'|', $InfoFieldList[1]);
2509 if (is_array($fields_label)) {
2511 $keyList .= implode(
', ', $fields_label);
2514 $filter_categorie =
false;
2515 if (count($InfoFieldList) > 5 && ((
string) $InfoFieldList[5] !=
'')) {
2516 if ($InfoFieldList[0] ==
'categorie') {
2517 $filter_categorie =
true;
2521 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2522 $sql .=
" FROM ".$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2523 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2526 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" IN (".$this->db->sanitize(implode(
',', $value_arr)).
")";
2528 dol_syslog(get_class($this).
':showOutputField type=chkbxlst', LOG_DEBUG);
2530 $resql = $this->db->query($sql);
2533 if (!$filter_categorie) {
2536 $numOfElem = $this->db->num_rows($resql);
2537 while ($obj = $this->db->fetch_object($resql)) {
2539 $fields_label = explode(
'|', $InfoFieldList[1]);
2542 if (count($fields_label) > 0) {
2543 if ($InfoFieldList[0] ==
'societe' && $InfoFieldList[1] ==
'nom' && $InfoFieldList[2] ==
'rowid') {
2545 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
2546 $tmpthirdpartystatic =
new Societe($this->db);
2547 $tmpthirdpartystatic->id = $obj->rowid;
2548 $tmpthirdpartystatic->name = $obj->nom;
2549 if ($numOfElem >= 3) {
2550 $tmpthirdpartystatic->name = $obj->nom;
2551 $label = $tmpthirdpartystatic->getNomUrl(2);
2552 } elseif ($numOfElem >= 2) {
2553 $tmpthirdpartystatic->name =
dol_trunc($obj->nom, 5);
2554 $label = $tmpthirdpartystatic->getNomUrl(1);
2556 $tmpthirdpartystatic->name = $obj->nom;
2557 $label = $tmpthirdpartystatic->getNomUrl(1);
2560 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: '.$txtcolor.
'">';
2561 foreach ($fields_label as $field_toshow) {
2563 if (!empty($obj->$field_toshow)) {
2564 $translabel = $outputlangs->trans($obj->$field_toshow);
2566 if ($translabel != $field_toshow) {
2567 $label .=
' '.dol_trunc($translabel, 18);
2569 $label .=
' '.$obj->$field_toshow;
2574 $toprint[] = $label;
2578 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2581 $numElem = $this->db->num_rows($resql);
2582 while ($obj = $this->db->fetch_object($resql)) {
2584 $c->fetch($obj->rowid);
2585 if ((
string) $mode !=
'list') {
2586 $ways =
$c->print_all_ways();
2587 foreach ($ways as $way) {
2588 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
2592 $forced_color =
'categtextwhite';
2595 $forced_color =
'categtextblack';
2600 $s =
'<li class="select2-search-choice-dolibarr noborderoncategories '.$forced_color.
' list"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>';
2601 if ($numElem >= 2) {
2602 $s .=
img_object(
$c->label,
'category',
'class="small"');
2604 $s .=
img_object(
$c->label,
'category',
'class="small"').
' '.
$c->label;
2611 if (!empty($toprint)) {
2612 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2615 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2618 } elseif ($type ==
'link') {
2621 $param_list = array_keys($param[
'options']);
2623 $InfoFieldList = explode(
":", $param_list[0]);
2624 $classname = $InfoFieldList[0];
2625 $classpath = $InfoFieldList[1];
2626 if (!empty($classpath)) {
2628 if ($classname && class_exists($classname)) {
2629 $tmpobject =
new $classname($this->db);
2630 '@phan-var-force CommonObject $tmpobject';
2631 $tmpobject->fetch($value);
2633 if (get_class($tmpobject) ==
'Categorie') {
2635 $color = $tmpobject->color;
2636 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2637 $sfortag .= $tmpobject->getNomUrl(3);
2638 $sfortag .=
'</span>';
2641 $value = $tmpobject->getNomUrl(3);
2645 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2646 return 'Error bad setup of extrafield';
2649 } elseif ($type ==
'point') {
2650 if (!empty($value)) {
2651 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2653 $value = $dolgeophp->getXYString($value);
2657 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2658 if (!empty($value)) {
2659 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2661 $value = $dolgeophp->getPointString($value);
2665 } elseif ($type ==
'text') {
2666 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2667 } elseif ($type ==
'html') {
2669 } elseif ($type ==
'password') {
2670 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2671 } elseif ($type ==
'stars') {
2672 $objectid = (int)
$object->id;
2673 $nbstars = (int) $value;
2674 if ($showValueInsteadOfInputField == 1) {
2675 $value =
'<span style="display:none;" id="'.$key.$object->id.
'">'.
dol_escape_htmltag($value).
'</span>';
2677 $value =
'<input type="hidden" class="flat" name="'.$key.
'" id="'.$key.$objectid.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2680 $value .=
'<div class="star-selection" id="'.$key.$objectid.
'_selection">';
2682 while ($i <= $size) {
2683 $value .=
'<span class="star'.($i <= $nbstars ?
' active' :
'').
'" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2688 $(document).ready(function() { /* extrafields.class.php 2 */
2689 let container = $("#'.$key.$objectid.
'_selection");
2690 let selectedStars = parseInt($("#'.$key.$objectid.
'").val() || $("#'.$key.$objectid.
'").text()) || 0;
2692 if ($showValueInsteadOfInputField == 0) {
2694 container.find(".star").on("mouseover", function() {
2695 console.log("Mouse over a star");
2696 let selectedStar = $(this).data("value");
2697 container.find(".star").each(function() {
2698 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2701 container.on("mouseout", function() {
2702 console.log("Mouse out of star");
2703 container.find(".star").each(function() {
2704 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2707 container.find(".star").off("click").on("click", function() {
2708 console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
2709 selectedStars = $(this).data("value");
2710 if (selectedStars == 1 && $("#'.$key.$objectid.
'").val() == 1) {
2713 container.find("#'.$key.$objectid.
'").val(selectedStars);
2714 container.find(".star").each(function() {
2715 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2718 url: "'.DOL_URL_ROOT.
'/core/ajax/updateextrafield.php",
2722 objectId:
'.((int) $objectid).',
2723 field: \
''.dol_escape_js($key).
'\',
2724 value: selectedStars,
2725 token: \
''.newToken().
'\'
2727 success:
function(response) {
2728 var res = JSON.parse(response);
2729 console[res.status ===
"success" ?
"log" :
"error"](res.message);
2731 error:
function(xhr,
status, error) {
2732 console.log(
"Ajax request failed while updating '.$key.':", error);
2741 $showsize = round((float) $size);
2742 if ($showsize > 48) {
2747 //print $type.'-
'.$size;