![]() ![]() | ![]() |
Gradestatus was changed - target was added.
1: # The LearningOnline Network with CAPA 2: # input definitons 3: # 4: # $Id: inputtags.pm,v 1.63 2002/10/01 21:05:45 sakharuk 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: # 28: # 2/19 Guy 29: 30: package Apache::inputtags; 31: use HTML::Entities(); 32: use strict; 33: 34: BEGIN { 35: &Apache::lonxml::register('Apache::inputtags',('textfield','textline','datasubmission')); 36: } 37: 38: 39: sub initialize_inputtags { 40: # list of current input ids 41: @Apache::inputtags::input=(); 42: # list of all input ids seen in this problem 43: @Apache::inputtags::inputlist=(); 44: # list of all current response ids 45: @Apache::inputtags::response=(); 46: # list of all response ids seen in this problem 47: @Apache::inputtags::responselist=(); 48: # list of whether or not a specific response was previously used 49: @Apache::inputtags::previous=(); 50: # id of current part, 0 means that no part is current (inside <problem> only 51: $Apache::inputtags::part=''; 52: # list of problem date statuses, the first element is for <problem> 53: # if there is a second element it is for the current <part> 54: @Apache::inputtags::status=(); 55: # hash of defined params for the current response 56: %Apache::inputtags::params=(); 57: # list of all ids, for <import>, these get join()ed and prepended 58: @Apache::inputtags::import=(); 59: } 60: 61: sub start_input { 62: my ($parstack,$safeeval)=@_; 63: my $id = &Apache::lonxml::get_param('id',$parstack,$safeeval); 64: if ($id eq '') { $id = $Apache::lonxml::curdepth; } 65: push (@Apache::inputtags::input,$id); 66: push (@Apache::inputtags::inputlist,$id); 67: return $id; 68: } 69: 70: sub end_input { 71: pop @Apache::inputtags::input; 72: return ''; 73: } 74: 75: sub start_textfield { 76: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 77: my $result = ""; 78: my $id = &start_input($parstack,$safeeval); 79: my $resid=$Apache::inputtags::response[-1]; 80: if ($target eq 'web') { 81: $Apache::lonxml::evaluate--; 82: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { 83: my $partid=$Apache::inputtags::part; 84: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"}); 85: my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval); 86: if ( $cols eq '') { $cols = 80; } 87: my $rows = &Apache::lonxml::get_param('rows',$parstack,$safeeval); 88: if ( $rows eq '') { $rows = 10; } 89: $result= '<textarea name="HWVAL'.$resid.'" '. 90: "rows=\"$rows\" cols=\"$cols\">".$oldresponse; 91: if ($oldresponse ne '') { 92: #get rid of any startup text if the user has already responded 93: &Apache::lonxml::get_all_text("/textfield",$$parser[-1]); 94: } 95: } else { 96: #right or wrong don't show it 97: #$result='<table border="1"><tr><td><i>'.$oldresponse.'</i></td></tr></table>'; 98: $result=''; 99: #get rid of any startup text 100: &Apache::lonxml::get_all_text("/textfield",$$parser[-1]); 101: } 102: } elsif ($target eq 'grade') { 103: my $seedtext=&Apache::lonxml::get_all_text("/textfield",$$parser[-1]); 104: if ($seedtext eq $ENV{'form.HWVAL'.$resid}) { 105: # if the seed text is still there it wasn't a real submission 106: $ENV{'form.HWVAL'.$resid}=''; 107: } 108: } elsif ($target eq 'edit') { 109: $result.=&Apache::edit::tag_start($target,$token); 110: $result.=&Apache::edit::text_arg('Rows:','rows',$token,4); 111: $result.=&Apache::edit::text_arg('Columns:','cols',$token,4); 112: my $bodytext=&Apache::lonxml::get_all_text("/textfield",$$parser[-1]); 113: $result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2); 114: } elsif ($target eq 'modified') { 115: my $constructtag=&Apache::edit::get_new_args($token,$parstack, 116: $safeeval,'rows','cols'); 117: if ($constructtag) { 118: $result = &Apache::edit::rebuild_tag($token); 119: } else { 120: $result=$token->[4]; 121: } 122: $result.=&Apache::edit::modifiedfield(); 123: } 124: return $result; 125: } 126: 127: sub end_textfield { 128: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 129: my $result; 130: if ($target eq 'web') { 131: $Apache::lonxml::evaluate++; 132: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { 133: return "</textarea>"; 134: } 135: } elsif ($target eq 'edit') { 136: $result=&Apache::edit::end_table(); 137: } 138: &end_input; 139: return $result; 140: } 141: 142: sub start_textline { 143: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 144: my $result = ""; 145: if ($target eq 'web') { 146: $Apache::lonxml::evaluate--; 147: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { 148: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval); 149: if ($size eq '') { $size=20; } 150: my $partid=$Apache::inputtags::part; 151: my $id=$Apache::inputtags::response[-1]; 152: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"}); 153: $result= '<input type="text" name="HWVAL'.$id.'" value="'. 154: $oldresponse.'" size="'.$size.'" />'; 155: } else { 156: #right or wrong don't show what was last typed in. 157: #$result='<i>'.$oldresponse.'</i>'; 158: $result=''; 159: } 160: } elsif ($target eq 'edit') { 161: $result=&Apache::edit::tag_start($target,$token); 162: $result.=&Apache::edit::text_arg('Size:','size',$token,'5')."</td></tr>"; 163: $result.=&Apache::edit::end_table; 164: } elsif ($target eq 'modified') { 165: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'size'); 166: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } 167: } 168: return $result; 169: } 170: 171: sub end_textline { 172: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 173: if ($target eq 'web') { $Apache::lonxml::evaluate++; } 174: elsif ($target eq 'edit') { return ('','no'); } 175: return ""; 176: } 177: 178: sub start_datasubmission { 179: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 180: my $id = &Apache::response::start_response($parstack,$safeeval); 181: my $result; 182: if ($target eq 'meta') { 183: $result = &Apache::response::meta_stores_write($token->[2]->{'name'}, 184: $token->[2]->{'type'}, 185: $token->[2]->{'display'}); 186: $result .= &Apache::response::meta_package_write('datasubmission'); 187: } 188: return $result; 189: } 190: 191: sub end_datasubmission { 192: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 193: my $result; 194: if ( $target eq 'web' ) { 195: } elsif ($target eq 'grade' ) { 196: if ( defined $ENV{'form.submitted'}) { 197: &Apache::response::setup_params('datasubmission'); 198: my $partid = $Apache::inputtags::part; 199: my $id = $Apache::inputtags::response['-1']; 200: my $response = $ENV{'form.HWVAL'.$id}; 201: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); 202: if ( $response =~ /[^\s]/) { 203: $Apache::lonhomework::results{"resource.$partid.$id.$name"}= 204: $response; 205: } 206: } 207: } 208: &Apache::response::end_response; 209: return $result; 210: } 211: 212: sub finalizeawards { 213: my $result=''; 214: my $award; 215: if ($#_ == '-1') { $result = "NO_RESPONSE"; } 216: if ($result eq '' ) { 217: my $blankcount; 218: foreach $award (@_) { 219: if ($award eq '') { 220: $result='MISSING_ANSWER'; 221: $blankcount++; 222: } 223: } 224: if ($blankcount == ($#_ + 1)) { $result = 'NO_RESPONSE'; } 225: } 226: if ($result eq '' ) { 227: foreach $award (@_) { if ($award eq 'MISSING_ANSWER') {$result='MISSING_ANSWER'; last;}} 228: } 229: if ($result eq '' ) { 230: foreach $award (@_) { if ($award eq 'ERROR') {$result='ERROR'; last;}} 231: } 232: if ($result eq '' ) { 233: foreach $award (@_) { if ($award eq 'NO_RESPONSE') {$result='NO_RESPONSE'; last;} } 234: } 235: 236: if ($result eq '' ) { 237: foreach $award (@_) { 238: if ($award eq 'UNIT_FAIL' || 239: $award eq 'NO_UNIT' || 240: $award eq 'UNIT_NOTNEEDED') { 241: $result=$award; last; 242: } 243: } 244: } 245: if ($result eq '' ) { 246: foreach $award (@_) { 247: if ($award eq 'WANTED_NUMERIC' || 248: $award eq 'BAD_FORMULA') {$result=$award; last;} 249: } 250: } 251: if ($result eq '' ) { 252: foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} } 253: } 254: if ($result eq '' ) { 255: foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} } 256: } 257: if ($result eq '' ) { 258: foreach $award (@_) { if ($award eq 'DRAFT') {$result=$award; last;} } 259: } 260: if ($result eq '' ) { 261: foreach $award (@_) { if ($award eq 'SUBMITTED') {$result=$award; last;} } 262: } 263: if ($result eq '' ) { 264: foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} } 265: } 266: if ($result eq '' ) { $result='EXACT_ANS'; } 267: return $result 268: } 269: 270: sub decideoutput { 271: my ($award,$solved,$previous)=@_; 272: my $message=''; 273: my $button=0; 274: my $previousmsg; 275: 276: if ($previous) { $previousmsg='You have entered that answer before'; } 277: 278: if ($solved =~ /^correct/) { 279: $message = "<b>You are correct.</b> Your receipt is ". 280: &Apache::lonnet::receipt; 281: $button=0; 282: $previousmsg=''; 283: } elsif ($solved =~ /^excused/) { 284: $message = "<b>You are excused from the problem.</b>"; 285: $button=0; 286: $previousmsg=''; 287: } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) { 288: if ($solved =~ /^incorrect/ || $solved eq '') { 289: $message = "Incorrect"; 290: $button=1; 291: } else { 292: $message = "<b>You are correct.</b> Your receipt is ". 293: &Apache::lonnet::receipt; 294: $button=0; 295: $previousmsg=''; 296: } 297: } elsif ($award eq 'NO_RESPONSE') { 298: $message = ''; 299: $button=1; 300: } elsif ($award eq 'MISSING_ANSWER') { 301: $message = 'Some parts were not submitted'; 302: $button = 1; 303: } elsif ($award eq 'WANTED_NUMERIC') { 304: $message = "This question expects a numeric answer"; 305: $button=1; 306: } elsif ($award eq 'SIG_FAIL') { 307: $message = "Please adjust significant figures.";# you provided %s significant figures"; 308: $button=1; 309: } elsif ($award eq 'UNIT_FAIL') { 310: $message = "Units incorrect."; #Computer reads units as %s"; 311: $button=1; 312: } elsif ($award eq 'UNIT_NOTNEEDED') { 313: $message = "Only a number required.";# Computer reads units of %s"; 314: $button=1; 315: } elsif ($award eq 'NO_UNIT') { 316: $message = "Units required"; 317: $button=1; 318: } elsif ($award eq 'BAD_FORMULA') { 319: $message = "Unable to understand formula"; 320: $button=1; 321: } elsif ($award eq 'INCORRECT') { 322: $message = "Incorrect"; 323: $button=1; 324: } elsif ($award eq 'SUBMITTED') { 325: $message = "Your submission has been recorded."; 326: $button=1; 327: } elsif ($award eq 'DRAFT') { 328: $message = "A draft copy has been saved."; 329: $button=1; 330: } else { 331: $message = "Unknown message: $award"; 332: $button=1; 333: } 334: return ($button,$message,$previousmsg); 335: } 336: 337: sub setgradedata { 338: my ($award,$id,$previously_used) = @_; 339: # if the student already has it correct, don't modify the status 340: if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER') { 341: $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award; 342: return ''; 343: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~ 344: /^correct/ ) { 345: #handle assignment of tries and solved status 346: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) { 347: $Apache::lonhomework::results{"resource.$id.afterduedate"}=''; 348: } 349: if ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) { 350: $Apache::lonhomework::results{"resource.$id.tries"} = 351: $Apache::lonhomework::history{"resource.$id.tries"} + 1; 352: $Apache::lonhomework::results{"resource.$id.solved"} = 353: 'correct_by_student'; 354: $Apache::lonhomework::results{"resource.$id.awarded"} = '1'; 355: } elsif ( $award eq 'INCORRECT' ) { 356: $Apache::lonhomework::results{"resource.$id.tries"} = 357: $Apache::lonhomework::history{"resource.$id.tries"} + 1; 358: $Apache::lonhomework::results{"resource.$id.solved"} = 359: 'incorrect_attempted' 360: } elsif ( $award eq 'SUBMITTED' ) { 361: $Apache::lonhomework::results{"resource.$id.tries"} = 362: $Apache::lonhomework::history{"resource.$id.tries"} + 1; 363: $Apache::lonhomework::results{"resource.$id.solved"} = 364: 'ungraded_attempted'; 365: } elsif ( $award eq 'DRAFT' ) { 366: $Apache::lonhomework::results{"resource.$id.solved"} = ''; 367: } elsif ( $award eq 'NO_RESPONSE' ) { 368: return ''; 369: } else { 370: $Apache::lonhomework::results{"resource.$id.solved"} = 371: 'incorrect_attempted'; 372: } 373: 374: # check if this was a previous submission if it was delete the 375: # unneeded data and update the previously_used attribute 376: if ( $previously_used eq 'PREVIOUSLY_USED') { 377: delete($Apache::lonhomework::results{"resource.$id.tries"}); 378: $Apache::lonhomework::results{"resource.$id.previous"} = '1'; 379: } elsif ( $previously_used eq 'PREVIOUSLY_LAST') { 380: #delete all data as they student didn't do anything, but save 381: #the list of collaborators. 382: foreach my $key (keys(%Apache::lonhomework::results)) { 383: if (($key =~ /^resource\.$id\./) && ($key !~ /\.collaborators$/)) { 384: &Apache::lonxml::debug("Removing $key"); 385: delete($Apache::lonhomework::results{$key}); 386: } 387: } 388: #and since they didn't do anything we were never here 389: return ''; 390: } else { 391: $Apache::lonhomework::results{"resource.$id.previous"} = '0'; 392: } 393: } 394: $Apache::lonhomework::results{"resource.$id.award"} = $award; 395: } 396: 397: sub grade { 398: my ($target) = @_; 399: my $id = $Apache::inputtags::part; 400: my $response=''; 401: if ( defined $ENV{'form.submitted'}) { 402: my @awards = (); 403: foreach $response (@Apache::inputtags::responselist) { 404: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail"); 405: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"}; 406: &Apache::lonxml::debug("keeping $value from $response for $id"); 407: push (@awards,$value); 408: } 409: my $finalaward = &finalizeawards(@awards); 410: my $previously_used; 411: if ( $#Apache::inputtags::previous eq $#awards ) { 412: $previously_used = 'PREVIOUSLY_LAST'; 413: foreach my $value (@Apache::inputtags::previous) { 414: if ($value eq 'PREVIOUSLY_USED' ) { 415: $previously_used = $value; 416: last; 417: } 418: } 419: } 420: &Apache::lonxml::debug("final award $finalaward, $previously_used"); 421: &setgradedata($finalaward,$id,$previously_used); 422: } 423: return ''; 424: } 425: 426: sub gradestatus { 427: my ($id,$target) = @_; 428: my $showbutton = 1; 429: my $message = ''; 430: my $latemessage = ''; 431: my $trystr=''; 432: my $button=''; 433: my $previousmsg=''; 434: 435: my $status = $Apache::inputtags::status['-1']; 436: &Apache::lonxml::debug("gradestatus has :$status:"); 437: if ( $status ne 'CLOSED' ) { 438: my $award = $Apache::lonhomework::history{"resource.$id.award"}; 439: my $solved = $Apache::lonhomework::history{"resource.$id.solved"}; 440: my $previous = $Apache::lonhomework::history{"resource.$id.previous"}; 441: &Apache::lonxml::debug("Found Award |$award|$solved|"); 442: if ( $award ne '' ) { 443: &Apache::lonxml::debug('Getting message'); 444: ($showbutton,$message,$previousmsg) = 445: &decideoutput($award,$solved,$previous); 446: if ($target eq 'tex') { 447: $message=' '.$message.' '; 448: } else { 449: $message="<td bgcolor=\"#aaffaa\">$message</td>"; 450: if ($previousmsg) { 451: $previousmsg="<td bgcolor=\"#ffaaaa\">$previousmsg</td>"; 452: } 453: } 454: } 455: my $tries = $Apache::lonhomework::history{"resource.$id.tries"}; 456: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries"); 457: &Apache::lonxml::debug("got maxtries of :$maxtries:"); 458: if ( $tries eq '' ) { $tries = '0'; } 459: if ( $maxtries eq '' ) { $maxtries = '2'; } 460: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } 461: if ( $showbutton ) { 462: if ($target eq 'tex') { 463: $trystr = ' '.$tries.'/'.$maxtries.' '; 464: } else { 465: $trystr = "<td>Tries $tries/$maxtries</td>"; 466: } 467: } 468: if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;} 469: if ( $showbutton ) { 470: if ($target ne 'tex') { 471: $button = '<br /><input type="submit" name="submit" value="Submit Answer" />'; 472: } 473: } 474: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) { 475: #last submissions was after due date 476: if ($target eq 'tex') { 477: $latemessage=' The last submission was after the Due Date '; 478: } else { 479: $latemessage="<td bgcolor=\"#ffaaaa\">The last submission was after the Due Date</td>"; 480: } 481: } 482: } 483: my $output= $previousmsg.$latemessage.$message.$trystr; 484: if ($output =~ /^\s*$/) { 485: return $button; 486: } else { 487: if ($target eq 'tex') { 488: return $button.' \vskip 0 mm '.$output.' '; 489: } else { 490: return $button.'<table><tr>'.$output.'</tr></table>'; 491: } 492: } 493: } 494: 1; 495: __END__ 496: