File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.104: download - view: text, annotated - select for diffs
Tue Nov 9 18:18:02 2004 UTC (19 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Suppress display of CC roles in a domain in which the user is a DC.  Allow the DC to select from recently visited CC roles in the domain, or select a course via lonpickcourse.

    1: # The LearningOnline Network with CAPA
    2: # User Roles Screen
    3: #
    4: # $Id: lonroles.pm,v 1.104 2004/11/09 18:18:02 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
  543:                             ($tcourseid);
  544:                         if (%newhash) {
  545: 			    $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
  546: 				"\0".$envkey;
  547:                             $twhere=$newhash{'description'}.
  548:                               ' <font size="-2">'.
  549:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
  550:                               '</font>';
  551:                         } else {
  552:                             $twhere=&mt('Currently not available');
  553:                             $ENV{'course.'.$tcourseid.'.description'}=$twhere;
  554: 			    $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
  555:                         }
  556:                     }
  557: 		    if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
  558:                 } elsif ($tdom) {
  559:                     $ttype='Domain';
  560:                     $twhere=$tdom;
  561: 		    $sortkey=$role.$twhere;
  562:                 } else {
  563:                     $ttype='System';
  564:                     $twhere=&mt('system wide');
  565: 		    $sortkey=$role.$twhere;
  566:                 }
  567:  
  568:                 $roletext.='<tr bgcolor='.$tbg.'>';
  569:                 unless ($nochoose) {
  570:                     if (!$button) {
  571: 			if ($switchserver) {
  572: 			    $roletext.='<td><a href="/adm/logout?handover='.
  573:                               $switchserver.'">'.&mt('Switch Server').'</a></td>';
  574:                         } else {
  575:                             $roletext.=('<td>&nbsp;</td>');
  576:                         }
  577:                     } elsif ($tstatus eq 'is') {
  578:                         $roletext.=('<td><input type=submit value="'.
  579: 				  &mt('Select').'" name="'.
  580:                                   $trolecode.'"></td>');
  581:                     } elsif ($tryagain) {
  582:                         $roletext.=
  583: 			    '<td><input type=submit value="'.
  584: 		  &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
  585:                     } elsif ($advanced) {
  586:                         $roletext.=
  587:                             '<td><input type=submit value="'.
  588: 		        &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
  589:                     } else {
  590:                         $roletext.='<td>&nbsp;</td>';
  591:                     }
  592:                 }
  593:                 $tremark.=&Apache::lonannounce::showday(time,1,
  594:                          &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
  595:                 
  596: 		$roletext.='<td><font color="'.$tfont.'">'.$trole.
  597:                       '</font></td><td><font color="'.$tfont.'">'.$ttype.
  598:                       '</font></td><td><font color="'.$tfont.'">'.$twhere.
  599:                       '</font></td><td><font color="'.$tfont.'">'.$tpstart.
  600:                       '</font></td><td><font color="'.$tfont.'">'.$tpend.
  601:                       '</font></td><td><font color="'.$tfont.'">'.$tremark.
  602:                       '&nbsp;</font></td></tr>'."\n";
  603: 		$roletext{$envkey}=$roletext;
  604: 		if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
  605: 		$sortrole{$sortkey}=$envkey;
  606: 		$roleclass{$envkey}=$ttype;
  607: 	    }
  608:         }
  609:     }
  610: # No active roles
  611:     if ($countactive==0) {
  612: 	if ($inrole) {
  613: 	    $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
  614: 	} else {
  615: 	    $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
  616: 	}
  617: 	$r->print('</form></body></html>');
  618: 	return OK;
  619: # Is there only one choice?
  620:     } elsif (($countactive==1) && ($ENV{'request.role'} eq 'cm')) {
  621: 	$r->print('<h3>'.&mt('Please stand by.').'</h3>'.
  622: 	    '<input type="hidden" name="'.$possiblerole.'" value="1" />');
  623: 	$r->print("</form>\n");
  624: 	$r->rflush();
  625: 	$r->print('<script>document.forms.rolechoice.submit();</script>');
  626: 	$r->print('</body></html>');
  627: 	return OK;
  628:     }
  629: # More than one possible role
  630: # ----------------------------------------------------------------------- Table
  631:     unless (($advanced) || ($nochoose)) {
  632: 	$r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
  633:     }
  634:     $r->print('<br /><table><tr>');
  635:     unless ($nochoose) { $r->print('<th>&nbsp;</th>'); }
  636:     $r->print('<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
  637:          '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
  638: 	      &mt('Remarks and Calendar Announcements').'</th></tr>'."\n");
  639:     my $doheaders=-1;
  640:     foreach my $type ('Construction Space','Course','Domain','System') {
  641: 	my $haverole=0;
  642: 	foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
  643: 	    if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { 
  644: 		$haverole=1;
  645: 	    }
  646: 	}
  647: 	if ($haverole) { $doheaders++; }
  648:     }
  649:     if ($numdc > 0) {
  650:          $r->print('<tr bgcolor="#BBffBB">'.
  651:                       '<td align="center" colspan="7">'.
  652:                       '<input type="hidden" name="all_cc_roles" value="1"/>'.
  653:                       '<input type="hidden" name="dcselected" value=""/>'.
  654:                       &mt('Domain').'</td>');
  655:          foreach my $dcdom (keys %dcroles) {
  656:              my $output = $roletext{$dcroles{$dcdom}};
  657:              my $ccrole = Apache::lonnet::plaintext('cc');
  658:              if ($ENV{'request.role'} =~ m-cc\./$dcdom/-) {
  659:                  $output.=$roletext{'user.role.'.$ENV{'request.role'}};
  660:              }
  661:              $r->print($output);
  662:              $r->print('<tr bgcolor="#77FF77">');
  663:              $r->print('<td><input type="button" value="'.
  664:                       &mt('Select').'" name="dcpick_'.$dcdom.'/" '.
  665:                       'onClick="setDCchoice('."'$dcdom'".')"></td>'.
  666:                       '<td><font color="#002200">'.
  667:                       $ccrole.'</font></td><td>'.&mt('Course').'</td>'.
  668:                       '<td><font color="#002200"><b>'.&mt('All courses').'</b>'.
  669:                       '<br />'.&mt('Domain').':'.$dcdom.'</font>'.
  670:                       '<td colspan="4"><font color="#002200">'.
  671:                       &mt('Course Coordinator access to all courses in domain').
  672:                       ': <b>'.$dcdom.'</b></font></td></tr>'."\n");
  673:          }
  674:          foreach my $type ('Construction Space','Course','Domain','System') {
  675:              my $output;
  676:              foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
  677:                 my $skiprole = 0;
  678:                 foreach my $dcdom (keys %dcroles) {
  679:                     if ($sortrole{$which} =~ m-(dc|cc)\./$dcdom/-) {
  680:                         $skiprole = 1;
  681:                         last;
  682:                     }
  683:                 }
  684:                 if (($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) && (!$skiprole)) {
  685:                     $output.=$roletext{$sortrole{$which}};
  686:                 }
  687:             }
  688:             if ($output) {
  689:                 if ($doheaders > 0) {
  690:                     $r->print("<tr bgcolor='#BBffBB'>".
  691:                           "<td align='center' colspan='7'>".&mt($type)."</td>
  692: ");
  693:                 }
  694:                 $r->print($output);
  695:             }
  696:         }
  697:     } else {
  698:         foreach my $type ('Construction Space','Course','Domain','System') {
  699: 	    my $output;
  700: 	    foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
  701: 	        if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { 
  702: 		    $output.=$roletext{$sortrole{$which}};
  703: 	        }
  704: 	    }
  705: 	    if ($output) {
  706: 	        if ($doheaders > 0) {
  707: 		    $r->print("<tr bgcolor='#BBffBB'>".
  708: 			      "<td align='center' colspan='7'>".&mt($type)."</td>");
  709: 	        }
  710: 	        $r->print($output);	    
  711: 	    }
  712:         }
  713:     }
  714:     my $tremark='';
  715:     my $tfont='#003300';
  716:     if ($ENV{'request.role'} eq 'cm') {
  717: 	$r->print('<tr bgcolor="#11CC55">');
  718:         $tremark=&mt('Currently selected. ');
  719:         $tfont='#002200';
  720:     } else {
  721:         $r->print('<tr bgcolor="#77FF77">');
  722:     }
  723:     unless ($nochoose) {
  724: 	if ($ENV{'request.role'} ne 'cm') {
  725: 	    $r->print('<td><input type=submit value="'.
  726: 		      &mt('Select').'" name="cm"></td>');
  727: 	} else {
  728: 	    $r->print('<td>&nbsp;</td>');
  729: 	}
  730:     }
  731:     $r->print('<td colspan=5><font color="'.$tfont.'">'.&mt('No role specified').
  732:       '</font></td><td><font color="'.$tfont.'">'.$tremark.
  733:       '&nbsp;</font></td></tr>'."\n");
  734: 
  735:     $r->print('</table>');
  736:     unless ($nochoose) {
  737: 	$r->print("</form>\n");
  738:     }
  739: # ------------------------------------------------------------ Privileges Info
  740:     if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
  741: 	$r->print('<hr><h2>Current Privileges</h2>');
  742: 
  743: 	foreach $envkey (sort keys %ENV) {
  744: 	    if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
  745: 		my $where=$envkey;
  746: 		$where=~s/^user\.priv\.$ENV{'request.role'}\.//;
  747: 		my $ttype;
  748: 		my $twhere;
  749: 		my ($tdom,$trest,$tsec)=
  750: 		    split(/\//,Apache::lonnet::declutter($where));
  751: 		if ($trest) {
  752: 		    if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
  753: 			$ttype='Construction Space';
  754: 			$twhere='User: '.$trest.', Domain: '.$tdom;
  755: 		    } else {
  756: 			$ttype='Course';
  757: 			$twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
  758: 			if ($tsec) {
  759: 			    $twhere.=' (Section/Group: '.$tsec.')';
  760: 			}
  761: 		    }
  762: 		} elsif ($tdom) {
  763: 		    $ttype='Domain';
  764: 		    $twhere=$tdom;
  765: 		} else {
  766: 		    $ttype='System';
  767: 		    $twhere='/';
  768: 		}
  769: 		$r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
  770: 		foreach (sort split(/:/,$ENV{$envkey})) {
  771: 		    if ($_) {
  772: 			my ($prv,$restr)=split(/\&/,$_);
  773: 			my $trestr='';
  774: 			if ($restr ne 'F') {
  775: 			    my $i;
  776: 			    $trestr.=' (';
  777: 			    for ($i=0;$i<length($restr);$i++) {
  778: 				$trestr.=
  779: 			       Apache::lonnet::plaintext(substr($restr,$i,1));
  780: 				if ($i<length($restr)-1) { $trestr.=', '; }
  781: 			    }
  782: 			    $trestr.=')';
  783: 			}
  784: 			$r->print('<li>'.
  785: 				  Apache::lonnet::plaintext($prv).$trestr.
  786: 				  '</li>');
  787: 		    }
  788: 		}
  789: 		$r->print('</ul>');
  790: 	    }
  791: 	}
  792:     }
  793:     $r->print(&Apache::lonnet::getannounce());
  794:     if ($advanced) {
  795: 	$r->print('<p><small><i>This is LON-CAPA '.
  796: 		  $r->dir_config('lonVersion').'</i><br />'.
  797: 		  '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
  798:     }
  799:     $r->print("</body></html>\n");
  800:     return OK;
  801: }
  802: 
  803: sub role_status {
  804:     my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
  805:     my @pwhere = ();
  806:     if (exists($ENV{$rolekey}) && $ENV{$rolekey} ne '') {
  807:         (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
  808:         unless (!defined($$role) || $$role eq '') {
  809:             $$where=join('.',@pwhere);
  810:             $$trolecode=$$role.'.'.$$where;
  811:             ($$tstart,$$tend)=split(/\./,$ENV{$rolekey});
  812:             $$tstatus='is';
  813:             if ($$tstart) {
  814:                 if ($$tstart>$then) {
  815:                     $$tstatus='future';
  816:                     if ($$tstart<$now) { $$tstatus='will'; }
  817:                 }
  818:             }
  819:             if ($$tend) {
  820:                 if ($$tend<$then) {
  821:                     $$tstatus='expired';
  822:                 } elsif ($$tend<$now) {
  823:                     $$tstatus='will_not';
  824:                 }
  825:             }
  826:         }
  827:     }
  828: }
  829: 
  830: sub dc_script {
  831:     my $response = (<<"END");
  832: function setDCchoice(caller) {
  833:     var dcname = "dc./"+caller+"/"
  834:     document.rolechoice.dcselected.value = caller
  835:     document.rolechoice.elements[3].name = dcname
  836:     document.rolechoice.submit()
  837: }
  838: END
  839:     return $response;
  840: }
  841:                                                                                  
  842: sub check_fordc {
  843:     my ($dcroles,$then) = @_;
  844:     my $numdc = 0;
  845:     if ($ENV{'user.adv'}) {
  846:         foreach my $envkey (sort keys %ENV) {
  847:             if ($envkey=~/^user\.role\.dc\.\/(\w+)\/$/) {
  848:                 my $dcdom = $1;
  849:                 my $livedc = 1;
  850:                 my ($tstart,$tend)=split(/\./,$ENV{$envkey});
  851:                 if ($tstart) {
  852:                     if ($tstart>$then) {
  853:                         $livedc = 0;
  854:                     }
  855:                 }
  856:                 if ($tend) {
  857:                     if ($tend<$then) {
  858:                         $livedc = 0;
  859:                     }
  860:                 }
  861:                 if ($livedc) {
  862:                     $$dcroles{$dcdom} = $envkey;
  863:                     $numdc ++;
  864:                 }
  865:             }
  866:         }
  867:     }
  868:     return $numdc;
  869: }
  870: 
  871: sub choosecourse_display {
  872:     my ($r,$dcdom,$then,$now) = @_;
  873:     my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'dom');
  874:     my $verify_script = <<"END";
  875: <script>
  876: function verifyCoursePick() {
  877:     var pickedCourse = document.roles.dccourse.value
  878:     var pickedDomain = document.roles.dcdomain.value
  879:     if (document.roles.dcdomain.value == document.roles.origdom.value) {
  880:         if (pickedCourse != '') {
  881:             var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
  882:             document.roles.elements[0].value = 1
  883:             document.roles.elements[0].name = courseTarget
  884:             document.roles.selectrole.value = 1
  885:             document.roles.submit()
  886:         }
  887:         else {
  888:             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");
  889:         }
  890:     }
  891:     else {
  892:         alert("You can only use this screen to select courses in the current domain")
  893:     }
  894: }
  895: </script>
  896: END
  897:     my $courseform=&Apache::loncommon::selectcourse_link
  898:                      ('roles','dccourse','dcdomain','coursedesc');
  899:     $r->print($cb_jscript.$verify_script);
  900:     my $formaction='/adm/roles';
  901:     $formaction=~s/\/+/\//g;
  902:     my $crs;
  903:     &select_recent_courses($r,$dcdom,$then,$now);
  904:     $r->print('<br /><form name="roles" method="post" action="'.$formaction.'" />');
  905:     $r->print('<h3>'.&mt('Choose a course from domain').': '.$dcdom.'</h3><font size="+1">'.$courseform.'</font><br /><br />'.
  906:               '<input type="hidden" name="chosencourse" value=""/>'.
  907:               'Course Title: <input type="text" size="20" name="coursedesc" value=""><br />'.
  908:               'Course ID: <input type="text" size="15" name="dccourse" />'.
  909:               '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
  910:               '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
  911:               '<input type="hidden" name="selectrole" value="" />'.
  912:               '<br /><br /><input type="button" name="proceed" value="'.&mt('Enter this course').'" onClick="verifyCoursePick()" />'.
  913:               '</form>');
  914:     return;
  915: }
  916: 
  917: sub select_recent_courses {
  918:     my ($r,$dcdom,$then,$now)=@_;
  919:     my $advanced = $ENV{'user.adv'};
  920:     my $tryagain = $ENV{'form.tryagain'};
  921:     my %recent=&Apache::lonnet::dump(&recent_filename('cc_pickby_dc_'.$dcdom));
  922:     my $numrecent = 0;
  923:     my $roletext = '<h3>'.&mt('Enter a recently visited course').'</h3>'.
  924:                    '<form name="rolechoice" action="/adm/roles" method="post">'.
  925:                    '<table><tr><th>&nbsp;</th>'.
  926:                    '<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
  927:                    '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
  928:                    &mt('Remarks and Calendar Announcements').'</th></tr>'."\n".
  929:                    '<tr bgcolor="#BBffBB">'.
  930:                    '<td align="center" colspan="7">'.
  931:                    &mt('Domain').' - '.&mt('Recent courses accessed in this domain').
  932:                     '</td></tr>'."\n";
  933:     foreach my $courseid (sort keys %recent) {
  934:         unless ($courseid =~/^error\:/) {
  935:             my ($dom,$crs) = split/_/,$courseid;
  936:             if ($dom eq $dcdom) {
  937:                 $numrecent ++;
  938:                 my $crskey = 'user.role.cc./'.$dom.'/'.$crs;
  939:                 my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$tbg,$tfont,$tremark,$inrole,$tpstart,$tpend);
  940:                 my $button = 1;
  941:                 &role_status($crskey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
  942:                 if ($tstart) {
  943:                     $tpstart=&Apache::lonlocal::locallocaltime($tstart);
  944:                 }
  945:                 if ($tend) {
  946:                     $tpend=&Apache::lonlocal::locallocaltime($tend);
  947:                 }
  948:                 my $ttype = &mt('Course');
  949:                 my $twhere;
  950:                 if ($ENV{'course.'.$courseid.'.description'}) {
  951:                     $twhere=$ENV{'course.'.$courseid.'.description'};
  952:                 }
  953:                 my ($tdom,$trest,$tsection)=
  954:                     split(/\//,Apache::lonnet::declutter($where));
  955:                 if ($ENV{'request.role'} eq $trolecode) {
  956:                     $tstatus='selected';
  957:                 }
  958:                 if ($tstatus eq 'is') {
  959:                     $tbg='#77FF77';
  960:                     $tfont='#003300';
  961:                 } elsif ($tstatus eq 'future') {
  962:                     $tbg='#FFFF77';
  963:                     $button=0;
  964:                 } elsif ($tstatus eq 'will') {
  965:                     $tbg='#FFAA77';
  966:                     $tremark.=&mt('Active at next login. ');
  967:                 } elsif ($tstatus eq 'expired') {
  968:                     $tbg='#FF7777';
  969:                     $tfont='#330000';
  970:                     $button=0;
  971:                 } elsif ($tstatus eq 'will_not') {
  972:                     $tbg='#AAFF77';
  973:                     $tremark.=&mt('Expired after logout. ');
  974:                 } elsif ($tstatus eq 'selected') {
  975:                     $tbg='#11CC55';
  976:                     $tfont='#002200';
  977:                     $inrole=1;
  978:                     $tremark.=&mt('Currently selected. ');
  979:                 }
  980:                 my $trole=Apache::lonnet::plaintext($role);
  981:                 $roletext.='<tr bgcolor='.$tbg.'>';
  982:                 if (!$button) {
  983:                     $roletext.=('<td>&nbsp;</td>');
  984:                 } elsif ($tstatus eq 'is') {
  985:                     $roletext.=('<td><input type=submit value="'.
  986:                               &mt('Select').'" name="'.
  987:                               $trolecode.'"></td>');
  988:                 } elsif ($tryagain) {
  989:                     $roletext.=
  990:                         '<td><input type=submit value="'.
  991:                         &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
  992:                 } elsif ($advanced) {
  993:                     $roletext.=
  994:                         '<td><input type=submit value="'.
  995:                         &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
  996:                 } else {
  997:                     $roletext.='<td>&nbsp;</td>';
  998:                 }
  999:                 $tremark.=&Apache::lonannounce::showday(time,1,
 1000:                          &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
 1001:                                                                                   
 1002:                 $roletext.='<td><font color="'.$tfont.'">'.$trole.
 1003:                       '</font></td><td><font color="'.$tfont.'">'.$ttype.
 1004:                       '</font></td><td><font color="'.$tfont.'">'.$twhere.
 1005:                       '</font></td><td><font color="'.$tfont.'">'.$tpstart.
 1006:                       '</font></td><td><font color="'.$tfont.'">'.$tpend.
 1007:                       '</font></td><td><font color="'.$tfont.'">'.$tremark.
 1008:                       '&nbsp;</font></td></tr>'."\n";
 1009:             }
 1010:         }
 1011:     }
 1012:     if ($numrecent > 0) {
 1013:         $r->print($roletext.'</table><input type="hidden" '.
 1014:                   'name="selectrole" value="1" /></form>'."\n");
 1015:     }
 1016: }
 1017: 
 1018: sub recent_filename {
 1019:     my $area=shift;
 1020:     return 'nohist_recent_'.&Apache::lonnet::escape($area);
 1021: }
 1022: 
 1023: 1;
 1024: __END__
 1025: 
 1026: =head1 NAME
 1027: 
 1028: Apache::lonroles - User Roles Screen
 1029: 
 1030: =head1 SYNOPSIS
 1031: 
 1032: Invoked by /etc/httpd/conf/srm.conf:
 1033: 
 1034:  <Location /adm/roles>
 1035:  PerlAccessHandler       Apache::lonacc
 1036:  SetHandler perl-script
 1037:  PerlHandler Apache::lonroles
 1038:  ErrorDocument     403 /adm/login
 1039:  ErrorDocument	  500 /adm/errorhandler
 1040:  </Location>
 1041: 
 1042: =head1 OVERVIEW
 1043: 
 1044: =head2 Choosing Roles
 1045: 
 1046: C<lonroles> is a handler that allows a user to switch roles in
 1047: mid-session. LON-CAPA attempts to work with "No Role Specified", the
 1048: default role that a user has before selecting a role, as widely as
 1049: possible, but certain handlers for example need specification which
 1050: course they should act on, etc. Both in this scenario, and when the
 1051: handler determines via C<lonnet>'s C<&allowed> function that a certain
 1052: action is not allowed, C<lonroles> is used as error handler. This
 1053: allows the user to select another role which may have permission to do
 1054: what they were trying to do. C<lonroles> can also be accessed via the
 1055: B<CRS> button in the Remote Control. 
 1056: 
 1057: =begin latex
 1058: 
 1059: \begin{figure}
 1060: \begin{center}
 1061: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
 1062:   \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
 1063: \end{center}
 1064: \end{figure}
 1065: 
 1066: =end latex
 1067: 
 1068: =head2 Role Initialization
 1069: 
 1070: 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.
 1071: 
 1072: =head1 INTRODUCTION
 1073: 
 1074: This module enables a user to select what role he wishes to
 1075: operate under (instructor, student, teaching assistant, course
 1076: coordinator, etc).  These roles are pre-established by the actions
 1077: of upper-level users.
 1078: 
 1079: This is part of the LearningOnline Network with CAPA project
 1080: described at http://www.lon-capa.org.
 1081: 
 1082: =head1 HANDLER SUBROUTINE
 1083: 
 1084: This routine is called by Apache and mod_perl.
 1085: 
 1086: =over 4
 1087: 
 1088: =item *
 1089: 
 1090: Roles Initialization (yes/no)
 1091: 
 1092: =item *
 1093: 
 1094: Get Error Message from Environment
 1095: 
 1096: =item *
 1097: 
 1098: Who is this?
 1099: 
 1100: =item *
 1101: 
 1102: Generate Page Output
 1103: 
 1104: =item *
 1105: 
 1106: Choice or no choice
 1107: 
 1108: =item *
 1109: 
 1110: Table
 1111: 
 1112: =item *
 1113: 
 1114: Privileges
 1115: 
 1116: =back
 1117: 
 1118: =cut

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