--- loncom/interface/lonconfigsettings.pm 2019/07/18 18:28:52 1.46 +++ loncom/interface/lonconfigsettings.pm 2022/09/08 01:41:13 1.67 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: lonconfigsettings.pm,v 1.46 2019/07/18 18:28:52 raeburn Exp $ +# $Id: lonconfigsettings.pm,v 1.67 2022/09/08 01:41:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,9 +40,9 @@ use Apache::courseclassifier(); use LONCAPA qw(:DEFAULT :match); sub print_header { - my ($r,$phase,$context,$jscript,$container,$instcode,$dom,$values) = @_; + my ($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values) = @_; my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check, - $crstype,@actions,@code_order); + $linkprot_check,$crstype,@actions,@code_order); if ($phase eq 'display') { @actions = &Apache::loncommon::get_env_multiple('form.actions'); } @@ -116,6 +116,113 @@ sub print_header { ENDSCRIPT } } + if (($context eq 'course') && ($phase eq 'display') && + (grep(/^linkprot$/,@actions))) { + my $allowed; + my $home = &Apache::lonnet::homeserver($confname,$dom); + unless ($home eq 'no_host') { + my @ids=&Apache::lonnet::current_machine_ids(); + foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } + } + if ($allowed) { + my (@changeable,@settable); + if (ref($values->{'linkprot'}) eq 'HASH') { + if (keys(%{$values->{'linkprot'}})) { + my @current = sort { $a <=> $b } keys(%{$values->{'linkprot'}}); + if (@current) { + for (my $i=0; $i<@current; $i++) { + my $num = $current[$i]; + if (ref($values->{'linkprot'}->{$num}) eq 'HASH') { + if ($values->{'linkprot'}->{$num}->{'usable'}) { + push(@changeable,$i); + } else { + push(@settable,$i); + } + } + } + } + } + } + my ($numrules,$intargjs); +$linkprot_check .= < \%loaditems,}; } } elsif ($context eq 'course') { + my $onload; if (grep(/^courseinfo$/,@actions)) { - if (@code_order) { - $additem = { - add_entries => {'onload' => "courseSet('','load');toggleCloners(document.display.cloners_instcode);"}, - }; + if (@code_order) { + $onload = "courseSet('','load');toggleCloners(document.display.cloners_instcode);"; } } + if (grep(/^linkprot$/,@actions)) { + if (ref($values) eq 'HASH') { + if (ref($values->{'linkprot'}) eq 'HASH') { + my $ltiauth; + if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) { + $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'}; + } else { + my %domdefs = &Apache::lonnet::get_domain_defaults($dom); + $ltiauth = $domdefs{'crsltiauth'}; + } + my $ishome; + my $chome = $env{'course.'.$env{'request.course.id'}.'.home'}; + unless (($chome eq 'no_host') || ($chome eq '')) { + my @ids=&Apache::lonnet::current_machine_ids(); + foreach my $id (@ids) { if ($id eq $chome) { $ishome=1; } } + } + my $posslti = scalar(keys(%{$values->{'linkprot'}})); + for (my $i=0; $i<=$posslti; $i++) { + my $num = $i; + if ($i == $posslti) { + $num = 'add'; + } + if (ref($values->{'linkprot'}->{$i}) eq 'HASH') { + if ($values->{'linkprot'}->{$i}->{'usable'}) { + $onload .= "toggleLinkProt(document.display,'$num','secret');"; + } + } + $onload .= "toggleLinkProtExtra(document.display,'returnurl','divurlparam','1','inline-block','$num');"; + if ($ltiauth) { + $onload .= "toggleLinkProtExtra(document.display,'requser','optional','1','block','$num');". + "toggleLinkProtExtra(document.display,'mapuser','userfield','other','inline-block','$num');"; + } + if ($ishome) { + $onload .= "uncheckLinkProtMakeVis('visible','$num');"; + } + } + } + } + } + if (grep(/^appearance$/,@actions)) { + $onload .= "toggleExtRes();"; + } + if (grep(/^localization$/,@actions)) { + $onload .= "toggleTimeZone();"; + } + if ($onload) { + my %loaditems = ( + 'onload' => $onload, + ); + $additem = {'add_entries' => \%loaditems,}; + } } } $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem)); @@ -348,7 +529,7 @@ sub make_changes { {href=>"javascript:changePage(document.$phase,'$phase')", text=>"Updated"}); &print_header($r,$phase,$context,undef,$container); - my ($crstype,%lastact); + my ($crstype,%lastact,$errors); if ($context eq 'course') { $crstype = &Apache::loncommon::course_type(); } @@ -362,9 +543,11 @@ sub make_changes { $confname,$item,$roles,$values,\%lastact)); } else { $changes{$item} = {}; - &Apache::courseprefs::process_changes($dom,$item,$values, - $prefs->{$item},$changes{$item}, - $allitems,\%disallowed,$crstype); + $errors = + &Apache::courseprefs::process_changes($dom,$confname,$item,$values, + $prefs->{$item},$changes{$item}, + $allitems,\%disallowed,$crstype, + \%lastact); if (keys(%{$changes{$item}}) > 0) { $numchanged ++; } @@ -396,6 +579,9 @@ sub make_changes { } $r->print('

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

'.$errors.'

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

'); my $footer_text = 'Back to configuration display'; @@ -419,7 +605,7 @@ sub display_settings { if (ref($values) eq 'HASH') { $instcode = $values->{'internal.coursecode'}; } - &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$values); + &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values); my $divwidth = 900; if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { if (@actions > 0) { @@ -466,13 +652,23 @@ sub display_settings { $settings = $inststatus; } } + } elsif ($item eq 'lti') { + if (ref($values->{'ltisec'}) eq 'HASH') { + if (ref($values->{'lti'}) eq 'HASH') { + $settings = {%{$values->{'lti'}},%{$values->{'ltisec'}}}; + } else { + $settings = $values->{'ltisec'}; + } + } elsif (ref($values->{'lti'}) eq 'HASH') { + $settings = $values->{'lti'}; + } } ($output{$item},$rowtotal{$item}) = &Apache::domainprefs::print_config_box($r,$dom,$confname, $phase,$item,$prefs->{$item},$settings); } else { ($output{$item},$rowtotal{$item}) = - &Apache::courseprefs::print_config_box($r,$dom,$phase, + &Apache::courseprefs::print_config_box($r,$dom,$confname,$phase, $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission); } $rowsum += $rowtotal{$item}; @@ -552,8 +748,8 @@ sub display_choices { $thirddiv = 1; } } - $r->print('
'); } + $r->print('

'); $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission)); $r->print(''); if ($container) {