File:  [LON-CAPA] / loncom / homework / inputtags.pm
Revision 1.24: download - view: text, annotated - select for diffs
Wed Jan 10 22:18:11 2001 UTC (23 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
- typo

    1: # The LearningOnline Network with CAPA
    2: # input  definitons
    3: 
    4: package Apache::inputtags;
    5: use strict;
    6: 
    7: sub BEGIN {
    8:   &Apache::lonxml::register('Apache::inputtags',('textarea','textline','datasubmission'));
    9: }
   10: 
   11: 
   12: sub initialize_inputtags {
   13:   @Apache::inputtags::input=();
   14:   @Apache::inputtags::inputlist=();
   15:   @Apache::inputtags::response=();
   16:   @Apache::inputtags::responselist=();
   17:   @Apache::inputtags::answergroup=();
   18:   $Apache::inputtags::part='';
   19:   @Apache::inputtags::status=();
   20:   %Apache::inputtags::params=();
   21: }
   22: 
   23: sub start_input {
   24:   my ($parstack,$safeeval)=@_;
   25:   my $args ='';
   26:   if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   27:   my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
   28:   push (@Apache::inputtags::input,$id);
   29:   push (@Apache::inputtags::inputlist,$id);
   30:   return $id;
   31: }
   32: 
   33: sub end_input {
   34:   pop @Apache::inputtags::input;
   35:   return '';
   36: }
   37: 
   38: sub start_textarea {
   39:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   40:   my $result = "";
   41:   my $id = &start_input($parstack,$safeeval);
   42:   if ($target eq 'web') {
   43:     $result= '<textarea name="HWVAL'.$id.'" value="">';
   44:   }
   45:   return $result;
   46: }
   47: 
   48: sub end_textarea {
   49:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   50:   if ($target eq 'web') {
   51:     return "</textarea>";
   52:   } 
   53:   &end_input;
   54:   return '';
   55: }
   56: 
   57: sub start_textline {
   58:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   59:   my $result = "";
   60:   if ($target eq 'web') {
   61:     my $args ='';
   62:     if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   63:     my $size = &Apache::run::run("{$args;".'return $size}',$safeeval);
   64:     if ($size eq '') { $size=20; }
   65:     my $oldresponse = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].submission"};
   66:     $result= '<input type="text" name="HWVAL'.$Apache::inputtags::response['-1'].'" value="'.$oldresponse.'" size="'.$size.'">';
   67:   }
   68:   return $result;
   69: }
   70: 
   71: sub end_textline {
   72:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   73:   return "";
   74: }
   75: 
   76: #answergroup is deprecated
   77: #sub start_answergroup {
   78: #  my ($target,$token,$parstack,$parser,$safeeval)=@_;
   79: #  my $args ='';
   80: #  if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   81: #  my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
   82: #  push (@Apache::inputtags::answergroup,$id);
   83: #  if ($target == 'web') {
   84: #    
   85: #  }
   86: #  return '';
   87: #}
   88: #
   89: #sub end_answergroup {
   90: #  my ($target,$token,$parstack,$parser,$safeeval)=@_;
   91: #  return ''; # <answergroup> has ben deprecated
   92: #  my $args ='';
   93: #  if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   94: #  my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
   95: #  push (@Apache::inputtags::answergroup,$id);
   96: #  my $result='';
   97: #  my $button='<input type="submit" name="submit" value="Submit All Answers">';
   98: #  my $showbutton='1';
   99: #  my $usedtry='1';
  100: #  my $response='';
  101: #  if ( $target == 'web' ) {
  102: #    if ( defined $ENV{'form.submit'}) {
  103: #    }
  104: #    if ($showbutton > 0) { $result.=$button }
  105: #  }
  106: #  pop @Apache::inputtags::answergroup;
  107: #  return $result;
  108: #}
  109: 
  110: 
  111: sub start_datasubmission {
  112: }
  113: 
  114: sub end_datasubmission {
  115:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
  116:   if ( $target == 'web' ) {
  117:     return '<input type="submit" name="submit" value="Submit All Data">';
  118:   }
  119:   return '';
  120: }
  121: 
  122: sub finalizeawards {
  123:   my $result='';
  124:   my $award;
  125:   if ($#_ == '-1') { $result = "NO_RESPONSE"; }
  126:   if ($result eq '' ) {
  127:     foreach $award (@_) { if ($award eq '') {$result='MISSING_ANSWER'; last;}}
  128:   }
  129:   if ($result eq '' ) {
  130:     foreach $award (@_) { if ($award eq 'ERROR') {$result='ERROR'; last;}}
  131:   }
  132: 
  133:   if ($result eq '' ) {
  134:     foreach $award (@_) { 
  135:       if ($award eq 'UNIT_FAIL' ||
  136: 	  $award eq 'NO_UNIT' ||
  137: 	  $award eq 'UNIT_NOTNEEDED') {
  138: 	$result=$award; last;
  139:       }
  140:     }
  141:   }
  142:   if ($result eq '' ) {
  143:     foreach $award (@_) { 
  144:       if ($award eq 'WANTED_NUMERIC' || 
  145: 	  $award eq 'BAD_FORMULA') {$result=$award; last;}
  146:     }
  147:   }
  148:   if ($result eq '' ) {
  149:     foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
  150:   }
  151:   if ($result eq '' ) {
  152:     foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
  153:   }
  154:   if ($result eq '' ) {
  155:     foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
  156:   }
  157:   if ($result eq '' ) { $result='EXACT_ANS'; }
  158:   return $result
  159: }
  160: 
  161: sub decideoutput {
  162:   my ($award)=@_;
  163:   my $message='';
  164:   my $button=0;
  165:   if      ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
  166:     $message = "<b>You are correct.</b> Your receipt is ".&Apache::lonnet::receipt;
  167:     $button=0;
  168:   } elsif ($award eq 'NO_RESPONSE') {
  169:     $message = '';
  170:     $button=1;
  171:   } elsif ($award eq 'MISSING_ANSWER') {
  172:     $message = 'Some parts were not submitted';
  173:     $button = 1;
  174:   } elsif ($award eq 'WANTED_NUMERIC') {
  175:     $message = "This question expects a numeric answer";
  176:     $button=1;
  177:   } elsif ($award eq 'SIG_FAIL') {
  178:     $message = "Please adjust significant figures.";# you provided %s significant figures";
  179:     $button=1;
  180:   } elsif ($award eq 'UNIT_FAIL') {
  181:     $message = "Units incorrect."; #Computer reads units as %s";
  182:     $button=1;
  183:   } elsif ($award eq 'UNIT_NOTNEEDED') {
  184:     $message = "Only a number required.";# Computer reads units of %s";
  185:     $button=1;
  186:   } elsif ($award eq 'NO_UNIT') {
  187:     $message = "Units required";
  188:     $button=1;
  189:   } elsif ($award eq 'BAD_FORMULA') {
  190:     $message = "Unable to understand formula";
  191:     $button=1;
  192:   } elsif ($award eq 'INCORRECT') {
  193:     $message = "Incorrect";
  194:     $button=1;
  195:   } else {
  196:     $message = "Unknown message: $award";
  197:     $button=1;
  198:   }
  199:   return ($button,$message);
  200: }
  201: 
  202: sub setgradedata {
  203:   my ($award,$id) = @_;
  204:   if ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
  205:     $Apache::lonhomework::results{"resource.$id.tries"} =
  206:       $Apache::lonhomework::history{"resource.$id.tries"} + 1;
  207:     $Apache::lonhomework::results{"resource.$id.solved"} =
  208:       'correct_by_student';
  209:     $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
  210:   } elsif ( $award eq 'INCORRECT' ) {
  211:     $Apache::lonhomework::results{"resource.$id.tries"} =
  212:       $Apache::lonhomework::history{"resource.$id.tries"} + 1;
  213:     $Apache::lonhomework::results{"resource.$id.solved"} =
  214:       'incorrect_attempted';
  215:   } else {
  216:     $Apache::lonhomework::results{"resource.$id.solved"} =
  217:       'incorrect_attempted';
  218:   }
  219:   $Apache::lonhomework::results{"resource.$id.award"} = $award;
  220: }
  221: 
  222: sub grade {
  223:   my ($target) = @_;
  224:   my $id = $Apache::inputtags::part;
  225: #  my $result='';
  226:   my $response='';
  227:   if ( $target == 'web' ) {
  228:     if ( defined $ENV{'form.submit'}) {
  229:       my @awards = ();
  230:       &Apache::lonxml::debug("$#Apache::inputtags::responselist");
  231:       foreach $response (@Apache::inputtags::responselist) {
  232: 	&Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
  233: 	my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
  234: 	if ( $value ne '' ) {
  235: 	  &Apache::lonxml::debug("keep ing $value from $response for $id");
  236: 	  push (@awards,$value);
  237: 	} else {
  238: 	  &Apache::lonxml::debug("skipping $value from $response for $id");
  239: 	}
  240:       }
  241:       my $finalaward = &finalizeawards(@awards);
  242:       &Apache::lonxml::debug("final award $finalaward");
  243:       &setgradedata($finalaward,$id);
  244:     }
  245:   }
  246:   return '';
  247: }
  248: 
  249: sub gradestatus {
  250:   my ($id) = @_;
  251:   my $showbutton = 1;
  252:   my $message = '';
  253:   my $trystr='';
  254:   my $button='';
  255:   
  256:   my $status = $Apache::inputtags::status['-1'];
  257:   &Apache::lonxml::debug("gradestatus has :$status:");
  258:   if ( $status ne 'CLOSED' ) {  
  259:     my $award = $Apache::lonhomework::history{"resource.$id.award"};
  260:     &Apache::lonxml::debug("Found Award |$award|");
  261:     if ( $award ne '' ) {
  262:       &Apache::lonxml::debug('Getting message');
  263:       ($showbutton,$message) = &decideoutput($award);
  264:     }
  265:     my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
  266:     my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
  267:     &Apache::lonxml::debug("got maxtries of :$maxtries:");
  268:     if ( $tries eq '' ) { $tries = '0'; }
  269:     if ( $maxtries eq '' ) { $maxtries = '2'; } 
  270:     if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } 
  271:     if ( $showbutton ) {
  272:       $trystr = "<br></br>Tries $tries/$maxtries";
  273:     }
  274:     if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
  275:     if ( $showbutton ) { 
  276:       $button = '<br></br><input type="submit" name="submit" value="Submit All Answers"><br></br>';
  277:     }
  278:   }
  279:   return $button.$message.$trystr;
  280: }
  281: 1;
  282: __END__
  283:  

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