Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / account_sponsor_page.php
blob64a4b22c1e63720ae32f5cc730c2050dccf42e14
1 <?php
2 # MantisBT - A PHP based bugtracking system
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.
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.
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/>.
17 /**
18 * CALLERS
19 * This page is called from:
20 * - print_menu()
21 * - print_account_menu()
23 * EXPECTED BEHAVIOUR
24 * - Display the user's current sponsorships
25 * - Allow the user to edit the payment flag
27 * CALLS
28 * This page calls the following pages:
29 * - account_sponsor_update.php (to save changes)
31 * RESTRICTIONS & PERMISSIONS
32 * - User must be authenticated, and not anonymous
33 * - sponsorship must be enabled
35 * @package MantisBT
36 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
37 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
38 * @link http://www.mantisbt.org
40 * @uses core.php
41 * @uses access_api.php
42 * @uses authentication_api.php
43 * @uses bug_api.php
44 * @uses config_api.php
45 * @uses constant_inc.php
46 * @uses current_user_api.php
47 * @uses database_api.php
48 * @uses form_api.php
49 * @uses gpc_api.php
50 * @uses helper_api.php
51 * @uses html_api.php
52 * @uses lang_api.php
53 * @uses print_api.php
54 * @uses project_api.php
55 * @uses sponsorship_api.php
56 * @uses string_api.php
57 * @uses version_api.php
60 require_once( 'core.php' );
61 require_api( 'access_api.php' );
62 require_api( 'authentication_api.php' );
63 require_api( 'bug_api.php' );
64 require_api( 'config_api.php' );
65 require_api( 'constant_inc.php' );
66 require_api( 'current_user_api.php' );
67 require_api( 'database_api.php' );
68 require_api( 'form_api.php' );
69 require_api( 'gpc_api.php' );
70 require_api( 'helper_api.php' );
71 require_api( 'html_api.php' );
72 require_api( 'lang_api.php' );
73 require_api( 'print_api.php' );
74 require_api( 'project_api.php' );
75 require_api( 'sponsorship_api.php' );
76 require_api( 'string_api.php' );
77 require_api( 'version_api.php' );
79 if ( config_get( 'enable_sponsorship' ) == OFF ) {
80 trigger_error( ERROR_SPONSORSHIP_NOT_ENABLED, ERROR );
83 # anonymous users are not allowed to sponsor issues
84 if ( current_user_is_anonymous() ) {
85 access_denied();
88 $t_show_all = gpc_get_bool( 'show_all', false );
90 # start the page
91 html_page_top( lang_get( 'my_sponsorship' ) );
93 $t_project = helper_get_current_project();
95 <br />
96 <table class="width100" cellspacing="1">
97 <tr>
98 <td class="form-title">
99 <?php echo lang_get( 'my_sponsorship' ) ?>
100 </td>
101 <td class="right">
102 <?php print_account_menu( 'account_sponsor_page.php' ) ?>
103 </td>
104 </tr>
105 </table>
106 <?php
107 # get issues user has sponsored
108 $t_user = auth_get_current_user_id();
109 $t_resolved = config_get( 'bug_resolved_status_threshold' );
110 $t_bug_table = db_get_table( 'bug' );
111 $t_sponsor_table = db_get_table( 'sponsorship' );
112 $t_payment = config_get( 'payment_enable', 0 );
114 $t_project_clause = helper_project_specific_where( $t_project );
116 $query = "SELECT b.id as bug, s.id as sponsor, s.paid, b.project_id, b.fixed_in_version, b.status
117 FROM $t_bug_table b, $t_sponsor_table s
118 WHERE s.user_id=" . db_param() . " AND s.bug_id = b.id " .
119 ( $t_show_all ? '' : 'AND ( b.status < ' . db_param() . ' OR s.paid < ' . SPONSORSHIP_PAID . ')' ) . "
120 AND $t_project_clause
121 ORDER BY s.paid ASC, b.project_id ASC, b.fixed_in_version ASC, b.status ASC, b.id DESC";
123 $result = db_query_bound( $query, $t_show_all ? Array( $t_user ) : Array( $t_user , $t_resolved ) );
125 $t_sponsors = db_num_rows( $result );
126 if ( 0 == $t_sponsors ) {
127 echo '<p>' . lang_get( 'no_own_sponsored' ) . '</p>';
128 } else {
131 <!-- # Edit own sponsorship Form BEGIN -->
132 <br />
133 <div align="center">
134 <table class="width100" cellspacing="1">
136 <!-- Headings -->
137 <tr>
138 <td class="form-title" colspan="9">
139 <?php echo lang_get( 'own_sponsored' ) ?>
140 </td>
141 </tr>
142 <tr>
143 <td class="form-title" width="10%"><?php echo lang_get( 'email_bug' ) ?></td>
144 <td class="form-title" width="8%"><?php echo lang_get( 'email_project' ) ?></td>
145 <td class="form-title" width="7%"><?php echo lang_get( 'fixed_in_version' ) ?></td>
146 <td class="form-title" width="10%"><?php echo lang_get( 'email_status' ) ?></td>
147 <td class="form-title" width="10%"><?php echo lang_get( 'email_handler' ) ?></td>
148 <td class="form-title" width="30%"><?php echo lang_get( 'email_summary' ) ?></td>
149 <td class="form-title" width="8%"><?php echo lang_get( 'amount' ) ?></td>
150 <td class="form-title" width="7%"><?php echo lang_get( 'status' ) ?></td>
151 <td class="form-title" width="10%">&nbsp;</td>
152 </tr>
153 <?php
154 $t_total_owing = 0;
155 $t_total_paid = 0;
156 for ( $i=0; $i < $t_sponsors; ++$i ) {
157 $row = db_fetch_array( $result );
158 $t_bug = bug_get( $row['bug'] );
159 $t_sponsor = sponsorship_get( $row['sponsor'] );
161 # describe bug
162 $t_status = string_attribute( get_enum_element( 'status', $t_bug->status ) );
163 $t_resolution = string_attribute( get_enum_element( 'resolution', $t_bug->resolution ) );
164 $t_version_id = version_get_id( $t_bug->fixed_in_version, $t_project );
165 if ( ( false !== $t_version_id ) && ( VERSION_RELEASED == version_get_field( $t_version_id, 'released' ) ) ) {
166 $t_released_label = '<a title="' . lang_get( 'released' ) . '">' . $t_bug->fixed_in_version . '</a>';
167 } else {
168 $t_released_label = $t_bug->fixed_in_version;
171 echo '<tr bgcolor="' . get_status_color( $t_bug->status ) . '">';
172 echo '<td><a href="' . string_get_bug_view_url( $row['bug'] ) . '">' . bug_format_id( $row['bug'] ) . '</a></td>';
173 echo '<td>' . project_get_field( $t_bug->project_id, 'name' ) . '&nbsp;</td>';
174 echo '<td class="right">' . $t_released_label . '&nbsp;</td>';
175 echo '<td><span class="issue-status" title="' . $t_resolution . '">' . $t_status . '</span></td>';
176 echo '<td>';
177 print_user( $t_bug->handler_id );
178 echo '</td>';
180 # summary
181 echo '<td>' . string_display_line( $t_bug->summary );
182 if ( VS_PRIVATE == $t_bug->view_state ) {
183 printf( ' <img src="%s" alt="(%s)" title="%s" />', $t_icon_path . 'protected.gif', lang_get( 'private' ), lang_get( 'private' ) );
185 echo '</td>';
187 # describe sponsorship amount
188 echo '<td class="right">' . sponsorship_format_amount( $t_sponsor->amount ) . '</td>';
189 echo '<td>' . get_enum_element( 'sponsorship', $t_sponsor->paid ) . '</td>';
191 if ( SPONSORSHIP_PAID == $t_sponsor->paid ) {
192 $t_total_paid += $t_sponsor->amount;
193 } else {
194 $t_total_owing += $t_sponsor->amount;
197 echo '<td>';
198 if ( $t_payment ) {
199 echo '(paypal button)';
200 } else {
201 echo '&nbsp;';
203 echo '</td>';
204 echo '</tr>';
207 <!-- Totals -->
208 <tr>
209 <td colspan="5"></td>
210 <td><?php echo lang_get( 'total_owing' ) ?></td>
211 <td class="right"><?php echo sponsorship_format_amount( $t_total_owing ) ?></td>
212 <td colspan="2"></td>
213 </tr>
214 <tr>
215 <td colspan="5"></td>
216 <td><?php echo lang_get( 'total_paid' ) ?></td>
217 <td class="right"><?php echo sponsorship_format_amount( $t_total_paid ) ?></td>
218 <td colspan="2"></td>
219 </tr>
220 </table>
221 </div>
222 <?php } # end sponsored issues
224 $query = "SELECT b.id as bug, s.id as sponsor, s.paid, b.project_id, b.fixed_in_version, b.status
225 FROM $t_bug_table b, $t_sponsor_table s
226 WHERE b.handler_id=" . db_param() . " AND s.bug_id = b.id " .
227 ( $t_show_all ? '' : 'AND ( b.status < ' . db_param() . ' OR s.paid < ' . SPONSORSHIP_PAID . ')' ) . "
228 AND $t_project_clause
229 ORDER BY s.paid ASC, b.project_id ASC, b.fixed_in_version ASC, b.status ASC, b.id DESC";
231 $result = db_query_bound( $query, $t_show_all ? Array( $t_user ) : Array( $t_user , $t_resolved ) );
232 $t_sponsors = db_num_rows( $result );
233 if ( 0 == $t_sponsors ) {
234 echo '<p>' . lang_get( 'no_sponsored' ) . '</p>';
235 } else {
238 <!-- # Edit sponsorship Form BEGIN -->
239 <br />
240 <div align="center">
241 <form method="post" action="account_sponsor_update.php">
242 <?php echo form_security_field( 'account_sponsor_update' ) ?>
243 <table class="width100" cellspacing="1">
245 <!-- Headings -->
246 <tr>
247 <td class="form-title" colspan="8">
248 <?php echo lang_get( 'issues_handled' ) ?>
249 </td>
250 </tr>
251 <tr>
252 <td class="form-title" width="10%"><?php echo lang_get( 'email_bug' ) ?></td>
253 <td class="form-title" width="8%"><?php echo lang_get( 'email_project' ) ?></td>
254 <td class="form-title" width="7%"><?php echo lang_get( 'fixed_in_version' ) ?></td>
255 <td class="form-title" width="10%"><?php echo lang_get( 'email_status' ) ?></td>
256 <td class="form-title" width="35%"><?php echo lang_get( 'email_summary' ) ?></td>
257 <td class="form-title" width="10%"><?php echo lang_get( 'sponsor' ) ?></td>
258 <td class="form-title" width="10%"><?php echo lang_get( 'amount' ) ?></td>
259 <td class="form-title" width="10%"><?php echo lang_get( 'status' ) ?></td>
260 </tr>
261 <?php
262 $t_bug_list = array();
263 $t_total_owing = 0;
264 $t_total_paid = 0;
265 for ( $i=0; $i < $t_sponsors; ++$i ) {
266 $row = db_fetch_array( $result );
267 $t_bug = bug_get( $row['bug'] );
268 $t_sponsor = sponsorship_get( $row['sponsor'] );
269 $t_buglist[] = $row['bug'] . ':' . $row['sponsor'];
271 # describe bug
272 $t_status = string_attribute( get_enum_element( 'status', $t_bug->status ) );
273 $t_resolution = string_attribute( get_enum_element( 'resolution', $t_bug->resolution ) );
274 $t_version_id = version_get_id( $t_bug->fixed_in_version, $t_project );
275 if ( ( false !== $t_version_id ) && ( VERSION_RELEASED == version_get_field( $t_version_id, 'released' ) ) ) {
276 $t_released_label = '<a title="' . lang_get( 'released' ) . '">' . $t_bug->fixed_in_version . '</a>';
277 } else {
278 $t_released_label = $t_bug->fixed_in_version;
281 echo '<tr bgcolor="' . get_status_color( $t_bug->status ) . '">';
282 echo '<td><a href="' . string_get_bug_view_url( $row['bug'] ) . '">' . bug_format_id( $row['bug'] ) . '</a></td>';
283 echo '<td>' . project_get_field( $t_bug->project_id, 'name' ) . '&nbsp;</td>';
284 echo '<td class="right">' . $t_released_label . '&nbsp;</td>';
285 echo '<td><a title="' . $t_resolution . '"><u>' . $t_status . '</u>&nbsp;</a></td>';
287 # summary
288 echo '<td>' . string_display_line( $t_bug->summary );
289 if ( VS_PRIVATE == $t_bug->view_state ) {
290 printf( ' <img src="%s" alt="(%s)" title="%s" />', $t_icon_path . 'protected.gif', lang_get( 'private' ), lang_get( 'private' ) );
293 # describe sponsorship amount
294 echo '<td>';
295 print_user( $t_sponsor->user_id );
296 echo '</td>';
297 echo '<td class="right">' . sponsorship_format_amount( $t_sponsor->amount ) . '</td>';
298 echo '<td><select name="sponsor_' . $row['bug'] . '_' . $t_sponsor->id . '">';
299 print_enum_string_option_list( 'sponsorship', $t_sponsor->paid );
300 echo '</select></td>';
302 echo '</tr>';
303 if ( SPONSORSHIP_PAID == $t_sponsor->paid ) {
304 $t_total_paid += $t_sponsor->amount;
305 } else {
306 $t_total_owing += $t_sponsor->amount;
310 $t_hidden_bug_list = implode( ',', $t_buglist );
312 <!-- Totals -->
313 <tr>
314 <td colspan="5"></td>
315 <td><?php echo lang_get( 'total_owing' ) ?></td>
316 <td class="right"><?php echo sponsorship_format_amount( $t_total_owing ) ?></td>
317 <td></td>
318 </tr>
319 <tr>
320 <td colspan="5"></td>
321 <td><?php echo lang_get( 'total_paid' ) ?></td>
322 <td class="right"><?php echo sponsorship_format_amount( $t_total_paid ) ?></td>
323 <td></td>
324 </tr>
325 <input type="hidden" name="buglist" value="<?php echo $t_hidden_bug_list ?>" />
326 <!-- BUTTONS -->
327 <tr>
328 <td colspan="5">&nbsp;</td>
329 <!-- Update Button -->
330 <td colspan="2">
331 <input type="submit" class="button" value="<?php echo lang_get( 'update_sponsorship_button' ) ?>" />
332 </td>
333 </tr>
334 </table>
335 </form>
336 </div>
337 <?php } # end sponsored issues ?>
339 <br />
340 <div align="center">
341 <?php
342 html_button ( 'account_sponsor_page.php',
343 lang_get( ( $t_show_all ? 'sponsor_hide' : 'sponsor_show' ) ),
344 array( 'show_all' => ( $t_show_all ? 0 : 1 ) ) );
346 </div>
348 <?php
349 html_page_bottom();