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 * This page allows users to add a new profile which is POSTed to
19 * account_prof_add.php
20 *
21 * Users can also manage their profiles
22 *
23 * @package MantisBT
24 * @copyright Copyright 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
25 * @copyright Copyright 2002  MantisBT Team - mantisbt-dev@lists.sourceforge.net
26 * @link http://www.mantisbt.org
27 *
28 * @uses core.php
29 * @uses access_api.php
30 * @uses authentication_api.php
31 * @uses config_api.php
32 * @uses constant_inc.php
33 * @uses current_user_api.php
34 * @uses form_api.php
35 * @uses html_api.php
36 * @uses lang_api.php
37 * @uses print_api.php
38 * @uses profile_api.php
39 */
40
41require_once( 'core.php' );
42require_api( 'access_api.php' );
43require_api( 'authentication_api.php' );
44require_api( 'config_api.php' );
45require_api( 'constant_inc.php' );
46require_api( 'current_user_api.php' );
47require_api( 'form_api.php' );
48require_api( 'html_api.php' );
49require_api( 'lang_api.php' );
50require_api( 'print_api.php' );
51require_api( 'profile_api.php' );
52
53if( !config_get( 'enable_profiles' ) ) {
54	trigger_error( ERROR_ACCESS_DENIED, ERROR );
55}
56
57if( isset( $g_global_profiles ) ) {
58	$g_global_profiles = true;
59} else {
60	$g_global_profiles = false;
61}
62
63auth_ensure_user_authenticated();
64current_user_ensure_unprotected();
65
66$t_manage_global_profile_threshold = config_get( 'manage_global_profile_threshold' );
67$t_can_manage_global_profile = access_has_global_level( $t_manage_global_profile_threshold );
68if( $g_global_profiles ) {
69	access_ensure_global_level( $t_manage_global_profile_threshold );
70} else {
71	access_ensure_global_level( config_get( 'add_profile_threshold' ) );
72}
73
74layout_page_header( lang_get( 'manage_profiles_link' ) );
75
76if( $g_global_profiles ) {
77	layout_page_begin( 'manage_overview_page.php' );
78	print_manage_menu( 'manage_prof_menu_page.php' );
79} else {
80	layout_page_begin();
81}
82
83if( $g_global_profiles ) {
84	$t_user_id = ALL_USERS;
85} else {
86	$t_user_id = auth_get_current_user_id();
87	print_account_menu( 'account_prof_menu_page.php' );
88}
89?>
90
91<div class="col-md-12 col-xs-12">
92
93<?php
94	# Profiles list BEGIN
95	$t_profiles = profile_get_all_for_user( $t_user_id );
96	if( $t_profiles ) {
97?>
98<div class="space-10"></div>
99<div id="categories" class="form-container">
100	<div class="widget-box widget-color-blue2">
101		<div class="widget-header widget-header-small">
102			<h4 class="widget-title lighter">
103				<?php print_icon( 'fa-file-o', 'ace-icon' ); ?>
104				<?php echo lang_get( 'manage_profiles_link' ) ?>
105			</h4>
106		</div>
107		<div class="widget-body">
108			<div class="widget-main no-padding">
109				<div class="table-responsive">
110					<table class="table table-striped table-bordered table-condensed table-hover">
111						<thead>
112							<tr>
113								<th><?php echo lang_get( 'platform' ) ?></th>
114								<th><?php echo lang_get( 'os' ) ?></th>
115								<th><?php echo lang_get( 'os_build' ) ?></th>
116<?php
117			if( !$g_global_profiles ) {
118?>
119								<th><?php echo lang_get( 'global_profile' ) ?></th>
120								<th><?php echo lang_get( 'default_profile' ) ?></th>
121<?php
122			}
123?>
124								<th class="center"><?php echo lang_get( 'actions' ) ?></th>
125							</tr>
126						</thead>
127
128						<tbody>
129<?php
130			$t_security_token = form_security_token( 'account_prof_update' );
131			$t_default_profile = current_user_get_pref( 'default_profile' );
132
133			foreach( $t_profiles as $t_profile ) {
134				/**
135				 * @var $v_id
136				 * @var $v_user_id
137				 * @var $v_platform
138				 * @var $v_os
139				 * @var $v_os_build
140				 */
141				extract( $t_profile, EXTR_PREFIX_ALL, 'v' );
142				$t_is_global_profile = $v_user_id == ALL_USERS;
143				$t_is_default_profile = $t_default_profile == $v_id
144?>
145							<tr>
146								<td><?php echo string_display_line( $v_platform ); ?></td>
147								<td><?php echo string_display_line( $v_os ); ?></td>
148								<td><?php echo string_display_line( $v_os_build );  ?></td>
149<?php
150				if( !$g_global_profiles ) {
151?>
152								<td class="center">
153									<?php if( $t_is_global_profile ) { ?>
154									<?php print_icon( 'fa-check', 'ace-icon fa-lg' ); ?>
155									<?php } ?>
156								</td>
157								<td class="center">
158									<?php if( $t_is_default_profile ) { ?>
159									<?php print_icon( 'fa-check', 'ace-icon fa-lg' ); ?>
160									<?php } ?>
161								</td>
162<?php
163				}
164?>
165								<td class="center">
166									<div class="btn-group inline">
167<?php
168				# Common POST parameters for action buttons
169				$t_param = array(
170					'profile_id' => $v_id,
171					'redirect' => basename( $_SERVER["SCRIPT_FILENAME"] ),
172				);
173
174				# Print the Edit and Delete buttons for local profiles, or
175				# if user can manage global ones.
176				if( !$t_is_global_profile || $t_can_manage_global_profile ) {
177					echo '<div class="pull-left">';
178					print_form_button(
179						'account_prof_edit_page.php',
180						lang_get( 'edit' ),
181						$t_param
182					);
183					echo '</div>';
184
185					echo '<div class="pull-left">';
186					print_form_button(
187						'account_prof_update.php',
188						lang_get( 'delete' ),
189						array_merge( $t_param, array( 'action' => 'delete' ) ),
190						$t_security_token
191					);
192					echo '</div>';
193				}
194
195				# Make / Clear Default button
196				if( !$g_global_profiles ) {
197					echo '<div class="pull-left">';
198					if( $t_is_default_profile ) {
199						$t_param['profile_id'] = 0;
200					}
201					print_form_button(
202						'account_prof_update.php',
203						lang_get( $t_is_default_profile ? 'clear_default' : 'make_default' ),
204						array_merge( $t_param, array( 'action' => 'make_default' ) ),
205						$t_security_token
206					);
207					echo '</div>';
208				}
209
210
211				echo '<div class="pull-left">';
212				echo '</div>';
213?>
214									</div>
215								</td>
216							</tr>
217<?php
218			} # end foreach profile
219?>
220						</tbody>
221					</table>
222				</div>
223			</div>
224		</div>
225	</div>
226</div>
227
228<?php
229	} # end if profiles
230	# Profiles list END
231
232	# Add Profile Form BEGIN
233?>
234
235<div class="space-10"></div>
236<div id="account-profile-div" class="form-container">
237	<form id="account-profile-form" method="post" action="account_prof_update.php">
238		<fieldset>
239			<?php  echo form_security_field( 'account_prof_update' )?>
240			<input type="hidden" name="action" value="add" />
241			<input type="hidden" name="user_id" value="<?php echo $t_user_id ?>" />
242
243			<div class="widget-box widget-color-blue2">
244
245				<div class="widget-header widget-header-small">
246					<h4 class="widget-title lighter">
247						<?php print_icon( 'fa-file-o', 'ace-icon' ); ?>
248						<?php echo lang_get( 'add_profile' ) ?>
249					</h4>
250				</div>
251
252				<div class="widget-body">
253					<div class="widget-main no-padding">
254						<div class="table-responsive">
255							<table class="table table-bordered table-condensed table-striped">
256								<tr>
257									<td class="category">
258										<span class="required">*</span>
259										<label for="platform">
260											<?php echo lang_get( 'platform' ) ?>
261										</label>
262									</td>
263									<td>
264										<input type="text" class="input-sm"
265											   id="platform" name="platform"
266											   size="32" maxlength="32" required />
267									</td>
268								</tr>
269								<tr>
270									<td class="category">
271										<span class="required">*</span>
272										<label for="os">
273											<?php echo lang_get( 'os' ) ?>
274										</label>
275									</td>
276									<td>
277										<input type="text" class="input-sm"
278											   id="os" name="os"
279											   size="32" maxlength="32" required />
280									</td>
281								</tr>
282								<tr>
283									<td class="category">
284										<span class="required">*</span>
285										<label for="os_build">
286											<?php echo lang_get( 'os_build' ) ?>
287										</label>
288									</td>
289									<td>
290										<input type="text" class="input-sm"
291											   id="os_build" name="os_build"
292											   size="16" maxlength="16" required />
293									</td>
294								</tr>
295								<tr>
296									<td class="category">
297										<label for="description">
298											<?php echo lang_get( 'profile_description' ) ?>
299										</label>
300									</td>
301									<td>
302									<textarea  id="description" name="description"
303											   class="form-control"
304											   cols="80" rows="8"></textarea>
305									</td>
306								</tr>
307							</table>
308						</div>
309					</div>
310				</div>
311
312				<div class="widget-toolbox padding-8 clearfix">
313				<span class="required pull-right">
314					* <?php echo lang_get( 'required' ); ?>
315				</span>
316					<button class="btn btn-primary btn-white btn-round">
317						<?php echo lang_get('add_profile'); ?>
318					</button>
319				</div>
320			</div>
321		</fieldset>
322	</form>
323</div>
324
325</div>
326<?php
327layout_page_end();
328