--- loncom/publisher/lonrights.pm 2006/04/06 22:15:19 1.18
+++ loncom/publisher/lonrights.pm 2012/11/09 15:29:19 1.34
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to show and edit custom distribution rights
#
-# $Id: lonrights.pm,v 1.18 2006/04/06 22:15:19 albertel Exp $
+# $Id: lonrights.pm,v 1.34 2012/11/09 15:29:19 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -55,101 +55,118 @@ sub handler {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
- my $js = &Apache::loncommon::coursebrowser_javascript();
-
- $r->print(&Apache::loncommon::start_page('Custom Distribution Rights',$js));
+ # Breadcrumbs
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb({
+ 'text' => 'Construction Space',
+ 'href' => &Apache::loncommon::authorspace($r->uri),
+ });
+ &Apache::lonhtmlcommon::add_breadcrumb({
+ 'text' => 'Custom Rights Editor',
+ 'title' => 'Custom Distribution Rights Editor',
+ 'href' => '',});
+
+ my $js = &Apache::loncommon::coursebrowser_javascript().
+ &Apache::loncommon::studentbrowser_javascript();
+ # Breadcrumbs are included by &start_page
+ $r->print(&Apache::loncommon::start_page('Custom Distribution Rights',$js)
+ .&Apache::loncommon::head_subbox(
+ &Apache::loncommon::CSTR_pageheader())
+ );
$r->rflush();
my $uri=$r->uri;
my $fn=&Apache::lonnet::filelocation('',$uri);
my $contents='';
- my $constructmode=($uri=~/^\/\~/);
+ my $constructmode=($uri=~ m{^/priv/});
# ============================================================ Modify and store
- if ($constructmode) {
- if ($env{'form.store'}) {
- my @newrules=();
- undef @newrules;
+ if ($constructmode && $env{'form.store'}) {
+
+ my @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>1)) {
- 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';
- }
+ foreach my $key (keys(%env)) {
+ next if ($key!~/^form\.effect\_(\d+)$/);
+ my $number=$1;
+ my %rulehash;
+ foreach my $action ('effect','type','domain','course','section','role') {
+ $rulehash{$action}=$env{'form.'.$action.'_'.$number};
+ }
+ if ($rulehash{'type'} !~ /^(user|course)$/) {
+ $rulehash{'type'} = 'course';
+ }
+ if ($rulehash{'type'} eq 'user') {
+ $rulehash{'section'}='';
+ $rulehash{'role'}='';
+ }
+ 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'} =
+ &LONCAPA::clean_domain($rulehash{'domain'});
+ if ($rulehash{'type'} eq 'course') {
+ $rulehash{'course'} =
+ &LONCAPA::clean_courseid($rulehash{'course'});
+ } else {
+ $rulehash{'course'} =
+ &LONCAPA::clean_username($rulehash{'course'});
+ }
+ $rulehash{'section'}=~s/\W//g;
+ if (!$rulehash{'domain'}) {
+ $rulehash{'domain'}=$env{'user.domain'};
+ }
+ my $realm='';
+ my $separator = ($rulehash{'type'} eq 'course') ? '_' : '/';
+ if ($number) {
+ $realm=$rulehash{'domain'};
+ if ($rulehash{'course'}) {
+ $realm.=$separator.$rulehash{'course'};
}
- }
-
+ if ($rulehash{'section'}) {
+ $realm.=$separator.$rulehash{'section'};
+ }
+ }
+ $newrules[$number]=$rulehash{'effect'}.':'.
+ $realm.':'.$rulehash{'role'}.':'.$rulehash{'type'};
+ }
+# edit actions?
+ foreach my $key (keys(%env)) {
+ next if ($key!~/^form\.action\_(\d+)$/);
+ my $number=$1;
+ if ($env{$key} eq 'delete') { splice(@newrules,$number,1); }
+ if (($env{$key} eq 'moveup') && ($number>1)) {
+ @newrules[$number-1,$number] = @newrules[$number,$number-1];
+ }
+ if (($env{$key} eq 'movedown') && ($number<$#newrules)) {
+ @newrules[$number+1,$number] = @newrules[$number,$number+1];
+ }
+ if ($env{$key} eq 'insertabove') {
+ splice(@newrules,$number,0,'deny');
+ }
+ if ($env{$key} eq 'insertbelow') {
+ splice(@newrules,$number+1,0,'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
- "