1068 public function showInputField($key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'', $objectid = 0, $extrafieldsobjectkey =
'', $mode = 0)
1070 global $conf, $langs, $form;
1072 if (!is_object($form)) {
1073 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
1074 $form =
new Form($this->db);
1079 if (!preg_match(
'/options_$/', $keyprefix)) {
1080 $keyprefix = $keyprefix.
'options_';
1083 if (empty($extrafieldsobjectkey)) {
1084 dol_syslog(get_class($this).
'::showInputField extrafieldsobjectkey required', LOG_ERR);
1085 return 'BadValueForParamExtraFieldsObjectKey';
1088 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1089 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1090 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1091 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1092 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1093 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1094 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1095 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1096 $perms = (int)
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
1097 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1098 $list = (string)
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
1099 $totalizable = $this->attributes[$extrafieldsobjectkey][
'totalizable'][$key];
1100 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1101 $hidden = (empty($list) ? 1 : 0);
1107 if (!preg_match(
'/^search_/', $keyprefix)) {
1108 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
1116 if (empty($morecss)) {
1118 if ($type ==
'date') {
1119 $morecss =
'minwidth100imp';
1120 } elseif ($type ==
'datetime' || $type ==
'datetimegmt' || $type ==
'link') {
1121 $morecss =
'minwidth200imp';
1122 } elseif (in_array($type, array(
'int',
'integer',
'double',
'price'))) {
1123 $morecss =
'maxwidth75';
1124 } elseif ($type ==
'password') {
1125 $morecss =
'maxwidth100';
1126 } elseif ($type ==
'url') {
1127 $morecss =
'minwidth400';
1128 } elseif ($type ==
'boolean') {
1130 } elseif ($type ==
'radio') {
1131 $morecss =
'width25';
1133 if (empty($size) || round((
float) $size) < 12) {
1134 $morecss =
'minwidth100';
1135 } elseif (round((
float) $size) <= 48) {
1136 $morecss =
'minwidth200';
1138 $morecss =
'minwidth400';
1142 if (!empty($this->attributes[$extrafieldsobjectkey][
'css'][$key])) {
1143 $morecss = $this->attributes[$extrafieldsobjectkey][
'css'][$key];
1147 if (in_array($type, array(
'date'))) {
1148 $tmp = explode(
',', $size);
1153 if (!$required && $value ==
'') {
1160 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1161 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1163 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1164 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"));
1165 $out .=
'</div><div class="nowrap">';
1166 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"));
1167 $out .=
'</div></div>';
1170 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
1172 } elseif (in_array($type, array(
'datetime',
'datetimegmt'))) {
1173 $tmp = explode(
',', $size);
1178 if (!$required && $value ==
'') {
1185 'start' => isset($value[
'start']) ? $value[
'start'] :
'',
1186 'end' => isset($value[
'end']) ? $value[
'end'] :
''
1188 $out =
'<div ' . ($moreparam ? $moreparam :
'') .
'><div class="nowrap">';
1189 $out .= $form->selectDate($prefill[
'start'], $keyprefix.$key.$keysuffix.
'_start', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"From"),
'tzuserrel');
1190 $out .=
'</div><div class="nowrap">';
1191 $out .= $form->selectDate($prefill[
'end'], $keyprefix.$key.$keysuffix.
'_end', 1, 1, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
1192 $out .=
'</div></div>';
1195 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
1197 } elseif (in_array($type, array(
'int',
'integer'))) {
1198 $tmp = explode(
',', $size);
1200 $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 :
'').
'>';
1201 } elseif (preg_match(
'/varchar/', $type)) {
1202 $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 :
'').
'>';
1203 } elseif (in_array($type, array(
'mail',
'ip',
'phone',
'url'))) {
1204 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1205 } elseif ($type ==
'icon') {
1211 $out .=
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat '.$morecss.
' maxwidthonsmartphone"';
1212 $out .=
' name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1215 $options =
"{ title: '<b>".$langs->trans(
"IconFieldSelector").
"</b>', placement: 'right', showFooter: false, templates: {";
1216 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
1217 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
1220 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
1221 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"".$langs->trans(
"TypeToFilter").
"\" />',";
1222 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
1223 $options .=
" <div class=\"arrow\" ></div>";
1224 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
1225 $options .=
" <div class=\"popover-content \" ></div>";
1226 $options .=
"</div>'}}";
1227 $out .=
"$('#".$keyprefix.$key.$keysuffix.
"').iconpicker(".$options.
");";
1228 $out .=
'</script>';
1230 } elseif ($type ==
'text') {
1231 if (!preg_match(
'/search_/', $keyprefix)) {
1232 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1233 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
1234 $out = (string) $doleditor->Create(1);
1236 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1238 } elseif ($type ==
'html') {
1239 if (!preg_match(
'/search_/', $keyprefix)) {
1240 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1241 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false, isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
1242 $out = (string) $doleditor->Create(1);
1244 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
1246 } elseif ($type ==
'boolean') {
1249 if (!empty($value)) {
1250 $checked =
' checked value="1" ';
1252 $checked =
' value="1" ';
1254 $out =
'<input type="checkbox" class="flat valignmiddle'.($morecss ?
' '.$morecss :
'').
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
1256 $out = $form->selectyesno($keyprefix.$key.$keysuffix, $value, 1,
false, 1);
1258 $out .=
'<input type="hidden" name="'.$keyprefix.$key.$keysuffix.
'_boolean" value="1">';
1259 } elseif ($type ==
'price') {
1260 if (!empty($value)) {
1261 $value =
price($value);
1263 $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).
'">';
1264 } elseif ($type ==
'pricecy') {
1265 $currency = $conf->currency;
1266 if (!empty($value)) {
1268 $pricetmp = explode(
':', $value);
1269 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
1270 $value =
price($pricetmp[0]);
1272 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1273 $out .= $form->selectCurrency($currency, $keyprefix.$key.$keysuffix.
'currency_id');
1274 } elseif ($type ==
'double') {
1275 if (!empty($value)) {
1276 $value =
price($value);
1278 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
1279 } elseif ($type ==
'select') {
1283 foreach ($param[
'options'] as $okey => $val) {
1284 if ((
string) $okey ==
'') {
1288 $valarray = explode(
'|', $val);
1289 $val = $valarray[0];
1291 if ($langfile && $val) {
1292 $options[$okey] = $langs->trans($val);
1294 $options[$okey] = $val;
1297 $selected = array();
1298 if (!is_array($value)) {
1299 $selected = explode(
',', $value);
1302 $out .= $form->multiselectarray($keyprefix.$key.$keysuffix, $options, $selected, 0, 0, $morecss, 0, 0,
'',
'',
'', !empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2'));
1304 if (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')) {
1305 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1306 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1309 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1310 $out .=
'<option value="0"> </option>';
1311 foreach ($param[
'options'] as $key2 => $val2) {
1312 if ((
string) $key2 ==
'') {
1315 $valarray = explode(
'|', $val2);
1316 $val2 = $valarray[0];
1318 if (!empty($valarray[1])) {
1319 $parent = $valarray[1];
1321 $out .=
'<option value="'.$key2.
'"';
1322 $out .= (((string) $value == (
string) $key2) ?
' selected' :
'');
1323 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1325 if ($langfile && $val2) {
1326 $out .= $langs->trans($val2);
1330 $out .=
'</option>';
1332 $out .=
'</select>';
1334 } elseif ($type ==
'sellist') {
1336 if (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')) {
1337 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1338 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1341 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
1342 if (is_array($param[
'options'])) {
1343 $tmpparamoptions = array_keys($param[
'options']);
1344 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1346 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1358 if (! empty($InfoFieldList[4])) {
1360 $parenthesisopen = 0;
1361 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1362 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1365 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1370 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1371 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1373 $InfoFieldList[4] = $tmpbefore;
1374 if ($tmpafter !==
'') {
1375 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1380 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1381 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1391 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1393 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1394 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1395 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1397 $keyList = $InfoFieldList[2].
' as rowid';
1400 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1401 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1402 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1403 $keyList .=
', main.'.$parentField;
1405 $keyList .=
', '.$parentField;
1409 $filter_categorie =
false;
1410 if (count($InfoFieldList) > 5) {
1411 if ($InfoFieldList[0] ==
'categorie') {
1412 $filter_categorie =
true;
1416 if ($filter_categorie ===
false) {
1417 $fields_label = explode(
'|', $InfoFieldList[1]);
1418 if (is_array($fields_label)) {
1420 $keyList .= implode(
', ', $fields_label);
1424 $sql =
"SELECT ".$keyList;
1425 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1428 if (!empty($InfoFieldList[4])) {
1430 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1431 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string) $conf->entity, $InfoFieldList[4]);
1434 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1435 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1439 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1440 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1442 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1447 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1448 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1449 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1455 $sqlwhere .=
' WHERE 1=1';
1472 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1473 $sqlwhere .=
' AND entity = '.((int) $conf->entity);
1478 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1480 dol_syslog(get_class($this).
'::showInputField type=sellist', LOG_DEBUG);
1481 $resql = $this->db->query($sql);
1483 $out .=
'<option value="0"> </option>';
1484 $num = $this->db->num_rows($resql);
1488 $obj = $this->db->fetch_object($resql);
1492 $fields_label = explode(
'|', $InfoFieldList[1]);
1493 if (is_array($fields_label) && count($fields_label) > 1) {
1495 foreach ($fields_label as $field_toshow) {
1496 $labeltoshow .= $obj->$field_toshow.
' ';
1499 $labeltoshow = $obj->{$InfoFieldList[1]};
1502 if ($value == $obj->rowid) {
1504 foreach ($fields_label as $field_toshow) {
1505 $translabel = $langs->trans($obj->$field_toshow);
1506 $labeltoshow = $translabel.
' ';
1509 $out .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
1512 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1513 $labeltoshow = $translabel;
1515 if (empty($labeltoshow)) {
1516 $labeltoshow =
'(not defined)';
1519 if (!empty($InfoFieldList[3]) && $parentField) {
1520 $parent = $parentName.
':'.$obj->{$parentField};
1523 $out .=
'<option value="'.$obj->rowid.
'"';
1524 $out .= ($value == $obj->rowid ?
' selected' :
'');
1525 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
1526 $out .=
'>'.$labeltoshow.
'</option>';
1531 $this->db->free($resql);
1533 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1536 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1537 $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1538 $out .=
'<option value="0"> </option>';
1539 if (is_array($data)) {
1540 foreach ($data as $data_key => $data_value) {
1541 $out .=
'<option value="'.$data_key.
'"';
1542 $out .= ($value == $data_key ?
' selected' :
'');
1543 $out .=
'>'.$data_value.
'</option>';
1548 $out .=
'</select>';
1549 } elseif ($type ==
'checkbox') {
1550 $value_arr = $value;
1551 if (!is_array($value)) {
1552 $value_arr = explode(
',', $value);
1554 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr,
'', 0,
'', 0,
'100%');
1555 } elseif ($type ==
'radio') {
1557 foreach ($param[
'options'] as $keyopt => $val) {
1558 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
1559 $out .=
' value="'.$keyopt.
'"';
1560 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
1561 $out .= ($value == $keyopt ?
'checked' :
'');
1562 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$langs->trans($val).
'</label><br>';
1564 } elseif ($type ==
'chkbxlst') {
1565 if (is_array($value)) {
1566 $value_arr = $value;
1568 $value_arr = explode(
',', $value);
1571 if (is_array($param[
'options'])) {
1572 $tmpparamoptions = array_keys($param[
'options']);
1573 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
1575 $InfoFieldList = explode(
":", $paramoptions[0], 5);
1587 if (! empty($InfoFieldList[4])) {
1589 $parenthesisopen = 0;
1590 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
1591 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
1594 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
1599 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
1600 $tmpafter = substr($InfoFieldList[4], $pos + 1);
1602 $InfoFieldList[4] = $tmpbefore;
1603 if ($tmpafter !==
'') {
1604 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
1609 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
1610 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
1620 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
1622 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1623 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1624 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
1626 $keyList = $InfoFieldList[2].
' as rowid';
1629 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
1630 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
1631 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
1632 $keyList .=
', main.'.$parentField;
1634 $keyList .=
', '.$parentField;
1638 $filter_categorie =
false;
1639 if (count($InfoFieldList) > 5) {
1640 if ($InfoFieldList[0] ==
'categorie') {
1641 $filter_categorie =
true;
1645 if ($filter_categorie ===
false) {
1646 $fields_label = explode(
'|', $InfoFieldList[1]);
1647 if (is_array($fields_label)) {
1649 $keyList .= implode(
', ', $fields_label);
1653 $sql =
"SELECT ".$keyList;
1654 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
1657 if (!empty($InfoFieldList[4])) {
1659 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
1660 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string) $conf->entity, $InfoFieldList[4]);
1663 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
1664 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
1668 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
1669 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
1670 } elseif (preg_match(
"#^.*list.php$#", $_SERVER[
"PHP_SELF"])) {
1672 $word =
'\b[a-zA-Z0-9-\.-_]+\b=\$ID\$';
1675 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1679 while ($nbPreg != 0) {
1681 $nbPregRepl = $nbPregSel = 0;
1683 $InfoFieldList[4] = preg_replace(
'#([^=])(\([^)^(]*('.$word.
')[^)^(]*\))#',
'$1 $3 ', $InfoFieldList[4], -1, $nbPregRepl);
1685 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1687 $InfoFieldList[4] = preg_replace(
'#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*('.$word.
')[^)^(]*\)#',
'$1 ', $InfoFieldList[4], -1, $nbPregSel);
1689 $InfoFieldList[4] = preg_replace(
'# *(=|\(|\)) *#',
'$1', $InfoFieldList[4]);
1692 $nbPreg = $nbPregRepl + $nbPregSel;
1696 $matchCondition = array();
1697 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1698 while (!empty($matchCondition[0])) {
1700 if (!empty($matchCondition[1]) && !empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3]) {
1702 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1704 if (!empty($matchCondition[1])) {
1705 $boolCond = (($matchCondition[1] ==
"AND") ?
' AND TRUE ' :
' OR FALSE ');
1706 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond.$matchCondition[3], $InfoFieldList[4]);
1707 } elseif (!empty($matchCondition[3])) {
1708 $boolCond = (($matchCondition[3] ==
"AND") ?
' TRUE AND ' :
' FALSE OR');
1709 $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond, $InfoFieldList[4]);
1711 $InfoFieldList[4] =
" TRUE ";
1716 preg_match(
'#(AND|OR|) *('.$word.
') *(AND|OR|)#', $InfoFieldList[4], $matchCondition);
1719 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
1724 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
1725 $sql .=
' as main, '.$this->db->sanitize($this->db->prefix().$InfoFieldList[0]).
'_extrafields as extra';
1726 $sqlwhere .=
" WHERE extra.fk_object = main.".$this->db->sanitize($InfoFieldList[2]);
1732 $sqlwhere .=
' WHERE 1=1';
1749 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
1750 $sqlwhere .=
" AND entity = ".((int) $conf->entity);
1756 $sql .=
' ORDER BY '.implode(
', ', $fields_label);
1758 dol_syslog(get_class($this).
'::showInputField type=chkbxlst', LOG_DEBUG);
1759 $resql = $this->db->query($sql);
1761 $num = $this->db->num_rows($resql);
1768 $obj = $this->db->fetch_object($resql);
1772 $fields_label = explode(
'|', $InfoFieldList[1]);
1773 if (is_array($fields_label)) {
1775 foreach ($fields_label as $field_toshow) {
1776 $labeltoshow .= $obj->$field_toshow.
' ';
1779 $labeltoshow = $obj->{$InfoFieldList[1]};
1781 $labeltoshow =
dol_trunc($labeltoshow, 45);
1783 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1785 foreach ($fields_label as $field_toshow) {
1786 $translabel = $langs->trans($obj->$field_toshow);
1787 if ($translabel != $obj->$field_toshow) {
1788 $labeltoshow .=
' '.dol_trunc($translabel, 18).
' ';
1790 $labeltoshow .=
' '.dol_trunc($obj->$field_toshow, 18).
' ';
1793 $data[$obj->rowid] = $labeltoshow;
1796 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1797 if ($translabel != $obj->{$InfoFieldList[1]}) {
1798 $labeltoshow =
dol_trunc($translabel, 18);
1800 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
1803 if (empty($labeltoshow)) {
1804 $labeltoshow =
'(not defined)';
1807 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1808 $data[$obj->rowid] = $labeltoshow;
1811 if (!empty($InfoFieldList[3]) && $parentField) {
1812 $parent = $parentName.
':'.$obj->{$parentField};
1815 $data[$obj->rowid] = $labeltoshow;
1820 $this->db->free($resql);
1822 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1824 print
'Error in request '.$sql.
' '.$this->db->lasterror().
'. Check setup of extra parameters.<br>';
1827 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1828 $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
1829 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr,
'', 0,
'', 0,
'100%');
1832 } elseif ($type ==
'link') {
1833 $param_list = array_keys($param[
'options']);
1840 $showempty = (($required && $default !=
'') ? 0 : 1);
1842 $tmparray = explode(
':', $param_list[0]);
1844 $element = $extrafieldsobjectkey;
1845 if ($element ==
'socpeople') {
1846 $element =
'contact';
1847 } elseif ($element ==
'projet') {
1848 $element =
'project';
1852 $objectdesc = $tmparray[0];
1853 $objectfield = $element.
':options_'.$key;
1855 $out = $form->selectForForms($objectdesc, $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss,
'', 0, 0,
'', $objectfield);
1856 } elseif (in_array($type, [
'point',
'multipts',
'linestrg',
'polygon'])) {
1857 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
1861 if (!empty($value)) {
1862 $tmparray = $dolgeophp->parseGeoString($value);
1863 $geojson = $tmparray[
'geojson'];
1864 $centroidjson = $tmparray[
'centroidjson'];
1866 if (!preg_match(
'/search_/', $keyprefix)) {
1867 require_once DOL_DOCUMENT_ROOT.
'/core/class/geomapeditor.class.php';
1869 $out .= $geomapeditor->getHtml($keyprefix.$key.$keysuffix, $geojson, $centroidjson, $type);
1874 } elseif ($type ==
'password') {
1876 $out =
'<input style="display:none" type="text" name="fakeusernameremembered">';
1877 $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 :
'').
'>';
1879 if (!empty($hidden)) {
1880 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
1903 public function showOutputField($key, $value, $moreparam =
'', $extrafieldsobjectkey =
'', $outputlangs =
null)
1905 global $conf, $langs;
1907 if (is_null($outputlangs) || !is_object($outputlangs)) {
1908 $outputlangs = $langs;
1911 if (empty($extrafieldsobjectkey)) {
1912 dol_syslog(get_class($this).
'::showOutputField extrafieldsobjectkey required', LOG_ERR);
1913 return 'BadValueForParamExtraFieldsObjectKey';
1916 $label = $this->attributes[$extrafieldsobjectkey][
'label'][$key];
1917 $type = $this->attributes[$extrafieldsobjectkey][
'type'][$key];
1918 $size = $this->attributes[$extrafieldsobjectkey][
'size'][$key];
1919 $default = $this->attributes[$extrafieldsobjectkey][
'default'][$key];
1920 $computed = $this->attributes[$extrafieldsobjectkey][
'computed'][$key];
1921 $unique = $this->attributes[$extrafieldsobjectkey][
'unique'][$key];
1922 $required = $this->attributes[$extrafieldsobjectkey][
'required'][$key];
1923 $param = $this->attributes[$extrafieldsobjectkey][
'param'][$key];
1924 $perms = (int)
dol_eval($this->attributes[$extrafieldsobjectkey][
'perms'][$key], 1, 1,
'2');
1925 $langfile = $this->attributes[$extrafieldsobjectkey][
'langfile'][$key];
1926 $list = (string)
dol_eval($this->attributes[$extrafieldsobjectkey][
'list'][$key], 1, 1,
'2');
1927 $help = $this->attributes[$extrafieldsobjectkey][
'help'][$key];
1928 $cssview = $this->attributes[$extrafieldsobjectkey][
'cssview'][$key];
1930 $hidden = (empty($list) ? 1 : 0);
1939 if ($type ==
'date') {
1941 if ($value !==
'') {
1944 } elseif ($type ==
'datetime') {
1946 if ($value !==
'') {
1949 } elseif ($type ==
'datetimegmt') {
1951 if ($value !==
'') {
1954 } elseif ($type ==
'int') {
1956 } elseif ($type ==
'double') {
1957 if (!empty($value)) {
1959 $sizeparts = explode(
",", $size);
1960 $number_decimals = array_key_exists(1, $sizeparts) ? $sizeparts[1] : 0;
1961 $value =
price($value, 0, $outputlangs, 0, 0, $number_decimals,
'');
1963 } elseif ($type ==
'boolean') {
1965 if (!empty($value)) {
1966 $checked =
' checked ';
1969 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
1971 $value =
yn($value ? 1 : 0);
1973 } elseif ($type ==
'mail') {
1975 } elseif ($type ==
'ip') {
1977 } elseif ($type ==
'icon') {
1978 $value =
'<span class="'.$value.
'"></span>';
1979 } elseif ($type ==
'url') {
1981 } elseif ($type ==
'phone') {
1983 } elseif ($type ==
'price') {
1985 if ($value || $value ==
'0') {
1986 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1).
' '.$outputlangs->getCurrencySymbol($conf->currency);
1988 } elseif ($type ==
'pricecy') {
1989 $currency = $conf->currency;
1990 if (!empty($value)) {
1992 $pricetmp = explode(
':', $value);
1993 $currency = !empty($pricetmp[1]) ? $pricetmp[1] : $conf->currency;
1994 $value = $pricetmp[0];
1996 if ($value || $value ==
'0') {
1997 $value =
price($value, 0, $outputlangs, 0,
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT'), -1, $currency);
1999 } elseif ($type ==
'select') {
2000 $valstr = (!empty($param[
'options'][$value]) ? $param[
'options'][$value] :
'');
2001 if (($pos = strpos($valstr,
"|")) !==
false) {
2002 $valstr = substr($valstr, 0, $pos);
2004 if ($langfile && $valstr) {
2005 $value = $outputlangs->trans($valstr);
2009 } elseif ($type ==
'sellist') {
2010 $param_list = array_keys($param[
'options']);
2011 $InfoFieldList = explode(
":", $param_list[0]);
2013 $selectkey =
"rowid";
2016 if (count($InfoFieldList) >= 3) {
2017 $selectkey = $InfoFieldList[2];
2018 $keyList = $InfoFieldList[2].
' as rowid';
2021 $fields_label = explode(
'|', $InfoFieldList[1]);
2022 if (is_array($fields_label)) {
2024 $keyList .= implode(
', ', $fields_label);
2027 $filter_categorie =
false;
2028 if (count($InfoFieldList) > 5) {
2029 if ($InfoFieldList[0] ==
'categorie') {
2030 $filter_categorie =
true;
2034 $sql =
"SELECT ".$keyList;
2035 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
2036 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
2039 if ($selectkey ==
'rowid' && empty($value)) {
2040 $sql .=
" WHERE ".$selectkey.
" = 0";
2041 } elseif ($selectkey ==
'rowid') {
2042 $sql .=
" WHERE ".$selectkey.
" = ".((int) $value);
2044 $sql .=
" WHERE ".$selectkey.
" = '".$this->db->escape($value).
"'";
2049 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
2050 $resql = $this->db->query($sql);
2052 if ($filter_categorie ===
false) {
2055 $obj = $this->db->fetch_object($resql);
2058 $fields_label = explode(
'|', $InfoFieldList[1]);
2060 if (is_array($fields_label) && count($fields_label) > 1) {
2061 foreach ($fields_label as $field_toshow) {
2063 if (!empty($obj->$field_toshow)) {
2064 $translabel = $outputlangs->trans($obj->$field_toshow);
2066 if ($translabel != $obj->$field_toshow) {
2067 $value .=
dol_trunc($translabel, 24) .
' ';
2069 $value .= $obj->$field_toshow .
' ';
2075 $tmppropname = $InfoFieldList[1];
2077 if (!empty(isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2078 $translabel = $outputlangs->trans($obj->$tmppropname);
2080 if ($translabel != (isset($obj->$tmppropname) ? $obj->$tmppropname :
'')) {
2083 $value = isset($obj->$tmppropname) ? $obj->$tmppropname :
'';
2088 $obj = $this->db->fetch_object($resql);
2090 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
2092 $result = $c->fetch($obj->rowid);
2094 $ways = $c->print_all_ways();
2095 foreach ($ways as $way) {
2096 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
2100 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2103 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2105 } elseif ($type ==
'radio') {
2106 if (!isset($param[
'options'][$value])) {
2107 $outputlangs->load(
'errors');
2108 $value = $outputlangs->trans(
'ErrorNoValueForRadioType');
2110 $value = $outputlangs->trans($param[
'options'][$value]);
2112 } elseif ($type ==
'checkbox') {
2113 $value_arr = explode(
',', $value);
2116 if (is_array($value_arr)) {
2117 foreach ($value_arr as $keyval => $valueval) {
2118 if (!empty($valueval)) {
2119 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$param[
'options'][$valueval].
'</li>';
2123 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2124 } elseif ($type ==
'chkbxlst') {
2125 $value_arr = explode(
',', $value);
2127 $param_list = array_keys($param[
'options']);
2128 $InfoFieldList = explode(
":", $param_list[0]);
2130 $selectkey =
"rowid";
2133 if (count($InfoFieldList) >= 3) {
2134 $selectkey = $InfoFieldList[2];
2135 $keyList = $InfoFieldList[2].
' as rowid';
2138 $fields_label = explode(
'|', $InfoFieldList[1]);
2139 if (is_array($fields_label)) {
2141 $keyList .= implode(
', ', $fields_label);
2144 $filter_categorie =
false;
2145 if (count($InfoFieldList) > 5) {
2146 if ($InfoFieldList[0] ==
'categorie') {
2147 $filter_categorie =
true;
2151 $sql =
"SELECT ".$keyList;
2152 $sql .=
" FROM ".$this->db->prefix().$InfoFieldList[0];
2153 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
2159 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
2160 $resql = $this->db->query($sql);
2162 if ($filter_categorie ===
false) {
2165 while ($obj = $this->db->fetch_object($resql)) {
2167 $fields_label = explode(
'|', $InfoFieldList[1]);
2168 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2169 if (is_array($fields_label) && count($fields_label) > 1) {
2170 $label =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">';
2171 foreach ($fields_label as $field_toshow) {
2173 if (!empty($obj->$field_toshow)) {
2174 $translabel = $outputlangs->trans($obj->$field_toshow);
2176 if ($translabel != $field_toshow) {
2177 $label .=
' '.dol_trunc($translabel, 18);
2179 $label .=
' '.$obj->$field_toshow;
2183 $toprint[] = $label;
2186 if (!empty($obj->{$InfoFieldList[1]})) {
2187 $translabel = $outputlangs->trans($obj->{$InfoFieldList[1]});
2189 if ($translabel != $obj->{$InfoFieldList[1]}) {
2190 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.dol_trunc($translabel, 18).
'</li>';
2192 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">'.$obj->{$InfoFieldList[1]}.
'</li>';
2198 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2201 while ($obj = $this->db->fetch_object($resql)) {
2202 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
2204 $c->fetch($obj->rowid);
2205 $ways = $c->print_all_ways();
2206 foreach ($ways as $way) {
2207 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ?
' style="background: #'.$c->color.
';"' :
' style="background: #bbb"').
'>'.
img_object(
'',
'category').
' '.$way.
'</li>';
2212 if (!empty($toprint)) {
2213 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
2216 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
2218 } elseif ($type ==
'link') {
2223 $param_list = array_keys($param[
'options']);
2225 $InfoFieldList = explode(
":", $param_list[0]);
2226 $classname = $InfoFieldList[0];
2227 $classpath = $InfoFieldList[1];
2228 if (!empty($classpath)) {
2230 if ($classname && class_exists($classname)) {
2231 $tmpobject =
new $classname($this->db);
2232 '@phan-var-force CommonObject $tmpobject';
2233 $tmpobject->fetch($value);
2235 if (get_class($tmpobject) ==
'Categorie') {
2237 $color = $tmpobject->color;
2238 $sfortag =
'<span class="noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
2239 $sfortag .= $tmpobject->getNomUrl(3);
2240 $sfortag .=
'</span>';
2243 $value = $tmpobject->getNomUrl(3);
2247 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
2248 return 'Error bad setup of extrafield';
2251 } elseif ($type ==
'point') {
2252 if (!empty($value)) {
2253 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2255 $value = $dolgeophp->getXYString($value);
2259 } elseif (in_array($type, [
'multipts',
'linestrg',
'polygon'])) {
2260 if (!empty($value)) {
2261 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeophp.class.php';
2263 $value = $dolgeophp->getPointString($value);
2267 } elseif ($type ==
'text') {
2268 $value =
'<div class="'.($cssview ? $cssview :
'shortmessagecut').
'">'.
dol_htmlentitiesbr($value).
'</div>';
2269 } elseif ($type ==
'html') {
2271 } elseif ($type ==
'password') {
2272 $value =
dol_trunc(preg_replace(
'/./i',
'*', $value), 8,
'right',
'UTF-8', 1);
2274 $showsize = round((
float) $size);
2275 if ($showsize > 48) {