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]);
1676 $sqlwhere .=
" AND " . forgeSQLFromUniversalSearchCriteria($InfoFieldList[4], $errstr, 1);
1678 $sqlwhere .=
" WHERE " . forgeSQLFromUniversalSearchCriteria($InfoFieldList[4], $errstr, 1);
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 foreach ($param[
'options'] as $keyopt => $val) {
1802 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1803 $out .=
' value="'.$keyopt.
'"';
1804 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1805 $out .= ($value == $keyopt ?
'checked' :
'');
1806 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1808 } elseif ($type ==
'chkbxlst') {
1811 if (is_array($value)) {
1812 $value_arr = $value;
1814 $value_arr = explode(
',', $value);
1818 $(document).ready(function () {
1819 $('#".$keyprefix.$key.$keysuffix.
"').select2({
1821 url: '".DOL_URL_ROOT.
'/core/ajax/ajaxextrafield.php'.
"',
1824 delay: 250, // wait 250 milliseconds before triggering the request
1825 data: function (params) {
1827 search: params.term,
1828 page: params.page || 1,
1829 objecttype: '".$extrafieldsobjectkey.
"',
1831 objectkey: '".$key.
"',
1844 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_multiselect" value="1">';
1845 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'[]" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
' multiple="multiple">';
1846 foreach ($value_arr as $value) {
1847 $out .=
' <option value="'.$value.
'" selected>'.$this->
showOutputField($key, $value, $moreparam, $extrafieldsobjectkey).
'</option>';
1849 $out .=
'</select>';
1851 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1852 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1855 if (is_array($value)) {
1856 $value_arr = $value;
1858 $value_arr = explode(
',', $value);
1861 if (is_array($param[
'options'])) {
1862 $tmpparamoptions = array_keys($param[
'options']);
1863 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1865 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1886 if (! empty($InfoFieldList[4])) {
1888 $parenthesisopen = 0;
1889 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1890 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1893 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1898 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1899 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1901 $InfoFieldList[4] = $tmpbefore;
1902 if ($tmpafter !==
'') {
1903 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1908 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1909 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1917 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1919 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1920 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1921 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1923 $keyList = $InfoFieldList[2].
' as rowid';
1926 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1927 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1928 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1929 $keyList .=
', main.'.$parentField;
1931 $keyList .=
', '.$parentField;
1936 $filter_categorie =
false;
1937 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
1938 $InfoFieldList[5] = (
string) $InfoFieldList[5];
1939 if ($InfoFieldList[0] ==
'categorie') {
1940 $filter_categorie =
true;
1942 $filter_categorie =
false;
1947 if (!$filter_categorie) {
1948 $fields_label = explode(
'|', $InfoFieldList[1]);
1949 if (is_array($fields_label)) {
1951 $keyList .= implode(
', ', $fields_label);
1955 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
1956 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
1959 if (!empty($InfoFieldList[4])) {
1961 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1962 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string)
$conf->entity, $InfoFieldList[4]);
1965 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1966 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1970 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1971 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1972 } elseif (substr($_SERVER[
"PHP_SELF"], -8) ==
'list.php') {
1976 $word =
'#\b([a-zA-Z0-9-\.-_]+)\b *= *\$ID\$#';
1977 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1979 $word =
'#\$ID\$ *= *\b([a-zA-Z0-9-\.-_]+)\b#';
1980 $InfoFieldList[4] = preg_replace($word,
'$1', $InfoFieldList[4]);
1982 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1987 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1988 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1989 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1990 $sqlwhere .=
" AND " . forgeSQLFromUniversalSearchCriteria($InfoFieldList[4], $errstr, 1);
1992 $sqlwhere .=
" WHERE " . forgeSQLFromUniversalSearchCriteria($InfoFieldList[4], $errstr, 1);
1995 $sqlwhere .=
' WHERE 1=1';
1998 if (count($InfoFieldList) > 5 && ($InfoFieldList[5] !=
'')) {
2000 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2001 $tmpcategory =
new Categorie($this->db);
2002 $tablesuffixcategory = empty($tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_TABLE[$InfoFieldList[5]];
2003 $fksuffixcategory = empty($tmpcategory->MAP_CAT_FK[$InfoFieldList[5]]) ? $InfoFieldList[5] : $tmpcategory->MAP_CAT_FK[$InfoFieldList[5]];
2005 $sqlwhere .=
' AND EXISTS (SELECT fk_categorie as categid FROM '.MAIN_DB_PREFIX.
'categorie_'.$this->db->sanitize($tablesuffixcategory);
2006 $sqlwhere .=
' WHERE fk_categorie IN ('.$this->db->sanitize($InfoFieldList[6]).
')';
2007 $sqlwhere .=
' AND fk_'.$this->db->sanitize($fksuffixcategory).
' = rowid)';
2025 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
2026 $sqlwhere .=
" AND entity = ".((int)
$conf->entity);
2032 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
2034 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
2036 $resql = $this->db->query($sql);
2038 $num = $this->db->num_rows($resql);
2045 $obj = $this->db->fetch_object($resql);
2049 $fields_label = explode(
'|', $InfoFieldList[1]);
2050 if (is_array($fields_label)) {
2052 foreach ($fields_label as $field_toshow) {
2053 $labeltoshow .= $obj->$field_toshow.
' ';
2056 $labeltoshow = $obj->{$InfoFieldList[1]};
2058 $labeltoshow =
dol_trunc($labeltoshow, 45);
2060 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2062 foreach ($fields_label as $field_toshow) {
2063 $translabel = $langs->trans($obj->$field_toshow);
2064 if ($translabel != $obj->$field_toshow) {
2065 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
2067 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
2070 $data[$obj->rowid] = $labeltoshow;
2073 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
2074 if ($translabel != $obj->{$InfoFieldList[1]}) {
2075 $labeltoshow =
dol_trunc($translabel, 18);
2077 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
2080 if (empty($labeltoshow)) {
2081 $labeltoshow =
'(not defined)';
2084 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2085 $data[$obj->rowid] = $labeltoshow;
2088 if (!empty($InfoFieldList[3]) && $parentField) {
2089 $parent = $parentName.
':'.$obj->{$parentField};
2092 $data[$obj->rowid] = $labeltoshow;
2097 $this->db->free($resql);
2099 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2101 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
2104 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2105 $categcode = $InfoFieldList[5];
2106 if (is_numeric($categcode)) {
2107 $tmpcategory =
new Categorie($this->db);
2108 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
2109 $categcode = $MAP_ID_TO_CODE[(int) $categcode];
2112 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
2113 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, 0, 0,
'', 0,
'100%');
2117 } elseif ($type ==
'link') {
2118 $param_list = array_keys($param[
'options']);
2125 $showempty = (($required && $default !=
'') ? 0 : 1);
2127 $tmparray = explode(
':', $param_list[0]);
2129 $element = $extrafieldsobjectkey;
2130 if ($element ==
'socpeople') {
2131 $element =
'contact';
2132 } elseif ($element ==
'projet') {
2133 $element =
'project';
2137 $objectdesc = $tmparray[0].(empty($tmparray[1]) ?
"" :
":".$tmparray[1]);
2138 $objectfield = $element.
':options_'.$key;
2140 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, (
int) $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
2141 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
2142 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2146 if (!empty($value)) {
2147 $tmparray = $dolgeophp->parseGeoString($value);
2148 $geojson = $tmparray[
'geojson'];
2149 $centroidjson = $tmparray[
'centroidjson'];
2151 if (!preg_match(
'/search_/', $keyprefix)) {
2152 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
2154 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
2159 } elseif ($type ==
'password') {
2161 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
2162 $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 :
'').
'>';
2163 } elseif ($type ==
'stars') {
2164 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2165 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
2167 while ($i <= $size) {
2168 $out .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2173 jQuery(function($) { /* extrafields.class.php 1 */
2174 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
2175 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
2176 container.find(".star").each(function() {
2177 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2179 container.find(".star").on("mouseover", function() {
2180 let selectedStar = $(this).data("value");
2181 container.find(".star").each(function() {
2182 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2185 container.on("mouseout", function() {
2186 container.find(".star").each(function() {
2187 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2190 container.find(".star").off("click").on("click", function() {
2191 selectedStars = $(this).data("value");
2192 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
2195 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
2196 container.find(".star").each(function() {
2197 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2203 if (!empty($hidden)) {
2204 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
2209 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2210 $out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey,
null,
$object);
2235 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null,
$object =
null, $mode =
'')
2237 global
$conf, $langs, $hookmanager;
2239 if (is_null($outputlangs) || !is_object($outputlangs)) {
2240 $outputlangs = $langs;
2243 if (empty($extrafieldsobjectkey)) {
2244 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
2245 return 'BadValueForParamExtraFieldsObjectKey';
2248 $parameters = array(
2251 'moreparam' => $moreparam,
2252 'extrafieldsobjectkey' => $extrafieldsobjectkey,
2253 'outputlangs' => $outputlangs,
2258 $reshook = $hookmanager->executeHooks(
'showOutputExtraField', $parameters, $this, $action);
2260 return $hookmanager->resPrint;
2263 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
2264 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
2265 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
2266 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
2267 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
2268 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
2269 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
2270 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
2271 $perms = (int)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
2272 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
2273 $list = (
string)
dol_eval((
string) $this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
2274 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
2275 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
2276 $alwayseditable = $this->attributes[$extrafieldsobjectkey][
'alwayseditable'][$key];
2279 $showValueInsteadOfInputField = 0;
2281 if ($alwayseditable == 0 && is_object(
$object) && isset(
$object->status) && defined(get_class(
$object).
"::STATUS_DRAFT") &&
$object->status != $object::STATUS_DRAFT) {
2282 $showValueInsteadOfInputField = 1;
2285 $hidden = (empty($list) ? 1 : 0);
2294 if ($type ==
'date') {
2296 if ($value !==
'') {
2299 } elseif ($type ==
'datetime') {
2301 if ($value !==
'') {
2304 } elseif ($type ==
'duration') {
2306 if ($value !==
'') {
2307 $value = intval($value);
2310 } elseif ($type ==
'datetimegmt') {
2312 if ($value !==
'') {
2315 } elseif ($type ==
'int') {
2317 } elseif ($type ==
'double') {
2318 if (!empty($value)) {
2322 $value =
price($value, 0, $outputlangs, 0, 0, -2,
'');
2324 } elseif ($type ==
'boolean') {
2326 if (!empty($value)) {
2327 $checked =
' checked ';
2330 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
2332 $value =
yn($value ? 1 : 0);
2334 } elseif ($type ==
'mail' || $type ==
'email') {
2336 } elseif ($type ==
'ip') {
2338 } elseif ($type ==
'icon') {
2339 $value =
'<span class="'.$value.
'"></span>';
2340 } elseif ($type ==
'url') {
2342 } elseif ($type ==
'phone') {
2344 } elseif ($type ==
'price') {
2346 if ($value || $value ==
'0') {
2347 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol(
$conf->currency);
2349 } elseif ($type ==
'pricecy') {
2350 $currency =
$conf->currency;
2351 if (!empty($value)) {
2353 $pricetmp = explode(
':', $value);
2354 $currency = !empty($pricetmp[1]) ? $pricetmp[1] :
$conf->currency;
2355 $value = $pricetmp[0];
2357 if ($value || $value ==
'0') {
2358 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
2360 } elseif ($type ==
'select') {
2361 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2362 if (($pos = strpos($valstr,
"|")) !==
false) {
2363 $valstr = substr($valstr, 0, $pos);
2365 if ($langfile && $valstr) {
2366 $value = $outputlangs->trans($valstr);
2370 } elseif ($type ==
'sellist') {
2371 $param_list = array_keys($param[
'options']);
2372 $InfoFieldList = explode(
":", $param_list[0]);
2374 $selectkey =
"rowid";
2377 if (count($InfoFieldList) >= 3) {
2378 $selectkey = $InfoFieldList[2];
2379 $keyList = $InfoFieldList[2].
' as rowid';
2382 $fields_label = explode(
'|', $InfoFieldList[1]);
2383 if (is_array($fields_label)) {
2385 $keyList .= implode(
', ', $fields_label);
2388 $filter_categorie =
false;
2389 if (count($InfoFieldList) > 5) {
2390 if ($InfoFieldList[0] ==
'categorie') {
2391 $filter_categorie =
true;
2395 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2396 $sql .=
' FROM '.$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2397 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2400 if ($selectkey ==
'rowid' && empty($value)) {
2401 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = 0";
2402 } elseif ($selectkey ==
'rowid') {
2403 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = ".((int) $value);
2405 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" = '".$this->db->escape($value).
"'";
2409 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2411 $resql = $this->db->query($sql);
2413 if (!$filter_categorie) {
2416 $obj = $this->db->fetch_object($resql);
2419 $fields_label = explode(
'|', $InfoFieldList[1]);
2421 if (is_array($fields_label) && count($fields_label) > 1) {
2422 foreach ($fields_label as $field_toshow) {
2424 $field_toshow = preg_replace(
'/^.*\./',
'', $field_toshow);
2425 if (!empty($obj->$field_toshow)) {
2426 $translabel = $outputlangs->trans($obj->$field_toshow);
2428 if ($translabel != $obj->$field_toshow) {
2429 $value .=
dol_trunc($translabel, 24) .
' ';
2431 $value .= $obj->$field_toshow .
' ';
2437 $tmppropname = $InfoFieldList[1];
2439 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2440 $translabel = $outputlangs->trans($obj->$tmppropname);
2442 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2445 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2450 $obj = $this->db->fetch_object($resql);
2452 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2454 $result =
$c->fetch($obj->rowid);
2456 $ways =
$c->print_all_ways();
2457 foreach ($ways as $way) {
2458 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
2462 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2465 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2467 } elseif ($type ==
'radio') {
2468 if ($required && !isset($param[
'options'][$value])) {
2469 $outputlangs->load(
'errors');
2470 $value =
'<span class="opacitymedium">'.$outputlangs->trans(
'ErrorNoValueForRadioType').
'</span>';
2472 if (isset($param[
'options'][$value])) {
2473 $value = $outputlangs->trans($param[
'options'][$value]);
2478 } elseif ($type ==
'checkbox') {
2479 $value_arr = explode(
',', $value);
2482 if (is_array($value_arr)) {
2483 foreach ($value_arr as $keyval => $valueval) {
2484 if (!empty($valueval)) {
2485 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2489 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2490 } elseif ($type ==
'chkbxlst') {
2492 if (!is_null($value) && $value !=
'') {
2493 $value_arr = explode(
',', $value);
2495 $param_list = array_keys($param[
'options']);
2496 $InfoFieldList = explode(
":", $param_list[0]);
2498 $selectkey =
"rowid";
2501 if (count($InfoFieldList) >= 3) {
2502 $selectkey = $InfoFieldList[2];
2503 $keyList = $InfoFieldList[2].
' as rowid';
2506 $fields_label = explode(
'|', $InfoFieldList[1]);
2507 if (is_array($fields_label)) {
2509 $keyList .= implode(
', ', $fields_label);
2512 $filter_categorie =
false;
2513 if (count($InfoFieldList) > 5 && ((
string) $InfoFieldList[5] !=
'')) {
2514 if ($InfoFieldList[0] ==
'categorie') {
2515 $filter_categorie =
true;
2519 $sql =
"SELECT ".$this->db->sanitize($keyList, 0, 0, 1);
2520 $sql .=
" FROM ".$this->db->prefix().$this->db->sanitize($InfoFieldList[0]);
2521 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2524 $sql .=
" WHERE ".$this->db->sanitize($selectkey).
" IN (".$this->db->sanitize(implode(
',', $value_arr)).
")";
2526 dol_syslog(get_class($this).
':showOutputField type=chkbxlst', LOG_DEBUG);
2528 $resql = $this->db->query($sql);
2531 if (!$filter_categorie) {
2534 $numOfElem = $this->db->num_rows($resql);
2535 while ($obj = $this->db->fetch_object($resql)) {
2537 $fields_label = explode(
'|', $InfoFieldList[1]);
2540 if (count($fields_label) > 0) {
2541 if ($InfoFieldList[0] ==
'societe' && $InfoFieldList[1] ==
'nom' && $InfoFieldList[2] ==
'rowid') {
2543 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
2544 $tmpthirdpartystatic =
new Societe($this->db);
2545 $tmpthirdpartystatic->id = $obj->rowid;
2546 $tmpthirdpartystatic->name = $obj->nom;
2547 if ($numOfElem >= 3) {
2548 $tmpthirdpartystatic->name = $obj->nom;
2549 $label = $tmpthirdpartystatic->getNomUrl(2);
2550 } elseif ($numOfElem >= 2) {
2551 $tmpthirdpartystatic->name =
dol_trunc($obj->nom, 5);
2552 $label = $tmpthirdpartystatic->getNomUrl(1);
2554 $tmpthirdpartystatic->name = $obj->nom;
2555 $label = $tmpthirdpartystatic->getNomUrl(1);
2558 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'" style="background: '.$txtcolor.
'">';
2559 foreach ($fields_label as $field_toshow) {
2561 if (!empty($obj->$field_toshow)) {
2562 $translabel = $outputlangs->trans($obj->$field_toshow);
2564 if ($translabel != $field_toshow) {
2565 $label .=
' '.dol_trunc($translabel, 18);
2567 $label .=
' '.$obj->$field_toshow;
2572 $toprint[] = $label;
2576 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2579 $numElem = $this->db->num_rows($resql);
2580 while ($obj = $this->db->fetch_object($resql)) {
2582 $c->fetch($obj->rowid);
2583 if ((
string) $mode !=
'list') {
2584 $ways =
$c->print_all_ways();
2585 foreach ($ways as $way) {
2586 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories'.($mode ?
' '.$mode :
'').
'"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
2590 $forced_color =
'categtextwhite';
2592 if (colorIsLight(
$c->color)) {
2593 $forced_color =
'categtextblack';
2598 $s =
'<li class="select2-search-choice-dolibarr noborderoncategories '.$forced_color.
' list"'.(
$c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>';
2599 if ($numElem >= 2) {
2600 $s .=
img_object(
$c->label,
'category',
'class="small"');
2602 $s .=
img_object(
$c->label,
'category',
'class="small"').
' '.
$c->label;
2609 if (!empty($toprint)) {
2610 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2613 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2616 } elseif ($type ==
'link') {
2619 $param_list = array_keys($param[
'options']);
2621 $InfoFieldList = explode(
":", $param_list[0]);
2622 $classname = $InfoFieldList[0];
2623 $classpath = $InfoFieldList[1];
2624 if (!empty($classpath)) {
2626 if ($classname && class_exists($classname)) {
2627 $tmpobject =
new $classname($this->db);
2628 '@phan-var-force CommonObject $tmpobject';
2629 $tmpobject->fetch($value);
2631 if (get_class($tmpobject) ==
'Categorie') {
2633 $color = $tmpobject->color;
2634 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2635 $sfortag .= $tmpobject->getNomUrl(3);
2636 $sfortag .=
'</span>';
2639 $value = $tmpobject->getNomUrl(3);
2643 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2644 return 'Error bad setup of extrafield';
2647 } elseif ($type ==
'point') {
2648 if (!empty($value)) {
2649 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2651 $value = $dolgeophp->getXYString($value);
2655 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2656 if (!empty($value)) {
2657 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2659 $value = $dolgeophp->getPointString($value);
2663 } elseif ($type ==
'text') {
2664 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2665 } elseif ($type ==
'html') {
2667 } elseif ($type ==
'password') {
2668 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2669 } elseif ($type ==
'stars') {
2670 $objectid = (int)
$object->id;
2671 $nbstars = (int) $value;
2672 if ($showValueInsteadOfInputField == 1) {
2673 $value =
'<span style="display:none;" id="'.$key.$object->id.
'">'.
dol_escape_htmltag($value).
'</span>';
2675 $value =
'<input type="hidden" class="flat" name="'.$key.
'" id="'.$key.$objectid.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').
'>';
2678 $value .=
'<div class="star-selection" id="'.$key.$objectid.
'_selection">';
2680 while ($i <= $size) {
2681 $value .=
'<span class="star'.($i <= $nbstars ?
' active' :
'').
'" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
2686 $(document).ready(function() { /* extrafields.class.php 2 */
2687 let container = $("#'.$key.$objectid.
'_selection");
2688 let selectedStars = parseInt($("#'.$key.$objectid.
'").val() || $("#'.$key.$objectid.
'").text()) || 0;
2690 if ($showValueInsteadOfInputField == 0) {
2692 container.find(".star").on("mouseover", function() {
2693 console.log("Mouse over a star");
2694 let selectedStar = $(this).data("value");
2695 container.find(".star").each(function() {
2696 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
2699 container.on("mouseout", function() {
2700 console.log("Mouse out of star");
2701 container.find(".star").each(function() {
2702 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2705 container.find(".star").off("click").on("click", function() {
2706 console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
2707 selectedStars = $(this).data("value");
2708 if (selectedStars == 1 && $("#'.$key.$objectid.
'").val() == 1) {
2711 container.find("#'.$key.$objectid.
'").val(selectedStars);
2712 container.find(".star").each(function() {
2713 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
2716 url: "'.DOL_URL_ROOT.
'/core/ajax/updateextrafield.php",
2720 objectId:
'.((int) $objectid).',
2721 field: \
''.dol_escape_js($key).
'\',
2722 value: selectedStars,
2723 token: \
''.newToken().
'\'
2725 success:
function(response) {
2726 var res = JSON.parse(response);
2727 console[res.status ===
"success" ?
"log" :
"error"](res.message);
2729 error:
function(xhr,
status, error) {
2730 console.log(
"Ajax request failed while updating '.$key.':", error);
2739 $showsize = round((float) $size);
2740 if ($showsize > 48) {
2745 //print $type.'-
'.$size;