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