[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/ -> bug_relationship_add.php (source)

   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   * @package MantisBT
  19   * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
  20   * @copyright Copyright (C) 2002 - 2010  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  21   * @author Marcello Scata' <marcelloscata at users.sourceforge.net> ITALY
  22   * @link http://www.mantisbt.org
  23   *
  24   * @uses core.php
  25   * @uses access_api.php
  26   * @uses bug_api.php
  27   * @uses config_api.php
  28   * @uses constant_inc.php
  29   * @uses email_api.php
  30   * @uses error_api.php
  31   * @uses form_api.php
  32   * @uses gpc_api.php
  33   * @uses helper_api.php
  34   * @uses history_api.php
  35   * @uses lang_api.php
  36   * @uses print_api.php
  37   * @uses relationship_api.php
  38   */
  39  
  40  require_once ( 'core.php' );
  41  require_api( 'access_api.php' );
  42  require_api( 'bug_api.php' );
  43  require_api( 'config_api.php' );
  44  require_api( 'constant_inc.php' );
  45  require_api( 'email_api.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( 'history_api.php' );
  51  require_api( 'lang_api.php' );
  52  require_api( 'print_api.php' );
  53  require_api( 'relationship_api.php' );
  54  
  55  form_security_validate( 'bug_relationship_add' );
  56  
  57  $f_rel_type = gpc_get_int( 'rel_type' );
  58  $f_src_bug_id = gpc_get_int( 'src_bug_id' );
  59  $f_dest_bug_id_string = gpc_get_string( 'dest_bug_id' );
  60  
  61  # user has access to update the bug...
  62  access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_src_bug_id );
  63  
  64  $f_dest_bug_id_string = str_replace( ',', '|', $f_dest_bug_id_string );
  65  
  66  $f_dest_bug_id_array = explode( '|', $f_dest_bug_id_string );
  67  
  68  foreach( $f_dest_bug_id_array as $f_dest_bug_id ) {
  69      $f_dest_bug_id = (int)$f_dest_bug_id;
  70  
  71      # source and destination bugs are the same bug...
  72      if ( $f_src_bug_id == $f_dest_bug_id ) {
  73          trigger_error( ERROR_RELATIONSHIP_SAME_BUG, ERROR );
  74      }
  75  
  76      # the related bug exists...
  77      bug_ensure_exists( $f_dest_bug_id );
  78  
  79      # bug is not read-only...
  80      if ( bug_is_readonly( $f_src_bug_id ) ) {
  81          error_parameters( $f_src_bug_id );
  82          trigger_error( ERROR_BUG_READ_ONLY_ACTION_DENIED, ERROR );
  83      }
  84  
  85      # user can access to the related bug at least as viewer...
  86      if ( !access_has_bug_level( VIEWER, $f_dest_bug_id ) ) {
  87          error_parameters( $f_dest_bug_id );
  88          trigger_error( ERROR_RELATIONSHIP_ACCESS_LEVEL_TO_DEST_BUG_TOO_LOW, ERROR );
  89      }
  90  
  91      $t_bug = bug_get( $f_src_bug_id, true );
  92      if( $t_bug->project_id != helper_get_current_project() ) {
  93          # in case the current project is not the same project of the bug we are viewing...
  94          # ... override the current project. This to avoid problems with categories and handlers lists etc.
  95          $g_project_override = $t_bug->project_id;
  96      }
  97  
  98      # check if there is other relationship between the bugs...
  99      $t_old_id_relationship = relationship_same_type_exists( $f_src_bug_id, $f_dest_bug_id, $f_rel_type );
 100  
 101      if ( $t_old_id_relationship == -1 ) {
 102          # the relationship type is exactly the same of the new one. No sense to proceed
 103          trigger_error( ERROR_RELATIONSHIP_ALREADY_EXISTS, ERROR );
 104      }
 105      else if ( $t_old_id_relationship > 0 ) {
 106          # there is already a relationship between them -> we have to update it and not to add a new one
 107          helper_ensure_confirmed( lang_get( 'replace_relationship_sure_msg' ), lang_get( 'replace_relationship_button' ) );
 108  
 109          # Update the relationship
 110          relationship_update( $t_old_id_relationship, $f_src_bug_id, $f_dest_bug_id, $f_rel_type );
 111  
 112          # Add log line to the history (both bugs)
 113          history_log_event_special( $f_src_bug_id, BUG_REPLACE_RELATIONSHIP, $f_rel_type, $f_dest_bug_id );
 114          history_log_event_special( $f_dest_bug_id, BUG_REPLACE_RELATIONSHIP, relationship_get_complementary_type( $f_rel_type ), $f_src_bug_id );
 115      } else {
 116          # Add the new relationship
 117          relationship_add( $f_src_bug_id, $f_dest_bug_id, $f_rel_type );
 118  
 119          # Add log line to the history (both bugs)
 120          history_log_event_special( $f_src_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_dest_bug_id );
 121          history_log_event_special( $f_dest_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type( $f_rel_type ), $f_src_bug_id );
 122      }
 123  
 124      # update bug last updated (just for the src bug)
 125      bug_update_date( $f_src_bug_id );
 126  
 127      # send email notification to the users addressed by both the bugs
 128      email_relationship_added( $f_src_bug_id, $f_dest_bug_id, $f_rel_type );
 129      email_relationship_added( $f_dest_bug_id, $f_src_bug_id, relationship_get_complementary_type( $f_rel_type ) );
 130  }
 131  
 132  form_security_purge( 'bug_relationship_add' );
 133  
 134  print_header_redirect_view( $f_src_bug_id );


Generated: Sat Mar 6 17:17:35 2010 Cross-referenced by PHPXref 0.7