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