get_blog_roles_daterange( 'rs', array( 'include_role_duration_key' => true, 'enforce_duration_limits' => false ) );	// arg: return array with additional key dimension for role duration 
		
		// for Administrators, display any custom post General Roles which were auto-assigned to maintain default editing rights
		global $current_rs_user;
		if ( $current_rs_user->ID == $user->ID ) {
			if ( is_content_administrator_rs() )
				$blog_roles[''][''] = ( isset($blog_roles['']['']) ) ? array_merge( $current_rs_user->assigned_blog_roles[''] ) : $current_rs_user->assigned_blog_roles[''];
		}
		
		foreach ( $this->scoper->taxonomies->get_all() as $taxonomy => $tx )	
			$term_roles[$taxonomy] = $user->get_term_roles_daterange( $taxonomy, 'rs', array( 'include_role_duration_key' => true, 'enforce_duration_limits' => false ) );	// arg: return array with additional key dimension for role duration
		$duration_limits_enabled = scoper_get_option( 'role_duration_limits' );
		$content_date_limits_enabled = scoper_get_option( 'role_content_date_limits' );
		
		$html = '';
		
		if ( $groups_only ) {
			if ( IS_MU_RS && scoper_get_option( 'mu_sitewide_groups', true ) ) {
				global $blog_id;
				
				$list = scoper_get_blog_list( 0, 'all' );
				
				$blog_path = '';
				foreach ( $list as $blog ) {
					if ( $blog['blog_id'] == $blog_id ) {
						$blog_path = $blog['path'];
						break;	
					}
				}
				$group_caption = sprintf( __('Group Roles %1$s(for %2$s)%3$s', 'scoper'), '', rtrim($blog_path, '/'), '' );
			} else
				$group_caption = __('Group Roles', 'scoper');
		} else {
			$html .= "
";
			$html .= "
" . __('Scoped Roles', 'scoper') . "
";
			$wp_blog_roles = array_intersect_key( $user->assigned_blog_roles[''], $scoper->role_defs->get_matching( 'wp' ) );
			if ( ! empty($wp_blog_roles) ) {
				$display_names = array();
				
				foreach (array_keys($wp_blog_roles) as $role_handle)
					$display_names []= $scoper->role_defs->get_display_name($role_handle);
				$html .= sprintf( __("
Assigned WordPress Role: %s", 'scoper'), implode(", ", $display_names) );
			
				if ( $contained_roles = $this->scoper->role_defs->get_contained_roles( array_keys($wp_blog_roles), false, 'rs' ) ) {
					$display_names = array();			
					foreach (array_keys($contained_roles) as $role_handle)
						$display_names []= $this->scoper->role_defs->get_display_name($role_handle);
					
					$html .= '
';
					$html .= sprintf( __("(contains %s)", 'scoper'), implode(", ", $display_names) );
					$html .= '';
				}
			}
			
			$html .= '
';
		}
		
		
		$display_names = array();
		
		foreach ( array_keys($blog_roles) as $duration_key ) {
			if ( is_serialized($duration_key) ) {
				$role_date_limits = unserialize( $duration_key );
				$role_date_limits->date_limited = true;
			} else
				$role_date_limits = array();
			foreach ( array_keys($blog_roles[$duration_key]) as $date_key ) {
				$display_names = array();
				
				if ( is_serialized($date_key) ) {
					$content_date_limits = unserialize( $date_key );
					$content_date_limits->content_date_limited = true;
				} else
					$content_date_limits = array();
				$date_caption = '';
					
				if ( $role_date_limits || $content_date_limits ) {
					$limit_class = ''; // unused byref arg
					$limit_style = ''; // unused byref arg
					$link_class = '';  // unused byref arg
					ScoperAdminUI::set_agent_formatting( array_merge( (array) $role_date_limits, (array) $content_date_limits ), $date_caption, $limit_class, $link_class, $limit_style, false ); // arg: no title='' wrapper around date_caption
					$date_caption = '
 ' . trim($date_caption) . '';
				}
					
				if ( $rs_blog_roles = $this->scoper->role_defs->filter( $blog_roles[$duration_key][$date_key], array( 'role_type' => 'rs' ) ) ) {
					foreach ( array_keys($rs_blog_roles) as $role_handle )
						$display_names []= $this->scoper->role_defs->get_display_name($role_handle);
					
					$url = "admin.php?page=rs-general_roles";
					$linkopen = "
";
					$linkclose = "";
					$list = implode(", ", $display_names);
					
					if ( $groups_only )
						$html .= sprintf( _n('
%1$sGeneral Role%2$s%4$s: %3$s', '
%1$sGeneral Roles%2$s%4$s: %3$s', count($display_names), 'scoper'), $linkopen, $linkclose, $list, $date_caption);
					else
						$html .= sprintf( _n('
Additional %1$sGeneral Role%2$s%4$s: %3$s', '
Additional %1$sGeneral Roles%2$s%4$s: %3$s', count($display_names), 'scoper'), $linkopen, $linkclose, $list, $date_caption);
				
					if ( $contained_roles = $this->scoper->role_defs->get_contained_roles( array_keys($rs_blog_roles), false, 'rs' ) ) {
						$display_names = array();
						foreach (array_keys($contained_roles) as $role_handle)
							$display_names []= $this->scoper->role_defs->get_display_name($role_handle);
						
						$html .= '
';
						$html .= sprintf( __("(contains %s)", 'scoper'), implode(", ", $display_names) );
						$html .= '';
					}
					
					$html .= '
';
				}
			} // end foreach content date range
		} // end foreach role duration date range
	
		
		$disable_role_admin = false;
		
		global $profileuser;
		$viewing_own_profile = ( ! empty($profileuser) && ( $profileuser->ID == $current_rs_user->ID ) );
		
		if ( ! $viewing_own_profile ) {
			if ( $require_blogwide_editor = scoper_get_option('role_admin_blogwide_editor_only') ) {
				if ( ( 'admin' == $require_blogwide_editor ) && ! is_user_administrator_rs() )
					return false;
					
				if ( ( 'admin_content' == $require_blogwide_editor ) && ! is_content_administrator_rs() )
					return false;
		
				$disable_role_admin = ! $scoper->user_can_edit_blogwide( 'post', '', array( 'require_others_cap' => true, 'status' => 'publish' ) );
			}
		}
		foreach ( $this->scoper->taxonomies->get_all() as $taxonomy => $tx ) {
			if ( empty($term_roles[$taxonomy]) )
				continue;
			
			$val = ORDERBY_HIERARCHY_RS;
			$args = array( 'order_by' => $val );
			if ( ! $terms = $this->scoper->get_terms($taxonomy, UNFILTERED_RS, COLS_ALL_RS, 0, $args) )
				continue;
			$object_types = array();
			
			$obj_src = $this->scoper->data_sources->get( $tx->object_source );
			
			if ( ! $obj_src || ! is_array($obj_src->object_types) )
				continue;
			foreach ( array_keys($obj_src->object_types) as $object_type)
				if ( scoper_get_otype_option('use_term_roles', $tx->object_source, $object_type) )
					$object_types []= $object_type;
				
			if ( ! $object_types )
				continue;
			$object_types []= $taxonomy;
				
			$admin_terms = ( $disable_role_admin ) ? array() : $this->scoper->get_terms($taxonomy, ADMIN_TERMS_FILTER_RS, COL_ID_RS);
			$strict_terms = $this->scoper->get_restrictions(TERM_SCOPE_RS, $taxonomy);
			$role_defs = $this->scoper->role_defs->get_matching('rs', $tx->object_source, $object_types);
			$tx_src = $this->scoper->data_sources->get( $tx->source );
			$col_id = $tx_src->cols->id;
			$col_name = $tx_src->cols->name;
			
			$term_names = array();
			foreach ( $terms as $term )
				$term_names[$term->$col_id] = $term->$col_name;
				
			foreach ( array_keys($term_roles[$taxonomy]) as $duration_key ) {
				if ( is_serialized($duration_key) ) {
					$role_date_limits = unserialize( $duration_key );
					$role_date_limits->date_limited = true;
				} else
					$role_date_limits = array();
					
				foreach ( array_keys($term_roles[$taxonomy][$duration_key]) as $date_key ) {
					if ( is_serialized($date_key) ) {
						$content_date_limits = unserialize( $date_key );
						$content_date_limits->content_date_limited = true;
					} else
						$content_date_limits = array();
						
					$title = '';
					$date_caption = '';
					$limit_class = '';
					$limit_style = '';
					$link_class = '';
					$style = '';
					
					if ( $role_date_limits || $content_date_limits ) {
						ScoperAdminUI::set_agent_formatting( array_merge( (array) $role_date_limits, (array) $content_date_limits ), $date_caption, $limit_class, $link_class, $limit_style );
						$title = "title='$date_caption'";
						$date_caption = '
 ' . trim($date_caption) . '';
					}
						
					if ( $admin_terms ) {
						$url = "admin.php?page=rs-$taxonomy-roles_t";
						//$html .= ("\n
' );
						$html .= ("\n
' );
					} else
						$html .= ("\n
" . sprintf(__('%1$s Roles%2$s:', 'scoper'), $tx->labels->singular_name, $date_caption) . '
' );
						//$html .= ("\n
" . sprintf(_ x('%1$s Roles%2$s:', 'Category Roles, content date range', 'scoper'), $tx->display_name, $date_caption) . '
' );
		
					$html .= '
';
					$html .= '- ';
					$html .= '';
					$html .= '| ' . __awp('Role') . '';
					$html .= ' | ' . $tx->labels->name . '';
					$html .= ' |  ';
					
					foreach ( array_keys($role_defs) as $role_handle ) {
						if ( isset( $term_roles[$taxonomy][$duration_key][$date_key][$role_handle] ) ) {
		
							$role_terms = $term_roles[$taxonomy][$duration_key][$date_key][$role_handle];
							$role_display = $this->scoper->role_defs->get_display_name($role_handle);
							$term_role_list = array();
							foreach ( $role_terms as $term_id ) {
								if ( ! in_array( $term_id, $admin_terms ) )
									$term_role_list []= $term_names[$term_id];
								elseif ( isset($strict_terms['restrictions'][$role_handle][$term_id]) 
								|| ( isset($strict_terms['unrestrictions'][$role_handle]) && is_array($strict_terms['unrestrictions'][$role_handle]) && ! isset($strict_terms['unrestrictions'][$role_handle][$term_id]) ) )
									$term_role_list []= "" . $term_names[$term_id] . '';
								else
									$term_role_list []= "" . $term_names[$term_id] . '';
							}
							
							$html .= "\r\n"
								. ""
								. "| " . str_replace(' ', ' ', $role_display) . ""
								. ' | ' . implode(', ', $term_role_list) . ''
								. " |  ";
							$style = ( ' class="alternate"' == $style ) ? ' class="rs-backwhite"' : ' class="alternate"';
						}
					}
		
					$html .= '
 ';
					$html .= '
';
					
				} // end foreach content date range
			
			} // end foreach role duration date range	
				
		} // end foreach taxonomy
		
		require_once( dirname(__FILE__).'/object_roles_list.php');
		$html .= scoper_object_roles_list($user, array( 'enforce_duration_limits' => false, 'is_user_profile' => $viewing_own_profile, 'echo' => false ) );
		
		if ( $groups_only ) {
			//if ( empty($rs_blog_roles) && empty($term_role_list) && empty($got_obj_roles) )
			if ( $html ) {
				echo '
';
				echo "
$group_caption
";
				echo $html;
				echo '';
				
				if ( IS_MU_RS )
					echo '
';
			}
				//echo '
' . __('No roles are assigned to this group.', 'scoper'), '
';
		} else {
			echo $html;
			echo '
';
				
				if ( IS_MU_RS && scoper_get_option( 'mu_sitewide_groups' ) ) {
					global $wpdb, $blog_id;
					$blog_ids = scoper_get_col( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id" );
					$orig_blog_id = $blog_id;	
				} else
					$blog_ids = array( '1' );
				foreach ( $blog_ids as $id ) {
					if ( count($blog_ids) > 1 )
						switch_to_blog( $id );
					ScoperProfileUI::display_ui_user_roles($user, true);  //arg: groups only
				}
				
				echo '
';
				
				if ( count($blog_ids) > 1 )
					switch_to_blog( $orig_blog_id );
			}
		}
	}
	
	
	function display_ui_user_groups() {
		if ( ! $all_groups = ScoperAdminLib::get_all_groups(UNFILTERED_RS) )
			return;
		global $current_rs_user, $profileuser;
		$user_id = $profileuser->id;
		
		$editable_ids = ScoperAdminLib::get_all_groups(FILTERED_RS, COL_ID_RS);
		
		if ( $user_id == $current_rs_user->ID )
			$stored_groups = array_keys($current_rs_user->groups);
		else {
			$user = new WP_Scoped_User($user_id, '', array( 'skip_role_merge' => 1 ) );
			$stored_groups = array_keys($user->groups);
		}
		
		// can't manually edit membership of WP Roles groups, other metagroups
		$all_ids = array();
		foreach ( $all_groups as $key => $group ) {
			$all_ids[]= $group->ID;
			
			if ( ! empty($group->meta_id) && ! is_null($group->meta_id) && in_array( $group->ID, $editable_ids ) && ! strpos($group->meta_id, '_editable') ) {
				$editable_ids = array_diff( $editable_ids, array($group->ID) );
				$stored_groups = array_diff( $stored_groups, array($group->ID) );
				unset( $all_groups[$key] );
			}
		}
		
		// avoid incorrect eligible count if orphaned group roles are included in editable_ids
		$editable_ids = array_intersect( $editable_ids, $all_ids );
		
		if ( ! $editable_ids && ! $stored_groups )
			return;
			
		echo "