[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

banghart lon-capa-cvs@mail.lon-capa.org
Thu, 04 Nov 2004 23:43:08 -0000


banghart		Thu Nov  4 18:43:08 2004 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  	Added get_marked_as_readonly sub. Slightly tested, not yet
  	integrated.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.560 loncom/lonnet/perl/lonnet.pm:1.561
--- loncom/lonnet/perl/lonnet.pm:1.560	Wed Nov  3 16:12:12 2004
+++ loncom/lonnet/perl/lonnet.pm	Thu Nov  4 18:43:07 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.560 2004/11/03 21:12:12 banghart Exp $
+# $Id: lonnet.pm,v 1.561 2004/11/04 23:43:07 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3787,19 +3787,42 @@
     my ($domain,$user,$files,$what) = @_;
     my %current_permissions = &Apache::lonnet::dump('file_permissions',$domain,$user);
     foreach my $file (@{$files}) {
-        push (@{$current_permissions{$file}},$what);
+        push(@{$current_permissions{$file}},$what);
     }
     &Apache::lonnet::put('file_permissions',\%current_permissions,$domain,$user);
     return;
 }
 
+#--------------------------------------------------------------Get Marked as Read Only
+
+sub get_marked_as_readonly {
+    my ($domain,$user,$what) = @_;
+    my %current_permissions = &Apache::lonnet::dump('file_permissions',$domain,$user);
+    my @readonly_files = [];
+    while ((my $file_name, my $value) = each %current_permissions) {
+        if (ref($value) eq "ARRAY"){
+            foreach my $stored_what (@{$value}) {
+                if ($stored_what eq $what) {
+                    push(@readonly_files, $file_name);
+                }
+            }
+        } 
+    }
+    return @readonly_files;
+}
+
 # ------------------------------------------------------------ Unmark as Read Only
 
 sub unmark_as_readonly {
-    my ($domain,$user,$file,$what) = @_;
-    my $current_permissions = &Apache::lonnet::dump('file_permissions',$domain,$user);
-    
-    &Apache::lonnet::put('file_permissions',$current_permissions,$domain,$user);
+    # unmarks all files locked by $what 
+    # for portfolio submissions, $what contains $crsid and $symb
+    my ($domain,$user,$what) = @_;
+    my %current_permissions = &Apache::lonnet::dump('file_permissions',$domain,$user);
+    my @readonly_files = &Apache::lonnet::get_marked_as_readonly($domain,$user,$what);
+    foreach my $file(@readonly_files){
+        
+    }
+    &Apache::lonnet::put('file_permissions',\%current_permissions,$domain,$user);
     return;
 }