[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface courseprefs.pm

raeburn raeburn at source.lon-capa.org
Wed Jul 3 12:20:51 EDT 2024


raeburn		Wed Jul  3 16:20:51 2024 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	courseprefs.pm 
  Log:
  - For 2.11
    Include a few changes from the many changes in rev. 1.91. Backport 1.127.
  
  
-------------- next part --------------
Index: loncom/interface/courseprefs.pm
diff -u loncom/interface/courseprefs.pm:1.49.2.29 loncom/interface/courseprefs.pm:1.49.2.30
--- loncom/interface/courseprefs.pm:1.49.2.29	Sun Jan 16 18:27:09 2022
+++ loncom/interface/courseprefs.pm	Wed Jul  3 16:20:50 2024
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set configuration settings for a course
 #
-# $Id: courseprefs.pm,v 1.49.2.29 2022/01/16 18:27:09 raeburn Exp $
+# $Id: courseprefs.pm,v 1.49.2.30 2024/07/03 16:20:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -543,7 +543,13 @@
                                                   $cnum,undef,\@allitems,
                                                   'coursepref',$parm_permission);
     } elsif (($phase eq 'display') && ($parm_permission->{'display'})) {
-        my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values);
+        my $noedit;
+        if (ref($parm_permission) eq 'HASH') {
+            unless ($parm_permission->{'process'}) {
+                $noedit = 1;
+            }
+        }
+        my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values,$noedit);
         my @allitems = &get_allitems(%prefs);
         &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
             \@prefs_order,\%prefs,\%values,undef,$jscript,\@allitems,$crstype,
@@ -716,7 +722,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') {
@@ -1258,6 +1264,33 @@
                                 $settings =~ s/,$//;
                             }
                             $newvalues{$entry} = $settings;
+                        } 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};
                         }
@@ -1391,6 +1424,40 @@
                                     unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts')) {
                                         $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};
@@ -1758,7 +1825,7 @@
 }
 
 sub get_jscript {
-    my ($cid,$cdom,$phase,$crstype,$settings) = @_;
+    my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
     my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
     my ($jscript,$categorize_js,$loncaparev_js,$instcode_js);
     my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
@@ -1884,11 +1951,56 @@
     }
 }
 ENDSCRIPT
+    my $grading_js;
+    unless ($noedit) {
+        $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
+    }
     $jscript = '<script type="text/javascript" language="Javascript">'."\n".
                '// <![CDATA['."\n".
                $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
                $cloners_js."\n".$instcode_js.
-               $syllabus_js."\n".'//]]>'."\n".
+               $syllabus_js."\n".$grading_js."\n".'//]]>'."\n".
                '</script>'."\n".$stubrowse_js."\n";
     return $jscript;
 }
@@ -3554,7 +3666,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};
@@ -3570,16 +3682,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.'"';
             }
-            $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.$disabled.'>'.
-                      ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
+            my $name = $item.'_sections';
+            unless ($item eq 'hidetotals') {
+                $name .= '_'.$num;
+            }
+            $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>';
             }
@@ -4031,7 +4151,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;
     }
@@ -4050,7 +4170,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',
@@ -4082,7 +4202,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 {
@@ -4287,7 +4407,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 '')) {
@@ -4309,16 +4429,26 @@
     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 {
-    my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit) = @_;
+    my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
     my $output;
     my $disabled;
     if ($noedit) {
@@ -4334,6 +4464,9 @@
                 $output .= ' size="'.$maxsize.'"';
             }
         }
+        if ($id ne '') {
+            $output .= ' id="'.$id.'"';
+        }
         $output .= $disabled.'>'."\n";
         if ($nullval ne '') {
             $output .= '<option value=""';
@@ -4367,7 +4500,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;
@@ -4418,12 +4551,63 @@
                 }
                 $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
             } elsif ($items->{$item}{input} eq 'selectbox') {
+                my ($id,$onchange);
+                if ($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);
+                                         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