PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/frontend/php/stats/index.php

#
PHP | 395 lines | 250 code | 79 blank | 66 comment | 24 complexity | df81d2600f11e4e28132485553887ce0 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. # <one line to give a brief idea of what this does.>
  3. #
  4. # Copyright 2004-2006 (c) Mathieu Roy <yeupou--gnu.org>
  5. # Yves Perrin <yves.perrin--cern.ch>
  6. #
  7. # This file is part of Savane.
  8. #
  9. # Savane is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU Affero General Public License as
  11. # published by the Free Software Foundation, either version 3 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # Savane is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. # Later, this page will provide per group and per group type statistics.
  22. require_once('../include/init.php');
  23. require_once('../include/sane.php');
  24. require_once('../include/stats/general.php');
  25. require_once('../include/calendar.php');
  26. require_once('../include/graphs.php');
  27. register_globals_off();
  28. extract(sane_import('get',
  29. array('update', 'since_month', 'since_day', 'since_year',
  30. 'until_month', 'until_day', 'until_year')));
  31. site_header(array('title'=>"Statistics"));
  32. ######################## BETWEEN TWO DATES
  33. if (empty($update))
  34. {
  35. # Replace since_ and util_ parameters
  36. $since_month = date("m")-1;
  37. $since_day = date("d");
  38. $since_year = date("Y");
  39. $until_month = date("m");
  40. $until_day = date("d");
  41. $until_year = date("Y");
  42. $hour = date("H");
  43. $min = date("i");
  44. }
  45. else
  46. {
  47. # If the user selected date, assume he speaks of completed days
  48. $hour = 0;
  49. $min = 0;
  50. }
  51. $since = mktime($hour,$min,0,$since_month, $since_day, $since_year);
  52. $until = mktime($hour,$min,0,$until_month, $until_day, $until_year);
  53. $form_opening = '<form action="'.$_SERVER['PHP_SELF'].'#options" method="GET">';
  54. $form_submit = '<input class="bold" value="'._("Apply").'" name="update" type="submit" />';
  55. # I18N
  56. # The strings are two dates.
  57. # Example: "From 12. September 2005 till 14. September 2005"
  58. print html_show_displayoptions(sprintf(_("From %s till %s."),
  59. calendar_selectbox("day",$since_day,"since_day").calendar_selectbox("month",$since_month,"since_month").'<input type="text" value="'.addslashes($since_year).'" name="since_year" size="4" maxlength="4" />',
  60. calendar_selectbox("day",$until_day,"until_day").calendar_selectbox("month",$until_month,"until_month").'<input type="text" value="'.addslashes($until_year).'" name="until_year" size="4" maxlength="4" />'),
  61. $form_opening,
  62. $form_submit);
  63. print '
  64. <p><h3>'.html_anchor(sprintf(_("From %s till %s"),utils_format_date($since),utils_format_date($until)),"between").'</h3>';
  65. if ($since > $until)
  66. {
  67. print '<p class="error">'._("Apparently, the period you asked for is incoherent.").'</p>';
  68. }
  69. print '
  70. <h4>'._("Accounts:").'</h4>
  71. ';
  72. $count_users = stats_getusers();
  73. $count_groups = stats_getprojects();
  74. $content = array();
  75. $total = array();
  76. $count = stats_getusers("add_date>='$since' AND add_date<='$until'");
  77. $key = ngettext("New user", "New users", $count);
  78. $content[$key] = $count;
  79. $total[$key] = $count_users;
  80. print '&nbsp;&nbsp;- '.sprintf(ngettext("%s new user", "%s new users", $count),$count)."<br />\n";
  81. $count = stats_getprojects("","","register_time>='$since' AND register_time<='$until'");
  82. $key = ngettext("New group", "New groups", $count);
  83. $content[$key] = $count;
  84. $total[$key] = $count_groups;
  85. print '&nbsp;&nbsp;- '.sprintf(ngettext("%s new project", "%s new projects", $count),$count)."<br />\n";
  86. print '</p><p>'._("New users and new groups / total:");
  87. graphs_build($content,0,0,$total);
  88. $content = array();
  89. $total = 0;
  90. $total_patch = stats_getitems("patch");
  91. $total_task = stats_getitems("task");
  92. $total_bugs = stats_getitems("bugs");
  93. $total_support = stats_getitems("support");
  94. print '</p>
  95. <p><h4>'._("Trackers:").'</h4>
  96. ';
  97. ### FIXME: ngettext force us to split several sentences in different bit.
  98. ### It may be severily unsuitable for proper translation.
  99. $content = array();
  100. $content_total = array();
  101. $total_open = 0;
  102. if ($total_support > 0)
  103. {
  104. $count = stats_getitems("support", 0, "date>='$since' AND date<='$until'");
  105. $total = $count;
  106. $count_open = stats_getitems("support", 3, "date>='$since' AND date<='$until'");
  107. $total_open += $count_open;
  108. print '&nbsp;&nbsp;- '
  109. # I18N
  110. # Please note that the next two msgids are in fact one sentence. They are
  111. # always displayed together. The reason for the split is to allow translators
  112. # to be able to use the correct plural form in both cases. The function
  113. # ngettext() does not allow to use more than one variable per call, so the
  114. # call had to be split.
  115. # The second msgid is re-used a few times in this code, for bugs, tasks
  116. # and so on. All those sentences are equivalent to the one about support
  117. # requests, please translate those half-sentences accordingly.
  118. .sprintf(ngettext("%s new support request,", "%s new support requests,", $count), $count)." "
  119. .sprintf(ngettext("including %s already closed", "including %s already closed", $count_open), $count_open)."<br />\n";
  120. $key = ngettext("Support request", "Support requests", $count);
  121. $content[$key] = $count;
  122. $content_total[$key] = $total_support;
  123. }
  124. if ($total_bugs > 0)
  125. {
  126. $count = stats_getitems("bugs", 0, "date>='$since' AND date<='$until'");
  127. $total += $count;
  128. $count_open = stats_getitems("bugs", 3, "date>='$since' AND date<='$until'");
  129. $total_open += $count_open;
  130. print '&nbsp;&nbsp;- '
  131. # I18N
  132. # This is to be used with "including %s already closed", see above
  133. .sprintf(ngettext("%s new bug,", "%s new bugs,", $count), $count)." "
  134. .sprintf(ngettext("including %s already closed", "including %s already closed", $count_open), $count_open)."<br />\n";
  135. $key = ngettext("Bug", "Bugs", $count);
  136. $content[$key] = $count;
  137. $content_total[$key] = $total_bugs;
  138. }
  139. if ($total_task > 0)
  140. {
  141. $count = stats_getitems("task", 0, "date>='$since' AND date<='$until'");
  142. $total += $count;
  143. $count_open = stats_getitems("task", 3, "date>='$since' AND date<='$until'");
  144. $total_open += $count_open;
  145. print '&nbsp;&nbsp;- '
  146. # I18N
  147. # This is to be used with "including %s already closed", see above
  148. .sprintf(ngettext("%s new task,", "%s new tasks,", $count), $count)." "
  149. .sprintf(ngettext("including %s already closed", "including %s already closed", $count_open), $count_open)."<br />\n";
  150. $key = ngettext("Task", "Tasks", $count);
  151. $content[$key] = $count;
  152. $content_total[$key] = $total_task;
  153. }
  154. if ($total_patch > 0)
  155. {
  156. $count = stats_getitems("patch", 0, "date>='$since' AND date<='$until'");
  157. $total += $count;
  158. $count_open = stats_getitems("patch", 3, "date>='$since' AND date<='$until'");
  159. $total_open += $count_open;
  160. print '&nbsp;&nbsp;- '
  161. # I18N
  162. # This is to be used with "including %s already closed", see above
  163. .sprintf(ngettext("%s new patch,", "%s new patches,", $count), $count)." "
  164. .sprintf(ngettext("including %s already closed", "including %s already closed", $count_open), $count_open)."<br />\n";
  165. $key = ngettext("Patch", "Patches", $count);
  166. $content[$key] = $count;
  167. $content_total[$key] = $total_patch;
  168. }
  169. if ($total_patch < 1 && $total_task < 1 && $total_support < 1 && $total_bugs < 1)
  170. {
  171. print _("The trackers looks unused, no items were found");
  172. }
  173. else
  174. {
  175. print "<br />\n&nbsp;&nbsp;- "
  176. # I18N
  177. # This is to be used with "including %s already closed", see above
  178. .sprintf(ngettext("%s new item,", "%s new items,", $total), $total)." "
  179. .sprintf(ngettext("including %s already closed", "including %s already closed", $total_open), $total_open)."<br />\n";
  180. print '</p><p>'._("New items per tracker / tracker total:");
  181. graphs_build($content,0,0,$content_total);
  182. unset($content,$content_total);
  183. }
  184. print "</p>\n";
  185. print '<p>&nbsp;</p>';
  186. ##################### GENERAL
  187. print '
  188. <p><h3>'.html_anchor(_("Overall"),"overall").'</h3>';
  189. print '
  190. <h4>'._("Accounts:").'</h4>
  191. ';
  192. $content = array();
  193. #print _("Are listed only active accounts.");
  194. print '&nbsp;&nbsp;- '.sprintf(ngettext("%s user", "%s users", $count_users), $count_users)."<br />\n";
  195. $count_groups_private = stats_getprojects("","0");
  196. print '&nbsp;&nbsp;- '
  197. # I18N
  198. # This is to be used with "including %s in private state", see above
  199. .sprintf(ngettext("%s project,", "%s projects,", $count_groups), $count_groups)." "
  200. .sprintf(ngettext("including %s in private state", "including %s in private state", $count_groups_private), $count_groups_private)."<br />\n";
  201. $result = db_query("SELECT type_id,name FROM group_type ORDER BY name");
  202. while ($eachtype = db_fetch_array($result))
  203. {
  204. $content[$eachtype['name']] = stats_getprojects($eachtype['type_id']);
  205. }
  206. print '</p><p>'._("Projects per group type:");
  207. graphs_build($content,0,0);
  208. unset($content);
  209. print '</p>
  210. <p><h4>'._("Trackers:").'</h4>
  211. ';
  212. $content = array();
  213. $count = $total_support;
  214. $total = $count;
  215. $total_open = 0;
  216. if ($count > 0)
  217. {
  218. $count_open = stats_getitems("support", 1);
  219. $total_open += $count_open;
  220. print '&nbsp;&nbsp;- '
  221. # I18N
  222. # This is to be used with "including %s still open", see above
  223. .sprintf(ngettext("%s support request,", "%s support requests,", $count), $count)." "
  224. .sprintf(ngettext("including %s still open", "including %s still open", $count_open), $count_open)."<br />\n";
  225. $content[ngettext("Support request", "Support requests", $count)] = $count;
  226. }
  227. $count = $total_bugs;
  228. $total += $count;
  229. if ($count > 0)
  230. {
  231. $count_open = stats_getitems("bugs", 1);
  232. $total_open += $count_open;
  233. print '&nbsp;&nbsp;- '
  234. # I18N
  235. # This is to be used with "including %s still open", see above
  236. .sprintf(ngettext("%s bug,", "%s bugs,", $count), $count)." "
  237. .sprintf(ngettext("including %s still open", "including %s still open", $count_open), $count_open)."<br />\n";
  238. $content[ngettext("Bug", "Bugs", $count)] = $count;
  239. }
  240. $count = $total_task;
  241. $total += $count;
  242. if ($count > 0)
  243. {
  244. $count_open = stats_getitems("task", 1);
  245. $total_open += $count_open;
  246. print '&nbsp;&nbsp;- '
  247. # I18N
  248. # This is to be used with "including %s still open", see above
  249. .sprintf(ngettext("%s task,", "%s tasks,", $count), $count)." "
  250. .sprintf(ngettext("including %s still open", "including %s still open", $count_open), $count_open)."<br />\n";
  251. $content[ngettext("Task", "Tasks", $count)] = $count;
  252. }
  253. $count = $total_patch;
  254. $total += $count;
  255. if ($count > 0)
  256. {
  257. $count_open = stats_getitems("patch", 1);
  258. $total_open += $count_open;
  259. print '&nbsp;&nbsp;- '
  260. # I18N
  261. # This is to be used with "including %s still open", see above
  262. .sprintf(ngettext("%s patch,", "%s patches,", $count), $count)." "
  263. .sprintf(ngettext("including %s still open", "including %s still open", $count_open), $count_open)."<br />\n";
  264. $content[ngettext("Patch", "Patches", $count)] = $count;
  265. }
  266. print "<br />\n&nbsp;&nbsp;- "
  267. # I18N
  268. # This is to be used with "including %s still open", see above
  269. .sprintf(ngettext("%s item,", "%s items,", $total), $total)." "
  270. .sprintf(ngettext("including %s still open", "including %s still open", $total_open), $total_open)."<br />\n";
  271. print '</p><p>'._("Items per tracker:");
  272. graphs_build($content,0,0);
  273. unset($content);
  274. print '</p>
  275. <p><h4>'._("Themes:").'</h4>
  276. ';
  277. # Get the more popular themes. 7 at most, all superior to 0%
  278. $themes_list = theme_list();
  279. $popular_themes = array();
  280. // Check if there's already at least one user registered
  281. if ($count_users)
  282. {
  283. while (list(,$theme) = each($themes_list))
  284. {
  285. // Get the number of users of the theme
  286. unset($count);
  287. $count = stats_getthemeusers(strtolower($theme));
  288. if (strtolower($theme) == strtolower($GLOBALS['sys_themedefault']))
  289. {
  290. // If it is the default theme, add the users that use the default
  291. $count += stats_getthemeusers("");
  292. }
  293. // Compute the percentage of users using it
  294. $percent = ($count / $count_users) * 100;
  295. // Store it only if superior to 0
  296. if (round($percent))
  297. {
  298. $popular_themes[$theme] = $percent;
  299. }
  300. }
  301. // Print the most popular theme
  302. arsort($popular_themes);
  303. $themes = '';
  304. while (list($theme,$percent) = each($popular_themes))
  305. {
  306. if ($themes)
  307. { $themes .= ", "; }
  308. $themes .= sprintf(_("%s (%s%%)"), $theme, round($percent));
  309. }
  310. print sprintf(_("Most popular color themes are: %s."), $themes);
  311. } else {
  312. print _('No users yet.');
  313. }
  314. print '
  315. </p>';
  316. site_footer(0);