Annotation of loncom/homework/inputtags.pm, revision 1.9

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # input  definitons
                      3: 
                      4: package Apache::inputtags;
                      5: use strict;
                      6: 
                      7: sub BEGIN {
1.6       albertel    8:   &Apache::lonxml::register('Apache::inputtags',('textarea','textline','answergroup','datasubmission'));
1.1       albertel    9: }
                     10: 
1.7       albertel   11: 
1.1       albertel   12: sub initialize_inputtags {
1.7       albertel   13:   @Apache::inputtags::input=();
                     14:   @Apache::inputtags::response=();
1.9     ! albertel   15:   @Apache::inputtags::responselist=();
1.7       albertel   16:   @Apache::inputtags::answergroup=();
1.8       albertel   17:   $Apache::inputtags::part='';
1.7       albertel   18:   %Apache::inputtags::params=();
1.1       albertel   19: }
                     20: 
1.6       albertel   21: sub start_textarea {
                     22:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
                     23:   my $result = "";
                     24:   $Apache::inputtags::curvalue++;
                     25:   if ($target eq 'web') {
1.7       albertel   26:     $result= '<textarea name="HWVAL'.$Apache::inputtags::curvalue.'" value="">';
1.6       albertel   27:   }
                     28:   return $result;
                     29: }
                     30: 
                     31: sub end_textarea {
                     32:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
                     33:   return "</textarea>";
                     34: }
                     35: 
1.1       albertel   36: sub start_textline {
                     37:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
                     38:   my $result = "";
                     39:   $Apache::inputtags::curvalue++;
1.6       albertel   40:   my $args ='';
                     41:   if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
                     42:   my $size = &Apache::run::run("{$args;".'return $size}',$safeeval);
                     43:   if ($size eq '') { $size=20; }
1.1       albertel   44:   if ($target eq 'web') {
1.7       albertel   45:     $result= '<input type="text" name="HWVAL'.$Apache::inputtags::curvalue.'" value="" size="'.$size.'">';
1.1       albertel   46:   }
                     47:   return $result;
                     48: }
                     49: 
                     50: sub end_textline {
                     51:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.6       albertel   52:   return "";
1.1       albertel   53: }
                     54: 
                     55: sub start_answergroup {
1.7       albertel   56:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
                     57:   my $args ='';
                     58:   if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
                     59:   my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
                     60:   push (@Apache::inputtags::answergroup,$id);
                     61:   if ($target == 'web') {
                     62:     
                     63:   }
                     64:   return '';
1.1       albertel   65: }
                     66: 
                     67: sub end_answergroup {
1.2       albertel   68:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.9     ! albertel   69:   return ''; # <answergroup> has ben deprecated
1.7       albertel   70:   my $args ='';
                     71:   if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
                     72:   my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
                     73:   push (@Apache::inputtags::answergroup,$id);
                     74:   my $result='';
                     75:   my $button='<input type="submit" name="submit" value="Submit All Answers">';
                     76:   my $showbutton='1';
                     77:   my $usedtry='1';
                     78:   my $response='';
1.2       albertel   79:   if ( $target == 'web' ) {
1.7       albertel   80:     if ( defined $ENV{'form.submit'}) {
                     81:     }
                     82:     if ($showbutton > 0) { $result.=$button }
1.6       albertel   83:   }
1.7       albertel   84:   pop @Apache::inputtags::answergroup;
                     85:   return $result;
1.6       albertel   86: }
                     87: 
                     88: 
                     89: sub start_datasubmission {
                     90: }
                     91: 
                     92: sub end_datasubmission {
                     93:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
                     94:   if ( $target == 'web' ) {
1.7       albertel   95:     return '<input type="submit" name="submit" value="Submit All Data">';
1.2       albertel   96:   }
1.9     ! albertel   97: }
        !            98: 
        !            99: sub finalizeawards {
        !           100:   my $result='';
        !           101:   my $award;
        !           102:   if ($#_ == '-1') { $result = "NO_RESPONSE"; }
        !           103:   foreach $award (@_) { if ($award eq '') {$result='MISSING_ANSWER'; last;}}
        !           104:   if ($result eq '' ) {
        !           105:     foreach $award (@_) { 
        !           106:       if ($award eq 'UNIT_FAIL' ||
        !           107: 	  $award eq 'NO_UNIT' ||
        !           108: 	  $award eq 'UNIT_NOTNEEDED') {
        !           109: 	$result=$award; last;
        !           110:       }
        !           111:     }
        !           112:   }
        !           113:   &Apache::lonxml::debug("1 $result");
        !           114:   if ($result eq '' ) {
        !           115:     foreach $award (@_) { 
        !           116:       if ($award eq 'WANTED_NUMERIC' || 
        !           117: 	  $award eq 'BAD_FORMULA') {$result=$award; last;}
        !           118:     }
        !           119:   }
        !           120:   &Apache::lonxml::debug("2 $result");
        !           121:   if ($result eq '' ) {
        !           122:     foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
        !           123:   }
        !           124:   &Apache::lonxml::debug("3 $result");
        !           125:   if ($result eq '' ) {
        !           126:     foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
        !           127:   }
        !           128:   &Apache::lonxml::debug("4 $result");
        !           129:   if ($result eq '' ) {
        !           130:     foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
        !           131:   }
        !           132:   &Apache::lonxml::debug("5 $result");
        !           133:   if ($result eq '' ) { $result='EXACT_ANS'; }
        !           134:   &Apache::lonxml::debug("6 $result");
        !           135:   return $result
        !           136: }
        !           137: 
        !           138: sub grade {
        !           139:   my ($target) = @_;
        !           140:   my $id = $Apache::inputtags::part;
        !           141:   my $result='';
        !           142:   my $button='<input type="submit" name="submit" value="Submit All Answers">';
        !           143:   my $showbutton='1';
        !           144:   my $usedtry='1';
        !           145:   my $response='';
        !           146:   if ( $target == 'web' ) {
        !           147:     if ( defined $ENV{'form.submit'}) {
        !           148:       my @awards = ();
        !           149:       foreach $response (@Apache::inputtags::responselist) {
        !           150: 	my $value=$Apache::lonhomework::results{"response.awarddetail.$id.$response"};
        !           151: 	if ( $value ne '' ) {
        !           152: 	  &Apache::lonxml::debug("keep ing $value from $response for $id");
        !           153: 	  push (@awards,$value);
        !           154: 	} else {
        !           155: 	  &Apache::lonxml::debug("skipping $value from $response for $id");
        !           156: 	}
        !           157:       }
        !           158:       my $finalaward = &finalizeawards(@awards);
        !           159:       &Apache::lonxml::debug("final award $finalaward");
        !           160:     }
        !           161:     if ($showbutton > 0) { $result.=$button }
        !           162:   }
        !           163:   return $result;
1.1       albertel  164: }
                    165: 
                    166: 1;
                    167: __END__
                    168:  

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