dolibarr  13.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 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 
36 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
37 
38 $userid = GETPOST('userid', 'int');
39 $socid = GETPOST('socid', 'int');
40 // Security check
41 if ($user->socid > 0)
42 {
43  $action = '';
44  $socid = $user->socid;
45 }
46 $nowyear = strftime("%Y", dol_now());
47 $year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
48 //$startyear=$year-2;
49 $startyear = $year - 1;
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->projet->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) $stats_tasks->userid = $userid;
77 if (!empty($socid) && $socid != -1) $stats_tasks->socid = $socid;
78 if (!empty($year)) $stats_tasks->year = $year;
79 
80 
81 
82 // Build graphic number of object
83 // $data = array(array('Lib',val1,val2,val3),...)
84 $data = $stats_tasks->getNbByMonthWithPrevYear($endyear, $startyear);
85 //var_dump($data);
86 
87 $filenamenb = $conf->project->dir_output."/stats/tasknbprevyear-".$year.".png";
88 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=taskstats&amp;file=tasknbprevyear-'.$year.'.png';
89 
90 $px1 = new DolGraph();
91 $mesg = $px1->isGraphKo();
92 if (!$mesg)
93 {
94  $px1->SetData($data);
95  $i = $startyear; $legend = array();
96  while ($i <= $endyear)
97  {
98  $legend[] = $i;
99  $i++;
100  }
101  $px1->SetLegend($legend);
102  $px1->SetMaxValue($px1->GetCeilMaxValue());
103  $px1->SetWidth($WIDTH);
104  $px1->SetHeight($HEIGHT);
105  $px1->SetYLabel($langs->trans("ProjectNbTask"));
106  $px1->SetShading(3);
107  $px1->SetHorizTickIncrement(1);
108  $px1->mode = 'depth';
109  $px1->SetTitle($langs->trans("ProjectNbTaskByMonth"));
110 
111  $px1->draw($filenamenb, $fileurlnb);
112 }
113 
114 
115 // Show array
116 $stats_tasks->year = 0;
117 $data_all_year = $stats_tasks->getAllByYear();
118 
119 if (!empty($year)) $stats_tasks->year = $year;
120 $arrayyears = array();
121 foreach ($data_all_year as $val) {
122  $arrayyears[$val['year']] = $val['year'];
123 }
124 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
125 
126 
127 $h = 0;
128 $head = array();
129 $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/stats/index.php?mode='.$mode;
130 $head[$h][1] = $langs->trans("ByMonthYear");
131 $head[$h][2] = 'byyear';
132 $h++;
133 
134 complete_head_from_modules($conf, $langs, null, $head, $h, $type);
135 
136 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1, '');
137 
138 
139 print '<div class="fichecenter"><div class="fichethirdleft">';
140 
141 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
142 print '<input type="hidden" name="token" value="'.newToken().'">';
143 
144 print '<table class="noborder centpercent">';
145 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
146 // Company
147 /*print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
148 print $form->select_company($socid,'socid','',1,0,0,array(),0,'','style="width: 95%"');
149 print '</td></tr>';
150 */
151 // User
152 /*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
153 print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
154 print '</td></tr>';*/
155 // Year
156 print '<tr><td>'.$langs->trans("Year").'</td><td>';
157 if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
158 if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
159 arsort($arrayyears);
160 print $form->selectarray('year', $arrayyears, $year, 0);
161 print '</td></tr>';
162 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
163 print '</table>';
164 print '</form>';
165 print '<br><br>';
166 
167 
168 print '<div class="div-table-responsive-no-min">';
169 print '<table class="noborder centpercent">';
170 print '<tr class="liste_titre" height="24">';
171 print '<td>'.$langs->trans("Year").'</td>';
172 print '<td class="right">'.$langs->trans("NbOfTasks").'</td>';
173 print '</tr>';
174 
175 $oldyear = 0;
176 foreach ($data_all_year as $val)
177 {
178  $year = $val['year'];
179  while ($year && $oldyear > $year + 1)
180  { // If we have empty year
181  $oldyear--;
182 
183  print '<tr class="oddeven" height="24">';
184  print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
185  print '<td class="right">0</td>';
186  print '</tr>';
187  }
188 
189  print '<tr class="oddeven" height="24">';
190  print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
191  print '<td class="right">'.$val['nb'].'</td>';
192  print '</tr>';
193  $oldyear = $year;
194 }
195 
196 print '</table>';
197 print '</div>';
198 
199 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
200 
201 $stringtoshow .= '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
202 if ($mesg) { print $mesg; } else {
203  $stringtoshow .= $px1->show();
204  $stringtoshow .= "<br>\n";
205 }
206 $stringtoshow .= '</td></tr></table>';
207 
208 print $stringtoshow;
209 
210 
211 print '</div></div></div>';
212 print '<div style="clear:both"></div>';
213 
214 // End of page
215 llxFooter();
216 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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 ...
Class to manage statistics on project tasks.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)