File:  [LON-CAPA] / loncom / homework / chemresponse.pm
Revision 1.8: download - view: text, annotated - select for diffs
Mon Jun 30 20:58:52 2003 UTC (20 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- not using this (using html files right now)

    1: # The LearningOnline Network with CAPA
    2: # chemical equation style response
    3: #
    4: # $Id: chemresponse.pm,v 1.8 2003/06/30 20:58:52 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',('organicresponse','organicstructure','reactionresponse'));
   36: }
   37: 
   38: sub seperate_jme_window {
   39:     my ($smile_input,$jme_input,$molecule,$options)=@_;
   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: 
   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 {
   64:         $smilesection
   65:         $jmesection
   66: 	window.close();
   67:     }
   68: }
   69: function openHelpWindow() {
   70:     window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600");
   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: <param name="options" value="$options" />
   80: </applet><br />
   81: <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>
   82: <form>
   83: <input type="button" name="submit" value="Insert Answer" onClick = "submitSmiles();" />
   84: <br />
   85: <input type="button" value="  Close  " onClick = "window.close()" />
   86: &nbsp;&nbsp;
   87: <input type="button" value="  Help  " onClick = "openHelpWindow()" />
   88: </form>
   89: </center>
   90: </body>
   91: </html>
   92: CHEMPAGE
   93:     $body=&HTML::Entities::encode($body);
   94:     $body=~s/\n/ /g;
   95:     my $result=<<CHEMINPUT;
   96: <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')" />
   97: CHEMINPUT
   98:     return $result;
   99: }
  100: 
  101: sub start_organicresponse {
  102:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  103:     my $result;
  104:     my $partid = $Apache::inputtags::part;
  105:     my $id = &Apache::response::start_response($parstack,$safeeval);
  106:     if ($target eq 'meta') {
  107:     } elsif ($target eq 'web') {
  108: 	my $molecule;
  109: 	if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) {
  110: 	    $molecule=$Apache::lonhomework::history{"resource.$partid.$id.molecule"};
  111: 	} else {
  112: 	    $molecule=&Apache::lonxml::get_param('molecule',$parstack,
  113: 						 $safeeval);
  114: 	}
  115: 	my $multipart=&Apache::lonxml::get_param('multipart',$parstack,
  116: 						 $safeeval);
  117: 	if ($multipart eq 'yes') {
  118: 	    $multipart = 'multipart';
  119: 	} else {
  120: 	    $multipart ='';
  121:         }
  122: 	$result=&seperate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,$multipart);
  123: 	$result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />';
  124:     } elsif ($target eq 'edit') {
  125: 	$result .=&Apache::edit::tag_start($target,$token);
  126: 	$result .='<nobr>'.
  127: 	    &Apache::edit::text_arg('Starting Molecule:','molecule',
  128: 				    $token,40);
  129: 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
  130: 						$safeeval);
  131: 	$result .=&seperate_jme_window(undef,
  132: 		      &Apache::edit::html_element_name('molecule'),
  133: 		      $molecule,'multipart');
  134: 	$result .='</nobr><br /><nobr>';
  135: 	$result .=&Apache::edit::text_arg('Correct Answer:','answer',
  136: 					  $token,40);
  137: 	$result .=&Apache::edit::hidden_arg('jmeanswer',$token);
  138: 	my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
  139: 						 $safeeval);
  140: 	$result .=&seperate_jme_window(
  141:                       &Apache::edit::html_element_name('answer'),
  142:                       &Apache::edit::html_element_name('jmeanswer'),
  143: 		      $jmeanswer,'multipart');
  144: 	$result .='</nobr>'.
  145: 	    &Apache::edit::select_arg('Multipart:','multipart',
  146: 				      ['no','yes'],$token);
  147: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  148:     } elsif ($target eq 'modified') {
  149: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  150: 						     $safeeval,'molecule',
  151: 						     'answer','jmeanswer',
  152: 						     'multipart');
  153: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  154:     }
  155:     return $result;
  156: }
  157: 
  158: sub end_organicresponse {
  159:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  160:     my $result;
  161:     if ($target eq 'grade' && defined($ENV{'form.submitted'})) {
  162: 	&Apache::response::setup_params($$tagstack[-1]);
  163: 	my $response = &Apache::response::getresponse();
  164: 	if ( $response =~ /[^\s]/) {
  165: 	    my $partid = $Apache::inputtags::part;
  166: 	    my $id = $Apache::inputtags::response['-1'];
  167: 	    my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
  168: 	    my %previous = &Apache::response::check_for_previous($response,$partid,$id);
  169: 	    $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
  170: 	    &Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
  171: 	    my $ad;
  172: 	    if ($response eq $answer) {
  173: 		$ad='EXACT_ANS';
  174: 	    } else {
  175: 		$ad='INCORRECT';
  176: 	    }
  177: 	    &Apache::response::handle_previous(\%previous,$ad);
  178: 	    $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
  179: 	    $Apache::lonhomework::results{"resource.$partid.$id.molecule"}=$ENV{"form.MOLECULE_$id"};
  180: 	}
  181:     } elsif ($target eq "edit") {
  182: 	$result.= &Apache::edit::tag_end($target,$token,'');
  183:     }
  184:     &Apache::response::end_response;
  185:     return $result;
  186: }
  187: 
  188: sub start_organicstructure {
  189:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  190:     my $result;
  191:     if ($target eq 'web') {
  192: 	my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
  193: 	my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
  194: 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval);
  195: 	$result=<<CHEMOUTPUT;
  196: <applet code="JME.class" archive="/adm/jme/JME.jar" width="$width" height="$height">
  197: <param name="options" value="depict border" />
  198: <param name="jme" value="$molecule" />
  199: </applet>
  200: CHEMOUTPUT
  201:     } elsif ($target eq 'edit') {
  202: 	$result .=&Apache::edit::tag_start($target,$token);
  203: 	$result .=&Apache::edit::text_arg('Width:','width',$token,5);
  204: 	$result .=&Apache::edit::text_arg('Height:','height',$token,5);
  205: 	$result .=&Apache::edit::text_arg('Molecule:','molecule',$token,40);
  206: 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
  207: 						$safeeval);
  208: 	$result .=&seperate_jme_window(undef,
  209: 		      &Apache::edit::html_element_name('molecule'),
  210: 		      $molecule,'multipart');
  211: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  212:     } elsif ($target eq 'modified') {
  213: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  214: 						     $safeeval,'molecule',
  215: 						     'width','height');
  216: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  217:     }
  218:     return $result;
  219: }
  220: 
  221: sub end_organicstructure {
  222:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  223:     my $result;
  224:     if ($target eq "edit") {
  225: 	$result.= &Apache::edit::tag_end($target,$token,'');
  226:     }
  227:     return $result;
  228: }
  229: 
  230: sub start_reactionresponse {
  231:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  232:     my $result;
  233:     my $id = &Apache::response::start_response($parstack,$safeeval);
  234:     if ($target eq 'web') {
  235: 	$result.=<<EDITREACTION;
  236: <input type='button' value='Edit Reaction' onClick="javascript:editor=window.open('/res/adm/reactionresponse/reaction_window.html','','width=500,height=270,scrollbars=no,resizable=yes'); document.cookie='problem=$id';" />
  237: EDITREACTION
  238: 
  239: #	$result.=&reaction_javascript();
  240: #	$result.='<iframe name="REACTION_'.$id.'" width="200" height="100" src="/adm/jme/reaction_viewer.html"></iframe>';
  241: #	$result.='<input type="button" value="Check" onClick = "javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200,scrollbars=1\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<center><br />\'+to_html(document.lonhomework.HWVAL_'.$id.'.value)+\'</center><input type=&quot;button&quot; value=&quot;  Close  &quot; onClick = &quot;parent.window.close()&quot; />\');newWindow.document.close()" />'
  242:     } elsif ($target eq "edit") {
  243:     }
  244:     return $result;
  245: }
  246: 
  247: sub end_reactionresponse {
  248:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  249:     my $result;
  250:     if ($target eq "edit") {
  251: 	$result.= &Apache::edit::tag_end($target,$token,'');
  252:     }
  253:     &Apache::response::end_response;
  254:     return $result;
  255: }
  256: 
  257: 1;
  258: __END__

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