dolibarr 20.0.2
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 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/projet/class/taskstats.class.php';
30
31// Security check
32if (!$user->hasRight('projet', 'lire')) {
34}
35
36
39
40$userid = GETPOSTINT('userid');
41$socid = GETPOSTINT('socid');
42// Security check
43if ($user->socid > 0) {
44 $action = '';
45 $socid = $user->socid;
46}
47$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
48$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
49$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
50$endyear = $year;
51
52// Load translation files required by the page
53$langs->loadlangs(array('companies', 'projects'));
54
55
56/*
57 * View
58 */
59
60$form = new Form($db);
61
62$includeuserlist = array();
63
64
65llxHeader('', $langs->trans('Tasks'));
66
67$title = $langs->trans("TasksStatistics");
68$dir = $conf->project->dir_output.'/temp';
69
70print load_fiche_titre($title, '', 'projecttask');
71
72dol_mkdir($dir);
73
74
75$stats_tasks = new TaskStats($db);
76if (!empty($userid) && $userid != -1) {
77 $stats_tasks->userid = $userid;
78}
79if (!empty($socid) && $socid != -1) {
80 $stats_tasks->socid = $socid;
81}
82if (!empty($year)) {
83 $stats_tasks->year = $year;
84}
85
86
87
88// Build graphic number of object
89// $data = array(array('Lib',val1,val2,val3),...)
90$data = $stats_tasks->getNbByMonthWithPrevYear($endyear, $startyear);
91//var_dump($data);
92
93$filenamenb = $conf->project->dir_output."/stats/tasknbprevyear-".$year.".png";
94$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=taskstats&amp;file=tasknbprevyear-'.$year.'.png';
95
96$px1 = new DolGraph();
97$mesg = $px1->isGraphKo();
98if (!$mesg) {
99 $px1->SetData($data);
100 $i = $startyear;
101 $legend = array();
102 while ($i <= $endyear) {
103 $legend[] = $i;
104 $i++;
105 }
106 $px1->SetLegend($legend);
107 $px1->SetMaxValue($px1->GetCeilMaxValue());
108 $px1->SetWidth($WIDTH);
109 $px1->SetHeight($HEIGHT);
110 $px1->SetYLabel($langs->trans("ProjectNbTask"));
111 $px1->SetShading(3);
112 $px1->SetHorizTickIncrement(1);
113 $px1->mode = 'depth';
114 $px1->SetTitle($langs->trans("ProjectNbTaskByMonth"));
115
116 $px1->draw($filenamenb, $fileurlnb);
117}
118
119
120// Show array
121$stats_tasks->year = 0;
122$data_all_year = $stats_tasks->getAllByYear();
123
124if (!empty($year)) {
125 $stats_tasks->year = $year;
126}
127$arrayyears = array();
128foreach ($data_all_year as $val) {
129 $arrayyears[$val['year']] = $val['year'];
130}
131if (!count($arrayyears)) {
132 $arrayyears[$nowyear] = $nowyear;
133}
134
135
136$h = 0;
137$head = array();
138$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/stats/index.php';
139$head[$h][1] = $langs->trans("ByMonthYear");
140$head[$h][2] = 'byyear';
141$h++;
142
143complete_head_from_modules($conf, $langs, null, $head, $h, 'project_tasks_stats');
144
145print dol_get_fiche_head($head, 'byyear', '', -1, '');
146
147
148print '<div class="fichecenter"><div class="fichethirdleft">';
149
150print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
151print '<input type="hidden" name="token" value="'.newToken().'">';
152
153print '<table class="noborder centpercent">';
154print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
155// Company
156/*print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
157print $form->select_company($socid,'socid','',1,0,0,array(),0,'','style="width: 95%"');
158print '</td></tr>';
159*/
160// User
161/*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
162print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
163print '</td></tr>';*/
164// Year
165print '<tr><td>'.$langs->trans("Year").'</td><td>';
166if (!in_array($year, $arrayyears)) {
167 $arrayyears[$year] = $year;
168}
169if (!in_array($nowyear, $arrayyears)) {
170 $arrayyears[$nowyear] = $nowyear;
171}
172arsort($arrayyears);
173print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
174print '</td></tr>';
175print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
176print '</table>';
177
178print '</form>';
179
180print '<br><br>';
181
182
183print '<div class="div-table-responsive-no-min">';
184print '<table class="noborder centpercent">';
185print '<tr class="liste_titre">';
186print '<td>'.$langs->trans("Year").'</td>';
187print '<td class="right">'.$langs->trans("NbOfTasks").'</td>';
188print '</tr>';
189
190$oldyear = 0;
191foreach ($data_all_year as $val) {
192 $year = $val['year'];
193 while ($year && $oldyear > $year + 1) { // If we have empty year
194 $oldyear--;
195
196 print '<tr class="oddeven">';
197 print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
198 print '<td class="right">0</td>';
199 print '</tr>';
200 }
201
202 print '<tr class="oddeven">';
203 print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
204 print '<td class="right">'.$val['nb'].'</td>';
205 print '</tr>';
206 $oldyear = $year;
207}
208
209print '</table>';
210print '</div>';
211
212print '</div><div class="fichetwothirdright">';
213
214$stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
215if ($mesg) {
216 print $mesg;
217} else {
218 $stringtoshow .= $px1->show();
219 $stringtoshow .= "<br>\n";
220}
221$stringtoshow .= '</td></tr></table>';
222
223print $stringtoshow;
224
225
226print '</div></div>';
227
228print '<div class="clearboth"></div>';
229
230print dol_get_fiche_end();
231
232// End of page
233llxFooter();
234$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
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 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.