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

raeburn raeburn at source.lon-capa.org
Sat Sep 23 23:31:18 EDT 2023


raeburn		Sun Sep 24 03:31:18 2023 EDT

  Modified files:              
    /loncom/interface	lonquickgrades.pm lonconfigsettings.pm 
                     	courseprefs.pm 
  Log:
  - Bug 2689
  
  
-------------- next part --------------
Index: loncom/interface/lonquickgrades.pm
diff -u loncom/interface/lonquickgrades.pm:1.125 loncom/interface/lonquickgrades.pm:1.126
--- loncom/interface/lonquickgrades.pm:1.125	Sat Oct 29 18:13:28 2022
+++ loncom/interface/lonquickgrades.pm	Sun Sep 24 03:31:18 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Quick Student Grades Display
 #
-# $Id: lonquickgrades.pm,v 1.125 2022/10/29 18:13:28 raeburn Exp $
+# $Id: lonquickgrades.pm,v 1.126 2023/09/24 03:31:18 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -270,9 +270,32 @@
                               $totalRight,$totalAttempted,$topLevelParts,$topLevelRight,
                               $topLevelAttempted);
         } else {
-            &outputTable($r,$showPoints,$notshowTotals,$navmap,$totalParts,$totalPossible,
-                         $totalRight,$totalAttempted,$topLevelParts,$topLevelRight,
-                         $topLevelAttempted);
+            my $nostdtotals;
+            if ($showPoints) {
+                if ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard') {
+                    my $hidetotals = $env{'course.'.$env{'request.course.id'}.'.hidetotals'};
+                    if ($hidetotals eq 'all') {
+                        $nostdtotals = 1;
+                    } elsif ($hidetotals ne '') {
+                        my $usec;
+                        if (($uname eq $env{'user.name'}) && ($env{'user.domain'})) {
+                            $usec = $env{'request.user.section'};
+                        } elsif ($cangrade) {
+                            $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
+                        }
+                        if ($usec ne '') {
+                            my %secnototals;
+                            map { $secnototals{$_} = 1; } split(/,/,$hidetotals);
+                            if ($secnototals{$usec}) {
+                                $nostdtotals = 1;
+                            }
+                        }
+                    }
+                }
+            }
+            &outputTable($r,$showPoints,$notshowTotals,$nostdtotals,$navmap,
+                         $totalParts,$totalPossible,$totalRight,$totalAttempted,
+                         $topLevelParts,$topLevelRight,$topLevelAttempted);
         }
     } else {
         if ($cangrade) { $r->print("\n</form>\n"); }
@@ -350,6 +373,8 @@
 
     my $showPoints =
         $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard';
+    my $hidetotals =
+        $env{'course.'.$env{'request.course.id'}.'.hidetotals'};
     my $notshowSPRSlink =
         (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external')
       || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals')
@@ -378,6 +403,20 @@
        push(@notes,&mt('Students do not see total points.')) if ($notshowTotals);
        push(@notes,&mt('Students do not see link to spreadsheet.')) if ($notshowSPRSlink);
        push(@notes,&mt('Students will see points based on problem weights.')) if ($showPoints);
+       if (($showPoints) && ($hidetotals ne '')) {
+           if ($hidetotals eq 'all') {
+               push(@notes,&mt('Students do not see course totals.'));
+           } else {
+               my @secs = split(/,/,$hidetotals);
+               if (@secs == 1) {
+                   push(@notes,&mt('Students in section [_1] do not see course totals.',
+                                   $hidetotals));
+               } elsif (@secs > 1) {
+                   push(@notes,&mt('Students in sections [_1] do not see course totals.',
+                                   join(', ', at secs)));
+               }
+           }
+       }
        push(@notes,&mt('Students will see points based on categories.')) if ($showCategories);
        push(@notes,&mt('Students will see link to spreadsheet.')) if ($showSPRSlink);
        push(@notes, &Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading'));
@@ -636,8 +675,8 @@
 
 sub outputTable {
 
-    my ($r,$showPoints,$notshowTotals,$navmap,$totalParts,$totalPossible,$totalRight,
-        $totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
+    my ($r,$showPoints,$notshowTotals,$nostdtotals,$navmap,$totalParts,$totalPossible,
+        $totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
 
     my @start = (255, 255, 192);
     my @end   = (0, 192, 0);
@@ -723,16 +762,18 @@
 # show totals (if applicable), close table
 #
     if ($showPoints) {
-        my $maxHelpLink = &Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct");
+        unless ($nostdtotals) {
+            my $maxHelpLink = &Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct");
 
-        $title = $showPoints ? "Points" : "Parts Done";
-        my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done");
-        $r->print(&Apache::loncommon::start_data_table_row()
-                 .'<td colspan="2" align="right">'.$totaltitle.': <b>'.$totalRight.'</b><br />');
-        $r->print(&mt('Max Possible To Date')." $maxHelpLink: <b>$totalPossible</b><br />");
-        $title = $showPoints ? "Points" : "Parts";
-        $r->print(&mt("Total $title In Course").': <b>'.$totalParts.'</b></td>'
-                 .&Apache::loncommon::end_data_table_row());
+            $title = $showPoints ? "Points" : "Parts Done";
+            my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done");
+            $r->print(&Apache::loncommon::start_data_table_row()
+                     .'<td colspan="2" align="right">'.$totaltitle.': <b>'.$totalRight.'</b><br />');
+            $r->print(&mt('Max Possible To Date')." $maxHelpLink: <b>$totalPossible</b><br />");
+            $title = $showPoints ? "Points" : "Parts";
+            $r->print(&mt("Total $title In Course").': <b>'.$totalParts.'</b></td>'
+                     .&Apache::loncommon::end_data_table_row());
+        }
     }
 
     $r->print(&Apache::loncommon::end_data_table());
Index: loncom/interface/lonconfigsettings.pm
diff -u loncom/interface/lonconfigsettings.pm:1.71 loncom/interface/lonconfigsettings.pm:1.72
--- loncom/interface/lonconfigsettings.pm:1.71	Sun Jun  4 00:06:10 2023
+++ loncom/interface/lonconfigsettings.pm	Sun Sep 24 03:31:18 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: lonconfigsettings.pm,v 1.71 2023/06/04 00:06:10 raeburn Exp $
+# $Id: lonconfigsettings.pm,v 1.72 2023/09/24 03:31:18 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -390,6 +390,9 @@
             if (grep(/^localization$/, at actions)) {
                 $onload .= "toggleTimeZone();";
             }
+            if (grep(/^grading$/, at actions)) {
+                $onload .= 'toggleGrading(document.display);toggleHiddenTotalsSec(document.display);';
+            }
             if ($onload) {
                 my %loaditems = (
                                   'onload' => $onload,
Index: loncom/interface/courseprefs.pm
diff -u loncom/interface/courseprefs.pm:1.126 loncom/interface/courseprefs.pm:1.127
--- loncom/interface/courseprefs.pm:1.126	Sat Sep  2 12:51:32 2023
+++ loncom/interface/courseprefs.pm	Sun Sep 24 03:31:18 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set configuration settings for a course
 #
-# $Id: courseprefs.pm,v 1.126 2023/09/02 12:51:32 raeburn Exp $
+# $Id: courseprefs.pm,v 1.127 2023/09/24 03:31:18 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -822,7 +822,7 @@
     } elsif ($action eq 'appearance') {
         $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
     } elsif ($action eq 'grading') {
-        $output .= &print_grading($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
+        $output .= &print_grading($cdom,$cnum,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
     } elsif ($action eq 'printouts') {
         $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
     } elsif ($action eq 'spreadsheet') {
@@ -1550,6 +1550,33 @@
                             } elsif ($values->{$entry}) {
                                 $changes->{$entry} = '';
                             }
+                        } elsif ($entry eq 'grading') {
+                            if ($env{'form.'.$entry} eq 'standard') {
+                                if ($env{'form.hidetotals'}) {
+                                    my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
+                                    if (keys(%sections)) {
+                                        my @secs = &Apache::loncommon::get_env_multiple('form.hidetotals_sections');
+                                        if (grep(/^all$/, at secs)) {
+                                            $newvalues{'hidetotals'} = 'all';
+                                        } elsif (@secs) {
+                                            $newvalues{'hidetotals'} = '';
+                                            foreach my $sec (sort {$a <=> $b} @secs) {
+                                                if (exists($sections{$sec})) {
+                                                    $newvalues{'hidetotals'} .= $sec.','
+                                                }
+                                            }
+                                            $newvalues{'hidetotals'} =~ s/,$//;
+                                        }
+                                    } else {
+                                        $newvalues{'hidetotals'} = 'all';
+                                    }
+                                }
+                            }
+                            if ($newvalues{'hidetotals'} ne $values->{'hidetotals'}) {
+                                $changes->{'hidetotals'} = $newvalues{'hidetotals'};
+                                $changes->{'grading'} = $env{'form.'.$entry};
+                            }
+                            $newvalues{$entry} = $env{'form.'.$entry};
                         } else {
                             $newvalues{$entry} = $env{'form.'.$entry};
                         }
@@ -2631,6 +2658,40 @@
                                     unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
                                         $displayval = $changes->{$item}{$key};
                                     }
+                                    if (($item eq 'grading') && ($key eq 'grading')) {
+                                        if ($displayval eq 'standard') {
+                                            my $hidetotals;
+                                            if (exists($changes->{$item}{'hidetotals'})) {
+                                                if ($changes->{$item}{'hidetotals'} eq '') {
+                                                    if (exists($values->{'hidetotals'})) {
+                                                        push(@delkeys,'hidetotals');
+                                                    }
+                                                } else {
+                                                    $hidetotals = $changes->{$item}{'hidetotals'};
+                                                }
+                                            } elsif (exists($values->{'hidetotals'})) {
+                                                $hidetotals = $values->{'hidetotals'};
+                                            }
+                                            if ($hidetotals eq '') {
+                                                $displayval = &mt('standard with "hide course totals" set to "No"');
+                                                if (exists($values->{'hidetotals'})) {
+                                                    push(@delkeys,'hidetotals');
+                                                }
+                                            } elsif ($hidetotals =~ /^([\w,]+)$/) {
+                                                my $secstr = $1;
+                                                my @secs = split(/,/,$secstr);
+                                                if (grep(/^all$/, at secs)) {
+                                                    $displayval = &mt('standard with "hide course totals" set to "Yes" for all users');
+                                                    $hidetotals = 'all';
+                                                } else {
+                                                    $displayval = &mt('standard with "hide course totals" set to "Yes" for users in section(s): [_1]',join(', ', at secs));
+                                                }
+                                                $storehash{'hidetotals'} = $hidetotals;
+                                            }
+                                        } elsif (exists($values->{'hidetotals'})) {
+                                            push(@delkeys,'hidetotals');
+                                        }
+                                    }
                                     if ($item eq 'feedback') {
                                         if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
                                             $text = $prefs->{$item}->{'itemtext'}{$1.$2};
@@ -3591,7 +3652,7 @@
     }
 }
 ENDSCRIPT
-    my $menuitems_js;
+    my ($menuitems_js,$grading_js);
     unless ($noedit) {
         my $collections;
         my $next = 1;
@@ -3673,6 +3734,48 @@
     }
 }
 ENDSCRIPT
+        $grading_js = <<"ENDSCRIPT";
+function toggleGrading(form) {
+    if (document.getElementById('hidetotalsdiv')) {
+        var totalsdivid = document.getElementById('hidetotalsdiv');
+        var selname = form.elements['grading'];
+        if (selname) {
+            var current = selname.options[selname.selectedIndex].value
+            if (current == 'standard') {
+                totalsdivid.style.display = 'inline-block';
+            } else {
+                totalsdivid.style.display = 'none';
+            }
+        }
+    }
+    return;
+}
+
+function toggleHiddenTotalsSec(form) {
+    if (document.getElementById('sectotalsdiv')) {
+        var sectotalsdivid = document.getElementById('sectotalsdiv');
+        var radioname = form.elements['hidetotals'];
+        if (radioname) {
+            if (radioname.length > 0) {
+                var setvis;
+                for (var i=0; i<radioname.length; i++) {
+                    if (radioname[i].checked == true) {
+                        if (radioname[i].value == 1) {
+                            sectotalsdivid.style.display = 'inline-block';
+                            setvis = 1;
+                        }
+                        break;
+                    }
+                }
+                if (!setvis) {
+                    sectotalsdivid.style.display = 'none';
+                }
+            }
+        }
+    }
+    return;
+}
+ENDSCRIPT
     }
     $extresource_js = <<"ENDSCRIPT";
 function toggleExtRes() {
@@ -3721,7 +3824,7 @@
                $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
                $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
                $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
-               &linkprot_javascript()."\n".'//]]>'."\n".
+               $grading_js."\n".&linkprot_javascript()."\n".'//]]>'."\n".
                '</script>'."\n".$stubrowse_js."\n".$ltitools_js."\n";
     return $jscript;
 }
@@ -5570,7 +5673,7 @@
 }
 
 sub select_sections {
-    my ($item,$num,$sections,$selected,$noedit) = @_;
+    my ($item,$num,$sections,$selected,$noedit,$allval) = @_;
     my ($output, at currsecs,$allsec,$disabled);
     if (ref($selected) eq 'ARRAY') {
         @currsecs = @{$selected};
@@ -5586,16 +5689,24 @@
             my $mult;
             if (@{$sections} > 1) {
                 $mult = ' multiple="multiple"';
+                my $size;
                 if (@{$sections} > 3) {
-                    $mult .= ' size="4"';
+                    $size = 4;
+                } else {
+                    $size = 1 + scalar(@{$sections});
                 }
+                $mult .= ' size="'.$size.'"';
+            }
+            my $name = $item.'_sections';
+            unless ($item eq 'hidetotals') {
+                $name .= '_'.$num;
             }
-            $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.$disabled.'>'.
-                      ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
+            $output = '<select name="'.$name.'"'.$mult.$disabled.'>'.
+                      ' <option value="'.$allval.'"'.$allsec.'>'.&mt('All').'</option>';
             foreach my $sec (@{$sections}) {
                 my $is_sel;
                 if ((@currsecs) && (grep(/^\Q$sec\E$/, at currsecs))) {
-                    $is_sel = 'selected="selected"';
+                    $is_sel = ' selected="selected"';
                 }
                 $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
             }
@@ -6079,7 +6190,7 @@
 }
 
 sub print_grading {
-    my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
+    my ($cdom,$cnum,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
     unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
         return;
     }
@@ -6099,7 +6210,7 @@
                  },
         'rndseed' => {
                    text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
-                           '<span class="LC_warning">'.'<br />'.
+                           '<br /><span class="LC_warning LC_nobreak">'.
                            &mt('Modifying this will make problems have different numbers and answers!').
                            '</span>',
                    input => 'selectbox',
@@ -6131,7 +6242,7 @@
                    input => 'radio',
                  },
     );
-    return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit);
+    return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit,$cnum);
 }
 
 sub print_printouts {
@@ -7710,7 +7821,7 @@
 }
 
 sub yesno_radio {
-    my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit) = @_;
+    my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit,$onclick,$reverse) = @_;
     my $itemon = ' ';
     my $itemoff = ' checked="checked" ';
     if (($valueyes eq '') && ($valueno eq '')) {
@@ -7732,12 +7843,22 @@
     my $disabled;
     if ($noedit) {
         $disabled = ' disabled="disabled"';
+    } elsif ($onclick) {
+        $onclick = ' onclick="'.$onclick.'"';
+    }
+    if ($reverse) {
+        return '<span class="LC_nobreak"><label>'.
+               '<input type="radio" name="'.$item.'"'.
+               $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label> '.
+               '<label><input type="radio" name="'.$item.'"'.
+               $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label></span>';
+    } else {
+        return '<span class="LC_nobreak"><label>'.
+               '<input type="radio" name="'.$item.'"'.
+               $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label> '.
+               '<label><input type="radio" name="'.$item.'"'.
+               $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label></span>';
     }
-    return '<span class="LC_nobreak"><label>'.
-           '<input type="radio" name="'.$item.'"'.
-           $itemon.' value="'.$valueyes.'"'.$disabled.' />'.&mt('Yes').'</label> '.
-           '<label><input type="radio" name="'.$item.'"'.
-           $itemoff.' value="'.$valueno.'"'.$disabled.' />'.&mt('No').'</label></span>';
 }
 
 sub select_from_options {
@@ -7793,7 +7914,7 @@
 }
 
 sub make_item_rows {
-    my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit) = @_;
+    my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit,$cnum) = @_;
     my $datatable;
     if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
         my $count = 0;
@@ -7856,16 +7977,65 @@
                 }
                 $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
             } elsif ($items->{$item}{input} eq 'selectbox') {
-                my $id;
+                my ($id,$onchange);
                 if ($caller eq 'menuitems') {
                     $id = $item;
+                } elsif ($caller eq 'grading') {
+                    if ($item eq 'grading') {
+                        $onchange = ' onchange="javascript:toggleGrading(this.form);"';
+                        $id = $item;
+                    }
                 }
                 my $curr = $settings->{$item};
                 $datatable .=
                     &select_from_options($item,$items->{$item}{'order'},
                                          $items->{$item}{'options'},$curr,
                                          $items->{$item}{'nullval'},
-                                         undef,undef,undef,$noedit,$id);
+                                         undef,undef,$onchange,$noedit,$id);
+                if ($item eq 'grading') {
+                    my ($unsetdefault,$valueyes,$valueno,$sectionbox);
+                    my $gradingsty = 'none';
+                    my $gradingsecsty = 'none';
+                    $unsetdefault = 0;
+                    my (@selsec, at sections,%current);
+                    if ($curr eq 'standard') {
+                        $gradingsty = 'inline-block';
+                        if (ref($settings) eq 'HASH') {
+                            $current{'hidetotals'} = $settings->{'hidetotals'};
+                            if ($settings->{'hidetotals'} =~ /^([\w,]+)$/) {
+                                my $secstr = $1;
+                                unless ($secstr eq 'all') {
+                                    @selsec = split(/,/,$secstr);
+                                }
+                                $current{'hidetotals'} = 1;
+                            }
+                        }
+                    }
+                    $valueyes = "1";
+                    $valueno = "0";
+                    my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
+                    if (keys(%sections)) {
+                        @sections = sort( { $a <=> $b } keys(%sections));
+                    }
+                    my $onclick = 'javascript:toggleHiddenTotalsSec(this.form);';
+                    my $sectionbox = '<div id="sectotalsdiv" style="display:'.$gradingsecsty.'; float:right">';
+                    my $reverse = 1;
+                    if (@sections) {
+                        $sectionbox .= ' ... '.&mt('hidden in sections').': '.
+                                       '<div style="position: relative; top: 0%;">'.
+                                       &select_sections('hidetotals','',\@sections,\@selsec,$noedit,'all').
+                                       '</div>';
+                    }
+                    $sectionbox .= '</div>';
+                    $datatable .= '<fieldset id="hidetotalsdiv" style="display:'.$gradingsty.';">'.
+                                  '<legend style="font-weight: normal;">'.
+                                  &mt('Hide Course Points Totals').'</legend>'.
+                                  '<div style="position: relative; top: 0%; float:left">'.
+                                  &yesno_radio('hidetotals',\%current,$unsetdefault,$valueyes,$valueno,$noedit,
+                                               $onclick,$reverse).'</div>'.
+                                  $sectionbox.
+                                  '</fieldset><div style="padding:0;clear:both;margin:0;border:0"></div>';
+                }
             } elsif ($items->{$item}{input} eq 'textbox') {
                 my $disabled;
                 if ($noedit) {


More information about the LON-CAPA-cvs mailing list