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