--- loncom/homework/chemresponse.pm 2005/01/08 03:54:32 1.43
+++ loncom/homework/chemresponse.pm 2005/02/18 23:12:29 1.48
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# chemical equation style response
#
-# $Id: chemresponse.pm,v 1.43 2005/01/08 03:54:32 albertel Exp $
+# $Id: chemresponse.pm,v 1.48 2005/02/18 23:12:29 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -32,7 +32,7 @@ use Apache::lonxml;
use Apache::lonnet;
BEGIN {
- &Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse'));
+ &Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse','chem'));
}
sub chem_standard_order {
@@ -84,7 +84,8 @@ JMESECTION
Molecule Editor
-
@@ -109,11 +111,11 @@ $molecule
JME Editor courtesy of Peter Ertl, Novartis
@@ -123,7 +125,7 @@ CHEMPAGE
$body=~s/\n/ /g;
my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
my $result=<
+
CHEMINPUT
return $result;
}
@@ -136,17 +138,34 @@ sub start_organicresponse {
if ($target eq 'meta') {
$result=&Apache::response::meta_package_write('organicresponse');
} elsif ($target eq 'web') {
- my $molecule;
- if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) {
- $molecule=$Apache::lonhomework::history{"resource.$partid.$id.molecule"};
+ if ( &Apache::response::show_answer() ) {
+ my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
+ $safeeval);
+ my $options=&Apache::lonxml::get_param('options',$parstack,
+ $safeeval);
+ my $width=&Apache::lonxml::get_param('width',$parstack,
+ $safeeval);
+ my $id=&Apache::loncommon::get_cgi_id();
+ $result="
';
+ &Apache::lonnet::appenv('cgi.'.$id.'.JME' =>
+ &Apache::lonnet::escape($jmeanswer),
+ 'cgi.'.$id.'.PNG' => 1,
+ 'cgi.'.$id.'.WIDTH' => $width);
} else {
- $molecule=&Apache::lonxml::get_param('molecule',$parstack,
- $safeeval);
+ 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,
+ $safeeval);
+ }
+ my $options=&Apache::lonxml::get_param('options',$parstack,
+ $safeeval);
+ $result=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,$options);
+ $result.= '';
}
- my $options=&Apache::lonxml::get_param('options',$parstack,
- $safeeval);
- $result=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,$options);
- $result.= '';
} elsif ($target eq 'edit') {
$result .=&Apache::edit::tag_start($target,$token);
my $options=&Apache::lonxml::get_param('options',$parstack,
@@ -178,12 +197,14 @@ sub start_organicresponse {
['reaction','Is a reaction'],
['number','Able to number atoms'] ],
,$token);
+ $result .=&Apache::edit::text_arg('Width of correct answer image:',
+ 'width',$token,10);
$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
} elsif ($target eq 'modified') {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,
$safeeval,'molecule',
'answer','jmeanswer',
- 'options');
+ 'options','width');
if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
}
return $result;
@@ -192,7 +213,7 @@ sub start_organicresponse {
sub end_organicresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
- if ($target eq 'grade' && defined($ENV{'form.submitted'})) {
+ if ($target eq 'grade' && &Apache::response::submitted()) {
&Apache::response::setup_params($$tagstack[-1],$safeeval);
my $response = &Apache::response::getresponse();
if ( $response =~ /[^\s]/) {
@@ -315,13 +336,15 @@ sub edit_reaction_button {
my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
my $result=<
+//
-
+
EDITREACTION
return $result;
}
@@ -371,7 +394,7 @@ sub start_reactionresponse {
sub end_reactionresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
- if ($target eq 'grade' && defined($ENV{'form.submitted'})) {
+ if ($target eq 'grade' && &Apache::response::submitted()) {
&Apache::response::setup_params($$tagstack[-1],$safeeval);
my $response = &Apache::response::getresponse();
if ( $response =~ /[^\s]/) {
@@ -412,5 +435,26 @@ sub end_reactionresponse {
return $result;
}
+sub start_chem {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
+ my $result = '';
+ my $inside = &Apache::lonxml::get_all_text_unbalanced("/chem",$parser);
+ if ($target eq 'tex' || $target eq 'web') {
+ $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
+ if (!$Apache::lonxml::default_homework_loaded) {
+ &Apache::lonxml::default_homework_load($safeeval);
+ }
+ @Apache::scripttag::parser_env = @_;
+ $result=&Apache::run::run("return &chemparse(q\0$inside\0);",$safeeval);
+ }
+ return $result;
+}
+
+sub end_chem {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
+ my $result = '';
+ return $result;
+}
+
1;
__END__