![]() ![]() | ![]() |
- <radiobuttonresponse> display answers now
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','formularesponse','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; 48: if ($ENV{'request.state'} eq "construct") { 49: $rndseed=$ENV{'form.rndseed'}; 50: if (!$rndseed) { $rndseed=time; } 51: } else { 52: $rndseed=&Apache::lonnet::rndseed(); 53: } 54: &Apache::lonxml::debug("randseed $rndseed"); 55: # $rndseed=unpack("%32i",$rndseed); 56: $rndseed=$rndseed 57: +(&Apache::lonnet::numval($Apache::inputtags::part) << 10); 58: if (defined($Apache::inputtags::response['-1'])) { 59: $rndseed=$rndseed 60: +&Apache::lonnet::numval($Apache::inputtags::response['-1']); 61: } 62: srand($rndseed); 63: &Apache::lonxml::debug("randseed $rndseed"); 64: return ''; 65: } 66: 67: sub meta_parameter_write { 68: my ($name,$type,$default,$display)=@_; 69: my $partref=$Apache::inputtags::part; 70: my $result='<parameter part="'.$Apache::inputtags::part.'"'; 71: if (defined($Apache::inputtags::response[-1])) { 72: $result.= ' id="'.$Apache::inputtags::response[-1].'"'; 73: $partref.='_'.$Apache::inputtags::response[-1]; 74: } 75: $result.= ' name="'.$name.'"'. 76: ' type="'.$type.'"'. 77: ($default?' default="'.$default.'"':''). 78: ($display?' display="'.$display.' [Part: '.$partref.']"':'') 79: .'></parameter>' 80: ."\n"; 81: return $result; 82: } 83: 84: sub meta_package_write { 85: my $name=shift; 86: my $result = '<parameter part="'.$Apache::inputtags::part.'"'; 87: if(defined($Apache::inputtags::response[-1])) { 88: $result.= ' id="'.$Apache::inputtags::response[-1].'"'; 89: } 90: $result.=' package="'.$name.'"></parameter>'."\n"; 91: return $result; 92: } 93: 94: sub meta_stores_write { 95: my ($name,$type,$display)=@_; 96: my $partref=$Apache::inputtags::part; 97: my $result = '<stores part="'.$Apache::inputtags::part.'"'; 98: if (defined($Apache::inputtags::response[-1])) { 99: $result.= ' id="'.$Apache::inputtags::response[-1].'"'; 100: $partref.='_'.$Apache::inputtags::response[-1]; 101: } 102: $result.= ' name="'.$name.'"'. 103: ' type="'.$type.'"'. 104: ' display="'.$display.' [Part: '.$partref.']"'. 105: "></stores>\n"; 106: } 107: 108: sub mandatory_part_meta { 109: # 110: # Autogenerate metadata for mandatory 111: # input (from RAT or lonparmset) and 112: # output (to lonspreadsheet) 113: # of each part 114: # 115: return 116: # &meta_parameter_write('opendate','date_start','', 117: # 'Opening Date'). 118: # &meta_parameter_write('duedate','date_end','', 119: # 'Due Date'). 120: # &meta_parameter_write('answerdate','date_start','', 121: # 'Show Answer Date'). 122: # &meta_parameter_write('weight','int_zeropos','', 123: # 'Available Points'). 124: # &meta_parameter_write('maxtries','int_pos','', 125: # 'Maximum Number of Tries'). 126: &meta_package_write('part'). 127: &meta_stores_write('solved','string', 128: 'Problem Status'). 129: &meta_stores_write('tries','int_zeropos', 130: 'Number of Attempts'). 131: &meta_stores_write('awarded','float', 132: 'Partial Credit Factor'); 133: # 134: # Note: responseid-specific data 'submission' and 'awarddetail' 135: # not available to spreadsheet -> skip here 136: # 137: } 138: 139: sub check_for_previous { 140: my ($curresponse,$partid,$id) = @_; 141: my %previous; 142: $previous{'used'} = 0; 143: foreach my $key (reverse(sort(keys(%Apache::lonhomework::history)))) { 144: if ($key =~ /resource\.$partid\.$id\.submission/) { 145: &Apache::lonxml::debug("Trying $key"); 146: my $pastresponse=$Apache::lonhomework::history{$key}; 147: if ($pastresponse eq $curresponse) { 148: $previous{'used'} = 1; 149: my $history; 150: if ( $key =~ /^(\d+):/ ) { 151: $history=$1; 152: $previous{'award'} = $Apache::lonhomework::history{"$history:resource.$partid.$id.awarddetail"}; 153: $previous{'last'}='0'; 154: } else { 155: $previous{'award'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"}; 156: $previous{'last'}='1'; 157: } 158: if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN'; } 159: &Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:"); 160: last; 161: } 162: } 163: } 164: return %previous; 165: } 166: 167: sub start_caparesponse { 168: require Apache::caparesponse; 169: import Apache::caparesponse; 170: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; 171: # print "\n<br />\nsimple caparesponse\n"; 172: return &Apache::caparesponse::start_caparesponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); 173: } 174: 175: sub start_stringresponse { 176: require Apache::caparesponse; 177: import Apache::caparesponse; 178: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; 179: return &Apache::caparesponse::start_stringresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); 180: } 181: 182: sub start_formularesponse { 183: require Apache::caparesponse; 184: import Apache::caparesponse; 185: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; 186: return &Apache::caparesponse::start_formularesponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); 187: } 188: 189: sub start_numericalresponse { 190: require Apache::caparesponse; 191: import Apache::caparesponse; 192: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; 193: return &Apache::caparesponse::start_numericalresponse 194: ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); 195: } 196: 197: sub start_radiobuttonresponse { 198: require Apache::radiobuttonresponse; 199: import Apache::radiobuttonresponse; 200: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; 201: return &Apache::radiobuttonresponse::start_radiobuttonresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); 202: } 203: 204: sub start_optionresponse { 205: require Apache::optionresponse; 206: import Apache::optionresponse; 207: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; 208: return &Apache::optionresponse::start_optionresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); 209: } 210: 211: sub start_imageresponse { 212: require Apache::imageresponse; 213: import Apache::imageresponse; 214: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; 215: return &Apache::imageresponse::start_imageresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); 216: } 217: 218: sub start_essayresponse { 219: require Apache::essayresponse; 220: import Apache::essayresponse; 221: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; 222: return &Apache::essayresponse::start_essayresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); 223: } 224: 225: sub view_or_modify { 226: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); 227: my $myself=0; 228: if ( ($name eq $ENV{'user.name'}) && ($domain eq $ENV{'user.domain'}) ) { 229: $myself=1; 230: } 231: my $vgr=&Apache::lonnet::allowed('vgr',$courseid); 232: my $mgr=&Apache::lonnet::allowed('vgr',$courseid); 233: if ($mgr) { return "M"; } 234: if ($vgr) { return "V"; } 235: if ($myself) { return "V"; } 236: return ''; 237: } 238: 239: sub start_dataresponse { 240: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 241: my $id = &Apache::response::start_response($parstack,$safeeval); 242: my $result; 243: if ($target eq 'web') { 244: $result = $token->[2]->{'display'}.':'; 245: } elsif ($target eq 'meta') { 246: $result = &Apache::response::meta_stores_write($token->[2]->{'name'}, 247: $token->[2]->{'type'}, 248: $token->[2]->{'display'}); 249: $result .= &Apache::response::meta_package_write('dataresponse'); 250: } 251: return $result; 252: } 253: 254: sub end_dataresponse { 255: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 256: my $result; 257: if ( $target eq 'web' ) { 258: } elsif ($target eq 'grade' ) { 259: if ( defined $ENV{'form.submitted'}) { 260: my ($symb,$courseid,$domain,$name)=&Apache::lonxml::whichuser(); 261: my $allowed=&Apache::lonnet::allowed('mgr',$courseid); 262: if ($allowed) { 263: &Apache::response::setup_params('datasubmission'); 264: my $partid = $Apache::inputtags::part; 265: my $id = $Apache::inputtags::response['-1']; 266: my $response = $ENV{'form.HWVAL'.$id}; 267: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); 268: if ( $response =~ /[^\s]/) { 269: $Apache::lonhomework::results{"resource.$partid.$id.$name"}= 270: $response; 271: $Apache::lonhomework::results{ 272: "resource.$partid.$id.submission"}= 273: $response; 274: $Apache::lonhomework::results{ 275: "resource.$partid.$id.awarddetail"}= 276: 'SUBMITTED'; 277: } 278: } else { 279: $result='Not Permitted to change values.' 280: } 281: } 282: } 283: &Apache::response::end_response; 284: return $result; 285: } 286: 287: sub start_responseparam { 288: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 289: my $result=''; 290: if ($target eq 'meta') { 291: $result = &meta_parameter_write($token->[2]->{'name'}, 292: $token->[2]->{'type'}, 293: $token->[2]->{'default'}, 294: $token->[2]->{'description'}); 295: } elsif ($target eq 'edit') { 296: $result.=&Apache::edit::tag_start($target,$token, 297: &Apache::lonxml::description($token)); 298: $result.=&Apache::edit::text_arg('Name:','name',$token). 299: &Apache::edit::text_arg('Type:','type',$token). 300: &Apache::edit::text_arg('Description:','description',$token). 301: &Apache::edit::text_arg('Default:','default',$token). 302: "</td></tr>"; 303: $result.=&Apache::edit::end_table; 304: } elsif ($target eq 'modified') { 305: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval, 306: 'name','type','description', 307: 'default'); 308: if ($constructtag) { 309: $result = &Apache::edit::rebuild_tag($token); 310: $result.=&Apache::edit::handle_insert(); 311: } 312: } 313: return $result; 314: } 315: 316: sub end_responseparam { 317: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 318: if ($target eq 'edit') { return ('','no'); } 319: return ''; 320: } 321: 322: sub setup_params { 323: my ($tag) = @_; 324: 325: @Apache::inputtags::params=(); 326: my %paramlist=(); 327: foreach my $key (keys(%Apache::lonnet::packagetab)) { 328: if ($key =~ /^$tag/) { 329: my ($package,$name) = split(/&/,$key); 330: $paramlist{$name}=1; 331: } 332: } 333: foreach my $key (keys(%paramlist)) { 334: my $entry= 'resource.'.$Apache::inputtags::part; 335: if (defined($Apache::inputtags::response[-1])) { 336: $entry.='_'.$Apache::inputtags::response[-1]; 337: } 338: $entry.='.'.$key; 339: &Apache::lonxml::debug("looking for $entry"); 340: my $value = &Apache::lonnet::EXT("$entry"); 341: &Apache::lonxml::debug("$key has value :$value:"); 342: if ($value eq 'con_lost' || $value =~ /^error:/) { 343: &Apache::lonxml::debug("using nothing"); 344: $Apache::inputtags::params{$key}=''; 345: } else { 346: &Apache::lonxml::debug("using value"); 347: $Apache::inputtags::params{$key}=$value; 348: } 349: } 350: } 351: 352: sub answer_header { 353: my ($type) = @_; 354: my $result; 355: if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse' ) { 356: $result = '<table border="1"><tr><th>Answer for Part:'. 357: $Apache::inputtags::part. '</th></tr><tr>'."\n"; 358: } else { 359: $result = '<table border="1"><tr><td>Answer for Part:'. 360: $Apache::inputtags::part. '</td>'."\n"; 361: } 362: return $result; 363: } 364: 365: sub answer_part { 366: my ($type,$answer) = @_; 367: my $result; 368: if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { 369: $result = '<td>'.$answer.'</td>'; 370: } else { 371: $result = '<td>'.$answer.'</td>'; 372: } 373: return $result; 374: } 375: 376: sub answer_footer { 377: my ($type) = @_; 378: my $result; 379: if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { 380: $result = '</tr></table>'; 381: } else { 382: $result = '</tr></table>'; 383: } 384: return $result; 385: } 386: 387: 1; 388: __END__ 389: