1058 global
$conf,$hookmanager;
1060 if (empty($elementtype)) {
1061 dol_syslog(__METHOD__.
'::empty elementtype', LOG_DEBUG);
1065 if ($elementtype ==
'thirdparty') {
1066 $elementtype =
'societe';
1068 if ($elementtype ==
'contact') {
1069 $elementtype =
'socpeople';
1071 if ($elementtype ==
'order_supplier') {
1072 $elementtype =
'commande_fournisseur';
1075 if ($elementtype !=
'all' && isset($this->attributes[$elementtype]) && $this->attributes[$elementtype][
'loaded'] == 1 && !$forceload && isset($this->attributes[$elementtype][
'label'])) {
1076 return $this->attributes[$elementtype][
'label'];
1079 $array_name_label = array();
1082 $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";
1083 $sql .=
" , css, cssview, csslist, personal_data";
1084 $sql .=
" FROM ".$this->db->prefix().
"extrafields";
1086 if ($elementtype && $elementtype !=
'all') {
1087 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1089 if ($attrname && $elementtype && $elementtype !=
'all') {
1090 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1092 $sql .=
" ORDER BY pos";
1094 $resql = $this->db->query($sql);
1097 if ($this->db->num_rows($resql)) {
1098 while ($tab = $this->db->fetch_object($resql)) {
1099 if ($tab->entity != 0 && $tab->entity !=
$conf->entity) {
1101 if ($tab->fieldrequired && is_null($tab->fielddefault)) {
1102 $this->attributes[$tab->elementtype][
'mandatoryfieldsofotherentities'][$tab->name] = $tab->type;
1108 if ($tab->type !=
'separate') {
1109 $array_name_label[$tab->name] = $tab->label;
1111 $array_name_label[$tab->name] = $tab->type;
1115 $this->attributes[$tab->elementtype][
'type'][$tab->name] = $tab->type;
1116 $this->attributes[$tab->elementtype][
'label'][$tab->name] = $tab->label;
1117 $this->attributes[$tab->elementtype][
'size'][$tab->name] = $tab->size;
1118 $this->attributes[$tab->elementtype][
'elementtype'][$tab->name] = $tab->elementtype;
1119 $this->attributes[$tab->elementtype][
'default'][$tab->name] = $tab->fielddefault;
1120 $this->attributes[$tab->elementtype][
'computed'][$tab->name] = $tab->fieldcomputed;
1121 $this->attributes[$tab->elementtype][
'unique'][$tab->name] = $tab->fieldunique;
1122 $this->attributes[$tab->elementtype][
'required'][$tab->name] = $tab->fieldrequired;
1123 $this->attributes[$tab->elementtype][
'param'][$tab->name] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1124 $this->attributes[$tab->elementtype][
'pos'][$tab->name] = $tab->pos;
1125 $this->attributes[$tab->elementtype][
'alwayseditable'][$tab->name] = $tab->alwayseditable;
1126 $this->attributes[$tab->elementtype][
'emptyonclone'][$tab->name] = $tab->emptyonclone;
1127 $this->attributes[$tab->elementtype][
'perms'][$tab->name] = $tab->perms;
1128 $this->attributes[$tab->elementtype][
'langfile'][$tab->name] = $tab->langs;
1129 $this->attributes[$tab->elementtype][
'list'][$tab->name] = $tab->list;
1130 $this->attributes[$tab->elementtype][
'printable'][$tab->name] = $tab->printable;
1131 $this->attributes[$tab->elementtype][
'showintooltip'][$tab->name] = $tab->showintooltip;
1132 $this->attributes[$tab->elementtype][
'totalizable'][$tab->name] = ($tab->totalizable ? 1 : 0);
1133 $this->attributes[$tab->elementtype][
'entityid'][$tab->name] = $tab->entity;
1134 $this->attributes[$tab->elementtype][
'enabled'][$tab->name] = $tab->enabled;
1135 $this->attributes[$tab->elementtype][
'help'][$tab->name] = $tab->help;
1136 $this->attributes[$tab->elementtype][
'aiprompt'][$tab->name] = $tab->aiprompt;
1137 $this->attributes[$tab->elementtype][
'css'][$tab->name] = $tab->css;
1138 $this->attributes[$tab->elementtype][
'cssview'][$tab->name] = $tab->cssview;
1139 $this->attributes[$tab->elementtype][
'csslist'][$tab->name] = $tab->csslist;
1140 $this->attributes[$tab->elementtype][
'personal_data'][$tab->name] = $tab->personal_data;
1142 $this->attributes[$tab->elementtype][
'loaded'] = 1;
1147 $this->attributes[$elementtype][
'loaded'] = 1;
1148 $this->attributes[$elementtype][
'count'] = $count;
1151 $this->error = $this->db->lasterror();
1152 dol_syslog(get_class($this).
"::fetch_name_optionals_label ".$this->error, LOG_ERR);
1156 if (is_object($hookmanager)) {
1157 $parameters = array(
1158 'elementtype' => $elementtype,
1159 'attrname' => $attrname,
1160 'forceload' => $forceload,
1162 $reshook = $hookmanager->executeHooks(
'completeFetchNameOptionalsLabel', $parameters, $this);
1163 if ($reshook > 0 && is_array($hookmanager->resArray)) {
1165 foreach ($hookmanager->resArray as $key => $val) {
1166 $array_name_label[$key] = $val;
1171 return $array_name_label;
1190 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'',
$object = 0, $extrafieldsobjectkey =
'', $mode = 0)
1192 global
$conf, $langs, $form, $hookmanager;
1194 if (!is_object($form)) {
1195 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
1196 $form =
new Form($this->db);
1200 $morecss =
'maxwidth125';
1203 $parameters = array(
1206 'moreparam' => $moreparam,
1207 'keysuffix' => $keysuffix,
1208 'keyprefix' => $keyprefix,
1209 'morecss' => $morecss,
1211 'extrafieldsobjectkey' => $extrafieldsobjectkey,
1216 $reshook = $hookmanager->executeHooks(
'showInputExtraField', $parameters, $this, $action);
1218 return $hookmanager->resPrint;
1225 if (!preg_match(
'/options_$/', $keyprefix)) {
1226 $keyprefix .=
'options_';
1229 if (empty($extrafieldsobjectkey)) {
1230 dol_syslog(get_class($this).
'::showInputField extrafieldsobjectkey required', LOG_ERR);
1231 return 'BadValueForParamExtraFieldsObjectKey';
1234 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1235 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1236 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1237 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1238 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1239 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1240 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1241 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1242 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
1243 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1244 $list = (
string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
1245 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
1246 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1247 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
1248 $hidden = (empty($list) ? 1 : 0);
1254 if (!preg_match(
'/^search_/', $keyprefix)) {
1255 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
1263 if (empty($morecss)) {
1265 if ($type ==
'date') {
1266 $morecss =
'minwidth100imp';
1267 } elseif ($type ==
'datetime' || $type ==
'datetimegmt' || $type ==
'link') {
1268 $morecss =
'minwidth200imp';
1269 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
1270 $morecss =
'maxwidth75';
1271 } elseif ($type ==
'password') {
1272 $morecss =
'maxwidth100';
1273 } elseif ($type ==
'url') {
1274 $morecss =
'minwidth400';
1275 } elseif ($type ==
'boolean') {
1277 } elseif ($type ==
'radio') {
1278 $morecss =
'width25';
1280 if (empty($size) || round((
float) $size) < 12) {
1281 $morecss =
'minwidth100';
1282 } elseif (round((
float) $size) <= 48) {
1283 $morecss =
'minwidth200';
1285 $morecss =
'minwidth400';
1289 if (!empty($this->attributes[$extrafieldsobjectkey][
'css'][$key])) {
1290 $morecss = $this->attributes[$extrafieldsobjectkey][
'css'][$key];
1294 if (in_array($type, array(
'date'))) {
1295 $tmp = explode(
',', $size);
1300 if (!$required && $value ==
'') {
1307 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1308 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1310 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1311 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"));
1312 $out .=
'</div><div class="nowrap">';
1313 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"));
1314 $out .=
'</div></div>';
1318 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required ? 0 : 2,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1320 } elseif (in_array($type, array(
'datetime',
'datetimegmt'))) {
1321 $tmp = explode(
',', $size);
1326 if (!$required && $value ==
'') {
1333 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1334 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1336 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1337 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"),
'tzuserrel');
1338 $out .=
'</div><div class="nowrap">';
1339 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
1340 $out .=
'</div></div>';
1344 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required ? 0 : 2,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1346 } elseif (in_array($type, array(
'int',
'integer'))) {
1347 $tmp = explode(
',', $size);
1349 $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 :
'').
'>';
1350 } elseif (preg_match(
'/varchar/', $type)) {
1351 $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 :
'').
'>';
1352 } elseif (in_array($type, array(
'email',
'mail',
'ip',
'phone',
'url'))) {
1353 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1354 } elseif ($type ==
'icon') {
1360 $out .=
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat '.$morecss.
' maxwidthonsmartphone"';
1361 $out .=
' name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1364 $options =
"{ title: '<b>".$langs->trans(
"IconFieldSelector").
"</b>', placement: 'right', showFooter: false, templates: {";
1365 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
1366 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
1369 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
1370 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"".$langs->trans(
"TypeToFilter").
"\" />',";
1371 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
1372 $options .=
" <div class=\"arrow\" ></div>";
1373 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
1374 $options .=
" <div class=\"popover-content \" ></div>";
1375 $options .=
"</div>'}}";
1376 $out .=
"$('#".$keyprefix.$key.$keysuffix.
"').iconpicker(".$options.
");";
1377 $out .=
'</script>';
1379 } elseif ($type ==
'text') {
1380 if (!preg_match(
'/search_/', $keyprefix)) {
1381 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1382 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1383 $out = (
string) $doleditor->Create(1);
1385 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1387 } elseif ($type ==
'html') {
1388 if (!preg_match(
'/search_/', $keyprefix)) {
1389 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1390 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
1391 $out = (
string) $doleditor->Create(1);
1393 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1395 } elseif ($type ==
'boolean') {
1398 if (!empty($value)) {
1399 $checked =
' checked value="1" ';
1401 $checked =
' value="1" ';
1403 $out =
'<input type="checkbox" class="flat valignmiddle'.($morecss ?
' '.$morecss :
'').
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1405 $out = $form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1, 1,
'width75 yesno');
1407 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_boolean" value="1">';
1408 } elseif ($type ==
'price') {
1409 if (!empty($value)) {
1410 $value =
price($value);
1412 $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).
'">';
1413 } elseif ($type ==
'pricecy') {
1414 $currency =
$conf->currency;
1415 if (!empty($value)) {
1417 $pricetmp = explode(
':', $value);
1418 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
1419 $value =
price($pricetmp[0]);
1421 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1422 $out .= $form->selectCurrency($currency, $keyprefix.$key.$keysuffix.
'currency_id');
1423 } elseif ($type ==
'duration') {
1424 $value = intval($value);
1425 $out = $form->select_duration($keyprefix . $key, $value, 0,
'text', 0, 1);
1426 } elseif ($type ==
'double') {
1427 if (!empty($value)) {
1428 $value =
price($value);
1430 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1431 } elseif ($type ==
'select') {
1435 foreach ($param[
'options'] as $okey => $val) {
1436 if ((
string) $okey ==
'') {
1440 $valarray = explode(
'|', $val);
1441 $val = $valarray[0];
1443 if ($langfile && $val) {
1444 $options[$okey] = $langs->trans($val);
1446 $options[$okey] = $val;
1449 $selected = array();
1450 if (!is_array($value)) {
1451 $selected = explode(
',', $value);
1454 $out .= $form->multiselectarray($keyprefix.$key.$keysuffix, $options, $selected, 0, 0, $morecss, 0, 0,
'',
'',
'', (
int) (!empty(
$conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')));
1457 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1458 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1461 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1462 $out .=
'<option value="0"> </option>';
1463 foreach ($param[
'options'] as $key2 => $val2) {
1464 if ((
string) $key2 ==
'') {
1467 $valarray = explode(
'|', $val2);
1468 $val2 = $valarray[0];
1470 if (!empty($valarray[1])) {
1471 $parent = $valarray[1];
1473 $out .=
'<option value="'.$key2.
'"';
1474 $out .= (((
string) $value == (
string) $key2) ?
' selected' :
'');
1475 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1477 if ($langfile && $val2) {
1478 $out .= $langs->trans($val2);
1482 $out .=
'</option>';
1484 $out .=
'</select>';
1486 } elseif ($type ==
'sellist') {
1488 if (!empty(
$conf->use_javascript_ajax)) {
1493 $(document).ready(function () {
1494 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1496 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1498 delay: 250, // wait 250 milliseconds before triggering the request
1499 data: function (params) {
1501 search: params.term,
1502 page: params.page || 1,
1503 objecttype: '".$extrafieldsobjectkey.
"',
1505 objectkey: '".$key.
"',
1515 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1516 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1517 $out .=
'</select>';
1519 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1520 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1525 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1526 if (is_array($param[
'options'])) {
1529 $tmpparamoptions = array_keys($param[
'options']);
1530 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1532 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1544 if (! empty($InfoFieldList[4])) {
1546 $parenthesisopen = 0;
1547 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1548 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1551 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1556 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1557 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1559 $InfoFieldList[4] = $tmpbefore;
1560 if ($tmpafter !==
'') {
1561 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1566 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1567 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1577 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1579 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1580 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1581 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1583 $keyList = $InfoFieldList[2].
' as rowid';
1586 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1587 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1588 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1589 $keyList .=
', main.'.$parentField;
1591 $keyList .=
', '.$parentField;
1595 $filter_categorie =
false;
1596 if (count($InfoFieldList) > 5) {
1597 if ($InfoFieldList[0] ==
'categorie') {
1598 $filter_categorie =
true;
1602 if (!$filter_categorie) {
1603 $fields_label = isset($InfoFieldList[1]) ? explode(
'|', $InfoFieldList[1]) : array();
1604 if (!empty($fields_label)) {
1606 $keyList .= implode(
', ', $fields_label);
1612 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
1613 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
1616 if (!empty($InfoFieldList[4])) {
1618 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1619 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1622 global $dolibarr_allow_unsecured_select_in_extrafields_filter;
1623 if (!empty($dolibarr_allow_unsecured_select_in_extrafields_filter)) {
1624 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1625 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1629 if (strpos($InfoFieldList[4],
'$MODE$') !==
false) {
1630 $InfoFieldList[4] = str_replace(
'$MODE$', preg_replace(
'/[^a-z0-9_]/i',
'', (
string) $mode), $InfoFieldList[4]);
1634 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1635 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1636 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1640 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1641 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1643 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1644 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1646 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1652 preg_match_all(
'/\$(.*?)\$/', $InfoFieldList[4], $tags);
1653 foreach ($tags[0] as $keytag => $valuetag) {
1654 $property = preg_replace(
'/[^a-z0-9_]/',
'', strtolower($tags[1][$keytag]));
1655 if (strpos($property,
'options_') === 0) {
1656 if (strpos($InfoFieldList[4], $valuetag) !==
false && isset(
$object->array_options[$property]) && !empty(
$object->array_options[$property])) {
1657 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->array_options[$property], $InfoFieldList[4]);
1659 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1662 if (strpos($InfoFieldList[4], $valuetag) !==
false && property_exists(
$object, $property) && !empty(
$object->$property)) {
1663 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->$property, $InfoFieldList[4]);
1665 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
1673 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1674 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1675 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1681 $sqlwhere .=
' WHERE 1=1';
1698 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1699 $sqlwhere .=
' AND entity = '.((int)
$conf->entity);
1703 $sql .= $this->db->order(implode(
', ', $fields_label));
1704 $sql .=
' LIMIT ' .
getDolGlobalInt(
'MAIN_EXTRAFIELDS_LIMIT_SELLIST_SQL', 1000);
1707 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1708 $resql = $this->db->query($sql);
1710 $out .=
'<option value="0"> </option>';
1711 $num = $this->db->num_rows($resql);
1715 $obj = $this->db->fetch_object($resql);
1717 $nameFields = $InfoFieldList[1];
1719 $nameFields = preg_replace(
'/[a-z_]+\([^\)]*\) as ([\w]+)/i',
'\1', $nameFields);
1721 $nameFields = preg_replace(
'/[^0-9a-z_\.\|]/i',
'', $nameFields);
1725 $fields_label = explode(
'|', $nameFields);
1726 if (is_array($fields_label) && count($fields_label) > 1) {
1728 foreach ($fields_label as $field_toshow) {
1729 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
1730 $labeltoshow .= $obj->$field_toshow.
' ';
1733 $labeltoshow = $obj->$nameFields;
1736 if ($value == $obj->rowid) {
1738 foreach ($fields_label as $field_toshow) {
1739 $translabel = $langs->trans($obj->$field_toshow);
1740 $labeltoshow = $translabel.
' ';
1743 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1746 $translabel = $langs->trans($obj->$nameFields);
1747 $labeltoshow = $translabel;
1749 if (empty($labeltoshow)) {
1750 $labeltoshow =
'(not defined)';
1753 if (!empty($InfoFieldList[3]) && $parentField) {
1755 $parentField = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $parentField);
1756 $parent = $parentName.
':'.$obj->{$parentField};
1759 $out .=
'<option value="'.$obj->rowid.
'"';
1760 $out .= ($value == $obj->rowid ?
' selected' :
'');
1761 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1762 $out .=
'>'.$labeltoshow.
'</option>';
1767 $this->db->free($resql);
1769 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1772 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1773 $categcode = $InfoFieldList[5];
1774 if (is_numeric($categcode)) {
1775 $tmpcategory =
new Categorie($this->db);
1776 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
1777 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
1780 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1781 $out .=
'<option value="0"> </option>';
1782 if (is_array($data)) {
1783 foreach ($data as $data_key => $data_value) {
1784 $out .=
'<option value="'.$data_key.
'"';
1785 $out .= ($value == $data_key ?
' selected' :
'');
1786 $out .=
'>'.$data_value.
'</option>';
1791 $out .=
'</select>';
1793 } elseif ($type ==
'checkbox') {
1794 $value_arr = $value;
1795 if (!is_array($value)) {
1796 $value_arr = explode(
',', $value);
1798 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0,
'', 0,
'100%');
1799 } elseif ($type ==
'radio') {
1801 $selectedvalue = ((
string) $value !==
'' ? $value : $default);
1802 foreach ($param[
'options'] as $keyopt => $val) {
1803 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1804 $out .=
' value="'.$keyopt.
'"';
1805 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1806 $out .= ((
string) $selectedvalue == (
string) $keyopt ?
' checked' :
'');
1807 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1809 } elseif ($type ==
'chkbxlst') {
1812 if (is_array($value)) {
1813 $value_arr = $value;
1815 $value_arr = explode(
',', $value);
1819 $(document).ready(function () {
1820 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1822 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1825 delay: 250, // wait 250 milliseconds before triggering the request
1826 data: function (params) {
1828 search: params.term,
1829 page: params.page || 1,
1830 objecttype: '".$extrafieldsobjectkey.
"',
1832 objectkey: '".$key.
"',
1845 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_multiselect" value="1">';
1846 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'[]" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
' multiple="multiple">';
1847 foreach ($value_arr as $value) {
1848 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1850 $out .=
'</select>';
1852 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1853 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1856 if (is_array($value)) {
1857 $value_arr = $value;
1859 $value_arr = explode(
',', $value);
1862 if (is_array($param[
'options'])) {
1863 $tmpparamoptions = array_keys($param[
'options']);
1864 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1866 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1887 if (! empty($InfoFieldList[4])) {
1889 $parenthesisopen = 0;
1890 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1891 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1894 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1899 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1900 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1902 $InfoFieldList[4] = $tmpbefore;
1903 if ($tmpafter !==
'') {
1904 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1909 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1910 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1918 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1920 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1921 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1922 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1924 $keyList = $InfoFieldList[2].
' as rowid';
1927 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1928 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1929 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1930 $keyList .=
', main.'.$parentField;
1932 $keyList .=
', '.$parentField;
1937 $filter_categorie =
false;
1938 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
1939 $InfoFieldList[5] = (
string) $InfoFieldList[5];
1940 if ($InfoFieldList[0] ==
'categorie') {
1941 $filter_categorie =
true;
1943 $filter_categorie =
false;
1948 if (!$filter_categorie) {
1949 $fields_label = explode(
'|', $InfoFieldList[1]);
1950 if (is_array($fields_label)) {
1952 $keyList .= implode(
', ', $fields_label);
1956 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
1957 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
1960 if (!empty($InfoFieldList[4])) {
1962 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1963 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1966 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1967 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1971 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1972 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1973 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1977 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1978 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1980 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1981 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1983 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1988 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1989 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1990 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1996 $sqlwhere .=
' WHERE 1=1';
1999 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
2001 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2002 $tmpcategory =
new Categorie($this->db);
2003 $tablesuffixcategory = empty($tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]];
2004 $fksuffixcategory = empty($tmpcategory->MAP_CAT_FK[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_FK[$InfoFieldList[5]];
2006 $sqlwhere .=
' AND EXISTS (SELECT fk_categorie as categid FROM '.MAIN_DB_PREFIX.
'categorie_'.$this->db->sanitize($tablesuffixcategory);
2007 $sqlwhere .=
' WHERE fk_categorie IN ('.$this->db->sanitize($InfoFieldList[6]).
')';
2008 $sqlwhere .=
' AND fk_'.$this->db->sanitize($fksuffixcategory).
' = rowid)';
2026 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
2027 $sqlwhere .=
" AND entity = ".((int)
$conf->entity);
2033 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
2035 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
2037 $resql = $this->db->query($sql);
2039 $num = $this->db->num_rows($resql);
2046 $obj = $this->db->fetch_object($resql);
2050 $fields_label = explode(
'|', $InfoFieldList[1]);
2051 if (is_array($fields_label)) {
2053 foreach ($fields_label as $field_toshow) {
2054 $labeltoshow .= $obj->$field_toshow.
' ';
2057 $labeltoshow = $obj->{$InfoFieldList[1]};
2059 $labeltoshow =
dol_trunc($labeltoshow, 45);
2061 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2063 foreach ($fields_label as $field_toshow) {
2064 $translabel = $langs->trans($obj->$field_toshow);
2065 if ($translabel != $obj->$field_toshow) {
2066 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
2068 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
2071 $data[$obj->rowid] = $labeltoshow;
2074 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
2075 if ($translabel != $obj->{$InfoFieldList[1]}) {
2076 $labeltoshow =
dol_trunc($translabel, 18);
2078 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
2081 if (empty($labeltoshow)) {
2082 $labeltoshow =
'(not defined)';
2085 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2086 $data[$obj->rowid] = $labeltoshow;
2089 if (!empty($InfoFieldList[3]) && $parentField) {
2090 $parent = $parentName.
':'.$obj->{$parentField};
2093 $data[$obj->rowid] = $labeltoshow;
2098 $this->db->free($resql);
2100 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2102 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
2105 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2106 $categcode = $InfoFieldList[5];
2107 if (is_numeric($categcode)) {
2108 $tmpcategory =
new Categorie($this->db);
2109 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
2110 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
2113 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
2114 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2118 } elseif ($type ==
'link') {
2119 $param_list = array_keys($param[
'options']);
2126 $showempty = (($required && $default !=
'') ? 0 : 1);
2128 $tmparray = explode(
':', $param_list[0]);
2130 $element = $extrafieldsobjectkey;
2131 if ($element ==
'socpeople') {
2132 $element =
'contact';
2133 } elseif ($element ==
'projet') {
2134 $element =
'project';
2138 $objectdesc = $tmparray[0].(empty($tmparray[1]) ?
"" :
":".$tmparray[1]);
2139 $objectfield = $element.
':options_'.$key;
2141 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, (
int) $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
2142 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
2143 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2147 if (!empty($value)) {
2148 $tmparray = $dolgeophp->parseGeoString($value);
2149 $geojson = $tmparray[
'geojson'];
2150 $centroidjson = $tmparray[
'centroidjson'];
2152 if (!preg_match(
'/search_/', $keyprefix)) {
2153 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
2155 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
2160 } elseif ($type ==
'password') {
2162 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
2163 $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 :
'').
'>';
2164 } elseif ($type ==
'stars') {
2165 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2166 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
2168 while ($i <= $size) {
2169 $out .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2174 jQuery(function($) { /* extrafields.class.php 1 */
2175 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
2176 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
2177 container.find(".star").each(function() {
2178 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2180 container.find(".star").on("mouseover", function() {
2181 let selectedStar = $(this).data("value");
2182 container.find(".star").each(function() {
2183 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2186 container.on("mouseout", function() {
2187 container.find(".star").each(function() {
2188 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2191 container.find(".star").off("click").on("click", function() {
2192 selectedStars = $(this).data("value");
2193 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
2196 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
2197 container.find(".star").each(function() {
2198 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2204 if (!empty($hidden)) {
2205 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
2210 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2211 $out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey,
null,
$object);
2236 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null,
$object =
null, $mode =
'')
2238 global
$conf, $langs, $hookmanager;
2240 if (is_null($outputlangs) || !is_object($outputlangs)) {
2241 $outputlangs = $langs;
2244 if (empty($extrafieldsobjectkey)) {
2245 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
2246 return 'BadValueForParamExtraFieldsObjectKey';
2249 $parameters = array(
2252 'moreparam' => $moreparam,
2253 'extrafieldsobjectkey' => $extrafieldsobjectkey,
2254 'outputlangs' => $outputlangs,
2259 $reshook = $hookmanager->executeHooks(
'showOutputExtraField', $parameters, $this, $action);
2261 return $hookmanager->resPrint;
2264 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
2265 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2266 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
2267 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
2268 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
2269 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
2270 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
2271 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
2272 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
2273 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
2274 $list = (
string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
2275 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
2276 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
2277 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
2280 $showValueInsteadOfInputField = 0;
2282 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2283 $showValueInsteadOfInputField = 1;
2286 $hidden = (empty($list) ? 1 : 0);
2295 if ($type ==
'date') {
2297 if ($value !==
'') {
2300 } elseif ($type ==
'datetime') {
2302 if ($value !==
'') {
2305 } elseif ($type ==
'duration') {
2307 if ($value !==
'') {
2308 $value = intval($value);
2311 } elseif ($type ==
'datetimegmt') {
2313 if ($value !==
'') {
2316 } elseif ($type ==
'int') {
2318 } elseif ($type ==
'double') {
2319 if (!empty($value)) {
2323 $value =
price($value, 0, $outputlangs, 0, 0, -2,
'');
2325 } elseif ($type ==
'boolean') {
2327 if (!empty($value)) {
2328 $checked =
' checked ';
2331 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
2333 $value =
yn($value ? 1 : 0);
2335 } elseif ($type ==
'mail' || $type ==
'email') {
2337 } elseif ($type ==
'ip') {
2339 } elseif ($type ==
'icon') {
2340 $value =
'<span class="'.$value.
'"></span>';
2341 } elseif ($type ==
'url') {
2343 } elseif ($type ==
'phone') {
2345 } elseif ($type ==
'price') {
2347 if ($value || $value ==
'0') {
2348 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol(
$conf->currency);
2350 } elseif ($type ==
'pricecy') {
2351 $currency =
$conf->currency;
2352 if (!empty($value)) {
2354 $pricetmp = explode(
':', $value);
2355 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
2356 $value = $pricetmp[0];
2358 if ($value || $value ==
'0') {
2359 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
2361 } elseif ($type ==
'select') {
2362 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2363 if (($pos = strpos($valstr,
"|")) !==
false) {
2364 $valstr = substr($valstr, 0, $pos);
2366 if ($langfile && $valstr) {
2367 $value = $outputlangs->trans($valstr);
2371 } elseif ($type ==
'sellist') {
2372 $param_list = array_keys($param[
'options']);
2373 $InfoFieldList = explode(
":", $param_list[0]);
2375 $selectkey =
"rowid";
2378 if (count($InfoFieldList) >= 3) {
2379 $selectkey = $InfoFieldList[2];
2380 $keyList = $InfoFieldList[2].
' as rowid';
2383 $fields_label = explode(
'|', $InfoFieldList[1]);
2384 if (is_array($fields_label)) {
2386 $keyList .= implode(
', ', $fields_label);
2389 $filter_categorie =
false;
2390 if (count($InfoFieldList) > 5) {
2391 if ($InfoFieldList[0] ==
'categorie') {
2392 $filter_categorie =
true;
2396 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2397 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2398 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2401 if ($selectkey ==
'rowid' && empty($value)) {
2402 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = 0";
2403 } elseif ($selectkey ==
'rowid') {
2404 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = ".((int) $value);
2406 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = '".$this->db->escape($value).
"'";
2410 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2412 $resql = $this->db->query($sql);
2414 if (!$filter_categorie) {
2417 $obj = $this->db->fetch_object($resql);
2420 $fields_label = explode(
'|', $InfoFieldList[1]);
2422 if (is_array($fields_label) && count($fields_label) > 1) {
2423 foreach ($fields_label as $field_toshow) {
2425 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
2426 if (!empty($obj->$field_toshow)) {
2427 $translabel = $outputlangs->trans($obj->$field_toshow);
2429 if ($translabel != $obj->$field_toshow) {
2430 $value .=
dol_trunc($translabel, 24) .
' ';
2432 $value .= $obj->$field_toshow .
' ';
2438 $tmppropname = $InfoFieldList[1];
2440 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2441 $translabel = $outputlangs->trans($obj->$tmppropname);
2443 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2446 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2451 $obj = $this->db->fetch_object($resql);
2453 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2455 $result =
$c->fetch($obj->rowid);
2457 $ways =
$c->print_all_ways();
2458 foreach ($ways as $way) {
2459 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
2463 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2466 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2468 } elseif ($type ==
'radio') {
2469 if ($required && !isset($param[
'options'][$value])) {
2470 $outputlangs->load(
'errors');
2471 $value =
'<span class="opacitymedium">'.$outputlangs->trans(
'ErrorNoValueForRadioType').
'</span>';
2473 if (isset($param[
'options'][$value])) {
2474 $value = $outputlangs->trans($param[
'options'][$value]);
2479 } elseif ($type ==
'checkbox') {
2480 $value_arr = explode(
',', $value);
2483 if (is_array($value_arr)) {
2484 foreach ($value_arr as $keyval => $valueval) {
2485 if (!empty($valueval)) {
2486 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2490 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2491 } elseif ($type ==
'chkbxlst') {
2493 if (!is_null($value) && $value !=
'') {
2494 $value_arr = explode(
',', $value);
2496 $param_list = array_keys($param[
'options']);
2497 $InfoFieldList = explode(
":", $param_list[0]);
2499 $selectkey =
"rowid";
2502 if (count($InfoFieldList) >= 3) {
2503 $selectkey = $InfoFieldList[2];
2504 $keyList = $InfoFieldList[2].
' as rowid';
2507 $fields_label = explode(
'|', $InfoFieldList[1]);
2508 if (is_array($fields_label)) {
2510 $keyList .= implode(
', ', $fields_label);
2513 $filter_categorie =
false;
2514 if (count($InfoFieldList) > 5 && ((
string) $InfoFieldList[5] !=
'')) {
2515 if ($InfoFieldList[0] ==
'categorie') {
2516 $filter_categorie =
true;
2520 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2521 $sql .=
" FROM ".$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2522 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2525 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" IN (".$this->db->sanitize(implode(
',', $value_arr)).
")";
2527 dol_syslog(get_class($this).
':showOutputField type=chkbxlst', LOG_DEBUG);
2529 $resql = $this->db->query($sql);
2532 if (!$filter_categorie) {
2535 $numOfElem = $this->db->num_rows($resql);
2536 while ($obj = $this->db->fetch_object($resql)) {
2538 $fields_label = explode(
'|', $InfoFieldList[1]);
2541 if (count($fields_label) > 0) {
2542 if ($InfoFieldList[0] ==
'societe' && $InfoFieldList[1] ==
'nom' && $InfoFieldList[2] ==
'rowid') {
2544 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
2545 $tmpthirdpartystatic =
new Societe($this->db);
2546 $tmpthirdpartystatic->id = $obj->rowid;
2547 $tmpthirdpartystatic->name = $obj->nom;
2548 if ($numOfElem >= 3) {
2549 $tmpthirdpartystatic->name = $obj->nom;
2550 $label = $tmpthirdpartystatic->getNomUrl(2);
2551 } elseif ($numOfElem >= 2) {
2552 $tmpthirdpartystatic->name =
dol_trunc($obj->nom, 5);
2553 $label = $tmpthirdpartystatic->getNomUrl(1);
2555 $tmpthirdpartystatic->name = $obj->nom;
2556 $label = $tmpthirdpartystatic->getNomUrl(1);
2559 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: '.$txtcolor.
'">';
2560 foreach ($fields_label as $field_toshow) {
2562 if (!empty($obj->$field_toshow)) {
2563 $translabel = $outputlangs->trans($obj->$field_toshow);
2565 if ($translabel != $field_toshow) {
2566 $label .=
' '.dol_trunc($translabel, 18);
2568 $label .=
' '.$obj->$field_toshow;
2573 $toprint[] = $label;
2577 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2580 $numElem = $this->db->num_rows($resql);
2581 while ($obj = $this->db->fetch_object($resql)) {
2583 $c->fetch($obj->rowid);
2584 if ((
string) $mode !=
'list') {
2585 $ways =
$c->print_all_ways();
2586 foreach ($ways as $way) {
2587 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
2591 $forced_color =
'categtextwhite';
2594 $forced_color =
'categtextblack';
2599 $s =
'<li class="select2-search-choice-dolibarr noborderoncategories '.$forced_color.
' list"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>';
2600 if ($numElem >= 2) {
2601 $s .=
img_object(
$c->label,
'category',
'class="small"');
2603 $s .=
img_object(
$c->label,
'category',
'class="small"').
' '.
$c->label;
2610 if (!empty($toprint)) {
2611 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2614 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2617 } elseif ($type ==
'link') {
2620 $param_list = array_keys($param[
'options']);
2622 $InfoFieldList = explode(
":", $param_list[0]);
2623 $classname = $InfoFieldList[0];
2624 $classpath = $InfoFieldList[1];
2625 if (!empty($classpath)) {
2627 if ($classname && class_exists($classname)) {
2628 $tmpobject =
new $classname($this->db);
2629 '@phan-var-force CommonObject $tmpobject';
2630 $tmpobject->fetch($value);
2632 if (get_class($tmpobject) ==
'Categorie') {
2634 $color = $tmpobject->color;
2635 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2636 $sfortag .= $tmpobject->getNomUrl(3);
2637 $sfortag .=
'</span>';
2640 $value = $tmpobject->getNomUrl(3);
2644 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2645 return 'Error bad setup of extrafield';
2648 } elseif ($type ==
'point') {
2649 if (!empty($value)) {
2650 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2652 $value = $dolgeophp->getXYString($value);
2656 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2657 if (!empty($value)) {
2658 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2660 $value = $dolgeophp->getPointString($value);
2664 } elseif ($type ==
'text') {
2665 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2666 } elseif ($type ==
'html') {
2668 } elseif ($type ==
'password') {
2669 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2670 } elseif ($type ==
'stars') {
2671 $objectid = (int)
$object->id;
2672 $nbstars = (int) $value;
2673 if ($showValueInsteadOfInputField == 1) {
2674 $value =
'<span style="display:none;" id="'.$key.$object->id.
'">'.
dol_escape_htmltag($value).
'</span>';
2676 $value =
'<input type="hidden" class="flat" name="'.$key.
'" id="'.$key.$objectid.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2679 $value .=
'<div class="star-selection" id="'.$key.$objectid.
'_selection">';
2681 while ($i <= $size) {
2682 $value .=
'<span class="star'.($i <= $nbstars ?
' active' :
'').
'" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2687 $(document).ready(function() { /* extrafields.class.php 2 */
2688 let container = $("#'.$key.$objectid.
'_selection");
2689 let selectedStars = parseInt($("#'.$key.$objectid.
'").val() || $("#'.$key.$objectid.
'").text()) || 0;
2691 if ($showValueInsteadOfInputField == 0) {
2693 container.find(".star").on("mouseover", function() {
2694 console.log("Mouse over a star");
2695 let selectedStar = $(this).data("value");
2696 container.find(".star").each(function() {
2697 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2700 container.on("mouseout", function() {
2701 console.log("Mouse out of star");
2702 container.find(".star").each(function() {
2703 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2706 container.find(".star").off("click").on("click", function() {
2707 console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
2708 selectedStars = $(this).data("value");
2709 if (selectedStars == 1 && $("#'.$key.$objectid.
'").val() == 1) {
2712 container.find("#'.$key.$objectid.
'").val(selectedStars);
2713 container.find(".star").each(function() {
2714 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2717 url: "'.DOL_URL_ROOT.
'/core/ajax/updateextrafield.php",
2721 objectId:
'.((int) $objectid).',
2722 field: \
''.dol_escape_js($key).
'\',
2723 value: selectedStars,
2724 token: \
''.newToken().
'\'
2726 success:
function(response) {
2727 var res = JSON.parse(response);
2728 console[res.status ===
"success" ?
"log" :
"error"](res.message);
2730 error:
function(xhr,
status, error) {
2731 console.log(
"Ajax request failed while updating '.$key.':", error);
2740 $showsize = round((float) $size);
2741 if ($showsize > 48) {
2746 //print $type.'-
'.$size;