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

raeburn raeburn@source.lon-capa.org
Mon, 30 Nov 2009 06:23:38 -0000


This is a MIME encoded message

--raeburn1259562218
Content-Type: text/plain

raeburn		Mon Nov 30 06:23:38 2009 EDT

  Modified files:              
    /loncom/interface	mydesk.tab lonmenu.pm courseprefs.pm 
                     	domainprefs.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Bug 6121.  
    - Display of "Upload PDF Forms" in Main Menu in a course/community 
      controlled by domain default or course configuration.
  courseprefs.pm
    - lonnet::delenv() used to update current user's session when a 
      course environment setting is deleted.
  domainprefs.pm
    - code moved from &print_helpsettings() to &radiobutton_prefs() 
      to facilitate reuse in course defaults menu (canuse_pdfforms).
  lonnet.pm
    - canuse_pdfforms domain default cached in domdefaults.
  Work in progess.
  
  
--raeburn1259562218
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20091130062338.txt"

Index: loncom/interface/mydesk.tab
diff -u loncom/interface/mydesk.tab:1.123 loncom/interface/mydesk.tab:1.124
--- loncom/interface/mydesk.tab:1.123	Wed Nov  4 18:30:17 2009
+++ loncom/interface/mydesk.tab	Mon Nov 30 06:23:32 2009
@@ -174,8 +174,8 @@
 6:1:author:rca:cstr.gif:co con-[_1]:struct[_2]:go('/priv/$caname/');:Enter construction space as a co-author:set
 6:1:author:raa:cstr.gif:co con-[_1]:struct[_2]:go('/priv/$caname/');:Enter construction space as an assistant co-author:set
 6:1:pmau:$requested_domain:conf.gif:domain[_1]:config[_1]:go('/adm/domainprefs');:Set domain configuration:dom
-6:1:course:any:pdfupload.gif:upload[_1]:pdf form[_1]:go('/pdfupload'):Upload a PDF Form with filled Form Fields:grd
-6:1:community:any:pdfupload.gif:upload[_1]:pdf form[_1]:go('/pdfupload'):Upload a PDF Form with filled Form Fields:grd
+6:1:courseenv_canuse_pdfforms:any:pdfupload.gif:upload[_1]:pdf form[_1]:go('/pdfupload'):Upload a PDF Form with filled Form Fields:grd
+6:1:community_canuse_pdfforms:any:pdfupload.gif:upload[_1]:pdf form[_1]:go('/pdfupload'):Upload a PDF Form with filled Form Fields:grd
 6:2:clear
 6:2:pbro:/res/:res.gif:resource[_1]:space[_1]:go('/res/?launch=1');:Browse own authored or co-authored resources:cnt
 6:2:pbre:$requested_domain:res.gif:resource[_1]:space[_1]:go('/res/$udom/?launch=1');:Browse published resources:cnt
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.306 loncom/interface/lonmenu.pm:1.307
--- loncom/interface/lonmenu.pm:1.306	Fri Nov 20 04:12:43 2009
+++ loncom/interface/lonmenu.pm	Mon Nov 30 06:23:32 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.306 2009/11/20 04:12:43 raeburn Exp $
+# $Id: lonmenu.pm,v 1.307 2009/11/30 06:23:32 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1453,15 +1453,31 @@
             }
         } elsif ($pro =~ /^courseenv_(.*)$/) {
             my $key = $1;
-            if (($env{'course.'.$env{'request.course.id'}.'.'.$key}) && 
-                ($crstype ne 'Community')) {
-                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+            if ($crstype ne 'Community') {
+                my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
+                if ($key eq 'canuse_pdfforms') {
+                    if ($env{'request.course.id'} && $coursepref eq '') {
+                        my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+                        $coursepref = $domdefs{'canuse_pdfforms'};
+                    }
+                }
+                if ($coursepref) { 
+                    $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+                }
             }
         } elsif ($pro =~ /^communityenv_(.*)$/) {
             my $key = $1;
-            if (($env{'course.'.$env{'request.course.id'}.'.'.$key}) && 
-                ($crstype eq 'Community')) {
-                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+            if ($crstype eq 'Community') {
+                my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
+                if ($key eq 'canuse_pdfforms') {
+                    if ($env{'request.course.id'} && $coursepref eq '') {
+                        my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+                        $coursepref = $domdefs{'canuse_pdfforms'};
+                    }
+                }
+                if ($coursepref) { 
+                    $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+                }
             }
         } elsif ($pro =~ /^course_(.*)$/) {
             # Check for permissions inside of a course
@@ -1616,7 +1632,7 @@
 function showCourseID() {
     document.getElementById('dccid').style.display='block';
     document.getElementById('dccid').style.textAlign='left';
-    document.getElementById('dccid').style.textFace='normal';    
+    document.getElementById('dccid').style.textFace='normal';
     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>';
     return;
 }
Index: loncom/interface/courseprefs.pm
diff -u loncom/interface/courseprefs.pm:1.13 loncom/interface/courseprefs.pm:1.14
--- loncom/interface/courseprefs.pm:1.13	Tue Nov 24 13:49:28 2009
+++ loncom/interface/courseprefs.pm	Mon Nov 30 06:23:32 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set configuration settings for a course
 #
-# $Id: courseprefs.pm,v 1.13 2009/11/24 13:49:28 bisitz Exp $
+# $Id: courseprefs.pm,v 1.14 2009/11/30 06:23:32 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -281,13 +281,14 @@
                                 col2 => 'Value',}],
                     ordered => ['problem_stream_switch','suppress_tries',
                                 'default_paper_size','print_header_format',
-                                'disableexampointprint'],
+                                'disableexampointprint','canuse_pdfforms'],
                     itemtext => {
                         problem_stream_switch => 'Allow problems to be split over pages',
                         suppress_tries        => 'Suppress number of tries in printing',
                         default_paper_size    => 'Default paper type',
                         print_header_format   => 'Print header format',
                         disableexampointprint => 'Disable automatically printing point values on exams',
+                        canuse_pdfforms    => 'Users can print problems as PDF forms and upload later for grading',
                                 },
                   },
         'spreadsheet' =>
@@ -983,15 +984,21 @@
                                         $displayname = &mt($text);
                                     }
                                     if (defined($yesno{$key})) {
-                                        $displayval = 'no';
+                                        $displayval = &mt('No');
                                         if ($changes->{$item}{$key} eq 'yes') {
-                                            $displayval = 'yes';                          
+                                            $displayval = &mt('Yes');                          
                                         }
                                     } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
                                         $displayval = &Apache::lonlocal::locallocaltime($displayval);
                                     } elsif ($key eq 'categories') {
                                         $displayval = $env{'form.categories_display'};
-                                    }  
+                                    } elsif ($key eq 'canuse_pdfforms') {
+                                        if ($changes->{$item}{$key} eq '1') {
+                                            $displayval = &mt('Yes');
+                                        } elsif ($changes->{$item}{$key} eq '0') {
+                                            $displayval = &mt('No');
+                                        }
+                                    }
                                     if ($changes->{$item}{$key} eq '') {
                                         push(@delkeys,$key);
                                         $output .= '<li>'.&mt('Deleted setting for [_1]',
@@ -1037,6 +1044,10 @@
                     $output .= &mt('An error occurred when removing course settings which are no longer in use.');
                 }
                 $output .= '</span>';
+            } else {
+                foreach my $key (@delkeys) {
+                    &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
+                }
             }
         }
         if (@need_env_update) {
@@ -2301,6 +2312,16 @@
             text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
             input => 'radio',
                                  },
+        canuse_pdfforms => {
+            text  => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
+            input => 'selectbox',
+            options => {
+                         1    => &mt('Yes'),
+                         0    => &mt('No'),
+                       },
+            order => ['1','0'],
+            nullval => 'None specified - use domain default',
+                    }
     );
     return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype);
 }
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.120 loncom/interface/domainprefs.pm:1.121
--- loncom/interface/domainprefs.pm:1.120	Mon Nov 23 21:45:18 2009
+++ loncom/interface/domainprefs.pm	Mon Nov 30 06:23:32 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.120 2009/11/23 21:45:18 raeburn Exp $
+# $Id: domainprefs.pm,v 1.121 2009/11/30 06:23:32 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -202,11 +202,12 @@
                 'quotas','autoenroll','autoupdate','directorysrch',
                 'usercreation','usermodification','contacts','defaults',
                 'scantron','coursecategories','serverstatuses',
-                'requestcourses','helpsettings'],$dom);
+                'requestcourses','helpsettings','coursedefaults'],$dom);
     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
                        'autoupdate','directorysrch','contacts',
                        'usercreation','usermodification','scantron',
-                       'requestcourses','coursecategories','serverstatuses','helpsettings');
+                       'requestcourses','coursecategories','serverstatuses','helpsettings',
+                       'coursedefaults');
     my %prefs = (
         'rolecolors' =>
                    { text => 'Default color schemes',
@@ -325,6 +326,12 @@
                   header => [{col1 => 'Setting',
                               col2 => 'Value',}],
                  },
+        'coursedefaults' => 
+                 {text => 'Course/Community defaults',
+                  help => 'Domain_Configuration_Course_Defaults',
+                  header => [{col1 => 'Setting',
+                              col2 => 'Value',}],
+                 },
         'privacy' => 
                  {text   => 'User Privacy',
                   help   => 'Domain_Configuration_User_Privacy',
@@ -429,6 +436,8 @@
         $output = &modify_quotas($dom,$action,%domconfig);
     } elsif ($action eq 'helpsettings') {
         $output = &modify_helpsettings($dom,%domconfig);
+    } elsif ($action eq 'coursedefaults') {
+        $output = &modify_coursedefaults($dom,%domconfig);
     }
     return $output;
 }
@@ -617,8 +626,10 @@
         } elsif ($action eq 'serverstatuses') {
             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
         } elsif ($action eq 'helpsettings') {
-        	$output .= &print_helpsettings($dom,$settings,\$rowtotal);
-    	}
+            $output .= &print_helpsettings($dom,$settings,\$rowtotal);
+    	} elsif ($action eq 'coursedefaults') {
+            $output .= &print_coursedefaults($dom,$settings,\$rowtotal);
+        }
     }
     $output .= '
    </table>
@@ -1935,33 +1946,40 @@
 }
 
 sub print_helpsettings {
-
-	my ($dom,$settings,$rowtotal) = @_;
-	my ($css_class,$datatable);
-	my $itemcount = 1;
-	my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
-	
-	%choices =
+    my ($dom,$settings,$rowtotal) = @_;
+    my ($css_class,$datatable);
+    my $itemcount = 1;
+    my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
+    %choices =
         &Apache::lonlocal::texthash (
             submitbugs => 'Display &quot;Submit a bug&quot; link?',
     );
-	
-	%defaultchecked = ('submitbugs' => 'on');
-	
-	@toggles = ('submitbugs',);
-    
-    foreach my $item (@toggles) {
-        if ($defaultchecked{$item} eq 'on') { 
+    %defaultchecked = ('submitbugs' => 'on');
+    @toggles = ('submitbugs',);
+    ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+                                                 \%choices,$itemcount);
+    $$rowtotal += $itemcount;
+    return $datatable;
+}
+
+sub radiobutton_prefs {
+    my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
+    return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
+                   (ref($choices) eq 'HASH'));
+
+    my (%checkedon,%checkedoff,$datatable,$css_class);
+
+    foreach my $item (@{$toggles}) {
+        if ($defaultchecked->{$item} eq 'on') {
             $checkedon{$item} = ' checked="checked" ';
             $checkedoff{$item} = ' ';
-        } elsif ($defaultchecked{$item} eq 'off') {
+        } elsif ($defaultchecked->{$item} eq 'off') {
             $checkedoff{$item} = ' checked="checked" ';
             $checkedon{$item} = ' ';
         }
     }
-    
     if (ref($settings) eq 'HASH') {
-        foreach my $item (@toggles) {
+        foreach my $item (@{$toggles}) {
             if ($settings->{$item} eq '1') {
                 $checkedon{$item} =  ' checked="checked" ';
                 $checkedoff{$item} = ' ';
@@ -1970,12 +1988,11 @@
                 $checkedon{$item} = ' ';
             }
         }
-     }
-    
-     foreach my $item (@toggles) {
+    }
+    foreach my $item (@{$toggles}) {
         $css_class = $itemcount%2?' class="LC_odd_row"':'';
-        $datatable .=  
-            '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{$item}.
+        $datatable .=
+            '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
             '</span></td>'.
             '<td class="LC_right_item"><span class="LC_nobreak">'.
             '<label><input type="radio" name="'.
@@ -1985,9 +2002,25 @@
             '</span></td>'.
             '</tr>';
         $itemcount ++;
-     }
-     return $datatable;
-	
+    }
+    return ($datatable,$itemcount);
+}
+
+sub print_coursedefaults {
+    my ($dom,$settings,$rowtotal) = @_;
+    my ($css_class,$datatable);
+    my $itemcount = 1;
+    my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
+    %choices =
+        &Apache::lonlocal::texthash (
+            canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
+    );
+    %defaultchecked = ('canuse_pdfforms' => 'off');
+    @toggles = ('canuse_pdfforms',);
+    ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+                                                 \%choices,$itemcount);
+    $$rowtotal += $itemcount;
+    return $datatable;
 }
 
 sub contact_titles {
@@ -5901,6 +5934,72 @@
     return $resulttext;
 }
 
+sub modify_coursedefaults {
+    my ($dom,%domconfig) = @_;
+    my ($resulttext,$errors,%changes,%defaultshash);
+    my %defaultchecked = ('canuse_pdfforms' => 'off');
+    my @offon = ('off','on');
+    my @toggles = ('canuse_pdfforms');
+
+    $defaultshash{'coursedefaults'} = {};
+
+    if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
+        if ($domconfig{'coursedefaults'} eq '') {
+            $domconfig{'coursedefaults'} = {};
+        }
+    }
+
+    if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
+        foreach my $item (@toggles) {
+            if ($defaultchecked{$item} eq 'on') {
+                if (($domconfig{'coursedefaults'}{$item} eq '') &&
+                    ($env{'form.'.$item} eq '0')) {
+                    $changes{$item} = 1;
+                } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
+                    $changes{$item} = 1;
+                }
+            } elsif ($defaultchecked{$item} eq 'off') {
+                if (($domconfig{'coursedefaults'}{$item} eq '') &&
+                    ($env{'form.'.$item} eq '1')) {
+                    $changes{$item} = 1;
+                } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
+                    $changes{$item} = 1;
+                }
+            }
+            $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
+        }
+    }
+    my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
+                                             $dom);
+    if ($putresult eq 'ok') {
+        if (keys(%changes) > 0) {
+            if ($changes{'canuse_pdfforms'}) {
+                my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+                $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
+                my $cachetime = 24*60*60;
+                &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+            }
+            $resulttext = &mt('Changes made:').'<ul>';
+            foreach my $item (sort(keys(%changes))) {
+                if ($item eq 'canuse_pdfforms') {
+                    if ($env{'form.'.$item} eq '1') {
+                        $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
+                    } else {
+                        $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
+                    }
+                }
+            }
+            $resulttext .= '</ul>';
+        } else {
+            $resulttext = &mt('No changes made to course defaults');
+        }
+    } else {
+        $resulttext = '<span class="LC_error">'.
+            &mt('An error occurred: [_1]',$putresult).'</span>';
+    }
+    return $resulttext;
+}
+
 sub recurse_check {
     my ($chkcats,$categories,$depth,$name) = @_;
     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1046 loncom/lonnet/perl/lonnet.pm:1.1047
--- loncom/lonnet/perl/lonnet.pm:1.1046	Sun Nov 29 00:17:22 2009
+++ loncom/lonnet/perl/lonnet.pm	Mon Nov 30 06:23:37 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1046 2009/11/29 00:17:22 raeburn Exp $
+# $Id: lonnet.pm,v 1.1047 2009/11/30 06:23:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1353,7 +1353,8 @@
     my %domdefaults;
     my %domconfig =
          &Apache::lonnet::get_dom('configuration',['defaults','quotas',
-                                  'requestcourses','inststatus'],$domain);
+                                  'requestcourses','inststatus',
+                                  'coursedefaults'],$domain);
     if (ref($domconfig{'defaults'}) eq 'HASH') {
         $domdefaults{'lang_def'} = $domconfig{'defaults'}{'lang_def'}; 
         $domdefaults{'auth_def'} = $domconfig{'defaults'}{'auth_def'};
@@ -1388,6 +1389,11 @@
             $domdefaults{$item} = $domconfig{'inststatus'}{$item};
         }
     }
+    if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
+        foreach my $item ('canuse_pdfforms') {
+            $domdefaults{$item} = $domconfig{'coursedefaults'}{$item};
+        }
+    }
     &Apache::lonnet::do_cache_new('domdefaults',$domain,\%domdefaults,
                                   $cachetime);
     return %domdefaults;

--raeburn1259562218--