File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.212: download - view: text, annotated - select for diffs
Thu Dec 4 16:56:46 2008 UTC (15 years, 7 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Standard styles for roles screen
and some other optimizations

lonroles.pm:
- Use data_table for roles screen
- Moved status color from whole row background to only the first column.
  (This change is meant as an intermediate suggestion to get rid of the "color shock" effect ("Everything's green here!") and usage of standard LON-CAPA styles by keeping the main functionality)
-  Only the green background for active, unselected roles isn't used anymore. (No special indication needed)
- Removed some hardcoded font styles
- Removed the usage of different font colors (not needed anymore; -> $tfont)
- Removed empty separator rows (separation now done by different background colors in the data table rows)
- Replaced hardcoded color styles with new external styles (->  $tbg)
- Use double quotes for html attributes
- Added missing &mt() call (-> Current Privileges)

loncommon.pm:
- Removed unneeded and unused rolesmenu styles
- Added new styles for status display on roles screen but keep already used color values (-> lonroles.pm)
- Don't change background color counter for standard rows anymore, if empty_row is called and displayed
- Removed now unused font parameter from syllabuswrapper

    1: # The LearningOnline Network with CAPA
    2: # User Roles Screen
    3: #
    4: # $Id: lonroles.pm,v 1.212 2008/12/04 16:56:46 bisitz 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: =pod
   31: 
   32: =head1 NAME
   33: 
   34: Apache::lonroles - User Roles Screen
   35: 
   36: =head1 SYNOPSIS
   37: 
   38: Invoked by /etc/httpd/conf/srm.conf:
   39: 
   40:  <Location /adm/roles>
   41:  PerlAccessHandler       Apache::lonacc
   42:  SetHandler perl-script
   43:  PerlHandler Apache::lonroles
   44:  ErrorDocument     403 /adm/login
   45:  ErrorDocument	  500 /adm/errorhandler
   46:  </Location>
   47: 
   48: =head1 OVERVIEW
   49: 
   50: =head2 Choosing Roles
   51: 
   52: C<lonroles> is a handler that allows a user to switch roles in
   53: mid-session. LON-CAPA attempts to work with "No Role Specified", the
   54: default role that a user has before selecting a role, as widely as
   55: possible, but certain handlers for example need specification which
   56: course they should act on, etc. Both in this scenario, and when the
   57: handler determines via C<lonnet>'s C<&allowed> function that a certain
   58: action is not allowed, C<lonroles> is used as error handler. This
   59: allows the user to select another role which may have permission to do
   60: what they were trying to do. C<lonroles> can also be accessed via the
   61: B<CRS> button in the Remote Control. 
   62: 
   63: =begin latex
   64: 
   65: \begin{figure}
   66: \begin{center}
   67: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
   68:   \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
   69: \end{center}
   70: \end{figure}
   71: 
   72: =end latex
   73: 
   74: =head2 Role Initialization
   75: 
   76: 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.
   77: 
   78: =head1 INTRODUCTION
   79: 
   80: This module enables a user to select what role he wishes to
   81: operate under (instructor, student, teaching assistant, course
   82: coordinator, etc).  These roles are pre-established by the actions
   83: of upper-level users.
   84: 
   85: This is part of the LearningOnline Network with CAPA project
   86: described at http://www.lon-capa.org.
   87: 
   88: =head1 HANDLER SUBROUTINE
   89: 
   90: This routine is called by Apache and mod_perl.
   91: 
   92: =over 4
   93: 
   94: =item *
   95: 
   96: Roles Initialization (yes/no)
   97: 
   98: =item *
   99: 
  100: Get Error Message from Environment
  101: 
  102: =item *
  103: 
  104: Who is this?
  105: 
  106: =item *
  107: 
  108: Generate Page Output
  109: 
  110: =item *
  111: 
  112: Choice or no choice
  113: 
  114: =item *
  115: 
  116: Table
  117: 
  118: =item *
  119: 
  120: Privileges
  121: 
  122: =back
  123: 
  124: =cut
  125: 
  126: 
  127: package Apache::lonroles;
  128: 
  129: use strict;
  130: use Apache::lonnet;
  131: use Apache::lonuserstate();
  132: use Apache::Constants qw(:common);
  133: use Apache::File();
  134: use Apache::lonmenu;
  135: use Apache::loncommon;
  136: use Apache::lonhtmlcommon;
  137: use Apache::lonannounce;
  138: use Apache::lonlocal;
  139: use Apache::lonpageflip();
  140: use Apache::lonnavdisplay();
  141: use GDBM_File;
  142: use LONCAPA qw(:DEFAULT :match);
  143: use HTML::Entities;
  144:  
  145: 
  146: sub redirect_user {
  147:     my ($r,$title,$url,$msg,$launch_nav) = @_;
  148:     $msg = $title if (! defined($msg));
  149:     &Apache::loncommon::content_type($r,'text/html');
  150:     &Apache::loncommon::no_cache($r);
  151:     $r->send_http_header;
  152:     my $swinfo=&Apache::lonmenu::rawconfig();
  153:     my $navwindow;
  154:     if ($launch_nav eq 'on') {
  155: 	$navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,
  156: 						       ($url =~ m-^/adm/whatsnew-));
  157:     } else {
  158: 	$navwindow.=&Apache::lonnavmaps::close();
  159:     }
  160:     my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
  161: 						    {'redirect' => [1,$url],});
  162:     my $end_page   = &Apache::loncommon::end_page();
  163: 
  164: # Note to style police: 
  165: # This must only replace the spaces, nothing else, or it bombs elsewhere.
  166:     $url=~s/ /\%20/g;
  167:     $r->print(<<ENDREDIR);
  168: $start_page
  169: <script type="text/javascript">
  170: $swinfo
  171: </script>
  172: $navwindow
  173: <h1>$msg</h1>
  174: $end_page
  175: ENDREDIR
  176:     return;
  177: }
  178: 
  179: sub error_page {
  180:     my ($r,$error,$dest)=@_;
  181:     &Apache::loncommon::content_type($r,'text/html');
  182:     &Apache::loncommon::no_cache($r);
  183:     $r->send_http_header;
  184:     return OK if $r->header_only;
  185:     $r->print(&Apache::loncommon::start_page('Problems during Course Initialization').
  186: 	      '<script type="text/javascript">'.
  187: 	      &Apache::lonmenu::rawconfig().'</script>'.
  188: 	      '<p>'.&mt('The following problems occurred:').
  189: 	      $error.
  190: 	      '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'.
  191: 	      &Apache::loncommon::end_page());
  192: }
  193: 
  194: sub handler {
  195: 
  196:     my $r = shift;
  197: 
  198:     my $now=time;
  199:     my $then=$env{'user.login.time'};
  200:     my $envkey;
  201:     my %dcroles = ();
  202:     my $numdc = &check_fordc(\%dcroles,$then);
  203:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
  204: 
  205: # ================================================================== Roles Init
  206:     if ($env{'form.selectrole'}) {
  207: 
  208:         my $locknum=&Apache::lonnet::get_locks();
  209:         if ($locknum) { return 409; }
  210: 
  211:         if ($env{'form.newrole'}) {
  212:             $env{'form.'.$env{'form.newrole'}}=1;
  213: 	}
  214: 	if ($env{'request.course.id'}) {
  215:             # Check if user is CC trying to select a course role
  216:             if ($env{'form.switchrole'}) {
  217:                 if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
  218:                     &adhoc_course_role($then);
  219:                 }
  220:             }
  221: 	    my %temp=('logout_'.$env{'request.course.id'} => time);
  222: 	    &Apache::lonnet::put('email_status',\%temp);
  223: 	    &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
  224: 	}
  225: 	&Apache::lonnet::appenv({"request.course.id"   => '',
  226: 			 	 "request.course.fn"   => '',
  227: 				 "request.course.uri"  => '',
  228: 				 "request.course.sec"  => '',
  229: 				 "request.role"        => 'cm',
  230:                                  "request.role.adv"    => $env{'user.adv'},
  231: 				 "request.role.domain" => $env{'user.domain'}});
  232: # Check if user is a DC trying to enter a course or author space and needs privs to be created
  233:         if ($numdc > 0) {
  234:             foreach my $envkey (keys %env) {
  235: # Is this an ad-hoc CC-role?
  236:                 if (my ($domain,$coursenum) =
  237: 		    ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {
  238:                     if ($dcroles{$domain}) {
  239:                         &check_privs($domain,$coursenum,$then,$now,'cc');
  240:                     }
  241:                     last;
  242:                 }
  243: # Is this an ad-hoc CA-role?
  244:                 if (my ($domain,$user) =
  245: 		    ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
  246:                     if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
  247:                         delete($env{$envkey});
  248:                         $env{'form.au./'.$domain.'/'} = 1;
  249:                         my ($server_status,$home) = &check_author_homeserver($user,$domain);
  250:                         if ($server_status eq 'switchserver') {
  251:                             my $trolecode = 'au./'.$domain.'/';
  252:                             my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
  253:                             $r->internal_redirect($switchserver);
  254:                         }
  255:                         last;
  256:                     }
  257:                     if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
  258:                         if (((($castart) && ($castart < $now)) || !$castart) && 
  259:                             ((!$caend) || (($caend) && ($caend > $now)))) {
  260:                             my ($server_status,$home) = &check_author_homeserver($user,$domain);
  261:                             if ($server_status eq 'switchserver') {
  262:                                 my $trolecode = 'ca./'.$domain.'/'.$user;
  263:                                 my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
  264:                                 $r->internal_redirect($switchserver);
  265:                             }
  266:                             last;
  267:                         }
  268:                     }
  269:                     # Check if author blocked ca-access
  270:                     my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
  271:                     if ($blocked{'domcoord.author'} eq 'blocked') {
  272:                         delete($env{$envkey});
  273:                         $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
  274:                         last;
  275:                     }
  276:                     if ($dcroles{$domain}) {
  277:                         my ($server_status,$home) = &check_author_homeserver($user,$domain);
  278:                         if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
  279:                             &check_privs($domain,$user,$then,$now,'ca');
  280:                             if ($server_status eq 'switchserver') {
  281:                                 my $trolecode = 'ca./'.$domain.'/'.$user; 
  282:                                 my $switchserver = '/adm/switchserver?'
  283:                                                   .'otherserver='.$home.'&role='.$trolecode;
  284:                                 $r->internal_redirect($switchserver);
  285:                             }
  286:                         } else {
  287:                             delete($env{$envkey});
  288:                         }
  289:                     } else {
  290:                         delete($env{$envkey});
  291:                     }
  292:                     last;
  293:                 }
  294:             }
  295:         }
  296: 
  297:         foreach $envkey (keys %env) {
  298:             next if ($envkey!~/^user\.role\./);
  299:             my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
  300:             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
  301:             if ($env{'form.'.$trolecode}) {
  302: 		if ($tstatus eq 'is') {
  303: 		    $where=~s/^\///;
  304: 		    my ($cdom,$cnum,$csec)=split(/\//,$where);
  305: # check for course groups
  306:                     my %coursegroups = &Apache::lonnet::get_active_groups(
  307:                           $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
  308:                     my $cgrps = join(':',keys(%coursegroups));
  309: 
  310: # store role if recent_role list being kept
  311:                     if ($env{'environment.recentroles'}) {
  312:                         my %frozen_roles =
  313:                            &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
  314: 			&Apache::lonhtmlcommon::store_recent('roles',
  315: 							     $trolecode,' ',$frozen_roles{$trolecode});
  316:                     }
  317: 
  318: 
  319: # check for keyed access
  320: 		    if (($role eq 'st') && 
  321:                        ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
  322: # who is key authority?
  323: 			my $authdom=$cdom;
  324: 			my $authnum=$cnum;
  325: 			if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
  326: 			    ($authnum,$authdom)=
  327: 				split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
  328: 			}
  329: # check with key authority
  330: 			unless (&Apache::lonnet::validate_access_key(
  331: 				     $env{'environment.key.'.$cdom.'_'.$cnum},
  332: 					     $authdom,$authnum)) {
  333: # there is no valid key
  334: 			     if ($env{'form.newkey'}) {
  335: # student attempts to register a new key
  336: 				 &Apache::loncommon::content_type($r,'text/html');
  337: 				 &Apache::loncommon::no_cache($r);
  338: 				 $r->send_http_header;
  339: 				 my $swinfo=&Apache::lonmenu::rawconfig();
  340: 				 my $start_page=&Apache::loncommon::start_page
  341: 				    ('Verifying Access Key to Unlock this Course');
  342: 				 my $end_page=&Apache::loncommon::end_page();
  343: 				 my $buttontext=&mt('Enter Course');
  344: 				 my $message=&mt('Successfully registered key');
  345: 				 my $assignresult=
  346: 				     &Apache::lonnet::assign_access_key(
  347: 						     $env{'form.newkey'},
  348: 						     $authdom,$authnum,
  349: 						     $cdom,$cnum,
  350:                                                      $env{'user.domain'},
  351: 						     $env{'user.name'},
  352:                                                      &mt('Assigned from [_1] at [_2] for [_3]'
  353:                                                         ,$ENV{'REMOTE_ADDR'}
  354:                                                         ,&Apache::lonlocal::locallocaltime()
  355:                                                         ,$trolecode)
  356:                                                      );
  357: 				 unless ($assignresult eq 'ok') {
  358: 				     $assignresult=~s/^error\:\s*//;
  359: 				     $message=&mt($assignresult).
  360: 				     '<br /><a href="/adm/logout">'.
  361: 				     &mt('Logout').'</a>';
  362: 				     $buttontext=&mt('Re-Enter Key');
  363: 				 }
  364: 				 $r->print(<<ENDENTEREDKEY);
  365: $start_page
  366: <script type="text/javascript">
  367: $swinfo
  368: </script>
  369: <form method="post">
  370: <input type="hidden" name="selectrole" value="1" />
  371: <input type="hidden" name="$trolecode" value="1" />
  372: <span class="LC_fontsize_large">$message</span><br />
  373: <input type="submit" value="$buttontext" />
  374: </form>
  375: $end_page
  376: ENDENTEREDKEY
  377:                                  return OK;
  378: 			     } else {
  379: # print form to enter a new key
  380: 				 &Apache::loncommon::content_type($r,'text/html');
  381: 				 &Apache::loncommon::no_cache($r);
  382: 				 $r->send_http_header;
  383: 				 my $swinfo=&Apache::lonmenu::rawconfig();
  384: 				 my $start_page=&Apache::loncommon::start_page
  385: 				    ('Enter Access Key to Unlock this Course');
  386: 				 my $end_page=&Apache::loncommon::end_page();
  387: 				 $r->print(<<ENDENTERKEY);
  388: $start_page
  389: <script type="text/javascript">
  390: $swinfo
  391: </script>
  392: <form method="post">
  393: <input type="hidden" name="selectrole" value="1" />
  394: <input type="hidden" name="$trolecode" value="1" />
  395: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
  396: <input type="submit" value="Enter key" />
  397: </form>
  398: $end_page
  399: ENDENTERKEY
  400: 				 return OK;
  401: 			     }
  402: 			 }
  403: 		     }
  404: 		    &Apache::lonnet::log($env{'user.domain'},
  405: 					 $env{'user.name'},
  406: 					 $env{'user.home'},
  407: 					 "Role ".$trolecode);
  408: 		    
  409: 		    &Apache::lonnet::appenv(
  410: 					   {'request.role'        => $trolecode,
  411: 					    'request.role.domain' => $cdom,
  412: 					    'request.course.sec'  => $csec,
  413:                                             'request.course.groups' => $cgrps});
  414:                     my $tadv=0;
  415: 
  416: 		    if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
  417:                         my $msg;
  418: 			my ($furl,$ferr)=
  419: 			    &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
  420: 			if (($env{'form.orgurl'}) && 
  421: 			    ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
  422: 			    my $dest=$env{'form.orgurl'};
  423: 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
  424: 			    &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
  425:                             if (($ferr) && ($tadv)) {
  426: 				&error_page($r,$ferr,$dest);
  427: 			    } else {
  428: 				$r->internal_redirect($dest);
  429: 			    }
  430: 			    return OK;
  431: 			} else {
  432: 			    if (!$env{'request.course.id'}) {
  433: 				&Apache::lonnet::appenv(
  434: 				      {"request.course.id"  => $cdom.'_'.$cnum});
  435: 				$furl='/adm/roles?tryagain=1';
  436: 				$msg=
  437: 				    '<h1><span class="LC_error">'.
  438: 				    &mt('Could not initialize [_1] at this time.',
  439: 					$env{'course.'.$cdom.'_'.$cnum.'.description'}).
  440: 				    '</span></h1><h3>'.&mt('Please try again.').'</h3>'.$ferr;
  441: 			    }
  442: 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
  443: 			    &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
  444: 
  445: 			    if (($ferr) && ($tadv)) {
  446: 				&error_page($r,$ferr,$furl);
  447: 			    } else {
  448: 				# Check to see if the user is a CC entering a course 
  449: 				# for the first time
  450: 				my (undef, undef, $role, $courseid) = split(/\./, $envkey);
  451: 				if (substr($courseid, 0, 1) eq '/') {
  452: 				    $courseid = substr($courseid, 1);
  453: 				}
  454: 				$courseid =~ s/\//_/;
  455: 				if ($role eq 'cc' && $env{'course.' . $courseid . 
  456: 							      '.course.helper.not.run'}) {
  457: 				    $furl = "/adm/helper/course.initialization.helper";
  458: 				    # Send the user to the course they selected
  459: 				} elsif ($env{'request.course.id'}) {
  460:                                     if ($env{'form.destinationurl'}) {
  461:                                         my $dest = $env{'form.destinationurl'};
  462:                                         if ($env{'form.destsymb'} ne '') {
  463:                                             my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
  464:                                             $dest .= '?symb='.$esc_symb;
  465:                                         }
  466:                                         &redirect_user($r,&mt('Entering [_1]',
  467:                                                       $env{'course.'.$courseid.'.description'}),
  468:                                                $dest,$msg,
  469:                                                $env{'environment.remotenavmap'});
  470:                                         return OK;
  471:                                     }
  472: 				    if (&Apache::lonnet::allowed('whn',
  473: 								 $env{'request.course.id'})
  474: 					|| &Apache::lonnet::allowed('whn',
  475: 								    $env{'request.course.id'}.'/'
  476: 								    .$env{'request.course.sec'})
  477: 					) {
  478: 					my $startpage = &courseloadpage($courseid);
  479: 					unless ($startpage eq 'firstres') {         
  480: 					    $msg = &mt('Entering [_1] ...',
  481: 						       $env{'course.'.$courseid.'.description'});
  482: 					    &redirect_user($r,&mt('New in course'),
  483: 							   '/adm/whatsnew?refpage=start',$msg,
  484: 							   $env{'environment.remotenavmap'});
  485: 					    return OK;
  486: 					}
  487: 				    }
  488: 				}
  489: # Are we allowed to look at the first resource?
  490: 				if ($furl !~ m|^/adm/|) {
  491: # Guess not ...
  492: 				    $furl=&Apache::lonpageflip::first_accessible_resource();
  493: 				}
  494:                                 $msg = &mt('Entering [_1] ...',
  495: 					   $env{'course.'.$courseid.'.description'});
  496: 				&redirect_user($r,&mt('Entering [_1]',
  497: 						      $env{'course.'.$courseid.'.description'}),
  498: 					       $furl,$msg,
  499: 					       $env{'environment.remotenavmap'});
  500: 			    }
  501: 			    return OK;
  502: 			}
  503: 		    }
  504:                     #
  505:                     # Send the user to the construction space they selected
  506:                     if ($role =~ /^(au|ca|aa)$/) {
  507:                         my $redirect_url = '/priv/';
  508:                         if ($role eq 'au') {
  509:                             $redirect_url.=$env{'user.name'};
  510:                         } else {
  511:                             $where =~ /\/(.*)$/;
  512:                             $redirect_url .= $1;
  513:                         }
  514:                         $redirect_url .= '/';
  515:                         &redirect_user($r,&mt('Entering Construction Space'),
  516:                                        $redirect_url);
  517:                         return OK;
  518:                     }
  519:                     if ($role eq 'dc') {
  520:                         my $redirect_url = '/adm/menu/';
  521:                         &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
  522:                                        $redirect_url);
  523:                         return OK;
  524:                     }
  525: 		}
  526:             }
  527:         }
  528:     }
  529: 
  530: 
  531: # =============================================================== No Roles Init
  532: 
  533:     &Apache::loncommon::content_type($r,'text/html');
  534:     &Apache::loncommon::no_cache($r);
  535:     $r->send_http_header;
  536:     return OK if $r->header_only;
  537: 
  538:     my $swinfo=&Apache::lonmenu::rawconfig();
  539:     my $start_page=&Apache::loncommon::start_page('User Roles');
  540:     my $standby=&mt('Role selected. Please stand by.');
  541:     $standby=~s/\n/\\n/g;
  542:     my $noscript='<span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';
  543: 
  544:     $r->print(<<ENDHEADER);
  545: $start_page
  546: <br />
  547: <noscript>
  548: $noscript
  549: </noscript>
  550: <script type="text/javascript">
  551: $swinfo
  552: window.focus();
  553: 
  554: active=true;
  555: 
  556: function enterrole (thisform,rolecode,buttonname) {
  557:     if (active) {
  558: 	active=false;
  559:         document.title='$standby';
  560:         window.status='$standby';
  561: 	thisform.newrole.value=rolecode;
  562: 	thisform.submit();
  563:     } else {
  564:        alert('$standby');
  565:     }   
  566: }
  567: </script>
  568: ENDHEADER
  569: 
  570: # ------------------------------------------ Get Error Message from Environment
  571: 
  572:     my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
  573:     if ($env{'user.error.msg'}) {
  574: 	$r->log_reason(
  575:    "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
  576:     }
  577: 
  578: # ------------------------------------------------- Can this user re-init, etc?
  579: 
  580:     my $advanced=$env{'user.adv'};
  581:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
  582:     my $tryagain=$env{'form.tryagain'};
  583:     my $reinit=$env{'user.reinit'};
  584:     delete $env{'user.reinit'};
  585: 
  586: # -------------------------------------------------------- Generate Page Output
  587: # --------------------------------------------------------------- Error Header?
  588:     if ($error) {
  589:         $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
  590: 	$r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
  591: 	if ($priv ne '') {
  592:             $r->print(&mt('Access  : ').&Apache::lonnet::plaintext($priv)."\n");
  593: 	}
  594: 	if ($fn ne '') {
  595:             $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
  596: 	}
  597: 	if ($msg ne '') {
  598:             $r->print(&mt('Action  : ').$msg."\n");
  599: 	}
  600: 	$r->print("</pre><hr />");
  601: 	my $url=$fn;
  602: 	my $last;
  603: 	if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
  604: 		&GDBM_READER(),0640)) {
  605: 	    $last=$hash{'last_known'};
  606: 	    untie(%hash);
  607: 	}
  608: 	if ($last) { $fn.='?symb='.&escape($last); }
  609: 
  610: 	&Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
  611: 					&Apache::lonenc::check_encrypt($fn));
  612:     } else {
  613:         if ($env{'user.error.msg'}) {
  614:             if ($reinit) {
  615:                 $r->print(
  616:  '<h3><span class="LC_error">'.
  617:  &mt('As your session file for the course has expired, you will need to re-select the course.').'</span></h3>');
  618:             } else {
  619: 	        $r->print(
  620:  '<h3><span class="LC_error">'.
  621:  &mt('You need to choose another user role or enter a specific course for this function').'</span></h3>');
  622: 	    }
  623:         }
  624:     }
  625: # -------------------------------------------------------- Choice or no choice?
  626:     if ($nochoose) {
  627: 	$r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
  628: 		  &mt('This action is currently not authorized.').'</span>'.
  629: 		  &Apache::loncommon::end_page());
  630: 	return OK;
  631:     } else {
  632:         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
  633:     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
  634:         }
  635:         $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
  636:         $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
  637:         $r->print('<input type="hidden" name="selectrole" value="1" />');
  638:         $r->print('<input type="hidden" name="newrole" value="" />');
  639:     }
  640:     my (%roletext,%sortrole,%roleclass);
  641:     my $countactive=0;
  642:     my $countfuture=0;
  643:     my $countwill=0;
  644:     my $inrole=0;
  645:     my $possiblerole='';
  646:     my %futureroles;
  647:     my %roles_nextlogin;
  648:     foreach $envkey (sort keys %env) {
  649:         my $button = 1;
  650:         my $switchserver='';
  651: 	my $roletext;
  652: 	my $sortkey;
  653:         if ($envkey=~/^user\.role\./) {
  654:             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
  655:             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
  656:             next if (!defined($role) || $role eq '' || $role =~ /^gr/);
  657:             $tremark='';
  658:             $tpstart='&nbsp;';
  659:             $tpend='&nbsp;';
  660:             if ($tstart) {
  661:                 $tpstart=&Apache::lonlocal::locallocaltime($tstart);
  662:             }
  663:             if ($tend) {
  664:                 $tpend=&Apache::lonlocal::locallocaltime($tend);
  665:             }
  666:             if ($env{'request.role'} eq $trolecode) {
  667: 		$tstatus='selected';
  668:             }
  669:             my $tbg;
  670:             if (($tstatus eq 'is') 
  671: 		|| ($tstatus eq 'selected') 
  672: 		|| ($tstatus eq 'will') 
  673: 		|| ($tstatus eq 'future') 
  674:                 || ($env{'form.showall'})) {
  675:                 if ($tstatus eq 'is') {
  676:                     $tbg='LC_roles_is';
  677: 		    $possiblerole=$trolecode;
  678: 		    $countactive++;
  679:                 } elsif ($tstatus eq 'future') {
  680:                     $tbg='LC_roles_future';
  681:                     $button=0;
  682:                     $futureroles{$trolecode} = $tstart.':'.$tend;
  683:                     $countfuture ++;
  684:                 } elsif ($tstatus eq 'will') {
  685:                     $tbg='LC_roles_will';
  686:                     $tremark.=&mt('Active at next login.').' ';
  687:                     $roles_nextlogin{$trolecode} = $tstart.':'.$tend;
  688:                     $countwill ++;
  689:                 } elsif ($tstatus eq 'expired') {
  690:                     $tbg='LC_roles_expired';
  691:                     $button=0;
  692:                 } elsif ($tstatus eq 'will_not') {
  693:                     $tbg='LC_roles_will_not';
  694:                     $tremark.=&mt('Expired after logout.').' ';
  695:                 } elsif ($tstatus eq 'selected') {
  696:                     $tbg='LC_roles_selected';
  697: 		    $inrole=1;
  698: 		    $countactive++;
  699:                     $tremark.=&mt('Currently selected.').' ';
  700:                 }
  701:                 my $trole;
  702:                 if ($role =~ /^cr\//) {
  703:                     my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
  704: 		    if ($tremark) { $tremark.='<br />'; }
  705:                     $tremark.=&mt('Defined by [_1] at [_2].',$rauthor,$rdomain);
  706: 		}
  707: 		$trole=Apache::lonnet::plaintext($role);
  708:                 my $ttype;
  709:                 my $twhere;
  710:                 my ($tdom,$trest,$tsection)=
  711:                     split(/\//,Apache::lonnet::declutter($where));
  712:                 # First, Co-Authorship roles
  713:                 if (($role eq 'ca') || ($role eq 'aa')) {
  714:                     my $home = &Apache::lonnet::homeserver($trest,$tdom);
  715: 		    my $allowed=0;
  716: 		    my @ids=&Apache::lonnet::current_machine_ids();
  717: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  718:                     if (!$allowed) {
  719: 			$button=0;
  720:                         $switchserver='otherserver='.$home.'&role='.$trolecode;
  721:                     }
  722:                     #next if ($home eq 'no_host');
  723:                     $home = &Apache::lonnet::hostname($home);
  724:                     $ttype='Construction Space';
  725:                     $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
  726: 			': '.$tdom.'<br />'.
  727:                         ' '.&mt('Server').':&nbsp;'.$home;
  728:                     $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
  729: 		    $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
  730: 		    $sortkey=$role."$trest:$tdom";
  731:                 } elsif ($role eq 'au') {
  732:                     # Authors
  733:                     my $home = &Apache::lonnet::homeserver
  734:                         ($env{'user.name'},$env{'user.domain'});
  735: 		    my $allowed=0;
  736: 		    my @ids=&Apache::lonnet::current_machine_ids();
  737: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  738:                     if (!$allowed) {
  739: 			$button=0;
  740:                         $switchserver='otherserver='.$home.'&role='.$trolecode;
  741:                     }
  742:                     #next if ($home eq 'no_host');
  743:                     $home = &Apache::lonnet::hostname($home);
  744:                     $ttype='Construction Space';
  745:                     $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
  746: 			':&nbsp;'.$home;
  747:                     $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
  748: 		    $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
  749: 		    $sortkey=$role;
  750:                 } elsif ($trest) {
  751:                     my $tcourseid=$tdom.'_'.$trest;
  752:                     $ttype = &Apache::loncommon::course_type($tcourseid);
  753:                     $trole = &Apache::lonnet::plaintext($role,$ttype);
  754:                     if ($env{'course.'.$tcourseid.'.description'}) {
  755:                         $twhere=$env{'course.'.$tcourseid.'.description'};
  756: 			$sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
  757:                         unless ($twhere eq &mt('Currently not available')) {
  758: 			    $twhere.=' <span class="LC_fontsize_small">'.
  759:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
  760:                                     '</span>';
  761: 			}
  762:                     } else {
  763:                         my %newhash=&Apache::lonnet::coursedescription($tcourseid);
  764:                         if (%newhash) {
  765: 			    $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
  766: 				"\0".$envkey;
  767:                             $twhere=$newhash{'description'}.
  768:                               ' <span class="LC_fontsize_small">'.
  769:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
  770:                               '</span>';
  771:                             $ttype = $newhash{'type'};
  772:                             $trole = &Apache::lonnet::plaintext($role,$ttype);
  773:                         } else {
  774:                             $twhere=&mt('Currently not available');
  775:                             $env{'course.'.$tcourseid.'.description'}=$twhere;
  776: 			    $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
  777:                             $ttype = 'Unavailable';
  778:                         }
  779:                     }
  780:                     if ($tsection) {
  781:                         $twhere.='<br />'.&mt('Section').': '.$tsection;
  782: 		    }
  783: 		    if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
  784:                 } elsif ($tdom) {
  785:                     $ttype='Domain';
  786:                     $twhere=$tdom;
  787: 		    $sortkey=$role.$twhere;
  788:                 } else {
  789:                     $ttype='System';
  790:                     $twhere=&mt('system wide');
  791: 		    $sortkey=$role.$twhere;
  792:                 }
  793:                 $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit);
  794: 		$roletext{$envkey}=$roletext;
  795: 		if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
  796: 		$sortrole{$sortkey}=$envkey;
  797: 		$roleclass{$envkey}=$ttype;
  798: 	    }
  799:         }
  800:     }
  801:     if ($env{'user.adv'}) {
  802:         $r->print(
  803:               '<p><label>'.&mt('Show all roles').': <input type="checkbox" name="showall"');
  804:         if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
  805:         $r->print(' /></label><input type="submit" value="'.&mt('Display').'" /></p>');
  806:     } else {
  807:         if ($countactive > 0) {
  808:             my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
  809:             my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); 
  810:             $r->print('<p>'.&mt('[_1]Visit the [_2]Course Catalog[_3] to view all [_4] LON-CAPA courses.','<b>','<a href="/adm/coursecatalog?showdom='.$esc_dom.'">','</a></b>',$domdesc).'<br />'.&mt('If a course is [_1]not[_2] in your list of current courses below, you may be able to enroll if self-enrollment is permitted.','<b>','</b>').'</p>');
  811:         }
  812:     }
  813: 
  814: # No active roles
  815:     if ($countactive==0) {
  816: 	if ($inrole) {
  817: 	    $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
  818: 	} else {
  819: 	    $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
  820: 	}
  821:         &findcourse_advice($r);
  822: 	$r->print('</form>');
  823:         if ($countfuture) {
  824:             $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
  825:             my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
  826:                                                $nochoose);
  827:             &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
  828:                             \%roletext);
  829:             my $tremark='';
  830:             my $tbg;
  831:             if ($env{'request.role'} eq 'cm') {
  832:                 $tbg="LC_roles_selected";
  833:                 $tremark=&mt('Currently selected.').' ';
  834:             } else {
  835:                 $tbg="LC_roles_is";
  836:             }
  837:             $r->print(&Apache::loncommon::start_data_table_row()
  838:                      .'<td class="'.$tbg.'">&nbsp;</td>'
  839:                      .'<td colspan="3">'
  840:                      .&mt('No role specified')
  841:                      .'</td>'
  842:                      .'<td>'.$tremark.'&nbsp;</td>'
  843:                      .&Apache::loncommon::end_data_table_row()
  844:             );
  845: 
  846:             $r->print(&Apache::loncommon::end_data_table());
  847:         }
  848:         $r->print(&Apache::loncommon::end_page());
  849: 	return OK;
  850:     }
  851: # ----------------------------------------------------------------------- Table
  852:     unless ((!&Apache::lonmenu::show_course()) || ($nochoose) || ($countactive==1)) {
  853: 	$r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
  854:     }
  855:     my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
  856:     if ($env{'environment.recentroles'}) {
  857:         my %recent_roles =
  858:                &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
  859: 	my $output='';
  860: 	foreach (sort(keys(%recent_roles))) {
  861: 	    if (defined($roletext{'user.role.'.$_})) {
  862: 		$output.=$roletext{'user.role.'.$_};
  863:                 if ($_ =~ m-dc\./($match_domain)/- 
  864: 		    && $dcroles{$1}) {
  865: 		    $output .= &adhoc_roles_row($1,'recent');
  866:                 }
  867: 	    } elsif ($numdc > 0) {
  868:                 unless ($_ =~/^error\:/) {
  869:                     $output.=&display_cc_role('user.role.'.$_);
  870:                 }
  871:             } 
  872: 	}
  873: 	if ($output) {
  874: 	    $r->print(&Apache::loncommon::start_data_table_empty_row()
  875:                      .'<td align="center" colspan="5">'
  876:                      .&mt('Recent Roles')
  877:                      .'</td>'
  878:                      .&Apache::loncommon::end_data_table_empty_row()
  879:             );
  880: 	    $r->print($output);
  881:             $doheaders ++;
  882: 	}
  883:     }
  884: 
  885:     if ($numdc > 0) {
  886:         $r->print(&coursepick_jscript());
  887:         $r->print(&Apache::loncommon::coursebrowser_javascript().
  888:                   &Apache::loncommon::authorbrowser_javascript());
  889:     }
  890:     &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
  891:     if ($countactive > 1) {
  892:         my $tremark='';
  893:         my $tbg;
  894:         if ($env{'request.role'} eq 'cm') {
  895:             $tbg="LC_roles_selected";
  896:             $tremark=&mt('Currently selected.').' ';
  897:         } else {
  898:                 $tbg="LC_roles_is";
  899:         }
  900:         $r->print(&Apache::loncommon::start_data_table_row());
  901:         unless ($nochoose) {
  902: 	    if ($env{'request.role'} ne 'cm') {
  903: 	        $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
  904: 		          &mt('Select').'" name="cm" /></td>');
  905: 	    } else {
  906: 	        $r->print('<td class="'.$tbg.'">&nbsp;</td>');
  907: 	    }
  908:         }
  909:         $r->print('<td colspan="3">'
  910:                  .&mt('No role specified')
  911:                  .'</td>'
  912:                  .'<td>'.$tremark.'&nbsp;</td>'
  913:                  .&Apache::loncommon::end_data_table_row()
  914:         );
  915:     } 
  916:     $r->print(&Apache::loncommon::end_data_table());
  917:     unless ($nochoose) {
  918: 	$r->print("</form>\n");
  919:     }
  920: # ------------------------------------------------------------ Privileges Info
  921:     if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
  922: 	$r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
  923: 	$r->print(&privileges_info());
  924:     }
  925:     $r->print(&Apache::lonnet::getannounce());
  926:     if ($advanced) {
  927:         my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
  928: 	$r->print('<p><small><i>'
  929:                  .&mt('This is LON-CAPA [_1]',$r->dir_config('lonVersion'))
  930: 		 .'</i><br />'
  931: 		 .'<a href="/adm/logout">'.&mt('Logout').'</a>&nbsp;&nbsp;'
  932:                  .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
  933:                  .&mt('Course Catalog')
  934:                  .'</small></p>');
  935:     }
  936:     $r->print(&Apache::loncommon::end_page());
  937:     return OK;
  938: }
  939: 
  940: sub roletable_headers {
  941:     my ($r,$roleclass,$sortrole,$nochoose) = @_;
  942:     my $doheaders;
  943:     if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
  944:         $r->print('<br />'
  945:                  .&Apache::loncommon::start_data_table()
  946:                  .&Apache::loncommon::start_data_table_header_row()
  947:         );
  948:         if (!$nochoose) { $r->print('<th>&nbsp;</th>'); }
  949:         $r->print('<th>'.&mt('User Role').'</th>'
  950:                  .'<th>'.&mt('Extent').'</th>'
  951:                  .'<th>'.&mt('Start').'</th>'
  952:                  .'<th>'.&mt('End').'</th>'
  953:                  .&Apache::loncommon::end_data_table_header_row()
  954:         );
  955:         $doheaders=-1;
  956:         my @roletypes = &roletypes();
  957:         foreach my $type (@roletypes) {
  958:             my $haverole=0;
  959:             foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
  960:                 if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
  961:                     $haverole=1;
  962:                 }
  963:             }
  964:             if ($haverole) { $doheaders++; }
  965:         }
  966:     }
  967:     return $doheaders;
  968: }
  969: 
  970: sub roletypes {
  971:     my @types = ('Domain','Construction Space','Course','Unavailable','System');
  972:     return @types; 
  973: }
  974: 
  975: sub print_rolerows {
  976:     my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
  977:     if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
  978:         my @types = &roletypes();
  979:         foreach my $type (@types) {
  980:             my $output;
  981:             foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
  982:                 if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
  983:                     if (ref($roletext) eq 'HASH') {
  984:                         $output.=$roletext->{$sortrole->{$which}};
  985:                         if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
  986:                             if (ref($dcroles) eq 'HASH') {
  987:                                 if ($dcroles->{$1}) {
  988:                                     $output .= &adhoc_roles_row($1,'');
  989:                                 }
  990:                             }
  991:                         }
  992:                     }
  993:                 }
  994:             }
  995:             if ($output) {
  996:                 if ($doheaders > 0) {
  997:                     $r->print(&Apache::loncommon::start_data_table_empty_row()
  998:                              .'<td align="center" colspan="5">'
  999:                              .&mt($type)
 1000:                              .'</td>'
 1001:                              .&Apache::loncommon::end_data_table_empty_row()
 1002:                     );
 1003:                 }
 1004:                 $r->print($output);
 1005:             }
 1006:         }
 1007:     }
 1008: }
 1009: 
 1010: sub findcourse_advice {
 1011:     my ($r) = @_;
 1012:     my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
 1013:     my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
 1014:     if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
 1015:         $r->print(&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).'
 1016: <ul>
 1017:  <li>'.&mt('The course has yet to be created.').'</li>
 1018:  <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
 1019:  <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
 1020:  <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
 1021:  <li>'.&mt('You registered for the course recently and there is a time lag between the time you register, and the time this information becomes available for the update of LON-CAPA course rosters.').'</li>
 1022:  </ul>');
 1023:     } else {
 1024:         $r->print(&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'<br />');
 1025:     }
 1026:     $r->print('<p>'.&mt('The [_1]Course Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created.','<a href="/adm/coursecatalog?showdom='.$esc_dom.'">','</a>',$domdesc).'<br />');
 1027:     $r->print(&mt('You can search the course catalog for courses which permit self-enrollment, if you would like to enroll in a course.').'</p>');
 1028:     return;
 1029: }
 1030: 
 1031: sub privileges_info {
 1032:     my ($which) = @_;
 1033:     my $output;
 1034: 
 1035:     $which ||= $env{'request.role'};
 1036: 
 1037:     foreach my $envkey (sort(keys(%env))) {
 1038: 	next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
 1039: 
 1040: 	my $where=$1;
 1041: 	my $ttype;
 1042: 	my $twhere;
 1043: 	my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
 1044: 	if ($trest) {
 1045: 	    if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
 1046: 		$ttype='Construction Space';
 1047: 		$twhere='User: '.$trest.', Domain: '.$tdom;
 1048: 	    } else {
 1049: 		$ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
 1050: 		$twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
 1051: 		if ($tsec) {
 1052: 		    my $sec_type = 'Section';
 1053: 		    if (exists($env{"user.role.gr.$where"})) {
 1054: 			$sec_type = 'Group';
 1055: 		    }
 1056: 		    $twhere.=' ('.$sec_type.': '.$tsec.')';
 1057: 		}
 1058: 	    }
 1059: 	} elsif ($tdom) {
 1060: 	    $ttype='Domain';
 1061: 	    $twhere=$tdom;
 1062: 	} else {
 1063: 	    $ttype='System';
 1064: 	    $twhere='/';
 1065: 	}
 1066: 	$output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
 1067: 	foreach my $priv (sort(split(/:/,$env{$envkey}))) {
 1068: 	    next if (!$priv);
 1069: 
 1070: 	    my ($prv,$restr)=split(/\&/,$priv);
 1071: 	    my $trestr='';
 1072: 	    if ($restr ne 'F') {
 1073: 		$trestr.=' ('.
 1074: 		    join(', ',
 1075: 			 map { &Apache::lonnet::plaintext($_) } 
 1076: 			     (split('',$restr))).') ';
 1077: 	    }
 1078: 	    $output .= "\n\t".
 1079: 		'<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
 1080: 	}
 1081: 	$output .= "\n".'</ul>';
 1082:     }
 1083:     return $output;
 1084: }
 1085: 
 1086: sub role_status {
 1087:     my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
 1088:     my @pwhere = ();
 1089:     if (exists($env{$rolekey}) && $env{$rolekey} ne '') {
 1090:         (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
 1091:         unless (!defined($$role) || $$role eq '') {
 1092:             $$where=join('.',@pwhere);
 1093:             $$trolecode=$$role.'.'.$$where;
 1094:             ($$tstart,$$tend)=split(/\./,$env{$rolekey});
 1095:             $$tstatus='is';
 1096:             if ($$tstart && $$tstart>$then) {
 1097: 		$$tstatus='future';
 1098: 		if ($$tstart<$now) { $$tstatus='will'; }
 1099:             }
 1100:             if ($$tend) {
 1101:                 if ($$tend<$then) {
 1102:                     $$tstatus='expired';
 1103:                 } elsif ($$tend<$now) {
 1104:                     $$tstatus='will_not';
 1105:                 }
 1106:             }
 1107:         }
 1108:     }
 1109: }
 1110: 
 1111: sub build_roletext {
 1112:     my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit) = @_;
 1113:     my $roletext=&Apache::loncommon::start_data_table_row();
 1114:     my $is_dc=($trolecode =~ m/^dc\./);
 1115:     my $rowspan=($is_dc) ? ''
 1116:                          : ' rowspan="2" ';
 1117: 
 1118:     unless ($nochoose) {
 1119:         my $buttonname=$trolecode;
 1120:         $buttonname=~s/\W//g;
 1121:         if (!$button) {
 1122:             if ($switchserver) {
 1123:                 $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
 1124:                           .'<a href="/adm/switchserver?'.$switchserver.'">'
 1125:                           .&mt('Switch Server')
 1126:                           .'</a></td>';
 1127:             } else {
 1128:                 $roletext.=('<td'.$rowspan.' class="'.$tbg.'">&nbsp;</td>');
 1129:             }
 1130:         } elsif ($tstatus eq 'is') {
 1131:             $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
 1132:                         '<input name="'.$buttonname.'" type="button" value="'.
 1133:                         &mt('Select').'" onClick="javascript:enterrole(this.form,\''.
 1134:                         $trolecode."','".$buttonname.'\');" /></td>';
 1135:         } elsif ($tryagain) {
 1136:             $roletext.=
 1137:                 '<td'.$rowspan.' class="'.$tbg.'">'.
 1138:                 '<input name="'.$buttonname.'" type="button" value="'.
 1139:                 &mt('Try Selecting Again').'" onClick="javascript:enterrole(this.form,\''.
 1140:                         $trolecode."','".$buttonname.'\');" /></td>';
 1141:         } elsif ($advanced) {
 1142:             $roletext.=
 1143:                 '<td'.$rowspan.' class="'.$tbg.'">'.
 1144:                 '<input name="'.$buttonname.'" type="button" value="'.
 1145:                 &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
 1146:                         $trolecode."','".$buttonname.'\');" /></td>';
 1147:         } elsif ($reinit) {
 1148:             $roletext.= 
 1149:                 '<td'.$rowspan.' class="'.$tbg.'">'.
 1150:                 '<input name="'.$buttonname.'" type="button" value="'.
 1151:                 &mt('Re-Select').'" onClick="javascript:enterrole(this.form,\''.
 1152:                         $trolecode."','".$buttonname.'\');" /></td>';
 1153:         } else {
 1154:             $roletext.=
 1155:                 '<td'.$rowspan.' class="'.$tbg.'">'.
 1156:                 '<input name="'.$buttonname.'" type="button" value="'.
 1157:                 &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
 1158:                         $trolecode."','".$buttonname.'\');" /></td>';
 1159:         }
 1160:     }
 1161:     if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
 1162: 	$tremark.=&Apache::lonannounce::showday(time,1,
 1163: 			 &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
 1164:     }
 1165:     $roletext.='<td>'.$trole.'</td>'
 1166:               .'<td>'.$twhere.'</td>'
 1167:               .'<td>'.$tpstart.'</td>'
 1168:               .'<td>'.$tpend.'</td>'
 1169:               .&Apache::loncommon::end_data_table_row();
 1170:     if (!$is_dc) {
 1171:         $roletext.=&Apache::loncommon::continue_data_table_row()
 1172:                   .'<td colspan="4">'
 1173:                   .$tremark.'&nbsp;'
 1174:                   .'</td>'
 1175:                   .&Apache::loncommon::end_data_table_row();
 1176:     }
 1177:     return $roletext;
 1178: }
 1179: 
 1180: sub check_needs_switchserver {
 1181:     my ($possiblerole) = @_;
 1182:     my $needs_switchserver;
 1183:     my ($role,$where) = split(/\./,$possiblerole,2);
 1184:     my (undef,$tdom,$twho) = split(/\//,$where);
 1185:     my ($server_status,$home);
 1186:     if (($role eq 'ca') || ($role eq 'aa')) {
 1187:         ($server_status,$home) = &check_author_homeserver($twho,$tdom);
 1188:     } else {
 1189:         ($server_status,$home) = &check_author_homeserver($env{'user.name'},
 1190:                                                           $env{'user.domain'});
 1191:     }
 1192:     if ($server_status eq 'switchserver') {
 1193:         $needs_switchserver = 1;
 1194:     }
 1195:     return $needs_switchserver;
 1196: }
 1197: 
 1198: sub check_author_homeserver {
 1199:     my ($uname,$udom)=@_;
 1200:     if (($uname eq '') || ($udom eq '')) {
 1201:         return ('fail','');
 1202:     }
 1203:     my $home = &Apache::lonnet::homeserver($uname,$udom);
 1204:     if (&Apache::lonnet::host_domain($home) ne $udom) {
 1205:         return ('fail',$home);
 1206:     }
 1207:     my @ids=&Apache::lonnet::current_machine_ids();
 1208:     if (grep(/^\Q$home\E$/,@ids)) {
 1209:         return ('ok',$home);
 1210:     } else {
 1211:         return ('switchserver',$home);
 1212:     }
 1213: }
 1214: 
 1215: sub check_privs {
 1216:     my ($cdom,$cnum,$then,$now,$checkrole) = @_;
 1217:     my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum; 
 1218:     if ($env{$cckey}) {
 1219:         my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
 1220:         &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
 1221:         unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
 1222:             &set_privileges($cdom,$cnum,$checkrole);
 1223:         }
 1224:     } else {
 1225:         &set_privileges($cdom,$cnum,$checkrole);
 1226:     }
 1227: }
 1228: 
 1229: sub check_fordc {
 1230:     my ($dcroles,$then) = @_;
 1231:     my $numdc = 0;
 1232:     if ($env{'user.adv'}) {
 1233:         foreach my $envkey (sort keys %env) {
 1234:             if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
 1235:                 my $dcdom = $1;
 1236:                 my $livedc = 1;
 1237:                 my ($tstart,$tend)=split(/\./,$env{$envkey});
 1238:                 if ($tstart && $tstart>$then) { $livedc = 0; }
 1239:                 if ($tend   && $tend  <$then) { $livedc = 0; }
 1240:                 if ($livedc) {
 1241:                     $$dcroles{$dcdom} = $envkey;
 1242:                     $numdc++;
 1243:                 }
 1244:             }
 1245:         }
 1246:     }
 1247:     return $numdc;
 1248: }
 1249: 
 1250: sub adhoc_course_role {
 1251:     my ($then) = @_; 
 1252:     my ($cdom,$cnum);
 1253:     $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1254:     $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1255:     if (&check_forcc($cdom,$cnum,$then)) {
 1256:         my $setprivs;
 1257:         if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
 1258:             $setprivs = 1;
 1259:         } else {
 1260:             my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
 1261:             if (($start && ($start>$then || $start == -1)) ||
 1262:                 ($end && $end<$then)) {
 1263:                 $setprivs = 1;
 1264:             }
 1265:         } 
 1266:         if ($setprivs) {
 1267:             if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 1268:                 my $role = $1;
 1269:                 my $custom_role = $2;
 1270:                 my $usec = $3;
 1271:                 if ($role eq 'cr') {
 1272:                     if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
 1273:                         $role .= $custom_role;
 1274:                     } else {
 1275:                         return;
 1276:                     }
 1277:                 }
 1278:                 my (%userroles,%newrole,%newgroups,%group_privs);
 1279:                 my %cgroups =
 1280:                     &Apache::lonnet::get_active_groups($env{'user.domain'},
 1281:                                             $env{'user.name'},$cdom,$cnum);
 1282:                 foreach my $group (keys(%cgroups)) {
 1283:                     $group_privs{$group} =
 1284:                         $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
 1285:                 }
 1286:                 $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
 1287:                 my $area = '/'.$cdom.'/'.$cnum;
 1288:                 my $spec = $role.'.'.$area;
 1289:                 if ($usec ne '') {
 1290:                     $spec .= '/'.$usec;
 1291:                     $area .= '/'.$usec;
 1292:                 }
 1293:                 &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
 1294:                 &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
 1295:                 my $adhocstart = $then-1;
 1296:                 $userroles{'user.role.'.$spec} = $adhocstart.'.';
 1297:                 &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
 1298:             }
 1299:         }
 1300:     }
 1301:     return;
 1302: }
 1303: 
 1304: sub check_forcc {
 1305:     my ($cdom,$cnum,$then) = @_;
 1306:     my $is_cc;
 1307:     if ($cdom ne '' && $cnum ne '') {
 1308:         if (&Apache::lonnet::is_course($cdom,$cnum)) {
 1309:             my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;
 1310:             if (defined($env{$envkey})) {
 1311:                 $is_cc = 1;
 1312:                 my ($tstart,$tend)=split(/\./,$env{$envkey});
 1313:                 if ($tstart && $tstart>$then) { $is_cc = 0; }
 1314:                 if ($tend   && $tend  <$then) { $is_cc = 0; }
 1315:             }
 1316:         }
 1317:     }
 1318:     return $is_cc;
 1319: }
 1320: 
 1321: sub courselink {
 1322:     my ($dcdom,$rowtype) = @_;
 1323:     my $courseform=&Apache::loncommon::selectcourse_link
 1324:                    ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
 1325:                     'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
 1326:                     $dcdom,$dcdom,undef);
 1327:     my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
 1328:                       '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
 1329:                       '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
 1330:                       '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
 1331:     return $courseform.$hiddenitems;
 1332: }
 1333: 
 1334: sub coursepick_jscript {
 1335:     my %lt = &Apache::lonlocal::texthash(
 1336:                   plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.",
 1337:                   youc => 'You can only use this screen to select courses in the current domain.',
 1338:              );
 1339:     my $verify_script = <<"END";
 1340: <script type="text/javascript">
 1341: function verifyCoursePick(caller) {
 1342:     var numbutton = getIndex(caller)
 1343:     var pickedCourse = document.rolechoice.elements[numbutton+4].value
 1344:     var pickedDomain = document.rolechoice.elements[numbutton+2].value
 1345:     if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
 1346:         if (pickedCourse != '') {
 1347:             if (numbutton != -1) {
 1348:                 var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
 1349:                 document.rolechoice.elements[numbutton+1].name = courseTarget
 1350:                 document.rolechoice.submit()
 1351:             }
 1352:         }
 1353:         else {
 1354:             alert("$lt{'plsu'}");
 1355:         }
 1356:     }
 1357:     else {
 1358:         alert("$lt{'youc'}")
 1359:     }
 1360: }
 1361: function getIndex(caller) {
 1362:     for (var i=0;i<document.rolechoice.elements.length;i++) {
 1363:         if (document.rolechoice.elements[i] == caller) {
 1364:             return i;
 1365:         }
 1366:     }
 1367:     return -1;
 1368: }
 1369: </script>
 1370: END
 1371:     return $verify_script;
 1372: }
 1373: 
 1374: sub coauthorlink {
 1375:     my ($dcdom,$rowtype) = @_;
 1376:     my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
 1377:     my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
 1378:     return $coauthorform.$hiddenitems;
 1379: }
 1380: 
 1381: sub display_cc_role {
 1382:     my $rolekey = shift;
 1383:     my $roletext;
 1384:     my $advanced = $env{'user.adv'};
 1385:     my $tryagain = $env{'form.tryagain'};
 1386:     unless ($rolekey =~/^error\:/) {
 1387:         if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {
 1388:             my $tcourseid = $1.'_'.$2;
 1389:             my $trolecode = 'cc./'.$1.'/'.$2;
 1390:             my $twhere;
 1391:             my $ttype;
 1392:             my $tbg='LC_roles_is';
 1393:             my %newhash=&Apache::lonnet::coursedescription($tcourseid);
 1394:             if (%newhash) {
 1395:                 $twhere=$newhash{'description'}.
 1396:                         ' <span style="LC_fontsize_small">'.
 1397:                         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1).
 1398:                         '</span>';
 1399:                 $ttype = $newhash{'type'};
 1400:             } else {
 1401:                 $twhere=&mt('Currently not available');
 1402:                 $env{'course.'.$tcourseid.'.description'}=$twhere;
 1403:             }
 1404:             my $trole = &Apache::lonnet::plaintext('cc',$ttype);
 1405:             $twhere.="<br />".&mt('Domain').":".$1;
 1406:             $roletext = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
 1407:         }
 1408:     }
 1409:     return ($roletext);
 1410: }
 1411: 
 1412: sub adhoc_roles_row {
 1413:     my ($dcdom,$rowtype) = @_;
 1414:     my $output = &Apache::loncommon::continue_data_table_row()
 1415:                  .' <td colspan="5">'
 1416:                  .'<table><tr><td>'
 1417:                  .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
 1418:                      ,'<span class="LC_cusr_emph">','</span>',$dcdom)
 1419:                  .'</td>'
 1420:                  .'<td>';
 1421:     my $selectcclink = &courselink($dcdom,$rowtype);
 1422:     my $ccrole = &Apache::lonnet::plaintext('cc');
 1423:     my $carole = &Apache::lonnet::plaintext('ca');
 1424:     my $selectcalink = &coauthorlink($dcdom,$rowtype);
 1425:     $output.=&mt('[_1]: [_2]',$ccrole,$selectcclink)
 1426:             .'<br /></td>'
 1427:             .'<td>&nbsp;&nbsp;</td>'
 1428:             .'<td>'.&mt('[_1]: [_2]',$carole,$selectcalink).'<br /></td>'
 1429:             .'</tr></table>'
 1430:             .'</td>'
 1431:             .&Apache::loncommon::end_data_table_row();
 1432:     return $output;
 1433: }
 1434: 
 1435: sub recent_filename {
 1436:     my $area=shift;
 1437:     return 'nohist_recent_'.&escape($area);
 1438: }
 1439: 
 1440: sub set_privileges {
 1441: # role can be cc or ca
 1442:     my ($dcdom,$pickedcourse,$role) = @_;
 1443:     my $area = '/'.$dcdom.'/'.$pickedcourse;
 1444:     my $spec = $role.'.'.$area;
 1445:     my %userroles = &Apache::lonnet::set_arearole($role,$area,'','',
 1446: 						  $env{'user.domain'},
 1447: 						  $env{'user.name'});
 1448:     my %ccrole = ();
 1449:     &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
 1450:     my ($author,$adv)= &Apache::lonnet::set_userprivs(\%userroles,\%ccrole);
 1451:     &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
 1452: 
 1453:     &Apache::lonnet::log($env{'user.domain'},
 1454:                          $env{'user.name'},
 1455:                          $env{'user.home'},
 1456:                         "Role ".$role);
 1457:     &Apache::lonnet::appenv(
 1458:                           {'request.role'        => $spec,
 1459:                           'request.role.domain' => $dcdom,
 1460:                           'request.course.sec'  => ''});
 1461:     my $tadv=0;
 1462:     if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
 1463:     &Apache::lonnet::appenv({'request.role.adv'    => $tadv});
 1464: }
 1465: 
 1466: sub courseloadpage {
 1467:     my ($courseid) = @_;
 1468:     my $startpage;
 1469:     my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
 1470: 					      [$courseid.':courseinit']);
 1471:     my ($tmp) = %entry_settings;
 1472:     unless ($tmp =~ /^error: 2 /) {
 1473:         $startpage = $entry_settings{$courseid.':courseinit'};
 1474:     }
 1475:     if ($startpage eq '') {
 1476:         if (exists($env{'environment.course_init_display'})) {
 1477:             $startpage = $env{'environment.course_init_display'};
 1478:         }
 1479:     }
 1480:     return $startpage;
 1481: }
 1482: 
 1483: 1;
 1484: __END__
 1485: 
 1486: =head1 NAME
 1487: 
 1488: Apache::lonroles - User Roles Screen
 1489: 
 1490: =head1 SYNOPSIS
 1491: 
 1492: Invoked by /etc/httpd/conf/srm.conf:
 1493: 
 1494:  <Location /adm/roles>
 1495:  PerlAccessHandler       Apache::lonacc
 1496:  SetHandler perl-script
 1497:  PerlHandler Apache::lonroles
 1498:  ErrorDocument     403 /adm/login
 1499:  ErrorDocument	  500 /adm/errorhandler
 1500:  </Location>
 1501: 
 1502: =head1 OVERVIEW
 1503: 
 1504: =head2 Choosing Roles
 1505: 
 1506: C<lonroles> is a handler that allows a user to switch roles in
 1507: mid-session. LON-CAPA attempts to work with "No Role Specified", the
 1508: default role that a user has before selecting a role, as widely as
 1509: possible, but certain handlers for example need specification which
 1510: course they should act on, etc. Both in this scenario, and when the
 1511: handler determines via C<lonnet>'s C<&allowed> function that a certain
 1512: action is not allowed, C<lonroles> is used as error handler. This
 1513: allows the user to select another role which may have permission to do
 1514: what they were trying to do. C<lonroles> can also be accessed via the
 1515: B<CRS> button in the Remote Control. 
 1516: 
 1517: =begin latex
 1518: 
 1519: \begin{figure}
 1520: \begin{center}
 1521: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
 1522:   \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
 1523: \end{center}
 1524: \end{figure}
 1525: 
 1526: =end latex
 1527: 
 1528: =head2 Role Initialization
 1529: 
 1530: 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.
 1531: 
 1532: =head1 INTRODUCTION
 1533: 
 1534: This module enables a user to select what role he wishes to
 1535: operate under (instructor, student, teaching assistant, course
 1536: coordinator, etc).  These roles are pre-established by the actions
 1537: of upper-level users.
 1538: 
 1539: This is part of the LearningOnline Network with CAPA project
 1540: described at http://www.lon-capa.org.
 1541: 
 1542: =head1 HANDLER SUBROUTINE
 1543: 
 1544: This routine is called by Apache and mod_perl.
 1545: 
 1546: =over 4
 1547: 
 1548: =item *
 1549: 
 1550: Roles Initialization (yes/no)
 1551: 
 1552: =item *
 1553: 
 1554: Get Error Message from Environment
 1555: 
 1556: =item *
 1557: 
 1558: Who is this?
 1559: 
 1560: =item *
 1561: 
 1562: Generate Page Output
 1563: 
 1564: =item *
 1565: 
 1566: Choice or no choice
 1567: 
 1568: =item *
 1569: 
 1570: Table
 1571: 
 1572: =item *
 1573: 
 1574: Privileges
 1575: 
 1576: =back
 1577: 
 1578: =cut

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