File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.112: download - view: text, annotated - select for diffs
Tue Nov 23 07:29:24 2004 UTC (19 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: version_1_2_99_0, HEAD
DC selection of CC role from all courses in a particular domain modified to work when user is DC in more than one domain. No longer duplicate javascript functions in allcourses_row().

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

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