Annotation of loncom/homework/response.pm, revision 1.44

1.38      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # various response type definitons response definition
1.38      albertel    3: 
1.7       www         4: # 11/23,11/24,11/28 Gerd Kortemeyer
1.38      albertel    5: # Guy Albertelli
1.39      www         6: # 08/04,08/07 Gerd Kortemeyer
1.5       www         7: 
1.1       albertel    8: package Apache::response;
                      9: use strict;
                     10: 
                     11: sub BEGIN {
1.44    ! albertel   12:   &Apache::lonxml::register('Apache::response',('responseparam','caparesponse','numericalresponse','stringresponse','radiobuttonresponse','optionresponse','imageresponse','essayresponse','dataresponse'));
1.1       albertel   13: }
                     14: 
1.13      albertel   15: sub start_response {
1.41      albertel   16:   my ($parstack,$safeeval)=@_;
1.38      albertel   17:   my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
                     18:   if ($id eq '') { $id = $Apache::lonxml::curdepth; }
                     19:   push (@Apache::inputtags::response,$id);
                     20:   push (@Apache::inputtags::responselist,$id);
                     21:   @Apache::inputtags::inputlist=();
                     22:   return $id;
1.13      albertel   23: }
                     24: 
                     25: sub end_response {
                     26:   pop @Apache::inputtags::response;
1.38      albertel   27:   @Apache::inputtags::inputlist=();
1.13      albertel   28:   return '';
                     29: }
                     30: 
1.41      albertel   31: sub start_hintresponse {
                     32:   my ($parstack,$safeeval)=@_;
                     33:   my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
                     34:   if ($id eq '') { $id = $Apache::lonxml::curdepth; }
                     35:   push (@Apache::inputtags::response,$id);
                     36:   return $id;
                     37: }
                     38: 
                     39: sub end_hintresponse {
                     40:   pop @Apache::inputtags::response;
                     41:   return '';
                     42: }
                     43: 
1.38      albertel   44: # used by response to set the non-safe space random number generator to something
                     45: # that is stable and unique based on the part number and response number
1.26      albertel   46: sub setrandomnumber {
1.38      albertel   47:   my $rndseed=&Apache::lonnet::rndseed();
                     48:   &Apache::lonxml::debug("randseed $rndseed");
                     49: #  $rndseed=unpack("%32i",$rndseed);
                     50:   $rndseed=$rndseed
                     51:     +(&Apache::lonnet::numval($Apache::inputtags::part) << 10);
                     52:   if (defined($Apache::inputtags::response['-1'])) {
                     53:     $rndseed=$rndseed
                     54:       +&Apache::lonnet::numval($Apache::inputtags::response['-1']);
                     55:   }
                     56:   srand($rndseed);
                     57:   &Apache::lonxml::debug("randseed $rndseed");
                     58:   return '';
1.26      albertel   59: }
                     60: 
1.7       www        61: sub meta_parameter_write {
1.38      albertel   62:     my ($name,$type,$default,$display)=@_;
1.41      albertel   63:     my $partref=$Apache::inputtags::part;
                     64:     my $result='<parameter part="'.$Apache::inputtags::part.'"';
                     65:     if (defined($Apache::inputtags::response[-1])) {
                     66:       $result.=            ' id="'.$Apache::inputtags::response[-1].'"';
                     67:       $partref.='_'.$Apache::inputtags::response[-1];
                     68:     }
                     69:     $result.=            ' name="'.$name.'"'.
                     70:                          ' type="'.$type.'"'.
                     71: ($default?' default="'.$default.'"':'').
                     72: ($display?' display="'.$display.' [Part: '.$partref.']"':'')
                     73:              .'></parameter>'
                     74:              ."\n";
                     75:     return $result;
1.33      www        76: }
                     77: 
                     78: sub meta_package_write {
                     79:     my $name=shift;
1.41      albertel   80:     my $result = '<parameter part="'.$Apache::inputtags::part.'"';
                     81:     if(defined($Apache::inputtags::response[-1])) {
                     82:       $result.=              ' id="'.$Apache::inputtags::response[-1].'"';
                     83:     }
                     84:     $result.=' package="'.$name.'"></parameter>'."\n";
                     85:     return $result;
1.7       www        86: }
                     87: 
                     88: sub meta_stores_write {
1.10      www        89:     my ($name,$type,$display)=@_;
1.41      albertel   90:     my $partref=$Apache::inputtags::part;
                     91:     my $result = '<stores part="'.$Apache::inputtags::part.'"';
                     92:     if (defined($Apache::inputtags::response[-1])) {
                     93:       $result.=           ' id="'.$Apache::inputtags::response[-1].'"';
                     94:       $partref.='_'.$Apache::inputtags::response[-1];
                     95:     }	
                     96:     $result.=          ' name="'.$name.'"'.
                     97:                        ' type="'.$type.'"'.
                     98: 	            ' display="'.$display.' [Part: '.$partref.']"'.
                     99: 		      "></stores>\n";
1.7       www       100: }
                    101: 
                    102: sub mandatory_part_meta {
                    103: #
                    104: # Autogenerate metadata for mandatory
                    105: # input (from RAT or lonparmset) and 
                    106: # output (to lonspreadsheet)
                    107: # of each part
                    108: #
1.38      albertel  109:  return
1.34      www       110: #    &meta_parameter_write('opendate','date_start','',
                    111: #                          'Opening Date').
                    112: #    &meta_parameter_write('duedate','date_end','',
                    113: #                          'Due Date').
                    114: #    &meta_parameter_write('answerdate','date_start','',
                    115: #                          'Show Answer Date').
                    116: #    &meta_parameter_write('weight','int_zeropos','',
                    117: #                          'Available Points').
                    118: #    &meta_parameter_write('maxtries','int_pos','',
                    119: #                          'Maximum Number of Tries').
1.39      www       120:     &meta_package_write('part').
1.10      www       121:     &meta_stores_write('solved','string',
1.7       www       122:                           'Problem Status').
1.38      albertel  123:     &meta_stores_write('tries','int_zeropos',
1.24      albertel  124:                           'Number of Attempts').
1.38      albertel  125:     &meta_stores_write('awarded','float',
1.7       www       126: 		          'Partial Credit Factor');
                    127: #
                    128: # Note: responseid-specific data 'submission' and 'awarddetail'
                    129: # not available to spreadsheet -> skip here
                    130: #
1.14      albertel  131: }
                    132: 
1.15      albertel  133: sub check_for_previous {
1.38      albertel  134:   my ($curresponse,$partid,$id) = @_;
                    135:   my %previous;
                    136:   $previous{'used'} = 0;
                    137:   foreach my $key (reverse(sort(keys(%Apache::lonhomework::history)))) {
                    138:     if ($key =~ /resource\.$partid\.$id\.submission/) {
                    139:       &Apache::lonxml::debug("Trying $key");
                    140:       my $pastresponse=$Apache::lonhomework::history{$key};
                    141:       if ($pastresponse eq $curresponse) {
                    142: 	$previous{'used'} = 1;
                    143: 	my $history;
                    144: 	if ( $key =~ /^(\d+):/ ) {
                    145: 	  $history=$1;
                    146: 	  $previous{'award'} = $Apache::lonhomework::history{"$history:resource.$partid.$id.awarddetail"};
                    147: 	  $previous{'last'}='0';
                    148: 	} else {
                    149: 	  $previous{'award'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"};
                    150: 	  $previous{'last'}='1';
1.32      albertel  151: 	}
1.38      albertel  152: 	if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN';	}
                    153: 	&Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:");
                    154: 	last;
                    155:       }
1.32      albertel  156:     }
1.38      albertel  157:   }
                    158:   return %previous;
1.15      albertel  159: }
                    160: 
1.31      albertel  161: sub start_caparesponse {
1.38      albertel  162:   require Apache::caparesponse; 
                    163:   import Apache::caparesponse; 
                    164:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31      albertel  165: #  print "\n<br />\nsimple caparesponse\n";
1.38      albertel  166:   return &Apache::caparesponse::start_caparesponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.31      albertel  167: }
                    168: 
                    169: sub start_stringresponse {
1.38      albertel  170:   require Apache::caparesponse;
                    171:   import Apache::caparesponse;
                    172:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    173:   return &Apache::caparesponse::start_stringresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.7       www       174: }
                    175: 
1.31      albertel  176: sub start_numericalresponse {
1.1       albertel  177:   require Apache::caparesponse; 
                    178:   import Apache::caparesponse; 
1.38      albertel  179:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.35      albertel  180:   return &Apache::caparesponse::start_numericalresponse
                    181:     ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.16      albertel  182: }
                    183: 
                    184: sub start_radiobuttonresponse {
1.38      albertel  185:   require Apache::radiobuttonresponse; 
                    186:   import Apache::radiobuttonresponse; 
                    187:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    188:   return &Apache::radiobuttonresponse::start_radiobuttonresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.19      albertel  189: }
                    190: 
                    191: sub start_optionresponse {
1.38      albertel  192:   require Apache::optionresponse; 
                    193:   import Apache::optionresponse; 
                    194:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    195:   return &Apache::optionresponse::start_optionresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.21      albertel  196: }
                    197: 
                    198: sub start_imageresponse {
1.38      albertel  199:   require Apache::imageresponse; 
                    200:   import Apache::imageresponse; 
                    201:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    202:   return &Apache::imageresponse::start_imageresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.23      albertel  203: }
                    204: 
                    205: sub start_essayresponse {
1.38      albertel  206:   require Apache::essayresponse; 
                    207:   import Apache::essayresponse; 
                    208:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    209:   return &Apache::essayresponse::start_essayresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.44    ! albertel  210: }
        !           211: 
        !           212: sub start_dataresponse {
        !           213:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
        !           214:   my $id = &Apache::response::start_response($parstack,$safeeval);
        !           215:   my $result;
        !           216:   if ($target eq 'meta') {
        !           217:     $result = &Apache::response::meta_stores_write($token->[2]->{'name'},
        !           218: 						   $token->[2]->{'type'},
        !           219: 						   $token->[2]->{'display'});
        !           220:     $result .= &Apache::response::meta_package_write('dataresponse');
        !           221:   }
        !           222:   return $result;
        !           223: }
        !           224: 
        !           225: sub end_dataresponse {
        !           226:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
        !           227:   my $result;
        !           228:   if ( $target eq 'web' ) {
        !           229:   } elsif ($target eq 'grade' ) {
        !           230:     if ( defined $ENV{'form.submitted'}) {
        !           231:       &Apache::response::setup_params('datasubmission');
        !           232:       my $partid = $Apache::inputtags::part;
        !           233:       my $id = $Apache::inputtags::response['-1'];
        !           234:       my $response = $ENV{'form.HWVAL'.$id};
        !           235:       my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
        !           236:       if ( $response =~ /[^\s]/) {
        !           237: 	$Apache::lonhomework::results{"resource.$partid.$id.$name"}=
        !           238: 	  $response;
        !           239: 	$Apache::lonhomework::results{"resource.$partid.$id.submission"}=
        !           240: 	  $response;
        !           241: 	$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=
        !           242: 	  'SUBMITTED';
        !           243:       }
        !           244:     }
        !           245:   }
        !           246:   &Apache::response::end_response;
        !           247:   return $result;
1.3       albertel  248: }
                    249: 
                    250: sub start_responseparam {
1.38      albertel  251:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.43      albertel  252:   my $result='';
1.42      albertel  253:   if ($target eq 'meta') {
                    254:     $result = &meta_parameter_write($token->[2]->{'name'},
                    255: 				    $token->[2]->{'type'},
                    256: 				    $token->[2]->{'default'},
                    257: 				    $token->[2]->{'description'});
1.38      albertel  258:   } elsif ($target eq 'edit') {
1.42      albertel  259:     $result.=&Apache::edit::tag_start($target,$token,
                    260: 				      &Apache::lonxml::description($token));
1.38      albertel  261:     $result.=&Apache::edit::text_arg('Name:','name',$token).
                    262:       &Apache::edit::text_arg('Type:','type',$token).
                    263: 	&Apache::edit::text_arg('Description:','description',$token).
                    264: 	  &Apache::edit::text_arg('Default:','default',$token).
                    265: 	    "</td></tr>";
                    266:     $result.=&Apache::edit::end_table;
                    267:   } elsif ($target eq 'modified') {
                    268:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
                    269: 						 'name','type','description',
                    270: 						 'default');
                    271:     if ($constructtag) {
                    272:       $result = &Apache::edit::rebuild_tag($token);
                    273:       $result.=&Apache::edit::handle_insert();
                    274:     }
                    275:   }
1.42      albertel  276:   return $result;
1.3       albertel  277: }
                    278: 
                    279: sub end_responseparam {
1.38      albertel  280:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    281:   if ($target eq 'edit') { return ('','no'); }
                    282:   return '';
1.42      albertel  283: }
                    284: 
                    285: sub setup_params {
                    286:   my ($tag) = @_;
                    287: 
                    288:   @Apache::inputtags::params=();
1.43      albertel  289:   my %paramlist=();
1.42      albertel  290:   foreach my $key (keys(%Apache::lonnet::packagetab)) {
                    291:     if ($key =~ /^$tag/) {
                    292:       my ($package,$name) = split(/&/,$key);
1.43      albertel  293:       $paramlist{$name}=1;
1.42      albertel  294:     }
                    295:   }
1.43      albertel  296:   foreach my $key (keys(%paramlist)) {
1.42      albertel  297:     my $entry= 'resource.'.$Apache::inputtags::part;
                    298:     if (defined($Apache::inputtags::response[-1])) {
                    299:       $entry.='_'.$Apache::inputtags::response[-1];
                    300:     }
                    301:     $entry.='.'.$key;
                    302:     &Apache::lonxml::debug("looking for $entry");
                    303:     my $value = &Apache::lonnet::EXT("$entry");
                    304:     &Apache::lonxml::debug("$key has value :$value:");
                    305:     if ($value eq 'con_lost' || $value =~ /^error:/) {
                    306:       &Apache::lonxml::debug("using nothing");
                    307:       $Apache::inputtags::params{$key}='';
                    308:     } else {
                    309:       &Apache::lonxml::debug("using value");
                    310:       $Apache::inputtags::params{$key}=$value;
                    311:     }
                    312:   }
1.1       albertel  313: }
1.2       albertel  314: 
1.1       albertel  315: 1;
                    316: __END__
1.38      albertel  317:  

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