PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/bugnote_view_inc.php

https://github.com/fusenigk/mantisbt-1
PHP | 287 lines | 203 code | 32 blank | 52 comment | 48 complexity | 5a1da193acf0a00f7ebf52a3143f54b0 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 include file prints out the list of bugnotes attached to the bug
  17. * $f_bug_id must be set and be set to the bug id
  18. *
  19. * @package MantisBT
  20. * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
  21. * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
  22. * @link http://www.mantisbt.org
  23. *
  24. * @uses access_api.php
  25. * @uses authentication_api.php
  26. * @uses bug_api.php
  27. * @uses bug_revision_api.php
  28. * @uses bugnote_api.php
  29. * @uses collapse_api.php
  30. * @uses config_api.php
  31. * @uses constant_inc.php
  32. * @uses current_user_api.php
  33. * @uses database_api.php
  34. * @uses event_api.php
  35. * @uses helper_api.php
  36. * @uses lang_api.php
  37. * @uses prepare_api.php
  38. * @uses print_api.php
  39. * @uses string_api.php
  40. * @uses user_api.php
  41. */
  42. if ( !defined( 'BUGNOTE_VIEW_INC_ALLOW' ) ) {
  43. return;
  44. }
  45. require_api( 'access_api.php' );
  46. require_api( 'authentication_api.php' );
  47. require_api( 'bug_api.php' );
  48. require_api( 'bug_revision_api.php' );
  49. require_api( 'bugnote_api.php' );
  50. require_api( 'collapse_api.php' );
  51. require_api( 'config_api.php' );
  52. require_api( 'constant_inc.php' );
  53. require_api( 'current_user_api.php' );
  54. require_api( 'database_api.php' );
  55. require_api( 'event_api.php' );
  56. require_api( 'helper_api.php' );
  57. require_api( 'lang_api.php' );
  58. require_api( 'prepare_api.php' );
  59. require_api( 'print_api.php' );
  60. require_api( 'string_api.php' );
  61. require_api( 'user_api.php' );
  62. # grab the user id currently logged in
  63. $t_user_id = auth_get_current_user_id();
  64. #precache access levels
  65. if ( isset( $g_project_override ) ) {
  66. access_cache_matrix_project( $g_project_override );
  67. } else {
  68. access_cache_matrix_project( helper_get_current_project() );
  69. }
  70. # get the bugnote data
  71. $t_bugnote_order = current_user_get_pref( 'bugnote_order' );
  72. $t_bugnotes = bugnote_get_all_visible_bugnotes( $f_bug_id, $t_bugnote_order, 0, $t_user_id );
  73. #precache users
  74. $t_bugnote_users = array();
  75. foreach($t_bugnotes as $t_bugnote) {
  76. $t_bugnote_users[] = $t_bugnote->reporter_id;
  77. }
  78. user_cache_array_rows( $t_bugnote_users );
  79. $num_notes = count( $t_bugnotes );
  80. ?>
  81. <?php # Bugnotes BEGIN ?>
  82. <a id="bugnotes"></a><br />
  83. <?php
  84. collapse_open( 'bugnotes' );
  85. ?>
  86. <table class="bugnotes width100" cellspacing="1">
  87. <tr>
  88. <td class="form-title" colspan="2">
  89. <?php
  90. collapse_icon( 'bugnotes' ); ?>
  91. <?php echo lang_get( 'bug_notes_title' ) ?>
  92. </td>
  93. </tr>
  94. <?php
  95. # no bugnotes
  96. if ( 0 == $num_notes ) {
  97. ?>
  98. <tr class="bugnotes-empty">
  99. <td class="center" colspan="2">
  100. <?php echo lang_get( 'no_bugnotes_msg' ) ?>
  101. </td>
  102. </tr>
  103. <?php }
  104. event_signal( 'EVENT_VIEW_BUGNOTES_START', array( $f_bug_id, $t_bugnotes ) );
  105. $t_normal_date_format = config_get( 'normal_date_format' );
  106. $t_total_time = 0;
  107. $t_bugnote_user_edit_threshold = config_get( 'bugnote_user_edit_threshold' );
  108. $t_bugnote_user_delete_threshold = config_get( 'bugnote_user_delete_threshold' );
  109. $t_bugnote_user_change_view_state_threshold = config_get( 'bugnote_user_change_view_state_threshold' );
  110. $t_can_edit_all_bugnotes = access_has_bug_level( config_get( 'update_bugnote_threshold' ), $f_bug_id );
  111. $t_can_delete_all_bugnotes = access_has_bug_level( config_get( 'delete_bugnote_threshold' ), $f_bug_id );
  112. $t_can_change_view_state_all_bugnotes = $t_can_edit_all_bugnotes && access_has_bug_level( config_get( 'change_view_status_threshold' ), $f_bug_id );
  113. for ( $i=0; $i < $num_notes; $i++ ) {
  114. $t_bugnote = $t_bugnotes[$i];
  115. if ( $t_bugnote->date_submitted != $t_bugnote->last_modified )
  116. $t_bugnote_modified = true;
  117. else
  118. $t_bugnote_modified = false;
  119. $t_bugnote_id_formatted = bugnote_format_id( $t_bugnote->id );
  120. if ( 0 != $t_bugnote->time_tracking ) {
  121. $t_time_tracking_hhmm = db_minutes_to_hhmm( $t_bugnote->time_tracking );
  122. $t_bugnote->note_type = TIME_TRACKING; // for older entries that didn't set the type @@@PLR FIXME
  123. $t_total_time += $t_bugnote->time_tracking;
  124. } else {
  125. $t_time_tracking_hhmm = '';
  126. }
  127. if ( VS_PRIVATE == $t_bugnote->view_state ) {
  128. $t_bugnote_css = 'bugnote-private';
  129. } else {
  130. $t_bugnote_css = 'bugnote-public';
  131. }
  132. if ( TIME_TRACKING == $t_bugnote->note_type ) {
  133. $t_bugnote_css .= ' bugnote-time-tracking';
  134. } else if ( REMINDER == $t_bugnote->note_type ) {
  135. $t_bugnote_css .= ' bugnote-reminder';
  136. }
  137. ?>
  138. <tr class="bugnote <?php echo $t_bugnote_css ?>" id="c<?php echo $t_bugnote->id ?>">
  139. <td class="bugnote-meta">
  140. <?php if ( ON == config_get("show_avatar") ) print_avatar( $t_bugnote->reporter_id ); ?>
  141. <span class="small bugnote-permalink"><a rel="bookmark" href="<?php echo string_get_bugnote_view_url($t_bugnote->bug_id, $t_bugnote->id) ?>" title="<?php echo lang_get( 'bugnote_link_title' ) ?>"><?php echo htmlentities( config_get_global( 'bugnote_link_tag' ) ) . $t_bugnote_id_formatted ?></a></span><br />
  142. <span class="bugnote-reporter">
  143. <?php
  144. echo print_user( $t_bugnote->reporter_id );
  145. ?>
  146. <span class="small access-level"><?php
  147. if ( user_exists( $t_bugnote->reporter_id ) ) {
  148. $t_access_level = access_get_project_level( null, (int)$t_bugnote->reporter_id );
  149. echo '(', get_enum_element( 'access_levels', $t_access_level ), ')';
  150. }
  151. ?></span>
  152. </span>
  153. <?php if ( VS_PRIVATE == $t_bugnote->view_state ) { ?>
  154. <span class="small bugnote-view-state">[ <?php echo lang_get( 'private' ) ?> ]</span>
  155. <?php } ?>
  156. <br />
  157. <span class="small bugnote-date-submitted"><?php echo date( $t_normal_date_format, $t_bugnote->date_submitted ); ?></span><br />
  158. <?php
  159. if ( $t_bugnote_modified ) {
  160. echo '<span class="small bugnote-last-modified">' . lang_get( 'last_edited') . lang_get( 'word_separator' ) . date( $t_normal_date_format, $t_bugnote->last_modified ) . '</span><br />';
  161. $t_revision_count = bug_revision_count( $f_bug_id, REV_BUGNOTE, $t_bugnote->id );
  162. if ( $t_revision_count >= 1) {
  163. $t_view_num_revisions_text = sprintf( lang_get( 'view_num_revisions' ), $t_revision_count );
  164. echo '<span class="small bugnote-revisions-link"><a href="bug_revision_view_page.php?bugnote_id=' . $t_bugnote->id . '">' . $t_view_num_revisions_text . '</a></span><br />';
  165. }
  166. }
  167. ?>
  168. <br /><div class="small bugnote-buttons">
  169. <?php
  170. # bug must be open to be editable
  171. if ( !bug_is_readonly( $f_bug_id ) ) {
  172. # check if the user can edit this bugnote
  173. if ( $t_user_id == $t_bugnote->reporter_id ) {
  174. $t_can_edit_bugnote = access_has_bugnote_level( $t_bugnote_user_edit_threshold, $t_bugnote->id );
  175. } else {
  176. $t_can_edit_bugnote = $t_can_edit_all_bugnotes;
  177. }
  178. # check if the user can delete this bugnote
  179. if ( $t_user_id == $t_bugnote->reporter_id ) {
  180. $t_can_delete_bugnote = access_has_bugnote_level( $t_bugnote_user_delete_threshold, $t_bugnote->id );
  181. } else {
  182. $t_can_delete_bugnote = $t_can_delete_all_bugnotes;
  183. }
  184. # check if the user can make this bugnote private
  185. if ( $t_user_id == $t_bugnote->reporter_id ) {
  186. $t_can_change_view_state = access_has_bugnote_level( $t_bugnote_user_change_view_state_threshold, $t_bugnote->id );
  187. } else {
  188. $t_can_change_view_state = $t_can_change_view_state_all_bugnotes;
  189. }
  190. # show edit button if the user is allowed to edit this bugnote
  191. if ( $t_can_edit_bugnote ) {
  192. print_button( 'bugnote_edit_page.php?bugnote_id='.$t_bugnote->id, lang_get( 'bugnote_edit_link' ) );
  193. }
  194. # show delete button if the user is allowed to delete this bugnote
  195. if ( $t_can_delete_bugnote ) {
  196. print_button( 'bugnote_delete.php?bugnote_id='.$t_bugnote->id, lang_get( 'delete_link' ) );
  197. }
  198. # show make public or make private button if the user is allowed to change the view state of this bugnote
  199. if ( $t_can_change_view_state ) {
  200. if ( VS_PRIVATE == $t_bugnote->view_state ) {
  201. print_button( 'bugnote_set_view_state.php?private=0&bugnote_id=' . $t_bugnote->id, lang_get( 'make_public' ) );
  202. } else {
  203. print_button( 'bugnote_set_view_state.php?private=1&bugnote_id=' . $t_bugnote->id, lang_get( 'make_private' ) );
  204. }
  205. }
  206. }
  207. ?>
  208. </div>
  209. </td>
  210. <td class="bugnote-note">
  211. <?php
  212. switch ( $t_bugnote->note_type ) {
  213. case REMINDER:
  214. echo '<em>' . lang_get( 'reminder_sent_to' ) . ' ';
  215. $t_note_attr = utf8_substr( $t_bugnote->note_attr, 1, utf8_strlen( $t_bugnote->note_attr ) - 2 );
  216. $t_to = array();
  217. foreach ( explode( '|', $t_note_attr ) as $t_recipient ) {
  218. $t_to[] = prepare_user_name( $t_recipient );
  219. }
  220. echo implode( ', ', $t_to ) . '</em><br /><br />';
  221. case TIME_TRACKING:
  222. if ( access_has_bug_level( config_get( 'time_tracking_view_threshold' ), $f_bug_id ) ) {
  223. echo '<div class="time-tracked">', $t_time_tracking_hhmm, '</div>';
  224. }
  225. break;
  226. }
  227. echo string_display_links( $t_bugnote->note );;
  228. ?>
  229. </td>
  230. </tr>
  231. <?php event_signal( 'EVENT_VIEW_BUGNOTE', array( $f_bug_id, $t_bugnote->id, VS_PRIVATE == $t_bugnote->view_state ) ); ?>
  232. <tr class="spacer">
  233. <td colspan="2"></td>
  234. </tr>
  235. <?php
  236. } # end for loop
  237. event_signal( 'EVENT_VIEW_BUGNOTES_END', $f_bug_id );
  238. ?>
  239. </table>
  240. <?php
  241. if ( $t_total_time > 0 && access_has_bug_level( config_get( 'time_tracking_view_threshold' ), $f_bug_id ) ) {
  242. echo '<p class="time-tracking-total">', sprintf ( lang_get( 'total_time_for_issue' ), '<span class="time-tracked">' . db_minutes_to_hhmm( $t_total_time ) . '</span>' ), '</p>';
  243. }
  244. collapse_closed( 'bugnotes' );
  245. ?>
  246. <table class="width100" cellspacing="1">
  247. <tr>
  248. <td class="form-title" colspan="2">
  249. <?php collapse_icon( 'bugnotes' ); ?>
  250. <?php echo lang_get( 'bug_notes_title' ) ?>
  251. </td>
  252. </tr>
  253. </table>
  254. <?php
  255. collapse_end( 'bugnotes' );