[ 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: profile_api.php,v 1.18.2.1 2007-10-13 22:35:39 giallu Exp $ 22 # -------------------------------------------------------- 23 24 ### Profile API ### 25 26 #=================================== 27 # Boolean queries and ensures 28 #=================================== 29 30 #=================================== 31 # Creation / Deletion / Updating 32 #=================================== 33 34 # -------------------- 35 # Create a new profile for the user, return the ID of the new profile 36 function profile_create( $p_user_id, $p_platform, $p_os, $p_os_build, $p_description ) { 37 $c_user_id = db_prepare_int( $p_user_id ); 38 $c_platform = db_prepare_string( $p_platform ); 39 $c_os = db_prepare_string( $p_os ); 40 $c_os_build = db_prepare_string( $p_os_build ); 41 $c_description = db_prepare_string( $p_description ); 42 43 if ( ALL_USERS != $p_user_id ) { 44 user_ensure_unprotected( $p_user_id ); 45 } 46 47 # platform cannot be blank 48 if ( is_blank( $c_platform ) ) { 49 error_parameters( lang_get( 'platform' ) ); 50 trigger_error( ERROR_EMPTY_FIELD, ERROR ); 51 } 52 53 # os cannot be blank 54 if ( is_blank( $c_os ) ) { 55 error_parameters( lang_get( 'operating_system' ) ); 56 trigger_error( ERROR_EMPTY_FIELD, ERROR ); 57 } 58 59 # os_build cannot be blank 60 if ( is_blank( $c_os_build ) ) { 61 error_parameters( lang_get( 'version' ) ); 62 trigger_error( ERROR_EMPTY_FIELD, ERROR ); 63 } 64 65 $t_user_profile_table = config_get( 'mantis_user_profile_table' ); 66 67 # Add profile 68 $query = "INSERT INTO $t_user_profile_table 69 ( user_id, platform, os, os_build, description ) 70 VALUES 71 ( '$c_user_id', '$c_platform', '$c_os', '$c_os_build', '$c_description' )"; 72 db_query( $query ); 73 74 return db_insert_id($t_user_profile_table); 75 } 76 77 # -------------------- 78 # Delete a profile for the user 79 # 80 # Note that although profile IDs are currently globally unique, the existing 81 # code included the user_id in the query and I have chosen to keep that for 82 # this API as it hides the details of id implementation from users of the API 83 function profile_delete( $p_user_id, $p_profile_id ) { 84 $c_user_id = db_prepare_int( $p_user_id ); 85 $c_profile_id = db_prepare_int( $p_profile_id ); 86 87 if ( ALL_USERS != $p_user_id ) { 88 user_ensure_unprotected( $p_user_id ); 89 } 90 91 $t_user_profile_table = config_get( 'mantis_user_profile_table' ); 92 93 # Delete the profile 94 $query = "DELETE FROM $t_user_profile_table 95 WHERE id='$c_profile_id' AND user_id='$c_user_id'"; 96 db_query( $query ); 97 98 # db_query() errors on failure so: 99 return true; 100 } 101 102 # -------------------- 103 # Update a profile for the user 104 function profile_update( $p_user_id, $p_profile_id, $p_platform, $p_os, $p_os_build, $p_description ) { 105 $c_user_id = db_prepare_int( $p_user_id ); 106 $c_profile_id = db_prepare_int( $p_profile_id ); 107 $c_platform = db_prepare_string( $p_platform ); 108 $c_os = db_prepare_string( $p_os ); 109 $c_os_build = db_prepare_string( $p_os_build ); 110 $c_description = db_prepare_string( $p_description ); 111 112 if ( ALL_USERS != $p_user_id ) { 113 user_ensure_unprotected( $p_user_id ); 114 } 115 116 # platform cannot be blank 117 if ( is_blank( $c_platform ) ) { 118 error_parameters( lang_get( 'platform' ) ); 119 trigger_error( ERROR_EMPTY_FIELD, ERROR ); 120 } 121 122 # os cannot be blank 123 if ( is_blank( $c_os ) ) { 124 error_parameters( lang_get( 'operating_system' ) ); 125 trigger_error( ERROR_EMPTY_FIELD, ERROR ); 126 } 127 128 # os_build cannot be blank 129 if ( is_blank( $c_os_build ) ) { 130 error_parameters( lang_get( 'version' ) ); 131 trigger_error( ERROR_EMPTY_FIELD, ERROR ); 132 } 133 134 $t_user_profile_table = config_get( 'mantis_user_profile_table' ); 135 136 # Add item 137 $query = "UPDATE $t_user_profile_table 138 SET platform='$c_platform', 139 os='$c_os', 140 os_build='$c_os_build', 141 description='$c_description' 142 WHERE id='$c_profile_id' AND user_id='$c_user_id'"; 143 $result = db_query( $query ); 144 145 # db_query() errors on failure so: 146 return true; 147 } 148 149 #=================================== 150 # Data Access 151 #=================================== 152 153 # -------------------- 154 # Return a profile row from the database 155 function profile_get_row( $p_user_id, $p_profile_id ) { 156 $c_user_id = db_prepare_int( $p_user_id ); 157 $c_profile_id = db_prepare_int( $p_profile_id ); 158 159 $t_user_profile_table = config_get( 'mantis_user_profile_table' ); 160 161 $query = "SELECT * 162 FROM $t_user_profile_table 163 WHERE id='$c_profile_id' AND user_id='$c_user_id'"; 164 $result = db_query( $query ); 165 166 return db_fetch_array( $result ); 167 } 168 169 # -------------------- 170 # Return a profile row from the database 171 function profile_get_row_direct( $p_profile_id ) { 172 $c_profile_id = db_prepare_int( $p_profile_id ); 173 174 $t_user_profile_table = config_get( 'mantis_user_profile_table' ); 175 176 $query = "SELECT * 177 FROM $t_user_profile_table 178 WHERE id='$c_profile_id'"; 179 $result = db_query( $query ); 180 181 return db_fetch_array( $result ); 182 } 183 184 # -------------------- 185 # Return an array containing all rows for a given user 186 function profile_get_all_rows( $p_user_id ) { 187 $c_user_id = db_prepare_int( $p_user_id ); 188 189 $t_user_profile_table = config_get( 'mantis_user_profile_table' ); 190 191 $query = "SELECT * 192 FROM $t_user_profile_table 193 WHERE user_id='$c_user_id' 194 ORDER BY platform, os, os_build"; 195 $result = db_query( $query ); 196 197 $t_rows = array(); 198 $t_row_count = db_num_rows( $result ); 199 200 for ( $i=0 ; $i < $t_row_count ; $i++ ) { 201 array_push( $t_rows, db_fetch_array( $result ) ); 202 } 203 204 return $t_rows; 205 } 206 207 # -------------------- 208 # Return an array containing all profiles for a given user, 209 # including global profiles 210 function profile_get_all_for_user( $p_user_id ) { 211 if ( ALL_USERS == $p_user_id ) { 212 return profile_get_all_rows( ALL_USERS ); 213 } else { 214 $t_profiles_array = array_merge( profile_get_all_rows( ALL_USERS ), 215 profile_get_all_rows( $p_user_id ) ); 216 asort( $t_profiles_array ); 217 return $t_profiles_array; 218 } 219 } 220 221 # -------------------- 222 # Return an array of strings containing unique values for the specified field based 223 # on private and public profiles accessible to the specified user. 224 function profile_get_field_all_for_user( $p_field, $p_user_id = null ) { 225 $c_user_id = ( $p_user_id === null ) ? auth_get_current_user_id() : db_prepare_int( $p_user_id ); 226 $c_field = db_prepare_string( $p_field ); 227 228 $t_user_profile_table = config_get( 'mantis_user_profile_table' ); 229 230 $query = "SELECT DISTINCT $c_field 231 FROM $t_user_profile_table 232 WHERE ( user_id='$c_user_id' ) OR ( user_id = '0' ) 233 ORDER BY $c_field"; 234 $result = db_query( $query ); 235 236 $t_rows = array(); 237 238 $t_row_count = db_num_rows( $result ); 239 240 for ( $i=0 ; $i < $t_row_count ; $i++ ) { 241 $t_row = db_fetch_array( $result ); 242 array_push( $t_rows, $t_row[$c_field] ); 243 } 244 245 return $t_rows; 246 } 247 248 # -------------------- 249 # Return an array containing all profiles used in a given project 250 function profile_get_all_for_project( $p_project_id ) { 251 $t_project_where = helper_project_specific_where( $p_project_id ); 252 253 $t_bug_table = config_get( 'mantis_bug_table' ); 254 $t_user_profile_table = config_get( 'mantis_user_profile_table' ); 255 256 # using up.* causes an SQL error on MS SQL since up.description is of type text 257 $query = "SELECT DISTINCT(up.id), up.user_id, up.platform, up.os, up.os_build 258 FROM $t_user_profile_table up, $t_bug_table b 259 WHERE $t_project_where 260 AND up.id = b.profile_id"; 261 $result = db_query( $query ); 262 263 $t_rows = array(); 264 $t_row_count = db_num_rows( $result ); 265 266 for ( $i=0 ; $i < $t_row_count ; $i++ ) { 267 array_push( $t_rows, db_fetch_array( $result ) ); 268 } 269 270 return $t_rows; 271 } 272 273 # -------------------- 274 # Return an array containing all global profiles 275 function profile_get_global() { 276 return profile_get_all_rows( ALL_USERS ); 277 } 278 # -------------------- 279 # Returns the default profile 280 function profile_get_default( $p_user_id ) { 281 282 $c_user_id = db_prepare_int( $p_user_id ); 283 $t_mantis_user_pref_table = config_get( 'mantis_user_pref_table' ); 284 285 $query = "SELECT default_profile 286 FROM $t_mantis_user_pref_table 287 WHERE user_id='$c_user_id'"; 288 $result = db_query( $query ); 289 290 $t_default_profile = db_result( $result, 0, 0 ); 291 292 return $t_default_profile; 293 } 294 # -------------------- 295 # Returns whether the specified profile is global 296 function profile_is_global( $p_profile_id ) { 297 $t_row = profile_get_row( ALL_USERS, $p_profile_id ); 298 return ( $t_row !== false ); 299 } 300 #=================================== 301 # Data Modification 302 #=================================== 303 ?>
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 |
![]() |