--- loncom/publisher/lonrights.pm 2003/03/20 19:20:31 1.4
+++ loncom/publisher/lonrights.pm 2003/03/20 20:58:40 1.5
@@ -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.5 2003/03/20 20:58:40 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -47,11 +47,72 @@ 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?
+
+# 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 +126,9 @@ sub handler {
}
$r->print('');
+ $r->print('');
}
$r->print('