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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sun, 06 Jul 2008 22:14:46 -0000


raeburn		Sun Jul  6 18:14:46 2008 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  Copying custom scantronformat.tab and/or default_scantronformat.tab files from /home/httpd/lonTabs and publishing for $dom-domainconfig user, the first time DC displays "Domain Configuration" screen for scantron format file, in a session hosted on the primary library server.
  - Fix some issues:
    - Only add keys is %error hash if error is defined
    - Results of split on md5sum needs to go into array, not a scalar.
    - If the original scantronformat.tab is different from the default, set the $is_cstom flag to 1.
    - If scantron entry has yet to be defined in hash from configuration.db, set scantronurl to custom file, if $is_custom true.  
  
  
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.59 loncom/interface/domainprefs.pm:1.60
--- loncom/interface/domainprefs.pm:1.59	Mon Jun 30 11:56:23 2008
+++ loncom/interface/domainprefs.pm	Sun Jul  6 18:14:46 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.59 2008/06/30 15:56:23 bisitz Exp $
+# $Id: domainprefs.pm,v 1.60 2008/07/06 22:14:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1847,7 +1847,8 @@
 sub print_scantronformat {
     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
     my $itemcount = 1;
-    my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls);
+    my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
+        %confhash);
     my $switchserver = &check_switchserver($dom,$confname);
     my %lt = &Apache::lonlocal::texthash (
                 default => 'Default scantron format file error',
@@ -1874,23 +1875,52 @@
                     );
                     my %md5chk;
                     foreach my $type (keys(%legacyfile)) {
-                        $md5chk{$type} = split(/ /,`md5sum $legacyfile{$type}`);
-                        chop($md5chk{$type});
+                        ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
+                        chomp($md5chk{$type});
                     }
                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                         foreach my $type (keys(%legacyfile)) {
-                            ($scantronurls{$type},$error{$type}) = 
+                            ($scantronurls{$type},my $error) = 
                                 &legacy_scantronformat($r,$dom,$confname,
                                                  $type,$legacyfile{$type},
                                                  $scantronurls{$type},
                                                  $scantronfiles{$type});
+                            if ($error ne '') {
+                                $error{$type} = $error;
+                            }
+                        }
+                        if (keys(%error) == 0) {
+                            $is_custom = 1;
+                            $confhash{'scantron'}{'scantronformat'} = 
+                                $scantronurls{'custom'};
+                            my $putresult = 
+                                &Apache::lonnet::put_dom('configuration',
+                                                         \%confhash,$dom);
+                            if ($putresult ne 'ok') {
+                                $error{'custom'} = 
+                                    '<span class="LC_error">'.
+                                    &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
+                            }
                         }
                     } else {
-                        ($scantronurls{'default'},$error{'default'}) =
+                        ($scantronurls{'default'},my $error) =
                             &legacy_scantronformat($r,$dom,$confname,
                                           'default',$legacyfile{'default'},
                                           $scantronurls{'default'},
                                           $scantronfiles{'default'});
+                        if ($error eq '') {
+                            $confhash{'scantron'}{'scantronformat'} = ''; 
+                            my $putresult =
+                                &Apache::lonnet::put_dom('configuration',
+                                                         \%confhash,$dom);
+                            if ($putresult ne 'ok') {
+                                $error{'default'} =
+                                    '<span class="LC_error">'.
+                                    &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
+                            }
+                        } else {
+                            $error{'default'} = $error;
+                        }
                     }
                 }
             }
@@ -1911,7 +1941,11 @@
             $scantronurl = $scantronurls{'default'};
         }
     } else {
-        $scantronurl = $scantronurls{'default'};
+        if ($is_custom) {
+            $scantronurl = $scantronurls{'custom'};
+        } else {
+            $scantronurl = $scantronurls{'default'};
+        }
     }
     $css_class = $itemcount%2?' class="LC_odd_row"':'';
     $datatable .= '<tr'.$css_class.'>';
@@ -1923,14 +1957,26 @@
         } else {
             $datatable = &mt('File unavailable for display');
         }
-        $datatable .= '</td><td valign="bottom">'.&mt('Upload:').'<br />';
+        $datatable .= '</td>';
+        if (keys(%error) == 0) { 
+            $datatable .= '<td valign="bottom">';
+            if (!$switchserver) {
+                $datatable .= &mt('Upload:').'<br />';
+            }
+        } else {
+            my $errorstr;
+            foreach my $key (sort(keys(%error))) {
+                $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
+            }
+            $datatable .= '<td>'.$errorstr;
+        }
     } else {
         if (keys(%error) > 0) {
             my $errorstr;
             foreach my $key (sort(keys(%error))) {
                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
             } 
-            $datatable .= '<td>'.$errorstr.'</td><td>';
+            $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
         } elsif ($scantronurl) {
             $datatable .= '<td><a href="'.$scantronurl.'" target="_blank">'                          .&mt('Custom scantron format file').'</a>'
                           .'<span class="LC_nobreak"><label>'
@@ -1990,7 +2036,7 @@
                     );
         my %level = &Apache::lonlocal::texthash (
                      dom => 'Set in "Modify Course" (Domain)',
-                     crs => 'Set in "Parameters" (Course)',   
+                     crs => 'Set in "Modify Parameters" (Course)',   
                     );
         $datatable = '<tr class="LC_odd_row">'.
                   '<td>'.$title{'togglecats'}.'</td>'.