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