--- loncom/lonnet/perl/lonnet.pm 2006/06/05 20:09:19 1.744 +++ loncom/lonnet/perl/lonnet.pm 2006/06/07 21:15:10 1.746 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.744 2006/06/05 20:09:19 albertel Exp $ +# $Id: lonnet.pm,v 1.746 2006/06/07 21:15:10 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -4555,9 +4555,15 @@ sub is_locked { $env{'user.domain'},$env{'user.name'}); my ($tmp)=keys(%locked); if ($tmp=~/^error:/) { undef(%locked); } - + if (ref($locked{$file_name}) eq 'ARRAY') { - $is_locked = 'true'; + $is_locked = 'false'; + foreach my $entry (@{$locked{$file_name}}) { + if (ref($entry) eq 'ARRAY') { + $is_locked = 'true'; + last; + } + } } else { $is_locked = 'false'; } @@ -4646,48 +4652,113 @@ sub files_not_in_path { return (@return_files); } -#--------------------------------------------------------------Get Marked as Read Only +#----------------------------------------------Get portfolio file permissions - -sub get_marked_as_readonly { - my ($domain,$user,$what) = @_; +sub get_portfile_permissions { + # returns a reference to a hash containing contents of file_permissions.db + my ($domain,$user) = @_; my %current_permissions = &dump('file_permissions',$domain,$user); my ($tmp)=keys(%current_permissions); if ($tmp=~/^error:/) { undef(%current_permissions); } + return \%current_permissions; +} + +#---------------------------------------------Get portfolio file access controls + +sub get_access_controls { + # returns a hash containing access control information retrieved from + # file_permissions.db. The hash contains key=value pairs where key is + # the control type, end date and start date, in the form type_end_start + # and value is a string containing access control settings (in XML), + # + # Internally access_controls are stored in file_permissions.db in an + # array of arrays and a hash, where arrays are locks set when a portfolio + # file has been uploaded to an essayresponse problem in a course, and + # the hash contains other data. Two keys are currently defined in the hash: + # access and accesscount. The value for accesscount is a scalar - equal to + # the next number to use as the first part of an access control key + # when defining a new control. The value for access is an anonymous hash + # where keys are access controls and values are settings. + # + my ($current_permissions,$group,$file) = @_; + my @access_checks = (); + my %access; + if (defined($file)) { + @access_checks = ($file); + } else { + @access_checks = keys(%{$current_permissions}); + } + foreach my $file_name (@access_checks) { + my $value = $$current_permissions{$file_name}; + if (defined($group)) { + if ($file_name !~ m-^\Q$group\E/-) { + next; + } + } + if (ref($value) eq "ARRAY") { + foreach my $stored_what (@{$value}) { + if (ref($stored_what) eq 'HASH') { + $access{$file_name} = $$stored_what{'access'}; + } + } + } + } + return %access; +} + +#------------------------------------------------------Get Marked as Read Only + +sub get_marked_as_readonly { + my ($domain,$user,$what,$group) = @_; + my $current_permissions = &get_portfile_permissions($domain,$user); my @readonly_files; my $cmp1=$what; if (ref($what)) { $cmp1=join('',@{$what}) }; - while (my ($file_name,$value) = each(%current_permissions)) { + while (my ($file_name,$value) = each(%{$current_permissions})) { + if (defined($group)) { + if ($file_name !~ m-^\Q$group\E/-) { + next; + } + } if (ref($value) eq "ARRAY"){ foreach my $stored_what (@{$value}) { my $cmp2=$stored_what; - if (ref($stored_what)) { $cmp2=join('',@{$stored_what}) }; + if (ref($stored_what eq 'HASH')) { + next; + } elsif (ref($stored_what eq 'ARRAY')) { + $cmp2=join('',@{$stored_what}); + } if ($cmp1 eq $cmp2) { push(@readonly_files, $file_name); + last; } elsif (!defined($what)) { push(@readonly_files, $file_name); + last; } } - } + } } return @readonly_files; } #-----------------------------------------------------------Get Marked as Read Only Hash sub get_marked_as_readonly_hash { - my ($domain,$user,$what) = @_; - my %current_permissions = &dump('file_permissions',$domain,$user); - my ($tmp)=keys(%current_permissions); - if ($tmp=~/^error:/) { undef(%current_permissions); } - + my ($current_permissions,$group,$what) = @_; my %readonly_files; - while (my ($file_name,$value) = each(%current_permissions)) { + while (my ($file_name,$value) = each(%{$current_permissions})) { + if (defined($group)) { + if ($file_name !~ m-^\Q$group\E/-) { + next; + } + } if (ref($value) eq "ARRAY"){ foreach my $stored_what (@{$value}) { - if ($stored_what eq $what) { - $readonly_files{$file_name} = 'locked'; - } elsif (!defined($what)) { - $readonly_files{$file_name} = 'locked'; + if (ref($stored_what) eq 'ARRAY') { + if ($stored_what eq $what) { + $readonly_files{$file_name} = 'locked'; + } elsif (!defined($what)) { + $readonly_files{$file_name} = 'locked'; + } } } } @@ -4699,13 +4770,13 @@ sub get_marked_as_readonly_hash { sub unmark_as_readonly { # unmarks $file_name (if $file_name is defined), or all files locked by $what # for portfolio submissions, $what contains [$symb,$crsid] - my ($domain,$user,$what,$file_name) = @_; + my ($domain,$user,$what,$file_name,$group) = @_; my $symb_crs = $what; if (ref($what)) { $symb_crs=join('',@$what); } - my %current_permissions = &dump('file_permissions',$domain,$user); + my %current_permissions = &dump('file_permissions',$domain,$user,$group); my ($tmp)=keys(%current_permissions); if ($tmp=~/^error:/) { undef(%current_permissions); } - my @readonly_files = &get_marked_as_readonly($domain,$user,$what); + my @readonly_files = &get_marked_as_readonly($domain,$user,$what,$group); foreach my $file (@readonly_files) { if (defined($file_name) && ($file_name ne $file)) { next; } my $current_locks = $current_permissions{$file}; @@ -4714,9 +4785,13 @@ sub unmark_as_readonly { if (ref($current_locks) eq "ARRAY"){ foreach my $locker (@{$current_locks}) { my $compare=$locker; - if (ref($locker)) { $compare=join('',@{$locker}) }; - if ($compare ne $symb_crs) { - push(@new_locks, $locker); + if (!ref($locker) eq 'ARRAY') { + push(@new_locks,$locker); + } else { + $compare=join('',@{$locker}); + if ($compare ne $symb_crs) { + push(@new_locks, $locker); + } } } if (scalar(@new_locks) > 0) {