/bug_monitor_add.php

https://github.com/fusenigk/mantisbt-1 · PHP · 101 lines · 46 code · 15 blank · 40 comment · 10 complexity · b6bdd9e36fa2ec08c83bfe48cccd2280 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. * This file turns monitoring on or off for a bug for the current user
  17. *
  18. * @package MantisBT
  19. * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
  20. * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
  21. * @link http://www.mantisbt.org
  22. *
  23. * @uses core.php
  24. * @uses access_api.php
  25. * @uses authentication_api.php
  26. * @uses bug_api.php
  27. * @uses config_api.php
  28. * @uses constant_inc.php
  29. * @uses error_api.php
  30. * @uses form_api.php
  31. * @uses gpc_api.php
  32. * @uses helper_api.php
  33. * @uses print_api.php
  34. * @uses user_api.php
  35. * @uses utility_api.php
  36. */
  37. /**
  38. * MantisBT Core API's
  39. */
  40. require_once( 'core.php' );
  41. require_api( 'access_api.php' );
  42. require_api( 'authentication_api.php' );
  43. require_api( 'bug_api.php' );
  44. require_api( 'config_api.php' );
  45. require_api( 'constant_inc.php' );
  46. require_api( 'error_api.php' );
  47. require_api( 'form_api.php' );
  48. require_api( 'gpc_api.php' );
  49. require_api( 'helper_api.php' );
  50. require_api( 'print_api.php' );
  51. require_api( 'user_api.php' );
  52. require_api( 'utility_api.php' );
  53. form_security_validate( 'bug_monitor_add' );
  54. $f_bug_id = gpc_get_int( 'bug_id' );
  55. $t_bug = bug_get( $f_bug_id, true );
  56. $f_username = gpc_get_string( 'username', '' );
  57. $t_logged_in_user_id = auth_get_current_user_id();
  58. if ( is_blank( $f_username ) ) {
  59. $t_user_id = $t_logged_in_user_id;
  60. } else {
  61. $t_user_id = user_get_id_by_name( $f_username );
  62. if ( $t_user_id === false ) {
  63. $t_user_id = user_get_id_by_realname( $f_username );
  64. if ( $t_user_id === false ) {
  65. error_parameters( $f_username );
  66. trigger_error( ERROR_USER_BY_NAME_NOT_FOUND, E_USER_ERROR );
  67. }
  68. }
  69. }
  70. if ( user_is_anonymous( $t_user_id ) ) {
  71. trigger_error( ERROR_PROTECTED_ACCOUNT, E_USER_ERROR );
  72. }
  73. bug_ensure_exists( $f_bug_id );
  74. if( $t_bug->project_id != helper_get_current_project() ) {
  75. # in case the current project is not the same project of the bug we are viewing...
  76. # ... override the current project. This to avoid problems with categories and handlers lists etc.
  77. $g_project_override = $t_bug->project_id;
  78. }
  79. if ( $t_logged_in_user_id == $t_user_id ) {
  80. access_ensure_bug_level( config_get( 'monitor_bug_threshold' ), $f_bug_id );
  81. } else {
  82. access_ensure_bug_level( config_get( 'monitor_add_others_bug_threshold' ), $f_bug_id );
  83. }
  84. bug_monitor( $f_bug_id, $t_user_id );
  85. form_security_purge( 'bug_monitor_add' );
  86. print_successful_redirect_to_bug( $f_bug_id );