Annotation of loncom/homework/chemresponse.pm, revision 1.47

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # chemical equation style response
                      3: #
1.47    ! albertel    4: # $Id: chemresponse.pm,v 1.46 2005/02/17 21:42:37 albertel Exp $
1.1       albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: #
                     29: package Apache::chemresponse;
                     30: use strict;
                     31: use Apache::lonxml;
                     32: use Apache::lonnet;
                     33: 
                     34: BEGIN {
1.46      albertel   35:     &Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse','chem'));
1.1       albertel   36: }
                     37: 
1.34      albertel   38: sub chem_standard_order {
                     39:     my ($reaction) = @_;
                     40:     my ($re,$pr) = split(/->|<=>/,$reaction);
                     41:     my @reactants = split(/\s\+/,$re);
                     42:     my @products =  split(/\s\+/,$pr);
                     43:     foreach my $substance (@reactants,@products) {
                     44: 	$substance =~ s/(\^\d*)\s+/$1_/g;         # protect superscript space
                     45: 	$substance =~ s/\s*//g;                   # strip whitespace
                     46: 	$substance =~ s/_/ /g;                    # restore superscript space
                     47:     }
                     48:     @reactants = sort @reactants;
                     49:     @products = sort @products;
                     50:     my $standard = '';
                     51:     foreach my $substance (@reactants) {
                     52: 	$standard .= $substance;
                     53: 	$standard .= ' + ';
                     54:     }
                     55:     $standard =~ s/ \+ $//;              # get rid of trailing plus sign
                     56:     $standard .= ' -> ';
                     57:     foreach my $substance (@products) {
                     58: 	$standard .= $substance;
                     59: 	$standard .= ' + ';
                     60:     }
                     61:     $standard =~ s/ \+ $//;              # get rid of trailing plus sign
                     62:     return $standard;
                     63: }
                     64: 
1.30      www        65: sub separate_jme_window {
1.6       albertel   66:     my ($smile_input,$jme_input,$molecule,$options)=@_;
1.2       albertel   67:     my $smilesection;
                     68:     if (defined($smile_input)) {
                     69: 	$smilesection=<<SMILESECTION;
1.21      albertel   70:         smiles = document.applets.JME.smiles();
1.2       albertel   71: 	opener.document.lonhomework.$smile_input.value = smiles;
                     72: SMILESECTION
                     73:     }
                     74:     my $jmesection;
                     75:     if (defined($jme_input)) {
                     76: 	$jmesection=<<JMESECTION;
                     77: 	jmeFile = document.applets.JME.jmeFile();
                     78: 	opener.document.lonhomework.$jme_input.value = jmeFile;
                     79: JMESECTION
                     80:     }
                     81: 
1.14      albertel   82:     if ($molecule) { $molecule='<param name="jme" value="'.$molecule.'" />'; }
1.1       albertel   83:     my $body=<<CHEMPAGE;
                     84: <html>
                     85: <head>
                     86: <title>Molecule Editor</title>
1.47    ! albertel   87: <script type="text/javascript">
        !            88: // <!--
1.1       albertel   89: function submitSmiles() {
1.21      albertel   90:     jmeFile = document.applets.JME.jmeFile();
                     91:     if (jmeFile == "") {
1.1       albertel   92: 	alert("Nothing to submit");
                     93:     } else {
1.21      albertel   94:         $jmesection
1.2       albertel   95:         $smilesection
1.1       albertel   96: 	window.close();
                     97:     }
                     98: }
                     99: function openHelpWindow() {
1.2       albertel  100:     window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600");
1.1       albertel  101: }
1.47    ! albertel  102: // -->
1.1       albertel  103: </script>
                    104: </head>
                    105: <body bgcolor="#ffffff">
                    106: <center>
1.27      albertel  107: <applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="440" height="390">
1.1       albertel  108: You have to enable Java and JavaScript on your machine.
1.12      albertel  109: $molecule
1.6       albertel  110: <param name="options" value="$options" />
1.1       albertel  111: </applet><br />
                    112: <font face="arial,helvetica,sans-serif" size=-1><a href="http://www.molinspiration.com/jme/index.html">JME Editor</a> courtesy of Peter Ertl, Novartis</font>
                    113: <form>
1.47    ! albertel  114: <input type="button" name="submit" value="Insert Answer" onclick = "submitSmiles();" />
1.1       albertel  115: <br />
1.47    ! albertel  116: <input type="button" value="  Close  " onclick = "window.close()" />
1.1       albertel  117: &nbsp;&nbsp;
1.47    ! albertel  118: <input type="button" value="  Help  " onclick = "openHelpWindow()" />
1.1       albertel  119: </form>
                    120: </center>
                    121: </body>
                    122: </html>
                    123: CHEMPAGE
1.32      albertel  124:     $body=&HTML::Entities::encode($body,'<>&"');
1.1       albertel  125:     $body=~s/\n/ /g;
1.41      www       126:     my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.1       albertel  127:     my $result=<<CHEMINPUT;
1.47    ! albertel  128: <input type="button" value="Draw Molecule" onclick="javascript:editor=window.open('','','width=500,height=500,scrollbars=no,resizable=yes');editor.$docopen;editor.document.writeln('$body')" />
1.1       albertel  129: CHEMINPUT
                    130:     return $result;
                    131: }
                    132: 
1.6       albertel  133: sub start_organicresponse {
1.1       albertel  134:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    135:     my $result;
                    136:     my $partid = $Apache::inputtags::part;
                    137:     my $id = &Apache::response::start_response($parstack,$safeeval);
                    138:     if ($target eq 'meta') {
1.28      albertel  139: 	$result=&Apache::response::meta_package_write('organicresponse');
1.1       albertel  140:     } elsif ($target eq 'web') {
1.44      albertel  141: 	if (  &Apache::response::show_answer() ) {
                    142: 	    my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
                    143: 						     $safeeval);
                    144: 	    my $options=&Apache::lonxml::get_param('options',$parstack,
                    145: 						   $safeeval);
                    146: 	    my $width=&Apache::lonxml::get_param('width',$parstack,
                    147: 						   $safeeval);
                    148: 	    my $id=&Apache::loncommon::get_cgi_id();
                    149: 	    $result="<img src='/cgi-bin/convertjme.pl?$id'";
                    150: 	    if ($options =~ /border/) { $result.= ' border="1"'; }
                    151: 	    $result.=' />';
                    152: 	    &Apache::lonnet::appenv('cgi.'.$id.'.JME'   =>
                    153: 				           &Apache::lonnet::escape($jmeanswer),
                    154: 				    'cgi.'.$id.'.PNG'   => 1,
                    155: 				    'cgi.'.$id.'.WIDTH' => $width);
1.1       albertel  156: 	} else {
1.44      albertel  157: 	    my $molecule;
                    158: 	    if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) {
                    159: 		$molecule=$Apache::lonhomework::history{"resource.$partid.$id.molecule"};
                    160: 	    } else {
                    161: 		$molecule=&Apache::lonxml::get_param('molecule',$parstack,
                    162: 						     $safeeval);
                    163: 	    }
                    164: 	    my $options=&Apache::lonxml::get_param('options',$parstack,
                    165: 						   $safeeval);
                    166: 	    $result=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,$options);
                    167: 	    $result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />';
1.1       albertel  168: 	}
1.2       albertel  169:     } elsif ($target eq 'edit') {
                    170: 	$result .=&Apache::edit::tag_start($target,$token);
1.12      albertel  171: 	my $options=&Apache::lonxml::get_param('options',$parstack,
                    172: 					       $safeeval);
                    173: 	if ($options !~ /multipart/) { $options.=',multipart'; }
1.7       albertel  174: 	$result .='<nobr>'.
                    175: 	    &Apache::edit::text_arg('Starting Molecule:','molecule',
                    176: 				    $token,40);
1.2       albertel  177: 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
                    178: 						$safeeval);
1.30      www       179: 	$result .=&separate_jme_window(undef,
1.2       albertel  180: 		      &Apache::edit::html_element_name('molecule'),
1.12      albertel  181: 		      $molecule,$options);
1.7       albertel  182: 	$result .='</nobr><br /><nobr>';
1.2       albertel  183: 	$result .=&Apache::edit::text_arg('Correct Answer:','answer',
                    184: 					  $token,40);
                    185: 	$result .=&Apache::edit::hidden_arg('jmeanswer',$token);
                    186: 	my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
                    187: 						 $safeeval);
1.30      www       188: 	$result .=&separate_jme_window(
1.2       albertel  189:                       &Apache::edit::html_element_name('answer'),
                    190:                       &Apache::edit::html_element_name('jmeanswer'),
1.12      albertel  191: 		      $jmeanswer,$options);
                    192: 	$result .='</nobr><br />';
                    193: 	$result .=&Apache::edit::checked_arg('Options:','options',
1.29      www       194: 				    [ ['autoez','Auto E,Z stereochemistry'],
1.18      albertel  195: 				      ['multipart','Multipart Structures'],
1.12      albertel  196: 				      ['nostereo','No stereochemistry'],
                    197: 				      ['reaction','Is a reaction'],
1.18      albertel  198: 				      ['number','Able to number atoms'] ],
1.12      albertel  199: 					     ,$token);
1.44      albertel  200: 	$result .=&Apache::edit::text_arg('Width of correct answer image:',
                    201: 					  'width',$token,10);
1.2       albertel  202: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    203:     } elsif ($target eq 'modified') {
                    204: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    205: 						     $safeeval,'molecule',
1.6       albertel  206: 						     'answer','jmeanswer',
1.44      albertel  207: 						     'options','width');
1.2       albertel  208: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.1       albertel  209:     }
                    210:     return $result;
                    211: }
                    212: 
1.6       albertel  213: sub end_organicresponse {
1.1       albertel  214:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    215:     my $result;
1.45      albertel  216:     if ($target eq 'grade' && &Apache::response::submitted()) {
1.31      albertel  217: 	&Apache::response::setup_params($$tagstack[-1],$safeeval);
1.1       albertel  218: 	my $response = &Apache::response::getresponse();
                    219: 	if ( $response =~ /[^\s]/) {
                    220: 	    my $partid = $Apache::inputtags::part;
                    221: 	    my $id = $Apache::inputtags::response['-1'];
1.13      albertel  222: 	    my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
1.1       albertel  223: 	    my %previous = &Apache::response::check_for_previous($response,$partid,$id);
                    224: 	    $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
                    225: 	    my $ad;
1.13      albertel  226: 	    foreach my $answer (@answers) {
                    227: 		&Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
                    228: 		if ($response eq $answer) {
                    229: 		    $ad='EXACT_ANS';
                    230: 		    last;
                    231: 		} else {
                    232: 		    $ad='INCORRECT';
                    233: 		}
1.1       albertel  234: 	    }
1.42      albertel  235: 	    if ($ad && $Apache::lonhomework::type eq 'survey') {
                    236: 		$ad='SUBMITTED';
                    237: 	    }
1.1       albertel  238: 	    &Apache::response::handle_previous(\%previous,$ad);
                    239: 	    $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
                    240: 	    $Apache::lonhomework::results{"resource.$partid.$id.molecule"}=$ENV{"form.MOLECULE_$id"};
                    241: 	}
1.2       albertel  242:     } elsif ($target eq "edit") {
                    243: 	$result.= &Apache::edit::tag_end($target,$token,'');
1.15      albertel  244:     } elsif ($target eq 'answer') {
                    245: 	my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
                    246: 						     $safeeval);
                    247: 	$result.=&Apache::response::answer_header('organicresponse');
                    248: 	foreach my $answer (@answers) {
                    249: 	    $result.=&Apache::response::answer_part('organicresponse',$answer);
                    250: 	}
                    251: 	$result.=&Apache::response::answer_footer('organicresponse');
1.1       albertel  252:     }
                    253:     &Apache::response::end_response;
                    254:     return $result;
                    255: }
                    256: 
1.6       albertel  257: sub start_organicstructure {
1.3       albertel  258:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    259:     my $result;
                    260:     if ($target eq 'web') {
                    261: 	my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
                    262: 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval);
1.12      albertel  263: 	my $options=&Apache::lonxml::get_param('options',$parstack,$safeeval);
1.23      albertel  264: 	my $id=&Apache::loncommon::get_cgi_id();
1.19      albertel  265: 	$result="<img src='/cgi-bin/convertjme.pl?$id'";
                    266: 	if ($options =~ /border/) { $result.= ' border="1"'; }
                    267: 	$result.=' />';
1.16      albertel  268: 	&Apache::lonnet::appenv(
                    269:             'cgi.'.$id.'.JME'   => &Apache::lonnet::escape($molecule),
1.17      albertel  270: 	    'cgi.'.$id.'.PNG' => 1,
1.16      albertel  271: 	    'cgi.'.$id.'.WIDTH' => $width );
1.17      albertel  272:     } elsif ($target eq 'tex') {
1.38      albertel  273: 	my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1);
1.17      albertel  274: 	if (!$texwidth) { $texwidth='90'; }
                    275: 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval);
                    276: 	my $options=&Apache::lonxml::get_param('options',$parstack,$safeeval);
                    277: 	my $filename = $ENV{'user.name'}.'_'.$ENV{'user.domain'}.
                    278: 	    '_'.time.'_'.$$.int(rand(1000)).'_organicstructure';
                    279: 	my $id=$filename;
                    280: 	&Apache::lonnet::appenv(
                    281: 		     'cgi.'.$id.'.JME'   => &Apache::lonnet::escape($molecule),
                    282: 		     'cgi.'.$id.'.PS' => 1,
                    283: 		     'cgi.'.$id.'.WIDTH' => $texwidth );
                    284: 	$id=&Apache::lonnet::escape($id);
                    285: 	&Apache::lonxml::register_ssi("/cgi-bin/convertjme.pl?$id");
1.20      albertel  286: 	if ($options =~ /border/) { $result.= '\fbox{'; }
                    287: 	$result .= '\graphicspath{{/home/httpd/perl/tmp/}}\includegraphics[width='.$texwidth.' mm]{'.$filename.'.eps}';
                    288: 	if ($options =~ /border/) { $result.= '} '; }
1.3       albertel  289:     } elsif ($target eq 'edit') {
                    290: 	$result .=&Apache::edit::tag_start($target,$token);
1.22      albertel  291: 	$result .=&Apache::edit::text_arg('Width (pixels):','width',$token,5);
                    292: 	$result .=&Apache::edit::text_arg('TeXwidth (mm):','texwidth',$token,5);
1.12      albertel  293: 	$result .='<nobr>';
1.3       albertel  294: 	$result .=&Apache::edit::text_arg('Molecule:','molecule',$token,40);
                    295: 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
                    296: 						$safeeval);
1.12      albertel  297: 	my $options=&Apache::lonxml::get_param('options',$parstack,
                    298: 					       $safeeval);
                    299: 	if ($options !~ /reaction/) {
                    300: 	    $options.= ',multipart,number';
                    301: 	}
                    302: 						   
1.30      www       303: 	$result .=&separate_jme_window(undef,
1.12      albertel  304: 				 &Apache::edit::html_element_name('molecule'),
                    305: 				       $molecule,$options);
                    306: 	$result.="</nobr><br />";
                    307: 	$result .=&Apache::edit::checked_arg('Options:','options',
1.18      albertel  308: 					     [ ['reaction','Is a reaction'],
1.12      albertel  309: 					       ['border','Draw a border'] ],
                    310: 					     $token);
1.24      albertel  311: 	$result .=&Apache::edit::end_row();
1.3       albertel  312:     } elsif ($target eq 'modified') {
                    313: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    314: 						     $safeeval,'molecule',
1.22      albertel  315: 						     'width','texwidth',
                    316: 						     'options');
1.3       albertel  317: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    318:     }
                    319:     return $result;
1.1       albertel  320: }
                    321: 
1.6       albertel  322: sub end_organicstructure {
1.3       albertel  323:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    324:     my $result;
                    325:     if ($target eq "edit") {
                    326: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    327:     }
1.4       albertel  328:     return $result;
                    329: }
                    330: 
1.9       albertel  331: sub edit_reaction_button {
1.11      albertel  332:     my ($id,$field,$reaction)=@_;
1.10      albertel  333:     my $id_es=&Apache::lonnet::escape($id);
                    334:     my $field_es=&Apache::lonnet::escape($field);
1.11      albertel  335:     my $reaction_es=&Apache::lonnet::escape($reaction);
1.41      www       336:     my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.9       albertel  337:     my $result=<<EDITREACTION;
1.10      albertel  338: <script type="text/javascript">
1.47    ! albertel  339: // <!--
1.10      albertel  340:     function create_reaction_window_${id}_${field} () {
                    341: 	editor=window.open('','','width=500,height=270,scrollbars=no,resizable=yes');
1.41      www       342: 	editor.$docopen;
1.37      albertel  343: 	editor.document.writeln('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><html> <head><title>LON-CAPA Reaction Editor</title></head><frameset rows="30%,*" border="0">  <frame src="/res/adm/pages/reactionresponse/reaction_viewer.html?inhibitmenu=yes" name="viewer" scrolling="no" />  <frame src="/res/adm/pages/reactionresponse/reaction_editor.html?inhibitmenu=yes&reaction=$reaction_es&id=$id_es&field=$field_es" name="editor" scrolling="no" /> </frameset> </html>');
1.10      albertel  344:     }
1.47    ! albertel  345: // -->
1.10      albertel  346: </script>
1.47    ! albertel  347: <input type='button' value='Edit Answer' onclick="javascript:create_reaction_window_${id}_${field}();void(0);" />
1.9       albertel  348: EDITREACTION
                    349:     return $result;
                    350: }
                    351: 
1.4       albertel  352: sub start_reactionresponse {
                    353:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    354:     my $result;
                    355:     my $id = &Apache::response::start_response($parstack,$safeeval);
1.10      albertel  356:     if ($target eq 'meta') {
1.28      albertel  357: 	$result=&Apache::response::meta_package_write('reactionresponse');
1.10      albertel  358:     } elsif ($target eq 'web') {
1.11      albertel  359: 	my $partid = $Apache::inputtags::part;
                    360: 	my $id = $Apache::inputtags::response['-1'];
                    361: 	my $reaction=$Apache::lonhomework::history{"resource.$partid.$id.submission"};
1.35      albertel  362: 	if ($reaction eq '') {  $reaction=&Apache::lonxml::get_param('initial',$parstack,$safeeval); }
1.33      albertel  363: 	my $status=$Apache::inputtags::status['-1'];
                    364: 	if ($status eq 'CAN_ANSWER') {
                    365: 	    $result.=&edit_reaction_button($id,"HWVAL_$id",$reaction);
                    366: 	}
                    367: 	if (  &Apache::response::show_answer() ) {
                    368: 	    my $ans=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
                    369: 	    $ans=~s/(\\|\')/\\$1/g;
                    370: 	    $Apache::inputtags::answertxt{$id}=&Apache::run::run("return &chemparse('$ans');",$safeeval);
                    371: 	}
1.4       albertel  372:     } elsif ($target eq "edit") {
1.9       albertel  373: 	$result .=&Apache::edit::tag_start($target,$token);
                    374: 	my $answer=&Apache::lonxml::get_param('answer',$parstack,
                    375: 						$safeeval);
1.10      albertel  376: 	$result .='<nobr>'.
                    377: 	    &Apache::edit::text_arg('Answer:','answer',$token,40);
                    378: 	$result .=&edit_reaction_button($id,&Apache::edit::html_element_name('answer'),$answer).'</nobr>';
1.35      albertel  379: 	my $initial=&Apache::lonxml::get_param('initial',$parstack,$safeeval);
                    380: 	$result.='<nobr>'.
1.43      albertel  381: 	    &Apache::edit::text_arg('Initial Reaction:','initial',$token,40);
1.35      albertel  382: 	$result .=&edit_reaction_button($id,&Apache::edit::html_element_name('initial'),$initial).'</nobr>';
1.10      albertel  383: 	
1.9       albertel  384: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.10      albertel  385:     }  elsif ($target eq 'modified') {
                    386: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.35      albertel  387: 						     $safeeval,'answer',
                    388: 						     'initial');
1.10      albertel  389: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.4       albertel  390:     }
                    391:     return $result;
                    392: }
                    393: 
                    394: sub end_reactionresponse {
                    395:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    396:     my $result;
1.45      albertel  397:     if ($target eq 'grade' && &Apache::response::submitted()) {
1.31      albertel  398: 	&Apache::response::setup_params($$tagstack[-1],$safeeval);
1.10      albertel  399: 	my $response = &Apache::response::getresponse();
                    400: 	if ( $response =~ /[^\s]/) {
                    401: 	    my $partid = $Apache::inputtags::part;
                    402: 	    my $id = $Apache::inputtags::response['-1'];
1.15      albertel  403: 	    my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
1.10      albertel  404: 	    my %previous = &Apache::response::check_for_previous($response,$partid,$id);
                    405: 	    $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
                    406: 	    my $ad;
1.13      albertel  407: 	    foreach my $answer (@answers) {
                    408: 		&Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
1.34      albertel  409: 		if (&chem_standard_order($response) eq 
                    410: 		    &chem_standard_order($answer)) {
1.13      albertel  411: 		    $ad='EXACT_ANS';
                    412: 		} else {
                    413: 		    $ad='INCORRECT';
                    414: 		}
1.10      albertel  415: 	    }
1.42      albertel  416: 	    if ($ad && $Apache::lonhomework::type eq 'survey') {
                    417: 		$ad='SUBMITTED';
                    418: 	    }
1.10      albertel  419: 	    &Apache::response::handle_previous(\%previous,$ad);
                    420: 	    $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
                    421: 	}
                    422:     }  elsif ($target eq "edit") {
1.4       albertel  423: 	$result.= &Apache::edit::tag_end($target,$token,'');
1.15      albertel  424:     } elsif ($target eq 'answer') {
                    425: 	my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
                    426: 						     $safeeval);
                    427: 	$result.=&Apache::response::answer_header('reactionresponse');
                    428: 	foreach my $answer (@answers) {
                    429: 	    $result.=&Apache::response::answer_part('reactionresponse',
                    430: 						    $answer);
                    431: 	}
                    432: 	$result.=&Apache::response::answer_footer('reactionresponse');
1.4       albertel  433:     }
                    434:     &Apache::response::end_response;
1.3       albertel  435:     return $result;
1.1       albertel  436: }
                    437: 
1.46      albertel  438: sub start_chem {
                    439:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
                    440:     my $result = '';
                    441:     if ($target eq 'tex' || $target eq 'web') {
                    442: 	&Apache::lonxml::startredirection();
                    443:     }    
                    444:     return $result;
                    445: }
                    446: 
                    447: sub end_chem {
                    448:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
                    449:     my $result = '';
                    450:     if ($target eq 'tex' || $target eq 'web') {
                    451: 	@Apache::scripttag::parser_env = @_;
                    452: 	if (!$Apache::lonxml::default_homework_loaded) {
                    453: 	    &Apache::lonxml::default_homework_load($safeeval);
                    454: 	}
                    455: 	my $innards=&Apache::lonxml::endredirection();
                    456: 	$result=&Apache::run::run("return &chemparse(q\0$innards\0);",$safeeval);
                    457:     }
                    458:     return $result;
                    459: }
                    460: 
1.1       albertel  461: 1;
                    462: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>