File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.138: download - view: text, annotated - select for diffs
Thu Dec 15 23:31:22 2005 UTC (18 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_1_0, version_2_0_99_1, HEAD
DC's "Select Course" link to become a CC in a course in the domain now works for regular link in "Domain" as well as link in "Recent Roles".

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

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