1: # The LearningOnline Network with CAPA
2: # Handler to show and edit custom distribution rights
3: #
4: # $Id: lonrights.pm,v 1.4 2003/03/20 19:20:31 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: my $colzero=($constructmode?'Edit action':'Rule');
72: # ---------------------------------------------------------- Start table output
73: $r->print(<<ENDSTARTTABLE);
74: <table border="2">
75: <tr><th>$colzero</th><th>Effect</th><th>Domain</th><th>Course</th>
76: <th>Section</th><th>Role</th></tr>
77: ENDSTARTTABLE
78: # --------------------------------------------------------------------- Default
79: # Fast forward to first rule
80: $token=$parser->get_token;
81: while ($token->[1] ne 'accessrule') { $token=$parser->get_token; }
82: # print default
83: $r->print('<tr><td> </td><td>');
84: if ($constructmode) {
85: $r->print(&Apache::loncommon::select_form
86: ($token->[2]->{'effect'},'effect_0',
87: ('allow' => 'allow',
88: 'deny' => 'deny')));
89: } else {
90: $r->print($token->[2]->{'effect'});
91: }
92: $r->print('</td><td colspan="4">Default');
93: if (($token->[2]->{'realm'}) || ($token->[2]->{'role'})) {
94: $r->print(' - <font color="red">Error! No default set.</font>');
95: }
96: $r->print('</td></tr>');
97: # Additional roles
98: while ($token=$parser->get_token) {
99: if (($token->[0] eq 'S') && ($token->[1] eq 'accessrule')) {
100: $rulecounter++;
101: $r->print('<tr><td>');
102: # insert, delete, etc
103: $r->print($rulecounter.'. ');
104: if ($constructmode) {
105: $r->print(&Apache::loncommon::select_form(
106: '','action_'.$rulecounter,
107: ('' => '',
108: 'delete' => 'Delete this rule',
109: 'insertabove' => 'Insert rule above',
110: 'insertbelow' => 'Insert rule below',
111: 'moveup' => 'Move rule up',
112: 'movedown' => 'Move rule down')));
113: }
114: $r->print('</td><td>');
115: # effect
116: if ($constructmode) {
117: $r->print(&Apache::loncommon::select_form
118: ($token->[2]->{'effect'},
119: 'effect_'.$rulecounter,
120: ('allow' => 'allow',
121: 'deny' => 'deny')));
122: } else {
123: $r->print($token->[2]->{'effect'});
124: }
125: $r->print('</td><td>');
126: # ---- realm
127: my $realm=$token->[2]->{'realm'};
128: $realm=~s/^\W//;
129: my ($rdom,$rcourse,$rsec)=split(/[\/\_]/,$realm);
130: # realm role
131: if ($constructmode) {
132: $r->print(&Apache::loncommon::select_dom_form($rdom,
133: 'domain_'.$rulecounter));
134: } else {
135: $r->print($rdom);
136: }
137: $r->print('</td><td>');
138: # realm course
139: if ($constructmode) {
140: $r->print('<input input type="text" size="25" name="course_'.
141: $rulecounter.'" value="'.$rcourse.'" />');
142: } else {
143: $r->print($rcourse);
144: }
145:
146: $r->print('</td><td>');
147: # realm section
148: if ($constructmode) {
149: $r->print('<input input type="text" size="5" name="section_'.
150: $rulecounter.'" value="'.$rsec.'" />');
151: } else {
152: $r->print($rsec);
153: }
154:
155: $r->print('</td><td>');
156: # role
157: if ($constructmode) {
158: my %hash=('' => '');
159: foreach ('au','cc','in','ta','st') {
160: $hash{$_}=&Apache::lonnet::plaintext($_);
161: }
162: my $role=$token->[2]->{'role'};
163: unless ($role) { $role=''; }
164: $r->print(&Apache::loncommon::select_form(
165: $role,'role_'.$rulecounter,%hash));
166: } else {
167: $r->print(&Apache::lonnet::plaintext($token->[2]->{'role'}));
168: }
169: # close row
170: $r->print('</td></tr>');
171: }
172: }
173: $r->print('</table>');
174: # ------------------------------------------------------------ End table output
175: if ($constructmode) {
176: $r->print('<input type="submit" value="Store" /></form>');
177: }
178: $r->print('</body></html>');
179: return OK;
180: }
181:
182:
183: 1;
184: __END__
185:
186:
187:
188:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>