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