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