1074 global
$conf,$hookmanager;
1076 if (empty($elementtype)) {
1077 dol_syslog(__METHOD__.
'::empty elementtype', LOG_DEBUG);
1081 if ($elementtype ==
'thirdparty') {
1082 $elementtype =
'societe';
1084 if ($elementtype ==
'contact') {
1085 $elementtype =
'socpeople';
1087 if ($elementtype ==
'order_supplier') {
1088 $elementtype =
'commande_fournisseur';
1091 if ($elementtype !=
'all' && isset($this->attributes[$elementtype]) && $this->attributes[$elementtype][
'loaded'] == 1 && !$forceload && isset($this->attributes[$elementtype][
'label'])) {
1092 return $this->attributes[$elementtype][
'label'];
1095 $array_name_label = array();
1098 $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";
1099 $sql .=
" , css, cssview, csslist, personal_data";
1100 $sql .=
" FROM ".$this->db->prefix().
"extrafields";
1102 if ($elementtype && $elementtype !=
'all') {
1103 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1105 if ($attrname && $elementtype && $elementtype !=
'all') {
1106 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1108 $sql .=
" ORDER BY pos";
1110 $resql = $this->db->query($sql);
1113 if ($this->db->num_rows($resql)) {
1114 while ($tab = $this->db->fetch_object($resql)) {
1115 if ($tab->entity != 0 && $tab->entity !=
$conf->entity) {
1117 if ($tab->fieldrequired && is_null($tab->fielddefault)) {
1118 $this->attributes[$tab->elementtype][
'mandatoryfieldsofotherentities'][$tab->name] = $tab->type;
1124 if ($tab->type !=
'separate') {
1125 $array_name_label[$tab->name] = $tab->label;
1127 $array_name_label[$tab->name] = $tab->type;
1131 $this->attributes[$tab->elementtype][
'type'][$tab->name] = $tab->type;
1132 $this->attributes[$tab->elementtype][
'label'][$tab->name] = $tab->label;
1133 $this->attributes[$tab->elementtype][
'size'][$tab->name] = $tab->size;
1134 $this->attributes[$tab->elementtype][
'elementtype'][$tab->name] = $tab->elementtype;
1135 $this->attributes[$tab->elementtype][
'default'][$tab->name] = $tab->fielddefault;
1136 $this->attributes[$tab->elementtype][
'computed'][$tab->name] = $tab->fieldcomputed;
1137 $this->attributes[$tab->elementtype][
'unique'][$tab->name] = $tab->fieldunique;
1138 $this->attributes[$tab->elementtype][
'required'][$tab->name] = $tab->fieldrequired;
1139 $this->attributes[$tab->elementtype][
'param'][$tab->name] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1140 $this->attributes[$tab->elementtype][
'pos'][$tab->name] = $tab->pos;
1141 $this->attributes[$tab->elementtype][
'alwayseditable'][$tab->name] = $tab->alwayseditable;
1142 $this->attributes[$tab->elementtype][
'emptyonclone'][$tab->name] = $tab->emptyonclone;
1143 $this->attributes[$tab->elementtype][
'perms'][$tab->name] = $tab->perms;
1144 $this->attributes[$tab->elementtype][
'langfile'][$tab->name] = $tab->langs;
1145 $this->attributes[$tab->elementtype][
'list'][$tab->name] = $tab->list;
1146 $this->attributes[$tab->elementtype][
'printable'][$tab->name] = $tab->printable;
1147 $this->attributes[$tab->elementtype][
'showintooltip'][$tab->name] = $tab->showintooltip;
1148 $this->attributes[$tab->elementtype][
'totalizable'][$tab->name] = ($tab->totalizable ? 1 : 0);
1149 $this->attributes[$tab->elementtype][
'entityid'][$tab->name] = $tab->entity;
1150 $this->attributes[$tab->elementtype][
'enabled'][$tab->name] = $tab->enabled;
1151 $this->attributes[$tab->elementtype][
'help'][$tab->name] = $tab->help;
1152 $this->attributes[$tab->elementtype][
'aiprompt'][$tab->name] = $tab->aiprompt;
1153 $this->attributes[$tab->elementtype][
'css'][$tab->name] = $tab->css;
1154 $this->attributes[$tab->elementtype][
'cssview'][$tab->name] = $tab->cssview;
1155 $this->attributes[$tab->elementtype][
'csslist'][$tab->name] = $tab->csslist;
1156 $this->attributes[$tab->elementtype][
'personal_data'][$tab->name] = $tab->personal_data;
1158 $this->attributes[$tab->elementtype][
'loaded'] = 1;
1163 $this->attributes[$elementtype][
'loaded'] = 1;
1164 $this->attributes[$elementtype][
'count'] = $count;
1167 $this->error = $this->db->lasterror();
1168 dol_syslog(get_class($this).
"::fetch_name_optionals_label ".$this->error, LOG_ERR);
1172 if (is_object($hookmanager)) {
1173 $parameters = array(
1174 'elementtype' => $elementtype,
1175 'attrname' => $attrname,
1176 'forceload' => $forceload,
1178 $reshook = $hookmanager->executeHooks(
'completeFetchNameOptionalsLabel', $parameters, $this);
1179 if ($reshook > 0 && is_array($hookmanager->resArray)) {
1181 foreach ($hookmanager->resArray as $key => $val) {
1182 $array_name_label[$key] = $val;
1187 return $array_name_label;
1207 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'',
$object = 0, $extrafieldsobjectkey =
'', $mode = 0, $filteronparentvalue = 0)
1209 global
$conf, $langs, $form, $hookmanager;
1211 if (!is_object($form)) {
1212 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
1213 $form =
new Form($this->db);
1217 $morecss =
'maxwidth125';
1220 $parameters = array(
1223 'moreparam' => $moreparam,
1224 'keysuffix' => $keysuffix,
1225 'keyprefix' => $keyprefix,
1226 'morecss' => $morecss,
1228 'extrafieldsobjectkey' => $extrafieldsobjectkey,
1233 $reshook = $hookmanager->executeHooks(
'showInputExtraField', $parameters, $this, $action);
1235 return $hookmanager->resPrint;
1242 if (!preg_match(
'/options_$/', $keyprefix)) {
1243 $keyprefix .=
'options_';
1246 if (empty($extrafieldsobjectkey)) {
1247 dol_syslog(get_class($this).
'::showInputField extrafieldsobjectkey required', LOG_ERR);
1248 return 'BadValueForParamExtraFieldsObjectKey';
1251 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1252 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1253 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1254 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1255 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1256 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1257 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1258 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1259 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
1260 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1261 $list = (string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
1262 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
1263 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1264 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
1265 $hidden = (empty($list) ? 1 : 0);
1271 if (!preg_match(
'/^search_/', $keyprefix)) {
1272 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
1280 if (empty($morecss)) {
1282 if ($type ==
'date') {
1283 $morecss =
'minwidth100imp';
1284 } elseif ($type ==
'datetime' || $type ==
'datetimegmt' || $type ==
'link') {
1285 $morecss =
'minwidth200imp';
1286 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
1287 $morecss =
'maxwidth75';
1288 } elseif ($type ==
'password') {
1289 $morecss =
'maxwidth100';
1290 } elseif ($type ==
'url') {
1291 $morecss =
'minwidth400';
1292 } elseif ($type ==
'boolean') {
1294 } elseif ($type ==
'radio') {
1295 $morecss =
'width25';
1297 if (empty($size) || round((
float) $size) < 12) {
1298 $morecss =
'minwidth100';
1299 } elseif (round((
float) $size) <= 48) {
1300 $morecss =
'minwidth200';
1302 $morecss =
'minwidth400';
1306 if (!empty($this->attributes[$extrafieldsobjectkey][
'css'][$key])) {
1307 $morecss = $this->attributes[$extrafieldsobjectkey][
'css'][$key];
1311 if (in_array($type, array(
'date'))) {
1312 $tmp = explode(
',', $size);
1317 if (!$required && $value ==
'') {
1324 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1325 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1327 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1328 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"));
1329 $out .=
'</div><div class="nowrap">';
1330 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"));
1331 $out .=
'</div></div>';
1335 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required ? 0 : 2,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1337 } elseif (in_array($type, array(
'datetime',
'datetimegmt'))) {
1338 $tmp = explode(
',', $size);
1343 if (!$required && $value ==
'') {
1350 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1351 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1353 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1354 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"),
'tzuserrel');
1355 $out .=
'</div><div class="nowrap">';
1356 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
1357 $out .=
'</div></div>';
1361 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required ? 0 : 2,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1363 } elseif (in_array($type, array(
'int',
'integer'))) {
1364 $tmp = explode(
',', $size);
1366 $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 :
'').
'>';
1367 } elseif (preg_match(
'/varchar/', $type)) {
1368 $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 :
'').
'>';
1369 } elseif ($type ==
'phone' && $mode != 1) {
1370 $out = $form->showPhoneInput($value, $keyprefix.$key.$keysuffix, (is_object(
$object) && !empty(
$object->country_id)) ?
$object->country_id : 0);
1371 } elseif (in_array($type, array(
'email',
'mail',
'ip',
'phone',
'url'))) {
1372 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1373 } elseif ($type ==
'icon') {
1379 $out .=
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat '.$morecss.
' maxwidthonsmartphone"';
1380 $out .=
' name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1383 $options =
"{ title: '<b>".$langs->trans(
"IconFieldSelector").
"</b>', placement: 'right', showFooter: false, templates: {";
1384 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
1385 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
1388 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
1389 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"".$langs->trans(
"TypeToFilter").
"\" />',";
1390 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
1391 $options .=
" <div class=\"arrow\" ></div>";
1392 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
1393 $options .=
" <div class=\"popover-content \" ></div>";
1394 $options .=
"</div>'}}";
1395 $out .=
"$('#".$keyprefix.$key.$keysuffix.
"').iconpicker(".$options.
");";
1396 $out .=
'</script>';
1398 } elseif ($type ==
'text') {
1399 if (!preg_match(
'/search_/', $keyprefix)) {
1400 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1401 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1402 $out = (string) $doleditor->Create(1);
1404 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1406 } elseif ($type ==
'html') {
1407 if (!preg_match(
'/search_/', $keyprefix)) {
1408 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1409 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
1410 $out = (string) $doleditor->Create(1);
1412 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1414 } elseif ($type ==
'boolean') {
1417 if (!empty($value)) {
1418 $checked =
' checked value="1" ';
1420 $checked =
' value="1" ';
1422 $out =
'<input type="checkbox" class="flat valignmiddle'.($morecss ?
' '.$morecss :
'').
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1424 $out = $form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1, 1,
'width75 yesno');
1426 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_boolean" value="1">';
1427 } elseif ($type ==
'price') {
1428 if (!empty($value)) {
1429 $value =
price($value);
1431 $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).
'">';
1432 } elseif ($type ==
'pricecy') {
1433 $currency =
$conf->currency;
1434 if (!empty($value)) {
1436 $pricetmp = explode(
':', $value);
1437 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
1438 $value =
price($pricetmp[0]);
1440 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1441 $out .= $form->selectCurrency($currency, $keyprefix.$key.$keysuffix.
'currency_id');
1442 } elseif ($type ==
'duration') {
1443 $value = intval($value);
1444 $out = $form->select_duration($keyprefix . $key, $value, 0,
'text', 0, 1);
1445 } elseif ($type ==
'double') {
1446 if (!empty($value)) {
1447 $value =
price($value);
1449 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1450 } elseif ($type ==
'select') {
1454 foreach ($param[
'options'] as $okey => $val) {
1455 if ((
string) $okey ==
'') {
1459 $valarray = explode(
'|', $val);
1460 $val = $valarray[0];
1462 if ($langfile && $val) {
1463 $options[$okey] = $langs->trans($val);
1465 $options[$okey] = $val;
1468 $selected = array();
1469 if (!is_array($value)) {
1470 $selected = explode(
',', $value);
1473 $out .= $form->multiselectarray($keyprefix.$key.$keysuffix, $options, $selected, 0, 0, $morecss, 0, 0,
'',
'',
'', (
int) (!empty(
$conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
1476 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1477 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1480 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1481 $out .=
'<option value="0"> </option>';
1482 foreach ($param[
'options'] as $key2 => $val2) {
1483 if ((
string) $key2 ==
'') {
1486 $valarray = explode(
'|', $val2);
1487 $val2 = $valarray[0];
1489 if (!empty($valarray[1])) {
1490 $parent = $valarray[1];
1496 if ($filteronparentvalue && !empty($parent) && (
string) $value != (
string) $key2) {
1497 $tmpparent = explode(
':', $parent, 2);
1498 if (!empty($tmpparent[1]) && is_object(
$object)) {
1499 $parentvalue = isset(
$object->array_options[
'options_'.$tmpparent[0]]) ?
$object->array_options[
'options_'.$tmpparent[0]] :
'';
1500 if ((
string) $parentvalue !==
'' && (
string) $parentvalue !== (
string) $tmpparent[1]) {
1505 $out .=
'<option value="'.$key2.
'"';
1506 $out .= (((string) $value == (
string) $key2) ?
' selected' :
'');
1507 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1509 if ($langfile && $val2) {
1510 $out .= $langs->trans($val2);
1514 $out .=
'</option>';
1516 $out .=
'</select>';
1518 } elseif ($type ==
'sellist') {
1520 if (!empty(
$conf->use_javascript_ajax)) {
1525 $(document).ready(function () {
1526 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1528 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1530 delay: 250, // wait 250 milliseconds before triggering the request
1531 data: function (params) {
1533 search: params.term,
1534 page: params.page || 1,
1535 objecttype: '".dol_escape_js($extrafieldsobjectkey).
"',
1538 mode: '".((int) $mode).
"',
1547 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1548 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1549 $out .=
'</select>';
1551 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1552 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1557 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1558 if (is_array($param[
'options'])) {
1561 $tmpparamoptions = array_keys($param[
'options']);
1562 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1564 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1576 if (! empty($InfoFieldList[4])) {
1578 $parenthesisopen = 0;
1579 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1580 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1583 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1588 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1589 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1591 $InfoFieldList[4] = $tmpbefore;
1592 if ($tmpafter !==
'') {
1593 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1598 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1599 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1609 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1611 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1612 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1613 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1615 $keyList = $InfoFieldList[2].
' as rowid';
1618 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1619 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1620 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1621 $keyList .=
', main.'.$parentField;
1623 $keyList .=
', '.$parentField;
1626 if (!empty($parentField)) {
1627 $keyList .=
', '.$parentField;
1631 $filter_categorie =
false;
1632 if (count($InfoFieldList) > 5) {
1633 if ($InfoFieldList[0] ==
'categorie') {
1634 $filter_categorie =
true;
1638 if (!$filter_categorie) {
1639 $fields_label = isset($InfoFieldList[1]) ? explode(
'|', $InfoFieldList[1]) : array();
1640 if (!empty($fields_label)) {
1642 $keyList .= implode(
', ', $fields_label);
1648 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
1649 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
1652 if (!empty($InfoFieldList[4])) {
1654 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1655 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1658 global $dolibarr_allow_unsecured_select_in_extrafields_filter;
1659 if (!empty($dolibarr_allow_unsecured_select_in_extrafields_filter)) {
1660 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1661 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1665 if (strpos($InfoFieldList[4],
'$MODE$') !==
false) {
1666 $InfoFieldList[4] = str_replace(
'$MODE$', preg_replace(
'/[^a-z0-9_]/i',
'', (
string) $mode), $InfoFieldList[4]);
1670 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1671 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1672 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1677 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1678 $InfoFieldList[4] = preg_replace($word,
'1:=:1', $InfoFieldList[4]);
1680 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1681 $InfoFieldList[4] = preg_replace($word,
'1:=:1', $InfoFieldList[4]);
1683 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *: *[<>!=]?= *: *\$ID\$#';
1684 $InfoFieldList[4] = preg_replace($word,
'1:=:1', $InfoFieldList[4]);
1686 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1692 preg_match_all(
'/\$(.*?)\$/', $InfoFieldList[4], $tags);
1693 foreach ($tags[0] as $keytag => $valuetag) {
1694 $property = preg_replace(
'/[^a-z0-9_]/',
'', strtolower($tags[1][$keytag]));
1695 if (strpos($property,
'options_') === 0) {
1696 if (strpos($InfoFieldList[4], $valuetag) !==
false && isset(
$object->array_options[$property]) && !empty(
$object->array_options[$property])) {
1697 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->array_options[$property], $InfoFieldList[4]);
1699 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1702 if (strpos($InfoFieldList[4], $valuetag) !==
false && property_exists(
$object, $property) && !empty(
$object->$property)) {
1703 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->$property, $InfoFieldList[4]);
1705 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1713 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1714 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1715 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1721 $sqlwhere .=
' WHERE 1=1';
1738 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1739 $sqlwhere .=
' AND entity = '.((int)
$conf->entity);
1743 $sql .= $this->db->order(implode(
', ', $fields_label));
1744 $sql .=
' LIMIT ' .
getDolGlobalInt(
'MAIN_EXTRAFIELDS_LIMIT_SELLIST_SQL', 1000);
1747 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1748 $resql = $this->db->query($sql);
1750 $out .=
'<option value="0"> </option>';
1751 $num = $this->db->num_rows($resql);
1755 $obj = $this->db->fetch_object($resql);
1757 $nameFields = $InfoFieldList[1];
1759 $nameFields = preg_replace(
'/[a-z_]+\([^\)]*\) as ([\w]+)/i',
'\1', $nameFields);
1761 $nameFields = preg_replace(
'/[^0-9a-z_\.\|]/i',
'', $nameFields);
1765 $fields_label = explode(
'|', $nameFields);
1766 if (is_array($fields_label) && count($fields_label) > 1) {
1768 foreach ($fields_label as $field_toshow) {
1769 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
1770 $labeltoshow .= $obj->$field_toshow.
' ';
1773 $labeltoshow = $obj->$nameFields;
1776 if ($value == $obj->rowid) {
1778 foreach ($fields_label as $field_toshow) {
1779 $translabel = $langs->trans($obj->$field_toshow);
1780 $labeltoshow = $translabel.
' ';
1783 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1786 $translabel = $langs->trans($obj->$nameFields);
1787 $labeltoshow = $translabel;
1789 if (empty($labeltoshow)) {
1790 $labeltoshow =
'(not defined)';
1793 if (!empty($InfoFieldList[3]) && $parentField) {
1795 $parentField = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $parentField);
1796 $parent = $parentName.
':'.$obj->{$parentField};
1799 $out .=
'<option value="'.$obj->rowid.
'"';
1800 $out .= ($value == $obj->rowid ?
' selected' :
'');
1801 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1802 $out .=
'>'.$labeltoshow.
'</option>';
1807 $this->db->free($resql);
1809 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1812 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1813 $categcode = $InfoFieldList[5];
1814 if (is_numeric($categcode)) {
1815 $tmpcategory =
new Categorie($this->db);
1816 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
1817 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
1820 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1821 $out .=
'<option value="0"> </option>';
1822 if (is_array($data)) {
1823 foreach ($data as $data_key => $data_value) {
1824 $out .=
'<option value="'.$data_key.
'"';
1825 $out .= ($value == $data_key ?
' selected' :
'');
1826 $out .=
'>'.$data_value.
'</option>';
1831 $out .=
'</select>';
1833 } elseif ($type ==
'checkbox') {
1834 $value_arr = $value;
1835 if (!is_array($value)) {
1836 $value_arr = explode(
',', $value);
1838 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0,
'', 0,
'100%');
1839 } elseif ($type ==
'radio') {
1841 $selectedvalue = ((string) $value !==
'' ? $value : $default);
1842 foreach ($param[
'options'] as $keyopt => $val) {
1843 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1844 $out .=
' value="'.$keyopt.
'"';
1845 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1846 $out .= ((string) $selectedvalue == (
string) $keyopt ?
' checked' :
'');
1847 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1849 } elseif ($type ==
'chkbxlst') {
1852 if (is_array($value)) {
1853 $value_arr = $value;
1855 $value_arr = explode(
',', $value);
1860 $(document).ready(function () {
1861 $('#".dol_escape_js($keyprefix.$key.$keysuffix).
"').select2({
1863 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1866 delay: 250, // wait 250 milliseconds before triggering the request
1867 data: function (params) {
1869 search: params.term,
1870 page: params.page || 1,
1871 objecttype: '".dol_escape_js($extrafieldsobjectkey).
"',
1874 mode: '".((int) $mode).
"',
1886 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_multiselect" value="1">';
1887 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'[]" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
' multiple="multiple">';
1888 foreach ($value_arr as $value) {
1889 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1891 $out .=
'</select>';
1893 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1894 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1897 if (is_array($value)) {
1898 $value_arr = $value;
1900 $value_arr = explode(
',', $value);
1903 if (is_array($param[
'options'])) {
1904 $tmpparamoptions = array_keys($param[
'options']);
1905 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1907 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1928 if (! empty($InfoFieldList[4])) {
1930 $parenthesisopen = 0;
1931 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1932 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1935 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1940 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1941 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1943 $InfoFieldList[4] = $tmpbefore;
1944 if ($tmpafter !==
'') {
1945 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1950 if (preg_match(
'/^\(?([a-z0-9_]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1951 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1959 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1961 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1962 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1963 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1965 $keyList = $InfoFieldList[2].
' as rowid';
1968 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1969 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1970 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1971 $keyList .=
', main.'.$parentField;
1973 $keyList .=
', '.$parentField;
1976 if (!empty($parentField)) {
1977 $keyList .=
', '.$parentField;
1981 $InfoFieldList[5] = (string) ($InfoFieldList[5]??
'');
1983 $filter_categorie =
false;
1984 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
1985 if ($InfoFieldList[0] ==
'categorie') {
1986 $filter_categorie =
true;
1988 $filter_categorie =
false;
1993 if (!$filter_categorie) {
1994 $fields_label = explode(
'|', $InfoFieldList[1]);
1995 if (is_array($fields_label)) {
1997 $keyList .= implode(
', ', $fields_label);
2001 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2002 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2005 if (!empty($InfoFieldList[4])) {
2007 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
2008 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
2011 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
2012 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
2016 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
2017 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
2018 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
2022 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
2023 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
2025 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
2026 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
2028 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
2033 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2034 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
2035 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
2041 $sqlwhere .=
' WHERE 1=1';
2044 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
2046 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2047 $tmpcategory =
new Categorie($this->db);
2048 $tablesuffixcategory = empty($tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]];
2049 $fksuffixcategory = empty($tmpcategory->MAP_CAT_FK[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_FK[$InfoFieldList[5]];
2051 $sqlwhere .=
' AND EXISTS (SELECT fk_categorie as categid FROM '.MAIN_DB_PREFIX.
'categorie_'.$this->db->sanitize($tablesuffixcategory);
2052 $sqlwhere .=
' WHERE fk_categorie IN ('.$this->db->sanitize($InfoFieldList[6]).
')';
2053 $sqlwhere .=
' AND fk_'.$this->db->sanitize($fksuffixcategory).
' = rowid)';
2071 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
2072 $sqlwhere .=
" AND entity = ".((int)
$conf->entity);
2078 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
2080 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
2082 $resql = $this->db->query($sql);
2084 $num = $this->db->num_rows($resql);
2091 $obj = $this->db->fetch_object($resql);
2095 $fields_label = explode(
'|', $InfoFieldList[1]);
2096 if (is_array($fields_label)) {
2098 foreach ($fields_label as $field_toshow) {
2099 $labeltoshow .= $obj->$field_toshow.
' ';
2102 $labeltoshow = $obj->{$InfoFieldList[1]};
2104 $labeltoshow =
dol_trunc($labeltoshow, 45);
2106 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2108 foreach ($fields_label as $field_toshow) {
2109 $translabel = $langs->trans($obj->$field_toshow);
2110 if ($translabel != $obj->$field_toshow) {
2111 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
2113 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
2116 $data[$obj->rowid] = $labeltoshow;
2119 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
2120 if ($translabel != $obj->{$InfoFieldList[1]}) {
2121 $labeltoshow =
dol_trunc($translabel, 18);
2123 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
2126 if (empty($labeltoshow)) {
2127 $labeltoshow =
'(not defined)';
2130 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2131 $data[$obj->rowid] = $labeltoshow;
2134 if (!empty($InfoFieldList[3]) && $parentField) {
2135 $parent = $parentName.
':'.$obj->{$parentField};
2138 $data[$obj->rowid] = $labeltoshow;
2143 $this->db->free($resql);
2145 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2147 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
2150 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2151 $categcode = $InfoFieldList[5];
2152 if (is_numeric($categcode)) {
2153 $tmpcategory =
new Categorie($this->db);
2154 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
2155 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
2158 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
2159 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2163 } elseif ($type ==
'link') {
2164 $param_list = array_keys($param[
'options']);
2171 $showempty = (($required && $default !=
'') ? 0 : 1);
2173 $tmparray = explode(
':', $param_list[0]);
2175 $element = $extrafieldsobjectkey;
2176 if ($element ==
'socpeople') {
2177 $element =
'contact';
2178 } elseif ($element ==
'projet') {
2179 $element =
'project';
2183 $objectdesc = $tmparray[0].(empty($tmparray[1]) ?
"" :
":".$tmparray[1]);
2184 $objectfield = $element.
':options_'.$key;
2186 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, (
int) $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
2187 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
2188 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2192 if (!empty($value)) {
2193 $tmparray = $dolgeophp->parseGeoString($value);
2194 $geojson = $tmparray[
'geojson'];
2195 $centroidjson = $tmparray[
'centroidjson'];
2197 if (!preg_match(
'/search_/', $keyprefix)) {
2198 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
2200 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
2205 } elseif ($type ==
'password') {
2207 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
2208 $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 :
'').
'>';
2209 } elseif ($type ==
'stars') {
2210 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2211 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
2213 while ($i <= $size) {
2214 $out .=
'<span class="star" data-value="'.$i.
'">'.img_picto(
'',
'fontawesome_star_fas').
'</span>';
2219 jQuery(function($) { /* extrafields.class.php 1 */
2220 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
2221 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
2222 container.find(".star").each(function() {
2223 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2225 container.find(".star").on("mouseover", function() {
2226 let selectedStar = $(this).data("value");
2227 container.find(".star").each(function() {
2228 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2231 container.on("mouseout", function() {
2232 container.find(".star").each(function() {
2233 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2236 container.find(".star").off("click").on("click", function() {
2237 selectedStars = $(this).data("value");
2238 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
2241 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
2242 container.find(".star").each(function() {
2243 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2249 if (!empty($hidden)) {
2250 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
2255 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2256 $out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey,
null,
$object);
2281 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null,
$object =
null, $mode =
'')
2283 global
$conf, $langs, $hookmanager;
2285 if (is_null($outputlangs) || !is_object($outputlangs)) {
2286 $outputlangs = $langs;
2289 if (empty($extrafieldsobjectkey)) {
2290 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
2291 return 'BadValueForParamExtraFieldsObjectKey';
2294 $parameters = array(
2297 'moreparam' => $moreparam,
2298 'extrafieldsobjectkey' => $extrafieldsobjectkey,
2299 'outputlangs' => $outputlangs,
2304 $reshook = $hookmanager->executeHooks(
'showOutputExtraField', $parameters, $this, $action);
2306 return $hookmanager->resPrint;
2309 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
2310 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2311 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
2312 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
2313 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
2314 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
2315 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
2316 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
2317 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
2318 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
2319 $list = (string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
2320 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
2321 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
2322 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
2325 $showValueInsteadOfInputField = 0;
2327 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2328 $showValueInsteadOfInputField = 1;
2331 $hidden = (empty($list) ? 1 : 0);
2340 if ($type ==
'date') {
2342 if ($value !==
'') {
2345 } elseif ($type ==
'datetime') {
2347 if ($value !==
'') {
2350 } elseif ($type ==
'duration') {
2352 if ($value !==
'') {
2353 $value = intval($value);
2356 } elseif ($type ==
'datetimegmt') {
2358 if ($value !==
'') {
2361 } elseif ($type ==
'int') {
2363 } elseif ($type ==
'double') {
2364 if (!empty($value)) {
2368 $value =
price($value, 0, $outputlangs, 0, 0, -2,
'');
2370 } elseif ($type ==
'boolean') {
2372 if (!empty($value)) {
2373 $checked =
' checked ';
2376 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
2378 $value = yn($value ? 1 : 0);
2380 } elseif ($type ==
'mail' || $type ==
'email') {
2382 } elseif ($type ==
'ip') {
2384 } elseif ($type ==
'icon') {
2385 $value =
'<span class="'.$value.
'"></span>';
2386 } elseif ($type ==
'url') {
2388 } elseif ($type ==
'phone') {
2390 } elseif ($type ==
'price') {
2392 if ($value || $value ==
'0') {
2393 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol(
$conf->currency);
2395 } elseif ($type ==
'pricecy') {
2396 $currency =
$conf->currency;
2397 if (!empty($value)) {
2399 $pricetmp = explode(
':', $value);
2400 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
2401 $value = $pricetmp[0];
2403 if ($value || $value ==
'0') {
2404 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
2406 } elseif ($type ==
'select') {
2407 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2408 if (($pos = strpos($valstr,
"|")) !==
false) {
2409 $valstr = substr($valstr, 0, $pos);
2411 if ($langfile && $valstr) {
2412 $value = $outputlangs->trans($valstr);
2416 } elseif ($type ==
'sellist') {
2417 $param_list = array_keys($param[
'options']);
2418 $InfoFieldList = explode(
":", $param_list[0]);
2420 $selectkey =
"rowid";
2423 if (count($InfoFieldList) >= 3) {
2424 $selectkey = $InfoFieldList[2];
2425 $keyList = $InfoFieldList[2].
' as rowid';
2428 $fields_label = explode(
'|', $InfoFieldList[1]);
2429 if (is_array($fields_label)) {
2431 $keyList .= implode(
', ', $fields_label);
2434 $filter_categorie =
false;
2435 if (count($InfoFieldList) > 5) {
2436 if ($InfoFieldList[0] ==
'categorie') {
2437 $filter_categorie =
true;
2441 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2442 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2443 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2446 if ($selectkey ==
'rowid' && empty($value)) {
2447 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = 0";
2448 } elseif ($selectkey ==
'rowid') {
2449 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = ".((int) $value);
2451 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = '".$this->db->escape($value).
"'";
2455 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2457 $resql = $this->db->query($sql);
2459 if (!$filter_categorie) {
2462 $obj = $this->db->fetch_object($resql);
2465 $fields_label = explode(
'|', $InfoFieldList[1]);
2467 if (is_array($fields_label) && count($fields_label) > 1) {
2468 foreach ($fields_label as $field_toshow) {
2470 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
2471 if (!empty($obj->$field_toshow)) {
2472 $translabel = $outputlangs->trans($obj->$field_toshow);
2474 if ($translabel != $obj->$field_toshow) {
2475 $value .=
dol_trunc($translabel, 24) .
' ';
2477 $value .= $obj->$field_toshow .
' ';
2483 $tmppropname = $InfoFieldList[1];
2485 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2486 $translabel = $outputlangs->trans($obj->$tmppropname);
2488 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2491 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2496 $obj = $this->db->fetch_object($resql);
2498 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2500 $result =
$c->fetch($obj->rowid);
2502 $ways =
$c->print_all_ways();
2503 foreach ($ways as $way) {
2504 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' . img_object(
'',
'category') .
' ' . $way .
'</li>';
2508 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2511 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2513 } elseif ($type ==
'radio') {
2514 if ($required && !isset($param[
'options'][$value])) {
2515 $outputlangs->load(
'errors');
2516 $value =
'<span class="opacitymedium">'.$outputlangs->trans(
'ErrorNoValueForRadioType').
'</span>';
2518 if (isset($param[
'options'][$value])) {
2519 $value = $outputlangs->trans($param[
'options'][$value]);
2524 } elseif ($type ==
'checkbox') {
2525 $value_arr = explode(
',', $value);
2528 if (is_array($value_arr)) {
2529 foreach ($value_arr as $keyval => $valueval) {
2530 if (!empty($valueval)) {
2531 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2535 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2536 } elseif ($type ==
'chkbxlst') {
2538 if (!is_null($value) && $value !=
'') {
2539 $value_arr = explode(
',', $value);
2541 $param_list = array_keys($param[
'options']);
2542 $InfoFieldList = explode(
":", $param_list[0]);
2544 $selectkey =
"rowid";
2547 if (count($InfoFieldList) >= 3) {
2548 $selectkey = $InfoFieldList[2];
2549 $keyList = $InfoFieldList[2].
' as rowid';
2552 $fields_label = explode(
'|', $InfoFieldList[1]);
2553 if (is_array($fields_label)) {
2555 $keyList .= implode(
', ', $fields_label);
2558 $filter_categorie =
false;
2559 if (count($InfoFieldList) > 5 && ((
string) $InfoFieldList[5] !=
'')) {
2560 if ($InfoFieldList[0] ==
'categorie') {
2561 $filter_categorie =
true;
2565 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2566 $sql .=
" FROM ".$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2567 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2570 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" IN (".$this->db->sanitize(implode(
',', $value_arr)).
")";
2572 dol_syslog(get_class($this).
':showOutputField type=chkbxlst', LOG_DEBUG);
2574 $resql = $this->db->query($sql);
2577 if (!$filter_categorie) {
2580 $numOfElem = $this->db->num_rows($resql);
2581 while ($obj = $this->db->fetch_object($resql)) {
2583 $fields_label = explode(
'|', $InfoFieldList[1]);
2586 if (count($fields_label) > 0) {
2587 if ($InfoFieldList[0] ==
'societe' && $InfoFieldList[1] ==
'nom' && $InfoFieldList[2] ==
'rowid') {
2589 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
2590 $tmpthirdpartystatic =
new Societe($this->db);
2591 $tmpthirdpartystatic->id = $obj->rowid;
2592 $tmpthirdpartystatic->name = $obj->nom;
2593 if ($numOfElem >= 3) {
2594 $tmpthirdpartystatic->name = $obj->nom;
2595 $label = $tmpthirdpartystatic->getNomUrl(2);
2596 } elseif ($numOfElem >= 2) {
2597 $tmpthirdpartystatic->name =
dol_trunc($obj->nom, 5);
2598 $label = $tmpthirdpartystatic->getNomUrl(1);
2600 $tmpthirdpartystatic->name = $obj->nom;
2601 $label = $tmpthirdpartystatic->getNomUrl(1);
2604 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: '.$txtcolor.
'">';
2605 foreach ($fields_label as $field_toshow) {
2607 if (!empty($obj->$field_toshow)) {
2608 $translabel = $outputlangs->trans($obj->$field_toshow);
2610 if ($translabel != $field_toshow) {
2611 $label .=
' '.dol_trunc($translabel, 18);
2613 $label .=
' '.$obj->$field_toshow;
2618 $toprint[] = $label;
2622 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2625 $numElem = $this->db->num_rows($resql);
2626 while ($obj = $this->db->fetch_object($resql)) {
2628 $c->fetch($obj->rowid);
2629 if ((
string) $mode !=
'list') {
2630 $ways =
$c->print_all_ways();
2631 foreach ($ways as $way) {
2632 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.img_object(
'',
'category').
' '.$way.
'</li>';
2636 $forced_color =
'categtextwhite';
2639 $forced_color =
'categtextblack';
2644 $s =
'<li class="select2-search-choice-dolibarr noborderoncategories '.$forced_color.
' list"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>';
2645 if ($numElem >= 2) {
2646 $s .= img_object(
$c->label,
'category',
'class="small"');
2648 $s .= img_object(
$c->label,
'category',
'class="small"').
' '.
$c->label;
2655 if (!empty($toprint)) {
2656 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2659 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2662 } elseif ($type ==
'link') {
2665 $param_list = array_keys($param[
'options']);
2667 $InfoFieldList = explode(
":", $param_list[0]);
2668 $classname = $InfoFieldList[0];
2669 $classpath = $InfoFieldList[1];
2670 if (!empty($classpath)) {
2672 if (!$classname || !class_exists($classname)) {
2675 dol_syslog(
'Extrafields::showOutputField the class '.$classname.
' of the link field '.$key.
' could not be loaded from '.$classpath.
', check the extrafield definition', LOG_WARNING);
2677 if ($classname && class_exists($classname)) {
2678 $tmpobject =
new $classname($this->db);
2679 '@phan-var-force CommonObject $tmpobject';
2680 $tmpobject->fetch($value);
2682 if (get_class($tmpobject) ==
'Categorie') {
2684 $color = $tmpobject->color;
2685 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2686 $sfortag .= $tmpobject->getNomUrl(3);
2687 $sfortag .=
'</span>';
2690 $value = $tmpobject->getNomUrl(3);
2694 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2695 return 'Error bad setup of extrafield';
2698 } elseif ($type ==
'point') {
2699 if (!empty($value)) {
2700 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2702 $value = $dolgeophp->getXYString($value);
2706 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2707 if (!empty($value)) {
2708 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2710 $value = $dolgeophp->getPointString($value);
2714 } elseif ($type ==
'text') {
2715 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2716 } elseif ($type ==
'html') {
2718 } elseif ($type ==
'password') {
2719 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2720 } elseif ($type ==
'stars') {
2721 $objectid = (int)
$object->id;
2722 $nbstars = (int) $value;
2723 if ($showValueInsteadOfInputField == 1) {
2724 $value =
'<span style="display:none;" id="'.$key.$object->id.
'">'.
dol_escape_htmltag($value).
'</span>';
2726 $value =
'<input type="hidden" class="flat" name="'.$key.
'" id="'.$key.$objectid.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2729 $value .=
'<div class="star-selection" id="'.$key.$objectid.
'_selection">';
2731 while ($i <= $size) {
2732 $value .=
'<span class="star'.($i <= $nbstars ?
' active' :
'').
'" data-value="'.$i.
'">'.img_picto(
'',
'fontawesome_star_fas').
'</span>';
2737 $(document).ready(function() { /* extrafields.class.php 2 */
2738 let container = $("#'.$key.$objectid.
'_selection");
2739 let selectedStars = parseInt($("#'.$key.$objectid.
'").val() || $("#'.$key.$objectid.
'").text()) || 0;
2741 if ($showValueInsteadOfInputField == 0) {
2743 container.find(".star").on("mouseover", function() {
2744 console.log("Mouse over a star");
2745 let selectedStar = $(this).data("value");
2746 container.find(".star").each(function() {
2747 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2750 container.on("mouseout", function() {
2751 console.log("Mouse out of star");
2752 container.find(".star").each(function() {
2753 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2756 container.find(".star").off("click").on("click", function() {
2757 console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
2758 selectedStars = $(this).data("value");
2759 if (selectedStars == 1 && $("#'.$key.$objectid.
'").val() == 1) {
2762 container.find("#'.$key.$objectid.
'").val(selectedStars);
2763 container.find(".star").each(function() {
2764 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2767 url: "'.DOL_URL_ROOT.
'/core/ajax/updateextrafield.php",
2771 objectId:
'.((int) $objectid).',
2772 field: \
''.dol_escape_js($key).
'\',
2773 value: selectedStars,
2774 token: \
''.currentToken().
'\'
2776 success:
function(response) {
2777 var res = JSON.parse(response);
2778 console[res.status ===
"success" ?
"log" :
"error"](res.message);
2780 error:
function(xhr,
status, error) {
2781 console.log(
"Ajax request failed while updating '.$key.':", error);
2790 $showsize = round((float) $size);
2791 if ($showsize > 48) {
2796 //print $type.'-
'.$size;