File:
[LON-CAPA] /
loncom /
homework /
chemresponse.pm
Revision
1.86:
download - view:
text,
annotated -
select for diffs
Tue Dec 23 18:51:44 2008 UTC (15 years, 7 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_99_1,
version_2_7_99_0,
bz6209-base,
bz6209,
bz5969,
bz2851,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ5971-printing-apage,
BZ5434-fox
- Restore pre-2.7.1 functionality: "Show Your Last Answer" button displayed if after answer date, but no jmeanswer (for display of computer's answer) provided in problem.
- Remove code no longer used from start_organicresponse() following changes in 1.79 and 1.80 which replaced "Draw Molecule" button before input textbox with pencil icon after textbox.
- Change wording in CSTR for textbox entry for JME string of the answer, now pencil icon is used instead of "Draw Molecule" button.
1: # The LearningOnline Network with CAPA
2: # chemical equation style response
3: #
4: # $Id: chemresponse.pm,v 1.86 2008/12/23 18:51:44 raeburn Exp $
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: use Apache::lonlocal;
34: use lib '/home/httpd/lib/perl/';
35: use LONCAPA;
36:
37:
38: BEGIN {
39: &Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse','chem'));
40: }
41:
42: sub chem_standard_order {
43: my ($reaction) = @_;
44: my ($re,$pr) = split(/->|<=>/,$reaction);
45: my @reactants = split(/\s\+/,$re);
46: my @products = split(/\s\+/,$pr);
47: foreach my $substance (@reactants,@products) {
48: $substance =~ s/(\^\d*)\s+/$1_/g; # protect superscript space
49: $substance =~ s/\s*//g; # strip whitespace
50: $substance =~ s/_/ /g; # restore superscript space
51: }
52: @reactants = sort @reactants;
53: @products = sort @products;
54: my $standard = '';
55: foreach my $substance (@reactants) {
56: $standard .= $substance;
57: $standard .= ' + ';
58: }
59: $standard =~ s/ \+ $//; # get rid of trailing plus sign
60: $standard .= ' -> ';
61: foreach my $substance (@products) {
62: $standard .= $substance;
63: $standard .= ' + ';
64: }
65: $standard =~ s/ \+ $//; # get rid of trailing plus sign
66: return $standard;
67: }
68:
69: sub separate_jme_window {
70: my ($smile_input,$jme_input,$molecule,$options,$shown_text)=@_;
71: my $smilesection;
72: if (defined($smile_input)) {
73: $smilesection=<<SMILESECTION;
74: smiles = document.applets.JME.smiles();
75: opener.document.lonhomework.$smile_input.value = smiles;
76: SMILESECTION
77: }
78: my $jmesection;
79: if (defined($jme_input)) {
80: $jmesection=<<JMESECTION;
81: jmeFile = document.applets.JME.jmeFile();
82: opener.document.lonhomework.$jme_input.value = jmeFile;
83: JMESECTION
84: }
85:
86: if ($molecule) { $molecule='<param name="jme" value="'.$molecule.'" />'; }
87: my $insert_answer;
88: if ($shown_text eq '') {
89: $insert_answer=
90: '<input type="button" name="submit" value="Insert Answer" onclick="javascript:submitSmiles();" />';
91: }
92:
93: my $js = <<CHEMJS;
94: <script type="text/javascript">
95: function submitSmiles() {
96: jmeFile = document.applets.JME.jmeFile();
97: if (jmeFile == "") {
98: alert("Nothing to submit");
99: } else {
100: $jmesection
101: $smilesection
102: window.close();
103: }
104: }
105: function openHelpWindow() {
106: window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600");
107: }
108: function substituent(r) {document.applets.JME.setSubstituent(r);}
109: </script>
110: CHEMJS
111:
112: my $start_page =
113: &Apache::loncommon::start_page('Molecule Editor',undef,
114: {'only_body' => 1,
115: 'js_ready' => 1,
116: 'bgcolor' => '#FFFFFF',});
117: my $end_page =
118: &Apache::loncommon::end_page({'js_ready' => 1,});
119:
120: my $body=<<CHEMPAGE;
121: $js
122: <center>
123: <form>
124: <table width="440"><tr>
125: <td></td>
126: <td align="right">
127: <select onchange="javascript:substituent(options[selectedIndex].text)">
128: <option>Select substituent</option>
129: <option>-C(=O)OH</option>
130: <option>-C(=O)OMe</option>
131: <option>-OC(=O)Me</option>
132: <option>-CMe3</option>
133: <option>-CF3</option>
134: <option>-CCl3</option>
135: <option>-NO2</option>
136: <option>-SO2-NH2</option>
137: <option>-NH-SO2-Me</option>
138: <option>-NMe2</option>
139: <option>-C#N</option>
140: <option>-C#C-Me</option>
141: <option>-C#CH</option>
142: </select>
143: </td></tr>
144: </table>
145: <applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="440" height="390" mayscript>
146: You have to enable Java and JavaScript on your machine.
147: $molecule
148: <param name="options" value="$options" />
149: </applet><br />
150: <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>
151: <br />
152: $insert_answer
153: <br />
154: <input type="button" value=" Close " onclick = "javascript:window.close()" />
155:
156: <input type="button" value=" Help " onclick = "javascript:openHelpWindow()" />
157: </form>
158: </center>
159: CHEMPAGE
160:
161: $body=&Apache::loncommon::js_ready($body);
162: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
163: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
164: my $display=&mt('Draw Molecule');
165: if (defined($shown_text)) { $display=&mt($shown_text); }
166: my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
167: my $function =
168: 'LONCAPA_draw_molecule_'.&Apache::lonhtmlcommon::get_uniq_name();
169: my $result=<<CHEMINPUT;
170: <script type="text/javascript">
171: function $function() {
172: editor=window.open($nothing,'jmeedit','width=500,height=500,menubar=no,scrollbars=no,resizable=yes');
173: editor.$docopen;
174: editor.document.write('$start_page $body $end_page');
175: editor.document.close();
176: editor.focus();
177: }
178: </script>
179: CHEMINPUT
180: if ($shown_text eq '') {
181: $result .=<<PENCIL;
182: <a href="javascript:$function();void(0);"><img class="stift" src='$iconpath/stift.gif' alt='$display' title='$display' /></a>
183: PENCIL
184: } else {
185: $result .= '<input type="button" value="'.&mt($shown_text).'" onclick="javascript:'.$function.'();void(0);" />';
186: }
187: return $result;
188: }
189: sub jme_img {
190: my ($jme,$smile,$width,$options)=@_;
191: my $id=&Apache::loncommon::get_cgi_id();
192: my $result='<img alt="'.$smile.'" src="/cgi-bin/convertjme.pl?'.$id.'"';
193: if ($options =~ /border/) { $result.= ' border="1"'; }
194: $result.=' />';
195: &Apache::lonnet::appenv({'cgi.'.$id.'.JME' =>
196: &escape($jme),
197: 'cgi.'.$id.'.PNG' => 1,
198: 'cgi.'.$id.'.WIDTH' => $width});
199: return $result;
200: }
201:
202: sub start_organicresponse {
203: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
204: my $result;
205: my $partid = $Apache::inputtags::part;
206: my $id = &Apache::response::start_response($parstack,$safeeval);
207: if ($target eq 'meta') {
208: $result=&Apache::response::meta_package_write('organicresponse');
209: } elsif ($target eq 'web') {
210: my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
211: $safeeval);
212: if (&Apache::response::show_answer()) {
213: my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
214: $safeeval);
215: if ($jmeanswer ne '') {
216: my $options=&Apache::lonxml::get_param('options',$parstack,
217: $safeeval);
218: my $width=&Apache::lonxml::get_param('width',$parstack,
219: $safeeval);
220: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
221: $safeeval);
222: $result.=&jme_img($jmeanswer,$answers[0],$width,$options);
223: }
224: } else {
225: $result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />';
226: }
227: } elsif ($target eq 'edit') {
228: $result .=&Apache::edit::tag_start($target,$token);
229: my $options=&Apache::lonxml::get_param('options',$parstack,
230: $safeeval);
231: if ($options !~ /multipart/) { $options.=',multipart'; }
232: $result .='<span class="LC_nobreak">'.
233: &Apache::edit::text_arg('Starting Molecule:','molecule',
234: $token,40);
235: my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
236: $safeeval);
237: $result .=&separate_jme_window(undef,
238: &Apache::edit::html_element_name('molecule'),
239: $molecule,$options);
240: $result .='</span><br /><span class="LC_nobreak">';
241: $result .=&Apache::edit::text_arg('Correct Answer:','answer',
242: $token,40);
243: $result .='</span><br /><span class="LC_nobreak">';
244: $result .=&Apache::edit::text_arg('JME string of the answer - automatically updated by "Insert Answer" in the JME pop-up (click pencil):',
245: 'jmeanswer',$token);
246: my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
247: $safeeval);
248: $result .=&separate_jme_window(
249: &Apache::edit::html_element_name('answer'),
250: &Apache::edit::html_element_name('jmeanswer'),
251: $jmeanswer,$options);
252: $result .='</span><br />';
253: $result .=&Apache::edit::checked_arg('Options:','options',
254: [ ['autoez','Auto E,Z stereochemistry'],
255: ['multipart','Multipart Structures'],
256: ['nostereo','No stereochemistry'],
257: ['reaction','Is a reaction'],
258: ['number','Able to number atoms'] ],
259: ,$token);
260: $result .=&Apache::edit::text_arg('Width of correct answer image:',
261: 'width',$token,10);
262: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
263: } elsif ($target eq 'modified') {
264: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
265: $safeeval,'molecule',
266: 'answer','jmeanswer',
267: 'options','width');
268: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
269: }
270:
271: return $result;
272: }
273:
274: sub end_organicresponse {
275: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
276: my $result;
277:
278: my $partid = $Apache::inputtags::part;
279: my $id = $Apache::inputtags::response['-1'];
280:
281: if ($target eq 'grade'
282: && &Apache::response::submitted()
283: && $Apache::lonhomework::type eq 'exam') {
284:
285: &Apache::response::scored_response($partid,$id);
286:
287: } elsif ($target eq 'grade'
288: && &Apache::response::submitted()
289: && $Apache::lonhomework::type ne 'exam') {
290:
291: &Apache::response::setup_params($$tagstack[-1],$safeeval);
292: my $response = &Apache::response::getresponse();
293: if ( $response =~ /[^\s]/) {
294: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
295: my %previous = &Apache::response::check_for_previous($response,$partid,$id);
296: $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
297: my $ad;
298: foreach my $answer (@answers) {
299: &Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
300: if ($response eq $answer) {
301: $ad='EXACT_ANS';
302: last;
303: } else {
304: $ad='INCORRECT';
305: }
306: }
307: if ($ad && $Apache::lonhomework::type eq 'survey') {
308: $ad='SUBMITTED';
309: }
310: &Apache::response::handle_previous(\%previous,$ad);
311: $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
312: $Apache::lonhomework::results{"resource.$partid.$id.molecule"}=$env{"form.MOLECULE_$id"};
313: }
314: } elsif ($target eq "edit") {
315: $result.= &Apache::edit::tag_end($target,$token,'');
316: } elsif ($target eq 'answer') {
317: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
318: $safeeval);
319: $result.=&Apache::response::answer_header('organicresponse');
320: foreach my $answer (@answers) {
321: $result.=&Apache::response::answer_part('organicresponse',$answer);
322: }
323: $result.=&Apache::response::answer_footer('organicresponse');
324: }
325: if ($target eq 'web') {
326: &Apache::response::setup_prior_tries_hash(\&format_prior_answer_organic,
327: ['molecule'])
328: }
329:
330: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
331: $target eq 'tex' || $target eq 'analyze') {
332: &Apache::lonxml::increment_counter(&Apache::response::repetition(),
333: "$partid.$id"); # part.response
334: if ($target eq 'analyze') {
335: $Apache::lonhomework::analyze{"$partid.$id.type"} = 'organicresponse';
336: push (@{ $Apache::lonhomework::analyze{"parts"} },"$partid.$id");
337: &Apache::lonhomework::set_bubble_lines();
338: }
339: }
340: if ($target eq 'web' ) {
341: my ($showpencil,$shown_text);
342: if ($Apache::inputtags::status['-1'] eq 'CAN_ANSWER') {
343: $showpencil = 1;
344: } elsif (&Apache::response::show_answer()) {
345: my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack, $safeeval);
346: if ($jmeanswer eq '') {
347: $showpencil = 1;
348: $shown_text="Show Your Last Answer";
349: }
350: }
351: if ($showpencil) {
352: my $options=&Apache::lonxml::get_param('options',$parstack,
353: $safeeval);
354:
355: my $molecule;
356: if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) {
357: $molecule=$Apache::lonhomework::history{"resource.$partid.$id.molecule"};
358: } else {
359: $molecule=&Apache::lonxml::get_param('molecule',$parstack,
360: $safeeval);
361: }
362: $result.=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,
363: $options,$shown_text);
364: }
365: }
366: &Apache::response::end_response();
367: return $result;
368: }
369:
370: sub format_prior_answer_organic {
371: my ($mode,$answer,$other_data) = @_;
372: my $result=&mt('Smile representation: "[_1]"','<tt>'.$answer.'</tt>');
373: my $jme=$other_data->[0];
374: $result.=&jme_img($jme,$answer,400);
375: return $result;
376: }
377:
378: sub start_organicstructure {
379: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
380: my $result;
381: if ($target eq 'web') {
382: my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
383: my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval);
384: my $options=&Apache::lonxml::get_param('options',$parstack,$safeeval);
385: my $id=&Apache::loncommon::get_cgi_id();
386: $result="<img src='/cgi-bin/convertjme.pl?$id'";
387: if ($options =~ /border/) { $result.= ' border="1"'; }
388: $result.=' />';
389: &Apache::lonnet::appenv(
390: {'cgi.'.$id.'.JME' => &escape($molecule),
391: 'cgi.'.$id.'.PNG' => 1,
392: 'cgi.'.$id.'.WIDTH' => $width});
393: } elsif ($target eq 'tex') {
394: my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1);
395: my $webwidth=&Apache::lonxml::get_param('width', $parstack, $safeeval);
396: my $webheight=&Apache::lonxml::get_param('height', $parstack, $safeeval);
397: if (!$webheight) { $webheight = $webwidth; }
398: if (!$texwidth) { $texwidth='90'; }
399: $result = "%DYNAMICIMAGE:$webwidth:$webheight:$texwidth\n";
400: my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval);
401: my $options=&Apache::lonxml::get_param('options',$parstack,$safeeval);
402: my $filename = $env{'user.name'}.'_'.$env{'user.domain'}.
403: '_'.time.'_'.$$.int(rand(1000)).'_organicstructure';
404: my $id=$filename;
405: &Apache::lonnet::appenv(
406: {'cgi.'.$id.'.JME' => &escape($molecule),
407: 'cgi.'.$id.'.PS' => 1,
408: 'cgi.'.$id.'.WIDTH' => $texwidth});
409: $id=&escape($id);
410: &Apache::lonxml::register_ssi("/cgi-bin/convertjme.pl?$id");
411: if ($options =~ /border/) { $result.= '\fbox{'; }
412: $result .= '\graphicspath{{/home/httpd/perl/tmp/}}\includegraphics[width='.$texwidth.' mm]{'.$filename.'.eps}';
413: if ($options =~ /border/) { $result.= '} '; }
414: } elsif ($target eq 'edit') {
415: $result .=&Apache::edit::tag_start($target,$token);
416: $result .=&Apache::edit::text_arg('Width (pixels):','width',$token,5);
417: $result .=&Apache::edit::text_arg('TeXwidth (mm):','texwidth',$token,5);
418: $result .='<span class="LC_nobreak">';
419: $result .=&Apache::edit::text_arg('Molecule:','molecule',$token,40);
420: my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
421: $safeeval);
422: my $options=&Apache::lonxml::get_param('options',$parstack,
423: $safeeval);
424: if ($options !~ /reaction/) {
425: $options.= ',multipart,number';
426: }
427:
428: $result .=&separate_jme_window(undef,
429: &Apache::edit::html_element_name('molecule'),
430: $molecule,$options);
431: $result.="</span><br />";
432: $result .=&Apache::edit::checked_arg('Options:','options',
433: [ ['reaction','Is a reaction'],
434: ['border','Draw a border'] ],
435: $token);
436: $result .=&Apache::edit::end_row();
437: } elsif ($target eq 'modified') {
438: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
439: $safeeval,'molecule',
440: 'width','texwidth',
441: 'options');
442: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
443: }
444: return $result;
445: }
446:
447: sub end_organicstructure {
448: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
449: my $result;
450: if ($target eq "edit") {
451: $result.= &Apache::edit::tag_end($target,$token,'');
452: }
453: return $result;
454: }
455:
456: sub edit_reaction_button {
457: my ($id,$field,$reaction)=@_;
458: my $id_es=&escape($id);
459: my $field_es=&escape($field);
460: my $reaction_es=&escape($reaction);
461: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
462: my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
463: my $display=&mt('Edit Answer');
464: my $start_page =
465: &Apache::loncommon::start_page('LON-CAPA Reaction Editor',undef,
466: {'frameset' => 1,
467: 'js_ready' => 1,
468: 'add_entries' => {
469: 'rows' => "30%,*",
470: 'border' => "0",}},);
471: my $end_page =
472: &Apache::loncommon::end_page({'frameset' => 1,
473: 'js_ready' => 1});
474: my $result=<<EDITREACTION;
475: <script type="text/javascript">
476: // <!--
477: function create_reaction_window_${id}_${field} () {
478: editor=window.open('','','width=500,height=270,scrollbars=no,resizable=yes');
479: editor.$docopen;
480: 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');
481: editor.document.close();
482: }
483: // -->
484: </script>
485: <a href="javascript:create_reaction_window_${id}_${field}();void(0);"><img class="stift" src='$iconpath/stift.gif' alt='$display' title='$display' /></a>
486: EDITREACTION
487: return $result;
488: }
489:
490: sub start_reactionresponse {
491: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
492: my $result;
493: my $id = &Apache::response::start_response($parstack,$safeeval);
494: if ($target eq 'meta') {
495: $result=&Apache::response::meta_package_write('reactionresponse');
496: } elsif ($target eq 'web') {
497: my $partid = $Apache::inputtags::part;
498: my $id = $Apache::inputtags::response['-1'];
499: if ( &Apache::response::show_answer() ) {
500: my $ans=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
501: if (!$Apache::lonxml::default_homework_loaded) {
502: &Apache::lonxml::default_homework_load($safeeval);
503: }
504: @Apache::scripttag::parser_env = @_;
505: $Apache::inputtags::answertxt{$id}=[&Apache::run::run("return &chemparse(q\0$ans\0);",$safeeval)];
506: }
507: } elsif ($target eq "edit") {
508: $result .=&Apache::edit::tag_start($target,$token);
509: my $answer=&Apache::lonxml::get_param('answer',$parstack,
510: $safeeval);
511: $result .='<span class="LC_nobreak">'.
512: &Apache::edit::text_arg('Answer:','answer',$token,40);
513: $result .=&edit_reaction_button($id,&Apache::edit::html_element_name('answer'),$answer).'</span>';
514: my $initial=&Apache::lonxml::get_param('initial',$parstack,$safeeval);
515: $result.='<span class="LC_nobreak">'.
516: &Apache::edit::text_arg('Initial Reaction:','initial',$token,40);
517: $result .=&edit_reaction_button($id,&Apache::edit::html_element_name('initial'),$initial).'</span>';
518: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
519: } elsif ($target eq 'modified') {
520: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
521: $safeeval,'answer',
522: 'initial');
523: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
524: }
525: return $result;
526: }
527:
528: sub end_reactionresponse {
529: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
530: my $result;
531:
532: my $partid = $Apache::inputtags::part;
533: my $id = $Apache::inputtags::response['-1'];
534:
535: if ($target eq 'grade'
536: && &Apache::response::submitted()
537: && $Apache::lonhomework::type eq 'exam') {
538:
539: &Apache::response::scored_response($partid,$id);
540:
541: } elsif ($target eq 'grade'
542: && &Apache::response::submitted()
543: && $Apache::lonhomework::type ne 'exam') {
544:
545: &Apache::response::setup_params($$tagstack[-1],$safeeval);
546: my $response = &Apache::response::getresponse();
547: if ( $response =~ /[^\s]/) {
548: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
549: my %previous = &Apache::response::check_for_previous($response,$partid,$id);
550: $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
551: my $ad;
552: foreach my $answer (@answers) {
553: &Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
554: if (&chem_standard_order($response) eq
555: &chem_standard_order($answer)) {
556: $ad='EXACT_ANS';
557: } else {
558: $ad='INCORRECT';
559: }
560: }
561: if ($ad && $Apache::lonhomework::type eq 'survey') {
562: $ad='SUBMITTED';
563: }
564: &Apache::response::handle_previous(\%previous,$ad);
565: $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
566: }
567: } elsif ($target eq "edit") {
568: $result.= &Apache::edit::tag_end($target,$token,'');
569: } elsif ($target eq 'answer') {
570: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
571: $safeeval);
572: $result.=&Apache::response::answer_header('reactionresponse');
573: foreach my $answer (@answers) {
574: $result.=&Apache::response::answer_part('reactionresponse',
575: $answer);
576: }
577: $result.=&Apache::response::answer_footer('reactionresponse');
578: }
579: if ($target eq 'web') {
580: &Apache::response::setup_prior_tries_hash(\&format_prior_response_reaction);
581: }
582:
583: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
584: $target eq 'tex' || $target eq 'analyze') {
585: &Apache::lonxml::increment_counter(&Apache::response::repetition(), "$partid.$id");
586: if ($target eq 'analyze') {
587: $Apache::lonhomework::analyze{"$partid.$id.type"} = 'reactionresponse';
588: push (@{ $Apache::lonhomework::analyze{"parts"} },"$partid.$id");
589: &Apache::lonhomework::set_bubble_lines();
590: }
591: }
592: my $status=$Apache::inputtags::status['-1'];
593: if (($target eq 'web') && ($Apache::lonhomework::type ne 'exam') && ($status eq 'CAN_ANSWER')) {
594: my $reaction=$Apache::lonhomework::history{"resource.$partid.$id.submission"};
595: if ($reaction eq '') { $reaction=&Apache::lonxml::get_param('initial',$parstack,$safeeval); }
596: $result.=&edit_reaction_button($id,"HWVAL_$id",$reaction);
597: }
598: &Apache::response::end_response();
599: return $result;
600: }
601:
602: sub format_prior_response_reaction {
603: my ($mode,$answer) =@_;
604: return '<span class="LC_prior_reaction">'.
605: &HTML::Entities::encode($answer,'"<>&').'</span>';
606: }
607:
608: sub start_chem {
609: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
610: my $result = '';
611: my $inside = &Apache::lonxml::get_all_text_unbalanced("/chem",$parser);
612: if ($target eq 'tex' || $target eq 'web') {
613: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
614: if (!$Apache::lonxml::default_homework_loaded) {
615: &Apache::lonxml::default_homework_load($safeeval);
616: }
617: @Apache::scripttag::parser_env = @_;
618: $result=&Apache::run::run("return &chemparse(q\0$inside\0);",$safeeval);
619: }
620: return $result;
621: }
622:
623: sub end_chem {
624: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
625: my $result = '';
626: return $result;
627: }
628:
629: 1;
630: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>