--- loncom/interface/lonpdfupload.pm 2010/03/18 19:11:05 1.18 +++ loncom/interface/lonpdfupload.pm 2015/06/09 21:22:57 1.25 @@ -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.25 2015/06/09 21:22:57 damieng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -122,6 +122,7 @@ sub handler() { sub get_javascripts() { my $message = &mt('Please choose a PDF-File.'); + &js_escape(\$message); # simple test if the upload ends with ".pdf" # it's only for giving a message to the user @@ -130,7 +131,7 @@ sub get_javascripts() { // ' - .&mt("Can't find any valid PDF formfields.") + .&mt("Can't find any valid PDF form fields.") .'

'; } } @@ -192,24 +193,24 @@ sub get_pdf_data() { 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 form fields + + foreach my $field (@formFields) { + my $dict = $pdf->getFormFieldDict($pdf->getFormField($field)); # get form field 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 form fieldnames 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; } sub grade_pdf { - my $result = (); my @pdfdata = @_; my ($result,$meta,%grades,%problems,%foreigncourse,$debug); @@ -299,10 +300,12 @@ sub grade_pdf { $result .= ''). - '">'.$problemname.''.$problemname.' &mt('You are correct.'), 'APPROX_ANS' => &mt('You are correct.'), 'INCORRECT' => &mt('You are incorrect'), + 'DRAFT' => &mt('Copy saved but not submitted.'), ); - foreach my $key (keys %answerhash) { + foreach my $key (keys(%answerhash)) { if($shortcut eq $key) { return $answerhash{$shortcut}; } @@ -391,12 +395,12 @@ sub dumpenv { my $r = shift; $r->print ("
-------------------
"); - foreach my $key (sort (keys %env)) { + foreach my $key (sort(keys(%env))) { $r->print ("
$key -> $env{$key}"); } $r->print ("
-------------------
"); $r->print ("
-------------------
"); - foreach my $key (sort (keys %ENV)) { + foreach my $key (sort(keys(%ENV))) { $r->print ("
$key -> $ENV{$key}"); } $r->print ("
-------------------
");