logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

mantisbt/core bug_api.php,1.85,1.86 constant_inc.php,1.32,1.33 email_api.ph: msg#00025

Subject: mantisbt/core bug_api.php,1.85,1.86 constant_inc.php,1.32,1.33 email_api.php,1.101,1.102 history_api.php,1.29,1.30 relationship_api.php,1.23,1.24
Update of /cvsroot/mantisbt/mantisbt/core
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13487

Modified Files:
        bug_api.php constant_inc.php email_api.php history_api.php 
        relationship_api.php 
Log Message:
Commit of Masc's Patches:
Fix 0004506: When cloning a bug you should be able to set the relationship 
Fix 0004484: Show which project a related issue belongs to 
Fix 0004184: Related issues resolved email should be more informative 
Fix 0004224: Can't resolve issue as duplicate of other with existing "related 
to" relationship 

Index: relationship_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/relationship_api.php,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- relationship_api.php        25 Sep 2004 15:05:07 -0000      1.23
+++ relationship_api.php        5 Oct 2004 21:10:14 -0000       1.24
@@ -65,18 +65,53 @@
        class BugRelationshipData {
                var $id;
                var $src_bug_id;
+               var $src_project_id;
                var $dest_bug_id;
+               var $dest_project_id;
                var $type;
        }
 
        # --------------------
-       function relationship_add( $p_src_bug_id, $p_dest_bug_id, 
$p_relationship_type ) {
-               $c_src_bug_id = db_prepare_int( $p_src_bug_id );
-               $c_dest_bug_id = db_prepare_int( $p_dest_bug_id );
-               $c_relationship_type = db_prepare_int( $p_relationship_type );
+       # Return the complementary type of the provided relationship
+       function relationship_get_complementary_type( $p_relationship_type ) {
+               switch ( $p_relationship_type ) {
+                       case BUG_BLOCKS:
+                               return BUG_DEPENDANT;
+                               break;
+                       case BUG_DEPENDANT:
+                               return BUG_BLOCKS;
+                               break;
+                       case BUG_HAS_DUPLICATE:
+                               return BUG_DUPLICATE;
+                               break;
+                       case BUG_DUPLICATE:
+                               return BUG_HAS_DUPLICATE;
+                               break;
+                       case BUG_RELATED:
+                               return BUG_RELATED;
+                               break;
+                       default:
+                               trigger_error( ERROR_GENERIC, ERROR );
+                               break;
+               }
+       }
 
+       # --------------------
+       function relationship_add( $p_src_bug_id, $p_dest_bug_id, 
$p_relationship_type ) {
                $t_mantis_bug_relationship_table = config_get( 
'mantis_bug_relationship_table' );
 
+               if( $p_relationship_type == BUG_BLOCKS || $p_relationship_type 
== BUG_HAS_DUPLICATE ) {
+                       # BUG_BLOCKS or BUG_HAS_DUPLICATE -> swap src and dest
+                       $c_src_bug_id = db_prepare_int( $p_dest_bug_id );
+                       $c_dest_bug_id = db_prepare_int( $p_src_bug_id );
+                       $c_relationship_type = db_prepare_int( 
relationship_get_complementary_type( $p_relationship_type ) );
+               }
+               else {
+                       $c_src_bug_id = db_prepare_int( $p_src_bug_id );
+                       $c_dest_bug_id = db_prepare_int( $p_dest_bug_id );
+                       $c_relationship_type = db_prepare_int( 
$p_relationship_type );
+               }
+
                $query = "INSERT INTO $t_mantis_bug_relationship_table
                                ( source_bug_id, destination_bug_id, 
relationship_type )
                                VALUES
@@ -95,13 +130,21 @@
 
        # --------------------
        function relationship_update( $p_relationship_id, $p_src_bug_id, 
$p_dest_bug_id, $p_relationship_type ) {
-               $c_relationship_id = db_prepare_int( $p_relationship_id );
-               $c_src_bug_id = db_prepare_int( $p_src_bug_id );
-               $c_dest_bug_id = db_prepare_int( $p_dest_bug_id );
-               $c_relationship_type = db_prepare_int( $p_relationship_type );
-
                $t_mantis_bug_relationship_table = config_get( 
'mantis_bug_relationship_table' );
 
+               if( $p_relationship_type == BUG_BLOCKS || $p_relationship_type 
== BUG_HAS_DUPLICATE ) {
+                       # BUG_BLOCKS or BUG_HAS_DUPLICATE -> swap src and dest
+                       $c_src_bug_id = db_prepare_int( $p_dest_bug_id );
+                       $c_dest_bug_id = db_prepare_int( $p_src_bug_id );
+                       $c_relationship_type = db_prepare_int( 
relationship_get_complementary_type( $p_relationship_type ) );
+               }
+               else {
+                       $c_src_bug_id = db_prepare_int( $p_src_bug_id );
+                       $c_dest_bug_id = db_prepare_int( $p_dest_bug_id );
+                       $c_relationship_type = db_prepare_int( 
$p_relationship_type );
+               }
+               $c_relationship_id = db_prepare_int( $p_relationship_id );
+
                $query = "UPDATE $t_mantis_bug_relationship_table
                                SET source_bug_id='$c_src_bug_id',
                                        destination_bug_id='$c_dest_bug_id',
@@ -200,20 +243,28 @@
                $c_src_bug_id = db_prepare_int( $p_src_bug_id );
 
                $t_mantis_bug_relationship_table = config_get( 
'mantis_bug_relationship_table' );
+               $t_mantis_bug_table = config_get( 'mantis_bug_table' );
 
-               $query = "SELECT *
+               $query = "SELECT $t_mantis_bug_relationship_table.id, 
$t_mantis_bug_relationship_table.relationship_type,
+                               $t_mantis_bug_relationship_table.source_bug_id, 
$t_mantis_bug_relationship_table.destination_bug_id,
+                               $t_mantis_bug_table.project_id
                                FROM $t_mantis_bug_relationship_table
+                               INNER JOIN $t_mantis_bug_table ON 
$t_mantis_bug_relationship_table.destination_bug_id = $t_mantis_bug_table.id
                                WHERE source_bug_id='$c_src_bug_id'
-                               ORDER BY relationship_type, id";
+                               ORDER BY relationship_type, 
$t_mantis_bug_relationship_table.id";
                $result = db_query( $query );
 
+               $t_src_project_id = bug_get_field( $p_src_bug_id, 'project_id' 
);
+
                $t_bug_relationship_data = array( new BugRelationshipData );
                $t_relationship_count = db_num_rows( $result );
                for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) {
                        $row = db_fetch_array( $result );
                        $t_bug_relationship_data[$i]->id = $row['id'];
                        $t_bug_relationship_data[$i]->src_bug_id = 
$row['source_bug_id'];
+                       $t_bug_relationship_data[$i]->src_project_id = 
$t_src_project_id;
                        $t_bug_relationship_data[$i]->dest_bug_id = 
$row['destination_bug_id'];
+                       $t_bug_relationship_data[$i]->dest_project_id = 
$row['project_id'];
                        $t_bug_relationship_data[$i]->type = 
$row['relationship_type'];
                }
                unset( $t_bug_relationship_data[$t_relationship_count] );
@@ -226,20 +277,28 @@
                $c_dest_bug_id = db_prepare_int( $p_dest_bug_id );
 
                $t_mantis_bug_relationship_table = config_get( 
'mantis_bug_relationship_table' );
+               $t_mantis_bug_table = config_get( 'mantis_bug_table' );
 
-               $query = "SELECT *
+               $query = "SELECT $t_mantis_bug_relationship_table.id, 
$t_mantis_bug_relationship_table.relationship_type,
+                               $t_mantis_bug_relationship_table.source_bug_id, 
$t_mantis_bug_relationship_table.destination_bug_id,
+                               $t_mantis_bug_table.project_id
                                FROM $t_mantis_bug_relationship_table
+                               INNER JOIN $t_mantis_bug_table ON 
$t_mantis_bug_relationship_table.source_bug_id = $t_mantis_bug_table.id
                                WHERE destination_bug_id='$c_dest_bug_id'
-                               ORDER BY relationship_type, id";
+                               ORDER BY relationship_type, 
$t_mantis_bug_relationship_table.id";
                $result = db_query( $query );
 
+               $t_dest_project_id = bug_get_field( $p_dest_bug_id, 
'project_id' );
+
                $t_bug_relationship_data = array( new BugRelationshipData );
                $t_relationship_count = db_num_rows( $result );
                for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) {
                        $row = db_fetch_array( $result );
                        $t_bug_relationship_data[$i]->id = $row['id'];
                        $t_bug_relationship_data[$i]->src_bug_id = 
$row['source_bug_id'];
+                       $t_bug_relationship_data[$i]->src_project_id = 
$row['project_id'];
                        $t_bug_relationship_data[$i]->dest_bug_id = 
$row['destination_bug_id'];
+                       $t_bug_relationship_data[$i]->dest_project_id = 
$t_dest_project_id;
                        $t_bug_relationship_data[$i]->type = 
$row['relationship_type'];
                }
                unset( $t_bug_relationship_data[$t_relationship_count] );
@@ -248,6 +307,37 @@
        }
 
        # --------------------
+       function relationship_get_all( $p_bug_id, &$p_is_different_projects ) {
+               $t_src = relationship_get_all_src( $p_bug_id );
+               $t_dest = relationship_get_all_dest( $p_bug_id );
+               $t_all = array_merge( $t_src, $t_dest );
+
+               $p_is_different_projects = false;
+               for ( $i = 0 ; $i < count( $t_all ) ; $i++ ) {
+                       $p_is_different_projects |= ( 
$t_all[$i]->src_project_id != $t_all[$i]->dest_project_id );
+               }
+               return $t_all;
+       }
+
+       # --------------------
+       # convert the relationship type in the type from the src/dest issues 
point of view
+       # i.e. issue A  is dependent (BUG_DEPENDANT) on issue B
+       #      passing B, A and this relationship as parameters, the return 
value will be BUG_BLOCKS
+       #      (issue B blocks issue A)
+       # return the relationship type using the information in the p_rel 
structure but src/dest issues as indicated
+       function relationship_conv_type_to_this_src_dest( $p_src_bug_id, 
$p_dest_bug_id, $p_rel ) {
+               if ( $p_rel->src_bug_id == $p_src_bug_id && $p_rel->dest_bug_id 
== $p_dest_bug_id ) {
+                       return $p_rel->type;
+               }
+               else if ( $p_rel->src_bug_id == $p_dest_bug_id && 
$p_rel->dest_bug_id == $p_src_bug_id ) {
+                       return relationship_get_complementary_type( 
$p_rel->type );
+               }
+               else {
+                       trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR );
+               }
+       }
+
+       # --------------------
        # check if there is a relationship between two bugs
        # return id if found 0 otherwise
        function relationship_exists( $p_src_bug_id, $p_dest_bug_id ) {
@@ -280,6 +370,32 @@
        }
 
        # --------------------
+       # check if there is a relationship between two bugs
+       # return:
+       #   0 if the relationship is not found
+       #  -1 if the relationship is found and it's of the same type $p_rel_type
+       #  id if the relationship is found and it's of a different time (this 
means it can be replaced with the new type $p_rel_type
+       function relationship_same_type_exists( $p_src_bug_id, $p_dest_bug_id, 
$p_rel_type ) {
+               # Check if there is already a relationship set between them
+               $t_id_relationship = relationship_exists( $p_src_bug_id, 
$p_dest_bug_id );
+
+               if ( $t_id_relationship > 0 ) {
+                       # if there is...
+
+                       # get all the relationship info
+                       $t_relationship = relationship_get( $t_id_relationship 
);
+
+                       if ( $t_relationship->src_bug_id == $p_src_bug_id && 
$t_relationship->dest_bug_id == $p_dest_bug_id ) {
+                               if( $t_relationship->type == $p_rel_type ) 
$t_id_relationship = -1;
+                       }
+                       else {
+                               if( $t_relationship->type == 
relationship_get_complementary_type( $p_rel_type ) ) $t_id_relationship = -1;
+                       }
+               }
+               return $t_id_relationship;
+       }
+
+       # --------------------
        # retrieve the linked bug id of the relationship: provide src -> return 
dest; provide dest -> return src
        function relationship_get_linked_bug_id( $p_relationship_id, $p_bug_id 
) {
 
@@ -386,21 +502,21 @@
 
        # --------------------
        # return formatted string with all the details on the requested 
relationship
-       function relationship_get_details( $p_bug_id, $p_relationship, $p_html 
= false, $p_html_preview = false, $p_user_id = null ) {
+       function relationship_get_details( $p_bug_id, $p_relationship, $p_html 
= false, $p_html_preview = false, $p_show_project = false ) {
                $t_summary_wrap_at = strlen( config_get( 'email_separator2' ) ) 
- 28;
 
-               if ( $p_user_id === null ) {
-                       $p_user_id = auth_get_current_user_id();
-               }
+               $p_user_id = auth_get_current_user_id();
 
                if ( $p_bug_id == $p_relationship->src_bug_id ) {
                        # root bug is in the src side, related bug in the dest 
side
                        $t_related_bug_id = $p_relationship->dest_bug_id;
+                       $t_related_project_name = project_get_name( 
$p_relationship->dest_project_id );
                        $t_relationship_descr = 
relationship_get_description_src_side( $p_relationship->type );
                }
                else {
                        # root bug is in the dest side, related bug in the src 
side
                        $t_related_bug_id = $p_relationship->src_bug_id;
+                       $t_related_project_name = project_get_name( 
$p_relationship->src_project_id );
                        $t_relationship_descr = 
relationship_get_description_dest_side( $p_relationship->type );
                }
 
@@ -426,26 +542,33 @@
                $t_status = string_attribute( get_enum_element( 'status', 
$t_bug->status ) );
                $t_resolution = string_attribute( get_enum_element( 
'resolution', $t_bug->resolution ) );
 
-               $t_relationship_info_html = '<nobr>' . $t_relationship_descr . 
'</nobr></td>';
+               $t_relationship_info_html = $t_td . '<nobr>' . 
$t_relationship_descr . '</nobr>&nbsp;</td>';
                if ( $p_html_preview == false ) {
                        $t_relationship_info_html .= '<td><a href="' . 
string_get_bug_view_url( $t_related_bug_id ) . '">' . bug_format_id( 
$t_related_bug_id ) . '</a></td>';
-                       $t_relationship_info_html .= '<td><a title="' . 
$t_resolution . '"><u>' . $t_status . '</u>&nbsp;</a></td>' . $t_td;
+                       $t_relationship_info_html .= '<td><a title="' . 
$t_resolution . '"><u>' . $t_status . '</u>&nbsp;</a></td>';
                }
                else {
                        $t_relationship_info_html .= $t_td . bug_format_id( 
$t_related_bug_id ) . '</td>';
-                       $t_relationship_info_html .= $t_td . $t_status . 
'&nbsp;</td>' . $t_td;
+                       $t_relationship_info_html .= $t_td . $t_status . 
'&nbsp;</td>';
                }
 
                $t_relationship_info_text = str_pad( $t_relationship_descr, 20 
);
                $t_relationship_info_text .= str_pad( bug_format_id( 
$t_related_bug_id ), 8 );
 
                # get the handler name of the related bug
+               $t_relationship_info_html .= $t_td;
                if ( $t_bug->handler_id > 0 )  {
                        $t_relationship_info_html .= '<nobr>' . user_get_name(  
$t_bug->handler_id ) . '</nobr>';
                }
+               $t_relationship_info_html .= '&nbsp;</td>';
+
+               # add project name
+               if( $p_show_project ) {
+                       $t_relationship_info_html .= $t_td . 
$t_related_project_name . '&nbsp;</td>';
+               }
 
                # add summary
-               $t_relationship_info_html .= '&nbsp;</td>' . $t_td . 
$t_bug->summary;
+               $t_relationship_info_html .= $t_td . $t_bug->summary;
                if( strlen( $t_bug->summary ) <= $t_summary_wrap_at ) {
                        $t_relationship_info_text .= $t_bug->summary;
                }
@@ -460,13 +583,14 @@
                        }
                }
 
+               $t_relationship_info_html .= '&nbsp;</td>';
                $t_relationship_info_text .= "\n";
 
                if ( $p_html_preview == false ) {
-                       $t_relationship_info_html = '<tr bgcolor="' . 
get_status_color( $t_bug->status ) . '">' . $t_td . $t_relationship_info_html . 
'&nbsp;</td></tr>';
+                       $t_relationship_info_html = '<tr bgcolor="' . 
get_status_color( $t_bug->status ) . '">' . $t_relationship_info_html . '</tr>' 
. "\n";
                }
                else {
-                       $t_relationship_info_html = '<tr>' . $t_td . 
$t_relationship_info_html . '&nbsp;</td></tr>';
+                       $t_relationship_info_html = '<tr>' . 
$t_relationship_info_html . '</tr>';
                }
 
                if ( $p_html == true ) {
@@ -482,22 +606,19 @@
        # print ALL the RELATIONSHIPS OF A SPECIFIC BUG
        function relationship_get_summary_html( $p_bug_id ) {
                $t_summary = '';
+               $t_show_project = false;
 
-               $t_relationship = relationship_get_all_src( $p_bug_id );
-               $t_relationship_count = count( $t_relationship );
-               for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) {
-                       $t_summary .= relationship_get_details ( $p_bug_id, 
$t_relationship[$i], true, false );
-               }
+               $t_relationship_all = relationship_get_all( $p_bug_id, 
$t_show_project );
+               $t_relationship_all_count = count( $t_relationship_all );
 
-               $t_relationship = relationship_get_all_dest( $p_bug_id );
-               $t_relationship_count = count( $t_relationship );
-               for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) {
-                       $t_summary .= relationship_get_details ( $p_bug_id, 
$t_relationship[$i], true, false );
+               #prepare the relationships table
+               for ( $i = 0 ; $i < $t_relationship_all_count ; $i++ ) {
+                       $t_summary .= relationship_get_details ( $p_bug_id, 
$t_relationship_all[$i], true, false, $t_show_project );
                }
 
                if ( !is_blank( $t_summary ) ) {
                        if ( relationship_can_resolve_bug( $p_bug_id ) == false 
) {
-                               $t_summary .= '<tr class="row-2"><td 
colspan="5"><b>' . lang_get( 'relationship_warning_blocking_bugs_not_resolved' 
) . '</b></td></tr>';
+                               $t_summary .= '<tr class="row-2"><td colspan=' 
. (5 + $t_show_project) . '><b>' . lang_get( 
'relationship_warning_blocking_bugs_not_resolved' ) . '</b></td></tr>';
                        }
                        $t_summary = '<table border="0" width="100%" 
cellpadding="0" cellspacing="1">' . $t_summary . '</table>';
                }
@@ -509,22 +630,19 @@
        # print ALL the RELATIONSHIPS OF A SPECIFIC BUG
        function relationship_get_summary_html_preview( $p_bug_id ) {
                $t_summary = '';
+               $t_show_project = false;
 
-               $t_relationship = relationship_get_all_src( $p_bug_id );
-               $t_relationship_count = count( $t_relationship );
-               for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) {
-                       $t_summary .= relationship_get_details ( $p_bug_id, 
$t_relationship[$i], true, true );
-               }
+               $t_relationship_all = relationship_get_all( $p_bug_id, 
$t_show_project );
+               $t_relationship_all_count = count( $t_relationship_all );
 
-               $t_relationship = relationship_get_all_dest( $p_bug_id );
-               $t_relationship_count = count( $t_relationship );
-               for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) {
-                       $t_summary .= relationship_get_details ( $p_bug_id, 
$t_relationship[$i], true, true );
+               #prepare the relationships table
+               for ( $i = 0 ; $i < $t_relationship_all_count ; $i++ ) {
+                       $t_summary .= relationship_get_details ( $p_bug_id, 
$t_relationship_all[$i], true, true, $t_show_project );
                }
 
                if ( !is_blank( $t_summary ) ) {
                        if ( relationship_can_resolve_bug( $p_bug_id ) == false 
) {
-                               $t_summary .= '<tr class="print"><td 
class="print" colspan="5"><b>' . lang_get( 
'relationship_warning_blocking_bugs_not_resolved' ) . '</b></td></tr>';
+                               $t_summary .= '<tr class="print"><td 
class="print" colspan=' . (5 + $t_show_project) . '><b>' . lang_get( 
'relationship_warning_blocking_bugs_not_resolved' ) . '</b></td></tr>';
                        }
                        $t_summary = '<table border="0" width="100%" 
cellpadding="0" cellspacing="1">' . $t_summary . '</table>';
                }
@@ -539,17 +657,14 @@
                $t_email_separator2 = config_get( 'email_separator2' );
 
                $t_summary = "";
+               $t_show_project = false;
 
-               $t_relationship = relationship_get_all_src( $p_bug_id );
-               $t_relationship_count = count( $t_relationship );
-               for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) {
-                       $t_summary .= relationship_get_details ( $p_bug_id, 
$t_relationship[$i], false );
-               }
+               $t_relationship_all = relationship_get_all( $p_bug_id, 
$t_show_project );
+               $t_relationship_all_count = count( $t_relationship_all );
 
-               $t_relationship = relationship_get_all_dest( $p_bug_id );
-               $t_relationship_count = count( $t_relationship );
-               for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) {
-                       $t_summary .= relationship_get_details ( $p_bug_id, 
$t_relationship[$i], false );
+               #prepare the relationships table
+               for ( $i = 0 ; $i < $t_relationship_all_count ; $i++ ) {
+                       $t_summary .= relationship_get_details ( $p_bug_id, 
$t_relationship_all[$i], false );
                }
 
                if ($t_summary != "") {
@@ -565,6 +680,33 @@
        }
 
        # --------------------
+       # print HTML relationship listbox
+       function relationship_list_box( $p_default_rel_type = -1 ) {
+?>
+<select name="rel_type">
+<option value="<?php echo BUG_RELATED ?>"<?php echo ( $p_default_rel_type == 
BUG_RELATED ? ' selected' : '' ) ?>><?php echo lang_get( 'related_to' ) 
?></option>
+<option value="<?php echo BUG_DEPENDANT ?>"<?php echo ( $p_default_rel_type == 
BUG_DEPENDANT ? ' selected' : '' ) ?>><?php echo lang_get( 'dependant_on' ) 
?></option>
+<option value="<?php echo BUG_BLOCKS ?>" <?php echo ( $p_default_rel_type == 
BUG_BLOCKS ? ' selected' : '' ) ?>><?php echo lang_get( 'blocks' ) ?></option>
+<option value="<?php echo BUG_DUPLICATE ?>"<?php echo ( $p_default_rel_type == 
BUG_DUPLICATE ? ' selected' : '' ) ?>><?php echo lang_get( 'duplicate_of' ) 
?></option>
+<option value="<?php echo BUG_HAS_DUPLICATE ?>"<?php echo ( 
$p_default_rel_type == BUG_HAS_DUPLICATE ? ' selected' : '' ) ?>><?php echo 
lang_get( 'has_duplicate' ) ?></option>
+</select>
+<?php
+       }
+
+       # --------------------
+       # print HTML relationship listbox
+       function relationship_list_box_for_cloned_bug( $p_default_rel_type = -1 
) {
+?>
+<select name="rel_type">
+<option value="-1"<?php echo ( $p_default_rel_type == -1 ? ' selected' : '' ) 
?>><?php echo lang_get( 'no_relationship' ) ?></option>
+<option value="<?php echo BUG_RELATED ?>"<?php echo ( $p_default_rel_type == 
BUG_RELATED ? ' selected' : '' ) ?>><?php echo lang_get( 'related_to' ) 
?></option>
+<option value="<?php echo BUG_DEPENDANT ?>"<?php echo ( $p_default_rel_type == 
BUG_DEPENDANT ? ' selected' : '' ) ?>><?php echo lang_get( 'dependant_on' ) 
?></option>
+<option value="<?php echo BUG_BLOCKS ?>" <?php echo ( $p_default_rel_type == 
BUG_BLOCKS ? ' selected' : '' ) ?>><?php echo lang_get( 'blocks' ) ?></option>
+</select>
+<?php
+       }
+
+       # --------------------
        # print HTML relationship form
        function relationship_view_box( $p_bug_id ) {
 ?>
@@ -577,7 +719,6 @@
                <?php
                        collapse_icon( 'relationships' );
                        echo lang_get( 'bug_relationships' );
-
                        if ( ON == config_get( 'relationship_graph_enable' ) ) {
                ?>
                <span class="small"><?php print_bracket_link( 
'bug_relationship_graph.php?bug_id=' . $p_bug_id . '&graph=relation', lang_get( 
'relation_graph' ) ) ?></span>
@@ -595,19 +736,13 @@
                        if ( access_has_bug_level( config_get( 
'update_bug_threshold' ), $p_bug_id ) ) {
 ?>
 <tr class="row-1">
-       <td class="category"><?php PRINT lang_get( 'add_new_relationship' ) 
?></td>
-       <td><?php PRINT lang_get( 'this_bug' ) ?>
+       <td class="category"><?php echo lang_get( 'add_new_relationship' ) 
?></td>
+       <td><?php echo lang_get( 'this_bug' ) ?>
                <form method="POST" action="bug_relationship_add.php">
-               <input type="hidden" name="src_bug_id" value="<?php PRINT 
$p_bug_id ?>" size="4" />
-               <select name="rel_type">
-               <option value="<?php PRINT BUG_RELATED ?>"><?php PRINT 
lang_get( 'related_to' ) ?></option>
-               <option value="<?php PRINT BUG_DEPENDANT ?>"><?php PRINT 
lang_get( 'dependant_on' ) ?></option>
-               <option value="<?php PRINT BUG_BLOCKS ?>"><?php PRINT lang_get( 
'blocks' ) ?></option>
-               <option value="<?php PRINT BUG_DUPLICATE ?>"><?php PRINT 
lang_get( 'duplicate_of' ) ?></option>
-               <option value="<?php PRINT BUG_HAS_DUPLICATE ?>"><?php PRINT 
lang_get( 'has_duplicate' ) ?></option>
-               </select>
+               <input type="hidden" name="src_bug_id" value="<?php echo 
$p_bug_id ?>" size="4" />
+               <? relationship_list_box( -1 ) ?>
                <input type="text" name="dest_bug_id" value="" maxlength="7" />
-               <input type="submit" name="add_relationship" class="button" 
value="<?php PRINT lang_get( 'add_new_relationship_button' ) ?>" />
+               <input type="submit" name="add_relationship" class="button" 
value="<?php echo lang_get( 'add_new_relationship_button' ) ?>" />
                </form>
        </td></tr>
 <?php
@@ -615,7 +750,7 @@
                }
 ?>
 <tr>
-       <td colspan="2"><?php PRINT relationship_get_summary_html( $p_bug_id ) 
?></td>
+       <td colspan="2"><?php echo relationship_get_summary_html( $p_bug_id ) 
?></td>
 </tr>
 </table>
 

Index: bug_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/bug_api.php,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- bug_api.php 4 Oct 2004 16:53:13 -0000       1.85
+++ bug_api.php 5 Oct 2004 21:10:14 -0000       1.86
@@ -1108,34 +1108,33 @@
                        bug_ensure_exists( $p_duplicate_id );
 
                        if( ON == config_get( 'enable_relationship' ) ) {
-                               $t_relationship_id = relationship_exists( 
$p_bug_id, $p_duplicate_id );
-                               if( $t_relationship_id > 0 ) {
-                                       # there is already a relationship 
between the bugs... we check if it's of the right type (otherwise error)
-
-                                       $t_relationship = relationship_get( 
$t_relationship_id );
-                                       if( $t_relationship != null ) {
-                                               if( ( $t_relationship->type != 
BUG_DUPLICATE ) && ( $t_relationship->type != BUG_HAS_DUPLICATE )) {
-                                                       # the relationship is 
not duplicates/has duplicated -> error
-                                                       trigger_error( 
ERROR_RELATIONSHIP_ALREADY_EXISTS, ERROR );
-                                               }
-                                       }
+                               # check if there is other relationship between 
the bugs...
+                               $t_id_relationship = 
relationship_same_type_exists( $p_bug_id, $p_duplicate_id, BUG_DUPLICATE );
 
+                               if ( $t_id_relationship == -1 ) {
+                                       # the relationship type is already set. 
Nothing to do
                                }
-                               else {
-                                       # no relationship found... we add the 
duplicate relationship
+                               else if ( $t_id_relationship > 0 ) {
+                                       # there is already a relationship 
between them -> we have to update it and not to add a new one
+                                       helper_ensure_confirmed( lang_get( 
'replace_relationship_sure_msg' ), lang_get( 'replace_relationship_button' ) );
 
-                                       # user can access to the related bug at 
least as viewer...
-                                       if( !access_has_bug_level( VIEWER, 
$p_duplicate_id ) ) {
-                                               error_parameters( 
$p_duplicate_id );
-                                               trigger_error( 
ERROR_RELATIONSHIP_ACCESS_LEVEL_TO_DEST_BUG_TOO_LOW, ERROR );
-                                       }
+                                       # Update the relationship
+                                       relationship_update( 
$t_id_relationship, $p_bug_id, $p_duplicate_id, BUG_DUPLICATE );
 
-                                       # Relationship feature active
+                                       # Add log line to the history (both 
bugs)
+                                       history_log_event_special( $p_bug_id, 
BUG_REPLACE_RELATIONSHIP, BUG_DUPLICATE, $p_duplicate_id );
+                                       history_log_event_special( 
$p_duplicate_id, BUG_REPLACE_RELATIONSHIP, BUG_HAS_DUPLICATE, $p_bug_id );
+                               }
+                               else {
+                                       # Add the new relationship
                                        relationship_add( $p_bug_id, 
$p_duplicate_id, BUG_DUPLICATE );
+
+                                       # Add log line to the history (both 
bugs)
                                        history_log_event_special( $p_bug_id, 
BUG_ADD_RELATIONSHIP, BUG_DUPLICATE, $p_duplicate_id );
                                        history_log_event_special( 
$p_duplicate_id, BUG_ADD_RELATIONSHIP, BUG_HAS_DUPLICATE, $p_bug_id );
                                }
                        }
+
                        bug_set_field( $p_bug_id, 'duplicate_id', 
(int)$p_duplicate_id );
                        # MASC RELATIONSHIP
                }

Index: history_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/history_api.php,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- history_api.php     26 Sep 2004 22:57:04 -0000      1.29
+++ history_api.php     5 Oct 2004 21:10:14 -0000       1.30
@@ -305,6 +305,10 @@
                                        $t_note = lang_get( 
'relationship_added' );
                                        $t_change = 
relationship_get_description_for_history( $p_old_value ) . ' ' . bug_format_id( 
$p_new_value );
                                        break;
+                               case BUG_REPLACE_RELATIONSHIP:
+                                       $t_note = lang_get( 
'relationship_replaced' );
+                                       $t_change = 
relationship_get_description_for_history( $p_old_value ) . ' ' . bug_format_id( 
$p_new_value );
+                                       break;
                                case BUG_DEL_RELATIONSHIP:
                                        $t_note = lang_get( 
'relationship_deleted' );
                                        $t_change = 
relationship_get_description_for_history( $p_old_value ) . ' ' . bug_format_id( 
$p_new_value );

Index: email_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/email_api.php,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- email_api.php       26 Sep 2004 02:05:14 -0000      1.101
+++ email_api.php       5 Oct 2004 21:10:14 -0000       1.102
@@ -156,7 +156,6 @@
        # ON or OFF.
        function email_notify_flag( $action, $flag ) {
                global  $g_notify_flags, $g_default_notify_flags;
-
                if ( isset ( $g_notify_flags[$action][$flag] ) ) {
                        return $g_notify_flags[$action][$flag];
                } elseif ( isset ( $g_default_notify_flags[$flag] ) ) {
@@ -389,7 +388,7 @@
        # $p_notify_type: use check who she get notified of such event.
        # $p_message_id: message id to be translated and included at the top of 
the email message.
        # Return false if it were problems sending email
-       function email_generic( $p_bug_id, $p_notify_type, $p_message_id = null 
) {
+       function email_generic( $p_bug_id, $p_notify_type, $p_message_id = 
null, $p_header_optional_params = null ) {
                $t_ok = true;
                if ( ON === config_get( 'enable_email_notification' ) ) {
                        ignore_user_abort( true );
@@ -405,7 +404,7 @@
                                # send email to every recipient
                                foreach ( $t_recipients as $t_user_id => 
$t_user_email ) {
                                        $t_visible_bug_data = 
email_build_visible_bug_data( $t_user_id, $p_bug_id, $p_message_id );
-                                       $t_ok = email_bug_info_to_one_user( 
$t_visible_bug_data, $p_message_id, $t_project_id, $t_user_id ) && $t_ok;
+                                       $t_ok = email_bug_info_to_one_user( 
$t_visible_bug_data, $p_message_id, $t_project_id, $t_user_id, 
$p_header_optional_params ) && $t_ok;
                                }
                        }
                }
@@ -416,15 +415,57 @@
        # --------------------
        # send notices when a relationship is ADDED
        # MASC RELATIONSHIP
-       function email_relationship_added( $p_bug_id ) {
-               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_relationship_added' );
+       function email_relationship_added( $p_bug_id, $p_related_bug_id, 
$p_rel_type ) {
+               $t_opt = array();
+               $t_opt[] = bug_format_id( $p_related_bug_id );
+               switch ( $p_rel_type ) {
+                       case BUG_BLOCKS:
+                               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_blocks_relationship_added', $t_opt );
+                               break;
+                       case BUG_DEPENDANT:
+                               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_dependant_on_relationship_added', $t_opt );
+                               break;
+                       case BUG_HAS_DUPLICATE:
+                               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_has_duplicate_relationship_added', $t_opt 
);
+                               break;
+                       case BUG_DUPLICATE:
+                               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_duplicate_of_relationship_added', $t_opt );
+                               break;
+                       case BUG_RELATED:
+                               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_related_to_relationship_added', $t_opt );
+                               break;
+                       default:
+                               trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, 
ERROR );
+                               break;
+                       }
        }
 
        # --------------------
        # send notices when a relationship is DELETED
        # MASC RELATIONSHIP
-       function email_relationship_deleted( $p_bug_id ) {
-               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_relationship_deleted' );
+       function email_relationship_deleted( $p_bug_id, $p_related_bug_id, 
$p_rel_type ) {
+               $t_opt = array();
+               $t_opt[] = bug_format_id( $p_related_bug_id );
+               switch ( $p_rel_type ) {
+                       case BUG_BLOCKS:
+                               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_blocks_relationship_deleted', $t_opt );
+                               break;
+                       case BUG_DEPENDANT:
+                               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_dependant_on_relationship_deleted', $t_opt 
);
+                               break;
+                       case BUG_HAS_DUPLICATE:
+                               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_has_duplicate_relationship_deleted', 
$t_opt );
+                               break;
+                       case BUG_DUPLICATE:
+                               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_duplicate_of_relationship_deleted', $t_opt 
);
+                               break;
+                       case BUG_RELATED:
+                               email_generic( $p_bug_id, 'relation', 
'email_notification_title_for_action_related_to_relationship_deleted', $t_opt );
+                               break;
+                       default:
+                               trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, 
ERROR );
+                               break;
+                       }
        }
 
        # --------------------
@@ -460,7 +501,9 @@
                                $t_status = bug_get_field( $t_src_bug_id, 
'status' );
                                if ( $t_status < config_get( 
'bug_resolved_status_threshold' ) ) {
                                        # sent the notification just for parent 
bugs not resolved/closed
-                                       email_generic( $t_src_bug_id, 
'handler', $p_message_id );
+                                       $t_opt = array();
+                                       $t_opt[] = bug_format_id( $p_bug_id );
+                                       email_generic( $t_src_bug_id, 
'handler', $p_message_id, $t_opt );
                                }
                        }
                }
@@ -755,7 +798,7 @@
        # --------------------
        # Send bug info to given user
        # return true on success
-       function email_bug_info_to_one_user( $p_visible_bug_data, 
$p_message_id, $p_project_id, $p_user_id ) {
+       function email_bug_info_to_one_user( $p_visible_bug_data, 
$p_message_id, $p_project_id, $p_user_id, $p_header_optional_params = null ) {
 
                $t_user_email = user_get_email( $p_user_id );
 
@@ -776,6 +819,11 @@
                # build message
 
                $t_message = lang_get_defaulted( $p_message_id, null );
+
+               if ( is_array( $p_header_optional_params ) ) {
+                       $t_message = vsprintf( $t_message, 
$p_header_optional_params );
+               }
+
                if ( ( $t_message !== null ) && ( !is_blank( $t_message ) ) ) {
                        $t_message .= "\n";
                }

Index: constant_inc.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/constant_inc.php,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- constant_inc.php    5 Oct 2004 17:20:33 -0000       1.32
+++ constant_inc.php    5 Oct 2004 21:10:14 -0000       1.33
@@ -141,6 +141,7 @@
        define( 'BUG_CLONED_TO',                                20 );
        define( 'BUG_CREATED_FROM',                     21 );
        define( 'CHECKIN',                              22 );
+       define( 'BUG_REPLACE_RELATIONSHIP',             23 );
 
        # bug relationship constants
        define( 'BUG_DUPLICATE',        0 );



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl


<Prev in Thread] Current Thread [Next in Thread>