Annotation of loncom/homework/response.pm, revision 1.53
1.38 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # various response type definitons response definition
1.53 ! albertel 3: #
! 4: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www Exp $
! 5: #
! 6: # Copyright Michigan State University Board of Trustees
! 7: #
! 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 9: #
! 10: # LON-CAPA is free software; you can redistribute it and/or modify
! 11: # it under the terms of the GNU General Public License as published by
! 12: # the Free Software Foundation; either version 2 of the License, or
! 13: # (at your option) any later version.
! 14: #
! 15: # LON-CAPA is distributed in the hope that it will be useful,
! 16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 18: # GNU General Public License for more details.
! 19: #
! 20: # You should have received a copy of the GNU General Public License
! 21: # along with LON-CAPA; if not, write to the Free Software
! 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 23: #
! 24: # /home/httpd/html/adm/gpl.txt
! 25: #
! 26: # http://www.lon-capa.org/
! 27: #
1.7 www 28: # 11/23,11/24,11/28 Gerd Kortemeyer
1.38 albertel 29: # Guy Albertelli
1.39 www 30: # 08/04,08/07 Gerd Kortemeyer
1.5 www 31:
1.1 albertel 32: package Apache::response;
33: use strict;
34:
35: sub BEGIN {
1.49 albertel 36: &Apache::lonxml::register('Apache::response',('responseparam','caparesponse','numericalresponse','formularesponse','stringresponse','radiobuttonresponse','optionresponse','imageresponse','essayresponse','dataresponse'));
1.1 albertel 37: }
38:
1.13 albertel 39: sub start_response {
1.41 albertel 40: my ($parstack,$safeeval)=@_;
1.38 albertel 41: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
42: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
1.51 albertel 43: if ($#Apache::inputtags::import > -1) {
44: &Apache::lonxml::debug("Turning :$id: into");
45: $id = join('_',@Apache::inputtags::import).'_'.$id;
46: &Apache::lonxml::debug("New :$id:");
47: }
1.38 albertel 48: push (@Apache::inputtags::response,$id);
49: push (@Apache::inputtags::responselist,$id);
50: @Apache::inputtags::inputlist=();
51: return $id;
1.13 albertel 52: }
53:
54: sub end_response {
55: pop @Apache::inputtags::response;
1.38 albertel 56: @Apache::inputtags::inputlist=();
1.13 albertel 57: return '';
58: }
59:
1.41 albertel 60: sub start_hintresponse {
61: my ($parstack,$safeeval)=@_;
62: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
63: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
64: push (@Apache::inputtags::response,$id);
65: return $id;
66: }
67:
68: sub end_hintresponse {
69: pop @Apache::inputtags::response;
70: return '';
71: }
72:
1.38 albertel 73: # used by response to set the non-safe space random number generator to something
74: # that is stable and unique based on the part number and response number
1.26 albertel 75: sub setrandomnumber {
1.48 albertel 76: my $rndseed;
77: if ($ENV{'request.state'} eq "construct") {
78: $rndseed=$ENV{'form.rndseed'};
79: if (!$rndseed) { $rndseed=time; }
80: } else {
81: $rndseed=&Apache::lonnet::rndseed();
82: }
1.38 albertel 83: &Apache::lonxml::debug("randseed $rndseed");
84: # $rndseed=unpack("%32i",$rndseed);
85: $rndseed=$rndseed
86: +(&Apache::lonnet::numval($Apache::inputtags::part) << 10);
87: if (defined($Apache::inputtags::response['-1'])) {
88: $rndseed=$rndseed
89: +&Apache::lonnet::numval($Apache::inputtags::response['-1']);
90: }
91: srand($rndseed);
92: &Apache::lonxml::debug("randseed $rndseed");
93: return '';
1.26 albertel 94: }
95:
1.7 www 96: sub meta_parameter_write {
1.38 albertel 97: my ($name,$type,$default,$display)=@_;
1.41 albertel 98: my $partref=$Apache::inputtags::part;
99: my $result='<parameter part="'.$Apache::inputtags::part.'"';
100: if (defined($Apache::inputtags::response[-1])) {
101: $result.= ' id="'.$Apache::inputtags::response[-1].'"';
102: $partref.='_'.$Apache::inputtags::response[-1];
103: }
104: $result.= ' name="'.$name.'"'.
105: ' type="'.$type.'"'.
106: ($default?' default="'.$default.'"':'').
107: ($display?' display="'.$display.' [Part: '.$partref.']"':'')
108: .'></parameter>'
109: ."\n";
110: return $result;
1.33 www 111: }
112:
113: sub meta_package_write {
114: my $name=shift;
1.41 albertel 115: my $result = '<parameter part="'.$Apache::inputtags::part.'"';
116: if(defined($Apache::inputtags::response[-1])) {
117: $result.= ' id="'.$Apache::inputtags::response[-1].'"';
118: }
119: $result.=' package="'.$name.'"></parameter>'."\n";
120: return $result;
1.7 www 121: }
122:
123: sub meta_stores_write {
1.10 www 124: my ($name,$type,$display)=@_;
1.41 albertel 125: my $partref=$Apache::inputtags::part;
126: my $result = '<stores part="'.$Apache::inputtags::part.'"';
127: if (defined($Apache::inputtags::response[-1])) {
128: $result.= ' id="'.$Apache::inputtags::response[-1].'"';
129: $partref.='_'.$Apache::inputtags::response[-1];
130: }
131: $result.= ' name="'.$name.'"'.
132: ' type="'.$type.'"'.
133: ' display="'.$display.' [Part: '.$partref.']"'.
134: "></stores>\n";
1.7 www 135: }
136:
137: sub mandatory_part_meta {
138: #
139: # Autogenerate metadata for mandatory
140: # input (from RAT or lonparmset) and
141: # output (to lonspreadsheet)
142: # of each part
143: #
1.38 albertel 144: return
1.34 www 145: # &meta_parameter_write('opendate','date_start','',
146: # 'Opening Date').
147: # &meta_parameter_write('duedate','date_end','',
148: # 'Due Date').
149: # &meta_parameter_write('answerdate','date_start','',
150: # 'Show Answer Date').
151: # &meta_parameter_write('weight','int_zeropos','',
152: # 'Available Points').
153: # &meta_parameter_write('maxtries','int_pos','',
154: # 'Maximum Number of Tries').
1.39 www 155: &meta_package_write('part').
1.10 www 156: &meta_stores_write('solved','string',
1.7 www 157: 'Problem Status').
1.38 albertel 158: &meta_stores_write('tries','int_zeropos',
1.24 albertel 159: 'Number of Attempts').
1.38 albertel 160: &meta_stores_write('awarded','float',
1.7 www 161: 'Partial Credit Factor');
162: #
163: # Note: responseid-specific data 'submission' and 'awarddetail'
164: # not available to spreadsheet -> skip here
165: #
1.14 albertel 166: }
167:
1.15 albertel 168: sub check_for_previous {
1.38 albertel 169: my ($curresponse,$partid,$id) = @_;
170: my %previous;
171: $previous{'used'} = 0;
172: foreach my $key (reverse(sort(keys(%Apache::lonhomework::history)))) {
173: if ($key =~ /resource\.$partid\.$id\.submission/) {
174: &Apache::lonxml::debug("Trying $key");
175: my $pastresponse=$Apache::lonhomework::history{$key};
176: if ($pastresponse eq $curresponse) {
177: $previous{'used'} = 1;
178: my $history;
179: if ( $key =~ /^(\d+):/ ) {
180: $history=$1;
181: $previous{'award'} = $Apache::lonhomework::history{"$history:resource.$partid.$id.awarddetail"};
182: $previous{'last'}='0';
183: } else {
184: $previous{'award'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"};
185: $previous{'last'}='1';
1.32 albertel 186: }
1.38 albertel 187: if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN'; }
188: &Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:");
189: last;
190: }
1.32 albertel 191: }
1.38 albertel 192: }
193: return %previous;
1.15 albertel 194: }
195:
1.31 albertel 196: sub start_caparesponse {
1.38 albertel 197: require Apache::caparesponse;
198: import Apache::caparesponse;
199: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31 albertel 200: # print "\n<br />\nsimple caparesponse\n";
1.38 albertel 201: return &Apache::caparesponse::start_caparesponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.31 albertel 202: }
203:
204: sub start_stringresponse {
1.38 albertel 205: require Apache::caparesponse;
206: import Apache::caparesponse;
207: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
208: return &Apache::caparesponse::start_stringresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.7 www 209: }
210:
1.49 albertel 211: sub start_formularesponse {
212: require Apache::caparesponse;
213: import Apache::caparesponse;
214: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
215: return &Apache::caparesponse::start_formularesponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
216: }
217:
1.31 albertel 218: sub start_numericalresponse {
1.1 albertel 219: require Apache::caparesponse;
220: import Apache::caparesponse;
1.38 albertel 221: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.35 albertel 222: return &Apache::caparesponse::start_numericalresponse
223: ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.16 albertel 224: }
225:
226: sub start_radiobuttonresponse {
1.38 albertel 227: require Apache::radiobuttonresponse;
228: import Apache::radiobuttonresponse;
229: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
230: return &Apache::radiobuttonresponse::start_radiobuttonresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.19 albertel 231: }
232:
233: sub start_optionresponse {
1.38 albertel 234: require Apache::optionresponse;
235: import Apache::optionresponse;
236: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
237: return &Apache::optionresponse::start_optionresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.21 albertel 238: }
239:
240: sub start_imageresponse {
1.38 albertel 241: require Apache::imageresponse;
242: import Apache::imageresponse;
243: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
244: return &Apache::imageresponse::start_imageresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.23 albertel 245: }
246:
247: sub start_essayresponse {
1.38 albertel 248: require Apache::essayresponse;
249: import Apache::essayresponse;
250: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
251: return &Apache::essayresponse::start_essayresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.44 albertel 252: }
253:
1.45 albertel 254: sub view_or_modify {
1.47 albertel 255: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
1.45 albertel 256: my $myself=0;
1.46 albertel 257: if ( ($name eq $ENV{'user.name'}) && ($domain eq $ENV{'user.domain'}) ) {
1.45 albertel 258: $myself=1;
259: }
260: my $vgr=&Apache::lonnet::allowed('vgr',$courseid);
261: my $mgr=&Apache::lonnet::allowed('vgr',$courseid);
262: if ($mgr) { return "M"; }
263: if ($vgr) { return "V"; }
264: if ($myself) { return "V"; }
265: return '';
266: }
267:
1.44 albertel 268: sub start_dataresponse {
269: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
270: my $id = &Apache::response::start_response($parstack,$safeeval);
271: my $result;
1.45 albertel 272: if ($target eq 'web') {
273: $result = $token->[2]->{'display'}.':';
274: } elsif ($target eq 'meta') {
1.44 albertel 275: $result = &Apache::response::meta_stores_write($token->[2]->{'name'},
276: $token->[2]->{'type'},
277: $token->[2]->{'display'});
278: $result .= &Apache::response::meta_package_write('dataresponse');
279: }
280: return $result;
281: }
282:
283: sub end_dataresponse {
284: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
285: my $result;
286: if ( $target eq 'web' ) {
287: } elsif ($target eq 'grade' ) {
288: if ( defined $ENV{'form.submitted'}) {
1.47 albertel 289: my ($symb,$courseid,$domain,$name)=&Apache::lonxml::whichuser();
1.45 albertel 290: my $allowed=&Apache::lonnet::allowed('mgr',$courseid);
291: if ($allowed) {
292: &Apache::response::setup_params('datasubmission');
293: my $partid = $Apache::inputtags::part;
294: my $id = $Apache::inputtags::response['-1'];
295: my $response = $ENV{'form.HWVAL'.$id};
296: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
297: if ( $response =~ /[^\s]/) {
298: $Apache::lonhomework::results{"resource.$partid.$id.$name"}=
299: $response;
300: $Apache::lonhomework::results{
301: "resource.$partid.$id.submission"}=
302: $response;
303: $Apache::lonhomework::results{
304: "resource.$partid.$id.awarddetail"}=
305: 'SUBMITTED';
306: }
307: } else {
308: $result='Not Permitted to change values.'
1.44 albertel 309: }
310: }
311: }
312: &Apache::response::end_response;
313: return $result;
1.3 albertel 314: }
315:
316: sub start_responseparam {
1.38 albertel 317: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.43 albertel 318: my $result='';
1.42 albertel 319: if ($target eq 'meta') {
320: $result = &meta_parameter_write($token->[2]->{'name'},
321: $token->[2]->{'type'},
322: $token->[2]->{'default'},
323: $token->[2]->{'description'});
1.38 albertel 324: } elsif ($target eq 'edit') {
1.42 albertel 325: $result.=&Apache::edit::tag_start($target,$token,
326: &Apache::lonxml::description($token));
1.38 albertel 327: $result.=&Apache::edit::text_arg('Name:','name',$token).
328: &Apache::edit::text_arg('Type:','type',$token).
329: &Apache::edit::text_arg('Description:','description',$token).
330: &Apache::edit::text_arg('Default:','default',$token).
331: "</td></tr>";
332: $result.=&Apache::edit::end_table;
333: } elsif ($target eq 'modified') {
334: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
335: 'name','type','description',
336: 'default');
337: if ($constructtag) {
338: $result = &Apache::edit::rebuild_tag($token);
339: $result.=&Apache::edit::handle_insert();
340: }
1.52 albertel 341: } elsif ($target eq 'grade') {
342: if ($ENV{'request.state'} eq 'construct') {
343: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
344: my $default = &Apache::lonxml::get_param('default',$parstack,$safeeval);
345: $Apache::inputtags::params{$name}=$default;
346: }
1.38 albertel 347: }
1.42 albertel 348: return $result;
1.3 albertel 349: }
350:
351: sub end_responseparam {
1.38 albertel 352: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
353: if ($target eq 'edit') { return ('','no'); }
354: return '';
1.42 albertel 355: }
356:
357: sub setup_params {
358: my ($tag) = @_;
359:
1.52 albertel 360: if ($ENV{'request.state'} eq 'construct') { return; }
1.42 albertel 361: @Apache::inputtags::params=();
1.43 albertel 362: my %paramlist=();
1.42 albertel 363: foreach my $key (keys(%Apache::lonnet::packagetab)) {
364: if ($key =~ /^$tag/) {
365: my ($package,$name) = split(/&/,$key);
1.43 albertel 366: $paramlist{$name}=1;
1.42 albertel 367: }
368: }
1.43 albertel 369: foreach my $key (keys(%paramlist)) {
1.42 albertel 370: my $entry= 'resource.'.$Apache::inputtags::part;
371: if (defined($Apache::inputtags::response[-1])) {
372: $entry.='_'.$Apache::inputtags::response[-1];
373: }
374: $entry.='.'.$key;
375: &Apache::lonxml::debug("looking for $entry");
376: my $value = &Apache::lonnet::EXT("$entry");
377: &Apache::lonxml::debug("$key has value :$value:");
378: if ($value eq 'con_lost' || $value =~ /^error:/) {
379: &Apache::lonxml::debug("using nothing");
380: $Apache::inputtags::params{$key}='';
381: } else {
382: &Apache::lonxml::debug("using value");
383: $Apache::inputtags::params{$key}=$value;
384: }
385: }
1.48 albertel 386: }
387:
388: sub answer_header {
389: my ($type) = @_;
390: my $result;
1.50 albertel 391: if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse' ) {
1.48 albertel 392: $result = '<table border="1"><tr><th>Answer for Part:'.
393: $Apache::inputtags::part. '</th></tr><tr>'."\n";
394: } else {
1.49 albertel 395: $result = '<table border="1"><tr><td>Answer for Part:'.
396: $Apache::inputtags::part. '</td>'."\n";
1.48 albertel 397: }
398: return $result;
399: }
400:
401: sub answer_part {
402: my ($type,$answer) = @_;
403: my $result;
1.50 albertel 404: if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') {
1.48 albertel 405: $result = '<td>'.$answer.'</td>';
406: } else {
407: $result = '<td>'.$answer.'</td>';
408: }
409: return $result;
410: }
411:
412: sub answer_footer {
413: my ($type) = @_;
414: my $result;
1.50 albertel 415: if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') {
1.48 albertel 416: $result = '</tr></table>';
417: } else {
418: $result = '</tr></table>';
419: }
420: return $result;
1.1 albertel 421: }
1.2 albertel 422:
1.1 albertel 423: 1;
424: __END__
1.38 albertel 425:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>