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 * Word 2000 export page
19 * The bugs displayed in print_all_bug_page.php are saved in a .doc file
20 * The IE icon allows to see or directly print the same result
21 *
22 * @package MantisBT
23 * @copyright Copyright 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
24 * @copyright Copyright 2002  MantisBT Team - mantisbt-dev@lists.sourceforge.net
25 * @link http://www.mantisbt.org
26 *
27 * @uses core.php
28 * @uses access_api.php
29 * @uses authentication_api.php
30 * @uses bug_api.php
31 * @uses bugnote_api.php
32 * @uses category_api.php
33 * @uses config_api.php
34 * @uses constant_inc.php
35 * @uses custom_field_api.php
36 * @uses date_api.php
37 * @uses file_api.php
38 * @uses filter_api.php
39 * @uses gpc_api.php
40 * @uses helper_api.php
41 * @uses html_api.php
42 * @uses http_api.php
43 * @uses lang_api.php
44 * @uses prepare_api.php
45 * @uses print_api.php
46 * @uses profile_api.php
47 * @uses project_api.php
48 * @uses string_api.php
49 */
50
51require_once( 'core.php' );
52require_api( 'access_api.php' );
53require_api( 'authentication_api.php' );
54require_api( 'bug_api.php' );
55require_api( 'bugnote_api.php' );
56require_api( 'category_api.php' );
57require_api( 'config_api.php' );
58require_api( 'constant_inc.php' );
59require_api( 'custom_field_api.php' );
60require_api( 'date_api.php' );
61require_api( 'file_api.php' );
62require_api( 'filter_api.php' );
63require_api( 'gpc_api.php' );
64require_api( 'helper_api.php' );
65require_api( 'html_api.php' );
66require_api( 'http_api.php' );
67require_api( 'lang_api.php' );
68require_api( 'prepare_api.php' );
69require_api( 'print_api.php' );
70require_api( 'profile_api.php' );
71require_api( 'project_api.php' );
72require_api( 'string_api.php' );
73
74auth_ensure_user_authenticated();
75
76$f_type_page	= gpc_get_string( 'type_page', 'word' );
77$f_search		= gpc_get_string( 'search', false ); # @todo need a better default
78$f_offset		= gpc_get_int( 'offset', 0 );
79$f_export		= gpc_get_string( 'export' );
80$f_show_flag	= gpc_get_bool( 'show_flag' );
81
82helper_begin_long_process();
83
84# word or html export
85if( $f_type_page != 'html' ) {
86	$t_export_title = helper_get_default_export_filename( '' );
87	$t_export_title = preg_replace( '/[\/:*?"<>|]/', '', $t_export_title );
88	$t_export_title .= '.doc';
89
90	# Make sure that IE can download the attachments under https.
91	header( 'Pragma: public' );
92
93	header( 'Content-Type: application/msword' );
94
95	http_content_disposition_header( $t_export_title );
96}
97
98# This is where we used to do the entire actual filter ourselves
99$t_page_number = gpc_get_int( 'page_number', 1 );
100$t_per_page = -1;
101$t_bug_count = null;
102$t_page_count = null;
103
104$t_result = filter_get_bug_rows( $t_page_number, $t_per_page, $t_page_count, $t_bug_count );
105$t_row_count = count( $t_result );
106
107# Headers depending on intended output
108if( $f_type_page == 'html' ) {
109	layout_page_header();
110} else {
111	echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"
112		xmlns:w="urn:schemas-microsoft-com:office:word"
113		xmlns="http://www.w3.org/TR/REC-html40">
114		<head><meta charset="utf-8"></head>';
115	echo '<body>';
116}
117
118$f_bug_arr = explode( ',', $f_export );
119$t_count_exported = 0;
120$t_date_format = config_get( 'normal_date_format' );
121$t_short_date_format = config_get( 'short_date_format' );
122
123$t_lang_bug_view_title = lang_get( 'bug_view_title' );
124$t_lang_id = lang_get( 'id' );
125$t_lang_category = lang_get( 'category' );
126$t_lang_severity = lang_get( 'severity' );
127$t_lang_reproducibility = lang_get( 'reproducibility' );
128$t_lang_date_submitted = lang_get( 'date_submitted' );
129$t_lang_last_update = lang_get( 'last_update' );
130$t_lang_reporter = lang_get( 'reporter' );
131$t_lang_assigned_to = lang_get( 'assigned_to' );
132$t_lang_platform = lang_get( 'platform' );
133$t_lang_due_date = lang_get( 'due_date' );
134$t_lang_os = lang_get( 'os' );
135$t_lang_os_build = lang_get( 'os_build' );
136$t_lang_fixed_in_version = lang_get( 'fixed_in_version' );
137$t_lang_resolution = lang_get( 'resolution' );
138$t_lang_priority = lang_get( 'priority' );
139$t_lang_product_build = lang_get( 'product_build' );
140$t_lang_eta = lang_get( 'eta' );
141$t_lang_status = lang_get( 'status' );
142$t_lang_product_version = lang_get( 'product_version' );
143$t_lang_no_bugnotes_msg = lang_get( 'no_bugnotes_msg' );
144$t_lang_projection = lang_get( 'projection' );
145$t_lang_target_version = lang_get( 'target_version' );
146$t_lang_summary = lang_get( 'summary' );
147$t_lang_description = lang_get( 'description' );
148$t_lang_steps_to_reproduce = lang_get( 'steps_to_reproduce' );
149$t_lang_additional_information = lang_get( 'additional_information' );
150$t_lang_bug_notes_title = lang_get( 'bug_notes_title' );
151$t_lang_system_profile = lang_get( 'profile_description' );
152$t_lang_attached_files = lang_get( 'attached_files' );
153$t_lang_tags = lang_get( 'tags' );
154
155$t_fields = config_get( 'bug_view_page_fields' );
156$t_fields = columns_filter_disabled( $t_fields );
157
158$t_show_tags = in_array( 'tags', $t_fields ) && access_has_global_level( config_get( 'tag_view_threshold' ) );
159
160$t_current_user_id = auth_get_current_user_id();
161$t_user_bugnote_order = user_pref_get_pref( $t_current_user_id, 'bugnote_order' );
162
163for( $j=0; $j < $t_row_count; $j++ ) {
164	$t_bug = $t_result[$j];
165	$t_id = $t_bug->id;
166
167	if( $j % 50 == 0 ) {
168		# to save ram as report will list data once, clear cache after 50 bugs
169		bug_clear_cache_all();
170		bugnote_clear_cache();
171	}
172
173	# display the available and selected bugs
174	if( in_array( $t_id, $f_bug_arr ) || !$f_show_flag ) {
175		if( $t_count_exported > 0 ) {
176			echo '<br style="mso-special-character: line-break; page-break-before: always" />';
177		}
178
179		$t_count_exported++;
180
181		$t_last_updated = date( $g_short_date_format, $t_bug->last_updated );
182
183		# grab the project name
184		$t_project_name = project_get_field( $t_bug->project_id, 'name' );
185		$t_category_name = category_full_name( $t_bug->category_id, false );
186?>
187<table class="table table-striped table-bordered table-condensed no-margin small">
188<tr>
189	<td class="bold" colspan="6">
190		<?php echo $t_lang_bug_view_title ?>
191	</td>
192</tr>
193<tr class="spacer" >
194	<td colspan="6"></td>
195</tr>
196<tr class="bold">
197	<td width="16%">
198		<?php echo sprintf( lang_get( 'label' ), $t_lang_id ) ?>
199	</td>
200	<td width="16%">
201		<?php echo sprintf( lang_get( 'label' ), $t_lang_category ) ?>
202	</td>
203	<td width="16%">
204		<?php echo sprintf( lang_get( 'label' ), $t_lang_severity ) ?>
205	</td>
206	<td width="16%">
207		<?php echo sprintf( lang_get( 'label' ), $t_lang_reproducibility ) ?>
208	</td>
209	<td width="16%">
210		<?php echo sprintf( lang_get( 'label' ), $t_lang_date_submitted ) ?>
211	</td>
212	<td width="16%">
213		<?php echo sprintf( lang_get( 'label' ), $t_lang_last_update ) ?>
214	</td>
215</tr>
216<tr>
217	<td>
218		<?php echo $t_id ?>
219	</td>
220	<td>
221		<?php echo '[' . string_display_line( $t_project_name ) . '] ' . string_display_line( $t_category_name ) ?>
222	</td>
223	<td>
224		<?php echo get_enum_element( 'severity', $t_bug->severity, auth_get_current_user_id(), $t_bug->project_id ) ?>
225	</td>
226	<td>
227		<?php echo get_enum_element( 'reproducibility', $t_bug->reproducibility, auth_get_current_user_id(), $t_bug->project_id ) ?>
228	</td>
229	<td>
230		<?php echo date( $t_date_format, $t_bug->date_submitted ) ?>
231	</td>
232	<td>
233		<?php echo date( $t_date_format, $t_bug->last_updated ) ?>
234	</td>
235</tr>
236<tr class="spacer" >
237	<td colspan="6"></td>
238</tr>
239<tr>
240	<td class="bold">
241		<?php echo sprintf( lang_get( 'label' ), $t_lang_reporter ) ?>
242	</td>
243	<td>
244		<?php print_user( $t_bug->reporter_id, false ) ?>
245	</td>
246	<td class="bold">
247		<?php echo sprintf( lang_get( 'label' ), $t_lang_platform ) ?>
248	</td>
249	<td>
250		<?php echo string_display_line( $t_bug->platform ) ?>
251	</td>
252<?php if( access_has_bug_level( config_get( 'due_date_view_threshold' ), $t_id ) ) { ?>
253	<td class="bold">
254		<?php echo sprintf( lang_get( 'label' ), $t_lang_due_date ) ?>
255	</td>
256<?php
257		if( bug_is_overdue( $t_id ) ) { ?>
258		<td class="bold">
259<?php
260		} else { ?>
261		<td>
262<?php
263		}
264		if( !date_is_null( $t_bug->due_date ) ) {
265				echo date( $t_short_date_format, $t_bug->due_date );
266		print "\t\t</td>\n";
267		}
268	} else {
269?>
270	<td colspan="2">&#160;</td>
271<?php } ?>
272</tr>
273<tr>
274	<td class="bold">
275		<?php echo sprintf( lang_get( 'label' ), $t_lang_assigned_to ) ?>
276	</td>
277	<td>
278		<?php
279			if( access_has_bug_level( config_get( 'view_handler_threshold' ), $t_id ) ) {
280				print_user( $t_bug->handler_id, false );
281			}
282		?>
283	</td>
284	<td class="bold">
285		<?php echo sprintf( lang_get( 'label' ), $t_lang_os ) ?>
286	</td>
287	<td>
288		<?php echo string_display_line( $t_bug->os ) ?>
289	</td>
290	<td colspan="2">&#160;</td>
291</tr>
292<tr>
293	<td class="bold">
294		<?php echo sprintf( lang_get( 'label' ), $t_lang_priority ) ?>
295	</td>
296	<td>
297		<?php echo get_enum_element( 'priority', $t_bug->priority, auth_get_current_user_id(), $t_bug->project_id ) ?>
298	</td>
299	<td class="bold">
300		<?php echo sprintf( lang_get( 'label' ), $t_lang_os_build ) ?>
301	</td>
302	<td>
303		<?php echo string_display_line( $t_bug->os_build ) ?>
304	</td>
305	<td colspan="2">&#160;</td>
306</tr>
307<tr>
308	<td class="bold">
309		<?php echo sprintf( lang_get( 'label' ), $t_lang_status ) ?>
310	</td>
311	<td>
312		<?php echo get_enum_element( 'status', $t_bug->status, auth_get_current_user_id(), $t_bug->project_id ) ?>
313	</td>
314	<td class="bold">
315		<?php echo sprintf( lang_get( 'label' ), $t_lang_product_version ) ?>
316	</td>
317	<td>
318		<?php echo string_display_line( $t_bug->version ) ?>
319	</td>
320	<td colspan="2">&#160;</td>
321</tr>
322<tr>
323	<td class="bold">
324		<?php echo sprintf( lang_get( 'label' ), $t_lang_product_build ) ?>
325	</td>
326	<td>
327		<?php echo string_display_line( $t_bug->build ) ?>
328	</td>
329	<td class="bold">
330		<?php echo sprintf( lang_get( 'label' ), $t_lang_resolution ) ?>
331	</td>
332	<td>
333		<?php echo get_enum_element( 'resolution', $t_bug->resolution, auth_get_current_user_id(), $t_bug->project_id ) ?>
334	</td>
335	<td colspan="2">&#160;</td>
336</tr>
337<tr>
338	<td class="bold">
339		<?php echo sprintf( lang_get( 'label' ), $t_lang_projection ) ?>
340	</td>
341	<td>
342		<?php echo get_enum_element( 'projection', $t_bug->projection, auth_get_current_user_id(), $t_bug->project_id ) ?>
343	</td>
344	<td class="bold">
345		&#160;
346	</td>
347	<td>
348		&#160;
349	</td>
350	<td colspan="2">&#160;</td>
351</tr>
352<tr>
353	<td class="bold">
354		<?php echo sprintf( lang_get( 'label' ), $t_lang_eta ) ?>
355	</td>
356	<td>
357		<?php echo get_enum_element( 'eta', $t_bug->eta, auth_get_current_user_id(), $t_bug->project_id ) ?>
358	</td>
359	<td class="bold">
360		<?php echo sprintf( lang_get( 'label' ), $t_lang_fixed_in_version ) ?>
361	</td>
362	<td>
363		<?php echo string_display_line( $t_bug->fixed_in_version ) ?>
364	</td>
365	<td colspan="2">&#160;</td>
366
367</tr>
368<tr>
369	<td class="bold">
370		&#160;
371	</td>
372	<td>
373		&#160;
374	</td>
375	<td class="bold">
376		<?php echo sprintf( lang_get( 'label' ), $t_lang_target_version ) ?>
377	</td>
378	<td>
379		<?php echo string_display_line( $t_bug->target_version ) ?>
380	</td>
381	<td colspan="2">&#160;</td>
382</tr>
383<?php
384$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->project_id );
385foreach( $t_related_custom_field_ids as $t_custom_field_id ) {
386	# Don't display the field if user does not have read access to it
387	if( !custom_field_has_read_access_by_project_id( $t_custom_field_id, $t_bug->project_id ) ) {
388		continue;
389	}
390
391	$t_def = custom_field_get_definition( $t_custom_field_id );
392?>
393<tr>
394	<td class="bold">
395		<?php echo string_display_line( sprintf( lang_get( 'label' ), lang_get_defaulted( $t_def['name'] ) ) ) ?>
396	</td>
397	<td colspan="5">
398		<?php print_custom_field_value( $t_def, $t_custom_field_id, $t_id ); ?>
399	</td>
400</tr>
401<?php
402}       # foreach
403?>
404<tr class="spacer" >
405	<td colspan="6"></td>
406</tr>
407<tr>
408	<td class="bold">
409		<?php echo sprintf( lang_get( 'label' ), $t_lang_summary ) ?>
410	</td>
411	<td colspan="5">
412		<?php echo string_display_line_links( $t_bug->summary ) ?>
413	</td>
414</tr>
415<tr>
416	<td class="bold">
417		<?php echo sprintf( lang_get( 'label' ), $t_lang_description ) ?>
418	</td>
419	<td colspan="5">
420		<?php echo string_display_links( $t_bug->description ) ?>
421	</td>
422</tr>
423<?php if( $t_show_tags ) { ?>
424<tr>
425	<td class="print">
426		<?php echo sprintf( lang_get( 'label' ), $t_lang_tags ) ?>
427	</td>
428	<td colspan="5">
429		<?php echo string_display_links( tag_bug_get_all( $t_bug->id ) ) ?>
430	</td>
431</tr>
432<?php }?>
433<tr>
434	<td class="bold">
435		<?php echo sprintf( lang_get( 'label' ), $t_lang_steps_to_reproduce ) ?>
436	</td>
437	<td colspan="5">
438		<?php echo string_display_links( $t_bug->steps_to_reproduce ) ?>
439	</td>
440</tr>
441<tr>
442	<td class="bold">
443		<?php echo sprintf( lang_get( 'label' ), $t_lang_additional_information ) ?>
444	</td>
445	<td colspan="5">
446		<?php echo string_display_links( $t_bug->additional_information ) ?>
447	</td>
448</tr>
449<?php
450	# account profile description
451	if( $t_bug->profile_id > 0 ) {
452		$t_profile_row = profile_get_row( $t_bug->profile_id );
453		$t_profile_description = string_display( $t_profile_row['description'] );
454
455?>
456<tr>
457	<td class="bold">
458		<?php echo $t_lang_system_profile ?>
459	</td>
460	<td colspan="5">
461		<?php echo $t_profile_description ?>
462	</td>
463</tr>
464<?php
465} # profile description
466?>
467<tr>
468	<td class="bold">
469		<?php echo sprintf( lang_get( 'label' ), $t_lang_attached_files ) ?>
470	</td>
471	<td colspan="5">
472		<?php
473			$t_attachments = file_get_visible_attachments( $t_id );
474			$t_first_attachment = true;
475			$t_path = config_get_global( 'path' );
476
477			foreach ( $t_attachments as $t_attachment  ) {
478				if( $t_first_attachment ) {
479					$t_first_attachment = false;
480				} else {
481					echo '<br />';
482				}
483
484				$c_filename = string_display_line( $t_attachment['display_name'] );
485				$c_download_url = htmlspecialchars( $t_attachment['download_url'] );
486				$c_filesize = number_format( $t_attachment['size'] );
487				$c_date_added = date( $t_date_format, $t_attachment['date_added'] );
488				echo $c_filename . ' (' . $c_filesize . ' ' . lang_get( 'bytes' )
489					. ') <span class="italic-small">' . $c_date_added . '</span><br />'
490					. string_display_line_links( $t_path . $c_download_url );
491
492				if( $t_attachment['preview'] && $t_attachment['type'] == 'image' && $f_type_page == 'html' ) {
493					echo '<br /><img src="', $c_download_url, '" alt="', $t_attachment['alt'], '" /><br />';
494				}
495			}
496		?>
497	</td>
498</tr>
499
500<tr class="spacer"><td colspan="6"></td></tr>
501</table>
502
503<?php
504$t_user_bugnote_limit = 0;
505
506$t_bugnotes = bugnote_get_all_visible_bugnotes( $t_id, $t_user_bugnote_order, $t_user_bugnote_limit );
507?>
508
509<table class="table table-striped table-bordered table-condensed no-margin small">
510<?php
511	# no bugnotes
512	if( 0 == count( $t_bugnotes ) ) {
513	?>
514<tr>
515	<td class="bold" colspan="2">
516		<?php echo $t_lang_no_bugnotes_msg ?>
517	</td>
518</tr>
519<?php
520	} else { # print bugnotes ?>
521<tr>
522	<td class="bold" colspan="2">
523			<?php echo $t_lang_bug_notes_title ?>
524	</td>
525</tr>
526	<?php
527		foreach ( $t_bugnotes as $t_bugnote ) {
528			# prefix all bugnote data with v3_
529			$t_date_submitted = date( $t_date_format, $t_bugnote->date_submitted );
530			$t_last_modified = date( $t_date_format, $t_bugnote->last_modified );
531
532			# grab the bugnote text and id and prefix with v3_
533			$t_note = string_display_links( $t_bugnote->note );
534	?>
535<tr>
536	<td width="12%">
537				(<?php echo bugnote_format_id( $t_bugnote->id ) ?>)
538			<br />
539				<?php print_user( $t_bugnote->reporter_id, false ) ?>&#160;&#160;&#160;
540			<br />
541				<?php echo $t_date_submitted ?>&#160;&#160;&#160;
542				<?php if( $t_bugnote->date_submitted != $t_bugnote->last_modified ) {
543					echo '<br />(' . lang_get( 'last_edited') . lang_get( 'word_separator' ) . $t_last_modified . ')';
544				} ?>
545			</td>
546	<td>
547<?php
548					switch ( $t_bugnote->note_type ) {
549						case REMINDER:
550							echo lang_get( 'reminder_sent_to' ) . ': ';
551							$t_note_attr = mb_substr( $t_bugnote->note_attr, 1, mb_strlen( $t_bugnote->note_attr ) - 2 );
552							$t_to = array();
553							foreach ( explode( '|', $t_note_attr ) as $t_recipient ) {
554								$t_to[] = prepare_user_name( $t_recipient );
555							}
556							echo implode( ', ', $t_to ) . '<br />';
557						default:
558							echo string_display_links( $t_bugnote->note );
559					}
560				?>
561			</td>
562		</tr>
563		<tr class="spacer"><td colspan="2"></td></tr>
564<?php
565		} # end for
566	} # end else
567?>
568</table>
569
570<?php # Bugnotes END ?>
571
572
573<?php
574		if( $f_type_page != 'html' ) {
575			echo '<hr>';
576		}
577	} # end in_array
578}  # end main loop
579
580layout_body_javascript();
581html_body_end();
582html_end();
583