dolibarr 24.0.0-beta
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2015 Florian HENRY <florian.henry@open-concept.pro>
3 * Copyright (C) 2015 Laurent Destailleur <ldestailleur@users.sourceforge.net>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/projet/class/taskstats.class.php';
32
41// Security check
42if (!$user->hasRight('projet', 'lire')) {
44}
45
46
49
50$mode = GETPOST('mode', 'alpha');
51
52$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'projectlist';
53
54$userid = GETPOSTINT('userid');
55$socid = GETPOSTINT('socid');
56// Security check
57if ($user->socid > 0) {
58 $action = '';
59 $socid = $user->socid;
60}
61$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
62$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
63$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
64$endyear = $year;
65
66// Load translation files required by the page
67$langs->loadlangs(array('companies', 'projects'));
68
69
70/*
71 * View
72 */
73
74$form = new Form($db);
75
76$includeuserlist = array();
77
78
79llxHeader('', $langs->trans('Tasks'), '', '', 0, 0, '', '', '', 'mod-project project-tasks page-stats');
80
81$title = $langs->trans("TasksStatistics");
82$dir = $conf->project->dir_output.'/temp';
83
84$page = 0;
85$sortfield = '';
86$sortorder = '';
87$massactionbutton = '';
88$num = 0;
89$nbtotalofrecords = $langs->trans("Statistics");
90$param = '';
91$limit = 0;
92
93$newcardbutton = '';
94
95$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/projet/tasks/list.php?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'common' ? 2 : 1), array('morecss' => 'reposition'));
96$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', DOL_URL_ROOT.'/projet/tasks/list.php?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
97$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.'/projet/tasks/stats/index.php?mode=statistics&contextpage='.$contextpage.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', 2, array('morecss' => 'reposition'));
98$newcardbutton .= dolGetButtonTitleSeparator();
99$newcardbutton .= dolGetButtonTitle($langs->trans('NewTask'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/tasks.php?action=create&backtopage='.urlencode(DOL_URL_ROOT.'/projet/tasks/list.php'), '', $user->hasRight('projet', 'creer'));
100
101
102// Show description of content
103$htmltooltip = '';
104if ($user->hasRight('projet', 'all', 'lire') && !$socid) {
105 $htmltooltip .= $langs->trans("TasksOnProjectsDesc");
106} else {
107 $htmltooltip .= $langs->trans("TasksOnProjectsPublicDesc");
108}
109
110print_barre_liste($form->textwithpicto($title, $htmltooltip), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'projecttask', 0, $newcardbutton, '', $limit, 0, 0, 1);
111
112dol_mkdir($dir);
113
114
115$stats_tasks = new TaskStats($db);
116if (!empty($userid) && $userid != -1) {
117 $stats_tasks->userid = $userid;
118}
119if (!empty($socid) && $socid != -1) {
120 $stats_tasks->socid = $socid;
121}
122if (!empty($year)) {
123 $stats_tasks->year = $year;
124}
125
126
127
128// Build graphic number of object
129// $data = array(array('Lib',val1,val2,val3),...)
130$data = $stats_tasks->getNbByMonthWithPrevYear($endyear, $startyear);
131//var_dump($data);
132
133$filenamenb = $conf->project->dir_output."/stats/tasknbprevyear-".$year.".png";
134$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=taskstats&amp;file=tasknbprevyear-'.$year.'.png';
135
136$px1 = new DolGraph();
137$mesg = $px1->isGraphKo();
138if (!$mesg) {
139 $px1->SetData($data);
140 $i = $startyear;
141 $legend = array();
142 while ($i <= $endyear) {
143 $legend[] = $i;
144 $i++;
145 }
146 $px1->SetLegend($legend);
147 $px1->SetMaxValue($px1->GetCeilMaxValue());
148 $px1->SetWidth($WIDTH);
149 $px1->SetHeight($HEIGHT);
150 $px1->SetYLabel($langs->trans("ProjectNbTask"));
151 $px1->SetShading(3);
152 $px1->SetHorizTickIncrement(1);
153 $px1->mode = 'depth';
154 $px1->SetTitle($langs->trans("ProjectNbTaskByMonth"));
155
156 $px1->draw($filenamenb, $fileurlnb);
157}
158
159
160// Show array
161$stats_tasks->year = 0;
162$data_all_year = $stats_tasks->getAllByYear();
163
164if (!empty($year)) {
165 $stats_tasks->year = $year;
166}
167$arrayyears = array();
168foreach ($data_all_year as $val) {
169 $arrayyears[$val['year']] = $val['year'];
170}
171if (!count($arrayyears)) {
172 $arrayyears[$nowyear] = $nowyear;
173}
174
175
176$h = 0;
177$head = array();
178$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/stats/index.php';
179$head[$h][1] = $langs->trans("ByMonthYear");
180$head[$h][2] = 'byyear';
181$h++;
182
183complete_head_from_modules($conf, $langs, null, $head, $h, 'project_tasks_stats');
184
185print dol_get_fiche_head($head, 'byyear', '', -1, '');
186
187
188print '<div class="fichecenter"><div class="fichethirdleft">';
189
190print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
191print '<input type="hidden" name="token" value="'.newToken().'">';
192
193print '<table class="noborder centpercent">';
194print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
195// Company
196/*print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
197print $form->select_company($socid,'socid','',1,0,0,array(),0,'','style="width: 95%"');
198print '</td></tr>';
199*/
200// User
201/*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
202print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
203print '</td></tr>';*/
204// Year
205print '<tr><td>'.$langs->trans("Year").'</td><td>';
206if (!in_array($year, $arrayyears)) {
207 $arrayyears[$year] = $year;
208}
209if (!in_array($nowyear, $arrayyears)) {
210 $arrayyears[$nowyear] = $nowyear;
211}
212arsort($arrayyears);
213print img_picto('', 'calendar', 'class="pictofixedwidth"');
214print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
215print '</td></tr>';
216print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
217print '</table>';
218
219print '</form>';
220
221print '<br><br>';
222
223
224print '<div class="div-table-responsive-no-min">';
225print '<table class="noborder centpercent">';
226print '<tr class="liste_titre">';
227print '<td>'.$langs->trans("Year").'</td>';
228print '<td class="right">'.$langs->trans("NbOfTasks").'</td>';
229print '</tr>';
230
231$oldyear = 0;
232foreach ($data_all_year as $val) {
233 $year = $val['year'];
234 while ($year && $oldyear > (int) $year + 1) { // If we have empty year
235 $oldyear--;
236
237 print '<tr class="oddeven">';
238 print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
239 print '<td class="right">0</td>';
240 print '</tr>';
241 }
242
243 print '<tr class="oddeven">';
244 print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
245 print '<td class="right">'.$val['nb'].'</td>';
246 print '</tr>';
247 $oldyear = $year;
248}
249
250print '</table>';
251print '</div>';
252
253print '</div><div class="fichetwothirdright">';
254
255$stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
256if ($mesg) {
257 print $mesg;
258} else {
259 $stringtoshow .= $px1->show();
260 $stringtoshow .= "<br>\n";
261}
262$stringtoshow .= '</td></tr></table>';
263
264print $stringtoshow;
265
266
267print '</div></div>';
268
269print '<div class="clearboth"></div>';
270
271print dol_get_fiche_end();
272
273// End of page
274llxFooter();
275$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage generation of HTML components Only common components must be here.
Class to manage statistics on project tasks.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
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='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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).
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.