--- loncom/interface/lonmodifycourse.pm 2023/12/23 02:17:38 1.104 +++ loncom/interface/lonmodifycourse.pm 2024/04/14 17:12:27 1.105 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # handler for DC-only modifiable course settings # -# $Id: lonmodifycourse.pm,v 1.104 2023/12/23 02:17:38 raeburn Exp $ +# $Id: lonmodifycourse.pm,v 1.105 2024/04/14 17:12:27 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -434,6 +434,7 @@ sub print_modification_menu { 'setltiauth' => 'View/Modify re-authentication requirement for LTI launch of deep-linked item', 'setexttool' => 'View/Modify External Tools permissions', 'setcrsauthor' => 'View/Modify In-course Authoring permissions', + 'setcrseditors' => 'View/Modify permitted course resource editors', ); } else { %linktext = ( @@ -444,6 +445,7 @@ sub print_modification_menu { 'setltiauth' => 'View re-authentication requirement for LTI launch of deep-linked item', 'setexttool' => 'View External Tools permissions', 'setcrsauthor' => 'View In-course Authoring permissions', + 'setcrseditors' => 'View permitted course resource editors', ); } if ($type eq 'Community') { @@ -592,6 +594,14 @@ sub print_modification_menu { permission => $permission->{'setcrsauthor'}, linktitle => '', }, + { + linktext => $linktext{'setcrseditors'}, + icon => 'crseditors.png', + #help => '', + url => &phaseurl('setcrseditors'), + permission => $permission->{'setcrseditors'}, + linktitle => '', + }, ] }, ); @@ -1314,12 +1324,13 @@ sub print_selfenrollconfig { sub print_default_overrides { my ($r,$cdom,$cnum,$cdesc,$type,$readonly,$item) = @_; my (%titles,$checkeddom,$checkedcrs,$divsty,$currcrsval,$crsdefault,%crschecked, - $helpfile,$title,$crselements); + $helpfile,$title,$crselements,@currcrseditors); %titles = &default_overrides_titles($type); my ($title,$domdefdisplay,$settings,$optiontext,$options) = &default_overrides_common($item,$cdom,$cnum,$type,\%titles); $checkeddom = ' checked="checked"'; $divsty = 'display:none'; + if ($item eq 'ltiauth') { $helpfile = 'Modify_Course_LTI_Authen'; $crsdefault = 0; @@ -1330,6 +1341,9 @@ sub print_default_overrides { } elsif ($item eq 'crsauthor') { $helpfile = 'Modify_Course_Crsauthor'; $crsdefault = 1; + } elsif ($item eq 'crseditors') { + $helpfile = 'Modify_Course_Resource_Editors'; + $crsdefault = 'edit,xml'; } } $currcrsval = $settings->{'internal.'.$item}; @@ -1337,33 +1351,55 @@ sub print_default_overrides { $checkedcrs = $checkeddom; $checkeddom = ''; $divsty = 'display:inline-block'; + if ($item eq 'crseditors') { + @currcrseditors = split(/,/,$currcrsval); + } foreach my $option (@{$options}) { - if ($currcrsval eq $option) { + if ($item eq 'crseditors') { + if (grep(/^\Q$option\E$/,@currcrseditors)) { + $crschecked{$option} = ' checked="checked"'; + } + } elsif ($currcrsval eq $option) { $crschecked{$option} = ' checked="checked"'; } else { $crschecked{$option} = ''; } } } else { + if ($item eq 'crseditors') { + my %domdefs = &Apache::lonnet::get_domain_defaults($cdom); + @currcrseditors = split(/,/,$domdefs{'crseditors'}); + } foreach my $option (@{$options}) { - if ($crsdefault eq $option) { + if ($item eq 'crseditors') { + if (grep(/^\Q$option\E$/,@currcrseditors)) { + $crschecked{$option} = ' checked="checked"'; + } + } elsif ($crsdefault eq $option) { $crschecked{$option} = ' checked="checked"'; } else { $crschecked{$option} = ''; } } } - my ($disabled,$submit); + my ($disabled,$submit,$inputtype,$separator); if ($readonly) { $disabled = ' disabled="disabled"'; } else { $submit = ''; } + if ($item eq 'crseditors') { + $inputtype = 'checkbox'; + $separator = ' 'x2; + } else { + $inputtype = 'radio'; + $separator = '
'; + } foreach my $option (@{$options}) { $crselements .= ''. - ''. - '
'."\n"; + ''.$separator."\n"; } &print_header($r,$type); my $hidden_elements = &hidden_form_elements(); @@ -1406,6 +1442,10 @@ sub default_overrides_titles { 'dom' => 'Only external tools defined in domain may be used', 'both' => 'External tools defined/configured in either domain or course may be used', 'stan' => "'In-course' authoring of standard LON-CAPA problems", + 'perc' => 'Permitted course resource editors', + 'edit' => 'Standard editor (Edit)', + 'xml' => 'Text editor (EditXML)', + 'daxe' => 'Daxe editor (Daxe)', 'on' => 'In-course authoring available', 'off' => 'In-course authoring unavailable', 'used' => 'Use domain default', @@ -1454,12 +1494,17 @@ sub default_overrides_common { 1 => $titles->{'on'}, 0 => $titles->{'off'}, ); + } elsif ($item eq 'crseditors') { + $title = $titles->{'perc'}; + $domdef = 1; + @options = ('edit','xml','daxe'); + map { $optiontext{$_} = $titles->{$_}; } @options; } } my %domconfig = &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom); if (ref($domconfig{'coursedefaults'}) eq 'HASH') { - if ($item eq 'ltiauth') { + if (($item eq 'ltiauth') || ($item eq 'crseditors')) { $domdef = $domconfig{'coursedefaults'}{$item}; } else { my $lctype = &get_lctype($type,\%settings); @@ -1499,6 +1544,18 @@ sub default_overrides_common { } else { $domdefdisplay = $titles->{'off'}; } + } elsif ($item eq 'crseditors') { + if (ref($domdef) eq 'ARRAY') { + if (@{$domdef} == 0) { + $domdefdisplay = &mt('No permitted editors'); + } elsif (@{$domdef} == 1) { + $domdefdisplay = $titles->{$domdef->[0]}.' ('.&mt('only').')'; + } else { + $domdefdisplay = join(', ', map { $titles->{$_}; } @{$domdef}); + } + } else { + $domdefdisplay = join(', ', map { $titles->{$_}; } ('edit','xml')); + } } return ($title,$domdefdisplay,\%settings,\%optiontext,\@options); } @@ -2533,7 +2590,13 @@ sub modify_default_overrides { chg => 'In-course authoring permissions changed', nochg => 'In-course authoring permissions unchanged', ); - } + } elsif ($item eq 'crseditors') { + %resulttext = + &Apache::lonlocal::texthash( + chg => 'Permitted course resource editors changed', + nochg => 'Permitted course resource editors unchanged', + ); + } &print_header($r,$type); $r->print('

'.$title.'

'."\n". '

'.&mt($type).': '.$cdesc.'

'."\n". @@ -2545,9 +2608,20 @@ sub modify_default_overrides { $change = 1; } } elsif ($env{'form.'.$item.'set'} eq 'course') { - my $posscrsval = $env{'form.'.$item}; - if (grep(/^\Q$posscrsval\E$/,@{$options})) { - $newcrsval = $posscrsval; + if ($item eq 'crseditors') { + my @neweditors; + my @posseditors = &Apache::loncommon::get_env_multiple('form.'.$item); + foreach my $editor (@posseditors) { + if (grep(/^\Q$editor\E$/,@{$options})) { + push(@neweditors,$editor); + } + } + $newcrsval = join(',',@neweditors); + } else { + my $posscrsval = $env{'form.'.$item}; + if (grep(/^\Q$posscrsval\E$/,@{$options})) { + $newcrsval = $posscrsval; + } } if ($oldcrsval eq $newcrsval) { $nochange = 1; @@ -2589,6 +2663,9 @@ sub modify_default_overrides { if ($itemvalue eq '') { $status = $titles{'used'}.': '. ''.$domdefdisplay.''; + } elsif ($item eq 'crseditors') { + $status = $titles{'cour'}.': '. + ''.join(', ', map { $titles{$_}; } split(/,/,$itemvalue)).''; } else { $status = $titles{'cour'}.': '. ''.$optiontext->{$itemvalue}.''; @@ -2767,7 +2844,8 @@ function togglePostsubmit(caller) { ENDSCRIPT - } elsif (($phase eq 'setltiauth') || ($phase eq 'setexttool') || ($phase eq 'setcrsauthor')) { + } elsif (($phase eq 'setltiauth') || ($phase eq 'setexttool') || + ($phase eq 'setcrsauthor') || ($phase eq 'setcrseditors')) { $js .= <<"ENDJS"; function toggleOptions(form,phase) { var radioname; @@ -2781,6 +2859,9 @@ function toggleOptions(form,phase) { } else if (phase == 'setcrsauthor') { radioname = 'crsauthorset'; divid = 'crscrsauthor'; + } else if (phase == 'setcrseditors') { + radioname = 'crseditorsset'; + divid = 'crscrseditors'; } var num = form.elements[radioname].length; if (num) { @@ -2816,7 +2897,7 @@ ENDJS $starthash = { add_entries => {'onload' => "hide_searching(); courseSet(document.filterpicker.official, 'load');"}, }; - } elsif ($env{'form.phase'} =~ /^set(ltiauth|exttool|crsauthor)$/) { + } elsif ($env{'form.phase'} =~ /^set(ltiauth|exttool|crsauthor|crseditors)$/) { $starthash = { add_entries => {'onload' => "toggleOptions(document.$env{'form.phase'},'$env{'form.phase'}');"}, }; @@ -2928,7 +3009,7 @@ sub hidden_form_elements { 'threshold','postsubmit','postsubtimeout','defaultcredits','uploadquota', 'selfenrollmgrdc','selfenrollmgrcc','action','state','currsec_st', 'sections','newsec','mysqltables','nopasswdchg','ltiauth','ltiauthset', - 'exttoolset','exttool','crsauthorset','crsauthor'], + 'exttoolset','exttool','crsauthorset','crsauthor','crseditorsset','crseditors'], ['^selfenrollmgr_','^selfenroll_'])."\n". ''; return $hidden_elements; @@ -2968,6 +3049,8 @@ sub get_permission { processexttool => 'edit', setcrsauthor => 'edit', processcrsauthor => 'edit', + setcrseditors => 'edit', + processcrseditors => 'edit', ); if ($passwdconf{'crsownerchg'}) { $permission{passwdchg} = 'edit'; @@ -2986,6 +3069,7 @@ sub get_permission { setltiauth => 'view', setexttool => 'view', setcrsauthor => 'view', + setcrseditors => 'view', ); if ($passwdconf{'crsownerchg'}) { $permission{passwdchg} = 'view'; @@ -3225,6 +3309,18 @@ sub handler { {href=>"javascript:changePage(document.$phase,'$phase')", text=>"Result"}); &modify_default_overrides($r,$cdom,$cnum,$cdesc,$domdesc,$type,'crsauthor'); + } elsif (($phase eq 'setcrseditors') && ($permission->{'setcrseditors'})) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"javascript:changePage(document.$phase,'$phase')", + text=>"Available course resource editors"}); + &print_default_overrides($r,$cdom,$cnum,$cdesc,$type,$readonly,'crseditors'); + } elsif (($phase eq 'processcrseditors') && ($permission->{'processcrseditors'})) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"javascript:changePage(document.$phase,'setcrseditors')", + text=>"Available course resource editors"}, + {href=>"javascript:changePage(document.$phase,'$phase')", + text=>"Result"}); + &modify_default_overrides($r,$cdom,$cnum,$cdesc,$domdesc,$type,'crseditors'); } } } else {