version 1.65, 2006/04/13 18:57:51
|
version 1.76, 2008/02/01 22:05:45
|
Line 31 use strict;
|
Line 31 use strict;
|
use Apache::lonxml; |
use Apache::lonxml; |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::lonlocal; |
use Apache::lonlocal; |
|
use lib '/home/httpd/lib/perl/'; |
|
use LONCAPA; |
|
|
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse','chem')); |
&Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse','chem')); |
Line 107 function substituent(r) {document.applet
|
Line 110 function substituent(r) {document.applet
|
CHEMJS |
CHEMJS |
|
|
my $start_page = |
my $start_page = |
&Apache::loncommon::start_page('Molecule Editor',$js, |
&Apache::loncommon::start_page('Molecule Editor',undef, |
{'only_body' => 1, |
{'only_body' => 1, |
|
'js_ready' => 1, |
'bgcolor' => '#FFFFFF',}); |
'bgcolor' => '#FFFFFF',}); |
my $end_page = |
my $end_page = |
&Apache::loncommon::end_page(); |
&Apache::loncommon::end_page({'js_ready' => 1,}); |
|
|
my $body=<<CHEMPAGE; |
my $body=<<CHEMPAGE; |
$start_page |
$js |
<center> |
<center> |
<form> |
<form> |
<table width="440"><tr> |
<table width="440"><tr> |
Line 152 $insert_answer
|
Line 156 $insert_answer
|
<input type="button" value=" Help " onclick = "javascript:openHelpWindow()" /> |
<input type="button" value=" Help " onclick = "javascript:openHelpWindow()" /> |
</form> |
</form> |
</center> |
</center> |
$end_page |
|
CHEMPAGE |
CHEMPAGE |
|
|
$body=&HTML::Entities::encode($body,'<>&"'); |
$body=&Apache::loncommon::js_ready($body); |
$body=~s/\n/ /g; |
|
my $nothing=&Apache::lonhtmlcommon::javascript_nothing(); |
my $nothing=&Apache::lonhtmlcommon::javascript_nothing(); |
my $docopen=&Apache::lonhtmlcommon::javascript_docopen(); |
my $docopen=&Apache::lonhtmlcommon::javascript_docopen(); |
my $display=&mt('Draw Molecule'); |
my $display=&mt('Draw Molecule'); |
if (defined($shown_text)) { $display=&mt($shown_text); } |
if (defined($shown_text)) { $display=&mt($shown_text); } |
|
my $function = |
|
'LONCAPA_draw_molecule_'.&Apache::lonhtmlcommon::get_uniq_name(); |
my $result=<<CHEMINPUT; |
my $result=<<CHEMINPUT; |
<input type="button" value="$display" onclick="javascript:editor=window.open($nothing,'jmeedit','width=500,height=500,menubar=no,scrollbars=no,resizable=yes');editor.$docopen;editor.document.write('$body');editor.document.close();editor.focus()" /> |
<script type="text/javascript"> |
|
function $function() { |
|
editor=window.open($nothing,'jmeedit','width=500,height=500,menubar=no,scrollbars=no,resizable=yes'); |
|
editor.$docopen; |
|
editor.document.write('$start_page $body $end_page'); |
|
editor.document.close(); |
|
editor.focus(); |
|
} |
|
</script> |
|
<input type="button" value="$display" onclick="javascript:$function();void(0);" /> |
CHEMINPUT |
CHEMINPUT |
return $result; |
return $result; |
} |
} |
Line 174 sub jme_img {
|
Line 187 sub jme_img {
|
if ($options =~ /border/) { $result.= ' border="1"'; } |
if ($options =~ /border/) { $result.= ' border="1"'; } |
$result.=' />'; |
$result.=' />'; |
&Apache::lonnet::appenv('cgi.'.$id.'.JME' => |
&Apache::lonnet::appenv('cgi.'.$id.'.JME' => |
&Apache::lonnet::escape($jme), |
&escape($jme), |
'cgi.'.$id.'.PNG' => 1, |
'cgi.'.$id.'.PNG' => 1, |
'cgi.'.$id.'.WIDTH' => $width); |
'cgi.'.$id.'.WIDTH' => $width); |
return $result; |
return $result; |
Line 232 sub start_organicresponse {
|
Line 245 sub start_organicresponse {
|
$result .='</nobr><br /><nobr>'; |
$result .='</nobr><br /><nobr>'; |
$result .=&Apache::edit::text_arg('Correct Answer:','answer', |
$result .=&Apache::edit::text_arg('Correct Answer:','answer', |
$token,40); |
$token,40); |
$result .=&Apache::edit::hidden_arg('jmeanswer',$token); |
$result .='</nobr><br /><nobr>'; |
|
$result .=&Apache::edit::text_arg('JME string of the answer (automatically updated when using the Draw Molecule button):', |
|
'jmeanswer',$token); |
my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack, |
my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack, |
$safeeval); |
$safeeval); |
$result .=&separate_jme_window( |
$result .=&separate_jme_window( |
Line 312 sub end_organicresponse {
|
Line 327 sub end_organicresponse {
|
} |
} |
$result.=&Apache::response::answer_footer('organicresponse'); |
$result.=&Apache::response::answer_footer('organicresponse'); |
} |
} |
|
if ($target eq 'web') { |
|
&Apache::response::setup_prior_tries_hash(\&format_prior_answer_organic, |
|
['molecule']) |
|
} |
|
|
if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || |
if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || |
$target eq 'tex' || $target eq 'analyze') { |
$target eq 'tex' || $target eq 'analyze') { |
&Apache::lonxml::increment_counter(&Apache::response::repetition()); |
&Apache::lonxml::increment_counter(&Apache::response::repetition(), |
|
"$partid.$id"); # part.response |
|
if ($target eq 'analyze') { |
|
$Apache::lonhomework::analyze{"$partid.$id.type"} = 'organicresponse'; |
|
&Apache::lonhomework::set_bubble_lines(); |
|
} |
} |
} |
&Apache::response::end_response(); |
&Apache::response::end_response(); |
return $result; |
return $result; |
} |
} |
|
|
|
sub format_prior_answer_organic { |
|
my ($mode,$answer,$other_data) = @_; |
|
my $result=&mt('Smile representation: "[_1]"','<tt>'.$answer.'</tt>'); |
|
my $jme=$other_data->[0]; |
|
$result.=&jme_img($jme,$answer,400); |
|
return $result; |
|
} |
|
|
sub start_organicstructure { |
sub start_organicstructure { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result; |
my $result; |
Line 333 sub start_organicstructure {
|
Line 365 sub start_organicstructure {
|
if ($options =~ /border/) { $result.= ' border="1"'; } |
if ($options =~ /border/) { $result.= ' border="1"'; } |
$result.=' />'; |
$result.=' />'; |
&Apache::lonnet::appenv( |
&Apache::lonnet::appenv( |
'cgi.'.$id.'.JME' => &Apache::lonnet::escape($molecule), |
'cgi.'.$id.'.JME' => &escape($molecule), |
'cgi.'.$id.'.PNG' => 1, |
'cgi.'.$id.'.PNG' => 1, |
'cgi.'.$id.'.WIDTH' => $width ); |
'cgi.'.$id.'.WIDTH' => $width ); |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
Line 349 sub start_organicstructure {
|
Line 381 sub start_organicstructure {
|
'_'.time.'_'.$$.int(rand(1000)).'_organicstructure'; |
'_'.time.'_'.$$.int(rand(1000)).'_organicstructure'; |
my $id=$filename; |
my $id=$filename; |
&Apache::lonnet::appenv( |
&Apache::lonnet::appenv( |
'cgi.'.$id.'.JME' => &Apache::lonnet::escape($molecule), |
'cgi.'.$id.'.JME' => &escape($molecule), |
'cgi.'.$id.'.PS' => 1, |
'cgi.'.$id.'.PS' => 1, |
'cgi.'.$id.'.WIDTH' => $texwidth ); |
'cgi.'.$id.'.WIDTH' => $texwidth ); |
$id=&Apache::lonnet::escape($id); |
$id=&escape($id); |
&Apache::lonxml::register_ssi("/cgi-bin/convertjme.pl?$id"); |
&Apache::lonxml::register_ssi("/cgi-bin/convertjme.pl?$id"); |
if ($options =~ /border/) { $result.= '\fbox{'; } |
if ($options =~ /border/) { $result.= '\fbox{'; } |
$result .= '\graphicspath{{/home/httpd/perl/tmp/}}\includegraphics[width='.$texwidth.' mm]{'.$filename.'.eps}'; |
$result .= '\graphicspath{{/home/httpd/perl/tmp/}}\includegraphics[width='.$texwidth.' mm]{'.$filename.'.eps}'; |
Line 401 sub end_organicstructure {
|
Line 433 sub end_organicstructure {
|
|
|
sub edit_reaction_button { |
sub edit_reaction_button { |
my ($id,$field,$reaction)=@_; |
my ($id,$field,$reaction)=@_; |
my $id_es=&Apache::lonnet::escape($id); |
my $id_es=&escape($id); |
my $field_es=&Apache::lonnet::escape($field); |
my $field_es=&escape($field); |
my $reaction_es=&Apache::lonnet::escape($reaction); |
my $reaction_es=&escape($reaction); |
my $docopen=&Apache::lonhtmlcommon::javascript_docopen(); |
my $docopen=&Apache::lonhtmlcommon::javascript_docopen(); |
my $start_page = |
my $start_page = |
&Apache::loncommon::start_page('LON-CAPA Reaction Editor',undef, |
&Apache::loncommon::start_page('LON-CAPA Reaction Editor',undef, |
{'frameset' => 1, |
{'frameset' => 1, |
'js_ready' => 1, |
'js_ready' => 1, |
'add_entries' => { |
'add_entries' => { |
'rows' => "30%", |
'rows' => "30%,*", |
'border' => "0",}},); |
'border' => "0",}},); |
my $end_page = |
my $end_page = |
&Apache::loncommon::end_page({'frameset' => 1, |
&Apache::loncommon::end_page({'frameset' => 1, |
Line 422 sub edit_reaction_button {
|
Line 454 sub edit_reaction_button {
|
editor=window.open('','','width=500,height=270,scrollbars=no,resizable=yes'); |
editor=window.open('','','width=500,height=270,scrollbars=no,resizable=yes'); |
editor.$docopen; |
editor.$docopen; |
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'); |
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'); |
|
editor.document.close(); |
} |
} |
// --> |
// --> |
</script> |
</script> |
Line 451 sub start_reactionresponse {
|
Line 484 sub start_reactionresponse {
|
&Apache::lonxml::default_homework_load($safeeval); |
&Apache::lonxml::default_homework_load($safeeval); |
} |
} |
@Apache::scripttag::parser_env = @_; |
@Apache::scripttag::parser_env = @_; |
$Apache::inputtags::answertxt{$id}=&Apache::run::run("return &chemparse(q\0$ans\0);",$safeeval); |
$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 526 sub end_reactionresponse {
|
Line 559 sub end_reactionresponse {
|
} |
} |
$result.=&Apache::response::answer_footer('reactionresponse'); |
$result.=&Apache::response::answer_footer('reactionresponse'); |
} |
} |
|
if ($target eq 'web') { |
|
&Apache::response::setup_prior_tries_hash(\&format_prior_response_reaction); |
|
} |
|
|
if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || |
if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || |
$target eq 'tex' || $target eq 'analyze') { |
$target eq 'tex' || $target eq 'analyze') { |
&Apache::lonxml::increment_counter(&Apache::response::repetition()); |
&Apache::lonxml::increment_counter(&Apache::response::repetition(), "$partid.$id"); |
} |
} |
&Apache::response::end_response(); |
&Apache::response::end_response(); |
return $result; |
return $result; |
} |
} |
|
|
|
sub format_prior_response_reaction { |
|
my ($mode,$answer) =@_; |
|
return '<span class="LC_prior_reaction">'. |
|
&HTML::Entities::encode($answer,'"<>&').'</span>'; |
|
} |
|
|
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 = ''; |