Annotation of loncom/homework/chemresponse.pm, revision 1.65
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # chemical equation style response
3: #
1.65 ! albertel 4: # $Id: chemresponse.pm,v 1.64 2006/03/09 01:12:05 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.57 albertel 84: my $insert_answer;
1.59 albertel 85: if ($shown_text eq '') {
1.57 albertel 86: $insert_answer=
87: '<input type="button" name="submit" value="Insert Answer" onclick="javascript:submitSmiles();" />';
88: }
89:
1.65 ! albertel 90: my $js = <<CHEMJS;
1.47 albertel 91: <script type="text/javascript">
1.1 albertel 92: function submitSmiles() {
1.21 albertel 93: jmeFile = document.applets.JME.jmeFile();
94: if (jmeFile == "") {
1.1 albertel 95: alert("Nothing to submit");
96: } else {
1.21 albertel 97: $jmesection
1.2 albertel 98: $smilesection
1.1 albertel 99: window.close();
100: }
101: }
102: function openHelpWindow() {
1.2 albertel 103: window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600");
1.1 albertel 104: }
1.60 albertel 105: function substituent(r) {document.applets.JME.setSubstituent(r);}
1.1 albertel 106: </script>
1.65 ! albertel 107: CHEMJS
! 108:
! 109: my $start_page =
! 110: &Apache::loncommon::start_page('Molecule Editor',$js,
! 111: {'only_body' => 1,
! 112: 'bgcolor' => '#FFFFFF',});
! 113: my $end_page =
! 114: &Apache::loncommon::end_page();
! 115:
! 116: my $body=<<CHEMPAGE;
! 117: $start_page
1.1 albertel 118: <center>
1.60 albertel 119: <form>
120: <table width="440"><tr>
121: <td></td>
122: <td align="right">
123: <select onchange="javascript:substituent(options[selectedIndex].text)">
124: <option>Select substituent</option>
125: <option>-C(=O)OH</option>
126: <option>-C(=O)OMe</option>
127: <option>-OC(=O)Me</option>
128: <option>-CMe3</option>
129: <option>-CF3</option>
130: <option>-CCl3</option>
131: <option>-NO2</option>
132: <option>-SO2-NH2</option>
133: <option>-NH-SO2-Me</option>
134: <option>-NMe2</option>
135: <option>-C#N</option>
136: <option>-C#C-Me</option>
137: <option>-C#CH</option>
138: </select>
139: </td></tr>
140: </table>
141: <applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="440" height="390" mayscript>
1.1 albertel 142: You have to enable Java and JavaScript on your machine.
1.12 albertel 143: $molecule
1.6 albertel 144: <param name="options" value="$options" />
1.1 albertel 145: </applet><br />
1.49 albertel 146: <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.61 albertel 147: <br />
1.57 albertel 148: $insert_answer
1.1 albertel 149: <br />
1.57 albertel 150: <input type="button" value=" Close " onclick = "javascript:window.close()" />
1.1 albertel 151:
1.57 albertel 152: <input type="button" value=" Help " onclick = "javascript:openHelpWindow()" />
1.1 albertel 153: </form>
154: </center>
1.65 ! albertel 155: $end_page
1.1 albertel 156: CHEMPAGE
1.65 ! albertel 157:
1.32 albertel 158: $body=&HTML::Entities::encode($body,'<>&"');
1.1 albertel 159: $body=~s/\n/ /g;
1.53 albertel 160: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.41 www 161: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.55 albertel 162: my $display=&mt('Draw Molecule');
163: if (defined($shown_text)) { $display=&mt($shown_text); }
1.1 albertel 164: my $result=<<CHEMINPUT;
1.61 albertel 165: <input type="button" value="$display" onclick="javascript:editor=window.open($nothing,'jmeedit','width=500,height=500,menubar=no,scrollbars=no,resizable=yes');editor.$docopen;editor.document.write('$body');editor.document.close();editor.focus()" />
1.1 albertel 166: CHEMINPUT
167: return $result;
168: }
169:
1.56 albertel 170: sub jme_img {
171: my ($jme,$smile,$width,$options)=@_;
172: my $id=&Apache::loncommon::get_cgi_id();
173: my $result='<img alt="'.$smile.'" src="/cgi-bin/convertjme.pl?'.$id.'"';
174: if ($options =~ /border/) { $result.= ' border="1"'; }
175: $result.=' />';
176: &Apache::lonnet::appenv('cgi.'.$id.'.JME' =>
177: &Apache::lonnet::escape($jme),
178: 'cgi.'.$id.'.PNG' => 1,
179: 'cgi.'.$id.'.WIDTH' => $width);
180: return $result;
181: }
182:
1.6 albertel 183: sub start_organicresponse {
1.1 albertel 184: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
185: my $result;
186: my $partid = $Apache::inputtags::part;
187: my $id = &Apache::response::start_response($parstack,$safeeval);
188: if ($target eq 'meta') {
1.28 albertel 189: $result=&Apache::response::meta_package_write('organicresponse');
1.1 albertel 190: } elsif ($target eq 'web') {
1.55 albertel 191: my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
192: $safeeval);
193: if ( &Apache::response::show_answer() && $jmeanswer ne '') {
1.44 albertel 194: my $options=&Apache::lonxml::get_param('options',$parstack,
195: $safeeval);
196: my $width=&Apache::lonxml::get_param('width',$parstack,
197: $safeeval);
1.56 albertel 198: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
199: $safeeval);
200: $result.=&jme_img($jmeanswer,$answers[0],$width,$options);
1.1 albertel 201: } else {
1.44 albertel 202: my $molecule;
203: if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) {
204: $molecule=$Apache::lonhomework::history{"resource.$partid.$id.molecule"};
205: } else {
206: $molecule=&Apache::lonxml::get_param('molecule',$parstack,
207: $safeeval);
208: }
209: my $options=&Apache::lonxml::get_param('options',$parstack,
210: $safeeval);
1.55 albertel 211: my $shown_text;
212: if (&Apache::response::show_answer()) {
213: $shown_text="Show Your Last Answer";
214: }
215: $result=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,
216: $options,$shown_text);
1.44 albertel 217: $result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />';
1.1 albertel 218: }
1.2 albertel 219: } elsif ($target eq 'edit') {
220: $result .=&Apache::edit::tag_start($target,$token);
1.12 albertel 221: my $options=&Apache::lonxml::get_param('options',$parstack,
222: $safeeval);
223: if ($options !~ /multipart/) { $options.=',multipart'; }
1.7 albertel 224: $result .='<nobr>'.
225: &Apache::edit::text_arg('Starting Molecule:','molecule',
226: $token,40);
1.2 albertel 227: my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
228: $safeeval);
1.30 www 229: $result .=&separate_jme_window(undef,
1.2 albertel 230: &Apache::edit::html_element_name('molecule'),
1.12 albertel 231: $molecule,$options);
1.7 albertel 232: $result .='</nobr><br /><nobr>';
1.2 albertel 233: $result .=&Apache::edit::text_arg('Correct Answer:','answer',
234: $token,40);
235: $result .=&Apache::edit::hidden_arg('jmeanswer',$token);
236: my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
237: $safeeval);
1.30 www 238: $result .=&separate_jme_window(
1.2 albertel 239: &Apache::edit::html_element_name('answer'),
240: &Apache::edit::html_element_name('jmeanswer'),
1.12 albertel 241: $jmeanswer,$options);
242: $result .='</nobr><br />';
243: $result .=&Apache::edit::checked_arg('Options:','options',
1.29 www 244: [ ['autoez','Auto E,Z stereochemistry'],
1.18 albertel 245: ['multipart','Multipart Structures'],
1.12 albertel 246: ['nostereo','No stereochemistry'],
247: ['reaction','Is a reaction'],
1.18 albertel 248: ['number','Able to number atoms'] ],
1.12 albertel 249: ,$token);
1.44 albertel 250: $result .=&Apache::edit::text_arg('Width of correct answer image:',
251: 'width',$token,10);
1.2 albertel 252: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
253: } elsif ($target eq 'modified') {
254: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
255: $safeeval,'molecule',
1.6 albertel 256: 'answer','jmeanswer',
1.44 albertel 257: 'options','width');
1.2 albertel 258: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.1 albertel 259: }
1.63 albertel 260:
1.1 albertel 261: return $result;
262: }
263:
1.6 albertel 264: sub end_organicresponse {
1.1 albertel 265: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
266: my $result;
1.64 albertel 267:
268: my $partid = $Apache::inputtags::part;
269: my $id = $Apache::inputtags::response['-1'];
270:
271: if ($target eq 'grade'
272: && &Apache::response::submitted()
273: && $Apache::lonhomework::type eq 'exam') {
274:
275: &Apache::response::scored_response($partid,$id);
276:
277: } elsif ($target eq 'grade'
278: && &Apache::response::submitted()
279: && $Apache::lonhomework::type ne 'exam') {
280:
1.31 albertel 281: &Apache::response::setup_params($$tagstack[-1],$safeeval);
1.1 albertel 282: my $response = &Apache::response::getresponse();
283: if ( $response =~ /[^\s]/) {
1.13 albertel 284: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
1.1 albertel 285: my %previous = &Apache::response::check_for_previous($response,$partid,$id);
286: $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
287: my $ad;
1.13 albertel 288: foreach my $answer (@answers) {
289: &Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
290: if ($response eq $answer) {
291: $ad='EXACT_ANS';
292: last;
293: } else {
294: $ad='INCORRECT';
295: }
1.1 albertel 296: }
1.42 albertel 297: if ($ad && $Apache::lonhomework::type eq 'survey') {
298: $ad='SUBMITTED';
299: }
1.1 albertel 300: &Apache::response::handle_previous(\%previous,$ad);
301: $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
1.50 albertel 302: $Apache::lonhomework::results{"resource.$partid.$id.molecule"}=$env{"form.MOLECULE_$id"};
1.1 albertel 303: }
1.2 albertel 304: } elsif ($target eq "edit") {
305: $result.= &Apache::edit::tag_end($target,$token,'');
1.15 albertel 306: } elsif ($target eq 'answer') {
307: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
308: $safeeval);
309: $result.=&Apache::response::answer_header('organicresponse');
310: foreach my $answer (@answers) {
311: $result.=&Apache::response::answer_part('organicresponse',$answer);
312: }
313: $result.=&Apache::response::answer_footer('organicresponse');
1.1 albertel 314: }
1.63 albertel 315:
316: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
317: $target eq 'tex' || $target eq 'analyze') {
318: &Apache::lonxml::increment_counter(&Apache::response::repetition());
319: }
320: &Apache::response::end_response();
1.1 albertel 321: return $result;
322: }
323:
1.6 albertel 324: sub start_organicstructure {
1.3 albertel 325: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
326: my $result;
327: if ($target eq 'web') {
328: my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
329: my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval);
1.12 albertel 330: my $options=&Apache::lonxml::get_param('options',$parstack,$safeeval);
1.23 albertel 331: my $id=&Apache::loncommon::get_cgi_id();
1.19 albertel 332: $result="<img src='/cgi-bin/convertjme.pl?$id'";
333: if ($options =~ /border/) { $result.= ' border="1"'; }
334: $result.=' />';
1.16 albertel 335: &Apache::lonnet::appenv(
336: 'cgi.'.$id.'.JME' => &Apache::lonnet::escape($molecule),
1.17 albertel 337: 'cgi.'.$id.'.PNG' => 1,
1.16 albertel 338: 'cgi.'.$id.'.WIDTH' => $width );
1.17 albertel 339: } elsif ($target eq 'tex') {
1.38 albertel 340: my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1);
1.58 foxr 341: my $webwidth=&Apache::lonxml::get_param('width', $parstack, $safeeval);
342: my $webheight=&Apache::lonxml::get_param('height', $parstack, $safeeval);
1.62 foxr 343: if (!$webheight) { $webheight = $webwidth; }
1.17 albertel 344: if (!$texwidth) { $texwidth='90'; }
1.58 foxr 345: $result = "%DYNAMICIMAGE:$webwidth:$webheight:$texwidth\n";
1.17 albertel 346: my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval);
347: my $options=&Apache::lonxml::get_param('options',$parstack,$safeeval);
1.50 albertel 348: my $filename = $env{'user.name'}.'_'.$env{'user.domain'}.
1.17 albertel 349: '_'.time.'_'.$$.int(rand(1000)).'_organicstructure';
350: my $id=$filename;
351: &Apache::lonnet::appenv(
352: 'cgi.'.$id.'.JME' => &Apache::lonnet::escape($molecule),
353: 'cgi.'.$id.'.PS' => 1,
354: 'cgi.'.$id.'.WIDTH' => $texwidth );
355: $id=&Apache::lonnet::escape($id);
356: &Apache::lonxml::register_ssi("/cgi-bin/convertjme.pl?$id");
1.20 albertel 357: if ($options =~ /border/) { $result.= '\fbox{'; }
358: $result .= '\graphicspath{{/home/httpd/perl/tmp/}}\includegraphics[width='.$texwidth.' mm]{'.$filename.'.eps}';
359: if ($options =~ /border/) { $result.= '} '; }
1.3 albertel 360: } elsif ($target eq 'edit') {
361: $result .=&Apache::edit::tag_start($target,$token);
1.22 albertel 362: $result .=&Apache::edit::text_arg('Width (pixels):','width',$token,5);
363: $result .=&Apache::edit::text_arg('TeXwidth (mm):','texwidth',$token,5);
1.12 albertel 364: $result .='<nobr>';
1.3 albertel 365: $result .=&Apache::edit::text_arg('Molecule:','molecule',$token,40);
366: my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
367: $safeeval);
1.12 albertel 368: my $options=&Apache::lonxml::get_param('options',$parstack,
369: $safeeval);
370: if ($options !~ /reaction/) {
371: $options.= ',multipart,number';
372: }
373:
1.30 www 374: $result .=&separate_jme_window(undef,
1.12 albertel 375: &Apache::edit::html_element_name('molecule'),
376: $molecule,$options);
377: $result.="</nobr><br />";
378: $result .=&Apache::edit::checked_arg('Options:','options',
1.18 albertel 379: [ ['reaction','Is a reaction'],
1.12 albertel 380: ['border','Draw a border'] ],
381: $token);
1.24 albertel 382: $result .=&Apache::edit::end_row();
1.3 albertel 383: } elsif ($target eq 'modified') {
384: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
385: $safeeval,'molecule',
1.22 albertel 386: 'width','texwidth',
387: 'options');
1.3 albertel 388: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
389: }
390: return $result;
1.1 albertel 391: }
392:
1.6 albertel 393: sub end_organicstructure {
1.3 albertel 394: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
395: my $result;
396: if ($target eq "edit") {
397: $result.= &Apache::edit::tag_end($target,$token,'');
398: }
1.4 albertel 399: return $result;
400: }
401:
1.9 albertel 402: sub edit_reaction_button {
1.11 albertel 403: my ($id,$field,$reaction)=@_;
1.10 albertel 404: my $id_es=&Apache::lonnet::escape($id);
405: my $field_es=&Apache::lonnet::escape($field);
1.11 albertel 406: my $reaction_es=&Apache::lonnet::escape($reaction);
1.41 www 407: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.65 ! albertel 408: my $start_page =
! 409: &Apache::loncommon::start_page('LON-CAPA Reaction Editor',undef,
! 410: {'frameset' => 1,
! 411: 'js_ready' => 1,
! 412: 'add_entries' => {
! 413: 'rows' => "30%",
! 414: 'border' => "0",}},);
! 415: my $end_page =
! 416: &Apache::loncommon::end_page({'frameset' => 1,
! 417: 'js_ready' => 1});
1.9 albertel 418: my $result=<<EDITREACTION;
1.10 albertel 419: <script type="text/javascript">
1.47 albertel 420: // <!--
1.10 albertel 421: function create_reaction_window_${id}_${field} () {
422: editor=window.open('','','width=500,height=270,scrollbars=no,resizable=yes');
1.41 www 423: editor.$docopen;
1.65 ! albertel 424: editor.document.writeln('$start_page <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" /> $end_page');
1.10 albertel 425: }
1.47 albertel 426: // -->
1.10 albertel 427: </script>
1.47 albertel 428: <input type='button' value='Edit Answer' onclick="javascript:create_reaction_window_${id}_${field}();void(0);" />
1.9 albertel 429: EDITREACTION
430: return $result;
431: }
432:
1.4 albertel 433: sub start_reactionresponse {
434: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
435: my $result;
436: my $id = &Apache::response::start_response($parstack,$safeeval);
1.10 albertel 437: if ($target eq 'meta') {
1.28 albertel 438: $result=&Apache::response::meta_package_write('reactionresponse');
1.10 albertel 439: } elsif ($target eq 'web') {
1.11 albertel 440: my $partid = $Apache::inputtags::part;
441: my $id = $Apache::inputtags::response['-1'];
442: my $reaction=$Apache::lonhomework::history{"resource.$partid.$id.submission"};
1.35 albertel 443: if ($reaction eq '') { $reaction=&Apache::lonxml::get_param('initial',$parstack,$safeeval); }
1.33 albertel 444: my $status=$Apache::inputtags::status['-1'];
445: if ($status eq 'CAN_ANSWER') {
446: $result.=&edit_reaction_button($id,"HWVAL_$id",$reaction);
447: }
448: if ( &Apache::response::show_answer() ) {
449: my $ans=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
1.51 albertel 450: if (!$Apache::lonxml::default_homework_loaded) {
451: &Apache::lonxml::default_homework_load($safeeval);
452: }
453: @Apache::scripttag::parser_env = @_;
454: $Apache::inputtags::answertxt{$id}=&Apache::run::run("return &chemparse(q\0$ans\0);",$safeeval);
1.33 albertel 455: }
1.4 albertel 456: } elsif ($target eq "edit") {
1.9 albertel 457: $result .=&Apache::edit::tag_start($target,$token);
458: my $answer=&Apache::lonxml::get_param('answer',$parstack,
459: $safeeval);
1.10 albertel 460: $result .='<nobr>'.
461: &Apache::edit::text_arg('Answer:','answer',$token,40);
462: $result .=&edit_reaction_button($id,&Apache::edit::html_element_name('answer'),$answer).'</nobr>';
1.35 albertel 463: my $initial=&Apache::lonxml::get_param('initial',$parstack,$safeeval);
464: $result.='<nobr>'.
1.43 albertel 465: &Apache::edit::text_arg('Initial Reaction:','initial',$token,40);
1.35 albertel 466: $result .=&edit_reaction_button($id,&Apache::edit::html_element_name('initial'),$initial).'</nobr>';
1.10 albertel 467:
1.9 albertel 468: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.10 albertel 469: } elsif ($target eq 'modified') {
470: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.35 albertel 471: $safeeval,'answer',
472: 'initial');
1.10 albertel 473: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.4 albertel 474: }
475: return $result;
476: }
477:
478: sub end_reactionresponse {
479: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
480: my $result;
1.64 albertel 481:
482: my $partid = $Apache::inputtags::part;
483: my $id = $Apache::inputtags::response['-1'];
484:
485: if ($target eq 'grade'
486: && &Apache::response::submitted()
487: && $Apache::lonhomework::type eq 'exam') {
488:
489: &Apache::response::scored_response($partid,$id);
490:
491: } elsif ($target eq 'grade'
492: && &Apache::response::submitted()
493: && $Apache::lonhomework::type ne 'exam') {
494:
1.31 albertel 495: &Apache::response::setup_params($$tagstack[-1],$safeeval);
1.10 albertel 496: my $response = &Apache::response::getresponse();
497: if ( $response =~ /[^\s]/) {
1.15 albertel 498: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
1.10 albertel 499: my %previous = &Apache::response::check_for_previous($response,$partid,$id);
500: $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
501: my $ad;
1.13 albertel 502: foreach my $answer (@answers) {
503: &Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
1.34 albertel 504: if (&chem_standard_order($response) eq
505: &chem_standard_order($answer)) {
1.13 albertel 506: $ad='EXACT_ANS';
507: } else {
508: $ad='INCORRECT';
509: }
1.10 albertel 510: }
1.42 albertel 511: if ($ad && $Apache::lonhomework::type eq 'survey') {
512: $ad='SUBMITTED';
513: }
1.10 albertel 514: &Apache::response::handle_previous(\%previous,$ad);
515: $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
516: }
517: } elsif ($target eq "edit") {
1.4 albertel 518: $result.= &Apache::edit::tag_end($target,$token,'');
1.15 albertel 519: } elsif ($target eq 'answer') {
520: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
521: $safeeval);
522: $result.=&Apache::response::answer_header('reactionresponse');
523: foreach my $answer (@answers) {
524: $result.=&Apache::response::answer_part('reactionresponse',
525: $answer);
526: }
527: $result.=&Apache::response::answer_footer('reactionresponse');
1.4 albertel 528: }
1.63 albertel 529:
530: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
531: $target eq 'tex' || $target eq 'analyze') {
532: &Apache::lonxml::increment_counter(&Apache::response::repetition());
533: }
534: &Apache::response::end_response();
1.3 albertel 535: return $result;
1.1 albertel 536: }
537:
1.46 albertel 538: sub start_chem {
539: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
540: my $result = '';
1.48 albertel 541: my $inside = &Apache::lonxml::get_all_text_unbalanced("/chem",$parser);
1.46 albertel 542: if ($target eq 'tex' || $target eq 'web') {
1.48 albertel 543: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
544: if (!$Apache::lonxml::default_homework_loaded) {
545: &Apache::lonxml::default_homework_load($safeeval);
546: }
547: @Apache::scripttag::parser_env = @_;
548: $result=&Apache::run::run("return &chemparse(q\0$inside\0);",$safeeval);
1.46 albertel 549: }
550: return $result;
551: }
552:
553: sub end_chem {
554: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
555: my $result = '';
556: return $result;
557: }
558:
1.1 albertel 559: 1;
560: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>