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