1<?php
2# ---------------------------------------------------------------------
3# rth is a requirement, test, and bugtracking system
4# Copyright (C) 2005 George Holbrook - rth@lists.sourceforge.net
5# This program is distributed under the terms and conditions of the GPL
6# See the README and LICENSE files for details
7#----------------------------------------------------------------------
8# ------------------------------------
9# CSV Export Page
10#
11# $RCSfile: excel_export.php,v $ $Revision: 1.2 $
12# ------------------------------------
13
14include"./api/include_api.php";
15auth_authenticate_user();
16
17$project_properties     = session_get_project_properties();
18$project_name           = $project_properties['project_name'];
19$project_id				= $project_properties['project_id'];
20
21$csv = "";
22
23switch ( $_GET['table'] ) {
24	case "requirements":
25
26		# columns to be included from the recordset and the
27		# name to use in the header row
28		$headers = 	array(	REQ_ID 					=> lang_get('req_id'),
29							REQ_FILENAME 			=> lang_get('req_name'),
30							REQ_VERS_DETAIL			=> lang_get('req_detail'),
31							REQ_DOC_TYPE_NAME 				=> lang_get('req_type'),
32							REQ_VERS_STATUS			=> lang_get('status'),
33							REQ_VERS_VERSION		=> lang_get('version'),
34							REQ_AREA_COVERAGE 		=> lang_get('req_area'),
35							REQ_LOCKED_BY 			=> lang_get('req_locked_by'),
36							REQ_LOCKED_DATE 		=> lang_get('req_locked_date'),
37							"Functionality"			=> lang_get('functionality'),
38							REQ_PRIORITY			=> lang_get('req_priority');
39
40		$display_options = session_get_display_options("requirements");
41
42		$rows = requirement_get( 	$project_id,
43									$page_number=0,
44									$display_options['order_by'],
45									$display_options['order_dir'],
46									$display_options['filter']['doc_type'],
47									$display_options['filter']['status'],
48									$display_options['filter']['area_covered'],
49									$display_options['filter']['functionality'],
50									$display_options['filter']['assign_release'],
51									$display_options['filter']['show_versions'],
52									$per_page="",
53									$display_options['filter']['requirement_search'],
54									$display_options['filter']['priority']
55							  );
56
57		# add functionality information of each requirement
58		foreach($rows as $row => $fields) {
59
60			# create functionality field
61			$rows[$row]["Functionality"] = "";
62
63			# get functionalities
64			$rows_functions = requirement_get_functionality($project_id, $fields[REQ_ID]);
65
66			# add functionalities to the array
67			foreach($rows_functions as $key => $value) {
68
69				$rows[$row]["Functionality"] .= $value."". NEWLINE;
70			}
71		}
72		break;
73	case "tests":
74
75		$headers = array(	TEST_ID			=> lang_get('test_id'),
76							TEST_MANUAL		=> "Manual",
77							TEST_AUTOMATED	=> "Auto",
78							TEST_AUTO_PASS	=> lang_get('autopass'),
79							TEST_NAME		=> lang_get('test_name'),
80							TEST_BA_OWNER	=> lang_get('ba_owner'),
81							TEST_QA_OWNER	=> lang_get('qa_owner'),
82							TEST_TESTER     => lang_get('tester'),
83							TEST_TESTTYPE	=> lang_get('testtype'),
84							TEST_AREA_TESTED=> lang_get('area_tested'),
85							TEST_STATUS		=> lang_get('test_status') );
86
87
88		$display_options = session_get_display_options( "test" );
89
90
91		$rows = test_filter_rows(	$project_id,
92									$display_options['filter']['manual_auto'],
93									$display_options['filter']['ba_owner'],
94									$display_options['filter']['qa_owner'],
95									$display_options['filter']['tester'],
96									$display_options['filter']['test_type'],
97									$display_options['filter']['area_tested'],
98									$display_options['filter']['test_status'],
99									$display_options['filter']['per_page'],
100									$display_options['filter']['test_search'],
101									$display_options['order_by'],
102									$display_options['order_dir'],
103									$page_number=0 );
104		break;
105	case "test_workflow":
106
107		$headers = array(	TEST_ID				=> lang_get('test_id'),
108							TEST_MANUAL			=> "Manual",
109							TEST_AUTOMATED		=> "Auto",
110							TEST_NAME			=> lang_get('test_name'),
111							TEST_STATUS			=> lang_get('test_status'),
112							TEST_PRIORITY		=> lang_get('priority'),
113							TEST_BA_OWNER		=> lang_get('ba_owner'),
114							TEST_QA_OWNER		=> lang_get('qa_owner'),
115							TEST_TESTER			=> lang_get('tester'),
116							TEST_DATE_ASSIGNED	=> lang_get('date_assigned'),
117							TEST_DATE_EXPECTED	=> lang_get('date_expected'),
118							TEST_DATE_COMPLETE	=> lang_get('date_complete'),
119							TEST_BA_SIGNOFF		=> lang_get('ba_signoff_date'),
120							TEST_COMMENTS		=> lang_get('info') );
121
122		$display_options = session_get_display_options( "test_workflow" );
123
124		$rows = test_workflow_filter_rows(	$project_id,
125											$display_options['filter']['manual_auto'],
126											$display_options['filter']['ba_owner'],
127											$display_options['filter']['qa_owner'],
128											$display_options['filter']['test_status'],
129											$display_options['filter']['per_page'],
130											$display_options['order_by'],
131											$display_options['order_dir'],
132											$page_number=0 );
133		break;
134	case "results":
135
136		$table_options = session_get_display_options("results");
137		$s_properties = session_get_properties("results");
138
139		$rows = results_filter_rows(	$project_id,
140										$table_options['filter']['manual_auto'],
141										$table_options['filter']['ba_owner'],
142										$table_options['filter']['qa_owner'],
143										$table_options['filter']['test_type'],
144										$table_options['filter']['area_tested'],
145										$table_options['filter']['test_status'],
146										$table_options['filter']['per_page'],
147										$table_options['order_by'],
148										$table_options['order_dir'],
149										$page_number=0,
150										$s_properties['release_id'],
151										$s_properties['build_id'],
152										$s_properties['testset_id'] );
153		break;
154	case "test_run":
155
156		$s_results 		= session_get_properties( "results" );
157		$test_run_id 	= $s_results['test_run_id'];
158
159		$rows_verify_details 	= results_get_verify_results_detail( $test_run_id );
160		$s_show_options 		= session_get_show_options();
161
162		# get project preferences that determine what fields we do and don't show for each project
163		$show_custom_1		= $s_show_options['show_custom_1'];
164		$show_custom_2		= $s_show_options['show_custom_2'];
165		$show_custom_3		= $s_show_options['show_custom_3'];
166		$show_custom_4		= $s_show_options['show_custom_4'];
167		$show_custom_5		= $s_show_options['show_custom_5'];
168		$show_custom_6		= $s_show_options['show_custom_6'];
169		$show_window		= $s_show_options['show_window'];
170		$show_object		= $s_show_options['show_object'];
171		$show_memory_stats	= $s_show_options['show_memory_stats'];
172
173		$headers = array(	VERIFY_RESULTS_VAL_ID			=> lang_get('step_no'),
174							VERIFY_RESULTS_ACTION			=> lang_get('action_'),
175							VERIFY_RESULTS_EXPECTED_RESULT	=> lang_get('expected_'),
176							VERIFY_RESULTS_ACTUAL_RESULT	=> lang_get('actual_'),
177							VERIFY_RESULTS_TEST_STATUS		=> lang_get('status') );
178
179		if( $show_custom_1 == 'Y' ) {
180			$headers[VERIFY_RESULTS_CUSTOM_1] = lang_get('custom_1');
181		}
182		if( $show_custom_2 == 'Y' ) {
183			$headers[VERIFY_RESULTS_CUSTOM_2] = lang_get('custom_2');
184		}
185		if( $show_custom_3 == 'Y' ) {
186			$headers[VERIFY_RESULTS_CUSTOM_3] = lang_get('custom_3');
187		}
188		if( $show_custom_4 == 'Y' ) {
189			$headers[VERIFY_RESULTS_CUSTOM_4] = lang_get('custom_4');
190		}
191		if( $show_custom_5 == 'Y' ) {
192			$headers[VERIFY_RESULTS_CUSTOM_5] = lang_get('custom_5');
193		}
194		if( $show_custom_6 == 'Y' ) {
195			$headers[VERIFY_RESULTS_CUSTOM_6] = lang_get('custom_6');
196		}
197
198		$headers[VERIFY_RESULTS_TIMESTAMP] 		= lang_get('time_tested');
199		$headers[VERIFY_RESULTS_WINDOW] 		= lang_get('window');
200		$headers[VERIFY_RESULTS_OBJ] 			= lang_get('object');
201		$headers[VERIFY_RESULTS_LINE_NUMBER]	= lang_get('line_no');
202
203		if( $show_memory_stats == 'Y' ) {
204
205			$headers[VERIFY_RESULTS_TOTAL_PHY_MEM] = lang_get('tot_phy_mem');
206			$headers[VERIFY_RESULTS_FREE_PHY_MEM] = lang_get('free_phy_mem');
207			$headers[VERIFY_RESULTS_TOTAL_VIR_MEM] = lang_get('tot_vir_mem');
208			$headers[VERIFY_RESULTS_FREE_VIR_MEM] = lang_get('free_vir_mem');
209			$headers[VERIFY_RESULTS_CUR_MEM_UTIL] = lang_get('cur_mem_util');
210			$headers[VERIFY_RESULTS_TOTAL_PAGE_FILE] = lang_get('tot_page_file');
211			$headers[VERIFY_RESULTS_FREE_PAGE_FILE] = lang_get('free_page_file');
212
213		}
214
215		$rows = results_get_verify_results_detail( $test_run_id );
216		break;
217	case "bugs":
218
219		$headers = array(	BUG_ID						=> lang_get('bug_id'),
220							BUG_PRIORITY				=> lang_get('bug_priority'),
221							BUG_STATUS					=> lang_get('bug_status'),
222							BUG_CATEGORY				=> lang_get('bug_category'),
223							BUG_REPORTER				=> lang_get('reported_by'),
224							BUG_ASSIGNED_TO				=> lang_get('assigned_to'),
225							BUG_ASSIGNED_TO_DEVELOPER	=> lang_get('assigned_to_developer'),
226							BUG_FOUND_IN_RELEASE		=> lang_get('found_in_release'),
227							BUG_ASSIGN_TO_RELEASE		=> lang_get('assigned_to_release'),
228							BUG_SUMMARY					=> lang_get('bug_summary') );
229
230
231		$display_options = session_get_display_options( "bug" );
232
233		/*
234		foreach( $display_options as $key => $val ){
235			print"$key = $val<br>";
236			if( $key == "filter" ){
237				print_r($val);
238			}
239		}
240		*/
241
242
243		$rows = bug_get(	$project_id,
244							$page_number=0,
245							$display_options['order_by'],
246							$display_options['order_dir'],
247							$display_options['filter']['status'],
248							$display_options['filter']['category'],
249							$display_options['filter']['component'],
250							$display_options['filter']['reported_by'],
251							$display_options['filter']['assigned_to'],
252							$display_options['filter']['assigned_to_developer'],
253							$display_options['filter']['found_in_release'],
254							$display_options['filter']['assigned_to_release'] );
255		/*
256		 bug_get($project_id, $page_number=0, $order_by=BUG_ID, $order_dir="DESC",
257				 $bug_status, $category="", $component="", $reported_by="", $assigned_to="", $assigned_to_developer="", $found_in_release="", $assigned_to_release=null, $per_page=null, $view_closed='No', $search="", $jump="", $csv_name=null)
258		*/
259		break;
260	case "test_steps":
261
262		$headers = array(	TEST_STEP_NO				=> lang_get('step_no'),
263							TEST_STEP_ACTION			=> lang_get('step_action'),
264							TEST_STEP_TEST_INPUTS		=> lang_get('test_inputs'),
265							TEST_STEP_EXPECTED			=> lang_get('step_expected'),
266							TEST_STEP_INFO_STEP			=> lang_get('info_step') );
267
268		$s_test_details			= session_get_properties("test");
269		$test_id				= $s_test_details['test_id'];
270
271		$rows = test_get_test_steps_for_export( $test_id );
272
273		break;
274	default:
275		exit;
276}
277
278
279if( isset($headers) ) {
280
281	# HEADER ROW
282	$row = $rows[0];
283	$header = "";
284	$data = "";
285
286	foreach($headers as $key => $value) {
287
288		# Replace double quotes with two double quotes
289		$value = str_replace('"', '""', $value);
290		$header .= '"'. $value .'"'. "\t";
291	}
292
293	# DATA ROWS
294	//print_r($rows);
295	foreach($rows as $row) {
296
297		$data_row = "";
298
299		foreach($row as $key => $value) {
300
301			//print"$key = $value<br>";
302			$data_field = str_replace( '"', '""', util_unhtmlentities( util_strip_html_tags($row[$key]) ) );
303
304			$data_row .= '"'. $data_field .'"'. "\t";
305		}
306
307		$data .= trim($data_row)."". NEWLINE;
308		//$csv .= substr($csv_row, 0, -1)."". NEWLINE;
309	}
310}
311else {
312
313	# HEADER ROW
314	$row = $rows[0];
315	$data_row = "";
316
317	foreach($row as $key => $value) {
318
319		# Replace double quotes with two double quotes
320		$data_field = str_replace('"', '""', $key);
321
322		$data_row .= '"'.$data_field.'"\t';
323	}
324
325	$data .= substr($data_row, 0, -1)."". NEWLINE;
326
327	# DATA ROWS
328	foreach($rows as $row) {
329
330		$data_row = "";
331
332		foreach($row as $key => $value) {
333
334			$data_field = str_replace('"', '""', util_unhtmlentities( util_strip_html_tags($value) ) );
335
336			$data_row .= '"'.$data_field.'"\t';
337		}
338
339		$data .= substr($data_row, 0, -1)."". NEWLINE;
340
341	}
342}
343
344
345$headers = str_replace("\r","",$header);
346$data = str_replace("\r","",$data);
347
348# OUTPUT
349header("Content-type: application/x-msdownload");
350header("Content-Disposition: attachment; filename=export.xls");
351header("Pragma: no-cache");
352header("Expires: 0");
353//print "$csv";
354print "$header\n$data";
355
356# ------------------------------------
357# $Log: excel_export.php,v $
358# Revision 1.2  2006/08/05 22:08:13  gth2
359# adding NEWLINE constant to support multiple OS newline chars - gth
360#
361# Revision 1.1  2006/02/27 18:00:05  gth2
362# adding excel integration - gth
363#
364# Revision 1.1.1.1  2005/11/30 23:00:56  gth2
365# importing initial version - gth
366#
367# ------------------------------------
368
369?>