File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.62: download - view: text, annotated - select for diffs
Tue Jun 24 15:52:32 2003 UTC (21 years ago) by matthew
Branches: MAIN
CVS tags: version_0_99_3, HEAD
Bug 1353: Automatically redirect the user to construction space when they
select an author or co-author role.
Added &redirect_user subroutine to do the redirection.
Modified course-coordinator/instructo/ta/student redirection to use the
new subroutine.

    1: # The LearningOnline Network with CAPA
    2: # User Roles Screen
    3: #
    4: # $Id: lonroles.pm,v 1.62 2003/06/24 15:52:32 matthew Exp $
    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: #
   28: # (Directory Indexer
   29: # (Login Screen
   30: # YEAR=1999
   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)
   33: # YEAR=2000
   34: # 1/14,03/06,06/01,07/22,07/24,07/25,
   35: # 09/04,09/06,09/28,09/29,09/30,10/2,10/5,10/26,10/28,
   36: # 12/08,12/28,
   37: # YEAR=2001
   38: # 01/15/01 Gerd Kortemeyer
   39: # 03/02,05/03,05/25,05/30,06/01,07/06,08/06 Gerd Kortemeyer
   40: # 12/29 Gerd Kortemeyer
   41: #
   42: ###
   43: 
   44: package Apache::lonroles;
   45: 
   46: use strict;
   47: use Apache::lonnet();
   48: use Apache::lonuserstate();
   49: use Apache::Constants qw(:common);
   50: use Apache::File();
   51: use Apache::lonmenu;
   52: use Apache::loncommon;
   53: use Apache::lonannounce;
   54: 
   55: sub redirect_user {
   56:     my ($r,$title,$url,$msg) = @_;
   57:     $msg = $title if (! defined($msg));
   58:     $r->content_type('text/html');
   59:     &Apache::loncommon::no_cache($r);
   60:     $r->send_http_header;
   61:     my $swinfo=&Apache::lonmenu::rawconfig();
   62:     my $bodytag=&Apache::loncommon::bodytag('Switching Role');
   63:     $r->print (<<ENDREDIR);
   64: <head><title>$title</title>
   65: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$url">
   66: </head>
   67: <html>
   68: $bodytag
   69: <script>
   70: $swinfo
   71: </script>
   72: <h1>$msg</h1>
   73: </body>
   74: </html>
   75: ENDREDIR
   76:     return;
   77: }
   78: 
   79: sub handler {
   80: 
   81:     my $r = shift;
   82: 
   83:     my $now=time;
   84:     my $then=$ENV{'user.login.time'};
   85:     my $envkey;
   86: 
   87: 
   88: # ================================================================== Roles Init
   89: 
   90:     if ($ENV{'form.selectrole'}) {
   91: 	if ($ENV{'request.course.id'}) {
   92: 	    my %temp=('logout_'.$ENV{'request.course.id'} => time);
   93: 	    &Apache::lonnet::put('email_status',\%temp);
   94:         }
   95: 	&Apache::lonnet::appenv("request.course.id"   => '',
   96: 				"request.course.fn"   => '',
   97: 				"request.course.uri"  => '',
   98: 				"request.course.sec"  => '',
   99: 				"request.role"        => 'cm',
  100:                                 "request.role.adv"    => $ENV{'user.adv'},
  101: 				"request.role.domain" => $ENV{'user.domain'});
  102:         foreach $envkey (keys %ENV) {
  103:             next if ($envkey!~/^user\.role\./);
  104: 	    my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
  105:             my $where=join('.',@pwhere);
  106:             my $trolecode=$role.'.'.$where;
  107:             if ($ENV{'form.'.$trolecode}) {
  108: 		my ($tstart,$tend)=split(/\./,$ENV{$envkey});
  109: 		my $tstatus='is';
  110: 		if ($tstart) {
  111: 		    if ($tstart>$then) { 
  112: 			$tstatus='future';
  113: 		    }
  114: 		}
  115: 		if ($tend) {
  116: 		    if ($tend<$then) { $tstatus='expired'; }
  117: 		    if ($tend<$now) { $tstatus='will_not'; }
  118: 		}
  119: 		if ($tstatus eq 'is') {
  120: 		    $where=~s/^\///;
  121: 		    my ($cdom,$cnum,$csec)=split(/\//,$where);
  122: # check for keyed access
  123: 		    if (($role eq 'st') && 
  124:                        ($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
  125: 		         unless (&Apache::lonnet::validate_access_key(
  126: 				     $ENV{'environment.key.'.$cdom.'_'.$cnum},
  127: 					     $cdom,$cnum)) {
  128: # there is no valid key
  129: 			     if ($ENV{'form.newkey'}) {
  130: # student attempts to register a new key
  131: 			     } else {
  132: # print form to enter a new key
  133: 				 $r->content_type('text/html');
  134: 				 &Apache::loncommon::no_cache($r);
  135: 				 $r->send_http_header;
  136: 				 my $swinfo=&Apache::lonmenu::rawconfig();
  137: 				 my $bodytag=&Apache::loncommon::bodytag
  138: 				    ('Enter Access Key to Unlock this Course');
  139: 				 $r->print(<<ENDENTERKEY);
  140: <head><title>Entering Course Access Key</title>
  141: </head>
  142: <html>
  143: $bodytag
  144: <script>
  145: $swinfo
  146: </script>
  147: <form method="post">
  148: <input type="hidden" name="selectrole" value="$ENV{'form.selectrole'}" />
  149: <input type="text" size="20" name="newkey" value="$ENV{'form.newkey'}" />
  150: <input type="submit" value="Enter key" />
  151: </form>
  152: </body></html>
  153: ENDENTERKEY
  154: 				 return OK;
  155: 			     }
  156: 			 }
  157: 		     }
  158:                     my $tadv=0;
  159:                     if (($trolecode!~/^st/) && 
  160:                         ($trolecode!~/^ta/) && 
  161:                         ($trolecode!~/^cm/)) { $tadv=1; }
  162: 		    &Apache::lonnet::appenv(
  163:                                            'request.role'        => $trolecode,
  164: 					   'request.role.adv'    => $tadv,
  165: 					   'request.role.domain' => $cdom,
  166: 					   'request.course.sec'  => $csec);
  167: 		    my $msg='Entering course ...';
  168: 
  169: 		    if (($cnum) && ($role ne 'ca')) {
  170: 			my ($furl,$ferr)=
  171: 			    &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
  172: 			if (($ENV{'form.orgurl'}) && 
  173: 			    ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) {
  174: 			    $r->internal_redirect($ENV{'form.orgurl'});
  175: 			    return OK;
  176: 			} else {
  177: 			    unless ($ENV{'request.course.id'}) {
  178: 				&Apache::lonnet::appenv(
  179: 				      "request.course.id"  => $cdom.'_'.$cnum);
  180: 				$furl='/adm/roles?tryagain=1';
  181: 				$msg=
  182: 	 '<h1><font color=red>Could not initialize course at this time.</font></h1><h3>Please try again.</h3>';
  183: 			    }
  184: 
  185: 			    # Check to see if the user is a CC entering a course 
  186: 			    # for the first time
  187: 			    my (undef, undef, $role, $courseid) = split(/\./, $envkey);
  188: 			    if (substr($courseid, 0, 1) eq '/') {
  189: 				$courseid = substr($courseid, 1);
  190: 			    }
  191: 			    $courseid =~ s/\//_/;
  192: 			    if ($role eq 'cc' && $ENV{'course.' . $courseid . 
  193: 							  '.course.helper.not.run'}) {
  194: 				$furl = "/adm/helper/course.initialization.helper";
  195: 			    }
  196:                             #
  197:                             # Send the user to the course they selected
  198:                             &redirect_user($r,'Entering Course',
  199:                                            $furl,$msg);
  200:                             return OK;
  201: 			}
  202: 		    }
  203:                     #
  204:                     # Send the user to the construction space they selected
  205:                     if ($role =~ /^(au|ca)$/) {
  206:                         my $redirect_url = '/priv/';
  207:                         if ($role eq 'au') {
  208:                             $redirect_url.=$ENV{'user.name'};
  209:                         } else {
  210:                             $where =~ /\/(.*)$/;
  211:                             $redirect_url .= $1;
  212:                         }
  213:                         $redirect_url .= '/';
  214:                         &redirect_user($r,'Entering Construction Space',
  215:                                        $redirect_url);
  216:                         return OK;
  217:                     }
  218: 		}
  219:             }
  220:         }
  221:     }
  222: 
  223: 
  224: # =============================================================== No Roles Init
  225: 
  226:     $r->content_type('text/html');
  227:     &Apache::loncommon::no_cache($r);
  228:     $r->send_http_header;
  229:     return OK if $r->header_only;
  230: 
  231:     my $swinfo=&Apache::lonmenu::rawconfig();
  232:     my $bodytag=&Apache::loncommon::bodytag('User Roles');
  233:     my $helptag=&Apache::loncommon::help_open_topic
  234:      ("General_Intro","Click here for help");
  235:     $r->print(<<ENDHEADER);
  236: <html>
  237: <head>
  238: <title>LON-CAPA User Roles</title>
  239: </head>
  240: $bodytag
  241: $helptag<br />
  242: <script>
  243: $swinfo
  244: window.focus();
  245: </script>
  246: ENDHEADER
  247: 
  248: # ------------------------------------------ Get Error Message from Environment
  249: 
  250:     my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
  251:     if ($ENV{'user.error.msg'}) {
  252: 	$r->log_reason(
  253:    "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
  254:     }
  255: 
  256: # ------------------------------------------------- Can this user re-init, etc?
  257: 
  258:     my $advanced=$ENV{'user.adv'};
  259:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
  260:     my $tryagain=$ENV{'form.tryagain'};
  261: 
  262: # -------------------------------------------------------- Generate Page Output
  263: # --------------------------------------------------------------- Error Header?
  264:     if ($error) {
  265: 	$r->print("<h1>LON-CAPA Access Control</h1>");
  266:         $r->print("<hr><pre>Access  : ".
  267:                   Apache::lonnet::plaintext($priv)."\n");
  268:         $r->print("Resource: $fn\n");
  269:         $r->print("Action  : $msg\n</pre><hr>");
  270:     } else {
  271:         if ($ENV{'user.error.msg'}) {
  272: 	    $r->print(
  273:  '<h3><font color=red>You need to choose another user role or '.
  274:  'enter a specific course for this function</font></h3>');
  275: 	}
  276:     }
  277: # -------------------------------------------------------- Choice or no choice?
  278:     if ($nochoose) {
  279:         if ($advanced) {
  280: 	    $r->print("<h2>Assigned User Roles</h2>\n");
  281:         } else {
  282: 	    $r->print("<h2>Sorry ...</h2>\nThis resource might be part of");
  283: 	    if ($ENV{'request.course.id'}) {
  284: 		$r->print(' another');
  285: 	    } else {
  286: 		$r->print(' a certain');
  287: 	    } 
  288: 	    $r->print(' course.</body></html>');
  289: 	    return OK;
  290:         } 
  291:     } else {
  292:         if ($advanced) {
  293: 	    $r->print("Your home server is ".
  294: 		      $Apache::lonnet::hostname{&Apache::lonnet::homeserver
  295:                       ($ENV{'user.name'},$ENV{'user.domain'})}.
  296: 		      "<br />\n");
  297: 	    $r->print("Author and Co-Author roles may not be available on ".
  298: 		      "servers other than your home server.");
  299:         } else {
  300: 	    $r->print("<h2>Select a Course to Enter</h2>\n");
  301:         }
  302:         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
  303:     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
  304:         }
  305:         $r->print('<form method=post action="'.(($fn)?$fn:$r->uri).'">');
  306:         $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
  307:         $r->print('<input type=hidden name=selectrole value=1>');
  308:     }
  309:     $r->print('<br>Show all roles: <input type=checkbox name=showall');
  310:     if ($ENV{'form.showall'}) { $r->print(' checked'); }
  311:     $r->print('><input type=submit value="Display"><br>');
  312: # ----------------------------------------------------------------------- Table
  313:     $r->print('<table><tr>');
  314:     unless ($nochoose) { $r->print('<th>&nbsp;</th>'); }
  315:     $r->print('<th>User Role</th><th colspan=2>Extent</th>'.
  316: 	      '<th>Start</th><th>End</th><th>Remark</th></tr>'."\n");
  317: 
  318:     foreach $envkey (sort keys %ENV) {
  319:         my $button = 1;
  320:         my $switchserver='';
  321:         if ($envkey=~/^user\.role\./) {
  322: 	    my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
  323:             next if (!defined($role) || $role eq '');
  324:             my $where=join('.',@pwhere);
  325:             my $trolecode=$role.'.'.$where;
  326:             my ($tstart,$tend)=split(/\./,$ENV{$envkey});
  327:             my $tremark='';
  328:             my $tstatus='is';
  329:             my $tpstart='&nbsp;';
  330:             my $tpend='&nbsp;';
  331:             my $tfont='#000000';
  332:             if ($tstart) {
  333: 		if ($tstart>$then) { 
  334:                     $tstatus='future';
  335:                     if ($tstart<$now) { $tstatus='will'; }
  336:                 }
  337:                 $tpstart=localtime($tstart);
  338:             }
  339:             if ($tend) {
  340:                 if ($tend<$then) { 
  341:                     $tstatus='expired'; 
  342:                 } elsif ($tend<$now) { 
  343:                     $tstatus='will_not'; 
  344:                 }
  345:                 $tpend=localtime($tend);
  346:             }
  347:             if ($ENV{'request.role'} eq $trolecode) {
  348: 		$tstatus='selected';
  349:             }
  350:             my $tbg;
  351:             if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
  352:                 ($ENV{'form.showall'})) {
  353:                 if ($tstatus eq 'is') {
  354:                     $tbg='#77FF77';
  355:                     $tfont='#003300';
  356:                 } elsif ($tstatus eq 'future') {
  357:                     $tbg='#FFFF77';
  358:                     $button=0;
  359:                 } elsif ($tstatus eq 'will') {
  360:                     $tbg='#FFAA77';
  361:                     $tremark.='Active at next login. ';
  362:                 } elsif ($tstatus eq 'expired') {
  363:                     $tbg='#FF7777';
  364:                     $tfont='#330000';
  365:                     $button=0;
  366:                 } elsif ($tstatus eq 'will_not') {
  367:                     $tbg='#AAFF77';
  368:                     $tremark.='Expired after logout. ';
  369:                 } elsif ($tstatus eq 'selected') {
  370:                     $tbg='#11CC55';
  371:                     $tfont='#002200';
  372:                     $tremark.='Currently selected. ';
  373:                 }
  374:                 my $trole;
  375:                 if ($role =~ /^cr\//) {
  376:                     my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
  377:                     $tremark.='<br>Defined by '.$rauthor.' at '.$rdomain.'.';
  378:                     $trole=$rrole;
  379:                 } else {
  380:                     $trole=Apache::lonnet::plaintext($role);
  381:                 }
  382:                 my $ttype;
  383:                 my $twhere;
  384:                 my ($tdom,$trest,$tsection)=
  385:                     split(/\//,Apache::lonnet::declutter($where));
  386:                 # First, Co-Authorship roles
  387:                 if ($role eq 'ca') {
  388:                     my $home = &Apache::lonnet::homeserver($trest,$tdom);
  389:                     if ($home ne $r->dir_config('lonHostID')) {
  390: 			$button=0;
  391:                         $switchserver=&Apache::lonnet::escape('http://'.
  392:                          $Apache::lonnet::hostname{$home}.
  393:                          '/adm/login?domain='.$ENV{'user.domain'}.
  394: 			  '&username='.$ENV{'user.name'}.
  395:                           '&firsturl=/priv/'.$trest);
  396:                     }
  397:                     #next if ($home eq 'no_host');
  398:                     $home = $Apache::lonnet::hostname{$home};
  399:                     $ttype='Construction Space';
  400:                     $twhere='User: '.$trest.'<br />Domain: '.$tdom.'<br />'.
  401:                         ' Server:&nbsp;'.$home;
  402:                     $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
  403:                 } elsif ($role eq 'au') {
  404:                     # Authors
  405:                     my $home = &Apache::lonnet::homeserver
  406:                         ($ENV{'user.name'},$ENV{'user.domain'});
  407:                     if ($home ne $r->dir_config('lonHostID')) {
  408: 			$button=0;
  409:                         $switchserver=&Apache::lonnet::escape('http://'.
  410:                          $Apache::lonnet::hostname{$home}.
  411:                           '/adm/login?domain='.$ENV{'user.domain'}.
  412: 			   '&username='.$ENV{'user.name'}.
  413:                            '&firsturl=/priv/'.$ENV{'user.name'});
  414:                     }
  415:                     #next if ($home eq 'no_host');
  416:                     $home = $Apache::lonnet::hostname{$home};
  417:                     $ttype='Construction Space';
  418:                     $twhere='Domain: '.$tdom.'<br />Server:&nbsp;'.$home;
  419:                     $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
  420:                 } elsif ($trest) {
  421:                     $ttype='Course';
  422:                     if ($tsection) {
  423:                         $ttype.='<br>Section/Group: '.$tsection;
  424: 		    }
  425:                     my $tcourseid=$tdom.'_'.$trest;
  426:                     if ($ENV{'course.'.$tcourseid.'.description'}) {
  427:                         $twhere=$ENV{'course.'.$tcourseid.'.description'};
  428:                         unless ($twhere eq 'Currently not available') {
  429: 			    $twhere.=' <font size="-2">'.
  430:         &Apache::loncommon::syllabuswrapper('Syllabus',$trest,$tdom,$tfont).
  431:                                     '</font>';
  432: 			}
  433:                     } else {
  434:                         my %newhash=Apache::lonnet::coursedescription
  435:                             ($tcourseid);
  436:                         if (%newhash) {
  437:                             $twhere=$newhash{'description'}.
  438:                               ' <font size="-2">'.
  439:         &Apache::loncommon::syllabuswrapper('Syllabus',$trest,$tdom,$tfont).
  440:                               '</font>';
  441:                         } else {
  442:                             $twhere='Currently not available';
  443:                             $ENV{'course.'.$tcourseid.'.description'}=$twhere;
  444:                         }
  445:                     }
  446: 		    if ($role ne 'st') { $twhere.="<br />Domain:".$tdom; }
  447:                 } elsif ($tdom) {
  448:                     $ttype='Domain';
  449:                     $twhere=$tdom;
  450:                 } else {
  451:                     $ttype='System';
  452:                     $twhere='system wide';
  453:                 }
  454:  
  455:                 $r->print('<tr bgcolor='.$tbg.'>');
  456:                 unless ($nochoose) {
  457:                     if (!$button) {
  458: 			if ($switchserver) {
  459: 			    $r->print('<td><a href="/adm/logout?handover='.
  460:                               $switchserver.'">Switch Server</a></td>');
  461:                         } else {
  462:                             $r->print('<td>&nbsp;</td>');
  463:                         }
  464:                     } elsif ($tstatus eq 'is') {
  465:                         $r->print('<td><input type=submit value=Select name="'.
  466:                                   $trolecode.'"></td>');
  467:                     } elsif ($tryagain) {
  468:                         $r->print
  469:                         ('<td><input type=submit value="Try Selecting Again"'.
  470:                              ' name="'.$trolecode.'"></td>');
  471:                     } elsif ($advanced) {
  472:                         $r->print
  473:                             ('<td><input type=submit value="Re-Initialize"'.
  474:                              ' name="'.$trolecode.'"></td>');
  475:                     } else {
  476:                         $r->print('<td>&nbsp;</td>');
  477:                     }
  478:                 }
  479:                 $tremark.=&Apache::lonannounce::showday(time,1,
  480:                          &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
  481:                 
  482: 		$r->print('<td><font color="'.$tfont.'">'.$trole.
  483:                       '</font></td><td><font color="'.$tfont.'">'.$ttype.
  484:                       '</font></td><td><font color="'.$tfont.'">'.$twhere.
  485:                       '</font></td><td><font color="'.$tfont.'">'.$tpstart.
  486:                       '</font></td><td><font color="'.$tfont.'">'.$tpend.
  487:                       '</font></td><td><font color="'.$tfont.'">'.$tremark.
  488:                       '&nbsp;</font></td></tr>'."\n");
  489: 	    }
  490:         }
  491:     }
  492:     my $tremark='';
  493:     my $tfont='#003300';
  494:     if ($ENV{'request.role'} eq 'cm') {
  495: 	$r->print('<tr bgcolor="#11CC55">');
  496:         $tremark='Currently selected.';
  497:         $tfont='#002200';
  498:     } else {
  499:         $r->print('<tr bgcolor="#77FF77">');
  500:     }
  501:     unless ($nochoose) {
  502: 	if ($ENV{'request.role'} ne 'cm') {
  503: 	    $r->print('<td><input type=submit value=Select name="cm"></td>');
  504: 	} else {
  505: 	    $r->print('<td>&nbsp;</td>');
  506: 	}
  507:     }
  508:     $r->print('<td colspan=5><font color="'.$tfont.'">No role specified'.
  509:       '</font></td><td><font color="'.$tfont.'">'.$tremark.
  510:       '&nbsp;</font></td></tr>'."\n");
  511: 
  512:     $r->print('</table>');
  513:     unless ($nochoose) {
  514: 	$r->print("</form>\n");
  515:     }
  516: # ------------------------------------------------------------ Privileges Info
  517:     if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
  518: 	$r->print('<hr><h2>Current Privileges</h2>');
  519: 
  520: 	foreach $envkey (sort keys %ENV) {
  521: 	    if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
  522: 		my $where=$envkey;
  523: 		$where=~s/^user\.priv\.$ENV{'request.role'}\.//;
  524: 		my $ttype;
  525: 		my $twhere;
  526: 		my ($tdom,$trest,$tsec)=
  527: 		    split(/\//,Apache::lonnet::declutter($where));
  528: 		if ($trest) {
  529: 		    if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
  530: 			$ttype='Construction Space';
  531: 			$twhere='User: '.$trest.', Domain: '.$tdom;
  532: 		    } else {
  533: 			$ttype='Course';
  534: 			$twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
  535: 			if ($tsec) {
  536: 			    $twhere.=' (Section/Group: '.$tsec.')';
  537: 			}
  538: 		    }
  539: 		} elsif ($tdom) {
  540: 		    $ttype='Domain';
  541: 		    $twhere=$tdom;
  542: 		} else {
  543: 		    $ttype='System';
  544: 		    $twhere='/';
  545: 		}
  546: 		$r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
  547: 		foreach (sort split(/:/,$ENV{$envkey})) {
  548: 		    if ($_) {
  549: 			my ($prv,$restr)=split(/\&/,$_);
  550: 			my $trestr='';
  551: 			if ($restr ne 'F') {
  552: 			    my $i;
  553: 			    $trestr.=' (';
  554: 			    for ($i=0;$i<length($restr);$i++) {
  555: 				$trestr.=
  556: 			       Apache::lonnet::plaintext(substr($restr,$i,1));
  557: 				if ($i<length($restr)-1) { $trestr.=', '; }
  558: 			    }
  559: 			    $trestr.=')';
  560: 			}
  561: 			$r->print('<li>'.
  562: 				  Apache::lonnet::plaintext($prv).$trestr.
  563: 				  '</li>');
  564: 		    }
  565: 		}
  566: 		$r->print('</ul>');
  567: 	    }
  568: 	}
  569:     }
  570: 
  571:     $r->print("</body></html>\n");
  572:     return OK;
  573: } 
  574: 
  575: 1;
  576: __END__
  577: 
  578: =head1 NAME
  579: 
  580: Apache::lonroles - User Roles Screen
  581: 
  582: =head1 SYNOPSIS
  583: 
  584: Invoked by /etc/httpd/conf/srm.conf:
  585: 
  586:  <Location /adm/roles>
  587:  PerlAccessHandler       Apache::lonacc
  588:  SetHandler perl-script
  589:  PerlHandler Apache::lonroles
  590:  ErrorDocument     403 /adm/login
  591:  ErrorDocument	  500 /adm/errorhandler
  592:  </Location>
  593: 
  594: =head1 INTRODUCTION
  595: 
  596: This module enables a user to select what role he wishes to
  597: operate under (instructor, student, teaching assistant, course
  598: coordinator, etc).  These roles are pre-established by the actions
  599: of upper-level users.
  600: 
  601: This is part of the LearningOnline Network with CAPA project
  602: described at http://www.lon-capa.org.
  603: 
  604: =head1 HANDLER SUBROUTINE
  605: 
  606: This routine is called by Apache and mod_perl.
  607: 
  608: =over 4
  609: 
  610: =item *
  611: 
  612: Roles Initialization (yes/no)
  613: 
  614: =item *
  615: 
  616: Get Error Message from Environment
  617: 
  618: =item *
  619: 
  620: Who is this?
  621: 
  622: =item *
  623: 
  624: Generate Page Output
  625: 
  626: =item *
  627: 
  628: Choice or no choice
  629: 
  630: =item *
  631: 
  632: Table
  633: 
  634: =item *
  635: 
  636: Privileges
  637: 
  638: =back
  639: 
  640: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>