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 * Manage Filter Page
19 *
20 * @package MantisBT
21 * @copyright Copyright 2016  MantisBT Team - mantisbt-dev@lists.sourceforge.net
22 * @link http://www.mantisbt.org
23 *
24 * @uses core.php
25 * @uses authentication_api.php
26 * @uses compress_api.php
27 * @uses config_api.php
28 * @uses database_api.php
29 * @uses filter_api.php
30 * @uses helper_api.php
31 * @uses html_api.php
32 * @uses lang_api.php
33 * @uses print_api.php
34 * @uses rss_api.php
35 */
36
37require_once( 'core.php' );
38require_api( 'authentication_api.php' );
39require_api( 'compress_api.php' );
40require_api( 'config_api.php' );
41require_api( 'database_api.php' );
42require_api( 'filter_api.php' );
43require_api( 'helper_api.php' );
44require_api( 'html_api.php' );
45require_api( 'lang_api.php' );
46require_api( 'print_api.php' );
47require_api( 'rss_api.php' );
48
49auth_ensure_user_authenticated();
50
51layout_page_header( lang_get('manage_filter_page_title' ) );
52
53layout_page_begin( 'manage_filter_page.php' );
54
55$t_project_id = helper_get_current_project();
56$t_user_id = auth_get_current_user_id();
57
58if( !access_has_project_level( config_get( 'stored_query_use_threshold' ) ) ) {
59	access_denied();
60}
61
62$t_filter_ids_available =
63		filter_db_get_named_filters( ALL_PROJECTS, $t_user_id, false ) +
64		filter_db_get_named_filters( ALL_PROJECTS, null, true ) +
65		filter_db_get_named_filters( $t_project_id, $t_user_id, false ) +
66		filter_db_get_named_filters( $t_project_id, null, true )
67		;
68filter_cache_rows( $t_filter_ids_available );
69
70$t_rss_enabled = config_get( 'rss_enabled' );
71
72function table_print_filter_headers() {
73	global $t_rss_enabled;
74?>
75	<thead>
76		<tr>
77			<th><?php echo lang_get( 'query_name' ) ?></td>
78			<?php if( $t_rss_enabled ) { ?>
79				<th><?php echo lang_get( 'rss' ) ?></td>
80			<?php } ?>
81			<th><?php echo lang_get( 'email_project' ) ?></td>
82			<th><?php echo lang_get( 'public' ) ?></td>
83			<th><?php echo lang_get( 'owner' ) ?></td>
84			<th><?php echo lang_get( 'actions' ) ?></td>
85		</tr>
86	</thead>
87<?php
88}
89
90function table_print_filter_row( $p_filter_id ) {
91	global $t_rss_enabled;
92	$t_editable = filter_db_can_delete_filter( $p_filter_id );
93	echo '<tr>';
94	# Filter name
95	echo '<td>';
96	$t_name = string_display_line( filter_get_field( $p_filter_id, 'name' ) );
97	print_link( 'view_filters_page.php?filter_id=' . $p_filter_id, $t_name );
98	echo '</td>';
99	# RSS
100	if( $t_rss_enabled ) {
101		echo '<td class="center">';
102		print_rss( rss_get_issues_feed_url( null, null, $p_filter_id ), lang_get( 'rss' ) );
103		echo '</td>';
104	}
105	# Project
106	echo '<td>' . string_display_line( project_get_name( filter_get_field( $p_filter_id, 'project_id' ) ) ) . '</td>';
107	# Public
108	echo '<td class="center">' . trans_bool( filter_get_field( $p_filter_id, 'is_public' ) ) . '</td>';
109	# Owner
110	echo '<td>' . user_get_name( filter_get_field( $p_filter_id, 'user_id' ) ) . '</td>';
111	# Actions
112	echo '<td>';
113	echo '<div class="pull-left">';
114	print_form_button( 'view_all_set.php', lang_get( 'apply_filter_button' ), array( 'type' => 3, 'source_query_id' =>  $p_filter_id ), /* security token */ OFF );
115	echo '</div>';
116	if( $t_editable ) {
117		echo '<div class="pull-left">';
118		print_form_button( 'manage_filter_edit_page.php', lang_get( 'edit' ), array( 'filter_id' =>  $p_filter_id ) );
119		echo '</div>';
120		echo '<div class="pull-left">';
121		print_form_button( 'manage_filter_delete.php', lang_get( 'delete' ), array( 'filter_id' =>  $p_filter_id ) );
122		echo '</div>';
123	}
124	echo '</div>';
125	echo '</td>';
126	echo '</tr>';
127}
128
129function table_print_filters( array $p_filter_array ) {
130	?>
131	<table class="table table-striped table-bordered table-condensed table-hover">
132		<?php table_print_filter_headers() ?>
133		<tbody>
134		<?php
135			foreach( $p_filter_array as $t_id => $t_name ) {
136				if( !is_blank( $t_name ) ) {
137					table_print_filter_row( $t_id );
138				}
139			}
140		?>
141		</tbody>
142	</table>
143	<?php
144}
145
146?>
147
148<div class="col-md-12 col-xs-12">
149	<div class="space-10"></div>
150
151	<div class="widget-box widget-color-blue2">
152		<div class="widget-header widget-header-small">
153			<h4 class="widget-title lighter">
154				<?php print_icon( 'fa-filter', 'ace-icon' ); ?>
155				<?php echo lang_get('available_filter_for_project') . ': ' . string_display_line( project_get_name( $t_project_id ) ) ?>
156			</h4>
157		</div>
158
159		<div class="widget-main no-padding">
160			<div class="table-responsive">
161			<?php
162			if( count( $t_filter_ids_available ) > 0 ) {
163				table_print_filters( $t_filter_ids_available );
164			}
165			?>
166			</div>
167		</div>
168	</div>
169</div>
170<?php
171
172layout_page_end();