[LON-CAPA-cvs] cvs: loncom /interface lonpreferences.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 22 Jun 2006 23:30:35 -0000


albertel		Thu Jun 22 19:30:35 2006 EDT

  Modified files:              
    /loncom/interface	lonpreferences.pm 
  Log:
  - from Mark Lucas (BUG#3763) fixes yup the role display order.
  
  
  
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.91 loncom/interface/lonpreferences.pm:1.92
--- loncom/interface/lonpreferences.pm:1.91	Thu Jun 22 19:22:41 2006
+++ loncom/interface/lonpreferences.pm	Thu Jun 22 19:30:33 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.91 2006/06/22 23:22:41 albertel Exp $
+# $Id: lonpreferences.pm,v 1.92 2006/06/22 23:30:33 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -307,6 +307,9 @@
         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().
@@ -315,31 +318,12 @@
 	    &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 ($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().
@@ -347,7 +331,7 @@
 		"<input type=\"checkbox\" $checked name=\"freezeroles\"".
 		" id=\"freezeroles$count\" value=\"$role_key\" /></td>".
 		"<td><label for=\"freezeroles$count\">".
-		"$trole - $tdomain $tother $section</label></td>".
+		"$role_text{$role_key}</label></td>".
 		&Apache::loncommon::end_data_table_row(). "\n";
         }
         $roles_check_list .= "</table>\n";
@@ -372,6 +356,35 @@
 </form>');
 }
 
+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 = &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";
+        }
+        $roletext{$item} = $tdomain." - ".$trole.$tother.$section;
+    }
+    return %roletext;
+}
+
 sub verify_and_change_rolespref {
     my $r = shift;
     my $user       = $env{'user.name'};
@@ -401,20 +414,22 @@
 # 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}='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 (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
-	    $message .= "<br />".&mt('Unfreezing Role: [_1]',$role_key)."\n";
+	    $message .= "<br />".&mt('Unfreezing Role: [_1]',$role_text{$role_key})."\n";
 	    &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
         }
     }
@@ -422,7 +437,7 @@
 # Freeze selected roles
     foreach my $role_key (@freeze_list) {
         if (!$frozen_roles{$role_key}) {
-             $message .= "<br />".&mt('Freezing Role: [_1]',$role_key)."\n";
+             $message .= "<br />".&mt('Freezing Role: [_1]',$role_text{$role_key})."\n";
              &Apache::lonhtmlcommon::store_recent('roles',
                                           $role_key,' ',1);
         }