[LON-CAPA-cvs] cvs: loncom /enrollment Autoenroll.pl Enrollment.pm /interface domainprefs.pm lonpopulate.pm

raeburn raeburn at source.lon-capa.org
Mon Dec 27 21:04:35 EST 2021


raeburn		Tue Dec 28 02:04:35 2021 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm lonpopulate.pm 
    /loncom/enrollment	Autoenroll.pl Enrollment.pm 
  Log:
  - Extend "zero enrollment failsafe" mechanism so it can also (optionally)
    protect against unwanted drops if partial data retrieved from institutional
    source for specific institutional section.
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.398 loncom/interface/domainprefs.pm:1.399
--- loncom/interface/domainprefs.pm:1.398	Fri Dec 24 11:07:42 2021
+++ loncom/interface/domainprefs.pm	Tue Dec 28 02:04:35 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.398 2021/12/24 11:07:42 raeburn Exp $
+# $Id: domainprefs.pm,v 1.399 2021/12/28 02:04:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -877,6 +877,8 @@
         $output .= &wafproxy_javascript($dom);
     } elsif ($action eq 'autoupdate') {
         $output .= &autoupdate_javascript();
+    } elsif ($action eq 'autoenroll') {
+        $output .= &autoenroll_javascript();
     } elsif ($action eq 'login') {
         $output .= &saml_javascript();
     } elsif ($action eq 'ipaccess') {
@@ -3688,6 +3690,41 @@
 ENDSCRIPT
 }
 
+sub autoenroll_javascript {
+    return <<"ENDSCRIPT";
+<script type="text/javascript">
+// <![CDATA[
+function toggleFailsafe(form) {
+    var radioname = 'autoenroll_failsafe';
+    var divid = 'autoenroll_failsafe_div';
+    var num = form.elements[radioname].length;
+    if (num) {
+        var setvis = '';
+        for (var i=0; i<num; i++) {
+            if (form.elements[radioname][i].checked) {
+                if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
+                    if (document.getElementById(divid)) {
+                        document.getElementById(divid).style.display = 'inline-block';
+                    }
+                    setvis = 1;
+                }
+                break;
+            }
+        }
+        if (!setvis) {
+            if (document.getElementById(divid)) {
+                document.getElementById(divid).style.display = 'none';
+            }
+        }
+    }
+    return;
+}
+// ]]>
+</script>
+
+ENDSCRIPT
+}
+
 sub saml_javascript {
     return <<"ENDSCRIPT";
 <script type="text/javascript">
@@ -3801,7 +3838,12 @@
 sub print_autoenroll {
     my ($dom,$settings,$rowtotal) = @_;
     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
-    my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
+    my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
+        $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
+    $failsafesty = 'none';
+    %failsafechecked = (
+        off => ' checked="checked"',
+    );
     if (ref($settings) eq 'HASH') {
         if (exists($settings->{'run'})) {
             if ($settings->{'run'} eq '0') {
@@ -3835,8 +3877,24 @@
         if (exists($settings->{'sender_domain'})) {
             $defdom = $settings->{'sender_domain'};
         }
-        if (exists($settings->{'autofailsafe'})) {
-            $failsafe = $settings->{'autofailsafe'};
+        if (exists($settings->{'failsafe'})) {
+            $failsafe = $settings->{'failsafe'};
+            if ($failsafe eq 'zero') {
+                $failsafechecked{'zero'} = ' checked="checked"'; 
+                $failsafechecked{'off'} = '';
+                $failsafesty = 'inline-block';
+            } elsif ($failsafe eq 'any') {
+                $failsafechecked{'any'} = ' checked="checked"';
+                $failsafechecked{'off'} = '';
+            }
+            $autofailsafe = $settings->{'autofailsafe'};
+        } elsif (exists($settings->{'autofailsafe'})) {
+            $autofailsafe = $settings->{'autofailsafe'};
+            if ($autofailsafe ne '') {
+                $failsafechecked{'zero'} = ' checked="checked"';
+                $failsafe = 'zero';
+                $failsafechecked{'off'} = ''; 
+            }
         }
     } else {
         if ($autorun) {
@@ -3876,8 +3934,14 @@
                   '</tr><tr>'.
                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   '<td class="LC_right_item"><span class="LC_nobreak">'.
-                  '<input type="text" name="autoenroll_failsafe"'.
-                  ' value="'.$failsafe.'" size="4" /></span></td></tr>';
+                  '<span class="LC_nobreak"><label><input type="radio name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)" />'.&mt('Not in use').'</label></span><br />'.
+                  '<span class="LC_nobreak"><label><input type="radio name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)" />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
+                  '<span class="LC_nobreak"><label><input type="radio name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)" />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
+                  '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
+                  '<span class="LC_nobreak">'.
+                  &mt('Threshold for number of students in section to drop: [_1]',
+                      '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
+                  '</span></div></td></tr>';
     $$rowtotal += 4;
     return $datatable;
 }
@@ -15918,7 +15982,7 @@
     my %title = ( run => 'Auto-enrollment active',
                   sender => 'Sender for notification messages',
                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
-                  failsafe => 'Failsafe for no drops if institutional data missing for a section');
+                  autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
     my @offon = ('off','on');
     my $sender_uname = $env{'form.sender_uname'};
     my $sender_domain = $env{'form.sender_domain'};
@@ -15928,17 +15992,23 @@
         $sender_domain = '';
     }
     my $coowners = $env{'form.autoassign_coowners'};
+    my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
+    $autofailsafe =~ s{^\s+|\s+$}{}g;
+    if ($autofailsafe =~ /\D/) {
+        undef($autofailsafe);
+    }
     my $failsafe = $env{'form.autoenroll_failsafe'};
-    $failsafe =~ s{^\s+|\s+$}{}g;
-    if ($failsafe =~ /\D/) {
-        undef($failsafe);
+    unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
+        $failsafe = 'off';
+        undef($autofailsafe);      
     }
     my %autoenrollhash =  (
                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                                        'sender_uname' => $sender_uname,
                                        'sender_domain' => $sender_domain,
                                        'co-owners' => $coowners,
-                                       'autofailsafe' => $failsafe,
+                                       'autofailsafe' => $autofailsafe,
+                                       'failsafe' => $failsafe, 
                                 }
                      );
     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
@@ -15966,9 +16036,12 @@
         } elsif ($coowners) {
             $changes{'coowners'} = 1;
         }
-        if ($currautoenroll{'autofailsafe'} ne $failsafe) {
+        if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
             $changes{'autofailsafe'} = 1;
         }
+        if ($currautoenroll{'failsafe'} ne $failsafe) {
+            $changes{'failsafe'} = 1;
+        }
         if (keys(%changes) > 0) {
             $resulttext = &mt('Changes made:').'<ul>';
             if ($changes{'run'}) {
@@ -15989,11 +16062,24 @@
                 }
             }
             if ($changes{'autofailsafe'}) {
-                if ($failsafe ne '') {
-                    $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
+                if ($autofailsafe ne '') {
+                    $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
                 } else {
-                    $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
+                    $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
                 }
+            }
+            if ($changes{'failsafe'}) {
+                if ($failsafe eq 'off') {
+                    unless ($changes{'autofailsafe'}) {
+                        $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
+                    }
+                } elsif ($failsafe eq 'zero') {
+                    $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
+                } else {
+                    $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
+                }
+            }
+            if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
                 &Apache::lonnet::get_domain_defaults($dom,1);
                 if (ref($lastactref) eq 'HASH') {
                     $lastactref->{'domdefaults'} = 1;
Index: loncom/interface/lonpopulate.pm
diff -u loncom/interface/lonpopulate.pm:1.89 loncom/interface/lonpopulate.pm:1.90
--- loncom/interface/lonpopulate.pm:1.89	Fri Aug 20 21:16:13 2021
+++ loncom/interface/lonpopulate.pm	Tue Dec 28 02:04:35 2021
@@ -1,5 +1,5 @@
 # automated enrollment configuration handler
-# $Id: lonpopulate.pm,v 1.89 2021/08/20 21:16:13 raeburn Exp $
+# $Id: lonpopulate.pm,v 1.90 2021/12/28 02:04:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -50,8 +50,9 @@
 ###############################################################
 
 sub choose_header {
-    my ($action,$permref) = @_;
+    my ($action,$permref,$dom) = @_;
     my $notify_check = '/^note_[0-9]+$/';
+    my $additems;
     my %js_lt = 
         &Apache::lonlocal::texthash(
             adds => 'You must select either "Enable" or "Disable" for nightly additions based on classlist changes',
@@ -220,18 +221,58 @@
 }
 
 ENDJSTWO
+    } elsif ($action eq 'chgfailsafe') {
+        my %domconfig =
+            &Apache::lonnet::get_dom('configuration',['autoenroll'],$dom);
+        my $includedom = 1;
+        if (ref($domconfig{'autoenroll'}) eq 'HASH') {
+            if ($domconfig{'autoenroll'}->{'failsafe'} eq 'off') {
+                $includedom = 0;
+            }
+        }
+        $scripttag .= <<ENDJSTHREE;
+
+function toggleFailsafe(form) {
+    var radioname = 'autodropfailsafetype';
+    var divid = 'autodropfailsafe';
+    var num = form.elements[radioname].length;
+    if (num) {
+        var includedom = '$includedom';
+        var setvis = '';
+        for (var i=0; i<num; i++) {
+            if (form.elements[radioname][i].checked) {
+                if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any') || ((form.elements[radioname][i].value == 'dom') && (includedom == 1))) {
+                    if (document.getElementById(divid)) {
+                        document.getElementById(divid).style.display = 'inline-block';
+                    }
+                    setvis = 1;
+                }
+                break;
+            }
+        }
+        if (!setvis) {
+            if (document.getElementById(divid)) {
+                document.getElementById(divid).style.display = 'none';
+            }
+        }
+    }
+    return;
+}
+
+ENDJSTHREE
+        $additems = { 'onload' => "toggleFailsafe(document.enter);" };
     }
     $scripttag .= <<ENDJS;
 // ]]>
 </script>
 ENDJS
-    my $args = &make_crumbs($action,$permref);
+    my $args = &make_crumbs($action,$permref,$additems);
     return &Apache::loncommon::start_page('Classlist Manager',
 					  $scripttag,$args);
 }
 
 sub make_crumbs {
-    my ($action,$permref) = @_;
+    my ($action,$permref,$additems) = @_;
     my ($tasklong,$tasktitle) = &get_task_text($permref);
     my $brcrum = [{href=>"/adm/createuser",
                    text=>"User Management",},
@@ -255,7 +296,8 @@
             );
     }
     return {bread_crumbs           => $brcrum,
-            bread_crumbs_component => 'Automated Management'};
+            bread_crumbs_component => 'Automated Management',
+            add_entries => $additems};
 }
 
 sub print_navmenu {
@@ -369,8 +411,8 @@
               <td>'.&mt('Use [_1]View students and change type[_2] to display the current course roster, and (optionally) change enrollment type for selected students from "auto" to "manual" and vice versa.','<i>"','"</i>').'</td>
             </tr>
             <tr>
-            <td> </td>
-              <td>'.&mt('Use [_1]Change zero enrollment failsafe[_2] to set number of existing enrollments in an institutional section above which no automated drops occur whenever section enrollment retrieved from institutional data is zero.','<i>"','"</i>').'</td>
+             <td> </td>
+             <td>'.&mt('Use [_1]View/change enrollment failsafe[_2] to (a) set number of drops from existing enrollments in an institutional section above which no automated drops will occur (e.g., when section enrollment retrieved from institutional data is incomplete) and (b) set whether this only applies when retrieved data contains zero records for the institutional section.','<i>"','"</i>').'</td>
             </tr>');
       } else {
           if (($permref->{'view'}) || ($permref->{'view_section'} ne '')) {
@@ -407,8 +449,8 @@
                         '<i>"','"</i>').'</td>
             </tr>
             <tr>
-            <td> </td>
-              <td>'.&mt('Use [_1]Zero enrollment failsafe[_2] to set number of existing enrollments in an institutional section above which no automated drops occur whenever section enrollment retrieved from institutional data is zero.','<i>"','"</i>').'</td>
+             <td> </td>
+             <td>'.&mt('Use [_1]Enrollment failsafe[_2] to display (a) number of drops from existing enrollments in an institutional section above which no automated drops occur (e.g., when section enrollment retrieved from institutional data is incomplete), and (b) whether this only applies when retrieved data contains zero records for the institutional section.','<i>"','"</i>').'</td>
             </tr>');
           }
           if (($permref->{'show'}) || ($permref->{'show_section'} ne '')) {
@@ -495,7 +537,12 @@
             <input type="hidden" name="state" value="process" />
             </form>'."\n");
   } elsif ($action eq 'chgfailsafe') {
-      my $autofailsafe;
+      my ($autofailsafe,$failsafetype,$failsafesty,%failsafechecked);
+      $failsafesty = 'inline-block';
+      %failsafechecked = (
+          dom => ' checked="checked"',
+      );
+      my $domdefault;
       my %domconfig =
           &Apache::lonnet::get_dom('configuration',['autoenroll'],$dom);
       if (ref($domconfig{'autoenroll'}) eq 'HASH') {
@@ -503,42 +550,101 @@
           if ($autofailsafe =~ /\D/) {
               undef($autofailsafe);
           }
+          if ($domconfig{'autoenroll'}->{'failsafe'} eq 'off') {
+              undef($autofailsafe);
+              $failsafesty = 'none';
+              $failsafetype = 'off';
+              $domdefault = &mt('Failsafe is not in use.');
+          } elsif ($domconfig{'autoenroll'}->{'failsafe'} eq 'any') {
+              $failsafesty = 'inline-block';
+              $failsafetype = 'any';
+              $domdefault = &mt('Failsafe will apply if retrieved enrollment for institutional section is zero or greater.');
+          } else {
+              $failsafesty = 'inline-block';
+              $failsafetype = 'zero';
+              $domdefault = &mt('Failsafe will only apply if retrieved enrollment for institutional section is zero.');
+          }
+      }
+      if ((exists($enrollvar{'autodropfailsafetype'})) &&
+          ($enrollvar{'autodropfailsafetype'} ne '')) {
+          if ($enrollvar{'autodropfailsafetype'} eq 'off') {
+              $failsafesty = 'none';
+              $failsafechecked{'dom'} = '';
+              $failsafechecked{'off'} = ' checked="checked"';
+          } elsif ($enrollvar{'autodropfailsafetype'} eq 'any') {
+              $failsafesty = 'inline-block';
+              $failsafechecked{'dom'} = '';
+              $failsafechecked{'any'} = ' checked="checked"';
+          } elsif ($enrollvar{'autodropfailsafetype'} eq 'zero') {
+              $failsafesty = 'inline-block';
+              $failsafechecked{'dom'} = '';
+              $failsafechecked{'zero'} = ' checked="checked"';
+          }
       }
       $r->print('
           <form name="enter" method="post" action=""><br />
            <table width="100%" border="0" cellpadding="2" cellspacing="2">
             <tr>
              <td align="left"><b>'.$$tasktitleref{$action}.'</b><br /><p>'.
-             &mt('In a course where multiple institutional sections provide enrollment, the "failsafe" value can prevent automated enrollment from expiring student roles for registered students in one section, in the case where no enrollment is returned for that particular section because of a temporary institutional data retrieval problem external to LON-CAPA.').'</p>'.
-            '<p>'.&mt('For example if this value is set to 10, and the current LON-CAPA enrollment count is 11 or more for a particular course section, no role expiration will occur if the latest retrieved enrollment count is zero for that institutional section (or cross-listing).').'</p>');
+             &mt('The "failsafe" mechanism for automated enrollment can prevent unwanted expiration of student roles for registered students in an institutional section, in the case where either no enrollment, or only partial enrollment, is returned for that particular section because of a temporary institutional data retrieval problem external to LON-CAPA.').'</p>'.
+            '<p>'.&mt('For example if the threshold is set to 10, and the current LON-CAPA enrollment count is 11 or more for a particular course section, no role expiration will occur if the latest retrieved enrollment count is zero for that institutional section (or cross-listing).').'</p>');
       if ($enrollvar{'autodropfailsafe'} eq '') {
-          $r->print('<p>'.&mt('Currently no course-specific failsafe value is set.').' ');
+          $r->print('<p>'.&mt('Currently no course-specific failsafe threshold is set.').' ');
           if ($autofailsafe eq '') {
               $r->print(&mt('Currently no domain default failsafe is set either.'));
           } else {
-              $r->print(&mt('The current domain default of [_1] will apply, unless a value is set here specific to this course.',$autofailsafe));
+              $r->print(&mt('The current domain default of [_1] will apply unless a value is set here specific to this course.','<b>'.$autofailsafe.'</b>'));
           }
           $r->print('</p>');
       } else {
-          $r->print('<p>'.&mt('Currently, the course-specific failsafe is set to [_1].',"<i>$enrollvar{'autodropfailsafe'}</i>").'</p>');
+          unless (($enrollvar{'autodropfailsafetype'} eq 'off') || 
+                  (($enrollvar{'autodropfailsafetype'} eq '') && ($failsafetype eq 'off'))) {
+              $r->print('<p>'.&mt('Currently, the course-specific failsafe is set to [_1].',"<i>$enrollvar{'autodropfailsafe'}</i>").'</p>');
+          }
+      }
+      unless (($enrollvar{'autodropfailsafe'} eq '') && ($autofailsafe eq '')) {
+          if ($enrollvar{'autodropfailsafetype'} eq '') {
+              $r->print('<p>'.&mt('Currently no course-specific failsafe condition is set.').' ');
+              if ($failsafetype eq 'any') {
+                  $r->print(&mt('The current domain default, whereby the failsafe is in effect if the retrieved section enrollment is zero or greater, will apply unless overridden here for this specific course.'));
+              } elsif ($failsafetype eq 'zero') {
+                  $r->print(&mt('The current domain default, whereby the failsafe is only in effect if the retrieved section enrollment is zero, will apply unless overridden here for this specific course.'));
+              } elsif ($failsafetype eq 'off') {
+                  $r->print(&mt('The current domain default (failsafe not in use) will apply unless overridden here for this specific course.'));
+              }
+              $r->print('</p>');
+          } else {
+              if ($enrollvar{'autodropfailsafetype'} eq 'zero') {
+                  $r->print('<p>'.&mt('Currently, the course-specific failsafe condition is set such that any failsafe threshold is only in effect when the retrieved institutional section enrollment is zero.'));
+              } elsif ($enrollvar{'autodropfailsafetype'} eq 'any') {
+                  $r->print('<p>'.&mt('Currently, the course-specific failsafe condition is set such that any failsafe threshold is in effect when the retrieved institutional section enrollment is zero (or greater).'));
+              } elsif ($enrollvar{'autodropfailsafetype'} eq 'off') {
+                  $r->print('<p>'.&mt('Currently, the course-specific failsafe condition is set such that a failsafe will not be used.'));
+              }
+              $r->print('</p>');
+          }
       }
       $r->print('
              </td>
             </tr>
            </table>
            <table width="100%" border="0" cellpadding="3" cellspacing="3">
-            <tr>
-             <td><b>
-            '.&mt('Failsafe (enter an integer)').'</b>  
-              <input type="textbox" name="autodropfailsafe" value="'.$enrollvar{'autodropfailsafe'}.'" size="4"'.$disabled.' /><br />');
-       if ($enrollvar{'autodropfailsafe'}) {
-          if ($autofailsafe) {  
-              $r->print(&mt('Leave blank to use domain default of [_1].',$autofailsafe));
-          } else {
-              $r->print(&mt('Leave blank to not use.'));
-          }
+             <tr>
+             <td><b>'.&mt('Condition for use of failsafe in this course').'</b><br />
+             <span class="LC_nobreak"><label><input type="radio" name="autodropfailsafetype" value="dom" onclick="toggleFailsafe(this.form);"'.$failsafechecked{'dom'}.$disabled.' />'.&mt('Use domain default').'</label></span> -- '.$domdefault.'<br />
+             <span class="LC_nobreak"><label><input type="radio" name="autodropfailsafetype" value="zero" onclick="toggleFailsafe(this.form);"'.$failsafechecked{'zero'}.$disabled.' />'.&mt('Failsafe will apply if retrieved institutional section enrollment is zero.').'</label></span><br />
+             <span class="LC_nobreak"><label><input type="radio" name="autodropfailsafetype" value="any" onclick="toggleFailsafe(this.form);"'.$failsafechecked{'any'}.$disabled.' />'.&mt('Failsafe will apply if retrieved institutional section enrollment is zero or greater.').'</label></span><br />
+             <span class="LC_nobreak"><label><input type="radio" name="autodropfailsafetype" value="off" onclick="toggleFailsafe(this.form);"'.$failsafechecked{'off'}.$disabled.' />'.&mt('Failsafe will not be in use in this course.').'</label></span><br />
+             <div class="LC_floatleft" style="display:'.$failsafesty.';" id="autodropfailsafe">
+             <span class="LC_nobreak"><b>'.
+             &mt('Failsafe threshold (enter an integer)').'</b>  
+             <input type="text" name="autodropfailsafe" value="'.$enrollvar{'autodropfailsafe'}.'" size="4"'.$disabled.' /></span><br />');
+       if ($autofailsafe) {
+           $r->print(&mt('Leave blank to use domain default of [_1].','<b>'.$autofailsafe.'</b>'));
+       } else {
+           $r->print(&mt('As no domain default is set, failsafe will not be used if blank.'));
        }
-       $r->print('
+       $r->print('</div>
              </td>
             </tr>
             <tr>
@@ -1683,32 +1789,58 @@
 
 sub print_chgfailsafe_response {
     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
-    my %settings = &Apache::lonnet::get('environment',['internal.autodropfailsafe'],
+    my %settings = &Apache::lonnet::get('environment',
+                                        ['internal.autodropfailsafe',
+                                         'internal.autodropfailsafetype'],
                                         $dom,$crs);
-    my ($currfailsafe,$newfailsafe,$response);
-    if ( defined($settings{'internal.autodropfailsafe'}) ) {
+    my ($currfailsafe,$newfailsafe,$currfailsafetype,$newfailsafetype,$response);
+    if (defined($settings{'internal.autodropfailsafe'})) {
         $currfailsafe = $settings{'internal.autodropfailsafe'};
     }
+    if (defined($settings{'internal.autodropfailsafetype'})) {
+        $currfailsafetype = $settings{'internal.autodropfailsafetype'};
+    }
     if (exists($env{'form.autodropfailsafe'})) {
         $env{'form.autodropfailsafe'} =~ s{^\s+|\s+$}{}g;
         if ($env{'form.autodropfailsafe'} !~ /\D/) { 
             $newfailsafe = $env{'form.autodropfailsafe'};
         }
     }
-    if ($currfailsafe ne $newfailsafe) {
-        my %cenv = ('internal.autodropfailsafe' => $newfailsafe);
+    if ($env{'form.autodropfailsafetype'} =~ /^(any|zero|off)$/) {
+        $newfailsafetype = $env{'form.autodropfailsafetype'};
+    }
+    if (($currfailsafe ne $newfailsafe) || ($currfailsafetype ne $newfailsafetype)) {
+        my %cenv = ('internal.autodropfailsafe' => $newfailsafe,
+                    'internal.autodropfailsafetype' => $newfailsafetype,
+                   );
         my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
         if ($reply ne 'ok') {
             $response =
                 &mt('There was a problem processing your requested changes.').' '.
                 &mt('The automated enrollment settings for this course have been left unchanged.').'<br />';
-        } elsif ($newfailsafe ne '') {
-            $response = &mt('Automated drop failsafe set to [_1]',$newfailsafe);
         } else {
-            $response = &mt('Course-specific automated drop failsafe deleted.');
+            if ($currfailsafetype ne $newfailsafetype) {
+                if ($env{'form.autodropfailsafetype'} eq 'dom') {
+                    $response = &mt('Course-specific setting for condition for when failsafe applies deleted; domain default now applies.');
+                } elsif ($newfailsafetype eq 'off') {
+                    $response = &mt('Course-specific setting set to disable failsafe use.');
+                } elsif ($newfailsafetype eq 'zero') {
+                    $response = &mt('Course-specific setting set so failsafe applies when zero enrollment retrieved for an institutional section.');
+                } else {
+                    $response = &mt('Course-specific setting set so failsafe applies when zero or greater enrollment is retrieved for an institutional section.');
+                }
+                $response .= '<br />';
+            }
+            if ($currfailsafe ne $newfailsafe) {
+                if ($newfailsafe ne '') {
+                    $response .= &mt('Course-specific setting for drop failsafe threshold set to [_1]',$newfailsafe);
+                } else {
+                    $response .= &mt('Course-specific setting for drop failsafe threshold deleted; domain default now applies.');
+                }
+            }
         }
     } else {
-        $response = &mt('The new value for the automated drop failsafe was the same as the existing value, so no changes have been made.'); 
+        $response = &mt('The new values for the automated drop failsafe threshold and conditions under which failsafe applies were the same as the existing values, so no changes have been made.'); 
     }
     &print_reply($r,$response,$$tasktitleref{$action});
     return;
@@ -3488,7 +3620,7 @@
         &Apache::lonlocal::texthash(
            information   => 'Task information',
            chgsettings   => 'Automated adds/drops',
-           chgfailsafe   => 'Change zero enrollment failsafe',
+           chgfailsafe   => 'View/change enrollment failsafe',
            setdates      => 'Change enrollment dates',
            setaccess     => 'Change access dates',
            notify        => 'Notification of changes',
@@ -3520,7 +3652,7 @@
     );
 
     if ((ref($permref) eq 'HASH') && (!$permref->{'edit'})) {
-        $tasklong{'chgfailsafe'} = &mt('Zero enrollment failsafe');
+        $tasklong{'chgfailsafe'} = &mt('Enrollment failsafe');
         $tasklong{'setdates'}    = &mt('Enrollment dates');
         $tasklong{'setaccess'}   = &mt('Access dates');
         $tasklong{'crosslist'}   = &mt('Crosslistings');
@@ -3628,12 +3760,12 @@
         $r->print(&header($action,\%permhash));
     } else {
         if ($state eq "choose") {
-            $r->print(&choose_header($action,\%permhash));
+            $r->print(&choose_header($action,\%permhash,$dom));
         } else {
             if ($action eq "crosslist") {
                 if ( exists($env{'form.numcross'}) ) {
                     if ( $env{'form.numcross'} > 0 ) {
-                        $r->print(&choose_header($action,\%permhash));
+                        $r->print(&choose_header($action,\%permhash,$dom));
                     } else {
                         $r->print(&header($action,\%permhash));
                     }
@@ -3643,7 +3775,7 @@
             } elsif ($action eq "sections") {
                 if ( exists($env{'form.numsec'}) ) {
                     if ( $env{'form.numsec'} > 0 ) {
-                        $r->print(&choose_header($action,\%permhash));
+                        $r->print(&choose_header($action,\%permhash,$dom));
                     } else {
                         $r->print(&header($action,\%permhash));
                     }
Index: loncom/enrollment/Autoenroll.pl
diff -u loncom/enrollment/Autoenroll.pl:1.35 loncom/enrollment/Autoenroll.pl:1.36
--- loncom/enrollment/Autoenroll.pl:1.35	Tue Jun 15 20:52:27 2021
+++ loncom/enrollment/Autoenroll.pl	Tue Dec 28 02:04:35 2021
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
 #Automated Enrollment script
-# $Id: Autoenroll.pl,v 1.35 2021/06/15 20:52:27 raeburn Exp $
+# $Id: Autoenroll.pl,v 1.36 2021/12/28 02:04:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -52,7 +52,7 @@
     foreach my $dom (@domains) {
         #only run if configured to
         my $run_enroll = 0;
-        my ($domsettings,$autofailsafe);
+        my ($domsettings,$autofailsafe,$autofailsafetype);
         my %domconfig =
             &Apache::lonnet::get_dom('configuration',['autoenroll','coursedefaults'],$dom);
         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
@@ -63,6 +63,9 @@
             if ($domsettings->{'autofailsafe'} ne '') {
                 $autofailsafe = $domsettings->{'autofailsafe'};
             }
+            if ($domsettings->{'failsafe'} =~ /^(zero|any|off)$/) {
+                 $autofailsafetype = $domsettings->{'failsafe'};
+            }
         } else {
             $run_enroll = &localenroll::run($dom);
         }
@@ -186,7 +189,11 @@
                         if ($enrollvar{$crs}{'autodropfailsafe'}) {
                             $failsafe = $enrollvar{$crs}{'autodropfailsafe'};
                         }
-                        my ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$enrollvar{$crs}{autoadds},$enrollvar{$crs}{autodrops},$enrollvar{$crs}{startdate},$enrollvar{$crs}{enddate},$enrollvar{$crs}{authtype},$enrollvar{$crs}{autharg},$showcredits,$defaultcredits,$failsafe,$affiliates{$crs},$LC_code{$crs},\$logmsg,\$newusermsg,'automated');
+                        my $failsafetype = $autofailsafetype;
+                        if ($enrollvar{$crs}{'autodropfailsafetype'}) {
+                            $failsafetype = $enrollvar{$crs}{'autodropfailsafetype'};  
+                        }
+                        my ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$enrollvar{$crs}{autoadds},$enrollvar{$crs}{autodrops},$enrollvar{$crs}{startdate},$enrollvar{$crs}{enddate},$enrollvar{$crs}{authtype},$enrollvar{$crs}{autharg},$showcredits,$defaultcredits,$failsafe,$failsafetype,$$affiliates{$crs},$LC_code{$crs},\$logmsg,\$newusermsg,'automated');
                         print $fh &mt('Messages start for [_1]',$crs)."\n";
                         print $fh "$logmsg\n";
                         print $fh &mt('Messages end for [_1]',$crs)."\n";
Index: loncom/enrollment/Enrollment.pm
diff -u loncom/enrollment/Enrollment.pm:1.56 loncom/enrollment/Enrollment.pm:1.57
--- loncom/enrollment/Enrollment.pm:1.56	Fri Oct  8 18:49:17 2021
+++ loncom/enrollment/Enrollment.pm	Tue Dec 28 02:04:35 2021
@@ -1,5 +1,5 @@
 # Automated Enrollment manager
-# $Id: Enrollment.pm,v 1.56 2021/10/08 18:49:17 raeburn Exp $
+# $Id: Enrollment.pm,v 1.57 2021/12/28 02:04:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -41,8 +41,8 @@
 
 sub update_LC {
     my ($dom,$crs,$adds,$drops,$startdate,$enddate,$authtype,$autharg,
-        $showcredits,$defaultcredits,$autofailsafe,$classesref,$groupref,
-        $logmsg,$newusermsg,$context,$phototypes) = @_;
+        $showcredits,$defaultcredits,$autofailsafe,$failsafe,$classesref,
+        $groupref,$logmsg,$newusermsg,$context,$phototypes) = @_;
 # Get institutional code and title of this class
     my %courseinfo = ();
     &get_courseinfo($dom,$crs,\%courseinfo);
@@ -452,11 +452,20 @@
 # Check enrollment count for institutional section of student to be dropped 
                         if ($$currlist{$uname}[$instidx]) {
                             if (exists($classcount{$$currlist{$uname}[$instidx]})) {
-                                if ($classcount{$$currlist{$uname}[$instidx]} == 0) {
+                                if ($failsafe eq 'any') { 
                                     if ($autofailsafe) {
-                                        push(@{$delaydrops{$$currlist{$uname}[$instidx]}},$uname);    
+                                        push(@{$delaydrops{$$currlist{$uname}[$instidx]}},$uname);
                                         next;
                                     }
+                                } else {
+                                    unless ($failsafe eq 'off') {
+                                        if ($classcount{$$currlist{$uname}[$instidx]} == 0) {
+                                            if ($autofailsafe) {
+                                                push(@{$delaydrops{$$currlist{$uname}[$instidx]}},$uname);
+                                                next;
+                                            }
+                                        }
+                                    }
                                 }
                             }
                         }


More information about the LON-CAPA-cvs mailing list