[ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 # Mantis - a php based bugtracking system 3 4 # Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 5 # Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net 6 7 # Mantis is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # Mantis is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Mantis. If not, see <http://www.gnu.org/licenses/>. 19 20 # -------------------------------------------------------- 21 # $Id: relationship_api.php,v 1.45.2.1 2007-10-13 22:35:41 giallu Exp $ 22 # -------------------------------------------------------- 23 24 ### Relationship API ### 25 26 $t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR; 27 28 require_once ( $t_core_dir . 'collapse_api.php' ); 29 30 # ====================================================================== 31 # Author: Marcello Scata' <marcelloscata at users.sourceforge.net> ITALY 32 # ====================================================================== 33 # RELATIONSHIP DEFINITIONS 34 # * Child/parent relationship: 35 # the child bug is generated by the parent bug or is directly linked with the parent with the following meaning 36 # the child bug has to be resolved before resolving the parent bug (the child bug "blocks" the parent bug) 37 # example: bug A is child bug of bug B. It means: A blocks B and B is blocked by A 38 # * General relationship: 39 # two bugs related each other without any hierarchy dependance 40 # bugs A and B are related 41 # * Duplicates: 42 # it's used to mark a bug as duplicate of an other bug already stored in the database 43 # bug A is marked as duplicate of B. It means: A duplicates B, B has duplicates 44 # 45 # Relations are always visible in the email body 46 # -------------------------------------------------------------------- 47 # ADD NEW RELATIONSHIP 48 # - Permission: user can update the source bug and at least view the destination bug 49 # - Action recorded in the history of both the bugs 50 # - Email notification sent to the users of both the bugs based based on the 'updated' bug notify type. 51 # -------------------------------------------------------- 52 # DELETE RELATIONSHIP 53 # - Permission: user can update the source bug and at least view the destination bug 54 # - Action recorded in the history of both the bugs 55 # - Email notification sent to the users of both the bugs based based on the 'updated' bug notify type. 56 # -------------------------------------------------------- 57 # RESOLVE/CLOSE BUGS WITH BLOCKING CHILD BUGS STILL OPEN 58 # Just a warning is print out on the form when an user attempts to resolve or close a bug with 59 # related bugs in relation BUG_DEPENDANT still not resolved. 60 # Anyway the user can force the resolving/closing action. 61 # -------------------------------------------------------- 62 # EMAIL NOTIFICATION TO PARENT BUGS WHEN CHILDREN BUGS ARE RESOLVED/CLOSED 63 # Every time a child bug is resolved or closed, an email notification is sent directly to all the handlers 64 # of the parent bugs. The notification is sent to bugs not already marked as resolved or closed. 65 # -------------------------------------------------------- 66 # ADD CHILD 67 # This function gives the opportunity to generate a child bug. In details the function: 68 # - create a new bug with the same basic information of the parent bug (plus the custom fields) 69 # - copy all the attachment of the parent bug to the child 70 # - not copy history, bugnotes, monitoring users 71 # - set a relationship between parent and child 72 # -------------------------------------------------------- 73 74 class BugRelationshipData { 75 var $id; 76 var $src_bug_id; 77 var $src_project_id; 78 var $dest_bug_id; 79 var $dest_project_id; 80 var $type; 81 } 82 83 $g_relationships = array(); 84 $g_relationships[ BUG_DEPENDANT ] = array( 85 '#forward' => TRUE, 86 '#complementary' => BUG_BLOCKS, 87 '#description' => 'dependant_on', 88 '#notify_added' => 'email_notification_title_for_action_dependant_on_relationship_added', 89 '#notify_deleted' => 'email_notification_title_for_action_dependant_on_relationship_deleted', 90 '#edge_style' => array ('color' => '#C00000','dir' => 'back'), 91 ); 92 $g_relationships[ BUG_BLOCKS ] = array( 93 '#forward' => FALSE, 94 '#complementary' => BUG_DEPENDANT, 95 '#description' => 'blocks', 96 '#notify_added' => 'email_notification_title_for_action_blocks_relationship_added', 97 '#notify_deleted' => 'email_notification_title_for_action_blocks_relationship_deleted', 98 '#edge_style' => array ('color' => '#C00000','dir' => 'forward'), 99 ); 100 $g_relationships[ BUG_DUPLICATE ] = array( 101 '#forward' => TRUE, 102 '#complementary' => BUG_HAS_DUPLICATE, 103 '#description' => 'duplicate_of', 104 '#notify_added' => 'email_notification_title_for_action_duplicate_of_relationship_added', 105 '#notify_deleted' => 'email_notification_title_for_action_duplicate_of_relationship_deleted', 106 '#edge_style' => array ('style' => 'dashed','color' => '#808080'), 107 ); 108 $g_relationships[ BUG_HAS_DUPLICATE ] = array( 109 '#forward' => FALSE, 110 '#complementary' => BUG_DUPLICATE, 111 '#description' => 'has_duplicate', 112 '#notify_added' => 'email_notification_title_for_action_has_duplicate_relationship_added', 113 '#notify_deleted' => 'email_notification_title_for_action_has_duplicate_relationship_deleted', 114 ); 115 $g_relationships[ BUG_RELATED ] = array( 116 '#forward' => TRUE, 117 '#complementary' => BUG_RELATED, 118 '#description' => 'related_to', 119 '#notify_added' => 'email_notification_title_for_action_related_to_relationship_added', 120 '#notify_deleted' => 'email_notification_title_for_action_related_to_relationship_deleted', 121 ); 122 123 if ( file_exists( dirname( dirname( __FILE__ ) ).DIRECTORY_SEPARATOR.'custom_relationships_inc.php' ) ) { 124 require_once( dirname( dirname( __FILE__ ) ).DIRECTORY_SEPARATOR.'custom_relationships_inc.php' ); 125 } 126 127 128 # -------------------- 129 # Return the complementary type of the provided relationship 130 function relationship_get_complementary_type( $p_relationship_type ) { 131 global $g_relationships; 132 if ( !isset( $g_relationships[ $p_relationship_type ] ) ) { 133 trigger_error( ERROR_GENERIC, ERROR ); 134 } 135 return $g_relationships[ $p_relationship_type ][ '#complementary' ]; 136 } 137 138 # -------------------- 139 function relationship_add( $p_src_bug_id, $p_dest_bug_id, $p_relationship_type ) { 140 $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); 141 142 global $g_relationships; 143 if ( $g_relationships[ $p_relationship_type ][ '#forward' ] === FALSE ) { 144 $c_src_bug_id = db_prepare_int( $p_dest_bug_id ); 145 $c_dest_bug_id = db_prepare_int( $p_src_bug_id ); 146 $c_relationship_type = db_prepare_int( relationship_get_complementary_type( $p_relationship_type ) ); 147 } else { 148 $c_src_bug_id = db_prepare_int( $p_src_bug_id ); 149 $c_dest_bug_id = db_prepare_int( $p_dest_bug_id ); 150 $c_relationship_type = db_prepare_int( $p_relationship_type ); 151 } 152 153 $query = "INSERT INTO $t_mantis_bug_relationship_table 154 ( source_bug_id, destination_bug_id, relationship_type ) 155 VALUES 156 ( '$c_src_bug_id', '$c_dest_bug_id', '$c_relationship_type' )"; 157 $result = db_query( $query ); 158 $t_relationship = db_fetch_array( $result ); 159 160 $t_bug_relationship_data = new BugRelationshipData; 161 $t_bug_relationship_data->id = $t_relationship['id']; 162 $t_bug_relationship_data->src_bug_id = $t_relationship['source_bug_id']; 163 $t_bug_relationship_data->dest_bug_id = $t_relationship['destination_bug_id']; 164 $t_bug_relationship_data->type = $t_relationship['relationship_type']; 165 166 return $t_bug_relationship_data; 167 } 168 169 # -------------------- 170 function relationship_update( $p_relationship_id, $p_src_bug_id, $p_dest_bug_id, $p_relationship_type ) { 171 $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); 172 173 global $g_relationships; 174 if ( $g_relationships[ $p_relationship_type ][ '#forward' ] === FALSE ) { 175 $c_src_bug_id = db_prepare_int( $p_dest_bug_id ); 176 $c_dest_bug_id = db_prepare_int( $p_src_bug_id ); 177 $c_relationship_type = db_prepare_int( relationship_get_complementary_type( $p_relationship_type ) ); 178 } else { 179 $c_src_bug_id = db_prepare_int( $p_src_bug_id ); 180 $c_dest_bug_id = db_prepare_int( $p_dest_bug_id ); 181 $c_relationship_type = db_prepare_int( $p_relationship_type ); 182 } 183 $c_relationship_id = db_prepare_int( $p_relationship_id ); 184 185 $query = "UPDATE $t_mantis_bug_relationship_table 186 SET source_bug_id='$c_src_bug_id', 187 destination_bug_id='$c_dest_bug_id', 188 relationship_type='$c_relationship_type' 189 WHERE id='$c_relationship_id'"; 190 $result = db_query( $query ); 191 $t_relationship = db_fetch_array( $result ); 192 193 $t_bug_relationship_data = new BugRelationshipData; 194 $t_bug_relationship_data->id = $t_relationship['id']; 195 $t_bug_relationship_data->src_bug_id = $t_relationship['source_bug_id']; 196 $t_bug_relationship_data->dest_bug_id = $t_relationship['destination_bug_id']; 197 $t_bug_relationship_data->type = $t_relationship['relationship_type']; 198 199 return $t_bug_relationship_data; 200 } 201 202 # -------------------- 203 function relationship_delete( $p_relationship_id ) { 204 $c_relationship_id = db_prepare_int( $p_relationship_id ); 205 206 $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); 207 208 $query = "DELETE FROM $t_mantis_bug_relationship_table 209 WHERE id='$c_relationship_id'"; 210 $result = db_query( $query ); 211 } 212 213 # -------------------- 214 # Deletes all the relationships related to a specific bug (both source and destination) 215 function relationship_delete_all( $p_bug_id ) { 216 $c_bug_id = db_prepare_int( $p_bug_id ); 217 218 $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); 219 220 $query = "DELETE FROM $t_mantis_bug_relationship_table 221 WHERE source_bug_id='$c_bug_id' OR 222 destination_bug_id='$c_bug_id'"; 223 $result = db_query( $query ); 224 } 225 226 # -------------------- 227 # copy all the relationships related to a specific bug to a new bug 228 function relationship_copy_all( $p_bug_id, $p_new_bug_id ) { 229 $c_bug_id = db_prepare_int( $p_bug_id ); 230 $c_new_bug_id = db_prepare_int( $p_new_bug_id ); 231 232 $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); 233 234 $t_relationship = relationship_get_all_src( $p_bug_id ); 235 $t_relationship_count = count( $t_relationship ); 236 for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) { 237 relationship_add($p_new_bug_id, $t_relationship[$i]->dest_bug_id, $t_relationship[$i]->type); 238 } 239 240 $t_relationship = relationship_get_all_dest( $p_bug_id ); 241 $t_relationship_count = count( $t_relationship ); 242 for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) { 243 relationship_add($t_relationship[$i]->src_bug_id, $p_new_bug_id, $t_relationship[$i]->type); 244 } 245 246 return; 247 } 248 249 # -------------------- 250 function relationship_get( $p_relationship_id ) { 251 $c_relationship_id = db_prepare_int( $p_relationship_id ); 252 253 $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); 254 255 $query = "SELECT * 256 FROM $t_mantis_bug_relationship_table 257 WHERE id='$c_relationship_id'"; 258 $result = db_query( $query, 1 ); 259 260 $t_relationship_count = db_num_rows( $result ); 261 262 if ( $t_relationship_count == 1 ) { 263 $t_relationship = db_fetch_array( $result ); 264 265 $t_bug_relationship_data = new BugRelationshipData; 266 $t_bug_relationship_data->id = $t_relationship['id']; 267 $t_bug_relationship_data->src_bug_id = $t_relationship['source_bug_id']; 268 $t_bug_relationship_data->dest_bug_id = $t_relationship['destination_bug_id']; 269 $t_bug_relationship_data->type = $t_relationship['relationship_type']; 270 } 271 else { 272 $t_bug_relationship_data = null; 273 } 274 275 return $t_bug_relationship_data; 276 } 277 278 # -------------------- 279 function relationship_get_all_src( $p_src_bug_id ) { 280 $c_src_bug_id = db_prepare_int( $p_src_bug_id ); 281 282 $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); 283 $t_mantis_bug_table = config_get( 'mantis_bug_table' ); 284 285 $query = "SELECT $t_mantis_bug_relationship_table.id, $t_mantis_bug_relationship_table.relationship_type, 286 $t_mantis_bug_relationship_table.source_bug_id, $t_mantis_bug_relationship_table.destination_bug_id, 287 $t_mantis_bug_table.project_id 288 FROM $t_mantis_bug_relationship_table 289 INNER JOIN $t_mantis_bug_table ON $t_mantis_bug_relationship_table.destination_bug_id = $t_mantis_bug_table.id 290 WHERE source_bug_id='$c_src_bug_id' 291 ORDER BY relationship_type, $t_mantis_bug_relationship_table.id"; 292 $result = db_query( $query ); 293 294 $t_src_project_id = bug_get_field( $p_src_bug_id, 'project_id' ); 295 296 $t_bug_relationship_data = array( new BugRelationshipData ); 297 $t_relationship_count = db_num_rows( $result ); 298 for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) { 299 $row = db_fetch_array( $result ); 300 $t_bug_relationship_data[$i]->id = $row['id']; 301 $t_bug_relationship_data[$i]->src_bug_id = $row['source_bug_id']; 302 $t_bug_relationship_data[$i]->src_project_id = $t_src_project_id; 303 $t_bug_relationship_data[$i]->dest_bug_id = $row['destination_bug_id']; 304 $t_bug_relationship_data[$i]->dest_project_id = $row['project_id']; 305 $t_bug_relationship_data[$i]->type = $row['relationship_type']; 306 } 307 unset( $t_bug_relationship_data[$t_relationship_count] ); 308 309 return $t_bug_relationship_data; 310 } 311 312 # -------------------- 313 function relationship_get_all_dest( $p_dest_bug_id ) { 314 $c_dest_bug_id = db_prepare_int( $p_dest_bug_id ); 315 316 $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); 317 $t_mantis_bug_table = config_get( 'mantis_bug_table' ); 318 319 $query = "SELECT $t_mantis_bug_relationship_table.id, $t_mantis_bug_relationship_table.relationship_type, 320 $t_mantis_bug_relationship_table.source_bug_id, $t_mantis_bug_relationship_table.destination_bug_id, 321 $t_mantis_bug_table.project_id 322 FROM $t_mantis_bug_relationship_table 323 INNER JOIN $t_mantis_bug_table ON $t_mantis_bug_relationship_table.source_bug_id = $t_mantis_bug_table.id 324 WHERE destination_bug_id='$c_dest_bug_id' 325 ORDER BY relationship_type, $t_mantis_bug_relationship_table.id"; 326 $result = db_query( $query ); 327 328 $t_dest_project_id = bug_get_field( $p_dest_bug_id, 'project_id' ); 329 330 $t_bug_relationship_data = array( new BugRelationshipData ); 331 $t_relationship_count = db_num_rows( $result ); 332 for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) { 333 $row = db_fetch_array( $result ); 334 $t_bug_relationship_data[$i]->id = $row['id']; 335 $t_bug_relationship_data[$i]->src_bug_id = $row['source_bug_id']; 336 $t_bug_relationship_data[$i]->src_project_id = $row['project_id']; 337 $t_bug_relationship_data[$i]->dest_bug_id = $row['destination_bug_id']; 338 $t_bug_relationship_data[$i]->dest_project_id = $t_dest_project_id; 339 $t_bug_relationship_data[$i]->type = $row['relationship_type']; 340 } 341 unset( $t_bug_relationship_data[$t_relationship_count] ); 342 343 return $t_bug_relationship_data; 344 } 345 346 # -------------------- 347 function relationship_get_all( $p_bug_id, &$p_is_different_projects ) { 348 $t_src = relationship_get_all_src( $p_bug_id ); 349 $t_dest = relationship_get_all_dest( $p_bug_id ); 350 $t_all = array_merge( $t_src, $t_dest ); 351 352 $p_is_different_projects = false; 353 for ( $i = 0 ; $i < count( $t_all ) ; $i++ ) { 354 $p_is_different_projects |= ( $t_all[$i]->src_project_id != $t_all[$i]->dest_project_id ); 355 } 356 return $t_all; 357 } 358 359 # -------------------- 360 # convert the relationship type in the type from the src/dest issues point of view 361 # i.e. issue A is dependent (BUG_DEPENDANT) on issue B 362 # passing B, A and this relationship as parameters, the return value will be BUG_BLOCKS 363 # (issue B blocks issue A) 364 # return the relationship type using the information in the p_rel structure but src/dest issues as indicated 365 function relationship_conv_type_to_this_src_dest( $p_src_bug_id, $p_dest_bug_id, $p_rel ) { 366 if ( $p_rel->src_bug_id == $p_src_bug_id && $p_rel->dest_bug_id == $p_dest_bug_id ) { 367 return $p_rel->type; 368 } 369 else if ( $p_rel->src_bug_id == $p_dest_bug_id && $p_rel->dest_bug_id == $p_src_bug_id ) { 370 return relationship_get_complementary_type( $p_rel->type ); 371 } 372 else { 373 trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); 374 } 375 } 376 377 # -------------------- 378 # check if there is a relationship between two bugs 379 # return id if found 0 otherwise 380 function relationship_exists( $p_src_bug_id, $p_dest_bug_id ) { 381 $c_src_bug_id = db_prepare_int( $p_src_bug_id ); 382 $c_dest_bug_id = db_prepare_int( $p_dest_bug_id ); 383 384 $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); 385 386 $t_query = "SELECT * 387 FROM $t_mantis_bug_relationship_table 388 WHERE 389 (source_bug_id='$c_src_bug_id' 390 AND destination_bug_id='$c_dest_bug_id') 391 OR 392 (source_bug_id='$c_dest_bug_id' 393 AND destination_bug_id='$c_src_bug_id')"; 394 $result = db_query( $t_query, 1 ); 395 396 $t_relationship_count = db_num_rows( $result ); 397 398 if ( $t_relationship_count == 1 ) { 399 # return the first id 400 $row = db_fetch_array( $result ); 401 return $row['id']; 402 } 403 else { 404 # no relationship found 405 return 0; 406 } 407 } 408 409 # -------------------- 410 # check if there is a relationship between two bugs 411 # return: 412 # 0 if the relationship is not found 413 # -1 if the relationship is found and it's of the same type $p_rel_type 414 # 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 415 function relationship_same_type_exists( $p_src_bug_id, $p_dest_bug_id, $p_rel_type ) { 416 # Check if there is already a relationship set between them 417 $t_id_relationship = relationship_exists( $p_src_bug_id, $p_dest_bug_id ); 418 419 if ( $t_id_relationship > 0 ) { 420 # if there is... 421 422 # get all the relationship info 423 $t_relationship = relationship_get( $t_id_relationship ); 424 425 if ( $t_relationship->src_bug_id == $p_src_bug_id && $t_relationship->dest_bug_id == $p_dest_bug_id ) { 426 if( $t_relationship->type == $p_rel_type ) $t_id_relationship = -1; 427 } 428 else { 429 if( $t_relationship->type == relationship_get_complementary_type( $p_rel_type ) ) $t_id_relationship = -1; 430 } 431 } 432 return $t_id_relationship; 433 } 434 435 # -------------------- 436 # retrieve the linked bug id of the relationship: provide src -> return dest; provide dest -> return src 437 function relationship_get_linked_bug_id( $p_relationship_id, $p_bug_id ) { 438 439 $t_bug_relationship_data = relationship_get( $p_relationship_id ); 440 441 if ( $t_bug_relationship_data->src_bug_id == $p_bug_id ) { 442 return $t_bug_relationship_data->dest_bug_id; 443 } 444 445 if ( $t_bug_relationship_data->dest_bug_id == $p_bug_id ) { 446 return $t_bug_relationship_data->src_bug_id; 447 } 448 449 trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); 450 } 451 452 # -------------------- 453 # get class description of a relationship (source side) 454 function relationship_get_description_src_side( $p_relationship_type ) { 455 global $g_relationships; 456 if ( !isset( $g_relationships[ $p_relationship_type ] ) ) { 457 trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); 458 } 459 return lang_get( $g_relationships[ $p_relationship_type ][ '#description' ] ); 460 } 461 462 # -------------------- 463 # get class description of a relationship (destination side) 464 function relationship_get_description_dest_side( $p_relationship_type ) { 465 global $g_relationships; 466 if ( !isset( $g_relationships[ $p_relationship_type ] ) || 467 !isset( $g_relationships[ $g_relationships[ $p_relationship_type ][ '#complementary' ] ] ) ) { 468 trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); 469 } 470 return lang_get( $g_relationships[ $g_relationships[ $p_relationship_type ][ '#complementary' ] ][ '#description' ] ); 471 } 472 473 # -------------------- 474 # get class description of a relationship as it's stored in the history 475 function relationship_get_description_for_history( $p_relationship_code ) { 476 return relationship_get_description_src_side( $p_relationship_code ); 477 } 478 479 # -------------------- 480 # return false if there are child bugs not resolved/closed 481 # N.B. we don't check if the parent bug is read-only. This is because the answer of this function is indepent from 482 # the state of the parent bug itself. 483 function relationship_can_resolve_bug( $p_bug_id ) { 484 485 # retrieve all the relationships in which the bug is the source bug 486 $t_relationship = relationship_get_all_src( $p_bug_id ); 487 $t_relationship_count = count( $t_relationship ); 488 if ( $t_relationship_count == 0 ) { 489 return true; 490 } 491 492 for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) { 493 # verify if each bug in relation BUG_DEPENDANT is already marked as resolved 494 if ( $t_relationship[$i]->type == BUG_DEPENDANT ) { 495 $t_dest_bug_id = $t_relationship[$i]->dest_bug_id; 496 $t_status = bug_get_field( $t_dest_bug_id, 'status' ); 497 if ( $t_status < config_get( 'bug_resolved_status_threshold' ) ) { 498 # the bug is NOT marked as resolved/closed 499 return false; 500 } 501 } 502 } 503 504 return true; 505 } 506 507 # -------------------- 508 # return formatted string with all the details on the requested relationship 509 function relationship_get_details( $p_bug_id, $p_relationship, $p_html = false, $p_html_preview = false, $p_show_project = false ) { 510 $t_summary_wrap_at = strlen( config_get( 'email_separator2' ) ) - 28; 511 $t_icon_path = config_get( 'icon_path' ); 512 513 $p_user_id = auth_get_current_user_id(); 514 515 if ( $p_bug_id == $p_relationship->src_bug_id ) { 516 # root bug is in the src side, related bug in the dest side 517 $t_related_bug_id = $p_relationship->dest_bug_id; 518 $t_related_project_name = project_get_name( $p_relationship->dest_project_id ); 519 $t_relationship_descr = relationship_get_description_src_side( $p_relationship->type ); 520 } 521 else { 522 # root bug is in the dest side, related bug in the src side 523 $t_related_bug_id = $p_relationship->src_bug_id; 524 $t_related_project_name = project_get_name( $p_relationship->src_project_id ); 525 $t_relationship_descr = relationship_get_description_dest_side( $p_relationship->type ); 526 } 527 528 # related bug not existing... 529 if ( !bug_exists( $t_related_bug_id ) ) { 530 return ''; 531 } 532 533 # user can access to the related bug at least as a viewer 534 if ( !access_has_bug_level( VIEWER, $t_related_bug_id ) ) { 535 return ''; 536 } 537 538 if ( $p_html_preview == false ) { 539 $t_td = '<td>'; 540 } 541 else { 542 $t_td = '<td class="print">'; 543 } 544 545 # get the information from the related bug and prepare the link 546 $t_bug = bug_prepare_display( bug_get( $t_related_bug_id, true ) ); 547 $t_status = string_attribute( get_enum_element( 'status', $t_bug->status ) ); 548 $t_resolution = string_attribute( get_enum_element( 'resolution', $t_bug->resolution ) ); 549 550 $t_relationship_info_html = $t_td . string_no_break( $t_relationship_descr ) . ' </td>'; 551 if ( $p_html_preview == false ) { 552 $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>'; 553 $t_relationship_info_html .= '<td><span class="issue-status" title="' . $t_resolution . '">' . $t_status . '</span></td>'; 554 } 555 else { 556 $t_relationship_info_html .= $t_td . bug_format_id( $t_related_bug_id ) . '</td>'; 557 $t_relationship_info_html .= $t_td . $t_status . ' </td>'; 558 } 559 560 $t_relationship_info_text = str_pad( $t_relationship_descr, 20 ); 561 $t_relationship_info_text .= str_pad( bug_format_id( $t_related_bug_id ), 8 ); 562 563 # get the handler name of the related bug 564 $t_relationship_info_html .= $t_td; 565 if ( $t_bug->handler_id > 0 ) { 566 $t_relationship_info_html .= string_no_break( prepare_user_name( $t_bug->handler_id ) ); 567 } 568 $t_relationship_info_html .= ' </td>'; 569 570 # add project name 571 if( $p_show_project ) { 572 $t_relationship_info_html .= $t_td . $t_related_project_name . ' </td>'; 573 } 574 575 # add summary 576 $t_relationship_info_html .= $t_td . $t_bug->summary; 577 if ( VS_PRIVATE == $t_bug->view_state ) { 578 $t_relationship_info_html .= sprintf( ' <img src="%s" alt="(%s)" title="%s" />', $t_icon_path . 'protected.gif', lang_get( 'private' ), lang_get( 'private' ) ); 579 } 580 if( strlen( $t_bug->summary ) <= $t_summary_wrap_at ) { 581 $t_relationship_info_text .= $t_bug->summary; 582 } 583 else { 584 $t_relationship_info_text .= substr( $t_bug->summary, 0, $t_summary_wrap_at - 3 ) . '...'; 585 } 586 587 # add delete link if bug not read only and user has access level 588 if ( !bug_is_readonly( $p_bug_id ) && !current_user_is_anonymous() && ( $p_html_preview == false ) ) { 589 if ( access_has_bug_level( config_get( 'update_bug_threshold' ), $p_bug_id ) ) { 590 $t_relationship_info_html .= " [<a class=\"small\" href=\"bug_relationship_delete.php?bug_id=$p_bug_id&rel_id=$p_relationship->id\">" . lang_get('delete_link') . '</a>]'; 591 } 592 } 593 594 $t_relationship_info_html .= ' </td>'; 595 $t_relationship_info_text .= "\n"; 596 597 if ( $p_html_preview == false ) { 598 $t_relationship_info_html = '<tr bgcolor="' . get_status_color( $t_bug->status ) . '">' . $t_relationship_info_html . '</tr>' . "\n"; 599 } 600 else { 601 $t_relationship_info_html = '<tr>' . $t_relationship_info_html . '</tr>'; 602 } 603 604 if ( $p_html == true ) { 605 return $t_relationship_info_html; 606 } 607 else { 608 return $t_relationship_info_text; 609 } 610 611 } 612 613 # -------------------- 614 # print ALL the RELATIONSHIPS OF A SPECIFIC BUG 615 function relationship_get_summary_html( $p_bug_id ) { 616 $t_summary = ''; 617 $t_show_project = false; 618 619 $t_relationship_all = relationship_get_all( $p_bug_id, $t_show_project ); 620 $t_relationship_all_count = count( $t_relationship_all ); 621 622 #prepare the relationships table 623 for ( $i = 0 ; $i < $t_relationship_all_count ; $i++ ) { 624 $t_summary .= relationship_get_details ( $p_bug_id, $t_relationship_all[$i], true, false, $t_show_project ); 625 } 626 627 if ( !is_blank( $t_summary ) ) { 628 if ( relationship_can_resolve_bug( $p_bug_id ) == false ) { 629 $t_summary .= '<tr class="row-2"><td colspan="' . (5 + $t_show_project) . '"><b>' . lang_get( 'relationship_warning_blocking_bugs_not_resolved' ) . '</b></td></tr>'; 630 } 631 $t_summary = '<table border="0" width="100%" cellpadding="0" cellspacing="1">' . $t_summary . '</table>'; 632 } 633 634 return $t_summary; 635 } 636 637 # -------------------- 638 # print ALL the RELATIONSHIPS OF A SPECIFIC BUG 639 function relationship_get_summary_html_preview( $p_bug_id ) { 640 $t_summary = ''; 641 $t_show_project = false; 642 643 $t_relationship_all = relationship_get_all( $p_bug_id, $t_show_project ); 644 $t_relationship_all_count = count( $t_relationship_all ); 645 646 #prepare the relationships table 647 for ( $i = 0 ; $i < $t_relationship_all_count ; $i++ ) { 648 $t_summary .= relationship_get_details ( $p_bug_id, $t_relationship_all[$i], true, true, $t_show_project ); 649 } 650 651 if ( !is_blank( $t_summary ) ) { 652 if ( relationship_can_resolve_bug( $p_bug_id ) == false ) { 653 $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>'; 654 } 655 $t_summary = '<table border="0" width="100%" cellpadding="0" cellspacing="1">' . $t_summary . '</table>'; 656 } 657 658 return $t_summary; 659 } 660 661 # -------------------- 662 # print ALL the RELATIONSHIPS OF A SPECIFIC BUG in text format (used by email_api.php 663 function relationship_get_summary_text( $p_bug_id ) { 664 $t_email_separator1 = config_get( 'email_separator1' ); 665 $t_email_separator2 = config_get( 'email_separator2' ); 666 667 $t_summary = ""; 668 $t_show_project = false; 669 670 $t_relationship_all = relationship_get_all( $p_bug_id, $t_show_project ); 671 $t_relationship_all_count = count( $t_relationship_all ); 672 673 #prepare the relationships table 674 for ( $i = 0 ; $i < $t_relationship_all_count ; $i++ ) { 675 $t_summary .= relationship_get_details ( $p_bug_id, $t_relationship_all[$i], false ); 676 } 677 678 if ($t_summary != "") { 679 $t_summary = 680 $t_email_separator1 . "\n" . 681 str_pad( lang_get( 'bug_relationships' ), 20 ) . 682 str_pad( lang_get( 'id' ), 8 ) . 683 lang_get( 'summary' ) . "\n" . 684 $t_email_separator2 . "\n" . $t_summary; 685 } 686 687 return $t_summary; 688 } 689 690 # -------------------- 691 # print HTML relationship listbox 692 function relationship_list_box( $p_default_rel_type = -1, $p_select_name = "rel_type", $p_include_any = false, $p_include_none = false ) { 693 global $g_relationships; 694 ?> 695 <select name="<?php echo $p_select_name ?>"> 696 <?php if ( $p_include_any ) { ?> 697 <option value="-1" <?php echo ( $p_default_rel_type == -1 ? ' selected="selected"' : '' ) ?>>[<?php echo lang_get( 'any' ) ?>]</option> 698 <?php 699 } 700 701 if ( $p_include_none ) { ?> 702 <option value="-2" <?php echo ( $p_default_rel_type == -2 ? ' selected="selected"' : '' ) ?>>[<?php echo lang_get( 'none' ) ?>]</option> 703 <?php 704 } 705 706 foreach ( $g_relationships as $type => $relationship ) { 707 ?> 708 <option value="<?php echo $type ?>"<?php echo ( $p_default_rel_type == $type ? ' selected="selected"' : '' ) ?>><?php echo lang_get( $relationship['#description'] ) ?></option> 709 <?php } ?> 710 </select> 711 <?php 712 } 713 714 # -------------------- 715 # print HTML relationship form 716 function relationship_view_box( $p_bug_id ) { 717 ?> 718 <br/> 719 720 <?php collapse_open( 'relationships' ); ?> 721 <table class="width100" cellspacing="1"> 722 <tr class="row-2" valign="top"> 723 <td width="15%" class="form-title" colspan="2"> 724 <?php 725 collapse_icon( 'relationships' ); 726 echo lang_get( 'bug_relationships' ); 727 if ( ON == config_get( 'relationship_graph_enable' ) ) { 728 ?> 729 <span class="small"><?php print_bracket_link( 'bug_relationship_graph.php?bug_id=' . $p_bug_id . '&graph=relation', lang_get( 'relation_graph' ) ) ?></span> 730 <span class="small"><?php print_bracket_link( 'bug_relationship_graph.php?bug_id=' . $p_bug_id . '&graph=dependency', lang_get( 'dependency_graph' ) ) ?></span> 731 <?php 732 } 733 ?> 734 </td> 735 </tr> 736 <?php 737 # bug not read-only and user authenticated 738 if ( !bug_is_readonly( $p_bug_id ) ) { 739 740 # user access level at least updater 741 if ( access_has_bug_level( config_get( 'update_bug_threshold' ), $p_bug_id ) ) { 742 ?> 743 <tr class="row-1"> 744 <td class="category"><?php echo lang_get( 'add_new_relationship' ) ?></td> 745 <td><?php echo lang_get( 'this_bug' ) ?> 746 <form method="post" action="bug_relationship_add.php"> 747 <input type="hidden" name="src_bug_id" value="<?php echo $p_bug_id ?>" size="4" /> 748 <?php relationship_list_box( -1 ) ?> 749 <input type="text" name="dest_bug_id" value="" /> 750 <input type="submit" name="add_relationship" class="button" value="<?php echo lang_get( 'add_new_relationship_button' ) ?>" /> 751 </form> 752 </td></tr> 753 <?php 754 } 755 } 756 ?> 757 <tr> 758 <td colspan="2"><?php echo relationship_get_summary_html( $p_bug_id ) ?></td> 759 </tr> 760 </table> 761 762 <?php collapse_closed( 'relationships' ); ?> 763 <table class="width100" cellspacing="1"> 764 <tr> 765 <td class="form-title"> 766 <?php 767 collapse_icon( 'relationships' ); 768 echo lang_get( 'bug_relationships' ); 769 ?> 770 </td> 771 </tr> 772 </table> 773 774 <?php 775 collapse_end( 'relationships' ); 776 } 777 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 09:42:17 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |