PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/account_sponsor_page.php

https://github.com/fusenigk/mantisbt-1
PHP | 352 lines | 253 code | 32 blank | 67 comment | 30 complexity | 4bfeab9845ce7ce6a2d5551b422fb11d MD5 | raw file
  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. * @uses core.php
  39. * @uses access_api.php
  40. * @uses authentication_api.php
  41. * @uses bug_api.php
  42. * @uses config_api.php
  43. * @uses constant_inc.php
  44. * @uses current_user_api.php
  45. * @uses database_api.php
  46. * @uses form_api.php
  47. * @uses gpc_api.php
  48. * @uses helper_api.php
  49. * @uses html_api.php
  50. * @uses lang_api.php
  51. * @uses print_api.php
  52. * @uses project_api.php
  53. * @uses sponsorship_api.php
  54. * @uses string_api.php
  55. * @uses version_api.php
  56. */
  57. /**
  58. * MantisBT Core API's
  59. */
  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' );
  78. if ( !config_get( 'enable_sponsorship' ) ) {
  79. trigger_error( ERROR_SPONSORSHIP_NOT_ENABLED, ERROR );
  80. }
  81. # anonymous users are not allowed to sponsor issues
  82. if ( current_user_is_anonymous() ) {
  83. access_denied();
  84. }
  85. $t_show_all = gpc_get_bool( 'show_all', false );
  86. # start the page
  87. html_page_top( lang_get( 'my_sponsorship' ) );
  88. $t_project = helper_get_current_project();
  89. ?>
  90. <br />
  91. <table class="width100" cellspacing="1">
  92. <tr>
  93. <td class="form-title">
  94. <?php echo lang_get( 'my_sponsorship' ) ?>
  95. </td>
  96. <td class="right">
  97. <?php print_account_menu( 'account_sponsor_page.php' ) ?>
  98. </td>
  99. </tr>
  100. </table>
  101. <?php
  102. # get issues user has sponsored
  103. $t_user = auth_get_current_user_id();
  104. $t_resolved = config_get( 'bug_resolved_status_threshold' );
  105. $t_bug_table = db_get_table( 'bug' );
  106. $t_sponsor_table = db_get_table( 'sponsorship' );
  107. $t_payment = config_get( 'payment_enable', 0 );
  108. $t_project_clause = helper_project_specific_where( $t_project );
  109. $query = "SELECT b.id as bug, s.id as sponsor, s.paid, b.project_id, b.fixed_in_version, b.status
  110. FROM $t_bug_table b, $t_sponsor_table s
  111. WHERE s.user_id=" . db_param() . " AND s.bug_id = b.id " .
  112. ( $t_show_all ? '' : 'AND ( b.status < ' . db_param() . ' OR s.paid < ' . SPONSORSHIP_PAID . ')' ) . "
  113. AND $t_project_clause
  114. ORDER BY s.paid ASC, b.project_id ASC, b.fixed_in_version ASC, b.status ASC, b.id DESC";
  115. $result = db_query_bound( $query, $t_show_all ? Array( $t_user ) : Array( $t_user , $t_resolved ) );
  116. $t_sponsors = db_num_rows( $result );
  117. if ( 0 == $t_sponsors ) {
  118. echo '<p>' . lang_get( 'no_own_sponsored' ) . '</p>';
  119. } else {
  120. ?>
  121. <!-- # Edit own sponsorship Form BEGIN -->
  122. <br />
  123. <div>
  124. <table class="width100" cellspacing="1">
  125. <!-- Headings -->
  126. <tr>
  127. <td class="form-title" colspan="9">
  128. <?php echo lang_get( 'own_sponsored' ) ?>
  129. </td>
  130. </tr>
  131. <tr>
  132. <td class="form-title" width="10%"><?php echo lang_get( 'email_bug' ) ?></td>
  133. <td class="form-title" width="8%"><?php echo lang_get( 'email_project' ) ?></td>
  134. <td class="form-title" width="7%"><?php echo lang_get( 'fixed_in_version' ) ?></td>
  135. <td class="form-title" width="10%"><?php echo lang_get( 'email_status' ) ?></td>
  136. <td class="form-title" width="10%"><?php echo lang_get( 'email_handler' ) ?></td>
  137. <td class="form-title" width="30%"><?php echo lang_get( 'email_summary' ) ?></td>
  138. <td class="form-title" width="8%"><?php echo lang_get( 'amount' ) ?></td>
  139. <td class="form-title" width="7%"><?php echo lang_get( 'status' ) ?></td>
  140. <td class="form-title" width="10%">&#160;</td>
  141. </tr>
  142. <?php
  143. $t_total_owing = 0;
  144. $t_total_paid = 0;
  145. for ( $i=0; $i < $t_sponsors; ++$i ) {
  146. $row = db_fetch_array( $result );
  147. $t_bug = bug_get( $row['bug'] );
  148. $t_sponsor = sponsorship_get( $row['sponsor'] );
  149. # describe bug
  150. $t_status = string_attribute( get_enum_element( 'status', $t_bug->status ) );
  151. $t_resolution = string_attribute( get_enum_element( 'resolution', $t_bug->resolution ) );
  152. $t_version_id = version_get_id( $t_bug->fixed_in_version, $t_project );
  153. if ( ( false !== $t_version_id ) && ( VERSION_RELEASED == version_get_field( $t_version_id, 'released' ) ) ) {
  154. $t_released_label = '<a title="' . lang_get( 'released' ) . '">' . $t_bug->fixed_in_version . '</a>';
  155. } else {
  156. $t_released_label = $t_bug->fixed_in_version;
  157. }
  158. echo '<tr bgcolor="' . get_status_color( $t_bug->status ) . '">';
  159. echo '<td><a href="' . string_get_bug_view_url( $row['bug'] ) . '">' . bug_format_id( $row['bug'] ) . '</a></td>';
  160. echo '<td>' . project_get_field( $t_bug->project_id, 'name' ) . '&#160;</td>';
  161. echo '<td class="right">' . $t_released_label . '&#160;</td>';
  162. echo '<td><span class="issue-status" title="' . $t_resolution . '">' . $t_status . '</span></td>';
  163. echo '<td>';
  164. print_user( $t_bug->handler_id );
  165. echo '</td>';
  166. # summary
  167. echo '<td>' . string_display_line( $t_bug->summary );
  168. if ( VS_PRIVATE == $t_bug->view_state ) {
  169. printf( ' <img src="%s" alt="(%s)" title="%s" />', $t_icon_path . 'protected.gif', lang_get( 'private' ), lang_get( 'private' ) );
  170. }
  171. echo '</td>';
  172. # describe sponsorship amount
  173. echo '<td class="right">' . sponsorship_format_amount( $t_sponsor->amount ) . '</td>';
  174. echo '<td>' . get_enum_element( 'sponsorship', $t_sponsor->paid ) . '</td>';
  175. if ( SPONSORSHIP_PAID == $t_sponsor->paid ) {
  176. $t_total_paid += $t_sponsor->amount;
  177. } else {
  178. $t_total_owing += $t_sponsor->amount;
  179. }
  180. echo '<td>';
  181. if ( $t_payment ) {
  182. echo '(paypal button)';
  183. } else {
  184. echo '&#160;';
  185. }
  186. echo '</td>';
  187. echo '</tr>';
  188. }
  189. ?>
  190. <!-- Totals -->
  191. <tr>
  192. <td colspan="5"></td>
  193. <td><?php echo lang_get( 'total_owing' ) ?></td>
  194. <td class="right"><?php echo sponsorship_format_amount( $t_total_owing ) ?></td>
  195. <td colspan="2"></td>
  196. </tr>
  197. <tr>
  198. <td colspan="5"></td>
  199. <td><?php echo lang_get( 'total_paid' ) ?></td>
  200. <td class="right"><?php echo sponsorship_format_amount( $t_total_paid ) ?></td>
  201. <td colspan="2"></td>
  202. </tr>
  203. </table>
  204. </div>
  205. <?php } # end sponsored issues
  206. $query = "SELECT b.id as bug, s.id as sponsor, s.paid, b.project_id, b.fixed_in_version, b.status
  207. FROM $t_bug_table b, $t_sponsor_table s
  208. WHERE b.handler_id=" . db_param() . " AND s.bug_id = b.id " .
  209. ( $t_show_all ? '' : 'AND ( b.status < ' . db_param() . ' OR s.paid < ' . SPONSORSHIP_PAID . ')' ) . "
  210. AND $t_project_clause
  211. ORDER BY s.paid ASC, b.project_id ASC, b.fixed_in_version ASC, b.status ASC, b.id DESC";
  212. $result = db_query_bound( $query, $t_show_all ? Array( $t_user ) : Array( $t_user , $t_resolved ) );
  213. $t_sponsors = db_num_rows( $result );
  214. if ( 0 == $t_sponsors ) {
  215. echo '<p>' . lang_get( 'no_sponsored' ) . '</p>';
  216. } else {
  217. ?>
  218. <!-- # Edit sponsorship Form BEGIN -->
  219. <br />
  220. <div>
  221. <form method="post" action="account_sponsor_update.php">
  222. <?php echo form_security_field( 'account_sponsor_update' ) ?>
  223. <table class="width100" cellspacing="1">
  224. <!-- Headings -->
  225. <tr>
  226. <td class="form-title" colspan="8">
  227. <?php echo lang_get( 'issues_handled' ) ?>
  228. </td>
  229. </tr>
  230. <tr>
  231. <td class="form-title" width="10%"><?php echo lang_get( 'email_bug' ) ?></td>
  232. <td class="form-title" width="8%"><?php echo lang_get( 'email_project' ) ?></td>
  233. <td class="form-title" width="7%"><?php echo lang_get( 'fixed_in_version' ) ?></td>
  234. <td class="form-title" width="10%"><?php echo lang_get( 'email_status' ) ?></td>
  235. <td class="form-title" width="35%"><?php echo lang_get( 'email_summary' ) ?></td>
  236. <td class="form-title" width="10%"><?php echo lang_get( 'sponsor' ) ?></td>
  237. <td class="form-title" width="10%"><?php echo lang_get( 'amount' ) ?></td>
  238. <td class="form-title" width="10%"><?php echo lang_get( 'status' ) ?></td>
  239. </tr>
  240. <?php
  241. $t_bug_list = array();
  242. $t_total_owing = 0;
  243. $t_total_paid = 0;
  244. for ( $i=0; $i < $t_sponsors; ++$i ) {
  245. $row = db_fetch_array( $result );
  246. $t_bug = bug_get( $row['bug'] );
  247. $t_sponsor = sponsorship_get( $row['sponsor'] );
  248. $t_buglist[] = $row['bug'] . ':' . $row['sponsor'];
  249. # describe bug
  250. $t_status = string_attribute( get_enum_element( 'status', $t_bug->status ) );
  251. $t_resolution = string_attribute( get_enum_element( 'resolution', $t_bug->resolution ) );
  252. $t_version_id = version_get_id( $t_bug->fixed_in_version, $t_project );
  253. if ( ( false !== $t_version_id ) && ( VERSION_RELEASED == version_get_field( $t_version_id, 'released' ) ) ) {
  254. $t_released_label = '<a title="' . lang_get( 'released' ) . '">' . $t_bug->fixed_in_version . '</a>';
  255. } else {
  256. $t_released_label = $t_bug->fixed_in_version;
  257. }
  258. echo '<tr bgcolor="' . get_status_color( $t_bug->status ) . '">';
  259. echo '<td><a href="' . string_get_bug_view_url( $row['bug'] ) . '">' . bug_format_id( $row['bug'] ) . '</a></td>';
  260. echo '<td>' . project_get_field( $t_bug->project_id, 'name' ) . '&#160;</td>';
  261. echo '<td class="right">' . $t_released_label . '&#160;</td>';
  262. echo '<td><a title="' . $t_resolution . '"><span class="underline">' . $t_status . '</span>&#160;</a></td>';
  263. # summary
  264. echo '<td>' . string_display_line( $t_bug->summary );
  265. if ( VS_PRIVATE == $t_bug->view_state ) {
  266. printf( ' <img src="%s" alt="(%s)" title="%s" />', $t_icon_path . 'protected.gif', lang_get( 'private' ), lang_get( 'private' ) );
  267. }
  268. # describe sponsorship amount
  269. echo '<td>';
  270. print_user( $t_sponsor->user_id );
  271. echo '</td>';
  272. echo '<td class="right">' . sponsorship_format_amount( $t_sponsor->amount ) . '</td>';
  273. echo '<td><select name="sponsor_' . $row['bug'] . '_' . $t_sponsor->id . '">';
  274. print_enum_string_option_list( 'sponsorship', $t_sponsor->paid );
  275. echo '</select></td>';
  276. echo '</tr>';
  277. if ( SPONSORSHIP_PAID == $t_sponsor->paid ) {
  278. $t_total_paid += $t_sponsor->amount;
  279. } else {
  280. $t_total_owing += $t_sponsor->amount;
  281. }
  282. }
  283. $t_hidden_bug_list = implode( ',', $t_buglist );
  284. ?>
  285. <!-- Totals -->
  286. <tr>
  287. <td colspan="5"></td>
  288. <td><?php echo lang_get( 'total_owing' ) ?></td>
  289. <td class="right"><?php echo sponsorship_format_amount( $t_total_owing ) ?></td>
  290. <td></td>
  291. </tr>
  292. <tr>
  293. <td colspan="5"></td>
  294. <td><?php echo lang_get( 'total_paid' ) ?></td>
  295. <td class="right"><?php echo sponsorship_format_amount( $t_total_paid ) ?></td>
  296. <td></td>
  297. </tr>
  298. <input type="hidden" name="buglist" value="<?php echo $t_hidden_bug_list ?>" />
  299. <!-- BUTTONS -->
  300. <tr>
  301. <td colspan="5">&#160;</td>
  302. <!-- Update Button -->
  303. <td colspan="2">
  304. <input type="submit" class="button" value="<?php echo lang_get( 'update_sponsorship_button' ) ?>" />
  305. </td>
  306. </tr>
  307. </table>
  308. </form>
  309. </div>
  310. <?php } # end sponsored issues ?>
  311. <br />
  312. <div>
  313. <?php
  314. html_button ( 'account_sponsor_page.php',
  315. lang_get( ( $t_show_all ? 'sponsor_hide' : 'sponsor_show' ) ),
  316. array( 'show_all' => ( $t_show_all ? 0 : 1 ) ) );
  317. ?>
  318. </div>
  319. <?php
  320. html_page_bottom();