5 * Copyright 2004 (c) GForge LLC
7 * @author Tim Perdue tim@gforge.org
10 * This file is part of GForge.
12 * GForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * GForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with GForge; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 require_once('../env.inc.php');
28 require_once $gfwww.'include/pre.php';
29 require_once($sys_path_to_jpgraph.'/jpgraph.php');
30 require_once($sys_path_to_jpgraph.'/jpgraph_line.php');
31 require_once $gfcommon.'reporting/ReportProjectAct.class.php';
32 require_once $gfwww.'include/unicode.php';
34 $area = getStringFromRequest('area');
35 $SPAN = getIntFromRequest('SPAN', 1);
36 $start = getIntFromRequest('start');
37 $end = getIntFromRequest('end');
38 $g_id = getIntFromRequest('g_id');
40 $area = util_ensure_value_in_set ($area, array ('tracker','forum','docman','taskman','downloads')) ;
45 $report=new ReportProjectAct($SPAN,$g_id,$start,$end);
48 // Check for error, such as license key problem
50 if ($report->isError()) {
51 echo $report->getErrorMessage();
58 $g =& group_get_object($g_id);
59 if (!$g || $g->isError()) {
60 exit_error("Could Not Get Group");
63 // Create the graph. These two calls are always required
64 $graph = new Graph(640, 480,"auto");
65 $graph->SetMargin(50,10,35,80);
66 $graph->SetScale( "textlin");
67 //$graph->SetScale( "linlog");
68 //$graph ->SetYScale("log");
70 if ($area=='tracker') {
72 // Create the tracker open plot
73 $ydata =& $report->getTrackerOpened();
74 $lineplot =new LinePlot($ydata);
75 $lineplot ->SetColor("black");
76 $graph->Add( $lineplot);
78 // Create the tracker close plot
79 $ydata2 =& $report->getTrackerClosed();
80 $lineplot2 =new LinePlot($ydata2);
81 $lineplot2 ->SetColor("blue");
82 $graph->Add( $lineplot2 );
85 $lineplot->SetLegend (convert_unicode(_('Tracker Items Opened')));
86 $lineplot2 ->SetLegend(convert_unicode(_('Tracker Items Closed')));
88 } elseif ($area=='forum') {
90 // Create the forum plot
91 $ydata3 =& $report->getForum();
92 $lineplot3 =new LinePlot($ydata3);
93 $lineplot3 ->SetColor("orange");
94 $graph->Add( $lineplot3 );
97 $lineplot3 ->SetLegend("Forum");
99 } elseif ($area=='docman') {
101 // Create the Docman plot
102 $ydata4 =& $report->getDocs();
103 $lineplot4 =new LinePlot($ydata4);
104 $lineplot4 ->SetColor("red");
105 $graph->Add( $lineplot4 );
108 $lineplot4 ->SetLegend(convert_unicode(_('Docs')));
110 } elseif ($area=='downloads') {
112 // Create the Docman plot
113 $ydata4 =& $report->getDownloads();
114 $lineplot4 =new LinePlot($ydata4);
115 $lineplot4 ->SetColor("red");
116 $graph->Add( $lineplot4 );
119 $lineplot4 ->SetLegend(convert_unicode(_('Downloads')));
121 } elseif ($area=='taskman') {
123 // Create the Tasks Opened plot
124 $ydata5 =& $report->getTaskOpened();
125 $lineplot5 =new LinePlot($ydata5);
126 $lineplot5 ->SetColor("purple");
127 $graph->Add( $lineplot5 );
129 // Create the Tasks Closed plot
130 $ydata6 =& $report->getTaskClosed();
131 $lineplot6 =new LinePlot($ydata6);
132 $lineplot6 ->SetColor("yellow");
133 $graph->Add( $lineplot6 );
136 $lineplot5 ->SetLegend(convert_unicode(_('Task Open')));
137 $lineplot6 ->SetLegend(convert_unicode(_('Task Close')));
139 } elseif ($area=='pageviews') {
141 // Create the PageViews plot
142 $ydata4 =& $report->getPageViews();
143 $lineplot4 =new LinePlot($ydata4);
144 $lineplot4 ->SetColor("blue");
145 $graph->Add( $lineplot4 );
148 $lineplot4 ->SetLegend(convert_unicode(_('Page Views')));
152 * The goal of this code is to get values from the activity hook to compute stats without the
153 * need of another specific hook or another dedicated tables.
155 * So, values are requested to the hook and stored in $results array.
156 * After, the sum is made according to the chosen interval
157 * And then, the sum is stored in the ydata array.
164 $hookParams['group'] = $g_id ;
165 $hookParams['results'] = &$results;
166 $hookParams['show'] = array();
167 $hookParams['begin'] = $start;
168 $hookParams['end'] = $end;
169 $hookParams['ids'] = &$ids;
170 $hookParams['texts'] = &$texts;
171 plugin_hook ("activity", $hookParams) ;
173 if ($SPAN == REPORT_TYPE_DAILY) {
174 $interval = REPORT_DAY_SPAN;
175 } elseif ($SPAN == REPORT_TYPE_WEEKLY) {
176 $interval = REPORT_WEEK_SPAN;
177 } elseif ($SPAN == REPORT_TYPE_MONTHLY) {
178 $interval = REPORT_MONTH_SPAN;
181 print "start: $start ".date('r',$start)."<br>";
182 print " end: $end ".date('r', $end)."<br>";
185 $starting_date = $start;
186 foreach ($results as $arr) {
187 $d = $arr['activity_date'];
188 $col = intval(($d - $starting_date)/$interval);
189 $col_date = $starting_date+$col*$interval;
193 // Now, stores the values in the ydata array for the graph.
196 foreach ($report->getDates() as $d) {
197 $ydata[$i++] = isset($sum[strtotime($d)]) ? $sum[strtotime($d)] : 0;
200 $lineplot =new LinePlot($ydata);
201 $lineplot->SetColor("violet");
202 $graph->Add( $lineplot );
205 $lineplot->SetLegend($area);
207 // var_dump($report->getDates());
216 $graph->title->Set("Project Activity For: ".util_unconvert_htmlspecialchars($g->getPublicName()).
217 " (".date('Y-m-d',$report->getStartDate()) ." to ". date('Y-m-d',$report->getEndDate()) .")");
218 $graph->subtitle->Set(forge_get_config ('forge_name'));
219 //$graph->xaxis-> title->Set("Date" );
220 //$graph->yaxis-> title->Set("Number" );
222 $a=$report->getDates();
223 $graph->xaxis->SetTickLabels($a);
224 $graph->xaxis->SetLabelAngle(90);
225 $graph->xaxis->SetTextLabelInterval($report->getGraphInterval());