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