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 file turns monitoring on or off for a bug for the current user
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 form_api.php
28 * @uses gpc_api.php
29 * @uses helper_api.php
30 * @uses print_api.php
31 * @uses utility_api.php
32 */
33
34require_once( 'core.php' );
35require_api( 'error_api.php' );
36require_api( 'form_api.php' );
37require_api( 'gpc_api.php' );
38require_api( 'helper_api.php' );
39require_api( 'print_api.php' );
40require_api( 'utility_api.php' );
41
42form_security_validate( 'bug_monitor_add' );
43
44$f_bug_id = gpc_get_int( 'bug_id' );
45$f_usernames = trim( gpc_get_string( 'user_to_add', '' ) );
46
47$t_payload = array();
48
49if( !is_blank( $f_usernames ) ) {
50	$t_usernames = preg_split( '/[,|]/', $f_usernames, -1, PREG_SPLIT_NO_EMPTY );
51	$t_users = array();
52	foreach( $t_usernames as $t_username ) {
53		$t_users[] = array( 'name_or_realname' => trim( $t_username ) );
54	}
55
56	$t_payload['users'] = $t_users;
57}
58
59$t_data = array(
60	'query' => array( 'issue_id' => $f_bug_id ),
61	'payload' => $t_payload,
62);
63
64$t_command = new MonitorAddCommand( $t_data );
65$t_command->execute();
66
67form_security_purge( 'bug_monitor_add' );
68
69print_successful_redirect_to_bug( $f_bug_id );
70