dolibarr 21.0.0-alpha
html.formwebportal.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2023-2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023-2024 Lionel Vessiller <lvessiller@easya.solutions>
4 * Copyright (C) 2023-2024 Patrice Andreani <pandreani@easya.solutions>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22
29require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php';
30
35class FormWebPortal extends Form
36{
40 public $db;
41
45 public $infofiles; // Used to return information by function getDocumentsLink
46
47
53 public function __construct($db)
54 {
55 $this->db = $db;
56 }
57
71 public function inputType($type, $name, $value = '', $id = '', $morecss = '', $moreparam = '', $label = '', $addInputLabel = '')
72 {
73 $out = '';
74 if ($label != '') {
75 $out .= '<label for="' . $id . '">';
76 }
77 $out .= '<input type="' . $type . '"';
78 $out .= ($morecss ? ' class="' . $morecss . '"' : '');
79 if ($id != '') {
80 $out .= ' id="' . $id . '"';
81 }
82 $out .= ' name="' . $name . '"';
83 $out .= ' value="' . $value . '"';
84 $out .= ($moreparam ? ' ' . $moreparam : '');
85 $out .= ' />' . $addInputLabel;
86 if ($label != '') {
87 $out .= $label . '</label>';
88 }
89
90 return $out;
91 }
92
104 public function inputDate($name, $value = '', $placeholder = '', $id = '', $morecss = '', $moreparam = '')
105 {
106 $out = '';
107
108 // Disabled: Use of native browser date input field as it is not compliant with multilanguagedate format,
109 // nor with timezone management.
110 /*
111 $out .= '<input';
112 if ($placeholder != '' && $value == '') {
113 // to show a placeholder on date input
114 $out .= ' type="text" placeholder="' . $placeholder . '" onfocus="(this.type=\'date\')"';
115 } else {
116 $out .= ' type="date"';
117 }
118 $out .= ($morecss ? ' class="' . $morecss . '"' : '');
119 if ($id != '') {
120 $out .= ' id="' . $id . '"';
121 }
122 $out .= ' name="' . $name . '"';
123 $out .= ' value="' . $value . '"';
124 $out .= ($moreparam ? ' ' . $moreparam : '');
125
126 $out .= '>';
127 */
128
129 $out = $this->selectDate($value === '' ? -1 : $value, $name, 0, 0, 0, "", 1, 0, 0, '');
130
131 return $out;
132 }
133
156 public static function selectarray($htmlname, $array, $id = '', $show_empty = 0, $key_in_label = 0, $value_as_key = 0, $moreparam = '', $translate = 0, $maxlen = 0, $disabled = 0, $sort = '', $morecss = 'minwidth75', $addjscombo = 1, $moreparamonempty = '', $disablebademail = 0, $nohtmlescape = 0)
157 {
158 global $langs;
159
160 if ($value_as_key) {
161 $array = array_combine($array, $array);
162 }
163
164 $out = '';
165
166 $idname = str_replace(array('[', ']'), array('', ''), $htmlname);
167 $out .= '<select id="' . preg_replace('/^\./', '', $idname) . '"' . ($disabled ? ' disabled="disabled"' : '') . ' class="' . ($morecss ? ' ' . $morecss : '') . '"';
168 $out .= ' name="' . preg_replace('/^\./', '', $htmlname) . '"' . ($moreparam ? ' ' . $moreparam : '');
169 $out .= '>' . "\n";
170
171 if ($show_empty) {
172 $textforempty = ' ';
173 if (!is_numeric($show_empty)) {
174 $textforempty = $show_empty;
175 }
176 $out .= '<option value="' . ($show_empty < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n";
177 }
178
179 if (is_array($array)) {
180 // Translate
181 if ($translate) {
182 foreach ($array as $key => $value) {
183 if (!is_array($value)) {
184 $array[$key] = $langs->trans($value);
185 } else {
186 $array[$key]['label'] = $langs->trans($value['label']);
187 }
188 }
189 }
190
191 // Sort
192 if ($sort == 'ASC') {
193 asort($array);
194 } elseif ($sort == 'DESC') {
195 arsort($array);
196 }
197
198 foreach ($array as $key => $tmpvalue) {
199 if (is_array($tmpvalue)) {
200 $value = $tmpvalue['label'];
201 $disabled = empty($tmpvalue['disabled']) ? '' : ' disabled';
202 } else {
203 $value = $tmpvalue;
204 $disabled = '';
205 }
206
207 if ($key_in_label) {
208 $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
209 } else {
210 $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value);
211 if ($value == '' || $value == '-') {
212 $selectOptionValue = '&nbsp;';
213 }
214 }
215
216 $out .= '<option value="' . $key . '"';
217 $out .= $disabled;
218 if (is_array($id)) {
219 if (in_array($key, $id) && !$disabled) {
220 $out .= ' selected'; // To preselect a value
221 }
222 } else {
223 $id = (string) $id; // if $id = 0, then $id = '0'
224 if ($id != '' && ($id == $key || ($id == 'ifone' && count($array) == 1)) && !$disabled) {
225 $out .= ' selected'; // To preselect a value
226 }
227 }
228 if (is_array($tmpvalue)) {
229 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
230 if (preg_match('/^data-/', $keyforvalue)) {
231 $out .= ' ' . $keyforvalue . '="' . dol_escape_htmltag($valueforvalue) . '"';
232 }
233 }
234 }
235 $out .= '>';
236 $out .= $selectOptionValue;
237 $out .= "</option>\n";
238 }
239 }
240
241 $out .= "</select>";
242
243 return $out;
244 }
245
259 public function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter = '', $morecss = '', $allfiles = 0)
260 {
261 include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
262
263 $out = '';
264
266 if (!$context) {
267 return '';
268 }
269
270 $this->infofiles = array('nboffiles' => 0, 'extensions' => array(), 'files' => array());
271
272 $entity = 1; // Without multicompany
273
274 // Get object entity
275 if (isModEnabled('multicompany')) {
276 $regs = array();
277 preg_match('/\/([0-9]+)\/[^\/]+\/' . preg_quote($modulesubdir, '/') . '$/', $filedir, $regs);
278 $entity = ((!empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
279 }
280
281 // Get list of files starting with name of ref (Note: files with '^ref\.extension' are generated files, files with '^ref-...' are uploaded files)
282 if ($allfiles || getDolGlobalString('MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP')) {
283 $filterforfilesearch = '^' . preg_quote(basename($modulesubdir), '/');
284 } else {
285 $filterforfilesearch = '^' . preg_quote(basename($modulesubdir), '/') . '\.';
286 }
287 $file_list = dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // We also discard .meta and .png preview
288
289 //var_dump($file_list);
290 // For ajax treatment
291 $out .= '<!-- html.formwebportal::getDocumentsLink -->' . "\n";
292 if (!empty($file_list)) {
293 $tmpout = '';
294
295 // Loop on each file found
296 $found = 0;
297 $i = 0;
298 foreach ($file_list as $file) {
299 $i++;
300 if ($filter && !preg_match('/' . $filter . '/i', $file["name"])) {
301 continue; // Discard this. It does not match provided filter.
302 }
303
304 $found++;
305 // Define relative path for download link (depends on module)
306 $relativepath = $file["name"]; // Cas general
307 if ($modulesubdir) {
308 $relativepath = $modulesubdir . "/" . $file["name"]; // Cas propal, facture...
309 }
310 // Autre cas
311 if ($modulepart == 'donation') {
312 $relativepath = get_exdir($modulesubdir, 2, 0, 0, null, 'donation') . $file["name"];
313 }
314 if ($modulepart == 'export') {
315 $relativepath = $file["name"];
316 }
317
318 $this->infofiles['nboffiles']++;
319 $this->infofiles['files'][] = $file['fullname'];
320 $ext = pathinfo($file["name"], PATHINFO_EXTENSION);
321 if (empty($this->infofiles['extensions'][$ext])) {
322 $this->infofiles['extensions'][$ext] = 1;
323 } else {
324 // @phan-suppress-next-line PhanTypeInvalidDimOffset
325 $this->infofiles['extensions'][$ext]++;
326 }
327
328 // Download
329 $url = $context->getControllerUrl('document') . '&modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($relativepath) . '&soc_id=' . $context->logged_thirdparty->id;
330 $tmpout .= '<a href="' . $url . '"' . ($morecss ? ' class="' . $morecss . '"' : '') . ' role="downloadlink"';
331 $mime = dol_mimetype($relativepath, '', 0);
332 if (preg_match('/text/', $mime)) {
333 $tmpout .= ' target="_blank" rel="noopener noreferrer"';
334 }
335 $tmpout .= '>';
336 $tmpout .= img_mime($relativepath, $file["name"]);
337 $tmpout .= strtoupper($ext);
338 $tmpout .= '</a>';
339 }
340
341 if ($found) {
342 $out .= $tmpout;
343 }
344 }
345
346 return $out;
347 }
348
359 public function getSignatureLink($modulepart, $object, $morecss = '')
360 {
361 global $langs;
362 require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
363 $out = '<!-- html.formwebportal::getSignatureLink -->' . "\n";
364 $url = getOnlineSignatureUrl(0, $modulepart, $object->ref, 1, $object);
365 if (!empty($url)) {
366 $out .= '<a target="_blank" rel="noopener noreferrer" href="' . $url . '"' . ($morecss ? ' class="' . $morecss . '"' : '') . ' role="signaturelink">';
367 $out .= '<i class="fa fa-file-signature"></i>';
368 $out .= $langs->trans("Sign");
369 $out .= '</a>';
370 }
371 return $out;
372 }
373
394 public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
395 {
396 global $conf;
397
398 $objecttmp = null;
399
400 // Example of value for $objectdec:
401 // Bom:bom/class/bom.class.php:0:t.status=1
402 // Bom:bom/class/bom.class.php:0:t.status=1:ref
403 // Bom:bom/class/bom.class.php:0:(t.status:=:1):ref
404 $InfoFieldList = explode(":", $objectdesc, 4);
405 $vartmp = (empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]);
406 $reg = array();
407 if (preg_match('/^.*:(\w*)$/', $vartmp, $reg)) {
408 $InfoFieldList[4] = $reg[1]; // take the sort field
409 }
410 $InfoFieldList[3] = preg_replace('/:\w*$/', '', $vartmp); // take the filter field
411
412 $classname = $InfoFieldList[0];
413 $classpath = $InfoFieldList[1];
414 $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3];
415 $sortfield = empty($InfoFieldList[4]) ? '' : $InfoFieldList[4];
416
417 if (!empty($classpath)) {
418 dol_include_once($classpath);
419
420 if ($classname && class_exists($classname)) {
421 $objecttmp = new $classname($this->db);
422
423 // Make some replacement
424 $sharedentities = getEntity(strtolower($classname));
425 $filter = str_replace(
426 array('__ENTITY__', '__SHARED_ENTITIES__'),
427 array($conf->entity, $sharedentities),
428 $filter
429 );
430 }
431 }
432 if (!is_object($objecttmp)) {
433 dol_syslog('Error bad setup of type for field ' . implode(',', $InfoFieldList), LOG_WARNING);
434 return 'Error bad setup of type for field ' . implode(',', $InfoFieldList);
435 }
436
437 dol_syslog(__METHOD__ . ' filter=' . $filter, LOG_DEBUG);
438 $out = '';
439 // Immediate load of table record.
440 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
441
442 return $out;
443 }
444
465 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield = '', $filter = '')
466 {
467 global $conf, $langs, $hookmanager;
468
469 $prefixforautocompletemode = $objecttmp->element;
470 if ($prefixforautocompletemode == 'societe') {
471 $prefixforautocompletemode = 'company';
472 }
473 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
474
475 if (in_array($objecttmp->element, array('adherent_type'))) {
476 $fieldstoshow = 't.libelle';
477 }
478 if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
479 $tmpfieldstoshow = '';
480 foreach ($objecttmp->fields as $key => $val) {
481 if (! (int) dol_eval($val['enabled'], 1, 1, '1')) {
482 continue;
483 }
484 if (!empty($val['showoncombobox'])) {
485 $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key;
486 }
487 }
488 if ($tmpfieldstoshow) {
489 $fieldstoshow = $tmpfieldstoshow;
490 }
491 } elseif (!in_array($objecttmp->element, array('adherent_type'))) {
492 // For backward compatibility
493 $objecttmp->fields['ref'] = array('type' => 'varchar(30)', 'label' => 'Ref', 'showoncombobox' => 1);
494 }
495
496 if (empty($fieldstoshow)) {
497 if (isset($objecttmp->fields['ref'])) {
498 $fieldstoshow = 't.ref';
499 } else {
500 $langs->load("errors");
501 $this->error = $langs->trans("ErrorNoFieldWithAttributeShowoncombobox");
502 return $langs->trans('ErrorNoFieldWithAttributeShowoncombobox');
503 }
504 }
505
506 $out = '';
507 $outarray = array();
508 $tmparray = array();
509
510 $num = 0;
511
512 // Search data
513 $sql = "SELECT t.rowid, " . $fieldstoshow . " FROM " . $this->db->prefix() . $objecttmp->table_element . " as t";
514 if (isset($objecttmp->ismultientitymanaged)) {
515 if (!is_numeric($objecttmp->ismultientitymanaged)) {
516 $tmparray = explode('@', $objecttmp->ismultientitymanaged);
517 $sql .= " INNER JOIN " . $this->db->prefix() . $tmparray[1] . " as parenttable ON parenttable.rowid = t." . $tmparray[0];
518 }
519 }
520
521 // Add where from hooks
522 $parameters = array(
523 'object' => $objecttmp,
524 'htmlname' => $htmlname,
525 'filter' => $filter,
526 'searchkey' => $searchkey
527 );
528
529 $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook
530 if (!empty($hookmanager->resPrint)) {
531 $sql .= $hookmanager->resPrint;
532 } else {
533 $sql .= " WHERE 1=1";
534 if (isset($objecttmp->ismultientitymanaged)) {
535 if ($objecttmp->ismultientitymanaged == 1) {
536 $sql .= " AND t.entity IN (" . getEntity($objecttmp->table_element) . ")";
537 }
538 if (!is_numeric($objecttmp->ismultientitymanaged)) {
539 $sql .= " AND parenttable.entity = t." . $tmparray[0];
540 }
541 }
542 if ($searchkey != '') {
543 $sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
544 }
545
546 if ($filter) { // Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
547 $errormessage = '';
548 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
549 if ($errormessage) {
550 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
551 }
552 }
553 }
554 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, "ASC");
555
556 // Build output string
557 $resql = $this->db->query($sql);
558 if ($resql) {
559 // Construct $out and $outarray
560 $out .= '<select id="' . $htmlname . '" class="' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ($moreparams ? ' ' . $moreparams : '') . ' name="' . $htmlname . '">' . "\n";
561
562 // Warning: Do not use textifempty = ' ' or '&nbsp;' here, or search on key will search on ' key'. Seems it is no more true with selec2 v4
563 $textifempty = '&nbsp;';
564
565 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
566 if (getDolGlobalString($confkeyforautocompletemode)) {
567 if ($showempty && !is_numeric($showempty)) {
568 $textifempty = $langs->trans($showempty);
569 } else {
570 $textifempty .= $langs->trans("All");
571 }
572 }
573 if ($showempty) {
574 $out .= '<option value="-1">' . $textifempty . '</option>' . "\n";
575 }
576
577 $num = $this->db->num_rows($resql);
578 $i = 0;
579 if ($num) {
580 while ($i < $num) {
581 $obj = $this->db->fetch_object($resql);
582 $label = '';
583 $labelhtml = '';
584 $tmparray = explode(',', $fieldstoshow);
585 $oldvalueforshowoncombobox = 0;
586 foreach ($tmparray as $key => $val) {
587 $val = preg_replace('/t\./', '', $val);
588 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
589 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
590 $label .= $obj->$val;
591 $labelhtml .= $obj->$val;
592
593 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val]['showoncombobox']) ? 0 : $objecttmp->fields[$val]['showoncombobox'];
594 }
595 if (empty($outputmode)) {
596 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
597 $out .= '<option value="' . $obj->rowid . '" selected data-html="' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>';
598 } else {
599 $out .= '<option value="' . $obj->rowid . '" data-html="' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>';
600 }
601 } else {
602 array_push($outarray, array('key' => $obj->rowid, 'value' => $label, 'label' => $label));
603 }
604
605 $i++;
606 if (($i % 10) == 0) {
607 $out .= "\n";
608 }
609 }
610 }
611
612 $out .= '</select>' . "\n";
613 } else {
614 dol_print_error($this->db);
615 }
616
617 $this->result = array('nbofelement' => $num);
618
619 if ($outputmode) {
620 return $outarray;
621 }
622
623 return $out;
624 }
625
639 public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
640 {
641 global $conf, $langs;
642
643 $out = '';
644 $param = array();
645 $reg = array();
646 $size = !empty($val['size']) ? $val['size'] : 0;
647 // see common object class
648 if (preg_match('/^(integer|link):(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
649 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] . ':' . $reg[5] => 'N');
650 $type = 'link';
651 } elseif (preg_match('/^(integer|link):(.*):(.*):(.*)/i', $val['type'], $reg)) {
652 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
653 $type = 'link';
654 } elseif (preg_match('/^(integer|link):(.*):(.*)/i', $val['type'], $reg)) {
655 $param['options'] = array($reg[2] . ':' . $reg[3] => 'N');
656 $type = 'link';
657 } elseif (preg_match('/^(sellist):(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
658 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] . ':' . $reg[5] => 'N');
659 $type = 'sellist';
660 } elseif (preg_match('/^(sellist):(.*):(.*):(.*)/i', $val['type'], $reg)) {
661 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
662 $type = 'sellist';
663 } elseif (preg_match('/^(sellist):(.*):(.*)/i', $val['type'], $reg)) {
664 $param['options'] = array($reg[2] . ':' . $reg[3] => 'N');
665 $type = 'sellist';
666 } elseif (preg_match('/^varchar\‍((\d+)\‍)/', $val['type'], $reg)) {
667 $param['options'] = array();
668 $type = 'text';
669 $size = $reg[1];
670 } elseif (preg_match('/^varchar/', $val['type'])) {
671 $param['options'] = array();
672 $type = 'text';
673 } elseif (preg_match('/^double(\‍([0-9],[0-9]\‍)){0,1}/', $val['type'])) {
674 $param['options'] = array();
675 $type = 'double';
676 } else {
677 $param['options'] = array();
678 $type = $val['type'];
679 }
680
681 // Special case that force options and type ($type can be integer, varchar, ...)
682 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
683 $param['options'] = $val['arrayofkeyval'];
684 $type = $val['type'] == 'checkbox' ? 'checkbox' : 'select';
685 }
686
687 //$label = $val['label'];
688 $default = (!empty($val['default']) ? $val['default'] : '');
689 $computed = (!empty($val['computed']) ? $val['computed'] : '');
690 //$unique = (!empty($val['unique']) ? $val['unique'] : 0);
691 $required = (!empty($val['required']) ? $val['required'] : 0);
692 $notNull = (!empty($val['notnull']) ? $val['notnull'] : 0);
693
694 //$langfile = (!empty($val['langfile']) ? $val['langfile'] : '');
695 //$list = (!empty($val['list']) ? $val[$key]['list'] : 0);
696 $hidden = (in_array(abs($val['visible']), array(0, 2)) ? 1 : 0);
697
698 //$objectid = $this->id;
699
700 if ($computed) {
701 if (!preg_match('/^search_/', $keyprefix)) {
702 return '<span>' . $langs->trans("AutomaticallyCalculated") . '</span>';
703 } else {
704 return '';
705 }
706 }
707
708 // Set value of $morecss. For this, we use in priority showsize from parameters, then $val['css'] then autodefine
709 if (empty($morecss) && !empty($val['css'])) {
710 $morecss = $val['css'];
711 }
712
713 $htmlName = $keyprefix . $key . $keysuffix;
714 $htmlId = $htmlName;
715 //$moreparam .= (!empty($required) ? ' required' : '');
716 switch ($type) {
717 case 'date':
718 case 'datetime':
719 // separate value YYYY-MM-DD HH:ii:ss to date and time
720 $valueDate = '';
721 $valueTime = '';
722 $dateArr = explode(' ', $value);
723 if (count($dateArr) > 0) {
724 $valueDate = $dateArr[0];
725 if (isset($dateArr[1])) {
726 $valueTime = $dateArr[1];
727 }
728 }
729 $out = $this->inputDate($htmlName, $valueDate, '', $htmlId, $morecss, $moreparam);
730
731 if ($type == 'datetime') {
732 //$moreparam .= ' step="1"'; to show seconds
733 $out .= ' ' . $this->inputType('time', $htmlName.'_time', $valueTime, $htmlId, $morecss, $moreparam);
734 }
735 break;
736
737 case 'integer':
738 $out = $this->inputType('number', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
739 break;
740
741 case 'text':
742 case 'html':
743 $moreparam .= ($size > 0 ? ' maxlength="' . $size . '"' : '');
744 $out = $this->inputType('text', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
745 break;
746
747 case 'email':
748 $out = $this->inputType('email', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
749 break;
750
751 case 'tel':
752 $out = $this->inputType('tel', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
753 break;
754
755 case 'url':
756 $out = $this->inputType('url', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
757 break;
758
759 case 'price':
760 if (!empty($value)) {
761 $value = price($value); // $value in memory is a php numeric, we format it into user number format.
762 }
763 $addInputLabel = ' ' . $langs->getCurrencySymbol($conf->currency);
764 $out = $this->inputType('text', $htmlName, $value, $htmlId, $morecss, $moreparam, '', $addInputLabel);
765 break;
766
767 case 'double':
768 if (!empty($value)) {
769 $value = price($value); // $value in memory is a php numeric, we format it into user number format.
770 }
771 $out = $this->inputType('text', $htmlName, $value, $htmlId, $morecss, $moreparam);
772 break;
773
774 case 'password':
775 $out = $this->inputType('password', $htmlName, $value, $htmlId, $morecss, $moreparam);
776 break;
777
778 case 'radio':
779 foreach ($param['options'] as $keyopt => $valopt) {
780 $htmlId = $htmlName . '_' . $keyopt;
781 $htmlMoreParam = $moreparam . ($value == $keyopt ? ' checked' : '');
782 $out .= $this->inputType('radio', $htmlName, $keyopt, $htmlId, $morecss, $htmlMoreParam, $valopt) . '<br>';
783 }
784 break;
785
786 case 'select':
787 $out = '<select class="' . $morecss . '" name="' . $htmlName . '" id="' . $htmlId . '"' . ($moreparam ? ' ' . $moreparam : '') . ' >';
788 if ($default == '' || $notNull != 1) {
789 $out .= '<option value="0">&nbsp;</option>';
790 }
791 foreach ($param['options'] as $keyb => $valb) {
792 if ($keyb == '') {
793 continue;
794 }
795 if (strpos($valb, "|") !== false) {
796 list($valb, $parent) = explode('|', $valb);
797 }
798 $out .= '<option value="' . $keyb . '"';
799 $out .= (((string) $value == $keyb) ? ' selected' : '');
800 $out .= (!empty($parent) ? ' parent="' . $parent . '"' : '');
801 $out .= '>' . $valb . '</option>';
802 }
803 $out .= '</select>';
804 break;
805 case 'sellist':
806 $out = '<select class="' . $morecss . '" name="' . $htmlName . '" id="' . $htmlId . '"' . ($moreparam ? ' ' . $moreparam : '') . '>';
807
808 $param_list = array_keys($param['options']);
809 $InfoFieldList = explode(":", $param_list[0]);
810 $parentName = '';
811 $parentField = '';
812 // 0 : tableName
813 // 1 : label field name
814 // 2 : key fields name (if differ of rowid)
815 // 3 : key field parent (for dependent lists)
816 // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
817 // 5 : id category type
818 // 6 : ids categories list separated by comma for category root
819 $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid');
820
821 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
822 if (strpos($InfoFieldList[4], 'extra.') !== false) {
823 $keyList = 'main.' . $InfoFieldList[2] . ' as rowid';
824 } else {
825 $keyList = $InfoFieldList[2] . ' as rowid';
826 }
827 }
828 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
829 list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
830 $keyList .= ', ' . $parentField;
831 }
832
833 $filter_categorie = false;
834 if (count($InfoFieldList) > 5) {
835 if ($InfoFieldList[0] == 'categorie') {
836 $filter_categorie = true;
837 }
838 }
839
840 if (!$filter_categorie) {
841 $fields_label = explode('|', $InfoFieldList[1]);
842 if (is_array($fields_label)) {
843 $keyList .= ', ';
844 $keyList .= implode(', ', $fields_label);
845 }
846
847 $sqlwhere = '';
848 $sql = "SELECT " . $keyList;
849 $sql .= " FROM " . $this->db->prefix() . $InfoFieldList[0];
850 if (!empty($InfoFieldList[4])) {
851 // can use SELECT request
852 if (strpos($InfoFieldList[4], '$SEL$') !== false) {
853 $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]);
854 }
855
856 // current object id can be use into filter
857 $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]);
858
859 //We have to join on extrafield table
860 if (strpos($InfoFieldList[4], 'extra') !== false) {
861 $sql .= " as main, " . $this->db->prefix() . $InfoFieldList[0] . "_extrafields as extra";
862 $sqlwhere .= " WHERE extra.fk_object=main." . $InfoFieldList[2] . " AND " . $InfoFieldList[4];
863 } else {
864 $sqlwhere .= " WHERE " . $InfoFieldList[4];
865 }
866 } else {
867 $sqlwhere .= ' WHERE 1=1';
868 }
869 // Some tables may have field, some other not. For the moment we disable it.
870 if (in_array($InfoFieldList[0], array('tablewithentity'))) {
871 $sqlwhere .= " AND entity = " . ((int) $conf->entity);
872 }
873 $sql .= $sqlwhere;
874 //print $sql;
875
876 $sql .= ' ORDER BY ' . implode(', ', $fields_label);
877
878 dol_syslog(get_class($this) . '::showInputField type=sellist', LOG_DEBUG);
879 $resql = $this->db->query($sql);
880 if ($resql) {
881 $out .= '<option value="0">&nbsp;</option>';
882 $num = $this->db->num_rows($resql);
883 $i = 0;
884 while ($i < $num) {
885 $labeltoshow = '';
886 $obj = $this->db->fetch_object($resql);
887
888 // Several field into label (eq table:code|libelle:rowid)
889 $notrans = false;
890 $fields_label = explode('|', $InfoFieldList[1]);
891 if (count($fields_label) > 1) {
892 $notrans = true;
893 foreach ($fields_label as $field_toshow) {
894 $labeltoshow .= $obj->$field_toshow . ' ';
895 }
896 } else {
897 $labeltoshow = $obj->{$InfoFieldList[1]};
898 }
899 $labeltoshow = dol_trunc($labeltoshow, 45);
900
901 if ($value == $obj->rowid) {
902 foreach ($fields_label as $field_toshow) {
903 $translabel = $langs->trans($obj->$field_toshow);
904 if ($translabel != $obj->$field_toshow) {
905 $labeltoshow = dol_trunc($translabel) . ' ';
906 } else {
907 $labeltoshow = dol_trunc($obj->$field_toshow) . ' ';
908 }
909 }
910 $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>';
911 } else {
912 if (!$notrans) {
913 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
914 if ($translabel != $obj->{$InfoFieldList[1]}) {
915 $labeltoshow = dol_trunc($translabel, 18);
916 } else {
917 $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]});
918 }
919 }
920 if (empty($labeltoshow)) {
921 $labeltoshow = '(not defined)';
922 }
923 if ($value == $obj->rowid) {
924 $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>';
925 }
926
927 if (!empty($InfoFieldList[3]) && $parentField) {
928 $parent = $parentName . ':' . $obj->{$parentField};
929 $isDependList = 1;
930 }
931
932 $out .= '<option value="' . $obj->rowid . '"';
933 $out .= ($value == $obj->rowid ? ' selected' : '');
934 $out .= (!empty($parent) ? ' parent="' . $parent . '"' : '');
935 $out .= '>' . $labeltoshow . '</option>';
936 }
937
938 $i++;
939 }
940 $this->db->free($resql);
941 } else {
942 $out .= 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>';
943 }
944 } else {
945 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
946 $categorytype = $InfoFieldList[5];
947 if (is_numeric($categorytype)) {
948 $categorytype = Categorie::$MAP_ID_TO_CODE[(int) $categorytype]; // For backward compatibility
949 }
950 $data = $this->select_all_categories($categorytype, '', 'parent', 64, $InfoFieldList[6], 1, 1);
951 $out .= '<option value="0">&nbsp;</option>';
952 foreach ($data as $data_key => $data_value) {
953 $out .= '<option value="' . $data_key . '"';
954 $out .= ($value == $data_key ? ' selected' : '');
955 $out .= '>' . $data_value . '</option>';
956 }
957 }
958 $out .= '</select>';
959 break;
960
961 case 'link':
962 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter[:Sortfield]]]'
963 $showempty = (($required && $default != '') ? '0' : '1');
964
965 $out = $this->selectForForms($param_list[0], $htmlName, $value, $showempty, '', '', $morecss, $moreparam, 0, empty($val['disabled']) ? 0 : 1);
966
967 break;
968
969 default:
970 if (!empty($hidden)) {
971 $out = $this->inputType('hidden', $htmlName, $value, $htmlId);
972 }
973 break;
974 }
975
976 return $out;
977 }
978
992 public function showOutputFieldForObject($object, $val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
993 {
994 global $conf, $langs;
995
996 $label = empty($val['label']) ? '' : $val['label'];
997 $type = empty($val['type']) ? '' : $val['type'];
998 $css = empty($val['css']) ? '' : $val['css'];
999 $picto = empty($val['picto']) ? '' : $val['picto'];
1000 $reg = array();
1001
1002 // Convert var to be able to share same code than showOutputField of extrafields
1003 if (preg_match('/varchar\‍((\d+)\‍)/', $type, $reg)) {
1004 $type = 'varchar'; // convert varchar(xx) int varchar
1005 $css = $reg[1];
1006 } elseif (preg_match('/varchar/', $type)) {
1007 $type = 'varchar'; // convert varchar(xx) int varchar
1008 }
1009 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
1010 $type = $val['type'] == 'checkbox' ? 'checkbox' : 'select';
1011 }
1012 if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
1013 $type = 'link';
1014 }
1015
1016 $default = empty($val['default']) ? '' : $val['default'];
1017 $computed = empty($val['computed']) ? '' : $val['computed'];
1018 $unique = empty($val['unique']) ? '' : $val['unique'];
1019 $required = empty($val['required']) ? '' : $val['required'];
1020 $param = array();
1021 $param['options'] = array();
1022
1023 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
1024 $param['options'] = $val['arrayofkeyval'];
1025 }
1026 if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
1027 $type = 'link';
1028 $stringforoptions = $reg[1] . ':' . $reg[2];
1029 if ($reg[1] == 'User') {
1030 $stringforoptions .= ':-1';
1031 }
1032 $param['options'] = array($stringforoptions => $stringforoptions);
1033 } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
1034 $param['options'] = array($reg[1] . ':' . $reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
1035 $type = 'sellist';
1036 } elseif (preg_match('/^sellist:(.*):(.*):(.*)/i', $val['type'], $reg)) {
1037 $param['options'] = array($reg[1] . ':' . $reg[2] . ':' . $reg[3] => 'N');
1038 $type = 'sellist';
1039 } elseif (preg_match('/^sellist:(.*):(.*)/i', $val['type'], $reg)) {
1040 $param['options'] = array($reg[1] . ':' . $reg[2] => 'N');
1041 $type = 'sellist';
1042 } elseif (preg_match('/^chkbxlst:(.*)/i', $val['type'], $reg)) {
1043 $param['options'] = array($reg[1] => 'N');
1044 $type = 'chkbxlst';
1045 }
1046
1047 $langfile = empty($val['langfile']) ? '' : $val['langfile'];
1048 $list = (empty($val['list']) ? '' : $val['list']);
1049 $help = (empty($val['help']) ? '' : $val['help']);
1050 $hidden = (($val['visible'] == 0) ? 1 : 0); // If zero, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
1051
1052 if ($hidden) {
1053 return '';
1054 }
1055
1056 // If field is a computed field, value must become result of compute
1057 if ($computed) {
1058 // Make the eval of compute string
1059 //var_dump($computed);
1060 $value = (string) dol_eval($computed, 1, 0, '2');
1061 }
1062
1063 // Format output value differently according to properties of field
1064 //
1065 // First the cases that do not use $value from the arguments:
1066 //
1067 if (in_array($key, array('rowid', 'ref'))) {
1068 if (property_exists($object, 'ref')) {
1069 $value = $object->ref;
1070 } elseif (property_exists($object, 'id')) {
1071 $value = $object->id;
1072 } else {
1073 $value = '';
1074 }
1075 } elseif ($key == 'status' && method_exists($object, 'getLibStatut')) {
1076 $value = $object->getLibStatut(3);
1077 //
1078 // Then the cases where $value is an array
1079 //
1080 } elseif (is_array($value)) {
1081 // Handle array early to get type identification solve for static
1082 // analysis
1083 if ($type == 'array') {
1084 $value = implode('<br>', $value);
1085 } else {
1086 dol_syslog(__METHOD__."Unexpected type=".$type." for array value=".((string) json_encode($value)), LOG_ERR);
1087 }
1088 //
1089 // Then the cases where $value is not an array (hence string)
1090 //
1091 } elseif ($type == 'date') {
1092 if (!empty($value)) {
1093 $value = dol_print_date($value, 'day'); // We suppose dates without time are always gmt (storage of course + output)
1094 } else {
1095 $value = '';
1096 }
1097 } elseif ($type == 'datetime' || $type == 'timestamp') {
1098 if (!empty($value)) {
1099 $value = dol_print_date($value, 'dayhour', 'tzuserrel');
1100 } else {
1101 $value = '';
1102 }
1103 } elseif ($type == 'duration') {
1104 include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
1105 if (!is_null($value) && $value !== '') {
1106 $value = convertSecondToTime((int) $value, 'allhourmin');
1107 } else {
1108 // Resulting type must be string
1109 $value = '';
1110 }
1111 } elseif ($type == 'double' || $type == 'real') {
1112 if (!is_null($value) && $value !== '') {
1113 $value = price($value);
1114 } else {
1115 // Resulting type must be string
1116 $value = '';
1117 }
1118 } elseif ($type == 'boolean') {
1119 $checked = '';
1120 if (!empty($value)) {
1121 $checked = ' checked ';
1122 }
1123 $value = '<input type="checkbox" ' . $checked . ' ' . ($moreparam ? $moreparam : '') . ' readonly disabled>';
1124 } elseif ($type == 'mail' || $type == 'email') {
1125 $value = dol_print_email($value, 0, 0, 0, 64, 1, 1);
1126 } elseif ($type == 'url') {
1127 $value = dol_print_url($value, '_blank', 32, 1);
1128 } elseif ($type == 'phone') {
1129 $value = dol_print_phone($value, '', 0, 0, '', '&nbsp;', 'phone');
1130 } elseif ($type == 'ip') {
1131 $value = dol_print_ip($value, 0);
1132 } elseif ($type == 'price') {
1133 if (!is_null($value) && $value !== '') {
1134 $value = price($value, 0, $langs, 0, 0, -1, $conf->currency);
1135 } else {
1136 // Resulting type must be string
1137 $value = '';
1138 }
1139 } elseif ($type == 'select') {
1140 $value = isset($param['options'][$value]) ? $param['options'][$value] : '';
1141 } elseif ($type == 'sellist') {
1142 $param_list = array_keys($param['options']);
1143 $InfoFieldList = explode(":", $param_list[0]);
1144
1145 $selectkey = "rowid";
1146 $keyList = 'rowid';
1147
1148 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1149 $selectkey = $InfoFieldList[2];
1150 $keyList = $InfoFieldList[2] . ' as rowid';
1151 }
1152
1153 $fields_label = explode('|', $InfoFieldList[1]);
1154 if (is_array($fields_label)) {
1155 $keyList .= ', ';
1156 $keyList .= implode(', ', $fields_label);
1157 }
1158
1159 $filter_categorie = false;
1160 if (count($InfoFieldList) > 5) {
1161 if ($InfoFieldList[0] == 'categorie') {
1162 $filter_categorie = true;
1163 }
1164 }
1165
1166 $sql = "SELECT " . $keyList;
1167 $sql .= ' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1168 if (strpos($InfoFieldList[4], 'extra') !== false) {
1169 $sql .= ' as main';
1170 }
1171 if ($selectkey == 'rowid' && empty($value)) {
1172 $sql .= " WHERE " . $selectkey . " = 0";
1173 } elseif ($selectkey == 'rowid') {
1174 $sql .= " WHERE " . $selectkey . " = " . ((int) $value);
1175 } else {
1176 $sql .= " WHERE " . $selectkey . " = '" . $this->db->escape($value) . "'";
1177 }
1178
1179 dol_syslog(__METHOD__ . ' type=sellist', LOG_DEBUG);
1180 $resql = $this->db->query($sql);
1181 if ($resql) {
1182 if (!$filter_categorie) {
1183 $value = ''; // value was used, so now we reset it to use it to build final output
1184 $numrows = $this->db->num_rows($resql);
1185 if ($numrows) {
1186 $obj = $this->db->fetch_object($resql);
1187
1188 // Several field into label (eq table:code|libelle:rowid)
1189 $fields_label = explode('|', $InfoFieldList[1]);
1190
1191 if (is_array($fields_label) && count($fields_label) > 1) {
1192 foreach ($fields_label as $field_toshow) {
1193 $translabel = '';
1194 if (!empty($obj->$field_toshow)) {
1195 $translabel = $langs->trans($obj->$field_toshow);
1196 }
1197 if ($translabel != $field_toshow) {
1198 $value .= dol_trunc($translabel, 18) . ' ';
1199 } else {
1200 $value .= $obj->$field_toshow . ' ';
1201 }
1202 }
1203 } else {
1204 $translabel = '';
1205 if (!empty($obj->{$InfoFieldList[1]})) {
1206 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1207 }
1208 if ($translabel != $obj->{$InfoFieldList[1]}) {
1209 $value = dol_trunc($translabel, 18);
1210 } else {
1211 $value = $obj->{$InfoFieldList[1]};
1212 }
1213 }
1214 }
1215 } else {
1216 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1217
1218 $toprint = array();
1219 $obj = $this->db->fetch_object($resql);
1220 $c = new Categorie($this->db);
1221 $c->fetch($obj->rowid);
1222 $ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
1223 foreach ($ways as $way) {
1224 $toprint[] = '<li>' . img_object('', 'category') . ' ' . $way . '</li>';
1225 }
1226 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1227 }
1228 } else {
1229 dol_syslog(__METHOD__ . ' error ' . $this->db->lasterror(), LOG_WARNING);
1230 }
1231 } elseif ($type == 'radio') {
1232 $value = (string) $param['options'][$value];
1233 } elseif ($type == 'checkbox') {
1234 $value_arr = explode(',', $value);
1235 $value = '';
1236 if (is_array($value_arr) && count($value_arr) > 0) {
1237 $toprint = array();
1238 foreach ($value_arr as $valueval) {
1239 if (!empty($valueval)) {
1240 $toprint[] = '<li>' . $param['options'][$valueval] . '</li>';
1241 }
1242 }
1243 if (!empty($toprint)) {
1244 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1245 }
1246 }
1247 } elseif ($type == 'chkbxlst') {
1248 $value_arr = explode(',', $value);
1249
1250 $param_list = array_keys($param['options']);
1251 $InfoFieldList = explode(":", $param_list[0]);
1252
1253 $selectkey = "rowid";
1254 $keyList = 'rowid';
1255
1256 if (count($InfoFieldList) >= 3) {
1257 $selectkey = $InfoFieldList[2];
1258 $keyList = $InfoFieldList[2] . ' as rowid';
1259 }
1260
1261 $fields_label = explode('|', $InfoFieldList[1]);
1262 if (is_array($fields_label)) {
1263 $keyList .= ', ';
1264 $keyList .= implode(', ', $fields_label);
1265 }
1266
1267 $filter_categorie = false;
1268 if (count($InfoFieldList) > 5) {
1269 if ($InfoFieldList[0] == 'categorie') {
1270 $filter_categorie = true;
1271 }
1272 }
1273
1274 $sql = "SELECT " . $keyList;
1275 $sql .= ' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1276 if (strpos($InfoFieldList[4], 'extra') !== false) {
1277 $sql .= ' as main';
1278 }
1279 // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'";
1280 // $sql.= ' AND entity = '.$conf->entity;
1281
1282 dol_syslog(__METHOD__ . ' type=chkbxlst', LOG_DEBUG);
1283 $resql = $this->db->query($sql);
1284 if ($resql) {
1285 if (!$filter_categorie) {
1286 $value = ''; // value was used, so now we reset it to use it to build final output
1287 $toprint = array();
1288 while ($obj = $this->db->fetch_object($resql)) {
1289 // Several field into label (eq table:code|libelle:rowid)
1290 $fields_label = explode('|', $InfoFieldList[1]);
1291 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1292 if (is_array($fields_label) && count($fields_label) > 1) {
1293 foreach ($fields_label as $field_toshow) {
1294 $translabel = '';
1295 if (!empty($obj->$field_toshow)) {
1296 $translabel = $langs->trans($obj->$field_toshow);
1297 }
1298 if ($translabel != $field_toshow) {
1299 $toprint[] = '<li>' . dol_trunc($translabel, 18) . '</li>';
1300 } else {
1301 $toprint[] = '<li>' . $obj->$field_toshow . '</li>';
1302 }
1303 }
1304 } else {
1305 $translabel = '';
1306 if (!empty($obj->{$InfoFieldList[1]})) {
1307 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1308 }
1309 if ($translabel != $obj->{$InfoFieldList[1]}) {
1310 $toprint[] = '<li>' . dol_trunc($translabel, 18) . '</li>';
1311 } else {
1312 $toprint[] = '<li>' . $obj->{$InfoFieldList[1]} . '</li>';
1313 }
1314 }
1315 }
1316 }
1317 } else {
1318 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1319
1320 $toprint = array();
1321 while ($obj = $this->db->fetch_object($resql)) {
1322 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1323 $c = new Categorie($this->db);
1324 $c->fetch($obj->rowid);
1325 $ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
1326 foreach ($ways as $way) {
1327 $toprint[] = '<li>' . img_object('', 'category') . ' ' . $way . '</li>';
1328 }
1329 }
1330 }
1331 }
1332 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1333 } else {
1334 dol_syslog(__METHOD__ . ' error ' . $this->db->lasterror(), LOG_WARNING);
1335 }
1336 } elseif ($type == 'link') {
1337 // only if something to display (perf)
1338 if ($value) {
1339 $param_list = array_keys($param['options']); // Example: $param_list='ObjectName:classPath:-1::customer'
1340
1341 $InfoFieldList = explode(":", $param_list[0]);
1342 $classname = $InfoFieldList[0];
1343 $classpath = $InfoFieldList[1];
1344 if (!empty($classpath)) {
1345 dol_include_once($InfoFieldList[1]);
1346 if ($classname && class_exists($classname)) {
1347 $object = new $classname($this->db);
1348 '@phan-var-force CommonObject $object';
1349 $result = $object->fetch($value);
1350 $value = '';
1351 if ($result > 0) {
1352 if (property_exists($object, 'label')) {
1353 $value = $object->label; // @phan-suppress-current-line PhanUndeclaredProperty
1354 } elseif (property_exists($object, 'libelle')) {
1355 $value = $object->libelle; // @phan-suppress-current-line PhanUndeclaredProperty
1356 } elseif (property_exists($object, 'nom')) {
1357 $value = $object->nom; // @phan-suppress-current-line PhanUndeclaredProperty
1358 }
1359 }
1360 }
1361 } else {
1362 dol_syslog(__METHOD__ . ' Error bad setup of field', LOG_WARNING);
1363 return 'Error bad setup of field';
1364 }
1365 } else {
1366 $value = '';
1367 }
1368 } elseif ($type == 'password') {
1369 $value = preg_replace('/./i', '*', $value);
1370 } else { // text|html|varchar
1371 $value = dol_htmlentitiesbr($value);
1372 }
1373
1374 $out = $value;
1375
1376 return $out;
1377 }
1378}
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage categories.
static getInstance()
Singleton method to create one instance of this object.
Class to manage generation of HTML components Only common components must be here.
selectDate($set_time='', $prefix='re', $h=0, $m=0, $empty=0, $form_name="", $d=1, $addnowlink=0, $disabled=0, $fullday='', $addplusone='', $adddateof='', $openinghours='', $stepminutes=1, $labeladddateof='', $placeholder='', $gm='auto')
Show a HTML widget to input a date or combo list for day, month, years and optionally hours and minut...
Class to manage generation of HTML components Only common components for WebPortal must be here.
inputType($type, $name, $value='', $id='', $morecss='', $moreparam='', $label='', $addInputLabel='')
Html for input with label.
showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss='')
Return HTML string to put an input field into a page Code very similar with showInputField for common...
inputDate($name, $value='', $placeholder='', $id='', $morecss='', $moreparam='')
Input for date.
showOutputFieldForObject($object, $val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss='')
Return HTML string to show a field into a page.
getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='', $morecss='', $allfiles=0)
Show a Document icon with link(s) You may want to call this into a div like this: print '.
selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty='', $searchkey='', $placeholder='', $morecss='', $moreparams='', $forcecombo=0, $outputmode=0, $disabled=0, $sortfield='', $filter='')
Output html form to select an object.
selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty='', $searchkey='', $placeholder='', $morecss='', $moreparams='', $forcecombo=0, $disabled=0, $selected_input_value='', $objectfield='')
Generic method to select a component from a combo list.
getSignatureLink($modulepart, $object, $morecss='')
Show a Signature icon with link You may want to call this into a div like this: print '.
__construct($db)
Constructor.
static selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='minwidth75', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition date.lib.php:242
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_ip($ip, $mode=0)
Return an IP formatted to be shown on screen.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
$context
@method int call_trigger(string $triggerName, User $user)
Definition logout.php:42