Diff for /loncom/homework/chemresponse.pm between versions 1.31 and 1.34

version 1.31, 2004/03/12 18:41:43 version 1.34, 2004/06/07 21:56:24
Line 35  BEGIN { Line 35  BEGIN {
     &Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse'));      &Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse'));
 }  }
   
   sub chem_standard_order {
       my ($reaction) = @_;
       my ($re,$pr) = split(/->|<=>/,$reaction);
       my @reactants = split(/\s\+/,$re);
       my @products =  split(/\s\+/,$pr);
       foreach my $substance (@reactants,@products) {
    $substance =~ s/(\^\d*)\s+/$1_/g;         # protect superscript space
    $substance =~ s/\s*//g;                   # strip whitespace
    $substance =~ s/_/ /g;                    # restore superscript space
       }
       @reactants = sort @reactants;
       @products = sort @products;
       my $standard = '';
       foreach my $substance (@reactants) {
    $standard .= $substance;
    $standard .= ' + ';
       }
       $standard =~ s/ \+ $//;              # get rid of trailing plus sign
       $standard .= ' -> ';
       foreach my $substance (@products) {
    $standard .= $substance;
    $standard .= ' + ';
       }
       $standard =~ s/ \+ $//;              # get rid of trailing plus sign
       return $standard;
   }
   
 sub separate_jme_window {  sub separate_jme_window {
     my ($smile_input,$jme_input,$molecule,$options)=@_;      my ($smile_input,$jme_input,$molecule,$options)=@_;
     my $smilesection;      my $smilesection;
Line 92  $molecule Line 119  $molecule
 </body>  </body>
 </html>  </html>
 CHEMPAGE  CHEMPAGE
     $body=&HTML::Entities::encode($body);      $body=&HTML::Entities::encode($body,'<>&"');
     $body=~s/\n/ /g;      $body=~s/\n/ /g;
     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.document.open('text/html','replace');editor.document.writeln('$body')" />  <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')" />
Line 304  sub start_reactionresponse { Line 331  sub start_reactionresponse {
  my $partid = $Apache::inputtags::part;   my $partid = $Apache::inputtags::part;
  my $id = $Apache::inputtags::response['-1'];   my $id = $Apache::inputtags::response['-1'];
  my $reaction=$Apache::lonhomework::history{"resource.$partid.$id.submission"};   my $reaction=$Apache::lonhomework::history{"resource.$partid.$id.submission"};
  $result.=&edit_reaction_button($id,"HWVAL_$id",$reaction);   my $status=$Apache::inputtags::status['-1'];
    if ($status eq 'CAN_ANSWER') {
       $result.=&edit_reaction_button($id,"HWVAL_$id",$reaction);
    }
    if (  &Apache::response::show_answer() ) {
       my $ans=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
       $ans=~s/(\\|\')/\\$1/g;
       $Apache::inputtags::answertxt{$id}=&Apache::run::run("return &chemparse('$ans');",$safeeval);
    }
     } elsif ($target eq "edit") {      } elsif ($target eq "edit") {
  $result .=&Apache::edit::tag_start($target,$token);   $result .=&Apache::edit::tag_start($target,$token);
  my $answer=&Apache::lonxml::get_param('answer',$parstack,   my $answer=&Apache::lonxml::get_param('answer',$parstack,
Line 337  sub end_reactionresponse { Line 372  sub end_reactionresponse {
     my $ad;      my $ad;
     foreach my $answer (@answers) {      foreach my $answer (@answers) {
  &Apache::lonxml::debug("submitted a $response for $answer<br \>\n");   &Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
  if ($response eq $answer) {   if (&chem_standard_order($response) eq 
       &chem_standard_order($answer)) {
     $ad='EXACT_ANS';      $ad='EXACT_ANS';
  } else {   } else {
     $ad='INCORRECT';      $ad='INCORRECT';

Removed from v.1.31  
changed lines
  Added in v.1.34


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