--- loncom/auth/lonroles.pm 2010/06/02 14:49:38 1.247 +++ loncom/auth/lonroles.pm 2016/05/04 05:14:49 1.314 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.247 2010/06/02 14:49:38 raeburn Exp $ +# $Id: lonroles.pm,v 1.314 2016/05/04 05:14:49 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -128,7 +128,7 @@ package Apache::lonroles; use strict; use Apache::lonnet; use Apache::lonuserstate(); -use Apache::Constants qw(:common); +use Apache::Constants qw(:common REDIRECT); use Apache::File(); use Apache::lonmenu; use Apache::loncommon; @@ -138,10 +138,13 @@ use Apache::lonlocal; use Apache::lonpageflip(); use Apache::lonnavdisplay(); use Apache::loncoursequeueadmin; +use Apache::longroup; +use Apache::lonrss; +use Apache::lonplacementtest; use GDBM_File; use LONCAPA qw(:DEFAULT :match); use HTML::Entities; - + sub redirect_user { my ($r,$title,$url,$msg) = @_; @@ -200,16 +203,60 @@ sub handler { my $r = shift; + # Check for critical messages and redirect if present. + my ($redirect,$url) = &Apache::loncommon::critical_redirect(300); + if ($redirect) { + &Apache::loncommon::content_type($r,'text/html'); + $r->header_out(Location => $url); + return REDIRECT; + } + my $now=time; my $then=$env{'user.login.time'}; my $refresh=$env{'user.refresh.time'}; + my $update=$env{'user.update.time'}; if (!$refresh) { $refresh = $then; } + if (!$update) { + $update = $then; + } + + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); + +# -------------------------------------------------- Check if setting hot list + my $hotlist; + if ($env{'form.action'} eq 'verify_and_change_rolespref') { + $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r); + } + +# -------------------------------------------------------- Check for new roles + my $updateresult; + if ($env{'form.state'} eq 'doupdate') { + my $show_course=&Apache::loncommon::show_course(); + my $checkingtxt; + if ($show_course) { + $checkingtxt = &mt('Checking for new courses ...'); + } else { + $checkingtxt = &mt('Checking for new roles ...'); + } + $updateresult = $checkingtxt; + $updateresult .= &update_session_roles(); + &Apache::lonnet::appenv({'user.update.time' => $now}); + $update = $now; + &Apache::loncoursequeueadmin::reqauthor_check(); + } + +# -------------------------------------------------- Check for author requests + my $reqauthor; + if ($env{'form.state'} eq 'requestauthor') { + $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update); + } + my $envkey; my %dcroles = (); - my $numdc = &check_fordc(\%dcroles,$then); - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); + my $numdc = &check_fordc(\%dcroles,$update,$then); + my $loncaparev = $r->dir_config('lonVersion'); # ================================================================== Roles Init if ($env{'form.selectrole'}) { @@ -223,30 +270,43 @@ 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'}})) { - &adhoc_course_role($refresh,$then); + 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 < $update) { + $switch_is_active = 1; + } + } + } + unless ($switch_is_active) { + &adhoc_course_role($refresh,$update,$then); } } my %temp=('logout_'.$env{'request.course.id'} => time); &Apache::lonnet::put('email_status',\%temp); &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'}); } - &Apache::lonnet::appenv({"request.course.id" => '', - "request.course.fn" => '', - "request.course.uri" => '', - "request.course.sec" => '', - "request.role" => 'cm', - "request.role.adv" => $env{'user.adv'}, - "request.role.domain" => $env{'user.domain'}}); + &Apache::lonnet::appenv({"request.course.id" => '', + "request.course.fn" => '', + "request.course.uri" => '', + "request.course.sec" => '', + "request.course.tied" => '', + "request.course.timechecked" => '', + "request.role" => 'cm', + "request.role.adv" => $env{'user.adv'}, + "request.role.domain" => $env{'user.domain'}}); # Check if user is a DC trying to enter a course or author space and needs privs to be created if ($numdc > 0) { - foreach my $envkey (keys %env) { + foreach my $envkey (keys(%env)) { # Is this an ad-hoc Coordinator role? if (my ($ccrole,$domain,$coursenum) = ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) { if ($dcroles{$domain}) { - &Apache::lonnet::check_adhoc_privs($domain,$coursenum, - $then,$refresh,$now,$ccrole); + if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum, + $update,$refresh,$now,$ccrole)) { + &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time}); + } } last; } @@ -259,8 +319,9 @@ 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); + return OK; } last; } @@ -270,8 +331,9 @@ 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); + return OK; } last; } @@ -286,13 +348,14 @@ sub handler { if ($dcroles{$domain}) { my ($server_status,$home) = &check_author_homeserver($user,$domain); if (($server_status eq 'ok') || ($server_status eq 'switchserver')) { - &Apache::lonnet::check_adhoc_privs($domain,$user,$then, + &Apache::lonnet::check_adhoc_privs($domain,$user,$update, $refresh,$now,'ca'); 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); + return OK; } } else { delete($env{$envkey}); @@ -305,15 +368,34 @@ sub handler { } } - foreach $envkey (keys %env) { + foreach $envkey (keys(%env)) { next if ($envkey!~/^user\.role\./); my ($where,$trolecode,$role,$tstatus,$tend,$tstart); - &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where, + &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where, \$trolecode,\$tstatus,\$tstart,\$tend); if ($env{'form.'.$trolecode}) { 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) = + &Apache::loncommon::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; + $r->print(&Apache::loncommon::check_release_result($switchwarning,$switchserver)); + return OK; + } + } + } + } # check for course groups my %coursegroups = &Apache::lonnet::get_active_groups( $env{'user.domain'},$env{'user.name'},$cdom, $cnum); @@ -433,14 +515,37 @@ ENDENTERKEY my $msg; my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum); + unless ($ferr) { + unless (($env{'form.switchrole'}) || + ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) { + &Apache::lonnet::put('nohist_crslastlogin', + {$env{'user.name'}.':'.$env{'user.domain'}. + ':'.$csec.':'.$role => $now},$cdom,$cnum); + } + my ($feeds,$syllabus_time); + &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds); + &Apache::lonnet::appenv({'request.course.feeds' => $feeds}); + &Apache::lonnet::get_numsuppfiles($cnum,$cdom,1); + unless ($env{'course.'.$cdom.'_'.$cnum.'.updatedsyllabus'}) { + unless (($env{'course.'.$cdom.'_'.$cnum.'.externalsyllabus'}) || + ($env{'course.'.$cdom.'_'.$cnum.'.uploadedsyllabus'})) { + my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum); + $syllabus_time = $syllabus{'uploaded.lastmodified'}; + if ($syllabus_time) { + &Apache::lonnet::appenv({'request.course.syllabustime' => $syllabus_time}); + } + } + } + } if (($env{'form.orgurl'}) && - ($env{'form.orgurl'}!~/^\/adm\/flip/)) { + ($env{'form.orgurl'}!~/^\/adm\/flip/) && + ($env{'form.orgurl'} ne '/adm/roles')) { my $dest=$env{'form.orgurl'}; if ($env{'form.symb'}) { if ($dest =~ /\?/) { $dest .= '&'; } else { - $dest .= '?' + $dest .= '?'; } $dest .= 'symb='.$env{'form.symb'}; } @@ -449,6 +554,13 @@ ENDENTERKEY if (($ferr) && ($tadv)) { &error_page($r,$ferr,$dest); } else { + if ($dest =~ m{^/adm/coursedocs\?folderpath}) { + if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { + my $chome = &Apache::lonnet::homeserver($cnum,$cdom); + &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome, + $cdom.'_'.$cnum); + } + } $r->internal_redirect($dest); } return OK; @@ -472,24 +584,71 @@ ENDENTERKEY } else { # Check to see if the user is a CC entering a course # for the first time - my (undef, undef, $role, $courseid) = split(/\./, $envkey); - if (substr($courseid, 0, 1) eq '/') { - $courseid = substr($courseid, 1); - } - $courseid =~ s/\//_/; if ((($role eq 'cc') || ($role eq 'co')) - && ($env{'course.' . $courseid .'.course.helper.not.run'})) { + && ($env{'course.'.$cdom.'_'.$cnum.'.course.helper.not.run'})) { $furl = "/adm/helper/course.initialization.helper"; # Send the user to the course they selected } elsif ($env{'request.course.id'}) { - if ($env{'form.destinationurl'}) { - my $dest = $env{'form.destinationurl'}; - if ($env{'form.destsymb'} ne '') { - my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&'); - $dest .= '?symb='.$esc_symb; + if ((&Apache::loncommon::course_type() eq 'Placement') && + (!$env{'request.role.adv'})) { + my ($score,$incomplete) = + &Apache::lonplacementtest::check_completion(undef,undef,1); + if (($incomplete) && ($incomplete < 100)) { + &redirect_user($r, &mt('Entering [_1]', + $env{'course.'.$cdom.'_'.$cnum.'.description'}), + '/adm/placement', $msg); + return OK; + } + } + my ($dest,$destsymb,$checkenc); + $dest = $env{'form.destinationurl'}; + $destsymb = $env{'form.destsymb'}; + if ($dest ne '') { + if ($env{'form.switchrole'}) { + if ($destsymb ne '') { + if ($destsymb !~ m{^/enc/}) { + unless ($env{'request.role.adv'}) { + $checkenc = 1; + } + } + } + if ($dest =~ m{^/enc/}) { + if ($env{'request.role.adv'}) { + $dest = &Apache::lonenc::unencrypted($dest); + if ($destsymb eq '') { + ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); + $destsymb = &unescape($destsymb); + } + } + } else { + if ($destsymb eq '') { + ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]+)/); + $destsymb = &unescape($destsymb); + } + unless ($env{'request.role.adv'}) { + $checkenc = 1; + } + } + if (($checkenc) && ($destsymb ne '')) { + my ($encstate,$unencsymb,$res); + $unencsymb = &Apache::lonnet::symbclean($destsymb); + (undef,undef,$res) = &Apache::lonnet::decode_symb($unencsymb); + &Apache::lonnet::symbverify($unencsymb,$res,\$encstate); + if ($encstate) { + if (($dest ne '') && ($dest !~ m{^/enc/})) { + $dest=&Apache::lonenc::encrypted($dest); + } + } + } + } + unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { + if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) { + my $esc_symb = &escape($destsymb); + $dest .= '?symb='.$esc_symb; + } } &redirect_user($r, &mt('Entering [_1]', - $env{'course.'.$courseid.'.description'}), + $env{'course.'.$cdom.'_'.$cnum.'.description'}), $dest, $msg); return OK; } @@ -499,25 +658,39 @@ ENDENTERKEY $env{'request.course.id'}.'/' .$env{'request.course.sec'}) ) { - my $startpage = &courseloadpage($courseid); + my $startpage = &courseloadpage($env{'request.course.id'}); unless ($startpage eq 'firstres') { $msg = &mt('Entering [_1] ...', - $env{'course.'.$courseid.'.description'}); + $env{'course.'.$env{'request.course.id'}.'.description'}); &redirect_user($r, &mt('New in course'), '/adm/whatsnew?refpage=start', $msg); return OK; } } } -# Are we allowed to look at the first resource? - if ($furl !~ m|^/adm/|) { -# Guess not ... - $furl=&Apache::lonpageflip::first_accessible_resource(); - } + # Are we allowed to look at the first resource? + my $access; + if ($furl =~ m{^(/adm/wrapper|)/ext/}) { + # If it's an external resource, + # strip off the symb argument and possible query + my ($exturl,$symb) = ($furl =~ m{^(.+)(?:\?|\&)symb=(.+)$}); + # Unencode $symb + $symb = &unescape($symb); + # Then check for permission + $access = &Apache::lonnet::allowed('bre',$exturl,$symb); + # For other resources just check for permission + } else { + $access = &Apache::lonnet::allowed('bre',$furl); + } + if (!$access) { + $furl = &Apache::lonpageflip::first_accessible_resource(); + } elsif ($access eq 'B') { + $furl = '/adm/navmaps?showOnlyHomework=1'; + } $msg = &mt('Entering [_1] ...', - $env{'course.'.$courseid.'.description'}); + $env{'course.'.$cdom.'_'.$cnum.'.description'}); &redirect_user($r, &mt('Entering [_1]', - $env{'course.'.$courseid.'.description'}), + $env{'course.'.$cdom.'_'.$cnum.'.description'}), $furl, $msg); } return OK; @@ -528,13 +701,12 @@ ENDENTERKEY if ($role =~ /^(au|ca|aa)$/) { my $redirect_url = '/priv/'; if ($role eq 'au') { - $redirect_url.=$env{'user.name'}; + $redirect_url.=$env{'user.domain'}.'/'.$env{'user.name'}; } else { - $where =~ /\/(.*)$/; - $redirect_url .= $1; + $redirect_url .= $where; } $redirect_url .= '/'; - &redirect_user($r,&mt('Entering Construction Space'), + &redirect_user($r,&mt('Entering Authoring Space'), $redirect_url); return OK; } @@ -566,22 +738,65 @@ ENDENTERKEY my $crumbtext = 'User Roles'; my $pagetitle = 'My Roles'; my $recent = &mt('Recent Roles'); + my $standby = &mt('Role selected. Please stand by.'); my $show_course=&Apache::loncommon::show_course(); 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 %roles_in_env; + my $showcount = &roles_from_env(\%roles_in_env,$update); + 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.').'

'; + my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'}); + my $cattype = 'std'; + if ($domdefs{'catauth'}) { + $cattype = $domdefs{'catauth'}; + } + my $placementonly; + if ($showcount == 1) { + if ($env{'request.course.id'}) { + if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') { + $placementonly = 1; + } + } else { + foreach my $rolecode (keys(%roles_in_env)) { + my ($cid) = ($rolecode =~ m{^\Quser.role.st./\E($match_domain/$match_courseid)(?:/|$)}); + if ($cid) { + my %coursedescription = + &Apache::lonnet::coursedescription($cid,{'one_time' => '1'}); + if ($coursedescription{'type'} eq 'Placement') { + $placementonly = 1; + } + last; + } + } + } + } + my ($start_page,$funcs); + if ($placementonly) { + $start_page=&Apache::loncommon::start_page($pagetitle,undef, + {bread_crumbs=>$brcrum,crstype=>'Placement'}); + } else { + $funcs = &get_roles_functions($showcount,$cattype); + my $crumbsright; + if ($env{'browser.mobile'}) { + $crumbsright = $funcs; + undef($funcs); + } + $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum, + bread_crumbs_component=>$crumbsright}); + } + &js_escape(\$standby); + 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(< +$funcs @@ -601,8 +816,22 @@ function enterrole (thisform,rolecode,bu thisform.submit(); } else { alert('$standby'); - } + } } + +function rolesView (caller) { + if ((caller == 'showall') || (caller == 'noshowall')) { + document.rolechoice.display.value = caller; + } else { + if ((caller == 'doupdate') || (caller == 'requestauthor') || + (caller == 'queued')) { + document.rolechoice.state.value = caller; + } + } + document.rolechoice.selectrole.value=''; + document.rolechoice.submit(); +} + // ]]> ENDHEADER @@ -663,47 +892,74 @@ ENDHEADER } } } -# -------------------------------------------------------- Choice or no choice? if ($nochoose) { $r->print("

".&mt('Sorry ...')."

\n". &mt('This action is currently not authorized.').''. &Apache::loncommon::end_page()); return OK; } else { + if ($updateresult || $reqauthor || $hotlist) { + my $showresult = '
'; + if ($updateresult) { + $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult); + } + if ($reqauthor) { + $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor); + } + if ($hotlist) { + $showresult .= $hotlist; + } + $showresult .= '
'; + $r->print($showresult); + } elsif ($env{'form.state'} eq 'queued') { + $r->print(&get_queued()); + } if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) { $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'}; } + my $display = ($env{'form.display'} =~ /^(showall)$/); $r->print('
'); $r->print(''); $r->print(''); $r->print(''); + $r->print(''); + $r->print(''); } + $r->rflush(); my (%roletext,%sortrole,%roleclass,%futureroles,%timezones); my ($countactive,$countfuture,$inrole,$possiblerole) = - &gather_roles($then,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass, - \%futureroles,\%timezones); - + &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext, + \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev); $refresh = $now; &Apache::lonnet::appenv({'user.refresh.time' => $refresh}); - if ($env{'user.adv'}) { - $r->print('

' - .' ' - .'

'); - } else { + if ($countactive == 1) { + if ($env{'request.course.id'}) { + if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') { + $placementonly = 1; + } + } elsif ($possiblerole) { + if ($possiblerole =~ m{^st\./($match_domain)/($match_courseid)(?:/|$)}) { + if ($env{'course.'.$1.'_'.$2.'.type'} eq 'Placement') { + $placementonly = 1; + } + } + } + } + if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'}) && + (!$placementonly)) { if ($countactive > 0) { - $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment()); my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); $r->print( '

' - .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]' - .' to view all [_4] LON-CAPA courses and communities.' + .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]' + .' to view all [_5] LON-CAPA courses and communities.' ,'' ,'' - ,'',$domdesc) + ,'' + ,'' + ,'"'.$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.' @@ -715,13 +971,7 @@ ENDHEADER # No active roles if ($countactive==0) { - if ($inrole) { - $r->print('

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

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

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

'); - } - &findcourse_advice($r); - &requestcourse_advice($r); + &requestcourse_advice($r,$cattype,$inrole); $r->print('
'); if ($countfuture) { $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture)); @@ -750,6 +1000,16 @@ ENDHEADER } $r->print(&Apache::loncommon::end_page()); return OK; + } elsif (($placementonly) && ($env{'request.role'} eq 'cm')) { + $r->print('

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

+ + '); + $r->rflush(); + $r->print(''); + $r->print(&Apache::loncommon::end_page()); + return OK; } # ----------------------------------------------------------------------- Table @@ -780,17 +1040,29 @@ ENDHEADER if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') { $output.= &Apache::loncommon::start_data_table_row(). $roletext{'user.role.'.$role}->[0]. - &Apache::loncommon::end_data_table_row(). - &Apache::loncommon::continue_data_table_row(). - $roletext{'user.role.'.$role}->[1]. &Apache::loncommon::end_data_table_row(); + if ($roletext{'user.role.'.$role}->[1] ne '') { + $output .= &Apache::loncommon::continue_data_table_row(). + $roletext{'user.role.'.$role}->[1]. + &Apache::loncommon::end_data_table_row(); + } if ($role =~ m{dc\./($match_domain)/} && $dcroles{$1}) { $output .= &adhoc_roles_row($1,'recent'); } } elsif ($numdc > 0) { unless ($role =~/^error\:/) { - $output.=&display_cc_role('user.role.'.$_); + my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role); + if ($roletext) { + $output.= &Apache::loncommon::start_data_table_row(). + $roletext. + &Apache::loncommon::end_data_table_row(); + if ($role_text_end) { + $output .= &Apache::loncommon::continue_data_table_row(). + $role_text_end. + &Apache::loncommon::end_data_table_row(); + } + } } } } @@ -840,45 +1112,60 @@ ENDHEADER $r->print('

'.&mt('Current Privileges').'

'); $r->print(&privileges_info()); } - $r->print(&Apache::lonnet::getannounce()); + my $announcements = &Apache::lonnet::getannounce(); + $r->print( + '
'. + '

'.&mt('Announcements').'

'. + $announcements + ) unless (!$announcements); if ($advanced) { my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); $r->print('

' .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion')) - .'
' - .''.&mt('Logout').'  ' - .'' - .&mt('Course/Community Catalog') - .'

'); + .'

'); } $r->print(&Apache::loncommon::end_page()); return OK; } +sub roles_from_env { + my ($roleshash,$update) = @_; + my $count = 0; + if (ref($roleshash) eq 'HASH') { + foreach my $envkey (keys(%env)) { + if ($envkey =~ m{^user\.role\.(\w+)[./]}) { + next if ($1 eq 'gr'); + $roleshash->{$envkey} = $env{$envkey}; + my ($start,$end) = split(/\./,$env{$envkey}); + unless ($end && $end<$update) { + $count ++; + } + } + } + } + return $count; +} + sub gather_roles { - my ($then,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones) = @_; + my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles, + $timezones,$loncaparev) = @_; my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,''); my $advanced = $env{'user.adv'}; my $tryagain = $env{'form.tryagain'}; - foreach my $envkey (sort(keys(%env))) { - my $button = 1; - my $switchserver=''; - my ($role_text,$role_text_end,$sortkey); - if ($envkey=~/^user\.role\./) { - my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend); - &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where, + my @ids = &Apache::lonnet::current_machine_ids(); + if (ref($roles_in_env) eq 'HASH') { + foreach my $envkey (sort(keys(%{$roles_in_env}))) { + my $button = 1; + my $switchserver=''; + my $switchwarning; + my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart, + $tend,$tremark,$tstatus,$tpstart,$tpend); + &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where, \$trolecode,\$tstatus,\$tstart,\$tend); next if (!defined($role) || $role eq '' || $role =~ /^gr/); - my $timezone = &role_timezone($where,$timezones); $tremark=''; $tpstart=' '; $tpend=' '; - if ($tstart) { - $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone); - } - if ($tend) { - $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone); - } if ($env{'request.role'} eq $trolecode) { $tstatus='selected'; } @@ -886,7 +1173,14 @@ sub gather_roles { if (($tstatus eq 'is') || ($tstatus eq 'selected') || ($tstatus eq 'future') - || ($env{'form.showall'})) { + || ($env{'form.display'} eq 'showall')) { + my $timezone = &role_timezone($where,$timezones); + if ($tstart) { + $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone); + } + if ($tend) { + $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone); + } if ($tstatus eq 'is') { $tbg='LC_roles_is'; $possiblerole=$trolecode; @@ -912,26 +1206,26 @@ sub gather_roles { if ($role =~ /^cr\//) { my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role); if ($tremark) { $tremark.='
'; } - $tremark.=&mt('Defined by [_1] at [_2].',$rauthor,$rdomain); + $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain); } $trole=Apache::lonnet::plaintext($role); my $ttype; my $twhere; + my $skipcal; my ($tdom,$trest,$tsection)= split(/\//,Apache::lonnet::declutter($where)); # First, Co-Authorship roles if (($role eq 'ca') || ($role eq 'aa')) { my $home = &Apache::lonnet::homeserver($trest,$tdom); my $allowed=0; - my @ids=&Apache::lonnet::current_machine_ids(); 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); - $ttype='Construction Space'; + $ttype='Authoring Space'; $twhere=&mt('User').': '.$trest.'
'.&mt('Domain'). ': '.$tdom.'
'. ' '.&mt('Server').': '.$home; @@ -943,15 +1237,14 @@ sub gather_roles { my $home = &Apache::lonnet::homeserver ($env{'user.name'},$env{'user.domain'}); my $allowed=0; - my @ids=&Apache::lonnet::current_machine_ids(); 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); - $ttype='Construction Space'; + $ttype='Authoring Space'; $twhere=&mt('Domain').': '.$tdom.'
'.&mt('Server'). ': '.$home; $env{'course.'.$tdom.'_'.$trest.'.description'}='ca'; @@ -962,31 +1255,58 @@ sub gather_roles { $ttype = &Apache::loncommon::course_type($tcourseid); $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid); if ($env{'course.'.$tcourseid.'.description'}) { + my $home=$env{'course.'.$tcourseid.'.home'}; $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). ''; + unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') { + my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'}; + if ($required ne '') { + ($switchserver,$switchwarning) = + &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required); + if ($switchserver || $switchwarning) { + $button = 0; + } + } + } } } else { my %newhash=&Apache::lonnet::coursedescription($tcourseid); 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); + my $home = $newhash{'home'}; + unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') { + my $required = $newhash{'internal.releaserequired'}; + if ($required ne '') { + ($switchserver,$switchwarning) = + &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required); + if ($switchserver || $switchwarning) { + $button = 0; + } + } + } } else { $twhere=&mt('Currently not available'); $env{'course.'.$tcourseid.'.description'}=$twhere; $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey; $ttype = 'Unavailable'; + $skipcal = 1; } } + if ($ttype eq 'Placement') { + $ttype = 'Placement Test'; + } if ($tsection) { $twhere.='
'.&mt('Section').': '.$tsection; } @@ -1003,7 +1323,8 @@ sub gather_roles { ($role_text,$role_text_end) = &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain, $advanced,$tremark,$tbg,$trole,$twhere,$tpstart, - $tpend,$nochoose,$button,$switchserver,$reinit); + $tpend,$nochoose,$button,$switchserver,$reinit, + $switchwarning,$skipcal); $roletext->{$envkey}=[$role_text,$role_text_end]; if (!$sortkey) {$sortkey=$twhere."\0".$envkey;} $sortrole->{$sortkey}=$envkey; @@ -1023,9 +1344,15 @@ sub role_timezone { my $cnum = $2; if ($cdom && $cnum) { if (!exists($timezones->{$cdom.'_'.$cnum})) { - my %timehash = - &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum); - if ($timehash{'timezone'} eq '') { + my $tz; + if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) { + $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'}; + } else { + my %timehash = + &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum); + $tz = $timehash{'timezone'}; + } + if ($tz eq '') { if (!exists($timezones->{$cdom})) { my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom); @@ -1038,7 +1365,7 @@ sub role_timezone { $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom}; } else { $timezones->{$cdom.'_'.$cnum} = - &Apache::lonlocal::gettimezone($timehash{'timezone'}); + &Apache::lonlocal::gettimezone($tz); } } $timezone = $timezones->{$cdom.'_'.$cnum}; @@ -1069,7 +1396,7 @@ sub roletable_headers { my $doheaders; if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) { $r->print('
' - .&Apache::loncommon::start_data_table() + .&Apache::loncommon::start_data_table('LC_textsize_mobile') .&Apache::loncommon::start_data_table_header_row() ); if (!$nochoose) { $r->print(' '); } @@ -1095,7 +1422,7 @@ sub roletable_headers { } sub roletypes { - my @types = ('Domain','Construction Space','Course','Community','Unavailable','System'); + my @types = ('Domain','Authoring Space','Course','Placement Test','Community','Unavailable','System'); return @types; } @@ -1111,10 +1438,12 @@ sub print_rolerows { if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') { $output.= &Apache::loncommon::start_data_table_row(). $roletext->{$sortrole->{$which}}->[0]. - &Apache::loncommon::end_data_table_row(). - &Apache::loncommon::continue_data_table_row(). - $roletext->{$sortrole->{$which}}->[1]. &Apache::loncommon::end_data_table_row(); + if ($roletext->{$sortrole->{$which}}->[1] ne '') { + $output .= &Apache::loncommon::continue_data_table_row(). + $roletext->{$sortrole->{$which}}->[1]. + &Apache::loncommon::end_data_table_row(); + } } if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) { if (ref($dcroles) eq 'HASH') { @@ -1142,7 +1471,7 @@ sub print_rolerows { } sub findcourse_advice { - my ($r) = @_; + my ($r,$cattype) = @_; my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) { @@ -1157,37 +1486,36 @@ 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.').'
'); } - $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()); + if (($cattype eq 'std') || ($cattype eq 'domonly')) { + $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; } sub requestcourse_advice { - my ($r) = @_; + my ($r,$cattype,$inrole) = @_; my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); - my (%can_request,%request_doms); + my (%can_request,%request_doms,$output); &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms); if (keys(%request_doms) > 0) { my ($types,$typename) = &Apache::loncommon::course_types(); if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) { - $r->print('

'.&mt('Request creation of a course or community').'

'. - '

'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'

'.&mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.','','').'

'); + } + if ($output) { + $r->print('

'.&mt('Request creation of a course or community').'

'. + '

'. + &mt('You have rights to request the creation of courses and/or communities in the following domain(s):'). + '

'. + &mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.', + '',''). + '

'); + } } + } elsif (!$env{'user.adv'}) { + if ($inrole) { + $r->print('

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

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

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

'); + } + &findcourse_advice($r,$cattype); } return; } @@ -1232,7 +1577,7 @@ sub privileges_info { my (undef,$tdom,$trest,$tsec)=split(m{/},$where); if ($trest) { if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') { - $ttype='Construction Space'; + $ttype='Authoring Space'; $twhere='User: '.$trest.', Domain: '.$tdom; } else { $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest); @@ -1273,7 +1618,8 @@ sub privileges_info { } sub build_roletext { - my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit) = @_; + my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere, + $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning,$skipcal) = @_; my ($roletext,$roletext_end); my $is_dc=($trolecode =~ m/^dc\./); my $rowspan=($is_dc) ? '' @@ -1291,6 +1637,13 @@ sub build_roletext { } else { $roletext.=(' '); } + if ($switchwarning) { + if ($tremark eq '') { + $tremark = $switchwarning; + } else { + $tremark .= '
'.$switchwarning; + } + } } elsif ($tstatus eq 'is') { $roletext.=''. ''; } } - if ($trolecode !~ m/^(dc|ca|au|aa)\./) { + if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) { $tremark.=&Apache::lonannounce::showday(time,1, &Apache::lonannounce::readcalendar($tdom.'_'.$trest)); } @@ -1338,24 +1691,6 @@ sub build_roletext { return ($roletext,$roletext_end); } -sub check_needs_switchserver { - my ($possiblerole) = @_; - my $needs_switchserver; - my ($role,$where) = split(/\./,$possiblerole,2); - my (undef,$tdom,$twho) = split(/\//,$where); - my ($server_status,$home); - if (($role eq 'ca') || ($role eq 'aa')) { - ($server_status,$home) = &check_author_homeserver($twho,$tdom); - } else { - ($server_status,$home) = &check_author_homeserver($env{'user.name'}, - $env{'user.domain'}); - } - if ($server_status eq 'switchserver') { - $needs_switchserver = 1; - } - return $needs_switchserver; -} - sub check_author_homeserver { my ($uname,$udom)=@_; if (($uname eq '') || ($udom eq '')) { @@ -1374,16 +1709,20 @@ sub check_author_homeserver { } sub check_fordc { - my ($dcroles,$then) = @_; + my ($dcroles,$update,$then) = @_; my $numdc = 0; if ($env{'user.adv'}) { - foreach my $envkey (sort keys %env) { + foreach my $envkey (sort(keys(%env))) { if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) { my $dcdom = $1; my $livedc = 1; my ($tstart,$tend)=split(/\./,$env{$envkey}); - if ($tstart && $tstart>$then) { $livedc = 0; } - if ($tend && $tend <$then) { $livedc = 0; } + my $limit = $update; + if ($env{'request.role'} eq 'dc./'.$dcdom.'/') { + $limit = $then; + } + if ($tstart && $tstart>$limit) { $livedc = 0; } + if ($tend && $tend <$limit) { $livedc = 0; } if ($livedc) { $$dcroles{$dcdom} = $envkey; $numdc++; @@ -1395,24 +1734,29 @@ sub check_fordc { } sub adhoc_course_role { - my ($refresh,$then) = @_; + my ($refresh,$update,$then) = @_; my ($cdom,$cnum,$crstype); $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; $crstype = &Apache::loncommon::course_type(); - if (&check_forcc($cdom,$cnum,$refresh,$then,$crstype)) { + if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) { my $setprivs; if (!defined($env{'user.role.'.$env{'form.switchrole'}})) { $setprivs = 1; } else { my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}}); if (($start && ($start>$refresh || $start == -1)) || - ($end && $end<$then)) { + ($end && $end<$update)) { + $setprivs = 1; + } + } + unless ($setprivs) { + if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) { $setprivs = 1; } } if ($setprivs) { - if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) { + if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)(.*?)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) { my $role = $1; my $custom_role = $2; my $usec = $3; @@ -1438,7 +1782,11 @@ sub adhoc_course_role { $spec .= '/'.$usec; $area .= '/'.$usec; } - &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area); + if ($role =~ /^cr/) { + &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area); + } else { + &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area); + } &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups); my $adhocstart = $refresh-1; $userroles{'user.role.'.$spec} = $adhocstart.'.'; @@ -1450,22 +1798,24 @@ sub adhoc_course_role { } sub check_forcc { - my ($cdom,$cnum,$refresh,$then,$crstype) = @_; + my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_; my ($is_cc,$ccrole); if ($crstype eq 'Community') { $ccrole = 'co'; } else { $ccrole = 'cc'; } - if ($cdom ne '' && $cnum ne '') { - if (&Apache::lonnet::is_course($cdom,$cnum)) { - my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum; - if (defined($env{$envkey})) { - $is_cc = 1; - my ($tstart,$tend)=split(/\./,$env{$envkey}); - if ($tstart && $tstart>$refresh) { $is_cc = 0; } - if ($tend && $tend <$then) { $is_cc = 0; } + if (&Apache::lonnet::is_course($cdom,$cnum)) { + my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum; + if (defined($env{$envkey})) { + $is_cc = 1; + my ($tstart,$tend)=split(/\./,$env{$envkey}); + my $limit = $update; + if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) { + $limit = $then; } + if ($tstart && $tstart>$refresh) { $is_cc = 0; } + if ($tend && $tend <$limit) { $is_cc = 0; } } } return $is_cc; @@ -1485,10 +1835,11 @@ sub courselink { } sub coursepick_jscript { - my %lt = &Apache::lonlocal::texthash( + my %js_lt = &Apache::lonlocal::texthash( plsu => "Please use the 'Select Course/Community' link to open a separate pick course window where you may select the course or community you wish to enter.", youc => 'You can only use this screen to select courses and communities in the current domain.', ); + &js_escape(\%js_lt); my $verify_script = <<"END";