--- loncom/interface/lonpreferences.pm 2006/06/14 18:59:25 1.89
+++ loncom/interface/lonpreferences.pm 2006/06/26 18:56:50 1.93
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Preferences
#
-# $Id: lonpreferences.pm,v 1.89 2006/06/14 18:59:25 albertel Exp $
+# $Id: lonpreferences.pm,v 1.93 2006/06/26 18:56:50 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -304,7 +304,12 @@ sub rolesprefchanger {
if ($env{'environment.recentroles'}) {
my %recent_roles =
&Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
+ my %frozen_roles =
+ &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
+ my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
+ my @sorted_roles = sort {$role_text{$a} cmp $role_text{$b}} keys(%role_text);
+
$roles_check_list .=
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row().
@@ -313,31 +318,12 @@ sub rolesprefchanger {
&Apache::loncommon::end_data_table_header_row().
"\n";
my $count;
- foreach $role_key (sort(keys(%recent_roles))) {
+ foreach $role_key (@sorted_roles) {
my $checked = "";
my $value = $recent_roles{$role_key};
- if ($value eq 'role_frozen') {
+ if ($frozen_roles{$role_key}) {
$checked = "checked=\"checked\"";
}
-# get course information
- my ($role,$rest) = split(/\./, $role_key);
- my $trole = &Apache::lonnet::plaintext($role);
- my ($tdomain,$other,$tsection)=
- split(/\//,Apache::lonnet::declutter($rest));
- my $tother = '-';
- if ($role =~ /cc|st|in|ta/ ) {
- my %newhash=&Apache::lonnet::coursedescription($tdomain."_".$other);
- $tother = " - ".$newhash{'description'};
- } elsif ($role =~ /dc/) {
- $tother = "";
- } else {
- $tother = " - $other";
- }
-
- my $section="";
- if ($tsection) {
- $section = " - Section/Group: $tsection";
- }
$count++;
$roles_check_list .=
&Apache::loncommon::start_data_table_row().
@@ -345,7 +331,7 @@ sub rolesprefchanger {
"".
"
| ".
+ "$role_text{$role_key}".
&Apache::loncommon::end_data_table_row(). "\n";
}
$roles_check_list .= "\n";
@@ -370,6 +356,36 @@ sub rolesprefchanger {
');
}
+sub rolespref_get_role_text {
+# Get a line of text for each role
+ my ($roles) = @_;
+ my %roletext = ();
+
+ foreach my $item (@$roles) {
+# get course information
+ my ($role,$rest) = split(/\./, $item);
+ my $trole = "";
+ $trole = &Apache::lonnet::plaintext($role);
+ my ($tdomain,$other,$tsection)= split(/\//,Apache::lonnet::declutter($rest));
+ my $tother = '-';
+ if ($role =~ /^(cc|st|in|ta|ep|cr)/ ) {
+ my %newhash=&Apache::lonnet::coursedescription($tdomain."_".$other);
+ $tother = " - ".$newhash{'description'};
+ } elsif ($role =~ /dc/) {
+ $tother = "";
+ } else {
+ $tother = " - $other";
+ }
+
+ my $section="";
+ if ($tsection) {
+ $section = " - Section/Group: $tsection";
+ }
+ $roletext{$item} = $tdomain." - ".$trole.$tother.$section;
+ }
+ return %roletext;
+}
+
sub verify_and_change_rolespref {
my $r = shift;
my $user = $env{'user.name'};
@@ -391,37 +407,40 @@ sub verify_and_change_rolespref {
&Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
&Apache::lonnet::appenv('environment.recentrolesn' => $hotlist_n);
if ($hotlist_flag) {
- $message.="
".&mt('Display [_1]$hotlist_n Most Recent Roles',
- $hotlist_n)."\n";
+ $message.="
".
+ &mt('Display [_1] Most Recent Roles',$hotlist_n)."\n";
}
}
# Get list of froze roles and list of recent roles
my @freeze_list = &Apache::loncommon::get_env_multiple('form.freezeroles');
my %freeze = ();
+ my %roletext = ();
+
foreach my $key (@freeze_list) {
- $freeze{$key}='role_frozen';
+ $freeze{$key}='1';
}
-
+
my %recent_roles =
&Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
+ my %frozen_roles =
+ &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
+ my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
# Unset any roles that were previously frozen but aren't in list
-
foreach my $role_key (sort(keys(%recent_roles))) {
- if (($recent_roles{$role_key} eq 'role_frozen') &&
- (!exists($freeze{$role_key}))) {
- $message .= "
".&mt('Unfreezing Role: [_1]',$role_key)."\n";
- &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ');
+ if (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
+ $message .= "
".&mt('Unfreezing Role: [_1]',$role_text{$role_key})."\n";
+ &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
}
}
# Freeze selected roles
foreach my $role_key (@freeze_list) {
- $message .= "
".&mt('Freezing Role: [_1]',$role_key)."\n";
- if ($recent_roles{$role_key} ne 'role_frozen') {
+ if (!$frozen_roles{$role_key}) {
+ $message .= "
".&mt('Freezing Role: [_1]',$role_text{$role_key})."\n";
&Apache::lonhtmlcommon::store_recent('roles',
- $role_key,'role_frozen');
+ $role_key,' ',1);
}
}
$message .= "
\n";