version 1.4, 2003/03/20 19:20:31
|
version 1.5, 2003/03/20 20:58:40
|
Line 47 sub handler {
|
Line 47 sub handler {
|
'<html><head><title>LON-CAPA Custom Distribution Rights</title></head>'); |
'<html><head><title>LON-CAPA Custom Distribution Rights</title></head>'); |
|
|
$r->print(&Apache::loncommon::bodytag('Custom Distribution Rights')); |
$r->print(&Apache::loncommon::bodytag('Custom Distribution Rights')); |
|
$r->rflush(); |
|
|
my $uri=$r->uri; |
my $uri=$r->uri; |
my $fn=&Apache::lonnet::filelocation('',$uri); |
my $fn=&Apache::lonnet::filelocation('',$uri); |
my $contents=''; |
my $contents=''; |
my $constructmode=($uri=~/^\/\~/); |
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 |
|
"<accessrule effect='$effect' realm='$realm' role='$role' />\n"; |
|
} |
|
} |
|
$fh->close; |
|
} |
|
} |
|
# ============================================================ Read and display |
unless ($constructmode) { |
unless ($constructmode) { |
# =========================================== This is not in construction space |
# =========================================== This is not in construction space |
$contents=&Apache::lonnet::getfile($fn); |
$contents=&Apache::lonnet::getfile($fn); |
Line 65 sub handler {
|
Line 126 sub handler {
|
} |
} |
$r->print('<form method="post">'); |
$r->print('<form method="post">'); |
} |
} |
|
unless ($contents=~/\<accessrule/s) { |
|
$contents='<accessrule effect="deny" />'; |
|
} |
my $parser=HTML::LCParser->new(\$contents); |
my $parser=HTML::LCParser->new(\$contents); |
my $token; |
my $token; |
my $rulecounter=0; |
my $rulecounter=0; |
Line 173 ENDSTARTTABLE
|
Line 237 ENDSTARTTABLE
|
$r->print('</table>'); |
$r->print('</table>'); |
# ------------------------------------------------------------ End table output |
# ------------------------------------------------------------ End table output |
if ($constructmode) { |
if ($constructmode) { |
$r->print('<input type="submit" value="Store" /></form>'); |
$r->print('<input type="submit" name="store" value="Store" /></form>'); |
} |
} |
$r->print('</body></html>'); |
$r->print('</body></html>'); |
return OK; |
return OK; |