--- loncom/homework/chemresponse.pm	2008/09/05 20:23:57	1.80
+++ loncom/homework/chemresponse.pm	2011/07/04 09:24:54	1.89
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # chemical equation style response
 #
-# $Id: chemresponse.pm,v 1.80 2008/09/05 20:23:57 riegler Exp $
+# $Id: chemresponse.pm,v 1.89 2011/07/04 09:24:54 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -116,7 +116,7 @@ CHEMJS
 					'bgcolor'   => '#FFFFFF',});
     my $end_page =
  	&Apache::loncommon::end_page({'js_ready' => 1,});
-	
+    my $java_not_enabled=&Apache::lonhtmlcommon::java_not_enabled();
     my $body=<<CHEMPAGE;
 $js
 <center>
@@ -143,7 +143,7 @@ $js
     </td></tr>
   </table>
 <applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="440" height="390" mayscript>
-You have to enable Java and JavaScript on your machine.
+$java_not_enabled
 $molecule
 <param name="options" value="$options" />
 </applet><br />
@@ -176,8 +176,14 @@ CHEMPAGE
 	editor.focus();
     }
 </script>
-<a href="javascript:$function();void(0);"><img class="stift" src='$iconpath/stift.gif' alt='$display' title='$display' /></a>
 CHEMINPUT
+    if ($shown_text eq '') {
+        $result .=<<PENCIL; 
+<a href="javascript:$function();void(0);"><img class="stift" src='$iconpath/stift.gif' alt='$display' title='$display' /></a>
+PENCIL
+    } else {
+        $result .= '<input type="button" value="'.&mt($shown_text).'" onclick="javascript:'.$function.'();void(0);" />';
+    }
     return $result;
 }
 sub jme_img {
@@ -203,30 +209,19 @@ sub start_organicresponse {
     } elsif ($target eq 'web') {
 	my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
 						 $safeeval);
-	if (  &Apache::response::show_answer() && $jmeanswer ne '') {
-	    my $options=&Apache::lonxml::get_param('options',$parstack,
-						   $safeeval);
-	    my $width=&Apache::lonxml::get_param('width',$parstack,
-						   $safeeval);
-	    my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
-							 $safeeval);
-	    $result.=&jme_img($jmeanswer,$answers[0],$width,$options);
-	} else {
-	    my $molecule;
-	    if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) {
-		$molecule=$Apache::lonhomework::history{"resource.$partid.$id.molecule"};
-	    } else {
-		$molecule=&Apache::lonxml::get_param('molecule',$parstack,
+	if (&Apache::response::show_answer()) {
+            my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
+                                                     $safeeval);
+            if ($jmeanswer ne '') {
+	        my $options=&Apache::lonxml::get_param('options',$parstack,
+	    					       $safeeval);
+	        my $width=&Apache::lonxml::get_param('width',$parstack,
 						     $safeeval);
-	    }
-	    my $options=&Apache::lonxml::get_param('options',$parstack,
-						   $safeeval);
-	    my $shown_text;
-	    if (&Apache::response::show_answer()) {
-		$shown_text="Show Your Last Answer";
-	    }
-	    #stift $result=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,
-#					 $options,$shown_text);
+	        my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
+							     $safeeval);
+	        $result.=&jme_img($jmeanswer,$answers[0],$width,$options);
+            }
+	} else {
 	    $result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />';
 	}
     } elsif ($target eq 'edit') {
@@ -234,7 +229,7 @@ sub start_organicresponse {
 	my $options=&Apache::lonxml::get_param('options',$parstack,
 					       $safeeval);
 	if ($options !~ /multipart/) { $options.=',multipart'; }
-	$result .='<nobr>'.
+	$result .='<span class="LC_nobreak">'.
 	    &Apache::edit::text_arg('Starting Molecule:','molecule',
 				    $token,40);
 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
@@ -242,11 +237,11 @@ sub start_organicresponse {
 	$result .=&separate_jme_window(undef,
 		      &Apache::edit::html_element_name('molecule'),
 		      $molecule,$options);
-	$result .='</nobr><br /><nobr>';
+	$result .='</span><br /><span class="LC_nobreak">';
 	$result .=&Apache::edit::text_arg('Correct Answer:','answer',
 					  $token,40);
-	$result .='</nobr><br /><nobr>';
-	$result .=&Apache::edit::text_arg('JME string of the answer (automatically updated when using the Draw Molecule button):',
+	$result .='</span><br /><span class="LC_nobreak">';
+	$result .=&Apache::edit::text_arg('JME string of the answer - automatically updated by "Insert Answer" in the JME pop-up (click pencil):',
 					  'jmeanswer',$token);
 	my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
 						 $safeeval);
@@ -254,7 +249,7 @@ sub start_organicresponse {
                       &Apache::edit::html_element_name('answer'),
                       &Apache::edit::html_element_name('jmeanswer'),
 		      $jmeanswer,$options);
-	$result .='</nobr><br />';
+	$result .='</span><br />';
 	$result .=&Apache::edit::checked_arg('Options:','options',
 				    [ ['autoez','Auto E,Z stereochemistry'],
 				      ['multipart','Multipart Structures'],
@@ -309,9 +304,17 @@ sub end_organicresponse {
 		    $ad='INCORRECT';
 		}
 	    }
-	    if ($ad && $Apache::lonhomework::type eq 'survey') {
-		$ad='SUBMITTED';
-	    }
+            if ($ad) {
+	        if ($Apache::lonhomework::type eq 'survey') {
+		    $ad='SUBMITTED';
+                } elsif ($Apache::lonhomework::type eq 'surveycred') {
+                    $ad='SUBMITTED_CREDIT';
+                } elsif ($Apache::lonhomework::type eq 'anonsurvey') {
+                    $ad='ANONYMOUS';
+                } elsif ($Apache::lonhomework::type eq 'anonsurveycred') {
+                    $ad='ANONYMOUS_CREDIT';
+                }
+            }
 	    &Apache::response::handle_previous(\%previous,$ad);
 	    $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
 	    $Apache::lonhomework::results{"resource.$partid.$id.molecule"}=$env{"form.MOLECULE_$id"};
@@ -338,16 +341,25 @@ sub end_organicresponse {
 					   "$partid.$id"); # part.response
 	if ($target eq 'analyze') {
             $Apache::lonhomework::analyze{"$partid.$id.type"} = 'organicresponse';
+            push (@{ $Apache::lonhomework::analyze{"parts"} },"$partid.$id");
 	    &Apache::lonhomework::set_bubble_lines();
 	}
     }
-    if (($target eq 'web' ) && ($Apache::lonhomework::type ne 'exam') && ($Apache::inputtags::status['-1'] eq 'CAN_ANSWER')){
-            my $options=&Apache::lonxml::get_param('options',$parstack,
-                                                   $safeeval);
-            my $shown_text;
-            if (&Apache::response::show_answer()) {
+    if ($target eq 'web' ) {
+        my ($showpencil,$shown_text);
+        if ($Apache::inputtags::status['-1'] eq 'CAN_ANSWER') {
+            $showpencil = 1;
+        } elsif (&Apache::response::show_answer()) {
+            my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,                                                         $safeeval);
+            if ($jmeanswer eq '') {
+                $showpencil = 1;
                 $shown_text="Show Your Last Answer";
             }
+        }
+        if ($showpencil) {
+            my $options=&Apache::lonxml::get_param('options',$parstack,
+                                                   $safeeval);
+
 	    my $molecule;
 	    if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) {
 		$molecule=$Apache::lonhomework::history{"resource.$partid.$id.molecule"};
@@ -355,8 +367,9 @@ sub end_organicresponse {
 		$molecule=&Apache::lonxml::get_param('molecule',$parstack,
 						     $safeeval);
 	    }
-	$result.=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,
-                             $options,$shown_text);
+	    $result.=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,
+                                          $options,$shown_text);
+        }
     }
     &Apache::response::end_response();
     return $result;
@@ -404,13 +417,14 @@ sub start_organicstructure {
 	$id=&escape($id);
 	&Apache::lonxml::register_ssi("/cgi-bin/convertjme.pl?$id");
 	if ($options =~ /border/) { $result.= '\fbox{'; }
-	$result .= '\graphicspath{{/home/httpd/perl/tmp/}}\includegraphics[width='.$texwidth.' mm]{'.$filename.'.eps}';
+	$result .= '\graphicspath{{'.LONCAPA::tempdir().
+	    '}}\includegraphics[width='.$texwidth.' mm]{'.$filename.'.eps}';
 	if ($options =~ /border/) { $result.= '} '; }
     } elsif ($target eq 'edit') {
 	$result .=&Apache::edit::tag_start($target,$token);
 	$result .=&Apache::edit::text_arg('Width (pixels):','width',$token,5);
 	$result .=&Apache::edit::text_arg('TeXwidth (mm):','texwidth',$token,5);
-	$result .='<nobr>';
+	$result .='<span class="LC_nobreak">';
 	$result .=&Apache::edit::text_arg('Molecule:','molecule',$token,40);
 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
 						$safeeval);
@@ -423,7 +437,7 @@ sub start_organicstructure {
 	$result .=&separate_jme_window(undef,
 				 &Apache::edit::html_element_name('molecule'),
 				       $molecule,$options);
-	$result.="</nobr><br />";
+	$result.="</span><br />";
 	$result .=&Apache::edit::checked_arg('Options:','options',
 					     [ ['reaction','Is a reaction'],
 					       ['border','Draw a border'] ],
@@ -491,8 +505,6 @@ sub start_reactionresponse {
     } elsif ($target eq 'web') {
 	my $partid = $Apache::inputtags::part;
 	my $id = $Apache::inputtags::response['-1'];
-	my $reaction=$Apache::lonhomework::history{"resource.$partid.$id.submission"};
-	if ($reaction eq '') {  $reaction=&Apache::lonxml::get_param('initial',$parstack,$safeeval); }
 	if (  &Apache::response::show_answer() ) {
 	    my $ans=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
 	    if (!$Apache::lonxml::default_homework_loaded) {
@@ -505,12 +517,13 @@ sub start_reactionresponse {
 	$result .=&Apache::edit::tag_start($target,$token);
 	my $answer=&Apache::lonxml::get_param('answer',$parstack,
 						$safeeval);
-	$result .='<nobr>'.
+	$result .='<span class="LC_nobreak">'.
 	    &Apache::edit::text_arg('Answer:','answer',$token,40);
+	$result .=&edit_reaction_button($id,&Apache::edit::html_element_name('answer'),$answer).'</span>';
 	my $initial=&Apache::lonxml::get_param('initial',$parstack,$safeeval);
-	$result.='<nobr>'.
+	$result.='<span class="LC_nobreak">'.
 	    &Apache::edit::text_arg('Initial Reaction:','initial',$token,40);
-	
+	$result .=&edit_reaction_button($id,&Apache::edit::html_element_name('initial'),$initial).'</span>';
 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
     }  elsif ($target eq 'modified') {
 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
@@ -554,9 +567,17 @@ sub end_reactionresponse {
 		    $ad='INCORRECT';
 		}
 	    }
-	    if ($ad && $Apache::lonhomework::type eq 'survey') {
-		$ad='SUBMITTED';
-	    }
+            if ($ad) {
+                if ($Apache::lonhomework::type eq 'survey') {
+		    $ad='SUBMITTED';
+	        } elsif ($ad && $Apache::lonhomework::type eq 'surveycred') {
+                    $ad='SUBMITTED_CREDIT';
+                } elsif ($ad && $Apache::lonhomework::type eq 'anonsurvey') {
+                    $ad='ANONYMOUS';
+                } elsif ($ad && $Apache::lonhomework::type eq 'anonsurveycred') {
+                    $ad='ANONYMOUS_CREDIT';
+                }
+            }
 	    &Apache::response::handle_previous(\%previous,$ad);
 	    $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
 	}
@@ -581,17 +602,16 @@ sub end_reactionresponse {
 	&Apache::lonxml::increment_counter(&Apache::response::repetition(), "$partid.$id");
         if ($target eq 'analyze') {
             $Apache::lonhomework::analyze{"$partid.$id.type"} = 'reactionresponse';
+            push (@{ $Apache::lonhomework::analyze{"parts"} },"$partid.$id");
             &Apache::lonhomework::set_bubble_lines();
         }
     }
-     my $status=$Apache::inputtags::status['-1'];
-        if  (($target eq 'web') && ($Apache::lonhomework::type ne 'exam') && ($status eq 'CAN_ANSWER')) {
-             my $partid = $Apache::inputtags::part;
-             my $id = $Apache::inputtags::response['-1'];
-             my $reaction=$Apache::lonhomework::history{"resource.$partid.$id.submission"};
-             $result.=&edit_reaction_button($id,"HWVAL_$id",$reaction);
-
-        }  
+    my $status=$Apache::inputtags::status['-1'];
+    if  (($target eq 'web') && ($Apache::lonhomework::type ne 'exam') && ($status eq 'CAN_ANSWER')) {
+        my $reaction=$Apache::lonhomework::history{"resource.$partid.$id.submission"};
+        if ($reaction eq '') {  $reaction=&Apache::lonxml::get_param('initial',$parstack,$safeeval); }
+        $result.=&edit_reaction_button($id,"HWVAL_$id",$reaction);
+    }
     &Apache::response::end_response();
     return $result;
 }