--- loncom/auth/lonroles.pm 2010/09/03 19:20:51 1.240.2.16 +++ loncom/auth/lonroles.pm 2010/08/12 23:40:49 1.256.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.240.2.16 2010/09/03 19:20:51 raeburn Exp $ +# $Id: lonroles.pm,v 1.256.2.1 2010/08/12 23:40:49 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -138,7 +138,6 @@ use Apache::lonannounce; use Apache::lonlocal; use Apache::lonpageflip(); use Apache::lonnavdisplay(); -use Apache::lonmainmenu(); use Apache::loncoursequeueadmin; use GDBM_File; use LONCAPA qw(:DEFAULT :match); @@ -154,10 +153,10 @@ sub redirect_user { my $swinfo=&Apache::lonmenu::rawconfig(); my $navwindow; if ($launch_nav eq 'on') { - $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef, - ($url =~ m-^/adm/whatsnew-)); + $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef, + ($url =~ m-^/adm/whatsnew-)); } else { - $navwindow.=&Apache::lonnavmaps::close(); + $navwindow.=&Apache::lonnavmaps::close(); } # Breadcrumbs @@ -166,7 +165,6 @@ sub redirect_user { my $start_page = &Apache::loncommon::start_page('Switching Role',undef, {'redirect' => [1,$url], 'bread_crumbs' => $brcrum,}); - &Apache::lonhtmlcommon::clear_breadcrumbs(); my $end_page = &Apache::loncommon::end_page(); # Note to style police: @@ -227,7 +225,7 @@ sub handler { my %dcroles = (); my $numdc = &check_fordc(\%dcroles,$then); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); - my $custommenu = &Apache::loncommon::needs_gci_custom(); + my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'}; # ================================================================== Roles Init if ($env{'form.selectrole'}) { @@ -241,7 +239,16 @@ sub handler { if ($env{'request.course.id'}) { # Check if user is CC trying to select a course role if ($env{'form.switchrole'}) { - if (!defined($env{'user.role.'.$env{'form.switchrole'}})) { + my $switch_is_active; + if (defined($env{'user.role.'.$env{'form.switchrole'}})) { + my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}}); + if (!$end || $end > $now) { + if (!$start || $start < $refresh) { + $switch_is_active = 1; + } + } + } + unless ($switch_is_active) { &adhoc_course_role($refresh,$then); } } @@ -277,7 +284,7 @@ sub handler { my ($server_status,$home) = &check_author_homeserver($user,$domain); if ($server_status eq 'switchserver') { my $trolecode = 'au./'.$domain.'/'; - my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; + my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; $r->internal_redirect($switchserver); } last; @@ -288,7 +295,7 @@ sub handler { my ($server_status,$home) = &check_author_homeserver($user,$domain); if ($server_status eq 'switchserver') { my $trolecode = 'ca./'.$domain.'/'.$user; - my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; + my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; $r->internal_redirect($switchserver); } last; @@ -309,7 +316,7 @@ sub handler { if ($server_status eq 'switchserver') { my $trolecode = 'ca./'.$domain.'/'.$user; my $switchserver = '/adm/switchserver?' - .'otherserver='.$home.'&role='.$trolecode; + .'otherserver='.$home.'&role='.$trolecode; $r->internal_redirect($switchserver); } } else { @@ -322,9 +329,7 @@ sub handler { } } } - if (($env{'form.cm'}) && ($env{'form.orgurl'})) { - $r->internal_redirect($env{'form.orgurl'}); - } + foreach $envkey (keys %env) { next if ($envkey!~/^user\.role\./); my ($where,$trolecode,$role,$tstatus,$tend,$tstart); @@ -334,6 +339,42 @@ sub handler { if ($tstatus eq 'is') { $where=~s/^\///; my ($cdom,$cnum,$csec)=split(/\//,$where); + if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) { + my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'}; + my @ids = &Apache::lonnet::current_machine_ids(); + unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) { + my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired'); + if ($curr_reqd_hash{'internal.releaserequired'} ne '') { + my ($switchserver,$switchwarning) = + &check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,$curr_reqd_hash{'internal.releaserequired'}); + if ($switchwarning ne '' || $switchserver ne '') { + &Apache::loncommon::content_type($r,'text/html'); + &Apache::loncommon::no_cache($r); + $r->send_http_header; + my $end_page=&Apache::loncommon::end_page(); + $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server'). + '
');
+ if ($switchwarning) {
+ $r->print($switchwarning.'
');
+ if (&Apache::loncommon::show_course()) {
+ $r->print(&mt('Display courses'));
+ } else {
+ $r->print(&mt('Display roles'));
+ }
+ $r->print('');
+ } elsif ($switchserver) {
+ $r->print(&mt('This course requires a newer version of LON-CAPA than is installed on this server.').
+ '
'.
+ ''.
+ &mt('Switch Server').
+ '');
+ }
+ $r->print('
'.&mt('Please try again.').'
' .''.$ferr.'
'; } + if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; } + &Apache::lonnet::appenv({'request.role.adv'=>$tadv}); if (($ferr) && ($tadv)) { &error_page($r,$ferr,$furl); @@ -501,7 +544,7 @@ ENDENTERKEY $courseid = substr($courseid, 1); } $courseid =~ s/\//_/; - if (($cdom ne 'gcitest') && (($role eq 'cc') || ($role eq 'co')) + if ((($role eq 'cc') || ($role eq 'co')) && ($env{'course.' . $courseid .'.course.helper.not.run'})) { $furl = "/adm/helper/course.initialization.helper"; # Send the user to the course they selected @@ -512,10 +555,10 @@ ENDENTERKEY my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&'); $dest .= '?symb='.$esc_symb; } - &redirect_user($r,&mt('Entering [_1]', - $env{'course.'.$courseid.'.description'}), - $dest,$msg, - $env{'environment.remotenavmap'}); + &redirect_user($r, &mt('Entering [_1]', + $env{'course.'.$courseid.'.description'}), + $dest, $msg, + $env{'environment.remotenavmap'}); return OK; } if (&Apache::lonnet::allowed('whn', @@ -525,12 +568,12 @@ ENDENTERKEY .$env{'request.course.sec'}) ) { my $startpage = &courseloadpage($courseid); - unless (($startpage eq 'firstres') || ($cdom eq 'gcitest')) { + unless ($startpage eq 'firstres') { $msg = &mt('Entering [_1] ...', $env{'course.'.$courseid.'.description'}); - &redirect_user($r,&mt('New in course'), - '/adm/whatsnew?refpage=start',$msg, - $env{'environment.remotenavmap'}); + &redirect_user($r,&mt('New in course'), + '/adm/whatsnew?refpage=start',$msg, + $env{'environment.remotenavmap'}); return OK; } } @@ -540,15 +583,12 @@ ENDENTERKEY # Guess not ... $furl=&Apache::lonpageflip::first_accessible_resource(); } - if (($cdom eq 'gcitest') && ($custommenu)) { - $furl = '/adm/navmaps'; - } $msg = &mt('Entering [_1] ...', $env{'course.'.$courseid.'.description'}); - &redirect_user($r,&mt('Entering [_1]', - $env{'course.'.$courseid.'.description'}), - $furl,$msg, - $env{'environment.remotenavmap'}); + &redirect_user($r,&mt('Entering [_1]', + $env{'course.'.$courseid.'.description'}), + $furl,$msg, + $env{'environment.remotenavmap'}); } return OK; } @@ -585,6 +625,7 @@ ENDENTERKEY } } + # =============================================================== No Roles Init &Apache::loncommon::content_type($r,'text/html'); @@ -592,34 +633,23 @@ ENDENTERKEY $r->send_http_header; return OK if $r->header_only; - my ($crumbtext,$pagetitle,$recent,$show_course); + my $crumbtext = 'User Roles'; + my $pagetitle = 'My Roles'; + my $recent = &mt('Recent Roles'); + my $show_course=&Apache::loncommon::show_course(); + if ($show_course) { + $crumbtext = 'Courses'; + $pagetitle = 'My Courses'; + $recent = &mt('Recent Courses'); + } + my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}]; + my $swinfo=&Apache::lonmenu::rawconfig(); + my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum}); + my $standby=&mt('Role selected. Please stand by.'); + $standby=~s/\n/\\n/g; my $noscript=''.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'