Annotation of loncom/auth/lonroles.pm, revision 1.37
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.37 ! albertel 4: # $Id: lonroles.pm,v 1.36 2002/05/06 14:20:27 matthew Exp $
1.31 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 harris41 28: # (Directory Indexer
29: # (Login Screen
1.32 harris41 30: # YEAR=1999
1.1 harris41 31: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
32: # 11/23 Gerd Kortemeyer)
1.32 harris41 33: # YEAR=2000
1.7 www 34: # 1/14,03/06,06/01,07/22,07/24,07/25,
1.19 www 35: # 09/04,09/06,09/28,09/29,09/30,10/2,10/5,10/26,10/28,
1.20 www 36: # 12/08,12/28,
1.32 harris41 37: # YEAR=2001
1.20 www 38: # 01/15/01 Gerd Kortemeyer
1.22 harris41 39: # 02/27/01 Scott Harrison
1.28 www 40: # 03/02,05/03,05/25,05/30,06/01,07/06,08/06 Gerd Kortemeyer
1.32 harris41 41: # 12/21 Scott Harrison
1.33 www 42: # 12/29 Gerd Kortemeyer
1.32 harris41 43: #
44: ###
1.22 harris41 45:
1.1 harris41 46: package Apache::lonroles;
47:
48: use strict;
49: use Apache::lonnet();
1.7 www 50: use Apache::lonuserstate();
1.1 harris41 51: use Apache::Constants qw(:common);
1.2 www 52: use Apache::File();
1.26 www 53: use Apache::lonmenu;
1.29 albertel 54: use Apache::loncommon;
1.1 harris41 55:
56: sub handler {
1.10 www 57:
1.1 harris41 58: my $r = shift;
59:
1.6 www 60: my $now=time;
61: my $then=$ENV{'user.login.time'};
62: my $envkey;
63:
1.10 www 64:
1.6 www 65: # ================================================================== Roles Init
66:
67: if ($ENV{'form.selectrole'}) {
1.33 www 68: if ($ENV{'request.course.id'}) {
69: my %temp=('logout_'.$ENV{'request.course.id'} => time);
70: &Apache::lonnet::put('email_status',\%temp);
71: }
1.13 www 72: &Apache::lonnet::appenv("request.course.id" => '',
73: "request.course.fn" => '',
74: "request.course.uri" => '',
75: "request.course.sec" => '',
76: "request.role" => 'cm');
77: foreach $envkey (keys %ENV) {
78: if ($envkey=~/^user\.role\./) {
1.6 www 79: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
80: my $where=join('.',@pwhere);
81: my $trolecode=$role.'.'.$where;
82: if ($ENV{'form.'.$trolecode}) {
83: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
84: my $tstatus='is';
85: if ($tstart) {
86: if ($tstart>$then) {
87: $tstatus='future';
88: }
89: }
90: if ($tend) {
91: if ($tend<$then) { $tstatus='expired'; }
1.19 www 92: if ($tend<$now) { $tstatus='will_not'; }
1.6 www 93: }
94: if ($tstatus eq 'is') {
1.13 www 95: $where=~s/^\///;
96: my ($cdom,$cnum,$csec)=split(/\//,$where);
97: &Apache::lonnet::appenv('request.role' => $trolecode,
1.14 www 98: 'request.course.sec' => $csec);
1.27 www 99: my $msg='Entering course ...';
1.25 www 100: if (($cnum) && ($role ne 'ca')) {
1.19 www 101: my ($furl,$ferr)=
102: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.20 www 103: if (($ENV{'form.orgurl'}) &&
104: ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) {
1.11 www 105: $r->internal_redirect($ENV{'form.orgurl'});
106: return OK;
1.19 www 107: } else {
1.27 www 108: unless ($ENV{'request.course.id'}) {
109: &Apache::lonnet::appenv(
110: "request.course.id" => $cdom.'_'.$cnum);
111: $furl='/adm/notfound.html';
112: $msg=
113: '<h1><font color=red>Could not initialize top-level map.</font></h1>';
114: }
1.20 www 115: $r->content_type('text/html');
1.30 albertel 116: &Apache::loncommon::no_cache($r);
1.20 www 117: $r->send_http_header;
1.36 matthew 118: my $swinfo=&Apache::lonmenu::rawconfig($r);
1.20 www 119: print (<<ENDREDIR);
120: <head><title>Entering Course</title>
121: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$furl">
122: </head>
123: <html>
124: <body bgcolor="#FFFFFF">
1.26 www 125: <script>
126: $swinfo
127: </script>
1.27 www 128: $msg
1.20 www 129: </body>
130: </html>
131: ENDREDIR
132: return OK;
1.19 www 133: }
1.7 www 134: }
1.6 www 135: }
136: }
137: }
138: }
1.20 www 139: }
1.6 www 140:
1.10 www 141:
1.6 www 142: # =============================================================== No Roles Init
1.10 www 143:
144: $r->content_type('text/html');
1.30 albertel 145: &Apache::loncommon::no_cache($r);
1.10 www 146: $r->send_http_header;
147: return OK if $r->header_only;
148:
1.36 matthew 149: my $swinfo=&Apache::lonmenu::rawconfig($r);
1.10 www 150: $r->print(<<ENDHEADER);
151: <html>
152: <head>
153: <title>LON-CAPA User Roles</title>
154: </head><body bgcolor="#FFFFFF">
1.26 www 155: <script>
156: $swinfo
157: window.focus();
158: </script>
1.10 www 159: ENDHEADER
1.6 www 160:
1.2 www 161: # ------------------------------------------ Get Error Message from Environment
162:
163: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.12 www 164: if ($ENV{'user.error.msg'}) {
165: $r->log_reason(
166: "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
167: }
1.1 harris41 168:
1.6 www 169: # ---------------------------------------------------------------- Who is this?
170:
171: my $advanced=0;
172: foreach $envkey (keys %ENV) {
173: if ($envkey=~/^user\.role\./) {
174: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
175: if ($role ne 'st') { $advanced=1; }
176: }
177: }
178:
1.2 www 179: # -------------------------------------------------------- Generate Page Output
1.6 www 180: # --------------------------------------------------------------- Error Header?
1.2 www 181: if ($error) {
182: $r->print("<h1>LON-CAPA Access Control</h1>");
1.4 www 183: $r->print("<hr><pre>Access : ".
184: Apache::lonnet::plaintext($priv)."\n");
185: $r->print("Resource: $fn\n");
186: $r->print("Action : $msg\n</pre><hr>");
1.2 www 187: } else {
188: $r->print("<h1>LON-CAPA User Roles</h1>");
1.25 www 189: if ($ENV{'user.error.msg'}) {
190: $r->print(
191: '<h3><font color=red>You need to choose another user role or '.
192: 'enter a specific course for this function</font></h3>');
193: }
1.2 www 194: }
1.6 www 195: # -------------------------------------------------------- Choice or no choice?
1.2 www 196: if ($nochoose) {
1.6 www 197: if ($advanced) {
198: $r->print("<h2>Assigned User Roles</h2>\n");
199: } else {
200: $r->print("<h2>Sorry ...</h2>\nThis resource might be part of");
201: if ($ENV{'request.course.id'}) {
202: $r->print(' another');
203: } else {
204: $r->print(' a certain');
205: }
206: $r->print(' course.</body></html>');
207: return OK;
208: }
209: } else {
210: if ($advanced) {
1.35 matthew 211: $r->print
212: ("<h2>$ENV{'user.name'}, Please Select a Role</h2>\n");
213: $r->print("Your home server is ".
214: $Apache::lonnet::hostname{&Apache::lonnet::homeserver
215: ($ENV{'user.name'},$ENV{'user.domain'})}."<br />\n");
216: $r->print("Author and Co-Author roles may not be available on ".
217: "servers other than your home server.");
1.6 www 218: } else {
219: $r->print("<h2>Enter a Course</h2>\n");
1.17 www 220: }
1.18 www 221: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
222: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 223: }
1.11 www 224: $r->print('<form method=post action="'.(($fn)?$fn:$r->uri).'">');
1.6 www 225: $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
226: $r->print('<input type=hidden name=selectrole value=1>');
227: }
1.27 www 228: $r->print('<br>Show all roles: <input type=checkbox name=showall');
229: if ($ENV{'form.showall'}) { $r->print(' checked'); }
230: $r->print('><input type=submit value="Display"><br>');
1.6 www 231: # ----------------------------------------------------------------------- Table
232: $r->print('<table><tr>');
233: unless ($nochoose) { $r->print('<th> </th>'); }
234: $r->print('<th>User Role</th><th colspan=2>Extent</th>'.
235: '<th>Start</th><th>End</th><th>Remark</th></tr>'."\n");
1.4 www 236:
1.3 albertel 237: foreach $envkey (sort keys %ENV) {
1.35 matthew 238: my $button = 1;
1.2 www 239: if ($envkey=~/^user\.role\./) {
1.4 www 240: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
241: my $where=join('.',@pwhere);
1.6 www 242: my $trolecode=$role.'.'.$where;
1.4 www 243: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
244: my $tremark='';
245: my $tstatus='is';
246: my $tpstart=' ';
247: my $tpend=' ';
248: if ($tstart) {
249: if ($tstart>$then) {
1.35 matthew 250: $tstatus='future';
251: if ($tstart<$now) { $tstatus='will'; }
1.4 www 252: }
253: $tpstart=localtime($tstart);
254: }
255: if ($tend) {
1.23 www 256: if ($tend<$then) {
1.35 matthew 257: $tstatus='expired';
1.23 www 258: } elsif ($tend<$now) {
1.35 matthew 259: $tstatus='will_not';
1.23 www 260: }
1.4 www 261: $tpend=localtime($tend);
262: }
1.6 www 263: if ($ENV{'request.role'} eq $trolecode) {
264: $tstatus='selected';
265: }
1.4 www 266: my $tbg;
1.35 matthew 267: if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
268: ($ENV{'form.showall'})) {
269: if ($tstatus eq 'is') {
270: $tbg='#77FF77';
271: } elsif ($tstatus eq 'future') {
272: $tbg='#FFFF77';
273: } elsif ($tstatus eq 'will') {
274: $tbg='#FFAA77';
275: $tremark.='Active at next login. ';
276: } elsif ($tstatus eq 'expired') {
277: $tbg='#FF7777';
278: } elsif ($tstatus eq 'will_not') {
279: $tbg='#AAFF77';
280: $tremark.='Expired after logout. ';
281: } elsif ($tstatus eq 'selected') {
282: $tbg='#11CC55';
283: $tremark.='Currently selected. ';
284: }
285: my $trole;
286: if ($role =~ /^cr\//) {
287: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
288: $tremark.='<br>Defined by '.$rauthor.' at '.$rdomain.'.';
289: $trole=$rrole;
1.8 www 290: } else {
1.35 matthew 291: $trole=Apache::lonnet::plaintext($role);
292: }
293: my $ttype;
294: my $twhere;
295: my ($tdom,$trest,$tsection)=
296: split(/\//,Apache::lonnet::declutter($where));
297: # First, Co-Authorship roles
298: if ($role eq 'ca') {
299: my $home = &Apache::lonnet::homeserver($trest,$tdom);
300: $button = 0 if ($home ne $r->dir_config('lonHostID'));
301: #next if ($home eq 'no_host');
302: $home = $Apache::lonnet::hostname{$home};
303: $ttype='Construction Space';
304: $twhere='User: '.$trest.'<br />Domain: '.$tdom.'<br />'.
305: ' Server: '.$home;
306: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
307: } elsif ($role eq 'au') {
308: # Authors
309: my $home = &Apache::lonnet::homeserver
310: ($ENV{'user.name'},$ENV{'user.domain'});
311: $button = 0 if ($home ne $r->dir_config('lonHostID'));
312: #next if ($home eq 'no_host');
313: $home = $Apache::lonnet::hostname{$home};
314: $ttype='Construction Space';
315: $twhere='Domain: '.$tdom.'<br />Server: '.$home;
316: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
317: } elsif ($trest) {
318: $ttype='Course';
319: if ($tsection) {
320: $ttype.='<br>Section/Group: '.$tsection;
1.37 ! albertel 321: }
1.35 matthew 322: my $tcourseid=$tdom.'_'.$trest;
323: if ($ENV{'course.'.$tcourseid.'.description'}) {
324: $twhere=$ENV{'course.'.$tcourseid.'.description'};
1.8 www 325: } else {
1.35 matthew 326: my %newhash=Apache::lonnet::coursedescription
327: ($tcourseid);
328: if (%newhash) {
329: $twhere=$newhash{'description'};
330: } else {
331: $twhere='Currently not available';
332: $ENV{'course.'.$tcourseid.'.description'}=$twhere;
333: }
1.8 www 334: }
1.37 ! albertel 335: if ($role ne 'st') { $twhere.="<br />Domain:".$tdom; }
1.35 matthew 336: } elsif ($tdom) {
337: $ttype='Domain';
338: $twhere=$tdom;
339: } else {
340: $ttype='System';
341: $twhere='system wide';
1.13 www 342: }
1.35 matthew 343:
344: # ----- do not trust the indention below here -----
345: $r->print('<tr bgcolor='.$tbg.'>');
346: unless ($nochoose) {
347: if (!$button) {
348: $r->print('<td> </td>');
349: } elsif ($tstatus eq 'is') {
350: $r->print('<td><input type=submit value=Select name="'.
351: $trolecode.'"></td>');
352: } elsif ($ENV{'user.adv'}) {
353: $r->print
354: ('<td><input type=submit value="Re-Initialize"'.
355: ' name="'.$trolecode.'"></td>');
356: } else {
357: $r->print('<td> </td>');
358: }
1.6 www 359: }
360: $r->print('<td>'.$trole.'</td><td>'.
1.4 www 361: $ttype.'</td><td>'.$twhere.'</td><td>'.$tpstart.
362: '</td><td>'.$tpend.
363: '</td><td>'.$tremark.' </td></tr>'."\n");
1.27 www 364: }
1.4 www 365: }
366: }
1.14 www 367: my $tremark='';
368: if ($ENV{'request.role'} eq 'cm') {
1.19 www 369: $r->print('<tr bgcolor="#11CC55">');
1.14 www 370: $tremark='Currently selected.';
371: } else {
372: $r->print('<tr bgcolor="#77FF77">');
373: }
374: unless ($nochoose) {
375: if ($ENV{'request.role'} ne 'cm') {
376: $r->print('<td><input type=submit value=Select name="cm"></td>');
377: } else {
378: $r->print('<td> </td>');
379: }
380: }
381: $r->print('<td colspan=5>No role specified'.
382: '</td><td>'.$tremark.' </td></tr>'."\n");
1.4 www 383:
384: $r->print('</table>');
385: unless ($nochoose) {
386: $r->print("</form>\n");
387: }
1.22 harris41 388: # ------------------------------------------------------------ Privileges Info
1.6 www 389: if ($advanced) {
1.22 harris41 390: $r->print('<hr><h2>Current Privileges</h2>');
1.4 www 391:
392: foreach $envkey (sort keys %ENV) {
1.15 www 393: if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
394: my $where=$envkey;
395: $where=~s/^user\.priv\.$ENV{'request.role'}\.//;
1.4 www 396: my $ttype;
397: my $twhere;
1.15 www 398: my ($tdom,$trest,$tsec)=
1.8 www 399: split(/\//,Apache::lonnet::declutter($where));
1.6 www 400: if ($trest) {
1.24 www 401: if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
402: $ttype='Construction Space';
403: $twhere='User: '.$trest.', Domain: '.$tdom;
404: } else {
1.4 www 405: $ttype='Course';
1.16 www 406: $twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
1.15 www 407: if ($tsec) {
408: $twhere.=' (Section/Group: '.$tsec.')';
409: }
1.24 www 410: }
1.4 www 411: } elsif ($tdom) {
412: $ttype='Domain';
413: $twhere=$tdom;
414: } else {
415: $ttype='System';
416: $twhere='/';
417: }
418: $r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
1.32 harris41 419: foreach (sort split(/:/,$ENV{$envkey})) {
1.4 www 420: if ($_) {
421: my ($prv,$restr)=split(/\&/,$_);
422: my $trestr='';
423: if ($restr ne 'F') {
424: my $i;
1.5 www 425: $trestr.=' (';
1.4 www 426: for ($i=0;$i<length($restr);$i++) {
1.5 www 427: $trestr.=
428: Apache::lonnet::plaintext(substr($restr,$i,1));
429: if ($i<length($restr)-1) { $trestr.=', '; }
430: }
431: $trestr.=')';
1.4 www 432: }
433: $r->print('<li>'.Apache::lonnet::plaintext($prv).$trestr.
434: '</li>');
435: }
1.32 harris41 436: }
1.4 www 437: $r->print('</ul>');
1.2 www 438: }
1.4 www 439: }
1.6 www 440: }
1.2 www 441:
1.1 harris41 442: $r->print("</body></html>\n");
443: return OK;
444: }
445:
446: 1;
447: __END__
1.32 harris41 448:
449: =head1 NAME
450:
451: Apache::lonroles - User Roles Screen
452:
453: =head1 SYNOPSIS
454:
455: Invoked by /etc/httpd/conf/srm.conf:
456:
457: <Location /adm/roles>
458: PerlAccessHandler Apache::lonacc
459: SetHandler perl-script
460: PerlHandler Apache::lonroles
461: ErrorDocument 403 /adm/login
462: ErrorDocument 500 /adm/errorhandler
463: </Location>
464:
465: =head1 INTRODUCTION
466:
467: This module enables a user to select what role he wishes to
468: operate under (instructor, student, teaching assistant, course
469: coordinator, etc). These roles are pre-established by the actions
470: of upper-level users.
471:
472: This is part of the LearningOnline Network with CAPA project
473: described at http://www.lon-capa.org.
474:
475: =head1 HANDLER SUBROUTINE
476:
477: This routine is called by Apache and mod_perl.
478:
479: =over 4
480:
481: =item *
482:
483: Roles Initialization (yes/no)
484:
485: =item *
486:
487: Get Error Message from Environment
488:
489: =item *
490:
491: Who is this?
492:
493: =item *
494:
495: Generate Page Output
496:
497: =item *
498:
499: Choice or no choice
500:
501: =item *
502:
503: Table
504:
505: =item *
506:
507: Privileges
508:
509: =back
510:
511: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>