dolibarr  17.0.4
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
26 require '../../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/projet/class/taskstats.class.php';
30 
31 // Security check
32 if (!$user->rights->projet->lire) {
34 }
35 
36 
38 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
39 
40 $userid = GETPOST('userid', 'int');
41 $socid = GETPOST('socid', 'int');
42 // Security check
43 if ($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 
65 llxHeader('', $langs->trans('Tasks'));
66 
67 $title = $langs->trans("TasksStatistics");
68 $dir = $conf->project->dir_output.'/temp';
69 
70 print load_fiche_titre($title, '', 'projecttask');
71 
72 dol_mkdir($dir);
73 
74 
75 $stats_tasks = new TaskStats($db);
76 if (!empty($userid) && $userid != -1) {
77  $stats_tasks->userid = $userid;
78 }
79 if (!empty($socid) && $socid != -1) {
80  $stats_tasks->socid = $socid;
81 }
82 if (!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();
98 if (!$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 
123 if (!empty($year)) {
124  $stats_tasks->year = $year;
125 }
126 $arrayyears = array();
127 foreach ($data_all_year as $val) {
128  $arrayyears[$val['year']] = $val['year'];
129 }
130 if (!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 
142 complete_head_from_modules($conf, $langs, null, $head, $h, 'project_tasks_stats');
143 
144 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1, '');
145 
146 
147 print '<div class="fichecenter"><div class="fichethirdleft">';
148 
149 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
150 print '<input type="hidden" name="token" value="'.newToken().'">';
151 
152 print '<table class="noborder centpercent">';
153 print '<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>';
156 print $form->select_company($socid,'socid','',1,0,0,array(),0,'','style="width: 95%"');
157 print '</td></tr>';
158 */
159 // User
160 /*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
161 print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
162 print '</td></tr>';*/
163 // Year
164 print '<tr><td>'.$langs->trans("Year").'</td><td>';
165 if (!in_array($year, $arrayyears)) {
166  $arrayyears[$year] = $year;
167 }
168 if (!in_array($nowyear, $arrayyears)) {
169  $arrayyears[$nowyear] = $nowyear;
170 }
171 arsort($arrayyears);
172 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
173 print '</td></tr>';
174 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
175 print '</table>';
176 
177 print '</form>';
178 
179 print '<br><br>';
180 
181 
182 print '<div class="div-table-responsive-no-min">';
183 print '<table class="noborder centpercent">';
184 print '<tr class="liste_titre">';
185 print '<td>'.$langs->trans("Year").'</td>';
186 print '<td class="right">'.$langs->trans("NbOfTasks").'</td>';
187 print '</tr>';
188 
189 $oldyear = 0;
190 foreach ($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 
208 print '</table>';
209 print '</div>';
210 
211 print '</div><div class="fichetwothirdright">';
212 
213 $stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
214 if ($mesg) {
215  print $mesg;
216 } else {
217  $stringtoshow .= $px1->show();
218  $stringtoshow .= "<br>\n";
219 }
220 $stringtoshow .= '</td></tr></table>';
221 
222 print $stringtoshow;
223 
224 
225 print '</div></div>';
226 
227 print '<div style="clear:both"></div>';
228 
229 print dol_get_fiche_end();
230 
231 // End of page
232 llxFooter();
233 $db->close();
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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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='')
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)
llxFooter()
Footer empty.
Definition: index.php:71
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
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.