version 1.47, 2005/02/18 05:37:42
|
version 1.60, 2005/06/30 18:56:35
|
Line 30 package Apache::chemresponse;
|
Line 30 package Apache::chemresponse;
|
use strict; |
use strict; |
use Apache::lonxml; |
use Apache::lonxml; |
use Apache::lonnet; |
use Apache::lonnet; |
|
use Apache::lonlocal; |
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse','chem')); |
&Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse','chem')); |
Line 63 sub chem_standard_order {
|
Line 64 sub chem_standard_order {
|
} |
} |
|
|
sub separate_jme_window { |
sub separate_jme_window { |
my ($smile_input,$jme_input,$molecule,$options)=@_; |
my ($smile_input,$jme_input,$molecule,$options,$shown_text)=@_; |
my $smilesection; |
my $smilesection; |
if (defined($smile_input)) { |
if (defined($smile_input)) { |
$smilesection=<<SMILESECTION; |
$smilesection=<<SMILESECTION; |
Line 80 JMESECTION
|
Line 81 JMESECTION
|
} |
} |
|
|
if ($molecule) { $molecule='<param name="jme" value="'.$molecule.'" />'; } |
if ($molecule) { $molecule='<param name="jme" value="'.$molecule.'" />'; } |
|
my $insert_answer; |
|
if ($shown_text eq '') { |
|
$insert_answer= |
|
'<input type="button" name="submit" value="Insert Answer" onclick="javascript:submitSmiles();" />'; |
|
} |
|
|
my $body=<<CHEMPAGE; |
my $body=<<CHEMPAGE; |
<html> |
<html> |
<head> |
<head> |
<title>Molecule Editor</title> |
<title>Molecule Editor</title> |
<script type="text/javascript"> |
<script type="text/javascript"> |
// <!-- |
|
function submitSmiles() { |
function submitSmiles() { |
jmeFile = document.applets.JME.jmeFile(); |
jmeFile = document.applets.JME.jmeFile(); |
if (jmeFile == "") { |
if (jmeFile == "") { |
Line 99 function submitSmiles() {
|
Line 105 function submitSmiles() {
|
function openHelpWindow() { |
function openHelpWindow() { |
window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600"); |
window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600"); |
} |
} |
// --> |
function substituent(r) {document.applets.JME.setSubstituent(r);} |
</script> |
</script> |
</head> |
</head> |
<body bgcolor="#ffffff"> |
<body bgcolor="#ffffff"> |
<center> |
<center> |
<applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="440" height="390"> |
<form> |
|
<table width="440"><tr> |
|
<td></td> |
|
<td align="right"> |
|
<select onchange="javascript:substituent(options[selectedIndex].text)"> |
|
<option>Select substituent</option> |
|
<option>-C(=O)OH</option> |
|
<option>-C(=O)OMe</option> |
|
<option>-OC(=O)Me</option> |
|
<option>-CMe3</option> |
|
<option>-CF3</option> |
|
<option>-CCl3</option> |
|
<option>-NO2</option> |
|
<option>-SO2-NH2</option> |
|
<option>-NH-SO2-Me</option> |
|
<option>-NMe2</option> |
|
<option>-C#N</option> |
|
<option>-C#C-Me</option> |
|
<option>-C#CH</option> |
|
</select> |
|
</td></tr> |
|
</table> |
|
<applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="440" height="390" mayscript> |
You have to enable Java and JavaScript on your machine. |
You have to enable Java and JavaScript on your machine. |
$molecule |
$molecule |
<param name="options" value="$options" /> |
<param name="options" value="$options" /> |
</applet><br /> |
</applet><br /> |
<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> |
<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> |
<form> |
$insert_answer |
<input type="button" name="submit" value="Insert Answer" onclick = "submitSmiles();" /> |
|
<br /> |
<br /> |
<input type="button" value=" Close " onclick = "window.close()" /> |
<input type="button" value=" Close " onclick = "javascript:window.close()" /> |
|
|
<input type="button" value=" Help " onclick = "openHelpWindow()" /> |
<input type="button" value=" Help " onclick = "javascript:openHelpWindow()" /> |
</form> |
</form> |
</center> |
</center> |
</body> |
</body> |
Line 123 $molecule
|
Line 150 $molecule
|
CHEMPAGE |
CHEMPAGE |
$body=&HTML::Entities::encode($body,'<>&"'); |
$body=&HTML::Entities::encode($body,'<>&"'); |
$body=~s/\n/ /g; |
$body=~s/\n/ /g; |
|
my $nothing=&Apache::lonhtmlcommon::javascript_nothing(); |
my $docopen=&Apache::lonhtmlcommon::javascript_docopen(); |
my $docopen=&Apache::lonhtmlcommon::javascript_docopen(); |
|
my $display=&mt('Draw Molecule'); |
|
if (defined($shown_text)) { $display=&mt($shown_text); } |
my $result=<<CHEMINPUT; |
my $result=<<CHEMINPUT; |
<input type="button" value="Draw Molecule" onclick="javascript:editor=window.open('','','width=500,height=500,scrollbars=no,resizable=yes');editor.$docopen;editor.document.writeln('$body')" /> |
<input type="button" value="$display" onclick="javascript:editor=window.open($nothing,'jmeedit','width=500,height=500,menubar=yes,scrollbars=no,resizable=yes');editor.$docopen;editor.document.write('$body');editor.document.close();editor.focus()" /> |
CHEMINPUT |
CHEMINPUT |
return $result; |
return $result; |
} |
} |
|
|
|
sub jme_img { |
|
my ($jme,$smile,$width,$options)=@_; |
|
my $id=&Apache::loncommon::get_cgi_id(); |
|
my $result='<img alt="'.$smile.'" src="/cgi-bin/convertjme.pl?'.$id.'"'; |
|
if ($options =~ /border/) { $result.= ' border="1"'; } |
|
$result.=' />'; |
|
&Apache::lonnet::appenv('cgi.'.$id.'.JME' => |
|
&Apache::lonnet::escape($jme), |
|
'cgi.'.$id.'.PNG' => 1, |
|
'cgi.'.$id.'.WIDTH' => $width); |
|
return $result; |
|
} |
|
|
sub start_organicresponse { |
sub start_organicresponse { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result; |
my $result; |
Line 138 sub start_organicresponse {
|
Line 181 sub start_organicresponse {
|
if ($target eq 'meta') { |
if ($target eq 'meta') { |
$result=&Apache::response::meta_package_write('organicresponse'); |
$result=&Apache::response::meta_package_write('organicresponse'); |
} elsif ($target eq 'web') { |
} elsif ($target eq 'web') { |
if ( &Apache::response::show_answer() ) { |
my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack, |
my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack, |
$safeeval); |
$safeeval); |
if ( &Apache::response::show_answer() && $jmeanswer ne '') { |
my $options=&Apache::lonxml::get_param('options',$parstack, |
my $options=&Apache::lonxml::get_param('options',$parstack, |
$safeeval); |
$safeeval); |
my $width=&Apache::lonxml::get_param('width',$parstack, |
my $width=&Apache::lonxml::get_param('width',$parstack, |
$safeeval); |
$safeeval); |
my $id=&Apache::loncommon::get_cgi_id(); |
my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack, |
$result="<img src='/cgi-bin/convertjme.pl?$id'"; |
$safeeval); |
if ($options =~ /border/) { $result.= ' border="1"'; } |
$result.=&jme_img($jmeanswer,$answers[0],$width,$options); |
$result.=' />'; |
|
&Apache::lonnet::appenv('cgi.'.$id.'.JME' => |
|
&Apache::lonnet::escape($jmeanswer), |
|
'cgi.'.$id.'.PNG' => 1, |
|
'cgi.'.$id.'.WIDTH' => $width); |
|
} else { |
} else { |
my $molecule; |
my $molecule; |
if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) { |
if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) { |
Line 163 sub start_organicresponse {
|
Line 201 sub start_organicresponse {
|
} |
} |
my $options=&Apache::lonxml::get_param('options',$parstack, |
my $options=&Apache::lonxml::get_param('options',$parstack, |
$safeeval); |
$safeeval); |
$result=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,$options); |
my $shown_text; |
|
if (&Apache::response::show_answer()) { |
|
$shown_text="Show Your Last Answer"; |
|
} |
|
$result=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule, |
|
$options,$shown_text); |
$result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />'; |
$result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />'; |
} |
} |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
Line 237 sub end_organicresponse {
|
Line 280 sub end_organicresponse {
|
} |
} |
&Apache::response::handle_previous(\%previous,$ad); |
&Apache::response::handle_previous(\%previous,$ad); |
$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad; |
$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad; |
$Apache::lonhomework::results{"resource.$partid.$id.molecule"}=$ENV{"form.MOLECULE_$id"}; |
$Apache::lonhomework::results{"resource.$partid.$id.molecule"}=$env{"form.MOLECULE_$id"}; |
} |
} |
} elsif ($target eq "edit") { |
} elsif ($target eq "edit") { |
$result.= &Apache::edit::tag_end($target,$token,''); |
$result.= &Apache::edit::tag_end($target,$token,''); |
Line 271 sub start_organicstructure {
|
Line 314 sub start_organicstructure {
|
'cgi.'.$id.'.WIDTH' => $width ); |
'cgi.'.$id.'.WIDTH' => $width ); |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1); |
my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1); |
|
my $webwidth=&Apache::lonxml::get_param('width', $parstack, $safeeval); |
|
my $webheight=&Apache::lonxml::get_param('height', $parstack, $safeeval); |
|
if ($webheight) { $webheight = $webwidth; } |
if (!$texwidth) { $texwidth='90'; } |
if (!$texwidth) { $texwidth='90'; } |
|
$result = "%DYNAMICIMAGE:$webwidth:$webheight:$texwidth\n"; |
my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval); |
my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval); |
my $options=&Apache::lonxml::get_param('options',$parstack,$safeeval); |
my $options=&Apache::lonxml::get_param('options',$parstack,$safeeval); |
my $filename = $ENV{'user.name'}.'_'.$ENV{'user.domain'}. |
my $filename = $env{'user.name'}.'_'.$env{'user.domain'}. |
'_'.time.'_'.$$.int(rand(1000)).'_organicstructure'; |
'_'.time.'_'.$$.int(rand(1000)).'_organicstructure'; |
my $id=$filename; |
my $id=$filename; |
&Apache::lonnet::appenv( |
&Apache::lonnet::appenv( |
Line 366 sub start_reactionresponse {
|
Line 413 sub start_reactionresponse {
|
} |
} |
if ( &Apache::response::show_answer() ) { |
if ( &Apache::response::show_answer() ) { |
my $ans=&Apache::lonxml::get_param('answer',$parstack,$safeeval); |
my $ans=&Apache::lonxml::get_param('answer',$parstack,$safeeval); |
$ans=~s/(\\|\')/\\$1/g; |
if (!$Apache::lonxml::default_homework_loaded) { |
$Apache::inputtags::answertxt{$id}=&Apache::run::run("return &chemparse('$ans');",$safeeval); |
&Apache::lonxml::default_homework_load($safeeval); |
|
} |
|
@Apache::scripttag::parser_env = @_; |
|
$Apache::inputtags::answertxt{$id}=&Apache::run::run("return &chemparse(q\0$ans\0);",$safeeval); |
} |
} |
} elsif ($target eq "edit") { |
} elsif ($target eq "edit") { |
$result .=&Apache::edit::tag_start($target,$token); |
$result .=&Apache::edit::tag_start($target,$token); |
Line 438 sub end_reactionresponse {
|
Line 488 sub end_reactionresponse {
|
sub start_chem { |
sub start_chem { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my $result = ''; |
my $result = ''; |
|
my $inside = &Apache::lonxml::get_all_text_unbalanced("/chem",$parser); |
if ($target eq 'tex' || $target eq 'web') { |
if ($target eq 'tex' || $target eq 'web') { |
&Apache::lonxml::startredirection(); |
$inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]); |
|
if (!$Apache::lonxml::default_homework_loaded) { |
|
&Apache::lonxml::default_homework_load($safeeval); |
|
} |
|
@Apache::scripttag::parser_env = @_; |
|
$result=&Apache::run::run("return &chemparse(q\0$inside\0);",$safeeval); |
} |
} |
return $result; |
return $result; |
} |
} |
Line 447 sub start_chem {
|
Line 503 sub start_chem {
|
sub end_chem { |
sub end_chem { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'tex' || $target eq 'web') { |
|
@Apache::scripttag::parser_env = @_; |
|
if (!$Apache::lonxml::default_homework_loaded) { |
|
&Apache::lonxml::default_homework_load($safeeval); |
|
} |
|
my $innards=&Apache::lonxml::endredirection(); |
|
$result=&Apache::run::run("return &chemparse(q\0$innards\0);",$safeeval); |
|
} |
|
return $result; |
return $result; |
} |
} |
|
|