dolibarr 25.0.0-alpha
html.formwebportal.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2023-2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023-2024 Lionel Vessiller <lvessiller@easya.solutions>
4 * Copyright (C) 2023-2024 Patrice Andreani <pandreani@easya.solutions>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2026 Charlene Benke <charlene@patas-monkey.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23
30require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php';
31
36class FormWebPortal extends Form
37{
41 public $db;
42
46 public $infofiles; // Used to return information by function getDocumentsLink
47
48
54 public function __construct($db)
55 {
56 $this->db = $db;
57 }
58
70 public function inputDate($name, $value = '', $placeholder = '', $id = '', $morecss = '', $moreparam = '')
71 {
72 $out = '';
73
74 // Disabled: Use of native browser date input field as it is not compliant with multilanguagedate format,
75 // nor with timezone management.
76 /*
77 $out .= '<input';
78 if ($placeholder != '' && $value == '') {
79 // to show a placeholder on date input
80 $out .= ' type="text" placeholder="' . $placeholder . '" onfocus="(this.type=\'date\')"';
81 } else {
82 $out .= ' type="date"';
83 }
84 $out .= ($morecss ? ' class="' . $morecss . '"' : '');
85 if ($id != '') {
86 $out .= ' id="' . $id . '"';
87 }
88 $out .= ' name="' . $name . '"';
89 $out .= ' value="' . $value . '"';
90 $out .= ($moreparam ? ' ' . $moreparam : '');
91
92 $out .= '>';
93 */
94
95 $out = $this->selectDate($value === '' ? -1 : $value, $name, 0, 0, 0, "", 1, 0, 0, '', '', '', '', 1, '', $placeholder, 'auto', DOL_URL_ROOT . "/theme/common/object_calendarday.png");
96
97 return $out;
98 }
99
122 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)
123 {
124 global $langs;
125
126 if ($value_as_key) {
127 $array = array_combine($array, $array);
128 }
129
130 $out = '';
131
132 $idname = str_replace(array('[', ']'), array('', ''), $htmlname);
133 $out .= '<select id="' . preg_replace('/^\./', '', $idname) . '"' . ($disabled ? ' disabled="disabled"' : '') . ' class="' . ($morecss ? ' ' . $morecss : '') . '"';
134 $out .= ' name="' . preg_replace('/^\./', '', $htmlname) . '"' . ($moreparam ? ' ' . $moreparam : '');
135 $out .= '>' . "\n";
136
137 if ($show_empty) {
138 $textforempty = ' ';
139 if (!is_numeric($show_empty)) {
140 $textforempty = $show_empty;
141 }
142 $out .= '<option value="' . ($show_empty < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n";
143 }
144
145 if (is_array($array)) {
146 // Translate
147 if ($translate) {
148 foreach ($array as $key => $value) {
149 if (!is_array($value)) {
150 $array[$key] = $langs->trans($value);
151 } else {
152 $array[$key]['label'] = $langs->trans($value['label']);
153 }
154 }
155 }
156
157 // Sort
158 if ($sort == 'ASC') {
159 asort($array);
160 } elseif ($sort == 'DESC') {
161 arsort($array);
162 }
163
164 foreach ($array as $key => $tmpvalue) {
165 if (is_array($tmpvalue)) {
166 $value = $tmpvalue['label'];
167 $disabled = empty($tmpvalue['disabled']) ? '' : ' disabled';
168 } else {
169 $value = $tmpvalue;
170 $disabled = '';
171 }
172
173 if ($key_in_label) {
174 $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
175 } else {
176 $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value);
177 if ($value == '' || $value == '-') {
178 $selectOptionValue = '&nbsp;';
179 }
180 }
181
182 $out .= '<option value="' . $key . '"';
183 $out .= $disabled;
184 $out .= is_array($tmpvalue) && !empty($tmpvalue['parent']) ? ' parent="' . dolPrintHTMLForAttribute($tmpvalue['parent']) . '"' : '';
185 if (is_array($id)) {
186 if (in_array($key, $id) && !$disabled) {
187 $out .= ' selected'; // To preselect a value
188 }
189 } else {
190 $id = (string) $id; // if $id = 0, then $id = '0'
191 if ($id != '' && ($id == $key || ($id == 'ifone' && count($array) == 1)) && !$disabled) {
192 $out .= ' selected'; // To preselect a value
193 }
194 }
195 if (is_array($tmpvalue)) {
196 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
197 if (preg_match('/^data-/', $keyforvalue)) {
198 $out .= ' ' . $keyforvalue . '="' . dol_escape_htmltag($valueforvalue) . '"';
199 }
200 }
201 }
202 $out .= '>';
203 $out .= $selectOptionValue;
204 $out .= "</option>\n";
205 }
206 }
207
208 $out .= "</select>";
209
210 return $out;
211 }
212
226 public function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter = '', $morecss = '', $allfiles = 0)
227 {
228 include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
229
230 $out = '';
231
233 if (!$context) {
234 return '';
235 }
236
237 $this->infofiles = array('nboffiles' => 0, 'extensions' => array(), 'files' => array());
238
239 $entity = 1; // Without multicompany
240
241 // Get object entity
242 if (isModEnabled('multicompany')) {
243 $regs = array();
244 preg_match('/\/([0-9]+)\/[^\/]+\/' . preg_quote($modulesubdir, '/') . '$/', $filedir, $regs);
245 $entity = ((!empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
246 }
247
248 // Get list of files starting with name of ref (Note: files with '^ref\.extension' are generated files, files with '^ref-...' are uploaded files)
249 if ($allfiles || getDolGlobalString('MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP')) {
250 $filterforfilesearch = '^' . preg_quote(basename($modulesubdir), '/');
251 } else {
252 $filterforfilesearch = '^' . preg_quote(basename($modulesubdir), '/') . '\.';
253 }
254 $file_list = dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // We also discard .meta and .png preview
255
256 //var_dump($file_list);
257 // For ajax treatment
258 $out .= '<!-- html.formwebportal::getDocumentsLink -->' . "\n";
259 if (!empty($file_list)) {
260 $tmpout = '';
261
262 // Loop on each file found
263 $found = 0;
264 $i = 0;
265 foreach ($file_list as $file) {
266 $i++;
267 if ($filter && !preg_match('/' . $filter . '/i', $file["name"])) {
268 continue; // Discard this. It does not match provided filter.
269 }
270
271 $found++;
272 // Define relative path for download link (depends on module)
273 $relativepath = $file["name"]; // Cas general
274 if ($modulesubdir) {
275 $relativepath = $modulesubdir . "/" . $file["name"]; // Cas propal, facture...
276 }
277 // Autre cas
278 if ($modulepart == 'donation') {
279 $relativepath = get_exdir($modulesubdir, 2, 0, 0, null, 'donation') . $file["name"];
280 }
281 if ($modulepart == 'export') {
282 $relativepath = $file["name"];
283 }
284
285 $this->infofiles['nboffiles']++;
286 $this->infofiles['files'][] = $file['fullname'];
287 $ext = pathinfo($file["name"], PATHINFO_EXTENSION);
288 if (empty($this->infofiles['extensions'][$ext])) {
289 $this->infofiles['extensions'][$ext] = 1;
290 } else {
291 // @phan-suppress-next-line PhanTypeInvalidDimOffset
292 $this->infofiles['extensions'][$ext]++;
293 }
294
295 // Download
296 $url = $context->getControllerUrl('document') . '&modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($relativepath) . '&soc_id=' . $context->logged_thirdparty->id;
297
298 $tmpout .= '<a href="' . $url . '" class="btn-download-link ' . $morecss . '" role="downloadlink"';
299 $mime = dol_mimetype($relativepath, '', 0);
300 if (preg_match('/text/', $mime)) {
301 $tmpout .= ' target="_blank" rel="noopener noreferrer"';
302 }
303 $tmpout .= '>';
304 $tmpout .= img_mime($relativepath, $file["name"]);
305 $tmpout .= strtoupper($ext);
306 $tmpout .= '</a>';
307 }
308
309 if ($found) {
310 $out .= $tmpout;
311 }
312 }
313
314 return $out;
315 }
316
327 public function getSignatureLink($modulepart, $object, $morecss = '')
328 {
329 global $langs;
330 require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
331 $out = '<!-- html.formwebportal::getSignatureLink -->' . "\n";
332 $url = getOnlineSignatureUrl(0, $modulepart, $object->ref, 1, $object);
333 if (!empty($url)) {
334 $out .= '<a target="_blank" rel="noopener noreferrer" href="' . $url . '"' . ($morecss ? ' class="' . $morecss . '"' : '') . ' role="signaturelink">';
335 $out .= '<i class="fa fa-file-signature"></i>';
336 $out .= $langs->trans("Sign");
337 $out .= '</a>';
338 }
339 return $out;
340 }
341
362 public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
363 {
364 global $conf;
365
366 $objecttmp = null;
367
368 // Example of value for $objectdec:
369 // Bom:bom/class/bom.class.php:0:t.status=1
370 // Bom:bom/class/bom.class.php:0:t.status=1:ref
371 // Bom:bom/class/bom.class.php:0:(t.status:=:1):ref
372 $InfoFieldList = explode(":", $objectdesc, 4);
373 $vartmp = (empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]);
374 $reg = array();
375 if (preg_match('/^.*:(\w*)$/', $vartmp, $reg)) {
376 $InfoFieldList[4] = $reg[1]; // take the sort field
377 }
378 $InfoFieldList[3] = preg_replace('/:\w*$/', '', $vartmp); // take the filter field
379
380 $classname = $InfoFieldList[0];
381 $classpath = $InfoFieldList[1];
382 $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3];
383 $sortfield = empty($InfoFieldList[4]) ? '' : $InfoFieldList[4];
384 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
426 public function showInputFieldForObject($object, $val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
427 {
428 // TODO Replace code with
429 //return $object->showInputField($val, $key, $value, '', '', '', 0);
430
431 global $conf, $langs;
432
433 $out = '';
434 $param = array();
435 $reg = array();
436 $size = !empty($val['size']) ? $val['size'] : 0;
437 // see common object class
438 if (preg_match('/^(integer|link):(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
439 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] . ':' . $reg[5] => 'N');
440 $type = 'link';
441 } elseif (preg_match('/^(integer|link):(.*):(.*):(.*)/i', $val['type'], $reg)) {
442 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
443 $type = 'link';
444 } elseif (preg_match('/^(integer|link):(.*):(.*)/i', $val['type'], $reg)) {
445 $param['options'] = array($reg[2] . ':' . $reg[3] => 'N');
446 $type = 'link';
447 } elseif (preg_match('/^(sellist):(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
448 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] . ':' . $reg[5] => 'N');
449 $type = 'sellist';
450 } elseif (preg_match('/^(sellist):(.*):(.*):(.*)/i', $val['type'], $reg)) {
451 $param['options'] = array($reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
452 $type = 'sellist';
453 } elseif (preg_match('/^(sellist):(.*):(.*)/i', $val['type'], $reg)) {
454 $param['options'] = array($reg[2] . ':' . $reg[3] => 'N');
455 $type = 'sellist';
456 } elseif (preg_match('/^varchar\‍((\d+)\‍)/', $val['type'], $reg)) {
457 $param['options'] = array();
458 $type = 'text';
459 $size = $reg[1];
460 } elseif (preg_match('/^varchar/', $val['type'])) {
461 $param['options'] = array();
462 $type = 'text';
463 } elseif (preg_match('/^double(\‍([0-9],[0-9]\‍)){0,1}/', $val['type'])) {
464 $param['options'] = array();
465 $type = 'double';
466 } else {
467 $param['options'] = array();
468 $type = $val['type'];
469 }
470
471 // Special case that force options and type ($type can be integer, varchar, ...)
472 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
473 $param['options'] = $val['arrayofkeyval'];
474 $type = $val['type'] == 'checkbox' ? 'checkbox' : 'select';
475 }
476
477 //$label = $val['label'];
478 $default = (!empty($val['default']) ? $val['default'] : '');
479 $computed = (!empty($val['computed']) ? $val['computed'] : '');
480 //$unique = (!empty($val['unique']) ? $val['unique'] : 0);
481 $required = (!empty($val['required']) ? $val['required'] : 0);
482 $notNull = (!empty($val['notnull']) ? $val['notnull'] : 0);
483
484 //$langfile = (!empty($val['langfile']) ? $val['langfile'] : '');
485 //$list = (!empty($val['list']) ? $val[$key]['list'] : 0);
486 $hidden = (in_array(abs($val['visible']), array(0, 2)) ? 1 : 0);
487
488 //$objectid = $this->id;
489
490 if ($computed) {
491 if (!preg_match('/^search_/', $keyprefix)) {
492 return '<span>' . $langs->trans("AutomaticallyCalculated") . '</span>';
493 } else {
494 return '';
495 }
496 }
497
498 // Set value of $morecss. For this, we use in priority showsize from parameters, then $val['css'] then autodefine
499 if (empty($morecss) && !empty($val['css'])) {
500 $morecss = $val['css'];
501 }
502
503 $htmlName = $keyprefix . $key . $keysuffix;
504 $htmlId = $htmlName;
505 //$moreparam .= (!empty($required) ? ' required' : '');
506 switch ($type) {
507 case 'date':
508 case 'datetime':
509 // separate value YYYY-MM-DD HH:ii:ss to date and time
510 $valueDate = '';
511 $valueTime = '';
512 $dateArr = explode(' ', $value);
513 if (count($dateArr) > 0) {
514 $valueDate = $dateArr[0];
515 if (isset($dateArr[1])) {
516 $valueTime = $dateArr[1];
517 }
518 }
519 $out = $this->inputDate($htmlName, $valueDate, '', $htmlId, $morecss, $moreparam);
520
521 if ($type == 'datetime') {
522 //$moreparam .= ' step="1"'; to show seconds
523 $out .= ' ' . $this->inputType('time', $htmlName.'_time', $valueTime, $htmlId, $morecss, $moreparam);
524 }
525 break;
526
527 case 'integer':
528 $out = $this->inputType('number', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
529 break;
530
531 case 'text':
532 case 'html':
533 $moreparam .= ($size > 0 ? ' maxlength="' . $size . '"' : '');
534 $out = $this->inputType('text', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
535 break;
536
537 case 'email':
538 $out = $this->inputType('email', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
539 break;
540
541 case 'tel':
542 $out = $this->inputType('tel', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
543 break;
544
545 case 'phone':
546 if (preg_match('/^search_/', $keyprefix)) {
547 $out = $this->inputType('text', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
548 } else {
549 $out = $this->showPhoneInput($value, $htmlName, !empty($object->country_id) ? $object->country_id : 0);
550 }
551 break;
552
553 case 'url':
554 $out = $this->inputType('url', $htmlName, dol_escape_htmltag($value), $htmlId, $morecss, $moreparam);
555 break;
556
557 case 'price':
558 if (!empty($value)) {
559 $value = price($value); // $value in memory is a php numeric, we format it into user number format.
560 }
561 $addInputLabel = ' ' . $langs->getCurrencySymbol();
562 $out = $this->inputType('text', $htmlName, $value, $htmlId, $morecss, $moreparam, '', $addInputLabel);
563 break;
564
565 case 'double':
566 if (!empty($value)) {
567 $value = price($value); // $value in memory is a php numeric, we format it into user number format.
568 }
569 $out = $this->inputType('text', $htmlName, $value, $htmlId, $morecss, $moreparam);
570 break;
571
572 case 'password':
573 $out = $this->inputType('password', $htmlName, $value, $htmlId, $morecss, $moreparam);
574 break;
575
576 case 'radio':
577 foreach ($param['options'] as $keyopt => $valopt) {
578 $htmlId = $htmlName . '_' . $keyopt;
579 $htmlMoreParam = $moreparam . ($value == $keyopt ? ' checked' : '');
580 $out .= $this->inputType('radio', $htmlName, $keyopt, $htmlId, $morecss, $htmlMoreParam, $valopt) . '<br>';
581 }
582 break;
583
584 case 'select':
585 $out = '<select class="' . $morecss . '" name="' . $htmlName . '" id="' . $htmlId . '"' . ($moreparam ? ' ' . $moreparam : '') . ' >';
586 if ($default == '' || $notNull != 1) {
587 $out .= '<option value="0">&nbsp;</option>';
588 }
589 foreach ($param['options'] as $keyb => $valb) {
590 if ($keyb == '') {
591 continue;
592 }
593 if (strpos($valb, "|") !== false) {
594 list($valb, $parent) = explode('|', $valb);
595 }
596 $out .= '<option value="' . $keyb . '"';
597 $out .= (((string) $value == $keyb) ? ' selected' : '');
598 $out .= (!empty($parent) ? ' parent="' . $parent . '"' : '');
599 $out .= '>' . $valb . '</option>';
600 }
601 $out .= '</select>';
602 break;
603 case 'sellist':
604 $out = '<select class="' . $morecss . '" name="' . $htmlName . '" id="' . $htmlId . '"' . ($moreparam ? ' ' . $moreparam : '') . '>';
605
606 $param_list = array_keys($param['options']);
607 $InfoFieldList = explode(":", $param_list[0]);
608 $parentName = '';
609 $parentField = '';
610 // 0 : tableName
611 // 1 : label field name
612 // 2 : key fields name (if differ of rowid)
613 // 3 : key field parent (for dependent lists)
614 // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
615 // 5 : id category type
616 // 6 : ids categories list separated by comma for category root
617 $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid');
618
619 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
620 if (strpos($InfoFieldList[4], 'extra.') !== false) {
621 $keyList = 'main.' . $InfoFieldList[2] . ' as rowid';
622 } else {
623 $keyList = $InfoFieldList[2] . ' as rowid';
624 }
625 }
626 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
627 list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
628 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4], 'extra.') !== false) {
629 $keyList .= ', main.'.$parentField;
630 } else {
631 $keyList .= ', '.$parentField;
632 }
633 }
634
635 $filter_categorie = false;
636 if (count($InfoFieldList) > 5) {
637 if ($InfoFieldList[0] == 'categorie') {
638 $filter_categorie = true;
639 }
640 }
641
642 if (!$filter_categorie) {
643 $fields_label = isset($InfoFieldList[1]) ? explode('|', $InfoFieldList[1]) : array();
644 if (!empty($fields_label)) {
645 $keyList .= ', ';
646 $keyList .= implode(', ', $fields_label);
647 }
648
649 $sqlwhere = '';
650 $sql = "SELECT " . $this->db->sanitize($keyList, 0, 0, 1);
651 $sql .= " FROM " . $this->db->prefix() . $this->db->sanitize($InfoFieldList[0]);
652 if (!empty($InfoFieldList[4])) {
653 // can use SELECT request
654 if (strpos($InfoFieldList[4], '$SEL$') !== false) {
655 $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]);
656 }
657
658 // current object id can be use into filter
659 $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]);
660
661 //We have to join on extrafield table
662 if (strpos($InfoFieldList[4], 'extra') !== false) {
663 $sql .= " as main, " . $this->db->prefix() . $this->db->sanitize($InfoFieldList[0]) . "_extrafields as extra";
664 // We trust this argument `$InfoFieldList[4]` @phan-suppress-next-line SqlInjection
665 $sqlwhere .= " WHERE extra.fk_object=main." . $this->db->sanitize($InfoFieldList[2]) . " AND " . $InfoFieldList[4];
666 } else {
667 // We trust this argument `$InfoFieldList[4]` @phan-suppress-next-line SqlInjection
668 $sqlwhere .= " WHERE " . $InfoFieldList[4];
669 }
670 } else {
671 $sqlwhere .= ' WHERE 1=1';
672 }
673 // Some tables may have field, some other not. For the moment we disable it.
674 if (in_array($InfoFieldList[0], array('tablewithentity'))) {
675 $sqlwhere .= " AND entity = " . ((int) $conf->entity);
676 }
677 $sql .= $sqlwhere;
678 //print $sql;
679
680 $sql .= ' ORDER BY ' . implode(', ', $fields_label);
681
682 dol_syslog(get_class($this) . '::showInputField type=sellist', LOG_DEBUG);
683 $resql = $this->db->query($sql);
684 if ($resql) {
685 $out .= '<option value="0">&nbsp;</option>';
686 $num = $this->db->num_rows($resql);
687 $i = 0;
688 while ($i < $num) {
689 $labeltoshow = '';
690 $obj = $this->db->fetch_object($resql);
691
692 // Several field into label (eq table:code|libelle:rowid)
693 $notrans = false;
694 $fields_label = explode('|', $InfoFieldList[1]);
695 if (count($fields_label) > 1) {
696 $notrans = true;
697 foreach ($fields_label as $field_toshow) {
698 $labeltoshow .= $obj->$field_toshow . ' ';
699 }
700 } else {
701 $labeltoshow = $obj->{$InfoFieldList[1]};
702 }
703 $labeltoshow = dol_trunc($labeltoshow, 45);
704
705 if ($value == $obj->rowid) {
706 foreach ($fields_label as $field_toshow) {
707 $translabel = $langs->trans($obj->$field_toshow);
708 if ($translabel != $obj->$field_toshow) {
709 $labeltoshow = dol_trunc($translabel) . ' ';
710 } else {
711 $labeltoshow = dol_trunc($obj->$field_toshow) . ' ';
712 }
713 }
714 $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>';
715 } else {
716 if (!$notrans) {
717 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
718 if ($translabel != $obj->{$InfoFieldList[1]}) {
719 $labeltoshow = dol_trunc($translabel, 18);
720 } else {
721 $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]});
722 }
723 }
724 if (empty($labeltoshow)) {
725 $labeltoshow = '(not defined)';
726 }
727 if ($value == $obj->rowid) {
728 $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>';
729 }
730
731 if (!empty($InfoFieldList[3]) && $parentField) {
732 $parent = $parentName . ':' . $obj->{$parentField};
733 $isDependList = 1;
734 }
735
736 $out .= '<option value="' . $obj->rowid . '"';
737 $out .= ($value == $obj->rowid ? ' selected' : '');
738 $out .= (!empty($parent) ? ' parent="' . $parent . '"' : '');
739 $out .= '>' . $labeltoshow . '</option>';
740 }
741
742 $i++;
743 }
744 $this->db->free($resql);
745 } else {
746 $out .= 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>';
747 }
748 } else {
749 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
750 $categorytype = $InfoFieldList[5];
751 if (is_numeric($categorytype)) { // deprecated: must use the category code instead of id. For backward compatibility.
752 $tmpcategory = new Categorie($this->db);
753 $MAP_ID_TO_CODE = array_flip($tmpcategory->MAP_ID);
754 $categorytype = $MAP_ID_TO_CODE[(int) $categorytype];
755 }
756
757 $data = $this->select_all_categories($categorytype, '', 'parent', 64, $InfoFieldList[6], 1, 1);
758 $out .= '<option value="0">&nbsp;</option>';
759 foreach ($data as $data_key => $data_value) {
760 $out .= '<option value="' . $data_key . '"';
761 $out .= ($value == $data_key ? ' selected' : '');
762 $out .= '>' . $data_value . '</option>';
763 }
764 }
765 $out .= '</select>';
766 break;
767
768 case 'link':
769 $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter[:Sortfield]]]'
770 $showempty = (($required && $default != '') ? '0' : '1');
771
772 $out = $this->selectForForms($param_list[0], $htmlName, (int) $value, $showempty, '', '', $morecss, $moreparam, 0, empty($val['disabled']) ? 0 : 1);
773
774 break;
775
776 default:
777 if (!empty($hidden)) {
778 $out = $this->inputType('hidden', $htmlName, $value, $htmlId);
779 }
780 break;
781 }
782
783 return $out;
784 }
785
799 public function showOutputFieldForObject($object, $val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
800 {
801 // TODO Replace code with
802 //return $object->showOutputField($val, $key, $value, '', '', '', 0);
803 // We must just implement different case like output a ref that must not include the link into backoffice
804
805 global $conf, $langs;
806
807 $label = empty($val['label']) ? '' : $val['label'];
808 $type = empty($val['type']) ? '' : $val['type'];
809 $css = empty($val['css']) ? '' : $val['css'];
810 $picto = empty($val['picto']) ? '' : $val['picto'];
811 $reg = array();
812
813 // Convert var to be able to share same code than showOutputField of extrafields
814 if (preg_match('/varchar\‍((\d+)\‍)/', $type, $reg)) {
815 $type = 'varchar'; // convert varchar(xx) int varchar
816 $css = $reg[1];
817 } elseif (preg_match('/varchar/', $type)) {
818 $type = 'varchar'; // convert varchar(xx) int varchar
819 }
820 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
821 $type = $val['type'] == 'checkbox' ? 'checkbox' : 'select';
822 }
823 if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
824 $type = 'link';
825 }
826
827 $default = empty($val['default']) ? '' : $val['default'];
828 $computed = empty($val['computed']) ? '' : $val['computed'];
829 $unique = empty($val['unique']) ? '' : $val['unique'];
830 $required = empty($val['required']) ? '' : $val['required'];
831 $param = array();
832 $param['options'] = array();
833
834 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
835 $param['options'] = $val['arrayofkeyval'];
836 }
837 if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
838 $type = 'link';
839 $stringforoptions = $reg[1] . ':' . $reg[2];
840 if ($reg[1] == 'User') {
841 $stringforoptions .= ':-1';
842 }
843 $param['options'] = array($stringforoptions => $stringforoptions);
844 } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
845 $param['options'] = array($reg[1] . ':' . $reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N');
846 $type = 'sellist';
847 } elseif (preg_match('/^sellist:(.*):(.*):(.*)/i', $val['type'], $reg)) {
848 $param['options'] = array($reg[1] . ':' . $reg[2] . ':' . $reg[3] => 'N');
849 $type = 'sellist';
850 } elseif (preg_match('/^sellist:(.*):(.*)/i', $val['type'], $reg)) {
851 $param['options'] = array($reg[1] . ':' . $reg[2] => 'N');
852 $type = 'sellist';
853 } elseif (preg_match('/^chkbxlst:(.*)/i', $val['type'], $reg)) {
854 $param['options'] = array($reg[1] => 'N');
855 $type = 'chkbxlst';
856 }
857
858 $langfile = empty($val['langfile']) ? '' : $val['langfile'];
859 $list = (empty($val['list']) ? '' : $val['list']);
860 $help = (empty($val['help']) ? '' : $val['help']);
861 $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)
862
863 if ($hidden) {
864 return '';
865 }
866
867 // If field is a computed field, value must become result of compute
868 if ($computed) {
869 // Make the eval of compute string
870 //var_dump($computed);
871 $value = (string) dol_eval((string) $computed, 1, 0, '2');
872 }
873
874 // Format output value differently according to properties of field
875 //
876 // First the cases that do not use $value from the arguments:
877 //
878 if (in_array($key, array('rowid', 'ref'))) {
879 if (property_exists($object, 'ref')) {
880 $value = (string) $object->ref;
881 } elseif (property_exists($object, 'id')) {
882 $value = $object->id;
883 } else {
884 $value = '';
885 }
886 } elseif ($key == 'status' && method_exists($object, 'getLibStatut')) {
887 $value = $object->getLibStatut(3);
888 //
889 // Then the cases where $value is an array
890 //
891 } elseif (is_array($value)) {
892 // Handle array early to get type identification solve for static
893 // analysis
894 if ($type == 'array') {
895 $value = implode('<br>', $value);
896 } else {
897 dol_syslog(__METHOD__."Unexpected type=".$type." for array value=".((string) json_encode($value)), LOG_ERR);
898 }
899 //
900 // Then the cases where $value is not an array (hence string)
901 //
902 } elseif ($type == 'date') {
903 if (!empty($value)) {
904 $value = dol_print_date($value, 'day'); // We suppose dates without time are always gmt (storage of course + output)
905 } else {
906 $value = '';
907 }
908 } elseif ($type == 'datetime' || $type == 'timestamp') {
909 if (!empty($value)) {
910 $value = dol_print_date($value, 'dayhour', 'tzuserrel');
911 } else {
912 $value = '';
913 }
914 } elseif ($type == 'duration') {
915 include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
916 if (!is_null($value) && $value !== '') {
917 $value = convertSecondToTime((int) $value, 'allhourmin');
918 } else {
919 // Resulting type must be string
920 $value = '';
921 }
922 } elseif ($type == 'double' || $type == 'real') {
923 if (!is_null($value) && $value !== '') {
924 $value = price($value);
925 } else {
926 // Resulting type must be string
927 $value = '';
928 }
929 } elseif ($type == 'boolean') {
930 $checked = '';
931 if (!empty($value)) {
932 $checked = ' checked ';
933 }
934 $value = '<input type="checkbox" ' . $checked . ' ' . ($moreparam ? $moreparam : '') . ' readonly disabled>';
935 } elseif ($type == 'mail' || $type == 'email') {
936 $value = dol_print_email($value, 0, 0, 0, 64, 1, 1);
937 } elseif ($type == 'url') {
938 $value = dol_print_url($value, '_blank', 32, 1);
939 } elseif ($type == 'phone') {
940 $value = dol_print_phone($value, '', 0, 0, '', '&nbsp;', 'phone');
941 } elseif ($type == 'ip') {
942 $value = dol_print_ip($value, 0);
943 } elseif ($type == 'price') {
944 if (!is_null($value) && $value !== '') {
945 $value = price($value, 0, $langs, 0, 0, -1, getDolCurrency());
946 } else {
947 // Resulting type must be string
948 $value = '';
949 }
950 } elseif ($type == 'select') {
951 $value = isset($param['options'][$value]) ? $param['options'][$value] : '';
952 } elseif ($type == 'sellist') {
953 $param_list = array_keys($param['options']);
954 $InfoFieldList = explode(":", $param_list[0]);
955
956 $selectkey = "rowid";
957 $keyList = 'rowid';
958
959 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
960 $selectkey = $InfoFieldList[2];
961 $keyList = $InfoFieldList[2] . ' as rowid';
962 }
963
964 $fields_label = explode('|', $InfoFieldList[1]);
965 if (is_array($fields_label)) {
966 $keyList .= ', ';
967 $keyList .= implode(', ', $fields_label);
968 }
969
970 $filter_categorie = false;
971 if (count($InfoFieldList) > 5) {
972 if ($InfoFieldList[0] == 'categorie') {
973 $filter_categorie = true;
974 }
975 }
976
977 $sql = "SELECT " . $this->db->sanitize($keyList);
978 $sql .= ' FROM ' . $this->db->prefix() . $this->db->sanitize($InfoFieldList[0]);
979 if (strpos($InfoFieldList[4], 'extra') !== false) {
980 $sql .= ' as main';
981 }
982 if ($selectkey == 'rowid' && empty($value)) {
983 $sql .= " WHERE " . $this->db->sanitize($selectkey) . " = 0";
984 } elseif ($selectkey == 'rowid') {
985 $sql .= " WHERE " . $this->db->sanitize($selectkey) . " = " . ((int) $value);
986 } else {
987 $sql .= " WHERE " . $this->db->sanitize($selectkey) . " = '" . $this->db->escape($value) . "'";
988 }
989
990 dol_syslog(__METHOD__ . ' type=sellist', LOG_DEBUG);
991 $resql = $this->db->query($sql);
992 if ($resql) {
993 if (!$filter_categorie) {
994 $value = ''; // value was used, so now we reset it to use it to build final output
995 $numrows = $this->db->num_rows($resql);
996 if ($numrows) {
997 $obj = $this->db->fetch_object($resql);
998
999 // Several field into label (eq table:code|libelle:rowid)
1000 $fields_label = explode('|', $InfoFieldList[1]);
1001
1002 if (is_array($fields_label) && count($fields_label) > 1) {
1003 foreach ($fields_label as $field_toshow) {
1004 $translabel = '';
1005 if (!empty($obj->$field_toshow)) {
1006 $translabel = $langs->trans($obj->$field_toshow);
1007 }
1008 if ($translabel != $field_toshow) {
1009 $value .= dol_trunc($translabel, 18) . ' ';
1010 } else {
1011 $value .= $obj->$field_toshow . ' ';
1012 }
1013 }
1014 } else {
1015 $translabel = '';
1016 if (!empty($obj->{$InfoFieldList[1]})) {
1017 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1018 }
1019 if ($translabel != $obj->{$InfoFieldList[1]}) {
1020 $value = dol_trunc($translabel, 18);
1021 } else {
1022 $value = $obj->{$InfoFieldList[1]};
1023 }
1024 }
1025 }
1026 } else {
1027 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1028
1029 $toprint = array();
1030 $obj = $this->db->fetch_object($resql);
1031 $c = new Categorie($this->db);
1032 $c->fetch($obj->rowid);
1033 $ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
1034 foreach ($ways as $way) {
1035 $toprint[] = '<li>' . img_object('', 'category') . ' ' . $way . '</li>';
1036 }
1037 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1038 }
1039 } else {
1040 dol_syslog(__METHOD__ . ' error ' . $this->db->lasterror(), LOG_WARNING);
1041 }
1042 } elseif ($type == 'radio') {
1043 $value = (string) $param['options'][$value];
1044 } elseif ($type == 'checkbox') {
1045 $value_arr = explode(',', $value);
1046 $value = '';
1047 if (is_array($value_arr) && count($value_arr) > 0) {
1048 $toprint = array();
1049 foreach ($value_arr as $valueval) {
1050 if (!empty($valueval)) {
1051 $toprint[] = '<li>' . $param['options'][$valueval] . '</li>';
1052 }
1053 }
1054 if (!empty($toprint)) {
1055 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1056 }
1057 }
1058 } elseif ($type == 'chkbxlst') {
1059 $value_arr = explode(',', $value);
1060
1061 $param_list = array_keys($param['options']);
1062 $InfoFieldList = explode(":", $param_list[0]);
1063
1064 $selectkey = "rowid";
1065 $keyList = 'rowid';
1066
1067 if (count($InfoFieldList) >= 3) {
1068 $selectkey = $InfoFieldList[2];
1069 $keyList = $InfoFieldList[2] . ' as rowid';
1070 }
1071
1072 $fields_label = explode('|', $InfoFieldList[1]);
1073 if (is_array($fields_label)) {
1074 $keyList .= ', ';
1075 $keyList .= implode(', ', $fields_label);
1076 }
1077
1078 $filter_categorie = false;
1079 if (count($InfoFieldList) > 5) {
1080 if ($InfoFieldList[0] == 'categorie') {
1081 $filter_categorie = true;
1082 }
1083 }
1084
1085 $sql = "SELECT " . $this->db->sanitize($keyList);
1086 $sql .= ' FROM ' . $this->db->prefix() . $this->db->sanitize($InfoFieldList[0]);
1087 if (strpos($InfoFieldList[4], 'extra') !== false) {
1088 $sql .= ' as main';
1089 }
1090 // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'";
1091 // $sql.= ' AND entity = '.((int) $conf->entity);
1092
1093 dol_syslog(__METHOD__ . ' type=chkbxlst', LOG_DEBUG);
1094 $resql = $this->db->query($sql);
1095 if ($resql) {
1096 if (!$filter_categorie) {
1097 $value = ''; // value was used, so now we reset it to use it to build final output
1098 $toprint = array();
1099 while ($obj = $this->db->fetch_object($resql)) {
1100 // Several field into label (eq table:code|libelle:rowid)
1101 $fields_label = explode('|', $InfoFieldList[1]);
1102 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1103 if (is_array($fields_label) && count($fields_label) > 1) {
1104 foreach ($fields_label as $field_toshow) {
1105 $translabel = '';
1106 if (!empty($obj->$field_toshow)) {
1107 $translabel = $langs->trans($obj->$field_toshow);
1108 }
1109 if ($translabel != $field_toshow) {
1110 $toprint[] = '<li>' . dol_trunc($translabel, 18) . '</li>';
1111 } else {
1112 $toprint[] = '<li>' . $obj->$field_toshow . '</li>';
1113 }
1114 }
1115 } else {
1116 $translabel = '';
1117 if (!empty($obj->{$InfoFieldList[1]})) {
1118 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1119 }
1120 if ($translabel != $obj->{$InfoFieldList[1]}) {
1121 $toprint[] = '<li>' . dol_trunc($translabel, 18) . '</li>';
1122 } else {
1123 $toprint[] = '<li>' . $obj->{$InfoFieldList[1]} . '</li>';
1124 }
1125 }
1126 }
1127 }
1128 } else {
1129 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1130
1131 $toprint = array();
1132 while ($obj = $this->db->fetch_object($resql)) {
1133 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1134 $c = new Categorie($this->db);
1135 $c->fetch($obj->rowid);
1136 $ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
1137 foreach ($ways as $way) {
1138 $toprint[] = '<li>' . img_object('', 'category') . ' ' . $way . '</li>';
1139 }
1140 }
1141 }
1142 }
1143 $value = '<div><ul>' . implode(' ', $toprint) . '</ul></div>';
1144 } else {
1145 dol_syslog(__METHOD__ . ' error ' . $this->db->lasterror(), LOG_WARNING);
1146 }
1147 } elseif ($type == 'link') {
1148 // only if something to display (perf)
1149 if ($value) {
1150 $param_list = array_keys($param['options']); // Example: $param_list='ObjectName:classPath:-1::customer'
1151
1152 $InfoFieldList = explode(":", $param_list[0]);
1153 $classname = $InfoFieldList[0];
1154 $classpath = $InfoFieldList[1];
1155 if (!empty($classpath)) {
1156 dol_include_once($InfoFieldList[1]);
1157 if ($classname && class_exists($classname)) {
1158 $object = new $classname($this->db);
1159 '@phan-var-force CommonObject $object';
1161 $result = $object->fetch($value);
1162 $value = '';
1163 if ($result > 0) {
1164 if (property_exists($object, 'label')) {
1165 $value = (string) $object->label; // @phan-suppress-current-line PhanUndeclaredProperty
1166 } elseif (property_exists($object, 'libelle')) {
1167 $value = (string) $object->libelle; // @phan-suppress-current-line PhanUndeclaredProperty
1168 } elseif (property_exists($object, 'nom')) {
1169 $value = (string) $object->nom; // @phan-suppress-current-line PhanUndeclaredProperty
1170 } elseif (property_exists($object, 'ref')) {
1171 $value = (string) $object->ref; // @phan-suppress-current-line PhanUndeclaredProperty
1172 }
1173 }
1174 }
1175 } else {
1176 dol_syslog(__METHOD__ . ' Error bad setup of field', LOG_WARNING);
1177 return 'Error bad setup of field';
1178 }
1179 } else {
1180 $value = '';
1181 }
1182 } elseif ($type == 'password') {
1183 $value = preg_replace('/./i', '*', $value);
1184 } else { // text|html|varchar
1185 $value = dol_htmlentitiesbr($value);
1186 }
1187
1188 $out = $value;
1189
1190 return $out;
1191 }
1192
1206 public function inputType($type, $name, $value = '', $id = '', $morecss = '', $moreparam = '', $label = '', $addInputLabel = '')
1207 {
1208 $out = '';
1209 if ($label != '') {
1210 $out .= '<label for="' . dolPrintHTMLForAttribute($id) . '">';
1211 }
1212 $out .= '<input type="' . dolPrintHTMLForAttribute($type) . '"';
1213 $out .= ' class="flat valignmiddle maxwidthonsmartphone ' . dolPrintHTMLForAttribute($morecss) . '"';
1214 if ($id != '') {
1215 $out .= ' id="' . dolPrintHTMLForAttribute($id) . '"';
1216 }
1217 $out .= ' name="' . dolPrintHTMLForAttribute($name) . '"';
1218 $out .= ' value="' . dolPrintHTMLForAttribute($value) . '" ';
1219 $out .= ($moreparam ? ' ' . $moreparam : '');
1220 $out .= ' />' . $addInputLabel;
1221 if ($label != '') {
1222 $out .= $label . '</label>';
1223 }
1224
1225 return $out;
1226 }
1227
1240 public function inputSelectAjax($htmlName, $array, $id, $ajaxUrl, $ajaxData = [], $morecss = 'minwidth75', $moreparam = '')
1241 {
1242 $out = "
1243 <script>
1244 $(document).ready(function () {
1245 $('#" . dol_escape_js($htmlName) . "').select2({
1246 ajax: {
1247 url: '" . dol_escape_js($ajaxUrl) . "',
1248 dataType: 'json',
1249 delay: 250, // wait 250 milliseconds before triggering the request
1250 data: function (params) {
1251 var query = {
1252 search: params.term,
1253 page: params.page || 1";
1254 if (!empty($ajaxData) && is_array($ajaxData)) {
1255 foreach ($ajaxData as $key => $value) {
1256 $out .= ", " . preg_replace('/[^a-z0-9_]/i', '', $key) . ": '" . dol_escape_js($value) . "'";
1257 }
1258 }
1259 $out .= "
1260 }
1261 return query;
1262 }
1263 }
1264 })
1265 });
1266 </script>";
1267
1268 $out .= $this->selectarray($htmlName, $array, $id, 0, 0, 0, $moreparam, 0, 0, 0, '', $morecss);
1269
1270 return $out;
1271 }
1272
1282 public function inputHtml($htmlName, $value, $morecss = '', $moreparam = '')
1283 {
1284 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
1285 $doleditor = new DolEditor($htmlName, $value, '', 200, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_5, '90%');
1286
1287 return (string) $doleditor->Create(1, '', true, '', '', $moreparam, $morecss);
1288 }
1289
1300 public function inputText($htmlName, $value, $morecss = '', $moreparam = '', $options = array())
1301 {
1302 global $langs;
1303 $out = '';
1304 if (!empty($options)) {
1305 // If the textarea field has a list of arrayofkeyval into its definition, we suggest a combo with possible values to fill the textarea.
1306 $out .= '<div class="text-area-multi-input-add-group" >';
1307 $out .= $this->selectarray($htmlName . "_multiinput", $options, '', 1, 0, 0, $moreparam, 0, 0, 0, '', "flat maxwidthonphone" . $morecss);
1308 $out .= '<input id="' . $htmlName . '_multiinputadd" type="button" class="button" value="' . $langs->trans("Add") . '">';
1309 $out .= '</div>';
1310 $out .= "<script>";
1311 $out .= '
1312 function handlemultiinputdisabling(htmlname){
1313 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
1314 multiinput = $("#"+htmlname+"_multiinput");
1315 multiinput.find("option").each(function(){
1316 tmpval = $("#"+htmlname).val();
1317 tmpvalarray = tmpval.split("\n");
1318 valtotest = $(this).val();
1319 if(tmpvalarray.includes(valtotest)){
1320 $(this).prop("disabled",true);
1321 } else {
1322 if($(this).prop("disabled") == true){
1323 console.log(valtotest)
1324 $(this).prop("disabled", false);
1325 }
1326 }
1327 });
1328 }
1329
1330 $(document).ready(function () {
1331 $("#' . $htmlName . '_multiinputadd").on("click",function() {
1332 tmpval = $("#' . $htmlName . '").val();
1333 tmpvalarray = tmpval.split(",");
1334 valtotest = $("#' . $htmlName . '_multiinput").val();
1335 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
1336 console.log("We add the selected value to the text area ' . $htmlName . '");
1337 if(tmpval == ""){
1338 tmpval = valtotest;
1339 } else {
1340 tmpval = tmpval + "\n" + valtotest;
1341 }
1342 $("#' . $htmlName . '").val(tmpval);
1343 handlemultiinputdisabling("' . $htmlName . '");
1344 $("#' . $htmlName . '_multiinput").val(-1);
1345 } else {
1346 console.log("We add nothing the text area ' . $htmlName . '");
1347 }
1348 });
1349 $("#' . $htmlName . '").on("change",function(){
1350 handlemultiinputdisabling("' . $htmlName . '");
1351 });
1352 handlemultiinputdisabling("' . $htmlName . '");
1353 })';
1354 $out .= "</script>";
1355 $value = str_replace(',', "\n", $value);
1356 }
1357
1358 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
1359 $doleditor = new DolEditor($htmlName, (string) $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5);
1360 $out .= (string) $doleditor->Create(1, '', true, '', '', $moreparam, $morecss);
1361
1362 return $out;
1363 }
1364
1375 public function inputRadio($htmlName, $options, $selectedValue, $morecss = '', $moreparam = '')
1376 {
1377 $out = '';
1378 foreach ($options as $optionKey => $optionLabel) {
1379 $selected = ((string) $selectedValue) === ((string) $optionKey) ? ' checked="checked"' : '';
1380 $optionId = $htmlName . '_' . $optionKey;
1381 $out .= '<input class="flat' . $morecss . '" type="radio" name="' . $htmlName . '" id="' . $optionId . '" value="' . dolPrintHTMLForAttribute((string) $optionKey) . '"' . $selected . $moreparam . '/><label for="' . $optionId . '">' . $optionLabel . '</label><br>';
1382 }
1383
1384 return $out;
1385 }
1386
1397 public function inputStars($htmlName, $size, $value, $morecss = '', $moreparam = '')
1398 {
1399 $out = '<input type="hidden" class="flat ' . $morecss . '" name="' . $htmlName . '" id="' . $htmlName . '" value="' . dolPrintHTMLForAttribute((string) $value) . '"' . $moreparam . '>';
1400 $out .= '<div class="star-selection" id="' . $htmlName . '_selection">';
1401 for ($i = 1; $i <= $size; $i++) {
1402 $out .= '<span class="star" data-value="' . $i . '">' . img_picto('', 'fontawesome_star_fas') . '</span>';
1403 }
1404 $out .= '</div>';
1405 $out .= '<script>
1406 jQuery(function($) { /* commonobject.class.php 1 */
1407 let container = $("#' . $htmlName . '_selection");
1408 let selectedStars = parseInt($("#' . $htmlName . '").val()) || 0;
1409 container.find(".star").each(function() {
1410 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
1411 });
1412 container.find(".star").on("mouseover", function() {
1413 let selectedStar = $(this).data("value");
1414 container.find(".star").each(function() {
1415 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
1416 });
1417 });
1418 container.on("mouseout", function() {
1419 container.find(".star").each(function() {
1420 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
1421 });
1422 });
1423 container.find(".star").off("click").on("click", function() {
1424 selectedStars = $(this).data("value");
1425 if (selectedStars === 1 && $("#' . $htmlName . '").val() == 1) {
1426 selectedStars = 0;
1427 }
1428 $("#' . $htmlName . '").val(selectedStars);
1429 container.find(".star").each(function() {
1430 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
1431 });
1432 });
1433 });
1434 </script>';
1435
1436 return $out;
1437 }
1438
1448 public function inputIcon($htmlName, $value, $morecss = '', $moreparam = '')
1449 {
1450 global $langs;
1451
1452 /* External lib inclusion are not allowed in backoffice. Also lib is included several time if there is several icon file.
1453 Some code must be added into main when MAIN_ADD_ICONPICKER_JS is set to add of lib in html header
1454 $out ='<link rel="stylesheet" href="'.dol_buildpath('/myfield/css/fontawesome-iconpicker.min.css', 1).'">';
1455 $out.='<script src="'.dol_buildpath('/myfield/js/fontawesome-iconpicker.min.js', 1).'"></script>';
1456 */
1457 $out = '<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat ' . $morecss . ' maxwidthonsmartphone"';
1458 $out .= ' name="' . $htmlName . '" id="' . $htmlName . '" value="' . dolPrintHTMLForAttribute((string) $value) . '" ' . ((string) $moreparam) . '>';
1459 if (getDolGlobalInt('MAIN_ADD_ICONPICKER_JS')) {
1460 $out .= '<script>';
1461 $options = "{ title: '<b>" . $langs->trans("IconFieldSelector") . "</b>', placement: 'right', showFooter: false, templates: {";
1462 $options .= "iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
1463 $options .= "iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
1464 // $options.="buttons: '<button style=\"background-color:#FFFFFF;\" class=\"iconpicker-btn iconpicker-btn-cancel btn btn-default btn-sm\">".$langs->trans("Cancel")."</button>";
1465 // $options.="<button style=\"background-color:#FFFFFF;\" class=\"iconpicker-btn iconpicker-btn-accept btn btn-primary btn-sm\">".$langs->trans("Save")."</button>',";
1466 $options .= "footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
1467 $options .= "search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"" . $langs->trans("TypeToFilter") . "\" />',";
1468 $options .= "popover: '<div class=\"iconpicker-popover popover\">";
1469 $options .= " <div class=\"arrow\" ></div>";
1470 $options .= " <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
1471 $options .= " <div class=\"popover-content \" ></div>";
1472 $options .= "</div>'}}";
1473 $out .= "$('#" . $htmlName . "').iconpicker(" . $options . ");";
1474 $out .= '</script>';
1475 }
1476
1477 return $out;
1478 }
1479
1488 public function inputGeoPoint($htmlName, $value, $type = '')
1489 {
1490 require_once DOL_DOCUMENT_ROOT . '/core/class/dolgeophp.class.php';
1491 require_once DOL_DOCUMENT_ROOT . '/core/class/geomapeditor.class.php';
1492 $dolgeophp = new DolGeoPHP($this->db);
1493 $geomapeditor = new GeoMapEditor();
1494
1495 $geojson = '{}';
1496 $centroidjson = getDolGlobalString('MAIN_INFO_SOCIETE_GEO_COORDINATES', '{}');
1497 if (!empty($value)) {
1498 $tmparray = $dolgeophp->parseGeoString($value);
1499 $geojson = $tmparray['geojson'];
1500 $centroidjson = $tmparray['centroidjson'];
1501 }
1502
1503 return $geomapeditor->getHtml($htmlName, $geojson, $centroidjson, $type);
1504 }
1505
1512 public function outputMultiValues($values)
1513 {
1514 $out = '';
1515 $toPrint = array();
1516 $values = is_array($values) ? $values : array();
1517
1518 foreach ($values as $value) {
1519 $toPrint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $value . '</li>';
1520 }
1521 if (!empty($toPrint)) {
1522 $out = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toPrint) . '</ul></div>';
1523 }
1524
1525 return $out;
1526 }
1527
1535 public function outputStars($size, $value)
1536 {
1537 $out = '<div class="star-selection" data-value="' . dolPrintHTMLForAttribute((string) $value) . '">';
1538 for ($i = 1; $i <= $size; $i++) {
1539 $out .= '<span class="star' . ($i <= $value ? ' active' : '') . '" data-value="' . $i . '">' . img_picto('', 'fontawesome_star_fas') . '</span>';
1540 }
1541 $out .= '</div>';
1542
1543 return $out;
1544 }
1545
1552 public function outputIcon($value)
1553 {
1554 $out = '<span class="' . dolPrintHTMLForAttribute((string) $value) . '"></span>';
1555
1556 return $out;
1557 }
1558
1566 public function outputGeoPoint($value, $type)
1567 {
1568 $out = '';
1569
1570 if (!empty($value)) {
1571 require_once DOL_DOCUMENT_ROOT . '/core/class/dolgeophp.class.php';
1572 $dolgeophp = new DolGeoPHP($this->db);
1573 if ($type == 'point') {
1574 $out = $dolgeophp->getXYString($value);
1575 } else { // multipts, linestrg, polygon
1576 $out = $dolgeophp->getPointString($value);
1577 }
1578 }
1579
1580 return $out;
1581 }
1582
1597 public function getNomUrl(&$object, $withpicto = 0, $option = '', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss = '', $add_label = 0, $sep = ' - ')
1598 {
1599 if (is_object($object) && method_exists($object, 'getNomUrl')) {
1600 $out = $object->getNomUrl($withpicto, $option, $maxlength, $save_lastsearch_value, $notooltip, $morecss, $add_label, $sep);
1601 $out = dol_string_nohtmltag($out);
1602 return $out;
1603 } else {
1604 return '';
1605 }
1606 }
1607
1626 public static function showphoto($modulepart, $object, $width = 100, $height = 0, $caneditfield = 0, $cssclass = 'photowithmargin', $imagesize = '', $addlinktofullsize = 1, $cache = 0, $forcecapture = '', $noexternsourceoverwrite = 0, $usesharelinkifavailable = 0)
1627 {
1628 $out = parent::showphoto($modulepart, $object, $width, $height, $caneditfield, $cssclass, $imagesize, $addlinktofullsize, $cache, $forcecapture, $noexternsourceoverwrite, $usesharelinkifavailable);
1629 $out = self::convertAllLink($out);
1630
1631 return $out;
1632 }
1633
1650 public function printFieldCell($key, $label, $value, $params = array())
1651 {
1652 $required = !empty($params['required']) ? ' required' : '';
1653 $cell_class = !empty($params['cell_class']) ? ' ' . dolPrintHTMLForAttribute(trim($params['cell_class'])) : '';
1654 $cell_attributes = !empty($params['cell_attributes']) ? ' ' . trim($params['cell_attributes']) : '';
1655 $label_class = !empty($params['label_class']) ? ' ' . dolPrintHTMLForAttribute(trim($params['label_class'])) : '';
1656 $label_attributes = !empty($params['label_attributes']) ? ' ' . trim($params['label_attributes']) : '';
1657 $value_class = !empty($params['value_class']) ? ' ' . dolPrintHTMLForAttribute(trim($params['value_class'])) : '';
1658 $value_attributes = !empty($params['value_attributes']) ? ' ' . trim($params['value_attributes']) : '';
1659
1660 $out = '<div class="grid field_' . dolPrintHTMLForAttribute(strtolower($key)) . $cell_class . '"' . $cell_attributes . '>';
1661 $out .= '<div class="' . $required . $label_class . '"' . $label_attributes . '>';
1662 $out .= $label;
1663 $out .= '</div>';
1664 $out .= '<div class="' . $value_class . '"' . $value_attributes . '>';
1665 $out .= $value;
1666 $out .= '</div>';
1667 $out .= '</div>';
1668
1669 return $out;
1670 }
1671
1680 public static function convertAllLink($html, $additionalViewImageParams = '', $additionalDocumentParams = '')
1681 {
1682 require_once DOL_DOCUMENT_ROOT . '/webportal/class/context.class.php';
1684
1685 $html = str_replace(DOL_URL_ROOT . '/viewimage.php?', $context->getControllerUrl('viewimage') . $additionalViewImageParams . '&', $html);
1686 $html = str_replace(urlencode(DOL_URL_ROOT . '/viewimage.php?'), urlencode($context->getControllerUrl('viewimage') . $additionalViewImageParams . '&'), $html);
1687 $html = str_replace(DOL_URL_ROOT . '/document.php?', $context->getControllerUrl('document') . $additionalDocumentParams . '&', $html);
1688 $html = str_replace(urlencode(DOL_URL_ROOT . '/document.php?'), urlencode($context->getControllerUrl('document') . $additionalDocumentParams . '&'), $html);
1689
1690 return $html;
1691 }
1692
1702 public function selectCurrency($selected = '', $htmlname = 'currency_id', $mode = 0, $useempty = '')
1703 {
1704
1705 return '<span class="form-select-currency-container">'.parent::selectCurrency($selected, $htmlname, $mode, $useempty).'</span>';
1706 }
1707}
$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:346
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.
showPhoneInput($phoneValue, $htmlname, $country_id_hint=0, $picto='object_phoning', $morecss='maxwidth150', $maxlength=0, $countrySelectorId='selectcountry_id')
Show a self-contained phone input: hidden field + country code dropdown + number text field + JS.
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:253
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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:65
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
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.
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.
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.
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.
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.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42