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 include file prints out the list of users sponsoring the current
19 * bug.	$f_bug_id must be set to the bug id
20 *
21 * @package MantisBT
22 * @copyright Copyright 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
23 * @copyright Copyright 2002  MantisBT Team - mantisbt-dev@lists.sourceforge.net
24 * @link http://www.mantisbt.org
25 *
26 * @uses access_api.php
27 * @uses bug_api.php
28 * @uses collapse_api.php
29 * @uses config_api.php
30 * @uses constant_inc.php
31 * @uses current_user_api.php
32 * @uses form_api.php
33 * @uses helper_api.php
34 * @uses lang_api.php
35 * @uses print_api.php
36 * @uses sponsorship_api.php
37 * @uses utility_api.php
38 */
39
40if( !defined( 'BUG_SPONSORSHIP_LIST_VIEW_INC_ALLOW' ) ) {
41	return;
42}
43
44require_api( 'access_api.php' );
45require_api( 'bug_api.php' );
46require_api( 'collapse_api.php' );
47require_api( 'config_api.php' );
48require_api( 'constant_inc.php' );
49require_api( 'current_user_api.php' );
50require_api( 'form_api.php' );
51require_api( 'helper_api.php' );
52require_api( 'lang_api.php' );
53require_api( 'print_api.php' );
54require_api( 'sponsorship_api.php' );
55require_api( 'utility_api.php' );
56
57#
58# Determine whether the sponsorship section should be shown.
59#
60
61if( ( config_get( 'enable_sponsorship' ) == ON ) && ( access_has_bug_level( config_get( 'view_sponsorship_total_threshold' ), $f_bug_id ) ) ) {
62	$t_sponsorship_ids = sponsorship_get_all_ids( $f_bug_id );
63
64	$t_sponsorships_exist = count( $t_sponsorship_ids ) > 0;
65	$t_can_sponsor = !bug_is_readonly( $f_bug_id ) && !current_user_is_anonymous();
66
67	$t_show_sponsorships = $t_sponsorships_exist || $t_can_sponsor;
68} else {
69	$t_show_sponsorships = false;
70}
71
72#
73# Sponsorship Box
74#
75
76if( $t_show_sponsorships ) {
77?>
78
79<a id="sponsorships"></a> <br />
80
81<?php
82	collapse_open( 'sponsorship' );
83?>
84
85<table class="width100" cellspacing="1">
86	<tr>
87		<td width="50" rowspan="3">
88			<?php print_icon( 'fa-usd', '', lang_get( 'sponsor_verb' ) ); ?>
89		</td>
90		<td class="form-title" colspan="2"><?php
91			collapse_icon( 'sponsorship' );
92			echo lang_get( 'users_sponsoring_bug' );
93
94			$t_details_url = lang_get( 'sponsorship_process_url' );
95			if( !is_blank( $t_details_url ) ) {
96				echo '&#160;[<a href="' . $t_details_url . '">'
97					. lang_get( 'sponsorship_more_info' ) . '</a>]';
98			}
99		?>
100		</td>
101	</tr>
102
103<?php
104	if( $t_can_sponsor ) {
105?>
106	<tr>
107		<th class="category" width="15%"><?php echo lang_get( 'sponsor_issue' ) ?></th>
108		<td>
109			<form method="post" action="bug_set_sponsorship.php">
110				<?php echo form_security_field( 'bug_set_sponsorship' ) ?>
111				<?php echo sponsorship_get_currency() ?>
112				<input type="hidden" name="bug_id" value="<?php echo $f_bug_id ?>" size="4" />
113				<input type="text" name="amount" class="input-sm" value="<?php echo config_get( 'minimum_sponsorship_amount' )  ?>" size="4" />
114				<input type="submit" class="btn btn-primary btn-white btn-round" name="sponsor" value="<?php echo lang_get( 'sponsor_verb' ) ?>" />
115			</form>
116		</td>
117	</tr>
118<?php
119	}
120
121	$t_total_sponsorship = bug_get_field( $f_bug_id, 'sponsorship_total' );
122	if( $t_total_sponsorship > 0 ) {
123?>
124	<tr>
125		<th class="category" width="15%"><?php echo lang_get( 'sponsors_list' ) ?></th>
126		<td>
127		<?php
128			echo sprintf( lang_get( 'total_sponsorship_amount' ),
129				sponsorship_format_amount( $t_total_sponsorship ) );
130
131			if( access_has_bug_level( config_get( 'view_sponsorship_details_threshold' ), $f_bug_id ) ) {
132				echo '<br /><br />';
133				$i = 0;
134				foreach ( $t_sponsorship_ids as $t_id ) {
135					$t_sponsorship = sponsorship_get( $t_id );
136					$t_date_added = date( config_get( 'normal_date_format' ), $t_sponsorship->date_submitted );
137
138					echo ($i > 0) ? '<br />' : '';
139					$i++;
140
141					echo sprintf( lang_get( 'label' ), $t_date_added ) . lang_get( 'word_separator' );
142					print_user( $t_sponsorship->user_id );
143					echo ' (' . sponsorship_format_amount( $t_sponsorship->amount ) . ')';
144					if( access_has_bug_level( config_get( 'handle_sponsored_bugs_threshold' ), $f_bug_id ) ) {
145						echo ' ' . get_enum_element( 'sponsorship', $t_sponsorship->paid );
146					}
147				}
148			}
149		?>
150		</td>
151		</tr>
152<?php
153		}
154?>
155</table>
156
157<?php
158	collapse_closed( 'sponsorship' );
159?>
160
161<table class="width100" cellspacing="1">
162	<tr>
163		<td class="form-title"><?php
164			collapse_icon( 'sponsorship' );
165			echo lang_get( 'users_sponsoring_bug' );
166
167			$t_details_url = lang_get( 'sponsorship_process_url' );
168			if( !is_blank( $t_details_url ) ) {
169				echo '&#160;[<a href="' . $t_details_url . '">'
170					. lang_get( 'sponsorship_more_info' ) . '</a>]';
171			}
172
173			if( $t_total_sponsorship > 0 ) {
174				echo ' <span style="font-weight: normal;">(';
175				echo sprintf( lang_get( 'total_sponsorship_amount' ),
176				sponsorship_format_amount( $t_total_sponsorship ) );
177				echo ')</span>';
178			}
179?>
180		</td>
181	</tr>
182</table>
183
184<?php
185	collapse_end( 'sponsorship' );
186} # If sponsorship enabled
187