PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/mantisbt-1.2.8/account_sponsor_page.php

#
PHP | 317 lines | 237 code | 32 blank | 48 comment | 31 complexity | f21da521d09b025cc0fd8d8ba24d5b1e MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. # MantisBT - a php based bugtracking system
  3. # MantisBT is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # MantisBT is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * CALLERS
  17. * This page is called from:
  18. * - print_menu()
  19. * - print_account_menu()
  20. *
  21. * EXPECTED BEHAVIOUR
  22. * - Display the user's current sponsorships
  23. * - Allow the user to edit the payment flag
  24. *
  25. * CALLS
  26. * This page calls the following pages:
  27. * - account_sponsor_update.php (to save changes)
  28. *
  29. * RESTRICTIONS & PERMISSIONS
  30. * - User must be authenticated, and not anonymous
  31. * - sponsorship must be enabled
  32. *
  33. * @package MantisBT
  34. * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
  35. * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
  36. * @link http://www.mantisbt.org
  37. */
  38. /**
  39. * MantisBT Core API's
  40. */
  41. require_once( 'core.php' );
  42. require_once( 'current_user_api.php' );
  43. if ( config_get( 'enable_sponsorship' ) == OFF ) {
  44. trigger_error( ERROR_SPONSORSHIP_NOT_ENABLED, ERROR );
  45. }
  46. # anonymous users are not allowed to sponsor issues
  47. if ( current_user_is_anonymous() ) {
  48. access_denied();
  49. }
  50. $t_show_all = gpc_get_bool( 'show_all', false );
  51. # start the page
  52. html_page_top( lang_get( 'my_sponsorship' ) );
  53. $t_project = helper_get_current_project();
  54. ?>
  55. <br />
  56. <table class="width100" cellspacing="1">
  57. <tr>
  58. <td class="form-title">
  59. <?php echo lang_get( 'my_sponsorship' ) ?>
  60. </td>
  61. <td class="right">
  62. <?php print_account_menu( 'account_sponsor_page.php' ) ?>
  63. </td>
  64. </tr>
  65. </table>
  66. <?php
  67. # get issues user has sponsored
  68. $t_user = auth_get_current_user_id();
  69. $t_resolved = config_get( 'bug_resolved_status_threshold' );
  70. $t_bug_table = db_get_table( 'mantis_bug_table' );
  71. $t_sponsor_table = db_get_table( 'mantis_sponsorship_table' );
  72. $t_payment = config_get( 'payment_enable', 0 );
  73. $t_project_clause = helper_project_specific_where( $t_project );
  74. $query = "SELECT b.id as bug, s.id as sponsor, s.paid, b.project_id, b.fixed_in_version, b.status
  75. FROM $t_bug_table b, $t_sponsor_table s
  76. WHERE s.user_id=" . db_param() . " AND s.bug_id = b.id " .
  77. ( $t_show_all ? '' : 'AND ( b.status < ' . db_param() . ' OR s.paid < ' . SPONSORSHIP_PAID . ')' ) . "
  78. AND $t_project_clause
  79. ORDER BY s.paid ASC, b.project_id ASC, b.fixed_in_version ASC, b.status ASC, b.id DESC";
  80. $result = db_query_bound( $query, $t_show_all ? Array( $t_user ) : Array( $t_user , $t_resolved ) );
  81. $t_sponsors = db_num_rows( $result );
  82. if ( 0 == $t_sponsors ) {
  83. echo '<p>' . lang_get( 'no_own_sponsored' ) . '</p>';
  84. } else {
  85. ?>
  86. <!-- # Edit own sponsorship Form BEGIN -->
  87. <br />
  88. <div align="center">
  89. <table class="width100" cellspacing="1">
  90. <!-- Headings -->
  91. <tr>
  92. <td class="form-title" colspan="9">
  93. <?php echo lang_get( 'own_sponsored' ) ?>
  94. </td>
  95. </tr>
  96. <tr>
  97. <td class="form-title" width="10%"><?php echo lang_get( 'email_bug' ) ?></td>
  98. <td class="form-title" width="8%"><?php echo lang_get( 'email_project' ) ?></td>
  99. <td class="form-title" width="7%"><?php echo lang_get( 'fixed_in_version' ) ?></td>
  100. <td class="form-title" width="10%"><?php echo lang_get( 'email_status' ) ?></td>
  101. <td class="form-title" width="10%"><?php echo lang_get( 'email_handler' ) ?></td>
  102. <td class="form-title" width="30%"><?php echo lang_get( 'email_summary' ) ?></td>
  103. <td class="form-title" width="8%"><?php echo lang_get( 'amount' ) ?></td>
  104. <td class="form-title" width="7%"><?php echo lang_get( 'status' ) ?></td>
  105. <td class="form-title" width="10%">&#160;</td>
  106. </tr>
  107. <?php
  108. $t_total_owing = 0;
  109. $t_total_paid = 0;
  110. for ( $i=0; $i < $t_sponsors; ++$i ) {
  111. $row = db_fetch_array( $result );
  112. $t_bug = bug_get( $row['bug'] );
  113. $t_sponsor = sponsorship_get( $row['sponsor'] );
  114. # describe bug
  115. $t_status = string_attribute( get_enum_element( 'status', $t_bug->status ) );
  116. $t_resolution = string_attribute( get_enum_element( 'resolution', $t_bug->resolution ) );
  117. $t_version_id = version_get_id( $t_bug->fixed_in_version, $t_project );
  118. if ( ( false !== $t_version_id ) && ( VERSION_RELEASED == version_get_field( $t_version_id, 'released' ) ) ) {
  119. $t_released_label = '<a title="' . lang_get( 'released' ) . '">' . $t_bug->fixed_in_version . '</a>';
  120. } else {
  121. $t_released_label = $t_bug->fixed_in_version;
  122. }
  123. echo '<tr bgcolor="' . get_status_color( $t_bug->status ) . '">';
  124. echo '<td><a href="' . string_get_bug_view_url( $row['bug'] ) . '">' . bug_format_id( $row['bug'] ) . '</a></td>';
  125. echo '<td>' . project_get_field( $t_bug->project_id, 'name' ) . '&#160;</td>';
  126. echo '<td class="right">' . $t_released_label . '&#160;</td>';
  127. echo '<td><span class="issue-status" title="' . $t_resolution . '">' . $t_status . '</span></td>';
  128. echo '<td>';
  129. print_user( $t_bug->handler_id );
  130. echo '</td>';
  131. # summary
  132. echo '<td>' . string_display_line( $t_bug->summary );
  133. if ( VS_PRIVATE == $t_bug->view_state ) {
  134. printf( ' <img src="%s" alt="(%s)" title="%s" />', $t_icon_path . 'protected.gif', lang_get( 'private' ), lang_get( 'private' ) );
  135. }
  136. echo '</td>';
  137. # describe sponsorship amount
  138. echo '<td class="right">' . sponsorship_format_amount( $t_sponsor->amount ) . '</td>';
  139. echo '<td>' . get_enum_element( 'sponsorship', $t_sponsor->paid ) . '</td>';
  140. if ( SPONSORSHIP_PAID == $t_sponsor->paid ) {
  141. $t_total_paid += $t_sponsor->amount;
  142. } else {
  143. $t_total_owing += $t_sponsor->amount;
  144. }
  145. echo '<td>';
  146. if ( $t_payment ) {
  147. echo '(paypal button)';
  148. } else {
  149. echo '&#160;';
  150. }
  151. echo '</td>';
  152. echo '</tr>';
  153. }
  154. ?>
  155. <!-- Totals -->
  156. <tr>
  157. <td colspan="5"></td>
  158. <td><?php echo lang_get( 'total_owing' ) ?></td>
  159. <td class="right"><?php echo sponsorship_format_amount( $t_total_owing ) ?></td>
  160. <td colspan="2"></td>
  161. </tr>
  162. <tr>
  163. <td colspan="5"></td>
  164. <td><?php echo lang_get( 'total_paid' ) ?></td>
  165. <td class="right"><?php echo sponsorship_format_amount( $t_total_paid ) ?></td>
  166. <td colspan="2"></td>
  167. </tr>
  168. </table>
  169. </div>
  170. <?php } # end sponsored issues
  171. $query = "SELECT b.id as bug, s.id as sponsor, s.paid, b.project_id, b.fixed_in_version, b.status
  172. FROM $t_bug_table b, $t_sponsor_table s
  173. WHERE b.handler_id=" . db_param() . " AND s.bug_id = b.id " .
  174. ( $t_show_all ? '' : 'AND ( b.status < ' . db_param() . ' OR s.paid < ' . SPONSORSHIP_PAID . ')' ) . "
  175. AND $t_project_clause
  176. ORDER BY s.paid ASC, b.project_id ASC, b.fixed_in_version ASC, b.status ASC, b.id DESC";
  177. $result = db_query_bound( $query, $t_show_all ? Array( $t_user ) : Array( $t_user , $t_resolved ) );
  178. $t_sponsors = db_num_rows( $result );
  179. if ( 0 == $t_sponsors ) {
  180. echo '<p>' . lang_get( 'no_sponsored' ) . '</p>';
  181. } else {
  182. ?>
  183. <!-- # Edit sponsorship Form BEGIN -->
  184. <br />
  185. <div align="center">
  186. <form method="post" action="account_sponsor_update.php">
  187. <?php echo form_security_field( 'account_sponsor_update' ) ?>
  188. <table class="width100" cellspacing="1">
  189. <!-- Headings -->
  190. <tr>
  191. <td class="form-title" colspan="8">
  192. <?php echo lang_get( 'issues_handled' ) ?>
  193. </td>
  194. </tr>
  195. <tr>
  196. <td class="form-title" width="10%"><?php echo lang_get( 'email_bug' ) ?></td>
  197. <td class="form-title" width="8%"><?php echo lang_get( 'email_project' ) ?></td>
  198. <td class="form-title" width="7%"><?php echo lang_get( 'fixed_in_version' ) ?></td>
  199. <td class="form-title" width="10%"><?php echo lang_get( 'email_status' ) ?></td>
  200. <td class="form-title" width="35%"><?php echo lang_get( 'email_summary' ) ?></td>
  201. <td class="form-title" width="10%"><?php echo lang_get( 'sponsor' ) ?></td>
  202. <td class="form-title" width="10%"><?php echo lang_get( 'amount' ) ?></td>
  203. <td class="form-title" width="10%"><?php echo lang_get( 'status' ) ?></td>
  204. </tr>
  205. <?php
  206. $t_bug_list = array();
  207. $t_total_owing = 0;
  208. $t_total_paid = 0;
  209. for ( $i=0; $i < $t_sponsors; ++$i ) {
  210. $row = db_fetch_array( $result );
  211. $t_bug = bug_get( $row['bug'] );
  212. $t_sponsor = sponsorship_get( $row['sponsor'] );
  213. $t_buglist[] = $row['bug'] . ':' . $row['sponsor'];
  214. # describe bug
  215. $t_status = string_attribute( get_enum_element( 'status', $t_bug->status ) );
  216. $t_resolution = string_attribute( get_enum_element( 'resolution', $t_bug->resolution ) );
  217. $t_version_id = version_get_id( $t_bug->fixed_in_version, $t_project );
  218. if ( ( false !== $t_version_id ) && ( VERSION_RELEASED == version_get_field( $t_version_id, 'released' ) ) ) {
  219. $t_released_label = '<a title="' . lang_get( 'released' ) . '">' . $t_bug->fixed_in_version . '</a>';
  220. } else {
  221. $t_released_label = $t_bug->fixed_in_version;
  222. }
  223. echo '<tr bgcolor="' . get_status_color( $t_bug->status ) . '">';
  224. echo '<td><a href="' . string_get_bug_view_url( $row['bug'] ) . '">' . bug_format_id( $row['bug'] ) . '</a></td>';
  225. echo '<td>' . project_get_field( $t_bug->project_id, 'name' ) . '&#160;</td>';
  226. echo '<td class="right">' . $t_released_label . '&#160;</td>';
  227. echo '<td><a title="' . $t_resolution . '"><u>' . $t_status . '</u>&#160;</a></td>';
  228. # summary
  229. echo '<td>' . string_display_line( $t_bug->summary );
  230. if ( VS_PRIVATE == $t_bug->view_state ) {
  231. printf( ' <img src="%s" alt="(%s)" title="%s" />', $t_icon_path . 'protected.gif', lang_get( 'private' ), lang_get( 'private' ) );
  232. }
  233. # describe sponsorship amount
  234. echo '<td>';
  235. print_user( $t_sponsor->user_id );
  236. echo '</td>';
  237. echo '<td class="right">' . sponsorship_format_amount( $t_sponsor->amount ) . '</td>';
  238. echo '<td><select name="sponsor_' . $row['bug'] . '_' . $t_sponsor->id . '">';
  239. print_enum_string_option_list( 'sponsorship', $t_sponsor->paid );
  240. echo '</select></td>';
  241. echo '</tr>';
  242. if ( SPONSORSHIP_PAID == $t_sponsor->paid ) {
  243. $t_total_paid += $t_sponsor->amount;
  244. } else {
  245. $t_total_owing += $t_sponsor->amount;
  246. }
  247. }
  248. $t_hidden_bug_list = implode( ',', $t_buglist );
  249. ?>
  250. <!-- Totals -->
  251. <tr>
  252. <td colspan="5"></td>
  253. <td><?php echo lang_get( 'total_owing' ) ?></td>
  254. <td class="right"><?php echo sponsorship_format_amount( $t_total_owing ) ?></td>
  255. <td></td>
  256. </tr>
  257. <tr>
  258. <td colspan="5"></td>
  259. <td><?php echo lang_get( 'total_paid' ) ?></td>
  260. <td class="right"><?php echo sponsorship_format_amount( $t_total_paid ) ?></td>
  261. <td></td>
  262. </tr>
  263. <input type="hidden" name="buglist" value="<?php echo $t_hidden_bug_list ?>" />
  264. <!-- BUTTONS -->
  265. <tr>
  266. <td colspan="5">&#160;</td>
  267. <!-- Update Button -->
  268. <td colspan="2">
  269. <input type="submit" class="button" value="<?php echo lang_get( 'update_sponsorship_button' ) ?>" />
  270. </td>
  271. </tr>
  272. </table>
  273. </form>
  274. </div>
  275. <?php } # end sponsored issues ?>
  276. <br />
  277. <div align="center">
  278. <?php
  279. html_button ( 'account_sponsor_page.php',
  280. lang_get( ( $t_show_all ? 'sponsor_hide' : 'sponsor_show' ) ),
  281. array( 'show_all' => ( $t_show_all ? 0 : 1 ) ) );
  282. ?>
  283. </div>
  284. <?php
  285. html_page_bottom();