Annotation of loncom/homework/chemresponse.pm, revision 1.2
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # chemical equation style response
3: #
1.2 ! albertel 4: # $Id: chemresponse.pm,v 1.1 2003/05/04 08:45:22 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 {
35: &Apache::lonxml::register('Apache::chemresponse',('chemresponse','chemstructure'));
36: }
37:
38: sub seperate_jme_window {
1.2 ! albertel 39: my ($smile_input,$jme_input,$molecule)=@_;
! 40: my $smilesection;
! 41: if (defined($smile_input)) {
! 42: $smilesection=<<SMILESECTION;
! 43: opener.document.lonhomework.$smile_input.value = smiles;
! 44: SMILESECTION
! 45: }
! 46: my $jmesection;
! 47: if (defined($jme_input)) {
! 48: $jmesection=<<JMESECTION;
! 49: jmeFile = document.applets.JME.jmeFile();
! 50: opener.document.lonhomework.$jme_input.value = jmeFile;
! 51: JMESECTION
! 52: }
! 53:
1.1 albertel 54: my $body=<<CHEMPAGE;
55: <html>
56: <head>
57: <title>Molecule Editor</title>
58: <script language="JavaScript">
59: function submitSmiles() {
60: smiles = document.applets.JME.smiles();
61: if (smiles == "") {
62: alert("Nothing to submit");
63: } else {
1.2 ! albertel 64: $smilesection
! 65: $jmesection
1.1 albertel 66: window.close();
67: }
68: }
69: function openHelpWindow() {
1.2 ! albertel 70: window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600");
1.1 albertel 71: }
72: </script>
73: </head>
74: <body bgcolor="#ffffff">
75: <center>
76: <applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="97%" height="78%">
77: You have to enable Java and JavaScript on your machine.
78: <param name="jme" value="$molecule" />
79: </applet><br />
80: <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>
81: <form>
82: <input type="button" name="submit" value="Insert Answer" onClick = "submitSmiles();" />
83: <br />
84: <input type="button" value=" Close " onClick = "window.close()" />
85:
86: <input type="button" value=" Help " onClick = "openHelpWindow()" />
87: </form>
88: </center>
89: </body>
90: </html>
91: CHEMPAGE
92: $body=&HTML::Entities::encode($body);
93: $body=~s/\n/ /g;
94: my $result=<<CHEMINPUT;
95: <input type="button" value="Draw Molecule" onClick="javascript:editor=window.open('','','width=500,height=500,scrollbars=no,resizable=yes');editor.document.open('text/html','replace');editor.document.writeln('$body')" />
96: CHEMINPUT
97: return $result;
98: }
99:
100: sub start_chemresponse {
101: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
102: my $result;
103: my $partid = $Apache::inputtags::part;
104: my $id = &Apache::response::start_response($parstack,$safeeval);
105: if ($target eq 'meta') {
106: } elsif ($target eq 'web') {
107: my $molecule;
108: if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) {
109: $molecule=$Apache::lonhomework::history{"resource.$partid.$id.molecule"};
110: } else {
111: $molecule=&Apache::lonxml::get_param('molecule',$parstack,
112: $safeeval);
113: }
1.2 ! albertel 114: $result=&seperate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule);
1.1 albertel 115: $result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />';
1.2 ! albertel 116: } elsif ($target eq 'edit') {
! 117: $result .=&Apache::edit::tag_start($target,$token);
! 118: $result .=&Apache::edit::text_arg('Starting Molecule:','molecule',
! 119: $token,40);
! 120: my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
! 121: $safeeval);
! 122: $result .=&seperate_jme_window(undef,
! 123: &Apache::edit::html_element_name('molecule'),
! 124: $molecule);
! 125: $result .='<br />';
! 126: $result .=&Apache::edit::text_arg('Correct Answer:','answer',
! 127: $token,40);
! 128: $result .=&Apache::edit::hidden_arg('jmeanswer',$token);
! 129: my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
! 130: $safeeval);
! 131: $result .=&seperate_jme_window(
! 132: &Apache::edit::html_element_name('answer'),
! 133: &Apache::edit::html_element_name('jmeanswer'),
! 134: $jmeanswer);
! 135: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
! 136: } elsif ($target eq 'modified') {
! 137: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
! 138: $safeeval,'molecule',
! 139: 'answer','jmeanswer');
! 140: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.1 albertel 141: }
142: return $result;
143: }
144:
145: sub end_chemresponse {
146: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
147: my $result;
148: if ($target eq 'grade' && defined($ENV{'form.submitted'})) {
149: &Apache::response::setup_params($$tagstack[-1]);
150: my $response = &Apache::response::getresponse();
151: if ( $response =~ /[^\s]/) {
152: my $partid = $Apache::inputtags::part;
153: my $id = $Apache::inputtags::response['-1'];
154: my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
155: my %previous = &Apache::response::check_for_previous($response,$partid,$id);
156: $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
157: &Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
158: my $ad;
159: if ($response eq $answer) {
160: $ad='EXACT_ANS';
161: } else {
162: $ad='INCORRECT';
163: }
164: &Apache::response::handle_previous(\%previous,$ad);
165: $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
166: $Apache::lonhomework::results{"resource.$partid.$id.molecule"}=$ENV{"form.MOLECULE_$id"};
167: }
1.2 ! albertel 168: } elsif ($target eq "edit") {
! 169: $result.= &Apache::edit::tag_end($target,$token,'');
1.1 albertel 170: }
171: &Apache::response::end_response;
172: return $result;
173: }
174:
175: sub start_chemstructure {
176: }
177:
178: sub end_chemstructure {
179: }
180:
181: 1;
182: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>