[LON-CAPA-cvs] cvs: loncom(version_2_9_X) /interface domainprefs.pm

raeburn raeburn@source.lon-capa.org
Sat, 02 Jan 2010 22:02:44 -0000


This is a MIME encoded message

--raeburn1262469764
Content-Type: text/plain

raeburn		Sat Jan  2 22:02:44 2010 EDT

  Modified files:              (Branch: version_2_9_X)
    /loncom/interface	domainprefs.pm 
  Log:
  - Bug 6121.
   - Display of "Upload PDF Forms" in Main Menu in a course/community
     controlled by domain default or course configuration.
  - Backport parts of 1.118, 1.121.
  
  
--raeburn1262469764
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100102220244.txt"

Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.102.2.6 loncom/interface/domainprefs.pm:1.102.2.7
--- loncom/interface/domainprefs.pm:1.102.2.6	Sat Jan  2 21:50:54 2010
+++ loncom/interface/domainprefs.pm	Sat Jan  2 22:02:44 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.102.2.6 2010/01/02 21:50:54 raeburn Exp $
+# $Id: domainprefs.pm,v 1.102.2.7 2010/01/02 22:02:44 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'],$dom);
+                'requestcourses','coursedefaults'],$dom);
     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
                        'autoupdate','directorysrch','contacts',
                        'usercreation','usermodification','scantron',
-                       'requestcourses','coursecategories','serverstatuses');
+                       'requestcourses','coursecategories','serverstatuses',
+                       'coursedefaults');
     my %prefs = (
         'rolecolors' =>
                    { text => 'Default color schemes',
@@ -318,6 +319,12 @@
                               col3 => 'Specific IPs',
                             }],
                  },
+        'coursedefaults' =>
+                 {text => 'Course/Community defaults',
+                  help => 'Domain_Configuration_Course_Defaults',
+                  header => [{col1 => 'Setting',
+                              col2 => 'Value',}],
+                 },
     );
     my @roles = ('student','coordinator','author','admin');
     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
@@ -404,6 +411,8 @@
         $output = &modify_serverstatuses($dom,%domconfig);
     } elsif ($action eq 'requestcourses') {
         $output = &modify_quotas($dom,$action,%domconfig);
+    } elsif ($action eq 'coursedefaults') {
+        $output = &modify_coursedefaults($dom,%domconfig);
     }
     return $output;
 }
@@ -581,6 +590,8 @@
             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'serverstatuses') {
             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
+        } elsif ($action eq 'coursedefaults') {
+            $output .= &print_coursedefaults($dom,$settings,\$rowtotal);
         }
     }
     $output .= '
@@ -1828,6 +1839,67 @@
     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') {
+            $checkedoff{$item} = ' checked="checked" ';
+            $checkedon{$item} = ' ';
+        }
+    }
+    if (ref($settings) eq 'HASH') {
+        foreach my $item (@{$toggles}) {
+            if ($settings->{$item} eq '1') {
+                $checkedon{$item} =  ' checked="checked" ';
+                $checkedoff{$item} = ' ';
+            } elsif ($settings->{$item} eq '0') {
+                $checkedoff{$item} =  ' checked="checked" ';
+                $checkedon{$item} = ' ';
+            }
+        }
+    }
+    foreach my $item (@{$toggles}) {
+        $css_class = $itemcount%2?' class="LC_odd_row"':'';
+        $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="'.
+            $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
+            '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
+            $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
+            '</span></td>'.
+            '</tr>';
+        $itemcount ++;
+    }
+    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 {
     my %titles = &Apache::lonlocal::texthash (
                    'supportemail' => 'Support E-mail address',
@@ -5618,6 +5690,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') {

--raeburn1262469764--