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