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

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

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