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