3 * FusionForge reporting system
5 * Copyright 2003-2004, Tim Perdue/GForge, LLC
6 * Copyright 2009, Roland Mas
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge 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 General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 DEFINE('REPORT_DAY_SPAN',24*60*60);
25 DEFINE('REPORT_WEEK_SPAN',7*24*60*60);
26 DEFINE('REPORT_MONTH_SPAN',30*24*60*60);
28 DEFINE('REPORT_TYPE_DAILY',1);
29 DEFINE('REPORT_TYPE_WEEKLY',2);
30 DEFINE('REPORT_TYPE_MONTHLY',3);
31 DEFINE('REPORT_TYPE_OA',4);
33 class Report extends Error {
35 //var $adjust_days=array('Sun'=>0, 'Sat'=>6, 'Fri'=>5, 'Thu'=>4, 'Wed'=>3, 'Tue'=>2, 'Mon'=>1);
36 var $adjust_days=array('Sun'=>'0.0', 'Sat'=>1, 'Fri'=>2, 'Thu'=>3, 'Wed'=>4, 'Tue'=>5, 'Mon'=>6);
37 var $month_start_arr=array();
38 var $week_start_arr=array();
45 var $span_name=array(1=>'Daily',2=>'Weekly',3=>'Monthly',4=>'OverAll');
46 var $graph_interval=array(1=>7,2=>1,3=>1,4=>1);
53 // All reporting action will be done in GMT timezone
59 * get the unix time that this install was setup.
61 function getMinDate() {
62 if (!$this->site_start_date) {
63 $res = db_query_params ('SELECT MIN(add_date) AS start_date FROM users WHERE add_date > 0',
65 $this->site_start_date=db_result($res,0,'start_date');
67 return $this->site_start_date;
70 function &getMonthStartArr() {
71 if (count($this->month_start_arr) < 1) {
72 $min_date=$this->getMinDate();
73 for ($i=0; $i<$this->max_month; $i++) {
74 $this->month_start_arr[]=mktime(0,0,0,date('m')+1-$i,1,date('Y'));
75 if ($this->month_start_arr[$i] < $min_date) {
79 sort($this->month_start_arr);
81 return $this->month_start_arr;
84 function &getWeekStartArr() {
85 if (count($this->week_start_arr) < 1) {
86 $min_date=$this->getMinDate();
87 $start=mktime(0,0,0,date('m'),(date('d')+$this->adjust_days[date('D')]),date('Y'));
88 for ($i=0; $i<$this->max_weeks; $i++) {
89 $this->week_start_arr[]=($start-REPORT_WEEK_SPAN*$i);
90 if ($this->week_start_arr[$i] < $min_date) {
94 sort($this->week_start_arr);
96 return $this->week_start_arr;
99 function setSpan($span) {
103 function getSpanName() {
104 return $this->span_name[$this->span];
107 function setData($result,$column) {
108 $this->data =& util_result_column_to_array($result,$column);
111 function setDates($result,$column) {
112 $arr =& util_result_column_to_array($result,$column);
113 if(isset($this->span) && $this->span == REPORT_TYPE_MONTHLY) {
119 for ($i=0; $i<count($arr); $i++) {
120 $this->labels[$i] = date($format,$arr[$i]);
124 function getGraphInterval() {
125 return $this->graph_interval[$this->span];
128 function &getData() {
132 function &getDates() {
133 return $this->labels;
136 function getStartDate() {
137 return $this->start_date;
140 function getEndDate() {
141 return $this->end_date;
148 // c-file-style: "bsd"