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