dolibarr 25.0.0-alpha
dashboard.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 * or see https://www.gnu.org/
17 */
18
32{
33 global $conf; // Used by theme_vars.inc.php
34
35 $colors = array();
36
37 $theme_vars_file = dol_getThemeFilePath('theme_vars.inc.php');
38 if ($theme_vars_file) {
39 include $theme_vars_file;
40 }
41
42 foreach (get_defined_vars() as $name => $value) {
43 if (preg_match('/^badgeStatus(\w+)$/', $name, $reg) && is_string($value)) {
44 $colors[(is_numeric($reg[1]) ? (int) $reg[1] : $reg[1])] = $value;
45 }
46 }
47
48 return $colors;
49}
50
51
66function getStatusPieChart($title, $series, $options = array())
67{
68 global $conf, $langs;
69
70 $graphid = empty($options['graphid']) ? 'idgraphstatus' : $options['graphid'];
71 $height = isset($options['height']) ? $options['height'] : 200;
72 $showpercent = isset($options['showpercent']) ? $options['showpercent'] : 1;
73
74 $dataseries = array();
75 $colorseries = array();
76 $sum = 0;
77 $usecolors = true;
78 foreach ($series as $slice) {
79 $dataseries[] = array($slice['label'], $slice['nb']);
80 if (isset($slice['color'])) {
81 $colorseries[] = $slice['color'];
82 } else {
83 $usecolors = false;
84 }
85 $sum += $slice['nb'];
86 }
87
88 $total = array_key_exists('total', $options) ? $options['total'] : $sum;
89
90 $out = '<div class="div-table-responsive-no-min">';
91 $out .= '<table class="noborder nohover centpercent">';
92 $out .= '<tr class="liste_titre"><th colspan="2">'.$title.'</th></tr>'."\n";
93
94 if (!empty($conf->use_javascript_ajax)) {
95 $out .= '<tr><td class="center" colspan="2">';
96
97 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
98 $dolgraph = new DolGraph();
99 $dolgraph->SetData($dataseries);
100 if ($usecolors) {
101 $dolgraph->SetDataColor($colorseries);
102 }
103 $dolgraph->setShowLegend(2);
104 $dolgraph->setShowPercent($showpercent);
105 $dolgraph->SetType(array('pie'));
106 $dolgraph->SetHeight($height);
107 if (!empty($options['width'])) {
108 $dolgraph->SetWidth($options['width']);
109 }
110 $dolgraph->draw($graphid);
111 $out .= $dolgraph->show($sum ? 0 : 1);
112
113 $out .= '</td></tr>';
114 } else {
115 foreach ($series as $slice) {
116 $out .= '<tr class="oddeven">';
117 $out .= '<td>'.(isset($slice['labelnojs']) ? $slice['labelnojs'] : dol_escape_htmltag($slice['label'])).'</td>';
118 $out .= '<td class="right">';
119 if (!empty($slice['url'])) {
120 $out .= '<a href="'.dol_escape_htmltag($slice['url']).'">'.$slice['nb'].'</a>';
121 } else {
122 $out .= $slice['nb'];
123 }
124 $out .= '</td>';
125 $out .= '</tr>'."\n";
126 }
127 }
128
129 if ($total !== false) {
130 $out .= '<tr class="liste_total"><td>'.(empty($options['totallabel']) ? $langs->trans("Total") : $options['totallabel']).'</td><td class="right">'.$total.'</td></tr>';
131 }
132
133 $out .= '</table></div><br>';
134
135 return $out;
136}
Class to build graphs.
getThemeBadgeStatusColors()
Return the colors of status badges defined by the current theme (theme_vars.inc.php)
getStatusPieChart($title, $series, $options=array())
Return the HTML table with a pie chart of values by status, as shown on the home page of a module.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_getThemeFilePath($file, $theme='')
Return the full filesystem path of a file located in the currently selected theme directory.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181