--- loncom/interface/domainprefs.pm 2015/05/12 00:20:42 1.160.6.63 +++ loncom/interface/domainprefs.pm 2015/05/22 14:12:08 1.160.6.64 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.160.6.63 2015/05/12 00:20:42 raeburn Exp $ +# $Id: domainprefs.pm,v 1.160.6.64 2015/05/22 14:12:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2891,6 +2891,7 @@ sub print_coursedefaults { uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)', usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)', postsubmit => 'Disable submit button/keypress following student submission', + canclone => "People who may clone a course (besides course's owner and coordinators)", ); my %staticdefaults = ( anonsurvey_threshold => 10, @@ -2901,10 +2902,82 @@ sub print_coursedefaults { %defaultchecked = ( 'uselcmath' => 'on', 'usejsme' => 'on', + 'canclone' => 'none', ); @toggles = ('uselcmath','usejsme'); ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, \%choices,$itemcount); + $css_class = $itemcount%2?' class="LC_odd_row"':''; + $datatable .= + ''. + ''.$choices{'canclone'}. + ''; + my $currcanclone = 'none'; + my $onclick; + my @cloneoptions = ('none','domain'); + my %clonetitles = ( + none => 'No additional course requesters', + domain => "Any course requester in course's domain", + instcode => 'Course requests for official courses ...', + ); + my (%codedefaults,@code_order,@posscodes); + if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults, + \@code_order) eq 'ok') { + if (@code_order > 0) { + push(@cloneoptions,'instcode'); + $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"'; + } + } + if (ref($settings) eq 'HASH') { + if ($settings->{'canclone'}) { + if (ref($settings->{'canclone'}) eq 'HASH') { + if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') { + if (@code_order > 0) { + $currcanclone = 'instcode'; + @posscodes = @{$settings->{'canclone'}{'instcode'}}; + } + } + } elsif ($settings->{'canclone'} eq 'domain') { + $currcanclone = $settings->{'canclone'}; + } + } + } + foreach my $option (@cloneoptions) { + my ($checked,$additional); + if ($currcanclone eq $option) { + $checked = ' checked="checked"'; + } + if ($option eq 'instcode') { + if (@code_order) { + my $show = 'none'; + if ($checked) { + $show = 'block'; + } + $additional = '
'. + &mt('Institutional codes for new and cloned course have identical:'). + '
'; + foreach my $item (@code_order) { + my $codechk; + if ($checked) { + if (grep(/^\Q$item\E$/,@posscodes)) { + $codechk = ' checked="checked"'; + } + } + $additional .= ''; + } + $additional .= (' 'x2).'('.&mt('check as many as needed').')
'; + } + } + $datatable .= + ' '.$additional.'
'; + } + $datatable .= ''. + ''; + $itemcount ++; } else { $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout); @@ -10297,7 +10370,42 @@ sub modify_coursedefaults { } } } - + my $currclone = $domconfig{'coursedefaults'}{'canclone'}; + my @currclonecode; + if (ref($currclone) eq 'HASH') { + if (ref($currclone->{'instcode'}) eq 'ARRAY') { + @currclonecode = @{$currclone->{'instcode'}}; + } + } + my $newclone; + if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) { + $newclone = $env{'form.canclone'}; + } + if ($newclone eq 'instcode') { + my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode'); + my (%codedefaults,@code_order,@clonecode); + &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults, + \@code_order); + foreach my $item (@code_order) { + if (grep(/^\Q$item\E$/,@newcodes)) { + push(@clonecode,$item); + } + } + if (@clonecode) { + $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode }; + my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode); + if (@diffs) { + $changes{'canclone'} = 1; + } + } else { + $newclone eq ''; + } + } elsif ($newclone ne '') { + $defaultshash{'coursedefaults'}{'canclone'} = $newclone; + } + if ($newclone ne $currclone) { + $changes{'canclone'} = 1; + } my %credits; foreach my $type (@types) { unless ($type eq 'community') { @@ -10381,7 +10489,8 @@ sub modify_coursedefaults { if (keys(%changes) > 0) { my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1); if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) || - ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'})) { + ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) || + ($changes{'canclone'})) { foreach my $item ('uselcmath','usejsme') { if ($changes{$item}) { $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item}; @@ -10413,6 +10522,18 @@ sub modify_coursedefaults { } } } + if ($changes{'canclone'}) { + if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') { + if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') { + my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}}; + if (@clonecodes) { + $domdefaults{'canclone'} = join('+',@clonecodes); + } + } + } else { + $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'}; + } + } my $cachetime = 24*60*60; &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime); if (ref($lastactref) eq 'HASH') { @@ -10501,6 +10622,17 @@ sub modify_coursedefaults { } else { $resulttext .= '
  • '.&mt('Student credits not in use for courses in this domain').'
  • '; } + } elsif ($item eq 'canclone') { + if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') { + if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') { + my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}}); + $resulttext .= '
  • '.&mt('By default, official courses can be cloned from existing courses with the same: [_1]',''.$clonecodes.'').'
  • '; + } + } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') { + $resulttext .= '
  • '.&mt('By default, a course requester can clone any course from his/her domain.').'
  • '; + } else { + $resulttext .= '
  • '.&mt('By default, only course owner and coordinators may clone a course.').'
  • '; + } } } $resulttext .= ''; @@ -12010,12 +12142,18 @@ function toggleDisplay(domForm,caller) { if (document.getElementById(caller)) { var divitem = document.getElementById(caller); var optionsElement = domForm.coursecredits; + var checkval = 1; + var dispval = 'block'; if (caller == 'emailoptions') { optionsElement = domForm.cancreate_email; } if (caller == 'studentsubmission') { optionsElement = domForm.postsubmit; } + if (caller == 'cloneinstcode') { + optionsElement = domForm.canclone; + checkval = 'instcode'; + } if (optionsElement.length) { var currval; for (var i=0; i