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

raeburn raeburn@source.lon-capa.org
Thu, 18 Mar 2010 16:08:48 -0000


raeburn		Thu Mar 18 16:08:48 2010 EDT

  Modified files:              
    /loncom/interface	lonpdfupload.pm 
  Log:
  - Check resource is in course, before making submission.
  - Display warning instead of grade display if no form items were found in course map.
  - Some coding style changes: keys().   
  
  
Index: loncom/interface/lonpdfupload.pm
diff -u loncom/interface/lonpdfupload.pm:1.16 loncom/interface/lonpdfupload.pm:1.17
--- loncom/interface/lonpdfupload.pm:1.16	Thu Mar 18 14:50:15 2010
+++ loncom/interface/lonpdfupload.pm	Thu Mar 18 16:08:48 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # PDF Form Upload Handler
 #
-# $Id: lonpdfupload.pm,v 1.16 2010/03/18 14:50:15 raeburn Exp $
+# $Id: lonpdfupload.pm,v 1.17 2010/03/18 16:08:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -207,13 +207,8 @@
 sub grade_pdf {
     my $result = ();
     my @pdfdata = @_;
+    my ($result,$meta,%grades,%problems,$debug);   
    
-    my $meta = ();
-    my %grades = ();
-    my %problems = ();
-        
-    my $debug = ();
-
     $debug  .= "Found: ". scalar @pdfdata." Entries \n";
 
     foreach my $entry (sort(@pdfdata)) {
@@ -231,21 +226,22 @@
                       .'</p>';
             }
 
-        } elsif($entry =~ /^upload.*/)  {
+        } elsif ($entry =~ /^upload.*/)  {
             $debug .= 'found: a problem -> '.$entry;
             my ($label, $value) = ($entry =~ /^([^?]*)\?(.*)/);
             my ($symb, $part, $type, $HWVAL) = split('&', $label);
-            my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symb);  
+            my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symb);
+            next unless (&Apache::lonnet::is_on_map($resource));
             $value =~ s/(.*)\n/$1/; 
 
             #filter incorrect radiobuttons (Bug in CABAReT Stage)
-            if($type eq 'radiobuttonresponse' && $value eq 'Off' ) {
+            if ($type eq 'radiobuttonresponse' && $value eq 'Off' ) {
                 next;
             }
  
             my $submit = $part;
             $submit =~ s/part_(.*)/submit_$1/;
-            if($problems{$symb.$part}) {
+            if ($problems{$symb.$part}) {
                  $problems{$symb.$part}{$HWVAL} = $value;
             } else {
                  $problems{$symb.$part} =  { 'resource' => $resource,
@@ -262,30 +258,36 @@
     #$result .= $debug;
 
     $result .= '<h2>'.&mt('Results of PDF Form problems').'</h2>';
-    $result .= &Apache::loncommon::start_data_table()
-              .&Apache::loncommon::start_data_table_header_row()
-              .'<th>'.&mt('Problem Name').'</th>'
-              .'<th>'.&mt('Grading').'</th>'
-              .&Apache::loncommon::start_data_table_header_row()
-              .&Apache::loncommon::end_data_table_header_row();
-
-    foreach my $key (sort (keys %problems)) {
-        my %problem = %{$problems{$key}};
-        my ($problemname, $grade) = &grade_problem(%problem);
-
-        $result .= &Apache::loncommon::start_data_table_row();
-        $result .= "<td>$problemname</td><td class='";
-        if($grade eq "EXACT_ANS" || $grade eq "APPROX_ANS") {
-            $result .= "LC_answer_correct";
-        } else { 
-            $result .= "LC_answer_charged_try";
+
+    if (keys(%problems) > 0) {
+        $result .= &Apache::loncommon::start_data_table()
+                  .&Apache::loncommon::start_data_table_header_row()
+                  .'<th>'.&mt('Problem Name').'</th>'
+                  .'<th>'.&mt('Grading').'</th>'
+                  .&Apache::loncommon::start_data_table_header_row()
+                  .&Apache::loncommon::end_data_table_header_row();
+
+        foreach my $key (sort(keys(%problems))) {
+            my %problem = %{$problems{$key}};
+            my ($problemname, $grade) = &grade_problem(%problem);
+
+            $result .= &Apache::loncommon::start_data_table_row();
+            $result .= "<td>$problemname</td><td class='";
+            if ($grade eq "EXACT_ANS" || $grade eq "APPROX_ANS") {
+                $result .= "LC_answer_correct";
+            } else { 
+                $result .= "LC_answer_charged_try";
+            }
+            $grade = &parse_grade_answer($grade);
+            $result .= "'>$grade</span></td>";
+            $result .= &Apache::loncommon::end_data_table_row();
         }
-        $grade = &parse_grade_answer($grade);
-        $result .= "'>$grade</span></td>";
-        $result .= &Apache::loncommon::end_data_table_row();
+        $result .= &Apache::loncommon::end_data_table();
+    } else {
+        $result .= '<p class="LC_warning">'.
+                   &mt('As no gradable form items were found, no submissions have been recorded.').
+                   '</p>';
     }
-    $result .= &Apache::loncommon::end_data_table();
-
 
     return $result;        
 }