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

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


albertel		Thu Jun 22 19:22:48 2006 EDT

  Modified files:              
    /loncom/interface	lonpreferences.pm lonhtmlcommon.pm 
    /loncom/auth	lonroles.pm 
  Log:
  - BUG#3763 - reqork role freezing functionality
  
  
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.90 loncom/interface/lonpreferences.pm:1.91
--- loncom/interface/lonpreferences.pm:1.90	Wed Jun 14 15:13:11 2006
+++ loncom/interface/lonpreferences.pm	Thu Jun 22 19:22:41 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.90 2006/06/14 19:13:11 albertel Exp $
+# $Id: lonpreferences.pm,v 1.91 2006/06/22 23:22:41 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -304,6 +304,8 @@
     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'});
         
         $roles_check_list .=
 	    &Apache::loncommon::start_data_table().
@@ -316,7 +318,7 @@
         foreach $role_key (sort(keys(%recent_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
@@ -400,28 +402,29 @@
     my @freeze_list = &Apache::loncommon::get_env_multiple('form.freezeroles');
     my %freeze = ();
     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'});
 
 # 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}))) {
+        if (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
 	    $message .= "<br />".&mt('Unfreezing Role: [_1]',$role_key)."\n";
-	    &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ');
+	    &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
         }
     }
 
 # 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') {
+        if (!$frozen_roles{$role_key}) {
+             $message .= "<br />".&mt('Freezing Role: [_1]',$role_key)."\n";
              &Apache::lonhtmlcommon::store_recent('roles',
-                                          $role_key,'role_frozen');
+                                          $role_key,' ',1);
         }
     }
     $message .= "<hr /><br />\n";
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.135 loncom/interface/lonhtmlcommon.pm:1.136
--- loncom/interface/lonhtmlcommon.pm:1.135	Thu Jun 22 11:53:48 2006
+++ loncom/interface/lonhtmlcommon.pm	Thu Jun 22 19:22:41 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.135 2006/06/22 15:53:48 albertel Exp $
+# $Id: lonhtmlcommon.pm,v 1.136 2006/06/22 23:22:41 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -99,25 +99,31 @@
 }
 
 sub store_recent {
-    my ($area,$name,$value)=@_;
+    my ($area,$name,$value,$freeze)=@_;
     my $file=&recent_filename($area);
     my %recent=&Apache::lonnet::dump($file);
     if (scalar(keys(%recent))>20) {
 # remove oldest value
-	my $oldest=time;
+	my $oldest=time();
 	my $delkey='';
-	foreach (keys %recent) {
-	    my $thistime=(split(/\&/,$recent{$_}))[0];
-	    if ($thistime<$oldest) {
+	foreach my $item (keys(%recent)) {
+	    my $thistime=(split(/\&/,$recent{$item}))[0];
+	    if (($thistime ne "always_include") && ($thistime<$oldest)) {
 		$oldest=$thistime;
-		$delkey=$_;
+		$delkey=$item;
 	    }
 	}
 	&Apache::lonnet::del($file,[$delkey]);
     }
 # store new value
+    my $timestamp;
+    if ($freeze) {
+        $timestamp = "always_include";
+    } else {
+        $timestamp = time();
+    }   
     &Apache::lonnet::put($file,{ $name => 
-				 time.'&'.&escape($value) });
+				 $timestamp.'&'.&escape($value) });
 }
 
 sub remove_recent {
@@ -132,11 +138,11 @@
     my $return="\n<select name='$fieldname'".
 	($event?" onchange='$event'":'').
 	">\n<option value=''>--- ".&mt('Recent')." ---</option>";
-    foreach (sort keys %recent) {
-	unless ($_=~/^error\:/) {
-	    my $escaped = &Apache::loncommon::escape_url($_);
+    foreach my $value (sort(keys(%recent))) {
+	unless ($value =~/^error\:/) {
+	    my $escaped = &Apache::loncommon::escape_url($value);
 	    $return.="\n<option value='$escaped'>".
-		&unescape((split(/\&/,$recent{$_}))[1]).
+		&unescape((split(/\&/,$recent{$value}))[1]).
 		'</option>';
 	}
     }
@@ -149,29 +155,45 @@
     my %recent=&Apache::lonnet::dump(&recent_filename($area));
 
 # Create hash with key as time and recent as value
+# Begin filling return_hash with any 'always_include' option
     my %time_hash = ();
-    my $nfrozen = 0;
-    foreach (keys %recent) {
-        my ($thistime,$thisvalue)=(split(/\&/,$recent{$_}));
-        if (($thisvalue eq 'role_frozen') && ($area='roles')) {
-            $thistime=time+$nfrozen;
-            $nfrozen++;
+    my %return_hash = ();
+    foreach my $item (keys %recent) {
+        my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
+        if ($thistime eq 'always_include') {
+            $return_hash{$item} = &unescape($thisvalue);
+            $n--;
+        } else {
+            $time_hash{$thistime} = $item;
         }
-        $time_hash{$thistime} = $_;
     }
 
 # Sort by decreasing time and return key value pairs
-    my %return_hash = ();
     my $idx = 1;
-    foreach (reverse sort keys %time_hash) {
-       $return_hash{$time_hash{$_}} =
-                  &unescape((split(/\&/,$recent{$time_hash{$_}}))[1]);
+    foreach my $item (reverse(sort(keys(%time_hash)))) {
+       $return_hash{$time_hash{$item}} =
+                  &unescape((split(/\&/,$recent{$time_hash{$item}}))[1]);
        if ($n && ($idx++ >= $n)) {last;}
     }
 
     return %return_hash;
 }
 
+sub get_recent_frozen {
+    my ($area) = @_;
+    my %recent=&Apache::lonnet::dump(&recent_filename($area));
+
+# Create hash with all 'frozen' items
+    my %return_hash = ();
+    foreach my $item (keys(%recent)) {
+        my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
+        if ($thistime eq 'always_include') {
+            $return_hash{$item} = &unescape($thisvalue);
+        }
+    }
+    return %return_hash;
+}
+
 
 
 =pod
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.157 loncom/auth/lonroles.pm:1.158
--- loncom/auth/lonroles.pm:1.157	Wed Jun  7 16:52:16 2006
+++ loncom/auth/lonroles.pm	Thu Jun 22 19:22:47 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.157 2006/06/07 20:52:16 albertel Exp $
+# $Id: lonroles.pm,v 1.158 2006/06/22 23:22:47 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -149,8 +149,10 @@
 
 # store role if recent_role list being kept
                     if ($env{'environment.recentroles'}) {
+                        my %frozen_roles =
+                           &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
 			&Apache::lonhtmlcommon::store_recent('roles',
-							     $trolecode,' ');
+							     $trolecode,' ',$frozen_roles{$trolecode});
                     }