--- loncom/auth/lonroles.pm 2010/12/05 16:35:58 1.240.2.21 +++ loncom/auth/lonroles.pm 2010/06/02 14:55:37 1.248 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.240.2.21 2010/12/05 16:35:58 raeburn Exp $ +# $Id: lonroles.pm,v 1.248 2010/06/02 14:55:37 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -57,8 +57,7 @@ course they should act on, etc. Both in handler determines via C's C<&allowed> function that a certain action is not allowed, C is used as error handler. This allows the user to select another role which may have permission to do -what they were trying to do. C can also be accessed via the -B button in the Remote Control. +what they were trying to do. =begin latex @@ -145,19 +144,11 @@ use HTML::Entities; sub redirect_user { - my ($r,$title,$url,$msg,$launch_nav) = @_; + my ($r,$title,$url,$msg) = @_; $msg = $title if (! defined($msg)); &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; - my $swinfo=&Apache::lonmenu::rawconfig(); - my $navwindow; - if ($launch_nav eq 'on') { - $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef, - ($url =~ m-^/adm/whatsnew-)); - } else { - $navwindow.=&Apache::lonnavmaps::close(); - } # Breadcrumbs my $brcrum = [{'href' => $url, @@ -165,7 +156,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: @@ -173,12 +163,6 @@ sub redirect_user { $url=~s/ /\%20/g; $r->print(< -// - -$navwindow

$msg

$end_page ENDREDIR @@ -226,7 +210,6 @@ 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(); # ================================================================== Roles Init if ($env{'form.selectrole'}) { @@ -276,7 +259,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; @@ -287,7 +270,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; @@ -308,7 +291,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 { @@ -321,9 +304,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); @@ -450,16 +431,8 @@ ENDENTERKEY if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) { my $msg; - if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; } - &Apache::lonnet::appenv({'request.role.adv'=>$tadv}); my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum); - if ($custommenu) { - unless (($ferr) || ($env{'form.switchrole'})) { - &Apache::lonnet::put('nohist_crslastlogin',{$env{'user.name'}.':'.$env{'user.domain'}.':'.$csec.':'.$role => $now}, - $cdom,$cnum); - } - } if (($env{'form.orgurl'}) && ($env{'form.orgurl'}!~/^\/adm\/flip/)) { my $dest=$env{'form.orgurl'}; @@ -471,6 +444,8 @@ ENDENTERKEY } $dest .= 'symb='.$env{'form.symb'}; } + if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; } + &Apache::lonnet::appenv({'request.role.adv'=>$tadv}); if (($ferr) && ($tadv)) { &error_page($r,$ferr,$dest); } else { @@ -489,6 +464,8 @@ ENDENTERKEY .'

'.&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); @@ -500,7 +477,7 @@ ENDENTERKEY $courseid = substr($courseid, 1); } $courseid =~ s/\//_/; - if (($cdom !~ /^\w+citest$/) && (($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 @@ -511,10 +488,9 @@ 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); return OK; } if (&Apache::lonnet::allowed('whn', @@ -524,12 +500,11 @@ ENDENTERKEY .$env{'request.course.sec'}) ) { my $startpage = &courseloadpage($courseid); - unless (($startpage eq 'firstres') || ($cdom =~ /^\w+citest$/)) { + 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); return OK; } } @@ -539,15 +514,11 @@ ENDENTERKEY # Guess not ... $furl=&Apache::lonpageflip::first_accessible_resource(); } - if (($cdom =~ /^\w+citest$/) && ($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); } return OK; } @@ -584,6 +555,7 @@ ENDENTERKEY } } + # =============================================================== No Roles Init &Apache::loncommon::content_type($r,'text/html'); @@ -591,43 +563,25 @@ ENDENTERKEY $r->send_http_header; return OK if $r->header_only; - my ($crumbtext,$pagetitle,$recent,$show_course); - $show_course=&Apache::loncommon::show_course(); - my $noscript='
'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'
'.&mt('As this is not the case, most functionality in the system will be unavailable.').'

'; - if ($custommenu) { - my $start_page = &Apache::loncommon::start_page('Main Menu'); - $r->print(<<"ENDCUSTOM"); -$start_page - -ENDCUSTOM - } else { - $crumbtext = 'User Roles'; - $pagetitle = 'My Roles'; - $recent = &mt('Recent Roles'); - my $standby=&mt('Role selected. Please stand by.'); - if ($show_course) { - $crumbtext = 'Courses'; - $pagetitle = 'My Courses'; - $recent = &mt('Recent Courses'); - $standby = &mt('Course selected. Please stand by.'); - } - my $brcrum = [{ href => '/adm/roles', - text => $crumbtext,}, - ]; - my $args; - if ($numdc) { - $args = {bread_crumbs => $brcrum}; - } else { - $args = {bread_crumbs => $brcrum, - bread_crumbs_menulink => '_nomenu'}; - } - my $start_page=&Apache::loncommon::start_page($pagetitle,undef,$args); - my $swinfo=&Apache::lonmenu::rawconfig(); - $standby=~s/\n/\\n/g; - $r->print(<"/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.').'
'.&mt('As this is not the case, most functionality in the system will be unavailable.').'

'; + + $r->print(< @@ -652,7 +606,6 @@ function enterrole (thisform,rolecode,bu // ]]> ENDHEADER - } # ------------------------------------------ Get Error Message from Environment @@ -720,12 +673,10 @@ ENDHEADER if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) { $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'}; } - unless ($custommenu) { - $r->print('
'); - $r->print(''); - $r->print(''); - $r->print(''); - } + $r->print(''); + $r->print(''); + $r->print(''); + $r->print(''); } my (%roletext,%sortrole,%roleclass,%futureroles,%timezones); @@ -735,35 +686,6 @@ ENDHEADER $refresh = $now; &Apache::lonnet::appenv({'user.refresh.time' => $refresh}); - if (!$countactive && !$countfuture) { - if (&Apache::loncommon::new_roles_update()) { - ($countactive,$countfuture,$inrole,$possiblerole) = - &gather_roles($then,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole, - \%roleclass,\%futureroles,\%timezones); - } - } - if ($custommenu) { - if ($env{'form.destinationurl'} eq '/adm/gci_info') { - $r->print(&gci_info_page()). - &Apache::loncommon::end_page(); - return OK; - } - my %courses = &Apache::loncommon::existing_gcitest_courses('cc'); - $env{'browser.interface'}='faketextual'; - $env{'environment.remote'}='off'; - my $numcourses = keys(%courses); - my $switcher; - if ($numcourses > 0) { - $switcher = &Apache::loncommon::gcitest_switcher('cc',%courses); - } - $r->print(&Apache::lonmenu::inlinemenu('gcicustom',$switcher). - &Apache::loncommon::end_page()); - return OK; - } else { - if ($env{'form.destinationurl'} eq '/adm/gci_info') { - delete($env{'form.destinationurl'}); - } - } if ($env{'user.adv'}) { $r->print('

' - .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]' - .' to view all [_4] LON-CAPA courses and communities.' - ,'' - ,'' - ,'',$domdesc) - .'
' - .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,' + $r->print( + '

' + .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]' + .' to view all [_4] LON-CAPA courses and communities.' + ,'' + ,'' + ,'',$domdesc) + .'
' + .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,' .' you may be able to enroll if self-enrollment is permitted.' ,'','') - .'

' - ); - } + .'

' + ); } } @@ -798,31 +718,13 @@ ENDHEADER if ($inrole) { $r->print('

'.&mt('Currently no additional roles, courses or communities').'

'); } else { - if ($show_course) { - if ($env{'user.domain'} =~ /^\w+citest$/) { - $r->print('

'.&mt('Currently no active Concept Tests').'

'); - } elsif ($env{'user.domain'} =~ /ci$/) { - $r->print('

'.&mt('Currently not assigned as a GCI contributor').'

'); - } - } else { - $r->print('

'.&mt('Currently no active roles, courses or communities').'

'); - } + $r->print('

'.&mt('Currently no active roles, courses or communities').'

'); } - unless ($env{'user.domain'} =~ /^\w+citest$/) { - &findcourse_advice($r); - &requestcourse_advice($r); - } + &findcourse_advice($r); + &requestcourse_advice($r); $r->print('
'); if ($countfuture) { - if ($show_course) { - if ($env{'user.domain'} =~ /^\w+citest$/) { - $r->print(&mt('The following [quant,_1,Concept Test] will be available in the future:',$countfuture)); - } else { - $r->print(&mt('The following [quant,_1,course] will become active in the future:',$countfuture)); - } - } else { - $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture)); - } + $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture)); my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole, $nochoose); &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles, @@ -848,30 +750,16 @@ ENDHEADER } $r->print(&Apache::loncommon::end_page()); return OK; - } elsif ($countactive==1) { # Is there only one choice? - my $needs_switchserver; - if ($env{'user.author'}) { - $needs_switchserver = &check_needs_switchserver($possiblerole); - } - if ((!$needs_switchserver) && ($env{'request.role'} eq 'cm')) { - $r->print('

'.&mt('Please stand by.').'

'. - ''. - ''); - $r->print("\n"); - $r->rflush(); - $r->print(''); - $r->print(&Apache::loncommon::end_page()); - return OK; - } - if ($needs_switchserver) { - $r->print("

".&mt('Server Switch Required')."

\n". - &mt('Construction Space access is only available from '. - 'the home server of the corresponding Author.').'
'. - &mt("Click the 'Switch Server' link to go there.").'
'); - } } # ----------------------------------------------------------------------- Table - unless ((!$show_course) || ($nochoose) || ($countactive==1)) { + + if ($numdc > 0) { + $r->print(&coursepick_jscript()); + $r->print(&Apache::loncommon::coursebrowser_javascript(). + &Apache::loncommon::authorbrowser_javascript()); + } + + unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) { $r->print("

".&mt('Select a Course to Enter')."

\n"); } if ($env{'form.destinationurl'}) { @@ -882,28 +770,29 @@ ENDHEADER $env{'form.destsymb'}.'" />'); } } + my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose); if ($env{'environment.recentroles'}) { my %recent_roles = &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'}); my $output=''; - foreach (sort(keys(%recent_roles))) { - if (ref($roletext{'user.role.'.$_}) eq 'ARRAY') { + foreach my $role (sort(keys(%recent_roles))) { + if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') { $output.= &Apache::loncommon::start_data_table_row(). - $roletext{'user.role.'.$_}->[0]. + $roletext{'user.role.'.$role}->[0]. &Apache::loncommon::end_data_table_row(). &Apache::loncommon::continue_data_table_row(). - $roletext{'user.role.'.$_}->[1]. + $roletext{'user.role.'.$role}->[1]. &Apache::loncommon::end_data_table_row(); - if ($_ =~ m-dc\./($match_domain)/- + if ($role =~ m{dc\./($match_domain)/} && $dcroles{$1}) { $output .= &adhoc_roles_row($1,'recent'); } } elsif ($numdc > 0) { - unless ($_ =~/^error\:/) { + unless ($role =~/^error\:/) { $output.=&display_cc_role('user.role.'.$_); } - } + } } if ($output) { $r->print(&Apache::loncommon::start_data_table_empty_row() @@ -916,12 +805,6 @@ ENDHEADER $doheaders ++; } } - - if ($numdc > 0) { - $r->print(&coursepick_jscript()); - $r->print(&Apache::loncommon::coursebrowser_javascript(). - &Apache::loncommon::authorbrowser_javascript()); - } &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext); if ($countactive > 1) { my $tremark=''; @@ -972,26 +855,6 @@ ENDHEADER return OK; } -sub gci_info_page { - return <<"END"; -
-
-

Welcome to the Geoscience Concept Inventory WebCenter

-

-Use the tabs to navigate the WebCenter and... -

    -
  • Review and comment on existing GCI questions
  • -
  • Submit GCI questions of your own
  • -
  • Create an online test for your students
  • -
  • View tutorials on creating online tests
  • -
-

-

For more information about writing and reviewing Concept Inventory questions -please refer to the GCI Workbook. -

-END -} - sub gather_roles { my ($then,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones) = @_; my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,''); @@ -1064,7 +927,7 @@ sub gather_roles { foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } if (!$allowed) { $button=0; - $switchserver='otherserver='.$home.'&role='.$trolecode; + $switchserver='otherserver='.$home.'&role='.$trolecode; } #next if ($home eq 'no_host'); $home = &Apache::lonnet::hostname($home); @@ -1084,7 +947,7 @@ sub gather_roles { foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } if (!$allowed) { $button=0; - $switchserver='otherserver='.$home.'&role='.$trolecode; + $switchserver='otherserver='.$home.'&role='.$trolecode; } #next if ($home eq 'no_host'); $home = &Apache::lonnet::hostname($home); @@ -1101,6 +964,7 @@ sub gather_roles { if ($env{'course.'.$tcourseid.'.description'}) { $twhere=$env{'course.'.$tcourseid.'.description'}; $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey; + $twhere = &HTML::Entities::encode($twhere,'"<>&'); unless ($twhere eq &mt('Currently not available')) { $twhere.=' '. &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom). @@ -1111,10 +975,10 @@ sub gather_roles { if (%newhash) { $sortkey=$role."\0".$tdom."\0".$newhash{'description'}. "\0".$envkey; - $twhere=$newhash{'description'}. - ' '. - &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom). - ''; + $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&'). + ' '. + &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom). + ''; $ttype = $newhash{'type'}; $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid); } else { @@ -1294,15 +1158,10 @@ sub findcourse_advice { } else { $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.').'
'); } - my $queued = &Apache::loncoursequeueadmin::queued_selfenrollment(); - if ($queued) { - $r->print($queued); - } else { - $r->print(&mt('You have no request for contributor access pending approval by the GCI WebCenter team.').'
    '. - '
  • '.&mt('This may mean that action was taken on your request in the time since your most recent log-in.[_1]View [_2]Message[_3] to see if this is the case.','
    ','','').'
  • '. - '
  • '.&mt('If you logout and log-in again you may find you now have access to the Geoscience Concept Inventory, as a contributor.').'
  • '. - '
'); - } + $r->print('

'.&mt('Self-Enrollment').'

'. + '

'.&mt('The [_1]Course/Community Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created, as well as any communities in the domain.','','',$domdesc).'
'); + $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'

'. + &Apache::loncoursequeueadmin::queued_selfenrollment()); return; } @@ -1777,8 +1636,7 @@ course they should act on, etc. Both in handler determines via C's C<&allowed> function that a certain action is not allowed, C is used as error handler. This allows the user to select another role which may have permission to do -what they were trying to do. C can also be accessed via the -B button in the Remote Control. +what they were trying to do. =begin latex