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

raeburn raeburn at source.lon-capa.org
Tue Aug 31 20:21:52 EDT 2021


raeburn		Wed Sep  1 00:21:52 2021 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm lonconfigsettings.pm 
  Log:
  - Bug 6959 Automated update can be configured to skip checking for changes
    in user information for users deemed inactive. 
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.384 loncom/interface/domainprefs.pm:1.385
--- loncom/interface/domainprefs.pm:1.384	Sun Aug  1 19:28:10 2021
+++ loncom/interface/domainprefs.pm	Wed Sep  1 00:21:52 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.384 2021/08/01 19:28:10 raeburn Exp $
+# $Id: domainprefs.pm,v 1.385 2021/09/01 00:21:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -857,6 +857,8 @@
         $output .= &proctoring_javascript($settings);
     } elsif ($action eq 'wafproxy') {
         $output .= &wafproxy_javascript($dom);
+    } elsif ($action eq 'autoupdate') {
+        $output .= &autoupdate_javascript();
     }
     $output .=
          '<table class="LC_nested_outer">
@@ -3311,6 +3313,41 @@
 ENDSCRIPT
 }
 
+sub autoupdate_javascript {
+    return <<"ENDSCRIPT";
+<script type="text/javascript">
+// <![CDATA[
+function toggleLastActiveDays(form) {
+    var radioname = 'lastactive';
+    var divid = 'lastactive_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 == '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;
+}
+// ]]>
+</script>
+
+ENDSCRIPT
+}
+
 sub print_autoenroll {
     my ($dom,$settings,$rowtotal) = @_;
     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
@@ -3397,42 +3434,69 @@
 
 sub print_autoupdate {
     my ($position,$dom,$settings,$rowtotal) = @_;
-    my $datatable;
+    my ($enable,$datatable);
     if ($position eq 'top') {
+        my %choices = &Apache::lonlocal::texthash (
+                          run        => 'Auto-update active?',
+                          classlists => 'Update information in classlists?',
+                          unexpired  => 'Skip updates for users without active or future roles?',
+                          lastactive => 'Skip updates for inactive users?',
+        );
+        my $itemcount = 0;
         my $updateon = ' ';
         my $updateoff = ' checked="checked" ';
-        my $classlistson = ' ';
-        my $classlistsoff = ' checked="checked" ';
         if (ref($settings) eq 'HASH') {
             if ($settings->{'run'} eq '1') {
                 $updateon = $updateoff;
                 $updateoff = ' ';
             }
-            if ($settings->{'classlists'} eq '1') {
-                $classlistson = $classlistsoff;
-                $classlistsoff = ' ';
-            }
         }
-        my %title = (
-                   run => 'Auto-update active?',
-                   classlists => 'Update information in classlists?',
-                    );
-        $datatable = '<tr class="LC_odd_row">'. 
-                  '<td>'.&mt($title{'run'}).'</td>'.
-                  '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
+        $enable = '<tr class="LC_odd_row">'.
+                  '<td>'.$choices{'run'}.'</td>'.
+                  '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
                   '<input type="radio" name="autoupdate_run"'.
-                  $updateon.' value="1" />'.&mt('Yes').'</label> '.
+                  $updateoff.' value="0" />'.&mt('No').'</label> '.
                   '<label><input type="radio" name="autoupdate_run"'.
-                  $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
-                  '</tr><tr>'.
-                  '<td>'.&mt($title{'classlists'}).'</td>'.
-                  '<td class="LC_right_item"><span class="LC_nobreak">'.
-                  '<label><input type="radio" name="classlists"'.
-                  $classlistson.' value="1" />'.&mt('Yes').'</label> '.
-                  '<label><input type="radio" name="classlists"'.
-                  $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
+                  $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
                   '</tr>';
-        $$rowtotal += 2;
+        my @toggles = ('classlists','unexpired');
+        my %defaultchecked = ('classlists' => 'off',
+                              'unexpired'  => 'off'
+                              );
+        $$rowtotal ++;
+        ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+                                                     \%choices,$itemcount,'','','left','no');
+        $datatable = $enable.$datatable;
+        $$rowtotal += $itemcount;
+        my $lastactiveon = ' ';
+        my $lastactiveoff = ' checked="checked" ';
+        my $lastactivestyle = 'none';
+        my $lastactivedays;
+        my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
+        if (ref($settings) eq 'HASH') {
+            if ($settings->{'lastactive'} =~ /^\d+$/) {
+                $lastactiveon = $lastactiveoff;
+                $lastactiveoff = ' ';
+                $lastactivestyle = 'inline-block';
+                $lastactivedays = $settings->{'lastactive'};
+            }
+        }
+        my $css_class = $itemcount%2?' class="LC_odd_row"':'';
+        $datatable .= '<tr'.$css_class.'>'.
+                      '<td>'.$choices{'lastactive'}.'</td>'.
+                      '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
+                      '<input type="radio" name="lastactive"'.
+                      $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
+                      ' <label>'.
+                      '<input type="radio" name="lastactive"'.
+                      $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
+                      '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
+                      ': '.&mt('inactive = no activity in last [_1] days',
+                          '<input type="text" size="5" name="lastactivedays" value="'.
+                          $lastactivedays.'" />').
+                      '</span></td>'.
+                      '</tr>';
+        $$rowtotal ++;
     } elsif ($position eq 'middle') {
         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
         my $numinrow = 3;
@@ -4561,7 +4625,7 @@
 
 sub radiobutton_prefs {
     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
-        $additional,$align) = @_;
+        $additional,$align,$firstval) = @_;
     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                    (ref($choices) eq 'HASH'));
 
@@ -4601,15 +4665,21 @@
         } else {
             $datatable .= '<td class="LC_right_item">';
         }
-        $datatable .=
-            '<span class="LC_nobreak">'.
-            '<label><input type="radio" name="'.
-            $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
-            '</label> <label><input type="radio" name="'.$item.'" '.
-            $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
-            '</span>'.$additional.
-            '</td>'.
-            '</tr>';
+        $datatable .= '<span class="LC_nobreak">';
+        if ($firstval eq 'no') {
+            $datatable .=
+                '<label><input type="radio" name="'.
+                $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
+                '</label> <label><input type="radio" name="'.$item.'" '.
+                $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
+        } else {
+            $datatable .=
+                '<label><input type="radio" name="'.
+                $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
+                '</label> <label><input type="radio" name="'.$item.'" '.
+                $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
+        }
+        $datatable .= '</span>'.$additional.'</td></tr>';
         $itemcount ++;
     }
     return ($datatable,$itemcount);
@@ -14935,8 +15005,10 @@
     }
     my @offon = ('off','on');
     my %title = &Apache::lonlocal::texthash (
-                   run => 'Auto-update:',
-                   classlists => 'Updates to user information in classlists?'
+                    run        => 'Auto-update:',
+                    classlists => 'Updates to user information in classlists?',
+                    unexpired  => 'Skip updates for users without active or future roles?',
+                    lastactive => 'Skip updates for inactive users?',
                 );
     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
     my %fieldtitles = &Apache::lonlocal::texthash (
@@ -14980,12 +15052,23 @@
     my %updatehash = (
                       autoupdate => { run => $env{'form.autoupdate_run'},
                                       classlists => $env{'form.classlists'},
+                                      unexpired  => $env{'form.unexpired'},
                                       fields => {%fields},
                                       lockablenames => \@lockablenames,
                                     }
                      );
+    my $lastactivedays;
+    if ($env{'form.lastactive'}) {
+        $lastactivedays = $env{'form.lastactivedays'};
+        $lastactivedays =~ s/^\s+|\s+$//g;
+        unless ($lastactivedays =~ /^\d+$/) {
+            undef($lastactivedays);
+            $env{'form.lastactive'} = 0;
+        }
+    }
+    $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
     foreach my $key (keys(%currautoupdate)) {
-        if (($key eq 'run') || ($key eq 'classlists')) {
+        if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
             if (exists($updatehash{autoupdate}{$key})) {
                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                     $changes{$key} = 1;
@@ -15031,6 +15114,16 @@
             $changes{'lockablenames'} = 1;
         }
     }
+    unless (grep(/^unexpired$/,keys(%currautoupdate))) {
+        if ($updatehash{'autoupdate'}{'unexpired'}) {
+            $changes{'unexpired'} = 1;
+        }
+    }
+    unless (grep(/^lastactive$/,keys(%currautoupdate))) {
+        if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
+            $changes{'lastactive'} = 1;
+        }
+    }
     foreach my $item (@{$types},'default') {
         if (defined($fields{$item})) {
             if (ref($currautoupdate{'fields'}) eq 'HASH') {
@@ -15093,6 +15186,11 @@
                     my $newvalue;
                     if ($key eq 'run') {
                         $newvalue = $offon[$env{'form.autoupdate_run'}];
+                    } elsif ($key eq 'lastactive') {
+                        $newvalue = $offon[$env{'form.lastactive'}];
+                        unless ($lastactivedays eq '') {
+                            $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
+                        }
                     } else {
                         $newvalue = $offon[$env{'form.'.$key}];
                     }
Index: loncom/interface/lonconfigsettings.pm
diff -u loncom/interface/lonconfigsettings.pm:1.51 loncom/interface/lonconfigsettings.pm:1.52
--- loncom/interface/lonconfigsettings.pm:1.51	Wed Aug  4 20:10:34 2021
+++ loncom/interface/lonconfigsettings.pm	Wed Sep  1 00:21:52 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: lonconfigsettings.pm,v 1.51 2021/08/04 20:10:34 raeburn Exp $
+# $Id: lonconfigsettings.pm,v 1.52 2021/09/01 00:21:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -263,6 +263,9 @@
             if (grep(/^scantron$/, at actions)) {
                 $onload .= "toggleScantron('document.display');";
             }
+            if (grep(/^autoupdate$/, at actions)) {
+                $onload .= "toggleLastActiveDays('document.display');";
+            }
             if ($onload) {
                 my %loaditems = (
                                   'onload' => $onload,


More information about the LON-CAPA-cvs mailing list