File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.147: download - view: text, annotated - select for diffs
Wed Apr 5 22:39:55 2006 UTC (18 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- start_page

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

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