--- loncom/publisher/lonrights.pm 2003/03/20 19:20:31 1.4
+++ loncom/publisher/lonrights.pm 2003/03/20 21:47:57 1.6
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to show and edit custom distribution rights
#
-# $Id: lonrights.pm,v 1.4 2003/03/20 19:20:31 www Exp $
+# $Id: lonrights.pm,v 1.6 2003/03/20 21:47:57 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -47,11 +47,100 @@ sub handler {
'
LON-CAPA Custom Distribution Rights');
$r->print(&Apache::loncommon::bodytag('Custom Distribution Rights'));
+ $r->rflush();
my $uri=$r->uri;
my $fn=&Apache::lonnet::filelocation('',$uri);
my $contents='';
my $constructmode=($uri=~/^\/\~/);
+
+# ============================================================ Modify and store
+ if ($constructmode) {
+ if ($ENV{'form.store'}) {
+ my @newrules=();
+ undef @newrules;
+# read rules from form
+ foreach (keys %ENV) {
+ if ($_=~/^form\.effect\_(\d+)$/) {
+ my $number=$1;
+ my %rulehash=();
+ foreach ('effect','domain','course','section','role') {
+ $rulehash{$_}=$ENV{'form.'.$_.'_'.$number};
+ }
+ if ($rulehash{'role'} eq 'au') {
+ $rulehash{'course'}='';
+ $rulehash{'section'}='';
+ }
+ if ($rulehash{'role'} eq 'cc') {
+ $rulehash{'section'}='';
+ }
+ unless (($rulehash{'effect'} eq 'deny') ||
+ ($rulehash{'effect'} eq 'allow')) {
+ $rulehash{'effect'}='deny';
+ }
+ $rulehash{'domain'}=~s/\W//g;
+ $rulehash{'course'}=~s/\W//g;
+ $rulehash{'section'}=~s/\W//g;
+ unless ($rulehash{'domain'}) {
+ $rulehash{'domain'}=$ENV{'user.domain'};
+ }
+ my $realm='';
+ if ($number) {
+ $realm=$rulehash{'domain'};
+ if ($rulehash{'course'}) {
+ $realm.='_'.$rulehash{'course'};
+ }
+ if ($rulehash{'section'}) {
+ $realm.='_'.$rulehash{'section'};
+ }
+ }
+ $newrules[$number]=$rulehash{'effect'}.':'.
+ $realm.':'.$rulehash{'role'};
+ }
+ }
+# edit actions?
+ foreach (keys %ENV) {
+ if ($_=~/^form\.action\_(\d+)$/) {
+ my $number=$1;
+ if ($ENV{$_} eq 'delete') { $newrules[$number]=''; }
+ if (($ENV{$_} eq 'moveup') && ($number>2)) {
+ my $buffer=$newrules[$number];
+ $newrules[$number]=$newrules[$number-1];
+ $newrules[$number-1]=$buffer;
+ }
+ if (($ENV{$_} eq 'movedown') && ($number<$#newrules)) {
+ my $buffer=$newrules[$number];
+ $newrules[$number]=$newrules[$number+1];
+ $newrules[$number+1]=$buffer;
+ }
+ if ($ENV{$_} eq 'insertabove') {
+ for (my $i=$#newrules;$i>=$number;$i--) {
+ $newrules[$i+1]=$newrules[$i];
+ }
+ $newrules[$number]='deny';
+ }
+ if ($ENV{$_} eq 'insertbelow') {
+ for (my $i=$#newrules;$i>$number;$i--) {
+ $newrules[$i+1]=$newrules[$i];
+ }
+ $newrules[$number+1]='deny';
+ }
+ }
+ }
+
+# store file
+ my $fh=Apache::File->new('>'.$fn);
+ foreach (my $i=0;$i<=$#newrules;$i++) {
+ if ($newrules[$i]) {
+ my ($effect,$realm,$role)=split(/\:/,$newrules[$i]);
+ print $fh
+ "\n";
+ }
+ }
+ $fh->close;
+ }
+ }
+# ============================================================ Read and display
unless ($constructmode) {
# =========================================== This is not in construction space
$contents=&Apache::lonnet::getfile($fn);
@@ -65,6 +154,9 @@ sub handler {
}
$r->print('