3 * FusionForge reporting system
5 * Copyright 2003-2004, Tim Perdue/GForge, LLC
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 DEFINE('REPORT_DAY_SPAN',24*60*60);
26 DEFINE('REPORT_WEEK_SPAN',7*24*60*60);
27 DEFINE('REPORT_MONTH_SPAN',30*24*60*60);
29 DEFINE('REPORT_TYPE_DAILY',1);
30 DEFINE('REPORT_TYPE_WEEKLY',2);
31 DEFINE('REPORT_TYPE_MONTHLY',3);
32 DEFINE('REPORT_TYPE_OA',4);
34 class Report extends Error {
36 //var $adjust_days=array('Sun'=>0, 'Sat'=>6, 'Fri'=>5, 'Thu'=>4, 'Wed'=>3, 'Tue'=>2, 'Mon'=>1);
37 var $adjust_days=array('Sun'=>'0.0', 'Sat'=>1, 'Fri'=>2, 'Thu'=>3, 'Wed'=>4, 'Tue'=>5, 'Mon'=>6);
38 var $month_start_arr=array();
39 var $week_start_arr=array();
46 var $span_name=array(1=>'Daily',2=>'Weekly',3=>'Monthly',4=>'OverAll');
47 var $graph_interval=array(1=>7,2=>1,3=>1,4=>1);
52 // All reporting action will be done in GMT timezone
58 * get the unix time that this install was setup.
60 function getMinDate() {
61 if (!$this->site_start_date) {
62 $res=db_query("select min(add_date) AS start_date from users where add_date > 0;");
63 $this->site_start_date=db_result($res,0,'start_date');
65 return $this->site_start_date;
68 function &getMonthStartArr() {
69 if (count($this->month_start_arr) < 1) {
70 $min_date=$this->getMinDate();
71 for ($i=0; $i<24; $i++) {
72 $this->month_start_arr[]=mktime(0,0,0,date('m')+1-$i,1,date('Y'));
73 if ($this->month_start_arr[$i] < $min_date) {
78 return $this->month_start_arr;
81 function &getWeekStartArr() {
82 if (count($this->week_start_arr) < 1) {
83 $min_date=$this->getMinDate();
84 $start=mktime(0,0,0,date('m'),(date('d')+$this->adjust_days[date('D')]),date('Y'));
85 for ($i=0; $i<104; $i++) {
86 $this->week_start_arr[]=($start-REPORT_WEEK_SPAN*$i);
87 if ($this->week_start_arr[$i] < $min_date) {
92 return $this->week_start_arr;
95 function setSpan($span) {
99 function getSpanName() {
100 return $this->span_name[$this->span];
103 function setData($result,$column) {
104 $this->data =& util_result_column_to_array($result,$column);
107 function setDates($result,$column) {
108 $arr =& util_result_column_to_array($result,$column);
109 for ($i=0; $i<count($arr); $i++) {
110 $this->labels[$i] = date('M d',$arr[$i]);
114 function getGraphInterval() {
115 return $this->graph_interval[$this->span];
118 function &getData() {
122 function &getDates() {
123 return $this->labels;
126 function getStartDate() {
127 return $this->start_date;
130 function getEndDate() {
131 return $this->end_date;
138 // c-file-style: "bsd"