File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.110: download - view: text, annotated - select for diffs
Sun Nov 14 18:27:08 2004 UTC (19 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Recent roles display for DC now gathers info for CC roles not viewed this session, but in recently viewed list.  Change in db name for recent roles.  Keys n db now: user.role.cc.\$dom\$course etc.  Ready for generalization to display of recent roles for all users.

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

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