[LON-CAPA-cvs] cvs: loncom /interface courseprefs.pm domainprefs.pm lonmodifycourse.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Sat Mar 7 18:17:21 EST 2015


raeburn		Sat Mar  7 23:17:21 2015 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm courseprefs.pm lonmodifycourse.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Additional Course/Community defaults for JSME Molecule Editor and Math
    Previewer (can be overridden in a course by CC), and for disabling submit
    button after student submission, with/without timeout, setby course container 
    type (can be overriden for specific course by a DC).   
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.256 loncom/interface/domainprefs.pm:1.257
--- loncom/interface/domainprefs.pm:1.256	Tue Mar  3 22:06:50 2015
+++ loncom/interface/domainprefs.pm	Sat Mar  7 23:17:15 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.256 2015/03/03 22:06:50 raeburn Exp $
+# $Id: domainprefs.pm,v 1.257 2015/03/07 23:17:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2844,7 +2844,7 @@
 
 sub radiobutton_prefs {
     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
-        $additional) = @_;
+        $additional,$align) = @_;
     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                    (ref($choices) eq 'HASH'));
 
@@ -2878,8 +2878,14 @@
         $datatable .=
             '<tr'.$css_class.'><td valign="top">'.
             '<span class="LC_nobreak">'.$choices->{$item}.
-            '</span></td>'.
-            '<td class="LC_right_item"><span class="LC_nobreak">'.
+            '</span></td>';
+        if ($align eq 'left') {
+            $datatable .= '<td class="LC_left_item">';
+        } 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.'" '.
@@ -2901,21 +2907,29 @@
         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
         coursecredits        => 'Credits can be specified for courses',
+        uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
+        usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
+        postsubmit           => 'Disable submit button/keypress following student submission',
     );
     my %staticdefaults = (
                            anonsurvey_threshold => 10,
                            uploadquota          => 500,
+                           postsubmit           => 60,
                          );
     if ($position eq 'top') {
-        %defaultchecked = ('canuse_pdfforms' => 'off');
-        @toggles = ('canuse_pdfforms');
+        %defaultchecked = (
+                            'canuse_pdfforms' => 'off',
+                            'uselcmath'       => 'on',
+                            'usejsme'         => 'on',
+                          );
+        @toggles = ('canuse_pdfforms','uselcmath','usejsme');
         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
-                                                 \%choices,$itemcount);
+                                                     \%choices,$itemcount);
     } else {
         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
-        my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
-            %curruploadquota);
+        my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
         my $currusecredits = 0;
+        my $postsubmitclient = 1;
         my @types = ('official','unofficial','community','textbook');
         if (ref($settings) eq 'HASH') {
             $currdefresponder = $settings->{'anonsurvey_threshold'};
@@ -2925,12 +2939,36 @@
                 }
             }
             if (ref($settings->{'coursecredits'}) eq 'HASH') {
-                $def_official_credits = $settings->{'coursecredits'}->{'official'};
-                $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
-                $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
-                if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
-                    ($def_textbook_credits ne '')) {
-                    $currusecredits = 1;
+                foreach my $type (@types) {
+                    next if ($type eq 'community');
+                    $defcredits{$type} = $settings->{'coursecredits'}->{$type};
+                    if ($defcredits{$type} ne '') {
+                        $currusecredits = 1;
+                    }
+                }
+            }
+            if (ref($settings->{'postsubmit'}) eq 'HASH') {
+                if ($settings->{'postsubmit'}->{'client'} eq 'off') {
+                    $postsubmitclient = 0;
+                    foreach my $type (@types) {
+                        $deftimeout{$type} = $staticdefaults{'postsubmit'};
+                    }
+                } else {
+                    foreach my $type (@types) {
+                        if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
+                            if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
+                                $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type}; 
+                            } else {
+                                $deftimeout{$type} = $staticdefaults{'postsubmit'};
+                            }
+                        } else {
+                            $deftimeout{$type} = $staticdefaults{'postsubmit'};
+                        }
+                    }
+                }
+            } else {
+                foreach my $type (@types) {
+                    $deftimeout{$type} = $staticdefaults{'postsubmit'};
                 }
             }
         }
@@ -2972,21 +3010,14 @@
             $display = 'block';
         }
         my $additional = '<div id="credits" style="display: '.$display.'">'.
-                         '<span class="LC_nobreak">'.
-                         &mt('Default credits for official courses [_1]',
-                         '<input type="text" name="official_credits" value="'.
-                         $def_official_credits.'" size="3" />').
-                         '</span><br />'.
-                         '<span class="LC_nobreak">'.
-                         &mt('Default credits for unofficial courses [_1]',
-                         '<input type="text" name="unofficial_credits" value="'.
-                         $def_unofficial_credits.'" size="3" />').
-                         '</span><br />'.
-                         '<span class="LC_nobreak">'.
-                         &mt('Default credits for textbook courses [_1]',
-                         '<input type="text" name="textbook_credits" value="'.
-                         $def_textbook_credits.'" size="3" />').
-                         '</span></div>'."\n";
+                         '<i>'.&mt('Default credits').'</i><br /><table><tr>';
+        foreach my $type (@types) {
+            next if ($type eq 'community');
+            $additional .= '<td align="center">'.&mt($type).'<br />'.
+                           '<input type="text" name="'.$type.'_credits"'.
+                           ' value="'.$defcredits{$type}.'" size="5" /></td>';
+        }
+        $additional .= '</tr></table></div>'."\n";
         %defaultchecked = ('coursecredits' => 'off');
         @toggles = ('coursecredits');
         my $current = {
@@ -2994,9 +3025,30 @@
                       };
         (my $table,$itemcount) =
             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
-                               \%choices,$itemcount,$onclick,$additional);
+                               \%choices,$itemcount,$onclick,$additional,'left');
+        $datatable .= $table;
+        $onclick = "toggleDisplay(this.form,'studentsubmission');";
+        my $display = 'none';
+        if ($postsubmitclient) {
+            $display = 'block';
+        }
+        $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
+                      '<i>'.&mt('Number of seconds submit is disabled').'</i><br /><table><tr>';
+        foreach my $type (@types) {
+            $additional .= '<td align="center">'.&mt($type).'<br />'.
+                           '<input type="text" name="'.$type.'_timeout" value="'.
+                           $deftimeout{$type}.'" size="5" /></td>';
+        }
+        $additional .= '</tr></table></div>'."\n";
+        %defaultchecked = ('postsubmit' => 'on');
+        @toggles = ('postsubmit');
+        my $current = {
+                        'postsubmit' => $postsubmitclient,
+                      };
+        ($table,$itemcount) =
+            &radiobutton_prefs($current,\@toggles,\%defaultchecked,
+                               \%choices,$itemcount,$onclick,$additional,'left');
         $datatable .= $table;
-        $itemcount ++;
     }
     $$rowtotal += $itemcount;
     return $datatable;
@@ -10174,14 +10226,19 @@
 sub modify_coursedefaults {
     my ($dom,$lastactref,%domconfig) = @_;
     my ($resulttext,$errors,%changes,%defaultshash);
-    my %defaultchecked = ('canuse_pdfforms' => 'off');
-    my @toggles = ('canuse_pdfforms');
+    my %defaultchecked = (
+                           'canuse_pdfforms' => 'off',
+                           'uselcmath'       => 'on',
+                           'usejsme'         => 'on'
+                         );
+    my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
                    'uploadquota_community','uploadquota_textbook');
     my @types = ('official','unofficial','community','textbook');
     my %staticdefaults = (
                            anonsurvey_threshold => 10,
                            uploadquota          => 500,
+                           postsubmit           => 60,
                          );
 
     $defaultshash{'coursedefaults'} = {};
@@ -10243,26 +10300,81 @@
             }
         }
 
-        my $officialcreds = $env{'form.official_credits'};
-        $officialcreds =~ s/[^\d.]+//g;
-        my $unofficialcreds = $env{'form.unofficial_credits'};
-        $unofficialcreds =~ s/[^\d.]+//g;
-        my $textbookcreds = $env{'form.textbook_credits'};
-        $textbookcreds =~ s/[^\d.]+//g;
-        if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
-                ($env{'form.coursecredits'} eq '1')) {
-                $changes{'coursecredits'} = 1;
-        } else {
-            if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds)  ||
-                ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
-                ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
-                $changes{'coursecredits'} = 1;
-            }
-        }
-        $defaultshash{'coursedefaults'}{'coursecredits'} = {
-            official   => $officialcreds,
-            unofficial => $unofficialcreds,
-            textbook   => $textbookcreds,
+        my %credits;
+        foreach my $type (@types) {
+            unless ($type eq 'community') {
+                $credits{$type} = $env{'form.'.$type.'_credits'};
+                $credits{$type} =~ s/[^\d.]+//g;
+            }
+        }
+        if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
+            ($env{'form.coursecredits'} eq '1')) {
+            $changes{'coursecredits'} = 1;
+            foreach my $type (keys(%credits)) {
+                $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
+            }
+        } else {
+            if ($env{'form.coursecredits'} eq '1') { 
+                foreach my $type (@types) {
+                    unless ($type eq 'community') {
+                        if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {        
+                            $changes{'coursecredits'} = 1;
+                        }
+                        $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
+                    }
+                }
+            } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
+                foreach my $type (@types) {
+                    unless ($type eq 'community') {
+                        if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
+                            $changes{'coursecredits'} = 1;
+                            last;
+                        }
+                    }
+                }
+            }
+        }
+        if ($env{'form.postsubmit'} eq '1') {
+            $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
+            my %currtimeout;
+            if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
+                if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
+                    $changes{'postsubmit'} = 1;
+                }
+                if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
+                    %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
+                }
+            } else {
+                $changes{'postsubmit'} = 1;
+            }
+            foreach my $type (@types) {
+                my $timeout = $env{'form.'.$type.'_timeout'};
+                $timeout =~ s/\D//g;
+                if ($timeout == $staticdefaults{'postsubmit'}) {
+                    $timeout = '';
+                } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
+                    $timeout = '0';
+                }
+                unless ($timeout eq '') {
+                    $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
+                }
+                if (exists($currtimeout{$type})) {
+                    if ($timeout ne $currtimeout{$type}) {
+                        $changes{'postsubmit'} = 1; 
+                    }
+                } elsif ($timeout ne '') {
+                    $changes{'postsubmit'} = 1;
+                }
+            }
+        } else {
+            $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
+            if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
+                if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
+                    $changes{'postsubmit'} = 1;
+                }
+            } else {
+                $changes{'postsubmit'} = 1;
+            }
         }
     }
     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
@@ -10270,19 +10382,30 @@
     if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {
             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
-            if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || 
-                ($changes{'uploadquota'})) { 
-                if ($changes{'canuse_pdfforms'}) {
-                    $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
-                }
+            if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
+                ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'})) { 
+                foreach my $item ('canuse_pdfforms','uselcmath','usejsme') { 
+                    if ($changes{$item}) {
+                        $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
+                    }
+                } 
                 if ($changes{'coursecredits'}) {
                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
-                        $domdefaults{'officialcredits'} =
-                            $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
-                        $domdefaults{'unofficialcredits'} =
-                            $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
-                        $domdefaults{'textbookcredits'} =
-                            $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
+                        foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
+                            $domdefaults{$type.'credits'} =
+                                $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
+                        }
+                    }
+                }
+                if ($changes{'postsubmit'}) {
+                    if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
+                        $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
+                        if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
+                            foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
+                                $domdefaults{$type.'postsubtimeout'} =
+                                    $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
+                            }
+                        }
                     }
                 }
                 if ($changes{'uploadquota'}) {
@@ -10306,6 +10429,18 @@
                     } else {
                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                     }
+                } elsif ($item eq 'uselcmath') {
+                    if ($env{'form.'.$item} eq '1') {
+                        $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
+                    } else {
+                        $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
+                    }
+                } elsif ($item eq 'usejsme') {
+                    if ($env{'form.'.$item} eq '1') {
+                        $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
+                    } else {
+                        $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>'; 
+                    }
                 } elsif ($item eq 'anonsurvey_threshold') {
                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
                 } elsif ($item eq 'uploadquota') {
@@ -10321,6 +10456,42 @@
                     } else {
                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                     }
+                } elsif ($item eq 'postsubmit') {
+                    if ($domdefaults{'postsubmit'} eq 'off') {
+                        $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
+                    } else {
+                        $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
+                        if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') { 
+                            $resulttext .= &mt('durations:').'<ul>';
+                            foreach my $type (@types) {
+                                $resulttext .= '<li>';
+                                my $timeout;
+                                if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
+                                    $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
+                                }
+                                my $display;
+                                if ($timeout eq '0') {
+                                    $display = &mt('unlimited');
+                                } elsif ($timeout eq '') {
+                                    $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
+                                } else {
+                                    $display = &mt('[quant,_1,second]',$timeout);
+                                }
+                                if ($type eq 'community') {
+                                    $resulttext .= &mt('Communities');
+                                } elsif ($type eq 'official') {
+                                    $resulttext .= &mt('Official courses');
+                                } elsif ($type eq 'unofficial') {
+                                    $resulttext .= &mt('Unofficial courses');
+                                } elsif ($type eq 'textbook') {
+                                    $resulttext .= &mt('Textbook courses');
+                                }
+                                $resulttext .= ' -- '.$display.'</li>';
+                            }
+                            $resulttext .= '</ul>';
+                        }
+                        $resulttext .= '</li>';    
+                    }
                 } elsif ($item eq 'coursecredits') {
                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                         if (($domdefaults{'officialcredits'} eq '') &&
@@ -11797,6 +11968,9 @@
         if (caller == 'emailoptions') {
             optionsElement = domForm.cancreate_email; 
         }
+        if (caller == 'studentsubmission') {
+            optionsElement = domForm.postsubmit;
+        }
         if (optionsElement.length) {
             var currval;
             for (var i=0; i<optionsElement.length; i++) {
Index: loncom/interface/courseprefs.pm
diff -u loncom/interface/courseprefs.pm:1.68 loncom/interface/courseprefs.pm:1.69
--- loncom/interface/courseprefs.pm:1.68	Sun Aug  3 01:47:49 2014
+++ loncom/interface/courseprefs.pm	Sat Mar  7 23:17:15 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set configuration settings for a course
 #
-# $Id: courseprefs.pm,v 1.68 2014/08/03 01:47:49 raeburn Exp $
+# $Id: courseprefs.pm,v 1.69 2015/03/07 23:17:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -463,13 +463,15 @@
                      help => 'Course_Prefs_Display',
                      ordered => ['default_xml_style','pageseparators',
                                  'disable_receipt_display','texengine',
-                                 'tthoptions'],
+                                 'tthoptions','uselcmath','usejsme'],
                       itemtext => {
                           default_xml_style       => 'Default XML style file',
                           pageseparators          => 'Visibly Separate Items on Pages',
                           disable_receipt_display => 'Disable display of problem receipts',
                           texengine               => 'Force use of a specific math rendering engine',
                           tthoptions              => 'Default set of options to pass to tth/m when converting TeX',
+                          uselcmath               => 'Student formula entry uses inline preview, not DragMath pop-up',
+                          usejsme                 => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
                                   },
                   },
         'grading' =>
@@ -1405,7 +1407,7 @@
                                         $displayval = &Apache::lonlocal::locallocaltime($displayval);
                                     } elsif ($key eq 'categories') {
                                         $displayval = $env{'form.categories_display'};
-                                    } elsif ($key eq 'canuse_pdfforms') {
+                                    } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') || ($key eq 'uselcmath')) {
                                         if ($changes->{$item}{$key} eq '1') {
                                             $displayval = &mt('Yes');
                                         } elsif ($changes->{$item}{$key} eq '0') {
@@ -3697,6 +3699,14 @@
                    input => 'textbox',
                    size => 40,
                  },
+         'uselcmath' => {
+                   text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
+                   input => 'radio',
+                 },
+         'usejsme'  => {
+                   text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
+                   input => 'radio',
+                 },
     );
     return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance');
 }
@@ -3959,20 +3969,30 @@
 }
 
 sub yesno_radio {
-    my ($item,$settings) = @_;
+    my ($item,$settings,$unsetdefault,$valueyes,$valueno) = @_;
     my $itemon = ' ';
     my $itemoff = ' checked="checked" ';
+    if (($valueyes eq '') && ($valueno eq '')) {
+        $valueyes = 'yes';
+        $valueno = '';
+    }
     if (ref($settings) eq 'HASH') {
-        if ($settings->{$item} eq 'yes') {
+        if ($settings->{$item} eq $valueyes) {
             $itemon = $itemoff;
             $itemoff = ' ';
         }
+        unless (exists($settings->{$item})) {
+            if ($unsetdefault eq $valueyes) {
+                $itemon = $itemoff;
+                $itemoff = ' ';
+            }
+        }
     }
     return '<span class="LC_nobreak"><label>'.
            '<input type="radio" name="'.$item.'"'.
-           $itemon.' value="yes" />'.&mt('Yes').'</label> '.
+           $itemon.' value="'.$valueyes.'" />'.&mt('Yes').'</label> '.
            '<label><input type="radio" name="'.$item.'"'.
-           $itemoff.' value="" />'.&mt('No').'</label></span>';
+           $itemoff.' value="'.$valueno.'" />'.&mt('No').'</label></span>';
 }
 
 sub select_from_options {
@@ -4057,7 +4077,16 @@
                    &Apache::lonhtmlcommon::date_setter('display',$item,
                                                        $settings->{$item});
             } elsif ($items->{$item}{input} eq 'radio') {
-                $datatable .= &yesno_radio($item,$settings);
+                my ($unsetdefault,$valueyes,$valueno);
+                if (($item eq 'usejsme') || ($item eq 'uselcmath')) {
+                     my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
+                     unless ($domdefs{$item} eq '0') {
+                         $unsetdefault = 1;
+                     }
+                     $valueyes = "1";
+                     $valueno = "0";
+                }
+                $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno);
             } elsif ($items->{$item}{input} eq 'selectbox') {
                 my $curr = $settings->{$item};
                 $datatable .=
@@ -4133,7 +4162,8 @@
                           '<span class="LC_nobreak"><label>'.
                           '<input type="radio" name="'.$item.'_'.$user.'"'.
                           $hideon.' value="" />'.&mt('Hidden').'</label> '.
-                          '<label><input type="radio" name="'.$item.'_'.$user.'"'.                          $hideoff.' value="yes" />'.&mt('Shown').'</label></span></td>'.
+                          '<label><input type="radio" name="'.$item.'_'.$user.'"'.
+                          $hideoff.' value="yes" />'.&mt('Shown').'</label></span></td>'.
                           '</tr>';
         }
         $datatable .= '</table>';
Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.74 loncom/interface/lonmodifycourse.pm:1.75
--- loncom/interface/lonmodifycourse.pm:1.74	Thu Jul 31 15:45:27 2014
+++ loncom/interface/lonmodifycourse.pm	Sat Mar  7 23:17:15 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # handler for DC-only modifiable course settings
 #
-# $Id: lonmodifycourse.pm,v 1.74 2014/07/31 15:45:27 musolffc Exp $
+# $Id: lonmodifycourse.pm,v 1.75 2015/03/07 23:17:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -261,7 +261,8 @@
         }
         $cat_text = 'View/Modify catalog settings for course';
     }
-    my $anon_text = 'Responder threshold required to display anonymous survey submissions';
+    my $anon_text = &mt('Responder threshold required to display anonymous survey submissions.');
+    my $postsubmit_text = &mt('Override defaults for submit button behavior post-submission for this specific course.'); 
 
     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
     my @additional_params = &catalog_settable($domconf{'coursecategories'},$type);
@@ -332,6 +333,14 @@
                 permission => &manage_selfenrollment($cdom,$cnum,$type,$coursehash),
                 linktitle => 'Configure user self-enrollment.',
             },
+            {
+                linktext => 'View/Modify submit button behavior, post-submission',
+                icon => 'emblem-readonly.png',
+                #help => '',
+                url => &phaseurl('setpostsubmit'),
+                permission => 1,
+                linktitle => '',
+            },
         ]
         },
         );
@@ -360,7 +369,8 @@
     }
     $menu_html .= '<li>'.$setquota_text.'</li>'."\n".
                   '<li>'.$setuploadquota_text.'</li>'."\n".
-                  '<li>'.$anon_text.'</li>'."\n";
+                  '<li>'.$anon_text.'</li>'."\n".
+                  '<li>'.$postsubmit_text.'</li>'."\n";
     foreach my $item (@additional_params) {
         if ($type eq 'Community') {
             if ($item eq 'togglecats') {
@@ -555,6 +565,98 @@
     return;
 }
 
+sub print_postsubmit_config {
+    my ($r,$cdom,$cnum,$cdesc,$type) = @_;
+    my %lt = &Apache::lonlocal::texthash (
+                'conf' => 'Configure submit button behavior after student makes a submission',
+                'disa' => 'Disable submit button/keypress following student submission',
+                'nums' => 'Number of seconds submit is disabled',
+                'modi' => 'Save',
+                'back' => 'Pick another action',
+                'yes'  => 'Yes',
+                'no'   => 'No',
+    );
+    my %settings = &Apache::lonnet::get('environment',['internal.postsubmit','internal.postsubtimeout',
+                                                       'internal.coursecode','internal.textbook'],$cdom,$cnum);
+    my $postsubmit = $settings{'internal.postsubmit'};
+    if ($postsubmit eq '') {
+        my %domconfig =
+            &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
+        $postsubmit = 1; 
+        if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
+            if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
+                if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
+                    $postsubmit = 0; 
+                }
+            }
+        }
+    }
+    my ($checkedon,$checkedoff,$display);
+    if ($postsubmit) {
+        $checkedon = 'checked="checked"';
+        $display = 'block';
+    } else {
+        $checkedoff = 'checked="checked"';
+        $display = 'none';
+    }
+    my $postsubtimeout = $settings{'internal.postsubtimeout'};
+    my $default = &domain_postsubtimeout($cdom,$type,\%settings);
+    my $zero = &mt('(Enter 0 to disable until next page reload, or leave blank to use the domain default: [_1])',$default);
+    if ($postsubtimeout eq '') {
+        $postsubtimeout = $default;
+    }
+    &print_header($r,$type);
+    my $hidden_elements = &hidden_form_elements();
+    my $helpitem = &Apache::loncommon::help_open_topic('Modify_Postsubmit_Config');
+    $r->print(<<ENDDOCUMENT);
+<form action="/adm/modifycourse" method="post" name="setpostsubmit" onsubmit="return verify_postsubmit();">
+<h3>$lt{'conf'} <span class="LC_nobreak">($cdesc)</span></h3>
+<p>
+$helpitem $lt{'disa'}: 
+<label><input type="radio" name="postsubmit" $checkedon onclick="togglePostsubmit('studentsubmission');" value="1" />
+$lt{'yes'}</label>  
+<label><input type="radio" name="postsubmit" $checkedoff onclick="togglePostsubmit('studentsubmission');" value="0" />
+$lt{'no'}</label>
+<div id="studentsubmission" style="display: $display">
+$lt{'nums'} <input type="text" name="postsubtimeout" value="$postsubtimeout" /><br />
+$zero</div>
+<br />     
+<input type="submit" value="$lt{'modi'}" />
+</p>
+$hidden_elements
+<a href="javascript:changePage(document.setpostsubmit,'menu')">$lt{'back'}</a>
+</form>
+ENDDOCUMENT
+    return;
+}
+
+sub domain_postsubtimeout {
+    my ($cdom,$type,$settings) = @_;
+    return unless (ref($settings) eq 'HASH'); 
+    my $lctype = lc($type);
+    unless ($type eq 'Community') {
+        $lctype = 'unofficial';
+        if ($settings->{'internal.coursecode'}) {
+            $lctype = 'official';
+        } elsif ($settings->{'internal.textbook'}) {
+            $lctype = 'textbook';
+        }
+    }
+    my %domconfig =
+        &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
+    my $postsubtimeout = 60;
+    if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
+        if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
+            if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
+                if ($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$lctype} ne '') {
+                    $postsubtimeout = $domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$lctype};
+                }
+            }
+        }
+    }
+    return $postsubtimeout;
+}
+
 sub print_catsettings {
     my ($r,$cdom,$cnum,$cdesc,$type) = @_;
     &print_header($r,$type);
@@ -1543,7 +1645,83 @@
     }
     $r->print('<p>'.
               '<a href="javascript:changePage(document.processthreshold,'."'menu'".')">'.
-              &mt('Pick another action').'</a>');
+              &mt('Pick another action').'</a></p>');
+    $r->print(&hidden_form_elements().'</form>');
+    return;
+}
+
+sub modify_postsubmit_config {
+    my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
+    &print_header($r,$type);
+    my %lt = &Apache::lonlocal::texthash(
+                subb => 'Submit button behavior after student makes a submission:',
+                unch => 'Post submission behavior of the Submit button is unchanged.',
+                erro => 'An error occurred when saving your proposed changes.',
+                inva => 'An invalid response was recorded.',
+                pick => 'Pick another action',
+             );
+    $r->print('<form action="/adm/modifycourse" method="post" name="processpostsubmit">'."\n".
+              '<h3>'.$lt{'subb'}.' <span class="LC_nobreak">('.$cdesc.')</span></h3><br />');
+    my %oldsettings = 
+        &Apache::lonnet::get('environment',['internal.postsubmit','internal.postsubtimeout','internal.coursecode','internal.textbook'],$cdom,$cnum);
+    my $postsubmit = $env{'form.postsubmit'};
+    if ($postsubmit eq '1') {
+        my $postsubtimeout = $env{'form.postsubtimeout'};
+        $postsubtimeout =~ s/[^\d\.]+//g;
+        if (($oldsettings{'internal.postsubmit'} eq $postsubmit) && ($oldsettings{'internal.postsubtimeout'} eq $postsubtimeout)) {
+            $r->print($lt{'unch'}); 
+        } else {
+            my %cenv = (
+                         'internal.postsubmit' => $postsubmit,
+                       );
+            if ($postsubtimeout eq '') {
+                my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
+                if ($putreply eq 'ok') {
+                    my $defaulttimeout = &domain_postsubtimeout($cdom,$type,\%oldsettings);
+                    $r->print(&mt('The proposed duration for disabling the Submit button post-submission was blank, so the domain default of [quant,_1,second] will be used.',$defaulttimeout));
+                    if (exists($oldsettings{'internal.postsubtimeout'})) {
+                        &Apache::lonnet::del('environment',['internal.postsubtimeout'],$cdom,$cnum);
+                    }
+                } else {
+                    $r->print($lt{'erro'});
+                }
+            } else { 
+                $cenv{'internal.postsubtimeout'} = $postsubtimeout;
+                my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
+                if ($putreply eq 'ok') {
+                    if ($postsubtimeout eq '0') {
+                        $r->print(&mt('Submit button will be disabled after student submission until page is reloaded.')); 
+                    } else {
+                        $r->print(&mt('Submit button will be disabled after student submission for [quant,_1,second].',$postsubtimeout));
+                    }
+                } else {
+                    $r->print($lt{'erro'});
+                }
+            }
+        }
+    } elsif ($postsubmit eq '0') {
+        if ($oldsettings{'internal.postsubmit'} eq $postsubmit) {
+            $r->print($lt{'unch'});
+        } else {
+            if (exists($oldsettings{'internal.postsubtimeout'})) {
+                &Apache::lonnet::del('environment',['internal.postsubtimeout'],$cdom,$cnum);  
+            }
+            my %cenv = (
+                         'internal.postsubmit' => $postsubmit,
+                       );
+            my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
+            if ($putreply eq 'ok') {
+                $r->print(&mt('Submit buttin will not be disabled after student submission'));
+            } else {
+                $r->print($lt{'erro'});
+            }
+        }
+    } else {
+        $r->print($lt{'inva'}.' '.$lt{'unch'});
+    }
+    $r->print('<p>'.
+              '<a href="javascript:changePage(document.processpostsubmit,'."'menu'".')">'.
+              &mt('Pick another action').'</a></p>');
     $r->print(&hidden_form_elements().'</form>');
     return;
 }
@@ -1763,8 +1941,83 @@
 }
 
 ENDSCRIPT
+    } elsif ($phase eq 'setpostsubmit') {
+        my $invalid = &mt('The choice entered for disabling the submit button is invalid.');
+        my $invalidtimeout = &mt('The timeout you entered for disabling the submit button is invalid.');
+        my $alert = &mt('Enter one of: a positive integer, 0 (for no timeout), or leave blank to use domain default');
+        my $regexp = ' /^\s*\d+\s*$/';
+
+        $js .= <<"ENDSCRIPT"; 
+
+function verify_postsubmit() {
+    var optionsElement = document.setpostsubmit.postsubmit;
+    var verified = '';
+    if (optionsElement.length) {
+        var currval;
+        for (var i=0; i<optionsElement.length; i++) {
+            if (optionsElement[i].checked) {
+               currval = optionsElement[i].value;
+            }
+        }
+        if (currval == 1) {
+            var newtimeout = document.setpostsubmit.postsubtimeout.value;
+            if (newtimeout == '') {
+                verified = 'ok';
+            } else {
+                var num_reg = $regexp;
+                if (num_reg.test(newtimeout)) {
+                    if (newtimeout>= 0) {
+                        verified = 'ok';
+                    } else {
+                        alert("$invalidtimeout\\n$alert");
+                        return false;
+                    }
+                } else {
+                    alert("$invalid\\n$alert");
+                    return false;
+                }
+            }
+        } else {
+            if (currval == 0) {
+               verified = 'ok'; 
+            } else {
+               alert('$invalid');
+               return false;
+            }
+        }
+        if (verified == 'ok') {
+            changePage(document.setpostsubmit,'processpostsubmit');
+            return true;
+        }
+    }
+    return false;
+}
+
+function togglePostsubmit(caller) {
+    var optionsElement = document.setpostsubmit.postsubmit;
+    if (document.getElementById(caller)) {
+        var divitem = document.getElementById(caller);
+        var optionsElement = document.setpostsubmit.postsubmit; 
+        if (optionsElement.length) {
+            var currval;
+            for (var i=0; i<optionsElement.length; i++) {
+                if (optionsElement[i].checked) {
+                   currval = optionsElement[i].value;
+                }
+            }
+            if (currval == 1) {
+                divitem.style.display = 'block';
+            } else {
+                divitem.style.display = 'none';
+            }
+        }
     }
+    return;
+}
 
+ENDSCRIPT
+
+    }
     my $starthash;
     if ($env{'form.phase'} eq 'ccrole') {
         $starthash = {
@@ -1866,8 +2119,9 @@
       &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode',
           'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
           'locarg','krbarg','krbver','counter','hidefromcat','usecategory',
-          'threshold','defaultcredits','uploadquota','selfenrollmgrdc','selfenrollmgrcc',
-          'action','state','currsec_st','sections','newsec'],['^selfenrollmgr_'])."\n".
+          'threshold','postsubmit','postsubtimeout','defaultcredits','uploadquota',
+          'selfenrollmgrdc','selfenrollmgrcc','action','state','currsec_st',
+          'sections','newsec'],['^selfenrollmgr_'])."\n".
           '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
     return $hidden_elements;
 }
@@ -1971,7 +2225,6 @@
                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                               text=>"Threshold for anonymous submissions display"});
                             &print_set_anonsurvey_threshold($r,$cdom,$cnum,$cdesc,$type);
-
                         } elsif ($phase eq 'processthreshold') {
                             &Apache::lonhtmlcommon::add_breadcrumb
                             ({href=>"javascript:changePage(document.$phase,'setanon')",
@@ -1980,6 +2233,16 @@
                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                               text=>"Result"});
                             &modify_anonsurvey_threshold($r,$cdom,$cnum,$cdesc,$domdesc,$type);
+                        } elsif ($phase eq 'setpostsubmit') {
+                            &Apache::lonhtmlcommon::add_breadcrumb
+                            ({href=>"javascript:changePage(document.$phase,'$phase')",
+                              text=>"Configure submit button behavior post-submission"});
+                            &print_postsubmit_config($r,$cdom,$cnum,$cdesc,$type);
+                        } elsif ($phase eq 'processpostsubmit') {
+                            &Apache::lonhtmlcommon::add_breadcrumb
+                            ({href=>"javascript:changePage(document.$phase,'$phase')",
+                              text=>"Result"});
+                            &modify_postsubmit_config($r,$cdom,$cnum,$cdesc,$domdesc,$type);
                         } elsif ($phase eq 'viewparms') {
                             &Apache::lonhtmlcommon::add_breadcrumb
                             ({href=>"javascript:changePage(document.$phase,'viewparms')",
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1276 loncom/lonnet/perl/lonnet.pm:1.1277
--- loncom/lonnet/perl/lonnet.pm:1.1276	Sun Dec 21 16:26:36 2014
+++ loncom/lonnet/perl/lonnet.pm	Sat Mar  7 23:17:21 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1276 2014/12/21 16:26:36 raeburn Exp $
+# $Id: lonnet.pm,v 1.1277 2015/03/07 23:17:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2076,6 +2076,11 @@
     }
     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
         $domdefaults{'canuse_pdfforms'} = $domconfig{'coursedefaults'}{'canuse_pdfforms'};
+        $domdefaults{'usejsme'} = $domconfig{'coursedefaults'}{'usejsme'};
+        $domdefaults{'uselcmath'} = $domconfig{'coursedefaults'}{'uselcmath'};
+        if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
+            $domdefaults{'postsubmit'} = $domconfig{'coursedefaults'}{'postsubmit'}{'client'};
+        }
         foreach my $type (@coursetypes) {
             if (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                 unless ($type eq 'community') {
@@ -2085,6 +2090,12 @@
             if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                 $domdefaults{$type.'quota'} = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
             }
+            if ($domdefaults{'postsubmit'} eq 'on') {
+                if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
+                    $domdefaults{$type.'postsubtimeout'} = 
+                        $domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$type}; 
+                }
+            }
         }
     }
     if (ref($domconfig{'usersessions'}) eq 'HASH') {


More information about the LON-CAPA-cvs mailing list