dolibarr 18.0.6
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->rights->projet->lire) {
34}
35
36
39
40$userid = GETPOST('userid', 'int');
41$socid = GETPOST('socid', 'int');
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 = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
49$startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->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; $legend = array();
101 while ($i <= $endyear) {
102 $legend[] = $i;
103 $i++;
104 }
105 $px1->SetLegend($legend);
106 $px1->SetMaxValue($px1->GetCeilMaxValue());
107 $px1->SetWidth($WIDTH);
108 $px1->SetHeight($HEIGHT);
109 $px1->SetYLabel($langs->trans("ProjectNbTask"));
110 $px1->SetShading(3);
111 $px1->SetHorizTickIncrement(1);
112 $px1->mode = 'depth';
113 $px1->SetTitle($langs->trans("ProjectNbTaskByMonth"));
114
115 $px1->draw($filenamenb, $fileurlnb);
116}
117
118
119// Show array
120$stats_tasks->year = 0;
121$data_all_year = $stats_tasks->getAllByYear();
122
123if (!empty($year)) {
124 $stats_tasks->year = $year;
125}
126$arrayyears = array();
127foreach ($data_all_year as $val) {
128 $arrayyears[$val['year']] = $val['year'];
129}
130if (!count($arrayyears)) {
131 $arrayyears[$nowyear] = $nowyear;
132}
133
134
135$h = 0;
136$head = array();
137$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/stats/index.php';
138$head[$h][1] = $langs->trans("ByMonthYear");
139$head[$h][2] = 'byyear';
140$h++;
141
142complete_head_from_modules($conf, $langs, null, $head, $h, 'project_tasks_stats');
143
144print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1, '');
145
146
147print '<div class="fichecenter"><div class="fichethirdleft">';
148
149print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
150print '<input type="hidden" name="token" value="'.newToken().'">';
151
152print '<table class="noborder centpercent">';
153print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
154// Company
155/*print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
156print $form->select_company($socid,'socid','',1,0,0,array(),0,'','style="width: 95%"');
157print '</td></tr>';
158*/
159// User
160/*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
161print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
162print '</td></tr>';*/
163// Year
164print '<tr><td>'.$langs->trans("Year").'</td><td>';
165if (!in_array($year, $arrayyears)) {
166 $arrayyears[$year] = $year;
167}
168if (!in_array($nowyear, $arrayyears)) {
169 $arrayyears[$nowyear] = $nowyear;
170}
171arsort($arrayyears);
172print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
173print '</td></tr>';
174print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
175print '</table>';
176
177print '</form>';
178
179print '<br><br>';
180
181
182print '<div class="div-table-responsive-no-min">';
183print '<table class="noborder centpercent">';
184print '<tr class="liste_titre">';
185print '<td>'.$langs->trans("Year").'</td>';
186print '<td class="right">'.$langs->trans("NbOfTasks").'</td>';
187print '</tr>';
188
189$oldyear = 0;
190foreach ($data_all_year as $val) {
191 $year = $val['year'];
192 while ($year && $oldyear > $year + 1) { // If we have empty year
193 $oldyear--;
194
195 print '<tr class="oddeven">';
196 print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
197 print '<td class="right">0</td>';
198 print '</tr>';
199 }
200
201 print '<tr class="oddeven">';
202 print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
203 print '<td class="right">'.$val['nb'].'</td>';
204 print '</tr>';
205 $oldyear = $year;
206}
207
208print '</table>';
209print '</div>';
210
211print '</div><div class="fichetwothirdright">';
212
213$stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
214if ($mesg) {
215 print $mesg;
216} else {
217 $stringtoshow .= $px1->show();
218 $stringtoshow .= "<br>\n";
219}
220$stringtoshow .= '</td></tr></table>';
221
222print $stringtoshow;
223
224
225print '</div></div>';
226
227print '<div class="clearboth"></div>';
228
229print dol_get_fiche_end();
230
231// End of page
232llxFooter();
233$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:56
llxFooter()
Empty footer.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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).
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.