[LON-CAPA-cvs] cvs: loncom /publisher lonrights.pm

www lon-capa-cvs@mail.lon-capa.org
Thu, 20 Mar 2003 20:58:40 -0000


www		Thu Mar 20 15:58:40 2003 EDT

  Modified files:              
    /loncom/publisher	lonrights.pm 
  Log:
  Can now store, but not yet do "insert", etc
  
  
Index: loncom/publisher/lonrights.pm
diff -u loncom/publisher/lonrights.pm:1.4 loncom/publisher/lonrights.pm:1.5
--- loncom/publisher/lonrights.pm:1.4	Thu Mar 20 14:20:31 2003
+++ loncom/publisher/lonrights.pm	Thu Mar 20 15:58:40 2003
@@ -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 @@
      '<html><head><title>LON-CAPA Custom Distribution Rights</title></head>');
 
   $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
+	       "<accessrule effect='$effect' realm='$realm' role='$role' />\n";
+	     }
+          }
+          $fh->close;
+      }
+  }
+# ============================================================ Read and display
   unless ($constructmode) { 
 # =========================================== This is not in construction space
       $contents=&Apache::lonnet::getfile($fn);
@@ -65,6 +126,9 @@
       }
       $r->print('<form method="post">');
   }
+  unless ($contents=~/\<accessrule/s) {
+      $contents='<accessrule effect="deny" />';
+  }
   my $parser=HTML::LCParser->new(\$contents);
   my $token;
   my $rulecounter=0;
@@ -173,7 +237,7 @@
   $r->print('</table>');
 # ------------------------------------------------------------ End table output
   if ($constructmode) { 
-     $r->print('<input type="submit" value="Store" /></form>'); 
+     $r->print('<input type="submit" name="store" value="Store" /></form>'); 
   }
   $r->print('</body></html>');
   return OK;