Annotation of loncom/auth/lonroles.pm, revision 1.11
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
3: # (Directory Indexer
4: # (Login Screen
5: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
6: # 11/23 Gerd Kortemeyer)
1.7 www 7: # 1/14,03/06,06/01,07/22,07/24,07/25,
1.9 www 8: # 09/04,09/06,09/28,09/29,09/30,10/2 Gerd Kortemeyer
1.1 harris41 9: #
10: package Apache::lonroles;
11:
12: use strict;
13: use Apache::lonnet();
1.7 www 14: use Apache::lonuserstate();
1.1 harris41 15: use Apache::Constants qw(:common);
1.2 www 16: use Apache::File();
1.1 harris41 17:
18: sub handler {
1.10 www 19:
1.1 harris41 20: my $r = shift;
21:
1.6 www 22: my $now=time;
23: my $then=$ENV{'user.login.time'};
24: my $envkey;
25:
1.10 www 26:
1.6 www 27: # ================================================================== Roles Init
28:
29: if ($ENV{'form.selectrole'}) {
30: foreach $envkey (keys %ENV) {
31: if ($envkey=~/^user\.role\./) {
32: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
33: my $where=join('.',@pwhere);
34: my $trolecode=$role.'.'.$where;
35: if ($ENV{'form.'.$trolecode}) {
36: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
37: my $tstatus='is';
38: if ($tstart) {
39: if ($tstart>$then) {
40: $tstatus='future';
41: }
42: }
43: if ($tend) {
44: if ($tend<$then) { $tstatus='expired'; }
45: if ($tend>$now) { $tstatus='will_not'; }
46: }
47: if ($tstatus eq 'is') {
48: &Apache::lonnet::appenv('request.role' => $trolecode);
1.7 www 49: my ($cdom,$cnum)=split(/\//,$where);
50: if ($cnum) {
1.9 www 51: &Apache::lonuserstate::readmap($where);
1.11 ! www 52: if ($ENV{'form.orgurl'}) {
! 53: $r->internal_redirect($ENV{'form.orgurl'});
! 54: return OK;
! 55: }
1.7 www 56: }
1.6 www 57: }
58: }
59: }
60: }
1.10 www 61: }
1.6 www 62:
1.10 www 63:
1.6 www 64: # =============================================================== No Roles Init
1.10 www 65:
66: $r->content_type('text/html');
67: $r->send_http_header;
68: return OK if $r->header_only;
69:
70: $r->print(<<ENDHEADER);
71: <html>
72: <head>
73: <title>LON-CAPA User Roles</title>
74: </head><body bgcolor="#FFFFFF">
75: ENDHEADER
1.6 www 76:
1.2 www 77: # ------------------------------------------ Get Error Message from Environment
78:
79: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.5 www 80: $r->log_reason(
81: "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
1.1 harris41 82:
1.6 www 83: # ---------------------------------------------------------------- Who is this?
84:
85: my $advanced=0;
86: foreach $envkey (keys %ENV) {
87: if ($envkey=~/^user\.role\./) {
88: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
89: if ($role ne 'st') { $advanced=1; }
90: }
91: }
92:
1.8 www 93: # ---------------------------------------------- Get cached course descriptions
94:
95: my %cdes=Apache::lonnet::dump('coursedescriptions');
96:
1.2 www 97: # -------------------------------------------------------- Generate Page Output
1.6 www 98: # --------------------------------------------------------------- Error Header?
1.2 www 99: if ($error) {
100: $r->print("<h1>LON-CAPA Access Control</h1>");
1.4 www 101: $r->print("<hr><pre>Access : ".
102: Apache::lonnet::plaintext($priv)."\n");
103: $r->print("Resource: $fn\n");
104: $r->print("Action : $msg\n</pre><hr>");
1.2 www 105: } else {
106: $r->print("<h1>LON-CAPA User Roles</h1>");
107: }
1.6 www 108: # -------------------------------------------------------- Choice or no choice?
1.2 www 109: if ($nochoose) {
1.6 www 110: if ($advanced) {
111: $r->print("<h2>Assigned User Roles</h2>\n");
112: } else {
113: $r->print("<h2>Sorry ...</h2>\nThis resource might be part of");
114: if ($ENV{'request.course.id'}) {
115: $r->print(' another');
116: } else {
117: $r->print(' a certain');
118: }
119: $r->print(' course.</body></html>');
120: return OK;
121: }
122: } else {
123: if ($advanced) {
124: $r->print("<h2>Select a User Role</h2>\n");
125: } else {
126: $r->print("<h2>Enter a Course</h2>\n");
127: }
1.11 ! www 128: $r->print('<form method=post action="'.(($fn)?$fn:$r->uri).'">');
1.6 www 129: $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
130: $r->print('<input type=hidden name=selectrole value=1>');
131: }
132: # ----------------------------------------------------------------------- Table
133: $r->print('<table><tr>');
134: unless ($nochoose) { $r->print('<th> </th>'); }
135: if ($advanced) {
136: $r->print('<th>User Role</th><th colspan=2>Extent</th>'.
137: '<th>Start</th><th>End</th><th>Remark</th></tr>'."\n");
1.2 www 138: } else {
1.6 www 139: $r->print('<th>Course</th></tr>'."\n");
1.2 www 140: }
1.4 www 141:
1.3 albertel 142: foreach $envkey (sort keys %ENV) {
1.2 www 143: if ($envkey=~/^user\.role\./) {
1.4 www 144: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
145: my $where=join('.',@pwhere);
1.6 www 146: my $trolecode=$role.'.'.$where;
1.4 www 147: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
148: my $tremark='';
149: my $tstatus='is';
150: my $tpstart=' ';
151: my $tpend=' ';
152: if ($tstart) {
153: if ($tstart>$then) {
154: $tstatus='future';
155: if ($tstart<$now) { $tstatus='will'; }
156: }
157: $tpstart=localtime($tstart);
158: }
159: if ($tend) {
160: if ($tend<$then) { $tstatus='expired'; }
161: if ($tend>$now) { $tstatus='will_not'; }
162: $tpend=localtime($tend);
163: }
1.6 www 164: if ($ENV{'request.role'} eq $trolecode) {
165: $tstatus='selected';
166: }
1.4 www 167: my $tbg;
168: if ($tstatus eq 'is') {
169: $tbg='#77FF77';
170: } elsif ($tstatus eq 'future') {
171: $tbg='#FFFF77';
172: } elsif ($tstatus eq 'will') {
173: $tbg='#FFAA77';
1.6 www 174: $tremark.='Active at next login. ';
1.4 www 175: } elsif ($tstatus eq 'expired') {
176: $tbg='#FF7777';
177: } elsif ($tstatus eq 'will_not') {
178: $tbg='#AAFF77';
1.6 www 179: $tremark.='Expired after logout. ';
180: } elsif ($tstatus eq 'selected') {
181: $tbg='#33FF33';
182: $tremark.='Currently selected. ';
1.4 www 183: }
184: my $trole;
185: if ($role =~ /^cr\//) {
186: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
187: $tremark.='<br>Defined by '.$rauthor.' at '.$rdomain.'.';
188: $trole=$rrole;
189: } else {
190: $trole=Apache::lonnet::plaintext($role);
191: }
192: my $ttype;
193: my $twhere;
1.8 www 194: my ($tdom,$trest)=
195: split(/\//,Apache::lonnet::declutter($where));
1.6 www 196: if ($trest) {
1.4 www 197: $ttype='Course';
1.8 www 198: my $tcourseid=$tdom.'/'.$trest;
199: if ($cdes{$tcourseid}) {
200: $twhere=$cdes{$tcourseid};
201: } else {
202: my %newhash=Apache::lonnet::coursedescription($tcourseid);
203: if (%newhash) {
204: $twhere=$newhash{'description'};
205: } else {
206: $twhere='Currently not available';
207: }
208: $cdes{$tcourseid}=$twhere;
209: }
1.4 www 210: } elsif ($tdom) {
211: $ttype='Domain';
212: $twhere=$tdom;
213: } else {
214: $ttype='System';
1.8 www 215: $twhere='system wide';
1.4 www 216: }
217:
1.6 www 218: $r->print('<tr bgcolor='.$tbg.'>');
219: unless ($nochoose) {
220: if ($tstatus eq 'is') {
221: $r->print('<td><input type=submit value=Select name="'.
222: $trolecode.'"></td>');
223: } else {
224: $r->print('<td> </td>');
225: }
226: }
227: $r->print('<td>'.$trole.'</td><td>'.
1.4 www 228: $ttype.'</td><td>'.$twhere.'</td><td>'.$tpstart.
229: '</td><td>'.$tpend.
230: '</td><td>'.$tremark.' </td></tr>'."\n");
231: }
232: }
233:
234: $r->print('</table>');
235: unless ($nochoose) {
236: $r->print("</form>\n");
237: }
1.6 www 238: # ------------------------------------------------------------ Priviledges Info
239: if ($advanced) {
1.4 www 240: $r->print('<hr><h2>Priviledges</h2>');
241:
242: foreach $envkey (sort keys %ENV) {
243: if ($envkey=~/^user\.priv\./) {
244: my ($dum1,$dum2,@pwhere)=split(/\./,$envkey);
245: my $where=join('.',@pwhere);
246: my $ttype;
247: my $twhere;
1.8 www 248: my ($tdom,$trest)=
249: split(/\//,Apache::lonnet::declutter($where));
1.6 www 250: if ($trest) {
1.4 www 251: $ttype='Course';
1.8 www 252: $twhere=$cdes{$tdom.'/'.$trest};
1.4 www 253: } elsif ($tdom) {
254: $ttype='Domain';
255: $twhere=$tdom;
256: } else {
257: $ttype='System';
258: $twhere='/';
259: }
260: $r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
261: map {
262: if ($_) {
263: my ($prv,$restr)=split(/\&/,$_);
264: my $trestr='';
265: if ($restr ne 'F') {
266: my $i;
1.5 www 267: $trestr.=' (';
1.4 www 268: for ($i=0;$i<length($restr);$i++) {
1.5 www 269: $trestr.=
270: Apache::lonnet::plaintext(substr($restr,$i,1));
271: if ($i<length($restr)-1) { $trestr.=', '; }
272: }
273: $trestr.=')';
1.4 www 274: }
275: $r->print('<li>'.Apache::lonnet::plaintext($prv).$trestr.
276: '</li>');
277: }
278: } sort split(/:/,$ENV{$envkey});
279: $r->print('</ul>');
1.2 www 280: }
1.4 www 281: }
1.6 www 282: }
1.4 www 283: # -------------------------------------------------------------- Debug - remove
284:
285: $->print("<hr><h1>Debugging</h1><hr>\n");
286:
287: foreach $envkey (sort keys %ENV) {
288: $r->print("$envkey ---- $ENV{$envkey}<br>");
1.1 harris41 289: }
1.6 www 290:
291: # ------------------------------------------------------------------- End Debug
1.2 www 292:
1.1 harris41 293: $r->print("</body></html>\n");
294: return OK;
295: }
296:
297: 1;
298: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>