File: Report.class.php

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (190 lines) | stat: -rw-r--r-- 4,838 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
 * FusionForge reporting system
 *
 * Copyright 2003-2004, Tim Perdue/GForge, LLC
 * Copyright 2009, Roland Mas
 * Copyright 2013, Franck Villaume - TrivialDev
 *
 * This file is part of FusionForge. FusionForge is free software;
 * you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the Licence, or (at your option)
 * any later version.
 *
 * FusionForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

DEFINE('REPORT_DAY_SPAN',24*60*60);
DEFINE('REPORT_WEEK_SPAN',7*24*60*60);
DEFINE('REPORT_MONTH_SPAN',30*24*60*60);

DEFINE('REPORT_TYPE_DAILY',1);
DEFINE('REPORT_TYPE_WEEKLY',2);
DEFINE('REPORT_TYPE_MONTHLY',3);
DEFINE('REPORT_TYPE_OA',4);

class Report extends Error {

//var $adjust_days=array('Sun'=>0, 'Sat'=>6, 'Fri'=>5, 'Thu'=>4, 'Wed'=>3, 'Tue'=>2, 'Mon'=>1);
var $adjust_days = array('Sun'=>'0.0', 'Sat'=>1, 'Fri'=>2, 'Thu'=>3, 'Wed'=>4, 'Tue'=>5, 'Mon'=>6);
var $month_start_arr = array();
var $month_start_arr_format = array();
var $week_start_arr = array();
var $week_start_arr_format = array();
var $site_start_date;
var $data;
var $labels;
var $span;
var $start_date;
var $end_date;
var $span_name = array(1=>'Daily',2=>'Weekly',3=>'Monthly',4=>'OverAll');
var $graph_interval = array(1=>7,2=>1,3=>1,4=>1);
var $max_weeks = 104;
var $max_month = 24;
var $rawdates = array();

function Report() {
	$this->Error();
	//
	//	All reporting action will be done in GMT timezone
	//
	putenv('TZ=GMT');
	date_default_timezone_set('GMT');
}

/**
 * getMinDate - get the unix time that this install was setup.
 *
 * @return	int	the startdate
 */
function getMinDate() {
	if (!$this->site_start_date) {
		$res = db_query_params ('SELECT MIN(add_date) AS start_date FROM users WHERE add_date > 0',
					array ());
		$this->site_start_date=db_result($res,0,'start_date');
	}
	return $this->site_start_date;
}

/**
 * setStartDate - force the start date for this report
 *
 * @param	int	$startdate	the epoch start date
 */
function setStartDate($startdate) {
	$_startdate = $this->getMinDate();
	if ($_startdate > $startdate) {
		$startdate = $_startdate;
	}
	$this->site_start_date = $startdate;
}

function &getMonthStartArr() {
	if (count($this->month_start_arr) < 1) {
		$min_date=$this->getMinDate();
		for ($i=0; $i<$this->max_month; $i++) {
			$this->month_start_arr[] = mktime(0,0,0,date('m')+1-$i,1,date('Y'));
			$this->month_start_arr_format[] = date('Ym', $this->month_start_arr[$i]);
			if ($this->month_start_arr[$i] < $min_date) {
				break;
			}
		}
		sort($this->month_start_arr);
		sort($this->month_start_arr_format);
	}
	return $this->month_start_arr;
}

function &getWeekStartArr() {
	if (count($this->week_start_arr) < 1) {
		$min_date=$this->getMinDate();
		$start=mktime(0,0,0,date('m'),(date('d')+$this->adjust_days[date('D')]),date('Y'));
		for ($i=0; $i<$this->max_weeks; $i++) {
			$this->week_start_arr[]=($start-REPORT_WEEK_SPAN*$i);
			$this->week_start_arr_format[] = date('Y/W', $this->week_start_arr[$i]);
			if ($this->week_start_arr[$i] < $min_date) {
				break;
			}
		}
		sort($this->week_start_arr);
		sort($this->week_start_arr_format);
	}
	return $this->week_start_arr;
}

function setSpan($span) {
	$this->span=$span;
}

function getSpanName() {
	return $this->span_name[$this->span];
}

function setData($result,$column) {
	$this->data =& util_result_column_to_array($result,$column);
}

function setDates($result,$column) {
	$arr = NULL;
	if (!is_array($result)) {
		$arr =& util_result_column_to_array($result,$column);
	} elseif (is_array($result)) {
		$arr = $result;
	}
	if(isset($this->span) && $this->span == REPORT_TYPE_MONTHLY) {
		$format = 'M Y';
	} else {
		$format = 'M d';
	}

	for ($i=0; $i<count($arr); $i++) {
		$this->labels[$i] = date($format,$arr[$i]);
		$this->rawdates[$i] = $arr[$i];
	}
}

function getGraphInterval() {
	return $this->graph_interval[$this->span];
}

function &getData() {
	return $this->data;
}

function &getDates() {
	return $this->labels;
}

function &getRawDates() {
	return $this->rawdates;
}

function getStartDate() {
	return $this->start_date;
}

function getEndDate() {
	return $this->end_date;
}

function getMonthStartArrFormat() {
	return $this->month_start_arr_format;
}

function getWeekStartArrFormat() {
	return $this->week_start_arr_format;
}
}

// Local Variables:
// mode: php
// c-file-style: "bsd"
// End: