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