--- loncom/auth/lonroles.pm 2024/09/07 01:49:32 1.269.2.39.2.10 +++ loncom/auth/lonroles.pm 2023/06/20 14:04:02 1.370 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.269.2.39.2.10 2024/09/07 01:49:32 raeburn Exp $ +# $Id: lonroles.pm,v 1.370 2023/06/20 14:04:02 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,$only_body) = @_; &Apache::loncommon::content_type($r,'text/html'); @@ -186,26 +190,6 @@ sub finish_loading_course { &HTML::Entities::encode($url,'"<>&').'">'.&mt('Continue').''; 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 = <send_http_header; - my $swinfo=&Apache::lonmenu::rawconfig(); - # Breadcrumbs - my $brcrum = [{'href' => $url, - 'text' => 'Switching Role'},]; - my $start_page = &Apache::loncommon::start_page('Switching Role',undef, - {'redirect' => [1,$url], - 'bread_crumbs' => $brcrum,}); - my $end_page = &Apache::loncommon::end_page(); + my $start_page; + if ($env{'request.lti.login'}) { + $start_page = &Apache::loncommon::start_page(undef,undef, + {'redirect' => [0,$url],}).$msg; + } else { + # Breadcrumbs + my $brcrum = [{'href' => $url, + 'text' => 'Switching Role'},]; + $start_page = &Apache::loncommon::start_page('Switching Role',undef, + {'redirect' => [1,$url], + 'bread_crumbs' => $brcrum,}). + "\n

$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; @@ -428,6 +411,8 @@ sub handler { } } + $registered_cleanup=0; + @{$rosterupdates}=(); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); # -------------------------------------------------- Check if setting hot list @@ -459,15 +444,27 @@ sub handler { $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update); } +# ------------------------------------------------- Check for approval results + my $approvalresult; + if (($env{'form.approvals'} eq 'show') && ($env{'form.state'} eq 'done')) { + $approvalresult = &Apache::loncoursequeueadmin::update_request_queue('othdombyuser', + $env{'user.domain'}); + } 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; } @@ -521,7 +518,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}); @@ -533,8 +530,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}) { @@ -625,10 +622,9 @@ sub handler { } last; } - } + } } } - foreach $envkey (keys(%env)) { next if ($envkey!~/^user\.role\./); my ($where,$trolecode,$role,$tstatus,$tend,$tstart); @@ -707,7 +703,7 @@ sub handler { $env{'user.name'}, &mt('Assigned from [_1] at [_2] for [_3]' ,$ip - ,&Apache::lonlocal::locallocaltime($now) + ,&Apache::lonlocal::locallocaltime() ,$trolecode) ); unless ($assignresult eq 'ok') { @@ -836,7 +832,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'}. @@ -877,7 +873,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 =~ /\?/) { @@ -900,14 +896,14 @@ ENDCLOSE &set_supplemental_access($cnum,$cdom); } 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) { @@ -929,6 +925,10 @@ 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); } @@ -944,12 +944,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.', @@ -960,6 +960,10 @@ ENDCLOSE } } else { &set_supplemental_access($cnum,$cdom); + 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); } @@ -970,6 +974,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',$only_body); + $r->rflush(); + return OK; + } + } my ($dest,$destsymb,$checkenc); $dest = $env{'form.destinationurl'}; $destsymb = $env{'form.destsymb'}; @@ -998,7 +1015,7 @@ ENDCLOSE if ($env{'request.role.adv'}) { $dest = &Apache::lonenc::unencrypted($dest); if ($destsymb eq '') { - ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); + ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); $destsymb = &unescape($destsymb); } } @@ -1023,7 +1040,7 @@ 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; @@ -1032,7 +1049,7 @@ ENDCLOSE if ($env{'form.ttoken'}) { $dest .= (($dest =~/\?/)? '&':'?').'ttoken='.$env{'form.ttoken'}; } - unless ($env{'request.deeplink.login'}) { + unless (($env{'request.lti.login'}) || ($env{'request.deeplink.login'})) { $msg = '

'.&mt('Entering [_1] ...', $env{'course.'.$cdom.'_'.$cnum.'.description'}). '

'; @@ -1054,18 +1071,18 @@ ENDCLOSE '

'; &finish_loading_course($r,$msg,'/adm/whatsnew?refpage=start',$only_body); $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); @@ -1098,13 +1115,18 @@ ENDCLOSE $furl = '/adm/navmaps?showOnlyHomework=1'; } } - $msg = '

'.&mt('Entering [_1] ...', - $env{'course.'.$cdom.'_'.$cnum.'.description'}). - '

'; - &finish_loading_course($r,$msg,$furl,$only_body); + if ($env{'request.lti.login'}) { + undef($msg); + &finish_loading_course($r,$msg,$furl,$only_body); + } else { + $msg = '

'.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '

'; + &finish_loading_course($r,$msg,$furl,$only_body); + } } $r->rflush(); - return OK; + return OK; } } # @@ -1190,16 +1212,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,$domdefs{'userapprovals'}); + 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('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.').'

'; @@ -1229,11 +1277,15 @@ function enterrole (thisform,rolecode,bu } function rolesView (caller) { - if ((caller == 'showall') || (caller == 'noshowall')) { + if (caller == 'approvals') { + document.rolechoice.approvals.value = 'show'; + } else if (caller == 'noapprovals') { + document.rolechoice.approvals.value = 'hide'; + } else if ((caller == 'showall') || (caller == 'noshowall')) { document.rolechoice.display.value = caller; } else { if ((caller == 'doupdate') || (caller == 'requestauthor') || - (caller == 'queued')) { + (caller == 'queued')) { document.rolechoice.state.value = caller; } } @@ -1312,7 +1364,7 @@ ENDHEADER &mt('You may need to login to LON-CAPA directly, or re-launch from a different external system.'). ''); } - $r->print(&Apache::loncommon::end_page()); + $r->print(&Apache::loncommon::end_page()); return OK; } else { if ($updateresult || $reqauthor || $hotlist) { @@ -1330,17 +1382,26 @@ ENDHEADER $r->print($showresult); } elsif ($env{'form.state'} eq 'queued') { $r->print(&get_queued()); + } elsif ($env{'form.approvals'} eq 'show') { + if ($env{'form.state'} eq 'done') { + $r->print($approvalresult).'
'; + } + $r->print('
'.&mt('Role assignments queued pending your acceptance').''. + &get_approvals(). + '

'); } if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) { $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'}; } my $display = ($env{'form.display'} =~ /^(showall)$/); + my $approvals = ($env{'form.approvals'} =~ /^(show)$/); $r->print('
'); $r->print(''); $r->print(''); $r->print(''); $r->print(''); $r->print(''); + $r->print(''); if ($blocked_by_ip) { my $blocked_role = 'student'; if ($blocked_type eq 'Community') { @@ -1360,7 +1421,21 @@ ENDHEADER \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev); $refresh = $now; &Apache::lonnet::appenv({'user.refresh.time' => $refresh}); - if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'})) { + 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) { my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); @@ -1437,6 +1512,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 @@ -1584,6 +1669,7 @@ sub gather_roles { my $advanced = $env{'user.adv'}; my $tryagain = $env{'form.tryagain'}; my @ids = &Apache::lonnet::current_machine_ids(); + my (%willtrust,%trustchecked); if (ref($roles_in_env) eq 'HASH') { my %adhocdesc; foreach my $envkey (sort(keys(%{$roles_in_env}))) { @@ -1652,10 +1738,23 @@ sub gather_roles { if (($role eq 'ca') || ($role eq 'aa')) { my $home = &Apache::lonnet::homeserver($trest,$tdom); my $allowed=0; + my $prohibited; foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } if (!$allowed) { $button=0; - $switchserver='otherserver='.$home.'&role='.$trolecode; + unless ($trustchecked{$tdom}) { + if ((&Apache::lonnet::will_trust('othcoau',$env{'user.domain'},$tdom)) && + (&Apache::lonnet::will_trust('coaurem',$tdom,$env{'user.domain'}))) { + $willtrust{$tdom} = 1; + $trustchecked{$tdom} = 1; + } + } + if ($willtrust{$tdom}) { + $switchserver='otherserver='.$home.'&role='.$trolecode; + } else { + $prohibited = 1; + $tremark .= &mt('Session switch required but prohibited.'); + } } #next if ($home eq 'no_host'); $home = &Apache::lonnet::hostname($home); @@ -1664,7 +1763,9 @@ sub gather_roles { ': '.$tdom.'
'. ' '.&mt('Server').': '.$home; $env{'course.'.$tdom.'_'.$trest.'.description'}='ca'; - $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/'); + unless ($prohibited) { + $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/'); + } $sortkey=$role."$trest:$tdom"; } elsif ($role eq 'au') { # Authors @@ -1700,9 +1801,9 @@ sub gather_roles { foreach my $rolename (sort(keys(%{$domdef{'adhocroles'}}))) { if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') { $adhocdesc{$tdom}{$rolename} = $domdef{'adhocroles'}{$rolename}{'desc'}; + $desc = $adhocdesc{$tdom}{$rolename}; } } - $desc = $adhocdesc{$tdom}{$rolename}; } } if ($desc ne '') { @@ -1763,6 +1864,9 @@ sub gather_roles { $skipcal = 1; } } + if ($ttype eq 'Placement') { + $ttype = 'Placement Test'; + } if ($tsection) { $twhere.='
'.&mt('Section').': '.$tsection; } @@ -1878,7 +1982,7 @@ sub roletable_headers { } sub roletypes { - my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System'); + my @types = ('Domain','Authoring Space','Course','Placement Test','Community','Unavailable','System'); return @types; } @@ -1940,7 +2044,7 @@ sub findcourse_advice {
  • '.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'
  • '.&mt('The start date for automated enrollment has yet to be reached.').'
  • '.&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.').'
  • -
  • '.&mt('Automated enrollment added you to the course in the time since you last logged-in.').' '.&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.').'
  • +
  • '.&mt('Automated enrollment added you to the course in the time since you last logged-in.').' '.&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.').'
  • '); } 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.').'

    '); @@ -1948,7 +2052,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.').'

    '); - } + } } if (($cattype eq 'std') || ($cattype eq 'domonly')) { $r->print('

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

    '. @@ -2141,7 +2245,7 @@ sub build_roletext { $trolecode."','".$buttonname.'\');" />'; } } - if (($trolecode !~ m/^(ca|aa)\./) && ($trest ne '') && (!$skipcal)) { + if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) { $tremark.=&Apache::lonannounce::showday(time,1, &Apache::lonannounce::readcalendar($tdom.'_'.$trest)); } @@ -2179,7 +2283,7 @@ sub check_for_adhoc { my $numdc = 0; my $numhelpdesk = 0; my $numadhoc = 0; - my $num_custom_adhoc = 0; + my $num_custom_adhoc = 0; if (($env{'user.adv'}) || ($env{'user.rar'})) { foreach my $envkey (sort(keys(%env))) { if ($envkey=~/^user\.role\.(dc|dh|da)\.\/($match_domain)\/$/) { @@ -2398,7 +2502,7 @@ sub display_cc_role { } else { $twhere=&mt('Currently not available'); $env{'course.'.$tcourseid.'.description'}=$twhere; - $skipcal = 1; + $skipcal = 1; } my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid); $twhere.="
    ".&mt('Domain').":".$tdom; @@ -2423,7 +2527,7 @@ sub display_curr_role { my $ttype = $env{'course.'.$cid.'.type'}; my $skipcal = 1; my $tbg='LC_roles_is'; - my $twhere = $env{'course.'.$cid.'.description'}. + my $twhere = $env{'course.'.$cid.'.description'}. ' '. &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom). ''; @@ -2469,7 +2573,7 @@ sub adhoc_customroles_row { if ($tstart && $tstart>$limit) { $liverole = 0; } if ($tend && $tend <$limit) { $liverole = 0; } return unless ($liverole); - my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom); + my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom); if (ref($domdefaults{'adhocroles'}) eq 'HASH') { if (scalar(keys(%{$domdefaults{'adhocroles'}})) > 0) { return &Apache::loncommon::continue_data_table_row() @@ -2600,22 +2704,6 @@ sub update_session_roles { } } else { $newrole{$rolekey} = $status_in_db; - if ($role eq 'au') { - my %userenv = - &Apache::lonnet::userenvironment($env{'user.domain'}, - $env{'user.name'},'authoreditors'); - if ($userenv{'authoreditors'}) { - $userenv{'editors'} = $userenv{'authoreditors'}; - } else { - my %domdef = &Apache::lonnet::get_domain_defaults($env{'user.domain'}); - if ($domdef{'editors'} ne '') { - $userenv{'editors'} = $domdef{'editors'}; - } else { - $userenv{'editors'} = 'edit,xml'; - } - } - &Apache::lonnet::appenv(\%userenv); - } } } } @@ -2815,7 +2903,7 @@ sub update_session_roles { &curr_role_status($currstart,$currend,$refresh,$update); my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/); my ($role,$rest)=split(m{\./},$rolekey,2); - $rest = '/'.$rest; + $rest = '/'.$rest; if (&Apache::lonnet::delenv($envkey,undef,[$role])) { if ($status_in_env eq 'active') { if ($role eq 'gr') { @@ -3015,15 +3103,15 @@ sub update_session_roles { } my $groupdesc; unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') { - %{$curr_groups{$cdom.'_'.$cnum}} = + %{$curr_groups{$cdom.'_'.$cnum}} = &Apache::longroup::coursegroups($cdom,$cnum); } unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') && ($groupdescs{$cdom.'_'.$cnum}{$group})) { - my %groupinfo = + my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group}); - $groupdescs{$cdom.'_'.$cnum}{$group} = + $groupdescs{$cdom.'_'.$cnum}{$group} = &unescape($groupinfo{'description'}); } $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group}; @@ -3142,7 +3230,7 @@ sub update_session_roles { my $cdom = $env{'course.'.$cid.'.domain'}; my $cnum = $env{'course.'.$cid.'.num'}; my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum); - my %groupdesc; + my %groupdesc; if (ref($groupchange{$crs}) eq 'HASH') { $groupchgmsg .= '
  • '.&mt('Course/Community: [_1]',''.$crsdesc.'
      '); foreach my $group (sort(keys(%{$groupchange{$crs}}))) { @@ -3297,7 +3385,7 @@ sub is_active_course { } sub get_roles_functions { - my ($rolescount,$cattype) = @_; + my ($rolescount,$cattype,$userapprovals) = @_; my @links; push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]); if ($env{'environment.canrequest.author'}) { @@ -3326,6 +3414,13 @@ sub get_roles_functions { unless ($cattype eq 'none') { push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]); } + if ($userapprovals) { + if ($env{'form.approvals'} eq 'show') { + push(@links,["javascript:rolesView('noapprovals');",'list-add-22x22',&mt('Hide pending')]); + } else { + push(@links,["javascript:rolesView('approvals');",'list-add-22x22',&mt('Show pending')]); + } + } my $funcs; if ($env{'browser.mobile'}) { my @functions; @@ -3375,7 +3470,7 @@ sub get_queued { if (ref($history{'details'}) eq 'HASH') { $description = $history{details}{'cdescr'}; } - @{$reqcrs{$reqtime}} = ($description,$showtype); + @{$reqcrs{$reqtime}} = ($description,$showtype); } } my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs)); @@ -3429,15 +3524,101 @@ sub get_queued { unless ($output) { if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} || $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) { - $output = &mt('No requests for courses, communities or authoring currently queued'); + $output = ''. + &mt('No requests for courses, communities or authoring currently queued'). + ''; } else { - $output = &mt('No enrollment requests currently queued awaiting approval'); + $output = ''. + &mt('No enrollment requests currently queued awaiting approval'). + ''; } } return '
      '.&mt('Queued requests').''. $output.'

      '; } +sub get_approvals { + return &Apache::loncoursequeueadmin::display_queued_requests('othdomaction',$env{'user.domain'},'','user'); +} + +sub process_lti { + my ($r,$cdom,$cnum) = @_; + my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); + my $uriscope = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'}, + $cdom,$cnum); + my $lonhost = $r->dir_config('lonHostID'); + my $internet_names = &Apache::lonnet::get_internet_names($lonhost); + if ($env{'request.lti.rosterid'} && + $env{'request.lti.rosterurl'}) { + if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') { + if ($lti{$env{'request.lti.login'}}{'roster'}) { + my @lcroles = ('in','ta','ep','st'); + my @possibleroles; + foreach my $role (@lcroles) { + if (&Apache::lonnet::allowed('c'.$role,"$cdom/$cnum")) { + push(@possibleroles,$role); + } + } + my $owner = $env{'course.'.$cdom.'_'.$cnum.'.internal.courseowner'}; + if ($owner eq $env{'user.name'}.':'.$env{'user.domain'}) { + my $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum); + if ($crstype eq 'Community') { + unshift(@possibleroles,'co'); + } else { + unshift(@possibleroles,'cc'); + } + } + if (@possibleroles) { + push(@{$rosterupdates},{cid => $cdom.'_'.$cnum, + lti => $env{'request.lti.login'}, + ltiref => $lti{$env{'request.lti.login'}}, + id => $env{'request.lti.rosterid'}, + url => $env{'request.lti.rosterurl'}, + sourcecrs => $env{'request.lti.sourcecrs'}, + uriscope => $uriscope, + possroles => \@possibleroles, + intdoms => $internet_names, + }); + unless ($registered_cleanup) { + my $handlers = $r->get_handlers('PerlCleanupHandler'); + $r->set_handlers('PerlCleanupHandler' => + [\<ienroll,@{$handlers}]); + $registered_cleanup=1; + } + } + } + } + } + if ($env{'request.lti.passbackid'} && + $env{'request.lti.passbackurl'}) { + if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') { + if ($lti{$env{'request.lti.login'}}{'passback'}) { + my ($pbnum,$error) = + &LONCAPA::ltiutils::store_passbackurl($env{'request.lti.login'}, + $env{'request.lti.passbackurl'}, + $cdom,$cnum); + if ($pbnum eq '') { + $pbnum = $env{'request.lti.passbackurl'}; + } + &Apache::lonnet::put('nohist_'.$cdom.'_'.$cnum.'_passback', + {"$uriscope\0$env{'request.lti.sourcecrs'}\0$env{'request.lti.login'}" => + "$pbnum\0$env{'request.lti.passbackid'}"}); + } + } + } + return; +} + +sub ltienroll { + if (ref($rosterupdates) eq 'ARRAY') { + foreach my $item (@{$rosterupdates}) { + if (ref($item) eq 'HASH') { + &LONCAPA::ltiutils::batchaddroster($item); + } + } + } +} + sub set_deeplink_target { my ($cnum,$cdom) = @_; if (($cnum ne '') && ($cdom ne '')) {