1: # The LearningOnline Network with CAPA
2: # various response type definitons response definition
3:
4: # 11/23,11/24,11/28 Gerd Kortemeyer
5: # Guy Albertelli
6: # 08/04,08/07 Gerd Kortemeyer
7:
8: package Apache::response;
9: use strict;
10:
11: sub BEGIN {
12: &Apache::lonxml::register('Apache::response',('responseparam','caparesponse','numericalresponse','stringresponse','radiobuttonresponse','optionresponse','imageresponse','essayresponse'));
13: }
14:
15: sub start_response {
16: my ($parstack,$safeeval)=@_;
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;
23: }
24:
25: sub end_response {
26: pop @Apache::inputtags::response;
27: @Apache::inputtags::inputlist=();
28: return '';
29: }
30:
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:
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
46: sub setrandomnumber {
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 '';
59: }
60:
61: sub meta_parameter_write {
62: my ($name,$type,$default,$display)=@_;
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;
76: }
77:
78: sub meta_package_write {
79: my $name=shift;
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;
86: }
87:
88: sub meta_stores_write {
89: my ($name,$type,$display)=@_;
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";
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: #
109: return
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').
120: &meta_package_write('part').
121: &meta_stores_write('solved','string',
122: 'Problem Status').
123: &meta_stores_write('tries','int_zeropos',
124: 'Number of Attempts').
125: &meta_stores_write('awarded','float',
126: 'Partial Credit Factor');
127: #
128: # Note: responseid-specific data 'submission' and 'awarddetail'
129: # not available to spreadsheet -> skip here
130: #
131: }
132:
133: sub check_for_previous {
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';
151: }
152: if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN'; }
153: &Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:");
154: last;
155: }
156: }
157: }
158: return %previous;
159: }
160:
161: sub start_caparesponse {
162: require Apache::caparesponse;
163: import Apache::caparesponse;
164: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
165: # print "\n<br />\nsimple caparesponse\n";
166: return &Apache::caparesponse::start_caparesponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
167: }
168:
169: sub start_stringresponse {
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);
174: }
175:
176: sub start_numericalresponse {
177: require Apache::caparesponse;
178: import Apache::caparesponse;
179: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
180: return &Apache::caparesponse::start_numericalresponse
181: ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
182: }
183:
184: sub start_radiobuttonresponse {
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);
189: }
190:
191: sub start_optionresponse {
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);
196: }
197:
198: sub start_imageresponse {
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);
203: }
204:
205: sub start_essayresponse {
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);
210: }
211:
212: sub start_responseparam {
213: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
214: if ($target eq 'grade' || $target eq 'web') {
215: my $default= &Apache::lonxml::get_param('default',$parstack,$safeeval);
216: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
217: my $entry= 'resource.'.$Apache::inputtags::part;
218: if (defined($Apache::inputtags::response[-1])) {
219: $entry.='_'.$Apache::inputtags::response[-1];
220: }
221: $entry.='.'.$name;
222: &Apache::lonxml::debug("looking for $entry");
223: my $value = &Apache::lonnet::EXT("$entry");
224: &Apache::lonxml::debug("$name has value :$value: and default :$default:");
225: if ($value eq '' || $value eq 'con_lost' || $value =~ /^error:/) {
226: &Apache::lonxml::debug("defaulting");
227: $Apache::inputtags::params{$name}=$default;
228: } else {
229: &Apache::lonxml::debug("using value");
230: $Apache::inputtags::params{$name}=$value;
231: }
232: return '';
233: } elsif ($target eq 'meta') {
234: return &meta_parameter_write($token->[2]->{'name'},
235: $token->[2]->{'type'},
236: $token->[2]->{'default'},
237: $token->[2]->{'description'});
238: } elsif ($target eq 'edit') {
239: my $result.=&Apache::edit::tag_start($target,$token,&Apache::lonxml::description($token));
240: $result.=&Apache::edit::text_arg('Name:','name',$token).
241: &Apache::edit::text_arg('Type:','type',$token).
242: &Apache::edit::text_arg('Description:','description',$token).
243: &Apache::edit::text_arg('Default:','default',$token).
244: "</td></tr>";
245: $result.=&Apache::edit::end_table;
246: return $result;
247: } elsif ($target eq 'modified') {
248: my $result;
249: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
250: 'name','type','description',
251: 'default');
252: if ($constructtag) {
253: $result = &Apache::edit::rebuild_tag($token);
254: $result.=&Apache::edit::handle_insert();
255: }
256: return $result;
257:
258: } else {
259: return '';
260: }
261: }
262:
263: sub end_responseparam {
264: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
265: if ($target eq 'edit') { return ('','no'); }
266: return '';
267: }
268:
269: 1;
270: __END__
271:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>