--- loncom/auth/lonroles.pm 2022/01/16 17:32:44 1.269.2.39.2.2 +++ loncom/auth/lonroles.pm 2022/05/25 18:04:17 1.364 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.269.2.39.2.2 2022/01/16 17:32:44 raeburn Exp $ +# $Id: lonroles.pm,v 1.364 2022/05/25 18:04:17 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -140,10 +140,14 @@ 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; - + +my $registered_cleanup; +my $rosterupdates; + sub start_loading_course { my ($r,$title) = @_; &Apache::loncommon::content_type($r,'text/html'); @@ -177,29 +181,10 @@ ENDREDIR sub finish_loading_course { my ($r,$msg,$url) = @_; - my $link = '
'; + my $link = ' '; my $end_page = &Apache::loncommon::end_page(); my $js_url = &js_escape($url); - my $remote_js; - if ($env{'environment.remote'} eq 'on') { - my ($menucoll,$deeplinkmenu,$menuref) = &Apache::loncommon::menucoll_in_effect(); - if ($menucoll) { - &Apache::lonnet::put('environment',{'remote' => 'off'}); - &Apache::lonnet::appenv({'environment.remote' => 'off'}); - my $menu_name = &Apache::lonmenu::get_menu_name(); - $remote_js = <$msg
"; + } + my $end_page = &Apache::loncommon::end_page(); # Note to style police: # This must only replace the spaces, nothing else, or it bombs elsewhere. $url=~s/ /\%20/g; $r->print(<$msg
$end_page ENDREDIR return; @@ -415,6 +400,8 @@ sub handler { } } + $registered_cleanup=0; + @{$rosterupdates}=(); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); # -------------------------------------------------- Check if setting hot list @@ -448,13 +435,19 @@ sub handler { my $envkey; my %dcroles = (); - my %helpdeskroles = (); - my ($numdc,$numhelpdesk,$numadhoc) = + my %helpdeskroles = (); + my ($numdc,$numhelpdesk,$numadhoc) = &check_for_adhoc(\%dcroles,\%helpdeskroles,$update,$then); my $loncaparev = $r->dir_config('lonVersion'); # ================================================================== Roles Init if ($env{'form.selectrole'}) { + if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq '')) { + if ($env{'form.ltitarget'} eq 'iframe') { + &Apache::lonnet::appenv({'request.lti.target' => 'iframe'}); + delete($env{'form.ltitarget'}); + } + } my $locknum=&Apache::lonnet::get_locks(); if ($locknum) { return 409; } @@ -507,7 +500,7 @@ sub handler { if ($custom_adhoc) { my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum,1); if (ref($possroles) eq 'ARRAY') { - if (grep(/^\Q$rolename\E$/,@{$possroles})) { + if (grep(/^\Q$rolename\E$/,@{$possroles})) { if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now, "cr/$cdom/$cdom".'-domainconfig/'.$rolename,undef,$sec)) { &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time}); @@ -519,8 +512,8 @@ sub handler { # Check if user is a DC trying to enter a course or author space and needs privs to be created # Check if user is a DH or DA trying to enter a course and needs privs to be created foreach my $envkey (keys(%env)) { - if ($numdc) { # Is this an ad-hoc Coordinator role? + if ($numdc) { if (my ($ccrole,$domain,$coursenum) = ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) { if ($dcroles{$domain}) { @@ -611,10 +604,9 @@ sub handler { } last; } - } + } } } - foreach $envkey (keys(%env)) { next if ($envkey!~/^user\.role\./); my ($where,$trolecode,$role,$tstatus,$tend,$tstart); @@ -811,7 +803,7 @@ ENDCLOSE $furl = '/adm/roles?tryagain=1'; } else { &Apache::lonnet::appenv({'request.course.timechecked'=>$now}); - unless (($env{'form.switchrole'}) || + unless (($env{'form.switchrole'}) || ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) { &Apache::lonnet::put('nohist_crslastlogin', {$env{'user.name'}.':'.$env{'user.domain'}. @@ -853,7 +845,7 @@ ENDCLOSE } if (($env{'form.orgurl'}) && ($env{'form.orgurl'}!~/^\/adm\/flip/) && - ($env{'form.orgurl'} ne '/adm/roles')) { + ($env{'form.orgurl'} ne '/adm/roles')) { my $dest=$env{'form.orgurl'}; if ($env{'form.symb'}) { if ($dest =~ /\?/) { @@ -874,14 +866,14 @@ ENDCLOSE } } if (($ferr) && ($tadv)) { - &error_page($r,$ferr,$furl); + &error_page($r,$ferr,$furl); } else { if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { if (($env{'form.orgurl'} ne '') && ($env{'form.symb'} ne '')) { unless (&Apache::lonnet::symbverify($env{'form.symb'},$env{'form.orgurl'})) { $dest=$env{'form.orgurl'}; } - } + } } if ($dest =~ m{^/adm/coursedocs\?folderpath}) { if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { @@ -903,6 +895,13 @@ ENDCLOSE &Apache::loncommon::end_page()); } } else { + if (($env{'request.lti.login'}) && + ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) { + &process_lti($r,$cdom,$cnum); + } + if ($env{'request.deeplink.login'}) { + &set_deeplink_target($cnum,$cdom); + } $msg = ''.&mt('Entering [_1] ...', $env{'course.'.$cdom.'_'.$cnum.'.description'}). '
'; @@ -915,12 +914,12 @@ ENDCLOSE if (!$env{'request.course.id'}) { &Apache::lonnet::appenv( {"request.course.id" => $cdom.'_'.$cnum}); - } + } if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; } &Apache::lonnet::appenv({'request.role.adv'=>$tadv}); - if ($ferr) { + if ($ferr) { if ($tadv) { - &error_page($r,$ferr,$furl); + &error_page($r,$ferr,$furl); } else { $r->print(''. &mt('Could not initialize [_1] at this time.', @@ -930,6 +929,13 @@ ENDCLOSE &Apache::loncommon::end_page()); } } else { + if (($env{'request.lti.login'}) && + ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) { + &process_lti($r,$cdom,$cnum); + } + if ($env{'request.deeplink.login'}) { + &set_deeplink_target($cnum,$cdom); + } # Check to see if the user is a CC entering a course # for the first time if ((($role eq 'cc') || ($role eq 'co')) @@ -937,6 +943,19 @@ ENDCLOSE $furl = "/adm/helper/course.initialization.helper"; # Send the user to the course they selected } elsif ($env{'request.course.id'}) { + 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)) { + $msg = '
'.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '
'; + &finish_loading_course($r,$msg,'/adm/placement'); + $r->rflush(); + return OK; + } + } my ($dest,$destsymb,$checkenc); $dest = $env{'form.destinationurl'}; $destsymb = $env{'form.destsymb'}; @@ -965,7 +984,7 @@ ENDCLOSE if ($env{'request.role.adv'}) { $dest = &Apache::lonenc::unencrypted($dest); if ($destsymb eq '') { - ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); + ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); $destsymb = &unescape($destsymb); } } @@ -990,18 +1009,20 @@ ENDCLOSE } } } - unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { + unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) { my $esc_symb = &escape($destsymb); $dest .= (($dest =~/\?/)? '&':'?').'symb='.$esc_symb; } } - $msg = ''.&mt('Entering [_1] ...', - $env{'course.'.$cdom.'_'.$cnum.'.description'}). - '
'; if ($env{'form.ttoken'}) { $dest .= (($dest =~/\?/)? '&':'?').'ttoken='.$env{'form.ttoken'}; } + unless ($env{'request.lti.login'}) { + $msg = ''.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '
'; + } &finish_loading_course($r,$msg,$dest); $r->rflush(); return OK; @@ -1019,18 +1040,18 @@ ENDCLOSE ''; &finish_loading_course($r,$msg,'/adm/whatsnew?refpage=start'); $r->rflush(); - return OK; + return OK; } } } # Are we allowed to look at the first resource? # # $furl returned by lonuserstate::readmap() has format: - # $url?symb=escaped($symb). If the resource has the + # $url?symb=escaped($symb). If the resource has the # encrypturl parameter in effect, the entire string # $url?symb=escaped($symb) is encrypted as a string # beginning /enc/. - # + # my ($access,$unencfurl,$unencsymb); if ($furl =~ m{^(.+)(?:\?|\&)symb=([^&]+)(?:$|&)}) { my ($poss_url,$poss_symb) = ($1,$2); @@ -1063,13 +1084,18 @@ ENDCLOSE $furl = '/adm/navmaps?showOnlyHomework=1'; } } - $msg = ''.&mt('Entering [_1] ...', - $env{'course.'.$cdom.'_'.$cnum.'.description'}). - '
'; - &finish_loading_course($r,$msg,$furl); + if ($env{'request.lti.login'}) { + undef($msg); + &finish_loading_course($r,$msg,$furl); + } else { + $msg = ''.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '
'; + &finish_loading_course($r,$msg,$furl); + } } $r->rflush(); - return OK; + return OK; } } # @@ -1149,16 +1175,42 @@ ENDCLOSE if ($domdefs{'catauth'}) { $cattype = $domdefs{'catauth'}; } - my ($funcs,$crumbsright); - unless (($norolelist) && ((split(/:/,$env{'user.error.msg'}))[2])) { - $funcs = &get_roles_functions($showcount,$cattype); - if ($env{'browser.mobile'}) { - $crumbsright = $funcs; - undef($funcs); + 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 { + my $crumbsright; + unless (($norolelist) && ((split(/:/,$env{'user.error.msg'}))[2])) { + $funcs = &get_roles_functions($showcount,$cattype); + if ($env{'browser.mobile'}) { + $crumbsright = $funcs; + undef($funcs); + } } + $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum, + bread_crumbs_component=>$crumbsright}); } - my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum, - bread_crumbs_component=>$crumbsright}); &js_escape(\$standby); my $noscript=''.&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'
'); @@ -1907,7 +2002,7 @@ sub findcourse_advice { $r->print(''.&mt('You may also have been assigned to a course in the time since you last logged-in, or checked for changes.').
'
'.
&mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'