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

1.1       harris41    1: # The LearningOnline Network with CAPA
                      2: # User Roles Screen
1.31      www         3: #
1.196   ! raeburn     4: # $Id: lonroles.pm,v 1.195 2008/06/04 19:14:20 bisitz 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.75      albertel  504:     my (%roletext,%sortrole,%roleclass);
1.84      www       505:     my $countactive=0;
1.191     raeburn   506:     my $countfuture=0;
                    507:     my $countwill=0;
1.84      www       508:     my $inrole=0;
                    509:     my $possiblerole='';
1.191     raeburn   510:     my %futureroles;
                    511:     my %roles_nextlogin;
1.118     albertel  512:     foreach $envkey (sort keys %env) {
1.35      matthew   513:         my $button = 1;
1.49      www       514:         my $switchserver='';
1.75      albertel  515: 	my $roletext;
                    516: 	my $sortkey;
1.2       www       517:         if ($envkey=~/^user\.role\./) {
1.102     raeburn   518:             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
                    519:             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1.136     raeburn   520:             next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1.102     raeburn   521:             $tremark='';
                    522:             $tpstart='&nbsp;';
                    523:             $tpend='&nbsp;';
                    524:             $tfont='#000000';
1.4       www       525:             if ($tstart) {
1.74      www       526:                 $tpstart=&Apache::lonlocal::locallocaltime($tstart);
1.4       www       527:             }
                    528:             if ($tend) {
1.74      www       529:                 $tpend=&Apache::lonlocal::locallocaltime($tend);
1.4       www       530:             }
1.118     albertel  531:             if ($env{'request.role'} eq $trolecode) {
1.6       www       532: 		$tstatus='selected';
                    533:             }
1.4       www       534:             my $tbg;
1.164     albertel  535:             if (($tstatus eq 'is') 
                    536: 		|| ($tstatus eq 'selected') 
                    537: 		|| ($tstatus eq 'will') 
                    538: 		|| ($tstatus eq 'future') 
                    539:                 || ($env{'form.showall'})) {
1.35      matthew   540:                 if ($tstatus eq 'is') {
                    541:                     $tbg='#77FF77';
1.47      www       542:                     $tfont='#003300';
1.84      www       543: 		    $possiblerole=$trolecode;
                    544: 		    $countactive++;
1.35      matthew   545:                 } elsif ($tstatus eq 'future') {
                    546:                     $tbg='#FFFF77';
1.49      www       547:                     $button=0;
1.191     raeburn   548:                     $futureroles{$trolecode} = $tstart.':'.$tend;
                    549:                     $countfuture ++;
1.35      matthew   550:                 } elsif ($tstatus eq 'will') {
                    551:                     $tbg='#FFAA77';
1.72      www       552:                     $tremark.=&mt('Active at next login. ');
1.191     raeburn   553:                     $roles_nextlogin{$trolecode} = $tstart.':'.$tend;
                    554:                     $countwill ++;
1.35      matthew   555:                 } elsif ($tstatus eq 'expired') {
                    556:                     $tbg='#FF7777';
1.47      www       557:                     $tfont='#330000';
1.49      www       558:                     $button=0;
1.35      matthew   559:                 } elsif ($tstatus eq 'will_not') {
                    560:                     $tbg='#AAFF77';
1.72      www       561:                     $tremark.=&mt('Expired after logout. ');
1.35      matthew   562:                 } elsif ($tstatus eq 'selected') {
                    563:                     $tbg='#11CC55';
1.47      www       564:                     $tfont='#002200';
1.84      www       565: 		    $inrole=1;
1.86      albertel  566: 		    $countactive++;
1.72      www       567:                     $tremark.=&mt('Currently selected. ');
1.35      matthew   568:                 }
                    569:                 my $trole;
                    570:                 if ($role =~ /^cr\//) {
                    571:                     my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.132     albertel  572: 		    if ($tremark) { $tremark.='<br />'; }
                    573:                     $tremark.=&mt('Defined by ').$rauthor.
1.72      www       574: 			&mt(' at ').$rdomain.'.';
1.159     albertel  575: 		}
                    576: 		$trole=Apache::lonnet::plaintext($role);
1.35      matthew   577:                 my $ttype;
                    578:                 my $twhere;
                    579:                 my ($tdom,$trest,$tsection)=
                    580:                     split(/\//,Apache::lonnet::declutter($where));
                    581:                 # First, Co-Authorship roles
1.125     www       582:                 if (($role eq 'ca') || ($role eq 'aa')) {
1.39      stredwic  583:                     my $home = &Apache::lonnet::homeserver($trest,$tdom);
1.83      albertel  584: 		    my $allowed=0;
                    585: 		    my @ids=&Apache::lonnet::current_machine_ids();
                    586: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    587:                     if (!$allowed) {
1.49      www       588: 			$button=0;
1.130     albertel  589:                         $switchserver='otherserver='.$home.'&role='.$trolecode;
1.49      www       590:                     }
1.35      matthew   591:                     #next if ($home eq 'no_host');
1.176     albertel  592:                     $home = &Apache::lonnet::hostname($home);
1.78      sakharuk  593:                     $ttype='Construction Space';
1.72      www       594:                     $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
                    595: 			': '.$tdom.'<br />'.
                    596:                         ' '.&mt('Server').':&nbsp;'.$home;
1.118     albertel  597:                     $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82      www       598: 		    $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1.75      albertel  599: 		    $sortkey=$role."$trest:$tdom";
1.35      matthew   600:                 } elsif ($role eq 'au') {
                    601:                     # Authors
                    602:                     my $home = &Apache::lonnet::homeserver
1.118     albertel  603:                         ($env{'user.name'},$env{'user.domain'});
1.83      albertel  604: 		    my $allowed=0;
                    605: 		    my @ids=&Apache::lonnet::current_machine_ids();
                    606: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    607:                     if (!$allowed) {
1.49      www       608: 			$button=0;
1.143     albertel  609:                         $switchserver='otherserver='.$home.'&role='.$trolecode;
1.49      www       610:                     }
1.35      matthew   611:                     #next if ($home eq 'no_host');
1.176     albertel  612:                     $home = &Apache::lonnet::hostname($home);
1.78      sakharuk  613:                     $ttype='Construction Space';
1.72      www       614:                     $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
                    615: 			':&nbsp;'.$home;
1.118     albertel  616:                     $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
                    617: 		    $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1.75      albertel  618: 		    $sortkey=$role;
1.35      matthew   619:                 } elsif ($trest) {
                    620:                     my $tcourseid=$tdom.'_'.$trest;
1.153     raeburn   621:                     $ttype = &Apache::loncommon::course_type($tcourseid);
                    622:                     $trole = &Apache::lonnet::plaintext($role,$ttype);
1.118     albertel  623:                     if ($env{'course.'.$tcourseid.'.description'}) {
                    624:                         $twhere=$env{'course.'.$tcourseid.'.description'};
1.80      albertel  625: 			$sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.72      www       626:                         unless ($twhere eq &mt('Currently not available')) {
1.55      albertel  627: 			    $twhere.=' <font size="-2">'.
1.72      www       628:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49      www       629:                                     '</font>';
1.55      albertel  630: 			}
1.8       www       631:                     } else {
1.105     raeburn   632:                         my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1.35      matthew   633:                         if (%newhash) {
1.80      albertel  634: 			    $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1.77      albertel  635: 				"\0".$envkey;
1.49      www       636:                             $twhere=$newhash{'description'}.
                    637:                               ' <font size="-2">'.
1.72      www       638:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49      www       639:                               '</font>';
1.152     raeburn   640:                             $ttype = $newhash{'type'};
1.153     raeburn   641:                             $trole = &Apache::lonnet::plaintext($role,$ttype);
1.35      matthew   642:                         } else {
1.72      www       643:                             $twhere=&mt('Currently not available');
1.118     albertel  644:                             $env{'course.'.$tcourseid.'.description'}=$twhere;
1.80      albertel  645: 			    $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.152     raeburn   646:                             $ttype = 'Unavailable';
1.35      matthew   647:                         }
1.8       www       648:                     }
1.121     albertel  649:                     if ($tsection) {
1.175     albertel  650:                         $twhere.='<br />'.&mt('Section').': '.$tsection;
1.121     albertel  651: 		    }
1.72      www       652: 		    if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1.35      matthew   653:                 } elsif ($tdom) {
1.78      sakharuk  654:                     $ttype='Domain';
1.35      matthew   655:                     $twhere=$tdom;
1.75      albertel  656: 		    $sortkey=$role.$twhere;
1.35      matthew   657:                 } else {
1.78      sakharuk  658:                     $ttype='System';
1.72      www       659:                     $twhere=&mt('system wide');
1.75      albertel  660: 		    $sortkey=$role.$twhere;
1.13      www       661:                 }
1.152     raeburn   662:                 $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);
1.75      albertel  663: 		$roletext{$envkey}=$roletext;
                    664: 		if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
                    665: 		$sortrole{$sortkey}=$envkey;
                    666: 		$roleclass{$envkey}=$ttype;
1.55      albertel  667: 	    }
1.4       www       668:         }
1.75      albertel  669:     }
1.196   ! raeburn   670:     if ($env{'user.adv'}) {
        !           671:         $r->print(
        !           672:               '<br /><span class="LC_rolesinfo"><label>'.&mt('Show all roles').': <input type="checkbox" name="showall"');
        !           673:         if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
        !           674:         $r->print(' /></label><input type="submit" value="'.&mt('Display').'" /></span>');
        !           675:     } else {
        !           676:         if ($countactive > 0) {
        !           677:             my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
        !           678:             $r->print('<p>'.&mt('[_1]Visit the [_2]Course Catalog[_3] to view all [_4] LON-CAPA courses.','<b>','<a href="/adm/coursecatalog">','</a></b>',$domdesc).'<br />'.&mt('If a course is [_1]not[_2] in your list of current courses below, you may be able to enroll if self-enrollment is permitted.','<b>','</b>').'</p>');
        !           679:         }
        !           680:     }
        !           681: 
1.84      www       682: # No active roles
                    683:     if ($countactive==0) {
                    684: 	if ($inrole) {
                    685: 	    $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
                    686: 	} else {
                    687: 	    $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
                    688: 	}
1.191     raeburn   689:         &findcourse_advice($r);
                    690: 	$r->print('</form>');
                    691:         if ($countfuture) {
                    692:             $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
                    693:             my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
                    694:                                                $nochoose);
                    695:             &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
                    696:                             \%roletext);
                    697:             my $tremark='';
                    698:             my $tfont='#003300';
                    699:             if ($env{'request.role'} eq 'cm') {
                    700:                 $r->print('<tr bgcolor="#11CC55">');
                    701:                 $tremark=&mt('Currently selected. ');
                    702:                 $tfont='#002200';
                    703:             } else {
                    704:                 $r->print('<tr bgcolor="#77FF77">');
                    705:             }
                    706:             $r->print('<td></td><td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
1.192     raeburn   707:                       '</span></font></td><td><font color="'.$tfont.'">'.$tremark.
1.191     raeburn   708:                       '&nbsp;</font></td></tr>'."\n");
                    709: 
                    710:             $r->print('</table>');
                    711:         }
                    712:         $r->print(&Apache::loncommon::end_page());
1.84      www       713: 	return OK;
                    714: # Is there only one choice?
1.118     albertel  715:     } elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) {
1.84      www       716: 	$r->print('<h3>'.&mt('Please stand by.').'</h3>'.
1.179     raeburn   717: 	    '<input type="hidden" name="'.$possiblerole.'" value="1" />'.
                    718:             '<noscript><br /><input type="submit" name="submit" value="'.&mt('Continue').'" /></noscript>');
1.84      www       719: 	$r->print("</form>\n");
                    720: 	$r->rflush();
1.179     raeburn   721: 	$r->print('<script type="text/javascript">document.forms.rolechoice.submit();</script>');
1.147     albertel  722: 	$r->print(&Apache::loncommon::end_page());
1.84      www       723: 	return OK;
                    724:     }
                    725: # More than one possible role
                    726: # ----------------------------------------------------------------------- Table
1.181     albertel  727:     unless ((!&Apache::lonmenu::show_course()) || ($nochoose)) {
1.173     albertel  728: 	$r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84      www       729:     }
1.191     raeburn   730:     my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118     albertel  731:     if ($env{'environment.recentroles'}) {
1.111     albertel  732:         my %recent_roles =
1.118     albertel  733:                &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111     albertel  734: 	my $output='';
                    735: 	foreach (sort(keys(%recent_roles))) {
                    736: 	    if (defined($roletext{'user.role.'.$_})) {
                    737: 		$output.=$roletext{'user.role.'.$_};
1.170     albertel  738:                 if ($_ =~ m-dc\./($match_domain)/- 
                    739: 		    && $dcroles{$1}) {
1.192     raeburn   740: 		    $output .= &adhoc_roles_row($1,'recent');
1.133     albertel  741:                 }
1.113     raeburn   742: 	    } elsif ($numdc > 0) {
                    743:                 unless ($_ =~/^error\:/) {
                    744:                     $output.=&display_cc_role('user.role.'.$_);
                    745:                 }
                    746:             } 
1.111     albertel  747: 	}
                    748: 	if ($output) {
1.132     albertel  749: 	    $r->print("<tr><td align='center' colspan='5'><font face='arial'>".
1.192     raeburn   750: 		      &mt('Recent Roles')."</font></td></tr>");
1.111     albertel  751: 	    $r->print($output);
1.114     raeburn   752:             $doheaders ++;
1.111     albertel  753: 	}
                    754:     }
                    755: 
1.104     raeburn   756:     if ($numdc > 0) {
1.112     raeburn   757:         $r->print(&coursepick_jscript());
1.193     raeburn   758:         $r->print(&Apache::loncommon::coursebrowser_javascript().
                    759:                   &Apache::loncommon::authorbrowser_javascript());
1.108     raeburn   760:     }
1.191     raeburn   761:     &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.14      www       762:     my $tremark='';
1.47      www       763:     my $tfont='#003300';
1.118     albertel  764:     if ($env{'request.role'} eq 'cm') {
1.19      www       765: 	$r->print('<tr bgcolor="#11CC55">');
1.72      www       766:         $tremark=&mt('Currently selected. ');
1.47      www       767:         $tfont='#002200';
1.14      www       768:     } else {
                    769:         $r->print('<tr bgcolor="#77FF77">');
                    770:     }
                    771:     unless ($nochoose) {
1.118     albertel  772: 	if ($env{'request.role'} ne 'cm') {
1.134     www       773: 	    $r->print('<td><input type="submit" value="'.
1.192     raeburn   774: 		      &mt('Select').'" name="cm" /></td>');
1.55      albertel  775: 	} else {
                    776: 	    $r->print('<td>&nbsp;</td>');
                    777: 	}
1.14      www       778:     }
1.177     www       779:     $r->print('<td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
1.192     raeburn   780:       '</span></font></td><td><font color="'.$tfont.'">'.$tremark.
1.47      www       781:       '&nbsp;</font></td></tr>'."\n");
1.4       www       782: 
                    783:     $r->print('</table>');
                    784:     unless ($nochoose) {
                    785: 	$r->print("</form>\n");
                    786:     }
1.22      harris41  787: # ------------------------------------------------------------ Privileges Info
1.118     albertel  788:     if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.127     albertel  789: 	$r->print('<hr /><h2>Current Privileges</h2>');
1.175     albertel  790: 	$r->print(&privileges_info());
1.4       www       791:     }
1.66      www       792:     $r->print(&Apache::lonnet::getannounce());
1.65      www       793:     if ($advanced) {
1.195     bisitz    794: 	$r->print('<p><small><i>'
                    795:                  .&mt('This is LON-CAPA [_1]',$r->dir_config('lonVersion'))
                    796: 		 .'</i><br />'
                    797: 		 .'<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
1.65      www       798:     }
1.147     albertel  799:     $r->print(&Apache::loncommon::end_page());
1.1       harris41  800:     return OK;
1.102     raeburn   801: }
                    802: 
1.191     raeburn   803: sub roletable_headers {
                    804:     my ($r,$roleclass,$sortrole,$nochoose) = @_;
                    805:     my $doheaders;
                    806:     if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
                    807:         $r->print('<br /><table id="LC_rolesmenu"><tr>');
                    808:         if (!$nochoose) { $r->print('<th>&nbsp;</th>'); }
                    809:         $r->print('<th>'.&mt('User Role').'</th><th>'.&mt('Extent')
                    810:                   .'</th><th>'.&mt('Start').'</th><th>'.&mt('End')
                    811:                   .'</th></tr>'."\n");
                    812:         $doheaders=-1;
                    813:         my @roletypes = &roletypes();
                    814:         foreach my $type (@roletypes) {
                    815:             my $haverole=0;
                    816:             foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
                    817:                 if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
                    818:                     $haverole=1;
                    819:                 }
                    820:             }
                    821:             if ($haverole) { $doheaders++; }
                    822:         }
                    823:     }
                    824:     return $doheaders;
                    825: }
                    826: 
                    827: sub roletypes {
                    828:     my @types = ('Domain','Construction Space','Course','Unavailable','System');
                    829:     return @types; 
                    830: }
                    831: 
                    832: sub print_rolerows {
                    833:     my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
                    834:     if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
                    835:         my @types = &roletypes();
                    836:         foreach my $type (@types) {
                    837:             my $output;
                    838:             foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
                    839:                 if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
                    840:                     if (ref($roletext) eq 'HASH') {
                    841:                         $output.=$roletext->{$sortrole->{$which}};
                    842:                         if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
                    843:                             if (ref($dcroles) eq 'HASH') {
                    844:                                 if ($dcroles->{$1}) {
1.192     raeburn   845:                                     $output .= &adhoc_roles_row($1,'');
1.191     raeburn   846:                                 }
                    847:                             }
                    848:                         }
                    849:                     }
                    850:                 }
                    851:             }
                    852:             if ($output) {
                    853:                 if ($doheaders > 0) {
                    854:                     $r->print("<tr>".
                    855:                               "<td align='center' colspan='5'><font face='arial'>".
                    856:                               &mt($type)."</font></td></tr>");
                    857:                 }
                    858:                 $r->print($output);
                    859:             }
                    860:         }
                    861:     }
                    862: }
                    863: 
                    864: sub findcourse_advice {
                    865:     my ($r) = @_;
                    866:     my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
                    867:     if (&check_autoenroll($env{'user.domain'})) {
                    868:         $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).'
                    869: <ul>
                    870:  <li>'.&mt('The course has yet to be created.').'</li>
                    871:  <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
                    872:  <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
                    873:  <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
                    874:  <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>
                    875:  </ul>');
                    876:     } else {
                    877:         $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 />');
                    878:     }
                    879:     $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 />');
                    880:     $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>');
                    881:     return;
                    882: }
                    883: 
1.175     albertel  884: sub privileges_info {
                    885:     my ($which) = @_;
                    886:     my $output;
                    887: 
                    888:     $which ||= $env{'request.role'};
                    889: 
                    890:     foreach my $envkey (sort(keys(%env))) {
                    891: 	next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
                    892: 
                    893: 	my $where=$1;
                    894: 	my $ttype;
                    895: 	my $twhere;
                    896: 	my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
                    897: 	if ($trest) {
                    898: 	    if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
                    899: 		$ttype='Construction Space';
                    900: 		$twhere='User: '.$trest.', Domain: '.$tdom;
                    901: 	    } else {
                    902: 		$ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
                    903: 		$twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
                    904: 		if ($tsec) {
                    905: 		    my $sec_type = 'Section';
                    906: 		    if (exists($env{"user.role.gr.$where"})) {
                    907: 			$sec_type = 'Group';
                    908: 		    }
                    909: 		    $twhere.=' ('.$sec_type.': '.$tsec.')';
                    910: 		}
                    911: 	    }
                    912: 	} elsif ($tdom) {
                    913: 	    $ttype='Domain';
                    914: 	    $twhere=$tdom;
                    915: 	} else {
                    916: 	    $ttype='System';
                    917: 	    $twhere='/';
                    918: 	}
                    919: 	$output .= "\n<h3>".$ttype.': '.$twhere.'</h3>'."\n<ul>";
                    920: 	foreach my $priv (sort(split(/:/,$env{$envkey}))) {
                    921: 	    next if (!$priv);
                    922: 
                    923: 	    my ($prv,$restr)=split(/\&/,$priv);
                    924: 	    my $trestr='';
                    925: 	    if ($restr ne 'F') {
                    926: 		$trestr.=' ('.
                    927: 		    join(', ',
                    928: 			 map { &Apache::lonnet::plaintext($_) } 
                    929: 			     (split('',$restr))).') ';
                    930: 	    }
                    931: 	    $output .= "\n\t".
                    932: 		'<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
                    933: 	}
                    934: 	$output .= "\n".'</ul>';
                    935:     }
                    936:     return $output;
                    937: }
                    938: 
1.102     raeburn   939: sub role_status {
                    940:     my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
                    941:     my @pwhere = ();
1.118     albertel  942:     if (exists($env{$rolekey}) && $env{$rolekey} ne '') {
1.102     raeburn   943:         (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
                    944:         unless (!defined($$role) || $$role eq '') {
                    945:             $$where=join('.',@pwhere);
                    946:             $$trolecode=$$role.'.'.$$where;
1.118     albertel  947:             ($$tstart,$$tend)=split(/\./,$env{$rolekey});
1.102     raeburn   948:             $$tstatus='is';
1.105     raeburn   949:             if ($$tstart && $$tstart>$then) {
                    950: 		$$tstatus='future';
                    951: 		if ($$tstart<$now) { $$tstatus='will'; }
1.102     raeburn   952:             }
                    953:             if ($$tend) {
                    954:                 if ($$tend<$then) {
                    955:                     $$tstatus='expired';
1.103     raeburn   956:                 } elsif ($$tend<$now) {
1.104     raeburn   957:                     $$tstatus='will_not';
1.102     raeburn   958:                 }
                    959:             }
                    960:         }
                    961:     }
                    962: }
1.1       harris41  963: 
1.110     raeburn   964: sub build_roletext {
1.152     raeburn   965:     my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
1.177     www       966:     my $roletext='<tr bgcolor="'.$tbg.'" class="LC_rolesmenu_'.$tstatus.'">';
1.132     albertel  967:     my $is_dc=($trolecode =~ m/^dc\./);
                    968:     my $rowspan=($is_dc) ? ''
                    969:                          : ' rowspan="2" ';
                    970: 
1.110     raeburn   971:     unless ($nochoose) {
1.134     www       972:         my $buttonname=$trolecode;
                    973:         $buttonname=~s/\W//g;
1.110     raeburn   974:         if (!$button) {
                    975:             if ($switchserver) {
1.177     www       976:                 $roletext.='<td'.$rowspan.'><span class="LC_rolesinfo"><a href="/adm/switchserver?'.
                    977:                 $switchserver.'">'.&mt('Switch Server').'</a></span></td>';
1.110     raeburn   978:             } else {
1.164     albertel  979:                 $roletext.=('<td'.$rowspan.'>&nbsp;</td>');
1.110     raeburn   980:             }
                    981:         } elsif ($tstatus eq 'is') {
1.134     www       982:             $roletext.='<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
                    983:                         &mt('Select').'" onClick="javascript:enterrole(this.form,\''.
1.192     raeburn   984:                         $trolecode."','".$buttonname.'\');" /></td>';
1.110     raeburn   985:         } elsif ($tryagain) {
                    986:             $roletext.=
1.134     www       987:                 '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
                    988:                 &mt('Try Selecting Again').'" onClick="javascript:enterrole(this.form,\''.
1.192     raeburn   989:                         $trolecode."','".$buttonname.'\');" /></td>';
1.110     raeburn   990:         } elsif ($advanced) {
                    991:             $roletext.=
1.134     www       992:                 '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
                    993:                 &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
1.192     raeburn   994:                         $trolecode."','".$buttonname.'\');" /></td>';
1.110     raeburn   995:         } else {
1.132     albertel  996:             $roletext.='<td'.$rowspan.'>&nbsp;</td>';
1.110     raeburn   997:         }
                    998:     }
1.165     albertel  999:     if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
                   1000: 	$tremark.=&Apache::lonannounce::showday(time,1,
                   1001: 			 &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
                   1002:     }
1.110     raeburn  1003:     $roletext.='<td><font color="'.$tfont.'">'.$trole.
1.121     albertel 1004: 	       '</font></td><td><font color="'.$tfont.'">'.$twhere.
1.110     raeburn  1005:                '</font></td><td><font color="'.$tfont.'">'.$tpstart.
                   1006:                '</font></td><td><font color="'.$tfont.'">'.$tpend.
1.132     albertel 1007:                '</font></td></tr>';
                   1008:     if (!$is_dc) {
1.177     www      1009: 	$roletext.='<tr bgcolor="'.$tbg.'"><td colspan="4"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.$tremark.
                   1010: 	    '</span>&nbsp;</font></td></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
1.132     albertel 1011:     }
1.110     raeburn  1012:     return $roletext;
                   1013: }
                   1014: 
1.193     raeburn  1015: sub check_author_homeserver {
1.183     www      1016:     my ($uname,$udom)=@_;
1.193     raeburn  1017:     if (($uname eq '') || ($udom eq '')) {
                   1018:         return ('fail','');
                   1019:     }
1.183     www      1020:     my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193     raeburn  1021:     if (&Apache::lonnet::host_domain($home) ne $udom) {
                   1022:         return ('fail',$home);
                   1023:     }
1.183     www      1024:     my @ids=&Apache::lonnet::current_machine_ids();
1.193     raeburn  1025:     if (grep(/^\Q$home\E$/,@ids)) {
                   1026:         return ('ok',$home);
                   1027:     } else {
                   1028:         return ('switchserver',$home);
1.183     www      1029:     }
                   1030: }
                   1031: 
1.110     raeburn  1032: sub check_privs {
1.182     www      1033:     my ($cdom,$cnum,$then,$now,$checkrole) = @_;
                   1034:     my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum; 
1.118     albertel 1035:     if ($env{$cckey}) {
1.110     raeburn  1036:         my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
                   1037:         &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
                   1038:         unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
1.182     www      1039:             &set_privileges($cdom,$cnum,$checkrole);
1.110     raeburn  1040:         }
                   1041:     } else {
1.182     www      1042:         &set_privileges($cdom,$cnum,$checkrole);
1.110     raeburn  1043:     }
                   1044: }
                   1045: 
1.104     raeburn  1046: sub check_fordc {
                   1047:     my ($dcroles,$then) = @_;
                   1048:     my $numdc = 0;
1.118     albertel 1049:     if ($env{'user.adv'}) {
                   1050:         foreach my $envkey (sort keys %env) {
1.170     albertel 1051:             if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104     raeburn  1052:                 my $dcdom = $1;
                   1053:                 my $livedc = 1;
1.118     albertel 1054:                 my ($tstart,$tend)=split(/\./,$env{$envkey});
1.105     raeburn  1055:                 if ($tstart && $tstart>$then) { $livedc = 0; }
                   1056:                 if ($tend   && $tend  <$then) { $livedc = 0; }
1.104     raeburn  1057:                 if ($livedc) {
                   1058:                     $$dcroles{$dcdom} = $envkey;
1.105     raeburn  1059:                     $numdc++;
1.104     raeburn  1060:                 }
                   1061:             }
                   1062:         }
                   1063:     }
                   1064:     return $numdc;
                   1065: }
                   1066: 
1.185     raeburn  1067: sub adhoc_course_role {
                   1068:     my ($then) = @_; 
                   1069:     my ($cdom,$cnum);
                   1070:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1071:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1072:     if (&check_forcc($cdom,$cnum,$then)) {
                   1073:         my $setprivs;
                   1074:         if (!defined($env{'user.role.'.$env{'form.selectrole'}})) {
                   1075:             $setprivs = 1;
                   1076:         } else {
                   1077:             my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.selectrole'}});
                   1078:             if (($start && ($start>$then || $start == -1)) ||
                   1079:                 ($end && $end<$then)) {
                   1080:                 $setprivs = 1;
                   1081:             }
                   1082:         } 
                   1083:         if ($setprivs) {
                   1084:             if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E(/?\w*)$-) {
                   1085:                 my $role = $1;
                   1086:                 my $custom_role = $2;
                   1087:                 my $usec = $3;
                   1088:                 if ($role eq 'cr') {
                   1089:                     if ($custom_role =~ m-^$match_domain/$match_courseid/\w+$-) {
                   1090:                         $role .= $custom_role;
                   1091:                     } else {
                   1092:                         return;
                   1093:                     }
                   1094:                 }
                   1095:                 my (%userroles,%newrole,%newgroups);
                   1096:                 my $area = '/'.$cdom.'/'.$cnum;
                   1097:                 my $spec = $role.'.'.$area;
                   1098:                 if ($usec ne '') {
                   1099:                     $spec .= '/'.$usec;
                   1100:                     $area .= '/'.$usec;
                   1101:                 }
                   1102:                 &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
                   1103:                 &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups);
                   1104:                 my $adhocstart = $then-1;
                   1105:                 $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186     raeburn  1106:                 &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185     raeburn  1107:             }
                   1108:         }
                   1109:     }
                   1110:     return;
                   1111: }
                   1112: 
                   1113: sub check_forcc {
                   1114:     my ($cdom,$cnum,$then) = @_;
                   1115:     my $is_cc;
                   1116:     if ($cdom ne '' && $cnum ne '') {
                   1117:         if (&Apache::lonnet::is_course($cdom,$cnum)) {
                   1118:             my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;
                   1119:             if (defined($env{$envkey})) {
                   1120:                 $is_cc = 1;
                   1121:                 my ($tstart,$tend)=split(/\./,$env{$envkey});
                   1122:                 if ($tstart && $tstart>$then) { $is_cc = 0; }
                   1123:                 if ($tend   && $tend  <$then) { $is_cc = 0; }
                   1124:             }
                   1125:         }
                   1126:     }
                   1127:     return $is_cc;
                   1128: }
                   1129: 
1.108     raeburn  1130: sub courselink {
1.193     raeburn  1131:     my ($dcdom,$rowtype) = @_;
1.109     raeburn  1132:     my $courseform=&Apache::loncommon::selectcourse_link
1.152     raeburn  1133:                    ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
                   1134:                     'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.173     albertel 1135:                     $dcdom,$dcdom,undef);
1.138     raeburn  1136:     my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
                   1137:                       '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
                   1138:                       '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
                   1139:                       '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112     raeburn  1140:     return $courseform.$hiddenitems;
1.109     raeburn  1141: }
                   1142: 
                   1143: sub coursepick_jscript {
1.184     raeburn  1144:     my %lt = &Apache::lonlocal::texthash(
                   1145:                   plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.",
                   1146:                   youc => 'You can only use this screen to select courses in the current domain.',
                   1147:              );
1.104     raeburn  1148:     my $verify_script = <<"END";
1.179     raeburn  1149: <script type="text/javascript">
1.108     raeburn  1150: function verifyCoursePick(caller) {
                   1151:     var numbutton = getIndex(caller)
1.112     raeburn  1152:     var pickedCourse = document.rolechoice.elements[numbutton+4].value
                   1153:     var pickedDomain = document.rolechoice.elements[numbutton+2].value
                   1154:     if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104     raeburn  1155:         if (pickedCourse != '') {
1.108     raeburn  1156:             if (numbutton != -1) {
                   1157:                 var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
                   1158:                 document.rolechoice.elements[numbutton+1].name = courseTarget
                   1159:                 document.rolechoice.submit()
                   1160:             }
1.104     raeburn  1161:         }
                   1162:         else {
1.184     raeburn  1163:             alert("$lt{'plsu'}");
1.104     raeburn  1164:         }
                   1165:     }
                   1166:     else {
1.184     raeburn  1167:         alert("$lt{'youc'}")
1.104     raeburn  1168:     }
                   1169: }
1.109     raeburn  1170: function getIndex(caller) {
1.108     raeburn  1171:     for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109     raeburn  1172:         if (document.rolechoice.elements[i] == caller) {
1.108     raeburn  1173:             return i;
                   1174:         }
                   1175:     }
                   1176:     return -1;
                   1177: }
1.104     raeburn  1178: </script>
                   1179: END
1.109     raeburn  1180:     return $verify_script;
1.104     raeburn  1181: }
                   1182: 
1.193     raeburn  1183: sub coauthorlink {
                   1184:     my ($dcdom,$rowtype) = @_;
                   1185:     my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
                   1186:     my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
                   1187:     return $coauthorform.$hiddenitems;
                   1188: }
                   1189: 
1.113     raeburn  1190: sub display_cc_role {
                   1191:     my $rolekey = shift;
                   1192:     my $roletext;
1.118     albertel 1193:     my $advanced = $env{'user.adv'};
                   1194:     my $tryagain = $env{'form.tryagain'};
1.113     raeburn  1195:     unless ($rolekey =~/^error\:/) {
1.171     albertel 1196:         if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {
1.113     raeburn  1197:             my $tcourseid = $1.'_'.$2;
                   1198:             my $trolecode = 'cc./'.$1.'/'.$2;
                   1199:             my $twhere;
1.152     raeburn  1200:             my $ttype;
1.113     raeburn  1201:             my $tbg='#77FF77';
                   1202:             my $tfont='#003300';
                   1203:             my %newhash=&Apache::lonnet::coursedescription($tcourseid);
                   1204:             if (%newhash) {
                   1205:                 $twhere=$newhash{'description'}.
                   1206:                         ' <font size="-2">'.
                   1207:                         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).
                   1208:                         '</font>';
1.153     raeburn  1209:                 $ttype = $newhash{'type'};
1.113     raeburn  1210:             } else {
                   1211:                 $twhere=&mt('Currently not available');
1.118     albertel 1212:                 $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110     raeburn  1213:             }
1.153     raeburn  1214:             my $trole = &Apache::lonnet::plaintext('cc',$ttype);
1.113     raeburn  1215:             $twhere.="<br />".&mt('Domain').":".$1;
1.152     raeburn  1216:             $roletext = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$tfont,$trole,$twhere,'','','',1,'');
1.104     raeburn  1217:         }
                   1218:     }
1.152     raeburn  1219:     return ($roletext);
1.104     raeburn  1220: }
                   1221: 
1.192     raeburn  1222: sub adhoc_roles_row {
1.138     raeburn  1223:     my ($dcdom,$rowtype) = @_;
1.132     albertel 1224:     my $output = '<tr bgcolor="#77FF77">'.
1.192     raeburn  1225:                  ' <td colspan="5"><table><tr><td><span class="LC_rolesinfo">'
                   1226:                  .&mt('[_1]Ad hoc[_2] roles in domain [_3] --',
                   1227:                  '<span class="LC_cusr_emph">','</span>',$dcdom).'</span></td><td>';
1.193     raeburn  1228:     my $selectcclink = &courselink($dcdom,$rowtype);
1.173     albertel 1229:     my $ccrole = &Apache::lonnet::plaintext('cc');
1.182     www      1230:     my $carole = &Apache::lonnet::plaintext('ca');
1.193     raeburn  1231:     my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.182     www      1232:     $output.= '<span class="LC_rolesinfo">'.
1.193     raeburn  1233:             &mt('[_1]: [_2]',$ccrole,$selectcclink).
1.192     raeburn  1234:             '</span><br /></td><td>&nbsp;&nbsp;</td><td><span class="LC_rolesinfo">'.
1.193     raeburn  1235:             &mt('[_1]: [_2]',$carole,$selectcalink).
1.192     raeburn  1236:             '</span><br /></td></tr></table></td></tr>'.
                   1237:             '<tr><td colspan="5" height="3"></td></tr>'."\n";
1.108     raeburn  1238:     return $output;
                   1239: }
                   1240: 
1.104     raeburn  1241: sub recent_filename {
                   1242:     my $area=shift;
1.149     www      1243:     return 'nohist_recent_'.&escape($area);
1.104     raeburn  1244: }
                   1245: 
1.106     raeburn  1246: sub set_privileges {
1.182     www      1247: # role can be cc or ca
                   1248:     my ($dcdom,$pickedcourse,$role) = @_;
1.106     raeburn  1249:     my $area = '/'.$dcdom.'/'.$pickedcourse;
                   1250:     my $spec = $role.'.'.$area;
1.168     albertel 1251:     my %userroles = &Apache::lonnet::set_arearole($role,$area,'','',
                   1252: 						  $env{'user.domain'},
                   1253: 						  $env{'user.name'});
1.106     raeburn  1254:     my %ccrole = ();
                   1255:     &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
1.154     albertel 1256:     my ($author,$adv)= &Apache::lonnet::set_userprivs(\%userroles,\%ccrole);
1.186     raeburn  1257:     &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.184     raeburn  1258: 
1.118     albertel 1259:     &Apache::lonnet::log($env{'user.domain'},
                   1260:                          $env{'user.name'},
                   1261:                          $env{'user.home'},
1.106     raeburn  1262:                         "Role ".$role);
                   1263:     &Apache::lonnet::appenv(
1.186     raeburn  1264:                           {'request.role'        => $spec,
1.106     raeburn  1265:                           'request.role.domain' => $dcdom,
1.186     raeburn  1266:                           'request.course.sec'  => ''});
1.106     raeburn  1267:     my $tadv=0;
                   1268:     if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186     raeburn  1269:     &Apache::lonnet::appenv({'request.role.adv'    => $tadv});
1.106     raeburn  1270: }
                   1271: 
1.139     raeburn  1272: sub courseloadpage {
                   1273:     my ($courseid) = @_;
                   1274:     my $startpage;
1.144     albertel 1275:     my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
                   1276: 					      [$courseid.':courseinit']);
1.139     raeburn  1277:     my ($tmp) = %entry_settings;
1.144     albertel 1278:     unless ($tmp =~ /^error: 2 /) {
1.139     raeburn  1279:         $startpage = $entry_settings{$courseid.':courseinit'};
                   1280:     }
                   1281:     if ($startpage eq '') {
                   1282:         if (exists($env{'environment.course_init_display'})) {
                   1283:             $startpage = $env{'environment.course_init_display'};
                   1284:         }
                   1285:     }
                   1286:     return $startpage;
                   1287: }
                   1288: 
1.191     raeburn  1289: sub check_autoenroll {
                   1290:     my ($dom) = @_;
                   1291:     my $run_enroll = 0;
                   1292:     my $settings;
                   1293:     my %domconfig =
                   1294:         &Apache::lonnet::get_dom('configuration',['autoenroll'],$dom);
                   1295:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   1296:         $settings = $domconfig{'autoenroll'};
                   1297:         if ($settings->{'run'} eq '1') {
                   1298:             $run_enroll = 1;
                   1299:         }
                   1300:     } else {
                   1301:         $run_enroll = &localenroll::run($dom);
                   1302:     }
                   1303:     return $run_enroll;
                   1304: }
                   1305: 
                   1306: 
1.1       harris41 1307: 1;
                   1308: __END__
1.32      harris41 1309: 
                   1310: =head1 NAME
                   1311: 
                   1312: Apache::lonroles - User Roles Screen
                   1313: 
                   1314: =head1 SYNOPSIS
                   1315: 
                   1316: Invoked by /etc/httpd/conf/srm.conf:
                   1317: 
                   1318:  <Location /adm/roles>
                   1319:  PerlAccessHandler       Apache::lonacc
                   1320:  SetHandler perl-script
                   1321:  PerlHandler Apache::lonroles
                   1322:  ErrorDocument     403 /adm/login
                   1323:  ErrorDocument	  500 /adm/errorhandler
                   1324:  </Location>
1.64      bowersj2 1325: 
                   1326: =head1 OVERVIEW
                   1327: 
                   1328: =head2 Choosing Roles
                   1329: 
                   1330: C<lonroles> is a handler that allows a user to switch roles in
                   1331: mid-session. LON-CAPA attempts to work with "No Role Specified", the
                   1332: default role that a user has before selecting a role, as widely as
                   1333: possible, but certain handlers for example need specification which
                   1334: course they should act on, etc. Both in this scenario, and when the
                   1335: handler determines via C<lonnet>'s C<&allowed> function that a certain
                   1336: action is not allowed, C<lonroles> is used as error handler. This
                   1337: allows the user to select another role which may have permission to do
                   1338: what they were trying to do. C<lonroles> can also be accessed via the
                   1339: B<CRS> button in the Remote Control. 
                   1340: 
                   1341: =begin latex
                   1342: 
                   1343: \begin{figure}
                   1344: \begin{center}
                   1345: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
                   1346:   \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
                   1347: \end{center}
                   1348: \end{figure}
                   1349: 
                   1350: =end latex
                   1351: 
                   1352: =head2 Role Initialization
                   1353: 
                   1354: 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 1355: 
                   1356: =head1 INTRODUCTION
                   1357: 
                   1358: This module enables a user to select what role he wishes to
                   1359: operate under (instructor, student, teaching assistant, course
                   1360: coordinator, etc).  These roles are pre-established by the actions
                   1361: of upper-level users.
                   1362: 
                   1363: This is part of the LearningOnline Network with CAPA project
                   1364: described at http://www.lon-capa.org.
                   1365: 
                   1366: =head1 HANDLER SUBROUTINE
                   1367: 
                   1368: This routine is called by Apache and mod_perl.
                   1369: 
                   1370: =over 4
                   1371: 
                   1372: =item *
                   1373: 
                   1374: Roles Initialization (yes/no)
                   1375: 
                   1376: =item *
                   1377: 
                   1378: Get Error Message from Environment
                   1379: 
                   1380: =item *
                   1381: 
                   1382: Who is this?
                   1383: 
                   1384: =item *
                   1385: 
                   1386: Generate Page Output
                   1387: 
                   1388: =item *
                   1389: 
                   1390: Choice or no choice
                   1391: 
                   1392: =item *
                   1393: 
                   1394: Table
                   1395: 
                   1396: =item *
                   1397: 
                   1398: Privileges
                   1399: 
                   1400: =back
                   1401: 
                   1402: =cut

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