dolibarr  16.0.5
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 require '../../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/projet/class/taskstats.class.php';
29 
30 // Security check
31 if (!$user->rights->projet->lire) {
33 }
34 
35 
37 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
38 
39 $userid = GETPOST('userid', 'int');
40 $socid = GETPOST('socid', 'int');
41 // Security check
42 if ($user->socid > 0) {
43  $action = '';
44  $socid = $user->socid;
45 }
46 $nowyear = strftime("%Y", dol_now());
47 $year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
48 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
49 $endyear = $year;
50 
51 // Load translation files required by the page
52 $langs->loadlangs(array('companies', 'projects'));
53 
54 
55 /*
56  * View
57  */
58 
59 $form = new Form($db);
60 
61 $includeuserlist = array();
62 
63 
64 llxHeader('', $langs->trans('Tasks'));
65 
66 $title = $langs->trans("TasksStatistics");
67 $dir = $conf->project->dir_output.'/temp';
68 
69 print load_fiche_titre($title, '', 'projecttask');
70 
71 dol_mkdir($dir);
72 
73 
74 $stats_tasks = new TaskStats($db);
75 if (!empty($userid) && $userid != -1) {
76  $stats_tasks->userid = $userid;
77 }
78 if (!empty($socid) && $socid != -1) {
79  $stats_tasks->socid = $socid;
80 }
81 if (!empty($year)) {
82  $stats_tasks->year = $year;
83 }
84 
85 
86 
87 // Build graphic number of object
88 // $data = array(array('Lib',val1,val2,val3),...)
89 $data = $stats_tasks->getNbByMonthWithPrevYear($endyear, $startyear);
90 //var_dump($data);
91 
92 $filenamenb = $conf->project->dir_output."/stats/tasknbprevyear-".$year.".png";
93 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=taskstats&amp;file=tasknbprevyear-'.$year.'.png';
94 
95 $px1 = new DolGraph();
96 $mesg = $px1->isGraphKo();
97 if (!$mesg) {
98  $px1->SetData($data);
99  $i = $startyear; $legend = array();
100  while ($i <= $endyear) {
101  $legend[] = $i;
102  $i++;
103  }
104  $px1->SetLegend($legend);
105  $px1->SetMaxValue($px1->GetCeilMaxValue());
106  $px1->SetWidth($WIDTH);
107  $px1->SetHeight($HEIGHT);
108  $px1->SetYLabel($langs->trans("ProjectNbTask"));
109  $px1->SetShading(3);
110  $px1->SetHorizTickIncrement(1);
111  $px1->mode = 'depth';
112  $px1->SetTitle($langs->trans("ProjectNbTaskByMonth"));
113 
114  $px1->draw($filenamenb, $fileurlnb);
115 }
116 
117 
118 // Show array
119 $stats_tasks->year = 0;
120 $data_all_year = $stats_tasks->getAllByYear();
121 
122 if (!empty($year)) {
123  $stats_tasks->year = $year;
124 }
125 $arrayyears = array();
126 foreach ($data_all_year as $val) {
127  $arrayyears[$val['year']] = $val['year'];
128 }
129 if (!count($arrayyears)) {
130  $arrayyears[$nowyear] = $nowyear;
131 }
132 
133 
134 $h = 0;
135 $head = array();
136 $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/stats/index.php';
137 $head[$h][1] = $langs->trans("ByMonthYear");
138 $head[$h][2] = 'byyear';
139 $h++;
140 
141 complete_head_from_modules($conf, $langs, null, $head, $h, 'project_tasks_stats');
142 
143 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1, '');
144 
145 
146 print '<div class="fichecenter"><div class="fichethirdleft">';
147 
148 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
149 print '<input type="hidden" name="token" value="'.newToken().'">';
150 
151 print '<table class="noborder centpercent">';
152 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
153 // Company
154 /*print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
155 print $form->select_company($socid,'socid','',1,0,0,array(),0,'','style="width: 95%"');
156 print '</td></tr>';
157 */
158 // User
159 /*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
160 print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
161 print '</td></tr>';*/
162 // Year
163 print '<tr><td>'.$langs->trans("Year").'</td><td>';
164 if (!in_array($year, $arrayyears)) {
165  $arrayyears[$year] = $year;
166 }
167 if (!in_array($nowyear, $arrayyears)) {
168  $arrayyears[$nowyear] = $nowyear;
169 }
170 arsort($arrayyears);
171 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
172 print '</td></tr>';
173 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
174 print '</table>';
175 
176 print '</form>';
177 
178 print '<br><br>';
179 
180 
181 print '<div class="div-table-responsive-no-min">';
182 print '<table class="noborder centpercent">';
183 print '<tr class="liste_titre">';
184 print '<td>'.$langs->trans("Year").'</td>';
185 print '<td class="right">'.$langs->trans("NbOfTasks").'</td>';
186 print '</tr>';
187 
188 $oldyear = 0;
189 foreach ($data_all_year as $val) {
190  $year = $val['year'];
191  while ($year && $oldyear > $year + 1) { // If we have empty year
192  $oldyear--;
193 
194  print '<tr class="oddeven">';
195  print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
196  print '<td class="right">0</td>';
197  print '</tr>';
198  }
199 
200  print '<tr class="oddeven">';
201  print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
202  print '<td class="right">'.$val['nb'].'</td>';
203  print '</tr>';
204  $oldyear = $year;
205 }
206 
207 print '</table>';
208 print '</div>';
209 
210 print '</div><div class="fichetwothirdright">';
211 
212 $stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
213 if ($mesg) {
214  print $mesg;
215 } else {
216  $stringtoshow .= $px1->show();
217  $stringtoshow .= "<br>\n";
218 }
219 $stringtoshow .= '</td></tr></table>';
220 
221 print $stringtoshow;
222 
223 
224 print '</div></div>';
225 
226 print '<div style="clear:both"></div>';
227 
228 print dol_get_fiche_end();
229 
230 // End of page
231 llxFooter();
232 $db->close();
DolGraph\getDefaultGraphSizeForStats
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Definition: dolgraph.class.php:1539
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
TaskStats
Class to manage statistics on project tasks.
Definition: taskstats.class.php:25
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603