[ 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: helper_api.php,v 1.75.2.2 2007-10-14 19:00:08 vboctor Exp $ 22 # -------------------------------------------------------- 23 24 ### Helper API ### 25 26 # These are miscellaneous functions 27 28 # -------------------- 29 # alternate color function 30 # If no index is given, continue alternating based on the last index given 31 function helper_alternate_colors( $p_index, $p_odd_color, $p_even_color ) { 32 static $t_index = 1; 33 34 if ( null !== $p_index ) { 35 $t_index = $p_index; 36 } 37 38 if ( 1 == $t_index++ % 2 ) { 39 return $p_odd_color; 40 } else { 41 return $p_even_color; 42 } 43 } 44 # -------------------- 45 # alternate classes for table rows 46 # If no index is given, continue alternating based on the last index given 47 function helper_alternate_class( $p_index=null, $p_odd_class="row-1", $p_even_class="row-2" ) { 48 static $t_index = 1; 49 50 if ( null !== $p_index ) { 51 $t_index = $p_index; 52 } 53 54 if ( 1 == $t_index++ % 2 ) { 55 return "class=\"$p_odd_class\""; 56 } else { 57 return "class=\"$p_even_class\""; 58 } 59 } 60 # -------------------- 61 # get the color string for the given status 62 function get_status_color( $p_status ) { 63 $t_status_enum_string = config_get( 'status_enum_string' ); 64 $t_status_colors = config_get( 'status_colors' ); 65 66 # This code creates the appropriate variable name 67 # then references that color variable 68 # You could replace this with a bunch of if... then... else 69 # statements 70 71 $t_color_str = 'closed'; 72 $t_color = '#ffffff'; 73 $t_arr = explode_enum_string( $t_status_enum_string ); 74 $t_arr_count = count( $t_arr ); 75 for ( $i=0; $i < $t_arr_count ;$i++ ) { 76 $elem_arr = explode_enum_arr( $t_arr[$i] ); 77 if ( $elem_arr[0] == $p_status ) { 78 # now get the appropriate translation 79 $t_color_str = $elem_arr[1]; 80 break; 81 } 82 } 83 84 if ( isset ( $t_status_colors[$t_color_str] ) ) { 85 $t_color = $t_status_colors[$t_color_str]; 86 } 87 88 return $t_color; 89 } 90 # -------------------- 91 # Given a enum string and num, return the appropriate string 92 function get_enum_element( $p_enum_name, $p_val ) { 93 $config_var = config_get( $p_enum_name.'_enum_string' ); 94 $string_var = lang_get( $p_enum_name.'_enum_string' ); 95 96 # use the global enum string to search 97 $t_arr = explode_enum_string( $config_var ); 98 $t_arr_count = count( $t_arr ); 99 for ( $i=0; $i < $t_arr_count ;$i++ ) { 100 $elem_arr = explode_enum_arr( $t_arr[$i] ); 101 if ( $elem_arr[0] == $p_val ) { 102 # now get the appropriate translation 103 return get_enum_to_string( $string_var, $p_val ); 104 } 105 } 106 return '@' . $p_val . '@'; 107 } 108 # -------------------- 109 # If $p_var is not an array and is equal to $p_val then we PRINT SELECTED. 110 # If $p_var is an array, then if any member is equal to $p_val we PRINT SELECTED. 111 # This is used when we want to know if a variable indicated a certain 112 # option element is selected 113 # 114 # If the second parameter is not given, the first parameter is compared 115 # to the boolean value true 116 function check_selected( $p_var, $p_val=true ) { 117 if ( is_array( $p_var ) ) { 118 foreach( $p_var as $t_this_var ) { 119 # catch the case where one entry is 0 and the other is a string. 120 if ( ( is_string( $t_this_var ) && !is_string( $p_val ) ) ) { 121 if ( $t_this_var === $p_val ) { 122 PRINT ' selected="selected" '; 123 return ; 124 } 125 } else if ( $t_this_var == $p_val ) { 126 PRINT ' selected="selected" '; 127 return ; 128 } 129 } 130 } else { 131 if ( is_string( $p_var ) && is_string( $p_val ) ) { 132 if ( $p_var === $p_val ) { 133 PRINT ' selected="selected" '; 134 return ; 135 } 136 } else if ( $p_var == $p_val ) { 137 PRINT ' selected="selected" '; 138 return ; 139 } 140 } 141 } 142 # -------------------- 143 # If $p_var and $p_val are equal to each other then we PRINT CHECKED 144 # This is used when we want to know if a variable indicated a certain 145 # element is checked 146 # 147 # If the second parameter is not given, the first parameter is compared 148 # to the boolean value true 149 function check_checked( $p_var, $p_val=true ) { 150 if ( $p_var == $p_val ) { 151 PRINT ' checked="checked" '; 152 } 153 } 154 155 # -------------------- 156 # Set up PHP for a long process execution 157 # The script timeout is set based on the value of the 158 # long_process_timeout config option. 159 # $p_ignore_abort specified whether to ignore user aborts by hitting 160 # the Stop button (the default is not to ignore user aborts) 161 function helper_begin_long_process( $p_ignore_abort=false ) { 162 $t_timeout = config_get( 'long_process_timeout' ); 163 164 # silent errors or warnings reported when safe_mode is ON. 165 @set_time_limit( $t_timeout ); 166 167 ignore_user_abort( $p_ignore_abort ); 168 return $t_timeout; 169 } 170 171 # this allows pages to override the current project settings. 172 # This typically applies to the view bug pages where the "current" 173 # project as used by the filters, etc, does not match the bug being viewed. 174 $g_project_override = null; 175 $g_cache_current_project = null; 176 177 # -------------------- 178 # Return the current project id as stored in a cookie 179 # If no cookie exists, the user's default project is returned 180 function helper_get_current_project() { 181 global $g_project_override, $g_cache_current_project; 182 183 if ( $g_project_override !== null ) { 184 return $g_project_override; 185 } 186 187 if( $g_cache_current_project === null) { 188 $t_cookie_name = config_get( 'project_cookie' ); 189 190 $t_project_id = gpc_get_cookie( $t_cookie_name, null ); 191 192 if ( null === $t_project_id ) { 193 $t_pref_row = user_pref_cache_row( auth_get_current_user_id(), ALL_PROJECTS, false ); 194 if ( false === $t_pref_row ) { 195 $t_project_id = ALL_PROJECTS; 196 } else { 197 $t_project_id = $t_pref_row['default_project']; 198 } 199 } else { 200 $t_project_id = split( ';', $t_project_id ); 201 $t_project_id = $t_project_id[ count( $t_project_id ) - 1 ]; 202 } 203 204 if ( !project_exists( $t_project_id ) || 205 ( 0 == project_get_field( $t_project_id, 'enabled' ) ) || 206 !access_has_project_level( VIEWER, $t_project_id ) ) { 207 $t_project_id = ALL_PROJECTS; 208 } 209 $g_cache_current_project = (int)$t_project_id; 210 } 211 return $g_cache_current_project; 212 } 213 214 # -------------------- 215 # Return the current project id as stored in a cookie, in an Array 216 # If no cookie exists, the user's default project is returned 217 # If the current project is a subproject, the return value will include 218 # any parent projects 219 function helper_get_current_project_trace() { 220 $t_cookie_name = config_get( 'project_cookie' ); 221 222 $t_project_id = gpc_get_cookie( $t_cookie_name, null ); 223 224 if ( null === $t_project_id ) { 225 $t_bottom = current_user_get_pref( 'default_project' ); 226 $t_project_id = Array( $t_bottom ); 227 } else { 228 $t_project_id = split( ';', $t_project_id ); 229 $t_bottom = $t_project_id[ count( $t_project_id ) - 1 ]; 230 } 231 232 if ( !project_exists( $t_bottom ) || 233 ( 0 == project_get_field( $t_bottom, 'enabled' ) ) || 234 !access_has_project_level( VIEWER, $t_bottom ) ) { 235 $t_project_id = Array( ALL_PROJECTS ); 236 } 237 238 return $t_project_id; 239 } 240 241 # -------------------- 242 # Set the current project id (stored in a cookie) 243 function helper_set_current_project( $p_project_id ) { 244 $t_project_cookie_name = config_get( 'project_cookie' ); 245 246 gpc_set_cookie( $t_project_cookie_name, $p_project_id, true ); 247 248 return true; 249 } 250 # -------------------- 251 # Clear all known user preference cookies 252 function helper_clear_pref_cookies() { 253 gpc_clear_cookie( config_get( 'project_cookie' ) ); 254 gpc_clear_cookie( config_get( 'manage_cookie' ) ); 255 } 256 # -------------------- 257 # Check whether the user has confirmed this action. 258 # 259 # If the user has not confirmed the action, generate a page which asks 260 # the user to confirm and then submits a form back to the current page 261 # with all the GET and POST data and an additional field called _confirmed 262 # to indicate that confirmation has been done. 263 function helper_ensure_confirmed( $p_message, $p_button_label ) { 264 if (true == gpc_get_bool( '_confirmed' ) ) { 265 return true; 266 } 267 268 html_page_top1(); 269 html_page_top2(); 270 271 # @@@ we need to improve this formatting. I'd like the text to only 272 # be about 50% the width of the screen so that it doesn't become to hard 273 # to read. 274 275 PRINT "<br />\n<div align=\"center\">\n"; 276 print_hr(); 277 PRINT "\n$p_message\n"; 278 279 PRINT '<form method="post" action="' . $_SERVER[ 'PHP_SELF' ] . "\">\n"; 280 281 print_hidden_inputs( gpc_strip_slashes( $_POST ) ); 282 print_hidden_inputs( gpc_strip_slashes( $_GET ) ); 283 284 PRINT "<input type=\"hidden\" name=\"_confirmed\" value=\"1\" />\n"; 285 PRINT '<br /><br /><input type="submit" class="button" value="' . $p_button_label . '" />'; 286 PRINT "\n</form>\n"; 287 288 print_hr(); 289 PRINT "</div>\n"; 290 html_page_bottom1(); 291 exit; 292 } 293 294 # -------------------- 295 # Call custom function. 296 # 297 # $p_function - Name of function to call (eg: do_stuff). The function will call custom_function_override_do_stuff() 298 # if found, otherwise, will call custom_function_default_do_stuff(). 299 # $p_args_array - Parameters to function as an array 300 function helper_call_custom_function( $p_function, $p_args_array ) { 301 $t_function = 'custom_function_override_' . $p_function; 302 303 if ( !function_exists( $t_function ) ) { 304 $t_function = 'custom_function_default_' . $p_function; 305 } 306 307 return call_user_func_array( $t_function, $p_args_array ); 308 } 309 310 # -------------------- 311 function helper_project_specific_where( $p_project_id, $p_user_id = null ) { 312 if ( null === $p_user_id ) { 313 $p_user_id = auth_get_current_user_id(); 314 } 315 316 if ( ALL_PROJECTS == $p_project_id ) { 317 $t_topprojects = $t_project_ids = user_get_accessible_projects( $p_user_id ); 318 foreach ( $t_topprojects as $t_project ) { 319 $t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $p_user_id, $t_project ) ); 320 } 321 322 $t_project_ids = array_unique( $t_project_ids ); 323 } else { 324 access_ensure_project_level( VIEWER, $p_project_id ); 325 $t_project_ids = user_get_all_accessible_subprojects( $p_user_id, $p_project_id ); 326 array_unshift( $t_project_ids, $p_project_id ); 327 } 328 329 $t_project_ids = array_map( 'db_prepare_int', $t_project_ids ); 330 331 if ( 0 == count( $t_project_ids ) ) { 332 $t_project_filter = ' 1<>1'; 333 } elseif ( 1 == count( $t_project_ids ) ) { 334 $t_project_filter = ' project_id=' . $t_project_ids[0]; 335 } else { 336 $t_project_filter = ' project_id IN (' . join( ',', $t_project_ids ) . ')'; 337 } 338 339 return $t_project_filter; 340 } 341 342 # -------------------- 343 function helper_get_columns_to_view( $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) { 344 $t_columns = helper_call_custom_function( 'get_columns_to_view', array( $p_columns_target ) ); 345 346 $t_enable_sponsorship = config_get( 'enable_sponsorship' ); 347 if ( OFF == $t_enable_sponsorship ) { 348 $t_keys = array_keys( $t_columns, 'sponsorship_total' ); 349 foreach ( $t_keys as $t_key ) { 350 unset( $t_columns[$t_key] ); 351 } 352 } 353 354 $t_show_attachments = config_get( 'show_attachment_indicator' ); 355 if ( OFF == $t_show_attachments ) { 356 $t_keys = array_keys( $t_columns, 'attachment' ); 357 foreach ( $t_keys as $t_key ) { 358 unset( $t_columns[$t_key] ); 359 } 360 } 361 362 if ( OFF == config_get( 'enable_relationship' ) ) { 363 $t_keys = array_keys( $t_columns, 'duplicate_id' ); 364 foreach ( $t_keys as $t_key ) { 365 unset( $t_columns[$t_key] ); 366 } 367 } 368 369 $t_current_project_id = helper_get_current_project(); 370 if ( $t_current_project_id != ALL_PROJECTS && !access_has_project_level( config_get( 'roadmap_view_threshold' ), $t_current_project_id ) ) { 371 $t_keys = array_keys( $t_columns, 'target_version' ); 372 foreach ( $t_keys as $t_key ) { 373 unset( $t_columns[$t_key] ); 374 } 375 } 376 377 # get the array values to remove gaps in the array which causes issue 378 # if the array is accessed using an index. 379 return array_values( $t_columns ); 380 } 381 382 # -------------------- 383 # if all projects selected, default to <prefix><username><suffix><extension>, otherwise default to 384 # <prefix><projectname><suffix><extension>. 385 function helper_get_default_export_filename( $p_extension_with_dot, $p_prefix = '', $p_suffix = '' ) { 386 $t_filename = $p_prefix; 387 388 $t_current_project_id = helper_get_current_project(); 389 390 if ( ALL_PROJECTS == $t_current_project_id ) { 391 $t_filename .= user_get_name( auth_get_current_user_id() ); 392 } else { 393 $t_filename .= project_get_field( $t_current_project_id, 'name' ); 394 } 395 396 return $t_filename . $p_suffix . $p_extension_with_dot; 397 } 398 399 # -------------------- 400 # returns a tab index value and increments it by one. This is used to give sequential tab index on 401 # a form. 402 function helper_get_tab_index_value() { 403 static $tab_index = 0; 404 return ++$tab_index; 405 } 406 407 # -------------------- 408 # returns a tab index and increments internal state by 1. This is used to give sequential tab index on 409 # a form. For example, this function returns: tabindex="1" 410 function helper_get_tab_index() { 411 return 'tabindex="' . helper_get_tab_index_value() . '"'; 412 } 413 414 # -------------------- 415 # returns a boolean indicating whether SQL queries executed should be shown 416 # or not. 417 function helper_show_queries() { 418 # Check is authenticated before checking access level, otherwise user gets 419 # redirected to login_page.php. See #8461. 420 return ON == config_get( 'show_queries_count' ) && 421 auth_is_user_authenticated() && 422 access_has_global_level( config_get( 'show_queries_threshold' ) ); 423 } 424 ?>
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 |
![]() |