File:
[LON-CAPA] /
loncom /
homework /
response.pm
Revision
1.45:
download - view:
text,
annotated -
select for diffs
Mon Aug 20 23:31:07 2001 UTC (23 years ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- cstore/restore/rndseed check the environmetn to see if we are rendering
for a different user or not (allowed calls need to be converted too)
- <dataresponse> displays some information about itself for target web
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','dataresponse'));
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 view_or_modify {
213: my ($symb,$courseid,$domain,$name) = &Apache::lonhomework::which_user();
214: my $myself=0;
215: if ( ($user eq $ENV{'user.name'}) && ($domain eq $ENV{'user.domain'}) ) {
216: $myself=1;
217: }
218: my $vgr=&Apache::lonnet::allowed('vgr',$courseid);
219: my $mgr=&Apache::lonnet::allowed('vgr',$courseid);
220: if ($mgr) { return "M"; }
221: if ($vgr) { return "V"; }
222: if ($myself) { return "V"; }
223: return '';
224: }
225:
226: sub start_dataresponse {
227: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
228: my $id = &Apache::response::start_response($parstack,$safeeval);
229: my $result;
230: if ($target eq 'web') {
231: $result = $token->[2]->{'display'}.':';
232: } elsif ($target eq 'meta') {
233: $result = &Apache::response::meta_stores_write($token->[2]->{'name'},
234: $token->[2]->{'type'},
235: $token->[2]->{'display'});
236: $result .= &Apache::response::meta_package_write('dataresponse');
237: }
238: return $result;
239: }
240:
241: sub end_dataresponse {
242: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
243: my $result;
244: if ( $target eq 'web' ) {
245: } elsif ($target eq 'grade' ) {
246: if ( defined $ENV{'form.submitted'}) {
247: my ($symb,$courseid,$domain,$name)=&Apache::lonhomework::which_user();
248: my $allowed=&Apache::lonnet::allowed('mgr',$courseid);
249: if ($allowed) {
250: &Apache::response::setup_params('datasubmission');
251: my $partid = $Apache::inputtags::part;
252: my $id = $Apache::inputtags::response['-1'];
253: my $response = $ENV{'form.HWVAL'.$id};
254: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
255: if ( $response =~ /[^\s]/) {
256: $Apache::lonhomework::results{"resource.$partid.$id.$name"}=
257: $response;
258: $Apache::lonhomework::results{
259: "resource.$partid.$id.submission"}=
260: $response;
261: $Apache::lonhomework::results{
262: "resource.$partid.$id.awarddetail"}=
263: 'SUBMITTED';
264: }
265: } else {
266: $result='Not Permitted to change values.'
267: }
268: }
269: }
270: &Apache::response::end_response;
271: return $result;
272: }
273:
274: sub start_responseparam {
275: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
276: my $result='';
277: if ($target eq 'meta') {
278: $result = &meta_parameter_write($token->[2]->{'name'},
279: $token->[2]->{'type'},
280: $token->[2]->{'default'},
281: $token->[2]->{'description'});
282: } elsif ($target eq 'edit') {
283: $result.=&Apache::edit::tag_start($target,$token,
284: &Apache::lonxml::description($token));
285: $result.=&Apache::edit::text_arg('Name:','name',$token).
286: &Apache::edit::text_arg('Type:','type',$token).
287: &Apache::edit::text_arg('Description:','description',$token).
288: &Apache::edit::text_arg('Default:','default',$token).
289: "</td></tr>";
290: $result.=&Apache::edit::end_table;
291: } elsif ($target eq 'modified') {
292: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
293: 'name','type','description',
294: 'default');
295: if ($constructtag) {
296: $result = &Apache::edit::rebuild_tag($token);
297: $result.=&Apache::edit::handle_insert();
298: }
299: }
300: return $result;
301: }
302:
303: sub end_responseparam {
304: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
305: if ($target eq 'edit') { return ('','no'); }
306: return '';
307: }
308:
309: sub setup_params {
310: my ($tag) = @_;
311:
312: @Apache::inputtags::params=();
313: my %paramlist=();
314: foreach my $key (keys(%Apache::lonnet::packagetab)) {
315: if ($key =~ /^$tag/) {
316: my ($package,$name) = split(/&/,$key);
317: $paramlist{$name}=1;
318: }
319: }
320: foreach my $key (keys(%paramlist)) {
321: my $entry= 'resource.'.$Apache::inputtags::part;
322: if (defined($Apache::inputtags::response[-1])) {
323: $entry.='_'.$Apache::inputtags::response[-1];
324: }
325: $entry.='.'.$key;
326: &Apache::lonxml::debug("looking for $entry");
327: my $value = &Apache::lonnet::EXT("$entry");
328: &Apache::lonxml::debug("$key has value :$value:");
329: if ($value eq 'con_lost' || $value =~ /^error:/) {
330: &Apache::lonxml::debug("using nothing");
331: $Apache::inputtags::params{$key}='';
332: } else {
333: &Apache::lonxml::debug("using value");
334: $Apache::inputtags::params{$key}=$value;
335: }
336: }
337: }
338:
339: 1;
340: __END__
341:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>