00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: reporting.php 5365 2006-02-14 09:46:49Z toddy $
00006 #
00007 # Copyright 2001-2002 (c) Laurent Julliard, CodeX Team, Xerox
00008 #
00009 # Copyright 2002-2005 (c) Mathieu Roy <yeupou--gnu.org>
00010 # Yves Perrin <yves.perrin--cern.ch>
00011 #
00012 # The Savane project is free software; you can redistribute it and/or
00013 # modify it under the terms of the GNU General Public License
00014 # as published by the Free Software Foundation; either version 2
00015 # of the License, or (at your option) any later version.
00016 #
00017 # The Savane project is distributed in the hope that it will be useful,
00018 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 # GNU General Public License for more details.
00021 #
00022 # You should have received a copy of the GNU General Public License
00023 # along with the Savane project; if not, write to the Free Software
00024 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00025
00026
00027 if (!$group_id)
00028 { exit_no_group(); }
00029
00030 # Give access to this page to anybody: people can already collect such
00031 # information since they are able to browse the trackers.
00032 # It does not make sense to restrict access to this data, in this spirit.
00033 # But if some specific installation need to do so for whatever reason,
00034 # we can make that a configuration option.
00035
00036 trackers_header(array ("title"=>_("Statistics")));
00037
00038 # FIXME: work in progress. We need to study how to mix infos coming from
00039 # trackers_data_...()
00040 # If artifact is not defined, we want statistics of all trackers.
00041 if (ARTIFACT == "project")
00042 { $artifact = "bugs,task,patch,support"; }
00043 else
00044 { $artifact = ARTIFACT; }
00045
00046
00047 # Specific function that list possible report.
00048 function specific_reports_list ($thisfield=0)
00049 {
00050 global $group_id;
00051
00052 if ($thisfield)
00053 {
00054 print '<p> </p><h3>'._("Other statistics:").'</h3>';
00055 }
00056 print "<ul>\n";
00057
00058 if ($thisfield != 'aging')
00059 {
00060 print "<li><a href=\"reporting.php?group_id=$group_id&field=aging\">"._("Aging Statistics")."</a></li>\n";
00061 }
00062 while ($field = trackers_list_all_fields())
00063 {
00064
00065 if (trackers_data_is_special($field) || $field == $thisfield)
00066 { continue; }
00067
00068 if (trackers_data_is_select_box($field) && trackers_data_is_used($field))
00069 {
00070
00071 print "<li><a href=\"reporting.php?group_id=$group_id&field=$field\">";
00072 printf(_("Statistics by '%s'"), trackers_data_get_label($field));
00073 print "</a></li>\n";
00074 }
00075 }
00076
00077 print "</ul>\n";
00078 }
00079
00080 # Initialize the global data structure before anything else
00081 trackers_init($group_id);
00082
00083 if ($field)
00084 {
00085 if ($field == 'aging')
00086 {
00087 print '<h3>'._("Aging statistics:").'</h3>';
00088
00089 $time_now=time();
00090 unset($content);
00091
00092 for ($counter=1; $counter<=8; $counter++)
00093 {
00094
00095 $start=($time_now-($counter*604800));
00096 $end=($time_now-(($counter-1)*604800));
00097
00098 $sql="SELECT round(avg((close_date-date)/86400), 0) FROM ".$artifact." WHERE close_date > 0 AND (date >= $start AND date <= $end) AND group_id='$group_id'";
00099 $result = db_query($sql);
00100
00101 $key = sprintf(_("%s to %s"), format_date($sys_datefmt,($start)), format_date($sys_datefmt,($end)));
00102 $content[$key] = db_result($result, 0,0);
00103 }
00104
00105 print '<h5>'._("Average Turnaround Time For Closed Items").'</h5>';
00106 graphs_build($content,0,0);
00107 unset($content);
00108 print "<p> </p>";
00109
00110 for ($counter=1; $counter<=8; $counter++)
00111 {
00112
00113 $start=($time_now-($counter*604800));
00114 $end=($time_now-(($counter-1)*604800));
00115
00116 $sql="SELECT count(*) FROM ".$artifact." WHERE date >= $start AND date <= $end AND group_id='$group_id'";
00117 $result = db_query($sql);
00118
00119 $key = sprintf(_("%s to %s"), format_date($sys_datefmt,($start)), format_date($sys_datefmt,($end)));
00120 $content[$key] = db_result($result, 0,0);
00121 }
00122
00123 print '<h5>'._("Number of Items Opened").'</h5>';
00124 graphs_build($content,0,0);
00125 unset($content);
00126 print "<p> </p>";
00127
00128 for ($counter=1; $counter<=8; $counter++)
00129 {
00130
00131 $start=($time_now-($counter*604800));
00132 $end=($time_now-(($counter-1)*604800));
00133
00134 $sql="SELECT count(*) FROM ".$artifact." WHERE date <= $end AND (close_date >= $end OR close_date < 1 OR close_date is null) AND group_id='$group_id'";
00135 $result = db_query($sql);
00136
00137 $content[format_date($sys_datefmt,($end))] = db_result($result, 0,0);
00138 }
00139
00140 print "\n<h5>"._("Number of Items Still Open")."</h5>";
00141 graphs_build($content,0,0);
00142 unset($content);
00143 print "<p> </p>";
00144
00145 }
00146 else
00147 {
00148
00149 # It's any of the select box field.
00150 $label = trackers_data_get_label($field);
00151
00152 # Title + field description
00153 print '<h3>'.sprintf(_("Statistics by '%s':"), $label).'</h3>'.
00154 '<p><em>'._('Field Description:').'</em> '.trackers_data_get_description($field).'</p>';
00155
00156 # Make sure it is a correct field
00157 if (trackers_data_is_special($field) || !trackers_data_is_used($field) ||
00158 !trackers_data_is_select_box($field) )
00159 {
00160
00161 print '<p class="error">'.sprintf(_("Can't generate report for field %s"), $label).'</p>';
00162
00163 }
00164 else
00165 {
00166
00167 # First graph the bug distribution for Open item only.
00168 # Assigned to must be handle in a specific way.
00169 # Meaningless in case of status field.
00170
00171 if ($field != 'status_id')
00172 {
00173
00174 print "\n<h5>".sprintf(_("Open Items"), $label)."</h5>";
00175
00176 # First graph the bug distribution for Open item only.
00177 # Assigned to must be handle in a specific way.
00178
00179 if ($field == 'assigned_to')
00180 {
00181
00182 $sql="SELECT user.user_name, count(*) AS Count FROM user,".$artifact." ".
00183 "WHERE user.user_id=".$artifact.".assigned_to AND ".
00184 "".$artifact.".status_id = '1' AND ".$artifact.".group_id='$group_id' ".
00185 "GROUP BY user_name";
00186 }
00187 else
00188 {
00189
00190 # check if the project has its own instance of the
00191 # value set
00192
00193 $sql="SELECT ".$artifact."_field_value.value FROM "
00194 .$artifact."_field_value WHERE "
00195 .$artifact."_field_value.bug_field_id='". trackers_data_get_field_id($field)."' AND ". $artifact."_field_value.group_id='$group_id'";
00196
00197 $result=db_query($sql);
00198 if ($result && db_numrows($result) > 0) {
00199 $group_to_be_used = $group_id;
00200 } else {
00201 # the project does not have its own instance so
00202 # use the default one (group_id = '100')
00203 $group_to_be_used = 100;
00204 }
00205
00206 $sql="SELECT ".$artifact."_field_value.value, count(*) AS Count FROM ".$artifact."_field_value,".$artifact." ".
00207 "WHERE ".$artifact."_field_value.value_id=".$artifact.".$field AND ".
00208 "".$artifact."_field_value.bug_field_id='".
00209 trackers_data_get_field_id($field)."' AND ".
00210 $artifact."_field_value.group_id=$group_to_be_used AND ".
00211 "".$artifact.".status_id = '1' AND ".$artifact.".group_id='$group_id' ".
00212 "GROUP BY value_id";
00213 }
00214
00215 $result=db_query($sql);
00216 if ($result && db_numrows($result) > 0)
00217 { graphs_build($result, $field); }
00218 else
00219 { print _("No item found."); }
00220
00221
00222 print "<p> </p>";
00223
00224 }
00225
00226 #Second graph the bug distribution for all items
00227
00228 print "\n<h5>".sprintf(_("All Items"), $label)."</h5>";
00229
00230 if ($field == 'assigned_to')
00231 {
00232
00233 $sql="SELECT user.user_name, count(*) AS Count FROM user,".$artifact." ".
00234 "WHERE user.user_id=".$artifact.".assigned_to AND ".$artifact.".group_id='$group_id' ".
00235 "GROUP BY user_name";
00236
00237
00238
00239 }
00240 else
00241 {
00242
00243 $sql="SELECT ".$artifact."_field_value.value FROM "
00244 .$artifact."_field_value WHERE "
00245 .$artifact."_field_value.bug_field_id='".
00246 trackers_data_get_field_id($field)."' AND ".
00247 $artifact."_field_value.group_id='$group_id'";
00248
00249 $result=db_query($sql);
00250 if ($result && db_numrows($result) > 0) {
00251 $group_to_be_used = $group_id;
00252 } else {
00253 # the project does not have its own instance so
00254 # use the default one (group_id = '100')
00255 $group_to_be_used = 100;
00256 }
00257
00258 $sql="SELECT ".$artifact."_field_value.value, count(*) AS Count FROM ".$artifact."_field_value,".$artifact." ".
00259 "WHERE ".$artifact."_field_value.value_id=".$artifact.".$field AND ".
00260 "".$artifact."_field_value.bug_field_id='".
00261 trackers_data_get_field_id($field)."' AND ".
00262 $artifact."_field_value.group_id=$group_to_be_used AND ".$artifact.".group_id='$group_id' ".
00263 "GROUP BY value_id";
00264 }
00265 $result=db_query($sql);
00266 if ($result && db_numrows($result) > 0)
00267 { graphs_build($result, $field); }
00268 else
00269 { print _("No item found. This field is probably unused"); }
00270
00271 }
00272 }
00273
00274 }
00275
00276 specific_reports_list($field);
00277 trackers_footer(array());
00278
00279 ?>