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 * My View Page
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 access_api.php
27 * @uses authentication_api.php
28 * @uses category_api.php
29 * @uses compress_api.php
30 * @uses config_api.php
31 * @uses constant_inc.php
32 * @uses current_user_api.php
33 * @uses gpc_api.php
34 * @uses helper_api.php
35 * @uses html_api.php
36 * @uses lang_api.php
37 * @uses print_api.php
38 * @uses user_api.php
39 */
40
41require_once( 'core.php' );
42require_api( 'access_api.php' );
43require_api( 'authentication_api.php' );
44require_api( 'category_api.php' );
45require_api( 'compress_api.php' );
46require_api( 'config_api.php' );
47require_api( 'constant_inc.php' );
48require_api( 'current_user_api.php' );
49require_api( 'gpc_api.php' );
50require_api( 'helper_api.php' );
51require_api( 'html_api.php' );
52require_api( 'lang_api.php' );
53require_api( 'print_api.php' );
54require_api( 'user_api.php' );
55require_api( 'layout_api.php' );
56require_css( 'status_config.php' );
57
58auth_ensure_user_authenticated();
59
60$t_current_user_id = auth_get_current_user_id();
61$t_current_project_id = helper_get_current_project();
62
63# Improve performance by caching category data in one pass
64category_get_all_rows( $t_current_project_id );
65
66compress_enable();
67
68# don't index my view page
69html_robots_noindex();
70
71layout_page_header_begin( lang_get( 'my_view_link' ) );
72
73$t_refresh_delay = current_user_get_pref( 'refresh_delay' );
74if( $t_refresh_delay > 0 ) {
75	html_meta_redirect( 'my_view_page.php?refresh=true', $t_refresh_delay * 60 );
76}
77
78layout_page_header_end();
79
80layout_page_begin( __FILE__ );
81
82$f_page_number = gpc_get_int( 'page_number', 1 );
83
84$t_per_page = config_get( 'my_view_bug_count' );
85$t_bug_count = null;
86$t_page_count = null;
87
88# The projects that need to be evaluated are those that will be included in the filters
89# used for each box. At this point, those filter are created for "current" project, and
90# may include subprojects, or not, based on the default "_view_type" property
91# Unless these following checks are redesigned to account for the actual filters used,
92# we will assume if subprojects are included by inspecting a default filter for current project.
93if( $t_current_project_id == ALL_PROJECTS ) {
94	$t_project_ids_to_check = null;
95} else {
96	# this creates a filter with the specific project informes, in the same way that
97	# those that will be used later for the boxes
98	$t_test_filter = filter_ensure_valid_filter( array( FILTER_PROPERTY_PROJECT_ID => [$t_current_project_id]) );
99	$t_project_ids_to_check = filter_get_included_projects( $t_test_filter );
100}
101
102# Retrieve the boxes to display
103# - exclude hidden boxes per configuration (order == 0)
104# - remove boxes that do not make sense in the user's context (access level)
105$t_boxes = array_filter( config_get( 'my_view_boxes' ) );
106$t_anonymous_user = current_user_is_anonymous();
107foreach( $t_boxes as $t_box_title => $t_box_display ) {
108	if( # Remove "Assigned to Me" box for users that can't handle issues
109		(  $t_box_title == 'assigned'
110		&& (  $t_anonymous_user
111		   || !access_has_any_project_level('handle_bug_threshold', $t_project_ids_to_check, $t_current_user_id )
112		   )
113		) ||
114		# Remove "Monitored by Me" box for users that can't monitor issues
115		(  $t_box_title == 'monitored'
116		&& (  $t_anonymous_user
117		   || !access_has_any_project_level( 'monitor_bug_threshold', $t_project_ids_to_check, $t_current_user_id )
118		   )
119		) ||
120		# Remove display of "Reported by Me", "Awaiting Feedback" and
121		# "Awating confirmation of resolution" boxes for users that can't report bugs
122		(  in_array( $t_box_title, array( 'reported', 'feedback', 'verify' ) )
123		&& (  $t_anonymous_user
124		   || !access_has_any_project_level( 'report_bug_threshold', $t_project_ids_to_check, $t_current_user_id )
125		   )
126		)
127	) {
128		unset( $t_boxes[$t_box_title] );
129	}
130}
131asort( $t_boxes );
132
133$t_timeline_view_threshold_access = access_has_any_project_level( config_get( 'timeline_view_threshold' ), $t_project_ids_to_check, $t_current_user_id );
134$t_timeline_view_class = ( $t_timeline_view_threshold_access ) ? "col-md-7" : "col-md-6";
135?>
136<div class="col-xs-12 <?php echo $t_timeline_view_class ?>">
137
138<?php
139define( 'MY_VIEW_INC_ALLOW', true );
140
141# Determine the box number where column 2 should start
142# Use shift-right bitwise operator to divide by 2 as integer
143$t_column2_start = ( count( $t_boxes ) + 1 ) >> 1;
144
145$t_counter = 0;
146foreach( $t_boxes as $t_box_title => $t_box_display ) {
147    # If timeline is OFF, display boxes on 2 columns
148    if( !$t_timeline_view_threshold_access && $t_counter++ == $t_column2_start ) {
149        # End of 1st column
150        echo '</div>';
151        echo '<div class="col-xs-12 col-md-6">';
152    }
153    include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'my_view_inc.php' );
154    echo '<div class="space-10"></div>';
155}
156?>
157</div>
158
159<?php if( $t_timeline_view_threshold_access ) { ?>
160<div class="col-xs-12 col-md-5">
161	<?php
162		# Build a simple filter that gets all bugs for current project
163		$g_timeline_filter = array();
164		$g_timeline_filter[FILTER_PROPERTY_HIDE_STATUS] = array( META_FILTER_NONE );
165		$g_timeline_filter = filter_ensure_valid_filter( $g_timeline_filter );
166		include( $g_core_path . 'timeline_inc.php' );
167	?>
168	<div class="space-10"></div>
169</div>
170<?php }
171layout_page_end();
172