| [ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 # MantisConnect - A webservice interface to Mantis Bug Tracker 3 # Copyright (C) 2004-2007 Victor Boctor - vboctor@users.sourceforge.net 4 # This program is distributed under dual licensing. These include 5 # GPL and a commercial licenses. Victor Boctor reserves the right to 6 # change the license of future releases. 7 # See docs/ folder for more details 8 9 # -------------------------------------------------------- 10 # $Id: mc_api.php,v 1.2 2007-08-22 04:09:59 vboctor Exp $ 11 # -------------------------------------------------------- 12 13 # use standard error handler rather than the one defined in Mantis. 14 restore_error_handler(); 15 16 # override some Mantis configurations 17 $g_show_detailed_errors = OFF; 18 $g_stop_on_errors = ON; 19 $g_display_errors = array( 20 E_WARNING => 'halt', 21 E_NOTICE => 'halt', 22 E_USER_ERROR => 'halt', 23 E_USER_WARNING => 'halt', 24 E_USER_NOTICE => 'halt' 25 ); 26 27 /** 28 * Get the MantisConnect webservice version. 29 */ 30 function mc_version() 31 { 32 return '1.1.0-SVN'; 33 } 34 35 # -------------------- 36 # Checks if Mantis installation is marked as offline by the administrator. 37 # true: offline, false: online 38 function mci_is_mantis_offline() { 39 $t_offline_file = dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'mantis_offline.php'; 40 return file_exists( $t_offline_file ); 41 } 42 43 # -------------------- 44 # return user_id if successful, otherwise false. 45 function mci_check_login( $p_username, $p_password ) { 46 if ( mci_is_mantis_offline() ) { 47 return false; 48 } 49 50 # if no user name supplied, then attempt to login as anonymous user. 51 if ( is_blank( $p_username ) ) { 52 $t_anon_allowed = config_get( 'allow_anonymous_login' ); 53 if ( OFF == $t_anon_allowed ) { 54 return false; 55 } 56 57 $p_username = config_get( 'anonymous_account' ); 58 59 # do not use password validation. 60 $p_password = null; 61 } 62 63 if ( false === auth_attempt_script_login( $p_username, $p_password ) ) { 64 return false; 65 } 66 67 return auth_get_current_user_id(); 68 } 69 70 # -------------------- 71 function mci_has_readonly_access( $p_user_id, $p_project_id = ALL_PROJECTS ) { 72 $t_access_level = user_get_access_level( $p_user_id, $p_project_id ); 73 return ( $t_access_level >= config_get( 'mc_readonly_access_level_threshold' ) ); 74 } 75 76 # -------------------- 77 function mci_has_readwrite_access( $p_user_id, $p_project_id = ALL_PROJECTS ) { 78 $t_access_level = user_get_access_level( $p_user_id, $p_project_id ); 79 return ( $t_access_level >= config_get( 'mc_readwrite_access_level_threshold' ) ); 80 } 81 82 # -------------------- 83 function mci_has_administrator_access( $p_user_id, $p_project_id = ALL_PROJECTS ) { 84 $t_access_level = user_get_access_level( $p_user_id, $p_project_id ); 85 return ( $t_access_level >= config_get( 'mc_admin_access_level_threshold' ) ); 86 } 87 88 # -------------------- 89 function mci_get_project_id( $p_project ) { 90 if ( (int)$p_project['id'] != 0 ) { 91 $t_project_id = (int)$p_project['id']; 92 } else { 93 $t_project_id = project_get_id_by_name( $p_project['name'] ); 94 } 95 96 return $t_project_id; 97 } 98 99 # -------------------- 100 function mci_get_project_status_id( $p_status ) { 101 return mci_get_enum_id_from_objectref( 'project_status', $p_status ); 102 } 103 104 # -------------------- 105 function mci_get_project_view_state_id( $p_view_state ) { 106 return mci_get_enum_id_from_objectref( 'project_view_state', $p_view_state ); 107 } 108 109 # -------------------- 110 function mci_get_user_id( &$p_user ) { 111 if ( !isset( $p_user ) ) { 112 return 0; 113 } 114 115 $t_user_id = 0; 116 117 if ( (int)$p_user['id'] != 0 ) { 118 $t_user_id = (int)$p_user['id']; 119 } else { 120 if ( isset( $p_user['name'] ) ) { 121 $t_user_id = user_get_id_by_name( $p_user['name'] ); 122 } 123 } 124 125 return $t_user_id; 126 } 127 128 # -------------------- 129 function mci_get_user_lang( $p_user_id ) { 130 $t_lang = user_pref_get_pref( $p_user_id, 'language' ); 131 if ( $t_lang == 'auto' ) { 132 $t_lang = config_get( 'fallback_language' ); 133 } 134 return $t_lang; 135 } 136 137 # -------------------- 138 function mci_get_status_id( $p_status ) { 139 return mci_get_enum_id_from_objectref( 'status', $p_status ); 140 } 141 142 # -------------------- 143 function mci_get_severity_id( $p_severity ) { 144 return mci_get_enum_id_from_objectref( 'severity', $p_severity ); 145 } 146 147 # -------------------- 148 function mci_get_priority_id( $p_priority ) { 149 return mci_get_enum_id_from_objectref( 'priority', $p_priority ); 150 } 151 152 # -------------------- 153 function mci_get_reproducibility_id( $p_reproducibility ) { 154 return mci_get_enum_id_from_objectref( 'reproducibility', $p_reproducibility ); 155 } 156 157 # -------------------- 158 function mci_get_resolution_id( $p_resolution ) { 159 return mci_get_enum_id_from_objectref( 'resolution', $p_resolution ); 160 } 161 162 # -------------------- 163 function mci_get_projection_id( $p_projection ) { 164 return mci_get_enum_id_from_objectref( 'projection', $p_projection ); 165 } 166 167 # -------------------- 168 function mci_get_eta_id( $p_eta ) { 169 return mci_get_enum_id_from_objectref( 'eta', $p_eta ); 170 } 171 172 # -------------------- 173 function mci_get_view_state_id( $p_view_state ) { 174 return mci_get_enum_id_from_objectref( 'view_state', $p_view_state ); 175 } 176 177 # -------------------- 178 # Get null on empty value. 179 # 180 # @param Object $p_value The value 181 # @return Object The value if not empty; null otherwise. 182 # 183 function mci_null_if_empty( &$p_value ) { 184 if( !is_blank( $p_value ) ) { 185 return $p_value; 186 } 187 188 return null; 189 } 190 191 /** 192 * Gets the url for Mantis. This is based on the 'path' config variable in Mantis. However, 193 * the default value for 'path' doesn't work properly when access from within MantisConnect. 194 * This internal function fixes this bug. 195 * 196 * @return Mantis URL terminated by a /. 197 */ 198 function mci_get_mantis_path() { 199 $t_path = config_get( 'path' ); 200 $t_dir = basename( dirname( __FILE__ ) ); 201 202 # for some reason str_replace() doesn't work when DIRECTORY_SEPARATOR (/) is in the search 203 # string. 204 $t_path = str_replace( $t_dir . '/', '', $t_path ); 205 206 return $t_path; 207 } 208 209 # -------------------- 210 # Given a enum string and num, return the appropriate localized string 211 function mci_get_enum_element( $p_enum_name, $p_val, $p_lang ) { 212 $config_var = config_get( $p_enum_name.'_enum_string' ); 213 $string_var = lang_get( $p_enum_name.'_enum_string', $p_lang ); 214 215 # use the global enum string to search 216 $t_arr = explode_enum_string( $config_var ); 217 $t_arr_count = count( $t_arr ); 218 for ( $i=0; $i < $t_arr_count ;$i++ ) { 219 $elem_arr = explode_enum_arr( $t_arr[$i] ); 220 if ( $elem_arr[0] == $p_val ) { 221 # now get the appropriate translation 222 return get_enum_to_string( $string_var, $p_val ); 223 } 224 } 225 return '@' . $p_val . '@'; 226 } 227 228 function mci_user_get_accessible_subprojects( $p_user_id, $p_parent_project_id ) { 229 $t_result = array(); 230 foreach( user_get_accessible_subprojects( $p_user_id, $p_parent_project_id ) as $t_subproject_id ) { 231 $t_subproject_row = project_cache_row( $t_subproject_id ); 232 $t_subproject = array(); 233 $t_subproject['id'] = $t_subproject_id; 234 $t_subproject['name'] = $t_subproject_row['name']; 235 $t_subproject['status'] = mci_enum_get_array_by_id( $t_subproject_row['status'], 'project_status', $t_lang ); 236 $t_subproject['enabled'] = $t_subproject_row['enabled']; 237 $t_subproject['view_state'] = mci_enum_get_array_by_id( $t_subproject_row['view_state'], 'project_view_state', $t_lang ); 238 $t_subproject['access_min'] = mci_enum_get_array_by_id( $t_subproject_row['access_min'], 'access_levels', $t_lang ); 239 $t_subproject['file_path'] = 240 array_key_exists( 'file_path', $t_subproject_row ) ? $t_subproject_row['file_path'] : ""; 241 $t_subproject['description'] = 242 array_key_exists( 'description', $t_subproject_row ) ? $t_subproject_row['description'] : ""; 243 $t_subproject['subprojects'] = mci_user_get_accessible_subprojects( $p_user_id, $t_subproject_id ); 244 $t_result[] = $t_subproject; 245 } 246 return $t_result; 247 } 248 249 # -------------------- 250 # category_get_all_rows did't respect subprojects. 251 function mci_category_get_all_rows( $p_project_id, $p_user_id ) { 252 $t_mantis_project_category_table = config_get( 'mantis_project_category_table' ); 253 254 $c_project_id = db_prepare_int( $p_project_id ); 255 256 $t_project_where = helper_project_specific_where( $c_project_id, $p_user_id ); 257 258 # grab all categories in the project category table 259 $cat_arr = array(); 260 $query = "SELECT DISTINCT category 261 FROM $t_mantis_project_category_table 262 WHERE $t_project_where 263 ORDER BY category"; 264 $result = db_query( $query ); 265 $category_count = db_num_rows( $result ); 266 for ($i=0;$i<$category_count;$i++) { 267 $row = db_fetch_array( $result ); 268 $cat_arr[] = string_attribute( $row['category'] ); 269 } 270 sort( $cat_arr ); 271 $cat_arr = array_unique( $cat_arr ); 272 273 $rows = array(); 274 foreach( $cat_arr as $t_category ) { 275 $rows[] = $t_category; 276 } 277 return $rows; 278 } 279 280 # set up error_handler() as the new default error handling function 281 set_error_handler( 'mc_error_handler' ); 282 283 ######################################### 284 # SECURITY NOTE: these globals are initialized here to prevent them 285 # being spoofed if register_globals is turned on 286 # 287 $g_error_parameters = array(); 288 $g_error_handled = false; 289 $g_error_proceed_url = null; 290 291 # --------------- 292 # Default error handler 293 # 294 # This handler will not receive E_ERROR, E_PARSE, E_CORE_*, or E_COMPILE_* 295 # errors. 296 # 297 # E_USER_* are triggered by us and will contain an error constant in $p_error 298 # The others, being system errors, will come with a string in $p_error 299 # 300 function mc_error_handler( $p_type, $p_error, $p_file, $p_line, $p_context ) { 301 global $g_error_parameters, $g_error_handled, $g_error_proceed_url; 302 global $g_lang_overrides; 303 global $g_error_send_page_header; 304 305 # check if errors were disabled with @ somewhere in this call chain 306 # also suppress php 5 strict warnings 307 if ( 0 == error_reporting() || 2048 == $p_type ) { 308 return; 309 } 310 311 $t_lang_pushed = false; 312 313 # flush any language overrides to return to user's natural default 314 if ( function_exists( 'db_is_connected' ) ) { 315 if ( db_is_connected() ) { 316 lang_push( lang_get_default() ); 317 $t_lang_pushed = true; 318 } 319 } 320 321 $t_short_file = basename( $p_file ); 322 $t_method_array = config_get( 'display_errors' ); 323 if ( isset( $t_method_array[$p_type] ) ) { 324 $t_method = $t_method_array[$p_type]; 325 } else { 326 $t_method = 'none'; 327 } 328 329 # build an appropriate error string 330 switch ( $p_type ) { 331 case E_WARNING: 332 $t_error_type = 'SYSTEM WARNING'; 333 $t_error_description = $p_error; 334 break; 335 case E_NOTICE: 336 $t_error_type = 'SYSTEM NOTICE'; 337 $t_error_description = $p_error; 338 break; 339 case E_USER_ERROR: 340 $t_error_type = "APPLICATION ERROR #$p_error"; 341 $t_error_description = error_string( $p_error ); 342 break; 343 case E_USER_WARNING: 344 $t_error_type = "APPLICATION WARNING #$p_error"; 345 $t_error_description = error_string( $p_error ); 346 break; 347 case E_USER_NOTICE: 348 # used for debugging 349 $t_error_type = 'DEBUG'; 350 $t_error_description = $p_error; 351 break; 352 default: 353 #shouldn't happen, just display the error just in case 354 $t_error_type = ''; 355 $t_error_description = $p_error; 356 } 357 358 $t_error_description = nl2br( $t_error_description ); 359 360 return new soap_fault( 'Server', '', $t_error_type . ': ' . $t_error_description ); 361 } 362 ?>
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 |
|