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