3 * FusionForge reporting system
5 * Copyright 2003-2004, Tim Perdue/GForge, LLC
6 * Copyright 2009, Roland Mas
7 * Copyright 2013, Franck Villaume - TrivialDev
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 FFError {
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 $month_start_arr_format = array();
40 var $week_start_arr = array();
41 var $week_start_arr_format = array();
48 var $span_name = array(1=>'Daily',2=>'Weekly',3=>'Monthly',4=>'OverAll');
49 var $graph_interval = array(1=>7,2=>1,3=>1,4=>1);
52 var $rawdates = array();
55 parent::__construct();
57 // All reporting action will be done in GMT timezone
60 date_default_timezone_set('GMT');
64 * getMinDate - get the unix time that this install was setup.
66 * @return int the startdate
68 function getMinDate() {
69 if (!$this->site_start_date) {
70 $res = db_query_params ('SELECT MIN(add_date) AS start_date FROM users WHERE add_date > 0',
72 $this->site_start_date=db_result($res,0,'start_date');
74 return $this->site_start_date;
78 * setStartDate - force the start date for this report
80 * @param int $startdate the epoch start date
82 function setStartDate($startdate) {
83 $_startdate = $this->getMinDate();
84 if ($_startdate > $startdate) {
85 $startdate = $_startdate;
87 $this->site_start_date = $startdate;
90 function &getMonthStartArr() {
91 if (count($this->month_start_arr) < 1) {
92 $min_date=$this->getMinDate();
93 for ($i=0; $i<$this->max_month; $i++) {
94 $this->month_start_arr[] = mktime(0,0,0,date('m')+1-$i,1,date('Y'));
95 $this->month_start_arr_format[] = date('Ym', $this->month_start_arr[$i]);
96 if ($this->month_start_arr[$i] < $min_date) {
100 sort($this->month_start_arr);
101 sort($this->month_start_arr_format);
103 return $this->month_start_arr;
106 function &getWeekStartArr() {
107 if (count($this->week_start_arr) < 1) {
108 $min_date=$this->getMinDate();
109 $start=mktime(0,0,0,date('m'),(date('d')+$this->adjust_days[date('D')]),date('Y'));
110 for ($i=0; $i<$this->max_weeks; $i++) {
111 $this->week_start_arr[]=($start-REPORT_WEEK_SPAN*$i);
112 $this->week_start_arr_format[] = date('Y/W', $this->week_start_arr[$i]);
113 if ($this->week_start_arr[$i] < $min_date) {
117 sort($this->week_start_arr);
118 sort($this->week_start_arr_format);
120 return $this->week_start_arr;
123 function setSpan($span) {
127 function getSpanName() {
128 return $this->span_name[$this->span];
131 function setData($result,$column) {
132 $this->data =& util_result_column_to_array($result,$column);
135 function setDates($result,$column) {
137 if (!is_array($result)) {
138 $arr =& util_result_column_to_array($result,$column);
139 } elseif (is_array($result)) {
142 if(isset($this->span) && $this->span == REPORT_TYPE_MONTHLY) {
148 for ($i=0; $i<count($arr); $i++) {
149 $this->labels[$i] = date($format,$arr[$i]);
150 $this->rawdates[$i] = $arr[$i];
154 function getGraphInterval() {
155 return $this->graph_interval[$this->span];
158 function &getData() {
162 function &getDates() {
163 return $this->labels;
166 function &getRawDates() {
167 return $this->rawdates;
170 function getStartDate() {
171 return $this->start_date;
174 function getEndDate() {
175 return $this->end_date;
178 function getMonthStartArrFormat() {
179 return $this->month_start_arr_format;
182 function getWeekStartArrFormat() {
183 return $this->week_start_arr_format;
189 // c-file-style: "bsd"