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