--- loncom/auth/lonroles.pm 2022/10/05 16:11:26 1.367 +++ loncom/auth/lonroles.pm 2025/02/23 05:16:01 1.376 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.367 2022/10/05 16:11:26 raeburn Exp $ +# $Id: lonroles.pm,v 1.376 2025/02/23 05:16:01 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -181,6 +181,7 @@ document.body.addEventListener('click', ENDREDIR } + $r->print('
'."\n"); return; } @@ -210,6 +211,7 @@ $msg // ]]> $link +
$end_page END return; @@ -444,6 +446,12 @@ 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 = (); @@ -499,6 +507,7 @@ sub handler { "request.course.sec" => '', "request.course.tied" => '', "request.course.timechecked" => '', + "request.course.suppupdated" => '', "request.role" => 'cm', "request.role.adv" => $env{'user.adv'}, "request.role.domain" => $env{'user.domain'}}); @@ -675,17 +684,24 @@ sub handler { $env{'environment.key.'.$cdom.'_'.$cnum}, $authdom,$authnum)) { # there is no valid key + my $swinfo=&Apache::lonmenu::rawconfig(); + my $crumbtext = 'User Roles'; + my $show_course=&Apache::loncommon::show_course(); + if ($show_course) { + $crumbtext = 'Courses'; + } if ($env{'form.newkey'}) { # student attempts to register a new key &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; - my $swinfo=&Apache::lonmenu::rawconfig(); + my $pagetitle = 'Verifying Access Key to Unlock this Course'; + my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}, + {href=>"/adm/roles",text=>'Verify Access Key'}]; my $start_page=&Apache::loncommon::start_page - ('Verifying Access Key to Unlock this Course'); + ($pagetitle, undef,{bread_crumbs=>$brcrum,}); my $end_page=&Apache::loncommon::end_page(); - my $buttontext=&mt('Enter Course'); - my $message=&mt('Successfully registered key'); + my ($buttontext,$message,$inputitem,$accessheader); my $ip = &Apache::lonnet::get_requestor_ip(); my $assignresult= &Apache::lonnet::assign_access_key( @@ -696,41 +712,63 @@ sub handler { $env{'user.name'}, &mt('Assigned from [_1] at [_2] for [_3]' ,$ip - ,&Apache::lonlocal::locallocaltime() + ,&Apache::lonlocal::locallocaltime($now) ,$trolecode) ); - unless ($assignresult eq 'ok') { - $assignresult=~s/^error\:\s*//; - $message=&mt($assignresult). - '
'. - &mt('Logout').''; - $buttontext=&mt('Re-Enter Key'); - } - $r->print(<&"')).'
'. + &mt('Result').': '.&mt($assignresult); + my $labeltext = &mt('Enter access key'); + $inputitem = ''; + } + $r->print(<<"ENDREGKEY"); $start_page -
+ +
+ -$message
+$inputitem +
$end_page -ENDENTEREDKEY +ENDREGKEY return OK; } else { # print form to enter a new key &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; - my $swinfo=&Apache::lonmenu::rawconfig(); + my $pagetitle = 'Enter Access Key to Unlock this Course'; + my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}, + {href=>"/adm/roles",text=>'Enter Access Key'}]; my $start_page=&Apache::loncommon::start_page - ('Enter Access Key to Unlock this Course'); + ($pagetitle,undef,{bread_crumbs=>$brcrum,}); my $end_page=&Apache::loncommon::end_page(); + my $accessheader = &mt('Access to this course requires an access key'); + my $preamble = &mt('Once you have successfully entered a valid key, you will no longer be prompted for one when entering the course.'); + my $labeltext = &mt('Enter access key'); + my $submittext = &mt('Submit'); $r->print(< @@ -738,12 +776,17 @@ $start_page $swinfo // ]]> +
+

$accessheader

+

$preamble

- - + +
+
$end_page ENDENTERKEY return OK; @@ -799,6 +842,9 @@ ENDENTERKEY ENDCLOSE &start_loading_course($r,$title,$only_body); + if ($only_body) { + $r->print('

'.$title.'

'); + } my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble); &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Loading ...')); $r->rflush(); @@ -853,7 +899,6 @@ ENDCLOSE 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'})) { @@ -886,6 +931,8 @@ ENDCLOSE if ($env{'form.symb'}) { $furl .= '&symb='.&HTML::Entities::encode($env{'form.symb'},'<>&"'); } + } else { + &set_supplemental_access($cnum,$cdom); } if (($ferr) && ($tadv)) { &error_page($r,$ferr,$furl); @@ -948,9 +995,11 @@ ENDCLOSE $env{'course.'.$cdom.'_'.$cnum.'.description'}). '

'. '

'.&mt('Please try again.').'

'. + ''. &Apache::loncommon::end_page()); } } else { + &set_supplemental_access($cnum,$cdom); if (($env{'request.lti.login'}) && ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) { &process_lti($r,$cdom,$cnum); @@ -1228,16 +1277,18 @@ ENDCLOSE $start_page=&Apache::loncommon::start_page($pagetitle,undef, {bread_crumbs=>$brcrum,crstype=>'Placement'}); } else { - my $crumbsright; + my ($crumbsright,$crumbs_style); unless (($norolelist) && ((split(/:/,$env{'user.error.msg'}))[2])) { - $funcs = &get_roles_functions($showcount,$cattype); + $funcs = &get_roles_functions($showcount,$cattype,$domdefs{'userapprovals'}); if ($env{'browser.mobile'}) { $crumbsright = $funcs; undef($funcs); + $crumbs_style = 'overflow: visible;'; } } $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum, - bread_crumbs_component=>$crumbsright}); + bread_crumbs_component=>$crumbsright, + bread_crumbs_style=>$crumbs_style,}); } &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.').'

'; @@ -1268,7 +1319,11 @@ 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') || @@ -1341,17 +1396,18 @@ ENDHEADER } } if ($nochoose) { - $r->print("

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

\n". + $r->print("
+

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

\n". &mt('This action is currently not authorized.').''); if ($error && $norolelist) { - $r->print('

'. + $r->print('

'. &mt('As your session was launched from a web page external to LON-CAPA some course content may be unavailable, including the resource you were trying to access.'). - '

'. - '

'. + '

'. + '

'. &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) { @@ -1364,22 +1420,31 @@ ENDHEADER } if ($hotlist) { $showresult .= $hotlist; - } + } $showresult .= ''; $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') { @@ -1779,9 +1844,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 '') { @@ -1937,7 +2002,7 @@ sub roletable_headers { .&Apache::loncommon::start_data_table('LC_textsize_mobile') .&Apache::loncommon::start_data_table_header_row() ); - if (!$nochoose) { $r->print(' '); } + if (!$nochoose) { $r->print(''.&mt('Action').''); } $r->print(''.&mt('User Role').'' .''.&mt('Extent').'' .''.&mt('Start').'' @@ -2223,7 +2288,7 @@ sub build_roletext { $trolecode."','".$buttonname.'\');" />'; } } - if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) { + if (($trolecode !~ m/^(ca|aa)\./) && ($trest ne '') && (!$skipcal)) { $tremark.=&Apache::lonannounce::showday(time,1, &Apache::lonannounce::readcalendar($tdom.'_'.$trest)); } @@ -2682,6 +2747,22 @@ 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); + } } } } @@ -3363,7 +3444,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'}) { @@ -3392,6 +3473,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; @@ -3409,7 +3497,7 @@ sub get_roles_functions { foreach my $link (@links) { $funcs .= &Apache::lonhtmlcommon::add_item_funclist( ''. - ''.$link->[2].''. + ''. $link->[2].''); } $funcs .= &Apache::lonhtmlcommon::end_funclist(); @@ -3495,15 +3583,23 @@ 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'); @@ -3579,7 +3675,9 @@ sub ltienroll { &LONCAPA::ltiutils::batchaddroster($item); } } + $rosterupdates = []; } + return OK; } sub set_deeplink_target { @@ -3610,6 +3708,14 @@ sub set_deeplink_target { return; } +sub set_supplemental_access { + my ($cnum,$cdom) = @_; + my ($supplemental,$refs_updated) = &Apache::loncommon::get_supplemental($cnum,$cdom); + unless ($refs_updated) { + &Apache::loncommon::set_supp_httprefs($cnum,$cdom,$supplemental); + } +} + 1; __END__