dolibarr 21.0.4
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 if (!empty($classpath)) {
417 dol_include_once($classpath);
418
419 if ($classname && class_exists($classname)) {
420 $objecttmp = new $classname($this->db);
421
422 // Make some replacement
423 $sharedentities = getEntity(strtolower($classname));
424 $filter = str_replace(
425 array('__ENTITY__', '__SHARED_ENTITIES__'),
426 array($conf->entity, $sharedentities),
427 $filter
428 );
429 }
430 }
431 if (!is_object($objecttmp)) {
432 dol_syslog('Error bad setup of type for field ' . implode(',', $InfoFieldList), LOG_WARNING);
433 return 'Error bad setup of type for field ' . implode(',', $InfoFieldList);
434 }
435
436 dol_syslog(__METHOD__ . ' filter=' . $filter, LOG_DEBUG);
437 $out = '';
438 // Immediate load of table record.
439 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
440
441 return $out;
442 }
443
464 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield = '', $filter = '')
465 {
466 global $conf, $langs, $hookmanager;
467
468 $prefixforautocompletemode = $objecttmp->element;
469 if ($prefixforautocompletemode == 'societe') {
470 $prefixforautocompletemode = 'company';
471 }
472 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
473
474 if (in_array($objecttmp->element, array('adherent_type'))) {
475 $fieldstoshow = 't.libelle';
476 }
477 if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
478 $tmpfieldstoshow = '';
479 foreach ($objecttmp->fields as $key => $val) {
480 if (! (int) dol_eval($val['enabled'], 1, 1, '1')) {
481 continue;
482 }
483 if (!empty($val['showoncombobox'])) {
484 $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key;
485 }
486 }
487 if ($tmpfieldstoshow) {
488 $fieldstoshow = $tmpfieldstoshow;
489 }
490 } elseif (!in_array($objecttmp->element, array('adherent_type'))) {
491 // For backward compatibility
492 $objecttmp->fields['ref'] = array('type' => 'varchar(30)', 'label' => 'Ref', 'showoncombobox' => 1);
493 }
494
495 if (empty($fieldstoshow)) {
496 if (isset($objecttmp->fields['ref'])) {
497 $fieldstoshow = 't.ref';
498 } else {
499 $langs->load("errors");
500 $this->error = $langs->trans("ErrorNoFieldWithAttributeShowoncombobox");
501 return $langs->trans('ErrorNoFieldWithAttributeShowoncombobox');
502 }
503 }
504
505 $out = '';
506 $outarray = array();
507 $tmparray = array();
508
509 $num = 0;
510
511 // Search data
512 $sql = "SELECT t.rowid, " . $fieldstoshow . " FROM " . $this->db->prefix() . $objecttmp->table_element . " as t";
513 if (isset($objecttmp->ismultientitymanaged)) {
514 if (!is_numeric($objecttmp->ismultientitymanaged)) {
515 $tmparray = explode('@', $objecttmp->ismultientitymanaged);
516 $sql .= " INNER JOIN " . $this->db->prefix() . $tmparray[1] . " as parenttable ON parenttable.rowid = t." . $tmparray[0];
517 }
518 }
519
520 if (!empty($objecttmp->isextrafieldmanaged)) {
521 $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) . "_extrafields as e ON t.rowid = e.fk_object";
522 }
523
524 // Add where from hooks
525 $parameters = array(
526 'object' => $objecttmp,
527 'htmlname' => $htmlname,
528 'filter' => $filter,
529 'searchkey' => $searchkey
530 );
531
532 $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook
533 if (!empty($hookmanager->resPrint)) {
534 $sql .= $hookmanager->resPrint;
535 } else {
536 $sql .= " WHERE 1=1";
537 if (isset($objecttmp->ismultientitymanaged)) {
538 if ($objecttmp->ismultientitymanaged == 1) {
539 $sql .= " AND t.entity IN (" . getEntity($objecttmp->table_element) . ")";
540 }
541 if (!is_numeric($objecttmp->ismultientitymanaged)) {
542 $sql .= " AND parenttable.entity = t." . $tmparray[0];
543 }
544 }
545 if ($searchkey != '') {
546 $sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
547 }
548
549 if ($filter) { // Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
550 $errormessage = '';
551 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
552 if ($errormessage) {
553 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
554 }
555 }
556 }
557 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, "ASC");
558
559 // Build output string
560 $resql = $this->db->query($sql);
561 if ($resql) {
562 // Construct $out and $outarray
563 $out .= '<select id="' . $htmlname . '" class="' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ($moreparams ? ' ' . $moreparams : '') . ' name="' . $htmlname . '">' . "\n";
564
565 // 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
566 $textifempty = '&nbsp;';
567
568 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
569 if (getDolGlobalString($confkeyforautocompletemode)) {
570 if ($showempty && !is_numeric($showempty)) {
571 $textifempty = $langs->trans($showempty);
572 } else {
573 $textifempty .= $langs->trans("All");
574 }
575 }
576 if ($showempty) {
577 $out .= '<option value="-1">' . $textifempty . '</option>' . "\n";
578 }
579
580 $num = $this->db->num_rows($resql);
581 $i = 0;
582 if ($num) {
583 while ($i < $num) {
584 $obj = $this->db->fetch_object($resql);
585 $label = '';
586 $labelhtml = '';
587 $tmparray = explode(',', $fieldstoshow);
588 $oldvalueforshowoncombobox = 0;
589 foreach ($tmparray as $key => $val) {
590 $val = preg_replace('/t\./', '', $val);
591 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
592 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
593 $label .= $obj->$val;
594 $labelhtml .= $obj->$val;
595
596 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val]['showoncombobox']) ? 0 : $objecttmp->fields[$val]['showoncombobox'];
597 }
598 if (empty($outputmode)) {
599 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
600 $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>';
601 } else {
602 $out .= '<option value="' . $obj->rowid . '" data-html="' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>';
603 }
604 } else {
605 array_push($outarray, array('key' => $obj->rowid, 'value' => $label, 'label' => $label));
606 }
607
608 $i++;
609 if (($i % 10) == 0) {
610 $out .= "\n";
611 }
612 }
613 }
614
615 $out .= '</select>' . "\n";
616 } else {
617 dol_print_error($this->db);
618 }
619
620 $this->result = array('nbofelement' => $num);
621
622 if ($outputmode) {
623 return $outarray;
624 }
625
626 return $out;
627 }
628
642 public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
643 {
644 global $conf, $langs;
645
646 $out = '';
647 $param = array();
648 $reg = array();
649 $size = !empty($val['size']) ? $val['size'] : 0;
650 // see common object class
651 if (preg_match('/^(integer|link):(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
652 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] . ':' . $reg[5] => 'N');
653 $type = 'link';
654 } elseif (preg_match('/^(integer|link):(.*):(.*):(.*)/i', $val['type'], $reg)) {
655 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
656 $type = 'link';
657 } elseif (preg_match('/^(integer|link):(.*):(.*)/i', $val['type'], $reg)) {
658 $param['options'] = array($reg[2] . ':' . $reg[3] => 'N');
659 $type = 'link';
660 } elseif (preg_match('/^(sellist):(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
661 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] . ':' . $reg[5] => 'N');
662 $type = 'sellist';
663 } elseif (preg_match('/^(sellist):(.*):(.*):(.*)/i', $val['type'], $reg)) {
664 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
665 $type = 'sellist';
666 } elseif (preg_match('/^(sellist):(.*):(.*)/i', $val['type'], $reg)) {
667 $param['options'] = array($reg[2] . ':' . $reg[3] => 'N');
668 $type = 'sellist';
669 } elseif (preg_match('/^varchar\‍((\d+)\‍)/', $val['type'], $reg)) {
670 $param['options'] = array();
671 $type = 'text';
672 $size = $reg[1];
673 } elseif (preg_match('/^varchar/', $val['type'])) {
674 $param['options'] = array();
675 $type = 'text';
676 } elseif (preg_match('/^double(\‍([0-9],[0-9]\‍)){0,1}/', $val['type'])) {
677 $param['options'] = array();
678 $type = 'double';
679 } else {
680 $param['options'] = array();
681 $type = $val['type'];
682 }
683
684 // Special case that force options and type ($type can be integer, varchar, ...)
685 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
686 $param['options'] = $val['arrayofkeyval'];
687 $type = $val['type'] == 'checkbox' ? 'checkbox' : 'select';
688 }
689
690 //$label = $val['label'];
691 $default = (!empty($val['default']) ? $val['default'] : '');
692 $computed = (!empty($val['computed']) ? $val['computed'] : '');
693 //$unique = (!empty($val['unique']) ? $val['unique'] : 0);
694 $required = (!empty($val['required']) ? $val['required'] : 0);
695 $notNull = (!empty($val['notnull']) ? $val['notnull'] : 0);
696
697 //$langfile = (!empty($val['langfile']) ? $val['langfile'] : '');
698 //$list = (!empty($val['list']) ? $val[$key]['list'] : 0);
699 $hidden = (in_array(abs($val['visible']), array(0, 2)) ? 1 : 0);
700
701 //$objectid = $this->id;
702
703 if ($computed) {
704 if (!preg_match('/^search_/', $keyprefix)) {
705 return '<span>' . $langs->trans("AutomaticallyCalculated") . '</span>';
706 } else {
707 return '';
708 }
709 }
710
711 // Set value of $morecss. For this, we use in priority showsize from parameters, then $val['css'] then autodefine
712 if (empty($morecss) && !empty($val['css'])) {
713 $morecss = $val['css'];
714 }
715
716 $htmlName = $keyprefix . $key . $keysuffix;
717 $htmlId = $htmlName;
718 //$moreparam .= (!empty($required) ? ' required' : '');
719 switch ($type) {
720 case 'date':
721 case 'datetime':
722 // separate value YYYY-MM-DD HH:ii:ss to date and time
723 $valueDate = '';
724 $valueTime = '';
725 $dateArr = explode(' ', $value);
726 if (count($dateArr) > 0) {
727 $valueDate = $dateArr[0];
728 if (isset($dateArr[1])) {
729 $valueTime = $dateArr[1];
730 }
731 }
732 $out = $this->inputDate($htmlName, $valueDate, '', $htmlId, $morecss, $moreparam);
733
734 if ($type == 'datetime') {
735 //$moreparam .= ' step="1"'; to show seconds
736 $out .= ' ' . $this->inputType('time', $htmlName.'_time', $valueTime, $htmlId, $morecss, $moreparam);
737 }
738 break;
739
740 case 'integer':
741 $out = $this->inputType('number', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
742 break;
743
744 case 'text':
745 case 'html':
746 $moreparam .= ($size > 0 ? ' maxlength="' . $size . '"' : '');
747 $out = $this->inputType('text', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
748 break;
749
750 case 'email':
751 $out = $this->inputType('email', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
752 break;
753
754 case 'tel':
755 $out = $this->inputType('tel', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
756 break;
757
758 case 'url':
759 $out = $this->inputType('url', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
760 break;
761
762 case 'price':
763 if (!empty($value)) {
764 $value = price($value); // $value in memory is a php numeric, we format it into user number format.
765 }
766 $addInputLabel = ' ' . $langs->getCurrencySymbol($conf->currency);
767 $out = $this->inputType('text', $htmlName, $value, $htmlId, $morecss, $moreparam, '', $addInputLabel);
768 break;
769
770 case 'double':
771 if (!empty($value)) {
772 $value = price($value); // $value in memory is a php numeric, we format it into user number format.
773 }
774 $out = $this->inputType('text', $htmlName, $value, $htmlId, $morecss, $moreparam);
775 break;
776
777 case 'password':
778 $out = $this->inputType('password', $htmlName, $value, $htmlId, $morecss, $moreparam);
779 break;
780
781 case 'radio':
782 foreach ($param['options'] as $keyopt => $valopt) {
783 $htmlId = $htmlName . '_' . $keyopt;
784 $htmlMoreParam = $moreparam . ($value == $keyopt ? ' checked' : '');
785 $out .= $this->inputType('radio', $htmlName, $keyopt, $htmlId, $morecss, $htmlMoreParam, $valopt) . '<br>';
786 }
787 break;
788
789 case 'select':
790 $out = '<select class="' . $morecss . '" name="' . $htmlName . '" id="' . $htmlId . '"' . ($moreparam ? ' ' . $moreparam : '') . ' >';
791 if ($default == '' || $notNull != 1) {
792 $out .= '<option value="0">&nbsp;</option>';
793 }
794 foreach ($param['options'] as $keyb => $valb) {
795 if ($keyb == '') {
796 continue;
797 }
798 if (strpos($valb, "|") !== false) {
799 list($valb, $parent) = explode('|', $valb);
800 }
801 $out .= '<option value="' . $keyb . '"';
802 $out .= (((string) $value == $keyb) ? ' selected' : '');
803 $out .= (!empty($parent) ? ' parent="' . $parent . '"' : '');
804 $out .= '>' . $valb . '</option>';
805 }
806 $out .= '</select>';
807 break;
808 case 'sellist':
809 $out = '<select class="' . $morecss . '" name="' . $htmlName . '" id="' . $htmlId . '"' . ($moreparam ? ' ' . $moreparam : '') . '>';
810
811 $param_list = array_keys($param['options']);
812 $InfoFieldList = explode(":", $param_list[0]);
813 $parentName = '';
814 $parentField = '';
815 // 0 : tableName
816 // 1 : label field name
817 // 2 : key fields name (if differ of rowid)
818 // 3 : key field parent (for dependent lists)
819 // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
820 // 5 : id category type
821 // 6 : ids categories list separated by comma for category root
822 $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid');
823
824 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
825 if (strpos($InfoFieldList[4], 'extra.') !== false) {
826 $keyList = 'main.' . $InfoFieldList[2] . ' as rowid';
827 } else {
828 $keyList = $InfoFieldList[2] . ' as rowid';
829 }
830 }
831 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
832 list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
833 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4], 'extra.') !== false) {
834 $keyList .= ', main.'.$parentField;
835 } else {
836 $keyList .= ', '.$parentField;
837 }
838 }
839
840 $filter_categorie = false;
841 if (count($InfoFieldList) > 5) {
842 if ($InfoFieldList[0] == 'categorie') {
843 $filter_categorie = true;
844 }
845 }
846
847 if (!$filter_categorie) {
848 $fields_label = explode('|', $InfoFieldList[1]);
849 if (is_array($fields_label)) {
850 $keyList .= ', ';
851 $keyList .= implode(', ', $fields_label);
852 }
853
854 $sqlwhere = '';
855 $sql = "SELECT " . $keyList;
856 $sql .= " FROM " . $this->db->prefix() . $InfoFieldList[0];
857 if (!empty($InfoFieldList[4])) {
858 // can use SELECT request
859 if (strpos($InfoFieldList[4], '$SEL$') !== false) {
860 $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]);
861 }
862
863 // current object id can be use into filter
864 $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]);
865
866 //We have to join on extrafield table
867 if (strpos($InfoFieldList[4], 'extra') !== false) {
868 $sql .= " as main, " . $this->db->prefix() . $InfoFieldList[0] . "_extrafields as extra";
869 $sqlwhere .= " WHERE extra.fk_object=main." . $InfoFieldList[2] . " AND " . $InfoFieldList[4];
870 } else {
871 $sqlwhere .= " WHERE " . $InfoFieldList[4];
872 }
873 } else {
874 $sqlwhere .= ' WHERE 1=1';
875 }
876 // Some tables may have field, some other not. For the moment we disable it.
877 if (in_array($InfoFieldList[0], array('tablewithentity'))) {
878 $sqlwhere .= " AND entity = " . ((int) $conf->entity);
879 }
880 $sql .= $sqlwhere;
881 //print $sql;
882
883 $sql .= ' ORDER BY ' . implode(', ', $fields_label);
884
885 dol_syslog(get_class($this) . '::showInputField type=sellist', LOG_DEBUG);
886 $resql = $this->db->query($sql);
887 if ($resql) {
888 $out .= '<option value="0">&nbsp;</option>';
889 $num = $this->db->num_rows($resql);
890 $i = 0;
891 while ($i < $num) {
892 $labeltoshow = '';
893 $obj = $this->db->fetch_object($resql);
894
895 // Several field into label (eq table:code|libelle:rowid)
896 $notrans = false;
897 $fields_label = explode('|', $InfoFieldList[1]);
898 if (count($fields_label) > 1) {
899 $notrans = true;
900 foreach ($fields_label as $field_toshow) {
901 $labeltoshow .= $obj->$field_toshow . ' ';
902 }
903 } else {
904 $labeltoshow = $obj->{$InfoFieldList[1]};
905 }
906 $labeltoshow = dol_trunc($labeltoshow, 45);
907
908 if ($value == $obj->rowid) {
909 foreach ($fields_label as $field_toshow) {
910 $translabel = $langs->trans($obj->$field_toshow);
911 if ($translabel != $obj->$field_toshow) {
912 $labeltoshow = dol_trunc($translabel) . ' ';
913 } else {
914 $labeltoshow = dol_trunc($obj->$field_toshow) . ' ';
915 }
916 }
917 $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>';
918 } else {
919 if (!$notrans) {
920 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
921 if ($translabel != $obj->{$InfoFieldList[1]}) {
922 $labeltoshow = dol_trunc($translabel, 18);
923 } else {
924 $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]});
925 }
926 }
927 if (empty($labeltoshow)) {
928 $labeltoshow = '(not defined)';
929 }
930 if ($value == $obj->rowid) {
931 $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>';
932 }
933
934 if (!empty($InfoFieldList[3]) && $parentField) {
935 $parent = $parentName . ':' . $obj->{$parentField};
936 $isDependList = 1;
937 }
938
939 $out .= '<option value="' . $obj->rowid . '"';
940 $out .= ($value == $obj->rowid ? ' selected' : '');
941 $out .= (!empty($parent) ? ' parent="' . $parent . '"' : '');
942 $out .= '>' . $labeltoshow . '</option>';
943 }
944
945 $i++;
946 }
947 $this->db->free($resql);
948 } else {
949 $out .= 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>';
950 }
951 } else {
952 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
953 $categorytype = $InfoFieldList[5];
954 if (is_numeric($categorytype)) {
955 $categorytype = Categorie::$MAP_ID_TO_CODE[(int) $categorytype]; // For backward compatibility
956 }
957 $data = $this->select_all_categories($categorytype, '', 'parent', 64, $InfoFieldList[6], 1, 1);
958 $out .= '<option value="0">&nbsp;</option>';
959 foreach ($data as $data_key => $data_value) {
960 $out .= '<option value="' . $data_key . '"';
961 $out .= ($value == $data_key ? ' selected' : '');
962 $out .= '>' . $data_value . '</option>';
963 }
964 }
965 $out .= '</select>';
966 break;
967
968 case 'link':
969 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter[:Sortfield]]]'
970 $showempty = (($required && $default != '') ? '0' : '1');
971
972 $out = $this->selectForForms($param_list[0], $htmlName, $value, $showempty, '', '', $morecss, $moreparam, 0, empty($val['disabled']) ? 0 : 1);
973
974 break;
975
976 default:
977 if (!empty($hidden)) {
978 $out = $this->inputType('hidden', $htmlName, $value, $htmlId);
979 }
980 break;
981 }
982
983 return $out;
984 }
985
999 public function showOutputFieldForObject($object, $val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
1000 {
1001 global $conf, $langs;
1002
1003 $label = empty($val['label']) ? '' : $val['label'];
1004 $type = empty($val['type']) ? '' : $val['type'];
1005 $css = empty($val['css']) ? '' : $val['css'];
1006 $picto = empty($val['picto']) ? '' : $val['picto'];
1007 $reg = array();
1008
1009 // Convert var to be able to share same code than showOutputField of extrafields
1010 if (preg_match('/varchar\‍((\d+)\‍)/', $type, $reg)) {
1011 $type = 'varchar'; // convert varchar(xx) int varchar
1012 $css = $reg[1];
1013 } elseif (preg_match('/varchar/', $type)) {
1014 $type = 'varchar'; // convert varchar(xx) int varchar
1015 }
1016 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
1017 $type = $val['type'] == 'checkbox' ? 'checkbox' : 'select';
1018 }
1019 if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
1020 $type = 'link';
1021 }
1022
1023 $default = empty($val['default']) ? '' : $val['default'];
1024 $computed = empty($val['computed']) ? '' : $val['computed'];
1025 $unique = empty($val['unique']) ? '' : $val['unique'];
1026 $required = empty($val['required']) ? '' : $val['required'];
1027 $param = array();
1028 $param['options'] = array();
1029
1030 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
1031 $param['options'] = $val['arrayofkeyval'];
1032 }
1033 if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
1034 $type = 'link';
1035 $stringforoptions = $reg[1] . ':' . $reg[2];
1036 if ($reg[1] == 'User') {
1037 $stringforoptions .= ':-1';
1038 }
1039 $param['options'] = array($stringforoptions => $stringforoptions);
1040 } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
1041 $param['options'] = array($reg[1] . ':' . $reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
1042 $type = 'sellist';
1043 } elseif (preg_match('/^sellist:(.*):(.*):(.*)/i', $val['type'], $reg)) {
1044 $param['options'] = array($reg[1] . ':' . $reg[2] . ':' . $reg[3] => 'N');
1045 $type = 'sellist';
1046 } elseif (preg_match('/^sellist:(.*):(.*)/i', $val['type'], $reg)) {
1047 $param['options'] = array($reg[1] . ':' . $reg[2] => 'N');
1048 $type = 'sellist';
1049 } elseif (preg_match('/^chkbxlst:(.*)/i', $val['type'], $reg)) {
1050 $param['options'] = array($reg[1] => 'N');
1051 $type = 'chkbxlst';
1052 }
1053
1054 $langfile = empty($val['langfile']) ? '' : $val['langfile'];
1055 $list = (empty($val['list']) ? '' : $val['list']);
1056 $help = (empty($val['help']) ? '' : $val['help']);
1057 $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)
1058
1059 if ($hidden) {
1060 return '';
1061 }
1062
1063 // If field is a computed field, value must become result of compute
1064 if ($computed) {
1065 // Make the eval of compute string
1066 //var_dump($computed);
1067 $value = (string) dol_eval($computed, 1, 0, '2');
1068 }
1069
1070 // Format output value differently according to properties of field
1071 //
1072 // First the cases that do not use $value from the arguments:
1073 //
1074 if (in_array($key, array('rowid', 'ref'))) {
1075 if (property_exists($object, 'ref')) {
1076 $value = $object->ref;
1077 } elseif (property_exists($object, 'id')) {
1078 $value = $object->id;
1079 } else {
1080 $value = '';
1081 }
1082 } elseif ($key == 'status' && method_exists($object, 'getLibStatut')) {
1083 $value = $object->getLibStatut(3);
1084 //
1085 // Then the cases where $value is an array
1086 //
1087 } elseif (is_array($value)) {
1088 // Handle array early to get type identification solve for static
1089 // analysis
1090 if ($type == 'array') {
1091 $value = implode('<br>', $value);
1092 } else {
1093 dol_syslog(__METHOD__."Unexpected type=".$type." for array value=".((string) json_encode($value)), LOG_ERR);
1094 }
1095 //
1096 // Then the cases where $value is not an array (hence string)
1097 //
1098 } elseif ($type == 'date') {
1099 if (!empty($value)) {
1100 $value = dol_print_date($value, 'day'); // We suppose dates without time are always gmt (storage of course + output)
1101 } else {
1102 $value = '';
1103 }
1104 } elseif ($type == 'datetime' || $type == 'timestamp') {
1105 if (!empty($value)) {
1106 $value = dol_print_date($value, 'dayhour', 'tzuserrel');
1107 } else {
1108 $value = '';
1109 }
1110 } elseif ($type == 'duration') {
1111 include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
1112 if (!is_null($value) && $value !== '') {
1113 $value = convertSecondToTime((int) $value, 'allhourmin');
1114 } else {
1115 // Resulting type must be string
1116 $value = '';
1117 }
1118 } elseif ($type == 'double' || $type == 'real') {
1119 if (!is_null($value) && $value !== '') {
1120 $value = price($value);
1121 } else {
1122 // Resulting type must be string
1123 $value = '';
1124 }
1125 } elseif ($type == 'boolean') {
1126 $checked = '';
1127 if (!empty($value)) {
1128 $checked = ' checked ';
1129 }
1130 $value = '<input type="checkbox" ' . $checked . ' ' . ($moreparam ? $moreparam : '') . ' readonly disabled>';
1131 } elseif ($type == 'mail' || $type == 'email') {
1132 $value = dol_print_email($value, 0, 0, 0, 64, 1, 1);
1133 } elseif ($type == 'url') {
1134 $value = dol_print_url($value, '_blank', 32, 1);
1135 } elseif ($type == 'phone') {
1136 $value = dol_print_phone($value, '', 0, 0, '', '&nbsp;', 'phone');
1137 } elseif ($type == 'ip') {
1138 $value = dol_print_ip($value, 0);
1139 } elseif ($type == 'price') {
1140 if (!is_null($value) && $value !== '') {
1141 $value = price($value, 0, $langs, 0, 0, -1, $conf->currency);
1142 } else {
1143 // Resulting type must be string
1144 $value = '';
1145 }
1146 } elseif ($type == 'select') {
1147 $value = isset($param['options'][$value]) ? $param['options'][$value] : '';
1148 } elseif ($type == 'sellist') {
1149 $param_list = array_keys($param['options']);
1150 $InfoFieldList = explode(":", $param_list[0]);
1151
1152 $selectkey = "rowid";
1153 $keyList = 'rowid';
1154
1155 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
1156 $selectkey = $InfoFieldList[2];
1157 $keyList = $InfoFieldList[2] . ' as rowid';
1158 }
1159
1160 $fields_label = explode('|', $InfoFieldList[1]);
1161 if (is_array($fields_label)) {
1162 $keyList .= ', ';
1163 $keyList .= implode(', ', $fields_label);
1164 }
1165
1166 $filter_categorie = false;
1167 if (count($InfoFieldList) > 5) {
1168 if ($InfoFieldList[0] == 'categorie') {
1169 $filter_categorie = true;
1170 }
1171 }
1172
1173 $sql = "SELECT " . $keyList;
1174 $sql .= ' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1175 if (strpos($InfoFieldList[4], 'extra') !== false) {
1176 $sql .= ' as main';
1177 }
1178 if ($selectkey == 'rowid' && empty($value)) {
1179 $sql .= " WHERE " . $selectkey . " = 0";
1180 } elseif ($selectkey == 'rowid') {
1181 $sql .= " WHERE " . $selectkey . " = " . ((int) $value);
1182 } else {
1183 $sql .= " WHERE " . $selectkey . " = '" . $this->db->escape($value) . "'";
1184 }
1185
1186 dol_syslog(__METHOD__ . ' type=sellist', LOG_DEBUG);
1187 $resql = $this->db->query($sql);
1188 if ($resql) {
1189 if (!$filter_categorie) {
1190 $value = ''; // value was used, so now we reset it to use it to build final output
1191 $numrows = $this->db->num_rows($resql);
1192 if ($numrows) {
1193 $obj = $this->db->fetch_object($resql);
1194
1195 // Several field into label (eq table:code|libelle:rowid)
1196 $fields_label = explode('|', $InfoFieldList[1]);
1197
1198 if (is_array($fields_label) && count($fields_label) > 1) {
1199 foreach ($fields_label as $field_toshow) {
1200 $translabel = '';
1201 if (!empty($obj->$field_toshow)) {
1202 $translabel = $langs->trans($obj->$field_toshow);
1203 }
1204 if ($translabel != $field_toshow) {
1205 $value .= dol_trunc($translabel, 18) . ' ';
1206 } else {
1207 $value .= $obj->$field_toshow . ' ';
1208 }
1209 }
1210 } else {
1211 $translabel = '';
1212 if (!empty($obj->{$InfoFieldList[1]})) {
1213 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1214 }
1215 if ($translabel != $obj->{$InfoFieldList[1]}) {
1216 $value = dol_trunc($translabel, 18);
1217 } else {
1218 $value = $obj->{$InfoFieldList[1]};
1219 }
1220 }
1221 }
1222 } else {
1223 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1224
1225 $toprint = array();
1226 $obj = $this->db->fetch_object($resql);
1227 $c = new Categorie($this->db);
1228 $c->fetch($obj->rowid);
1229 $ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
1230 foreach ($ways as $way) {
1231 $toprint[] = '<li>' . img_object('', 'category') . ' ' . $way . '</li>';
1232 }
1233 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1234 }
1235 } else {
1236 dol_syslog(__METHOD__ . ' error ' . $this->db->lasterror(), LOG_WARNING);
1237 }
1238 } elseif ($type == 'radio') {
1239 $value = (string) $param['options'][$value];
1240 } elseif ($type == 'checkbox') {
1241 $value_arr = explode(',', $value);
1242 $value = '';
1243 if (is_array($value_arr) && count($value_arr) > 0) {
1244 $toprint = array();
1245 foreach ($value_arr as $valueval) {
1246 if (!empty($valueval)) {
1247 $toprint[] = '<li>' . $param['options'][$valueval] . '</li>';
1248 }
1249 }
1250 if (!empty($toprint)) {
1251 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1252 }
1253 }
1254 } elseif ($type == 'chkbxlst') {
1255 $value_arr = explode(',', $value);
1256
1257 $param_list = array_keys($param['options']);
1258 $InfoFieldList = explode(":", $param_list[0]);
1259
1260 $selectkey = "rowid";
1261 $keyList = 'rowid';
1262
1263 if (count($InfoFieldList) >= 3) {
1264 $selectkey = $InfoFieldList[2];
1265 $keyList = $InfoFieldList[2] . ' as rowid';
1266 }
1267
1268 $fields_label = explode('|', $InfoFieldList[1]);
1269 if (is_array($fields_label)) {
1270 $keyList .= ', ';
1271 $keyList .= implode(', ', $fields_label);
1272 }
1273
1274 $filter_categorie = false;
1275 if (count($InfoFieldList) > 5) {
1276 if ($InfoFieldList[0] == 'categorie') {
1277 $filter_categorie = true;
1278 }
1279 }
1280
1281 $sql = "SELECT " . $keyList;
1282 $sql .= ' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1283 if (strpos($InfoFieldList[4], 'extra') !== false) {
1284 $sql .= ' as main';
1285 }
1286 // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'";
1287 // $sql.= ' AND entity = '.$conf->entity;
1288
1289 dol_syslog(__METHOD__ . ' type=chkbxlst', LOG_DEBUG);
1290 $resql = $this->db->query($sql);
1291 if ($resql) {
1292 if (!$filter_categorie) {
1293 $value = ''; // value was used, so now we reset it to use it to build final output
1294 $toprint = array();
1295 while ($obj = $this->db->fetch_object($resql)) {
1296 // Several field into label (eq table:code|libelle:rowid)
1297 $fields_label = explode('|', $InfoFieldList[1]);
1298 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1299 if (is_array($fields_label) && count($fields_label) > 1) {
1300 foreach ($fields_label as $field_toshow) {
1301 $translabel = '';
1302 if (!empty($obj->$field_toshow)) {
1303 $translabel = $langs->trans($obj->$field_toshow);
1304 }
1305 if ($translabel != $field_toshow) {
1306 $toprint[] = '<li>' . dol_trunc($translabel, 18) . '</li>';
1307 } else {
1308 $toprint[] = '<li>' . $obj->$field_toshow . '</li>';
1309 }
1310 }
1311 } else {
1312 $translabel = '';
1313 if (!empty($obj->{$InfoFieldList[1]})) {
1314 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1315 }
1316 if ($translabel != $obj->{$InfoFieldList[1]}) {
1317 $toprint[] = '<li>' . dol_trunc($translabel, 18) . '</li>';
1318 } else {
1319 $toprint[] = '<li>' . $obj->{$InfoFieldList[1]} . '</li>';
1320 }
1321 }
1322 }
1323 }
1324 } else {
1325 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1326
1327 $toprint = array();
1328 while ($obj = $this->db->fetch_object($resql)) {
1329 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1330 $c = new Categorie($this->db);
1331 $c->fetch($obj->rowid);
1332 $ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
1333 foreach ($ways as $way) {
1334 $toprint[] = '<li>' . img_object('', 'category') . ' ' . $way . '</li>';
1335 }
1336 }
1337 }
1338 }
1339 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1340 } else {
1341 dol_syslog(__METHOD__ . ' error ' . $this->db->lasterror(), LOG_WARNING);
1342 }
1343 } elseif ($type == 'link') {
1344 // only if something to display (perf)
1345 if ($value) {
1346 $param_list = array_keys($param['options']); // Example: $param_list='ObjectName:classPath:-1::customer'
1347
1348 $InfoFieldList = explode(":", $param_list[0]);
1349 $classname = $InfoFieldList[0];
1350 $classpath = $InfoFieldList[1];
1351 if (!empty($classpath)) {
1352 dol_include_once($InfoFieldList[1]);
1353 if ($classname && class_exists($classname)) {
1354 $object = new $classname($this->db);
1355 '@phan-var-force CommonObject $object';
1356 $result = $object->fetch($value);
1357 $value = '';
1358 if ($result > 0) {
1359 if (property_exists($object, 'label')) {
1360 $value = $object->label; // @phan-suppress-current-line PhanUndeclaredProperty
1361 } elseif (property_exists($object, 'libelle')) {
1362 $value = $object->libelle; // @phan-suppress-current-line PhanUndeclaredProperty
1363 } elseif (property_exists($object, 'nom')) {
1364 $value = $object->nom; // @phan-suppress-current-line PhanUndeclaredProperty
1365 }
1366 }
1367 }
1368 } else {
1369 dol_syslog(__METHOD__ . ' Error bad setup of field', LOG_WARNING);
1370 return 'Error bad setup of field';
1371 }
1372 } else {
1373 $value = '';
1374 }
1375 } elseif ($type == 'password') {
1376 $value = preg_replace('/./i', '*', $value);
1377 } else { // text|html|varchar
1378 $value = dol_htmlentitiesbr($value);
1379 }
1380
1381 $out = $value;
1382
1383 return $out;
1384 }
1385}
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
$c
Definition line.php:327
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', $calendarpicto='')
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:244
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
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$context
@method int call_trigger(string $triggerName, User $user)
Definition logout.php:42