[LON-CAPA-cvs] cvs: loncom /interface courseclassifier.pm courseprefs.pm lonconfigsettings.pm

raeburn raeburn at source.lon-capa.org
Thu May 21 19:26:35 EDT 2015


raeburn		Thu May 21 23:26:35 2015 EDT

  Modified files:              
    /loncom/interface	courseclassifier.pm courseprefs.pm 
                     	lonconfigsettings.pm 
  Log:
  - General course settings: users allowed to clone course.
    - Show if domain default is set.
    - Adding any course-specific setting will cause domain default to
      be ignored.
    - For official courses, where localenroll::instcode_defaults()
      has been customized, can also allow cloning by specific 
      partial institutional codes (e.g., department + number: such as
      phy184 for example).
  
  
-------------- next part --------------
Index: loncom/interface/courseclassifier.pm
diff -u loncom/interface/courseclassifier.pm:1.21 loncom/interface/courseclassifier.pm:1.22
--- loncom/interface/courseclassifier.pm:1.21	Wed May 13 19:30:13 2015
+++ loncom/interface/courseclassifier.pm	Thu May 21 23:26:34 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utilities for classifying courses based on institutional code
 #
-# $Id: courseclassifier.pm,v 1.21 2015/05/13 19:30:13 raeburn Exp $
+# $Id: courseclassifier.pm,v 1.22 2015/05/21 23:26:34 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -575,15 +575,18 @@
 }
 
 sub build_instcode_selectors {
-    my ($numtitles,$lasttitle,$cat_items,$codetitles,$cat_titles,$cat_order) = @_;
+    my ($numtitles,$lasttitle,$cat_items,$codetitles,$cat_titles,$cat_order,$official,$class,$id) = @_;
     my $output;
     my @standardnames = &Apache::loncommon::get_standard_codeitems();
     if ($numtitles > 0) {
         my $style;
-        if ($env{'form.official'} eq 'off') {
+        if ($official eq 'off') {
             $style = ' style="display: none"';
         }
-        $output .= '<div id="instcodes"'.$style.'><table><tr>';
+        if ($id eq '') {
+            $id = 'instcodes';
+        }
+        $output .= '<div id="'.$id.'"'.$style.'><table><tr>';
         for (my $k=0; $k<$lasttitle-1; $k++) {
             my (@items, at unsorted);
             if (ref($cat_items->{$codetitles->[$k]}) eq 'ARRAY') {
@@ -599,8 +602,11 @@
                 @longitems = @items;
             }
             $output .= '<td align="center">'.$codetitles->[$k].'<br />'."\n".
-                       '<select name="'.$standardnames[$k].'" onchange="courseSet(this)"'.
-                       '>'."\n".'<option value="0">'.&mt('All').'</option>'."\n";
+                       '<select name="'.$standardnames[$k].'" onchange="courseSet(this)"';
+            if ($class) {
+                $output .= ' class="'.$class.'"';
+            }
+            $output .= '>'."\n".'<option value="0">'.&mt('All').'</option>'."\n";
             for (my $i=0; $i<@items; $i++) {
                 if ($longitems[$i] eq '') {
                     $longitems[$i] = $items[$i];
@@ -644,7 +650,7 @@
                    '<input type="radio" name="official" value="off"'.$unofficial.
                    ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
                    &build_instcode_selectors($numtitles,$lasttitle,\%cat_items,$codetitles,
-                                             \%cat_titles,\%cat_order)."\n".
+                                             \%cat_titles,\%cat_order,$env{'form.official'})."\n".
                    '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
                    '<input type="hidden" name="state" value="listing" />'."\n";
     }
Index: loncom/interface/courseprefs.pm
diff -u loncom/interface/courseprefs.pm:1.70 loncom/interface/courseprefs.pm:1.71
--- loncom/interface/courseprefs.pm:1.70	Tue Apr 28 13:20:41 2015
+++ loncom/interface/courseprefs.pm	Thu May 21 23:26:35 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set configuration settings for a course
 #
-# $Id: courseprefs.pm,v 1.70 2015/04/28 13:20:41 raeburn Exp $
+# $Id: courseprefs.pm,v 1.71 2015/05/21 23:26:35 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_'.
@@ -4469,17 +4673,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);
                             }
                         }
                     }
@@ -4489,24 +4695,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);
                             }
                         }
                     }
Index: loncom/interface/lonconfigsettings.pm
diff -u loncom/interface/lonconfigsettings.pm:1.29 loncom/interface/lonconfigsettings.pm:1.30
--- loncom/interface/lonconfigsettings.pm:1.29	Wed Apr 23 10:11:26 2014
+++ loncom/interface/lonconfigsettings.pm	Thu May 21 23:26:35 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: lonconfigsettings.pm,v 1.29 2014/04/23 10:11:26 raeburn Exp $
+# $Id: lonconfigsettings.pm,v 1.30 2015/05/21 23:26:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,15 +36,20 @@
 use Apache::lonhtmlcommon();
 use Apache::lonlocal;
 use Apache::lonparmset();
+use Apache::courseclassifier();
+use LONCAPA qw(:DEFAULT :match); 
 
 sub print_header {
     my ($r,$phase,$context,$jscript,$container) = @_;
-    my ($pagetitle,$brcrumtitle,$action,$call_category_check,$crstype);
+    my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
+        $crstype, at actions, at code_order);
+    if ($phase eq 'display') {
+        @actions = &Apache::loncommon::get_env_multiple('form.actions');
+    }
     if ($context eq 'domain') {
         ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
         $action = '/adm/domainprefs';
         if ($phase eq 'display') {
-            my @actions = &Apache::loncommon::get_env_multiple('form.actions');
             if (grep(/^coursecategories$/, at actions)) {
                 $call_category_check = qq|
     if (formname == document.display) {
@@ -63,6 +68,54 @@
             ($pagetitle,$brcrumtitle) = ('Course Configuration','Course Configuration');
         }
         $action = '/adm/courseprefs';
+        if ($phase eq 'display') {
+            if (grep(/^courseinfo$/, at actions)) {
+                my %codedefaults;
+                &Apache::lonnet::auto_instcode_defaults($env{'request.role.domain'},\%codedefaults,
+                                                        \@code_order);
+                if (@code_order) {
+                   my $noinstcodestr = &mt('You indicated cloning based on category, but did not select any categories.');
+                   $instcode_check = <<"ENDSCRIPT";
+    if (formname == document.display) {
+        if (formname.cloners_instcode.length) {
+            for (var j=0; j<formname.cloners_instcode.length; j++) {
+                if (formname.cloners_instcode[j].checked) {
+                    if (formname.cloners_instcode[j].value == 1) {
+                        var codes;
+                        if (document.getElementsByClassName) {
+                            codes = document.getElementsByClassName('LC_cloners_instcodes');
+                        } else {
+                            codes = getElementsByClassName(document.body,'LC_cloners_instcodes');
+                        }
+                        if (codes.length) {
+                            var gotcode = 0;
+                            for (var i=0; i<codes.length; i++) {
+                                if (codes[i].selectedIndex != 0) {
+                                     gotcode = 1; 
+                                     break;
+                                }
+                            }
+                            if (!gotcode) {
+                                for (var k=0; k<formname.cloners_instcode.length; k++) {
+                                    if (formname.cloners_instcode[k].value == 0) {
+                                        formname.cloners_instcode[k].checked = true;
+                                    }
+                                }
+                                toggleCloners(document.display.cloners_instcode);
+                                alert('$noinstcodestr');
+                                return false;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+ENDSCRIPT
+                }
+            }
+        }
     }
     my $alert = &mt('You must select at least one functionality type to display.');
     my $js = '
@@ -91,7 +144,7 @@
             return;
         }
     }
-    '.$call_category_check.'
+    '.$instcode_check.$call_category_check.'
     formname.submit();
 }'."\n";
     if ($phase eq 'pickactions') {
@@ -120,6 +173,25 @@
                     'onload' => "setFormElements(document.pickactions);",
                         );
         $additem = {'add_entries' => \%loaditems,};
+    } elsif ($phase eq 'display') {
+        if ($context eq 'domain') {
+            if (grep(/^coursedefaults$/, at actions)) {
+                my %loaditems = (
+                    '             onload' => "toggleDisplay(document.display,'cloneinstcode');".
+                                             "toggleDisplay(document.display,'credits');".
+                                             "toggleDisplay(document.display,'studentsubmission');",
+                                );
+                $additem = {'add_entries' => \%loaditems,};
+            }
+        } elsif ($context eq 'course') {
+            if (grep(/^courseinfo$/, at actions)) {
+                if (@code_order) { 
+                    $additem = {
+                                   add_entries => {'onload' => "courseSet('','load');toggleCloners(document.display.cloners_instcode);"},
+                               };
+                }
+            }
+        }
     }
     $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
@@ -255,7 +327,11 @@
     &Apache::lonhtmlcommon::add_breadcrumb
         ({href=>"javascript:changePage(document.$phase,'display')",
           text=>"Display/Edit Settings"});
-    &print_header($r,$phase,$context,$jscript,$container);
+    my $instcode;
+    if (ref($values) eq 'HASH') {
+        $instcode = $values->{'internal.coursecode'};
+    }
+    &print_header($r,$phase,$context,$jscript,$container,$instcode);
     my $divwidth = 900;
     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { 
         if (@actions > 0) {


More information about the LON-CAPA-cvs mailing list