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

onken onken@source.lon-capa.org
Mon, 22 Mar 2010 15:33:38 -0000


onken		Mon Mar 22 15:33:38 2010 EDT

  Modified files:              
    /loncom/interface	lonpdfupload.pm 
  Log:
  Avoids a server-error when uploading a pdf-file without formfields.
  
  
  
Index: loncom/interface/lonpdfupload.pm
diff -u loncom/interface/lonpdfupload.pm:1.18 loncom/interface/lonpdfupload.pm:1.19
--- loncom/interface/lonpdfupload.pm:1.18	Thu Mar 18 19:11:05 2010
+++ loncom/interface/lonpdfupload.pm	Mon Mar 22 15:33:38 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # PDF Form Upload Handler
 #
-# $Id: lonpdfupload.pm,v 1.18 2010/03/18 19:11:05 raeburn Exp $
+# $Id: lonpdfupload.pm,v 1.19 2010/03/22 15:33:38 onken Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -192,19 +192,20 @@
     my @data = ();
     my $pdf = CAM::PDF->new($env{'form.file'});
 
-    my @formFields = $pdf->getFormFieldList(); #get names of formfields
-    
-    foreach my $field (@formFields) {
-	my $dict = $pdf->getFormFieldDict($pdf->getFormField($field)); # get formfield dictonary
+    if($pdf) {
+        my @formFields = $pdf->getFormFieldList(); #get names of formfields
+
+        foreach my $field (@formFields) {
+            my $dict = $pdf->getFormFieldDict($pdf->getFormField($field)); # get formfield dictonary
 
-        #
-        # this is necessary because CAM::PDF has a problem with formfieldnames which include a
-        # dot in fieldnames. So a fieldname like "i.am.aFormfield" will offer three fieldnames "i", "i.am" 
-        # and "i.am.aFormfield". The fragmentary names keep no values and will be ignored.
-        if($dict->{'V'}) {
-            push(@data, $field."?". $dict->{'V'}{'value'}); #binding fieldname with value
+            # this is necessary because CAM::PDF has a problem with formfieldnames which include a
+            # dot in fieldnames. So a fieldname like "i.am.aFormfield" will offer three fieldnames
+            # "i", "i.am" and "i.am.aFormfield". The fragmentary names keep no values and will be ignored.
+            if($dict->{'V'}) {
+                push(@data, $field."?". $dict->{'V'}{'value'}); #binding fieldname with value
+            }
         }
-    } 
+    }
     return @data;
 }