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

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 14 Jun 2006 18:59:26 -0000


albertel		Wed Jun 14 14:59:26 2006 EDT

  Modified files:              
    /loncom/interface	lonpreferences.pm loncommon.pm 
  Log:
  - BUG#3786 (from mlucas) can make a role stay in the recent roles list
  
  
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.88 loncom/interface/lonpreferences.pm:1.89
--- loncom/interface/lonpreferences.pm:1.88	Wed Jun 14 14:56:58 2006
+++ loncom/interface/lonpreferences.pm	Wed Jun 14 14:59:25 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.88 2006/06/14 18:56:58 albertel Exp $
+# $Id: lonpreferences.pm,v 1.89 2006/06/14 18:59:25 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -298,25 +298,76 @@
 	$options .= "<option $select>$i</option>\n";
     }
 
-    $r->print(<<ENDSCREEN);
-<p>Some LON-CAPA users have a long list of roles. The Recent Roles Hotlist
-feature keeps track of the last N roles which have been
-visited and places a table of these at the top of the roles page.
-People with very few roles should leave this feature disabled.
-</p>
+# Get list of recent roles and display with checkbox in front
+    my $roles_check_list = '';
+    my $role_key='';
+    if ($env{'environment.recentroles'}) {
+        my %recent_roles =
+               &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
+        
+        $roles_check_list .=
+	    &Apache::loncommon::start_data_table().
+	    &Apache::loncommon::start_data_table_header_row().
+	    "<th>".&mt('Freeze Role')."</th>".
+	    "<th>".&mt('Role')."</td>".
+	    &Apache::loncommon::end_data_table_header_row().
+	    "\n";
+	my $count;
+        foreach $role_key (sort(keys(%recent_roles))) {
+            my $checked = "";
+            my $value = $recent_roles{$role_key};
+            if ($value eq 'role_frozen') {
+                $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";
+            }
 
-<form name="prefs" action="/adm/preferences" method="post">
+            my $section="";
+	    if ($tsection) {
+               $section = " - Section/Group: $tsection";
+            }
+	    $count++;
+            $roles_check_list .=
+		&Apache::loncommon::start_data_table_row().
+		'<td class="LC_table_cell_checkbox">'.
+		"<input type=\"checkbox\" $checked name=\"freezeroles\"".
+		" id=\"freezeroles$count\" value=\"$role_key\" /></td>".
+		"<td><label for=\"freezeroles$count\">".
+		"$trole - $tdomain $tother $section</label></td>".
+		&Apache::loncommon::end_data_table_row(). "\n";
+        }
+        $roles_check_list .= "</table>\n";
+    }
+
+    $r->print('
+<p>'.&mt('Some LON-CAPA users have a long list of roles. The Recent Roles Hotlist feature keeps track of the last N roles which have been visited and places a table of these at the top of the roles page. People with very few roles should leave this feature disabled.').'
+</p>
+<form name="prefs" action="/adm/preferences" method="POST">
 <input type="hidden" name="action" value="verify_and_change_rolespref" />
-<br /><label>Enable Recent Roles Hotlist:
-<input type="checkbox" $checked name="recentroles" value="true" /></label>
-<br />Number of roles in Hotlist:
+<br /><label>'.&mt('Enable Recent Roles Hotlist:').'
+<input type="checkbox" '.$checked.' name="recentroles" value="true" /></label>
+<br />'.&mt('Number of roles in Hotlist:').'
 <select name="recentrolesn" size="1">
-$options
+'.$options.'
 </select>
+<p>'.&mt('This list below can be used to <q>freeze</q> roles on your screen. Those marked as frozen will not be removed from the list, even if they have not been used recently.').'
+</p>
+'.$roles_check_list.'
 <br />
-<input type="submit" value="Change" />
-</form>
-ENDSCREEN
+<input type="submit" value="'.&mt('Change').'" />
+</form>');
 }
 
 sub verify_and_change_rolespref {
@@ -326,23 +377,54 @@
 # Recent Roles Hotlist Flag
     my $hotlist_flag  = $env{'form.recentroles'};
     my $hotlist_n  = $env{'form.recentrolesn'};
-    my $message='';
+    my $message='<hr />';
     if ($hotlist_flag) {
         &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
         &Apache::lonnet::appenv('environment.recentroles' => $hotlist_flag);
-        $message='Recent Roles Hotlist is Enabled';
+        $message=&mt('Recent Roles Hotlist is Enabled');
     } else {
         &Apache::lonnet::del('environment',['recentroles']);
         &Apache::lonnet::delenv('environment\.recentroles');
-        $message='Recent Roles Hotlist is Disabled';
+        $message=&mt('Recent Roles Hotlist is Disabled');
     }
     if ($hotlist_n) {
         &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
         &Apache::lonnet::appenv('environment.recentrolesn' => $hotlist_n);
         if ($hotlist_flag) {
-            $message.="<br />Display $hotlist_n Most Recent Roles\n";
+            $message.="<br />".&mt('Display [_1]$hotlist_n 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 = ();
+    foreach my $key (@freeze_list) {
+        $freeze{$key}='role_frozen';
+    }
+    
+    my %recent_roles =
+        &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
+
+# 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 .= "<br />".&mt('Unfreezing Role: [_1]',$role_key)."\n";
+	    &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ');
+        }
+    }
+
+# Freeze selected roles
+    foreach my $role_key (@freeze_list) {
+        $message .= "<br />".&mt('Freezing Role: [_1]',$role_key)."\n";
+        if ($recent_roles{$role_key} ne 'role_frozen') {
+             &Apache::lonhtmlcommon::store_recent('roles',
+                                          $role_key,'role_frozen');
         }
     }
+    $message .= "<hr /><br />\n";
 
     $r->print(<<ENDRPSCREEN);
 $message
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.382 loncom/interface/loncommon.pm:1.383
--- loncom/interface/loncommon.pm:1.382	Mon Jun 12 18:30:04 2006
+++ loncom/interface/loncommon.pm	Wed Jun 14 14:59:25 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.382 2006/06/12 22:30:04 albertel Exp $
+# $Id: loncommon.pm,v 1.383 2006/06/14 18:59:25 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3229,6 +3229,10 @@
   font-size: larger;
   text-align: right;
 }
+td.LC_table_cell_checkbox {
+  text-align: center;
+}
+
 .LC_menubuttons_inline_text {
   color: $font;
   font-family: $sans;