dolibarr 25.0.0-alpha
html.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
46function dolPrintLabel($s, $escapeonlyhtmltags = 0)
47{
48 return dol_escape_htmltag(dol_string_nohtmltag($s, 1, 'UTF-8', 0, 0), 0, 0, '', $escapeonlyhtmltags, 1);
49}
50
60function dolPrintText($s)
61{
62 return dol_escape_htmltag(dol_string_nohtmltag($s, 2, 'UTF-8', 0, 0), 0, 1, '', 0, 1);
63}
64
77function dolPrintHTML($s, $allowiframe = 0, $moreallowedtags = array())
78{
79 // If text is already HTML, we want to escape only dangerous chars else we want to escape all content.
80 //$isAlreadyHTML = dol_textishtml($s);
81
82 // dol_htmlentitiesbr encode all chars except "'" if string is not already HTML, but
83 // encode only special char like accented chars but not &, <, >, ", ' if already HTML.
84 $stringWithEntitesForSpecialChar = dol_htmlentitiesbr((string) $s);
85
86 $allowedtags = 'common';
87 if (!empty($moreallowedtags)) {
88 $allowedtags .= ','.implode(',', $moreallowedtags);
89 }
90 return dol_escape_htmltag(dol_htmlwithnojs(dol_string_onlythesehtmltags($stringWithEntitesForSpecialChar, 1, 1, 1, $allowiframe, $allowedtags)), 1, 1, $allowedtags, 0, 1);
91}
92
104function dolPrintHTMLForAttribute($s, $escapeonlyhtmltags = 0, $allowothertags = array())
105{
106 $allowedtags = array('br', 'b', 'font', 'hr', 'span');
107 if (!empty($allowothertags) && is_array($allowothertags)) {
108 $allowedtags = array_merge($allowedtags, $allowothertags);
109 }
110 // The dol_htmlentitiesbr will convert simple text into html, including switching accent into HTML entities
111 // The dol_escape_htmltag will escape html tags.
112 if ($escapeonlyhtmltags) {
113 return dol_escape_htmltag(dol_string_onlythesehtmltags($s, 1, 0, 0, 0, $allowedtags), 1, -1, '', 1, 1);
114 } else {
115 return dol_escape_htmltag(dol_string_onlythesehtmltags(dol_htmlentitiesbr($s), 1, 0, 0, 0, $allowedtags), 1, -1, '', 0, 1);
116 }
117}
118
128function dolPrintHTMLForAttributeUrl($s)
129{
130 // The dol_htmlentitiesbr has been removed compared to dolPrintHTMLForAttribute because we know content is a HTML URL string (even if we have no way to detect it automatically)
131 // The dol_escape_htmltag will escape html chars.
132 $escapeonlyhtmltags = 1;
133 return dol_escape_htmltag(dol_string_onlythesehtmltags($s, 1, 1, 1, 0, array()), 0, 0, '', $escapeonlyhtmltags, 1);
134}
135
148function dolPrintHTMLForTextArea($s, $allowiframe = 0)
149{
150 return dol_escape_htmltag(dol_htmlwithnojs(dol_string_onlythesehtmltags(dol_htmlentitiesbr($s), 1, 1, 1, $allowiframe)), 1, 1, '', 0, 1);
151}
152
160function dolPrintPassword($s)
161{
162 return htmlspecialchars($s, ENT_HTML5, 'UTF-8');
163}
164
165
183function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags = '', $escapeonlyhtmltags = 0, $cleanalsojavascript = 0)
184{
185 if ($stringtoescape === null) {
186 return '';
187 }
188 $reg = array();
189 if (preg_match('/^common([a-z,]*)/', $noescapetags, $reg)) {
190 $noescapetags = 'html,body,a,b,em,hr,i,u,ul,ol,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody,h1,h2,h3,h4,h5,h6,h7,h8,h9';
191 // Add also html5 tags
192 $noescapetags .= ',header,footer,nav,section,menu,menuitem';
193 if (!empty($reg[1])) {
194 $noescapetags .= $reg[1];
195 }
196 }
197 if ($cleanalsojavascript) {
198 $stringtoescape = dol_string_onlythesehtmltags($stringtoescape, 0, 0, $cleanalsojavascript, 0, array(), 0);
199 }
200
201 // escape quotes and backslashes, newlines, etc.
202 if ($escapeonlyhtmltags) {
203 $tmp = htmlspecialchars_decode((string) $stringtoescape, ENT_COMPAT);
204 } else {
205 // We make a manipulation by calling the html_entity_decode() to convert content into NON HTML UTF8 string.
206 // Because content can be or not already HTML.
207 // For example, this decode &egrave; into its UTF-8 char so string is UTF8 (but numbers entities like &#39; is not decoded).
208 // In a future, we should not need this
209
210 $tmp = (string) $stringtoescape;
211
212 // We protect the 6 special entities that we don't want to decode.
213 $tmp = str_ireplace('&lt', '__DONOTDECODELT', $tmp);
214 $tmp = str_ireplace('&gt', '__DONOTDECODEGT', $tmp);
215 $tmp = str_ireplace('&amp', '__DONOTDECODEAMP', $tmp);
216 $tmp = str_ireplace('&quot', '__DONOTDECODEQUOT', $tmp);
217 $tmp = str_ireplace('&apos', '__DONOTDECODEAPOS', $tmp);
218 $tmp = str_ireplace('&#39', '__DONOTDECODE39', $tmp);
219
220 $tmp = html_entity_decode((string) $tmp, ENT_COMPAT, 'UTF-8'); // Convert entities into UTF8
221
222 // We restore the 6 special entities that we don't want to have been decoded by previous command
223 $tmp = str_ireplace('__DONOTDECODELT', '&lt', $tmp);
224 $tmp = str_ireplace('__DONOTDECODEGT', '&gt', $tmp);
225 $tmp = str_ireplace('__DONOTDECODEAMP', '&amp', $tmp);
226 $tmp = str_ireplace('__DONOTDECODEQUOT', '&quot', $tmp);
227 $tmp = str_ireplace('__DONOTDECODEAPOS', '&apos', $tmp);
228 $tmp = str_ireplace('__DONOTDECODE39', '&#39', $tmp);
229
230 $tmp = str_ireplace('&#39;', '__SIMPLEQUOTE__', $tmp); // HTML 4
231 }
232 if (!$keepb) {
233 $tmp = strtr($tmp, array("<b>" => '', '</b>' => '', '<strong>' => '', '</strong>' => ''));
234 }
235 if (!$keepn) {
236 $tmp = strtr($tmp, array("\r" => '\\r', "\n" => '\\n'));
237 } elseif ($keepn == -1) {
238 $tmp = strtr($tmp, array("\r" => '', "\n" => ''));
239 }
240
241 if ($escapeonlyhtmltags) {
242 $tmp = htmlspecialchars($tmp, ENT_COMPAT, 'UTF-8');
243 return $tmp;
244 } else {
245 // Now we protect all the tags we want to keep
246 $tmparrayoftags = array();
247 $tmparrayoftagsfound = array();
248 if ($noescapetags) {
249 $tmparrayoftags = explode(',', $noescapetags);
250 }
251
252 if (count($tmparrayoftags)) {
253 // Now we will protect tags (defined into $tmparrayoftags) that we want to keep untouched
254
255 $reg = array();
256 // Remove reserved keywords. They are forbidden in a source string
257 $tmp = str_ireplace(array('__DOUBLEQUOTE', '__BEGINTAGTOREPLACE', '__ENDTAGTOREPLACE', '__BEGINENDTAGTOREPLACE'), '', $tmp);
258
259 foreach ($tmparrayoftags as $tagtoreplace) {
260 // The 4 patterns below all start with '<tag' or '</tag': a tag that is not in the string can not be protected, so it
261 // does not need the 4 regex passes, nor to be restored later. On a list page, most strings hold no tag at all.
262 if (stripos($tmp, '<' . $tagtoreplace) === false && stripos($tmp, '</' . $tagtoreplace) === false) {
263 continue;
264 }
265 $tmparrayoftagsfound[] = $tagtoreplace;
266
267 // For case of tag without attributes '<abc>', '</abc>', '<abc />', we protect them to avoid transformation by htmlentities() later
268 $tmp = preg_replace('/<' . preg_quote($tagtoreplace, '/') . '>/', '__BEGINTAGTOREPLACE' . $tagtoreplace . '__', $tmp);
269 $tmp = str_ireplace('</' . $tagtoreplace . '>', '__ENDTAGTOREPLACE' . $tagtoreplace . '__', $tmp);
270 $tmp = preg_replace('/<' . preg_quote($tagtoreplace, '/') . ' \/>/', '__BEGINENDTAGTOREPLACE' . $tagtoreplace . '__', $tmp);
271
272 // For case of tag with attributes.
273 // All the occurrences are protected in a single pass: the replacement string contains no '<', so it
274 // can never build a new tag to protect (a loop replacing one distinct attribute string per round was
275 // rescanning the whole content for each of them, so the cost was quadratic on large contents).
276 $tmp = preg_replace_callback(
277 '/<'.preg_quote($tagtoreplace, '/').'(\s+)([^>]+)>/',
282 static function ($reg) use ($tagtoreplace) {
283 // We want to protect the attribute part ... in '<xxx ...>' to avoid transformation by htmlentities() later
284 $tmpattributes = str_ireplace(array('[', ']'), '_', $reg[2]); // We must never have [ ] inside the attribute string
285 $tmpattributes = str_ireplace('"', '__DOUBLEQUOTE__', $tmpattributes);
286 $tmpattributes = preg_replace('/[^a-z0-9_%,\/\?\;\s=&\.\-@:\.#\+]/i', '', $tmpattributes);
287 //$tmpattributes = preg_replace("/float:\s*(left|right)/", "", $tmpattributes); // Disabled: we must not remove content
288 return '__BEGINTAGTOREPLACE'.$tagtoreplace.'['.$tmpattributes.']__';
289 },
290 $tmp
291 ) ?? $tmp;
292 }
293
294 $tmp = str_ireplace('&amp', '__ANDNOSEMICOLON__', $tmp);
295 $tmp = str_ireplace('&quot', '__DOUBLEQUOTENOSEMICOLON__', $tmp);
296 $tmp = str_ireplace('&lt', '__LESSTHAN__', $tmp);
297 $tmp = str_ireplace('&gt', '__GREATERTHAN__', $tmp);
298 }
299
300 // Warning: htmlentities encode all special chars that remains (except "'" with ENT_COMPAT).
301 $result = htmlentities($tmp, ENT_COMPAT, 'UTF-8');
302
303 //print $result;
304
305 if (count($tmparrayoftags)) {
306 // Restore protected tags
307 foreach ($tmparrayoftagsfound as $tagtoreplace) {
308 $result = str_ireplace('__BEGINTAGTOREPLACE' . $tagtoreplace . '__', '<' . $tagtoreplace . '>', $result);
309 $result = preg_replace('/__BEGINTAGTOREPLACE' . $tagtoreplace . '\[([^\]]*)\]__/', '<' . $tagtoreplace . ' \1>', $result);
310 $result = str_ireplace('__ENDTAGTOREPLACE' . $tagtoreplace . '__', '</' . $tagtoreplace . '>', $result);
311 $result = str_ireplace('__BEGINENDTAGTOREPLACE' . $tagtoreplace . '__', '<' . $tagtoreplace . ' />', $result);
312 $result = preg_replace('/__BEGINENDTAGTOREPLACE' . $tagtoreplace . '\[([^\]]*)\]__/', '<' . $tagtoreplace . ' \1 />', $result);
313 }
314
315 $result = str_ireplace('__DOUBLEQUOTE__', '"', $result);
316
317 $result = str_ireplace('__ANDNOSEMICOLON__', '&amp', $result);
318 $result = str_ireplace('__DOUBLEQUOTENOSEMICOLON__', '&quot', $result);
319 $result = str_ireplace('__LESSTHAN__', '&lt', $result);
320 $result = str_ireplace('__GREATERTHAN__', '&gt', $result);
321 }
322
323 $result = str_ireplace('__SIMPLEQUOTE__', '&#39;', $result);
324
325 //$result="\n\n\n".var_export($tmp, true)."\n\n\n".var_export($result, true);
326
327 return $result;
328 }
329}
330
331
343function dolButtonToOpenExportDialog($name, $label, $buttonstring, $exportSiteName, $overwriteGitUrl, $website)
344{
345 global $langs, $db;
346
347 $form = new Form($db);
348
349 $templatenameforexport = $website->name_template; // Example 'website_template-corporate'
350 if (empty($templatenameforexport)) {
351 $templatenameforexport = 'website_' . $website->ref;
352 }
353
354 $out = '';
355 $out .= '<input type="button" class="cursorpointer button bordertransp" id="open-dialog-' . $name . '" value="' . dol_escape_htmltag($buttonstring) . '"/>';
356
357 // for generate popup
358 $out .= '<script nonce="' . getNonce() . '" type="text/javascript">';
359 $out .= 'jQuery(document).ready(function () {';
360 $out .= ' jQuery("#open-dialog-' . $name . '").click(function () {';
361 $out .= ' var dialogHtml = \'';
362
363 $dialogcontent = ' <div id="custom-dialog-' . $name . '">';
364 $dialogcontent .= ' <div style="margin-top: 20px;">';
365 $dialogcontent .= ' <label for="export-site-' . $name . '"><strong>' . $langs->trans("ExportSiteLabel") . '...</label><br>';
366 $dialogcontent .= ' <button class="button smallpaddingimp" id="export-site-' . $name . '">' . dol_escape_htmltag($langs->trans("DownloadZip")) . '</button>';
367 $dialogcontent .= ' </div>';
368 $dialogcontent .= ' <br>';
369 $dialogcontent .= ' <div style="margin-top: 20px;">';
370 $dialogcontent .= ' <strong>' . $langs->trans("ExportSiteGitLabel") . ' ' . $form->textwithpicto('', $langs->trans("SourceFiles"), 1, 'help', '', 0, 3, '') . '</strong><br>';
371 $dialogcontent .= ' <form action="' . dol_escape_htmltag($overwriteGitUrl) . '" method="POST">';
372 $dialogcontent .= ' <input type="hidden" name="action" value="overwritesite">';
373 $dialogcontent .= ' <input type="hidden" name="token" value="' . newToken() . '">';
374 $dialogcontent .= ' <input type="text" autofocus name="export_path" id="export-path-' . $name . '" placeholder="' . $langs->trans('ExportPath') . '" style="width:400px " value="' . dol_escape_htmltag($templatenameforexport) . '"/><br>';
375 $dialogcontent .= ' <button type="submit" class="button smallpaddingimp" id="overwrite-git-' . $name . '">' . dol_escape_htmltag($langs->trans("ExportIntoGIT")) . '</button>';
376 $dialogcontent .= ' </form>';
377 $dialogcontent .= ' </div>';
378 $dialogcontent .= ' </div>';
379
380 $out .= dol_escape_js($dialogcontent);
381
382 $out .= '\';';
383
384
385 // Add the content of the dialog to the body of the page
386 $out .= ' var $dialog = jQuery("#custom-dialog-' . $name . '");';
387 $out .= ' if ($dialog.length > 0) {
388 $dialog.remove();
389 }
390 jQuery("body").append(dialogHtml);';
391
392 // Configuration of popup
393 $out .= ' jQuery("#custom-dialog-' . $name . '").dialog({';
394 $out .= ' autoOpen: false,';
395 $out .= ' modal: true,';
396 $out .= ' height: 290,';
397 $out .= ' width: "40%",';
398 $out .= ' title: \'' . dol_escape_js($label) . '\',';
399 $out .= ' });';
400
401 // Simulate a click on the original "submit" input to export the site.
402 $out .= ' jQuery("#export-site-' . $name . '").click(function () {';
403 $out .= ' console.log("Click on exportsite.");';
404 $out .= ' var target = jQuery("input[name=\'' . dol_escape_js($exportSiteName) . '\']");';
405 $out .= ' console.log("element founded:", target.length > 0);';
406 $out .= ' if (target.length > 0) { target.click(); }';
407 $out .= ' jQuery("#custom-dialog-' . $name . '").dialog("close");';
408 $out .= ' });';
409
410 // open popup
411 $out .= ' jQuery("#custom-dialog-' . $name . '").dialog("open");';
412 $out .= ' return false;';
413 $out .= ' });';
414 $out .= '});';
415 $out .= '</script>';
416
417 return $out;
418}
419
420
437function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled = '', $morecss = 'classlink button bordertransp', $jsonopen = '', $jsonclose = '', $accesskey = '')
438{
439 global $conf;
440
441 if (strpos($url, '?') > 0) {
442 $url .= '&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=' . urlencode($name);
443 } else {
444 $url .= '?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=' . urlencode($name);
445 }
446
447 if (preg_match('/^https/i', $url)) {
448 $urltoopen = $url;
449 } else {
450 $urltoopen = DOL_URL_ROOT . $url;
451 }
452
453 $out = '';
454
455 //print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("MediaFiles")).'" name="file_manager">';
456 $out .= '<!-- a link for button to open url into a dialog popup -->';
457 $out .= '<a ' . ($accesskey ? ' accesskey="' . $accesskey . '"' : '') . ' class="cursorpointer reposition button_' . $name . ($morecss ? ' ' . $morecss : '') . '"' . $disabled . ' title="' . dol_escape_htmltag($label) . '"';
458 if (empty($conf->use_javascript_ajax)) {
459 $out .= ' href="' . $urltoopen . '" target="_blank"';
460 } elseif ($jsonopen) {
461 $out .= ' href="#" onclick="' . $jsonopen . '"';
462 } else {
463 $out .= ' href="#"';
464 }
465 $out .= '>' . $buttonstring . '</a>';
466
467 if (!empty($conf->use_javascript_ajax)) {
468 // Add code to open url using the popup.
469 $out .= '<!-- code to open popup and variables to retrieve returned variables -->';
470 $out .= '<div id="idfordialog' . $name . '" class="hidden">' . (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER') < 2 ? 'div for dialog' : '') . '</div>';
471
472 $out .= '<!-- Add js code to open dialog popup on dialog -->';
473 $out .= '<script nonce="' . getNonce() . '" type="text/javascript">
474 jQuery(document).ready(function () {
475 jQuery(".button_' . $name . '").click(function () {
476 console.log(\'Open popup with jQuery(...).dialog() on URL ' . dol_escape_js($urltoopen) . '\');
477 var $tmpdialog = $(\'#idfordialog' . $name . '\');
478 $tmpdialog.html(\'<iframe class="iframedialog" id="iframedialog' . $name . '" style="border: 0px;" src="' . $urltoopen . '" width="100%" height="98%"></iframe>\');
479 $tmpdialog.dialog({
480 autoOpen: false,
481 modal: true,
482 height: (window.innerHeight - 150),
483 width: \'80%\',
484 title: \'' . dol_escape_js($label) . '\',
485 open: function (event, ui) {
486 console.log("open popup name=' . $name . '");
487 },
488 close: function (event, ui) {
489 console.log("Popup is closed, run jsonclose = ' . $jsonclose . '");
490 ' . (empty($jsonclose) || preg_match('/^TODO/', $jsonclose) ? '' : $jsonclose . ';') . '
491 }
492 });
493
494 $tmpdialog.dialog(\'open\');
495 return false;
496 });
497 });
498 </script>';
499 }
500 return $out;
501}
502
520function dol_fiche_head($links = array(), $active = '0', $title = '', $notab = 0, $picto = '', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '', $limittoshow = 0, $moretabssuffix = '')
521{
522 print dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
523}
524
542function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab = 0, $picto = '', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '', $limittoshow = 0, $moretabssuffix = '', $dragdropfile = 0, $morecssdiv = '')
543{
544 global $conf, $langs, $hookmanager;
545
546 // Show title
547 $showtitle = 1;
548 if (!empty($conf->dol_optimize_smallscreen)) {
549 $showtitle = 0;
550 }
551
552 $out = "\n" . '<!-- dol_fiche_head - dol_get_fiche_head -->';
553
554 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
555 $out .= '<div class="tabs' . ($picto ? '' : ' nopaddingleft') . '" data-role="controlgroup" data-type="horizontal">' . "\n";
556 }
557
558 // Show right part
559 if ($morehtmlright) {
560 $out .= '<div class="inline-block floatright tabsElem">' . $morehtmlright . '</div>'; // Output right area first so when space is missing, text is in front of tabs and not under.
561 }
562
563 // Show tabs
564
565 // Define max of key (max may be higher than sizeof because of hole due to module disabling some tabs).
566 $maxkey = -1;
567 if (is_array($links) && !empty($links)) {
568 $keys = array_keys($links);
569 if (count($keys)) {
570 $maxkey = max($keys);
571 }
572 }
573
574 // if =0 we don't use the feature
575 if (empty($limittoshow)) {
576 $limittoshow = getDolGlobalInt('MAIN_MAXTABS_IN_CARD', 99);
577 }
578 if (!empty($conf->dol_optimize_smallscreen)) { // If on smartphone, we limit to 1 tab to show
579 $limittoshow = 1;
580 }
581
582 $displaytab = 0;
583 $nbintab = 0;
584 $popuptab = 0;
585 $outmore = '';
586 for ($i = 0; $i <= $maxkey; $i++) {
587 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
588 // If active tab is already present
589 if ($i >= $limittoshow) {
590 $limittoshow--;
591 }
592 }
593 }
594
595 for ($i = 0; $i <= $maxkey; $i++) {
596 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
597 $isactive = true;
598 } else {
599 $isactive = false;
600 }
601
602 if ($i < $limittoshow || $isactive) {
603 // Output entry with a visible tab
604 $out .= '<div class="inline-block tabsElem' . ($isactive ? ' tabsElemActive' : '') . ((!$isactive && getDolGlobalString('MAIN_HIDE_INACTIVETAB_ON_PRINT')) ? ' hideonprint' : '') . '"><!-- id tab = ' . (empty($links[$i][2]) ? '' : dol_escape_htmltag($links[$i][2])) . ' -->';
605
606 if (isset($links[$i][2]) && $links[$i][2] == 'image') {
607 if (!empty($links[$i][0])) {
608 $out .= '<a class="tabimage' . ($morecss ? ' ' . $morecss : '') . '" href="' . $links[$i][0] . '">' . $links[$i][1] . '</a>' . "\n";
609 } else {
610 $out .= '<span class="tabspan">' . $links[$i][1] . '</span>' . "\n";
611 }
612 } elseif (!empty($links[$i][1])) {
613 //print "x $i $active ".$links[$i][2]." z";
614 $out .= '<div class="tab tab' . ($isactive ? 'active' : 'unactive') . '" style="margin: 0 !important">';
615
616 if (!empty($links[$i][0])) {
617 $titletoshow = preg_replace('/<.*$/', '', $links[$i][1]);
618 $out .= '<a' . (!empty($links[$i][2]) ? ' id="' . $links[$i][2] . '"' : '') . ' class="tab inline-block valignmiddle' . ($morecss ? ' ' . $morecss : '') . (!empty($links[$i][5]) ? ' ' . $links[$i][5] : '') . '" href="' . $links[$i][0] . '" title="' . dol_escape_htmltag($titletoshow) . '">';
619 }
620
621 if ($displaytab == 0 && $picto) {
622 $out .= img_picto($title, $picto, '', $pictoisfullpath, 0, 0, '', 'imgTabTitle paddingright marginrightonlyshort');
623 }
624
625 $out .= $links[$i][1];
626 if (!empty($links[$i][0])) {
627 $out .= '</a>' . "\n";
628 }
629 $out .= empty($links[$i][4]) ? '' : $links[$i][4];
630 $out .= '</div>';
631 }
632
633 $out .= '</div>';
634 } else {
635 // Add entry into the combo popup with the other tabs
636 if (!$popuptab) {
637 $popuptab = 1;
638 $outmore .= '<div class="popuptabset wordwrap">'; // The css used to hide/show popup
639 }
640 $outmore_content = '';
641
642 if (isset($links[$i][2]) && $links[$i][2] == 'image') {
643 if (!empty($links[$i][0])) {
644 $outmore_content .= '<a class="tabimage' . ($morecss ? ' ' . $morecss : '') . '" href="' . $links[$i][0] . '">' . $links[$i][1] . '</a>' . "\n";
645 } else {
646 $outmore_content .= '<span class="tabspan">' . $links[$i][1] . '</span>' . "\n";
647 }
648 } elseif (!empty($links[$i][1])) {
649 $outmore_content .= '<a' . (!empty($links[$i][2]) ? ' id="' . $links[$i][2] . '"' : '') . ' class="wordwrap inline-block' . ($morecss ? ' ' . $morecss : '') . '" href="' . $links[$i][0] . '">';
650 $outmore_content .= preg_replace('/([a-z])\|([a-z])/i', '\\1 | \\2', $links[$i][1]); // Replace x|y with x | y to allow wrap on long composed texts.
651 $outmore_content .= '</a>' . "\n";
652 }
653 if ($outmore_content !== '') {
654 $outmore .= '<div class="popuptab wordwrap" style="display:inherit;">' . $outmore_content . '</div>';
655 }
656
657 $nbintab++;
658 }
659
660 $displaytab = $i + 1;
661 }
662 if ($popuptab) {
663 $outmore .= '</div>';
664 }
665
666 if ($popuptab) { // If there is some tabs not shown
667 $left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
668 $right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
669 $widthofpopup = 240;
670
671 $tabsname = $moretabssuffix;
672 if (empty($tabsname)) {
673 $tabsname = str_replace("@", "", $picto);
674 }
675 $out .= '<div id="moretabs' . $tabsname . '" class="inline-block tabsElem valignmiddle">';
676 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
677 $out .= '<div class="tab valignmiddle"><a href="#" class="tab moretab inline-block tabunactive valignmiddle"><span class="fa fa-angle-down"></span> <span class="opacitymedium">+' . $nbintab . '</span></a></div>'; // Do not use "reposition" class in the "More".
678 }
679 $out .= '<div id="moretabsList' . $tabsname . '" style="width: ' . $widthofpopup . 'px; position: absolute; ' . $left . ': -999em; text-align: ' . $left . '; margin:0px; padding:2px; z-index:10;">';
680 $out .= $outmore;
681 $out .= '</div>';
682 $out .= '<div></div>';
683 $out .= "</div>\n";
684
685 $out .= '<script nonce="' . getNonce() . '">';
686 $out .= "$('#moretabs" . $tabsname . "').mouseenter( function() {
687 var x = this.offsetLeft, y = this.offsetTop;
688 console.log('mouseenter " . $left . " x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
689 if ((window.innerWidth - x) < " . ($widthofpopup + 10) . ") {
690 $('#moretabsList" . $tabsname . "').css('" . $right . "','8px');
691 }
692 $('#moretabsList" . $tabsname . "').css('" . $left . "','auto');
693 });
694 ";
695 $out .= "$('#moretabs" . $tabsname . "').mouseleave( function() { console.log('mouseleave " . $left . "'); $('#moretabsList" . $tabsname . "').css('" . $left . "','-999em');});";
696 $out .= "</script>";
697 }
698
699 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
700 $out .= "</div>\n";
701 }
702
703 if (!$notab || $notab == -1 || $notab == -2 || $notab == -3 || $notab == -4) {
704 $out .= "\n" . '<div id="dragDropAreaTabBar" class="tabBar' . ($notab == -1 ? '' : ($notab == -2 ? ' tabBarNoTop' : ((($notab == -3 || $notab == -4) ? ' noborderbottom' : '') . ($notab == -4 ? '' : ' tabBarWithBottom'))));
705 $out .= ($morecssdiv ? ' ' . $morecssdiv : '');
706 $out .= '">' . "\n";
707 }
708 if (!empty($dragdropfile)) {
709 include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
710 $out .= dragAndDropFileUpload("dragDropAreaTabBar");
711 }
712 $parameters = array('tabname' => $active, 'out' => $out);
713 $reshook = $hookmanager->executeHooks('printTabsHead', $parameters); // This hook usage is called just before output the head of tabs. Take also a look at "completeTabsHead"
714 if ($reshook > 0) {
715 $out = $hookmanager->resPrint;
716 }
717
718 return $out;
719}
720
729function dol_fiche_end($notab = 0)
730{
731 print dol_get_fiche_end($notab);
732}
733
740function dol_get_fiche_end($notab = 0)
741{
742 if (!$notab || $notab == -1) {
743 return "\n</div>\n";
744 } else {
745 return '';
746 }
747}
748
769function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldid = 'rowid', $fieldref = 'ref', $morehtmlref = '', $moreparam = '', $nodbprefix = 0, $morehtmlleft = '', $morehtmlstatus = '', $onlybanner = 0, $morehtmlright = '')
770{
771 global $conf, $form, $user, $langs, $hookmanager, $action;
772
773 $error = 0;
774
775 $maxvisiblephotos = 1;
776 $showimage = 1;
777 $entity = (empty($object->entity) ? $conf->entity : $object->entity);
778 // @phan-suppress-next-line PhanUndeclaredMethod
779 $showbarcode = !isModEnabled('barcode') ? 0 : (empty($object->barcode) ? 0 : 1);
780 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('barcode', 'lire_advance')) {
781 $showbarcode = 0;
782 }
783 $modulepart = 'unknown';
784
785 if (in_array($object->element, ['societe', 'contact', 'product', 'ticket', 'bom'])) {
786 $modulepart = $object->element;
787 } elseif ($object->element == 'member') {
788 $modulepart = 'memberphoto';
789 } elseif ($object->element == 'user') {
790 $modulepart = 'userphoto';
791 }
792
793 if (class_exists("Imagick")) {
794 if ($object->element == 'expensereport' || $object->element == 'propal' || $object->element == 'commande' || $object->element == 'facture' || $object->element == 'supplier_proposal') {
795 $modulepart = $object->element;
796 } elseif ($object->element == 'fichinter' || $object->element == 'intervention') {
797 $modulepart = 'ficheinter';
798 } elseif ($object->element == 'contrat' || $object->element == 'contract') {
799 $modulepart = 'contract';
800 } elseif ($object->element == 'order_supplier') {
801 $modulepart = 'supplier_order';
802 } elseif ($object->element == 'invoice_supplier') {
803 $modulepart = 'supplier_invoice';
804 }
805 }
806
807 if ($object->element == 'product') {
809 '@phan-var-force Product $object';
810 $width = 80;
811 $cssclass = 'photowithmargin photoref';
812 $showimage = $object->is_photo_available($conf->product->multidir_output[$entity]);
813 $maxvisiblephotos = getDolGlobalInt('PRODUCT_MAX_VISIBLE_PHOTO', 5);
814 if ($conf->browser->layout == 'phone') {
815 $maxvisiblephotos = 1;
816 }
817 $useLinkPathPhoto = getDolGlobalInt('PRODUCT_USE_LINK_PATH_FOR_PHOTO');
818 if ($showimage || $useLinkPathPhoto) {
819 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('product', $conf->product->multidir_output[$entity], 1, $maxvisiblephotos, 0, 0, 0, 0, $width, 0, '') . '</div>';
820 } else {
821 if (getDolGlobalString('PRODUCT_NODISPLAYIFNOPHOTO')) {
822 $nophoto = '';
823 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
824 } else { // Show no photo link
825 $nophoto = '/public/theme/common/nophoto.png';
826 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo' . $modulepart . ' ' . $cssclass . '" title="' . dol_escape_htmltag($langs->trans("UploadAnImageToSeeAPhotoHere", $langs->transnoentitiesnoconv("Documents"))) . '" alt="No photo" style="width: ' . $width . 'px" src="' . DOL_URL_ROOT . $nophoto . '"></div>';
827 }
828 }
829 } elseif ($object->element == 'category') {
831 '@phan-var-force Categorie $object';
832 $width = 80;
833 $cssclass = 'photowithmargin photoref';
834 $showimage = $object->isAnyPhotoAvailable($conf->categorie->multidir_output[$entity]);
835 $maxvisiblephotos = getDolGlobalInt('CATEGORY_MAX_VISIBLE_PHOTO', 5);
836 if ($conf->browser->layout == 'phone') {
837 $maxvisiblephotos = 1;
838 }
839 if ($showimage) {
840 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('category', $conf->categorie->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, 0, $width, 0, '') . '</div>';
841 } else {
842 if (getDolGlobalString('CATEGORY_NODISPLAYIFNOPHOTO')) {
843 $nophoto = '';
844 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
845 } else { // Show no photo link
846 $nophoto = '/public/theme/common/nophoto.png';
847 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo' . $modulepart . ' ' . $cssclass . '" title="' . dol_escape_htmltag($langs->trans("UploadAnImageToSeeAPhotoHere", $langs->transnoentitiesnoconv("Documents"))) . '" alt="No photo" style="width: ' . $width . 'px" src="' . DOL_URL_ROOT . $nophoto . '"></div>';
848 }
849 }
850 } elseif ($object->element == 'bom') {
852 '@phan-var-force Bom $object';
853 $width = 80;
854 $cssclass = 'photowithmargin photoref';
855 $showimage = $object->is_photo_available($conf->bom->multidir_output[$entity]);
856 $maxvisiblephotos = getDolGlobalInt('BOM_MAX_VISIBLE_PHOTO', 5);
857 if ($conf->browser->layout == 'phone') {
858 $maxvisiblephotos = 1;
859 }
860 if ($showimage) {
861 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('bom', $conf->bom->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, 0, $width, 0, '') . '</div>';
862 } else {
863 if (getDolGlobalString('BOM_NODISPLAYIFNOPHOTO')) {
864 $nophoto = '';
865 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
866 } else { // Show no photo link
867 $nophoto = '/public/theme/common/nophoto.png';
868 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo' . $modulepart . ' ' . $cssclass . '" title="' . dol_escape_htmltag($langs->trans("UploadAnImageToSeeAPhotoHere", $langs->transnoentitiesnoconv("Documents"))) . '" alt="No photo" style="width: ' . $width . 'px" src="' . DOL_URL_ROOT . $nophoto . '"></div>';
869 }
870 }
871 } elseif ($object->element == 'ticket') {
872 $width = 80;
873 $cssclass = 'photoref';
875 '@phan-var-force Ticket $object';
876 $showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity] . '/' . $object->ref);
877 $maxvisiblephotos = getDolGlobalInt('TICKET_MAX_VISIBLE_PHOTO', 2);
878 if ($conf->browser->layout == 'phone') {
879 $maxvisiblephotos = 1;
880 }
881
882 if ($showimage) {
883 $showphoto = $object->show_photos('ticket', $conf->ticket->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
884 if ($object->nbphoto > 0) {
885 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $showphoto . '</div>';
886 } else {
887 $showimage = 0;
888 }
889 }
890 if (!$showimage) {
891 if (getDolGlobalString('TICKET_NODISPLAYIFNOPHOTO')) {
892 $nophoto = '';
893 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
894 } else { // Show no photo link
895 $nophoto = img_picto('No photo', 'object_ticket');
896 $morehtmlleft .= '<!-- No photo to show -->';
897 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
898 $morehtmlleft .= $nophoto;
899 $morehtmlleft .= '</div></div>';
900 }
901 }
902 } else {
903 // $modulepart may have been set previously if Imagick class exists (see before).
904 if ($modulepart != 'unknown' || method_exists($object, 'getDataToShowPhoto')) {
905 $phototoshow = '';
906 // Check if a preview file is available
907 if (in_array($modulepart, array('propal', 'commande', 'facture', 'ficheinter', 'contract', 'supplier_order', 'supplier_proposal', 'supplier_invoice', 'expensereport')) && class_exists("Imagick")) {
908 $objectref = dol_sanitizeFileName($object->ref);
909 $dir_output = (empty($conf->$modulepart->multidir_output[$entity]) ? $conf->$modulepart->dir_output : $conf->$modulepart->multidir_output[$entity]) . "/";
910 if (in_array($modulepart, array('invoice_supplier', 'supplier_invoice'))) {
911 $subdir = get_exdir($object->id, 2, 0, 1, $object, $modulepart);
912 $subdir .= ((!empty($subdir) && !preg_match('/\/$/', $subdir)) ? '/' : '') . $objectref; // the objectref dir is not included into get_exdir when used with level=2, so we add it at end
913 } else {
914 $subdir = get_exdir($object->id, 0, 0, 1, $object, $modulepart);
915 }
916 if (empty($subdir)) {
917 $subdir = 'errorgettingsubdirofobject'; // Protection to avoid to return empty path
918 }
919
920 $filepath = $dir_output . $subdir . "/";
921
922 $filepdf = $filepath . $objectref . ".pdf";
923 $relativepath = $subdir . '/' . $objectref . '.pdf';
924
925 // Define path to preview pdf file (preview precompiled "file.ext" are "file.ext_preview.png")
926 $fileimage = $filepdf . '_preview.png';
927 $relativepathimage = $relativepath . '_preview.png';
928
929 $pdfexists = file_exists($filepdf);
930
931 // If PDF file exists
932 if ($pdfexists) {
933 // Conversion du PDF en image png si fichier png non existent
934 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
935 if (!getDolGlobalString('MAIN_DISABLE_PDF_THUMBS')) { // If you experience trouble with pdf thumb generation and imagick, you can disable here.
936 include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
937 $ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png
938 if ($ret < 0) {
939 $error++;
940 }
941 }
942 }
943 }
944
945 if ($pdfexists && !$error) {
946 $heightforphotref = 80;
947 if (!empty($conf->dol_optimize_smallscreen)) {
948 $heightforphotref = 60;
949 }
950 // If the preview file is found
951 if (file_exists($fileimage)) {
952 $phototoshow = '<div class="photoref">';
953 $phototoshow .= '<img height="' . $heightforphotref . '" class="photo photowithborder" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=apercu' . $modulepart . '&amp;file=' . urlencode($relativepathimage) . '">';
954 $phototoshow .= '</div>';
955 }
956 }
957 } elseif (!$phototoshow) { // example if modulepart = 'societe' or 'photo' or 'memberphoto'
958 $phototoshow .= $form->showphoto($modulepart, $object, 0, 0, 0, 'photowithmargin photoref', 'small', 1, 0);
959 }
960
961 if ($phototoshow) {
962 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">';
963 $morehtmlleft .= $phototoshow;
964 $morehtmlleft .= '</div>';
965 }
966 }
967
968 if (empty($phototoshow)) { // Show No photo link (picto of object)
969 if ($object->element == 'action') {
970 $width = 80;
971 $cssclass = 'photorefcenter';
972 $nophoto = img_picto('No photo', 'title_agenda');
973 } else {
974 $width = 14;
975 $cssclass = 'photorefcenter';
976 $picto = $object->picto; // @phan-suppress-current-line PhanUndeclaredProperty
977 $prefix = 'object_';
978 if ($object->element == 'project' && !$object->public) { // @phan-suppress-current-line PhanUndeclaredProperty
979 $picto = 'project'; // instead of projectpub
980 }
981 if (strpos($picto, 'fontawesome_') !== false) {
982 $prefix = '';
983 }
984 $nophoto = img_picto('No photo', $prefix . $picto);
985 }
986 $morehtmlleft .= '<!-- No photo to show -->';
987 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
988 $morehtmlleft .= $nophoto;
989 $morehtmlleft .= '</div></div>';
990 }
991 }
992
993 if (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') == '1' || preg_match('/' . preg_quote($object->element, '/') . '/i', getDolGlobalString('MAIN_SHOW_TECHNICAL_ID'))) && !empty($object->id)) {
994 $morehtmlref .= '<div style="clear: both;"></div>';
995 $morehtmlref .= '<div class="smallimp refidno opacitymedium banner-object-technical-id">';
996 $morehtmlref .= $langs->trans("TechnicalID") . ': ' . ((int) $object->id);
997 $morehtmlref .= '</div>';
998 }
999
1000
1001 // Show barcode
1002 if ($showbarcode) {
1003 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $form->showbarcode($object, 100, 'photoref valignmiddle') . '</div>';
1004 }
1005
1006 if ($object->element == 'societe') {
1008 if (!empty($conf->use_javascript_ajax) && $user->hasRight('societe', 'creer') && getDolGlobalString('MAIN_DIRECT_STATUS_UPDATE')) {
1009 $morehtmlstatus .= ajax_object_onoff($object, 'status', 'status', 'InActivity', 'ActivityCeased');
1010 } else {
1011 $morehtmlstatus .= $object->getLibStatut(6);
1012 }
1013 } elseif ($object->element == 'product') {
1015 //$morehtmlstatus.=$langs->trans("Status").' ('.$langs->trans("Sell").') ';
1016 if (!empty($conf->use_javascript_ajax) && $user->hasRight('produit', 'creer') && getDolGlobalString('MAIN_DIRECT_STATUS_UPDATE')) {
1017 $morehtmlstatus .= ajax_object_onoff($object, 'status', 'status', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
1018 } else {
1019 $morehtmlstatus .= '<span class="statusrefsell">' . $object->getLibStatut(6, 0) . '</span>';
1020 }
1021 $morehtmlstatus .= ' &nbsp; ';
1022 //$morehtmlstatus.=$langs->trans("Status").' ('.$langs->trans("Buy").') ';
1023 if (!empty($conf->use_javascript_ajax) && $user->hasRight('produit', 'creer') && getDolGlobalString('MAIN_DIRECT_STATUS_UPDATE')) {
1024 $morehtmlstatus .= ajax_object_onoff($object, 'status_buy', 'status_buy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
1025 } else {
1026 $morehtmlstatus .= '<span class="statusrefbuy">' . $object->getLibStatut(6, 1) . '</span>';
1027 }
1028 } elseif (in_array($object->element, array('salary'))) {
1030 '@phan-var-force Salary $object';
1031 $tmptxt = $object->getLibStatut(6, $object->totalpaid);
1032 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
1033 $tmptxt = $object->getLibStatut(5, $object->totalpaid);
1034 }
1035 $morehtmlstatus .= $tmptxt;
1036 } elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier'))) {
1038 '@phan-var-force Facture|FactureFournisseur|CommonInvoice $object';
1039 if (!isset($object->alreadypaid)) {
1040 $object->totalpaid = $object->getSommePaiement(0);
1041 $object->totalcreditnotes = $object->getSumCreditNotesUsed(0);
1042 $object->totaldeposits = $object->getSumDepositsUsed(0);
1043 $object->alreadypaid = $object->totalpaid + $object->totalcreditnotes + $object->totaldeposits;
1044 }
1045 $tmptxt = $object->getLibStatut(6, (float) $object->alreadypaid);
1046 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
1047 $tmptxt = $object->getLibStatut(5, (float) $object->alreadypaid);
1048 }
1049 $morehtmlstatus .= $tmptxt;
1050 } elseif (in_array($object->element, array('chargesociales', 'loan', 'tva'))) { // TODO Move this to use ->alreadypaid like for invoices
1052 '@phan-var-force ChargeSociales|Loan|Tva $object';
1053 $tmptxt = $object->getLibStatut(6, $object->totalpaid);
1054 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
1055 $tmptxt = $object->getLibStatut(5, $object->totalpaid);
1056 }
1057 $morehtmlstatus .= $tmptxt;
1058 } elseif ($object->element == 'contrat' || $object->element == 'contract') {
1060 if ($object->status == 0) {
1061 $morehtmlstatus .= $object->getLibStatut(5);
1062 } else {
1063 $morehtmlstatus .= $object->getLibStatut(4);
1064 }
1065 } elseif ($object->element == 'facturerec') {
1067 '@phan-var-force FactureRec $object';
1068 if ($object->frequency == 0) {
1069 $morehtmlstatus .= $object->getLibStatut(2);
1070 } else {
1071 $morehtmlstatus .= $object->getLibStatut(5);
1072 }
1073 } elseif ($object->element == 'project_task') {
1075 $tmptxt = $object->getLibStatut(4);
1076 $morehtmlstatus .= $tmptxt;
1077 } elseif (method_exists($object, 'getLibStatut')) { // Generic case for status
1078 $tmptxt = $object->getLibStatut(6);
1079 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
1080 $tmptxt = $object->getLibStatut(5);
1081 }
1082 $morehtmlstatus .= $tmptxt;
1083 }
1084
1085 // Say if object was dispatched/transferred "into accountancy"
1086 if (isModEnabled('accounting') && in_array($object->element, array('bank', 'paiementcharge', 'facture', 'invoice', 'invoice_supplier', 'expensereport', 'payment_various'))) {
1087 // Note: For 'chargesociales', 'salaries'... this is the payments that are dispatched (so element = 'bank')
1088 if (method_exists($object, 'getVentilExportCompta')) {
1089 $accounted = $object->getVentilExportCompta(1);
1090 $langs->load("accountancy");
1091 $morehtmlstatus .= '</div><div class="statusref statusrefbis"><span class="opacitymedium">' . ($accounted > 0 ? '<a href="' . DOL_URL_ROOT . '/accountancy/bookkeeping/list.php?search_mvt_num=' . ((int) $accounted) . '">' . $langs->trans("Accounted") . '</a>' : $langs->trans("NotYetAccounted")) . '</span>';
1092 }
1093 }
1094
1095 // Add alias for thirdparty
1096 if (!empty($object->name_alias)) {
1098 '@phan-var-force Societe $object';
1099 $morehtmlref .= '<div class="refidno opacitymedium banner-object-name-alias">' . dol_escape_htmltag($object->name_alias) . '</div>';
1100 }
1101
1102 // Add label
1103 if (in_array($object->element, array('product', 'bank_account', 'project_task'))) {
1105 if (!empty($object->label)) {
1106 $morehtmlref .= '<div class="refidno banner-object-label">' . $object->label . '</div>';
1107 }
1108 }
1109 // Show address and email
1110 if (method_exists($object, 'getBannerAddress') && !in_array($object->element, array('product', 'bookmark', 'ecm_directories', 'ecm_files'))) {
1111 $moreaddress = $object->getBannerAddress('refaddress', $object); // address, email, url, social networks
1112 if ($moreaddress) {
1113 $morehtmlref .= '<div class="refidno refaddress">';
1114 $morehtmlref .= $moreaddress;
1115 $morehtmlref .= '</div>';
1116 }
1117 }
1118
1119 $parameters = array('morehtmlref' => &$morehtmlref, 'moreparam' => &$moreparam, 'morehtmlleft' => &$morehtmlleft, 'morehtmlstatus' => &$morehtmlstatus, 'morehtmlright' => &$morehtmlright);
1120 $reshook = $hookmanager->executeHooks('formDolBanner', $parameters, $object, $action);
1121 if ($reshook < 0) {
1122 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1123 } elseif (empty($reshook)) {
1124 $morehtmlref .= $hookmanager->resPrint;
1125 } elseif ($reshook > 0) {
1126 $morehtmlref = $hookmanager->resPrint;
1127 }
1128
1129 // $morehtml is the right part (link "Back to list")
1130 // $morehtmlref is the part after the ref
1131 // $morehtmlleft is the picto or photo of banner
1132 // $morehtmlstatus is part under the status
1133 // $morehtmlright is part of htmlright
1134
1135 print '<div class="' . ($onlybanner ? 'arearefnobottom ' : 'arearef ') . 'heightref valignmiddle centpercent object-banner-tab-container" data-module-part="'.dolPrintHTMLForAttribute($modulepart).'">';
1136 print $form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
1137 print '</div>';
1138 print '<div class="underrefbanner clearboth"></div>';
1139}
1140
1150function fieldLabel($langkey, $fieldkey, $fieldrequired = 0)
1151{
1152 global $langs;
1153 $ret = '';
1154 if ($fieldrequired) {
1155 $ret .= '<span class="fieldrequired">';
1156 }
1157 $ret .= '<label for="' . $fieldkey . '">';
1158 $ret .= $langs->trans($langkey);
1159 $ret .= '</label>';
1160 if ($fieldrequired) {
1161 $ret .= '</span>';
1162 }
1163 return $ret;
1164}
1165
1166
1182function dolOutputDates($datep, $datef = null, $fullday = 0, $addseconds = 0, $pictotoadd = '', $tzoutput = 'tzuserrel', $reduceformat = 0)
1183{
1184 $tmpa = dol_getdate($datep);
1185 if (empty($datef)) {
1186 $tmpb = $tmpa;
1187 } else {
1188 $tmpb = dol_getdate($datef);
1189 }
1190
1191 $s = '';
1192
1193 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1194 // The same day
1195 $s .= '<div class="center inline-block">';
1196 if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes']) {
1197 // Not the same hour
1198 $s .= dol_print_date($datep, 'day'.($reduceformat ? 'reduceformat' : ''), $tzoutput);
1199 $s .= $pictotoadd;
1200 if (empty($fullday)) {
1201 $s .= '<br><span class="small opacitymedium">';
1202 $s .= dol_print_date($datep, 'hour'.($addseconds ? 'sec' : '').'reduceformat', $tzoutput);
1203 $s .= '-'.dol_print_date($datef, 'hour'.($addseconds ? 'sec' : '').'reduceformat', $tzoutput);
1204 $s .= '</span>';
1205 }
1206 } else {
1207 // The same hour
1208 $s .= dol_print_date($datep, 'day'.($reduceformat ? 'reduceformat' : ''), 'tzuserrel');
1209 $s .= $pictotoadd;
1210 if (empty($fullday)) {
1211 $s .= '<br><span class="small opacitymedium">';
1212 $s .= dol_print_date($datep, 'hour'.($addseconds ? 'sec' : '').'reduceformat', $tzoutput);
1213 $s .= '</span>';
1214 }
1215 }
1216 $s .= '</div>';
1217 } else {
1218 // Not the same day
1219 $s .= '<div class="center inline-block dateborderright">';
1220 $s .= dol_print_date($datep, 'day'.($reduceformat ? 'reduceformat' : ''), $tzoutput);
1221 if (empty($fullday)) {
1222 $s .= '<br><span class="small opacitymedium">';
1223 $s .= dol_print_date($datep, 'hour'.($addseconds ? 'sec' : '').'reduceformat', $tzoutput);
1224 $s .= '</span>';
1225 }
1226 $s .= '</div>';
1227 $s .= '<div class="center inline-block dateborderleft">';
1228 $s .= dol_print_date($datef, 'day'.($reduceformat ? 'reduceformat' : ''), 'tzuserrel');
1229 $s .= $pictotoadd;
1230 if (empty($fullday)) {
1231 $s .= '<br><span class="small opacitymedium">';
1232 $s .= dol_print_date($datef, 'hour'.($addseconds ? 'sec' : '').'reduceformat', $tzoutput);
1233 $s .= '</span>';
1234 }
1235 $s .= '</div>';
1236 }
1237
1238 return $s;
1239}
1240
1241
1249function getPictoForType($key, $morecss = '')
1250{
1251 // Set array with type -> picto
1252 $type2picto = array(
1253 'varchar' => 'font',
1254 'text' => 'font',
1255 'html' => 'code',
1256 'int' => 'sort-numeric-down',
1257 'double' => 'sort-numeric-down',
1258 'price' => 'currency',
1259 'pricecy' => 'multicurrency',
1260 'password' => 'key',
1261 'boolean' => 'check-square',
1262 'date' => 'calendar',
1263 'datetime' => 'calendar',
1264 'duration' => 'hourglass',
1265 'phone' => 'phone',
1266 'mail' => 'email',
1267 'url' => 'url',
1268 'ip' => 'country',
1269 'select' => 'list',
1270 'sellist' => 'list',
1271 'stars' => 'fontawesome_star_fas',
1272 'radio' => 'check-circle',
1273 'checkbox' => 'list',
1274 'chkbxlst' => 'list',
1275 'link' => 'link',
1276 'icon' => "question",
1277 'point' => "country",
1278 'multipts' => 'country',
1279 'linestrg' => "country",
1280 'polygon' => "country",
1281 'separate' => 'minus'
1282 );
1283
1284 if (!empty($type2picto[$key])) {
1285 return img_picto('', $type2picto[$key], 'class="pictofixedwidth' . ($morecss ? ' ' . $morecss : '') . '"');
1286 }
1287
1288 return img_picto('', 'generic', 'class="pictofixedwidth' . ($morecss ? ' ' . $morecss : '') . '"');
1289}
1290
1291
1316function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $alt = '', $morecss = '', $marginleftonlyshort = 2, $allowothertags = array())
1317{
1318 global $conf;
1319
1320 // We forge fullpathpicto for image to $path/img/$picto. By default, we take DOL_URL_ROOT/theme/$conf->theme/img/$picto
1321 $url = DOL_URL_ROOT;
1322 $theme = isset($conf->theme) ? $conf->theme : null;
1323 $path = 'theme/' . $theme;
1324 if (empty($picto)) {
1325 $picto = 'generic';
1326 }
1327
1328 if ($titlealt) {
1329 $titlealt = str_replace(array('\n', "\n"), ' - ', $titlealt);
1330 }
1331
1332 // Define fullpathpicto to use into src
1333 if ($pictoisfullpath) {
1334 // Clean parameters
1335 if (!preg_match('/(\.png|\.gif|\.svg)$/i', $picto)) {
1336 $picto .= '.png';
1337 }
1338 $fullpathpicto = $picto;
1339 $reg = array();
1340 if (preg_match('/class="([^"]+)"/', $moreatt, $reg)) {
1341 $morecss .= ($morecss ? ' ' : '') . $reg[1];
1342 $moreatt = str_replace('class="' . $reg[1] . '"', '', $moreatt);
1343 }
1344 } else {
1345 // $picto can not be null since replaced with 'generic' in that case
1346 // $pictowithouttext = preg_replace('/(\.png|\.gif|\.svg)$/', '', (is_null($picto) ? '' : $picto));
1347 $pictowithouttext = preg_replace('/(\.png|\.gif|\.svg)$/', '', $picto);
1348 $pictowithouttext = str_replace('object_', '', $pictowithouttext);
1349 $pictowithouttext = str_replace('_nocolor', '', $pictowithouttext);
1350
1351 // Fix some values of $pictowithouttext
1352 $pictoconvertkey = array(
1353 'facture' => 'bill',
1354 'shipping' => 'shipment',
1355 'fichinter' => 'intervention',
1356 'agenda' => 'calendar',
1357 'invoice_supplier' => 'supplier_invoice',
1358 'order_supplier' => 'supplier_order');
1359 if (in_array($pictowithouttext, array_keys($pictoconvertkey))) {
1360 $pictowithouttext = $pictoconvertkey[$pictowithouttext];
1361 }
1362
1363 if (strpos($pictowithouttext, 'fontawesome_') === 0 || strpos($pictowithouttext, 'fa-') === 0) {
1364 // This is a font awesome image 'fontawesome_xxx' or 'fa-xxx'
1365 $pictowithouttext = str_replace('fontawesome_', '', $pictowithouttext);
1366 $pictowithouttext = str_replace('fa-', '', $pictowithouttext);
1367
1368 // Compatibility with old fontawesome versions
1369 if ($pictowithouttext == 'file-o') {
1370 $pictowithouttext = 'file';
1371 }
1372
1373 $pictowithouttextarray = explode('_', $pictowithouttext);
1374 $marginleftonlyshort = 0;
1375
1376 if (!empty($pictowithouttextarray[1])) {
1377 // Syntax is 'fontawesome_fakey_faprefix_facolor_fasize' or 'fa-fakey_faprefix_facolor_fasize'
1378 $fakey = 'fa-' . $pictowithouttextarray[0];
1379 $faprefix = empty($pictowithouttextarray[1]) ? 'fas' : $pictowithouttextarray[1];
1380 $facolor = empty($pictowithouttextarray[2]) ? '' : $pictowithouttextarray[2];
1381 $fasize = empty($pictowithouttextarray[3]) ? '' : $pictowithouttextarray[3];
1382 } else {
1383 $fakey = 'fa-' . $pictowithouttext;
1384 $faprefix = 'fas';
1385 $facolor = '';
1386 $fasize = '';
1387 }
1388
1389 // This snippet only needed since function img_edit accepts only one additional parameter: no separate one for css only.
1390 // class/style need to be extracted to avoid duplicate class/style validation errors when $moreatt is added to the end of the attributes.
1391 $morestyle = '';
1392 $reg = array();
1393 if (preg_match('/class="([^"]+)"/', $moreatt, $reg)) {
1394 $morecss .= ($morecss ? ' ' : '') . $reg[1];
1395 $moreatt = str_replace('class="' . $reg[1] . '"', '', $moreatt);
1396 }
1397 if (preg_match('/style="([^"]+)"/', $moreatt, $reg)) {
1398 $morestyle = $reg[1];
1399 $moreatt = str_replace('style="' . $reg[1] . '"', '', $moreatt);
1400 }
1401 $moreatt = trim($moreatt);
1402
1403 $enabledisablehtml = '<span class="' . $faprefix . ' ' . $fakey;
1404 $enabledisablehtml .= ($morecss ? ' ' . $morecss : '') . '" style="' . ($fasize ? ('font-size: ' . $fasize . ';') : '') . ($facolor ? (' color: ' . $facolor . ';') : '') . ($morestyle ? ' ' . $morestyle : '') . '"' . (($notitle || empty($titlealt)) ? '' : ' title="' . dolPrintHTMLForAttribute($titlealt) . '"') . ($moreatt ? ' ' . $moreatt : '') . '>';
1405 $enabledisablehtml .= '</span>';
1406
1407 return $enabledisablehtml;
1408 }
1409
1410 if (empty($srconly) && !preg_match('/[\.\/@]/', $picto)) { // If original picto code does not contains a / and no . inside, it is not a path to an image file on disk
1411 $fakey = $pictowithouttext;
1412 $facolor = '';
1413 $fasize = '';
1414 $fa = getDolGlobalString('MAIN_FONTAWESOME_ICON_STYLE', 'fas');
1415 if (in_array($pictowithouttext, array('card', 'bell', 'clock', 'establishment', 'file', 'file-o', 'generic', 'minus-square', 'object_generic', 'pdf', 'plus-square', 'timespent', 'note', 'off', 'on', 'object_bookmark', 'bookmark', 'vcard'))) {
1416 $fa = 'far';
1417 }
1418 if (in_array($pictowithouttext, array('black-tie', 'discord', 'facebook', 'flickr', 'github', 'google', 'google-plus-g', 'instagram', 'linkedin', 'meetup', 'microsoft', 'pinterest', 'skype', 'slack', 'twitter', 'reddit', 'snapchat', 'stripe', 'stripe-s', 'tumblr', 'viadeo', 'whatsapp', 'youtube'))) {
1419 $fa = 'fab';
1420 }
1421
1422 $arrayconvpictotofa = getImgPictoConv('fa');
1423
1424 if ($pictowithouttext == 'off') {
1425 $fakey = 'fa-square';
1426 $fasize = '1.3em';
1427 } elseif ($pictowithouttext == 'on') {
1428 $fakey = 'fa-check-square';
1429 $fasize = '1.3em';
1430 } elseif ($pictowithouttext == 'listlight') {
1431 $fakey = 'fa-download';
1432 $marginleftonlyshort = 1;
1433 } elseif ($pictowithouttext == 'printer') {
1434 $fakey = 'fa-print';
1435 $fasize = '1.2em';
1436 } elseif ($pictowithouttext == 'note') {
1437 $fakey = 'fa-sticky-note';
1438 $marginleftonlyshort = 1;
1439 } elseif (in_array($pictowithouttext, array('1uparrow', '1downarrow', '1leftarrow', '1rightarrow', '1uparrow_selected', '1downarrow_selected', '1leftarrow_selected', '1rightarrow_selected'))) {
1440 $convertarray = array('1uparrow' => 'caret-up', '1downarrow' => 'caret-down', '1leftarrow' => 'caret-left', '1rightarrow' => 'caret-right', '1uparrow_selected' => 'caret-up', '1downarrow_selected' => 'caret-down', '1leftarrow_selected' => 'caret-left', '1rightarrow_selected' => 'caret-right');
1441 $fakey = 'fa-' . $convertarray[$pictowithouttext];
1442 if (preg_match('/selected/', $pictowithouttext)) {
1443 $facolor = '#888';
1444 }
1445 $marginleftonlyshort = 1;
1446 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
1447 $fakey = 'fa-' . $arrayconvpictotofa[$pictowithouttext];
1448 } else {
1449 $fakey = 'fa-' . $pictowithouttext;
1450 }
1451
1452 if (in_array($pictowithouttext, array('dollyrevert', 'member', 'members', 'contract', 'group', 'resource', 'shipment', 'reception'))) {
1453 $morecss .= ' em092';
1454 }
1455 if (in_array($pictowithouttext, array('conferenceorbooth', 'eventorganization', 'holiday', 'info', 'info_black', 'project', 'workstation'))) {
1456 $morecss .= ' em088';
1457 }
1458 if (in_array($pictowithouttext, array('asset', 'intervention', 'payment', 'loan', 'partnership', 'stock', 'technic'))) {
1459 $morecss .= ' em080';
1460 }
1461
1462 // Define $marginleftonlyshort
1463 $arrayconvpictotomarginleftonly = array(
1464 'bank',
1465 'check',
1466 'delete',
1467 'generic',
1468 'grip',
1469 'grip_title',
1470 'jabber',
1471 'grip_title',
1472 'grip',
1473 'listlight',
1474 'note',
1475 'on',
1476 'off',
1477 'playdisabled',
1478 'printer',
1479 'resize',
1480 'sign-out',
1481 'stats',
1482 'switch_on',
1483 'switch_on_grey',
1484 'switch_on_red',
1485 'switch_off',
1486 'switch_off_grey',
1487 'switch_off_red',
1488 'uparrow',
1489 '1uparrow',
1490 '1downarrow',
1491 '1leftarrow',
1492 '1rightarrow',
1493 '1uparrow_selected',
1494 '1downarrow_selected',
1495 '1leftarrow_selected',
1496 '1rightarrow_selected'
1497 );
1498 if (!array_key_exists($pictowithouttext, $arrayconvpictotomarginleftonly)) {
1499 $marginleftonlyshort = 0;
1500 }
1501
1502 // Add CSS
1503 $arrayconvpictotomorcess = array(
1504 'action' => 'infobox-action',
1505 'account' => 'infobox-bank_account',
1506 'accounting_account' => 'infobox-bank_account',
1507 'accountline' => 'infobox-bank_account',
1508 'accountancy' => 'infobox-bank_account',
1509 'admin' => 'opacitymedium',
1510 'asset' => 'infobox-bank_account',
1511 'bank_account' => 'infobox-bank_account',
1512 'bill' => 'infobox-commande',
1513 'billa' => 'infobox-commande',
1514 'billr' => 'infobox-commande',
1515 'billd' => 'infobox-commande',
1516 'bookcal' => 'infobox-portal',
1517 'margin' => 'infobox-bank_account',
1518 'conferenceorbooth' => 'infobox-project',
1519 'cash-register' => 'infobox-portal',
1520 'contract' => 'infobox-contrat',
1521 'check' => 'font-status4',
1522 'conversation' => 'infobox-contrat',
1523 'donation' => 'infobox-commande',
1524 'dolly' => 'infobox-commande',
1525 'dollyrevert' => 'flip infobox-order_supplier',
1526 'ecm' => 'infobox-action',
1527 'eventorganization' => 'infobox-project',
1528 'hrm' => 'infobox-adherent',
1529 'group' => 'infobox-adherent',
1530 'intervention' => 'infobox-contrat',
1531 'incoterm' => 'infobox-supplier_proposal',
1532 'intracommreport' => 'infobox-bank_account',
1533 'currency' => 'infobox-bank_account',
1534 'multicurrency' => 'infobox-bank_account',
1535 'members' => 'infobox-adherent',
1536 'member' => 'infobox-adherent',
1537 'money-bill-alt' => 'infobox-bank_account',
1538 'order' => 'infobox-commande',
1539 'user' => 'infobox-adherent',
1540 'users' => 'infobox-adherent',
1541 'error' => 'pictoerror',
1542 'warning' => 'pictowarning',
1543 'switch_on' => 'font-status4',
1544 'switch_on_warning' => 'font-status4 warning',
1545 'switch_on_red' => 'font-status8',
1546 'switch_off_warning' => 'font-status4 warning',
1547 'switch_off_red' => 'font-status8',
1548 'holiday' => 'infobox-holiday',
1549 'info' => 'opacityhigh',
1550 'info_black' => 'purple',
1551 'invoice' => 'infobox-commande',
1552 'knowledgemanagement' => 'infobox-contrat rotate90',
1553 'loan' => 'infobox-commande',
1554 'payment' => 'infobox-bank_account',
1555 'payment_vat' => 'infobox-bank_account',
1556 'poll' => 'infobox-portal',
1557 'pos' => 'infobox-bank_account',
1558 'project' => 'infobox-project',
1559 'projecttask' => 'infobox-project',
1560 'propal' => 'infobox-propal',
1561 'proposal' => 'infobox-propal',
1562 'private' => 'infobox-project',
1563 'reception' => 'flip infobox-order_supplier',
1564 'recruitmentjobposition' => 'infobox-adherent',
1565 'recruitmentcandidature' => 'infobox-adherent',
1566 'resource' => 'infobox-action',
1567 'salary' => 'infobox-commande',
1568 'shapes' => 'infobox-adherent',
1569 'shipment' => 'infobox-commande',
1570 'store' => 'infobox-portal',
1571 'stripe' => 'infobox-bank_account',
1572 'supplier_invoice' => 'infobox-order_supplier',
1573 'supplier_invoicea' => 'infobox-order_supplier',
1574 'supplier_invoiced' => 'infobox-order_supplier',
1575 'supplier_invoicer' => 'infobox-order_supplier',
1576 'supplier' => 'infobox-order_supplier',
1577 'supplier_order' => 'infobox-order_supplier',
1578 'supplier_proposal' => 'infobox-supplier_proposal',
1579 'ticket' => 'infobox-contrat',
1580 'title_accountancy' => 'infobox-bank_account',
1581 'title_hrm' => 'infobox-holiday',
1582 'expensereport' => 'infobox-expensereport',
1583 'trip' => 'infobox-expensereport',
1584 'title_agenda' => 'infobox-action',
1585 'vat' => 'infobox-bank_account',
1586 'webportal' => 'infobox-portal',
1587 'website' => 'infobox-portal',
1588 //'title_setup'=>'infobox-action', 'tools'=>'infobox-action',
1589 'list-alt' => 'imgforviewmode',
1590 'calendar' => 'imgforviewmode',
1591 'calendarweek' => 'imgforviewmode',
1592 'calendarmonth' => 'imgforviewmode',
1593 'calendarday' => 'imgforviewmode',
1594 'calendarperuser' => 'imgforviewmode',
1595 'calendarpertype' => 'imgforviewmode'
1596 );
1597 if (!empty($arrayconvpictotomorcess[$pictowithouttext]) && strpos($picto, '_nocolor') === false) {
1598 $morecss .= ($morecss ? ' ' : '') . $arrayconvpictotomorcess[$pictowithouttext];
1599 }
1600
1601 // Define $color
1602 $arrayconvpictotocolor = array(
1603 'address' => '#6c6aa8',
1604 'building' => '#6c6aa8',
1605 'bom' => '#a69944',
1606 'clone' => '#999',
1607 'cog' => '#999',
1608 'companies' => '#6c6aa8',
1609 'company' => '#6c6aa8',
1610 'contact' => '#6c6aa8',
1611 'cron' => '#555',
1612 'dynamicprice' => '#a69944',
1613 'edit' => '#444',
1614 'note' => '#999',
1615 'error' => '',
1616 'help' => '#bbb',
1617 'listlight' => '#999',
1618 'language' => '#555',
1619 //'dolly'=>'#a69944', 'dollyrevert'=>'#a69944',
1620 'lock' => '#ddd',
1621 'lot' => '#a69944',
1622 'map-marker-alt' => '#aaa',
1623 'mrp' => '#a69944',
1624 'product' => '#a69944',
1625 'service' => '#a69944',
1626 'inventory' => '#a69944',
1627 'stock' => '#a69944',
1628 'movement' => '#a69944',
1629 'other' => '#ddd',
1630 'world' => '#986c6a',
1631 'partnership' => '#6c6aa8',
1632 'playdisabled' => '#ccc',
1633 'printer' => '#444',
1634 'projectpub' => '#986c6a',
1635 'resize' => '#444',
1636 'rss' => '#cba',
1637 //'shipment'=>'#a69944',
1638 'search-plus' => '#808080',
1639 'security' => '#999',
1640 'square' => '#888',
1641 'stop-circle' => '#888',
1642 'stats' => '#444',
1643 'superadmin' => '#600',
1644 'switch_off' => '#999',
1645 'technic' => '#999',
1646 'tick' => '#282',
1647 'timespent' => '#555',
1648 'uncheck' => '#800',
1649 'uparrow' => '#555',
1650 'user-cog' => '#999',
1651 'country' => '#aaa',
1652 'globe-americas' => '#aaa',
1653 'region' => '#aaa',
1654 'state' => '#aaa',
1655 //'website' => '#304',
1656 'workstation' => '#a69944'
1657 );
1658 if (isset($arrayconvpictotocolor[$pictowithouttext]) && strpos($picto, '_nocolor') === false) {
1659 $facolor = $arrayconvpictotocolor[$pictowithouttext];
1660 }
1661
1662 // This snippet only needed since function img_edit accepts only one additional parameter: no separate one for css only.
1663 // class/style need to be extracted to avoid duplicate class/style validation errors when $moreatt is added to the end of the attributes.
1664 $morestyle = '';
1665 $reg = array();
1666 if (preg_match('/class="([^"]+)"/', $moreatt, $reg)) {
1667 $morecss .= ($morecss ? ' ' : '') . $reg[1];
1668 $moreatt = str_replace('class="' . $reg[1] . '"', '', $moreatt);
1669 }
1670 if (preg_match('/style="([^"]+)"/', $moreatt, $reg)) {
1671 $morestyle = $reg[1];
1672 $moreatt = str_replace('style="' . $reg[1] . '"', '', $moreatt);
1673 }
1674 $moreatt = trim($moreatt);
1675
1676 $enabledisablehtml = '<span class="' . $fa . ' ' . $fakey . ($marginleftonlyshort ? ($marginleftonlyshort == 1 ? ' marginleftonlyshort' : ' marginleftonly') : '');
1677 $enabledisablehtml .= ($morecss ? ' ' . $morecss : '') . '" style="' . ($fasize ? ('font-size: ' . $fasize . ';') : '') . ($facolor ? (' color: ' . $facolor . ';') : '') . ($morestyle ? ' ' . $morestyle : '') . '"' . (($notitle || empty($titlealt)) ? '' : ' title="' . dolPrintHTMLForAttribute($titlealt) . '"') . ($moreatt ? ' ' . $moreatt : '') . '>';
1678 $enabledisablehtml .= '</span>';
1679
1680 return $enabledisablehtml;
1681 }
1682
1683 if (getDolGlobalString('MAIN_OVERWRITE_THEME_PATH')) {
1684 $path = getDolGlobalString('MAIN_OVERWRITE_THEME_PATH') . '/theme/' . $theme; // If the theme does not have the same name as the module
1685 } elseif (getDolGlobalString('MAIN_OVERWRITE_THEME_RES')) {
1686 $path = getDolGlobalString('MAIN_OVERWRITE_THEME_RES') . '/theme/' . getDolGlobalString('MAIN_OVERWRITE_THEME_RES'); // To allow an external module to overwrite image resources whatever is activated theme
1687 } elseif (!empty($conf->modules_parts['theme']) && array_key_exists($theme, $conf->modules_parts['theme'])) {
1688 $path = $theme . '/theme/' . $theme; // If the theme have the same name as the module
1689 }
1690
1691 // If we ask an image into $url/$mymodule/img (instead of default path)
1692 $regs = array();
1693 if (preg_match('/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
1694 $picto = $regs[1];
1695 $path = $regs[2]; // $path is $mymodule
1696 }
1697
1698 // Clean parameters
1699 if (!preg_match('/(\.png|\.gif|\.svg)$/i', $picto)) {
1700 $picto .= '.png';
1701 }
1702 // If alt path are defined, define url where img file is, according to physical path
1703 // ex: array(["main"]=>"/home/maindir/htdocs", ["alt0"]=>"/home/moddir0/htdocs", ...)
1704 foreach ($conf->file->dol_document_root as $type => $dirroot) {
1705 if ($type == 'main') {
1706 continue;
1707 }
1708 // This consumes a lot of time, that's why enabling alternative dir like "custom" dir should be avoid
1709 if (file_exists($dirroot . '/' . $path . '/img/' . $picto) && !empty($conf->file->dol_url_root)) {
1710 $url = DOL_URL_ROOT . $conf->file->dol_url_root[$type];
1711 break;
1712 }
1713 }
1714
1715 // $url is '' or '/custom', $path is current theme or
1716 $fullpathpicto = $url . '/' . $path . '/img/' . $picto;
1717 }
1718
1719 if ($srconly) {
1720 return $fullpathpicto;
1721 }
1722
1723 // tag title is used for tooltip on <a>, tag alt can be used with very simple text on image for blind people
1724 return '<img src="' . $fullpathpicto . '"' . ($notitle ? '' : ' alt="' . dolPrintHTMLForAttribute($alt, 0, $allowothertags) . '"') . (($notitle || empty($titlealt)) ? '' : ' title="' . dolPrintHTMLForAttribute($titlealt, 0, $allowothertags) . '"') . ($moreatt ? ' ' . $moreatt . ($morecss ? ' class="' . $morecss . '"' : '') : ' class="inline-block' . ($morecss ? ' ' . $morecss : '') . '"') . '>'; // Alt is used for accessibility, title for popup
1725}
1726
1734function getImgPictoConv($mode = 'fa')
1735{
1736 global $conf;
1737
1738 if (empty($mode) || $mode == 'fa') {
1739 // Array when the fa picto key is different than the Dolibarr picto key.
1740 $arrayconvpictotofa = array(
1741 'account' => 'university',
1742 'accounting_account' => 'clipboard-list',
1743 'accountline' => 'receipt',
1744 'accountancy' => 'search-dollar',
1745 'action' => 'calendar-alt',
1746 'add' => 'plus-circle',
1747 'address' => 'address-book',
1748 'ai' => 'magic',
1749 'admin' => 'star',
1750 'asset' => 'money-check-alt',
1751 'autofill' => 'fill',
1752 'back' => 'arrow-left',
1753 'bank_account' => 'university',
1754 'bill' => 'file-invoice-dollar',
1755 'billa' => 'file-excel',
1756 'billr' => 'file-invoice-dollar',
1757 'billd' => 'file-medical',
1758 'blockedlog' => 'file-archive',
1759 'bookcal' => 'calendar-check',
1760 'supplier_invoice' => 'file-invoice-dollar',
1761 'supplier_invoicea' => 'file-excel',
1762 'supplier_invoicer' => 'file-invoice-dollar',
1763 'supplier_invoiced' => 'file-medical',
1764 'bom' => 'shapes',
1765 'card' => 'address-card',
1766 'chart' => 'chart-line',
1767 'company' => 'building',
1768 'contact' => 'address-book',
1769 'contract' => 'suitcase',
1770 'collab' => 'people-arrows',
1771 'conversation' => 'comments',
1772 'country' => 'globe-americas',
1773 'cron' => 'business-time',
1774 'cross' => 'times',
1775 'chevron-double-left' => 'angle-double-left',
1776 'chevron-double-right' => 'angle-double-right',
1777 'chevron-double-down' => 'angle-double-down',
1778 'chevron-double-top' => 'angle-double-up',
1779 'donation' => 'gift',
1780 'dynamicprice' => 'hand-holding-usd',
1781 'setup' => 'cog',
1782 'companies' => 'building',
1783 'products' => 'cube',
1784 'commercial' => 'suitcase',
1785 'invoicing' => 'coins',
1786 'accounting' => 'search-dollar',
1787 'category' => 'tag',
1788 'dollyrevert' => 'dolly',
1789 'file-o' => 'file',
1790 'generate' => 'plus-square',
1791 'hrm' => 'user-tie',
1792 'incoterm' => 'truck-loading',
1793 'margin' => 'calculator',
1794 'members' => 'user-friends',
1795 'ticket' => 'ticket-alt',
1796 'globe' => 'external-link-alt',
1797 'lot' => 'barcode',
1798 'email' => 'at',
1799 'establishment' => 'building',
1800 'edit' => 'pencil-alt',
1801 'entity' => 'globe',
1802 'graph' => 'chart-line',
1803 'grip_title' => 'arrows-alt',
1804 'grip' => 'arrows-alt',
1805 'help' => 'question-circle',
1806 'generic' => 'file',
1807 'holiday' => 'umbrella-beach',
1808 'info' => 'info-circle',
1809 'info_black' => 'info-circle',
1810 'inventory' => 'boxes',
1811 'intracommreport' => 'globe-europe',
1812 'jobprofile' => 'cogs',
1813 'knowledgemanagement' => 'ticket-alt',
1814 'label' => 'layer-group',
1815 'layout' => 'columns',
1816 'line' => 'bars',
1817 'loan' => 'money-bill-alt',
1818 'member' => 'user-alt',
1819 'meeting' => 'chalkboard-teacher',
1820 'mrp' => 'cubes',
1821 'next' => 'arrow-alt-circle-right',
1822 'trip' => 'wallet',
1823 'expensereport' => 'wallet',
1824 'group' => 'users',
1825 'movement' => 'people-carry',
1826 'sign-out' => 'sign-out-alt',
1827 'superadmin' => 'star',
1828 'switch_off' => 'toggle-off',
1829 'switch_off_grey' => 'toggle-off',
1830 'switch_off_warning' => 'toggle-off',
1831 'switch_off_red' => 'toggle-off',
1832 'switch_on' => 'toggle-on',
1833 'switch_on_grey' => 'toggle-on',
1834 'switch_on_warning' => 'toggle-on',
1835 'switch_on_red' => 'toggle-on',
1836 'check' => 'check',
1837 'bookmark' => 'star',
1838 'bank' => 'university',
1839 'close_title' => 'times',
1840 'delete' => 'trash',
1841 'filter' => 'filter',
1842 'list-alt' => 'list-alt',
1843 'calendarlist' => 'bars',
1844 'calendar' => 'calendar-alt',
1845 'calendarmonth' => 'calendar-alt',
1846 'calendarweek' => 'calendar-week',
1847 'calendarday' => 'calendar-day',
1848 'calendarperuser' => 'table',
1849 'calendarpertype' => 'table',
1850 'intervention' => 'ambulance',
1851 'invoice' => 'file-invoice-dollar',
1852 'order' => 'file-invoice',
1853 'error' => 'exclamation-triangle',
1854 'warning' => 'exclamation-triangle',
1855 'other' => 'square',
1856 'playdisabled' => 'play',
1857 'pdf' => 'file-pdf',
1858 'poll' => 'check-double',
1859 'pos' => 'cash-register',
1860 'preview' => 'binoculars',
1861 'project' => 'project-diagram',
1862 'projectpub' => 'project-diagram',
1863 'projecttask' => 'tasks',
1864 'propal' => 'file-signature',
1865 'proposal' => 'file-signature',
1866 'partnership' => 'handshake',
1867 'payment' => 'money-check-alt',
1868 'payment_vat' => 'money-check-alt',
1869 'pictoconfirm' => 'check-square',
1870 'phoning' => 'phone',
1871 'phoning_mobile' => 'mobile-alt',
1872 'phoning_fax' => 'fax',
1873 'previous' => 'arrow-alt-circle-left',
1874 'printer' => 'print',
1875 'product' => 'cube',
1876 'puce' => 'angle-right',
1877 'recent' => 'check-square',
1878 'reception' => 'dolly',
1879 'recruitmentjobposition' => 'id-card-alt',
1880 'recruitmentcandidature' => 'id-badge',
1881 'resize' => 'crop',
1882 'supplier_order' => 'dol-order_supplier',
1883 'supplier_proposal' => 'file-signature',
1884 'refresh' => 'redo',
1885 'region' => 'map-marked',
1886 'replacement' => 'exchange-alt',
1887 'resource' => 'laptop-house',
1888 'recurring' => 'history',
1889 'service' => 'concierge-bell',
1890 'skill' => 'shapes',
1891 'state' => 'map-marked-alt',
1892 'security' => 'key',
1893 'salary' => 'wallet',
1894 'shipment' => 'dolly',
1895 'stock' => 'box-open',
1896 'stats' => 'chart-bar',
1897 'split' => 'code-branch',
1898 'status' => 'stop-circle',
1899 'stripe' => 'stripe-s',
1900 'supplier' => 'building',
1901 'technic' => 'cogs',
1902 'tick' => 'check',
1903 'timespent' => 'clock',
1904 'title_setup' => 'tools',
1905 'title_accountancy' => 'money-check-alt',
1906 'title_bank' => 'university',
1907 'title_hrm' => 'umbrella-beach',
1908 'title_agenda' => 'calendar-alt',
1909 'uncheck' => 'times',
1910 'uparrow' => 'share',
1911 'url' => 'external-link-alt',
1912 'vat' => 'money-check-alt',
1913 'vcard' => 'arrow-alt-circle-down',
1914 'jabber' => 'comment',
1915 'website' => 'globe-americas',
1916 'workstation' => 'pallet',
1917 'webhook' => 'bullseye',
1918 'world' => 'globe',
1919 'private' => 'user-lock',
1920 'conferenceorbooth' => 'chalkboard-teacher',
1921 'eventorganization' => 'project-diagram',
1922 'webportal' => 'door-open'
1923 );
1924
1925 if ($conf->currency == 'EUR') {
1926 $arrayconvpictotofa['currency'] = 'euro-sign';
1927 $arrayconvpictotofa['multicurrency'] = 'dollar-sign';
1928 } else {
1929 $arrayconvpictotofa['currency'] = 'dollar-sign';
1930 $arrayconvpictotofa['multicurrency'] = 'euro-sign';
1931 }
1932 } else {
1933 $arrayconvpictotofa = array();
1934 }
1935
1936 return $arrayconvpictotofa;
1937}
1938
1939
1955function img_object($titlealt, $picto, $moreatt = '', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $allowothertags = array())
1956{
1957 return img_picto($titlealt, $picto, $moreatt, $pictoisfullpath, $srconly, $notitle, '', '', 2, $allowothertags);
1958}
1959
1971function img_weather($titlealt, $picto, $moreatt = '', $pictoisfullpath = 0, $morecss = '')
1972{
1973 global $conf;
1974
1975 if (is_numeric($picto)) {
1976 //$leveltopicto = array(0=>'weather-clear.png', 1=>'weather-few-clouds.png', 2=>'weather-clouds.png', 3=>'weather-many-clouds.png', 4=>'weather-storm.png');
1977 //$picto = $leveltopicto[$picto];
1978 return '<i class="fa fa-weather-level' . $picto . '"></i>';
1979 } elseif (!preg_match('/(\.png|\.gif)$/i', $picto)) {
1980 $picto .= '.png';
1981 }
1982
1983 $path = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/weather/' . $picto;
1984
1985 return img_picto($titlealt, $path, $moreatt, 1, 0, 0, '', $morecss);
1986}
1987
1999function img_picto_common($titlealt, $picto, $moreatt = '', $pictoisfullpath = 0, $notitle = 0)
2000{
2001 global $conf;
2002
2003 if (!preg_match('/(\.png|\.gif)$/i', $picto)) {
2004 $picto .= '.png';
2005 }
2006
2007 if ($pictoisfullpath) {
2008 $path = $picto;
2009 } else {
2010 $path = DOL_URL_ROOT . '/theme/common/' . $picto;
2011
2012 if (getDolGlobalInt('MAIN_MODULE_CAN_OVERWRITE_COMMONICONS')) {
2013 $themeimg = '/theme/' . $conf->theme . '/img/' . $picto;
2014
2015 if (file_exists(DOL_DOCUMENT_ROOT . $themeimg)) {
2016 $path = DOL_URL_ROOT . $themeimg;
2017 } elseif (!empty($conf->modules_parts['theme'])) { // Using this feature slow down application
2018 foreach ($conf->modules_parts['theme'] as $reldir) {
2019 if (file_exists(dol_buildpath($reldir . $themeimg, 0))) {
2020 $path = dol_buildpath($reldir . $themeimg, 1);
2021 break;
2022 }
2023 }
2024 }
2025 }
2026 }
2027
2028 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
2029}
2030
2044function img_action($titlealt, $numaction, $picto = '', $moreatt = '')
2045{
2046 global $langs;
2047
2048 if (empty($titlealt) || $titlealt == 'default') {
2049 if ($numaction == '-1' || $numaction == 'ST_NO') {
2050 $numaction = -1;
2051 $titlealt = $langs->transnoentitiesnoconv('ChangeDoNotContact');
2052 } elseif ($numaction == '0' || $numaction == 'ST_NEVER') {
2053 $numaction = 0;
2054 $titlealt = $langs->transnoentitiesnoconv('ChangeNeverContacted');
2055 } elseif ($numaction == '1' || $numaction == 'ST_TODO') {
2056 $numaction = 1;
2057 $titlealt = $langs->transnoentitiesnoconv('ChangeToContact');
2058 } elseif ($numaction == '2' || $numaction == 'ST_PEND') {
2059 $numaction = 2;
2060 $titlealt = $langs->transnoentitiesnoconv('ChangeContactInProcess');
2061 } elseif ($numaction == '3' || $numaction == 'ST_DONE') {
2062 $numaction = 3;
2063 $titlealt = $langs->transnoentitiesnoconv('ChangeContactDone');
2064 } else {
2065 $titlealt = $langs->transnoentitiesnoconv('ChangeStatus ' . $numaction);
2066 $numaction = 0;
2067 }
2068 }
2069 if (!is_numeric($numaction)) {
2070 $numaction = 0;
2071 }
2072
2073 return img_picto($titlealt, (empty($picto) ? 'stcomm' . $numaction . '.png' : $picto), $moreatt);
2074}
2075
2084function img_edit_add($titlealt = 'default', $other = '')
2085{
2086 global $langs;
2087
2088 if ($titlealt == 'default') {
2089 $titlealt = $langs->trans('Add');
2090 }
2091
2092 return img_picto($titlealt, 'edit_add.png', $other);
2093}
2102function img_edit_remove($titlealt = 'default', $other = '')
2103{
2104 global $langs;
2105
2106 if ($titlealt == 'default') {
2107 $titlealt = $langs->trans('Remove');
2108 }
2109
2110 return img_picto($titlealt, 'edit_remove.png', $other);
2111}
2112
2122function img_edit($titlealt = 'default', $float = 0, $other = '')
2123{
2124 global $langs;
2125
2126 if ($titlealt == 'default') {
2127 $titlealt = $langs->trans('Modify');
2128 }
2129
2130 return img_picto($titlealt, 'edit', ($float ? 'style="float: ' . ($langs->tab_translate["DIRECTION"] == 'rtl' ? 'left' : 'right') . '"' : "") . ($other ? ' ' . $other : ''));
2131}
2132
2142function img_view($titlealt = 'default', $float = 0, $other = 'class="valignmiddle"')
2143{
2144 global $langs;
2145
2146 if ($titlealt == 'default') {
2147 $titlealt = $langs->trans('View');
2148 }
2149
2150 $moreatt = ($float ? 'style="float: right" ' : '') . $other;
2151
2152 return img_picto($titlealt, 'eye', $moreatt);
2153}
2154
2164function img_delete($titlealt = 'default', $other = 'class="pictodelete"', $morecss = '')
2165{
2166 global $langs;
2167
2168 if ($titlealt == 'default') {
2169 $titlealt = $langs->trans('Delete');
2170 }
2171
2172 return img_picto($titlealt, 'delete', $other, 0, 0, 0, '', $morecss);
2173}
2174
2182function img_printer($titlealt = "default", $other = '')
2183{
2184 global $langs;
2185 if ($titlealt == "default") {
2186 $titlealt = $langs->trans("Print");
2187 }
2188 return img_picto($titlealt, 'printer', $other);
2189}
2190
2198function img_split($titlealt = 'default', $other = 'class="pictosplit"')
2199{
2200 global $langs;
2201
2202 if ($titlealt == 'default') {
2203 $titlealt = $langs->trans('Split');
2204 }
2205
2206 return img_picto($titlealt, 'split', $other);
2207}
2208
2217function img_help($usehelpcursor = 1, $usealttitle = 1)
2218{
2219 global $langs;
2220
2221 if ($usealttitle) {
2222 if (is_string($usealttitle)) {
2223 $usealttitle = dol_escape_htmltag($usealttitle);
2224 } else {
2225 $usealttitle = $langs->trans('Info');
2226 }
2227 }
2228
2229 return img_picto($usealttitle, 'info', 'style="vertical-align: middle;' . ($usehelpcursor == 1 ? ' cursor: help' : ($usehelpcursor == 2 ? ' cursor: pointer' : '')) . '"');
2230}
2231
2239function img_info($titlealt = 'default')
2240{
2241 global $langs;
2242
2243 if ($titlealt == 'default') {
2244 $titlealt = $langs->trans('Informations');
2245 }
2246
2247 return img_picto($titlealt, 'info', 'style="vertical-align: middle;"');
2248}
2249
2259function img_warning($titlealt = 'default', $moreatt = '', $morecss = 'pictowarning')
2260{
2261 global $langs;
2262
2263 if ($titlealt == 'default') {
2264 $titlealt = $langs->trans('Warning');
2265 }
2266
2267 //return '<div class="imglatecoin">'.img_picto($titlealt, 'warning_white.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): '')).'</div>';
2268 return img_picto($titlealt, 'warning', 'class="' . $morecss . '"' . ($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' ' . $moreatt) : ''));
2269}
2270
2278function img_error($titlealt = 'default')
2279{
2280 global $langs;
2281
2282 if ($titlealt == 'default') {
2283 $titlealt = $langs->trans('Error');
2284 }
2285
2286 return img_picto($titlealt, 'error');
2287}
2288
2296function img_next($titlealt = 'default', $moreatt = '')
2297{
2298 global $langs;
2299
2300 if ($titlealt == 'default') {
2301 $titlealt = $langs->trans('Next');
2302 }
2303
2304 //return img_picto($titlealt, 'next.png', $moreatt);
2305 return '<span class="fa fa-chevron-right paddingright paddingleft" title="' . dol_escape_htmltag($titlealt) . '"></span>';
2306}
2307
2315function img_previous($titlealt = 'default', $moreatt = '')
2316{
2317 global $langs;
2318
2319 if ($titlealt == 'default') {
2320 $titlealt = $langs->trans('Previous');
2321 }
2322
2323 //return img_picto($titlealt, 'previous.png', $moreatt);
2324 return '<span class="fa fa-chevron-left paddingright paddingleft" title="' . dol_escape_htmltag($titlealt) . '"></span>';
2325}
2326
2335function img_down($titlealt = 'default', $selected = 0, $moreclass = '')
2336{
2337 global $langs;
2338
2339 if ($titlealt == 'default') {
2340 $titlealt = $langs->trans('Down');
2341 }
2342
2343 return img_picto($titlealt, ($selected ? '1downarrow_selected' : '1downarrow'), 'class="imgdown' . ($moreclass ? " " . $moreclass : "") . '"');
2344}
2345
2354function img_up($titlealt = 'default', $selected = 0, $moreclass = '')
2355{
2356 global $langs;
2357
2358 if ($titlealt == 'default') {
2359 $titlealt = $langs->trans('Up');
2360 }
2361
2362 return img_picto($titlealt, ($selected ? '1uparrow_selected' : '1uparrow'), 'class="imgup' . ($moreclass ? " " . $moreclass : "") . '"');
2363}
2364
2373function img_left($titlealt = 'default', $selected = 0, $moreatt = '')
2374{
2375 global $langs;
2376
2377 if ($titlealt == 'default') {
2378 $titlealt = $langs->trans('Left');
2379 }
2380
2381 return img_picto($titlealt, ($selected ? '1leftarrow_selected' : '1leftarrow'), $moreatt);
2382}
2383
2392function img_right($titlealt = 'default', $selected = 0, $moreatt = '')
2393{
2394 global $langs;
2395
2396 if ($titlealt == 'default') {
2397 $titlealt = $langs->trans('Right');
2398 }
2399
2400 return img_picto($titlealt, ($selected ? '1rightarrow_selected' : '1rightarrow'), $moreatt);
2401}
2402
2410function img_allow($allow, $titlealt = 'default')
2411{
2412 global $langs;
2413
2414 if ($titlealt == 'default') {
2415 $titlealt = $langs->trans('Active');
2416 }
2417
2418 if ($allow == 1) {
2419 return img_picto($titlealt, 'tick');
2420 }
2421
2422 return '-';
2423}
2424
2432function img_credit_card($brand, $morecss = 'fa-2x inline-block valignmiddle')
2433{
2434 if (is_null($morecss)) {
2435 $morecss = 'fa-2x';
2436 }
2437
2438 if ($brand == 'visa' || $brand == 'Visa') {
2439 $brand = 'cc-visa';
2440 } elseif ($brand == 'mastercard' || $brand == 'MasterCard') {
2441 $brand = 'cc-mastercard';
2442 } elseif ($brand == 'amex' || $brand == 'American Express') {
2443 $brand = 'cc-amex';
2444 } elseif ($brand == 'discover' || $brand == 'Discover') {
2445 $brand = 'cc-discover';
2446 } elseif ($brand == 'jcb' || $brand == 'JCB') {
2447 $brand = 'cc-jcb';
2448 } elseif ($brand == 'diners' || $brand == 'Diners club') {
2449 $brand = 'cc-diners-club';
2450 } elseif (!in_array($brand, array('cc-visa', 'cc-mastercard', 'cc-amex', 'cc-discover', 'cc-jcb', 'cc-diners-club'))) {
2451 $brand = 'credit-card';
2452 }
2453
2454 return '<span class="fa fa-' . $brand . ' fa-fw' . ($morecss ? ' ' . $morecss : '') . '"></span>';
2455}
2456
2465function img_mime($file, $titlealt = '', $morecss = '')
2466{
2467 require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
2468
2469 $mimetype = dol_mimetype($file, '', 1);
2470 //$mimeimg = dol_mimetype($file, '', 2);
2471 $mimefa = dol_mimetype($file, '', 4);
2472
2473 if (empty($titlealt)) {
2474 $titlealt = 'Mime type: ' . $mimetype;
2475 }
2476
2477 //return img_picto_common($titlealt, 'mime/'.$mimeimg, 'class="'.$morecss.'"');
2478 return '<i class="fa fa-' . $mimefa . ' ' . (preg_match('/pictofixedwidth/', $morecss) ? '' : 'paddingright ') . ($morecss ? ' ' . $morecss : '') . '"' . ($titlealt ? ' title="' . dolPrintHTMLForAttribute($titlealt) . '"' : '') . '></i>';
2479}
2480
2481
2489function img_search($titlealt = 'default', $other = '')
2490{
2491 global $langs;
2492
2493 if ($titlealt == 'default') {
2494 $titlealt = $langs->trans('Search');
2495 }
2496
2497 $img = img_picto($titlealt, 'search', $other, 0, 1);
2498
2499 $input = '<input type="image" class="liste_titre" name="button_search" src="' . $img . '" ';
2500 $input .= 'value="' . dol_escape_htmltag($titlealt) . '" title="' . dol_escape_htmltag($titlealt) . '" >';
2501
2502 return $input;
2503}
2504
2512function img_searchclear($titlealt = 'default', $other = '')
2513{
2514 global $langs;
2515
2516 if ($titlealt == 'default') {
2517 $titlealt = $langs->trans('Search');
2518 }
2519
2520 $img = img_picto($titlealt, 'searchclear.png', $other, 0, 1);
2521
2522 $input = '<input type="image" class="liste_titre" name="button_removefilter" src="' . $img . '" ';
2523 $input .= 'value="' . dol_escape_htmltag($titlealt) . '" title="' . dol_escape_htmltag($titlealt) . '" >';
2524
2525 return $input;
2526}
2527
2542function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin = '1', $morecss = 'hideonsmartphone', $textfordropdown = '', $picto = '', $textonpictotooltip = '', $cssfordropdown = 'info_admin')
2543{
2544 global $conf, $langs;
2545
2546 if ($infoonimgalt) {
2547 $result = img_picto($text, 'info', 'class="' . ($morecss ? ' ' . $morecss : '') . '"');
2548 } else {
2549 if (empty($conf->use_javascript_ajax)) {
2550 $textfordropdown = '';
2551 }
2552
2553 $class = (empty($admin) ? 'undefined' : ((string) $admin == '1' ? 'info' : $admin));
2554 $fa = 'info-circle';
2555 if ($picto == 'warning') {
2556 $fa = 'exclamation-triangle';
2557 }
2558 $result = ($nodiv ? '' : '<div class="wordbreak ' . $class . ($cssfordropdown ? ' ' . $cssfordropdown : '') . ($morecss ? ' ' . $morecss : '') . ($textfordropdown ? ' hidden' : '') . '">');
2559 $result .= img_picto(((string) $admin ? $langs->trans('InfoAdmin') : $langs->trans('Note')).($textonpictotooltip ? ' : '.$textonpictotooltip : ''), $fa);
2560 $result .= ' ';
2561 $result .= dol_escape_htmltag($text, 1, 0, 'div,span,b,br,a');
2562 $result .= ($nodiv ? '' : '</div>');
2563
2564 if ($textfordropdown) {
2565 $tmpresult = '<span class="' . $class . ' '. $cssfordropdown.'text opacitymedium cursorpointer">' . $langs->trans($textfordropdown) . ' ' . img_picto($langs->trans($textfordropdown), '1downarrow') . '</span>';
2566 $tmpresult .= '<script nonce="' . getNonce() . '" type="text/javascript">
2567 jQuery(document).ready(function() {
2568 jQuery(".' . $cssfordropdown . 'text").click(function() {
2569 console.log("toggle text of .'.$cssfordropdown.'");
2570 jQuery(".' . $cssfordropdown . '").toggle().removeClass("hidden");
2571 });
2572 });
2573 </script>';
2574
2575 $result = $tmpresult . $result;
2576 }
2577 }
2578
2579 return $result;
2580}
2581
2582
2595function dol_print_error($db = null, $error = '', $errors = null)
2596{
2597 global $conf, $langs, $user, $argv;
2598 global $dolibarr_main_prod;
2599
2600 $out = '';
2601 $syslog = '';
2602
2603 // If error occurs before the $lang object was loaded
2604 if (!$langs) {
2605 require_once DOL_DOCUMENT_ROOT . '/core/class/translate.class.php';
2606 $langs = new Translate('', $conf);
2607 $langs->load("main");
2608 }
2609
2610 // Load translation files required by the error messages
2611 $langs->loadLangs(array('main', 'errors'));
2612
2613 if ($_SERVER['DOCUMENT_ROOT']) { // Mode web
2614 $out .= $langs->trans("DolibarrHasDetectedError") . ".<br>\n";
2615 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') > 0) {
2616 $out .= "You use an experimental or develop level of features, so please do NOT report any bugs or vulnerability, except if problem is confirmed after moving option MAIN_FEATURES_LEVEL back to 0.<br>\n";
2617 }
2618 $out .= $langs->trans("InformationToHelpDiagnose") . ":<br>\n";
2619
2620 $out .= "<b>" . $langs->trans("Date") . ":</b> " . dol_print_date(dol_now(), 'dayhourlog') . "<br>\n";
2621 $out .= "<b>" . $langs->trans("Dolibarr") . ":</b> " . DOL_VERSION . " - https://www.dolibarr.org<br>\n";
2622 if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
2623 $out .= "<b>" . $langs->trans("LevelOfFeature") . ":</b> " . getDolGlobalInt('MAIN_FEATURES_LEVEL') . "<br>\n";
2624 }
2625 if ($user instanceof User) {
2626 $out .= "<b>" . $langs->trans("Login") . ":</b> " . $user->login . "<br>\n";
2627 }
2628 if (function_exists("phpversion")) {
2629 $out .= "<b>" . $langs->trans("PHP") . ":</b> " . phpversion() . "<br>\n";
2630 }
2631 $out .= "<b>" . $langs->trans("Server") . ":</b> " . (isset($_SERVER["SERVER_SOFTWARE"]) ? dol_htmlentities($_SERVER["SERVER_SOFTWARE"], ENT_COMPAT) : '') . "<br>\n";
2632 if (function_exists("php_uname")) {
2633 $out .= "<b>" . $langs->trans("OS") . ":</b> " . php_uname() . "<br>\n";
2634 }
2635 $out .= "<b>" . $langs->trans("UserAgent") . ":</b> " . (isset($_SERVER["HTTP_USER_AGENT"]) ? dol_htmlentities($_SERVER["HTTP_USER_AGENT"], ENT_COMPAT) : '') . "<br>\n";
2636 $out .= "<br>\n";
2637 $out .= "<b>" . $langs->trans("RequestedUrl") . ":</b> " . (isset($_SERVER["REQUEST_URI"]) ? dol_htmlentities($_SERVER["REQUEST_URI"], ENT_COMPAT) : '') . "<br>\n";
2638 $out .= "<b>" . $langs->trans("Referer") . ":</b> " . (isset($_SERVER["HTTP_REFERER"]) ? dol_htmlentities($_SERVER["HTTP_REFERER"], ENT_COMPAT) : '') . "<br>\n";
2639 $out .= "<b>" . $langs->trans("MenuManager") . ":</b> " . (isset($conf->standard_menu) ? dol_htmlentities($conf->standard_menu, ENT_COMPAT) : '') . "<br>\n";
2640 $out .= "<br>\n";
2641 $syslog .= "url=" . (isset($_SERVER["REQUEST_URI"]) ? dol_escape_htmltag($_SERVER["REQUEST_URI"]) : '');
2642 $syslog .= ", query_string=" . (isset($_SERVER["QUERY_STRING"]) ? dol_escape_htmltag($_SERVER["QUERY_STRING"]) : '');
2643 } else { // Mode CLI
2644 $out .= '> ' . $langs->transnoentities("ErrorInternalErrorDetected") . ":\n" . $argv[0] . "\n";
2645 $syslog .= "pid=" . dol_getmypid();
2646 }
2647
2648 if (!empty($conf->modules)) {
2649 $out .= "<b>" . $langs->trans("Modules") . ":</b> " . implode(', ', $conf->modules) . "<br>\n";
2650 }
2651
2652 if (is_object($db)) {
2653 if ($_SERVER['DOCUMENT_ROOT']) { // Mode web
2654 $out .= "<b>" . $langs->trans("DatabaseTypeManager") . ":</b> " . $db->type . "<br>\n";
2655 $lastqueryerror = $db->lastqueryerror();
2656 if (!utf8_check($lastqueryerror)) {
2657 $lastqueryerror = "SQL error string is not a valid UTF8 string. We can't show it.";
2658 }
2659 $out .= "<b>" . $langs->trans("RequestLastAccessInError") . ":</b> " . ($lastqueryerror ? dol_escape_htmltag($lastqueryerror) : $langs->trans("ErrorNoRequestInError")) . "<br>\n";
2660 $out .= "<b>" . $langs->trans("ReturnCodeLastAccessInError") . ":</b> " . ($db->lasterrno() ? dol_escape_htmltag($db->lasterrno()) : $langs->trans("ErrorNoRequestInError")) . "<br>\n";
2661 $out .= "<b>" . $langs->trans("InformationLastAccessInError") . ":</b> " . ($db->lasterror() ? dol_escape_htmltag($db->lasterror()) : $langs->trans("ErrorNoRequestInError")) . "<br>\n";
2662 $out .= "<br>\n";
2663 } else { // Mode CLI
2664 // No dol_escape_htmltag for output, we are in CLI mode
2665 $out .= '> ' . $langs->transnoentities("DatabaseTypeManager") . ":\n" . $db->type . "\n";
2666 $out .= '> ' . $langs->transnoentities("RequestLastAccessInError") . ":\n" . ($db->lastqueryerror() ? $db->lastqueryerror() : $langs->transnoentities("ErrorNoRequestInError")) . "\n";
2667 $out .= '> ' . $langs->transnoentities("ReturnCodeLastAccessInError") . ":\n" . ($db->lasterrno() ? $db->lasterrno() : $langs->transnoentities("ErrorNoRequestInError")) . "\n";
2668 $out .= '> ' . $langs->transnoentities("InformationLastAccessInError") . ":\n" . ($db->lasterror() ? $db->lasterror() : $langs->transnoentities("ErrorNoRequestInError")) . "\n";
2669 }
2670 $syslog .= ", sql=" . $db->lastquery();
2671 $syslog .= ", db_error=" . $db->lasterror();
2672 }
2673
2674 if ($error || $errors) {
2675 // Merge all into $errors array
2676 if (is_array($error) && is_array($errors)) {
2677 $errors = array_merge($error, $errors);
2678 } elseif (is_array($error)) { // deprecated, use second parameters
2679 $errors = $error;
2680 } elseif (is_array($errors) && !empty($error)) {
2681 $errors = array_merge(array($error), $errors);
2682 } elseif (!empty($error)) {
2683 $errors = array_merge(array($error), array($errors));
2684 }
2685
2686 $langs->load("errors");
2687
2688 foreach ($errors as $msg) {
2689 if (empty($msg)) {
2690 continue;
2691 }
2692 if ($_SERVER['DOCUMENT_ROOT']) { // Mode web
2693 $out .= "<b>" . $langs->trans("Message") . ":</b> " . dol_escape_htmltag($msg) . "<br>\n";
2694 } else { // Mode CLI
2695 $out .= '> ' . $langs->transnoentities("Message") . ":\n" . $msg . "\n";
2696 }
2697 $syslog .= ", msg=" . $msg;
2698 }
2699 }
2700 if (empty($dolibarr_main_prod) && $_SERVER['DOCUMENT_ROOT'] && function_exists('xdebug_print_function_stack') && function_exists('xdebug_call_file')) {
2701 xdebug_print_function_stack();
2702 $out .= '<b>XDebug information:</b>' . "<br>\n";
2703 $out .= 'File: ' . xdebug_call_file() . "<br>\n";
2704 $out .= 'Line: ' . xdebug_call_line() . "<br>\n";
2705 $out .= 'Function: ' . xdebug_call_function() . "<br>\n";
2706 $out .= "<br>\n";
2707 }
2708
2709 // Return a http header with error code if possible
2710 if (!headers_sent()) {
2711 if (function_exists('top_httphead')) { // In CLI context, the method does not exists
2712 top_httphead();
2713 }
2714 //http_response_code(500); // If we use 500, message is not output with some command line tools
2715 http_response_code(202); // If we use 202, this is not really an error message, but this allow to output message on command line tools
2716 }
2717
2718 if (empty($dolibarr_main_prod)) {
2719 print $out;
2720 } else {
2721 if (empty($langs->defaultlang)) {
2722 $langs->setDefaultLang();
2723 }
2724 $langs->loadLangs(array("main", "errors")); // Reload main because language may have been set only on previous line so we have to reload files we need.
2725 // This should not happen, except if there is a bug somewhere. Enabled and check log in such case.
2726 print 'This website or feature is currently temporarily not available or failed after a technical error.<br><br>This may be due to a maintenance operation. Current status of operation (' . dol_print_date(dol_now(), 'dayhourrfc') . ') are on next line...<br><br>' . "\n";
2727 print $langs->trans("DolibarrHasDetectedError") . '. ';
2728 print $langs->trans("YouCanSetOptionDolibarrMainProdToZero");
2729 if (!defined("MAIN_CORE_ERROR")) {
2730 define("MAIN_CORE_ERROR", 1);
2731 }
2732 }
2733
2734 dol_syslog("Error " . $syslog, LOG_ERR);
2735}
2736
2747function dol_print_error_email($prefixcode, $errormessage = '', $errormessages = array(), $morecss = 'error', $email = '')
2748{
2749 global $langs;
2750
2751 if (empty($email)) {
2752 $email = getDolGlobalString('MAIN_INFO_SOCIETE_MAIL');
2753 }
2754
2755 $langs->load("errors");
2756 $now = dol_now();
2757
2758 print '<br><div class="center login_main_message"><div class="' . $morecss . '">';
2759 print $langs->trans("ErrorContactEMail", $email, $prefixcode . '-' . dol_print_date($now, '%Y%m%d%H%M%S'));
2760 if ($errormessage) {
2761 print '<br><br>' . $errormessage;
2762 }
2763 if (is_array($errormessages) && count($errormessages)) {
2764 foreach ($errormessages as $mesgtoshow) {
2765 print '<br><br>' . $mesgtoshow;
2766 }
2767 }
2768 print '</div></div>';
2769}
2770
2787function print_liste_field_titre($name, $file = "", $field = "", $begin = "", $param = "", $moreattrib = "", $sortfield = "", $sortorder = "", $prefix = "", $tooltip = "", $forcenowrapcolumntitle = 0)
2788{
2789 print getTitleFieldOfList($name, 0, $file, $field, $begin, $param, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
2790}
2791
2810function getTitleFieldOfList($name, $thead = 0, $file = "", $field = "", $begin = "", $moreparam = "", $moreattrib = "", $sortfield = "", $sortorder = "", $prefix = "", $disablesortlink = 0, $tooltip = '', $forcenowrapcolumntitle = 0)
2811{
2812 global $langs, $form;
2813 //print "$name, $file, $field, $begin, $options, $moreattrib, $sortfield, $sortorder<br>\n";
2814
2815 if ($moreattrib == 'class="right"') {
2816 $prefix .= 'right '; // For backward compatibility
2817 }
2818
2819 $tooltip = (string) $tooltip; // In case $tooltip is null
2820
2821 $sortorder = strtoupper((string) $sortorder);
2822 $out = '';
2823 $sortimg = '';
2824
2825 $tag = 'th';
2826 if ($thead == 2) {
2827 $tag = 'div';
2828 }
2829
2830 $tmpsortfield = explode(',', (string) $sortfield);
2831 $sortfield1 = trim($tmpsortfield[0]); // If $sortfield is 'd.datep,d.id', it becomes 'd.datep'
2832 $tmpfield = explode(',', $field);
2833 $field1 = trim($tmpfield[0]); // If $field is 'd.datep,d.id', it becomes 'd.datep'
2834
2835 if (strpos((string) $tooltip, ':') !== false) {
2836 $tmptooltip = explode(':', (string) $tooltip);
2837 } else {
2838 $tmptooltip = array($tooltip);
2839 }
2840
2841 $wrapcolumntitle = (empty($forcenowrapcolumntitle) || (!empty($tmptooltip[2]) && $tmptooltip[2] == '-1'));
2842
2843 if (!getDolGlobalString('MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE') && $wrapcolumntitle) {
2844 $prefix = 'wrapcolumntitle ' . $prefix;
2845 }
2846
2847 //var_dump('field='.$field.' field1='.$field1.' sortfield='.$sortfield.' sortfield1='.$sortfield1);
2848 // If field is used as sort criteria we use a specific css class liste_titre_sel
2849 // Example if (sortfield,field)=("nom","xxx.nom") or (sortfield,field)=("nom","nom")
2850 $liste_titre = 'liste_titre';
2851 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace("/^[^\.]+\./", "", $field1))) {
2852 $liste_titre = 'liste_titre_sel';
2853 }
2854
2855 $tagstart = '<' . $tag . ' class="' . $prefix . $liste_titre . '" ' . $moreattrib;
2856 //$out .= (($field && empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && preg_match('/^[a-zA-Z_0-9\s\.\-:&;]*$/', $name)) ? ' title="'.dol_escape_htmltag($langs->trans($name)).'"' : '');
2857 $tagstart .= ($name && !getDolGlobalString('MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE') && $wrapcolumntitle && !dol_textishtml($name)) ? ' title="' . dolPrintHTMLForAttribute($langs->trans($name)) . '"' : '';
2858 $tagstart .= '>';
2859
2860 if (empty($thead) && $field && empty($disablesortlink)) { // If this is a sort field
2861 $options = preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i', '', (is_scalar($moreparam) ? $moreparam : ''));
2862 $options = preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i', '', $options);
2863 $options = preg_replace('/&+/i', '&', $options);
2864 if (!preg_match('/^&/', $options)) {
2865 $options = '&' . $options;
2866 }
2867
2868 $sortordertouseinlink = '';
2869 if ($field1 != $sortfield1) { // We are on another field than current sorted field
2870 if (preg_match('/^DESC/i', $sortorder)) {
2871 $sortordertouseinlink .= str_repeat('desc,', count(explode(',', $field)));
2872 } else { // We reverse the var $sortordertouseinlink
2873 $sortordertouseinlink .= str_repeat('asc,', count(explode(',', $field)));
2874 }
2875 } else { // We are on field that is the first current sorting criteria
2876 if (preg_match('/^ASC/i', $sortorder)) { // We reverse the var $sortordertouseinlink
2877 $sortordertouseinlink .= str_repeat('desc,', count(explode(',', $field)));
2878 } else {
2879 $sortordertouseinlink .= str_repeat('asc,', count(explode(',', $field)));
2880 }
2881 }
2882 $sortordertouseinlink = preg_replace('/,$/', '', $sortordertouseinlink);
2883 $out .= '<a class="reposition" href="' . dolBuildUrl($file, ['sortfield' => $field, 'sortorder' => $sortordertouseinlink, 'begin' => $begin]) . $options . '"';
2884 //$out .= (getDolGlobalString('MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE') ? '' : ' title="'.dol_escape_htmltag($langs->trans($name)).'"');
2885 $out .= '>';
2886 }
2887 if ($tooltip && $tmptooltip[0]) {
2888 // You can also use 'TranslationString:[keyfortooltiponclick]:[tooltipdirection]' for a tooltip on click or to change tooltip position.
2889 $out .= $form->textwithpicto($langs->trans((string) $name), $langs->trans((string) $tmptooltip[0]), (empty($tmptooltip[2]) ? '1' : $tmptooltip[2]), 'help', ((!empty($tmptooltip[2]) && $tmptooltip[2] == '-1') ? 'paddingrightonly' : ''), 0, 3, (empty($tmptooltip[1]) ? '' : 'extra_' . str_replace('.', '_', $field) . '_' . $tmptooltip[1]));
2890 } else {
2891 $out .= $langs->trans((string) $name);
2892 }
2893
2894 if (empty($thead) && $field && empty($disablesortlink)) { // If this is a sort field
2895 $out .= '</a>';
2896 }
2897
2898 if (empty($thead) && $field) { // If this is a sort field
2899 $options = preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i', '', (is_scalar($moreparam) ? $moreparam : ''));
2900 $options = preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i', '', $options);
2901 $options = preg_replace('/&+/i', '&', $options);
2902 if (!preg_match('/^&/', $options)) {
2903 $options = '&' . $options;
2904 }
2905
2906 if (!$sortorder || ($field1 != $sortfield1)) {
2907 // Nothing
2908 } else {
2909 if (preg_match('/^DESC/', $sortorder)) {
2910 $sortimg .= '<span class="nowrap">' . img_up("Z-A", 0, 'paddingright') . '</span>';
2911 }
2912 if (preg_match('/^ASC/', $sortorder)) {
2913 $sortimg .= '<span class="nowrap">' . img_down("A-Z", 0, 'paddingright') . '</span>';
2914 }
2915 }
2916 }
2917
2918 $tagend = '</' . $tag . '>';
2919
2920 $out = $tagstart . $sortimg . $out . $tagend;
2921
2922 return $out;
2923}
2924
2934function print_titre($title)
2935{
2936 dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
2937
2938 print '<div class="titre">' . $title . '</div>';
2939}
2940
2953function print_fiche_titre($title, $mesg = '', $picto = 'generic', $pictoisfullpath = 0, $id = '')
2954{
2955 print load_fiche_titre($title, $mesg, $picto, $pictoisfullpath, $id);
2956}
2957
2972function load_fiche_titre($title, $morehtmlright = '', $picto = 'generic', $pictoisfullpath = 0, $id = '', $morecssontable = '', $morehtmlcenter = '', $morecssonpicto = 'widthpictotitle')
2973{
2974 $return = '';
2975
2976 if ($picto == 'setup') {
2977 $picto = 'generic';
2978 }
2979
2980 $return .= "\n";
2981 $return .= '<table ' . ($id ? 'id="' . $id . '" ' : '') . 'class="centpercent notopnoleftnoright table-fiche-title' . ($morecssontable ? ' ' . $morecssontable : '') . '">'; // margin bottom must be same than into print_barre_list
2982 $return .= '<tr class="toptitle">';
2983 if ($picto) {
2984 $return .= '<td class="nobordernopadding widthpictotitle valignmiddle col-picto">' . img_picto('', $picto, 'class="valignmiddle pictotitle'.($morecssonpicto ? ' '.$morecssonpicto : '').'"', $pictoisfullpath) . '</td>';
2985 }
2986 $return .= '<td class="nobordernopadding valignmiddle col-title">';
2987 $return .= '<div class="titre inline-block">';
2988 $return .= '<span class="inline-block valignmiddle print-barre-liste">' . $title . '</span>'; // $title is already HTML sanitized content
2989 $return .= '</div>';
2990 $return .= '</td>';
2991 if (dol_strlen($morehtmlcenter)) {
2992 $return .= '<td class="nobordernopadding center valignmiddle col-center">' . $morehtmlcenter . '</td>';
2993 }
2994 if (dol_strlen($morehtmlright)) {
2995 $return .= '<td class="nobordernopadding titre_right wordbreakimp right valignmiddle col-right">' . $morehtmlright . '</td>';
2996 }
2997 $return .= '</tr></table>' . "\n";
2998
2999 return $return;
3000}
3001
3026function print_barre_liste($title, $page, $file, $options = '', $sortfield = '', $sortorder = '', $morehtmlcenter = '', $num = -1, $totalnboflines = '', $picto = 'generic', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '', $limit = -1, $selectlimitsuffix = 0, $hidenavigation = 0, $pagenavastextinput = 0, $morehtmlrightbeforearrow = '')
3027{
3028 global $conf, $langs;
3029
3030 $savlimit = $limit;
3031 $savtotalnboflines = $totalnboflines;
3032 if (is_numeric($totalnboflines)) {
3033 $totalnboflines = abs($totalnboflines);
3034 }
3035
3036 // Detect if there is a subtitle
3037 $subtitle = '';
3038 $tmparray = preg_split('/<br>/i', $title, 2);
3039 if (!empty($tmparray[1])) {
3040 $title = $tmparray[0];
3041 $subtitle = $tmparray[1];
3042 }
3043
3044 $page = (int) $page;
3045
3046 if ($picto == 'setup') {
3047 $picto = 'title_setup';
3048 }
3049 if (($conf->browser->name == 'ie') && $picto == 'generic') {
3050 $picto = 'title.gif';
3051 }
3052 if ($limit < 0) {
3053 $limit = $conf->liste_limit;
3054 }
3055
3056 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
3057 $nextpage = 1;
3058 } else {
3059 $nextpage = 0;
3060 }
3061 //print 'totalnboflines='.$totalnboflines.'-savlimit='.$savlimit.'-limit='.$limit.'-num='.$num.'-nextpage='.$nextpage.'-selectlimitsuffix='.$selectlimitsuffix.'-hidenavigation='.$hidenavigation;
3062
3063 print "\n";
3064 print "<!-- Begin print_barre_liste -->\n";
3065 print '<table class="centpercent notopnoleftnoright table-fiche-title' . ($morecss ? ' ' . $morecss : '') . '">';
3066 print '<tr class="toptitle">'; // margin bottom must be same than into load_fiche_tire
3067
3068 // Left
3069
3070 if ($picto && $title) {
3071 print '<td class="nobordernopadding widthpictotitle valignmiddle col-picto">';
3072 print img_picto('', $picto, 'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath);
3073 print '</td>';
3074 }
3075
3076 print '<td class="nobordernopadding valignmiddle col-title">';
3077 print '<div class="titre inline-block nowrap">';
3078 print '<span class="inline-block valignmiddle print-barre-liste">' . $title . '</span>'; // $title may contains HTML like a combo list from page consumption.php, so we do not use dolPrintLabel here()
3079 if (!empty($title) && $savtotalnboflines >= 0 && (string) $savtotalnboflines != '') {
3080 if (is_numeric($totalnboflines) && (int) $totalnboflines > 0) {
3081 print '<span class="opacitymedium colorblack marginleftonly totalnboflines valignmiddle" title="' . $langs->trans("NbRecordQualified") . '">(' . $totalnboflines . ')</span>';
3082 } else {
3083 print '<span class="opacitymedium colorblack marginleftonly totalnboflines valignmiddle">(' . $totalnboflines . ')</span>';
3084 }
3085 }
3086 print '</div>';
3087 if (!empty($subtitle)) {
3088 print '<br><div class="subtitle inline-block hideonsmartphone">' . $subtitle . '</div>';
3089 }
3090 print '</td>';
3091
3092 // Center
3093 if ($morehtmlcenter && empty($conf->dol_optimize_smallscreen)) {
3094 print '<td class="nobordernopadding center valignmiddle col-center">' . $morehtmlcenter . '</td>';
3095 }
3096
3097 // Right
3098 print '<td class="nobordernopadding valignmiddle right col-right">';
3099 print '<input type="hidden" name="pageplusoneold" value="' . ((int) $page + 1) . '">';
3100 $query = [];
3101 parse_str($options, $query);
3102 if ($sortfield) {
3103 $query += ['sortfield' => $sortfield];
3104 }
3105 if ($sortorder) {
3106 $query += ['sortorder' => $sortorder];
3107 }
3108
3109 $options = '&' . http_build_query($query);
3110 if ($page) {
3111 $query = array_merge($query, ['page' => $page]);
3112 }
3113 // Show navigation bar
3114 $pagelist = '';
3115 if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
3116 if ($totalnboflines) { // If we know total nb of lines
3117 // Define nb of extra page links before and after selected page + ... + first or last
3118 $maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 0);
3119
3120 if ($limit > 0) {
3121 $nbpages = ceil($totalnboflines / $limit);
3122 } else {
3123 $nbpages = 1;
3124 }
3125 $cpt = ($page - $maxnbofpage);
3126 if ($cpt < 0) {
3127 $cpt = 0;
3128 }
3129
3130 if ($cpt >= 1) {
3131 if (empty($pagenavastextinput)) {
3132 $query['page'] = 0;
3133 $pagelist .= '<li class="pagination"><a class="reposition" href="' . dolBuildUrl($file, $query) . '">1</a></li>';
3134 if ($cpt > 2) {
3135 $pagelist .= '<li class="pagination"><span class="inactive">...</span></li>';
3136 } elseif ($cpt == 2) {
3137 $query['page'] = 0;
3138 $pagelist .= '<li class="pagination"><a class="reposition" href="' . dolBuildUrl($file, $query) . '">2</a></li>';
3139 }
3140 }
3141 }
3142
3143 do {
3144 if ($pagenavastextinput) {
3145 if ($cpt == $page) {
3146 $pagelist .= '<li class="pagination pageplusone valignmiddle"><input type="text" class="' . ($totalnboflines > 100 ? 'width40' : 'width25') . ' center pageplusone heightofcombo" name="pageplusone" value="' . ($page + 1) . '"></li>';
3147 $pagelist .= '/';
3148 }
3149 } else {
3150 if ($cpt == $page) {
3151 $pagelist .= '<li class="pagination"><span class="active">' . ($page + 1) . '</span></li>';
3152 } else {
3153 $query['page'] = $cpt;
3154 $pagelist .= '<li class="pagination"><a class="reposition" href="' . dolBuildUrl($file, $query) . '">' . ($cpt + 1) . '</a></li>';
3155 }
3156 }
3157 $cpt++;
3158 } while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
3159
3160 if (empty($pagenavastextinput)) {
3161 if ($cpt < $nbpages) {
3162 if ($cpt < $nbpages - 2) {
3163 $pagelist .= '<li class="pagination"><span class="inactive">...</span></li>';
3164 } elseif ($cpt == $nbpages - 2) {
3165 $query['page'] = ($nbpages - 2);
3166 $pagelist .= '<li class="pagination"><a class="reposition" href="' . dolBuildUrl($file, $query) . '">' . ($nbpages - 1) . '</a></li>';
3167 }
3168 $query['page'] = ($nbpages - 1);
3169 $pagelist .= '<li class="pagination"><a class="reposition" href="' . dolBuildUrl($file, $query) . '">' . $nbpages . '</a></li>';
3170 }
3171 } else {
3172 $query['page'] = ($nbpages - 1);
3173 $pagelist .= '<li class="pagination paginationlastpage"><a class="reposition" href="' . dolBuildUrl($file, $query) . '">' . $nbpages . '</a></li>';
3174 }
3175 } else {
3176 $pagelist .= '<li class="pagination"><span class="active">' . ($page + 1) . "</li>";
3177 }
3178 }
3179
3180 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
3181 // Show the combolist to select number of record per page and the navigation arrows.
3182 print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $selectlimitsuffix, $morehtmlrightbeforearrow, $hidenavigation); // output the div and ul for previous/last completed with page numbers into $pagelist
3183 }
3184
3185 // js to autoselect page field on focus
3186 if ($pagenavastextinput) {
3187 print ajax_autoselect('.pageplusone');
3188 }
3189
3190 print '</td>';
3191 print '</tr>';
3192
3193 print "</table>\n";
3194
3195 // Center
3196 if ($morehtmlcenter && !empty($conf->dol_optimize_smallscreen)) {
3197 print '<div class="nobordernopadding marginbottomonly center valignmiddle col-center centpercent">' . $morehtmlcenter . '</div>';
3198 }
3199
3200 print "<!-- End title -->\n\n";
3201}
3202
3219function print_fleche_navigation($page, $file, $options = '', $nextpage = 0, $betweenarrows = '', $afterarrows = '', $limit = -1, $totalnboflines = 0, $selectlimitsuffix = '', $beforearrows = '', $hidenavigation = 0)
3220{
3221 global $conf, $langs;
3222
3223 print '<div class="pagination"><ul>';
3224 if ($beforearrows) {
3225 print '<li class="paginationbeforearrows">';
3226 print $beforearrows;
3227 print '</li>';
3228 }
3229
3230 if (empty($hidenavigation)) {
3231 if ((int) $limit > 0 && (empty($selectlimitsuffix) || !is_numeric($selectlimitsuffix))) {
3232 $pagesizechoices = '10:10,15:15,20:20,25:25,50:50,100:100,250:250,500:500,1000:1000';
3233 $pagesizechoices .= ',5000:5000';
3234 //$pagesizechoices .= ',10000:10000'; // Memory trouble on most browsers
3235 //$pagesizechoices .= ',20000:20000'; // Memory trouble on most browsers
3236 //$pagesizechoices .= ',0:'.$langs->trans("All"); // Not yet supported
3237 //$pagesizechoices .= ',2:2';
3238 if (getDolGlobalString('MAIN_PAGESIZE_CHOICES')) {
3239 $pagesizechoices = getDolGlobalString('MAIN_PAGESIZE_CHOICES');
3240 }
3241
3242 if (getDolGlobalString('MAIN_USE_HTML5_LIMIT_SELECTOR')) {
3243 print '<li class="pagination">';
3244 print '<input onfocus="this.value=null;" onchange="this.blur();" class="flat selectlimit nopadding maxwidth75 right pageplusone" id="limit" name="limit" list="limitlist" title="' . dol_escape_htmltag($langs->trans("MaxNbOfRecordPerPage")) . '" value="' . $limit . '">';
3245 print '<datalist id="limitlist">';
3246 } else {
3247 print '<li class="paginationcombolimit valignmiddle">';
3248 print '<select id="limit' . (is_numeric($selectlimitsuffix) ? '' : $selectlimitsuffix) . '" name="'.(is_numeric($selectlimitsuffix) ? 'limit' : $selectlimitsuffix).'" class="flat selectlimit nopadding maxwidth75 center' . (is_numeric($selectlimitsuffix) ? '' : ' ' . $selectlimitsuffix) . '" title="' . dol_escape_htmltag($langs->trans("MaxNbOfRecordPerPage")) . '">';
3249 }
3250 $tmpchoice = explode(',', $pagesizechoices);
3251 $tmpkey = $limit . ':' . $limit;
3252 if (!in_array($tmpkey, $tmpchoice)) {
3253 $tmpchoice[$tmpkey] = $tmpkey;
3254 }
3255 $tmpkey = $conf->liste_limit . ':' . $conf->liste_limit;
3256 if (!in_array($tmpkey, $tmpchoice)) {
3257 $tmpchoice[$tmpkey] = $tmpkey;
3258 }
3259 asort($tmpchoice, SORT_NUMERIC);
3260 foreach ($tmpchoice as $val) {
3261 $selected = '';
3262 $tmp = explode(':', $val);
3263 $key = $tmp[0];
3264 $val = $tmp[1];
3265 if ($key != '' && $val != '') {
3266 if ((int) $key == (int) $limit) {
3267 $selected = ' selected="selected"';
3268 }
3269 print '<option name="' . $key . '"' . $selected . '>' . dol_escape_htmltag($val) . '</option>' . "\n";
3270 }
3271 }
3272 if (getDolGlobalString('MAIN_USE_HTML5_LIMIT_SELECTOR')) {
3273 print '</datalist>';
3274 } else {
3275 print '</select>';
3276 print ajax_combobox("limit" . (is_numeric($selectlimitsuffix) ? '' : $selectlimitsuffix), array(), 0, 0, 'resolve', '-1', 'limit');
3277 //print ajax_combobox("limit");
3278 }
3279
3280 if ($conf->use_javascript_ajax) {
3281 print '<!-- JS CODE TO ENABLE select limit to launch submit of page -->
3282 <script>
3283 jQuery(document).ready(function () {
3284 jQuery(".selectlimit").change(function() {
3285 console.log("We change limit so we submit the form");
3286 $(this).parents(\'form:first\').submit();
3287 });
3288 });
3289 </script>
3290 ';
3291 }
3292 print '</li>';
3293 }
3294 if ($page > 0) {
3295 print '<li class="pagination paginationpage paginationpageleft"><a class="paginationprevious reposition" href="' . $file . '?page=' . ($page - 1) . $options . '"><i class="fa fa-chevron-left" title="' . dol_escape_htmltag($langs->trans("Previous")) . '"></i></a></li>';
3296 }
3297 if ($betweenarrows) {
3298 print '<!--<div class="betweenarrows nowraponall inline-block">-->';
3299 print $betweenarrows;
3300 print '<!--</div>-->';
3301 }
3302 if ($nextpage > 0) {
3303 print '<li class="pagination paginationpage paginationpageright"><a class="paginationnext reposition" href="' . $file . '?page=' . ($page + 1) . $options . '"><i class="fa fa-chevron-right" title="' . dol_escape_htmltag($langs->trans("Next")) . '"></i></a></li>';
3304 }
3305 if ($afterarrows) {
3306 print '<li class="paginationafterarrows">';
3307 print $afterarrows;
3308 print '</li>';
3309 }
3310 }
3311 print '</ul></div>' . "\n";
3312}
3313
3314
3321function showTotalAmount($amount)
3322{
3323 return '<span class="amount">'.$amount.'</span>';
3324}
3325
3338function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput = 'no', $use_short_label = 0)
3339{
3340 require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php';
3341
3342 if (($forceunitoutput == 'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
3343 $dimension *= 1000000;
3344 $unit -= 6;
3345 } elseif (($forceunitoutput == 'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
3346 $dimension *= 1000;
3347 $unit -= 3;
3348 } elseif (($forceunitoutput == 'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
3349 $dimension /= 1000000;
3350 $unit += 6;
3351 } elseif (($forceunitoutput == 'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
3352 $dimension /= 1000;
3353 $unit += 3;
3354 }
3355 // Special case when we want output unit into pound or ounce
3356 /* TODO
3357 if ($unit < 90 && $type == 'weight' && is_numeric($forceunitoutput) && (($forceunitoutput == 98) || ($forceunitoutput == 99))
3358 {
3359 $dimension = // convert dimension from standard unit into ounce or pound
3360 $unit = $forceunitoutput;
3361 }
3362 if ($unit > 90 && $type == 'weight' && is_numeric($forceunitoutput) && $forceunitoutput < 90)
3363 {
3364 $dimension = // convert dimension from standard unit into ounce or pound
3365 $unit = $forceunitoutput;
3366 }*/
3367
3368 $ret = price($dimension, 0, $outputlangs, 0, 0, $round);
3369 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
3370 $ret .= ' ' . measuringUnitString(0, $type, $unit, $use_short_label, $outputlangs);
3371
3372 return $ret;
3373}
3374
3375
3376
3386function yn($yesno, $format = 1, $color = 0)
3387{
3388 global $langs;
3389
3390 $result = 'unknown';
3391 $classname = '';
3392 if ($yesno === true || (int) $yesno == 1 || (isset($yesno) && (strtolower($yesno) == 'yes' || strtolower($yesno) == 'true'))) { // To set to 'no' before the test because of the '== 0'
3393 $result = $langs->trans('yes');
3394 if ($format == 1 || $format == 3) {
3395 $result = $langs->trans("Yes");
3396 }
3397 if ($format == 2) {
3398 $result = '<input type="checkbox" value="1" checked disabled>';
3399 }
3400 if ($format == 3) {
3401 $result = '<input type="checkbox" value="1" checked disabled> ' . $result;
3402 }
3403 if ($format == 4 || !is_numeric($format)) {
3404 $result = img_picto(is_numeric($format) ? '' : $format, 'check');
3405 }
3406
3407 $classname = 'ok';
3408 } else {
3409 $result = $langs->trans("no");
3410 if ($format == 1 || $format == 3) {
3411 $result = $langs->trans("No");
3412 }
3413 if ($format == 2) {
3414 $result = '<input type="checkbox" value="0" disabled>';
3415 }
3416 if ($format == 3) {
3417 $result = '<input type="checkbox" value="0" disabled> ' . $result;
3418 }
3419 if ($format == 4 || !is_numeric($format)) {
3420 $result = img_picto(is_numeric($format) ? '' : $format, 'uncheck');
3421 }
3422
3423 if ($color == 2) {
3424 $classname = 'ok';
3425 } else {
3426 $classname = 'error';
3427 }
3428 }
3429 if ($color) {
3430 return '<span class="' . $classname . '">' . $result . '</span>';
3431 }
3432 return $result;
3433}
3434
3435
3449function setEventMessage($mesgs, $style = 'mesgs', $noduplicate = 0, $attop = 0)
3450{
3451 //dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING); This is not deprecated, it is used by setEventMessages function
3452 if (!is_array($mesgs)) {
3453 $mesgs = trim((string) $mesgs);
3454 // If mesgs is a not an empty string
3455 if ($mesgs) {
3456 if (!empty($noduplicate) && isset($_SESSION['dol_events'][$style]) && in_array($mesgs, $_SESSION['dol_events'][$style])) {
3457 return;
3458 }
3459 if ($attop) {
3460 array_unshift($_SESSION['dol_events'][$style], $mesgs);
3461 } else {
3462 $_SESSION['dol_events'][$style][] = $mesgs;
3463 }
3464 }
3465 } else {
3466 // If mesgs is an array
3467 foreach ($mesgs as $mesg) {
3468 $mesg = trim((string) $mesg);
3469 if ($mesg) {
3470 if (!empty($noduplicate) && isset($_SESSION['dol_events'][$style]) && in_array($mesg, $_SESSION['dol_events'][$style])) {
3471 return;
3472 }
3473 if ($attop) {
3474 array_unshift($_SESSION['dol_events'][$style], $mesgs);
3475 } else {
3476 $_SESSION['dol_events'][$style][] = $mesg;
3477 }
3478 }
3479 }
3480 }
3481}
3482
3497function setEventMessages($mesg, $mesgs, $style = 'mesgs', $messagekey = '', $noduplicate = 0, $attop = 0)
3498{
3499 if (empty($mesg) && empty($mesgs)) {
3500 dol_syslog("Try to add a message in stack, but value to add is empty message" . getCallerInfoString(), LOG_WARNING);
3501 } else {
3502 if ($messagekey) {
3503 // Complete message with a js link to set a cookie "DOLHIDEMESSAGE".$messagekey;
3504 // TODO
3505 $mesg .= '';
3506 }
3507 if (empty($messagekey) || empty($_COOKIE["DOLUSER_HIDEMESSAGE" . $messagekey])) {
3508 if (!in_array((string) $style, array('mesgs', 'warnings', 'errors'))) {
3509 dol_print_error(null, 'Bad parameter style=' . $style . ' for setEventMessages');
3510 }
3511 if (empty($mesgs)) {
3512 setEventMessage((string) $mesg, $style, $noduplicate, $attop);
3513 } else {
3514 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
3515 setEventMessage($mesg, $style, $noduplicate, $attop); // Add message string if not already into array
3516 }
3517 setEventMessage($mesgs, $style, $noduplicate, $attop);
3518 }
3519 }
3520 }
3521}
3522
3532function dol_htmloutput_events($disabledoutputofmessages = 0)
3533{
3534 // Show mesgs
3535 if (isset($_SESSION['dol_events']['mesgs'])) {
3536 if (empty($disabledoutputofmessages)) {
3537 dol_htmloutput_mesg('', $_SESSION['dol_events']['mesgs']);
3538 }
3539 unset($_SESSION['dol_events']['mesgs']);
3540 }
3541 // Show errors
3542 if (isset($_SESSION['dol_events']['errors'])) {
3543 if (empty($disabledoutputofmessages)) {
3544 dol_htmloutput_mesg('', $_SESSION['dol_events']['errors'], 'error');
3545 }
3546 unset($_SESSION['dol_events']['errors']);
3547 }
3548
3549 // Show warnings
3550 if (isset($_SESSION['dol_events']['warnings'])) {
3551 if (empty($disabledoutputofmessages)) {
3552 dol_htmloutput_mesg('', $_SESSION['dol_events']['warnings'], 'warning');
3553 }
3554 unset($_SESSION['dol_events']['warnings']);
3555 }
3556}
3557
3572function get_htmloutput_mesg($mesgstring = '', $mesgarray = [], $style = 'ok', $keepembedded = 0)
3573{
3574 global $conf, $langs;
3575
3576 $ret = 0;
3577 $return = '';
3578 $out = '';
3579 $divstart = $divend = '';
3580
3581 // If inline message with no format, we add it.
3582 if ((empty($conf->use_javascript_ajax) || getDolGlobalString('MAIN_DISABLE_JQUERY_JNOTIFY') || defined('DISABLE_JQUERY_JNOTIFY') || $keepembedded) && !preg_match('/<div class=".*">/i', $out)) {
3583 $divstart = '<div class="' . $style . ' clearboth">';
3584 $divend = '</div>';
3585 }
3586
3587 if ((is_array($mesgarray) && count($mesgarray)) || $mesgstring) {
3588 $langs->load("errors");
3589 $out .= $divstart;
3590 if (is_array($mesgarray) && count($mesgarray)) {
3591 foreach ($mesgarray as $message) {
3592 $ret++;
3593 $out .= $langs->trans($message);
3594 if ($ret < count($mesgarray)) {
3595 $out .= "<br>\n";
3596 }
3597 }
3598 }
3599 if ($mesgstring) {
3600 $ret++;
3601 $out .= $langs->trans($mesgstring);
3602 }
3603 $out .= $divend;
3604 }
3605
3606 if ($out) {
3607 if (!empty($conf->use_javascript_ajax) && !getDolGlobalString('MAIN_DISABLE_JQUERY_JNOTIFY') && !defined('DISABLE_JQUERY_JNOTIFY') && empty($keepembedded)) {
3608 if ($style == "ok") {
3609 // For success messages (green), allow manual click to close immediately without fade
3610 $return = '<script nonce="' . getNonce() . '">
3611 /* jnotify(message, params) */
3612 $(document).ready(function() {
3613 $.jnotify(\'' . dol_escape_js($out) . '\', {
3614 delay: 3000,
3615 type: \'' . dol_escape_js($style) . '\',
3616 sticky: false,
3617 create: function($note) {
3618 $note.css("cursor", "pointer").click(function(e) {
3619 e.stopPropagation();
3620 $note.remove();
3621 });
3622 }
3623 });
3624 });
3625 </script>';
3626 } else {
3627 // For error and warning messages, close immediately on click without fade
3628 $return = '<script nonce="' . getNonce() . '">
3629 $(document).ready(function() {
3630 $.jnotify(\'' . dol_escape_js($out) . '\', {
3631 delay: 3000,
3632 type: \'' . dol_escape_js($style) . '\',
3633 sticky: true,
3634 create: function($note) {
3635 $note.find("a.jnotify-close").click(function(e) {
3636 e.stopPropagation();
3637 $note.remove();
3638 });
3639 }
3640 });
3641 });
3642 </script>';
3643 }
3644 } else {
3645 $return = $out;
3646 }
3647 }
3648
3649 return $return;
3650}
3651
3663function get_htmloutput_errors($mesgstring = '', $mesgarray = array(), $keepembedded = 0)
3664{
3665 return get_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded);
3666}
3667
3681function dol_htmloutput_mesg($mesgstring = '', $mesgarray = array(), $style = 'ok', $keepembedded = 0)
3682{
3683 if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) {
3684 return;
3685 }
3686
3687 $iserror = 0;
3688 $iswarning = 0;
3689 if (is_array($mesgarray)) {
3690 foreach ($mesgarray as $val) {
3691 if ($val && preg_match('/class="error"/i', $val)) {
3692 $iserror++;
3693 break;
3694 }
3695 if ($val && preg_match('/class="warning"/i', $val)) {
3696 $iswarning++;
3697 break;
3698 }
3699 }
3700 } elseif ($mesgstring && preg_match('/class="error"/i', $mesgstring)) {
3701 $iserror++;
3702 } elseif ($mesgstring && preg_match('/class="warning"/i', $mesgstring)) {
3703 $iswarning++;
3704 }
3705 if ($style == 'error' || $style == 'errors') {
3706 $iserror++;
3707 }
3708 if ($style == 'warning' || $style == 'warnings') {
3709 $iswarning++;
3710 }
3711
3712 if ($iserror || $iswarning) {
3713 // Remove div from texts
3714 $mesgstring = preg_replace('/<\/div><div class="(error|warning)">/', '<br>', $mesgstring);
3715 $mesgstring = preg_replace('/<div class="(error|warning)">/', '', $mesgstring);
3716 $mesgstring = preg_replace('/<\/div>/', '', $mesgstring);
3717 // Remove div from texts array
3718 if (is_array($mesgarray)) {
3719 $newmesgarray = array();
3720 foreach ($mesgarray as $val) {
3721 if (is_string($val)) {
3722 $tmpmesgstring = preg_replace('/<\/div><div class="(error|warning)">/', '<br>', $val);
3723 $tmpmesgstring = preg_replace('/<div class="(error|warning)">/', '', $tmpmesgstring);
3724 $tmpmesgstring = preg_replace('/<\/div>/', '', $tmpmesgstring);
3725 $newmesgarray[] = $tmpmesgstring;
3726 } else {
3727 dol_syslog("Error call of dol_htmloutput_mesg with an array with a value that is not a string", LOG_WARNING);
3728 }
3729 }
3730 $mesgarray = $newmesgarray;
3731 }
3732 print get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ? 'error' : 'warning'), $keepembedded);
3733 } else {
3734 print get_htmloutput_mesg($mesgstring, $mesgarray, 'ok', $keepembedded);
3735 }
3736}
3737
3749function dol_htmloutput_errors($mesgstring = '', $mesgarray = array(), $keepembedded = 0)
3750{
3751 dol_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded);
3752}
3753
3754
3755
3764function picto_from_langcode($codelang, $moreatt = '', $notitlealt = 0)
3765{
3766 if (empty($codelang)) {
3767 return '';
3768 }
3769
3770 if ($codelang == 'auto') {
3771 return '<span class="fa fa-language"></span>';
3772 }
3773
3774 $langtocountryflag = array(
3775 'ar_AR' => '',
3776 'ca_ES' => 'catalonia',
3777 'da_DA' => 'dk',
3778 'fr_CA' => 'mq',
3779 'sv_SV' => 'se',
3780 'sw_SW' => 'unknown',
3781 'AQ' => 'unknown',
3782 'CW' => 'unknown',
3783 'IM' => 'unknown',
3784 'JE' => 'unknown',
3785 'MF' => 'unknown',
3786 'BL' => 'unknown',
3787 'SX' => 'unknown'
3788 );
3789
3790 if (isset($langtocountryflag[$codelang])) {
3791 $flagImage = $langtocountryflag[$codelang];
3792 } else {
3793 $tmparray = explode('_', $codelang);
3794 $flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
3795 }
3796
3797 $morecss = '';
3798 $reg = array();
3799 if (preg_match('/class="([^"]+)"/', $moreatt, $reg)) {
3800 $morecss = $reg[1];
3801 $moreatt = "";
3802 }
3803
3804 // return img_picto_common($codelang, 'flags/'.strtolower($flagImage).'.png', $moreatt, 0, $notitlealt);
3805 return '<span class="flag-sprite ' . strtolower($flagImage) . ($morecss ? ' ' . $morecss : '') . '"' . ($moreatt ? ' ' . $moreatt : '') . (!$notitlealt ? ' title="' . $codelang . '"' : '') . '></span>';
3806}
3807
3808
3820function printCommonFooter($zone = 'private')
3821{
3822 global $conf, $hookmanager, $user, $langs;
3823 global $action;
3824 global $micro_start_time;
3825
3826 if ($zone == 'private') {
3827 print "\n" . '<!-- Common footer for private page -->' . "\n";
3828 } else {
3829 print "\n" . '<!-- Common footer for public page -->' . "\n";
3830 }
3831
3832 // A div to store page_y POST parameter so we can read it using javascript
3833 print "\n<!-- A div to store page_y POST parameter -->\n";
3834 print '<div id="page_y" style="display: none;">' . (GETPOST('page_y') ? GETPOST('page_y') : '') . '</div>' . "\n";
3835
3836 $parameters = array('zone' => $zone);
3837 $tmpobject = null;
3838 // @phan-suppress-next-line PhanPluginConstantVariableNull
3839 $reshook = $hookmanager->executeHooks('printCommonFooter', $parameters, $tmpobject, $action); // Note that $action and $object may have been modified by some hooks
3840 if (empty($reshook)) {
3841 if (getDolGlobalString('MAIN_HTML_FOOTER')) {
3842 print getDolGlobalString('MAIN_HTML_FOOTER') . "\n";
3843 }
3844
3845 print "\n";
3846 if (!empty($conf->use_javascript_ajax)) {
3847 print "\n<!-- A script section to add menuhider handler on backoffice, manage focus and mandatory fields, tuning info, ... -->\n";
3848 print '<script>' . "\n";
3849 print 'jQuery(document).ready(function() {' . "\n";
3850
3851 if ($zone == 'private' && empty($conf->dol_use_jmobile)) {
3852 print "\n";
3853 print '/* JS CODE TO ENABLE to manage handler to switch left menu page (menuhider) */' . "\n";
3854 print 'jQuery("li.menuhider").click(function(event) {';
3855 print ' if (!$( "body" ).hasClass( "sidebar-collapse" )){ event.preventDefault(); }' . "\n";
3856 print ' console.log("We click on .menuhider");' . "\n";
3857 print ' $("body").toggleClass("sidebar-collapse")' . "\n";
3858 print '});' . "\n";
3859 }
3860
3861 // Management of focus and mandatory for fields
3862 if ($action == 'create' || $action == 'add' || $action == 'edit' || (empty($action) && (preg_match('/new\.php/', $_SERVER["PHP_SELF"]))) || ((empty($action) || $action == 'addline') && (preg_match('/card\.php/', $_SERVER["PHP_SELF"])))) {
3863 print '/* JS CODE TO ENABLE to manage focus and mandatory form fields */' . "\n";
3864 $relativepathstring = $_SERVER["PHP_SELF"];
3865 // Clean $relativepathstring
3866 if (constant('DOL_URL_ROOT')) {
3867 $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_URL_ROOT'), '/') . '/', '', $relativepathstring);
3868 }
3869 $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
3870 $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
3871 //$tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
3872
3873 if (!empty($user->default_values[$relativepathstring]['focus'])) {
3874 foreach ($user->default_values[$relativepathstring]['focus'] as $defkey => $defval) {
3875 $qualified = 0;
3876 if ($defkey != '_noquery_') {
3877 $tmpqueryarraytohave = explode('&', $defkey);
3878 $foundintru = 0;
3879 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
3880 $tmpquerytohaveparam = explode('=', $tmpquerytohave);
3881 //print "console.log('".$tmpquerytohaveparam[0]." ".$tmpquerytohaveparam[1]." ".GETPOST($tmpquerytohaveparam[0])."');";
3882 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) {
3883 $foundintru = 1;
3884 }
3885 }
3886 if (!$foundintru) {
3887 $qualified = 1;
3888 }
3889 //var_dump($defkey.'-'.$qualified);
3890 } else {
3891 $qualified = 1;
3892 }
3893
3894 if ($qualified) {
3895 print 'console.log("set the focus by executing jQuery(...).focus();")' . "\n";
3896 foreach ($defval as $paramkey => $paramval) {
3897 // Set focus on field
3898 print 'jQuery("input[name=\'' . $paramkey . '\']").focus();' . "\n";
3899 print 'jQuery("textarea[name=\'' . $paramkey . '\']").focus();' . "\n"; // TODO KO with ckeditor
3900 print 'jQuery("select[name=\'' . $paramkey . '\']").focus();' . "\n"; // Not really useful, but we keep it in case of.
3901 }
3902 }
3903 }
3904 }
3905 if (!empty($user->default_values[$relativepathstring]['mandatory'])) {
3906 foreach ($user->default_values[$relativepathstring]['mandatory'] as $defkey => $defval) {
3907 $qualified = 0;
3908 if ($defkey != '_noquery_') {
3909 $tmpqueryarraytohave = explode('&', $defkey);
3910 $foundintru = 0;
3911 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
3912 $tmpquerytohaveparam = explode('=', $tmpquerytohave);
3913 //print "console.log('".$tmpquerytohaveparam[0]." ".$tmpquerytohaveparam[1]." ".GETPOST($tmpquerytohaveparam[0])."');";
3914 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) {
3915 $foundintru = 1;
3916 }
3917 }
3918 if (!$foundintru) {
3919 $qualified = 1;
3920 }
3921 //var_dump($defkey.'-'.$qualified);
3922 } else {
3923 $qualified = 1;
3924 }
3925
3926 if ($qualified) {
3927 print 'console.log("set the js code to manage fields that are set as mandatory");' . "\n";
3928
3929 foreach ($defval as $paramkey => $paramval) {
3930 // Solution 1: Add handler on submit to check if mandatory fields are empty
3931 print 'var form = $(\'[name="'.dol_escape_js($paramkey).'"]\').closest("form");'."\n";
3932 print "form.on('submit', function(event) {
3933 var submitter = \$(this).find(':submit:focus').get(0);
3934 var buttonName = submitter ? \$(submitter).attr('name') : 'save';
3935
3936 if (buttonName == 'cancel') {
3937 console.log('We click on cancel button so we accept submit with no need to check mandatory fields');
3938 return true;
3939 }
3940
3941 console.log('We did not click on cancel button but on something else, we check that field [name=".dol_escape_js($paramkey)."] is not empty');
3942
3943 var tmpvalue = jQuery('[name=\"".dol_escape_js($paramkey)."\"]').val();
3944 let tmptypefield = jQuery('[name=\"".dol_escape_js($paramkey)."\"]').prop('nodeName').toLowerCase(); // Get the tag name (div, section, footer...)
3945
3946 if (tmptypefield == 'textarea') {
3947 // We must instead check the content of ckeditor
3948 var tmpeditor = (typeof CKEDITOR !== 'undefined') ? CKEDITOR.instances['".dol_escape_js($paramkey)."'] : null;
3949 if (tmpeditor) {
3950 tmpvalue = tmpeditor.getData();
3951 console.log('For textarea tmpvalue is '+tmpvalue);
3952 }
3953 }
3954
3955 let tmpvalueisempty = false;
3956 if (tmpvalue === null || tmpvalue === undefined || tmpvalue === '' || tmpvalue === -1 || tmpvalue === '-1') {
3957 tmpvalueisempty = true;
3958 }
3959 if (tmpvalue === '0' && (tmptypefield == 'select' || tmptypefield == 'input')) {
3960 tmpvalueisempty = true;
3961 }
3962 if (tmpvalueisempty && buttonName !== 'cancel') {
3963 console.log('field has type '+tmptypefield+' and is empty, we cancel the submit');
3964 event.preventDefault(); // Stop submission of form to allow custom code to decide.
3965 event.stopPropagation(); // Stop other handlers.
3966
3967 alert('".dol_escape_js($langs->transnoentitiesnoconv("ErrorFieldRequired", $paramkey).' ('.$langs->transnoentitiesnoconv("CustomMandatoryFieldRule").')')."');
3968
3969 return false;
3970 }
3971 console.log('field has type '+tmptypefield+' and is defined to '+tmpvalue);
3972 return true;
3973 });
3974 \n";
3975
3976 // Solution 2: Add property 'required' on input
3977 // so browser will check value and try to focus on it when submitting the form.
3978 //print 'setTimeout(function() {'; // If we want to wait that ckeditor beuatifier has finished its job.
3979 //print 'jQuery("input[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n";
3980 //print 'jQuery("textarea[id=\''.$paramkey.'\']").prop(\'required\',true);'."\n";
3981 //print 'jQuery("select[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n";*/
3982 //print '// required on a select works only if key is "", so we add the required attributes but also we reset the key -1 or 0 to an empty string'."\n";
3983 //print 'jQuery("select[name=\''.$paramkey.'\'] option[value=\'-1\']").prop(\'value\', \'\');'."\n";
3984 //print 'jQuery("select[name=\''.$paramkey.'\'] option[value=\'0\']").prop(\'value\', \'\');'."\n";
3985 // Add 'field required' class on closest td for all input elements : input, textarea and select
3986 //print '}, 500);'; // 500 milliseconds delay
3987
3988 // Now set the class "fieldrequired"
3989 print 'jQuery(\':input[name="' . dol_escape_js($paramkey) . '"]\').closest("tr").find("td:first").addClass("fieldrequired");' . "\n";
3990 }
3991
3992 // If we submit using the cancel button, we remove the required attributes
3993 print 'jQuery("input[name=\'cancel\']").click(function() {
3994 console.log("We click on cancel button so removed all required attribute");
3995 jQuery("input, textarea, select").each(function(){this.removeAttribute(\'required\');});
3996 });' . "\n";
3997 }
3998 }
3999 }
4000 }
4001
4002 print '});' . "\n";
4003
4004 // End of tuning
4005 if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO']) || getDolGlobalString('MAIN_SHOW_TUNING_INFO')) {
4006 print "\n";
4007 print "/* JS CODE TO ENABLE to add memory info */\n";
4008 print 'window.console && console.log("';
4009 if (getDolGlobalString('MEMCACHED_SERVER')) {
4010 print 'MEMCACHED_SERVER=' . getDolGlobalString('MEMCACHED_SERVER') . ' - ';
4011 }
4012 print 'MAIN_OPTIMIZE_SPEED=' . getDolGlobalString('MAIN_OPTIMIZE_SPEED', 'off');
4013 if (!empty($micro_start_time)) { // Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable.
4014 $micro_end_time = microtime(true);
4015 print ' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) . ' ms';
4016 }
4017
4018 if (function_exists("memory_get_usage")) {
4019 print ' - Mem: ' . memory_get_usage(); // Do not use true here, it seems it takes the peak amount
4020 }
4021 if (function_exists("memory_get_peak_usage")) {
4022 print ' - Real mem peak: ' . memory_get_peak_usage(true);
4023 }
4024 if (function_exists("zend_loader_file_encoded")) {
4025 print ' - Zend encoded file: ' . (zend_loader_file_encoded() ? 'yes' : 'no');
4026 }
4027 print '");' . "\n";
4028 }
4029
4030 print "\n" . '</script>' . "\n";
4031
4032 // Google Analytics
4033 // TODO Remove this, can be replaced with the hook printCommonFooter
4034 if (isModEnabled('google') && getDolGlobalString('MAIN_GOOGLE_AN_ID')) {
4035 $tmptagarray = explode(',', getDolGlobalString('MAIN_GOOGLE_AN_ID'));
4036 foreach ($tmptagarray as $tmptag) {
4037 print "\n";
4038 print "<!-- JS CODE TO ENABLE for google analtics tag -->\n";
4039 print '
4040 <!-- Global site tag (gtag.js) - Google Analytics -->
4041 <script nonce="' . getNonce() . '" async src="https://www.googletagmanager.com/gtag/js?id=' . trim($tmptag) . '"></script>
4042 <script>
4043 window.dataLayer = window.dataLayer || [];
4044 function gtag(){dataLayer.push(arguments);}
4045 gtag(\'js\', new Date());
4046
4047 gtag(\'config\', \'' . trim($tmptag) . '\');
4048 </script>';
4049 print "\n";
4050 }
4051 }
4052 }
4053
4054 // Add Xdebug coverage of code
4055 if (defined('XDEBUGCOVERAGE')) {
4056 print_r(xdebug_get_code_coverage());
4057 }
4058
4059 // Output string from hooks
4060 if (!empty($hookmanager->resPrint)) {
4061 print $hookmanager->resPrint;
4062 }
4063
4064 // Add DebugBar data
4065 if ($user->hasRight('debugbar', 'read')) {
4066 global $debugbar;
4067 if ($debugbar instanceof DebugBar\DebugBar) {
4068 if (isset($debugbar['time'])) {
4069 // @phan-suppress-next-line PhanPluginUnknownObjectMethodCall
4070 $debugbar['time']->stopMeasure('pageaftermaster');
4071 }
4072 print '<!-- Output debugbar data -->' . "\n";
4073 $renderer = $debugbar->getJavascriptRenderer();
4074 print $renderer->render();
4075 }
4076 } elseif (count($conf->logbuffer)) { // If there is some logs in buffer to show
4077 print "\n";
4078 print "<!-- Start of log output\n";
4079 //print '<div class="hidden">'."\n";
4080 foreach ($conf->logbuffer as $logline) {
4081 print $logline . "<br>\n";
4082 }
4083 //print '</div>'."\n";
4084 print "End of log output -->\n";
4085 }
4086 }
4087}
4088
4089
4097function dol_set_focus($selector, $nooutput = 0)
4098{
4099 $out = "\n" . '<!-- Set focus onto a specific field -->' . "\n";
4100 $out .= '<script nonce="' . getNonce() . '">jQuery(document).ready(function() { console.log("Force focus by dol_set_focus"); jQuery(\'' . dol_escape_js($selector) . '\').focus(); });</script>' . "\n";
4101
4102 if ($nooutput) {
4103 return $out;
4104 } else {
4105 print $out;
4106 }
4107
4108 return '';
4109}
4110
4111
4112
4120function showSimpleHTMLTable($outputlangs, $object)
4121{
4122 global $conf;
4123
4124 $outputlangs->loadLangs(array("products"));
4125
4126 $discountIsAvailable = false;
4127 $orderPositionHasNoPrice = false;
4128
4129 if (!property_exists($object->lines[0], "remise_percent") ||
4130 !property_exists($object->lines[0], "fk_unit") ||
4131 !property_exists($object->lines[0], "multicurrency_total_ttc") ||
4132 !property_exists($object->lines[0], "description") ||
4133 !property_exists($object->lines[0], "qty")) {
4134 return"";
4135 }
4136
4137 foreach ($object->lines as $order_position) {
4138 if (!property_exists($order_position, "price")) {
4139 $orderPositionHasNoPrice = true;
4140 break;
4141 }
4142
4143 if (!empty($order_position->remise_percent)) {
4144 $discountIsAvailable = true;
4145 break;
4146 }
4147 };
4148
4149 if ($orderPositionHasNoPrice) {
4150 return "";
4151 }
4152
4153 $discountHeader = $discountIsAvailable ? '<th style="width:120px">'.$outputlangs->trans("Discount").'</th>' : '';
4154
4155 $table = '<table border="0" cellpadding="1" cellspacing="1">';
4156 $table .= '
4157 <thead>
4158 <tr>
4159 <th style="width:50px; text-align:left">#</th>
4160 <th style="text-align:left">'.$outputlangs->trans("Description").'</th>
4161 <th style="width:120px; text-align:right;">'.$outputlangs->trans("Price").'</th>
4162 <th style="width:100px; text-align:right;">'.$outputlangs->trans("Quantity").'</th>
4163 <th style="width:120px; text-align:right;">'.$outputlangs->trans("Unit").'</th>'.
4164 $discountHeader.'
4165 <th style="width:120px; text-align:right;">'.$outputlangs->trans("Sum").'</th>
4166 </tr>
4167 </thead>
4168 <tbody>';
4169
4170 foreach ($object->lines as $index => $order_position) {
4171 $position = $index + 1;
4172 $price = price($order_position->price, 0, $outputlangs, 0, -1, -1, $conf->currency);
4173 $unit = measuringUnitString($order_position->fk_unit, '', null, 1);
4174 $total = price($order_position->multicurrency_total_ttc, 0, $outputlangs, 0, -1, -1, $conf->currency);
4175 $discount = $discountIsAvailable ? '<td style="text-align:center">'.$order_position->remise_percent.'%</td>' : "";
4176
4177 $table .= '
4178 <tr>
4179 <td>'.$position.'</td>
4180 <td>'.$order_position->description.'</td>
4181 <td style="text-align:right">'.$price.'</td>
4182 <td style="text-align:right">'.$order_position->qty.'</td>
4183 <td style="text-align:right">'.$unit.'</td>'.
4184 $discount.'
4185 <td style="text-align:right">'.$total.'</td>
4186 </tr>';
4187 }
4188 $table .= '</tbody></table>';
4189
4190 return $table;
4191}
4192
4199function showDirectDownloadLink($object)
4200{
4201 global $langs;
4202
4203 $out = '';
4204 $url = $object->getLastMainDocLink($object->element);
4205
4206 $out .= img_picto($langs->trans("PublicDownloadLinkDesc"), 'globe') . ' <span class="opacitymedium">' . $langs->trans("DirectDownloadLink") . '</span><br>';
4207 if ($url) {
4208 $out .= '<div class="urllink"><input type="text" id="directdownloadlink" class="quatrevingtpercent" value="' . $url . '"></div>';
4209 $out .= ajax_autoselect("directdownloadlink", '');
4210 } else {
4211 $out .= '<div class="urllink">' . $langs->trans("FileNotShared") . '</div>';
4212 }
4213
4214 return $out;
4215}
4216
4217
4218
4228function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param = '')
4229{
4230 global $conf, $langs;
4231
4232 if (empty($conf->use_javascript_ajax)) {
4233 return '';
4234 }
4235
4236 $isAllowedForPreview = dolIsAllowedForPreview($relativepath);
4237
4238 if ($alldata == 1) {
4239 if ($isAllowedForPreview) {
4240 return array('target' => '_blank', 'css' => 'documentpreview', 'url' => DOL_URL_ROOT . '/document.php?modulepart=' . urlencode($modulepart) . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : ''), 'mime' => dol_mimetype($relativepath));
4241 } else {
4242 return array();
4243 }
4244 }
4245
4246 // old behavior, return a string
4247 if ($isAllowedForPreview) {
4248 $tmpurl = DOL_URL_ROOT . '/document.php?modulepart=' . urlencode($modulepart) . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : '');
4249 $title = $langs->transnoentities("Preview");
4250 //$title = '%27-alert(document.domain)-%27'; // An example of js injection into a corrupted title string, that should be blocked by the dol_escape_uri().
4251 //$tmpurl = 'file='.urlencode("'-alert(document.domain)-'_small.jpg"); // An example of tmpurl that should be blocked by the dol_escape_uri()
4252
4253 // We need to do a dol_escape_uri() on the full string after the javascript: because such parts are the URI and when we click on such links, a RFC3986 decode is done,
4254 // by the browser, converting the %27 (like when having param file=abc%27def), or when having a corrupted title), into a ', BEFORE interpreting the content that can be a js code.
4255 // Using the dol_escape_uri guarantee that we encode for URI so decode retrieve original expected value.
4256 return 'javascript:' . dol_escape_uri('document_preview(\'' . dol_escape_js($tmpurl) . '\', \'' . dol_escape_js(dol_mimetype($relativepath)) . '\', \'' . dol_escape_js($title) . '\')');
4257 } else {
4258 return '';
4259 }
4260}
4261
4262
4272function ajax_autoselect($htmlname, $addlink = '', $textonlink = 'Link')
4273{
4274 global $langs;
4275 $out = '<script nonce="' . getNonce() . '">
4276 jQuery(document).ready(function () {
4277 jQuery("' . ((strpos($htmlname, '.') === 0 ? '' : '#') . $htmlname) . '").click(function() { jQuery(this).select(); } );
4278 });
4279 </script>';
4280 if ($addlink) {
4281 if ($textonlink === 'image') {
4282 $out .= ' <a href="' . $addlink . '" target="_blank" rel="noopener noreferrer">' . img_picto('', 'globe') . '</a>';
4283 } else {
4284 $out .= ' <a href="' . $addlink . '" target="_blank" rel="noopener noreferrer">' . $langs->trans("Link") . '</a>';
4285 }
4286 }
4287 return $out;
4288}
4289
4290
4291
4304function dolGetBadge($label, $html = '', $type = 'primary', $mode = '', $url = '', $params = array())
4305{
4306 $csstouse = 'badge';
4307 $csstouse .= (!empty($mode) ? ' badge-' . $mode : '');
4308 $csstouse .= (!empty($type) ? ' badge-' . $type : '');
4309 $csstouse .= (empty($params['css']) ? '' : ' ' . $params['css']);
4310
4311 $attr = array(
4312 'class' => $csstouse
4313 );
4314
4315 if (empty($html)) {
4316 $html = $label;
4317 }
4318
4319 if (!empty($url)) {
4320 $attr['href'] = $url;
4321 }
4322
4323 if ($mode === 'dot') {
4324 $attr['class'] .= ' classfortooltip';
4325 $attr['title'] = $html;
4326 $attr['aria-label'] = $label;
4327 $html = '';
4328 }
4329
4330 // Override attr
4331 if (!empty($params['attr']) && is_array($params['attr'])) {
4332 foreach ($params['attr'] as $key => $value) {
4333 if ($key == 'class') {
4334 $attr['class'] .= ' ' . $value;
4335 } elseif ($key == 'classOverride') {
4336 $attr['class'] = $value;
4337 } else {
4338 $attr[$key] = $value;
4339 }
4340 }
4341 }
4342
4343 // TODO: add hook
4344
4345 // escape all attribute
4346 $attr = array_map('dolPrintHTMLForAttribute', $attr);
4347
4348 $TCompiledAttr = array();
4349 foreach ($attr as $key => $value) {
4350 $TCompiledAttr[] = $key . '="' . $value . '"';
4351 }
4352
4353 $compiledAttributes = !empty($TCompiledAttr) ? implode(' ', $TCompiledAttr) : '';
4354
4355 $tag = !empty($url) ? 'a' : 'span';
4356
4357 return '<' . $tag . ' ' . $compiledAttributes . '>' . $html . '</' . $tag . '>';
4358}
4359
4360
4374function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $statusType = 'status0', $displayMode = 0, $url = '', $params = array())
4375{
4376 global $conf;
4377
4378 $return = '';
4379 $dolGetBadgeParams = array();
4380
4381 if (!empty($params['badgeParams'])) {
4382 $dolGetBadgeParams = $params['badgeParams'];
4383 }
4384
4385 // TODO : add a hook
4386 if ($displayMode == 0) {
4387 $return = !empty($html) ? $html : (empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort));
4388 } elseif ($displayMode == 1) {
4389 $return = !empty($html) ? $html : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
4390 } elseif (getDolGlobalString('MAIN_STATUS_USES_IMAGES')) {
4391 // Use status with images (for backward compatibility)
4392 $return = '';
4393 $htmlLabel = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone">' : '') . (!empty($html) ? $html : $statusLabel) . (in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
4394 $htmlLabelShort = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone">' : '') . (!empty($html) ? $html : (!empty($statusLabelShort) ? $statusLabelShort : $statusLabel)) . (in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
4395
4396 // For small screen, we always use the short label instead of long label.
4397 if (!empty($conf->dol_optimize_smallscreen)) {
4398 if ($displayMode == 0) {
4399 $displayMode = 1;
4400 } elseif ($displayMode == 4) {
4401 $displayMode = 2;
4402 } elseif ($displayMode == 6) {
4403 $displayMode = 5;
4404 }
4405 }
4406
4407 // For backward compatibility. Image's filename are still in French, so we use this array to convert
4408 $statusImg = array(
4409 'status0' => 'statut0',
4410 'status1' => 'statut1',
4411 'status2' => 'statut2',
4412 'status3' => 'statut3',
4413 'status4' => 'statut4',
4414 'status5' => 'statut5',
4415 'status6' => 'statut6',
4416 'status7' => 'statut7',
4417 'status8' => 'statut8',
4418 'status9' => 'statut9'
4419 );
4420
4421 if (!empty($statusImg[$statusType])) {
4422 $htmlImg = img_picto($statusLabel, $statusImg[$statusType]);
4423 } else {
4424 $htmlImg = img_picto($statusLabel, $statusType);
4425 }
4426
4427 if ($displayMode === 2) {
4428 $return = $htmlImg . ' ' . $htmlLabelShort;
4429 } elseif ($displayMode === 3) {
4430 $return = $htmlImg;
4431 } elseif ($displayMode === 4) {
4432 $return = $htmlImg . ' ' . $htmlLabel;
4433 } elseif ($displayMode === 5) {
4434 $return = $htmlLabelShort . ' ' . $htmlImg;
4435 } else { // $displayMode >= 6
4436 $return = $htmlLabel . ' ' . $htmlImg;
4437 }
4438 } elseif (!empty($displayMode)) {
4439 // Use new badge (MAIN_STATUS_USES_IMAGES already handled by the previous branch)
4440 $statusLabelShort = (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
4441
4442 $dolGetBadgeParams['attr']['class'] = 'badge-status';
4443 if (empty($dolGetBadgeParams['attr']['title'])) {
4444 $dolGetBadgeParams['attr']['title'] = empty($params['tooltip']) ? $statusLabel : ($params['tooltip'] != 'no' ? $params['tooltip'] : '');
4445 } else { // If a title was forced from $params['badgeParams']['attr']['title'], we set the class to get it as a tooltip.
4446 $dolGetBadgeParams['attr']['class'] .= ' classfortooltip';
4447 // And if we use tooltip, we can output title in HTML @phan-suppress-next-line PhanTypeInvalidDimOffset
4448 $dolGetBadgeParams['attr']['title'] = dol_htmlentitiesbr((string) $dolGetBadgeParams['attr']['title'], 1);
4449 }
4450
4451 if ($displayMode == 3) {
4452 $return = dolGetBadge((empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), '', $statusType, 'dot', $url, $dolGetBadgeParams);
4453 } elseif ($displayMode === 5) {
4454 $return = dolGetBadge($statusLabelShort, $html, $statusType, '', $url, $dolGetBadgeParams);
4455 } else {
4456 $return = dolGetBadge(((empty($conf->dol_optimize_smallscreen) && $displayMode != 2) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), $html, $statusType, '', $url, $dolGetBadgeParams);
4457 }
4458 }
4459
4460 return $return;
4461}
4462
4463
4502function dolGetButtonAction($label, $text = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params = array())
4503{
4504 global $hookmanager, $action, $object, $langs;
4505
4506 // If $url is an array, we must build a dropdown button or recursively iterate over each value
4507 if (is_array($url)) {
4508 // Loop on $url array to remove entries of disabled modules
4509 foreach ($url as $key => $subbutton) {
4510 if (isset($subbutton['enabled']) && empty($subbutton['enabled'])) {
4511 unset($url[$key]);
4512 }
4513 }
4514
4515 $out = '';
4516
4517 if (array_key_exists('areDropdownButtons', $params) && $params["areDropdownButtons"] === false) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
4518 foreach ($url as $button) {
4519 if (!empty($button['lang'])) {
4520 $langs->load($button['lang']);
4521 }
4522 $label = $langs->trans($button['label']);
4523 $text = $button['text'] ?? '';
4524 $actionType = $button['actionType'] ?? '';
4525 $tmpUrl = '';
4526 if (isset($button['urlraw']) && !empty($button['urlraw'])) {
4527 $tmpUrl = $button['urlraw']; // Use raw url, no url completion, use only what developer send
4528 } elseif (!empty($button['urlroot'])) {
4529 $tmpUrl = $button['urlroot'] . (empty($params['backtopage']) ? '' : '&amp;backtopage=' . urlencode($params['backtopage']));
4530 } elseif (!empty($button['url'])) {
4531 $tmpUrl = DOL_URL_ROOT . $button['url'] . (empty($params['backtopage']) ? '' : '&amp;backtopage=' . urlencode($params['backtopage']));
4532 }
4533
4534 $id = $button['id'] ?? '';
4535 $userRight = $button['perm'] ?? 1;
4536 $button['params'] = $button['params'] ?? []; // @phan-suppress-current-line PhanPluginDuplicateExpressionAssignmentOperation
4537
4538 $out .= dolGetButtonAction($label, $text, $actionType, $tmpUrl, $id, $userRight, $button['params']);
4539 }
4540 return $out;
4541 }
4542
4543 if (count($url) > 1 || !empty($params["forceDropdownButtons"])) {
4544 $out .= '<div class="dropdown inline-block dropdown-holder">';
4545 $out .= '<a style="margin-right: auto;" class="dropdown-toggle classfortooltip butAction' . ($userRight ? '' : 'Refused') . '" title="' . dol_escape_htmltag($label) . '" data-toggle="dropdown">' . ($text ? $text : $label) . '</a>';
4546 $out .= '<div class="dropdown-content">';
4547 foreach ($url as $subbutton) {
4548 if (!empty($subbutton['lang'])) {
4549 $langs->load($subbutton['lang']);
4550 }
4551
4552 if (!empty($subbutton['urlraw'])) {
4553 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
4554 } else {
4555 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
4556 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot'])); // For 'urlroot', no need to complete with DOL_URL_ROOT.
4557 }
4558
4559 $subbuttonparam = array();
4560 if (!empty($subbutton['attr'])) {
4561 $subbuttonparam['attr'] = $subbutton['attr'];
4562 }
4563 $subbuttonparam['isDropDown'] = (empty($params['isDropDown']) ? ($subbutton['isDropDown'] ?? false) : $params['isDropDown']);
4564
4565 $out .= dolGetButtonAction($subbutton['text'] ?? '', $langs->trans($subbutton['label']), 'default', $tmpurl, $subbutton['id'] ?? '', $subbutton['perm'], $subbuttonparam);
4566 }
4567 $out .= "</div>";
4568 $out .= "</div>";
4569 } else {
4570 foreach ($url as $subbutton) { // Should loop on 1 record only
4571 if (!empty($subbutton['lang'])) {
4572 $langs->load($subbutton['lang']);
4573 }
4574
4575 if (!empty($subbutton['urlraw'])) {
4576 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
4577 } else {
4578 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
4579 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
4580 }
4581
4582 $label = $langs->trans($subbutton['label']);
4583 $text = $subbutton['text'] ?? '';
4584 if (empty($text)) {
4585 $text = $label;
4586 $label = '';
4587 }
4588
4589 $out .= dolGetButtonAction($label, $text, 'default', $tmpurl, '', $subbutton['perm'], $params);
4590 }
4591 }
4592
4593 return $out;
4594 }
4595
4596 // Here, $url is a simple link
4597 if (!empty($params['isDropdown']) || !empty($params['isDropDown'])) { // Use the dropdown-item style (not for action button)
4598 $class = "dropdown-item";
4599 } else {
4600 $class = 'butAction';
4601 if ($actionType == 'edit') {
4602 $class = 'butAction butActionEdit';
4603 } elseif ($actionType == 'email') {
4604 $class = 'butAction butActionEmail';
4605 } elseif ($actionType == 'clone') {
4606 $class = 'butAction butActionClone';
4607 } elseif ($actionType == 'cancel') {
4608 $class = 'butAction butActionDelete';
4609 } elseif ($actionType == 'danger' || $actionType == 'delete') {
4610 $class = 'butAction butActionDelete';
4611 if (!empty($url) && strpos($url, 'token=') === false) {
4612 $url .= '&token=' . newToken();
4613 }
4614 }
4615 }
4616 if (empty($label) && !empty($userRight) && $userRight > 0 && in_array($actionType, array('email', 'clone', 'delete', 'danger', 'cancel'))) {
4617 $label = $text; // These buttons are shown as a picto only, so we need the text as tooltip
4618 }
4619 $attr = array(
4620 'class' => $class,
4621 'href' => empty($url) ? '' : $url,
4622 'title' => $label
4623 );
4624
4625 if (empty($text)) {
4626 $text = $label;
4627 $attr['title'] = ''; // if html not set, using label on title is redundant
4628 } else {
4629 $attr['title'] = $label;
4630 $attr['aria-label'] = $label;
4631 }
4632
4633 if (empty($userRight) || $userRight < 0) {
4634 $attr['class'] = 'butActionRefused';
4635 $attr['href'] = '';
4636 $attr['title'] = (($label && $text && $label != $text) ? $label : '');
4637 $attr['title'] = ($attr['title'] ? $attr['title'] . (empty($userRight) ? '<br>' : '') : '');
4638 $attr['title'] .= ((empty($userRight) && empty($label)) ? $langs->trans('NotEnoughPermissions') : '');
4639 }
4640
4641 if (!empty($id)) {
4642 $attr['id'] = $id;
4643 }
4644
4645 // Override attr
4646 if (!empty($params['attr']) && is_array($params['attr'])) {
4647 foreach ($params['attr'] as $key => $value) {
4648 if ($key == 'class') {
4649 $attr['class'] .= ' ' . $value;
4650 } elseif ($key == 'classOverride') {
4651 $attr['class'] = $value;
4652 } else {
4653 $attr[$key] = $value;
4654 }
4655 }
4656 }
4657
4658 // automatic add tooltip when title is detected
4659 if (!empty($attr['title']) && !empty($attr['class']) && strpos($attr['class'], 'classfortooltip') === false) {
4660 $attr['class'] .= ' classfortooltip';
4661 }
4662
4663 // Js Confirm button
4664 if ($userRight && !empty($params['confirm'])) {
4665 if (!is_array($params['confirm'])) {
4666 $params['confirm'] = array();
4667 }
4668
4669 if (empty($params['confirm']['url'])) {
4670 $params['confirm']['url'] = $url . (strpos($url, '?') > 0 ? '&' : '?') . 'confirm=yes';
4671 }
4672
4673 // for js disabled compatibility set $url as call to confirm action and $params['confirm']['url'] to confirmed action
4674 $attr['data-confirm-url'] = $params['confirm']['url'];
4675 $attr['data-confirm-title'] = !empty($params['confirm']['title']) ? $params['confirm']['title'] : $langs->trans('ConfirmBtnCommonTitle', $label);
4676 $attr['data-confirm-content'] = !empty($params['confirm']['content']) ? $params['confirm']['content'] : $langs->trans('ConfirmBtnCommonContent', $label);
4677 $attr['data-confirm-content'] = preg_replace("/\r|\n/", "", $attr['data-confirm-content']);
4678 $attr['data-confirm-action-btn-label'] = !empty($params['confirm']['action-btn-label']) ? $params['confirm']['action-btn-label'] : $langs->trans('Confirm');
4679 $attr['data-confirm-cancel-btn-label'] = !empty($params['confirm']['cancel-btn-label']) ? $params['confirm']['cancel-btn-label'] : $langs->trans('CloseDialog');
4680 $attr['data-confirm-modal'] = !empty($params['confirm']['modal']) ? $params['confirm']['modal'] : true;
4681
4682 $attr['class'] .= ' butActionConfirm';
4683 }
4684
4685 if (isset($attr['href']) && empty($attr['href'])) {
4686 unset($attr['href']);
4687 }
4688
4689 // TODO replace this $TCompiledAttr generation block by commonHtmlAttributeBuilder like line below
4690 // $TCompiledAttr = commonHtmlAttributeBuilder($attr, $params['use_unsecured_unescapedattr'] ?? []);
4691 $TCompiledAttr = array();
4692 foreach ($attr as $key => $value) {
4693 if (!empty($params['use_unsecured_unescapedattr']) && is_array($params['use_unsecured_unescapedattr']) && in_array($key, $params['use_unsecured_unescapedattr'])) {
4694 // Deprecated, forbidden.
4695 $value = dol_htmlentities($value, ENT_QUOTES | ENT_SUBSTITUTE);
4696 } elseif (in_array($key, ['href', 'data-confirm-url'])) {
4697 $value = dolPrintHTMLForAttributeUrl($value);
4698 } else {
4699 $value = dolPrintHTMLForAttribute($value);
4700 }
4701
4702 $TCompiledAttr[] = $key . '="' . $value . '"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
4703 }
4704 $compiledAttributes = empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr);
4705
4706 $tag = !empty($attr['href']) ? 'a' : 'span';
4707
4708 $parameters = array(
4709 'TCompiledAttr' => $TCompiledAttr, // array
4710 'compiledAttributes' => $compiledAttributes, // string
4711 'attr' => $attr,
4712 'tag' => $tag,
4713 'label' => $label,
4714 'html' => $text,
4715 'actionType' => $actionType,
4716 'url' => $url,
4717 'id' => $id,
4718 'userRight' => $userRight,
4719 'params' => $params
4720 );
4721
4722 $reshook = $hookmanager->executeHooks('dolGetButtonAction', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
4723 if ($reshook < 0) {
4724 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
4725 }
4726
4727 if (empty($reshook)) {
4728 if (dol_textishtml($text)) { // If content already HTML encoded
4729 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton">' . $text . '</span></' . $tag . '>';
4730 } else {
4731 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton">' . dol_escape_htmltag($text) . '</span></' . $tag . '>';
4732 }
4733 } else {
4734 return $hookmanager->resPrint;
4735 }
4736}
4737
4768function commonHtmlAttributeBuilder($attr, array $unescapedAttr = [])
4769{
4770 $TCompiledAttr = array();
4771 if (empty($attr)) {
4772 return [];
4773 }
4774
4775 foreach ($attr as $key => $value) {
4776 // special boolean attributes case
4777 if (in_array($key, getListOfHtmlBooleanAttributes())) {
4778 if ($value) {
4779 $TCompiledAttr[$key] = $key;
4780 }
4781 continue;
4782 }
4783
4784 if (!empty($unescapedAttr) && in_array($key, $unescapedAttr)) {
4785 // Not recommended
4786 $value = dol_htmlentities((string) $value, ENT_QUOTES | ENT_SUBSTITUTE);
4787 } elseif (in_array($key, ['href', 'data-confirm-url'])) {
4788 $value = dolPrintHTMLForAttributeUrl((string) $value);
4789 } else {
4790 $value = dolPrintHTMLForAttribute((string) $value);
4791 }
4792
4793 $TCompiledAttr[$key] = $key . '="' . $value . '"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
4794 }
4795
4796 return $TCompiledAttr;
4797}
4798
4814{
4815 return [
4816 // Input / Form
4817 'checked',
4818 'disabled',
4819 'readonly',
4820 'required',
4821 'autofocus',
4822 'multiple',
4823
4824 // Option
4825 'selected',
4826
4827 // Form / General
4828 'novalidate',
4829 'formnovalidate',
4830
4831 // Media
4832 'autoplay',
4833 'controls',
4834 'loop',
4835 'muted',
4836 'playsinline',
4837
4838 // Other elements
4839 'hidden',
4840 'open',
4841 'ismap',
4842 'reversed',
4843 'allowfullscreen',
4844 'itemscope',
4845 'nomodule',
4846 'defer',
4847 'async',
4848 'default',
4849 'inert',
4850 ];
4851}
4852
4853
4862function dolCompletUrlForDropdownButton(string $url, array $params, bool $addDolUrlRoot = true)
4863{
4864 if (empty($url)) {
4865 return '';
4866 }
4867
4868 $parsedUrl = parse_url($url);
4869 if ((isset($parsedUrl['scheme']) && in_array($parsedUrl['scheme'], ['javascript', 'mailto', 'tel'])) || strpos($url, '#') === 0) {
4870 return $url;
4871 }
4872
4873 if (!empty($parsedUrl['query'])) {
4874 // Use parse_str() function to parse the string passed via URL
4875 $urlQuery = '';
4876 parse_str($parsedUrl['query'], $urlQuery);
4877 if (!isset($urlQuery['backtopage']) && isset($params['backtopage'])) {
4878 $url .= '&amp;backtopage=' . urlencode($params['backtopage']);
4879 }
4880 }
4881
4882 if (!isset($parsedUrl['scheme']) && $addDolUrlRoot) {
4883 $url = DOL_URL_ROOT . $url;
4884 }
4885
4886 return $url;
4887}
4888
4889
4896function dolGetButtonTitleSeparator($moreClass = "")
4897{
4898 return '<span class="button-title-separator ' . $moreClass . '" ></span>';
4899}
4900
4907function getFieldErrorIcon($fieldValidationErrorMsg)
4908{
4909 $out = '';
4910 if (!empty($fieldValidationErrorMsg)) {
4911 $out .= '<span class="field-error-icon classfortooltip" title="' . dol_escape_htmltag($fieldValidationErrorMsg, 1) . '" role="alert" >'; // role alert is used for accessibility
4912 $out .= '<span class="fa fa-exclamation-circle" aria-hidden="true" ></span>'; // For accessibility icon is separated and aria-hidden
4913 $out .= '</span>';
4914 }
4915
4916 return $out;
4917}
4918
4931function dolGetButtonTitle($label, $helpText = '', $iconClass = 'fa fa-file', $url = '', $id = '', $status = 1, $params = array())
4932{
4933 global $langs, $user;
4934
4935 // Actually this conf is used in css too for external module compatibility and smooth transition to this function
4936 if (getDolGlobalString('MAIN_BUTTON_HIDE_UNAUTHORIZED') && (!$user->admin) && $status <= 0) {
4937 return '';
4938 }
4939 // Fix old picto fa-th-list to use fa-grid-vertical instead
4940 if ($iconClass == 'fa fa-th-list imgforviewmode') {
4941 $iconClass = ' fa fa-grip-horizontal imgforviewmode';
4942 }
4943
4944 $class = 'btnTitle';
4945 if (in_array($iconClass, array('fa fa-plus-circle', 'fa fa-plus-circle size15x', 'fa fa-comment-dots', 'fa fa-paper-plane'))) {
4946 $class .= ' btnTitlePlus';
4947 }
4948 $useclassfortooltip = 1;
4949
4950 if (!empty($params['morecss'])) {
4951 $class .= ' ' . $params['morecss'];
4952 }
4953
4954 $attr = array(
4955 'class' => $class,
4956 'href' => empty($url) ? '' : $url
4957 );
4958
4959 if (!empty($helpText)) {
4960 $attr['title'] = $helpText;
4961 } elseif ($label) { // empty($attr['title']) &&
4962 $attr['title'] = $label;
4963 $useclassfortooltip = 0;
4964 }
4965
4966 if ($status == 2) {
4967 $attr['class'] .= ' btnTitleSelected';
4968 } elseif ($status <= 0) {
4969 $attr['class'] .= ' refused';
4970
4971 $attr['href'] = '';
4972
4973 if ($status == -1) { // disable
4974 $attr['title'] = $langs->transnoentitiesnoconv("FeatureDisabled");
4975 } elseif ($status == 0) { // Not enough permissions
4976 $attr['title'] = $langs->transnoentitiesnoconv("NotEnoughPermissions");
4977 }
4978 }
4979
4980 if (!empty($attr['title']) && $useclassfortooltip) {
4981 $attr['class'] .= ' classfortooltip';
4982 }
4983
4984 if (!empty($id)) {
4985 $attr['id'] = $id;
4986 }
4987
4988 // Override attr
4989 if (!empty($params['attr']) && is_array($params['attr'])) {
4990 foreach ($params['attr'] as $key => $value) {
4991 if ($key == 'class') {
4992 $attr['class'] .= ' ' . $value;
4993 } elseif ($key == 'classOverride') {
4994 $attr['class'] = $value;
4995 } else {
4996 $attr[$key] = $value;
4997 }
4998 }
4999 }
5000
5001 if (isset($attr['href']) && empty($attr['href'])) {
5002 unset($attr['href']);
5003 }
5004
5005 // TODO : add a hook
5006
5007 // Generate attributes with escapement
5008 $TCompiledAttr = array();
5009 foreach ($attr as $key => $value) {
5010 $TCompiledAttr[] = $key . '="' . dol_escape_htmltag($value) . '"'; // Do not use dolPrintHTMLForAttribute() here, we must accept "javascript:string"
5011 }
5012
5013 $compiledAttributes = (empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr));
5014
5015 $tag = (empty($attr['href']) ? 'span' : 'a');
5016
5017 $button = '<' . $tag . ' ' . $compiledAttributes . '>';
5018 $button .= '<span class="' . $iconClass . ' valignmiddle btnTitle-icon"></span>';
5019 if (!empty($params['forcenohideoftext'])) {
5020 $button .= '<span class="valignmiddle text-plus-circle btnTitle-label' . (empty($params['forcenohideoftext']) ? ' hideonsmartphone' : '') . '">' . $label . '</span>';
5021 }
5022 $button .= '</' . $tag . '>';
5023
5024 return $button;
5025}
5026
5027
5028
5042function startSimpleTable($header, $link = "", $arguments = "", $emptyColumns = 0, $number = -1, $pictofulllist = '')
5043{
5044 global $langs;
5045
5046 print '<div class="div-table-responsive-no-min">';
5047 print '<table class="noborder centpercent">';
5048 print '<tr class="liste_titre">';
5049
5050 print ($emptyColumns < 1) ? '<th>' : '<th colspan="' . ($emptyColumns + 1) . '">';
5051
5052 print '<span class="valignmiddle">' . $langs->trans($header) . '</span>';
5053
5054 if (!empty($link)) {
5055 if (!empty($arguments)) {
5056 print '<a href="' . DOL_URL_ROOT . '/' . $link . '?' . $arguments . '">';
5057 } else {
5058 print '<a href="' . DOL_URL_ROOT . '/' . $link . '">';
5059 }
5060 }
5061
5062 if ($number > -1) {
5063 print '<span class="badge marginleftonlyshort">' . $number . '</span>';
5064 } elseif (!empty($link)) {
5065 print '<span class="badge marginleftonlyshort">...</span>';
5066 }
5067
5068 if (!empty($link)) {
5069 print '</a>';
5070 }
5071
5072 print '</th>';
5073
5074 if ($number < 0 && !empty($link)) {
5075 print '<th class="right">';
5076 print '</th>';
5077 }
5078
5079 print '</tr>';
5080}
5081
5090function finishSimpleTable($addLineBreak = false)
5091{
5092 print '</table>';
5093 print '</div>';
5094
5095 if ($addLineBreak) {
5096 print '<br>';
5097 }
5098}
5099
5111function addSummaryTableLine($tableColumnCount, $num, $nbofloop = 0, $total = 0, $noneWord = "None", $extraRightColumn = false)
5112{
5113 global $langs;
5114
5115 if ($num === 0) {
5116 print '<tr class="oddeven">';
5117 print '<td colspan="' . $tableColumnCount . '"><span class="opacitymedium">' . $langs->trans($noneWord) . '</span></td>';
5118 print '</tr>';
5119 return;
5120 }
5121
5122 if ($nbofloop === 0) {
5123 // don't show a summary line
5124 return;
5125 }
5126
5127 /* Case already handled above, commented to satisfy phpstan.
5128 if ($num === 0) {
5129 $colspan = $tableColumnCount;
5130 } else
5131 */
5132 if ($num > $nbofloop) {
5133 $colspan = $tableColumnCount;
5134 } else {
5135 $colspan = $tableColumnCount - 1;
5136 }
5137
5138 if ($extraRightColumn) {
5139 $colspan--;
5140 }
5141
5142 print '<tr class="liste_total">';
5143
5144 if ($nbofloop > 0 && $num > $nbofloop) {
5145 print '<td colspan="' . $colspan . '" class="right">' . $langs->trans("XMoreLines", ($num - $nbofloop)) . '</td>';
5146 } else {
5147 print '<td colspan="' . $colspan . '" class="right"> ' . $langs->trans("Total") . '</td>';
5148 print '<td class="right centpercent">' . price($total) . '</td>';
5149 }
5150
5151 if ($extraRightColumn) {
5152 print '<td></td>';
5153 }
5154
5155 print '</tr>';
5156}
5157
5158
5159
5169function showValueWithClipboardCPButton($valuetocopy, $showonlyonhover = 1, $texttoshow = '')
5170{
5171 global $langs;
5172
5173 $tag = 'span'; // Using div (like any style of type 'block') does not work when using the js copy code.
5174
5175 $result = '<span class="clipboardCP' . ($showonlyonhover ? ' clipboardCPShowOnHover valignmiddle' : '') . '">';
5176 if ($texttoshow === 'none') {
5177 $result .= '<' . $tag . ' class="clipboardCPValue hidewithsize">' . dol_escape_htmltag($valuetocopy, 1, 1) . '</' . $tag . '>';
5178 $result .= '<span class="clipboardCPValueToPrint"></span>';
5179 } elseif ($texttoshow) {
5180 $result .= '<' . $tag . ' class="clipboardCPValue hidewithsize">' . dol_escape_htmltag($valuetocopy, 1, 1) . '</' . $tag . '>';
5181 $result .= '<span class="clipboardCPValueToPrint">' . dol_escape_htmltag($texttoshow, 1, 1) . '</span>';
5182 } else {
5183 $result .= '<' . $tag . ' class="clipboardCPValue">' . dol_escape_htmltag($valuetocopy, 1, 1) . '</' . $tag . '>';
5184 }
5185 $result .= '<span class="clipboardCPButton far fa-clipboard opacitymedium paddingleft pictomodule" title="' . dolPrintHTML($langs->trans("ClickToCopyToClipboard")) . '"></span>';
5186 $result .= img_picto('', 'tick', 'class="clipboardCPTick hidden paddingleft pictomodule"');
5187 $result .= '<span class="clipboardCPText"></span>';
5188 $result .= '</span>';
5189
5190 return $result;
5191}
5192
5193
5194
5212function show_actions_messaging($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC')
5213{
5214 dol_syslog('show_actions_messaging::begin', LOG_DEBUG);
5215 global $user, $conf;
5216 global $form;
5217
5218 global $param, $massactionbutton;
5219
5220 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
5221
5222 // Check parameters
5223 if (!is_object($filterobj) && !is_object($objcon)) {
5224 dol_print_error(null, 'BadParameter');
5225 }
5226
5227 $histo = array();
5228 '@phan-var-force array<int,array{type:string,tododone:string,id:string,datestart:int|string,dateend:int|string,fulldayevent:int,note:string,message:string,percent:string,userid:string,login:string,userfirstname:string,userlastname:string,userphoto:string,msg_from?:string,contact_id?:string,socpeopleassigned?:int[],lastname?:string,firstname?:string,fk_element?:int,elementtype?:string,acode:string,alabel?:string,libelle?:string,apicto?:string}> $histo';
5229
5230 $numaction = 0;
5231 $now = dol_now();
5232
5233 $sortfield_list = explode(',', $sortfield);
5234 $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
5235 $sanitized_sortfield_new_list = array();
5236 foreach ($sortfield_list as $sortfield_value) {
5237 $sanitized_sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)]; //@phan-suppress-current-line SqlInjection
5238 }
5239 $sanitized_sortfield_new = implode(',', $sanitized_sortfield_new_list);
5240
5241 $sql = null;
5242 $sql2 = null;
5243
5244 if (isModEnabled('agenda')) {
5245 // Search histo on actioncomm
5246 if (is_object($objcon) && $objcon->id > 0) {
5247 $sql = "SELECT DISTINCT a.id, a.label as label,";
5248 } else {
5249 $sql = "SELECT a.id, a.label as label,";
5250 }
5251 $sql .= " a.datep as dp,";
5252 $sql .= " a.note as message,";
5253 $sql .= " a.datep2 as dp2,";
5254 $sql .= " a.percent as percent, 'action' as type,";
5255 $sql .= " a.fk_element, a.elementtype,";
5256 $sql .= " a.fk_contact, a.fulldayevent,";
5257 $sql .= " a.email_from as msg_from,";
5258 $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
5259 $sql .= " u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname";
5260 if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
5261 $sql .= ", sp.lastname, sp.firstname";
5262 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
5263 $sql .= ", m.lastname, m.firstname";
5264 } elseif (is_object($filterobj) && in_array(get_class($filterobj), array('Commande', 'CommandeFournisseur', 'Product', 'Ticket', 'BOM', 'Contrat', 'Facture', 'FactureFournisseur', 'Propal', 'Expedition'))) {
5265 $sql .= ", o.ref";
5266 } else {
5267 if (is_object($filterobj) && !empty($filterobj->table_element) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists('ref', $filterobj->fields)) {
5268 $sql .= ", o.ref";
5269 }
5270 }
5271 $sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm as a";
5272 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on u.rowid = a.fk_user_action";
5273 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_actioncomm as c ON a.fk_action = c.id";
5274
5275 $force_filter_contact = $filterobj instanceof User;
5276
5277 if (is_object($objcon) && $objcon->id > 0) {
5278 $force_filter_contact = true;
5279 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "actioncomm_resources as r ON a.id = r.fk_actioncomm";
5280 $sql .= " AND r.element_type = '" . $db->escape($objcon->table_element) . "' AND r.fk_element = " . ((int) $objcon->id);
5281 }
5282
5283 if ((is_object($filterobj) && get_class($filterobj) == 'Societe') || (is_object($filterobj) && get_class($filterobj) == 'Contact')) {
5284 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sp ON a.fk_contact = sp.rowid";
5285 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
5286 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "element_resources as er";
5287 $sql .= " ON er.resource_type = 'dolresource'";
5288 $sql .= " AND er.element_id = a.id";
5289 $sql .= " AND er.resource_id = " . ((int) $filterobj->id);
5290 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
5291 $sql .= ", " . MAIN_DB_PREFIX . "adherent as m";
5292 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
5293 $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as o";
5294 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
5295 $sql .= ", " . MAIN_DB_PREFIX . "product as o";
5296 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
5297 $sql .= ", " . MAIN_DB_PREFIX . "ticket as o";
5298 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
5299 $sql .= ", " . MAIN_DB_PREFIX . "bom_bom as o";
5300 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
5301 $sql .= ", " . MAIN_DB_PREFIX . "contrat as o";
5302 } elseif (is_object($filterobj) && get_class($filterobj) == 'Facture') {
5303 $sql .= ", " . MAIN_DB_PREFIX . "facture as o";
5304 } elseif (is_object($filterobj) && get_class($filterobj) == 'FactureFournisseur') {
5305 $sql .= ", " . MAIN_DB_PREFIX . "facture_fourn as o";
5306 } elseif (is_object($filterobj) && get_class($filterobj) == 'Commande') {
5307 $sql .= ", " . MAIN_DB_PREFIX . "commande as o";
5308 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
5309 $sql .= ", " . MAIN_DB_PREFIX . "expedition as o";
5310 } elseif (is_object($filterobj) && get_class($filterobj) == 'Propal') {
5311 $sql .= ", " . MAIN_DB_PREFIX . "propal as o";
5312 } else {
5313 if (is_object($filterobj) && !empty($filterobj->table_element) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists('ref', $filterobj->fields)) {
5314 $sql .= ", " . MAIN_DB_PREFIX . $filterobj->table_element . " as o";
5315 }
5316 }
5317 $sql .= " WHERE a.entity IN (" . getEntity('agenda') . ")";
5318 if (!$force_filter_contact) {
5319 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
5320 $sql .= " AND a.fk_soc = " . ((int) $filterobj->id);
5321 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
5322 $sql .= " AND a.fk_project = o.rowid AND a.fk_project = " . ((int) $filterobj->id);
5323 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
5324 $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
5325 if ($filterobj->id) {
5326 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
5327 }
5328 } elseif (is_object($filterobj) && get_class($filterobj) == 'Commande') {
5329 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order'";
5330 if ($filterobj->id) {
5331 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
5332 }
5333 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
5334 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'shipping'";
5335 if ($filterobj->id) {
5336 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
5337 }
5338 } elseif (is_object($filterobj) && get_class($filterobj) == 'Propal') {
5339 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'propal'";
5340 if ($filterobj->id) {
5341 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
5342 }
5343 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
5344 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
5345 if ($filterobj->id) {
5346 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
5347 }
5348 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
5349 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
5350 if ($filterobj->id) {
5351 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
5352 }
5353 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
5354 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
5355 if ($filterobj->id) {
5356 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
5357 }
5358 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
5359 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
5360 if ($filterobj->id) {
5361 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
5362 }
5363 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
5364 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
5365 if ($filterobj->id) {
5366 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
5367 }
5368 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contact' && $filterobj->id) {
5369 $sql .= " AND a.fk_contact = sp.rowid";
5370 $sql .= " AND a.fk_contact = " . ((int) $filterobj->id);
5371 } elseif (is_object($filterobj) && get_class($filterobj) == 'Facture') {
5372 $sql .= " AND a.fk_element = o.rowid";
5373 if ($filterobj->id) {
5374 $sql .= " AND a.fk_element = " . ((int) $filterobj->id) . " AND a.elementtype = 'invoice'";
5375 }
5376 } elseif (is_object($filterobj) && get_class($filterobj) == 'FactureFournisseur') {
5377 $sql .= " AND a.fk_element = o.rowid";
5378 if ($filterobj->id) {
5379 $sql .= " AND a.fk_element = " . ((int) $filterobj->id) . " AND a.elementtype = 'invoice_supplier'";
5380 }
5381 } else {
5382 if (is_object($filterobj) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists('ref', $filterobj->fields)) {
5383 $sql .= " AND a.fk_element = o.rowid";
5384 $sql .= " AND a.elementtype = '" . $db->escape($filterobj->element) . "'";
5385 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
5386 }
5387 }
5388 } else {
5389 $sql .= " AND u.rowid = " . ((int) $filterobj->id);
5390 }
5391
5392 // Condition on actioncode
5393 if (!empty($actioncode) && $actioncode != '-1') {
5394 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
5395 if ($actioncode == 'AC_NON_AUTO') {
5396 $sql .= " AND c.type != 'systemauto'";
5397 } elseif ($actioncode == 'AC_ALL_AUTO') {
5398 $sql .= " AND c.type = 'systemauto'";
5399 } else {
5400 if ($actioncode == 'AC_OTH') {
5401 $sql .= " AND c.type != 'systemauto'";
5402 } elseif ($actioncode == 'AC_OTH_AUTO') {
5403 $sql .= " AND c.type = 'systemauto'";
5404 }
5405 }
5406 } else {
5407 if ($actioncode == 'AC_NON_AUTO') {
5408 $sql .= " AND c.type != 'systemauto'";
5409 } elseif ($actioncode == 'AC_ALL_AUTO') {
5410 $sql .= " AND c.type = 'systemauto'";
5411 } else {
5412 $sql .= " AND c.code = '" . $db->escape($actioncode) . "'";
5413 }
5414 }
5415 }
5416 if ($donetodo == 'todo') {
5417 $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '" . $db->idate($now) . "'))";
5418 } elseif ($donetodo == 'done') {
5419 $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" . $db->idate($now) . "'))";
5420 }
5421 if (is_array($filters) && $filters['search_agenda_label']) {
5422 $sql .= natural_search('a.label', $filters['search_agenda_label']);
5423 }
5424 }
5425
5426 // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
5427 if (
5428 isModEnabled('mailing') && !empty($objcon->email)
5429 && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')
5430 ) {
5431 $langs->load("mails");
5432
5433 $sql2 = "SELECT m.rowid as id, m.titre as label, mc.date_envoi as dp, mc.date_envoi as dp2, '100' as percent, 'mailing' as type";
5434 $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
5435 $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
5436 $sql2 .= ", u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; // User that valid action
5437 if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
5438 $sql2 .= ", '' as lastname, '' as firstname";
5439 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
5440 $sql2 .= ", '' as lastname, '' as firstname";
5441 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
5442 $sql2 .= ", '' as ref";
5443 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
5444 $sql2 .= ", '' as ref";
5445 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
5446 $sql2 .= ", '' as ref";
5447 }
5448 $sql2 .= " FROM " . MAIN_DB_PREFIX . "mailing as m, " . MAIN_DB_PREFIX . "mailing_cibles as mc, " . MAIN_DB_PREFIX . "user as u";
5449 $sql2 .= " WHERE mc.email = '" . $db->escape((string) $objcon->email) . "'"; // Search is done on email.
5450 $sql2 .= " AND mc.statut = 1";
5451 $sql2 .= " AND u.rowid = m.fk_user_valid";
5452 $sql2 .= " AND mc.fk_mailing=m.rowid";
5453 }
5454
5455 $num = 0;
5456 $MAXWITHOUTPAGINATION = getDolGlobalInt('AGENDA_MAX_EVENTS_ON_PAGE_WITHOUT_PAGINATION', 100);
5457
5458 if ($sql || $sql2) { // May not be defined if module Agenda is not enabled and mailing module disabled too
5459 if (!empty($sql) && !empty($sql2)) {
5460 $sql = $sql . " UNION " . $sql2;
5461 } elseif (empty($sql) && !empty($sql2)) {
5462 $sql = $sql2;
5463 }
5464
5465 //TODO Add navigation with this limits...
5466 $offset = 0;
5467 $limit = $MAXWITHOUTPAGINATION;
5468
5469 // Complete request and execute it with limit
5470 $sql .= $db->order($sanitized_sortfield_new, $sortorder);
5471 if ($limit) {
5472 $sql .= $db->plimit($limit + 1, $offset);
5473 }
5474
5475 dol_syslog("function.lib::show_actions_messaging", LOG_DEBUG);
5476
5477 $resql = $db->query($sql);
5478 if ($resql) {
5479 $i = 0;
5480 $num = $db->num_rows($resql);
5481
5482 $imaxinloop = ($limit ? min($num, $limit) : $num);
5483 while ($i < $imaxinloop) {
5484 $obj = $db->fetch_object($resql);
5485
5486 if ($obj->type == 'action') {
5487 $contactaction = new ActionComm($db);
5488 $contactaction->id = $obj->id;
5489 $result = $contactaction->fetchResources();
5490 if ($result < 0) {
5491 dol_print_error($db);
5492 setEventMessage("actions.lib::show_actions_messaging Error fetch resource", 'errors');
5493 }
5494
5495 //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
5496 //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
5497 $tododone = '';
5498 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->dp > $now)) {
5499 $tododone = 'todo';
5500 }
5501
5502 $histo[$numaction] = array(
5503 'type' => $obj->type,
5504 'tododone' => $tododone,
5505 'id' => $obj->id,
5506 'datestart' => $db->jdate($obj->dp),
5507 'dateend' => $db->jdate($obj->dp2),
5508 'fulldayevent' => (int) $obj->fulldayevent,
5509 'note' => $obj->label,
5510 'message' => $obj->message,
5511 'percent' => $obj->percent,
5512
5513 'userid' => $obj->user_id,
5514 'login' => $obj->user_login,
5515 'userfirstname' => $obj->user_firstname,
5516 'userlastname' => $obj->user_lastname,
5517 'userphoto' => $obj->user_photo,
5518 'msg_from' => $obj->msg_from,
5519
5520 'contact_id' => $obj->fk_contact,
5521 'socpeopleassigned' => $contactaction->socpeopleassigned,
5522 'lastname' => (empty($obj->lastname) ? '' : $obj->lastname),
5523 'firstname' => (empty($obj->firstname) ? '' : $obj->firstname),
5524 'fk_element' => $obj->fk_element,
5525 'elementtype' => $obj->elementtype,
5526 // Type of event
5527 'acode' => $obj->acode,
5528 'alabel' => $obj->alabel,
5529 'libelle' => $obj->alabel, // deprecated
5530 'apicto' => $obj->apicto
5531 );
5532 } else {
5533 $histo[$numaction] = array(
5534 'type' => $obj->type,
5535 'tododone' => 'done',
5536 'id' => $obj->id,
5537 'datestart' => $db->jdate($obj->dp),
5538 'dateend' => $db->jdate($obj->dp2),
5539 'fulldayevent' => (int) $obj->fulldayevent,
5540 'note' => $obj->label,
5541 'message' => $obj->message,
5542 'percent' => $obj->percent,
5543 'acode' => $obj->acode,
5544
5545 'userid' => $obj->user_id,
5546 'login' => $obj->user_login,
5547 'userfirstname' => $obj->user_firstname,
5548 'userlastname' => $obj->user_lastname,
5549 'userphoto' => $obj->user_photo
5550 );
5551 }
5552
5553 $numaction++;
5554 $i++;
5555 }
5556 } else {
5557 dol_print_error($db);
5558 }
5559 }
5560
5561 // Set $out to show events
5562 $out = '';
5563
5564 if (!isModEnabled('agenda')) {
5565 $langs->loadLangs(array("admin", "errors"));
5566 $out = info_admin($langs->trans("WarningModuleXDisabledSoYouMayMissEventHere", $langs->transnoentitiesnoconv("Module2400Name")), 0, 0, 'warning');
5567 }
5568
5569 if (isModEnabled('agenda') || (isModEnabled('mailing') && !empty($objcon->email))) {
5570 $delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
5571
5572 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
5573 include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
5574 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
5575 require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
5576
5577 $formactions = new FormActions($db);
5578
5579 $actionstatic = new ActionComm($db);
5580 $userstatic = new User($db);
5581 $contactstatic = new Contact($db);
5582 $userGetNomUrlCache = array();
5583 $contactGetNomUrlCache = array();
5584
5585 $out .= '<div class="filters-container" >';
5586 $out .= '<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '" method="POST" spellcheck="false">';
5587 $out .= '<input type="hidden" name="token" value="' . newToken() . '">';
5588
5589 if (
5590 $objcon && get_class($objcon) == 'Contact' &&
5591 (is_null($filterobj) || get_class($filterobj) == 'Societe')
5592 ) {
5593 $out .= '<input type="hidden" name="id" value="' . $objcon->id . '" />';
5594 } else {
5595 $out .= '<input type="hidden" name="id" value="' . $filterobj->id . '" />';
5596 }
5597 if (($filterobj && get_class($filterobj) == 'Societe')) {
5598 $out .= '<input type="hidden" name="socid" value="' . $filterobj->id . '" />';
5599 } else {
5600 $out .= '<input type="hidden" name="userid" value="' . $filterobj->id . '" />';
5601 }
5602
5603 $out .= "\n";
5604
5605 $out .= '<div class="div-table-responsive-no-min">';
5606 $out .= '<table class="noborder borderbottom centpercent">';
5607
5608 $out .= '<tr class="liste_titre">';
5609
5610 // Action column
5611 if ($conf->main_checkbox_left_column) {
5612 $out .= '<th class="liste_titre width50 middle">';
5613 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
5614 $out .= $searchpicto;
5615 $out .= '</th>';
5616 }
5617
5618 // Date
5619 $out .= getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', '', $param, '', $sortfield, $sortorder, 'nowraponall nopaddingleftimp ') . "\n";
5620
5621 $out .= '<th class="liste_titre hideonsmartphone"><strong class="hideonsmartphone">' . $langs->trans("Search") . ' : </strong></th>';
5622 if ($donetodo) {
5623 $out .= '<th class="liste_titre"></th>';
5624 }
5625 // Type of event
5626 $out .= '<th class="liste_titre">';
5627 $out .= '<span class="fas fa-square inline-block fawidth30 hideonsmartphone" style="color: #ddd;" title="' . $langs->trans("ActionType") . '"></span>';
5628 $out .= $formactions->select_type_actions($actioncode, "actioncode", '', getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? -1 : 1, 0, 0, 1, 'selecttype minwidth100', $langs->trans("Type"));
5629 $out .= '</th>';
5630 // Label
5631 $out .= '<th class="liste_titre maxwidth100onsmartphone">';
5632 $out .= '<input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="' . $filters['search_agenda_label'] . '" placeholder="' . $langs->trans("Label") . '">';
5633 $out .= '</th>';
5634
5635 // Action column
5636 if (!$conf->main_checkbox_left_column) {
5637 $out .= '<th class="liste_titre width50 middle">';
5638 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
5639 $out .= $searchpicto;
5640 $out .= '</th>';
5641 }
5642
5643 $out .= '</tr>';
5644
5645 $out .= '</table>';
5646
5647 $out .= '</form>';
5648 $out .= '</div>';
5649
5650 $out .= "\n";
5651
5652 $out .= '<ul class="timeline">';
5653
5654 if ($donetodo) {
5655 $tmp = '';
5656 if ($filterobj instanceof Societe) {
5657 $tmp .= '<a href="' . DOL_URL_ROOT . '/comm/action/list.php?mode=show_list&socid=' . $filterobj->id . '&status=done">';
5658 }
5659 if ($filterobj instanceof User) {
5660 $tmp .= '<a href="' . DOL_URL_ROOT . '/comm/action/list.php?mode=show_list&socid=' . $filterobj->id . '&status=done">';
5661 }
5662 $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
5663 $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
5664 $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
5665 //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
5666 if ($filterobj instanceof Societe) {
5667 $tmp .= '</a>';
5668 }
5669 if ($filterobj instanceof User) {
5670 $tmp .= '</a>';
5671 }
5672 $out .= getTitleFieldOfList($tmp);
5673 }
5674
5675 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/cactioncomm.class.php';
5676 $caction = new CActionComm($db);
5677 $arraylist = $caction->liste_array(1, 'code', '', (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 1 : 0), '', 1);
5678
5679 $actualCycleDate = false;
5680
5681 // Loop on each event to show it
5682 foreach ($histo as $key => $value) {
5683 $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
5684
5685 $actionstatic->type_picto = $histo[$key]['apicto'];
5686 $actionstatic->type_code = $histo[$key]['acode'];
5687
5688 $labeltype = $actionstatic->type_code;
5689 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
5690 $labeltype = 'AC_OTH';
5691 }
5692 if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
5693 $labeltype = $langs->trans("Message");
5694 } else {
5695 if (!empty($arraylist[$labeltype])) {
5696 $labeltype = $arraylist[$labeltype];
5697 }
5698 if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
5699 $labeltype .= ' - ' . $arraylist[$actionstatic->code]; // Use code in priority on type_code
5700 }
5701 }
5702
5703 $url = DOL_URL_ROOT . '/comm/action/card.php?id=' . $histo[$key]['id'];
5704
5705 $tmpa = dol_getdate($histo[$key]['datestart'], false);
5706
5707 if (isset($tmpa['year']) && isset($tmpa['yday']) && $actualCycleDate !== $tmpa['year'] . '-' . $tmpa['yday']) {
5708 $actualCycleDate = $tmpa['year'] . '-' . $tmpa['yday'];
5709 $out .= '<!-- timeline time label -->';
5710 $out .= '<li class="time-label">';
5711 $out .= '<span class="timeline-badge-date">';
5712 $out .= dol_print_date($histo[$key]['datestart'], 'daytext', 'tzuserrel', $langs);
5713 $out .= '</span>';
5714 $out .= '</li>';
5715 $out .= '<!-- /.timeline-label -->';
5716 }
5717
5718
5719 $out .= '<!-- timeline item -->' . "\n";
5720 $out .= '<li class="timeline-code-' . (!empty($actionstatic->code) ? strtolower($actionstatic->code) : "none") . '">';
5721
5722 //$timelineicon = getTimelineIcon($actionstatic, $histo, $key);
5723 $typeicon = $actionstatic->getTypePicto('pictofixedwidth timeline-icon-not-applicble', $labeltype);
5724 //$out .= $timelineicon;
5725 //var_dump($timelineicon);
5726 $out .= $typeicon;
5727
5728 $out .= '<div class="timeline-item">' . "\n";
5729
5730 $out .= '<span class="time timeline-header-action2">';
5731
5732 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
5733 $out .= '<a class="paddingleft paddingright timeline-btn2 editfielda" href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo[$key]['id'] . '">' . img_object($langs->trans("ShowEMailing"), "email") . ' ';
5734 $out .= $histo[$key]['id'];
5735 $out .= '</a> ';
5736 } else {
5737 $out .= $actionstatic->getNomUrl(1, -1, 'valignmiddle') . ' ';
5738 }
5739
5740 if (
5741 $user->hasRight('agenda', 'allactions', 'create') ||
5742 (($actionstatic->authorid == $user->id || $actionstatic->userownerid == $user->id) && $user->hasRight('agenda', 'myactions', 'create'))
5743 ) {
5744 $out .= '<a class="paddingleft paddingright timeline-btn2 editfielda" href="' . DOL_MAIN_URL_ROOT . '/comm/action/card.php?action=edit&token=' . newToken() . '&id=' . $actionstatic->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?' . $param) . '">';
5745 //$out .= '<i class="fa fa-pencil" title="'.$langs->trans("Modify").'" ></i>';
5746 $out .= img_picto($langs->trans("Modify"), 'edit', 'class="edita"');
5747 $out .= '</a>';
5748 }
5749
5750 $out .= '</span>';
5751
5752 // Date
5753 $out .= '<span class="time"><i class="fa fa-clock valignmiddle"></i> ';
5754 $out .= '<span class="valignmiddle marginrightonly">';
5755 $out .= dol_print_date($histo[$key]['datestart'], 'day', 'tzuserrel');
5756 //$out .= '</span>';
5757 //$out .= '<span class="valignmiddle">'.
5758 $out .= ' '.dol_print_date($histo[$key]['datestart'], 'hour', 'tzuserrel', null, false, 'opacitymedium');
5759 //$out .= '</span>';
5760 if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart']) {
5761 $tmpa = dol_getdate($histo[$key]['datestart'], true);
5762 $tmpb = dol_getdate($histo[$key]['dateend'], true);
5763 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
5764 $out .= ' - ' . dol_print_date($histo[$key]['dateend'], 'hour', 'tzuserrel', null, false, 1);
5765 } else {
5766 $out .= ' - ' . dol_print_date($histo[$key]['dateend'], 'day', 'tzuserrel');
5767 //$out .= '<span class="valignmiddle marginrightonly">';
5768 $out .= ' '.dol_print_date($histo[$key]['dateend'], 'hour', 'tzuserrel', null, false, 'opacitymedium');
5769 //$out .= '</span>';
5770 }
5771 }
5772 $late = 0;
5773 if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
5774 $late = 1;
5775 }
5776 if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
5777 $late = 1;
5778 }
5779 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
5780 $late = 1;
5781 }
5782 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
5783 $late = 1;
5784 }
5785 if ($late) {
5786 $out .= img_warning($langs->trans("Late")) . ' ';
5787 }
5788 $out .= "</span></span>\n";
5789
5790 $out .= '<span class="time">';
5791 $out .= $actionstatic->getLibStatut(2);
5792 $out .= '</span>';
5793
5794 // Ref
5795 $out .= '<h3 class="timeline-header">';
5796
5797 // Author of event
5798 $out .= '<div class="messaging-author inline-block tdoverflowmax150 valignmiddle marginrightonly">';
5799 if ($histo[$key]['userid'] > 0) {
5800 if (!isset($userGetNomUrlCache[$histo[$key]['userid']])) { // is in cache ?
5801 $userstatic->fetch($histo[$key]['userid']);
5802 $userGetNomUrlCache[$histo[$key]['userid']] = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
5803 }
5804 $out .= $userGetNomUrlCache[$histo[$key]['userid']];
5805 } elseif (!empty($histo[$key]['msg_from']) && $actionstatic->code == 'TICKET_MSG') {
5806 if (!isset($contactGetNomUrlCache[$histo[$key]['msg_from']])) {
5807 if ($contactstatic->fetch(0, null, '', $histo[$key]['msg_from']) > 0) {
5808 $contactGetNomUrlCache[$histo[$key]['msg_from']] = $contactstatic->getNomUrl(-1, '', 16);
5809 } else {
5810 $contactGetNomUrlCache[$histo[$key]['msg_from']] = $histo[$key]['msg_from'];
5811 }
5812 }
5813 $out .= $contactGetNomUrlCache[$histo[$key]['msg_from']];
5814 } else {
5815 $out .= '<img class="photomemberphoto userphoto" alt="" src="/public/theme/common/user_anonymous.png">'.$langs->trans("Anonymous");
5816 }
5817 $out .= '</div>';
5818
5819 // Title
5820 $out .= ' <div class="messaging-title inline-block">';
5821 //$out .= $actionstatic->getTypePicto(); // The type of event is already into the timeline on left.
5822 if (empty($conf->dol_optimize_smallscreen) && $actionstatic->type_code != 'AC_OTH_AUTO') {
5823 $out .= $labeltype . ' - ';
5824 }
5825
5826 $tmplabel = '';
5827
5828 if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
5829 $out .= $langs->trans('TicketNewMessage').' - <em>'.img_picto($langs->trans('Private'), 'lock', 'class="valignmiddle"').' '.$langs->trans('Private').'</em>';
5830 $summary = preg_replace('/\[[^\]]*\]\s*/', '', $actionstatic->label);
5831 //if ($summary != $object->title) {
5832 $out .= ' - '.dolPrintHTML($summary);
5833 //}
5834 } elseif (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
5835 $out .= $langs->trans('TicketNewMessage');
5836 } elseif (isset($histo[$key]['type'])) {
5837 if ($histo[$key]['type'] == 'action') {
5838 $transcode = $langs->transnoentitiesnoconv("Action" . $histo[$key]['acode']);
5839 //$tmplabel = ($transcode != "Action" . $histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
5840 $tmplabel = $histo[$key]['note'];
5841 $actionstatic->id = $histo[$key]['id'];
5842 if ($tmplabel != $labeltype) {
5843 $out .= dol_escape_htmltag(dol_trunc($tmplabel, 120));
5844 }
5845 } elseif ($histo[$key]['type'] == 'mailing') {
5846 $out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo[$key]['id'] . '">' . img_object($langs->trans("ShowEMailing"), "email") . ' ';
5847 $transcode = $langs->transnoentitiesnoconv("Action" . $histo[$key]['acode']);
5848 $tmplabel = ($transcode != "Action" . $histo[$key]['acode'] ? $transcode : 'Send mass mailing');
5849 $out .= dol_escape_htmltag(dol_trunc($tmplabel, 120));
5850 } else {
5851 $tmplabel .= $histo[$key]['note'];
5852 $out .= dol_escape_htmltag(dol_trunc($tmplabel, 120));
5853 }
5854 }
5855 $out = preg_replace('/ - $/', '', $out); // Remove ending ' - '
5856
5857 if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
5858 if (isset($conf->cache['elementlinkcache'][$histo[$key]['elementtype']]) && isset($conf->cache['elementlinkcache'][$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
5859 $link = $conf->cache['elementlinkcache'][$histo[$key]['elementtype']][$histo[$key]['fk_element']];
5860 } else {
5861 if (!isset($conf->cache['elementlinkcache'][$histo[$key]['elementtype']])) {
5862 $conf->cache['elementlinkcache'][$histo[$key]['elementtype']] = array();
5863 }
5864 $link = dolGetElementUrl($histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
5865 $conf->cache['elementlinkcache'][$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
5866 }
5867
5868 // We do not show if link if on object we are filtering on (no need to show the link to ticket X when we are on page of events for the ticket X)
5869 $showlink = 1;
5870 if (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
5871 if ($histo[$key]['elementtype'] == 'ticket') {
5872 $showlink = 0;
5873 }
5874 }
5875
5876 if ($link && $showlink) {
5877 $out .= ' - ' . $link;
5878 }
5879 }
5880
5881 $out .= '</div>';
5882
5883 $out .= '</h3>';
5884
5885 // Message
5886 if ($actionstatic->code == 'AC_TICKET_CREATE') {
5887 $newmess = $filterobj->message;
5888 } else {
5889 $newmess = $histo[$key]['message'];
5890 }
5891 if (
5892 !empty($newmess && $newmess != $tmplabel)
5893 && $actionstatic->code != 'AC_TICKET_MODIFY'
5894 ) {
5895 $out .= '<div class="timeline-body wordbreak small">';
5896 $truncateLines = getDolGlobalInt('MAIN_TRUNCATE_TIMELINE_MESSAGE', 3);
5897 $truncatedText = dolGetFirstLineOfText($newmess, $truncateLines);
5898 // dolGetFirstLineOfText() cuts on <br> without caring about tag balance, so a message wrapped in
5899 // a block tag leaves the excerpt with an unclosed tag. The browser then nests the read more link
5900 // and the full text inside the excerpt, and hiding the excerpt hides the whole message (#39035).
5901 $truncatedText = dolCloseUnclosedHtmlTags($truncatedText);
5902 if ($truncateLines > 0 && strlen($newmess) > strlen($truncatedText)) {
5903 $out .= '<div class="readmore-block --closed" >';
5904 $out .= ' <div class="readmore-block__excerpt">';
5905 $out .= dolPrintHTML($truncatedText, 0, array('pre', 'code'));
5906 $out .= ' <br><a class="read-more-link" data-read-more-action="open" href="' . DOL_MAIN_URL_ROOT . '/comm/action/card.php?id=' . $actionstatic->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?' . $param) . '" >' . $langs->trans("ReadMore") . ' <span class="fa fa-chevron-right" aria-hidden="true"></span></a>';
5907 $out .= ' </div>';
5908 $out .= ' <div class="readmore-block__full-text" >';
5909
5910 $out .= dolPrintHTML($newmess, 0, array('pre', 'code'));
5911
5912 $out .= ' <a class="read-less-link" data-read-more-action="close" href="#" ><span class="fa fa-chevron-up" aria-hidden="true"></span> ' . $langs->trans("ReadLess") . '</a>';
5913 $out .= ' </div>';
5914 $out .= '</div>';
5915 } else {
5916 $out .= dolPrintHTML($newmess, 0, array('pre', 'code'));
5917 }
5918 $out .= '</div>';
5919 }
5920
5921 // Timeline footer
5922 $footer = '';
5923
5924 // Contact for this action
5925 if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
5926 $contactList = '';
5927 foreach ($histo[$key]['socpeopleassigned'] as $cid => $Tab) {
5928 if (empty($conf->cache['contact'][$cid])) {
5929 $contact = new Contact($db);
5930 $result = $contact->fetch($cid);
5931 $conf->cache['contact'][$cid] = $contact;
5932 } else {
5933 $contact = $conf->cache['contact'][$cid];
5934 $result = ($contact instanceof Contact) ? $contact->id : 0;
5935 }
5936
5937 if ($result > 0) {
5938 $contactList .= !empty($contactList) ? ', ' : '';
5939 $contactList .= $contact->getNomUrl(1);
5940 if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
5941 if (!empty($contact->phone_pro)) {
5942 $contactList .= '(' . dol_print_phone($contact->phone_pro) . ')';
5943 }
5944 }
5945 }
5946 }
5947
5948 $footer .= $langs->trans('ActionOnContact') . ' : ' . $contactList;
5949 } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
5950 if (empty($conf->cache['contact'][$histo[$key]['contact_id']])) {
5951 $contact = new Contact($db);
5952 $result = $contact->fetch($histo[$key]['contact_id']);
5953 $conf->cache['contact'][$histo[$key]['contact_id']] = $contact;
5954 } else {
5955 $contact = $conf->cache['contact'][$histo[$key]['contact_id']];
5956 $result = ($contact instanceof Contact) ? $contact->id : 0;
5957 }
5958
5959 if ($result > 0) {
5960 $footer .= $contact->getNomUrl(1);
5961 if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
5962 if (!empty($contact->phone_pro)) {
5963 $footer .= '(' . dol_print_phone($contact->phone_pro) . ')';
5964 }
5965 }
5966 }
5967 }
5968
5969 $documents = getActionCommEcmList($actionstatic);
5970 if (!empty($documents)) {
5971 $footer .= '<div class="timeline-documents-container">';
5972 foreach ($documents as $doc) {
5973 $footer .= '<span id="document_' . $doc->id . '" class="timeline-documents" ';
5974 $footer .= ' data-id="' . $doc->id . '" ';
5975 $footer .= ' data-path="' . $doc->filepath . '"';
5976 $footer .= ' data-filename="' . dol_escape_htmltag($doc->filename) . '" ';
5977 $footer .= '>';
5978
5979 $filePath = DOL_DATA_ROOT . '/' . $doc->filepath . '/' . $doc->filename;
5980 $mime = dol_mimetype($filePath);
5981 if (empty($doc->agenda_id)) {
5982 $dir_ref = $actionstatic->id;
5983 $modulepart = 'actions';
5984 } else {
5985 $split_dir = explode('/', $doc->filepath);
5986 $modulepart = array_shift($split_dir);
5987 $dir_ref = implode('/', $split_dir);
5988 }
5989
5990 $file = $dir_ref . '/' . $doc->filename;
5991 $thumb = $dir_ref . '/thumbs/' . substr($doc->filename, 0, strrpos($doc->filename, '.')) . '_mini' . substr($doc->filename, strrpos($doc->filename, '.'));
5992 $doclink = dol_buildpath('document.php', 1) . '?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode($file) . '&entity=' . $conf->entity;
5993 $viewlink = dol_buildpath('viewimage.php', 1) . '?modulepart=' . $modulepart . '&file=' . urlencode($thumb) . '&entity=' . $conf->entity;
5994
5995
5996
5997 $mimeAttr = ' mime="' . $mime . '" ';
5998 $class = '';
5999 if (in_array($mime, array('image/png', 'image/jpeg', 'application/pdf'))) {
6000 $class .= ' documentpreview';
6001 }
6002
6003 $footer .= '<a href="' . $doclink . '" class="btn-link ' . $class . '" target="_blank" rel="noopener noreferrer" ' . $mimeAttr . ' >';
6004 $footer .= img_mime($filePath) . ' ' . $doc->filename;
6005 $footer .= '</a>';
6006
6007 $footer .= '</span>';
6008 }
6009 $footer .= '</div>';
6010 }
6011
6012 if (!empty($footer)) {
6013 $out .= '<div class="timeline-footer">' . $footer . '</div>';
6014 }
6015
6016 $out .= '</div>' . "\n"; // end timeline-item
6017
6018 $out .= '</li>';
6019 $out .= '<!-- END timeline item -->';
6020 }
6021
6022 $out .= "</ul>\n";
6023
6024 // Code to manage the click on button data-read-more-action to show full description of an event
6025 $out .= '<script>
6026 jQuery(document).ready(function () {
6027 $(document).on("click", "[data-read-more-action]", function(e){
6028 console.log("We click on data-read-more-action");
6029 let readMoreBloc = $(this).closest(".readmore-block");
6030 if(readMoreBloc.length > 0){
6031 e.preventDefault();
6032 if($(this).attr("data-read-more-action") == "close"){
6033 readMoreBloc.addClass("--closed").removeClass("--open");
6034 $("html, body").animate({
6035 scrollTop: readMoreBloc.offset().top - 200
6036 }, 100);
6037 }else{
6038 readMoreBloc.addClass("--open").removeClass("--closed");
6039 }
6040 }
6041 });
6042 });
6043 </script>';
6044
6045
6046 if (empty($histo)) {
6047 $out .= '<span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span>';
6048 }
6049
6050 if ($num > $MAXWITHOUTPAGINATION) {
6051 $langs->load("errors");
6052 $out .= '<center><span class="opacitymedium">...' . $langs->trans("WarningTooManyDataPleaseUseMoreFilters", $MAXWITHOUTPAGINATION) . '...</span></center>';
6053 }
6054 }
6055
6056 if ($noprint) {
6057 return $out;
6058 } else {
6059 print $out;
6060 return null;
6061 }
6062}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:488
ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input=array(), $morecss='', $htmlname='', $forcenojs=0, $moreparam='', $readonly=0)
On/off button to change a property status of an object This uses the ajax service objectonoff....
Definition ajax.lib.php:827
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage agenda events (actions)
Class to manage different types of events.
Class to manage contact/addresses.
Class to manage building of HTML components.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert a PDF file into another image format.
dragAndDropFileUpload($htmlname)
Function to manage the drag and drop of a file.
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
dol_now($mode='gmt')
Return date for now.
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.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
dol_escape_uri($stringtoescape)
Returns text escaped by RFC 3986 for inclusion into a clickable link.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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).
dolCloseUnclosedHtmlTags($text)
Close the HTML tags left open in a truncated HTML string.
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.
getNonce()
Return a random string to be used as a nonce value for js.
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...
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external links.
getActionCommEcmList($object)
getActionCommEcmList
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
utf8_check($str)
Check if a string is in UTF8.
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_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
img_weather($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $morecss='')
Show weather picto.
finishSimpleTable($addLineBreak=false)
Add the correct HTML close tags for "startSimpleTable(...)" (use after the last table line)
show_actions_messaging($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC')
Show html area with actions in messaging format.
img_credit_card($brand, $morecss='fa-2x inline-block valignmiddle')
Return image of a credit card according to its brand name.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_right($titlealt='default', $selected=0, $moreatt='')
Show right arrow logo.
commonHtmlAttributeBuilder($attr, array $unescapedAttr=[])
Builds an array of safe and properly escaped HTML attributes from a key-value pair list.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
img_left($titlealt='default', $selected=0, $moreatt='')
Show left arrow logo.
getListOfHtmlBooleanAttributes()
Returns a list of HTML boolean attributes.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dolOutputDates($datep, $datef=null, $fullday=0, $addseconds=0, $pictotoadd='', $tzoutput='tzuserrel', $reduceformat=0)
Print decorated date-hour.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
getPictoForType($key, $morecss='')
Return the picto for a data type.
img_allow($allow, $titlealt='default')
Show tick logo if allowed.
dolButtonToOpenExportDialog($name, $label, $buttonstring, $exportSiteName, $overwriteGitUrl, $website)
Create a dialog with two buttons for export and overwrite of a website.
Definition html.lib.php:343
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
dolCompletUrlForDropdownButton(string $url, array $params, bool $addDolUrlRoot=true)
An function to complete dropdown url in dolGetButtonAction.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
img_picto_common($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $notitle=0)
Show picto (generic function)
img_search($titlealt='default', $other='')
Show search logo.
showTotalAmount($amount)
Style total amount of an object.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
fieldLabel($langkey, $fieldkey, $fieldrequired=0)
Show a string with the label tag dedicated to the HTML edit field.
img_printer($titlealt="default", $other='')
Show printer logo.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
getImgPictoConv($mode='fa')
Get array to convert the Dolibarr picto keys into Font awesome keys.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
img_split($titlealt='default', $other='class="pictosplit"')
Show split logo.
dol_print_error_email($prefixcode, $errormessage='', $errormessages=array(), $morecss='error', $email='')
Show a public email and error code to contact if technical error.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
img_next($titlealt='default', $moreatt='')
Show next logo.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
get_htmloutput_mesg($mesgstring='', $mesgarray=[], $style='ok', $keepembedded=0)
Get formatted messages to output (Used to show messages on html output).
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $selectlimitsuffix='', $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
addSummaryTableLine($tableColumnCount, $num, $nbofloop=0, $total=0, $noneWord="None", $extraRightColumn=false)
Add a summary line to the current open table ("None", "XMoreLines" or "Total xxx")
img_searchclear($titlealt='default', $other='')
Show search logo.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
startSimpleTable($header, $link="", $arguments="", $emptyColumns=0, $number=-1, $pictofulllist='')
Start a table with headers and a optional clickable number (don't forget to use "finishSimpleTable()"...
getFieldErrorIcon($fieldValidationErrorMsg)
get field error icon
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
treeview li table
No Email.