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 19/** 20 * \file htdocs/projet/tasks/stats/index.php 21 * \ingroup project 22 * \brief Page for tasks statistics 23 */ 24 25require '../../../main.inc.php'; 26require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; 27require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; 28require_once DOL_DOCUMENT_ROOT.'/projet/class/taskstats.class.php'; 29 30// Security check 31if (!$user->rights->projet->lire) 32 accessforbidden(); 33 34 35$WIDTH = DolGraph::getDefaultGraphSizeForStats('width'); 36$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height'); 37 38$userid = GETPOST('userid', 'int'); 39$socid = GETPOST('socid', 'int'); 40// Security check 41if ($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 65llxHeader('', $langs->trans('Tasks')); 66 67$title = $langs->trans("TasksStatistics"); 68$dir = $conf->projet->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) $stats_tasks->userid = $userid; 77if (!empty($socid) && $socid != -1) $stats_tasks->socid = $socid; 78if (!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&file=tasknbprevyear-'.$year.'.png'; 89 90$px1 = new DolGraph(); 91$mesg = $px1->isGraphKo(); 92if (!$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 119if (!empty($year)) $stats_tasks->year = $year; 120$arrayyears = array(); 121foreach ($data_all_year as $val) { 122 $arrayyears[$val['year']] = $val['year']; 123} 124if (!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 134complete_head_from_modules($conf, $langs, null, $head, $h, $type); 135 136print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1, ''); 137 138 139print '<div class="fichecenter"><div class="fichethirdleft">'; 140 141print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">'; 142print '<input type="hidden" name="token" value="'.newToken().'">'; 143 144print '<table class="noborder centpercent">'; 145print '<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>'; 148print $form->select_company($socid,'socid','',1,0,0,array(),0,'','style="width: 95%"'); 149print '</td></tr>'; 150*/ 151// User 152/*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>'; 153print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist); 154print '</td></tr>';*/ 155// Year 156print '<tr><td>'.$langs->trans("Year").'</td><td>'; 157if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year; 158if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear; 159arsort($arrayyears); 160print $form->selectarray('year', $arrayyears, $year, 0); 161print '</td></tr>'; 162print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>'; 163print '</table>'; 164print '</form>'; 165print '<br><br>'; 166 167 168print '<div class="div-table-responsive-no-min">'; 169print '<table class="noborder centpercent">'; 170print '<tr class="liste_titre" height="24">'; 171print '<td>'.$langs->trans("Year").'</td>'; 172print '<td class="right">'.$langs->trans("NbOfTasks").'</td>'; 173print '</tr>'; 174 175$oldyear = 0; 176foreach ($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.'&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.'&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 196print '</table>'; 197print '</div>'; 198 199print '</div><div class="fichetwothirdright"><div class="ficheaddleft">'; 200 201$stringtoshow .= '<table class="border centpercent"><tr class="pair nohover"><td class="center">'; 202if ($mesg) { print $mesg; } else { 203 $stringtoshow .= $px1->show(); 204 $stringtoshow .= "<br>\n"; 205} 206$stringtoshow .= '</td></tr></table>'; 207 208print $stringtoshow; 209 210 211print '</div></div></div>'; 212print '<div style="clear:both"></div>'; 213 214// End of page 215llxFooter(); 216$db->close(); 217