File:
[LON-CAPA] /
loncom /
homework /
chemresponse.pm
Revision
1.1:
download - view:
text,
annotated -
select for diffs
Sun May 4 08:45:22 2003 UTC (21 years, 1 month ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- adding <chemresponse> thi version work for student input on Mozilla,
needs:
- edit mode
- to be installed
- <chemstructure>
- check to work with IE and Netscape 4.X DOM models
- add JME files
- inorganic mode
1: # The LearningOnline Network with CAPA
2: # chemical equation style response
3: #
4: # $Id: chemresponse.pm,v 1.1 2003/05/04 08:45:22 albertel 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:
34: BEGIN {
35: &Apache::lonxml::register('Apache::chemresponse',('chemresponse','chemstructure'));
36: }
37:
38: sub seperate_jme_window {
39: my ($id,$molecule)=@_;
40: my $body=<<CHEMPAGE;
41: <html>
42: <head>
43: <title>Molecule Editor</title>
44: <script language="JavaScript">
45: function submitSmiles() {
46: smiles = document.applets.JME.smiles();
47: if (smiles == "") {
48: alert("Nothing to submit");
49: } else {
50: jmeFile = document.applets.JME.jmeFile();
51: opener.document.lonhomework.HWVAL_$id.value = smiles;
52: opener.document.lonhomework.MOLECULE_$id.value = jmeFile;
53: window.close();
54: }
55: }
56: function openHelpWindow() {
57: window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600")
58: }
59: </script>
60: </head>
61: <body bgcolor="#ffffff">
62: <center>
63: <applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="97%" height="78%">
64: You have to enable Java and JavaScript on your machine.
65: <param name="jme" value="$molecule" />
66: </applet><br />
67: <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>
68: <form>
69: <input type="button" name="submit" value="Insert Answer" onClick = "submitSmiles();" />
70: <br />
71: <input type="button" value=" Close " onClick = "window.close()" />
72:
73: <input type="button" value=" Help " onClick = "openHelpWindow()" />
74: </form>
75: </center>
76: </body>
77: </html>
78: CHEMPAGE
79: $body=&HTML::Entities::encode($body);
80: $body=~s/\n/ /g;
81: my $result=<<CHEMINPUT;
82: <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')" />
83: CHEMINPUT
84: return $result;
85: }
86:
87: sub start_chemresponse {
88: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
89: my $result;
90: my $partid = $Apache::inputtags::part;
91: my $id = &Apache::response::start_response($parstack,$safeeval);
92: if ($target eq 'meta') {
93: } elsif ($target eq 'web') {
94: my $molecule;
95: if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) {
96: $molecule=$Apache::lonhomework::history{"resource.$partid.$id.molecule"};
97: } else {
98: $molecule=&Apache::lonxml::get_param('molecule',$parstack,
99: $safeeval);
100: }
101: $result=&seperate_jme_window($id,$molecule);
102: $result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />';
103: }
104: return $result;
105: }
106:
107: sub end_chemresponse {
108: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
109: my $result;
110: if ($target eq 'grade' && defined($ENV{'form.submitted'})) {
111: &Apache::response::setup_params($$tagstack[-1]);
112: my $response = &Apache::response::getresponse();
113: if ( $response =~ /[^\s]/) {
114: my $partid = $Apache::inputtags::part;
115: my $id = $Apache::inputtags::response['-1'];
116: my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
117: my %previous = &Apache::response::check_for_previous($response,$partid,$id);
118: $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
119: &Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
120: my $ad;
121: if ($response eq $answer) {
122: $ad='EXACT_ANS';
123: } else {
124: $ad='INCORRECT';
125: }
126: &Apache::response::handle_previous(\%previous,$ad);
127: $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
128: $Apache::lonhomework::results{"resource.$partid.$id.molecule"}=$ENV{"form.MOLECULE_$id"};
129: }
130: }
131: &Apache::response::end_response;
132: return $result;
133: }
134:
135: sub start_chemstructure {
136: }
137:
138: sub end_chemstructure {
139: }
140:
141: 1;
142: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>