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