dolibarr 21.0.0-alpha
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 *
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 */
19
26// Load Dolibarr environment
27require '../../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/projet/class/taskstats.class.php';
31
32// Security check
33if (!$user->hasRight('projet', 'lire')) {
35}
36
37
40
41$userid = GETPOSTINT('userid');
42$socid = GETPOSTINT('socid');
43// Security check
44if ($user->socid > 0) {
45 $action = '';
46 $socid = $user->socid;
47}
48$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
49$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
50$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
51$endyear = $year;
52
53// Load translation files required by the page
54$langs->loadlangs(array('companies', 'projects'));
55
56
57/*
58 * View
59 */
60
61$form = new Form($db);
62
63$includeuserlist = array();
64
65
66llxHeader('', $langs->trans('Tasks'), '', '', 0, 0, '', '', '', 'mod-project project-tasks page-stats');
67
68$title = $langs->trans("TasksStatistics");
69$dir = $conf->project->dir_output.'/temp';
70
71print load_fiche_titre($title, '', 'projecttask');
72
73dol_mkdir($dir);
74
75
76$stats_tasks = new TaskStats($db);
77if (!empty($userid) && $userid != -1) {
78 $stats_tasks->userid = $userid;
79}
80if (!empty($socid) && $socid != -1) {
81 $stats_tasks->socid = $socid;
82}
83if (!empty($year)) {
84 $stats_tasks->year = $year;
85}
86
87
88
89// Build graphic number of object
90// $data = array(array('Lib',val1,val2,val3),...)
91$data = $stats_tasks->getNbByMonthWithPrevYear($endyear, $startyear);
92//var_dump($data);
93
94$filenamenb = $conf->project->dir_output."/stats/tasknbprevyear-".$year.".png";
95$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=taskstats&amp;file=tasknbprevyear-'.$year.'.png';
96
97$px1 = new DolGraph();
98$mesg = $px1->isGraphKo();
99if (!$mesg) {
100 $px1->SetData($data);
101 $i = $startyear;
102 $legend = array();
103 while ($i <= $endyear) {
104 $legend[] = $i;
105 $i++;
106 }
107 $px1->SetLegend($legend);
108 $px1->SetMaxValue($px1->GetCeilMaxValue());
109 $px1->SetWidth($WIDTH);
110 $px1->SetHeight($HEIGHT);
111 $px1->SetYLabel($langs->trans("ProjectNbTask"));
112 $px1->SetShading(3);
113 $px1->SetHorizTickIncrement(1);
114 $px1->mode = 'depth';
115 $px1->SetTitle($langs->trans("ProjectNbTaskByMonth"));
116
117 $px1->draw($filenamenb, $fileurlnb);
118}
119
120
121// Show array
122$stats_tasks->year = 0;
123$data_all_year = $stats_tasks->getAllByYear();
124
125if (!empty($year)) {
126 $stats_tasks->year = $year;
127}
128$arrayyears = array();
129foreach ($data_all_year as $val) {
130 $arrayyears[$val['year']] = $val['year'];
131}
132if (!count($arrayyears)) {
133 $arrayyears[$nowyear] = $nowyear;
134}
135
136
137$h = 0;
138$head = array();
139$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/stats/index.php';
140$head[$h][1] = $langs->trans("ByMonthYear");
141$head[$h][2] = 'byyear';
142$h++;
143
144complete_head_from_modules($conf, $langs, null, $head, $h, 'project_tasks_stats');
145
146print dol_get_fiche_head($head, 'byyear', '', -1, '');
147
148
149print '<div class="fichecenter"><div class="fichethirdleft">';
150
151print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
152print '<input type="hidden" name="token" value="'.newToken().'">';
153
154print '<table class="noborder centpercent">';
155print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
156// Company
157/*print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
158print $form->select_company($socid,'socid','',1,0,0,array(),0,'','style="width: 95%"');
159print '</td></tr>';
160*/
161// User
162/*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
163print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
164print '</td></tr>';*/
165// Year
166print '<tr><td>'.$langs->trans("Year").'</td><td>';
167if (!in_array($year, $arrayyears)) {
168 $arrayyears[$year] = $year;
169}
170if (!in_array($nowyear, $arrayyears)) {
171 $arrayyears[$nowyear] = $nowyear;
172}
173arsort($arrayyears);
174print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
175print '</td></tr>';
176print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
177print '</table>';
178
179print '</form>';
180
181print '<br><br>';
182
183
184print '<div class="div-table-responsive-no-min">';
185print '<table class="noborder centpercent">';
186print '<tr class="liste_titre">';
187print '<td>'.$langs->trans("Year").'</td>';
188print '<td class="right">'.$langs->trans("NbOfTasks").'</td>';
189print '</tr>';
190
191$oldyear = 0;
192foreach ($data_all_year as $val) {
193 $year = $val['year'];
194 while ($year && $oldyear > (int) $year + 1) { // If we have empty year
195 $oldyear--;
196
197 print '<tr class="oddeven">';
198 print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
199 print '<td class="right">0</td>';
200 print '</tr>';
201 }
202
203 print '<tr class="oddeven">';
204 print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
205 print '<td class="right">'.$val['nb'].'</td>';
206 print '</tr>';
207 $oldyear = $year;
208}
209
210print '</table>';
211print '</div>';
212
213print '</div><div class="fichetwothirdright">';
214
215$stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
216if ($mesg) {
217 print $mesg;
218} else {
219 $stringtoshow .= $px1->show();
220 $stringtoshow .= "<br>\n";
221}
222$stringtoshow .= '</td></tr></table>';
223
224print $stringtoshow;
225
226
227print '</div></div>';
228
229print '<div class="clearboth"></div>';
230
231print dol_get_fiche_end();
232
233// End of page
234llxFooter();
235$db->close();
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:70
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.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
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.