File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.269.2.27: download - view: text, annotated - select for diffs
Sun Oct 23 18:30:32 2016 UTC (7 years, 8 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.315, 1.316, 1.317, 1.318

    1: # The LearningOnline Network with CAPA
    2: # User Roles Screen
    3: #
    4: # $Id: lonroles.pm,v 1.269.2.27 2016/10/23 18:30:32 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: =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.
   61: 
   62: =begin latex
   63: 
   64: \begin{figure}
   65: \begin{center}
   66: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
   67:   \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
   68: \end{center}
   69: \end{figure}
   70: 
   71: =end latex
   72: 
   73: =head2 Role Initialization
   74: 
   75: 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.
   76: 
   77: =head1 INTRODUCTION
   78: 
   79: This module enables a user to select what role he wishes to
   80: operate under (instructor, student, teaching assistant, course
   81: coordinator, etc).  These roles are pre-established by the actions
   82: of upper-level users.
   83: 
   84: This is part of the LearningOnline Network with CAPA project
   85: described at http://www.lon-capa.org.
   86: 
   87: =head1 HANDLER SUBROUTINE
   88: 
   89: This routine is called by Apache and mod_perl.
   90: 
   91: =over 4
   92: 
   93: =item *
   94: 
   95: Roles Initialization (yes/no)
   96: 
   97: =item *
   98: 
   99: Get Error Message from Environment
  100: 
  101: =item *
  102: 
  103: Who is this?
  104: 
  105: =item *
  106: 
  107: Generate Page Output
  108: 
  109: =item *
  110: 
  111: Choice or no choice
  112: 
  113: =item *
  114: 
  115: Table
  116: 
  117: =item *
  118: 
  119: Privileges
  120: 
  121: =back
  122: 
  123: =cut
  124: 
  125: 
  126: package Apache::lonroles;
  127: 
  128: use strict;
  129: use Apache::lonnet;
  130: use Apache::lonuserstate();
  131: use Apache::Constants qw(:common REDIRECT);
  132: use Apache::File();
  133: use Apache::lonmenu;
  134: use Apache::loncommon;
  135: use Apache::lonhtmlcommon;
  136: use Apache::lonannounce;
  137: use Apache::lonlocal;
  138: use Apache::lonpageflip();
  139: use Apache::lonnavdisplay();
  140: use Apache::loncoursequeueadmin;
  141: use Apache::longroup;
  142: use Apache::lonrss;
  143: use GDBM_File;
  144: use LONCAPA qw(:DEFAULT :match);
  145: use HTML::Entities;
  146:  
  147: 
  148: sub redirect_user {
  149:     my ($r,$title,$url,$msg) = @_;
  150:     $msg = $title if (! defined($msg));
  151:     &Apache::loncommon::content_type($r,'text/html');
  152:     &Apache::loncommon::no_cache($r);
  153:     $r->send_http_header;
  154:     my $swinfo=&Apache::lonmenu::rawconfig();
  155: 
  156:     # Breadcrumbs
  157:     my $brcrum = [{'href' => $url,
  158:                    'text' => 'Switching Role'},];
  159:     my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
  160:                                                     {'redirect' => [1,$url],
  161:                                                      'bread_crumbs' => $brcrum,});
  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: // <![CDATA[
  171: $swinfo
  172: // ]]>
  173: </script>
  174: <p>$msg</p>
  175: $end_page
  176: ENDREDIR
  177:     return;
  178: }
  179: 
  180: sub error_page {
  181:     my ($r,$error,$dest)=@_;
  182:     &Apache::loncommon::content_type($r,'text/html');
  183:     &Apache::loncommon::no_cache($r);
  184:     $r->send_http_header;
  185:     return OK if $r->header_only;
  186:     # Breadcrumbs
  187:     my $brcrum = [{'href' => $dest,
  188:                    'text' => 'Problems during Course Initialization'},];
  189:     $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
  190:                                              undef,
  191:                                              {'bread_crumbs' => $brcrum,})
  192:     );
  193:     $r->print(
  194:         '<script type="text/javascript">'.
  195:         '// <![CDATA['.
  196:         &Apache::lonmenu::rawconfig().
  197:         '// ]]>'.
  198:         '</script>'.
  199: 	      '<p class="LC_error">'.&mt('The following problems occurred:').
  200:           '<br />'.
  201: 	      $error.
  202: 	      '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'
  203:     );
  204:     $r->print(&Apache::loncommon::end_page());
  205: }
  206: 
  207: sub handler {
  208: 
  209:     my $r = shift;
  210: 
  211:     # Check for critical messages and redirect if present.
  212:     my ($redirect,$url) = &Apache::loncommon::critical_redirect(300);
  213:     if ($redirect) {
  214:         &Apache::loncommon::content_type($r,'text/html');
  215:         $r->header_out(Location => $url);
  216:         return REDIRECT;
  217:     }
  218: 
  219:     my $now=time;
  220:     my $then=$env{'user.login.time'};
  221:     my $refresh=$env{'user.refresh.time'};
  222:     my $update=$env{'user.update.time'};
  223:     if (!$refresh) {
  224:         $refresh = $then;
  225:     }
  226:     if (!$update) {
  227:         $update = $then;
  228:     }
  229: 
  230:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
  231: 
  232: # -------------------------------------------------- Check if setting hot list
  233:     my $hotlist;
  234:     if ($env{'form.action'} eq 'verify_and_change_rolespref') {
  235:         $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
  236:     }
  237: 
  238: # -------------------------------------------------------- Check for new roles
  239:     my $updateresult;
  240:     if ($env{'form.state'} eq 'doupdate') {
  241:         my $show_course=&Apache::loncommon::show_course();
  242:         my $checkingtxt;
  243:         if ($show_course) {
  244:             $checkingtxt = &mt('Checking for new courses ...');
  245:         } else {
  246:             $checkingtxt = &mt('Checking for new roles ...');
  247:         }
  248:         $updateresult = $checkingtxt;
  249:         $updateresult .= &update_session_roles();
  250:         &Apache::lonnet::appenv({'user.update.time'  => $now});
  251:         $update = $now;
  252:         &Apache::loncoursequeueadmin::reqauthor_check();
  253:     }
  254: 
  255: # -------------------------------------------------- Check for author requests
  256:     my $reqauthor;
  257:     if ($env{'form.state'} eq 'requestauthor') {
  258:        $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
  259:     }
  260: 
  261:     my $envkey;
  262:     my %dcroles = ();
  263:     my %dhroles = ();
  264:     my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then);
  265:     my $loncaparev = $r->dir_config('lonVersion');
  266: 
  267: # ================================================================== Roles Init
  268:     if ($env{'form.selectrole'}) {
  269: 
  270:         my $locknum=&Apache::lonnet::get_locks();
  271:         if ($locknum) { return 409; }
  272: 
  273:         my $custom_adhoc;
  274:         if ($env{'form.newrole'}) {
  275:             $env{'form.'.$env{'form.newrole'}}=1;
  276: # Check if this is a Domain Helpdesk role trying to enter a course
  277:             if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) {
  278:                 if ($dhroles{$1}) {
  279:                     $custom_adhoc = 1;
  280:                 }
  281:             }
  282: 	}
  283: 	if ($env{'request.course.id'}) {
  284:             # Check if user is CC trying to select a course role
  285:             if ($env{'form.switchrole'}) {
  286:                 my $switch_is_active;
  287:                 if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
  288:                     my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
  289:                     if (!$end || $end > $now) {
  290:                         if (!$start || $start < $update) {
  291:                             $switch_is_active = 1;
  292:                         }
  293:                     }
  294:                 }
  295:                 unless ($switch_is_active) {
  296:                     &adhoc_course_role($refresh,$update,$then);
  297:                 }
  298:             }
  299: 	    my %temp=('logout_'.$env{'request.course.id'} => time);
  300: 	    &Apache::lonnet::put('email_status',\%temp);
  301: 	    &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
  302: 	}
  303: 	&Apache::lonnet::appenv({"request.course.id"           => '',
  304: 			 	 "request.course.fn"           => '',
  305: 				 "request.course.uri"          => '',
  306: 				 "request.course.sec"          => '',
  307:                                  "request.course.tied"         => '',
  308:                                  "request.course.timechecked"  => '',
  309: 				 "request.role"                => 'cm',
  310:                                  "request.role.adv"            => $env{'user.adv'},
  311: 				 "request.role.domain"         => $env{'user.domain'}});
  312: # Check if Domain Helpdesk role trying to enter a course needs privs to be created
  313:         if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)$}) {
  314:             my $cdom = $1;
  315:             my $rolename = $2;
  316:             my $cnum = $3;
  317:             if ($custom_adhoc) {
  318:                 my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
  319:                                                                   'adhocroles.'.$cdom);
  320:                 if (keys(%adhocroles)) {
  321:                     my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom});
  322:                     if (grep(/^\Q$rolename\E$/,@adhoc)) {
  323:                         if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,
  324:                                                                "cr/$cdom/$cdom".'-domainconfig/'.$rolename)) {
  325:                             &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});
  326:                         }
  327:                     }
  328:                 }
  329:             }
  330:         } elsif ($numdc > 0) {
  331: # Check if user is a DC trying to enter a course or author space and needs privs to be created
  332:             foreach my $envkey (keys(%env)) {
  333: # Is this an ad-hoc Coordinator role?
  334:                 if (my ($ccrole,$domain,$coursenum) =
  335: 		    ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
  336:                     if ($dcroles{$domain}) {
  337:                         if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
  338:                                                            $update,$refresh,$now,$ccrole)) {
  339:                             &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
  340:                         }
  341:                     }
  342:                     last;
  343:                 }
  344: # Is this an ad-hoc CA-role?
  345:                 if (my ($domain,$user) =
  346: 		    ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
  347:                     if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
  348:                         delete($env{$envkey});
  349:                         $env{'form.au./'.$domain.'/'} = 1;
  350:                         my ($server_status,$home) = &check_author_homeserver($user,$domain);
  351:                         if ($server_status eq 'switchserver') {
  352:                             my $trolecode = 'au./'.$domain.'/';
  353:                             my $switchserver = '/adm/switchserver?otherserver='.$home.'&amp;role='.$trolecode;
  354:                             $r->internal_redirect($switchserver);
  355:                             return OK;
  356:                         }
  357:                         last;
  358:                     }
  359:                     if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
  360:                         if (((($castart) && ($castart < $now)) || !$castart) && 
  361:                             ((!$caend) || (($caend) && ($caend > $now)))) {
  362:                             my ($server_status,$home) = &check_author_homeserver($user,$domain);
  363:                             if ($server_status eq 'switchserver') {
  364:                                 my $trolecode = 'ca./'.$domain.'/'.$user;
  365:                                 my $switchserver = '/adm/switchserver?otherserver='.$home.'&amp;role='.$trolecode;
  366:                                 $r->internal_redirect($switchserver);
  367:                                 return OK;
  368:                             }
  369:                             last;
  370:                         }
  371:                     }
  372:                     # Check if author blocked ca-access
  373:                     my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
  374:                     if ($blocked{'domcoord.author'} eq 'blocked') {
  375:                         delete($env{$envkey});
  376:                         $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
  377:                         last;
  378:                     }
  379:                     if ($dcroles{$domain}) {
  380:                         my ($server_status,$home) = &check_author_homeserver($user,$domain);
  381:                         if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
  382:                             &Apache::lonnet::check_adhoc_privs($domain,$user,$update,
  383:                                                                $refresh,$now,'ca');
  384:                             if ($server_status eq 'switchserver') {
  385:                                 my $trolecode = 'ca./'.$domain.'/'.$user; 
  386:                                 my $switchserver = '/adm/switchserver?'
  387:                                                   .'otherserver='.$home.'&amp;role='.$trolecode;
  388:                                 $r->internal_redirect($switchserver);
  389:                                 return OK;
  390:                             }
  391:                         } else {
  392:                             delete($env{$envkey});
  393:                         }
  394:                     } else {
  395:                         delete($env{$envkey});
  396:                     }
  397:                     last;
  398:                 }
  399:             }
  400:         }
  401: 
  402:         foreach $envkey (keys(%env)) {
  403:             next if ($envkey!~/^user\.role\./);
  404:             my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
  405:             &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
  406:                                          \$trolecode,\$tstatus,\$tstart,\$tend);
  407:             if ($env{'form.'.$trolecode}) {
  408: 		if ($tstatus eq 'is') {
  409: 		    $where=~s/^\///;
  410: 		    my ($cdom,$cnum,$csec)=split(/\//,$where);
  411:                     if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
  412:                         my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'};
  413:                         my @ids = &Apache::lonnet::current_machine_ids();
  414:                         unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) {
  415:                             my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
  416:                             if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
  417:                                 my ($switchserver,$switchwarning) =
  418:                                     &Apache::loncommon::check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,
  419:                                                                                $curr_reqd_hash{'internal.releaserequired'});
  420:                                 if ($switchwarning ne '' || $switchserver ne '') {
  421:                                     &Apache::loncommon::content_type($r,'text/html');
  422:                                     &Apache::loncommon::no_cache($r);
  423:                                     $r->send_http_header;
  424:                                     $r->print(&Apache::loncommon::check_release_result($switchwarning,$switchserver));
  425:                                     return OK;
  426:                                 }
  427:                             }
  428:                         }
  429:                     }
  430: # check for course groups
  431:                     my %coursegroups = &Apache::lonnet::get_active_groups(
  432:                           $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
  433:                     my $cgrps = join(':',keys(%coursegroups));
  434: 
  435: # store role if recent_role list being kept
  436:                     if ($env{'environment.recentroles'}) {
  437:                         my %frozen_roles =
  438:                            &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
  439: 			&Apache::lonhtmlcommon::store_recent('roles',
  440: 							     $trolecode,' ',$frozen_roles{$trolecode});
  441:                     }
  442: 
  443: 
  444: # check for keyed access
  445: 		    if (($role eq 'st') && 
  446:                        ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
  447: # who is key authority?
  448: 			my $authdom=$cdom;
  449: 			my $authnum=$cnum;
  450: 			if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
  451: 			    ($authnum,$authdom)=
  452: 				split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
  453: 			}
  454: # check with key authority
  455: 			unless (&Apache::lonnet::validate_access_key(
  456: 				     $env{'environment.key.'.$cdom.'_'.$cnum},
  457: 					     $authdom,$authnum)) {
  458: # there is no valid key
  459: 			     if ($env{'form.newkey'}) {
  460: # student attempts to register a new key
  461: 				 &Apache::loncommon::content_type($r,'text/html');
  462: 				 &Apache::loncommon::no_cache($r);
  463: 				 $r->send_http_header;
  464: 				 my $swinfo=&Apache::lonmenu::rawconfig();
  465: 				 my $start_page=&Apache::loncommon::start_page
  466: 				    ('Verifying Access Key to Unlock this Course');
  467: 				 my $end_page=&Apache::loncommon::end_page();
  468: 				 my $buttontext=&mt('Enter Course');
  469: 				 my $message=&mt('Successfully registered key');
  470: 				 my $assignresult=
  471: 				     &Apache::lonnet::assign_access_key(
  472: 						     $env{'form.newkey'},
  473: 						     $authdom,$authnum,
  474: 						     $cdom,$cnum,
  475:                                                      $env{'user.domain'},
  476: 						     $env{'user.name'},
  477:                                                      &mt('Assigned from [_1] at [_2] for [_3]'
  478:                                                         ,$ENV{'REMOTE_ADDR'}
  479:                                                         ,&Apache::lonlocal::locallocaltime()
  480:                                                         ,$trolecode)
  481:                                                      );
  482: 				 unless ($assignresult eq 'ok') {
  483: 				     $assignresult=~s/^error\:\s*//;
  484: 				     $message=&mt($assignresult).
  485: 				     '<br /><a href="/adm/logout">'.
  486: 				     &mt('Logout').'</a>';
  487: 				     $buttontext=&mt('Re-Enter Key');
  488: 				 }
  489: 				 $r->print(<<ENDENTEREDKEY);
  490: $start_page
  491: <script type="text/javascript">
  492: // <![CDATA[
  493: $swinfo
  494: // ]]>
  495: </script>
  496: <form action="" method="post">
  497: <input type="hidden" name="selectrole" value="1" />
  498: <input type="hidden" name="$trolecode" value="1" />
  499: <span class="LC_fontsize_large">$message</span><br />
  500: <input type="submit" value="$buttontext" />
  501: </form>
  502: $end_page
  503: ENDENTEREDKEY
  504:                                  return OK;
  505: 			     } else {
  506: # print form to enter a new key
  507: 				 &Apache::loncommon::content_type($r,'text/html');
  508: 				 &Apache::loncommon::no_cache($r);
  509: 				 $r->send_http_header;
  510: 				 my $swinfo=&Apache::lonmenu::rawconfig();
  511: 				 my $start_page=&Apache::loncommon::start_page
  512: 				    ('Enter Access Key to Unlock this Course');
  513: 				 my $end_page=&Apache::loncommon::end_page();
  514: 				 $r->print(<<ENDENTERKEY);
  515: $start_page
  516: <script type="text/javascript">
  517: // <![CDATA[
  518: $swinfo
  519: // ]]>
  520: </script>
  521: <form action="" method="post">
  522: <input type="hidden" name="selectrole" value="1" />
  523: <input type="hidden" name="$trolecode" value="1" />
  524: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
  525: <input type="submit" value="Enter key" />
  526: </form>
  527: $end_page
  528: ENDENTERKEY
  529: 				 return OK;
  530: 			     }
  531: 			 }
  532: 		     }
  533: 		    &Apache::lonnet::log($env{'user.domain'},
  534: 					 $env{'user.name'},
  535: 					 $env{'user.home'},
  536: 					 "Role ".$trolecode);
  537: 		    
  538: 		    &Apache::lonnet::appenv(
  539: 					   {'request.role'        => $trolecode,
  540: 					    'request.role.domain' => $cdom,
  541: 					    'request.course.sec'  => $csec,
  542:                                             'request.course.groups' => $cgrps});
  543:                     my $tadv=0;
  544: 
  545: 		    if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
  546:                         my $msg;
  547:                         my ($furl,$ferr)=
  548:                             &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
  549:                         unless ($ferr) {
  550:                             unless (($env{'form.switchrole'}) ||
  551:                                     ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) {
  552:                                 &Apache::lonnet::put('nohist_crslastlogin',
  553:                                     {$env{'user.name'}.':'.$env{'user.domain'}.
  554:                                      ':'.$csec.':'.$role => $now},$cdom,$cnum);
  555:                             }
  556:                             my ($feeds,$syllabus_time);
  557:                             &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds);
  558:                             &Apache::lonnet::appenv({'request.course.feeds' => $feeds});
  559:                             &Apache::lonnet::get_numsuppfiles($cnum,$cdom,1);
  560:                             unless ($env{'course.'.$cdom.'_'.$cnum.'.updatedsyllabus'}) {
  561:                                 unless (($env{'course.'.$cdom.'_'.$cnum.'.externalsyllabus'}) ||
  562:                                         ($env{'course.'.$cdom.'_'.$cnum.'.uploadedsyllabus'})) {
  563:                                     my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
  564:                                     $syllabus_time = $syllabus{'uploaded.lastmodified'};
  565:                                     if ($syllabus_time) {
  566:                                         &Apache::lonnet::appenv({'request.course.syllabustime' => $syllabus_time});
  567:                                     }
  568:                                 }
  569:                             }
  570:                         }
  571: 			if (($env{'form.orgurl'}) && 
  572: 			    ($env{'form.orgurl'}!~/^\/adm\/flip/) &&
  573:                             ($env{'form.orgurl'} ne '/adm/roles')) {
  574: 			    my $dest=$env{'form.orgurl'};
  575:                             if ($env{'form.symb'}) {
  576:                                 if ($dest =~ /\?/) {
  577:                                     $dest .= '&';
  578:                                 } else {
  579:                                     $dest .= '?';
  580:                                 }
  581:                                 $dest .= 'symb='.$env{'form.symb'};
  582:                             }
  583: 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
  584: 			    &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
  585:                             if (($ferr) && ($tadv)) {
  586: 				&error_page($r,$ferr,$dest);
  587: 			    } else {
  588:                                 if ($dest =~ m{^/adm/coursedocs\?folderpath}) {
  589:                                     if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { 
  590:                                         my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
  591:                                         &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
  592:                                                                                        $cdom.'_'.$cnum);
  593:                                     }
  594:                                 }
  595: 				$r->internal_redirect($dest);
  596: 			    }
  597: 			    return OK;
  598: 			} else {
  599: 			    if (!$env{'request.course.id'}) {
  600: 				&Apache::lonnet::appenv(
  601: 				      {"request.course.id"  => $cdom.'_'.$cnum});
  602: 				$furl='/adm/roles?tryagain=1';
  603:                 $msg='<p><span class="LC_error">'
  604:                     .&mt('Could not initialize [_1] at this time.',
  605:                          $env{'course.'.$cdom.'_'.$cnum.'.description'})
  606:                     .'</span></p>'
  607:                     .'<p>'.&mt('Please try again.').'</p>'
  608:                     .'<p>'.$ferr.'</p>';
  609: 			    }
  610: 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
  611: 			    &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
  612: 
  613: 			    if (($ferr) && ($tadv)) {
  614: 				&error_page($r,$ferr,$furl);
  615: 			    } else {
  616: 				# Check to see if the user is a CC entering a course 
  617: 				# for the first time
  618: 				if ((($role eq 'cc') || ($role eq 'co')) 
  619:                                     && ($env{'course.'.$cdom.'_'.$cnum.'.course.helper.not.run'})) { 
  620: 				    $furl = "/adm/helper/course.initialization.helper";
  621: 				    # Send the user to the course they selected
  622: 				} elsif ($env{'request.course.id'}) {
  623:                                     my ($dest,$destsymb,$checkenc);
  624:                                     $dest = $env{'form.destinationurl'};
  625:                                     $destsymb = $env{'form.destsymb'};
  626:                                     if ($dest ne '') {
  627:                                         if ($env{'form.switchrole'}) {
  628:                                             if ($destsymb ne '') {
  629:                                                 if ($destsymb !~ m{^/enc/}) {
  630:                                                     unless ($env{'request.role.adv'}) {
  631:                                                         $checkenc = 1;
  632:                                                     }
  633:                                                 }
  634:                                             }
  635:                                             if ($dest =~ m{^/enc/}) {
  636:                                                 if ($env{'request.role.adv'}) {
  637:                                                     $dest = &Apache::lonenc::unencrypted($dest);
  638:                                                     if ($destsymb eq '') {
  639:                                                         ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); 
  640:                                                         $destsymb = &unescape($destsymb);
  641:                                                     }
  642:                                                 }
  643:                                             } else {
  644:                                                 if ($destsymb eq '') {
  645:                                                     ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]+)/);
  646:                                                     $destsymb = &unescape($destsymb);
  647:                                                 }
  648:                                                 unless ($env{'request.role.adv'}) {
  649:                                                     $checkenc = 1;
  650:                                                 }
  651:                                             }
  652:                                             if (($checkenc) && ($destsymb ne '')) {
  653:                                                 my ($encstate,$unencsymb,$res);
  654:                                                 $unencsymb = &Apache::lonnet::symbclean($destsymb);
  655:                                                 (undef,undef,$res) = &Apache::lonnet::decode_symb($unencsymb);
  656:                                                 &Apache::lonnet::symbverify($unencsymb,$res,\$encstate);
  657:                                                 if ($encstate) {
  658:                                                     if (($dest ne '') && ($dest !~ m{^/enc/})) {
  659:                                                         $dest=&Apache::lonenc::encrypted($dest);
  660:                                                     }
  661:                                                 }
  662:                                             }
  663:                                         }
  664:                                         unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { 
  665:                                             if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) {
  666:                                                 my $esc_symb = &escape($destsymb);
  667:                                                 $dest .= '?symb='.$esc_symb;
  668:                                             }
  669:                                         }
  670:                                         &redirect_user($r, &mt('Entering [_1]',
  671:                                                        $env{'course.'.$cdom.'_'.$cnum.'.description'}),
  672:                                                        $dest, $msg);
  673:                                         return OK;
  674:                                     }
  675: 				    if (&Apache::lonnet::allowed('whn',
  676: 								 $env{'request.course.id'})
  677: 					|| &Apache::lonnet::allowed('whn',
  678: 								    $env{'request.course.id'}.'/'
  679: 								    .$env{'request.course.sec'})
  680: 					) {
  681: 					my $startpage = &courseloadpage($env{'request.course.id'});
  682: 					unless ($startpage eq 'firstres') {         
  683: 					    $msg = &mt('Entering [_1] ...',
  684: 						       $env{'course.'.$env{'request.course.id'}.'.description'});
  685: 					    &redirect_user($r, &mt('New in course'),
  686:                                        '/adm/whatsnew?refpage=start', $msg);
  687: 					    return OK;
  688: 					}
  689: 				    }
  690: 				}
  691:                                 # Are we allowed to look at the first resource?
  692:                                 my $access;
  693:                                 if ($furl =~ m{^(/adm/wrapper|)/ext/}) {
  694:                                     # If it's an external resource,
  695:                                     # strip off the symb argument and possible query
  696:                                     my ($exturl,$symb) = ($furl =~ m{^(.+)(?:\?|\&)symb=(.+)$});
  697:                                     # Unencode $symb
  698:                                     $symb = &unescape($symb);
  699:                                     # Then check for permission
  700:                                     $access = &Apache::lonnet::allowed('bre',$exturl,$symb);
  701:                                 # For other resources just check for permission
  702:                                 } else {
  703:                                     $access = &Apache::lonnet::allowed('bre',$furl);
  704:                                 }
  705:                                 if (!$access) {
  706:                                     $furl = &Apache::lonpageflip::first_accessible_resource();
  707:                                 } elsif ($access eq 'B') {
  708:                                     $furl = '/adm/navmaps?showOnlyHomework=1';
  709:                                 }
  710:                                 $msg = &mt('Entering [_1] ...',
  711: 					   $env{'course.'.$cdom.'_'.$cnum.'.description'});
  712: 				&redirect_user($r, &mt('Entering [_1]',
  713:                                $env{'course.'.$cdom.'_'.$cnum.'.description'}),
  714:                                $furl, $msg);
  715: 			    }
  716: 			    return OK;
  717: 			}
  718: 		    }
  719:                     #
  720:                     # Send the user to the construction space they selected
  721:                     if ($role =~ /^(au|ca|aa)$/) {
  722:                         my $redirect_url = '/priv/';
  723:                         if ($role eq 'au') {
  724:                             $redirect_url.=$env{'user.domain'}.'/'.$env{'user.name'};
  725:                         } else {
  726:                             $redirect_url .= $where;
  727:                         }
  728:                         $redirect_url .= '/';
  729:                         &redirect_user($r,&mt('Entering Authoring Space'),
  730:                                        $redirect_url);
  731:                         return OK;
  732:                     }
  733:                     if ($role eq 'dc') {
  734:                         my $redirect_url = '/adm/menu/';
  735:                         &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
  736:                                        $redirect_url);
  737:                         return OK;
  738:                     }
  739:                     if ($role eq 'dh') {
  740:                         my $redirect_url = '/adm/menu/';
  741:                         &redirect_user($r,&mt('Loading Domain Helpdesk Menu'),
  742:                                        $redirect_url);
  743:                         return OK;
  744:                     }
  745:                     if ($role eq 'sc') {
  746:                         my $redirect_url = '/adm/grades?command=scantronupload';
  747:                         &redirect_user($r,&mt('Loading Data Upload Page'),
  748:                                        $redirect_url);
  749:                         return OK;
  750:                     }
  751: 		}
  752:             }
  753:         }
  754:     }
  755: 
  756: 
  757: # =============================================================== No Roles Init
  758: 
  759:     &Apache::loncommon::content_type($r,'text/html');
  760:     &Apache::loncommon::no_cache($r);
  761:     $r->send_http_header;
  762:     return OK if $r->header_only;
  763: 
  764:     my $crumbtext = 'User Roles';
  765:     my $pagetitle = 'My Roles';
  766:     my $recent = &mt('Recent Roles');
  767:     my $standby = &mt('Role selected. Please stand by.');
  768:     my $show_course=&Apache::loncommon::show_course();
  769:     if ($show_course) {
  770:         $crumbtext = 'Courses';
  771:         $pagetitle = 'My Courses';
  772:         $recent = &mt('Recent Courses');
  773:         $standby = &mt('Course selected. Please stand by.');
  774:     }
  775:     my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
  776: 
  777:     my %roles_in_env;
  778:     my $showcount = &roles_from_env(\%roles_in_env,$update); 
  779: 
  780:     my $swinfo=&Apache::lonmenu::rawconfig();
  781:     my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'}); 
  782:     my $cattype = 'std';
  783:     if ($domdefs{'catauth'}) {
  784:         $cattype = $domdefs{'catauth'};
  785:     }
  786:     my $funcs = &get_roles_functions($showcount,$cattype);
  787:     my $crumbsright;
  788:     if ($env{'browser.mobile'}) {
  789:         $crumbsright = $funcs;
  790:         undef($funcs);
  791:     }
  792:     my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum,
  793:                                                                     bread_crumbs_component=>$crumbsright});
  794:     &js_escape(\$standby);
  795:     my $noscript='<br /><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 />';
  796: 
  797:     $r->print(<<ENDHEADER);
  798: $start_page
  799: $funcs
  800: <noscript>
  801: $noscript
  802: </noscript>
  803: <script type="text/javascript">
  804: // <![CDATA[
  805: $swinfo
  806: window.focus();
  807: 
  808: active=true;
  809: 
  810: function enterrole (thisform,rolecode,buttonname) {
  811:     if (active) {
  812: 	active=false;
  813:         document.title='$standby';
  814:         window.status='$standby';
  815: 	thisform.newrole.value=rolecode;
  816: 	thisform.submit();
  817:     } else {
  818:        alert('$standby');
  819:     }
  820: }
  821: 
  822: function rolesView (caller) {
  823:     if ((caller == 'showall') || (caller == 'noshowall')) {
  824:         document.rolechoice.display.value = caller;
  825:     } else {
  826:         if ((caller == 'doupdate') || (caller == 'requestauthor') ||
  827:             (caller == 'queued')) {
  828:             document.rolechoice.state.value = caller;
  829:         }
  830:     }
  831:     document.rolechoice.selectrole.value='';
  832:     document.rolechoice.submit();
  833: }
  834: 
  835: // ]]>
  836: </script>
  837: ENDHEADER
  838: 
  839: # ------------------------------------------ Get Error Message from Environment
  840: 
  841:     my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
  842:     if ($env{'user.error.msg'}) {
  843: 	$r->log_reason(
  844:    "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
  845:     }
  846: 
  847: # ------------------------------------------------- Can this user re-init, etc?
  848: 
  849:     my $advanced=$env{'user.adv'};
  850:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
  851:     my $tryagain=$env{'form.tryagain'};
  852:     my $reinit=$env{'user.reinit'};
  853:     delete $env{'user.reinit'};
  854: 
  855: # -------------------------------------------------------- Generate Page Output
  856: # --------------------------------------------------------------- Error Header?
  857:     if ($error) {
  858:         $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
  859: 	$r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
  860: 	if ($priv ne '') {
  861:             $r->print(&mt('Access  : ').&Apache::lonnet::plaintext($priv)."\n");
  862: 	}
  863: 	if ($fn ne '') {
  864:             $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
  865: 	}
  866: 	if ($msg ne '') {
  867:             $r->print(&mt('Action  : ').$msg."\n");
  868: 	}
  869: 	$r->print("</pre><hr />");
  870: 	my $url=$fn;
  871: 	my $last;
  872: 	if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
  873: 		&GDBM_READER(),0640)) {
  874: 	    $last=$hash{'last_known'};
  875: 	    untie(%hash);
  876: 	}
  877: 	if ($last) { $fn.='?symb='.&escape($last); }
  878: 
  879: 	&Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
  880: 					&Apache::lonenc::check_encrypt($fn));
  881:     } else {
  882:         if ($env{'user.error.msg'}) {
  883:             if ($reinit) {
  884:                 $r->print(
  885:  '<h3><span class="LC_error">'.
  886:  &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
  887:             } else {
  888: 	        $r->print(
  889:  '<h3><span class="LC_error">'.
  890:  &mt('You need to choose another user role or enter a specific course or community for this function.').
  891:  '</span></h3>');
  892: 	    }
  893:         }
  894:     }
  895:     if ($nochoose) {
  896: 	$r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
  897: 		  &mt('This action is currently not authorized.').'</span>'.
  898: 		  &Apache::loncommon::end_page());
  899: 	return OK;
  900:     } else {
  901:         if ($updateresult || $reqauthor || $hotlist) {
  902:             my $showresult = '<div>';
  903:             if ($updateresult) {
  904:                 $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult);
  905:             }
  906:             if ($reqauthor) {
  907:                 $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor);
  908:             }
  909:             if ($hotlist) {
  910:                 $showresult .= $hotlist;
  911:             }
  912:             $showresult .= '</div>';
  913:             $r->print($showresult);
  914:         } elsif ($env{'form.state'} eq 'queued') {
  915:             $r->print(&get_queued());
  916:         }
  917:         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
  918:     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
  919:         }
  920:         my $display = ($env{'form.display'} =~ /^(showall)$/);
  921:         $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
  922:         $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
  923:         $r->print('<input type="hidden" name="selectrole" value="1" />');
  924:         $r->print('<input type="hidden" name="newrole" value="" />');
  925:         $r->print('<input type="hidden" name="display" value="'.$display.'" />');
  926:         $r->print('<input type="hidden" name="state" value="" />');
  927:     }
  928:     $r->rflush();
  929: 
  930:     my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
  931:     my ($countactive,$countfuture,$inrole,$possiblerole) = 
  932:         &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext,
  933:                       \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
  934:     $refresh = $now;
  935:     &Apache::lonnet::appenv({'user.refresh.time'  => $refresh});
  936:     if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'})) {
  937:         if ($countactive > 0) {
  938:             my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
  939:             my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); 
  940:             $r->print(
  941:                 '<p>'
  942:                .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]'
  943:                    .' to view all [_5] LON-CAPA courses and communities.'
  944:                    ,'<b>'
  945:                    ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
  946:                    ,'</a>'
  947:                    ,'</b>'
  948:                    ,'"'.$domdesc.'"')
  949:                .'<br />'
  950:                .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
  951:                    .' you may be able to enroll if self-enrollment is permitted.'
  952:                    ,'<b>','</b>')
  953:                .'</p>'
  954:             );
  955:         }
  956:     }
  957: 
  958: # No active roles
  959:     if ($countactive==0) {
  960:         &requestcourse_advice($r,$cattype,$inrole); 
  961: 	$r->print('</form>');
  962:         if ($countfuture) {
  963:             $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
  964:             my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
  965:                                                $nochoose);
  966:             &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
  967:                             \%roletext);
  968:             my $tremark='';
  969:             my $tbg;
  970:             if ($env{'request.role'} eq 'cm') {
  971:                 $tbg="LC_roles_selected";
  972:                 $tremark=&mt('Currently selected.').' ';
  973:             } else {
  974:                 $tbg="LC_roles_is";
  975:             }
  976:             $r->print(&Apache::loncommon::start_data_table_row()
  977:                      .'<td class="'.$tbg.'">&nbsp;</td>'
  978:                      .'<td colspan="3">'
  979:                      .&mt('No role specified')
  980:                      .'</td>'
  981:                      .'<td>'.$tremark.'&nbsp;</td>'
  982:                      .&Apache::loncommon::end_data_table_row()
  983:             );
  984: 
  985:             $r->print(&Apache::loncommon::end_data_table());
  986:         }
  987:         $r->print(&Apache::loncommon::end_page());
  988: 	return OK;
  989:     }
  990: # ----------------------------------------------------------------------- Table
  991: 
  992:     if (($numdc > 0) || (($numdh > 0) && ($numadhoc > 0))) {
  993:         $r->print(&coursepick_jscript());
  994:         $r->print(&Apache::loncommon::coursebrowser_javascript().
  995:                   &Apache::loncommon::authorbrowser_javascript());
  996:     }
  997: 
  998:     unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
  999: 	$r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
 1000:     }
 1001:     if ($env{'form.destinationurl'}) {
 1002:         $r->print('<input type="hidden" name="destinationurl" value="'.
 1003:                   $env{'form.destinationurl'}.'" />');
 1004:         if ($env{'form.destsymb'} ne '') {
 1005:             $r->print('<input type="hidden" name="destsymb" value="'.
 1006:                       $env{'form.destsymb'}.'" />');
 1007:         }
 1008:     }
 1009: 
 1010:     my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
 1011:     if ($env{'environment.recentroles'}) {
 1012:         my %recent_roles =
 1013:                &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
 1014: 	my $output='';
 1015: 	foreach my $role (sort(keys(%recent_roles))) {
 1016: 	    if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
 1017: 		$output.= &Apache::loncommon::start_data_table_row().
 1018:                           $roletext{'user.role.'.$role}->[0].
 1019:                           &Apache::loncommon::end_data_table_row();
 1020:                 if ($roletext{'user.role.'.$role}->[1] ne '') {
 1021:                     $output .= &Apache::loncommon::continue_data_table_row().
 1022:                                $roletext{'user.role.'.$role}->[1].
 1023:                                &Apache::loncommon::end_data_table_row();
 1024:                 }
 1025:                 if ($role =~ m{^dc\./($match_domain)/$} 
 1026: 		    && $dcroles{$1}) {
 1027: 		    $output .= &adhoc_roles_row($1,'recent');
 1028:                 } elsif ($role =~ m{^dh\./($match_domain)/$}
 1029:                          && ($env{'environment.adhocroles.'.$1} ne '')) {
 1030:                     $output .= &adhoc_customroles_row($1,'recent');
 1031:                 }
 1032: 	    } elsif ($numdc > 0) {
 1033:                 unless ($role =~/^error\:/) {
 1034:                     my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
 1035:                     if ($roletext) {
 1036:                         $output.= &Apache::loncommon::start_data_table_row().
 1037:                                   $roletext.
 1038:                                   &Apache::loncommon::end_data_table_row();
 1039:                         if ($role_text_end) {
 1040:                             $output .= &Apache::loncommon::continue_data_table_row().
 1041:                                        $role_text_end.
 1042:                                        &Apache::loncommon::end_data_table_row();
 1043:                         }
 1044:                     }
 1045:                 }
 1046:             }
 1047: 	}
 1048: 	if ($output) {
 1049: 	    $r->print(&Apache::loncommon::start_data_table_empty_row()
 1050:                      .'<td align="center" colspan="5">'
 1051:                      .$recent
 1052:                      .'</td>'
 1053:                      .&Apache::loncommon::end_data_table_empty_row()
 1054:             );
 1055: 	    $r->print($output);
 1056:             $doheaders ++;
 1057: 	}
 1058:     }
 1059:     &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
 1060:     if ($countactive > 1) {
 1061:         my $tremark='';
 1062:         my $tbg;
 1063:         if ($env{'request.role'} eq 'cm') {
 1064:             $tbg="LC_roles_selected";
 1065:             $tremark=&mt('Currently selected.').' ';
 1066:         } else {
 1067:                 $tbg="LC_roles_is";
 1068:         }
 1069:         $r->print(&Apache::loncommon::start_data_table_row());
 1070:         unless ($nochoose) {
 1071: 	    if ($env{'request.role'} ne 'cm') {
 1072: 	        $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
 1073: 		          &mt('Select').'" name="cm" /></td>');
 1074: 	    } else {
 1075: 	        $r->print('<td class="'.$tbg.'">&nbsp;</td>');
 1076: 	    }
 1077:         }
 1078:         $r->print('<td colspan="3">'
 1079:                  .&mt('No role specified')
 1080:                  .'</td>'
 1081:                  .'<td>'.$tremark.'&nbsp;</td>'
 1082:                  .&Apache::loncommon::end_data_table_row()
 1083:         );
 1084:     } 
 1085:     $r->print(&Apache::loncommon::end_data_table());
 1086:     unless ($nochoose) {
 1087: 	$r->print("</form>\n");
 1088:     }
 1089: # ------------------------------------------------------------ Privileges Info
 1090:     if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
 1091: 	$r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
 1092: 	$r->print(&privileges_info());
 1093:     }
 1094:     my $announcements = &Apache::lonnet::getannounce();
 1095:     $r->print(
 1096:         '<br />'.
 1097:         '<h2>'.&mt('Announcements').'</h2>'.
 1098:         $announcements
 1099:     ) unless (!$announcements);
 1100:     if ($advanced) {
 1101:         my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
 1102:         $r->print('<p><small><i>'
 1103:                  .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
 1104:                  .'</i></small></p>');
 1105:     }
 1106:     $r->print(&Apache::loncommon::end_page());
 1107:     return OK;
 1108: }
 1109: 
 1110: sub roles_from_env {
 1111:     my ($roleshash,$update) = @_;
 1112:     my $count = 0;
 1113:     if (ref($roleshash) eq 'HASH') {
 1114:         foreach my $envkey (keys(%env)) {
 1115:             if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
 1116:                 next if ($1 eq 'gr');
 1117:                 $roleshash->{$envkey} = $env{$envkey};
 1118:                 my ($start,$end) = split(/\./,$env{$envkey});
 1119:                 unless ($end && $end<$update) {
 1120:                     $count ++;
 1121:                 }
 1122:             }
 1123:         }
 1124:     }
 1125:     return $count;
 1126: }
 1127: 
 1128: sub gather_roles {
 1129:     my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
 1130:         $timezones,$loncaparev) = @_;
 1131:     my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
 1132:     my $advanced = $env{'user.adv'};
 1133:     my $tryagain = $env{'form.tryagain'};
 1134:     my @ids = &Apache::lonnet::current_machine_ids();
 1135:     if (ref($roles_in_env) eq 'HASH') {
 1136:         foreach my $envkey (sort(keys(%{$roles_in_env}))) {
 1137:             my $button = 1;
 1138:             my $switchserver='';
 1139:             my $switchwarning;
 1140:             my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
 1141:                 $tend,$tremark,$tstatus,$tpstart,$tpend);
 1142:             &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
 1143:                                          \$trolecode,\$tstatus,\$tstart,\$tend);
 1144:             next if (!defined($role) || $role eq '' || $role =~ /^gr/);
 1145:             $tremark='';
 1146:             $tpstart='&nbsp;';
 1147:             $tpend='&nbsp;';
 1148:             if ($env{'request.role'} eq $trolecode) {
 1149:                 $tstatus='selected';
 1150:             }
 1151:             my $tbg;
 1152:             if (($tstatus eq 'is')
 1153:                 || ($tstatus eq 'selected')
 1154:                 || ($tstatus eq 'future')
 1155:                 || ($env{'form.display'} eq 'showall')) {
 1156:                 my $timezone = &role_timezone($where,$timezones);
 1157:                 if ($tstart) {
 1158:                     $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
 1159:                 }
 1160:                 if ($tend) {
 1161:                     $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
 1162:                 }
 1163:                 if ($tstatus eq 'is') {
 1164:                     $tbg='LC_roles_is';
 1165:                     $possiblerole=$trolecode;
 1166:                     $countactive++;
 1167:                 } elsif ($tstatus eq 'future') {
 1168:                     $tbg='LC_roles_future';
 1169:                     $button=0;
 1170:                     $futureroles->{$trolecode} = $tstart.':'.$tend;
 1171:                     $countfuture ++;
 1172:                 } elsif ($tstatus eq 'expired') {
 1173:                     $tbg='LC_roles_expired';
 1174:                     $button=0;
 1175:                 } elsif ($tstatus eq 'will_not') {
 1176:                     $tbg='LC_roles_will_not';
 1177:                     $tremark.=&mt('Expired after logout.').' ';
 1178:                 } elsif ($tstatus eq 'selected') {
 1179:                     $tbg='LC_roles_selected';
 1180:                     $inrole=1;
 1181:                     $countactive++;
 1182:                     $tremark.=&mt('Currently selected.').' ';
 1183:                 }
 1184:                 my $trole;
 1185:                 if ($role =~ /^cr\//) {
 1186:                     my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
 1187:                     if ($tremark) { $tremark.='<br />'; }
 1188:                     $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
 1189:                 }
 1190:                 $trole=Apache::lonnet::plaintext($role);
 1191:                 my $ttype;
 1192:                 my $twhere;
 1193:                 my ($tdom,$trest,$tsection)=
 1194:                     split(/\//,Apache::lonnet::declutter($where));
 1195:                 # First, Co-Authorship roles
 1196:                 if (($role eq 'ca') || ($role eq 'aa')) {
 1197:                     my $home = &Apache::lonnet::homeserver($trest,$tdom);
 1198:                     my $allowed=0;
 1199:                     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1200:                     if (!$allowed) {
 1201:                         $button=0;
 1202:                         $switchserver='otherserver='.$home.'&amp;role='.$trolecode;
 1203:                     }
 1204:                     #next if ($home eq 'no_host');
 1205:                     $home = &Apache::lonnet::hostname($home);
 1206:                     $ttype='Authoring Space';
 1207:                     $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
 1208:                         ': '.$tdom.'<br />'.
 1209:                         ' '.&mt('Server').':&nbsp;'.$home;
 1210:                     $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
 1211:                     $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
 1212:                     $sortkey=$role."$trest:$tdom";
 1213:                 } elsif ($role eq 'au') {
 1214:                     # Authors
 1215:                     my $home = &Apache::lonnet::homeserver
 1216:                         ($env{'user.name'},$env{'user.domain'});
 1217:                     my $allowed=0;
 1218:                     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1219:                     if (!$allowed) {
 1220:                         $button=0;
 1221:                         $switchserver='otherserver='.$home.'&amp;role='.$trolecode;
 1222:                     }
 1223:                     #next if ($home eq 'no_host');
 1224:                     $home = &Apache::lonnet::hostname($home);
 1225:                     $ttype='Authoring Space';
 1226:                     $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
 1227:                         ':&nbsp;'.$home;
 1228:                     $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
 1229:                     $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
 1230:                     $sortkey=$role;
 1231:                 } elsif ($trest) {
 1232:                     my $tcourseid=$tdom.'_'.$trest;
 1233:                     $ttype = &Apache::loncommon::course_type($tcourseid);
 1234:                     $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
 1235:                     if ($env{'course.'.$tcourseid.'.description'}) {
 1236:                         my $home=$env{'course.'.$tcourseid.'.home'};
 1237:                         $twhere=$env{'course.'.$tcourseid.'.description'};
 1238:                         $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
 1239:                         $twhere = &HTML::Entities::encode($twhere,'"<>&');
 1240:                         unless ($twhere eq &mt('Currently not available')) {
 1241:                             $twhere.=' <span class="LC_fontsize_small">'.
 1242:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
 1243:                                     '</span>';
 1244:                             unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
 1245:                                 my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
 1246:                                 if ($required ne '') {
 1247:                                     ($switchserver,$switchwarning) = 
 1248:                                         &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
 1249:                                     if ($switchserver || $switchwarning) {
 1250:                                         $button = 0;
 1251:                                     }
 1252:                                 }
 1253:                             }
 1254:                         }
 1255:                     } else {
 1256:                         my %newhash=&Apache::lonnet::coursedescription($tcourseid);
 1257:                         if (%newhash) {
 1258:                             $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
 1259:                                 "\0".$envkey;
 1260:                             $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
 1261:                                     ' <span class="LC_fontsize_small">'.
 1262:                                      &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
 1263:                                     '</span>';
 1264:                             $ttype = $newhash{'type'};
 1265:                             $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
 1266:                             my $home = $newhash{'home'};
 1267:                             unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
 1268:                                 my $required = $newhash{'internal.releaserequired'};
 1269:                                 if ($required ne '') {
 1270:                                     ($switchserver,$switchwarning) =
 1271:                                         &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
 1272:                                     if ($switchserver || $switchwarning) {
 1273:                                         $button = 0;
 1274:                                     }
 1275:                                 }
 1276:                             }
 1277:                         } else {
 1278:                             $twhere=&mt('Currently not available');
 1279:                             $env{'course.'.$tcourseid.'.description'}=$twhere;
 1280:                             $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
 1281:                             $ttype = 'Unavailable';
 1282:                         }
 1283:                     }
 1284:                     if ($tsection) {
 1285:                         $twhere.='<br />'.&mt('Section').': '.$tsection;
 1286:                     }
 1287:                     if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
 1288:                 } elsif ($tdom) {
 1289:                     $ttype='Domain';
 1290:                     $twhere=$tdom;
 1291:                     $sortkey=$role.$twhere;
 1292:                 } else {
 1293:                     $ttype='System';
 1294:                     $twhere=&mt('system wide');
 1295:                     $sortkey=$role.$twhere;
 1296:                 }
 1297:                 ($role_text,$role_text_end) =
 1298:                     &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
 1299:                                     $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
 1300:                                     $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
 1301:                 $roletext->{$envkey}=[$role_text,$role_text_end];
 1302:                 if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
 1303:                 $sortrole->{$sortkey}=$envkey;
 1304:                 $roleclass->{$envkey}=$ttype;
 1305:             }
 1306:         }
 1307:     }
 1308:     return ($countactive,$countfuture,$inrole,$possiblerole);
 1309: }
 1310: 
 1311: sub role_timezone {
 1312:     my ($where,$timezones) = @_;
 1313:     my $timezone;
 1314:     if (ref($timezones) eq 'HASH') { 
 1315:         if ($where =~ m{^/($match_domain)/($match_courseid)}) {
 1316:             my $cdom = $1;
 1317:             my $cnum = $2;
 1318:             if ($cdom && $cnum) {
 1319:                 if (!exists($timezones->{$cdom.'_'.$cnum})) {
 1320:                     my $tz;
 1321:                     if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
 1322:                         $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
 1323:                     } else {
 1324:                         my %timehash =
 1325:                             &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
 1326:                         $tz = $timehash{'timezone'};
 1327:                     }
 1328:                     if ($tz eq '') {
 1329:                         if (!exists($timezones->{$cdom})) {
 1330:                             my %domdefaults = 
 1331:                                 &Apache::lonnet::get_domain_defaults($cdom);
 1332:                             if ($domdefaults{'timezone_def'} eq '') {
 1333:                                 $timezones->{$cdom} = 'local';
 1334:                             } else {
 1335:                                 $timezones->{$cdom} = $domdefaults{'timezone_def'};
 1336:                             }
 1337:                         }
 1338:                         $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
 1339:                     } else {
 1340:                         $timezones->{$cdom.'_'.$cnum} = 
 1341:                             &Apache::lonlocal::gettimezone($tz);
 1342:                     }
 1343:                 }
 1344:                 $timezone = $timezones->{$cdom.'_'.$cnum};
 1345:             }
 1346:         } else {
 1347:             my ($tdom) = ($where =~ m{^/($match_domain)});
 1348:             if ($tdom) {
 1349:                 if (!exists($timezones->{$tdom})) {
 1350:                     my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
 1351:                     if ($domdefaults{'timezone_def'} eq '') {
 1352:                         $timezones->{$tdom} = 'local';
 1353:                     } else {
 1354:                         $timezones->{$tdom} = $domdefaults{'timezone_def'};
 1355:                     }
 1356:                 }
 1357:                 $timezone = $timezones->{$tdom};
 1358:             }
 1359:         }
 1360:         if ($timezone eq 'local') {
 1361:             $timezone = undef;
 1362:         }
 1363:     }
 1364:     return $timezone;
 1365: }
 1366: 
 1367: sub roletable_headers {
 1368:     my ($r,$roleclass,$sortrole,$nochoose) = @_;
 1369:     my $doheaders;
 1370:     if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
 1371:         $r->print('<br />'
 1372:                  .&Apache::loncommon::start_data_table('LC_textsize_mobile')
 1373:                  .&Apache::loncommon::start_data_table_header_row()
 1374:         );
 1375:         if (!$nochoose) { $r->print('<th>&nbsp;</th>'); }
 1376:         $r->print('<th>'.&mt('User Role').'</th>'
 1377:                  .'<th>'.&mt('Extent').'</th>'
 1378:                  .'<th>'.&mt('Start').'</th>'
 1379:                  .'<th>'.&mt('End').'</th>'
 1380:                  .&Apache::loncommon::end_data_table_header_row()
 1381:         );
 1382:         $doheaders=-1;
 1383:         my @roletypes = &roletypes();
 1384:         foreach my $type (@roletypes) {
 1385:             my $haverole=0;
 1386:             foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
 1387:                 if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
 1388:                     $haverole=1;
 1389:                 }
 1390:             }
 1391:             if ($haverole) { $doheaders++; }
 1392:         }
 1393:     }
 1394:     return $doheaders;
 1395: }
 1396: 
 1397: sub roletypes {
 1398:     my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System');
 1399:     return @types; 
 1400: }
 1401: 
 1402: sub print_rolerows {
 1403:     my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
 1404:     if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
 1405:         my @types = &roletypes();
 1406:         foreach my $type (@types) {
 1407:             my $output;
 1408:             foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
 1409:                 if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
 1410:                     if (ref($roletext) eq 'HASH') {
 1411:                         if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
 1412:                             $output.= &Apache::loncommon::start_data_table_row().
 1413:                                       $roletext->{$sortrole->{$which}}->[0].
 1414:                                       &Apache::loncommon::end_data_table_row();
 1415:                             if ($roletext->{$sortrole->{$which}}->[1] ne '') {
 1416:                                 $output .= &Apache::loncommon::continue_data_table_row().
 1417:                                            $roletext->{$sortrole->{$which}}->[1].
 1418:                                            &Apache::loncommon::end_data_table_row();
 1419:                             }
 1420:                         }
 1421:                         if ($sortrole->{$which} =~ m{^user\.role\.dc\./($match_domain)/}) {
 1422:                             if (ref($dcroles) eq 'HASH') {
 1423:                                 if ($dcroles->{$1}) {
 1424:                                     $output .= &adhoc_roles_row($1,'');
 1425:                                 }
 1426:                             }
 1427:                         } elsif (($sortrole->{$which} =~ m{^user\.role\.dh\./($match_domain)/}) &&
 1428:                                  ($env{'environment.adhocroles.'.$1} ne '')) {
 1429:                             $output .= &adhoc_customroles_row($1,'');
 1430:                         }
 1431:                     }
 1432:                 }
 1433:             }
 1434:             if ($output) {
 1435:                 if ($doheaders > 0) {
 1436:                     $r->print(&Apache::loncommon::start_data_table_empty_row()
 1437:                              .'<td align="center" colspan="5">'
 1438:                              .&mt($type)
 1439:                              .'</td>'
 1440:                              .&Apache::loncommon::end_data_table_empty_row()
 1441:                     );
 1442:                 }
 1443:                 $r->print($output);
 1444:             }
 1445:         }
 1446:     }
 1447: }
 1448: 
 1449: sub findcourse_advice {
 1450:     my ($r,$cattype) = @_;
 1451:     my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
 1452:     my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
 1453:     if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
 1454:         $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).'
 1455: <ul>
 1456:  <li>'.&mt('The course has yet to be created.').'</li>
 1457:  <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
 1458:  <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
 1459:  <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
 1460:  <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>
 1461:  </ul>');
 1462:     } else {
 1463:         $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 />');
 1464:     }
 1465:     if (($cattype eq 'std') || ($cattype eq 'domonly')) {
 1466:         $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
 1467:                   '<p>'.&mt('The [_1]Course/Community Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created, as well as any communities in the domain.','<a href="/adm/coursecatalog?showdom='.$esc_dom.'">','</a>',$domdesc).'<br />');
 1468:         $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
 1469:         &Apache::loncoursequeueadmin::queued_selfenrollment());
 1470:     }
 1471:     return;
 1472: }
 1473: 
 1474: sub requestcourse_advice {
 1475:     my ($r,$cattype,$inrole) = @_;
 1476:     my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
 1477:     my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
 1478:     my (%can_request,%request_doms,$output);
 1479:     &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
 1480:     if (keys(%request_doms) > 0) {
 1481:         my ($types,$typename) = &Apache::loncommon::course_types();
 1482:         if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) { 
 1483:             my (@reqdoms,@reqtypes);
 1484:             foreach my $type (sort(keys(%request_doms))) {
 1485:                 push(@reqtypes,$type); 
 1486:                 if (ref($request_doms{$type}) eq 'ARRAY') {
 1487:                     my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
 1488:                     $output .=
 1489:                         '<li>'
 1490:                        .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
 1491:                             '<i>',
 1492:                             '</i>',
 1493:                             '<b>'.$domstr.'</b>')
 1494:                        .'</li>';
 1495:                     foreach my $dom (@{$request_doms{$type}}) {
 1496:                         unless (grep(/^\Q$dom\E/,@reqdoms)) {
 1497:                             push(@reqdoms,$dom);
 1498:                         }
 1499:                     }
 1500:                 }
 1501:             }
 1502:             my @showtypes;
 1503:             foreach my $type (@{$types}) {
 1504:                 if (grep(/^\Q$type\E$/,@reqtypes)) {
 1505:                     push(@showtypes,$type);
 1506:                 }
 1507:             }
 1508:             my $requrl = '/adm/requestcourse';
 1509:             if (@reqdoms == 1) {
 1510:                 $requrl .= '?showdom='.$reqdoms[0];
 1511:             }
 1512:             if (@showtypes > 0) {
 1513:                 $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
 1514:             }
 1515:             if (@reqdoms == 1 || @showtypes > 0) {
 1516:                 $requrl .= '&state=crstype&action=new';
 1517:             }
 1518:             if ($output) {
 1519:                 $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
 1520:                           '<p>'.
 1521:                           &mt('You have rights to request the creation of courses and/or communities in the following domain(s):').
 1522:                           '<ul>'.
 1523:                           $output.
 1524:                           '</ul>'.
 1525:                           &mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.',
 1526:                               '<a href="'.$requrl.'">','</a>').
 1527:                           '</p>');
 1528:             }
 1529:         }
 1530:     } elsif (!$env{'user.adv'}) {
 1531:        if ($inrole) {
 1532:             $r->print('<h3>'.&mt('Currently no additional roles, courses or communities').'</h3>');
 1533:         } else {
 1534:             $r->print('<h3>'.&mt('Currently no active roles, courses or communities').'</h3>');
 1535:         }
 1536:         &findcourse_advice($r,$cattype);
 1537:     }
 1538:     return;
 1539: }
 1540: 
 1541: sub privileges_info {
 1542:     my ($which) = @_;
 1543:     my $output;
 1544: 
 1545:     $which ||= $env{'request.role'};
 1546: 
 1547:     foreach my $envkey (sort(keys(%env))) {
 1548: 	next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
 1549: 
 1550: 	my $where=$1;
 1551: 	my $ttype;
 1552: 	my $twhere;
 1553: 	my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
 1554: 	if ($trest) {
 1555: 	    if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
 1556: 		$ttype='Authoring Space';
 1557: 		$twhere='User: '.$trest.', Domain: '.$tdom;
 1558: 	    } else {
 1559: 		$ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
 1560: 		$twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
 1561: 		if ($tsec) {
 1562: 		    my $sec_type = 'Section';
 1563: 		    if (exists($env{"user.role.gr.$where"})) {
 1564: 			$sec_type = 'Group';
 1565: 		    }
 1566: 		    $twhere.=' ('.$sec_type.': '.$tsec.')';
 1567: 		}
 1568: 	    }
 1569: 	} elsif ($tdom) {
 1570: 	    $ttype='Domain';
 1571: 	    $twhere=$tdom;
 1572: 	} else {
 1573: 	    $ttype='System';
 1574: 	    $twhere='/';
 1575: 	}
 1576: 	$output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
 1577: 	foreach my $priv (sort(split(/:/,$env{$envkey}))) {
 1578: 	    next if (!$priv);
 1579: 
 1580: 	    my ($prv,$restr)=split(/\&/,$priv);
 1581: 	    my $trestr='';
 1582: 	    if ($restr ne 'F') {
 1583: 		$trestr.=' ('.
 1584: 		    join(', ',
 1585: 			 map { &Apache::lonnet::plaintext($_) } 
 1586: 			     (split('',$restr))).') ';
 1587: 	    }
 1588: 	    $output .= "\n\t".
 1589: 		'<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
 1590: 	}
 1591: 	$output .= "\n".'</ul>';
 1592:     }
 1593:     return $output;
 1594: }
 1595: 
 1596: sub build_roletext {
 1597:     my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
 1598:     my ($roletext,$roletext_end);
 1599:     my $is_dc=($trolecode =~ m/^dc\./);
 1600:     my $rowspan=($is_dc) ? ''
 1601:                          : ' rowspan="2" ';
 1602: 
 1603:     unless ($nochoose) {
 1604:         my $buttonname=$trolecode;
 1605:         $buttonname=~s/\W//g;
 1606:         if (!$button) {
 1607:             if ($switchserver) {
 1608:                 $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
 1609:                           .'<a href="/adm/switchserver?'.$switchserver.'">'
 1610:                           .&mt('Switch Server')
 1611:                           .'</a></td>';
 1612:             } else {
 1613:                 $roletext.=('<td'.$rowspan.' class="'.$tbg.'">&nbsp;</td>');
 1614:             }
 1615:             if ($switchwarning) {
 1616:                 if ($tremark eq '') {
 1617:                     $tremark = $switchwarning;
 1618:                 } else {
 1619:                     $tremark .= '<br />'.$switchwarning;
 1620:                 }
 1621:             }
 1622:         } elsif ($tstatus eq 'is') {
 1623:             $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
 1624:                         '<input name="'.$buttonname.'" type="button" value="'.
 1625:                         &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
 1626:                         $trolecode."','".$buttonname.'\');" /></td>';
 1627:         } elsif ($tryagain) {
 1628:             $roletext.=
 1629:                 '<td'.$rowspan.' class="'.$tbg.'">'.
 1630:                 '<input name="'.$buttonname.'" type="button" value="'.
 1631:                 &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
 1632:                         $trolecode."','".$buttonname.'\');" /></td>';
 1633:         } elsif ($advanced) {
 1634:             $roletext.=
 1635:                 '<td'.$rowspan.' class="'.$tbg.'">'.
 1636:                 '<input name="'.$buttonname.'" type="button" value="'.
 1637:                 &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
 1638:                         $trolecode."','".$buttonname.'\');" /></td>';
 1639:         } elsif ($reinit) {
 1640:             $roletext.= 
 1641:                 '<td'.$rowspan.' class="'.$tbg.'">'.
 1642:                 '<input name="'.$buttonname.'" type="button" value="'.
 1643:                 &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
 1644:                         $trolecode."','".$buttonname.'\');" /></td>';
 1645:         } else {
 1646:             $roletext.=
 1647:                 '<td'.$rowspan.' class="'.$tbg.'">'.
 1648:                 '<input name="'.$buttonname.'" type="button" value="'.
 1649:                 &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
 1650:                         $trolecode."','".$buttonname.'\');" /></td>';
 1651:         }
 1652:     }
 1653:     if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
 1654: 	$tremark.=&Apache::lonannounce::showday(time,1,
 1655: 			 &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
 1656:     }
 1657:     $roletext.='<td>'.$trole.'</td>'
 1658:               .'<td>'.$twhere.'</td>'
 1659:               .'<td>'.$tpstart.'</td>'
 1660:               .'<td>'.$tpend.'</td>';
 1661:     if (!$is_dc) {
 1662:         $roletext_end = '<td colspan="4">'.
 1663:                         $tremark.'&nbsp;'.
 1664:                         '</td>';
 1665:     }
 1666:     return ($roletext,$roletext_end);
 1667: }
 1668: 
 1669: sub check_author_homeserver {
 1670:     my ($uname,$udom)=@_;
 1671:     if (($uname eq '') || ($udom eq '')) {
 1672:         return ('fail','');
 1673:     }
 1674:     my $home = &Apache::lonnet::homeserver($uname,$udom);
 1675:     if (&Apache::lonnet::host_domain($home) ne $udom) {
 1676:         return ('fail',$home);
 1677:     }
 1678:     my @ids=&Apache::lonnet::current_machine_ids();
 1679:     if (grep(/^\Q$home\E$/,@ids)) {
 1680:         return ('ok',$home);
 1681:     } else {
 1682:         return ('switchserver',$home);
 1683:     }
 1684: }
 1685: 
 1686: sub check_for_adhoc {
 1687:     my ($dcroles,$dhroles,$update,$then) = @_;
 1688:     my $numdc = 0;
 1689:     my $numdh = 0;
 1690:     my $numadhoc = 0;
 1691:     my $num_custom_adhoc = 0;
 1692:     if ($env{'user.adv'}) {
 1693:         foreach my $envkey (sort(keys(%env))) {
 1694:             if ($envkey=~/^user\.role\.(dc|dh)\.\/($match_domain)\/$/) {
 1695:                 my $role = $1;
 1696:                 my $roledom = $2;
 1697:                 my $liverole = 1;
 1698:                 my ($tstart,$tend)=split(/\./,$env{$envkey});
 1699:                 my $limit = $update;
 1700:                 if ((($role eq 'dc') && ($env{'request.role'} eq 'dc./'.$roledom.'/')) ||
 1701:                     (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$roledom.'/'))) {
 1702:                     $limit = $then;
 1703:                 }
 1704:                 if ($tstart && $tstart>$limit) { $liverole = 0; }
 1705:                 if ($tend   && $tend  <$limit) { $liverole = 0; }
 1706:                 if ($liverole) {
 1707:                     if ($role eq 'dc') {
 1708:                         $dcroles->{$roledom} = $envkey;
 1709:                         $numdc++;
 1710:                     } else {
 1711:                         $dhroles->{$roledom} = $envkey;
 1712:                         if ($env{'environment.adhocroles.'.$roledom} ne '') {
 1713:                             $numadhoc ++;
 1714:                         }
 1715:                         $numdh++;
 1716:                     }
 1717:                 }
 1718:             }
 1719:         }
 1720:     }
 1721:     return ($numdc,$numdh,$numadhoc);
 1722: }
 1723: 
 1724: sub adhoc_course_role {
 1725:     my ($refresh,$update,$then) = @_;
 1726:     my ($cdom,$cnum,$crstype);
 1727:     $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1728:     $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1729:     $crstype = &Apache::loncommon::course_type();
 1730:     if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
 1731:         my $setprivs;
 1732:         if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
 1733:             $setprivs = 1;
 1734:         } else {
 1735:             my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
 1736:             if (($start && ($start>$refresh || $start == -1)) ||
 1737:                 ($end && $end<$update)) {
 1738:                 $setprivs = 1;
 1739:             }
 1740:         }
 1741:         unless ($setprivs) {
 1742:             if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
 1743:                 $setprivs = 1;
 1744:             }
 1745:         }
 1746:         if ($setprivs) {
 1747:             if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)(.*?)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 1748:                 my $role = $1;
 1749:                 my $custom_role = $2;
 1750:                 my $usec = $3;
 1751:                 if ($role eq 'cr') {
 1752:                     if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
 1753:                         $role .= $custom_role;
 1754:                     } else {
 1755:                         return;
 1756:                     }
 1757:                 }
 1758:                 my (%userroles,%newrole,%newgroups,%group_privs);
 1759:                 my %cgroups =
 1760:                     &Apache::lonnet::get_active_groups($env{'user.domain'},
 1761:                                             $env{'user.name'},$cdom,$cnum);
 1762:                 foreach my $group (keys(%cgroups)) {
 1763:                     $group_privs{$group} =
 1764:                         $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
 1765:                 }
 1766:                 $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
 1767:                 my $area = '/'.$cdom.'/'.$cnum;
 1768:                 my $spec = $role.'.'.$area;
 1769:                 if ($usec ne '') {
 1770:                     $spec .= '/'.$usec;
 1771:                     $area .= '/'.$usec;
 1772:                 }
 1773:                 if ($role =~ /^cr/) {
 1774:                     &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
 1775:                 } else {
 1776:                     &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
 1777:                 }
 1778:                 &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
 1779:                 my $adhocstart = $refresh-1;
 1780:                 $userroles{'user.role.'.$spec} = $adhocstart.'.';
 1781:                 &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
 1782:             }
 1783:         }
 1784:     }
 1785:     return;
 1786: }
 1787: 
 1788: sub check_forcc {
 1789:     my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
 1790:     my ($is_cc,$ccrole);
 1791:     if ($crstype eq 'Community') {
 1792:         $ccrole = 'co';
 1793:     } else {
 1794:         $ccrole = 'cc';
 1795:     }
 1796:     if (&Apache::lonnet::is_course($cdom,$cnum)) {
 1797:         my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
 1798:         if (defined($env{$envkey})) {
 1799:             $is_cc = 1;
 1800:             my ($tstart,$tend)=split(/\./,$env{$envkey});
 1801:             my $limit = $update;
 1802:             if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
 1803:                 $limit = $then;
 1804:             }
 1805:             if ($tstart && $tstart>$refresh) { $is_cc = 0; }
 1806:             if ($tend   && $tend  <$limit) { $is_cc = 0; }
 1807:         }
 1808:     }
 1809:     return $is_cc;
 1810: }
 1811: 
 1812: sub courselink {
 1813:     my ($roledom,$rowtype,$role) = @_;
 1814:     my $courseform=&Apache::loncommon::selectcourse_link
 1815:                    ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role,
 1816:                     'domain'.$rowtype.'_'.$roledom.'_'.$role,
 1817:                     'coursedesc'.$rowtype.'_'.$roledom.'_'.$role,
 1818:                     $roledom.':'.$role,undef,'Course/Community');
 1819:     my $hiddenitems = '<input type="hidden" name="domain'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
 1820:                       '<input type="hidden" name="origdom'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
 1821:                       '<input type="hidden" name="course'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />'.
 1822:                       '<input type="hidden" name="coursedesc'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />';
 1823:     return $courseform.$hiddenitems;
 1824: }
 1825: 
 1826: sub coursepick_jscript {
 1827:     my %js_lt = &Apache::lonlocal::texthash(
 1828:                   plsu => "Please use the 'Select Course/Community' link to open a separate pick course window where you may select the course or community you wish to enter.",
 1829:                   youc => 'You can only use this screen to select courses and communities in the current domain.',
 1830:              );
 1831:     &js_escape(\%js_lt);
 1832:     my $verify_script = <<"END";
 1833: <script type="text/javascript">
 1834: // <![CDATA[
 1835: function verifyCoursePick(caller) {
 1836:     var numbutton = getIndex(caller)
 1837:     var pickedCourse = document.rolechoice.elements[numbutton+4].value
 1838:     var pickedDomain = document.rolechoice.elements[numbutton+2].value
 1839:     if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
 1840:         if (pickedCourse != '') {
 1841:             if (numbutton != -1) {
 1842:                 var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
 1843:                 document.rolechoice.elements[numbutton+1].name = courseTarget
 1844:                 document.rolechoice.submit()
 1845:             }
 1846:         }
 1847:         else {
 1848:             alert("$js_lt{'plsu'}");
 1849:         }
 1850:     }
 1851:     else {
 1852:         alert("$js_lt{'youc'}")
 1853:     }
 1854: }
 1855: function getIndex(caller) {
 1856:     for (var i=0;i<document.rolechoice.elements.length;i++) {
 1857:         if (document.rolechoice.elements[i] == caller) {
 1858:             return i;
 1859:         }
 1860:     }
 1861:     return -1;
 1862: }
 1863: // ]]>
 1864: </script>
 1865: END
 1866:     return $verify_script;
 1867: }
 1868: 
 1869: sub coauthorlink {
 1870:     my ($dcdom,$rowtype) = @_;
 1871:     my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
 1872:     my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
 1873:     return $coauthorform.$hiddenitems;
 1874: }
 1875: 
 1876: sub display_cc_role {
 1877:     my $rolekey = shift;
 1878:     my ($roletext,$roletext_end);
 1879:     my $advanced = $env{'user.adv'};
 1880:     my $tryagain = $env{'form.tryagain'};
 1881:     unless ($rolekey =~/^error\:/) {
 1882:         if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
 1883:             my $ccrole = $1;
 1884:             my $tdom = $2;
 1885:             my $trest = $3;
 1886:             my $tcourseid = $tdom.'_'.$trest;
 1887:             my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
 1888:             my $twhere;
 1889:             my $ttype;
 1890:             my $tbg='LC_roles_is';
 1891:             my %newhash=&Apache::lonnet::coursedescription($tcourseid);
 1892:             if (%newhash) {
 1893:                 $twhere=$newhash{'description'}.
 1894:                         ' <span class="LC_fontsize_small">'.
 1895:                         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
 1896:                         '</span>';
 1897:                 $ttype = $newhash{'type'};
 1898:             } else {
 1899:                 $twhere=&mt('Currently not available');
 1900:                 $env{'course.'.$tcourseid.'.description'}=$twhere;
 1901:             }
 1902:             my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
 1903:             $twhere.="<br />".&mt('Domain').":".$tdom;
 1904:             ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
 1905:         }
 1906:     }
 1907:     return ($roletext,$roletext_end);
 1908: }
 1909: 
 1910: sub adhoc_roles_row {
 1911:     my ($dcdom,$rowtype) = @_;
 1912:     my $output = &Apache::loncommon::continue_data_table_row()
 1913:                  .' <td colspan="5" class="LC_textsize_mobile">'
 1914:                  .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
 1915:                      ,'<span class="LC_cusr_emph">','</span>',$dcdom)
 1916:                  .' ';
 1917:     my $role = 'cc';
 1918:     my $selectcclink = &courselink($dcdom,$rowtype,$role);
 1919:     my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
 1920:     my $carole = &Apache::lonnet::plaintext('ca');
 1921:     my $selectcalink = &coauthorlink($dcdom,$rowtype);
 1922:     $output.=$ccrole.': '.$selectcclink
 1923:             .' | '.$carole.': '.$selectcalink.'</td>'
 1924:             .&Apache::loncommon::end_data_table_row();
 1925:     return $output;
 1926: }
 1927: 
 1928: sub adhoc_customroles_row {
 1929:     my ($dhdom,$rowtype) = @_;
 1930:     my $output = &Apache::loncommon::continue_data_table_row()
 1931:                  .' <td colspan="5" class="LC_textsize_mobile">'
 1932:                  .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --',
 1933:                       '<span class="LC_cusr_emph">','</span>',$dhdom);
 1934:     my @customroles = split(/,/,$env{'environment.adhocroles.'.$dhdom});
 1935:     my $count = 0;
 1936:     foreach my $role (@customroles) {
 1937:         next if (($role eq '') || ($role =~ /\W/));
 1938:         $output .= ' '.$role.': '.&courselink($dhdom,$rowtype,$role).' |';
 1939:         $count ++;
 1940:     }
 1941:     if ($count) {
 1942:         return $output;
 1943:     }
 1944:     return;
 1945: }
 1946: 
 1947: sub recent_filename {
 1948:     my $area=shift;
 1949:     return 'nohist_recent_'.&escape($area);
 1950: }
 1951: 
 1952: sub courseloadpage {
 1953:     my ($courseid) = @_;
 1954:     my $startpage;
 1955:     my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
 1956: 					      [$courseid.':courseinit']);
 1957:     my ($tmp) = %entry_settings;
 1958:     unless ($tmp =~ /^error: 2 /) {
 1959:         $startpage = $entry_settings{$courseid.':courseinit'};
 1960:     }
 1961:     if ($startpage eq '') {
 1962:         if (exists($env{'environment.course_init_display'})) {
 1963:             $startpage = $env{'environment.course_init_display'};
 1964:         }
 1965:     }
 1966:     return $startpage;
 1967: }
 1968: 
 1969: sub update_session_roles {
 1970:     my $then=$env{'user.login.time'};
 1971:     my $refresh=$env{'user.refresh.time'};
 1972:     if (!$refresh) {
 1973:         $refresh = $then;
 1974:     }
 1975:     my $update = $env{'user.update.time'};
 1976:     if (!$update) {
 1977:         $update = $then;
 1978:     }
 1979:     my $now = time;
 1980:     my %roleshash =
 1981:         &Apache::lonnet::get_my_roles('','','userroles',
 1982:                                       ['active','future','previous'],
 1983:                                       undef,undef,1);
 1984:     my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
 1985:         %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
 1986:         %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
 1987:         %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
 1988:         @rolecodes);
 1989:     my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
 1990:     my %courseroles;
 1991:     foreach my $item (keys(%roleshash)) {
 1992:         my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
 1993:         my ($tstart,$tend) = split(/:/,$roleshash{$item});
 1994:         my ($section,$group,@group_privs);
 1995:         if ($role =~ m{^gr/(\w*)$}) {
 1996:             $role = 'gr';
 1997:             my $priv = $1;
 1998:             next if ($tstart eq '-1');
 1999:             if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
 2000:                 if ($priv ne '') {
 2001:                     push(@group_privs,$priv);
 2002:                 }
 2003:             }
 2004:             if ($remainder =~ /:/) {
 2005:                 (my $additional_privs,$group) =
 2006:                     ($remainder =~ /^([\w:]+):([^:]+)$/);
 2007:                 if ($additional_privs ne '') {
 2008:                     if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
 2009:                         push(@group_privs,split(/:/,$additional_privs));
 2010:                         @group_privs = sort(@group_privs);
 2011:                     }
 2012:                 }
 2013:             } else {
 2014:                 $group = $remainder;
 2015:             }
 2016:         } else {
 2017:             $section = $remainder;
 2018:         }
 2019:         my $where = "/$udom/$uname";
 2020:         if ($section ne '') {
 2021:             $where .= "/$section";
 2022:         } elsif ($group ne '') {
 2023:             $where .= "/$group";
 2024:         }
 2025:         my $rolekey = "$role.$where";
 2026:         my $envkey = "user.role.$rolekey";
 2027:         $dbroles{$envkey} = 1;
 2028:         if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
 2029:             if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
 2030:                 $currrole_expired = 1;
 2031:             }
 2032:         }
 2033:         if ($env{$envkey} eq '') {
 2034:             my $status_in_db =
 2035:                 &curr_role_status($tstart,$tend,$now,$now);
 2036:                 &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
 2037:             if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
 2038:                 if ($status_in_db eq 'active') {
 2039:                     if ($section eq '') {
 2040:                         push(@newsec,'none');
 2041:                     } else {
 2042:                         push(@newsec,$section);
 2043:                     }
 2044:                 }
 2045:             } else {
 2046:                 unless (grep(/^\Q$role\E$/,@changed_roles)) {
 2047:                     push(@changed_roles,$role);
 2048:                 }
 2049:                 if ($status_in_db ne 'previous') {
 2050:                     if ($role eq 'gr') {
 2051:                         $newgroup{$rolekey} = $status_in_db;
 2052:                         if ($status_in_db eq 'active') {
 2053:                             unless (ref($courseroles{$udom}) eq 'HASH') {
 2054:                                 %{$courseroles{$udom}} =
 2055:                                     &Apache::lonnet::get_my_roles('','','userroles',
 2056:                                                                   ['active'],\@possroles,
 2057:                                                                   [$udom],1);
 2058:                             }
 2059:                             &Apache::lonnet::get_groups_roles($udom,$uname,
 2060:                                                               $courseroles{$udom},
 2061:                                                               \@rolecodes,\%groups_roles);
 2062:                         }
 2063:                     } else {
 2064:                         $newrole{$rolekey} = $status_in_db;
 2065:                     }
 2066:                 }
 2067:             }
 2068:         } else {
 2069:             my ($currstart,$currend) = split(/\./,$env{$envkey});
 2070:             if ($role eq 'gr') {
 2071:                 if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
 2072:                     $hasgroups = 1;
 2073:                 }
 2074:             }
 2075:             if (($currstart ne $tstart) || ($currend ne $tend)) {
 2076:                 my $status_in_env =
 2077:                     &curr_role_status($currstart,$currend,$refresh,$update);
 2078:                 my $status_in_db =
 2079:                     &curr_role_status($tstart,$tend,$now,$now);
 2080:                 if ($status_in_env ne $status_in_db) {
 2081:                     if ($status_in_env eq 'active') {
 2082:                         if ($role eq 'st') {
 2083:                             if ($env{'request.role'} eq $rolekey) {
 2084:                                 my $switchsection;
 2085:                                 unless (ref($courseroles{$udom}) eq 'HASH') {
 2086:                                     %{$courseroles{$udom}} =
 2087:                                         &Apache::lonnet::get_my_roles('','','userroles',
 2088:                                                                       ['active'],
 2089:                                                                       \@possroles,[$udom],1);
 2090:                                 }
 2091:                                 foreach my $crsrole (keys(%{$courseroles{$udom}})) {
 2092:                                     if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
 2093:                                         $switchsection = 1;
 2094:                                         last;
 2095:                                     }
 2096:                                 }
 2097:                                 if ($switchsection) {
 2098:                                     if ($section eq '') {
 2099:                                         $oldsec = 'none';
 2100:                                     } else {
 2101:                                         $oldsec = $section;
 2102:                                     }
 2103:                                     &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
 2104:                                 } else {
 2105:                                     $currrole_expired = 1;
 2106:                                     next;
 2107:                                 }
 2108:                             }
 2109:                         }
 2110:                         unless ($rolekey eq $env{'request.role'}) {
 2111:                             if ($role eq 'gr') {
 2112:                                 &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
 2113:                             } else {
 2114:                                 &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
 2115:                                 &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
 2116:                             }
 2117:                             &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
 2118:                         }
 2119:                     } elsif ($status_in_db eq 'active') {
 2120:                         if (($role eq 'st') &&
 2121:                             ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
 2122:                             if ($section eq '') {
 2123:                                 push(@newsec,'none');
 2124:                             } else {
 2125:                                 push(@newsec,$section);
 2126:                             }
 2127:                         } elsif ($role eq 'gr') {
 2128:                             unless (ref($courseroles{$udom}) eq 'HASH') {
 2129:                                 %{$courseroles{$udom}} =
 2130:                                     &Apache::lonnet::get_my_roles('','','userroles',
 2131:                                                                   ['active'],
 2132:                                                                   \@possroles,[$udom],1);
 2133:                             }
 2134:                             &Apache::lonnet::get_groups_roles($udom,$uname,
 2135:                                                               $courseroles{$udom},
 2136:                                                               \@rolecodes,\%groups_roles);
 2137:                         }
 2138:                         &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
 2139:                     }
 2140:                     unless (grep(/^\Q$role\E$/,@changed_roles)) {
 2141:                         push(@changed_roles,$role);
 2142:                     }
 2143:                     if ($role eq 'gr') {
 2144:                         $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
 2145:                     } else {
 2146:                         $rolechange{$rolekey} = $status_in_db;
 2147:                     }
 2148:                 }
 2149:             } else {
 2150:                 if ($role eq 'gr') {
 2151:                     unless ($checkedgroup{$where}) {
 2152:                         my $status_in_db =
 2153:                             &curr_role_status($tstart,$tend,$refresh,$now);
 2154:                         if ($tstart eq '-1') {
 2155:                             $status_in_db = 'deleted';
 2156:                         }
 2157:                         unless (ref($courseroles{$udom}) eq 'HASH') {
 2158:                             %{$courseroles{$udom}} =
 2159:                                 &Apache::lonnet::get_my_roles('','','userroles',
 2160:                                                               ['active'],
 2161:                                                               \@possroles,[$udom],1);
 2162:                         }
 2163:                         if (ref($courseroles{$udom}) eq 'HASH') {
 2164:                             foreach my $item (keys(%{$courseroles{$udom}})) {
 2165:                                 next unless ($item =~ /^\Q$uname\E/);
 2166:                                 my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
 2167:                                 my $area = '/'.$cdom.'/'.$cnum;
 2168:                                 if ($crssec ne '') {
 2169:                                     $area .= '/'.$crssec;
 2170:                                 }
 2171:                                 my $crsrolekey = $crsrole.'.'.$area;
 2172:                                 my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
 2173:                                 $currprivs =~ s/^://;
 2174:                                 $currprivs =~ s/\&F$//;
 2175:                                 my @curr_grp_privs = split(/\&F:/,$currprivs);
 2176:                                 @curr_grp_privs = sort(@curr_grp_privs);
 2177:                                 my @diffs;
 2178:                                 if (@group_privs > 0 || @curr_grp_privs > 0) {
 2179:                                     @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
 2180:                                 }
 2181:                                 if (@diffs == 0) {
 2182:                                     last;
 2183:                                 } else {
 2184:                                     unless(grep(/^\Qgr\E$/,@rolecodes)) {
 2185:                                         push(@rolecodes,'gr');
 2186:                                     }
 2187:                                     &gather_roleprivs(\%allroles,\%allgroups,
 2188:                                                       \%userroles,$where,$role,
 2189:                                                       $tstart,$tend,$status_in_db);
 2190:                                     if ($status_in_db eq 'active') {
 2191:                                         &Apache::lonnet::get_groups_roles($udom,$uname,
 2192:                                                                           $courseroles{$udom},
 2193:                                                                           \@rolecodes,\%groups_roles);
 2194:                                     }
 2195:                                     $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
 2196:                                     last;
 2197:                                 }
 2198:                             }
 2199:                         }
 2200:                         $checkedgroup{$where} = 1;
 2201:                     }
 2202:                 } elsif ($role =~ /^cr/) {
 2203:                     my $status_in_db =
 2204:                         &curr_role_status($tstart,$tend,$refresh,$now);
 2205:                     my ($rdummy,$rest) = split(/\//,$role,2);
 2206:                     my %currpriv;
 2207:                     unless (exists($crprivs{$rest})) {
 2208:                         my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
 2209:                         my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
 2210:                         if (&Apache::lonnet::hostname($homsvr) ne '') {
 2211:                             my ($rdummy,$roledef)=
 2212:                             &Apache::lonnet::get('roles',["rolesdef_$rrole"],
 2213:                                                  $rdomain,$rauthor);
 2214:                             if (($rdummy ne 'con_lost') && ($roledef ne '')) {
 2215:                                 my $i = 0;
 2216:                                 my @scopes = ('sys','dom','crs');
 2217:                                 my @privs = split(/\_/,$roledef);
 2218:                                 foreach my $priv (@privs) {
 2219:                                     my ($blank,@prv) = split(/:/,$priv);
 2220:                                     @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
 2221:                                     if (@prv) {
 2222:                                         $priv = ':'.join(':',sort(@prv));
 2223:                                     }
 2224:                                     $crprivs{$rest}{$scopes[$i]} = $priv;
 2225:                                     $i++;
 2226:                                 }
 2227:                             }
 2228:                         }
 2229:                     }
 2230:                     my $status_in_env =
 2231:                         &curr_role_status($currstart,$currend,$refresh,$update);
 2232:                     if ($status_in_env eq 'active') {
 2233:                         $currpriv{sys} = $env{"user.priv.$rolekey./"};
 2234:                         $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
 2235:                         $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
 2236:                         if (keys(%crprivs)) {
 2237:                             if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
 2238:                                 ($crprivs{$rest}{dom} ne $currpriv{dom})
 2239:  ||
 2240:                                 ($crprivs{$rest}{crs} ne $currpriv{crs})) {
 2241:                                 &gather_roleprivs(\%allroles,\%allgroups,
 2242:                                                   \%userroles,$where,$role,
 2243:                                                   $tstart,$tend,$status_in_db);
 2244:                                 unless (grep(/^\Q$role\E$/,@changed_roles)) {
 2245:                                     push(@changed_roles,$role);
 2246:                                 }
 2247:                                 $customprivchg{$rolekey} = $status_in_env;
 2248:                             }
 2249:                         }
 2250:                     }
 2251:                 }
 2252:             }
 2253:         }
 2254:     }
 2255:     foreach my $envkey (keys(%env)) {
 2256:         next unless ($envkey =~ /^user\.role\./);
 2257:         next if ($dbroles{$envkey});
 2258:         next if ($envkey eq 'user.role.'.$env{'request.role'});
 2259:         my ($currstart,$currend) = split(/\./,$env{$envkey});
 2260:         my $status_in_env =
 2261:             &curr_role_status($currstart,$currend,$refresh,$update);
 2262:         my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
 2263:         my ($role,$rest)=split(m{\./},$rolekey,2);
 2264:         $rest = '/'.$rest; 
 2265:         if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
 2266:             if ($status_in_env eq 'active') {
 2267:                 if ($role eq 'gr') {
 2268:                     &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
 2269:                                                            \@possroles);
 2270:                 } else {
 2271:                     &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
 2272:                     &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
 2273:                 }
 2274:                 unless (grep(/^\Q$role\E$/,@changed_roles)) {
 2275:                     push(@changed_roles,$role);
 2276:                 }
 2277:                 $deletedroles{$rolekey} = 1;
 2278:             }
 2279:         }
 2280:     }
 2281:     if (($oldsec) && (@newsec > 0)) {
 2282:         if (@newsec > 1) {
 2283:             $msg = '<p class="LC_warning">'.&mt('The section has changed for your current role. Log-out and log-in again to select a role for the new section.').'</p>';
 2284:         } else {
 2285:             my $newrole = $env{'request.role'};
 2286:             if ($newsec[0] eq 'none') {
 2287:                 $newrole =~ s{(/[^/])$}{};
 2288:             } elsif ($oldsec eq 'none') {
 2289:                 $newrole .= '/'.$newsec[0];
 2290:             } else {
 2291:                 $newrole =~ s{([^/]+)$}{$newsec[0]};
 2292:             }
 2293:             my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
 2294:             my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
 2295:             my %temp=('logout_'.$env{'request.course.id'} => time);
 2296:             &Apache::lonnet::put('email_status',\%temp);
 2297:             &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
 2298:             &Apache::lonnet::appenv({"request.course.id"   => '',
 2299:                                      "request.course.fn"   => '',
 2300:                                      "request.course.uri"  => '',
 2301:                                      "request.course.sec"  => '',
 2302:                                      "request.role"        => 'cm',
 2303:                                      "request.role.adv"    => $env{'user.adv'},
 2304:                                      "request.role.domain" => $env{'user.domain'}});
 2305:             my $rolename = &Apache::loncommon::plainname($curr_role);
 2306:             $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
 2307:                    '<input type="hidden" name="newrole" value="" />'.
 2308:                    '<input type="hidden" name="selectrole" value="1" />'.
 2309:                    '<span class="LC_info">'.
 2310:                    &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
 2311:             my $button = '<input type="button" name="sectionchanged" value="'.
 2312:                          &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
 2313:             if ($newsec[0] eq 'none') {
 2314:                 $msg .= &mt('[_1] to continue with your new section-less role.',$button);
 2315:             } else {
 2316:                 $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
 2317:             }
 2318:             $msg .= '</form></p>';
 2319:         }
 2320:     } elsif ($currrole_expired) {
 2321:         $msg .= '<p class="LC_warning">';
 2322:         if (&Apache::loncommon::show_course()) {
 2323:             $msg .= &mt('Your role in the current course has expired.');
 2324:         } else {
 2325:             $msg .= &mt('Your current role has expired.');
 2326:         }
 2327:         $msg .= '<br />'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'</p>';
 2328:     }
 2329:     &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
 2330:     my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
 2331:     $curr_author = $env{'user.author'};
 2332:     if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
 2333:         ($env{'request.role'} =~/^aa/)) {
 2334:         $curr_role_author=1;
 2335:     }
 2336:     $curr_is_adv = $env{'user.adv'};
 2337:     $curr_role_adv = $env{'request.role.adv'};
 2338:     if (keys(%userroles) > 0) {
 2339:         foreach my $role (@changed_roles) {
 2340:             unless(grep(/^\Q$role\E$/,@rolecodes)) {
 2341:                 push(@rolecodes,$role);
 2342:             }
 2343:         }
 2344:         unless(grep(/^\Qcm\E$/,@rolecodes)) {
 2345:             push(@rolecodes,'cm');
 2346:         }
 2347:         &Apache::lonnet::appenv(\%userroles,\@rolecodes);
 2348:     }
 2349:     my %newenv;
 2350:     if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
 2351:         unless ($curr_is_adv) {
 2352:             $newenv{'user.adv'} = 1;
 2353:         }
 2354:     } elsif ($curr_is_adv && !$curr_role_adv) {
 2355:         &Apache::lonnet::delenv('user.adv');
 2356:     }
 2357:     my %authorroleshash =
 2358:         &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
 2359:     if (keys(%authorroleshash)) {
 2360:         unless ($curr_author) {
 2361:             $newenv{'user.author'} = 1;
 2362:         }
 2363:     } elsif ($curr_author && !$curr_role_author) {
 2364:         &Apache::lonnet::delenv('user.author');
 2365:     }
 2366:     if ($env{'request.course.id'}) {
 2367:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 2368:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 2369:         my (@activecrsgroups,$crsgroupschanged);
 2370:         if ($env{'request.course.groups'}) {
 2371:             @activecrsgroups = split(/:/,$env{'request.course.groups'});
 2372:             foreach my $item (keys(%deletedroles)) {
 2373:                 if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
 2374:                     if (grep(/^\Q$1\E$/,@activecrsgroups)) {
 2375:                         $crsgroupschanged = 1;
 2376:                         last;
 2377:                     }
 2378:                 }
 2379:             }
 2380:         }
 2381:         unless ($crsgroupschanged) {
 2382:             foreach my $item (keys(%newgroup)) {
 2383:                 if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
 2384:                     if ($newgroup{$item} eq 'active') {
 2385:                         $crsgroupschanged = 1;
 2386:                         last;
 2387:                     }
 2388:                 }
 2389:             }
 2390:         }
 2391:         if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
 2392:             (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
 2393:             ($crsgroupschanged)) {
 2394:             my %grouproles =  &Apache::lonnet::get_my_roles('','','userroles',
 2395:                                                             ['active'],['gr'],[$cdom],1);
 2396:             my @activegroups;
 2397:             foreach my $item (keys(%grouproles)) {
 2398:                 next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
 2399:                 my $group;
 2400:                 my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
 2401:                 if ($remainder =~ /:/) {
 2402:                     (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
 2403:                 } else {
 2404:                     $group = $remainder;
 2405:                 }
 2406:                 if ($group ne '') {
 2407:                     push(@activegroups,$group);
 2408:                 }
 2409:             }
 2410:             $newenv{'request.course.groups'} = join(':',@activegroups);
 2411:         }
 2412:     }
 2413:     if (keys(%newenv)) {
 2414:         &Apache::lonnet::appenv(\%newenv);
 2415:     }
 2416:     if (!@changed_roles || !(keys(%changed_groups))) {
 2417:         my ($rolesmsg,$groupsmsg);
 2418:         if (!@changed_roles) {
 2419:             if (&Apache::loncommon::show_course()) {
 2420:                 $rolesmsg = &mt('No new courses or communities');
 2421:             } else {
 2422:                 $rolesmsg = &mt('No role changes');
 2423:             }
 2424:         }
 2425:         if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
 2426:             $groupsmsg = &mt('No changes in course/community groups');
 2427:         }
 2428:         if (!@changed_roles && !(keys(%changed_groups))) {
 2429:             if (($msg ne '') || ($groupsmsg ne '')) {
 2430:                 $msg .= '<ul>';
 2431:                 if ($rolesmsg) {
 2432:                     $msg .= '<li>'.$rolesmsg.'</li>';
 2433:                 }
 2434:                 if ($groupsmsg) {
 2435:                     $msg .= '<li>'.$groupsmsg.'</li>';
 2436:                 }
 2437:                 $msg .= '</ul>';
 2438:             } else {
 2439:                 $msg = '&nbsp;<span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
 2440:             }
 2441:             return $msg;
 2442:         }
 2443:     }
 2444:     my $changemsg;
 2445:     if (@changed_roles > 0) {
 2446:         if (keys(%newgroup) > 0) {
 2447:             my $groupmsg;
 2448:             my (%curr_groups,%groupdescs,$currcrs);
 2449:             foreach my $item (sort(keys(%newgroup))) {
 2450:                 if (&is_active_course($item,$refresh,$update,\%roleshash)) {
 2451:                     if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
 2452:                         my ($cdom,$cnum) = split(/\//,$1);
 2453:                         my $group = $2;
 2454:                         if ($currcrs ne $cdom.'_'.$cnum) {
 2455:                             if ($currcrs) {
 2456:                                 $groupmsg .= '</ul><li>';
 2457:                             }
 2458:                             $groupmsg .= '<li><b>'.
 2459:                                          $env{'course.'.$cdom.'_'.$cnum.'.description'}.'</b><ul>';
 2460:                             $currcrs = $cdom.'_'.$cnum;
 2461:                         }
 2462:                         my $groupdesc;
 2463:                         unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
 2464:                             %{$curr_groups{$cdom.'_'.$cnum}} =
 2465:                                 &Apache::longroup::coursegroups($cdom,$cnum);
 2466:                         }
 2467:                         unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
 2468:                             ($groupdescs{$cdom.'_'.$cnum}{$group})) {
 2469: 
 2470:                             my %groupinfo =
 2471:                                 &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
 2472:                             $groupdescs{$cdom.'_'.$cnum}{$group} =
 2473:                                 &unescape($groupinfo{'description'});
 2474:                         }
 2475:                         $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
 2476:                         if ($groupdesc) {
 2477:                             $groupmsg .= '<li>'.
 2478:                                          &mt('[_1] with status: [_2].',
 2479:                                          '<b>'.$groupdesc.'</b>',$newgroup{$item}).'</li>';
 2480:                         }
 2481:                     }
 2482:                 }
 2483:                 if ($groupmsg) {
 2484:                     $groupmsg .= '</ul></li>';
 2485:                 }
 2486:             }
 2487:             if ($groupmsg) {
 2488:                 $changemsg .= '<li>'.
 2489:                               &mt('Courses with new groups').'</li>'.
 2490:                               '<ul>'.$groupmsg.'</ul></li>';
 2491:             }
 2492:         }
 2493:         if (keys(%newrole) > 0) {
 2494:             my $newmsg;
 2495:             foreach my $item (sort(keys(%newrole))) {
 2496:                 my $desc = &role_desc($item,$update,$refresh,$now);
 2497:                 if ($desc) {
 2498:                     $newmsg .= '<li>'.
 2499:                                &mt('[_1] with status: [_2].',
 2500:                                $desc,&mt($newrole{$item})).'</li>';
 2501:                 }
 2502:             }
 2503:             if ($newmsg) {
 2504:                 $changemsg .= '<li>'.&mt('New roles').
 2505:                               '<ul>'.$newmsg.'</ul>'.
 2506:                               '</li>';
 2507:             }
 2508:         }
 2509:         if (keys(%customprivchg) > 0) {
 2510:             my $privmsg;
 2511:             foreach my $item (sort(keys(%customprivchg))) {
 2512:                 my $desc = &role_desc($item,$update,$refresh,$now);
 2513:                 if ($desc) {
 2514:                     $privmsg .= '<li>'.$desc.'</li>';
 2515:                 }
 2516:             }
 2517:             if ($privmsg) {
 2518:                 $changemsg .= '<li>'.
 2519:                               &mt('Custom roles with privilege changes').
 2520:                               '<ul>'.$privmsg.'</ul>'.
 2521:                               '</li>';
 2522:              }
 2523:         }
 2524:         if (keys(%rolechange) > 0) {
 2525:             my $rolemsg;
 2526:             foreach my $item (sort(keys(%rolechange))) {
 2527:                 my $desc = &role_desc($item,$update,$refresh,$now);  
 2528:                 if ($desc) {
 2529:                     $rolemsg .= '<li>'.
 2530:                                 &mt('[_1] status now: [_2].',$desc,
 2531:                                 $rolechange{$item}).'</li>';
 2532:                 }
 2533:             }
 2534:             if ($rolemsg) {
 2535:                 $changemsg .= '<li>'.
 2536:                               &mt('Existing roles with status changes').'</li>'.
 2537:                               '<ul>'.$rolemsg.'</ul>'.
 2538:                               '</li>';
 2539:             }
 2540:         }
 2541:         if (keys(%deletedroles) > 0) {
 2542:             my $delmsg;
 2543:             foreach my $item (sort(keys(%deletedroles))) {
 2544:                 my $desc = &role_desc($item,$update,$refresh,$now);
 2545:                 if ($desc) {
 2546:                     $delmsg .= '<li>'.$desc.'</li>';
 2547:                 }
 2548:             }
 2549:             if ($delmsg) {
 2550:                 $changemsg .= '<li>'.
 2551:                               &mt('Existing roles now expired').'</li>'.
 2552:                               '<ul>'.$delmsg.'</ul>'.
 2553:                               '</li>';
 2554:             }
 2555:         }
 2556:     }
 2557:     if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
 2558:         my $groupchgmsg;
 2559:         foreach my $key (sort(keys(%changed_groups))) {
 2560:             my $crs = 'gr/'.$key;
 2561:             $crs =~ s/_/\//;
 2562:             if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
 2563:                 if (ref($changed_groups{$key}) eq 'HASH') {
 2564:                     my @showgroups;
 2565:                     foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
 2566:                         if ($changed_groups{$key}{$group} eq 'active') {
 2567:                             push(@showgroups,$group);
 2568:                         }
 2569:                     }
 2570:                     if (@showgroups > 0) {
 2571:                         $groupchgmsg .= '<li>'.
 2572:                                         &mt('Course: [_1], groups: [_2].',$key,
 2573:                                         join(', ',@showgroups)).
 2574:                                         '</li>';
 2575:                     }
 2576:                 }
 2577:             }
 2578:         }
 2579:         if (keys(%groupchange) > 0) {
 2580:             $groupchgmsg .= '<li>'.
 2581:                           &mt('Existing course/community groups with status changes').'</li>'.
 2582:                           '<ul>';
 2583:             foreach my $crs (sort(keys(%groupchange))) {
 2584:                 my $cid = $crs;
 2585:                 $cid=~s{^/}{};
 2586:                 $cid=~s{/}{_};
 2587:                 my $crsdesc = $env{'course.'.$cid.'.description'};
 2588:                 my $cdom = $env{'course.'.$cid.'.domain'};
 2589:                 my $cnum = $env{'course.'.$cid.'.num'};
 2590:                 my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
 2591:                 my %groupdesc;
 2592:                 if (ref($groupchange{$crs}) eq 'HASH') {
 2593:                     $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crsdesc.'</b><ul>');
 2594:                     foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
 2595:                         unless ($groupdesc{$group}) {
 2596:                             my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
 2597:                             $groupdesc{$group} =  &unescape($groupinfo{'description'});
 2598:                         }
 2599:                         $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$groupdesc{$group}.'</b>',$groupchange{$crs}{$group}).'</li>';
 2600:                     }
 2601:                     $groupchgmsg .= '</ul></li>';
 2602:                 }
 2603:             }
 2604:             $groupchgmsg .= '</ul></li>';
 2605:         }
 2606:         if ($groupchgmsg) {
 2607:             $changemsg .= '<li>'.
 2608:                           &mt('Courses with changes in groups').'</li>'.
 2609:                           '<ul>'.$groupchgmsg.'</ul></li>';
 2610:         }
 2611:     }
 2612:     if ($changemsg) {
 2613:         $msg .= '<ul>'.$changemsg.'</ul>';
 2614:     } else {
 2615:         if (&Apache::loncommon::show_course()) {
 2616:             $msg = &mt('No new courses or communities');
 2617:         } else {
 2618:             $msg = &mt('No role changes');
 2619:         }
 2620:     }
 2621:     return $msg;
 2622: }
 2623: 
 2624: sub role_desc {
 2625:     my ($item,$update,$refresh,$now) = @_;
 2626:     my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
 2627:         $trole,$tremark);
 2628:     &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh,
 2629:                                  $now,\$role,\$where,\$trolecode,
 2630:                                  \$tstatus,\$tstart,\$tend);
 2631:     return unless ($role);
 2632:     if ($role =~ /^cr\//) {
 2633:         my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
 2634:         $tremark = &mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
 2635:     }
 2636:     $trole=Apache::lonnet::plaintext($role);
 2637:     my ($tdom,$trest,$tsection)=
 2638:         split(/\//,Apache::lonnet::declutter($where));
 2639:     if (($role eq 'ca') || ($role eq 'aa')) {
 2640:         my $home = &Apache::lonnet::homeserver($trest,$tdom);
 2641:         $home = &Apache::lonnet::hostname($home);
 2642:         $twhere=&mt('User').':&nbsp;'.$trest.'&nbsp; '.&mt('Domain').
 2643:                 ':&nbsp;'.$tdom.'&nbsp; '.&mt('Server').':&nbsp;'.$home;
 2644:     } elsif ($role eq 'au') {
 2645:         my $home = &Apache::lonnet::homeserver
 2646:                        ($env{'user.name'},$env{'user.domain'});
 2647:         $home = &Apache::lonnet::hostname($home);
 2648:         $twhere=&mt('Domain').':&nbsp;'.$tdom.'&nbsp; '.&mt('Server').
 2649:                         ':&nbsp;'.$home;
 2650:     } elsif ($trest) {
 2651:         my $tcourseid=$tdom.'_'.$trest;
 2652:         my $crstype = &Apache::loncommon::course_type($tcourseid);
 2653:         $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
 2654:         if ($env{'course.'.$tcourseid.'.description'}) {
 2655:             $twhere=$env{'course.'.$tcourseid.'.description'};
 2656:         } else {
 2657:             my %newhash=&Apache::lonnet::coursedescription($tcourseid);
 2658:             if (%newhash) {
 2659:                 $twhere=$newhash{'description'};
 2660:             } else {
 2661:                 $twhere=&mt('Currently not available');
 2662:             }
 2663:         }
 2664:         if ($tsection) {
 2665:             $twhere.= '&nbsp; '.&mt('Section').':&nbsp;'.$tsection;
 2666:         }
 2667:         if ($role ne 'st') {
 2668:             $twhere.= '&nbsp; '.&mt('Domain').':&nbsp;'.$tdom;
 2669:         }
 2670:     } elsif ($tdom) {
 2671:         $twhere = &mt('Domain').':&nbsp;'.$tdom;
 2672:     }
 2673:     my $output;
 2674:     if ($trole) {
 2675:         $output = $trole;
 2676:         if ($twhere) {
 2677:             $output .= " -- $twhere";
 2678:         }
 2679:         if ($tremark) {
 2680:             $output .= '<br />'.$tremark;
 2681:         }
 2682:     }
 2683:     return $output;
 2684: }
 2685: 
 2686: sub curr_role_status {
 2687:     my ($start,$end,$refresh,$update) = @_;
 2688:     if (($start) && ($start<0)) { return 'deleted' };
 2689:     my $status = 'active';
 2690:     if (($end) && ($end<=$update)) {
 2691:         $status = 'previous';
 2692:     }
 2693:     if (($start) && ($refresh<$start)) {
 2694:         $status = 'future';
 2695:     }
 2696:     return $status;
 2697: }
 2698: 
 2699: sub gather_roleprivs {
 2700:     my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
 2701:     return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
 2702:     if (($area ne '') && ($role ne '')) {
 2703:         &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
 2704:                                      $area,$tstart,$tend);
 2705:         my $spec=$role.'.'.$area;
 2706:         $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
 2707:         my ($tdummy,$tdomain,$trest)=split(/\//,$area);
 2708:         if ($status eq 'active') { 
 2709:             if ($role =~ /^cr\//) {
 2710:                 &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
 2711:             } elsif ($role eq 'gr') {
 2712:                 my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
 2713:                                                     $env{'user.domain'},
 2714:                                                     $env{'user.name'});
 2715:                 my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
 2716:                 (undef,my $group_privs) = split(/\//,$trole);
 2717:                 $group_privs = &unescape($group_privs);
 2718:                 &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
 2719:             } else {
 2720:                 &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
 2721:             }
 2722:         }
 2723:     }
 2724:     return;
 2725: }
 2726: 
 2727: sub is_active_course {
 2728:     my ($rolekey,$refresh,$update,$roleshashref) = @_;
 2729:     return unless(ref($roleshashref) eq 'HASH');
 2730:     my ($role,$cdom,$cnum) = split(/\//,$rolekey);
 2731:     my $is_active;
 2732:     foreach my $key (keys(%{$roleshashref})) {
 2733:         if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
 2734:             my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
 2735:             my $status = &curr_role_status($tstart,$tend,$refresh,$update);
 2736:             if ($status eq 'active') {
 2737:                 $is_active = 1;
 2738:                 last;
 2739:             }
 2740:         }
 2741:     }
 2742:     return $is_active;
 2743: }
 2744: 
 2745: sub get_roles_functions {
 2746:     my ($rolescount,$cattype) = @_;
 2747:     my @links;
 2748:     push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
 2749:     if ($env{'environment.canrequest.author'}) {
 2750:         unless (&Apache::loncoursequeueadmin::is_active_author()) {
 2751:             push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
 2752:         }
 2753:     }
 2754:     if (($rolescount > 3) || ($env{'environment.recentroles'})) {
 2755:         push(@links,['/adm/preferences?action=changerolespref&amp;returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
 2756:     }
 2757:     if (&Apache::lonmenu::check_for_rcrs()) {
 2758:         push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
 2759:     }
 2760:     if ($env{'form.state'} eq 'queued') {
 2761:         push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
 2762:     } else {
 2763:         push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
 2764:     }
 2765:     if ($env{'user.adv'}) {
 2766:         if ($env{'form.display'} eq 'showall') {
 2767:             push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired')]);
 2768:         } else {
 2769:             push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired')]);
 2770:         }
 2771:     }
 2772:     unless ($cattype eq 'none') {
 2773:         push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
 2774:     }
 2775:     my $funcs;
 2776:     if ($env{'browser.mobile'}) {
 2777:         my @functions;
 2778:         foreach my $link (@links) {
 2779:             push(@functions,[$link->[0],$link->[2]]);
 2780:         }
 2781:         my $title = 'Display options';
 2782:         if ($env{'user.adv'}) {
 2783:             $title = 'Roles options';
 2784:         }
 2785:         $funcs = &Apache::lonmenu::create_submenu('','',$title,\@functions,1,'LC_breadcrumbs_hoverable');
 2786:         $funcs = '<ol class="LC_primary_menu LC_floatright">'.$funcs.'</ol>';
 2787:     } else {
 2788:         $funcs = &Apache::lonhtmlcommon::start_funclist();
 2789:         foreach my $link (@links) {
 2790:             $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
 2791:                           '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
 2792:                           '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
 2793:                           $link->[2].'</a>');
 2794:         }
 2795:         $funcs .= &Apache::lonhtmlcommon::end_funclist();
 2796:         $funcs = &Apache::loncommon::head_subbox($funcs);
 2797:     }
 2798:     return $funcs;
 2799: }
 2800: 
 2801: sub get_queued {
 2802:     my ($output,%reqcrs);
 2803:     my ($types,$typenames) = &Apache::loncommon::course_types();
 2804:     my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
 2805:                                            $env{'user.name'},'^status:');
 2806:     foreach my $key (keys(%statusinfo)) {
 2807:         next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
 2808:         (undef,my($cdom,$cnum)) = split(/:/,$key);
 2809:         my $requestkey = $cdom.'_'.$cnum;
 2810:         if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
 2811:             my %history = &Apache::lonnet::restore($requestkey,'courserequests',
 2812:                                                    $env{'user.domain'},$env{'user.name'});
 2813:             next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
 2814:             my $reqtime = $history{'reqtime'};
 2815:             my $lastupdate = $history{'timestamp'};
 2816:             my $showtype = $history{'crstype'};
 2817:             if (defined($typenames->{$history{'crstype'}})) {
 2818:                 $showtype = $typenames->{$history{'crstype'}};
 2819:             }
 2820:             my $description;
 2821:             if (ref($history{'details'}) eq 'HASH') {
 2822:                 $description = $history{details}{'cdescr'};
 2823:             }
 2824:             @{$reqcrs{$reqtime}} = ($description,$showtype);
 2825:         }
 2826:     }
 2827:     my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
 2828:     if (@sortedtimes > 0) {
 2829:         $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
 2830:                    &Apache::loncommon::start_data_table().
 2831:                    &Apache::loncommon::start_data_table_header_row().
 2832:                    '<th>'.&mt('Date requested').'</th>'.
 2833:                    '<th>'.&mt('Course title').'</th>'.
 2834:                    '<th>'.&mt('Course type').'</th>';
 2835:                    &Apache::loncommon::end_data_table_header_row();
 2836:         foreach my $reqtime (@sortedtimes) {
 2837:             next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
 2838:             $output .= &Apache::loncommon::start_data_table_row().
 2839:                        '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
 2840:                        '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
 2841:                        &Apache::loncommon::end_data_table_row();
 2842:         }
 2843:         $output .= &Apache::loncommon::end_data_table().
 2844:                    '<br /></p>';
 2845:     }
 2846:     my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
 2847:     if ($queuedselfenroll) {
 2848:         $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
 2849:                    $queuedselfenroll.'<br /></p>';
 2850:     }
 2851:     if ($env{'environment.canrequest.author'}) {
 2852:         unless (&Apache::loncoursequeueadmin::is_active_author()) {
 2853:             my $requestauthor;
 2854:             my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
 2855:             if (($status eq 'approval') || ($status eq 'approved')) {
 2856:                 $output .= '<p><b>'.&mt('Author role request').'</b><br />';
 2857:                 if ($status eq 'approval') {
 2858:                     $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
 2859:                                   &Apache::lonlocal::locallocaltime($timestamp));
 2860:                 } elsif ($status eq 'approved') {
 2861:                     my %roleshash =
 2862:                         &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
 2863:                                                       ['active'],['au'],[$env{'user.domain'}]);
 2864:                     if (keys(%roleshash)) {
 2865:                         $output .= '<span class="LC_info">'.
 2866:                                    &mt('Your request for an author role has been approved.').'<br />'.
 2867:                                    &mt('Use the "Check for changes" link to update your list of roles.').
 2868:                                    '</span>';
 2869:                     }
 2870:                 }
 2871:                 $output .= '</p>';
 2872:             }
 2873:         }
 2874:     }
 2875:     unless ($output) {
 2876:         if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
 2877:             $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
 2878:             $output = &mt('No requests for courses, communities or authoring currently queued');
 2879:         } else {
 2880:             $output = &mt('No enrollment requests currently queued awaiting approval');
 2881:         }
 2882:     }
 2883:     return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
 2884:            $output.'</fieldset></div><br clear="all" />';
 2885: }
 2886: 
 2887: 1;
 2888: __END__
 2889: 
 2890: =head1 NAME
 2891: 
 2892: Apache::lonroles - User Roles Screen
 2893: 
 2894: =head1 SYNOPSIS
 2895: 
 2896: Invoked by /etc/httpd/conf/srm.conf:
 2897: 
 2898:  <Location /adm/roles>
 2899:  PerlAccessHandler       Apache::lonacc
 2900:  SetHandler perl-script
 2901:  PerlHandler Apache::lonroles
 2902:  ErrorDocument     403 /adm/login
 2903:  ErrorDocument	  500 /adm/errorhandler
 2904:  </Location>
 2905: 
 2906: =head1 OVERVIEW
 2907: 
 2908: =head2 Choosing Roles
 2909: 
 2910: C<lonroles> is a handler that allows a user to switch roles in
 2911: mid-session. LON-CAPA attempts to work with "No Role Specified", the
 2912: default role that a user has before selecting a role, as widely as
 2913: possible, but certain handlers for example need specification which
 2914: course they should act on, etc. Both in this scenario, and when the
 2915: handler determines via C<lonnet>'s C<&allowed> function that a certain
 2916: action is not allowed, C<lonroles> is used as error handler. This
 2917: allows the user to select another role which may have permission to do
 2918: what they were trying to do.
 2919: 
 2920: =begin latex
 2921: 
 2922: \begin{figure}
 2923: \begin{center}
 2924: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
 2925:   \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
 2926: \end{center}
 2927: \end{figure}
 2928: 
 2929: =end latex
 2930: 
 2931: =head2 Role Initialization
 2932: 
 2933: 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.
 2934: 
 2935: =head1 INTRODUCTION
 2936: 
 2937: This module enables a user to select what role he wishes to
 2938: operate under (instructor, student, teaching assistant, course
 2939: coordinator, etc).  These roles are pre-established by the actions
 2940: of upper-level users.
 2941: 
 2942: This is part of the LearningOnline Network with CAPA project
 2943: described at http://www.lon-capa.org.
 2944: 
 2945: =head1 HANDLER SUBROUTINE
 2946: 
 2947: This routine is called by Apache and mod_perl.
 2948: 
 2949: =over 4
 2950: 
 2951: =item *
 2952: 
 2953: Roles Initialization (yes/no)
 2954: 
 2955: =item *
 2956: 
 2957: Get Error Message from Environment
 2958: 
 2959: =item *
 2960: 
 2961: Who is this?
 2962: 
 2963: =item *
 2964: 
 2965: Generate Page Output
 2966: 
 2967: =item *
 2968: 
 2969: Choice or no choice
 2970: 
 2971: =item *
 2972: 
 2973: Table
 2974: 
 2975: =item *
 2976: 
 2977: Privileges
 2978: 
 2979: =back
 2980: 
 2981: =cut

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