File:  [LON-CAPA] / loncom / publisher / lonrights.pm
Revision 1.3: download - view: text, annotated - select for diffs
Thu Mar 20 16:17:37 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
* New routine in loncommon for very simple select forms
* Continued work on custom rights viewer/editor

    1: # The LearningOnline Network with CAPA
    2: # Handler to show and edit custom distribution rights
    3: #
    4: # $Id: lonrights.pm,v 1.3 2003/03/20 16:17:37 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: #
   29: ###
   30: 
   31: package Apache::lonrights;
   32: 
   33: use strict;
   34: use Apache::Constants qw(:common :http);
   35: use Apache::lonnet();
   36: use Apache::loncommon();
   37: use HTML::LCParser;
   38: use Apache::File;
   39: 
   40: sub handler {
   41: 
   42:   my $r=shift;
   43:   $r->content_type('text/html');
   44:   $r->send_http_header;
   45: 
   46:   $r->print(
   47:      '<html><head><title>LON-CAPA Custom Distribution Rights</title></head>');
   48: 
   49:   $r->print(&Apache::loncommon::bodytag('Custom Distribution Rights'));
   50: 
   51:   my $uri=$r->uri;
   52:   my $fn=&Apache::lonnet::filelocation('',$uri);
   53:   my $contents='';
   54:   my $constructmode=($uri=~/^\/\~/);
   55:   unless ($constructmode) { 
   56: # =========================================== This is not in construction space
   57:       $contents=&Apache::lonnet::getfile($fn);
   58:       if ($contents==-1) { $contents=''; }
   59:   } else {
   60: # =============================================== This is in construction space
   61:       if (-e $fn) {
   62: 	  my $fh=Apache::File->new($fn);
   63:           $contents=join('',<$fh>);
   64:           $fh->close();
   65:       }
   66:       $r->print('<form method="post">');
   67:   }
   68:   my $parser=HTML::LCParser->new(\$contents);
   69:   my $token;
   70:   my $rulecounter=0;
   71: # ---------------------------------------------------------- Start table output
   72:   $r->print('<table border="2">');
   73: # --------------------------------------------------------------------- Default
   74: # Fast forward to first rule
   75:   $token=$parser->get_token;
   76:   while ($token->[1] ne 'accessrule') { $token=$parser->get_token; }
   77: # print default
   78:   $r->print('<tr><td>&nbsp;</td><td>');
   79:   if ($constructmode) {
   80:       $r->print(&Apache::loncommon::select_form
   81:                                  ($token->[2]->{'effect'},'effect_0',
   82:                                    ('allow' => 'allow',
   83:                                     'deny'  => 'deny')));
   84:   } else {
   85:       $r->print($token->[2]->{'effect'});
   86:   }
   87:   $r->print('</td><td colspan="2">Default');
   88:   if (($token->[2]->{'realm'}) || ($token->[2]->{'role'})) {
   89:       $r->print(' - <font color="red">Error! No default set.</font>');
   90:   }
   91:   $r->print('</td></tr>');
   92: # Additional roles
   93:   while ($token=$parser->get_token) {
   94:       if (($token->[0] eq 'S') && ($token->[1] eq 'accessrule')) {
   95:           $rulecounter++;
   96: 	  $r->print('<tr><td>');
   97: # inset, delete, etc
   98:           $r->print('</td><td>');
   99: # effect
  100:           if ($constructmode) {
  101:              $r->print(&Apache::loncommon::select_form
  102:                                  ($token->[2]->{'effect'},
  103:                                   'effect_'.$rulecounter,
  104:                                    ('allow' => 'allow',
  105:                                     'deny'  => 'deny')));
  106:           } else {
  107:              $r->print($token->[2]->{'effect'});
  108:           }
  109: 	  $r->print('</td><td>');
  110: # realm
  111:           my $realm=$token->[2]->{'realm'};
  112:           $realm=~s/^\W//;
  113:           my ($rdom,$rcourse,$rsec)=split(/(\/|\_)/,$realm);
  114:           if ($constructmode) {
  115:               $r->print(&Apache::loncommon::select_dom_form($rdom,
  116:                                                       'domain_'.$rulecounter));
  117:           } else {
  118:               $r->print($token->[2]->{'realm'});
  119:           }
  120:           $r->print('</td><td>');
  121: # role
  122:           if ($constructmode) {
  123:           } else {
  124:               $r->print($token->[2]->{'role'});
  125:           }
  126: # close row
  127:           $r->print('</td></tr>');
  128:      }                                       
  129:   }
  130:   $r->print('</table>');
  131: # ------------------------------------------------------------ End table output
  132:   if ($constructmode) { 
  133:      $r->print('<input type="submit" value="Store" /></form>'); 
  134:   }
  135:   $r->print('</body></html>');
  136:   return OK;  
  137: }
  138: 
  139: 
  140: 1;
  141: __END__
  142: 
  143: 
  144: 
  145: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>