5 * Copyright 2003-2004 (c) GForge LLC
7 * This file is part of FusionForge. FusionForge is free software;
8 * you can redistribute it and/or modify it under the terms of the
9 * GNU General Public License as published by the Free Software
10 * Foundation; either version 2 of the Licence, or (at your option)
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 require_once('../env.inc.php');
24 require_once $gfcommon.'include/pre.php';
25 require_once(forge_get_config('jpgraph_path').'/jpgraph.php');
26 require_once(forge_get_config('jpgraph_path').'/jpgraph_line.php');
27 require_once $gfcommon.'reporting/ReportProjectAct.class.php';
28 require_once $gfwww.'include/unicode.php';
30 $area = getStringFromRequest('area');
31 $SPAN = getIntFromRequest('SPAN', 1);
32 $start = getIntFromRequest('start');
33 $end = getIntFromRequest('end');
34 $g_id = getIntFromRequest('g_id');
36 $area = util_ensure_value_in_set ($area, array ('tracker','forum','docman','taskman','downloads')) ;
41 $report=new ReportProjectAct($SPAN,$g_id,$start,$end);
44 // Check for error, such as license key problem
46 if ($report->isError()) {
47 exit_error($report->getErrorMessage());
53 $g = group_get_object($g_id);
54 if (!$g || !is_object($g)) {
56 } elseif ($g->isError()) {
57 exit_error($g->getErrorMessage(),'');
60 // Create the graph. These two calls are always required
61 $graph = new Graph(640, 480,"auto");
62 $graph->SetMargin(50,10,35,80);
63 $graph->SetScale( "textlin");
64 //$graph->SetScale( "linlog");
65 //$graph ->SetYScale("log");
67 if ($area=='tracker') {
69 // Create the tracker open plot
70 $ydata =& $report->getTrackerOpened();
71 $lineplot =new LinePlot($ydata);
72 $lineplot ->SetColor("black");
73 $graph->Add( $lineplot);
75 // Create the tracker close plot
76 $ydata2 =& $report->getTrackerClosed();
77 $lineplot2 =new LinePlot($ydata2);
78 $lineplot2 ->SetColor("blue");
79 $graph->Add( $lineplot2 );
82 $lineplot->SetLegend (convert_unicode(_('Tracker Items Opened')));
83 $lineplot2 ->SetLegend(convert_unicode(_('Tracker Items Closed')));
85 } elseif ($area=='forum') {
87 // Create the forum plot
88 $ydata3 =& $report->getForum();
89 $lineplot3 =new LinePlot($ydata3);
90 $lineplot3 ->SetColor("orange");
91 $graph->Add( $lineplot3 );
94 $lineplot3 ->SetLegend("Forum");
96 } elseif ($area=='docman') {
98 // Create the Docman plot
99 $ydata4 =& $report->getDocs();
100 $lineplot4 =new LinePlot($ydata4);
101 $lineplot4 ->SetColor("red");
102 $graph->Add( $lineplot4 );
105 $lineplot4 ->SetLegend(convert_unicode(_('Docs')));
107 } elseif ($area=='downloads') {
109 // Create the Docman plot
110 $ydata4 =& $report->getDownloads();
111 $lineplot4 =new LinePlot($ydata4);
112 $lineplot4 ->SetColor("red");
113 $graph->Add( $lineplot4 );
116 $lineplot4 ->SetLegend(convert_unicode(_('Downloads')));
118 } elseif ($area=='taskman') {
120 // Create the Tasks Opened plot
121 $ydata5 =& $report->getTaskOpened();
122 $lineplot5 =new LinePlot($ydata5);
123 $lineplot5 ->SetColor("purple");
124 $graph->Add( $lineplot5 );
126 // Create the Tasks Closed plot
127 $ydata6 =& $report->getTaskClosed();
128 $lineplot6 =new LinePlot($ydata6);
129 $lineplot6 ->SetColor("yellow");
130 $graph->Add( $lineplot6 );
133 $lineplot5 ->SetLegend(convert_unicode(_('Task Open')));
134 $lineplot6 ->SetLegend(convert_unicode(_('Task Close')));
136 } elseif ($area=='pageviews') {
138 // Create the PageViews plot
139 $ydata4 =& $report->getPageViews();
140 $lineplot4 =new LinePlot($ydata4);
141 $lineplot4 ->SetColor("blue");
142 $graph->Add( $lineplot4 );
145 $lineplot4 ->SetLegend(convert_unicode(_('Page Views')));
149 * The goal of this code is to get values from the activity hook to compute stats without the
150 * need of another specific hook or another dedicated tables.
152 * So, values are requested to the hook and stored in $results array.
153 * After, the sum is made according to the chosen interval
154 * And then, the sum is stored in the ydata array.
161 $hookParams['group'] = $g_id ;
162 $hookParams['results'] = &$results;
163 $hookParams['show'] = array();
164 $hookParams['begin'] = $start;
165 $hookParams['end'] = $end;
166 $hookParams['ids'] = &$ids;
167 $hookParams['texts'] = &$texts;
168 plugin_hook ("activity", $hookParams) ;
170 if ($SPAN == REPORT_TYPE_DAILY) {
171 $interval = REPORT_DAY_SPAN;
172 } elseif ($SPAN == REPORT_TYPE_WEEKLY) {
173 $interval = REPORT_WEEK_SPAN;
174 } elseif ($SPAN == REPORT_TYPE_MONTHLY) {
175 $interval = REPORT_MONTH_SPAN;
178 print "start: $start ".date('r',$start)."<br>";
179 print " end: $end ".date('r', $end)."<br>";
182 $starting_date = $start;
183 foreach ($results as $arr) {
184 $d = $arr['activity_date'];
185 $col = intval(($d - $starting_date)/$interval);
186 $col_date = $starting_date+$col*$interval;
190 // Now, stores the values in the ydata array for the graph.
193 foreach ($report->getDates() as $d) {
194 $ydata[$i++] = isset($sum[strtotime($d)]) ? $sum[strtotime($d)] : 0;
197 $lineplot =new LinePlot($ydata);
198 $lineplot->SetColor("violet");
199 $graph->Add( $lineplot );
202 $lineplot->SetLegend($area);
204 // var_dump($report->getDates());
213 $graph->title->Set("Project Activity For: ".util_unconvert_htmlspecialchars($g->getPublicName()).
214 " (".date('Y-m-d',$report->getStartDate()) ." to ". date('Y-m-d',$report->getEndDate()) .")");
215 $graph->subtitle->Set(forge_get_config ('forge_name'));
216 //$graph->xaxis-> title->Set("Date" );
217 //$graph->yaxis-> title->Set("Number" );
219 $a=$report->getDates();
220 $graph->xaxis->SetTickLabels($a);
221 $graph->xaxis->SetLabelAngle(90);
222 $graph->xaxis->SetTextLabelInterval($report->getGraphInterval());