[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface courseprefs.pm
raeburn
raeburn at source.lon-capa.org
Fri May 22 12:39:44 EDT 2015
raeburn Fri May 22 16:39:44 2015 EDT
Modified files: (Branch: version_2_11_X)
/loncom/interface courseprefs.pm
Log:
- For 2.11
Backport 1.71
-------------- next part --------------
Index: loncom/interface/courseprefs.pm
diff -u loncom/interface/courseprefs.pm:1.49.2.17 loncom/interface/courseprefs.pm:1.49.2.18
--- loncom/interface/courseprefs.pm:1.49.2.17 Wed Mar 11 00:28:28 2015
+++ loncom/interface/courseprefs.pm Fri May 22 16:39:43 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set configuration settings for a course
#
-# $Id: courseprefs.pm,v 1.49.2.17 2015/03/11 00:28:28 raeburn Exp $
+# $Id: courseprefs.pm,v 1.49.2.18 2015/05/22 16:39:43 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -217,6 +217,7 @@
use Apache::lonconfigsettings;
use Apache::lonrelrequtils;
use Apache::lonparmset;
+use Apache::courseclassifier;
use Apache::lonlocal;
use LONCAPA qw(:DEFAULT :match);
@@ -540,7 +541,7 @@
\@prefs_order,\%prefs,\%values,
$cnum,undef,\@allitems,'coursepref');
} elsif ($phase eq 'display') {
- my $jscript = &get_jscript($cid,$cdom,$phase,$crstype);
+ my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values);
my @allitems = &get_allitems(%prefs);
&Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
\@prefs_order,\%prefs,\%values,undef,$jscript,\@allitems,$crstype,'coursepref');
@@ -786,7 +787,7 @@
my @clonedoms;
if (exists($env{'form.cloners_activate'})) {
my $actnum = $env{'form.cloners_activate'};
- if ($actnum ne '') {
+ if ($actnum ne '-1') {
if ($env{'form.cloners_dom_'.$actnum} ne '') {
my $clonedom = $env{'form.cloners_dom_'.$actnum};
if (&check_clone($clonedom,$disallowed) eq 'ok') {
@@ -804,7 +805,7 @@
my $clonedom = $env{'form.cloners_dom_'.$i};
if (&check_clone($clonedom,$disallowed) eq 'ok') {
if (!grep(/^\*:\Q$clonedom\E$/, at clonedoms)) {
- push (@clonedoms,'*:'.$clonedom);
+ push(@clonedoms,'*:'.$clonedom);
}
}
}
@@ -850,6 +851,37 @@
}
}
}
+ if (ref($values) eq 'HASH') {
+ my (@code_order,%codedefaults);
+ &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
+ \@code_order);
+ my $clonebycode;
+ if ($env{'form.cloners_instcode'}) {
+ if (@code_order > 0) {
+ my @standardnames = &Apache::loncommon::get_standard_codeitems();
+ my %local_to_standard;
+ for (my $i=0; $i<@code_order; $i++) {
+ $local_to_standard{$code_order[$i]} = $standardnames[$i];
+ }
+ foreach my $item (@code_order) {
+ my $key = $local_to_standard{$item};
+ if ($key ne '') {
+ if ($env{'form.'.$key}) {
+ $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
+ }
+ }
+ }
+ $clonebycode =~ s/\&$//;
+ }
+ }
+ if ($clonebycode) {
+ if ($newvalues{$entry}) {
+ $newvalues{$entry} .= ','.$clonebycode;
+ } else {
+ $newvalues{$entry} = $clonebycode;
+ }
+ }
+ }
}
if (ref($disallowed) eq 'HASH') {
if (ref($disallowed->{'cloners'}) eq 'HASH') {
@@ -1684,12 +1716,93 @@
}
sub get_jscript {
- my ($cid,$cdom,$phase,$crstype) = @_;
+ my ($cid,$cdom,$phase,$crstype,$settings) = @_;
my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
- my ($jscript,$categorize_js,$loncaparev_js);
+ my ($jscript,$categorize_js,$loncaparev_js,$instcode_js);
my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
my $cloners_js = &cloners_javascript($phase);
+ my @code_order;
+ if ($crstype ne 'Community') {
+ if (ref($settings) eq 'HASH') {
+ my %codedefaults;
+ &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
+ \@code_order);
+ if (@code_order > 0) {
+ if ($phase eq 'display') {
+ my @actions = &Apache::loncommon::get_env_multiple('form.actions');
+ if (grep(/^courseinfo$/, at actions)) {
+ if ($settings->{'cloners'} ne '') {
+ unless ($settings->{'cloners'} eq '*') {
+ my @cloners = split(/,/,$settings->{'cloners'});
+ my @standardnames = &Apache::loncommon::get_standard_codeitems();
+ my %local_to_standard;
+ for (my $i=0; $i<@code_order; $i++) {
+ $local_to_standard{$code_order[$i]} = $standardnames[$i];
+ }
+ foreach my $cloner (@cloners) {
+ if (($cloner !~ /^\Q*:\E$match_domain$/) &&
+ ($cloner !~ /^$match_username\:$match_domain$/)) {
+ foreach my $item (split(/\&/,$cloner)) {
+ my ($key,$val) = split(/\=/,$item);
+ $val = &unescape($val);
+ foreach my $code (@code_order) {
+ if ($key eq $local_to_standard{$code}) {
+ $env{'form.'.$key} = $val;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ my @codetitles;
+ (undef,$instcode_js) =
+ &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
+ \@codetitles);
+ $instcode_js .= <<ENDSCRIPT;
+function toggleCloners(callerradio) {
+ if (document.getElementById('LC_cloners_instcode')) {
+ if (callerradio.value == 1) {
+ document.getElementById('LC_cloners_instcode').style.display = "block";
+ } else {
+ uncheckOfficialLists();
+ document.getElementById('LC_cloners_instcode').style.display = "none";
+ }
+ }
+}
+
+if (!document.getElementsByClassName) {
+ function getElementsByClassName(node, classname) {
+ var a = [];
+ var re = new RegExp('(^| )'+classname+'( |$)');
+ var els = node.getElementsByTagName("*");
+ for(var i=0,j=els.length; i<j; i++)
+ if(re.test(els[i].className))a.push(els[i]);
+ return a;
+ }
+}
+
+function uncheckOfficialLists() {
+ var codepicks;
+ if (document.getElementsByClassName) {
+ codepicks = document.getElementsByClassName('LC_cloners_instcodes');
+ } else {
+ codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
+ }
+ if (codepicks.length) {
+ for (var i=0; i<codepicks.length; i++) {
+ codepicks[i].selectedIndex = 0;
+ }
+ }
+}
+
+ENDSCRIPT
+ }
+ }
+ }
if ($can_categorize) {
$categorize_js = <<ENDSCRIPT;
function catsbrowser() {
@@ -1732,7 +1845,7 @@
$jscript = '<script type="text/javascript" language="Javascript">'."\n".
'// <![CDATA['."\n".
$browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
- $cloners_js."\n".
+ $cloners_js."\n".$instcode_js.
$syllabus_js."\n".'//]]>'."\n".
'</script>'."\n".$stubrowse_js."\n";
return $jscript;
@@ -1768,7 +1881,7 @@
if (document.$formname.cloners_activate[i].value == '0') {
document.$formname.cloners_activate[i].checked = false;
}
- if (document.$formname.cloners_activate[i].value == '') {
+ if (document.$formname.cloners_activate[i].value == '-1') {
document.$formname.cloners_activate[i].checked = true;
}
}
@@ -1825,9 +1938,10 @@
unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
return;
}
- my ($cathash,$categoriesform,$autocoowner);
+ my ($cathash,$categoriesform,$autocoowner,$clonedefaults);
my %domconf =
- &Apache::lonnet::get_dom('configuration',['coursecategories','autoenroll'],$cdom);
+ &Apache::lonnet::get_dom('configuration',
+ ['coursecategories','autoenroll','coursedefaults'],$cdom);
if (ref($domconf{'coursecategories'}) eq 'HASH') {
$cathash = $domconf{'coursecategories'}{'cats'};
if (ref($cathash) eq 'HASH') {
@@ -1839,10 +1953,58 @@
if (ref($domconf{'autoenroll'}) eq 'HASH') {
$autocoowner = $domconf{'autoenroll'}{'co-owners'};
}
+ my ($currcanclone, at code_order,$cloner_instcode);
+ my %codedefaults;
+ &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
+ \@code_order);
+ if ($settings->{'cloners'}) {
+ unless ($settings->{'cloners'} eq '*') {
+ my @currclone = split(/,/,$settings->{'cloners'});
+ foreach my $item (@currclone) {
+ unless ($item eq '*') {
+ if (($item !~ /\:/) && ($item =~ /=/)) {
+ $cloner_instcode = 1;
+ }
+ }
+ }
+ }
+ }
+ if (ref($domconf{'coursedefaults'}) eq 'HASH') {
+ my $canclone = $domconf{'coursedefaults'}{'canclone'};
+ if (ref($canclone) eq 'HASH') {
+ if (ref($canclone->{'instcode'}) eq 'ARRAY') {
+ if ($settings->{'internal.coursecode'}) {
+ my @posscodes;
+ if (@code_order > 0) {
+ $currcanclone = 'instcode';
+ foreach my $item (@{$canclone->{'instcode'}}) {
+ if (grep(/^\Q$item\E$/, at code_order)) {
+ push(@posscodes,$item);
+ }
+ }
+ my $codestr = join(' + ', at posscodes);
+ $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
+ '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
+ }
+ }
+ }
+ } elsif ($canclone eq 'domain') {
+ $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
+ '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
+ $currcanclone = 'domain';
+ }
+ if ($clonedefaults) {
+ if ($settings->{'cloners'} ne '') {
+ $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
+ } else {
+ $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
+ }
+ $clonedefaults = '<br /><br />'.$clonedefaults;
+ }
+ }
if (!defined($categoriesform)) {
$categoriesform = &mt('No categories defined in this domain.');
}
-
my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
@@ -1889,7 +2051,8 @@
},
'cloners' => {
text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
- &mt('Owner and Coordinators included automatically'),
+ &mt('Owner and Coordinators included automatically').
+ $clonedefaults,
input => 'textbox',
size => '40'
},
@@ -1960,12 +2123,13 @@
}
$datatable .= 'onchange="javascript:update_cloners('.
"'cloners_all'".');" />'.&mt('Yes').'</label>'.
- (' 'x2).'<input type="radio" name="cloners_all" value="0" ';
+ (' 'x2).'<label>'.
+ '<input type="radio" name="cloners_all" value="0" ';
if ($settings->{$item} ne '*') {
$datatable .= ' checked="checked" ';
}
$datatable .= ' onchange="javascript:update_cloners('.
- "'cloners_all'".');"/>'.&mt('No').'</label></td>'.
+ "'cloners_all'".');" />'.&mt('No').'</label></td>'.
&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table().
'<table><tr><td align="left"><b>'.&mt('Or').
@@ -1973,7 +2137,11 @@
&Apache::loncommon::start_data_table();
my @cloners;
if ($settings->{$item} eq '') {
- $datatable .= &new_cloners_dom_row($cdom,'0');
+ my $default;
+ if ($currcanclone eq 'domain') {
+ $default = '0';
+ }
+ $datatable .= &new_cloners_dom_row($cdom,'0',$default);
} elsif ($settings->{$item} ne '*') {
my @entries = split(/,/,$settings->{$item});
if (@entries > 0) {
@@ -2032,6 +2200,37 @@
$items{$item}{'size'}).
'</td>'.&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table();
+ if (@code_order > 0) {
+ my (%cat_items, at codetitles,%cat_titles,%cat_order);
+ my ($jscript,$totcodes,$numtitles,$lasttitle) =
+ &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
+ \%cat_items,\@codetitles,
+ \%cat_titles,\%cat_order);
+ my $showncodes = 'off';
+ my $checkedoff = ' checked="checked"';
+ my $checkedon = '';
+ if ($cloner_instcode) {
+ $checkedon = $checkedoff;
+ $checkedoff = '';
+ $showncodes = 'on';
+ }
+ $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
+ '</b></td></tr></table>'.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_row().
+ '<td align="left"><span class="LC_nobreak">'.
+ &mt('Cloning by official course(s) based on course category').(' 'x2).
+ '<label>'.
+ '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.' />'.&mt('Yes').'</label>'.
+ (' ').
+ '<label>'.
+ '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.' />'.&mt('No').'</label>'.
+ &Apache::courseclassifier::build_instcode_selectors($numtitles,
+ $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
+ $showncodes,'LC_cloners_instcodes','LC_cloners_instcode').
+ '</td>'.&Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
+ }
} elsif ($item eq 'rolenames') {
$datatable .= '</td><td align="right">'.
&Apache::loncommon::start_data_table();
@@ -2153,19 +2352,24 @@
}
sub new_cloners_dom_row {
- my ($newdom,$num) = @_;
- my $output;
+ my ($newdom,$num,$default) = @_;
+ my ($output,$checkedon,$checkedoff);
if ($newdom ne '') {
+ if ($num eq $default) {
+ $checkedon = 'checked="checked" ';
+ } else {
+ $checkedoff = 'checked="checked" ';
+ }
$output .= &Apache::loncommon::start_data_table_row().
'<td valign="top"><span class="LC_nobreak">'.
&mt('Any user in domain:').' <b>'.$newdom.'</b>'.
(' 'x2).'<label><input type="radio" '.
- 'name="cloners_activate" value="'.$num.'" '.
+ 'name="cloners_activate" value="'.$num.'" '.$checkedon.
'onchange="javascript:update_cloners('.
"'cloners_activate','$num'".');" />'.
&mt('Yes').'</label>'.(' 'x2).
'<label><input type="radio" '.
- 'name="cloners_activate" value="" checked="checked" '.
+ 'name="cloners_activate" value="-1" '.$checkedoff.
'onchange="javascript:update_cloners('.
"'cloners_activate','$num'".');" />'.
&mt('No').'</label><input type="hidden" name="cloners_dom_'.
@@ -4416,17 +4620,19 @@
foreach my $currclone (@allowclone) {
if (!grep(/^$currclone$/,@$oldcloner)) {
if ($currclone ne '*') {
- my ($uname,$udom) = split(/:/,$currclone);
- if ($uname && $udom && $uname ne '*') {
- if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
- my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
- if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
- if ($currclonecrs{'cloneable'} eq '') {
- $currclonecrs{'cloneable'} = $clone_crs;
- } else {
- $currclonecrs{'cloneable'} .= ','.$clone_crs;
+ if ($currclone =~ /:/) {
+ my ($uname,$udom) = split(/:/,$currclone);
+ if ($uname && $udom && $uname ne '*') {
+ if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
+ my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
+ if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
+ if ($currclonecrs{'cloneable'} eq '') {
+ $currclonecrs{'cloneable'} = $clone_crs;
+ } else {
+ $currclonecrs{'cloneable'} .= ','.$clone_crs;
+ }
+ &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
}
- &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
}
}
}
@@ -4436,24 +4642,26 @@
foreach my $oldclone (@$oldcloner) {
if (!grep(/^\Q$oldclone\E$/, at allowclone)) {
if ($oldclone ne '*') {
- my ($uname,$udom) = split(/:/,$oldclone);
- if ($uname && $udom && $uname ne '*' ) {
- if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
- my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
- my %newclonecrs = ();
- if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
- if ($currclonecrs{'cloneable'} =~ /,/) {
- my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
- foreach my $crs (@currclonecrs) {
- if ($crs ne $clone_crs) {
- $newclonecrs{'cloneable'} .= $crs.',';
+ if ($oldclone =~ /:/) {
+ my ($uname,$udom) = split(/:/,$oldclone);
+ if ($uname && $udom && $uname ne '*' ) {
+ if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
+ my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
+ my %newclonecrs = ();
+ if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
+ if ($currclonecrs{'cloneable'} =~ /,/) {
+ my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
+ foreach my $crs (@currclonecrs) {
+ if ($crs ne $clone_crs) {
+ $newclonecrs{'cloneable'} .= $crs.',';
+ }
}
+ $newclonecrs{'cloneable'} =~ s/,$//;
+ } else {
+ $newclonecrs{'cloneable'} = '';
}
- $newclonecrs{'cloneable'} =~ s/,$//;
- } else {
- $newclonecrs{'cloneable'} = '';
+ &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
}
- &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
}
}
}
More information about the LON-CAPA-cvs
mailing list