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