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 * Project Document 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 config_api.php
29 * @uses constant_inc.php
30 * @uses database_api.php
31 * @uses file_api.php
32 * @uses gpc_api.php
33 * @uses helper_api.php
34 * @uses html_api.php
35 * @uses lang_api.php
36 * @uses print_api.php
37 * @uses project_api.php
38 * @uses string_api.php
39 * @uses user_api.php
40 */
41
42require_once( 'core.php' );
43require_api( 'access_api.php' );
44require_api( 'authentication_api.php' );
45require_api( 'config_api.php' );
46require_api( 'constant_inc.php' );
47require_api( 'database_api.php' );
48require_api( 'file_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( 'project_api.php' );
55require_api( 'string_api.php' );
56require_api( 'user_api.php' );
57
58$f_project_id = gpc_get_int( 'project_id', helper_get_current_project() );
59
60# Check if project documentation feature is enabled.
61if( OFF == config_get( 'enable_project_documentation' ) || !file_is_uploading_enabled() ) {
62	access_denied();
63}
64
65# Override the current page to make sure we get the appropriate project-specific configuration
66$g_project_override = $f_project_id;
67
68$t_user_id = auth_get_current_user_id();
69$t_pub = VS_PUBLIC;
70$t_priv = VS_PRIVATE;
71$t_admin = config_get_global( 'admin_site_threshold' );
72
73if( $f_project_id == ALL_PROJECTS ) {
74	# Select all the projects that the user has access to
75	$t_projects = user_get_accessible_projects( $t_user_id );
76} else {
77	# Select the specific project
78	$t_projects = array( $f_project_id );
79}
80
81$t_projects[] = ALL_PROJECTS; # add "ALL_PROJECTS to the list of projects to fetch
82
83$t_reqd_access = config_get( 'view_proj_doc_threshold' );
84if( is_array( $t_reqd_access ) ) {
85	if( 1 == count( $t_reqd_access ) ) {
86		$t_access_clause = '= ' . array_shift( $t_reqd_access ) . ' ';
87	} else {
88		$t_access_clause = 'IN (' . implode( ',', $t_reqd_access ) . ')';
89	}
90} else {
91	$t_access_clause = '>= ' . $t_reqd_access . ' ';
92}
93
94$t_query = 'SELECT pft.id, pft.project_id, pft.filename, pft.filesize, pft.title, pft.description, pft.date_added
95			FROM {project_file} pft
96				LEFT JOIN {project} pt ON pft.project_id = pt.id
97				LEFT JOIN {project_user_list} pult
98					ON pft.project_id = pult.project_id AND pult.user_id = ' . db_param() . '
99				LEFT JOIN {user} ut ON ut.id = ' . db_param() . '
100			WHERE pft.project_id in (' . implode( ',', $t_projects ) . ') AND
101				( ( ( pt.view_state = ' . db_param() . ' OR pt.view_state is null ) AND pult.user_id is null AND ut.access_level ' . $t_access_clause . ' ) OR
102					( ( pult.user_id = ' . db_param() . ' ) AND ( pult.access_level ' . $t_access_clause . ' ) ) OR
103					( ut.access_level >= ' . db_param() . ' ) )
104			ORDER BY pt.name ASC, pft.title ASC';
105$t_result = db_query( $t_query, array( $t_user_id, $t_user_id, $t_pub, $t_user_id, $t_admin ) );
106
107layout_page_header( lang_get( 'docs_link' ) );
108
109layout_page_begin( 'proj_doc_page.php' );
110
111print_doc_menu( 'proj_doc_page.php' );
112?>
113
114<div class="col-md-12 col-xs-12">
115<div class="space-10"></div>
116
117<div class="widget-box widget-color-blue2">
118<div class="widget-header widget-header-small">
119	<h4 class="widget-title lighter">
120		<?php print_icon( 'fa-file', 'ace-icon' ); ?>
121		<?php echo lang_get('project_documentation_title') ?>
122	</h4>
123</div>
124
125<div class="widget-body">
126<div class="widget-main">
127<div class="table-responsive">
128<table class="table table-bordered table-condensed table-striped">
129<tr>
130	<th><?php echo lang_get( 'filename' ); ?></th>
131	<th><?php echo lang_get( 'description' ); ?></th>
132</tr>
133
134<?php
135$i = 0;
136while( $t_row = db_fetch_array( $t_result ) ) {
137	$i++;
138	extract( $t_row, EXTR_PREFIX_ALL, 'v' );
139	$v_filesize = number_format( $v_filesize );
140	$v_title = string_display_line( $v_title );
141	$v_description = string_display_links( $v_description );
142	$v_date_added = date( config_get( 'normal_date_format' ), $v_date_added );
143
144?>
145<tr>
146	<td>
147		<span class="pull-left">
148<?php
149	$t_href = '<a href="file_download.php?file_id=' . $v_id . '&amp;type=doc">';
150	echo $t_href;
151	print_file_icon( $v_filename );
152	echo '</a>&#160;' . $t_href . $v_title . '</a> (' . $v_filesize . lang_get( 'word_separator' ) . lang_get( 'bytes' ) . ')';
153?>
154			<br />
155			<span class="small">
156<?php
157	if( $v_project_id == ALL_PROJECTS ) {
158		echo lang_get( 'all_projects' ) . '<br />';
159	} else if( $v_project_id != $f_project_id ) {
160		$t_project_name = project_get_name( $v_project_id );
161		echo $t_project_name . '<br />';
162	}
163	echo '(' . $v_date_added . ')';
164?>
165			</span>
166		</span>
167		<span class="pull-right">
168<?php
169	if( access_has_project_level( config_get( 'upload_project_file_threshold', null, null, $v_project_id ), $v_project_id ) ) {
170		print_link_button( 'proj_doc_edit_page.php?file_id=' . $v_id, lang_get( 'edit' ), 'btn-xs' );
171		echo '&#160;';
172		print_link_button( 'proj_doc_delete.php?file_id=' . $v_id, lang_get( 'delete' ), 'btn-xs' );
173	}
174?>
175		</span>
176	</td>
177	<td>
178		<?php echo $v_description ?>
179	</td>
180</tr>
181<?php
182} # end for loop
183?>
184</table>
185</div>
186</div>
187</div>
188</div>
189</div>
190
191<?php
192layout_page_end();
193