1<?php
2# MantisBT - A PHP based bugtracking system
3
4# MantisBT is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 2 of the License, or
7# (at your option) any later version.
8#
9# MantisBT is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Export billing information to csv
19 *
20 * @package MantisBT
21 * @copyright Copyright 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
22 * @copyright Copyright 2002  MantisBT Team - mantisbt-dev@lists.sourceforge.net
23 * @link http://www.mantisbt.org
24 *
25 * @uses core.php
26 * @uses billing_api.php
27 * @uses bug_api.php
28 * @uses csv_api.php
29 */
30
31require_once( 'core.php' );
32require_api( 'billing_api.php' );
33require_api( 'bug_api.php' );
34require_api( 'csv_api.php' );
35
36helper_begin_long_process();
37
38$t_date_format = config_get( 'normal_date_format' );
39
40$f_project_id = gpc_get_int( 'project_id' );
41$f_cost = gpc_get_int( 'cost' );
42$f_from = gpc_get_string( 'from' );
43$f_to = gpc_get_string( 'to' );
44$f_include_subprojects = gpc_get_bool( 'include_subprojects' );
45
46$t_new_line = csv_get_newline();
47$t_separator = csv_get_separator();
48
49billing_ensure_reporting_access( $f_project_id );
50
51$t_show_cost = ON == config_get( 'time_tracking_with_billing' ) && $f_cost != 0;
52
53$t_billing_rows = billing_get_for_project( $f_project_id, $f_from, $f_to, $f_cost, $f_include_subprojects );
54
55csv_start( csv_get_default_filename() );
56
57echo csv_escape_string( lang_get( 'issue_id' ) ) . $t_separator;
58echo csv_escape_string( lang_get( 'project_name' ) ) . $t_separator;
59echo csv_escape_string( lang_get( 'category' ) ) . $t_separator;
60echo csv_escape_string( lang_get( 'summary' ) ) . $t_separator;
61echo csv_escape_string( lang_get( 'username' ) ) . $t_separator;
62echo csv_escape_string( lang_get( 'timestamp' ) ) . $t_separator;
63echo csv_escape_string( lang_get( 'minutes' ) ) . $t_separator;
64echo csv_escape_string( lang_get( 'time_tracking_time_spent' ) ) . $t_separator;
65
66if( $t_show_cost ) {
67	echo csv_escape_string( 'cost' ) . $t_separator;
68}
69
70echo csv_escape_string( 'note' );
71echo $t_new_line;
72
73foreach( $t_billing_rows as $t_billing ) {
74	echo csv_escape_string( bug_format_id( $t_billing['bug_id'] ) ) . $t_separator;
75	echo csv_escape_string( $t_billing['project_name'] ) . $t_separator;
76	echo csv_escape_string( $t_billing['bug_category'] ) . $t_separator;
77	echo csv_escape_string( $t_billing['bug_summary'] ) . $t_separator;
78	echo csv_escape_string( $t_billing['reporter_name'] ) . $t_separator;
79	echo csv_escape_string( date( $t_date_format, $t_billing['date_submitted'] ) ) . $t_separator;
80	echo csv_escape_string( $t_billing['minutes'] ) . $t_separator;
81	echo csv_escape_string( $t_billing['duration'] ) . $t_separator;
82
83	if( $t_show_cost ) {
84		echo csv_escape_string( $t_billing['cost'] ) . $t_separator;
85	}
86
87	echo csv_escape_string( $t_billing['note'] );
88	echo $t_new_line;
89}
90
91
92