File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.140: download - view: text, annotated - select for diffs
Tue Dec 20 15:47:07 2005 UTC (18 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
typo

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

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