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

www lon-capa-cvs@mail.lon-capa.org
Thu, 20 Mar 2003 16:17:37 -0000


www		Thu Mar 20 11:17:37 2003 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
    /loncom/publisher	lonrights.pm 
  Log:
  * New routine in loncommon for very simple select forms
  * Continued work on custom rights viewer/editor
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.87 loncom/interface/loncommon.pm:1.88
--- loncom/interface/loncommon.pm:1.87	Mon Mar 10 15:21:45 2003
+++ loncom/interface/loncommon.pm	Thu Mar 20 11:17:37 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.87 2003/03/10 20:21:45 matthew Exp $
+# $Id: loncommon.pm,v 1.88 2003/03/20 16:17:37 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -596,6 +596,32 @@
     }
     return @domains;
 }
+
+#-------------------------------------------
+
+=pod
+
+=item select_form($defdom,$name,%hash)
+
+Returns a string containing a <select name='$name' size='1'> form to 
+allow a user to select options from a hash option_name => displayed text.  
+See lonrights.pm for an example invocation and use.
+
+=cut
+
+#-------------------------------------------
+sub select_form {
+    my ($def,$name,%hash) = @_;
+    my $selectform = "<select name=\"$name\" size=\"1\">\n";
+    foreach (keys %hash) {
+        $selectform.="<option value=\"$_\" ".
+            ($_ eq $def ? 'selected' : '').
+                ">".$hash{$_}."</option>\n";
+    }
+    $selectform.="</select>";
+    return $selectform;
+}
+
 
 #-------------------------------------------
 
Index: loncom/publisher/lonrights.pm
diff -u loncom/publisher/lonrights.pm:1.2 loncom/publisher/lonrights.pm:1.3
--- loncom/publisher/lonrights.pm:1.2	Wed Mar 19 17:14:23 2003
+++ loncom/publisher/lonrights.pm	Thu Mar 20 11:17:37 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to show and edit custom distribution rights
 #
-# $Id: lonrights.pm,v 1.2 2003/03/19 22:14:23 www Exp $
+# $Id: lonrights.pm,v 1.3 2003/03/20 16:17:37 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -43,7 +43,8 @@
   $r->content_type('text/html');
   $r->send_http_header;
 
-  $r->print('<html><head><title>LON-CAPA Custom Distribution Rights</title></head>');
+  $r->print(
+     '<html><head><title>LON-CAPA Custom Distribution Rights</title></head>');
 
   $r->print(&Apache::loncommon::bodytag('Custom Distribution Rights'));
 
@@ -62,16 +63,74 @@
           $contents=join('',<$fh>);
           $fh->close();
       }
+      $r->print('<form method="post">');
   }
   my $parser=HTML::LCParser->new(\$contents);
   my $token;
+  my $rulecounter=0;
+# ---------------------------------------------------------- Start table output
+  $r->print('<table border="2">');
+# --------------------------------------------------------------------- Default
+# Fast forward to first rule
+  $token=$parser->get_token;
+  while ($token->[1] ne 'accessrule') { $token=$parser->get_token; }
+# print default
+  $r->print('<tr><td>&nbsp;</td><td>');
+  if ($constructmode) {
+      $r->print(&Apache::loncommon::select_form
+                                 ($token->[2]->{'effect'},'effect_0',
+                                   ('allow' => 'allow',
+                                    'deny'  => 'deny')));
+  } else {
+      $r->print($token->[2]->{'effect'});
+  }
+  $r->print('</td><td colspan="2">Default');
+  if (($token->[2]->{'realm'}) || ($token->[2]->{'role'})) {
+      $r->print(' - <font color="red">Error! No default set.</font>');
+  }
+  $r->print('</td></tr>');
+# Additional roles
   while ($token=$parser->get_token) {
       if (($token->[0] eq 'S') && ($token->[1] eq 'accessrule')) {
-         $r->print('<br />'.
-                   $token->[2]->{'effect'}.': '.
-                   $token->[2]->{'realm'}.' '.
-                   $token->[2]->{'role'});
+          $rulecounter++;
+	  $r->print('<tr><td>');
+# inset, delete, etc
+          $r->print('</td><td>');
+# effect
+          if ($constructmode) {
+             $r->print(&Apache::loncommon::select_form
+                                 ($token->[2]->{'effect'},
+                                  'effect_'.$rulecounter,
+                                   ('allow' => 'allow',
+                                    'deny'  => 'deny')));
+          } else {
+             $r->print($token->[2]->{'effect'});
+          }
+	  $r->print('</td><td>');
+# realm
+          my $realm=$token->[2]->{'realm'};
+          $realm=~s/^\W//;
+          my ($rdom,$rcourse,$rsec)=split(/(\/|\_)/,$realm);
+          if ($constructmode) {
+              $r->print(&Apache::loncommon::select_dom_form($rdom,
+                                                      'domain_'.$rulecounter));
+          } else {
+              $r->print($token->[2]->{'realm'});
+          }
+          $r->print('</td><td>');
+# role
+          if ($constructmode) {
+          } else {
+              $r->print($token->[2]->{'role'});
+          }
+# close row
+          $r->print('</td></tr>');
      }                                       
+  }
+  $r->print('</table>');
+# ------------------------------------------------------------ End table output
+  if ($constructmode) { 
+     $r->print('<input type="submit" value="Store" /></form>'); 
   }
   $r->print('</body></html>');
   return OK;