File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.105: download - view: text, annotated - select for diffs
Tue Nov 9 20:04:48 2004 UTC (19 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Changes made during a house call by the style police

    1: # The LearningOnline Network with CAPA
    2: # User Roles Screen
    3: #
    4: # $Id: lonroles.pm,v 1.105 2004/11/09 20:04:48 raeburn 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: ###
   29: 
   30: package Apache::lonroles;
   31: 
   32: use strict;
   33: use Apache::lonnet();
   34: use Apache::lonuserstate();
   35: use Apache::Constants qw(:common);
   36: use Apache::File();
   37: use Apache::lonmenu;
   38: use Apache::loncommon;
   39: use Apache::lonhtmlcommon;
   40: use Apache::lonannounce;
   41: use Apache::lonlocal;
   42: 
   43: sub redirect_user {
   44:     my ($r,$title,$url,$msg,$launch_nav) = @_;
   45:     $msg = $title if (! defined($msg));
   46:     &Apache::loncommon::content_type($r,'text/html');
   47:     &Apache::loncommon::no_cache($r);
   48:     $r->send_http_header;
   49:     my $swinfo=&Apache::lonmenu::rawconfig();
   50:     my $navwindow;
   51:     if ($launch_nav eq 'on') {
   52: 	$navwindow.=&Apache::lonnavmaps::launch_win('now');
   53:     } else {
   54: 	$navwindow.=&Apache::lonnavmaps::close();
   55:     }
   56:     my $bodytag=&Apache::loncommon::bodytag('Switching Role');
   57: # Note to style police: 
   58: # This must only replace the spaces, nothing else, or it bombs elsewhere.
   59:     $url=~s/ /\%20/g;
   60:     $r->print(<<ENDREDIR);
   61: <head><title>$title</title>
   62: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$url">
   63: </head>
   64: <html>
   65: $bodytag
   66: <script type="text/javascript">
   67: $swinfo
   68: </script>
   69: $navwindow
   70: <h1>$msg</h1>
   71: <a href="$url">Continue</a>
   72: </body>
   73: </html>
   74: ENDREDIR
   75:     return;
   76: }
   77: 
   78: sub handler {
   79: 
   80:     my $r = shift;
   81: 
   82:     my $now=time;
   83:     my $then=$ENV{'user.login.time'};
   84:     my $envkey;
   85:     my $dcselect='';
   86: 
   87: 
   88: # ================================================================== Roles Init
   89:     if ($ENV{'form.selectrole'}) {
   90:         if ($ENV{'form.dcselected'}) {
   91:             my $dcdom = $ENV{'form.dcselected'};
   92:             my $dckey = 'user.role.dc./'.$dcdom.'/';
   93:             if ($ENV{$dckey}) {
   94:                 my ($dcstart,$dcend)=split(/\./,$ENV{$dckey});
   95:                 my $active_dc = 1;
   96:                 if ($dcstart) {
   97:                     if ($dcstart>$then) {
   98:                         $active_dc = 0;
   99:                     }
  100:                 }
  101:                 if ($dcend) {
  102:                     if ($dcend < $then) {
  103:                         $active_dc = 0;
  104:                     }
  105:                 }
  106:                 if ($active_dc) {
  107:                     $dcselect = $dcdom;
  108:                 }
  109:             }
  110:         }
  111: 	if ($ENV{'request.course.id'}) {
  112: 	    my %temp=('logout_'.$ENV{'request.course.id'} => time);
  113: 	    &Apache::lonnet::put('email_status',\%temp);
  114: 	    &Apache::lonnet::delenv('user.state.'.$ENV{'request.course.id'});
  115: 	}
  116: 	&Apache::lonnet::appenv("request.course.id"   => '',
  117: 				"request.course.fn"   => '',
  118: 				"request.course.uri"  => '',
  119: 				"request.course.sec"  => '',
  120: 				"request.role"        => 'cm',
  121:                                 "request.role.adv"    => $ENV{'user.adv'},
  122: 				"request.role.domain" => $ENV{'user.domain'});
  123:         foreach $envkey (keys %ENV) {
  124:             next if ($envkey!~/^user\.role\./);
  125:             my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
  126:             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
  127:             if ($ENV{'form.'.$trolecode}) {
  128: 		if ($tstatus eq 'is') {
  129: 		    $where=~s/^\///;
  130: 		    my ($cdom,$cnum,$csec)=split(/\//,$where);
  131: # check for keyed access
  132: 		    if (($role eq 'st') && 
  133:                        ($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
  134: # who is key authority?
  135: 			my $authdom=$cdom;
  136: 			my $authnum=$cnum;
  137: 			if ($ENV{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
  138: 			    ($authnum,$authdom)=
  139: 				split(/\W/,$ENV{'course.'.$cdom.'_'.$cnum.'.keyauth'});
  140: 			}
  141: # check with key authority
  142: 			unless (&Apache::lonnet::validate_access_key(
  143: 				     $ENV{'environment.key.'.$cdom.'_'.$cnum},
  144: 					     $authdom,$authnum)) {
  145: # there is no valid key
  146: 			     if ($ENV{'form.newkey'}) {
  147: # student attempts to register a new key
  148: 				 &Apache::loncommon::content_type($r,'text/html');
  149: 				 &Apache::loncommon::no_cache($r);
  150: 				 $r->send_http_header;
  151: 				 my $swinfo=&Apache::lonmenu::rawconfig();
  152: 				 my $bodytag=&Apache::loncommon::bodytag
  153: 				    ('Verifying Access Key to Unlock this Course');
  154: 				 my $buttontext=&mt('Enter Course');
  155: 				 my $message=&mt('Successfully registered key');
  156: 				 my $assignresult=
  157: 				     &Apache::lonnet::assign_access_key(
  158: 						     $ENV{'form.newkey'},
  159: 						     $authdom,$authnum,
  160: 						     $cdom,$cnum,
  161:                                                      $ENV{'user.domain'},
  162: 						     $ENV{'user.name'},
  163: 	      'Assigned from '.$ENV{'REMOTE_ADDR'}.' at '.localtime().' for '.
  164:                                                      $trolecode);
  165: 				 unless ($assignresult eq 'ok') {
  166: 				     $assignresult=~s/^error\:\s*//;
  167: 				     $message=&mt($assignresult).
  168: 				     '<br /><a href="/adm/logout">'.
  169: 				     &mt('Logout').'</a>';
  170: 				     $buttontext=&mt('Re-Enter Key');
  171: 				 }
  172: 				 $r->print(<<ENDENTEREDKEY);
  173: <head><title>Verifying Course Access Key</title>
  174: </head>
  175: <html>
  176: $bodytag
  177: <script>
  178: $swinfo
  179: </script>
  180: <form method="post">
  181: <input type="hidden" name="selectrole" value="1" />
  182: <input type="hidden" name="$trolecode" value="1" />
  183: <font size="+2">$message</font><br />
  184: <input type="submit" value="$buttontext" />
  185: </form>
  186: </body></html>
  187: ENDENTEREDKEY
  188:                                  return OK;
  189: 			     } else {
  190: # print form to enter a new key
  191: 				 &Apache::loncommon::content_type($r,'text/html');
  192: 				 &Apache::loncommon::no_cache($r);
  193: 				 $r->send_http_header;
  194: 				 my $swinfo=&Apache::lonmenu::rawconfig();
  195: 				 my $bodytag=&Apache::loncommon::bodytag
  196: 				    ('Enter Access Key to Unlock this Course');
  197: 				 $r->print(<<ENDENTERKEY);
  198: <head><title>Entering Course Access Key</title>
  199: </head>
  200: <html>
  201: $bodytag
  202: <script>
  203: $swinfo
  204: </script>
  205: <form method="post">
  206: <input type="hidden" name="selectrole" value="1" />
  207: <input type="hidden" name="$trolecode" value="1" />
  208: <input type="text" size="20" name="newkey" value="$ENV{'form.newkey'}" />
  209: <input type="submit" value="Enter key" />
  210: </form>
  211: </body></html>
  212: ENDENTERKEY
  213: 				 return OK;
  214: 			     }
  215: 			 }
  216: 		     }
  217: 		    &Apache::lonnet::log($ENV{'user.domain'},
  218: 					 $ENV{'user.name'},
  219: 					 $ENV{'user.home'},
  220: 					 "Role ".$trolecode);
  221: 		    
  222: 		    &Apache::lonnet::appenv(
  223: 					   'request.role'        => $trolecode,
  224: 					   'request.role.domain' => $cdom,
  225: 					   'request.course.sec'  => $csec);
  226:                     my $tadv=0;
  227: 		    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
  228: 		    &Apache::lonnet::appenv('request.role.adv'    => $tadv);
  229: 
  230: 		    my $msg=&mt('Entering course ...');
  231: 
  232: 		    if (($cnum) && ($role ne 'ca')) {
  233: 			my ($furl,$ferr)=
  234: 			    &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
  235: 			if (($ENV{'form.orgurl'}) && 
  236: 			    ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) {
  237: 			    my $dest=$ENV{'form.orgurl'};
  238: 			    if ( &Apache::lonnet::mod_perl_version() == 2 ) {
  239: 				&Apache::lonnet::cleanenv();
  240: 			    }
  241: 			    $r->internal_redirect($dest);
  242: 			    return OK;
  243: 			} else {
  244: 			    unless ($ENV{'request.course.id'}) {
  245: 				&Apache::lonnet::appenv(
  246: 				      "request.course.id"  => $cdom.'_'.$cnum);
  247: 				$furl='/adm/roles?tryagain=1';
  248: 				$msg=
  249: 				    '<h1><font color=red>'.
  250: 			 &mt('Could not initialize course at this time.').
  251: 		    '</font></h1><h3>'.&mt('Please try again.').'</h3>'.$ferr;
  252: 			    }
  253: 
  254: 			    # Check to see if the user is a CC entering a course 
  255: 			    # for the first time
  256: 			    my (undef, undef, $role, $courseid) = split(/\./, $envkey);
  257: 			    if (substr($courseid, 0, 1) eq '/') {
  258: 				$courseid = substr($courseid, 1);
  259: 			    }
  260: 			    $courseid =~ s/\//_/;
  261: 			    if ($role eq 'cc' && $ENV{'course.' . $courseid . 
  262: 							  '.course.helper.not.run'}) {
  263: 				$furl = "/adm/helper/course.initialization.helper";
  264: 			    }
  265:                             # Check to see if the user is a DC coming from the
  266:                             # course selection page
  267:                             my $dcflag = 0;
  268:                             if ($ENV{'form.dccourse'}) {
  269:                                 my $formaction = '/adm/roles/';
  270:                                 my ($dcdom,$pickedcourse) = split/_/,$courseid;
  271:                                 if ($ENV{'user.role.dc./'.$dcdom.'/'}) {
  272:                                     &Apache::lonhtmlcommon::store_recent('cc_pickby_dc_'.$dcdom,
  273:                                     $courseid,$formaction);
  274:                                 }
  275:                             }
  276:                             #
  277:                             # Send the user to the course they selected
  278:                             &redirect_user($r,&mt('Entering Course'),
  279:                                            $furl,$msg,
  280: 					   $ENV{'environment.remotenavmap'});
  281:                             return OK;
  282: 			}
  283: 		    }
  284:                     #
  285:                     # Send the user to the construction space they selected
  286:                     if ($role =~ /^(au|ca)$/) {
  287:                         my $redirect_url = '/priv/';
  288:                         if ($role eq 'au') {
  289:                             $redirect_url.=$ENV{'user.name'};
  290:                         } else {
  291:                             $where =~ /\/(.*)$/;
  292:                             $redirect_url .= $1;
  293:                         }
  294:                         $redirect_url .= '/';
  295:                         &redirect_user($r,&mt('Entering Construction Space'),
  296:                                        $redirect_url);
  297:                         return OK;
  298:                     }
  299:                     if ($role eq 'dc') {
  300:                         unless ($dcselect) {
  301:                             my $redirect_url = '/adm/menu/';
  302:                             &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
  303:                                        $redirect_url);
  304:                             return OK;
  305:                         }
  306:                     }
  307: 		}
  308:             }
  309:         }
  310:     }
  311: 
  312: 
  313: # =============================================================== No Roles Init
  314: 
  315:     &Apache::loncommon::content_type($r,'text/html');
  316:     &Apache::loncommon::no_cache($r);
  317:     $r->send_http_header;
  318:     return OK if $r->header_only;
  319: 
  320:     my $swinfo=&Apache::lonmenu::rawconfig();
  321:     my $setDCchoice = &dc_script();
  322:     my $bodytag=&Apache::loncommon::bodytag('User Roles');
  323:     my $helptag='<table><tr><td>'.&Apache::loncommon::help_open_menu('','General Intro','General_Intro','User Roles',1,undef,undef,undef,undef,,&mt("Click here for help")).'</td></td></tr></table>';
  324:     $r->print(<<ENDHEADER);
  325: <html>
  326: <head>
  327: <title>LON-CAPA User Roles</title>
  328: </head>
  329: $bodytag
  330: $helptag<br />
  331: <script>
  332: $swinfo
  333: window.focus();
  334: $setDCchoice
  335: </script>
  336: ENDHEADER
  337: 
  338: # ------------------------------------------ Get Error Message from Environment
  339: 
  340:     my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
  341:     if ($ENV{'user.error.msg'}) {
  342: 	$r->log_reason(
  343:    "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
  344:     }
  345: 
  346: # ------------------------------------------------- Can this user re-init, etc?
  347: 
  348:     my $advanced=$ENV{'user.adv'};
  349:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
  350:     my $tryagain=$ENV{'form.tryagain'};
  351: 
  352: # -------------------------------------------------------- Generate Page Output
  353: # -------------------------------------------------------- Domain Coordinator? 
  354:     if ($dcselect ne '') {
  355:         &choosecourse_display($r,$dcselect,$then,$now);
  356:         return OK;
  357:     }
  358: 
  359: # --------------------------------------------------------------- Error Header?
  360:     if ($error) {
  361: 	$r->print("<h1>LON-CAPA Access Control</h1>");
  362:         $r->print("<hr><pre>Access  : ".
  363:                   Apache::lonnet::plaintext($priv)."\n");
  364:         $r->print("Resource: $fn\n");
  365:         $r->print("Action  : $msg\n</pre><hr>");
  366:     } else {
  367:         if ($ENV{'user.error.msg'}) {
  368: 	    $r->print(
  369:  '<h3><font color=red>'.
  370:  &mt('You need to choose another user role or enter a specific course for this function').'</font></h3>');
  371: 	}
  372:     }
  373: # -------------------------------------------------------- Choice or no choice?
  374:     if ($nochoose) {
  375:         if ($advanced) {
  376: 	    $r->print("<h2>".&mt('Assigned User Roles')."</h2>\n");
  377:         } else {
  378: 	    $r->print("<h2>".&mt('Sorry ...')."</h2>\n".
  379: 		      &mt('This resource might be part of'));
  380: 	    if ($ENV{'request.course.id'}) {
  381: 		$r->print(&mt(' another'));
  382: 	    } else {
  383: 		$r->print(&mt(' a certain'));
  384: 	    } 
  385: 	    $r->print(&mt(' course.').'</body></html>');
  386: 	    return OK;
  387:         } 
  388:     } else {
  389:         if ($advanced) {
  390: 	    $r->print(&mt("Your home server is ").
  391: 		      $Apache::lonnet::hostname{&Apache::lonnet::homeserver
  392:                       ($ENV{'user.name'},$ENV{'user.domain'})}.
  393: 		      "<br />\n");
  394: 	    $r->print(&mt(
  395:       "Author and Co-Author roles may not be available on servers other than your home server."));
  396:         }
  397:         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
  398:     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
  399:         }
  400:         $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
  401:         $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
  402:         $r->print('<input type=hidden name=selectrole value=1>');
  403:     }
  404:     if ($ENV{'user.adv'}) {
  405: 	$r->print(
  406: 	      '<br />'.&mt('Show all roles').': <input type="checkbox" name="showall"');
  407: 	if ($ENV{'form.showall'}) { $r->print(' checked'); }
  408: 	$r->print('><input type=submit value="'.&mt('Display').'">');
  409:     }
  410: 
  411:     my %dcroles = ();
  412:     my $numdc = &check_fordc(\%dcroles,$then);
  413: 
  414:     my (%roletext,%sortrole,%roleclass);
  415:     my $countactive=0;
  416:     my $inrole=0;
  417:     my $possiblerole='';
  418:     foreach $envkey (sort keys %ENV) {
  419:         my $button = 1;
  420:         my $switchserver='';
  421: 	my $roletext;
  422: 	my $sortkey;
  423:         if ($envkey=~/^user\.role\./) {
  424:             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
  425:             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
  426:             next if (!defined($role) || $role eq '');
  427:             $tremark='';
  428:             $tpstart='&nbsp;';
  429:             $tpend='&nbsp;';
  430:             $tfont='#000000';
  431:             if ($tstart) {
  432:                 $tpstart=&Apache::lonlocal::locallocaltime($tstart);
  433:             }
  434:             if ($tend) {
  435:                 $tpend=&Apache::lonlocal::locallocaltime($tend);
  436:             }
  437:             if ($ENV{'request.role'} eq $trolecode) {
  438: 		$tstatus='selected';
  439:             }
  440:             my $tbg;
  441:             if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
  442:                 ($ENV{'form.showall'})) {
  443:                 if ($tstatus eq 'is') {
  444:                     $tbg='#77FF77';
  445:                     $tfont='#003300';
  446: 		    $possiblerole=$trolecode;
  447: 		    $countactive++;
  448:                 } elsif ($tstatus eq 'future') {
  449:                     $tbg='#FFFF77';
  450:                     $button=0;
  451:                 } elsif ($tstatus eq 'will') {
  452:                     $tbg='#FFAA77';
  453:                     $tremark.=&mt('Active at next login. ');
  454:                 } elsif ($tstatus eq 'expired') {
  455:                     $tbg='#FF7777';
  456:                     $tfont='#330000';
  457:                     $button=0;
  458:                 } elsif ($tstatus eq 'will_not') {
  459:                     $tbg='#AAFF77';
  460:                     $tremark.=&mt('Expired after logout. ');
  461:                 } elsif ($tstatus eq 'selected') {
  462:                     $tbg='#11CC55';
  463:                     $tfont='#002200';
  464: 		    $inrole=1;
  465: 		    $countactive++;
  466:                     $tremark.=&mt('Currently selected. ');
  467:                 }
  468:                 my $trole;
  469:                 if ($role =~ /^cr\//) {
  470:                     my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
  471:                     $tremark.='<br>'.&mt('Defined by ').$rauthor.
  472: 			&mt(' at ').$rdomain.'.';
  473:                     $trole=$rrole;
  474:                 } else {
  475:                     $trole=Apache::lonnet::plaintext($role);
  476:                 }
  477:                 my $ttype;
  478:                 my $twhere;
  479:                 my ($tdom,$trest,$tsection)=
  480:                     split(/\//,Apache::lonnet::declutter($where));
  481:                 # First, Co-Authorship roles
  482:                 if ($role eq 'ca') {
  483:                     my $home = &Apache::lonnet::homeserver($trest,$tdom);
  484: 		    my $allowed=0;
  485: 		    my @ids=&Apache::lonnet::current_machine_ids();
  486: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  487:                     if (!$allowed) {
  488: 			$button=0;
  489:                         $switchserver=&Apache::lonnet::escape('http://'.
  490:                          $Apache::lonnet::hostname{$home}.
  491:                          '/adm/login?domain='.$ENV{'user.domain'}.
  492: 			  '&username='.$ENV{'user.name'}.
  493:                           '&firsturl=/priv/'.$trest.'/');
  494:                     }
  495:                     #next if ($home eq 'no_host');
  496:                     $home = $Apache::lonnet::hostname{$home};
  497:                     $ttype='Construction Space';
  498:                     $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
  499: 			': '.$tdom.'<br />'.
  500:                         ' '.&mt('Server').':&nbsp;'.$home;
  501:                     $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
  502: 		    $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
  503: 		    $sortkey=$role."$trest:$tdom";
  504:                 } elsif ($role eq 'au') {
  505:                     # Authors
  506:                     my $home = &Apache::lonnet::homeserver
  507:                         ($ENV{'user.name'},$ENV{'user.domain'});
  508: 		    my $allowed=0;
  509: 		    my @ids=&Apache::lonnet::current_machine_ids();
  510: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  511:                     if (!$allowed) {
  512: 			$button=0;
  513:                         $switchserver=&Apache::lonnet::escape('http://'.
  514:                          $Apache::lonnet::hostname{$home}.
  515:                           '/adm/login?domain='.$ENV{'user.domain'}.
  516: 			   '&username='.$ENV{'user.name'}.
  517:                            '&firsturl=/priv/'.$ENV{'user.name'}.'/');
  518:                     }
  519:                     #next if ($home eq 'no_host');
  520:                     $home = $Apache::lonnet::hostname{$home};
  521:                     $ttype='Construction Space';
  522:                     $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
  523: 			':&nbsp;'.$home;
  524:                     $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
  525: 		    $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$ENV{'user.name'}.'/');
  526: 		    $sortkey=$role;
  527:                 } elsif ($trest) {
  528:                     $ttype='Course';
  529:                     if ($tsection) {
  530:                         $ttype.='<br>'.&mt('Section/Group').': '.$tsection;
  531: 		    }
  532:                     my $tcourseid=$tdom.'_'.$trest;
  533:                     if ($ENV{'course.'.$tcourseid.'.description'}) {
  534:                         $twhere=$ENV{'course.'.$tcourseid.'.description'};
  535: 			$sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
  536:                         unless ($twhere eq &mt('Currently not available')) {
  537: 			    $twhere.=' <font size="-2">'.
  538:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
  539:                                     '</font>';
  540: 			}
  541:                     } else {
  542:                         my %newhash=&Apache::lonnet::coursedescription($tcourseid);
  543:                         if (%newhash) {
  544: 			    $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
  545: 				"\0".$envkey;
  546:                             $twhere=$newhash{'description'}.
  547:                               ' <font size="-2">'.
  548:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
  549:                               '</font>';
  550:                         } else {
  551:                             $twhere=&mt('Currently not available');
  552:                             $ENV{'course.'.$tcourseid.'.description'}=$twhere;
  553: 			    $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
  554:                         }
  555:                     }
  556: 		    if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
  557:                 } elsif ($tdom) {
  558:                     $ttype='Domain';
  559:                     $twhere=$tdom;
  560: 		    $sortkey=$role.$twhere;
  561:                 } else {
  562:                     $ttype='System';
  563:                     $twhere=&mt('system wide');
  564: 		    $sortkey=$role.$twhere;
  565:                 }
  566:  
  567:                 $roletext.='<tr bgcolor='.$tbg.'>';
  568:                 unless ($nochoose) {
  569:                     if (!$button) {
  570: 			if ($switchserver) {
  571: 			    $roletext.='<td><a href="/adm/logout?handover='.
  572:                               $switchserver.'">'.&mt('Switch Server').'</a></td>';
  573:                         } else {
  574:                             $roletext.=('<td>&nbsp;</td>');
  575:                         }
  576:                     } elsif ($tstatus eq 'is') {
  577:                         $roletext.=('<td><input type=submit value="'.
  578: 				  &mt('Select').'" name="'.
  579:                                   $trolecode.'"></td>');
  580:                     } elsif ($tryagain) {
  581:                         $roletext.=
  582: 			    '<td><input type=submit value="'.
  583: 		  &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
  584:                     } elsif ($advanced) {
  585:                         $roletext.=
  586:                             '<td><input type=submit value="'.
  587: 		        &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
  588:                     } else {
  589:                         $roletext.='<td>&nbsp;</td>';
  590:                     }
  591:                 }
  592:                 $tremark.=&Apache::lonannounce::showday(time,1,
  593:                          &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
  594:                 
  595: 		$roletext.='<td><font color="'.$tfont.'">'.$trole.
  596:                       '</font></td><td><font color="'.$tfont.'">'.$ttype.
  597:                       '</font></td><td><font color="'.$tfont.'">'.$twhere.
  598:                       '</font></td><td><font color="'.$tfont.'">'.$tpstart.
  599:                       '</font></td><td><font color="'.$tfont.'">'.$tpend.
  600:                       '</font></td><td><font color="'.$tfont.'">'.$tremark.
  601:                       '&nbsp;</font></td></tr>'."\n";
  602: 		$roletext{$envkey}=$roletext;
  603: 		if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
  604: 		$sortrole{$sortkey}=$envkey;
  605: 		$roleclass{$envkey}=$ttype;
  606: 	    }
  607:         }
  608:     }
  609: # No active roles
  610:     if ($countactive==0) {
  611: 	if ($inrole) {
  612: 	    $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
  613: 	} else {
  614: 	    $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
  615: 	}
  616: 	$r->print('</form></body></html>');
  617: 	return OK;
  618: # Is there only one choice?
  619:     } elsif (($countactive==1) && ($ENV{'request.role'} eq 'cm')) {
  620: 	$r->print('<h3>'.&mt('Please stand by.').'</h3>'.
  621: 	    '<input type="hidden" name="'.$possiblerole.'" value="1" />');
  622: 	$r->print("</form>\n");
  623: 	$r->rflush();
  624: 	$r->print('<script>document.forms.rolechoice.submit();</script>');
  625: 	$r->print('</body></html>');
  626: 	return OK;
  627:     }
  628: # More than one possible role
  629: # ----------------------------------------------------------------------- Table
  630:     unless (($advanced) || ($nochoose)) {
  631: 	$r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
  632:     }
  633:     $r->print('<br /><table><tr>');
  634:     unless ($nochoose) { $r->print('<th>&nbsp;</th>'); }
  635:     $r->print('<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
  636:          '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
  637: 	      &mt('Remarks and Calendar Announcements').'</th></tr>'."\n");
  638:     my $doheaders=-1;
  639:     foreach my $type ('Construction Space','Course','Domain','System') {
  640: 	my $haverole=0;
  641: 	foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
  642: 	    if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { 
  643: 		$haverole=1;
  644: 	    }
  645: 	}
  646: 	if ($haverole) { $doheaders++; }
  647:     }
  648:     if ($numdc > 0) {
  649:          $r->print('<tr bgcolor="#BBffBB">'.
  650:                       '<td align="center" colspan="7">'.
  651:                       '<input type="hidden" name="all_cc_roles" value="1"/>'.
  652:                       '<input type="hidden" name="dcselected" value=""/>'.
  653:                       &mt('Domain').'</td>');
  654:          foreach my $dcdom (keys %dcroles) {
  655:              my $output = $roletext{$dcroles{$dcdom}};
  656:              my $ccrole = Apache::lonnet::plaintext('cc');
  657:              if ($ENV{'request.role'} =~ m-cc\./$dcdom/-) {
  658:                  $output.=$roletext{'user.role.'.$ENV{'request.role'}};
  659:              }
  660:              $r->print($output);
  661:              $r->print('<tr bgcolor="#77FF77">');
  662:              $r->print('<td><input type="button" value="'.
  663:                       &mt('Select').'" name="dcpick_'.$dcdom.'/" '.
  664:                       'onClick="setDCchoice('."'$dcdom'".')"></td>'.
  665:                       '<td><font color="#002200">'.
  666:                       $ccrole.'</font></td><td>'.&mt('Course').'</td>'.
  667:                       '<td><font color="#002200"><b>'.&mt('All courses').'</b>'.
  668:                       '<br />'.&mt('Domain').':'.$dcdom.'</font>'.
  669:                       '<td colspan="4"><font color="#002200">'.
  670:                       &mt('Course Coordinator access to all courses in domain').
  671:                       ': <b>'.$dcdom.'</b></font></td></tr>'."\n");
  672:          }
  673:          foreach my $type ('Construction Space','Course','Domain','System') {
  674:              my $output;
  675:              foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
  676:                 my $skiprole = 0;
  677:                 foreach my $dcdom (keys %dcroles) {
  678:                     if ($sortrole{$which} =~ m-(dc|cc)\./$dcdom/-) {
  679:                         $skiprole = 1;
  680:                         last;
  681:                     }
  682:                 }
  683:                 if (($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) && (!$skiprole)) {
  684:                     $output.=$roletext{$sortrole{$which}};
  685:                 }
  686:             }
  687:             if ($output) {
  688:                 if ($doheaders > 0) {
  689:                     $r->print("<tr bgcolor='#BBffBB'>".
  690:                           "<td align='center' colspan='7'>".&mt($type)."</td>
  691: ");
  692:                 }
  693:                 $r->print($output);
  694:             }
  695:         }
  696:     } else {
  697:         foreach my $type ('Construction Space','Course','Domain','System') {
  698: 	    my $output;
  699: 	    foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
  700: 	        if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { 
  701: 		    $output.=$roletext{$sortrole{$which}};
  702: 	        }
  703: 	    }
  704: 	    if ($output) {
  705: 	        if ($doheaders > 0) {
  706: 		    $r->print("<tr bgcolor='#BBffBB'>".
  707: 			      "<td align='center' colspan='7'>".&mt($type)."</td>");
  708: 	        }
  709: 	        $r->print($output);	    
  710: 	    }
  711:         }
  712:     }
  713:     my $tremark='';
  714:     my $tfont='#003300';
  715:     if ($ENV{'request.role'} eq 'cm') {
  716: 	$r->print('<tr bgcolor="#11CC55">');
  717:         $tremark=&mt('Currently selected. ');
  718:         $tfont='#002200';
  719:     } else {
  720:         $r->print('<tr bgcolor="#77FF77">');
  721:     }
  722:     unless ($nochoose) {
  723: 	if ($ENV{'request.role'} ne 'cm') {
  724: 	    $r->print('<td><input type=submit value="'.
  725: 		      &mt('Select').'" name="cm"></td>');
  726: 	} else {
  727: 	    $r->print('<td>&nbsp;</td>');
  728: 	}
  729:     }
  730:     $r->print('<td colspan=5><font color="'.$tfont.'">'.&mt('No role specified').
  731:       '</font></td><td><font color="'.$tfont.'">'.$tremark.
  732:       '&nbsp;</font></td></tr>'."\n");
  733: 
  734:     $r->print('</table>');
  735:     unless ($nochoose) {
  736: 	$r->print("</form>\n");
  737:     }
  738: # ------------------------------------------------------------ Privileges Info
  739:     if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
  740: 	$r->print('<hr><h2>Current Privileges</h2>');
  741: 
  742: 	foreach $envkey (sort keys %ENV) {
  743: 	    if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
  744: 		my $where=$envkey;
  745: 		$where=~s/^user\.priv\.$ENV{'request.role'}\.//;
  746: 		my $ttype;
  747: 		my $twhere;
  748: 		my ($tdom,$trest,$tsec)=
  749: 		    split(/\//,Apache::lonnet::declutter($where));
  750: 		if ($trest) {
  751: 		    if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
  752: 			$ttype='Construction Space';
  753: 			$twhere='User: '.$trest.', Domain: '.$tdom;
  754: 		    } else {
  755: 			$ttype='Course';
  756: 			$twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
  757: 			if ($tsec) {
  758: 			    $twhere.=' (Section/Group: '.$tsec.')';
  759: 			}
  760: 		    }
  761: 		} elsif ($tdom) {
  762: 		    $ttype='Domain';
  763: 		    $twhere=$tdom;
  764: 		} else {
  765: 		    $ttype='System';
  766: 		    $twhere='/';
  767: 		}
  768: 		$r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
  769: 		foreach (sort split(/:/,$ENV{$envkey})) {
  770: 		    if ($_) {
  771: 			my ($prv,$restr)=split(/\&/,$_);
  772: 			my $trestr='';
  773: 			if ($restr ne 'F') {
  774: 			    my $i;
  775: 			    $trestr.=' (';
  776: 			    for ($i=0;$i<length($restr);$i++) {
  777: 				$trestr.=
  778: 			       Apache::lonnet::plaintext(substr($restr,$i,1));
  779: 				if ($i<length($restr)-1) { $trestr.=', '; }
  780: 			    }
  781: 			    $trestr.=')';
  782: 			}
  783: 			$r->print('<li>'.
  784: 				  Apache::lonnet::plaintext($prv).$trestr.
  785: 				  '</li>');
  786: 		    }
  787: 		}
  788: 		$r->print('</ul>');
  789: 	    }
  790: 	}
  791:     }
  792:     $r->print(&Apache::lonnet::getannounce());
  793:     if ($advanced) {
  794: 	$r->print('<p><small><i>This is LON-CAPA '.
  795: 		  $r->dir_config('lonVersion').'</i><br />'.
  796: 		  '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
  797:     }
  798:     $r->print("</body></html>\n");
  799:     return OK;
  800: }
  801: 
  802: sub role_status {
  803:     my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
  804:     my @pwhere = ();
  805:     if (exists($ENV{$rolekey}) && $ENV{$rolekey} ne '') {
  806:         (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
  807:         unless (!defined($$role) || $$role eq '') {
  808:             $$where=join('.',@pwhere);
  809:             $$trolecode=$$role.'.'.$$where;
  810:             ($$tstart,$$tend)=split(/\./,$ENV{$rolekey});
  811:             $$tstatus='is';
  812:             if ($$tstart && $$tstart>$then) {
  813: 		$$tstatus='future';
  814: 		if ($$tstart<$now) { $$tstatus='will'; }
  815:             }
  816:             if ($$tend) {
  817:                 if ($$tend<$then) {
  818:                     $$tstatus='expired';
  819:                 } elsif ($$tend<$now) {
  820:                     $$tstatus='will_not';
  821:                 }
  822:             }
  823:         }
  824:     }
  825: }
  826: 
  827: sub dc_script {
  828:     my $response = (<<"END");
  829: function setDCchoice(caller) {
  830:     var dcname = "dc./"+caller+"/"
  831:     document.rolechoice.dcselected.value = caller
  832:     document.rolechoice.elements[3].name = dcname
  833:     document.rolechoice.submit()
  834: }
  835: END
  836:     return $response;
  837: }
  838:                                                                                  
  839: sub check_fordc {
  840:     my ($dcroles,$then) = @_;
  841:     my $numdc = 0;
  842:     if ($ENV{'user.adv'}) {
  843:         foreach my $envkey (sort keys %ENV) {
  844:             if ($envkey=~/^user\.role\.dc\.\/(\w+)\/$/) {
  845:                 my $dcdom = $1;
  846:                 my $livedc = 1;
  847:                 my ($tstart,$tend)=split(/\./,$ENV{$envkey});
  848:                 if ($tstart && $tstart>$then) { $livedc = 0; }
  849:                 if ($tend   && $tend  <$then) { $livedc = 0; }
  850:                 if ($livedc) {
  851:                     $$dcroles{$dcdom} = $envkey;
  852:                     $numdc++;
  853:                 }
  854:             }
  855:         }
  856:     }
  857:     return $numdc;
  858: }
  859: 
  860: sub choosecourse_display {
  861:     my ($r,$dcdom,$then,$now) = @_;
  862:     my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'dom');
  863:     my $verify_script = <<"END";
  864: <script>
  865: function verifyCoursePick() {
  866:     var pickedCourse = document.roles.dccourse.value
  867:     var pickedDomain = document.roles.dcdomain.value
  868:     if (document.roles.dcdomain.value == document.roles.origdom.value) {
  869:         if (pickedCourse != '') {
  870:             var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
  871:             document.roles.elements[0].value = 1
  872:             document.roles.elements[0].name = courseTarget
  873:             document.roles.selectrole.value = 1
  874:             document.roles.submit()
  875:         }
  876:         else {
  877:             alert("You must use the 'Select Course' link to open a separate pick course window which you can use to select the course you wish to enter");
  878:         }
  879:     }
  880:     else {
  881:         alert("You can only use this screen to select courses in the current domain")
  882:     }
  883: }
  884: </script>
  885: END
  886:     my $courseform=&Apache::loncommon::selectcourse_link
  887:                      ('roles','dccourse','dcdomain','coursedesc');
  888:     $r->print($cb_jscript.$verify_script);
  889:     my $formaction='/adm/roles';
  890:     $formaction=~s/\/+/\//g;
  891:     my $crs;
  892:     &select_recent_courses($r,$dcdom,$then,$now);
  893:     $r->print('<br /><form name="roles" method="post" action="'.$formaction.'" />');
  894:     $r->print('<h3>'.&mt('Choose a course from domain').': '.$dcdom.'</h3><font size="+1">'.$courseform.'</font><br /><br />'.
  895:               '<input type="hidden" name="chosencourse" value=""/>'.
  896:               'Course Title: <input type="text" size="20" name="coursedesc" value=""><br />'.
  897:               'Course ID: <input type="text" size="15" name="dccourse" />'.
  898:               '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
  899:               '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
  900:               '<input type="hidden" name="selectrole" value="" />'.
  901:               '<br /><br /><input type="button" name="proceed" value="'.&mt('Enter this course').'" onClick="verifyCoursePick()" />'.
  902:               '</form>');
  903:     return;
  904: }
  905: 
  906: sub select_recent_courses {
  907:     my ($r,$dcdom,$then,$now)=@_;
  908:     my $advanced = $ENV{'user.adv'};
  909:     my $tryagain = $ENV{'form.tryagain'};
  910:     my %recent=&Apache::lonnet::dump(&recent_filename('cc_pickby_dc_'.$dcdom));
  911:     my $numrecent = 0;
  912:     my $roletext = '<h3>'.&mt('Enter a recently visited course').'</h3>'.
  913:                    '<form name="rolechoice" action="/adm/roles" method="post">'.
  914:                    '<table><tr><th>&nbsp;</th>'.
  915:                    '<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
  916:                    '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
  917:                    &mt('Remarks and Calendar Announcements').'</th></tr>'."\n".
  918:                    '<tr bgcolor="#BBffBB">'.
  919:                    '<td align="center" colspan="7">'.
  920:                    &mt('Domain').' - '.&mt('Recent courses accessed in this domain').
  921:                     '</td></tr>'."\n";
  922:     foreach my $courseid (sort keys %recent) {
  923:         unless ($courseid =~/^error\:/) {
  924:             my ($dom,$crs) = split/_/,$courseid;
  925:             if ($dom eq $dcdom) {
  926:                 $numrecent ++;
  927:                 my $crskey = 'user.role.cc./'.$dom.'/'.$crs;
  928:                 my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$tbg,$tfont,$tremark,$inrole,$tpstart,$tpend);
  929:                 my $button = 1;
  930:                 &role_status($crskey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
  931:                 if ($tstart) {
  932:                     $tpstart=&Apache::lonlocal::locallocaltime($tstart);
  933:                 }
  934:                 if ($tend) {
  935:                     $tpend=&Apache::lonlocal::locallocaltime($tend);
  936:                 }
  937:                 my $ttype = &mt('Course');
  938:                 my $twhere;
  939:                 if ($ENV{'course.'.$courseid.'.description'}) {
  940:                     $twhere=$ENV{'course.'.$courseid.'.description'};
  941:                 }
  942:                 my ($tdom,$trest,$tsection)=
  943:                     split(/\//,Apache::lonnet::declutter($where));
  944:                 if ($ENV{'request.role'} eq $trolecode) {
  945:                     $tstatus='selected';
  946:                 }
  947:                 if ($tstatus eq 'is') {
  948:                     $tbg='#77FF77';
  949:                     $tfont='#003300';
  950:                 } elsif ($tstatus eq 'future') {
  951:                     $tbg='#FFFF77';
  952:                     $button=0;
  953:                 } elsif ($tstatus eq 'will') {
  954:                     $tbg='#FFAA77';
  955:                     $tremark.=&mt('Active at next login. ');
  956:                 } elsif ($tstatus eq 'expired') {
  957:                     $tbg='#FF7777';
  958:                     $tfont='#330000';
  959:                     $button=0;
  960:                 } elsif ($tstatus eq 'will_not') {
  961:                     $tbg='#AAFF77';
  962:                     $tremark.=&mt('Expired after logout. ');
  963:                 } elsif ($tstatus eq 'selected') {
  964:                     $tbg='#11CC55';
  965:                     $tfont='#002200';
  966:                     $inrole=1;
  967:                     $tremark.=&mt('Currently selected. ');
  968:                 }
  969:                 my $trole=Apache::lonnet::plaintext($role);
  970:                 $roletext.='<tr bgcolor='.$tbg.'>';
  971:                 if (!$button) {
  972:                     $roletext.=('<td>&nbsp;</td>');
  973:                 } elsif ($tstatus eq 'is') {
  974:                     $roletext.=('<td><input type=submit value="'.
  975:                               &mt('Select').'" name="'.
  976:                               $trolecode.'"></td>');
  977:                 } elsif ($tryagain) {
  978:                     $roletext.=
  979:                         '<td><input type=submit value="'.
  980:                         &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
  981:                 } elsif ($advanced) {
  982:                     $roletext.=
  983:                         '<td><input type=submit value="'.
  984:                         &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
  985:                 } else {
  986:                     $roletext.='<td>&nbsp;</td>';
  987:                 }
  988:                 $tremark.=&Apache::lonannounce::showday(time,1,
  989:                          &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
  990:                                                                                   
  991:                 $roletext.='<td><font color="'.$tfont.'">'.$trole.
  992:                       '</font></td><td><font color="'.$tfont.'">'.$ttype.
  993:                       '</font></td><td><font color="'.$tfont.'">'.$twhere.
  994:                       '</font></td><td><font color="'.$tfont.'">'.$tpstart.
  995:                       '</font></td><td><font color="'.$tfont.'">'.$tpend.
  996:                       '</font></td><td><font color="'.$tfont.'">'.$tremark.
  997:                       '&nbsp;</font></td></tr>'."\n";
  998:             }
  999:         }
 1000:     }
 1001:     if ($numrecent > 0) {
 1002:         $r->print($roletext.'</table><input type="hidden" '.
 1003:                   'name="selectrole" value="1" /></form>'."\n");
 1004:     }
 1005: }
 1006: 
 1007: sub recent_filename {
 1008:     my $area=shift;
 1009:     return 'nohist_recent_'.&Apache::lonnet::escape($area);
 1010: }
 1011: 
 1012: 1;
 1013: __END__
 1014: 
 1015: =head1 NAME
 1016: 
 1017: Apache::lonroles - User Roles Screen
 1018: 
 1019: =head1 SYNOPSIS
 1020: 
 1021: Invoked by /etc/httpd/conf/srm.conf:
 1022: 
 1023:  <Location /adm/roles>
 1024:  PerlAccessHandler       Apache::lonacc
 1025:  SetHandler perl-script
 1026:  PerlHandler Apache::lonroles
 1027:  ErrorDocument     403 /adm/login
 1028:  ErrorDocument	  500 /adm/errorhandler
 1029:  </Location>
 1030: 
 1031: =head1 OVERVIEW
 1032: 
 1033: =head2 Choosing Roles
 1034: 
 1035: C<lonroles> is a handler that allows a user to switch roles in
 1036: mid-session. LON-CAPA attempts to work with "No Role Specified", the
 1037: default role that a user has before selecting a role, as widely as
 1038: possible, but certain handlers for example need specification which
 1039: course they should act on, etc. Both in this scenario, and when the
 1040: handler determines via C<lonnet>'s C<&allowed> function that a certain
 1041: action is not allowed, C<lonroles> is used as error handler. This
 1042: allows the user to select another role which may have permission to do
 1043: what they were trying to do. C<lonroles> can also be accessed via the
 1044: B<CRS> button in the Remote Control. 
 1045: 
 1046: =begin latex
 1047: 
 1048: \begin{figure}
 1049: \begin{center}
 1050: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
 1051:   \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
 1052: \end{center}
 1053: \end{figure}
 1054: 
 1055: =end latex
 1056: 
 1057: =head2 Role Initialization
 1058: 
 1059: The privileges for a user are established at login time and stored in the session environment. As a consequence, a new role does not become active till the next login. Handlers are able to query for privileges using C<lonnet>'s C<&allowed> function. When a user first logs in, their role is the "common" role, which means that they have the sum of all of their privileges. During a session it might become necessary to choose a particular role, which as a consequence also limits the user to only the privileges in that particular role.
 1060: 
 1061: =head1 INTRODUCTION
 1062: 
 1063: This module enables a user to select what role he wishes to
 1064: operate under (instructor, student, teaching assistant, course
 1065: coordinator, etc).  These roles are pre-established by the actions
 1066: of upper-level users.
 1067: 
 1068: This is part of the LearningOnline Network with CAPA project
 1069: described at http://www.lon-capa.org.
 1070: 
 1071: =head1 HANDLER SUBROUTINE
 1072: 
 1073: This routine is called by Apache and mod_perl.
 1074: 
 1075: =over 4
 1076: 
 1077: =item *
 1078: 
 1079: Roles Initialization (yes/no)
 1080: 
 1081: =item *
 1082: 
 1083: Get Error Message from Environment
 1084: 
 1085: =item *
 1086: 
 1087: Who is this?
 1088: 
 1089: =item *
 1090: 
 1091: Generate Page Output
 1092: 
 1093: =item *
 1094: 
 1095: Choice or no choice
 1096: 
 1097: =item *
 1098: 
 1099: Table
 1100: 
 1101: =item *
 1102: 
 1103: Privileges
 1104: 
 1105: =back
 1106: 
 1107: =cut

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