[LON-CAPA-cvs] cvs: loncom /homework optionresponse.pm

onken lon-capa-cvs-allow@mail.lon-capa.org
Thu, 11 Sep 2008 17:38:17 -0000


onken		Thu Sep 11 13:38:17 2008 EDT

  Modified files:              
    /loncom/homework	optionresponse.pm 
  Log:
  Add optionresponse problems to PDF-Forms
  
  
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.151 loncom/homework/optionresponse.pm:1.152
--- loncom/homework/optionresponse.pm:1.151	Fri Aug  8 12:37:13 2008
+++ loncom/homework/optionresponse.pm	Thu Sep 11 13:38:14 2008
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.151 2008/08/08 16:37:13 bisitz Exp $
+# $Id: optionresponse.pm,v 1.152 2008/09/11 17:38:14 onken Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -159,8 +159,12 @@
     } # else nothing changed so just use the default mechanism
   }
   if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
+    if($env{'form.pdfFormFields'} ne 'yes') {
       $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}
                    \begin{enumerate} ';
+    } else {
+      $result .= "\\\\";
+    }
   }
   return $result;
 }
@@ -290,7 +294,11 @@
     $result.=&Apache::edit::end_table();
   }
   if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
+    if($env{'form.pdfFormFields'} ne 'yes') {
       $result .= '\end{enumerate}';
+    } else {
+      $result .= "\\\\";
+    }
   }
   &Apache::response::poprandomnumber();
   return $result;
@@ -423,13 +431,27 @@
       }
       my $lastopt=$lastresponse{$name};
       my $optionlist="<option></option>\n";
+
+      if($target eq 'tex' and $env{'form.pdfFormFields'} eq 'yes') {
+          my $fieldname = $env{'request.symb'}.'&part_'.$Apache::inputtags::part.'&optionresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'].':'.$temp;
+          $optionlist =  &Apache::lonxml::print_pdf_start_combobox($fieldname);
+      }
+
       foreach my $option (@opt) {
 	  my $escopt=&HTML::Entities::encode($option,'\'"&<>');
-	  if ($option eq $lastopt) {
-	      $optionlist.="<option value='".$escopt."' selected=\"selected\">$option</option>\n";
-	  } else {
-	      $optionlist.="<option value='".$escopt."'>$option</option>\n";
-	  }
+          if ($option eq $lastopt) {
+              if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
+                  $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
+              } else {
+                  $optionlist.="<option value='".$escopt."' selected=\"selected\">$option</option>\n";
+              }
+          } else {
+              if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
+                  $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
+              } else {
+                  $optionlist.="<option value='".$escopt."'>$option</option>\n";
+              }
+          }
       }
       if ($target ne 'tex') {
 	  if ($Apache::lonhomework::type ne 'exam') {
@@ -467,13 +489,18 @@
 	  if ($text=~m/\\item /) {
 	      if ($Apache::lonhomework::type eq 'exam') {
 	          $text=~s/\\item/\\vskip 2 mm/;
-	      }
-	      $result.= $texoptionlist.$text;
-	  } else {
+	      } elsif ($env{'form.pdfFormFields'} ne 'yes') {
+                  $result.= $texoptionlist.$text;
+              }
+          } else {
 	      if ($Apache::lonhomework::type eq 'exam') {
 		  $result.= $texoptionlist.'  '.$text;
-	      } else {
-		  if ($text=~/\S/) {$result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;} else {$result.= $texoptionlist;}
+	      } elsif ($env{'form.pdfFormFields'} ne 'yes') {
+		  if ($text=~/\S/) {
+                      $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;
+                  } else {
+                      $result.= $texoptionlist;
+                  }
 	      }
 	  }
 	  if ($Apache::lonhomework::type eq 'exam') {
@@ -482,6 +509,12 @@
 		  '\end{enumerate} \vskip -8 mm \strut ';
 	      $internal_counter++;
 	  }
+          if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
+              $text =~ s/.*indent(.*)$/$1/;
+              $text = $1;
+              $result .= " $optionlist ". &Apache::lonxml::print_pdf_end_combobox($text).'\strut \\\\';
+              $temp++;
+          }
 	  $displayoptionintex=0;
       }
     }