--- loncom/interface/domainprefs.pm 2015/05/11 18:11:42 1.263
+++ loncom/interface/domainprefs.pm 2015/05/21 22:59:16 1.264
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.263 2015/05/11 18:11:42 raeburn Exp $
+# $Id: domainprefs.pm,v 1.264 2015/05/21 22:59:16 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2910,6 +2910,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,
@@ -2921,10 +2922,82 @@ sub print_coursedefaults {
'canuse_pdfforms' => 'off',
'uselcmath' => 'on',
'usejsme' => 'on',
+ 'canclone' => 'none',
);
@toggles = ('canuse_pdfforms','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);
@@ -10317,7 +10390,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') {
@@ -10401,7 +10509,8 @@ sub modify_coursedefaults {
if (keys(%changes) > 0) {
my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
- ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'})) {
+ ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
+ ($changes{'canclone'})) {
foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
if ($changes{$item}) {
$domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
@@ -10433,6 +10542,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') {
@@ -10527,6 +10648,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 .= '';
@@ -12036,12 +12168,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