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