From: Jeroen L. <jl...@us...> - 2005-02-25 00:19:07
|
Update of /cvsroot/mantisbt/mantisbt/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12709/core Modified Files: constant_inc.php html_api.php print_api.php profile_api.php Log Message: Enh #3070: Standard Profiles for all users to use Index: html_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/html_api.php,v retrieving revision 1.149 retrieving revision 1.150 diff -u -d -r1.149 -r1.150 --- html_api.php 17 Feb 2005 21:15:57 -0000 1.149 +++ html_api.php 25 Feb 2005 00:18:40 -0000 1.150 @@ -566,6 +566,7 @@ $t_manage_user_page = 'manage_user_page.php'; $t_manage_project_menu_page = 'manage_proj_page.php'; $t_manage_custom_field_page = 'manage_custom_field_page.php'; + $t_manage_prof_menu_page = 'manage_prof_menu_page.php'; $t_permissions_summary_report = 'adm_permissions_report.php'; # $t_documentation_page = 'documentation_page.php'; @@ -582,6 +583,9 @@ case $t_permissions_summary_report: $t_permissions_summary_report = ''; break; + case $t_manage_prof_menu_page: + $t_manage_prof_menu_page = ''; + break; # case $t_documentation_page: # $t_documentation_page = ''; # break; @@ -597,6 +601,9 @@ if ( access_has_project_level( config_get( 'manage_custom_fields_threshold' ) ) ) { print_bracket_link( $t_manage_custom_field_page, lang_get( 'manage_custom_field_link' ) ); } + if ( access_has_global_level( config_get( 'manage_global_profile_threshold' ) ) ) { + print_bracket_link( $t_manage_prof_menu_page, lang_get( 'manage_global_profiles_link' ) ); + } if ( access_has_project_level( ADMINISTRATOR ) ) { print_bracket_link( $t_permissions_summary_report, lang_get( 'permissions_summary_report' ) ); } Index: constant_inc.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/constant_inc.php,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- constant_inc.php 13 Feb 2005 21:36:37 -0000 1.38 +++ constant_inc.php 25 Feb 2005 00:18:39 -0000 1.39 @@ -114,6 +114,9 @@ # all projects define( 'ALL_PROJECTS', 0 ); + + # all users + define( 'ALL_USERS', 0 ); # no user define( 'NO_USER', 0 ); Index: profile_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/profile_api.php,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- profile_api.php 12 Feb 2005 20:01:18 -0000 1.8 +++ profile_api.php 25 Feb 2005 00:18:40 -0000 1.9 @@ -28,7 +28,9 @@ $c_os_build = db_prepare_string( $p_os_build ); $c_description = db_prepare_string( $p_description ); - user_ensure_unprotected( $p_user_id ); + if ( ALL_USERS != $p_user_id ) { + user_ensure_unprotected( $p_user_id ); + } # platform, os, os_build cannot be blank if ( is_blank( $c_platform ) || is_blank( $c_os ) || is_blank( $c_os_build ) ) { @@ -57,7 +59,9 @@ $c_user_id = db_prepare_int( $p_user_id ); $c_profile_id = db_prepare_int( $p_profile_id ); - user_ensure_unprotected( $p_user_id ); + if ( ALL_USERS != $p_user_id ) { + user_ensure_unprotected( $p_user_id ); + } $t_user_profile_table = config_get( 'mantis_user_profile_table' ); @@ -80,7 +84,9 @@ $c_os_build = db_prepare_string( $p_os_build ); $c_description = db_prepare_string( $p_description ); - user_ensure_unprotected( $p_user_id ); + if ( ALL_USERS != $p_user_id ) { + user_ensure_unprotected( $p_user_id ); + } # platform, os, os_build cannot be blank if ( is_blank( $c_platform ) || is_blank( $c_os ) || is_blank( $c_os_build ) ) { @@ -143,7 +149,45 @@ return $t_rows; } + + # -------------------- + # Return an array containing all profiles for a given user, + # including global profiles + function profile_get_all_for_user( $p_user_id ) { + if ( ALL_USERS == $p_user_id ) { + return profile_get_all_rows( ALL_USERS ); + } else { + return array_merge( profile_get_all_rows( ALL_USERS ), + profile_get_all_rows( $p_user_id ) ); + } + } + + # -------------------- + # Return an array containing all global profiles + function profile_get_global() { + return profile_get_all_rows( ALL_USERS ); + } + # -------------------- + # Returns the default profile + function profile_get_default( $p_user_id ) { + global $g_mantis_user_pref_table; + + $c_user_id = db_prepare_int( $p_user_id ); + $query = "SELECT default_profile + FROM $g_mantis_user_pref_table + WHERE user_id='$c_user_id'"; + $result = db_query( $query ); + + $t_default_profile = db_result( $result, 0, 0 ); + + return $t_default_profile; + } + # -------------------- + # Returns whether the specified profile is global + function profile_is_global( $p_profile_id ) { + return 0 < count( profile_get_row( ALL_USERS, $p_profile_id ) ); + } #=================================== # Data Modification #=================================== Index: print_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/print_api.php,v retrieving revision 1.115 retrieving revision 1.116 diff -u -d -r1.115 -r1.116 --- print_api.php 20 Feb 2005 21:12:07 -0000 1.115 +++ print_api.php 25 Feb 2005 00:18:40 -0000 1.116 @@ -14,6 +14,7 @@ require_once( $t_core_dir . 'current_user_api.php' ); require_once( $t_core_dir . 'string_api.php' ); require_once( $t_core_dir . 'prepare_api.php' ); + require_once( $t_core_dir . 'profile_api.php' ); ### Print API ### @@ -334,35 +335,18 @@ # -------------------- # prints the profiles given the user id function print_profile_option_list( $p_user_id, $p_select_id='' ) { - global $g_mantis_user_profile_table, $g_mantis_user_pref_table; - - $c_user_id = db_prepare_int( $p_user_id ); - - $query = "SELECT default_profile - FROM $g_mantis_user_pref_table - WHERE user_id='$c_user_id'"; - $result = db_query( $query ); - $v_default_profile = db_result( $result, 0, 0 ); - - # Get profiles - $query = "SELECT id, platform, os, os_build - FROM $g_mantis_user_profile_table - WHERE user_id='$c_user_id' - ORDER BY id"; - $result = db_query( $query ); - $profile_count = db_num_rows( $result ); + $t_default_profile = profile_get_default( $p_user_id ); + $t_profiles = profile_get_all_for_user( $p_user_id ); PRINT '<option value=""></option>'; - for ($i=0;$i<$profile_count;$i++) { - # prefix data with v_ - $row = db_fetch_array( $result ); - extract( $row, EXTR_PREFIX_ALL, 'v' ); + foreach ( $t_profiles as $t_profile ) { + extract( $t_profile, EXTR_PREFIX_ALL, 'v' ); $v_platform = string_display( $v_platform ); $v_os = string_display( $v_os ); $v_os_build = string_display( $v_os_build ); PRINT "<option value=\"$v_id\""; - check_selected( $v_id, $v_default_profile ); + check_selected( $v_id, $t_default_profile ); PRINT ">$v_platform $v_os $v_os_build</option>"; } } |