index.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. * \file htdocs/projet/tasks/stats/index.php
  20. * \ingroup project
  21. * \brief Page for tasks statistics
  22. */
  23. // Load Dolibarr environment
  24. require '../../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/projet/class/taskstats.class.php';
  28. // Security check
  29. if (!$user->hasRight('projet', 'lire')) {
  30. accessforbidden();
  31. }
  32. $WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
  33. $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
  34. $userid = GETPOST('userid', 'int');
  35. $socid = GETPOST('socid', 'int');
  36. // Security check
  37. if ($user->socid > 0) {
  38. $action = '';
  39. $socid = $user->socid;
  40. }
  41. $nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
  42. $year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
  43. $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
  44. $endyear = $year;
  45. // Load translation files required by the page
  46. $langs->loadlangs(array('companies', 'projects'));
  47. /*
  48. * View
  49. */
  50. $form = new Form($db);
  51. $includeuserlist = array();
  52. llxHeader('', $langs->trans('Tasks'));
  53. $title = $langs->trans("TasksStatistics");
  54. $dir = $conf->project->dir_output.'/temp';
  55. print load_fiche_titre($title, '', 'projecttask');
  56. dol_mkdir($dir);
  57. $stats_tasks = new TaskStats($db);
  58. if (!empty($userid) && $userid != -1) {
  59. $stats_tasks->userid = $userid;
  60. }
  61. if (!empty($socid) && $socid != -1) {
  62. $stats_tasks->socid = $socid;
  63. }
  64. if (!empty($year)) {
  65. $stats_tasks->year = $year;
  66. }
  67. // Build graphic number of object
  68. // $data = array(array('Lib',val1,val2,val3),...)
  69. $data = $stats_tasks->getNbByMonthWithPrevYear($endyear, $startyear);
  70. //var_dump($data);
  71. $filenamenb = $conf->project->dir_output."/stats/tasknbprevyear-".$year.".png";
  72. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=taskstats&amp;file=tasknbprevyear-'.$year.'.png';
  73. $px1 = new DolGraph();
  74. $mesg = $px1->isGraphKo();
  75. if (!$mesg) {
  76. $px1->SetData($data);
  77. $i = $startyear; $legend = array();
  78. while ($i <= $endyear) {
  79. $legend[] = $i;
  80. $i++;
  81. }
  82. $px1->SetLegend($legend);
  83. $px1->SetMaxValue($px1->GetCeilMaxValue());
  84. $px1->SetWidth($WIDTH);
  85. $px1->SetHeight($HEIGHT);
  86. $px1->SetYLabel($langs->trans("ProjectNbTask"));
  87. $px1->SetShading(3);
  88. $px1->SetHorizTickIncrement(1);
  89. $px1->mode = 'depth';
  90. $px1->SetTitle($langs->trans("ProjectNbTaskByMonth"));
  91. $px1->draw($filenamenb, $fileurlnb);
  92. }
  93. // Show array
  94. $stats_tasks->year = 0;
  95. $data_all_year = $stats_tasks->getAllByYear();
  96. if (!empty($year)) {
  97. $stats_tasks->year = $year;
  98. }
  99. $arrayyears = array();
  100. foreach ($data_all_year as $val) {
  101. $arrayyears[$val['year']] = $val['year'];
  102. }
  103. if (!count($arrayyears)) {
  104. $arrayyears[$nowyear] = $nowyear;
  105. }
  106. $h = 0;
  107. $head = array();
  108. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/stats/index.php';
  109. $head[$h][1] = $langs->trans("ByMonthYear");
  110. $head[$h][2] = 'byyear';
  111. $h++;
  112. complete_head_from_modules($conf, $langs, null, $head, $h, 'project_tasks_stats');
  113. print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1, '');
  114. print '<div class="fichecenter"><div class="fichethirdleft">';
  115. print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  116. print '<input type="hidden" name="token" value="'.newToken().'">';
  117. print '<table class="noborder centpercent">';
  118. print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
  119. // Company
  120. /*print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  121. print $form->select_company($socid,'socid','',1,0,0,array(),0,'','style="width: 95%"');
  122. print '</td></tr>';
  123. */
  124. // User
  125. /*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
  126. print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
  127. print '</td></tr>';*/
  128. // Year
  129. print '<tr><td>'.$langs->trans("Year").'</td><td>';
  130. if (!in_array($year, $arrayyears)) {
  131. $arrayyears[$year] = $year;
  132. }
  133. if (!in_array($nowyear, $arrayyears)) {
  134. $arrayyears[$nowyear] = $nowyear;
  135. }
  136. arsort($arrayyears);
  137. print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
  138. print '</td></tr>';
  139. print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
  140. print '</table>';
  141. print '</form>';
  142. print '<br><br>';
  143. print '<div class="div-table-responsive-no-min">';
  144. print '<table class="noborder centpercent">';
  145. print '<tr class="liste_titre">';
  146. print '<td>'.$langs->trans("Year").'</td>';
  147. print '<td class="right">'.$langs->trans("NbOfTasks").'</td>';
  148. print '</tr>';
  149. $oldyear = 0;
  150. foreach ($data_all_year as $val) {
  151. $year = $val['year'];
  152. while ($year && $oldyear > $year + 1) { // If we have empty year
  153. $oldyear--;
  154. print '<tr class="oddeven">';
  155. print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
  156. print '<td class="right">0</td>';
  157. print '</tr>';
  158. }
  159. print '<tr class="oddeven">';
  160. print '<td><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
  161. print '<td class="right">'.$val['nb'].'</td>';
  162. print '</tr>';
  163. $oldyear = $year;
  164. }
  165. print '</table>';
  166. print '</div>';
  167. print '</div><div class="fichetwothirdright">';
  168. $stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
  169. if ($mesg) {
  170. print $mesg;
  171. } else {
  172. $stringtoshow .= $px1->show();
  173. $stringtoshow .= "<br>\n";
  174. }
  175. $stringtoshow .= '</td></tr></table>';
  176. print $stringtoshow;
  177. print '</div></div>';
  178. print '<div class="clearboth"></div>';
  179. print dol_get_fiche_end();
  180. // End of page
  181. llxFooter();
  182. $db->close();