Annotation of loncom/auth/lonroles.pm, revision 1.194

1.1       harris41    1: # The LearningOnline Network with CAPA
                      2: # User Roles Screen
1.31      www         3: #
1.194   ! www         4: # $Id: lonroles.pm,v 1.193 2008/05/19 17:55:38 raeburn Exp $
1.31      www         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: #
1.32      harris41   28: ###
1.22      harris41   29: 
1.1       harris41   30: package Apache::lonroles;
                     31: 
                     32: use strict;
1.118     albertel   33: use Apache::lonnet;
1.7       www        34: use Apache::lonuserstate();
1.1       harris41   35: use Apache::Constants qw(:common);
1.2       www        36: use Apache::File();
1.26      www        37: use Apache::lonmenu;
1.29      albertel   38: use Apache::loncommon;
1.104     raeburn    39: use Apache::lonhtmlcommon;
1.57      www        40: use Apache::lonannounce;
1.72      www        41: use Apache::lonlocal;
1.151     www        42: use Apache::lonpageflip();
1.167     albertel   43: use Apache::lonnavdisplay();
1.120     albertel   44: use GDBM_File;
1.170     albertel   45: use LONCAPA qw(:DEFAULT :match);
1.149     www        46:  
1.1       harris41   47: 
1.62      matthew    48: sub redirect_user {
1.95      albertel   49:     my ($r,$title,$url,$msg,$launch_nav) = @_;
1.62      matthew    50:     $msg = $title if (! defined($msg));
1.73      www        51:     &Apache::loncommon::content_type($r,'text/html');
1.62      matthew    52:     &Apache::loncommon::no_cache($r);
                     53:     $r->send_http_header;
                     54:     my $swinfo=&Apache::lonmenu::rawconfig();
1.96      albertel   55:     my $navwindow;
1.95      albertel   56:     if ($launch_nav eq 'on') {
1.166     albertel   57: 	$navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,
                     58: 						       ($url =~ m-^/adm/whatsnew-));
1.96      albertel   59:     } else {
                     60: 	$navwindow.=&Apache::lonnavmaps::close();
1.95      albertel   61:     }
1.147     albertel   62:     my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
                     63: 						    {'redirect' => [1,$url],});
                     64:     my $end_page   = &Apache::loncommon::end_page();
                     65: 
1.92      www        66: # Note to style police: 
                     67: # This must only replace the spaces, nothing else, or it bombs elsewhere.
                     68:     $url=~s/ /\%20/g;
1.93      albertel   69:     $r->print(<<ENDREDIR);
1.147     albertel   70: $start_page
1.96      albertel   71: <script type="text/javascript">
1.62      matthew    72: $swinfo
                     73: </script>
1.96      albertel   74: $navwindow
1.62      matthew    75: <h1>$msg</h1>
1.147     albertel   76: $end_page
1.62      matthew    77: ENDREDIR
                     78:     return;
                     79: }
                     80: 
1.150     www        81: sub error_page {
                     82:     my ($r,$error,$dest)=@_;
                     83:     &Apache::loncommon::content_type($r,'text/html');
                     84:     &Apache::loncommon::no_cache($r);
                     85:     $r->send_http_header;
                     86:     return OK if $r->header_only;
                     87:     $r->print(&Apache::loncommon::start_page('Problems during Course Initialization').
                     88: 	      '<script type="text/javascript">'.
                     89: 	      &Apache::lonmenu::rawconfig().'</script>'.
                     90: 	      '<p>'.&mt('The following problems occurred:').
                     91: 	      $error.
1.156     albertel   92: 	      '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'.
1.150     www        93: 	      &Apache::loncommon::end_page());
                     94: }
                     95: 
1.1       harris41   96: sub handler {
1.10      www        97: 
1.1       harris41   98:     my $r = shift;
                     99: 
1.6       www       100:     my $now=time;
1.118     albertel  101:     my $then=$env{'user.login.time'};
1.6       www       102:     my $envkey;
1.107     raeburn   103:     my %dcroles = ();
                    104:     my $numdc = &check_fordc(\%dcroles,$then);
1.148     albertel  105:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.10      www       106: 
1.6       www       107: # ================================================================== Roles Init
1.118     albertel  108:     if ($env{'form.selectrole'}) {
1.188     www       109: 
                    110:         my $locknum=&Apache::lonnet::get_locks();
                    111:         if ($locknum) { return 409; }
                    112: 
1.134     www       113:         if ($env{'form.newrole'}) {
                    114:             $env{'form.'.$env{'form.newrole'}}=1;
                    115: 	}
1.118     albertel  116: 	if ($env{'request.course.id'}) {
1.185     raeburn   117:             # Check if user is CC trying to select a course role
                    118:             if ($env{'form.switchrole'}) {
                    119:                 if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
                    120:                     &adhoc_course_role($then);
                    121:                 }
                    122:             }
1.118     albertel  123: 	    my %temp=('logout_'.$env{'request.course.id'} => time);
1.33      www       124: 	    &Apache::lonnet::put('email_status',\%temp);
1.118     albertel  125: 	    &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
1.100     albertel  126: 	}
1.186     raeburn   127: 	&Apache::lonnet::appenv({"request.course.id"   => '',
                    128: 			 	 "request.course.fn"   => '',
                    129: 				 "request.course.uri"  => '',
                    130: 				 "request.course.sec"  => '',
                    131: 				 "request.role"        => 'cm',
                    132:                                  "request.role.adv"    => $env{'user.adv'},
                    133: 				 "request.role.domain" => $env{'user.domain'}});
1.182     www       134: # Check if user is a DC trying to enter a course or author space and needs privs to be created
1.107     raeburn   135:         if ($numdc > 0) {
1.118     albertel  136:             foreach my $envkey (keys %env) {
1.182     www       137: # Is this an ad-hoc CC-role?
1.146     raeburn   138:                 if (my ($domain,$coursenum) =
1.171     albertel  139: 		    ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {
1.146     raeburn   140:                     if ($dcroles{$domain}) {
1.182     www       141:                         &check_privs($domain,$coursenum,$then,$now,'cc');
                    142:                     }
                    143:                     last;
                    144:                 }
1.193     raeburn   145: # Is this an ad-hoc CA-role?
1.183     www       146:                 if (my ($domain,$user) =
                    147: 		    ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
1.193     raeburn   148:                    # Check if author blocked ca-access
1.190     www       149:                     my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
                    150:                     if ($blocked{'domcoord.author'} eq 'blocked') {
                    151:                        delete($env{$envkey});
                    152:                        $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
                    153:                        last;
                    154:                     }
1.193     raeburn   155:                     if ($dcroles{$domain}) {
                    156:                         my ($server_status,$home) = &check_author_homeserver($user,$domain);
                    157:                         if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
                    158:                             &check_privs($domain,$user,$then,$now,'ca');
                    159:                             if ($server_status eq 'switchserver') {
                    160:                                 my $trolecode = 'ca./'.$domain.'/'.$user; 
                    161:                                 my $switchserver = '/adm/switchserver?'
                    162:                                                   .'otherserver='.$home.'&role='.$trolecode;
                    163:                                 $r->internal_redirect($switchserver);
                    164:                             }
                    165:                         } else {
                    166:                             delete($env{$envkey});
                    167:                         }
1.183     www       168:                     } else {
                    169:                         delete($env{$envkey});
1.182     www       170:                     }
                    171:                     last;
                    172:                 }
1.107     raeburn   173:             }
                    174:         }
                    175: 
1.118     albertel  176:         foreach $envkey (keys %env) {
1.40      matthew   177:             next if ($envkey!~/^user\.role\./);
1.102     raeburn   178:             my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
                    179:             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1.118     albertel  180:             if ($env{'form.'.$trolecode}) {
1.55      albertel  181: 		if ($tstatus eq 'is') {
                    182: 		    $where=~s/^\///;
                    183: 		    my ($cdom,$cnum,$csec)=split(/\//,$where);
1.137     raeburn   184: # check for course groups
                    185:                     my %coursegroups = &Apache::lonnet::get_active_groups(
                    186:                           $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
                    187:                     my $cgrps = join(':',keys(%coursegroups));
                    188: 
1.111     albertel  189: # store role if recent_role list being kept
1.118     albertel  190:                     if ($env{'environment.recentroles'}) {
1.158     albertel  191:                         my %frozen_roles =
                    192:                            &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.111     albertel  193: 			&Apache::lonhtmlcommon::store_recent('roles',
1.158     albertel  194: 							     $trolecode,' ',$frozen_roles{$trolecode});
1.111     albertel  195:                     }
                    196: 
                    197: 
1.53      www       198: # check for keyed access
1.55      albertel  199: 		    if (($role eq 'st') && 
1.118     albertel  200:                        ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89      www       201: # who is key authority?
                    202: 			my $authdom=$cdom;
                    203: 			my $authnum=$cnum;
1.118     albertel  204: 			if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
1.89      www       205: 			    ($authnum,$authdom)=
1.172     albertel  206: 				split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
1.89      www       207: 			}
                    208: # check with key authority
                    209: 			unless (&Apache::lonnet::validate_access_key(
1.118     albertel  210: 				     $env{'environment.key.'.$cdom.'_'.$cnum},
1.89      www       211: 					     $authdom,$authnum)) {
1.53      www       212: # there is no valid key
1.118     albertel  213: 			     if ($env{'form.newkey'}) {
1.53      www       214: # student attempts to register a new key
1.89      www       215: 				 &Apache::loncommon::content_type($r,'text/html');
                    216: 				 &Apache::loncommon::no_cache($r);
                    217: 				 $r->send_http_header;
                    218: 				 my $swinfo=&Apache::lonmenu::rawconfig();
1.147     albertel  219: 				 my $start_page=&Apache::loncommon::start_page
1.89      www       220: 				    ('Verifying Access Key to Unlock this Course');
1.147     albertel  221: 				 my $end_page=&Apache::loncommon::end_page();
1.90      www       222: 				 my $buttontext=&mt('Enter Course');
                    223: 				 my $message=&mt('Successfully registered key');
                    224: 				 my $assignresult=
                    225: 				     &Apache::lonnet::assign_access_key(
1.118     albertel  226: 						     $env{'form.newkey'},
1.90      www       227: 						     $authdom,$authnum,
1.91      www       228: 						     $cdom,$cnum,
1.118     albertel  229:                                                      $env{'user.domain'},
                    230: 						     $env{'user.name'},
1.90      www       231: 	      'Assigned from '.$ENV{'REMOTE_ADDR'}.' at '.localtime().' for '.
                    232:                                                      $trolecode);
                    233: 				 unless ($assignresult eq 'ok') {
                    234: 				     $assignresult=~s/^error\:\s*//;
                    235: 				     $message=&mt($assignresult).
                    236: 				     '<br /><a href="/adm/logout">'.
1.89      www       237: 				     &mt('Logout').'</a>';
1.90      www       238: 				     $buttontext=&mt('Re-Enter Key');
                    239: 				 }
1.89      www       240: 				 $r->print(<<ENDENTEREDKEY);
1.147     albertel  241: $start_page
1.179     raeburn   242: <script type="text/javascript">
1.89      www       243: $swinfo
                    244: </script>
                    245: <form method="post">
                    246: <input type="hidden" name="selectrole" value="1" />
                    247: <input type="hidden" name="$trolecode" value="1" />
1.90      www       248: <font size="+2">$message</font><br />
1.89      www       249: <input type="submit" value="$buttontext" />
                    250: </form>
1.147     albertel  251: $end_page
1.89      www       252: ENDENTEREDKEY
                    253:                                  return OK;
1.55      albertel  254: 			     } else {
1.53      www       255: # print form to enter a new key
1.73      www       256: 				 &Apache::loncommon::content_type($r,'text/html');
1.55      albertel  257: 				 &Apache::loncommon::no_cache($r);
                    258: 				 $r->send_http_header;
                    259: 				 my $swinfo=&Apache::lonmenu::rawconfig();
1.147     albertel  260: 				 my $start_page=&Apache::loncommon::start_page
1.55      albertel  261: 				    ('Enter Access Key to Unlock this Course');
1.147     albertel  262: 				 my $end_page=&Apache::loncommon::end_page();
1.55      albertel  263: 				 $r->print(<<ENDENTERKEY);
1.147     albertel  264: $start_page
1.179     raeburn   265: <script type="text/javascript">
1.53      www       266: $swinfo
                    267: </script>
                    268: <form method="post">
1.89      www       269: <input type="hidden" name="selectrole" value="1" />
                    270: <input type="hidden" name="$trolecode" value="1" />
1.118     albertel  271: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
1.53      www       272: <input type="submit" value="Enter key" />
                    273: </form>
1.147     albertel  274: $end_page
1.53      www       275: ENDENTERKEY
1.55      albertel  276: 				 return OK;
                    277: 			     }
                    278: 			 }
                    279: 		     }
1.118     albertel  280: 		    &Apache::lonnet::log($env{'user.domain'},
                    281: 					 $env{'user.name'},
                    282: 					 $env{'user.home'},
1.87      www       283: 					 "Role ".$trolecode);
1.101     albertel  284: 		    
1.56      www       285: 		    &Apache::lonnet::appenv(
1.186     raeburn   286: 					   {'request.role'        => $trolecode,
                    287: 					    'request.role.domain' => $cdom,
                    288: 					    'request.course.sec'  => $csec,
                    289:                                             'request.course.groups' => $cgrps});
1.101     albertel  290:                     my $tadv=0;
1.62      matthew   291: 
1.125     www       292: 		    if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
1.152     raeburn   293:                         my $msg;
1.55      albertel  294: 			my ($furl,$ferr)=
                    295: 			    &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.118     albertel  296: 			if (($env{'form.orgurl'}) && 
                    297: 			    ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
                    298: 			    my $dest=$env{'form.orgurl'};
1.117     albertel  299: 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186     raeburn   300: 			    &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.150     www       301:                             if (($ferr) && ($tadv)) {
                    302: 				&error_page($r,$ferr,$dest);
                    303: 			    } else {
                    304: 				$r->internal_redirect($dest);
                    305: 			    }
1.55      albertel  306: 			    return OK;
                    307: 			} else {
1.155     albertel  308: 			    if (!$env{'request.course.id'}) {
1.55      albertel  309: 				&Apache::lonnet::appenv(
1.186     raeburn   310: 				      {"request.course.id"  => $cdom.'_'.$cnum});
1.61      www       311: 				$furl='/adm/roles?tryagain=1';
1.55      albertel  312: 				$msg=
1.157     albertel  313: 				    '<h1><span class="LC_error">'.
1.162     albertel  314: 				    &mt('Could not initialize [_1] at this time.',
                    315: 					$env{'course.'.$cdom.'_'.$cnum.'.description'}).
1.157     albertel  316: 				    '</span></h1><h3>'.&mt('Please try again.').'</h3>'.$ferr;
1.55      albertel  317: 			    }
1.117     albertel  318: 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186     raeburn   319: 			    &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.152     raeburn   320: 
1.150     www       321: 			    if (($ferr) && ($tadv)) {
                    322: 				&error_page($r,$ferr,$furl);
                    323: 			    } else {
                    324: 				# Check to see if the user is a CC entering a course 
                    325: 				# for the first time
                    326: 				my (undef, undef, $role, $courseid) = split(/\./, $envkey);
                    327: 				if (substr($courseid, 0, 1) eq '/') {
                    328: 				    $courseid = substr($courseid, 1);
                    329: 				}
                    330: 				$courseid =~ s/\//_/;
                    331: 				if ($role eq 'cc' && $env{'course.' . $courseid . 
                    332: 							      '.course.helper.not.run'}) {
                    333: 				    $furl = "/adm/helper/course.initialization.helper";
                    334: 				    # Send the user to the course they selected
                    335: 				} elsif ($env{'request.course.id'}) {
1.185     raeburn   336:                                     if ($env{'form.destinationurl'}) {
                    337:                                         my $dest = $env{'form.destinationurl'};
                    338:                                         &redirect_user($r,&mt('Entering [_1]',
                    339:                                                       $env{'course.'.$courseid.'.description'}),
                    340:                                                $dest,$msg,
                    341:                                                $env{'environment.remotenavmap'});
                    342:                                         return OK;
                    343:                                     }
1.150     www       344: 				    if (&Apache::lonnet::allowed('whn',
                    345: 								 $env{'request.course.id'})
                    346: 					|| &Apache::lonnet::allowed('whn',
                    347: 								    $env{'request.course.id'}.'/'
                    348: 								    .$env{'request.course.sec'})
                    349: 					) {
                    350: 					my $startpage = &courseloadpage($courseid);
                    351: 					unless ($startpage eq 'firstres') {         
1.162     albertel  352: 					    $msg = &mt('Entering [_1] ....',
                    353: 						       $env{'course.'.$courseid.'.description'});
1.150     www       354: 					    &redirect_user($r,&mt('New in course'),
                    355: 							   '/adm/whatsnew?refpage=start',$msg,
                    356: 							   $env{'environment.remotenavmap'});
                    357: 					    return OK;
                    358: 					}
                    359: 				    }
                    360: 				}
1.151     www       361: # Are we allowed to look at the first resource?
1.169     albertel  362: 				if ($furl !~ m|^/adm/|) {
1.151     www       363: # Guess not ...
                    364: 				    $furl=&Apache::lonpageflip::first_accessible_resource();
                    365: 				}
1.162     albertel  366:                                 $msg = &mt('Entering [_1] ...',
                    367: 					   $env{'course.'.$courseid.'.description'});
                    368: 				&redirect_user($r,&mt('Entering [_1]',
                    369: 						      $env{'course.'.$courseid.'.description'}),
1.150     www       370: 					       $furl,$msg,
                    371: 					       $env{'environment.remotenavmap'});
1.58      bowersj2  372: 			    }
1.124     albertel  373: 			    return OK;
1.55      albertel  374: 			}
                    375: 		    }
1.62      matthew   376:                     #
                    377:                     # Send the user to the construction space they selected
1.125     www       378:                     if ($role =~ /^(au|ca|aa)$/) {
1.62      matthew   379:                         my $redirect_url = '/priv/';
                    380:                         if ($role eq 'au') {
1.118     albertel  381:                             $redirect_url.=$env{'user.name'};
1.62      matthew   382:                         } else {
                    383:                             $where =~ /\/(.*)$/;
                    384:                             $redirect_url .= $1;
                    385:                         }
                    386:                         $redirect_url .= '/';
1.78      sakharuk  387:                         &redirect_user($r,&mt('Entering Construction Space'),
1.62      matthew   388:                                        $redirect_url);
                    389:                         return OK;
                    390:                     }
1.104     raeburn   391:                     if ($role eq 'dc') {
1.108     raeburn   392:                         my $redirect_url = '/adm/menu/';
                    393:                         &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104     raeburn   394:                                        $redirect_url);
1.108     raeburn   395:                         return OK;
1.104     raeburn   396:                     }
1.55      albertel  397: 		}
                    398:             }
1.6       www       399:         }
1.40      matthew   400:     }
1.44      www       401: 
1.10      www       402: 
1.6       www       403: # =============================================================== No Roles Init
1.10      www       404: 
1.73      www       405:     &Apache::loncommon::content_type($r,'text/html');
1.30      albertel  406:     &Apache::loncommon::no_cache($r);
1.10      www       407:     $r->send_http_header;
                    408:     return OK if $r->header_only;
                    409: 
1.52      www       410:     my $swinfo=&Apache::lonmenu::rawconfig();
1.147     albertel  411:     my $start_page=&Apache::loncommon::start_page('User Roles');
1.134     www       412:     my $standby=&mt('Role selected. Please stand by.');
1.135     albertel  413:     $standby=~s/\n/\\n/g;
1.184     raeburn   414:     my $noscript='<span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';
1.163     www       415: 
1.10      www       416:     $r->print(<<ENDHEADER);
1.147     albertel  417: $start_page
1.163     www       418: <br />
1.179     raeburn   419: <noscript>
                    420: $noscript
                    421: </noscript>
                    422: <script type="text/javascript">
1.26      www       423: $swinfo
                    424: window.focus();
1.134     www       425: 
                    426: active=true;
                    427: 
                    428: function enterrole (thisform,rolecode,buttonname) {
                    429:     if (active) {
                    430: 	active=false;
                    431:         document.title='$standby';
                    432:         window.status='$standby';
                    433: 	thisform.newrole.value=rolecode;
                    434: 	thisform.submit();
                    435:     } else {
                    436:        alert('$standby');
                    437:     }   
                    438: }
1.26      www       439: </script>
1.10      www       440: ENDHEADER
1.6       www       441: 
1.2       www       442: # ------------------------------------------ Get Error Message from Environment
                    443: 
1.118     albertel  444:     my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
                    445:     if ($env{'user.error.msg'}) {
1.55      albertel  446: 	$r->log_reason(
1.118     albertel  447:    "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12      www       448:     }
1.1       harris41  449: 
1.61      www       450: # ------------------------------------------------- Can this user re-init, etc?
1.6       www       451: 
1.118     albertel  452:     my $advanced=$env{'user.adv'};
1.61      www       453:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118     albertel  454:     my $tryagain=$env{'form.tryagain'};
1.6       www       455: 
1.2       www       456: # -------------------------------------------------------- Generate Page Output
1.6       www       457: # --------------------------------------------------------------- Error Header?
1.2       www       458:     if ($error) {
1.187     bisitz    459:         $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174     albertel  460: 	$r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
                    461: 	if ($priv ne '') {
1.187     bisitz    462:             $r->print(&mt('Access  : ').&Apache::lonnet::plaintext($priv)."\n");
1.174     albertel  463: 	}
                    464: 	if ($fn ne '') {
1.187     bisitz    465:             $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174     albertel  466: 	}
                    467: 	if ($msg ne '') {
1.187     bisitz    468:             $r->print(&mt('Action  : ').$msg."\n");
1.174     albertel  469: 	}
                    470: 	$r->print("</pre><hr />");
1.120     albertel  471: 	my $url=$fn;
                    472: 	my $last;
                    473: 	if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
                    474: 		&GDBM_READER(),0640)) {
                    475: 	    $last=$hash{'last_known'};
                    476: 	    untie(%hash);
                    477: 	}
1.149     www       478: 	if ($last) { $fn.='?symb='.&escape($last); }
1.120     albertel  479: 
                    480: 	&Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
                    481: 					&Apache::lonenc::check_encrypt($fn));
1.2       www       482:     } else {
1.118     albertel  483:         if ($env{'user.error.msg'}) {
1.25      www       484: 	    $r->print(
1.157     albertel  485:  '<h3><span class="LC_error">'.
                    486:  &mt('You need to choose another user role or enter a specific course for this function').'</span></h3>');
1.25      www       487: 	}
1.2       www       488:     }
1.6       www       489: # -------------------------------------------------------- Choice or no choice?
1.2       www       490:     if ($nochoose) {
1.177     www       491: 	$r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
                    492: 		  &mt('This action is currently not authorized.').'</span>'.
1.150     www       493: 		  &Apache::loncommon::end_page());
                    494: 	return OK;
1.6       www       495:     } else {
1.18      www       496:         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
                    497:     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6       www       498:         }
1.84      www       499:         $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116     albertel  500:         $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
                    501:         $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134     www       502:         $r->print('<input type="hidden" name="newrole" value="" />');
1.6       www       503:     }
1.118     albertel  504:     if ($env{'user.adv'}) {
1.63      www       505: 	$r->print(
1.177     www       506: 	      '<br /><span class="LC_rolesinfo"><label>'.&mt('Show all roles').': <input type="checkbox" name="showall"');
1.118     albertel  507: 	if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
1.177     www       508: 	$r->print(' /></label><input type="submit" value="'.&mt('Display').'" /></span>');
1.63      www       509:     }
1.4       www       510: 
1.75      albertel  511:     my (%roletext,%sortrole,%roleclass);
1.84      www       512:     my $countactive=0;
1.191     raeburn   513:     my $countfuture=0;
                    514:     my $countwill=0;
1.84      www       515:     my $inrole=0;
                    516:     my $possiblerole='';
1.191     raeburn   517:     my %futureroles;
                    518:     my %roles_nextlogin;
1.118     albertel  519:     foreach $envkey (sort keys %env) {
1.35      matthew   520:         my $button = 1;
1.49      www       521:         my $switchserver='';
1.75      albertel  522: 	my $roletext;
                    523: 	my $sortkey;
1.2       www       524:         if ($envkey=~/^user\.role\./) {
1.102     raeburn   525:             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
                    526:             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1.136     raeburn   527:             next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1.102     raeburn   528:             $tremark='';
                    529:             $tpstart='&nbsp;';
                    530:             $tpend='&nbsp;';
                    531:             $tfont='#000000';
1.4       www       532:             if ($tstart) {
1.74      www       533:                 $tpstart=&Apache::lonlocal::locallocaltime($tstart);
1.4       www       534:             }
                    535:             if ($tend) {
1.74      www       536:                 $tpend=&Apache::lonlocal::locallocaltime($tend);
1.4       www       537:             }
1.118     albertel  538:             if ($env{'request.role'} eq $trolecode) {
1.6       www       539: 		$tstatus='selected';
                    540:             }
1.4       www       541:             my $tbg;
1.164     albertel  542:             if (($tstatus eq 'is') 
                    543: 		|| ($tstatus eq 'selected') 
                    544: 		|| ($tstatus eq 'will') 
                    545: 		|| ($tstatus eq 'future') 
                    546:                 || ($env{'form.showall'})) {
1.35      matthew   547:                 if ($tstatus eq 'is') {
                    548:                     $tbg='#77FF77';
1.47      www       549:                     $tfont='#003300';
1.84      www       550: 		    $possiblerole=$trolecode;
                    551: 		    $countactive++;
1.35      matthew   552:                 } elsif ($tstatus eq 'future') {
                    553:                     $tbg='#FFFF77';
1.49      www       554:                     $button=0;
1.191     raeburn   555:                     $futureroles{$trolecode} = $tstart.':'.$tend;
                    556:                     $countfuture ++;
1.35      matthew   557:                 } elsif ($tstatus eq 'will') {
                    558:                     $tbg='#FFAA77';
1.72      www       559:                     $tremark.=&mt('Active at next login. ');
1.191     raeburn   560:                     $roles_nextlogin{$trolecode} = $tstart.':'.$tend;
                    561:                     $countwill ++;
1.35      matthew   562:                 } elsif ($tstatus eq 'expired') {
                    563:                     $tbg='#FF7777';
1.47      www       564:                     $tfont='#330000';
1.49      www       565:                     $button=0;
1.35      matthew   566:                 } elsif ($tstatus eq 'will_not') {
                    567:                     $tbg='#AAFF77';
1.72      www       568:                     $tremark.=&mt('Expired after logout. ');
1.35      matthew   569:                 } elsif ($tstatus eq 'selected') {
                    570:                     $tbg='#11CC55';
1.47      www       571:                     $tfont='#002200';
1.84      www       572: 		    $inrole=1;
1.86      albertel  573: 		    $countactive++;
1.72      www       574:                     $tremark.=&mt('Currently selected. ');
1.35      matthew   575:                 }
                    576:                 my $trole;
                    577:                 if ($role =~ /^cr\//) {
                    578:                     my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.132     albertel  579: 		    if ($tremark) { $tremark.='<br />'; }
                    580:                     $tremark.=&mt('Defined by ').$rauthor.
1.72      www       581: 			&mt(' at ').$rdomain.'.';
1.159     albertel  582: 		}
                    583: 		$trole=Apache::lonnet::plaintext($role);
1.35      matthew   584:                 my $ttype;
                    585:                 my $twhere;
                    586:                 my ($tdom,$trest,$tsection)=
                    587:                     split(/\//,Apache::lonnet::declutter($where));
                    588:                 # First, Co-Authorship roles
1.125     www       589:                 if (($role eq 'ca') || ($role eq 'aa')) {
1.39      stredwic  590:                     my $home = &Apache::lonnet::homeserver($trest,$tdom);
1.83      albertel  591: 		    my $allowed=0;
                    592: 		    my @ids=&Apache::lonnet::current_machine_ids();
                    593: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    594:                     if (!$allowed) {
1.49      www       595: 			$button=0;
1.130     albertel  596:                         $switchserver='otherserver='.$home.'&role='.$trolecode;
1.49      www       597:                     }
1.35      matthew   598:                     #next if ($home eq 'no_host');
1.176     albertel  599:                     $home = &Apache::lonnet::hostname($home);
1.78      sakharuk  600:                     $ttype='Construction Space';
1.72      www       601:                     $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
                    602: 			': '.$tdom.'<br />'.
                    603:                         ' '.&mt('Server').':&nbsp;'.$home;
1.118     albertel  604:                     $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82      www       605: 		    $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1.75      albertel  606: 		    $sortkey=$role."$trest:$tdom";
1.35      matthew   607:                 } elsif ($role eq 'au') {
                    608:                     # Authors
                    609:                     my $home = &Apache::lonnet::homeserver
1.118     albertel  610:                         ($env{'user.name'},$env{'user.domain'});
1.83      albertel  611: 		    my $allowed=0;
                    612: 		    my @ids=&Apache::lonnet::current_machine_ids();
                    613: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    614:                     if (!$allowed) {
1.49      www       615: 			$button=0;
1.143     albertel  616:                         $switchserver='otherserver='.$home.'&role='.$trolecode;
1.49      www       617:                     }
1.35      matthew   618:                     #next if ($home eq 'no_host');
1.176     albertel  619:                     $home = &Apache::lonnet::hostname($home);
1.78      sakharuk  620:                     $ttype='Construction Space';
1.72      www       621:                     $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
                    622: 			':&nbsp;'.$home;
1.118     albertel  623:                     $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
                    624: 		    $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1.75      albertel  625: 		    $sortkey=$role;
1.35      matthew   626:                 } elsif ($trest) {
                    627:                     my $tcourseid=$tdom.'_'.$trest;
1.153     raeburn   628:                     $ttype = &Apache::loncommon::course_type($tcourseid);
                    629:                     $trole = &Apache::lonnet::plaintext($role,$ttype);
1.118     albertel  630:                     if ($env{'course.'.$tcourseid.'.description'}) {
                    631:                         $twhere=$env{'course.'.$tcourseid.'.description'};
1.80      albertel  632: 			$sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.72      www       633:                         unless ($twhere eq &mt('Currently not available')) {
1.55      albertel  634: 			    $twhere.=' <font size="-2">'.
1.72      www       635:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49      www       636:                                     '</font>';
1.55      albertel  637: 			}
1.8       www       638:                     } else {
1.105     raeburn   639:                         my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1.35      matthew   640:                         if (%newhash) {
1.80      albertel  641: 			    $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1.77      albertel  642: 				"\0".$envkey;
1.49      www       643:                             $twhere=$newhash{'description'}.
                    644:                               ' <font size="-2">'.
1.72      www       645:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49      www       646:                               '</font>';
1.152     raeburn   647:                             $ttype = $newhash{'type'};
1.153     raeburn   648:                             $trole = &Apache::lonnet::plaintext($role,$ttype);
1.35      matthew   649:                         } else {
1.72      www       650:                             $twhere=&mt('Currently not available');
1.118     albertel  651:                             $env{'course.'.$tcourseid.'.description'}=$twhere;
1.80      albertel  652: 			    $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.152     raeburn   653:                             $ttype = 'Unavailable';
1.35      matthew   654:                         }
1.8       www       655:                     }
1.121     albertel  656:                     if ($tsection) {
1.175     albertel  657:                         $twhere.='<br />'.&mt('Section').': '.$tsection;
1.121     albertel  658: 		    }
1.72      www       659: 		    if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1.35      matthew   660:                 } elsif ($tdom) {
1.78      sakharuk  661:                     $ttype='Domain';
1.35      matthew   662:                     $twhere=$tdom;
1.75      albertel  663: 		    $sortkey=$role.$twhere;
1.35      matthew   664:                 } else {
1.78      sakharuk  665:                     $ttype='System';
1.72      www       666:                     $twhere=&mt('system wide');
1.75      albertel  667: 		    $sortkey=$role.$twhere;
1.13      www       668:                 }
1.152     raeburn   669:                 $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);
1.75      albertel  670: 		$roletext{$envkey}=$roletext;
                    671: 		if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
                    672: 		$sortrole{$sortkey}=$envkey;
                    673: 		$roleclass{$envkey}=$ttype;
1.55      albertel  674: 	    }
1.4       www       675:         }
1.75      albertel  676:     }
1.84      www       677: # No active roles
                    678:     if ($countactive==0) {
                    679: 	if ($inrole) {
                    680: 	    $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
                    681: 	} else {
                    682: 	    $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
                    683: 	}
1.191     raeburn   684:         &findcourse_advice($r);
                    685: 	$r->print('</form>');
                    686:         if ($countfuture) {
                    687:             $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
                    688:             my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
                    689:                                                $nochoose);
                    690:             &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
                    691:                             \%roletext);
                    692:             my $tremark='';
                    693:             my $tfont='#003300';
                    694:             if ($env{'request.role'} eq 'cm') {
                    695:                 $r->print('<tr bgcolor="#11CC55">');
                    696:                 $tremark=&mt('Currently selected. ');
                    697:                 $tfont='#002200';
                    698:             } else {
                    699:                 $r->print('<tr bgcolor="#77FF77">');
                    700:             }
                    701:             $r->print('<td></td><td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
1.192     raeburn   702:                       '</span></font></td><td><font color="'.$tfont.'">'.$tremark.
1.191     raeburn   703:                       '&nbsp;</font></td></tr>'."\n");
                    704: 
                    705:             $r->print('</table>');
                    706:         }
                    707:         $r->print(&Apache::loncommon::end_page());
1.84      www       708: 	return OK;
                    709: # Is there only one choice?
1.118     albertel  710:     } elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) {
1.84      www       711: 	$r->print('<h3>'.&mt('Please stand by.').'</h3>'.
1.179     raeburn   712: 	    '<input type="hidden" name="'.$possiblerole.'" value="1" />'.
                    713:             '<noscript><br /><input type="submit" name="submit" value="'.&mt('Continue').'" /></noscript>');
1.84      www       714: 	$r->print("</form>\n");
                    715: 	$r->rflush();
1.179     raeburn   716: 	$r->print('<script type="text/javascript">document.forms.rolechoice.submit();</script>');
1.147     albertel  717: 	$r->print(&Apache::loncommon::end_page());
1.84      www       718: 	return OK;
                    719:     }
                    720: # More than one possible role
                    721: # ----------------------------------------------------------------------- Table
1.181     albertel  722:     unless ((!&Apache::lonmenu::show_course()) || ($nochoose)) {
1.173     albertel  723: 	$r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84      www       724:     }
1.191     raeburn   725:     my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118     albertel  726:     if ($env{'environment.recentroles'}) {
1.111     albertel  727:         my %recent_roles =
1.118     albertel  728:                &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111     albertel  729: 	my $output='';
                    730: 	foreach (sort(keys(%recent_roles))) {
                    731: 	    if (defined($roletext{'user.role.'.$_})) {
                    732: 		$output.=$roletext{'user.role.'.$_};
1.170     albertel  733:                 if ($_ =~ m-dc\./($match_domain)/- 
                    734: 		    && $dcroles{$1}) {
1.192     raeburn   735: 		    $output .= &adhoc_roles_row($1,'recent');
1.133     albertel  736:                 }
1.113     raeburn   737: 	    } elsif ($numdc > 0) {
                    738:                 unless ($_ =~/^error\:/) {
                    739:                     $output.=&display_cc_role('user.role.'.$_);
                    740:                 }
                    741:             } 
1.111     albertel  742: 	}
                    743: 	if ($output) {
1.132     albertel  744: 	    $r->print("<tr><td align='center' colspan='5'><font face='arial'>".
1.192     raeburn   745: 		      &mt('Recent Roles')."</font></td></tr>");
1.111     albertel  746: 	    $r->print($output);
1.114     raeburn   747:             $doheaders ++;
1.111     albertel  748: 	}
                    749:     }
                    750: 
1.104     raeburn   751:     if ($numdc > 0) {
1.112     raeburn   752:         $r->print(&coursepick_jscript());
1.193     raeburn   753:         $r->print(&Apache::loncommon::coursebrowser_javascript().
                    754:                   &Apache::loncommon::authorbrowser_javascript());
1.108     raeburn   755:     }
1.191     raeburn   756:     &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.14      www       757:     my $tremark='';
1.47      www       758:     my $tfont='#003300';
1.118     albertel  759:     if ($env{'request.role'} eq 'cm') {
1.19      www       760: 	$r->print('<tr bgcolor="#11CC55">');
1.72      www       761:         $tremark=&mt('Currently selected. ');
1.47      www       762:         $tfont='#002200';
1.14      www       763:     } else {
                    764:         $r->print('<tr bgcolor="#77FF77">');
                    765:     }
                    766:     unless ($nochoose) {
1.118     albertel  767: 	if ($env{'request.role'} ne 'cm') {
1.134     www       768: 	    $r->print('<td><input type="submit" value="'.
1.192     raeburn   769: 		      &mt('Select').'" name="cm" /></td>');
1.55      albertel  770: 	} else {
                    771: 	    $r->print('<td>&nbsp;</td>');
                    772: 	}
1.14      www       773:     }
1.177     www       774:     $r->print('<td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
1.192     raeburn   775:       '</span></font></td><td><font color="'.$tfont.'">'.$tremark.
1.47      www       776:       '&nbsp;</font></td></tr>'."\n");
1.4       www       777: 
                    778:     $r->print('</table>');
                    779:     unless ($nochoose) {
                    780: 	$r->print("</form>\n");
                    781:     }
1.22      harris41  782: # ------------------------------------------------------------ Privileges Info
1.118     albertel  783:     if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.127     albertel  784: 	$r->print('<hr /><h2>Current Privileges</h2>');
1.175     albertel  785: 	$r->print(&privileges_info());
1.4       www       786:     }
1.66      www       787:     $r->print(&Apache::lonnet::getannounce());
1.65      www       788:     if ($advanced) {
                    789: 	$r->print('<p><small><i>This is LON-CAPA '.
1.85      www       790: 		  $r->dir_config('lonVersion').'</i><br />'.
                    791: 		  '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
1.65      www       792:     }
1.147     albertel  793:     $r->print(&Apache::loncommon::end_page());
1.1       harris41  794:     return OK;
1.102     raeburn   795: }
                    796: 
1.191     raeburn   797: sub roletable_headers {
                    798:     my ($r,$roleclass,$sortrole,$nochoose) = @_;
                    799:     my $doheaders;
                    800:     if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
                    801:         $r->print('<br /><table id="LC_rolesmenu"><tr>');
                    802:         if (!$nochoose) { $r->print('<th>&nbsp;</th>'); }
                    803:         $r->print('<th>'.&mt('User Role').'</th><th>'.&mt('Extent')
                    804:                   .'</th><th>'.&mt('Start').'</th><th>'.&mt('End')
                    805:                   .'</th></tr>'."\n");
                    806:         $doheaders=-1;
                    807:         my @roletypes = &roletypes();
                    808:         foreach my $type (@roletypes) {
                    809:             my $haverole=0;
                    810:             foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
                    811:                 if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
                    812:                     $haverole=1;
                    813:                 }
                    814:             }
                    815:             if ($haverole) { $doheaders++; }
                    816:         }
                    817:     }
                    818:     return $doheaders;
                    819: }
                    820: 
                    821: sub roletypes {
                    822:     my @types = ('Domain','Construction Space','Course','Unavailable','System');
                    823:     return @types; 
                    824: }
                    825: 
                    826: sub print_rolerows {
                    827:     my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
                    828:     if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
                    829:         my @types = &roletypes();
                    830:         foreach my $type (@types) {
                    831:             my $output;
                    832:             foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
                    833:                 if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
                    834:                     if (ref($roletext) eq 'HASH') {
                    835:                         $output.=$roletext->{$sortrole->{$which}};
                    836:                         if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
                    837:                             if (ref($dcroles) eq 'HASH') {
                    838:                                 if ($dcroles->{$1}) {
1.192     raeburn   839:                                     $output .= &adhoc_roles_row($1,'');
1.191     raeburn   840:                                 }
                    841:                             }
                    842:                         }
                    843:                     }
                    844:                 }
                    845:             }
                    846:             if ($output) {
                    847:                 if ($doheaders > 0) {
                    848:                     $r->print("<tr>".
                    849:                               "<td align='center' colspan='5'><font face='arial'>".
                    850:                               &mt($type)."</font></td></tr>");
                    851:                 }
                    852:                 $r->print($output);
                    853:             }
                    854:         }
                    855:     }
                    856: }
                    857: 
                    858: sub findcourse_advice {
                    859:     my ($r) = @_;
                    860:     my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
                    861:     if (&check_autoenroll($env{'user.domain'})) {
                    862:         $r->print(&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).'
                    863: <ul>
                    864:  <li>'.&mt('The course has yet to be created.').'</li>
                    865:  <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
                    866:  <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
                    867:  <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
                    868:  <li>'.&mt('You registered for the course recently and there is a time lag between the time you register, and the time this information becomes available for the update of LON-CAPA course rosters.').'</li>
                    869:  </ul>');
                    870:     } else {
                    871:         $r->print(&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'<br />');
                    872:     }
                    873:     $r->print('<p>'.&mt('The [_1]Course Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created.','<a href="/adm/coursecatalog">','</a>',$domdesc).'<br />');
                    874:     $r->print(&mt('You can search the course catalog for courses which permit self-enrollment, if you would like to enroll in a course.').'</p>');
                    875:     return;
                    876: }
                    877: 
1.175     albertel  878: sub privileges_info {
                    879:     my ($which) = @_;
                    880:     my $output;
                    881: 
                    882:     $which ||= $env{'request.role'};
                    883: 
                    884:     foreach my $envkey (sort(keys(%env))) {
                    885: 	next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
                    886: 
                    887: 	my $where=$1;
                    888: 	my $ttype;
                    889: 	my $twhere;
                    890: 	my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
                    891: 	if ($trest) {
                    892: 	    if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
                    893: 		$ttype='Construction Space';
                    894: 		$twhere='User: '.$trest.', Domain: '.$tdom;
                    895: 	    } else {
                    896: 		$ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
                    897: 		$twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
                    898: 		if ($tsec) {
                    899: 		    my $sec_type = 'Section';
                    900: 		    if (exists($env{"user.role.gr.$where"})) {
                    901: 			$sec_type = 'Group';
                    902: 		    }
                    903: 		    $twhere.=' ('.$sec_type.': '.$tsec.')';
                    904: 		}
                    905: 	    }
                    906: 	} elsif ($tdom) {
                    907: 	    $ttype='Domain';
                    908: 	    $twhere=$tdom;
                    909: 	} else {
                    910: 	    $ttype='System';
                    911: 	    $twhere='/';
                    912: 	}
                    913: 	$output .= "\n<h3>".$ttype.': '.$twhere.'</h3>'."\n<ul>";
                    914: 	foreach my $priv (sort(split(/:/,$env{$envkey}))) {
                    915: 	    next if (!$priv);
                    916: 
                    917: 	    my ($prv,$restr)=split(/\&/,$priv);
                    918: 	    my $trestr='';
                    919: 	    if ($restr ne 'F') {
                    920: 		$trestr.=' ('.
                    921: 		    join(', ',
                    922: 			 map { &Apache::lonnet::plaintext($_) } 
                    923: 			     (split('',$restr))).') ';
                    924: 	    }
                    925: 	    $output .= "\n\t".
                    926: 		'<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
                    927: 	}
                    928: 	$output .= "\n".'</ul>';
                    929:     }
                    930:     return $output;
                    931: }
                    932: 
1.102     raeburn   933: sub role_status {
                    934:     my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
                    935:     my @pwhere = ();
1.118     albertel  936:     if (exists($env{$rolekey}) && $env{$rolekey} ne '') {
1.102     raeburn   937:         (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
                    938:         unless (!defined($$role) || $$role eq '') {
                    939:             $$where=join('.',@pwhere);
                    940:             $$trolecode=$$role.'.'.$$where;
1.118     albertel  941:             ($$tstart,$$tend)=split(/\./,$env{$rolekey});
1.102     raeburn   942:             $$tstatus='is';
1.105     raeburn   943:             if ($$tstart && $$tstart>$then) {
                    944: 		$$tstatus='future';
                    945: 		if ($$tstart<$now) { $$tstatus='will'; }
1.102     raeburn   946:             }
                    947:             if ($$tend) {
                    948:                 if ($$tend<$then) {
                    949:                     $$tstatus='expired';
1.103     raeburn   950:                 } elsif ($$tend<$now) {
1.104     raeburn   951:                     $$tstatus='will_not';
1.102     raeburn   952:                 }
                    953:             }
                    954:         }
                    955:     }
                    956: }
1.1       harris41  957: 
1.110     raeburn   958: sub build_roletext {
1.152     raeburn   959:     my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
1.177     www       960:     my $roletext='<tr bgcolor="'.$tbg.'" class="LC_rolesmenu_'.$tstatus.'">';
1.132     albertel  961:     my $is_dc=($trolecode =~ m/^dc\./);
                    962:     my $rowspan=($is_dc) ? ''
                    963:                          : ' rowspan="2" ';
                    964: 
1.110     raeburn   965:     unless ($nochoose) {
1.134     www       966:         my $buttonname=$trolecode;
                    967:         $buttonname=~s/\W//g;
1.110     raeburn   968:         if (!$button) {
                    969:             if ($switchserver) {
1.177     www       970:                 $roletext.='<td'.$rowspan.'><span class="LC_rolesinfo"><a href="/adm/switchserver?'.
                    971:                 $switchserver.'">'.&mt('Switch Server').'</a></span></td>';
1.110     raeburn   972:             } else {
1.164     albertel  973:                 $roletext.=('<td'.$rowspan.'>&nbsp;</td>');
1.110     raeburn   974:             }
                    975:         } elsif ($tstatus eq 'is') {
1.134     www       976:             $roletext.='<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
                    977:                         &mt('Select').'" onClick="javascript:enterrole(this.form,\''.
1.192     raeburn   978:                         $trolecode."','".$buttonname.'\');" /></td>';
1.110     raeburn   979:         } elsif ($tryagain) {
                    980:             $roletext.=
1.134     www       981:                 '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
                    982:                 &mt('Try Selecting Again').'" onClick="javascript:enterrole(this.form,\''.
1.192     raeburn   983:                         $trolecode."','".$buttonname.'\');" /></td>';
1.110     raeburn   984:         } elsif ($advanced) {
                    985:             $roletext.=
1.134     www       986:                 '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
                    987:                 &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
1.192     raeburn   988:                         $trolecode."','".$buttonname.'\');" /></td>';
1.110     raeburn   989:         } else {
1.132     albertel  990:             $roletext.='<td'.$rowspan.'>&nbsp;</td>';
1.110     raeburn   991:         }
                    992:     }
1.165     albertel  993:     if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
                    994: 	$tremark.=&Apache::lonannounce::showday(time,1,
                    995: 			 &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
                    996:     }
1.110     raeburn   997:     $roletext.='<td><font color="'.$tfont.'">'.$trole.
1.121     albertel  998: 	       '</font></td><td><font color="'.$tfont.'">'.$twhere.
1.110     raeburn   999:                '</font></td><td><font color="'.$tfont.'">'.$tpstart.
                   1000:                '</font></td><td><font color="'.$tfont.'">'.$tpend.
1.132     albertel 1001:                '</font></td></tr>';
                   1002:     if (!$is_dc) {
1.177     www      1003: 	$roletext.='<tr bgcolor="'.$tbg.'"><td colspan="4"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.$tremark.
                   1004: 	    '</span>&nbsp;</font></td></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
1.132     albertel 1005:     }
1.110     raeburn  1006:     return $roletext;
                   1007: }
                   1008: 
1.193     raeburn  1009: sub check_author_homeserver {
1.183     www      1010:     my ($uname,$udom)=@_;
1.193     raeburn  1011:     if (($uname eq '') || ($udom eq '')) {
                   1012:         return ('fail','');
                   1013:     }
1.183     www      1014:     my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193     raeburn  1015:     if (&Apache::lonnet::host_domain($home) ne $udom) {
                   1016:         return ('fail',$home);
                   1017:     }
1.183     www      1018:     my @ids=&Apache::lonnet::current_machine_ids();
1.193     raeburn  1019:     if (grep(/^\Q$home\E$/,@ids)) {
                   1020:         return ('ok',$home);
                   1021:     } else {
                   1022:         return ('switchserver',$home);
1.183     www      1023:     }
                   1024: }
                   1025: 
1.110     raeburn  1026: sub check_privs {
1.182     www      1027:     my ($cdom,$cnum,$then,$now,$checkrole) = @_;
                   1028:     my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum; 
1.118     albertel 1029:     if ($env{$cckey}) {
1.110     raeburn  1030:         my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
                   1031:         &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
                   1032:         unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
1.182     www      1033:             &set_privileges($cdom,$cnum,$checkrole);
1.110     raeburn  1034:         }
                   1035:     } else {
1.182     www      1036:         &set_privileges($cdom,$cnum,$checkrole);
1.110     raeburn  1037:     }
                   1038: }
                   1039: 
1.104     raeburn  1040: sub check_fordc {
                   1041:     my ($dcroles,$then) = @_;
                   1042:     my $numdc = 0;
1.118     albertel 1043:     if ($env{'user.adv'}) {
                   1044:         foreach my $envkey (sort keys %env) {
1.170     albertel 1045:             if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104     raeburn  1046:                 my $dcdom = $1;
                   1047:                 my $livedc = 1;
1.118     albertel 1048:                 my ($tstart,$tend)=split(/\./,$env{$envkey});
1.105     raeburn  1049:                 if ($tstart && $tstart>$then) { $livedc = 0; }
                   1050:                 if ($tend   && $tend  <$then) { $livedc = 0; }
1.104     raeburn  1051:                 if ($livedc) {
                   1052:                     $$dcroles{$dcdom} = $envkey;
1.105     raeburn  1053:                     $numdc++;
1.104     raeburn  1054:                 }
                   1055:             }
                   1056:         }
                   1057:     }
                   1058:     return $numdc;
                   1059: }
                   1060: 
1.185     raeburn  1061: sub adhoc_course_role {
                   1062:     my ($then) = @_; 
                   1063:     my ($cdom,$cnum);
                   1064:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1065:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1066:     if (&check_forcc($cdom,$cnum,$then)) {
                   1067:         my $setprivs;
                   1068:         if (!defined($env{'user.role.'.$env{'form.selectrole'}})) {
                   1069:             $setprivs = 1;
                   1070:         } else {
                   1071:             my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.selectrole'}});
                   1072:             if (($start && ($start>$then || $start == -1)) ||
                   1073:                 ($end && $end<$then)) {
                   1074:                 $setprivs = 1;
                   1075:             }
                   1076:         } 
                   1077:         if ($setprivs) {
                   1078:             if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E(/?\w*)$-) {
                   1079:                 my $role = $1;
                   1080:                 my $custom_role = $2;
                   1081:                 my $usec = $3;
                   1082:                 if ($role eq 'cr') {
                   1083:                     if ($custom_role =~ m-^$match_domain/$match_courseid/\w+$-) {
                   1084:                         $role .= $custom_role;
                   1085:                     } else {
                   1086:                         return;
                   1087:                     }
                   1088:                 }
                   1089:                 my (%userroles,%newrole,%newgroups);
                   1090:                 my $area = '/'.$cdom.'/'.$cnum;
                   1091:                 my $spec = $role.'.'.$area;
                   1092:                 if ($usec ne '') {
                   1093:                     $spec .= '/'.$usec;
                   1094:                     $area .= '/'.$usec;
                   1095:                 }
                   1096:                 &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
                   1097:                 &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups);
                   1098:                 my $adhocstart = $then-1;
                   1099:                 $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186     raeburn  1100:                 &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185     raeburn  1101:             }
                   1102:         }
                   1103:     }
                   1104:     return;
                   1105: }
                   1106: 
                   1107: sub check_forcc {
                   1108:     my ($cdom,$cnum,$then) = @_;
                   1109:     my $is_cc;
                   1110:     if ($cdom ne '' && $cnum ne '') {
                   1111:         if (&Apache::lonnet::is_course($cdom,$cnum)) {
                   1112:             my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;
                   1113:             if (defined($env{$envkey})) {
                   1114:                 $is_cc = 1;
                   1115:                 my ($tstart,$tend)=split(/\./,$env{$envkey});
                   1116:                 if ($tstart && $tstart>$then) { $is_cc = 0; }
                   1117:                 if ($tend   && $tend  <$then) { $is_cc = 0; }
                   1118:             }
                   1119:         }
                   1120:     }
                   1121:     return $is_cc;
                   1122: }
                   1123: 
1.108     raeburn  1124: sub courselink {
1.193     raeburn  1125:     my ($dcdom,$rowtype) = @_;
1.109     raeburn  1126:     my $courseform=&Apache::loncommon::selectcourse_link
1.152     raeburn  1127:                    ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
                   1128:                     'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.173     albertel 1129:                     $dcdom,$dcdom,undef);
1.138     raeburn  1130:     my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
                   1131:                       '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
                   1132:                       '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
                   1133:                       '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112     raeburn  1134:     return $courseform.$hiddenitems;
1.109     raeburn  1135: }
                   1136: 
                   1137: sub coursepick_jscript {
1.184     raeburn  1138:     my %lt = &Apache::lonlocal::texthash(
                   1139:                   plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.",
                   1140:                   youc => 'You can only use this screen to select courses in the current domain.',
                   1141:              );
1.104     raeburn  1142:     my $verify_script = <<"END";
1.179     raeburn  1143: <script type="text/javascript">
1.108     raeburn  1144: function verifyCoursePick(caller) {
                   1145:     var numbutton = getIndex(caller)
1.112     raeburn  1146:     var pickedCourse = document.rolechoice.elements[numbutton+4].value
                   1147:     var pickedDomain = document.rolechoice.elements[numbutton+2].value
                   1148:     if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104     raeburn  1149:         if (pickedCourse != '') {
1.108     raeburn  1150:             if (numbutton != -1) {
                   1151:                 var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
                   1152:                 document.rolechoice.elements[numbutton+1].name = courseTarget
                   1153:                 document.rolechoice.submit()
                   1154:             }
1.104     raeburn  1155:         }
                   1156:         else {
1.184     raeburn  1157:             alert("$lt{'plsu'}");
1.104     raeburn  1158:         }
                   1159:     }
                   1160:     else {
1.184     raeburn  1161:         alert("$lt{'youc'}")
1.104     raeburn  1162:     }
                   1163: }
1.109     raeburn  1164: function getIndex(caller) {
1.108     raeburn  1165:     for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109     raeburn  1166:         if (document.rolechoice.elements[i] == caller) {
1.108     raeburn  1167:             return i;
                   1168:         }
                   1169:     }
                   1170:     return -1;
                   1171: }
1.104     raeburn  1172: </script>
                   1173: END
1.109     raeburn  1174:     return $verify_script;
1.104     raeburn  1175: }
                   1176: 
1.193     raeburn  1177: sub coauthorlink {
                   1178:     my ($dcdom,$rowtype) = @_;
                   1179:     my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
                   1180:     my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
                   1181:     return $coauthorform.$hiddenitems;
                   1182: }
                   1183: 
1.113     raeburn  1184: sub display_cc_role {
                   1185:     my $rolekey = shift;
                   1186:     my $roletext;
1.118     albertel 1187:     my $advanced = $env{'user.adv'};
                   1188:     my $tryagain = $env{'form.tryagain'};
1.113     raeburn  1189:     unless ($rolekey =~/^error\:/) {
1.171     albertel 1190:         if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {
1.113     raeburn  1191:             my $tcourseid = $1.'_'.$2;
                   1192:             my $trolecode = 'cc./'.$1.'/'.$2;
                   1193:             my $twhere;
1.152     raeburn  1194:             my $ttype;
1.113     raeburn  1195:             my $tbg='#77FF77';
                   1196:             my $tfont='#003300';
                   1197:             my %newhash=&Apache::lonnet::coursedescription($tcourseid);
                   1198:             if (%newhash) {
                   1199:                 $twhere=$newhash{'description'}.
                   1200:                         ' <font size="-2">'.
                   1201:                         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).
                   1202:                         '</font>';
1.153     raeburn  1203:                 $ttype = $newhash{'type'};
1.113     raeburn  1204:             } else {
                   1205:                 $twhere=&mt('Currently not available');
1.118     albertel 1206:                 $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110     raeburn  1207:             }
1.153     raeburn  1208:             my $trole = &Apache::lonnet::plaintext('cc',$ttype);
1.113     raeburn  1209:             $twhere.="<br />".&mt('Domain').":".$1;
1.152     raeburn  1210:             $roletext = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$tfont,$trole,$twhere,'','','',1,'');
1.104     raeburn  1211:         }
                   1212:     }
1.152     raeburn  1213:     return ($roletext);
1.104     raeburn  1214: }
                   1215: 
1.192     raeburn  1216: sub adhoc_roles_row {
1.138     raeburn  1217:     my ($dcdom,$rowtype) = @_;
1.132     albertel 1218:     my $output = '<tr bgcolor="#77FF77">'.
1.192     raeburn  1219:                  ' <td colspan="5"><table><tr><td><span class="LC_rolesinfo">'
                   1220:                  .&mt('[_1]Ad hoc[_2] roles in domain [_3] --',
                   1221:                  '<span class="LC_cusr_emph">','</span>',$dcdom).'</span></td><td>';
1.193     raeburn  1222:     my $selectcclink = &courselink($dcdom,$rowtype);
1.173     albertel 1223:     my $ccrole = &Apache::lonnet::plaintext('cc');
1.182     www      1224:     my $carole = &Apache::lonnet::plaintext('ca');
1.193     raeburn  1225:     my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.182     www      1226:     $output.= '<span class="LC_rolesinfo">'.
1.193     raeburn  1227:             &mt('[_1]: [_2]',$ccrole,$selectcclink).
1.192     raeburn  1228:             '</span><br /></td><td>&nbsp;&nbsp;</td><td><span class="LC_rolesinfo">'.
1.193     raeburn  1229:             &mt('[_1]: [_2]',$carole,$selectcalink).
1.192     raeburn  1230:             '</span><br /></td></tr></table></td></tr>'.
                   1231:             '<tr><td colspan="5" height="3"></td></tr>'."\n";
1.108     raeburn  1232:     return $output;
                   1233: }
                   1234: 
1.104     raeburn  1235: sub recent_filename {
                   1236:     my $area=shift;
1.149     www      1237:     return 'nohist_recent_'.&escape($area);
1.104     raeburn  1238: }
                   1239: 
1.106     raeburn  1240: sub set_privileges {
1.182     www      1241: # role can be cc or ca
                   1242:     my ($dcdom,$pickedcourse,$role) = @_;
1.106     raeburn  1243:     my $area = '/'.$dcdom.'/'.$pickedcourse;
                   1244:     my $spec = $role.'.'.$area;
1.168     albertel 1245:     my %userroles = &Apache::lonnet::set_arearole($role,$area,'','',
                   1246: 						  $env{'user.domain'},
                   1247: 						  $env{'user.name'});
1.106     raeburn  1248:     my %ccrole = ();
                   1249:     &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
1.154     albertel 1250:     my ($author,$adv)= &Apache::lonnet::set_userprivs(\%userroles,\%ccrole);
1.186     raeburn  1251:     &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.184     raeburn  1252: 
1.118     albertel 1253:     &Apache::lonnet::log($env{'user.domain'},
                   1254:                          $env{'user.name'},
                   1255:                          $env{'user.home'},
1.106     raeburn  1256:                         "Role ".$role);
                   1257:     &Apache::lonnet::appenv(
1.186     raeburn  1258:                           {'request.role'        => $spec,
1.106     raeburn  1259:                           'request.role.domain' => $dcdom,
1.186     raeburn  1260:                           'request.course.sec'  => ''});
1.106     raeburn  1261:     my $tadv=0;
                   1262:     if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186     raeburn  1263:     &Apache::lonnet::appenv({'request.role.adv'    => $tadv});
1.106     raeburn  1264: }
                   1265: 
1.139     raeburn  1266: sub courseloadpage {
                   1267:     my ($courseid) = @_;
                   1268:     my $startpage;
1.144     albertel 1269:     my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
                   1270: 					      [$courseid.':courseinit']);
1.139     raeburn  1271:     my ($tmp) = %entry_settings;
1.144     albertel 1272:     unless ($tmp =~ /^error: 2 /) {
1.139     raeburn  1273:         $startpage = $entry_settings{$courseid.':courseinit'};
                   1274:     }
                   1275:     if ($startpage eq '') {
                   1276:         if (exists($env{'environment.course_init_display'})) {
                   1277:             $startpage = $env{'environment.course_init_display'};
                   1278:         }
                   1279:     }
                   1280:     return $startpage;
                   1281: }
                   1282: 
1.191     raeburn  1283: sub check_autoenroll {
                   1284:     my ($dom) = @_;
                   1285:     my $run_enroll = 0;
                   1286:     my $settings;
                   1287:     my %domconfig =
                   1288:         &Apache::lonnet::get_dom('configuration',['autoenroll'],$dom);
                   1289:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   1290:         $settings = $domconfig{'autoenroll'};
                   1291:         if ($settings->{'run'} eq '1') {
                   1292:             $run_enroll = 1;
                   1293:         }
                   1294:     } else {
                   1295:         $run_enroll = &localenroll::run($dom);
                   1296:     }
                   1297:     return $run_enroll;
                   1298: }
                   1299: 
                   1300: 
1.1       harris41 1301: 1;
                   1302: __END__
1.32      harris41 1303: 
                   1304: =head1 NAME
                   1305: 
                   1306: Apache::lonroles - User Roles Screen
                   1307: 
                   1308: =head1 SYNOPSIS
                   1309: 
                   1310: Invoked by /etc/httpd/conf/srm.conf:
                   1311: 
                   1312:  <Location /adm/roles>
                   1313:  PerlAccessHandler       Apache::lonacc
                   1314:  SetHandler perl-script
                   1315:  PerlHandler Apache::lonroles
                   1316:  ErrorDocument     403 /adm/login
                   1317:  ErrorDocument	  500 /adm/errorhandler
                   1318:  </Location>
1.64      bowersj2 1319: 
                   1320: =head1 OVERVIEW
                   1321: 
                   1322: =head2 Choosing Roles
                   1323: 
                   1324: C<lonroles> is a handler that allows a user to switch roles in
                   1325: mid-session. LON-CAPA attempts to work with "No Role Specified", the
                   1326: default role that a user has before selecting a role, as widely as
                   1327: possible, but certain handlers for example need specification which
                   1328: course they should act on, etc. Both in this scenario, and when the
                   1329: handler determines via C<lonnet>'s C<&allowed> function that a certain
                   1330: action is not allowed, C<lonroles> is used as error handler. This
                   1331: allows the user to select another role which may have permission to do
                   1332: what they were trying to do. C<lonroles> can also be accessed via the
                   1333: B<CRS> button in the Remote Control. 
                   1334: 
                   1335: =begin latex
                   1336: 
                   1337: \begin{figure}
                   1338: \begin{center}
                   1339: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
                   1340:   \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
                   1341: \end{center}
                   1342: \end{figure}
                   1343: 
                   1344: =end latex
                   1345: 
                   1346: =head2 Role Initialization
                   1347: 
                   1348: 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.
1.32      harris41 1349: 
                   1350: =head1 INTRODUCTION
                   1351: 
                   1352: This module enables a user to select what role he wishes to
                   1353: operate under (instructor, student, teaching assistant, course
                   1354: coordinator, etc).  These roles are pre-established by the actions
                   1355: of upper-level users.
                   1356: 
                   1357: This is part of the LearningOnline Network with CAPA project
                   1358: described at http://www.lon-capa.org.
                   1359: 
                   1360: =head1 HANDLER SUBROUTINE
                   1361: 
                   1362: This routine is called by Apache and mod_perl.
                   1363: 
                   1364: =over 4
                   1365: 
                   1366: =item *
                   1367: 
                   1368: Roles Initialization (yes/no)
                   1369: 
                   1370: =item *
                   1371: 
                   1372: Get Error Message from Environment
                   1373: 
                   1374: =item *
                   1375: 
                   1376: Who is this?
                   1377: 
                   1378: =item *
                   1379: 
                   1380: Generate Page Output
                   1381: 
                   1382: =item *
                   1383: 
                   1384: Choice or no choice
                   1385: 
                   1386: =item *
                   1387: 
                   1388: Table
                   1389: 
                   1390: =item *
                   1391: 
                   1392: Privileges
                   1393: 
                   1394: =back
                   1395: 
                   1396: =cut

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