dolibarr 23.0.3
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-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2025 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
69 public function inputDate($name, $value = '', $placeholder = '', $id = '', $morecss = '', $moreparam = '')
70 {
71 $out = '';
72
73 // Disabled: Use of native browser date input field as it is not compliant with multilanguagedate format,
74 // nor with timezone management.
75 /*
76 $out .= '<input';
77 if ($placeholder != '' && $value == '') {
78 // to show a placeholder on date input
79 $out .= ' type="text" placeholder="' . $placeholder . '" onfocus="(this.type=\'date\')"';
80 } else {
81 $out .= ' type="date"';
82 }
83 $out .= ($morecss ? ' class="' . $morecss . '"' : '');
84 if ($id != '') {
85 $out .= ' id="' . $id . '"';
86 }
87 $out .= ' name="' . $name . '"';
88 $out .= ' value="' . $value . '"';
89 $out .= ($moreparam ? ' ' . $moreparam : '');
90
91 $out .= '>';
92 */
93
94 $out = $this->selectDate($value === '' ? -1 : $value, $name, 0, 0, 0, "", 1, 0, 0, '', '', '', '', 1, '', $placeholder);
95
96 return $out;
97 }
98
121 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)
122 {
123 global $langs;
124
125 if ($value_as_key) {
126 $array = array_combine($array, $array);
127 }
128
129 $out = '';
130
131 $idname = str_replace(array('[', ']'), array('', ''), $htmlname);
132 $out .= '<select id="' . preg_replace('/^\./', '', $idname) . '"' . ($disabled ? ' disabled="disabled"' : '') . ' class="' . ($morecss ? ' ' . $morecss : '') . '"';
133 $out .= ' name="' . preg_replace('/^\./', '', $htmlname) . '"' . ($moreparam ? ' ' . $moreparam : '');
134 $out .= '>' . "\n";
135
136 if ($show_empty) {
137 $textforempty = ' ';
138 if (!is_numeric($show_empty)) {
139 $textforempty = $show_empty;
140 }
141 $out .= '<option value="' . ($show_empty < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n";
142 }
143
144 if (is_array($array)) {
145 // Translate
146 if ($translate) {
147 foreach ($array as $key => $value) {
148 if (!is_array($value)) {
149 $array[$key] = $langs->trans($value);
150 } else {
151 $array[$key]['label'] = $langs->trans($value['label']);
152 }
153 }
154 }
155
156 // Sort
157 if ($sort == 'ASC') {
158 asort($array);
159 } elseif ($sort == 'DESC') {
160 arsort($array);
161 }
162
163 foreach ($array as $key => $tmpvalue) {
164 if (is_array($tmpvalue)) {
165 $value = $tmpvalue['label'];
166 $disabled = empty($tmpvalue['disabled']) ? '' : ' disabled';
167 } else {
168 $value = $tmpvalue;
169 $disabled = '';
170 }
171
172 if ($key_in_label) {
173 $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
174 } else {
175 $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value);
176 if ($value == '' || $value == '-') {
177 $selectOptionValue = '&nbsp;';
178 }
179 }
180
181 $out .= '<option value="' . $key . '"';
182 $out .= $disabled;
183 $out .= is_array($tmpvalue) && !empty($tmpvalue['parent']) ? ' parent="' . dolPrintHTMLForAttribute($tmpvalue['parent']) . '"' : '';
184 if (is_array($id)) {
185 if (in_array($key, $id) && !$disabled) {
186 $out .= ' selected'; // To preselect a value
187 }
188 } else {
189 $id = (string) $id; // if $id = 0, then $id = '0'
190 if ($id != '' && ($id == $key || ($id == 'ifone' && count($array) == 1)) && !$disabled) {
191 $out .= ' selected'; // To preselect a value
192 }
193 }
194 if (is_array($tmpvalue)) {
195 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
196 if (preg_match('/^data-/', $keyforvalue)) {
197 $out .= ' ' . $keyforvalue . '="' . dol_escape_htmltag($valueforvalue) . '"';
198 }
199 }
200 }
201 $out .= '>';
202 $out .= $selectOptionValue;
203 $out .= "</option>\n";
204 }
205 }
206
207 $out .= "</select>";
208
209 return $out;
210 }
211
225 public function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter = '', $morecss = '', $allfiles = 0)
226 {
227 include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
228
229 $out = '';
230
232 if (!$context) {
233 return '';
234 }
235
236 $this->infofiles = array('nboffiles' => 0, 'extensions' => array(), 'files' => array());
237
238 $entity = 1; // Without multicompany
239
240 // Get object entity
241 if (isModEnabled('multicompany')) {
242 $regs = array();
243 preg_match('/\/([0-9]+)\/[^\/]+\/' . preg_quote($modulesubdir, '/') . '$/', $filedir, $regs);
244 $entity = ((!empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
245 }
246
247 // Get list of files starting with name of ref (Note: files with '^ref\.extension' are generated files, files with '^ref-...' are uploaded files)
248 if ($allfiles || getDolGlobalString('MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP')) {
249 $filterforfilesearch = '^' . preg_quote(basename($modulesubdir), '/');
250 } else {
251 $filterforfilesearch = '^' . preg_quote(basename($modulesubdir), '/') . '\.';
252 }
253 $file_list = dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // We also discard .meta and .png preview
254
255 //var_dump($file_list);
256 // For ajax treatment
257 $out .= '<!-- html.formwebportal::getDocumentsLink -->' . "\n";
258 if (!empty($file_list)) {
259 $tmpout = '';
260
261 // Loop on each file found
262 $found = 0;
263 $i = 0;
264 foreach ($file_list as $file) {
265 $i++;
266 if ($filter && !preg_match('/' . $filter . '/i', $file["name"])) {
267 continue; // Discard this. It does not match provided filter.
268 }
269
270 $found++;
271 // Define relative path for download link (depends on module)
272 $relativepath = $file["name"]; // Cas general
273 if ($modulesubdir) {
274 $relativepath = $modulesubdir . "/" . $file["name"]; // Cas propal, facture...
275 }
276 // Autre cas
277 if ($modulepart == 'donation') {
278 $relativepath = get_exdir($modulesubdir, 2, 0, 0, null, 'donation') . $file["name"];
279 }
280 if ($modulepart == 'export') {
281 $relativepath = $file["name"];
282 }
283
284 $this->infofiles['nboffiles']++;
285 $this->infofiles['files'][] = $file['fullname'];
286 $ext = pathinfo($file["name"], PATHINFO_EXTENSION);
287 if (empty($this->infofiles['extensions'][$ext])) {
288 $this->infofiles['extensions'][$ext] = 1;
289 } else {
290 // @phan-suppress-next-line PhanTypeInvalidDimOffset
291 $this->infofiles['extensions'][$ext]++;
292 }
293
294 // Download
295 $url = $context->getControllerUrl('document') . '&modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($relativepath) . '&soc_id=' . $context->logged_thirdparty->id;
296
297 $tmpout .= '<a href="' . $url . '" class="btn-download-link ' . $morecss . '" role="downloadlink"';
298 $mime = dol_mimetype($relativepath, '', 0);
299 if (preg_match('/text/', $mime)) {
300 $tmpout .= ' target="_blank" rel="noopener noreferrer"';
301 }
302 $tmpout .= '>';
303 $tmpout .= img_mime($relativepath, $file["name"]);
304 $tmpout .= strtoupper($ext);
305 $tmpout .= '</a>';
306 }
307
308 if ($found) {
309 $out .= $tmpout;
310 }
311 }
312
313 return $out;
314 }
315
326 public function getSignatureLink($modulepart, $object, $morecss = '')
327 {
328 global $langs;
329 require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
330 $out = '<!-- html.formwebportal::getSignatureLink -->' . "\n";
331 $url = getOnlineSignatureUrl(0, $modulepart, $object->ref, 1, $object);
332 if (!empty($url)) {
333 $out .= '<a target="_blank" rel="noopener noreferrer" href="' . $url . '"' . ($morecss ? ' class="' . $morecss . '"' : '') . ' role="signaturelink">';
334 $out .= '<i class="fa fa-file-signature"></i>';
335 $out .= $langs->trans("Sign");
336 $out .= '</a>';
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 if (!empty($classpath)) {
384 dol_include_once($classpath);
385
386 if ($classname && class_exists($classname)) {
387 $objecttmp = new $classname($this->db);
388
389 // Make some replacement
390 $sharedentities = getEntity(strtolower($classname));
391 $filter = str_replace(
392 array('__ENTITY__', '__SHARED_ENTITIES__'),
393 array($conf->entity, $sharedentities),
394 $filter
395 );
396 }
397 }
398 if (!is_object($objecttmp)) {
399 dol_syslog('Error bad setup of type for field ' . implode(',', $InfoFieldList), LOG_WARNING);
400 return 'Error bad setup of type for field ' . implode(',', $InfoFieldList);
401 }
402
403 dol_syslog(__METHOD__ . ' filter=' . $filter, LOG_DEBUG);
404 $out = '';
405 // Immediate load of table record.
406 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
407
408 return $out;
409 }
410
425 public function showInputFieldForObject($object, $val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
426 {
427 // TODO Replace code with
428 //return $object->showInputField($val, $key, $value, '', '', '', 0);
429
430 global $conf, $langs;
431
432 $out = '';
433 $param = array();
434 $reg = array();
435 $size = !empty($val['size']) ? $val['size'] : 0;
436 // see common object class
437 if (preg_match('/^(integer|link):(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
438 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] . ':' . $reg[5] => 'N');
439 $type = 'link';
440 } elseif (preg_match('/^(integer|link):(.*):(.*):(.*)/i', $val['type'], $reg)) {
441 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
442 $type = 'link';
443 } elseif (preg_match('/^(integer|link):(.*):(.*)/i', $val['type'], $reg)) {
444 $param['options'] = array($reg[2] . ':' . $reg[3] => 'N');
445 $type = 'link';
446 } elseif (preg_match('/^(sellist):(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
447 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] . ':' . $reg[5] => 'N');
448 $type = 'sellist';
449 } elseif (preg_match('/^(sellist):(.*):(.*):(.*)/i', $val['type'], $reg)) {
450 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
451 $type = 'sellist';
452 } elseif (preg_match('/^(sellist):(.*):(.*)/i', $val['type'], $reg)) {
453 $param['options'] = array($reg[2] . ':' . $reg[3] => 'N');
454 $type = 'sellist';
455 } elseif (preg_match('/^varchar\‍((\d+)\‍)/', $val['type'], $reg)) {
456 $param['options'] = array();
457 $type = 'text';
458 $size = $reg[1];
459 } elseif (preg_match('/^varchar/', $val['type'])) {
460 $param['options'] = array();
461 $type = 'text';
462 } elseif (preg_match('/^double(\‍([0-9],[0-9]\‍)){0,1}/', $val['type'])) {
463 $param['options'] = array();
464 $type = 'double';
465 } else {
466 $param['options'] = array();
467 $type = $val['type'];
468 }
469
470 // Special case that force options and type ($type can be integer, varchar, ...)
471 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
472 $param['options'] = $val['arrayofkeyval'];
473 $type = $val['type'] == 'checkbox' ? 'checkbox' : 'select';
474 }
475
476 //$label = $val['label'];
477 $default = (!empty($val['default']) ? $val['default'] : '');
478 $computed = (!empty($val['computed']) ? $val['computed'] : '');
479 //$unique = (!empty($val['unique']) ? $val['unique'] : 0);
480 $required = (!empty($val['required']) ? $val['required'] : 0);
481 $notNull = (!empty($val['notnull']) ? $val['notnull'] : 0);
482
483 //$langfile = (!empty($val['langfile']) ? $val['langfile'] : '');
484 //$list = (!empty($val['list']) ? $val[$key]['list'] : 0);
485 $hidden = (in_array(abs($val['visible']), array(0, 2)) ? 1 : 0);
486
487 //$objectid = $this->id;
488
489 if ($computed) {
490 if (!preg_match('/^search_/', $keyprefix)) {
491 return '<span>' . $langs->trans("AutomaticallyCalculated") . '</span>';
492 } else {
493 return '';
494 }
495 }
496
497 // Set value of $morecss. For this, we use in priority showsize from parameters, then $val['css'] then autodefine
498 if (empty($morecss) && !empty($val['css'])) {
499 $morecss = $val['css'];
500 }
501
502 $htmlName = $keyprefix . $key . $keysuffix;
503 $htmlId = $htmlName;
504 //$moreparam .= (!empty($required) ? ' required' : '');
505 switch ($type) {
506 case 'date':
507 case 'datetime':
508 // separate value YYYY-MM-DD HH:ii:ss to date and time
509 $valueDate = '';
510 $valueTime = '';
511 $dateArr = explode(' ', $value);
512 if (count($dateArr) > 0) {
513 $valueDate = $dateArr[0];
514 if (isset($dateArr[1])) {
515 $valueTime = $dateArr[1];
516 }
517 }
518 $out = $this->inputDate($htmlName, $valueDate, '', $htmlId, $morecss, $moreparam);
519
520 if ($type == 'datetime') {
521 //$moreparam .= ' step="1"'; to show seconds
522 $out .= ' ' . $this->inputType('time', $htmlName.'_time', $valueTime, $htmlId, $morecss, $moreparam);
523 }
524 break;
525
526 case 'integer':
527 $out = $this->inputType('number', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
528 break;
529
530 case 'text':
531 case 'html':
532 $moreparam .= ($size > 0 ? ' maxlength="' . $size . '"' : '');
533 $out = $this->inputType('text', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
534 break;
535
536 case 'email':
537 $out = $this->inputType('email', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
538 break;
539
540 case 'tel':
541 $out = $this->inputType('tel', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
542 break;
543
544 case 'url':
545 $out = $this->inputType('url', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
546 break;
547
548 case 'price':
549 if (!empty($value)) {
550 $value = price($value); // $value in memory is a php numeric, we format it into user number format.
551 }
552 $addInputLabel = ' ' . $langs->getCurrencySymbol();
553 $out = $this->inputType('text', $htmlName, $value, $htmlId, $morecss, $moreparam, '', $addInputLabel);
554 break;
555
556 case 'double':
557 if (!empty($value)) {
558 $value = price($value); // $value in memory is a php numeric, we format it into user number format.
559 }
560 $out = $this->inputType('text', $htmlName, $value, $htmlId, $morecss, $moreparam);
561 break;
562
563 case 'password':
564 $out = $this->inputType('password', $htmlName, $value, $htmlId, $morecss, $moreparam);
565 break;
566
567 case 'radio':
568 foreach ($param['options'] as $keyopt => $valopt) {
569 $htmlId = $htmlName . '_' . $keyopt;
570 $htmlMoreParam = $moreparam . ($value == $keyopt ? ' checked' : '');
571 $out .= $this->inputType('radio', $htmlName, $keyopt, $htmlId, $morecss, $htmlMoreParam, $valopt) . '<br>';
572 }
573 break;
574
575 case 'select':
576 $out = '<select class="' . $morecss . '" name="' . $htmlName . '" id="' . $htmlId . '"' . ($moreparam ? ' ' . $moreparam : '') . ' >';
577 if ($default == '' || $notNull != 1) {
578 $out .= '<option value="0">&nbsp;</option>';
579 }
580 foreach ($param['options'] as $keyb => $valb) {
581 if ($keyb == '') {
582 continue;
583 }
584 if (strpos($valb, "|") !== false) {
585 list($valb, $parent) = explode('|', $valb);
586 }
587 $out .= '<option value="' . $keyb . '"';
588 $out .= (((string) $value == $keyb) ? ' selected' : '');
589 $out .= (!empty($parent) ? ' parent="' . $parent . '"' : '');
590 $out .= '>' . $valb . '</option>';
591 }
592 $out .= '</select>';
593 break;
594 case 'sellist':
595 $out = '<select class="' . $morecss . '" name="' . $htmlName . '" id="' . $htmlId . '"' . ($moreparam ? ' ' . $moreparam : '') . '>';
596
597 $param_list = array_keys($param['options']);
598 $InfoFieldList = explode(":", $param_list[0]);
599 $parentName = '';
600 $parentField = '';
601 // 0 : tableName
602 // 1 : label field name
603 // 2 : key fields name (if differ of rowid)
604 // 3 : key field parent (for dependent lists)
605 // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
606 // 5 : id category type
607 // 6 : ids categories list separated by comma for category root
608 $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid');
609
610 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
611 if (strpos($InfoFieldList[4], 'extra.') !== false) {
612 $keyList = 'main.' . $InfoFieldList[2] . ' as rowid';
613 } else {
614 $keyList = $InfoFieldList[2] . ' as rowid';
615 }
616 }
617 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
618 list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
619 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4], 'extra.') !== false) {
620 $keyList .= ', main.'.$parentField;
621 } else {
622 $keyList .= ', '.$parentField;
623 }
624 }
625
626 $filter_categorie = false;
627 if (count($InfoFieldList) > 5) {
628 if ($InfoFieldList[0] == 'categorie') {
629 $filter_categorie = true;
630 }
631 }
632
633 if (!$filter_categorie) {
634 $fields_label = isset($InfoFieldList[1]) ? explode('|', $InfoFieldList[1]) : array();
635 if (!empty($fields_label)) {
636 $keyList .= ', ';
637 $keyList .= implode(', ', $fields_label);
638 }
639
640 $sqlwhere = '';
641 $sql = "SELECT " . $keyList;
642 $sql .= " FROM " . $this->db->prefix() . $InfoFieldList[0];
643 if (!empty($InfoFieldList[4])) {
644 // can use SELECT request
645 if (strpos($InfoFieldList[4], '$SEL$') !== false) {
646 $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]);
647 }
648
649 // current object id can be use into filter
650 $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]);
651
652 //We have to join on extrafield table
653 if (strpos($InfoFieldList[4], 'extra') !== false) {
654 $sql .= " as main, " . $this->db->prefix() . $InfoFieldList[0] . "_extrafields as extra";
655 $sqlwhere .= " WHERE extra.fk_object=main." . $InfoFieldList[2] . " AND " . $InfoFieldList[4];
656 } else {
657 $sqlwhere .= " WHERE " . $InfoFieldList[4];
658 }
659 } else {
660 $sqlwhere .= ' WHERE 1=1';
661 }
662 // Some tables may have field, some other not. For the moment we disable it.
663 if (in_array($InfoFieldList[0], array('tablewithentity'))) {
664 $sqlwhere .= " AND entity = " . ((int) $conf->entity);
665 }
666 $sql .= $sqlwhere;
667 //print $sql;
668
669 $sql .= ' ORDER BY ' . implode(', ', $fields_label);
670
671 dol_syslog(get_class($this) . '::showInputField type=sellist', LOG_DEBUG);
672 $resql = $this->db->query($sql);
673 if ($resql) {
674 $out .= '<option value="0">&nbsp;</option>';
675 $num = $this->db->num_rows($resql);
676 $i = 0;
677 while ($i < $num) {
678 $labeltoshow = '';
679 $obj = $this->db->fetch_object($resql);
680
681 // Several field into label (eq table:code|libelle:rowid)
682 $notrans = false;
683 $fields_label = explode('|', $InfoFieldList[1]);
684 if (count($fields_label) > 1) {
685 $notrans = true;
686 foreach ($fields_label as $field_toshow) {
687 $labeltoshow .= $obj->$field_toshow . ' ';
688 }
689 } else {
690 $labeltoshow = $obj->{$InfoFieldList[1]};
691 }
692 $labeltoshow = dol_trunc($labeltoshow, 45);
693
694 if ($value == $obj->rowid) {
695 foreach ($fields_label as $field_toshow) {
696 $translabel = $langs->trans($obj->$field_toshow);
697 if ($translabel != $obj->$field_toshow) {
698 $labeltoshow = dol_trunc($translabel) . ' ';
699 } else {
700 $labeltoshow = dol_trunc($obj->$field_toshow) . ' ';
701 }
702 }
703 $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>';
704 } else {
705 if (!$notrans) {
706 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
707 if ($translabel != $obj->{$InfoFieldList[1]}) {
708 $labeltoshow = dol_trunc($translabel, 18);
709 } else {
710 $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]});
711 }
712 }
713 if (empty($labeltoshow)) {
714 $labeltoshow = '(not defined)';
715 }
716 if ($value == $obj->rowid) {
717 $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>';
718 }
719
720 if (!empty($InfoFieldList[3]) && $parentField) {
721 $parent = $parentName . ':' . $obj->{$parentField};
722 $isDependList = 1;
723 }
724
725 $out .= '<option value="' . $obj->rowid . '"';
726 $out .= ($value == $obj->rowid ? ' selected' : '');
727 $out .= (!empty($parent) ? ' parent="' . $parent . '"' : '');
728 $out .= '>' . $labeltoshow . '</option>';
729 }
730
731 $i++;
732 }
733 $this->db->free($resql);
734 } else {
735 $out .= 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>';
736 }
737 } else {
738 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
739 $categorytype = $InfoFieldList[5];
740 if (is_numeric($categorytype)) { // deprecated: must use the category code instead of id. For backward compatibility.
741 $tmpcategory = new Categorie($this->db);
742 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
743 $categorytype = $MAP_ID_TO_CODE[(int) $categorytype];
744 }
745
746 $data = $this->select_all_categories($categorytype, '', 'parent', 64, $InfoFieldList[6], 1, 1);
747 $out .= '<option value="0">&nbsp;</option>';
748 foreach ($data as $data_key => $data_value) {
749 $out .= '<option value="' . $data_key . '"';
750 $out .= ($value == $data_key ? ' selected' : '');
751 $out .= '>' . $data_value . '</option>';
752 }
753 }
754 $out .= '</select>';
755 break;
756
757 case 'link':
758 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter[:Sortfield]]]'
759 $showempty = (($required && $default != '') ? '0' : '1');
760
761 $out = $this->selectForForms($param_list[0], $htmlName, (int) $value, $showempty, '', '', $morecss, $moreparam, 0, empty($val['disabled']) ? 0 : 1);
762
763 break;
764
765 default:
766 if (!empty($hidden)) {
767 $out = $this->inputType('hidden', $htmlName, $value, $htmlId);
768 }
769 break;
770 }
771
772 return $out;
773 }
774
788 public function showOutputFieldForObject($object, $val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
789 {
790 // TODO Replace code with
791 //return $object->showOutputField($val, $key, $value, '', '', '', 0);
792 // We must just implement different case like output a ref that must not include the link into backoffice
793
794 global $conf, $langs;
795
796 $label = empty($val['label']) ? '' : $val['label'];
797 $type = empty($val['type']) ? '' : $val['type'];
798 $css = empty($val['css']) ? '' : $val['css'];
799 $picto = empty($val['picto']) ? '' : $val['picto'];
800 $reg = array();
801
802 // Convert var to be able to share same code than showOutputField of extrafields
803 if (preg_match('/varchar\‍((\d+)\‍)/', $type, $reg)) {
804 $type = 'varchar'; // convert varchar(xx) int varchar
805 $css = $reg[1];
806 } elseif (preg_match('/varchar/', $type)) {
807 $type = 'varchar'; // convert varchar(xx) int varchar
808 }
809 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
810 $type = $val['type'] == 'checkbox' ? 'checkbox' : 'select';
811 }
812 if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
813 $type = 'link';
814 }
815
816 $default = empty($val['default']) ? '' : $val['default'];
817 $computed = empty($val['computed']) ? '' : $val['computed'];
818 $unique = empty($val['unique']) ? '' : $val['unique'];
819 $required = empty($val['required']) ? '' : $val['required'];
820 $param = array();
821 $param['options'] = array();
822
823 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
824 $param['options'] = $val['arrayofkeyval'];
825 }
826 if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
827 $type = 'link';
828 $stringforoptions = $reg[1] . ':' . $reg[2];
829 if ($reg[1] == 'User') {
830 $stringforoptions .= ':-1';
831 }
832 $param['options'] = array($stringforoptions => $stringforoptions);
833 } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
834 $param['options'] = array($reg[1] . ':' . $reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
835 $type = 'sellist';
836 } elseif (preg_match('/^sellist:(.*):(.*):(.*)/i', $val['type'], $reg)) {
837 $param['options'] = array($reg[1] . ':' . $reg[2] . ':' . $reg[3] => 'N');
838 $type = 'sellist';
839 } elseif (preg_match('/^sellist:(.*):(.*)/i', $val['type'], $reg)) {
840 $param['options'] = array($reg[1] . ':' . $reg[2] => 'N');
841 $type = 'sellist';
842 } elseif (preg_match('/^chkbxlst:(.*)/i', $val['type'], $reg)) {
843 $param['options'] = array($reg[1] => 'N');
844 $type = 'chkbxlst';
845 }
846
847 $langfile = empty($val['langfile']) ? '' : $val['langfile'];
848 $list = (empty($val['list']) ? '' : $val['list']);
849 $help = (empty($val['help']) ? '' : $val['help']);
850 $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)
851
852 if ($hidden) {
853 return '';
854 }
855
856 // If field is a computed field, value must become result of compute
857 if ($computed) {
858 // Make the eval of compute string
859 //var_dump($computed);
860 $value = (string) dol_eval((string) $computed, 1, 0, '2');
861 }
862
863 // Format output value differently according to properties of field
864 //
865 // First the cases that do not use $value from the arguments:
866 //
867 if (in_array($key, array('rowid', 'ref'))) {
868 if (property_exists($object, 'ref')) {
869 $value = (string) $object->ref;
870 } elseif (property_exists($object, 'id')) {
871 $value = $object->id;
872 } else {
873 $value = '';
874 }
875 } elseif ($key == 'status' && method_exists($object, 'getLibStatut')) {
876 $value = $object->getLibStatut(3);
877 //
878 // Then the cases where $value is an array
879 //
880 } elseif (is_array($value)) {
881 // Handle array early to get type identification solve for static
882 // analysis
883 if ($type == 'array') {
884 $value = implode('<br>', $value);
885 } else {
886 dol_syslog(__METHOD__."Unexpected type=".$type." for array value=".((string) json_encode($value)), LOG_ERR);
887 }
888 //
889 // Then the cases where $value is not an array (hence string)
890 //
891 } elseif ($type == 'date') {
892 if (!empty($value)) {
893 $value = dol_print_date($value, 'day'); // We suppose dates without time are always gmt (storage of course + output)
894 } else {
895 $value = '';
896 }
897 } elseif ($type == 'datetime' || $type == 'timestamp') {
898 if (!empty($value)) {
899 $value = dol_print_date($value, 'dayhour', 'tzuserrel');
900 } else {
901 $value = '';
902 }
903 } elseif ($type == 'duration') {
904 include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
905 if (!is_null($value) && $value !== '') {
906 $value = convertSecondToTime((int) $value, 'allhourmin');
907 } else {
908 // Resulting type must be string
909 $value = '';
910 }
911 } elseif ($type == 'double' || $type == 'real') {
912 if (!is_null($value) && $value !== '') {
913 $value = price($value);
914 } else {
915 // Resulting type must be string
916 $value = '';
917 }
918 } elseif ($type == 'boolean') {
919 $checked = '';
920 if (!empty($value)) {
921 $checked = ' checked ';
922 }
923 $value = '<input type="checkbox" ' . $checked . ' ' . ($moreparam ? $moreparam : '') . ' readonly disabled>';
924 } elseif ($type == 'mail' || $type == 'email') {
925 $value = dol_print_email($value, 0, 0, 0, 64, 1, 1);
926 } elseif ($type == 'url') {
927 $value = dol_print_url($value, '_blank', 32, 1);
928 } elseif ($type == 'phone') {
929 $value = dol_print_phone($value, '', 0, 0, '', '&nbsp;', 'phone');
930 } elseif ($type == 'ip') {
931 $value = dol_print_ip($value, 0);
932 } elseif ($type == 'price') {
933 if (!is_null($value) && $value !== '') {
934 $value = price($value, 0, $langs, 0, 0, -1, getDolCurrency());
935 } else {
936 // Resulting type must be string
937 $value = '';
938 }
939 } elseif ($type == 'select') {
940 $value = isset($param['options'][$value]) ? $param['options'][$value] : '';
941 } elseif ($type == 'sellist') {
942 $param_list = array_keys($param['options']);
943 $InfoFieldList = explode(":", $param_list[0]);
944
945 $selectkey = "rowid";
946 $keyList = 'rowid';
947
948 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
949 $selectkey = $InfoFieldList[2];
950 $keyList = $InfoFieldList[2] . ' as rowid';
951 }
952
953 $fields_label = explode('|', $InfoFieldList[1]);
954 if (is_array($fields_label)) {
955 $keyList .= ', ';
956 $keyList .= implode(', ', $fields_label);
957 }
958
959 $filter_categorie = false;
960 if (count($InfoFieldList) > 5) {
961 if ($InfoFieldList[0] == 'categorie') {
962 $filter_categorie = true;
963 }
964 }
965
966 $sql = "SELECT " . $keyList;
967 $sql .= ' FROM ' . $this->db->prefix() . $InfoFieldList[0];
968 if (strpos($InfoFieldList[4], 'extra') !== false) {
969 $sql .= ' as main';
970 }
971 if ($selectkey == 'rowid' && empty($value)) {
972 $sql .= " WHERE " . $selectkey . " = 0";
973 } elseif ($selectkey == 'rowid') {
974 $sql .= " WHERE " . $selectkey . " = " . ((int) $value);
975 } else {
976 $sql .= " WHERE " . $selectkey . " = '" . $this->db->escape($value) . "'";
977 }
978
979 dol_syslog(__METHOD__ . ' type=sellist', LOG_DEBUG);
980 $resql = $this->db->query($sql);
981 if ($resql) {
982 if (!$filter_categorie) {
983 $value = ''; // value was used, so now we reset it to use it to build final output
984 $numrows = $this->db->num_rows($resql);
985 if ($numrows) {
986 $obj = $this->db->fetch_object($resql);
987
988 // Several field into label (eq table:code|libelle:rowid)
989 $fields_label = explode('|', $InfoFieldList[1]);
990
991 if (is_array($fields_label) && count($fields_label) > 1) {
992 foreach ($fields_label as $field_toshow) {
993 $translabel = '';
994 if (!empty($obj->$field_toshow)) {
995 $translabel = $langs->trans($obj->$field_toshow);
996 }
997 if ($translabel != $field_toshow) {
998 $value .= dol_trunc($translabel, 18) . ' ';
999 } else {
1000 $value .= $obj->$field_toshow . ' ';
1001 }
1002 }
1003 } else {
1004 $translabel = '';
1005 if (!empty($obj->{$InfoFieldList[1]})) {
1006 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1007 }
1008 if ($translabel != $obj->{$InfoFieldList[1]}) {
1009 $value = dol_trunc($translabel, 18);
1010 } else {
1011 $value = $obj->{$InfoFieldList[1]};
1012 }
1013 }
1014 }
1015 } else {
1016 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1017
1018 $toprint = array();
1019 $obj = $this->db->fetch_object($resql);
1020 $c = new Categorie($this->db);
1021 $c->fetch($obj->rowid);
1022 $ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
1023 foreach ($ways as $way) {
1024 $toprint[] = '<li>' . img_object('', 'category') . ' ' . $way . '</li>';
1025 }
1026 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1027 }
1028 } else {
1029 dol_syslog(__METHOD__ . ' error ' . $this->db->lasterror(), LOG_WARNING);
1030 }
1031 } elseif ($type == 'radio') {
1032 $value = (string) $param['options'][$value];
1033 } elseif ($type == 'checkbox') {
1034 $value_arr = explode(',', $value);
1035 $value = '';
1036 if (is_array($value_arr) && count($value_arr) > 0) {
1037 $toprint = array();
1038 foreach ($value_arr as $valueval) {
1039 if (!empty($valueval)) {
1040 $toprint[] = '<li>' . $param['options'][$valueval] . '</li>';
1041 }
1042 }
1043 if (!empty($toprint)) {
1044 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1045 }
1046 }
1047 } elseif ($type == 'chkbxlst') {
1048 $value_arr = explode(',', $value);
1049
1050 $param_list = array_keys($param['options']);
1051 $InfoFieldList = explode(":", $param_list[0]);
1052
1053 $selectkey = "rowid";
1054 $keyList = 'rowid';
1055
1056 if (count($InfoFieldList) >= 3) {
1057 $selectkey = $InfoFieldList[2];
1058 $keyList = $InfoFieldList[2] . ' as rowid';
1059 }
1060
1061 $fields_label = explode('|', $InfoFieldList[1]);
1062 if (is_array($fields_label)) {
1063 $keyList .= ', ';
1064 $keyList .= implode(', ', $fields_label);
1065 }
1066
1067 $filter_categorie = false;
1068 if (count($InfoFieldList) > 5) {
1069 if ($InfoFieldList[0] == 'categorie') {
1070 $filter_categorie = true;
1071 }
1072 }
1073
1074 $sql = "SELECT " . $keyList;
1075 $sql .= ' FROM ' . $this->db->prefix() . $InfoFieldList[0];
1076 if (strpos($InfoFieldList[4], 'extra') !== false) {
1077 $sql .= ' as main';
1078 }
1079 // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'";
1080 // $sql.= ' AND entity = '.$conf->entity;
1081
1082 dol_syslog(__METHOD__ . ' type=chkbxlst', LOG_DEBUG);
1083 $resql = $this->db->query($sql);
1084 if ($resql) {
1085 if (!$filter_categorie) {
1086 $value = ''; // value was used, so now we reset it to use it to build final output
1087 $toprint = array();
1088 while ($obj = $this->db->fetch_object($resql)) {
1089 // Several field into label (eq table:code|libelle:rowid)
1090 $fields_label = explode('|', $InfoFieldList[1]);
1091 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1092 if (is_array($fields_label) && count($fields_label) > 1) {
1093 foreach ($fields_label as $field_toshow) {
1094 $translabel = '';
1095 if (!empty($obj->$field_toshow)) {
1096 $translabel = $langs->trans($obj->$field_toshow);
1097 }
1098 if ($translabel != $field_toshow) {
1099 $toprint[] = '<li>' . dol_trunc($translabel, 18) . '</li>';
1100 } else {
1101 $toprint[] = '<li>' . $obj->$field_toshow . '</li>';
1102 }
1103 }
1104 } else {
1105 $translabel = '';
1106 if (!empty($obj->{$InfoFieldList[1]})) {
1107 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1108 }
1109 if ($translabel != $obj->{$InfoFieldList[1]}) {
1110 $toprint[] = '<li>' . dol_trunc($translabel, 18) . '</li>';
1111 } else {
1112 $toprint[] = '<li>' . $obj->{$InfoFieldList[1]} . '</li>';
1113 }
1114 }
1115 }
1116 }
1117 } else {
1118 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1119
1120 $toprint = array();
1121 while ($obj = $this->db->fetch_object($resql)) {
1122 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1123 $c = new Categorie($this->db);
1124 $c->fetch($obj->rowid);
1125 $ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
1126 foreach ($ways as $way) {
1127 $toprint[] = '<li>' . img_object('', 'category') . ' ' . $way . '</li>';
1128 }
1129 }
1130 }
1131 }
1132 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1133 } else {
1134 dol_syslog(__METHOD__ . ' error ' . $this->db->lasterror(), LOG_WARNING);
1135 }
1136 } elseif ($type == 'link') {
1137 // only if something to display (perf)
1138 if ($value) {
1139 $param_list = array_keys($param['options']); // Example: $param_list='ObjectName:classPath:-1::customer'
1140
1141 $InfoFieldList = explode(":", $param_list[0]);
1142 $classname = $InfoFieldList[0];
1143 $classpath = $InfoFieldList[1];
1144 if (!empty($classpath)) {
1145 dol_include_once($InfoFieldList[1]);
1146 if ($classname && class_exists($classname)) {
1147 $object = new $classname($this->db);
1148 '@phan-var-force CommonObject $object';
1150 $result = $object->fetch($value);
1151 $value = '';
1152 if ($result > 0) {
1153 if (property_exists($object, 'label')) {
1154 $value = (string) $object->label; // @phan-suppress-current-line PhanUndeclaredProperty
1155 } elseif (property_exists($object, 'libelle')) {
1156 $value = (string) $object->libelle; // @phan-suppress-current-line PhanUndeclaredProperty
1157 } elseif (property_exists($object, 'nom')) {
1158 $value = (string) $object->nom; // @phan-suppress-current-line PhanUndeclaredProperty
1159 }
1160 }
1161 }
1162 } else {
1163 dol_syslog(__METHOD__ . ' Error bad setup of field', LOG_WARNING);
1164 return 'Error bad setup of field';
1165 }
1166 } else {
1167 $value = '';
1168 }
1169 } elseif ($type == 'password') {
1170 $value = preg_replace('/./i', '*', $value);
1171 } else { // text|html|varchar
1172 $value = dol_htmlentitiesbr($value);
1173 }
1174
1175 $out = $value;
1176
1177 return $out;
1178 }
1179
1193 public function inputType($type, $name, $value = '', $id = '', $morecss = '', $moreparam = '', $label = '', $addInputLabel = '')
1194 {
1195 $out = '';
1196 if ($label != '') {
1197 $out .= '<label for="' . dolPrintHTMLForAttribute($id) . '">';
1198 }
1199 $out .= '<input type="' . dolPrintHTMLForAttribute($type) . '"';
1200 $out .= ' class="flat valignmiddle maxwidthonsmartphone ' . dolPrintHTMLForAttribute($morecss) . '"';
1201 if ($id != '') {
1202 $out .= ' id="' . dolPrintHTMLForAttribute($id) . '"';
1203 }
1204 $out .= ' name="' . dolPrintHTMLForAttribute($name) . '"';
1205 $out .= ' value="' . dolPrintHTMLForAttribute($value) . '" ';
1206 $out .= ($moreparam ? ' ' . $moreparam : '');
1207 $out .= ' />' . $addInputLabel;
1208 if ($label != '') {
1209 $out .= $label . '</label>';
1210 }
1211
1212 return $out;
1213 }
1214
1227 public function inputSelectAjax($htmlName, $array, $id, $ajaxUrl, $ajaxData = [], $morecss = 'minwidth75', $moreparam = '')
1228 {
1229 $out = "
1230 <script>
1231 $(document).ready(function () {
1232 $('#" . $htmlName . "').select2({
1233 ajax: {
1234 url: '" . $ajaxUrl . "',
1235 dataType: 'json',
1236 delay: 250, // wait 250 milliseconds before triggering the request
1237 data: function (params) {
1238 var query = {
1239 search: params.term,
1240 page: params.page || 1";
1241 if (!empty($ajaxData) && is_array($ajaxData)) {
1242 foreach ($ajaxData as $key => $value) {
1243 $out .= ", " . $key . ": '" . $value . "'";
1244 }
1245 }
1246 $out .= "
1247 }
1248 return query;
1249 }
1250 }
1251 })
1252 });
1253 </script>";
1254
1255 $out .= $this->selectarray($htmlName, $array, $id, 0, 0, 0, $moreparam, 0, 0, 0, '', $morecss);
1256
1257 return $out;
1258 }
1259
1269 public function inputHtml($htmlName, $value, $morecss = '', $moreparam = '')
1270 {
1271 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
1272 $doleditor = new DolEditor($htmlName, $value, '', 200, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_5, '90%');
1273
1274 return (string) $doleditor->Create(1, '', true, '', '', $moreparam, $morecss);
1275 }
1276
1287 public function inputText($htmlName, $value, $morecss = '', $moreparam = '', $options = array())
1288 {
1289 global $langs;
1290
1291 $out = '';
1292 if (!empty($options)) {
1293 // If the textarea field has a list of arrayofkeyval into its definition, we suggest a combo with possible values to fill the textarea.
1294 $out .= $this->selectarray($htmlName . "_multiinput", $options, '', 1, 0, 0, $moreparam, 0, 0, 0, '', "flat maxwidthonphone" . $morecss);
1295 $out .= '<input id="' . $htmlName . '_multiinputadd" type="button" class="button" value="' . $langs->trans("Add") . '">';
1296 $out .= "<script>";
1297 $out .= '
1298 function handlemultiinputdisabling(htmlname){
1299 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
1300 multiinput = $("#"+htmlname+"_multiinput");
1301 multiinput.find("option").each(function(){
1302 tmpval = $("#"+htmlname).val();
1303 tmpvalarray = tmpval.split("\n");
1304 valtotest = $(this).val();
1305 if(tmpvalarray.includes(valtotest)){
1306 $(this).prop("disabled",true);
1307 } else {
1308 if($(this).prop("disabled") == true){
1309 console.log(valtotest)
1310 $(this).prop("disabled", false);
1311 }
1312 }
1313 });
1314 }
1315
1316 $(document).ready(function () {
1317 $("#' . $htmlName . '_multiinputadd").on("click",function() {
1318 tmpval = $("#' . $htmlName . '").val();
1319 tmpvalarray = tmpval.split(",");
1320 valtotest = $("#' . $htmlName . '_multiinput").val();
1321 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
1322 console.log("We add the selected value to the text area ' . $htmlName . '");
1323 if(tmpval == ""){
1324 tmpval = valtotest;
1325 } else {
1326 tmpval = tmpval + "\n" + valtotest;
1327 }
1328 $("#' . $htmlName . '").val(tmpval);
1329 handlemultiinputdisabling("' . $htmlName . '");
1330 $("#' . $htmlName . '_multiinput").val(-1);
1331 } else {
1332 console.log("We add nothing the text area ' . $htmlName . '");
1333 }
1334 });
1335 $("#' . $htmlName . '").on("change",function(){
1336 handlemultiinputdisabling("' . $htmlName . '");
1337 });
1338 handlemultiinputdisabling("' . $htmlName . '");
1339 })';
1340 $out .= "</script>";
1341 $value = str_replace(',', "\n", $value);
1342 }
1343
1344 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
1345 $doleditor = new DolEditor($htmlName, (string) $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%');
1346 $out .= (string) $doleditor->Create(1, '', true, '', '', $moreparam, $morecss);
1347
1348 return $out;
1349 }
1350
1361 public function inputRadio($htmlName, $options, $selectedValue, $morecss = '', $moreparam = '')
1362 {
1363 $out = '';
1364 foreach ($options as $optionKey => $optionLabel) {
1365 $selected = ((string) $selectedValue) === ((string) $optionKey) ? ' checked="checked"' : '';
1366 $optionId = $htmlName . '_' . $optionKey;
1367 $out .= '<input class="flat' . $morecss . '" type="radio" name="' . $htmlName . '" id="' . $optionId . '" value="' . dolPrintHTMLForAttribute((string) $optionKey) . '"' . $selected . $moreparam . '/><label for="' . $optionId . '">' . $optionLabel . '</label><br>';
1368 }
1369
1370 return $out;
1371 }
1372
1383 public function inputStars($htmlName, $size, $value, $morecss = '', $moreparam = '')
1384 {
1385 $out = '<input type="hidden" class="flat ' . $morecss . '" name="' . $htmlName . '" id="' . $htmlName . '" value="' . dolPrintHTMLForAttribute((string) $value) . '"' . $moreparam . '>';
1386 $out .= '<div class="star-selection" id="' . $htmlName . '_selection">';
1387 for ($i = 1; $i <= $size; $i++) {
1388 $out .= '<span class="star" data-value="' . $i . '">' . img_picto('', 'fontawesome_star_fas') . '</span>';
1389 }
1390 $out .= '</div>';
1391 $out .= '<script>
1392 jQuery(function($) { /* commonobject.class.php 1 */
1393 let container = $("#' . $htmlName . '_selection");
1394 let selectedStars = parseInt($("#' . $htmlName . '").val()) || 0;
1395 container.find(".star").each(function() {
1396 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
1397 });
1398 container.find(".star").on("mouseover", function() {
1399 let selectedStar = $(this).data("value");
1400 container.find(".star").each(function() {
1401 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
1402 });
1403 });
1404 container.on("mouseout", function() {
1405 container.find(".star").each(function() {
1406 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
1407 });
1408 });
1409 container.find(".star").off("click").on("click", function() {
1410 selectedStars = $(this).data("value");
1411 if (selectedStars === 1 && $("#' . $htmlName . '").val() == 1) {
1412 selectedStars = 0;
1413 }
1414 $("#' . $htmlName . '").val(selectedStars);
1415 container.find(".star").each(function() {
1416 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
1417 });
1418 });
1419 });
1420 </script>';
1421
1422 return $out;
1423 }
1424
1434 public function inputIcon($htmlName, $value, $morecss = '', $moreparam = '')
1435 {
1436 global $langs;
1437
1438 /* External lib inclusion are not allowed in backoffice. Also lib is included several time if there is several icon file.
1439 Some code must be added into main when MAIN_ADD_ICONPICKER_JS is set to add of lib in html header
1440 $out ='<link rel="stylesheet" href="'.dol_buildpath('/myfield/css/fontawesome-iconpicker.min.css', 1).'">';
1441 $out.='<script src="'.dol_buildpath('/myfield/js/fontawesome-iconpicker.min.js', 1).'"></script>';
1442 */
1443 $out = '<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat ' . $morecss . ' maxwidthonsmartphone"';
1444 $out .= ' name="' . $htmlName . '" id="' . $htmlName . '" value="' . dolPrintHTMLForAttribute((string) $value) . '" ' . ((string) $moreparam) . '>';
1445 if (getDolGlobalInt('MAIN_ADD_ICONPICKER_JS')) {
1446 $out .= '<script>';
1447 $options = "{ title: '<b>" . $langs->trans("IconFieldSelector") . "</b>', placement: 'right', showFooter: false, templates: {";
1448 $options .= "iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
1449 $options .= "iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
1450 // $options.="buttons: '<button style=\"background-color:#FFFFFF;\" class=\"iconpicker-btn iconpicker-btn-cancel btn btn-default btn-sm\">".$langs->trans("Cancel")."</button>";
1451 // $options.="<button style=\"background-color:#FFFFFF;\" class=\"iconpicker-btn iconpicker-btn-accept btn btn-primary btn-sm\">".$langs->trans("Save")."</button>',";
1452 $options .= "footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
1453 $options .= "search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"" . $langs->trans("TypeToFilter") . "\" />',";
1454 $options .= "popover: '<div class=\"iconpicker-popover popover\">";
1455 $options .= " <div class=\"arrow\" ></div>";
1456 $options .= " <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
1457 $options .= " <div class=\"popover-content \" ></div>";
1458 $options .= "</div>'}}";
1459 $out .= "$('#" . $htmlName . "').iconpicker(" . $options . ");";
1460 $out .= '</script>';
1461 }
1462
1463 return $out;
1464 }
1465
1474 public function inputGeoPoint($htmlName, $value, $type = '')
1475 {
1476 require_once DOL_DOCUMENT_ROOT . '/core/class/dolgeophp.class.php';
1477 require_once DOL_DOCUMENT_ROOT . '/core/class/geomapeditor.class.php';
1478 $dolgeophp = new DolGeoPHP($this->db);
1479 $geomapeditor = new GeoMapEditor();
1480
1481 $geojson = '{}';
1482 $centroidjson = getDolGlobalString('MAIN_INFO_SOCIETE_GEO_COORDINATES', '{}');
1483 if (!empty($value)) {
1484 $tmparray = $dolgeophp->parseGeoString($value);
1485 $geojson = $tmparray['geojson'];
1486 $centroidjson = $tmparray['centroidjson'];
1487 }
1488
1489 return $geomapeditor->getHtml($htmlName, $geojson, $centroidjson, $type);
1490 }
1491
1498 public function outputMultiValues($values)
1499 {
1500 $out = '';
1501 $toPrint = array();
1502 $values = is_array($values) ? $values : array();
1503
1504 foreach ($values as $value) {
1505 $toPrint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $value . '</li>';
1506 }
1507 if (!empty($toPrint)) {
1508 $out = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toPrint) . '</ul></div>';
1509 }
1510
1511 return $out;
1512 }
1513
1521 public function outputStars($size, $value)
1522 {
1523 $out = '<div class="star-selection" data-value="' . dolPrintHTMLForAttribute((string) $value) . '">';
1524 for ($i = 1; $i <= $size; $i++) {
1525 $out .= '<span class="star' . ($i <= $value ? ' active' : '') . '" data-value="' . $i . '">' . img_picto('', 'fontawesome_star_fas') . '</span>';
1526 }
1527 $out .= '</div>';
1528
1529 return $out;
1530 }
1531
1538 public function outputIcon($value)
1539 {
1540 $out = '<span class="' . dolPrintHTMLForAttribute((string) $value) . '"></span>';
1541
1542 return $out;
1543 }
1544
1552 public function outputGeoPoint($value, $type)
1553 {
1554 $out = '';
1555
1556 if (!empty($value)) {
1557 require_once DOL_DOCUMENT_ROOT . '/core/class/dolgeophp.class.php';
1558 $dolgeophp = new DolGeoPHP($this->db);
1559 if ($type == 'point') {
1560 $out = $dolgeophp->getXYString($value);
1561 } else { // multipts, linestrg, polygon
1562 $out = $dolgeophp->getPointString($value);
1563 }
1564 }
1565
1566 return $out;
1567 }
1568
1583 public function getNomUrl(&$object, $withpicto = 0, $option = '', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss = '', $add_label = 0, $sep = ' - ')
1584 {
1585 if (is_object($object) && method_exists($object, 'getNomUrl')) {
1586 $out = $object->getNomUrl($withpicto, $option, $maxlength, $save_lastsearch_value, $notooltip, $morecss, $add_label, $sep);
1587 $out = dol_string_nohtmltag($out);
1588 return $out;
1589 } else {
1590 return '';
1591 }
1592 }
1593
1612 public static function showphoto($modulepart, $object, $width = 100, $height = 0, $caneditfield = 0, $cssclass = 'photowithmargin', $imagesize = '', $addlinktofullsize = 1, $cache = 0, $forcecapture = '', $noexternsourceoverwrite = 0, $usesharelinkifavailable = 0)
1613 {
1614 $out = parent::showphoto($modulepart, $object, $width, $height, $caneditfield, $cssclass, $imagesize, $addlinktofullsize, $cache, $forcecapture, $noexternsourceoverwrite, $usesharelinkifavailable);
1615 $out = self::convertAllLink($out);
1616
1617 return $out;
1618 }
1619
1636 public function printFieldCell($key, $label, $value, $params = array())
1637 {
1638 $required = !empty($params['required']) ? ' required' : '';
1639 $cell_class = !empty($params['cell_class']) ? ' ' . dolPrintHTMLForAttribute(trim($params['cell_class'])) : '';
1640 $cell_attributes = !empty($params['cell_attributes']) ? ' ' . trim($params['cell_attributes']) : '';
1641 $label_class = !empty($params['label_class']) ? ' ' . dolPrintHTMLForAttribute(trim($params['label_class'])) : '';
1642 $label_attributes = !empty($params['label_attributes']) ? ' ' . trim($params['label_attributes']) : '';
1643 $value_class = !empty($params['value_class']) ? ' ' . dolPrintHTMLForAttribute(trim($params['value_class'])) : '';
1644 $value_attributes = !empty($params['value_attributes']) ? ' ' . trim($params['value_attributes']) : '';
1645
1646 $out = '<div class="grid field_' . dolPrintHTMLForAttribute(strtolower($key)) . $cell_class . '"' . $cell_attributes . '>';
1647 $out .= '<div class="' . $required . $label_class . '"' . $label_attributes . '>';
1648 $out .= $label;
1649 $out .= '</div>';
1650 $out .= '<div class="' . $value_class . '"' . $value_attributes . '>';
1651 $out .= $value;
1652 $out .= '</div>';
1653 $out .= '</div>';
1654
1655 return $out;
1656 }
1657
1666 public static function convertAllLink($html, $additionalViewImageParams = '', $additionalDocumentParams = '')
1667 {
1668 require_once DOL_DOCUMENT_ROOT . '/webportal/class/context.class.php';
1670
1671 $html = str_replace(DOL_URL_ROOT . '/viewimage.php?', $context->getControllerUrl('viewimage') . $additionalViewImageParams . '&', $html);
1672 $html = str_replace(urlencode(dol_escape_js(DOL_URL_ROOT . '/viewimage.php?')), urlencode(dol_escape_js($context->getControllerUrl('viewimage') . $additionalViewImageParams . '&')), $html);
1673 $html = str_replace(DOL_URL_ROOT . '/document.php?', $context->getControllerUrl('document') . $additionalDocumentParams . '&', $html);
1674 $html = str_replace(urlencode(dol_escape_js(DOL_URL_ROOT . '/document.php?')), urlencode(dol_escape_js($context->getControllerUrl('document') . $additionalDocumentParams . '&')), $html);
1675
1676 return $html;
1677 }
1678
1688 public function selectCurrency($selected = '', $htmlname = 'currency_id', $mode = 0, $useempty = '')
1689 {
1690
1691 return '<span class="form-select-currency-container">'.parent::selectCurrency($selected, $htmlname, $mode, $useempty).'</span>';
1692 }
1693}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$c
Definition line.php:331
Class to manage categories.
static getInstance()
Singleton method to create one instance of this object.
Class to manage a WYSIWYG editor.
Class to manage Geo processing Usage: $dolgeophp=new DolGeoPHP($db);.
Class to manage generation of HTML components Only common components must be here.
selectDate($set_time='', $prefix='re', $h=0, $m=0, $empty=0, $form_name="", $d=1, $addnowlink=0, $disabled=0, $fullday='', $addplusone='', $adddateof='', $openinghours='', $stepminutes=1, $labeladddateof='', $placeholder='', $gm='auto', $calendarpicto='')
Show a HTML widget to input a date or combo list for day, month, years and optionally hours and minut...
selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty='', $searchkey='', $placeholder='', $morecss='', $moreparams='', $forcecombo=0, $outputmode=0, $disabled=0, $sortfield='', $filter='', $sortorder='ASC')
Output html form to select an object.
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.
printFieldCell($key, $label, $value, $params=array())
Return HTML code of the cell.
selectCurrency($selected='', $htmlname='currency_id', $mode=0, $useempty='')
Retourne la liste des devises, dans la langue de l'utilisateur.
inputDate($name, $value='', $placeholder='', $id='', $morecss='', $moreparam='')
Input for date.
inputHtml($htmlName, $value, $morecss='', $moreparam='')
Html for HTML area.
inputStars($htmlName, $size, $value, $morecss='', $moreparam='')
Html for input stars.
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 '.
static convertAllLink($html, $additionalViewImageParams='', $additionalDocumentParams='')
Convert all link of the provided html output.
outputMultiValues($values)
Html for show selected multiple values.
showInputFieldForObject($object, $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...
outputStars($size, $value)
Html for show stars.
inputSelectAjax($htmlName, $array, $id, $ajaxUrl, $ajaxData=[], $morecss='minwidth75', $moreparam='')
Html for select with get options by AJAX.
outputGeoPoint($value, $type)
Html for show geo point.
outputIcon($value)
Html for show icon.
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.
inputGeoPoint($htmlName, $value, $type='')
Html for input geo point.
getSignatureLink($modulepart, $object, $morecss='')
Show a Signature icon with link You may want to call this into a div like this: print '.
inputIcon($htmlName, $value, $morecss='', $moreparam='')
Html for input icon.
inputRadio($htmlName, $options, $selectedValue, $morecss='', $moreparam='')
Html for input radio.
__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.
getNomUrl(&$object, $withpicto=0, $option='', $maxlength=0, $save_lastsearch_value=-1, $notooltip=0, $morecss='', $add_label=0, $sep=' - ')
Return link of object.
inputText($htmlName, $value, $morecss='', $moreparam='', $options=array())
Html for HTML area.
static showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $imagesize='', $addlinktofullsize=1, $cache=0, $forcecapture='', $noexternsourceoverwrite=0, $usesharelinkifavailable=0)
Return HTML code to output a photo.
Class to manage a Leaflet map width geometrics objects.
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:247
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:64
dol_print_ip($ip, $mode=0, $showname=0)
Return an IP formatted to be shown on screen.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
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...
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42