File:  [LON-CAPA] / loncom / homework / response.pm
Revision 1.152: download - view: text, annotated - select for diffs
Mon Dec 4 21:23:01 2006 UTC (17 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: version_2_3_X, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_99_1, version_2_2_99_0, HEAD
- expecting an array of values in answertxt now (for when there are multiple input fields)

    1: # The LearningOnline Network with CAPA
    2: # various response type definitons response definition
    3: #
    4: # $Id: response.pm,v 1.152 2006/12/04 21:23:01 albertel 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: 
   29: package Apache::response;
   30: use strict;
   31: use Apache::lonlocal;
   32: use Apache::lonnet;
   33: 
   34: BEGIN {
   35:     &Apache::lonxml::register('Apache::response',('responseparam','parameter','dataresponse','customresponse','mathresponse'));
   36: }
   37: 
   38: sub start_response {
   39:     my ($parstack,$safeeval)=@_;
   40:     my $id = &Apache::lonxml::get_id($parstack,$safeeval);
   41:     if ($#Apache::inputtags::import > -1) {
   42: 	&Apache::lonxml::debug("Turning :$id: into");
   43: 	$id = join('_',@Apache::inputtags::import).'_'.$id;
   44: 	&Apache::lonxml::debug("New  :$id:");
   45:     }
   46:     push (@Apache::inputtags::response,$id);
   47:     push (@Apache::inputtags::responselist,$id);
   48:     @Apache::inputtags::inputlist=();
   49:     if ($Apache::inputtags::part eq '' && 
   50: 	!$Apache::lonhomework::ignore_response_errors) {
   51: 	&Apache::lonxml::error(&HTML::Entities::encode(&mt("Found a <*response> outside of a <part> in a <part>ed problem"),'<>&"'));
   52:     }
   53:     if ($Apache::inputtags::response_with_no_part &&
   54: 	$Apache::inputtags::part ne '0') {
   55: 	&Apache::lonxml::error(&HTML::Entities::encode(&mt("<*response>s are both inside of <part> and outside of <part>, this is not a valid problem, errors in grading may occur."),'<>&"').'<br />');
   56:     }
   57:     if ($Apache::inputtags::part eq '0') {
   58: 	$Apache::inputtags::response_with_no_part=1;
   59:     }
   60:     return $id;
   61: }
   62: 
   63: sub end_response {
   64:     #pop @Apache::inputtags::response;
   65:     @Apache::inputtags::inputlist=();
   66:     return '';
   67: }
   68: 
   69: sub start_hintresponse {
   70:     my ($parstack,$safeeval)=@_;
   71:     my $id = &Apache::lonxml::get_id($parstack,$safeeval);
   72:     push (@Apache::inputtags::hint,$id);
   73:     push (@Apache::inputtags::hintlist,$id);
   74:     push (@Apache::inputtags::paramstack,[%Apache::inputtags::params]);
   75:     return $id;
   76: }
   77: 
   78: sub end_hintresponse {
   79:     pop @Apache::inputtags::hint;
   80:     if (defined($Apache::inputtags::paramstack[-1])) {
   81: 	%Apache::inputtags::params=
   82: 	    @{ pop(@Apache::inputtags::paramstack) };
   83:     }
   84:     return '';
   85: }
   86: 
   87: my @randomseeds;
   88: sub pushrandomnumber {
   89:     my $rand_alg=&Apache::lonnet::get_rand_alg();
   90:     if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
   91: 	$rand_alg eq '64bit2') {
   92: 	# do nothing
   93:     } else {
   94: 	my @seed=&Math::Random::random_get_seed();
   95: 	push(@randomseeds,\@seed);
   96:     }
   97:     &Apache::response::setrandomnumber(@_);
   98: }
   99: sub poprandomnumber {
  100:     my $rand_alg=&Apache::lonnet::get_rand_alg();
  101:     if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
  102: 	$rand_alg eq '64bit2') {
  103: 	return;
  104:     }
  105:     my $seed=pop(@randomseeds);
  106:     if ($seed) {
  107: 	&Math::Random::random_set_seed(@$seed);
  108:     } else {
  109: 	&Apache::lonxml::error("Unable to restore random algorithm.");
  110:     }
  111: }
  112: 
  113: sub setrandomnumber {
  114:     my ($ignore_id2) = @_;
  115:     my $rndseed;
  116:     $rndseed=&Apache::structuretags::setup_rndseed();
  117:     if (!defined($rndseed)) { $rndseed=&Apache::lonnet::rndseed(); }
  118:     &Apache::lonxml::debug("randseed $rndseed");
  119:     #  $rndseed=unpack("%32i",$rndseed);
  120:     my $rand_alg=&Apache::lonnet::get_rand_alg();
  121:     my ($rndmod,$rndmod2);
  122: 
  123:     my ($id1,$id2,$shift_amt);
  124:     if ($Apache::lonhomework::parsing_a_problem) {
  125: 	$id1=$Apache::inputtags::part;
  126: 	if (defined($Apache::inputtags::response[-1])) {
  127: 	    $id2=$Apache::inputtags::response[-1];
  128: 	}
  129: 	$shift_amt=scalar(@Apache::inputtags::responselist);
  130:     } elsif ($Apache::lonhomework::parsing_a_task) {
  131: 	$id1=&Apache::bridgetask::get_dim_id();
  132: 	if (!$ignore_id2 && ref($Apache::bridgetask::instance{$id1})) {
  133: 	    $id2=$Apache::bridgetask::instance{$id1}[-1];
  134: 	    $shift_amt=scalar(@{$Apache::bridgetask::instance{$id1}});
  135: 	} else {
  136: 	    $shift_amt=0;
  137: 	}
  138:     } 
  139:     &Apache::lonxml::debug("id1: $id1, id2: $id2, shift_amt: $shift_amt");
  140:     if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
  141: 	$rand_alg eq '64bit2') {
  142: 	$rndmod=(&Apache::lonnet::numval($id1) << 10);
  143: 	if (defined($id2)) { $rndmod+=&Apache::lonnet::numval($id2); }
  144:     } elsif ($rand_alg eq '64bit3') {
  145: 	$rndmod=(&Apache::lonnet::numval2($id1) << 10);
  146: 	if (defined($id2)) { $rndmod+=&Apache::lonnet::numval2($id2); }
  147:     } elsif ($rand_alg eq '64bit4') {
  148: 	my $shift=(4*$shift_amt)%30;
  149: 	$rndmod=(&Apache::lonnet::numval3($id1) << (($shift+15)%30));
  150: 	if (defined($id2)) {
  151: 	    $rndmod+=(&Apache::lonnet::numval3($id2) << $shift );
  152: 	}
  153:     } else {
  154: 	($rndmod,$rndmod2)=&Apache::lonnet::digest("$id1,$id2");
  155:     }
  156: 
  157:     if ($rndseed =~/([,:])/) {
  158: 	my $char=$1;
  159: 	use integer;
  160: 	my ($num1,$num2)=split(/\Q$char\E/,$rndseed);
  161: 	$num1+=$rndmod;
  162: 	$num2+= ((defined($rndmod2)) ? $rndmod2 : $rndmod);
  163: 	if($Apache::lonnet::_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); }
  164: 	$rndseed=$num1.$char.$num2;
  165:     } else {
  166: 	$rndseed+=$rndmod;
  167: 	if($Apache::lonnet::_64bit) {
  168: 	    use integer;
  169: 	    $rndseed=(($rndseed<<32)>>32);
  170: 	}
  171:     }
  172:     &Apache::lonxml::debug("randseed $rndmod $rndseed");
  173:     &Apache::lonnet::setup_random_from_rndseed($rndseed);
  174:     return '';
  175: }
  176: 
  177: sub meta_parameter_write {
  178:     my ($name,$type,$default,$display)=@_;
  179:     my $partref=$Apache::inputtags::part;
  180:     my $result='<parameter part="'.$Apache::inputtags::part.'"';
  181:     if (defined($Apache::inputtags::response[-1])) {
  182: 	$result.=            ' id="'.$Apache::inputtags::response[-1].'"';
  183: 	$partref.='_'.$Apache::inputtags::response[-1];
  184:     }
  185:     $result.=            ' name="'.$name.'"'.
  186:                          ' type="'.$type.'"'.
  187: (defined($default)?' default="'.$default.'"':'').
  188: (defined($display)?' display="'.$display.' [Part: '.$partref.']"':'')
  189:              .'></parameter>'
  190:              ."\n";
  191:     return $result;
  192: }
  193: 
  194: sub meta_package_write {
  195:     my $name=shift;
  196:     my $result = '<parameter part="'.$Apache::inputtags::part.'"';
  197:     if(defined($Apache::inputtags::response[-1])) {
  198: 	$result.= ' id="'.$Apache::inputtags::response[-1].'"';
  199:     }
  200:     $result.=' package="'.$name.'"></parameter>'."\n";
  201:     return $result;
  202: }
  203: 
  204: sub meta_stores_write {
  205:     my ($name,$type,$display)=@_;
  206:     my $partref=$Apache::inputtags::part;
  207:     my $result = '<stores part="'.$Apache::inputtags::part.'"';
  208:     if (defined($Apache::inputtags::response[-1])) {
  209: 	$result.=           ' id="'.$Apache::inputtags::response[-1].'"';
  210: 	$partref.='_'.$Apache::inputtags::response[-1];
  211:     }	
  212:     $result.=          ' name="'.$name.'"'.
  213:                        ' type="'.$type.'"'.
  214: 	            ' display="'.$display.' [Part: '.$partref.']"'.
  215: 		      "></stores>\n";
  216: }
  217: 
  218: sub mandatory_part_meta {
  219: #
  220: # Autogenerate metadata for mandatory
  221: # input (from RAT or lonparmset) and 
  222: # output (to lonspreadsheet)
  223: # of each part
  224: #
  225:     return
  226: #    &meta_parameter_write('opendate','date_start','',
  227: #                          'Opening Date').
  228: #    &meta_parameter_write('duedate','date_end','',
  229: #                          'Due Date').
  230: #    &meta_parameter_write('answerdate','date_start','',
  231: #                          'Show Answer Date').
  232: #    &meta_parameter_write('weight','int_zeropos','',
  233: #                          'Available Points').
  234: #    &meta_parameter_write('maxtries','int_pos','',
  235: #                          'Maximum Number of Tries').
  236: 	&meta_package_write('part').
  237:         &meta_stores_write('solved','string',
  238: 			   'Problem Status').
  239:         &meta_stores_write('tries','int_zeropos',
  240: 			   'Number of Attempts').
  241:         &meta_stores_write('awarded','float',
  242: 			   'Partial Credit Factor');
  243: #
  244: # Note: responseid-specific data 'submission' and 'awarddetail'
  245: # not available to spreadsheet -> skip here
  246: #
  247: }
  248: 
  249: sub meta_part_order {
  250:     if (@Apache::inputtags::partlist) {
  251: 	my @parts=@Apache::inputtags::partlist;
  252: 	shift(@parts);
  253: 	return '<partorder>'.join(',',@parts).'</partorder>'."\n";
  254:     } else {
  255: 	return '<partorder>0</partorder>'."\n";
  256:     }
  257: }
  258: 
  259: sub meta_response_order {
  260:     if (@Apache::inputtags::responselist) {
  261: 	return '<responseorder>'.join(',',@Apache::inputtags::responselist).
  262: 	    '</responseorder>'."\n";
  263:     }
  264: }
  265: 
  266: sub check_for_previous {
  267:     my ($curresponse,$partid,$id) = @_;
  268:     my %previous;
  269:     $previous{'used'} = 0;
  270:     foreach my $key (sort(keys(%Apache::lonhomework::history))) {
  271: 	if ($key =~ /resource\.$partid\.$id\.submission$/) {
  272: 	    &Apache::lonxml::debug("Trying $key");
  273: 	    my $pastresponse=$Apache::lonhomework::history{$key};
  274: 	    if ($pastresponse eq $curresponse) {
  275: 		$previous{'used'} = 1;
  276: 		my $history;
  277: 		if ( $key =~ /^(\d+):/ ) {
  278: 		    $history=$1;
  279: 		    $previous{'award'} = $Apache::lonhomework::history{"$history:resource.$partid.$id.awarddetail"};
  280: 		    $previous{'last'}='0';
  281: 		    push(@{ $previous{'version'} },$history);
  282: 		} else {
  283: 		    $previous{'award'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"};
  284: 		    $previous{'last'}='1';
  285: 		}
  286: 		if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN';	}
  287: 		&Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:");
  288: 	    }
  289: 	}
  290:     }
  291:     &Apache::lonhomework::showhash(%previous);
  292:     return %previous;
  293: }
  294: 
  295: sub handle_previous {
  296:     my ($previous,$ad)=@_;
  297:     if ($$previous{'used'} && ($$previous{'award'} eq $ad) ) {
  298: 	if ($$previous{'last'}) {
  299: 	    push(@Apache::inputtags::previous,'PREVIOUSLY_LAST');
  300: 	    push(@Apache::inputtags::previous_version,$$previous{'version'});
  301: 	} elsif ($Apache::lonhomework::type ne 'survey') {
  302: 	    push(@Apache::inputtags::previous,'PREVIOUSLY_USED');
  303: 	    push(@Apache::inputtags::previous_version,$$previous{'version'});
  304: 	}
  305:     }
  306: }
  307: 
  308: sub view_or_modify {
  309:     my ($symb,$courseid,$domain,$name) = &Apache::lonnet::whichuser();
  310:     my $myself=0;
  311:     if ( ($name eq $env{'user.name'}) && ($domain eq $env{'user.domain'}) ) {
  312: 	$myself=1;
  313:     }
  314:     my $vgr=&Apache::lonnet::allowed('vgr',$courseid);
  315:     my $mgr=&Apache::lonnet::allowed('vgr',$courseid);
  316:     if ($mgr) { return "M"; }
  317:     if ($vgr) { return "V"; }
  318:     if ($myself) { return "V"; }
  319:     return '';
  320: }
  321: 
  322: sub start_dataresponse {
  323:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  324:     my $id = &Apache::response::start_response($parstack,$safeeval);
  325:     my $result;
  326:     if ($target eq 'web') {
  327: 	$result = $token->[2]->{'display'}.':';
  328:     } elsif ($target eq 'meta') {
  329: 	$result = &Apache::response::meta_stores_write($token->[2]->{'name'},
  330: 						       $token->[2]->{'type'},
  331: 						       $token->[2]->{'display'});
  332: 	$result .= &Apache::response::meta_package_write('dataresponse');
  333:     }
  334:     return $result;
  335: }
  336: 
  337: sub end_dataresponse {
  338:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  339:     my $result;
  340:     if ( $target eq 'web' ) {
  341:     } elsif ($target eq 'grade' ) {
  342: 	if ( defined $env{'form.submitted'}) {
  343: 	    my ($symb,$courseid,$domain,$name)=&Apache::lonnet::whichuser();
  344: 	    my $allowed=&Apache::lonnet::allowed('mgr',$courseid);
  345: 	    if ($allowed) {
  346: 		&Apache::response::setup_params('dataresponse',$safeeval);
  347: 		my $partid = $Apache::inputtags::part;
  348: 		my $id = $Apache::inputtags::response['-1'];
  349: 		my $response = $env{'form.HWVAL_'.$id};
  350: 		my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
  351: 		if ( $response =~ /[^\s]/) {
  352: 		    $Apache::lonhomework::results{"resource.$partid.$id.$name"}=$response;
  353: 		    $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
  354: 		    $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}='SUBMITTED';
  355: 		}
  356: 	    } else {
  357: 		$result='Not Permitted to change values.'
  358: 	    }
  359: 	}
  360:     }
  361:     &Apache::response::end_response;
  362:     return $result;
  363: }
  364: 
  365: sub start_customresponse {
  366:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  367:     my $id = &Apache::response::start_response($parstack,$safeeval);
  368:     push(@Apache::lonxml::namespace,'customresponse');
  369:     my $result;
  370:     undef($Apache::response::custom_answer);
  371:     &Apache::lonxml::register('Apache::response',('answer'));
  372:     if ($target eq 'web') {
  373:   	if (  &Apache::response::show_answer() ) {
  374: 	    my $answer = &Apache::lonxml::get_param('answerdisplay',$parstack,
  375: 						   $safeeval);
  376: 	    $Apache::inputtags::answertxt{$id}=[$answer];
  377: 	}
  378:     } elsif ($target eq 'edit') {
  379: 	$result.=&Apache::edit::tag_start($target,$token);
  380: 	$result.=&Apache::edit::text_arg('String to display for answer:',
  381: 					 'answerdisplay',$token);
  382: 	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  383:     } elsif ($target eq 'modified') {
  384: 	my $constructtag;
  385: 	$constructtag=&Apache::edit::get_new_args($token,$parstack,
  386: 						  $safeeval,'answerdisplay');
  387: 	if ($constructtag) {
  388: 	    $result = &Apache::edit::rebuild_tag($token);
  389: 	    $result.=&Apache::edit::handle_insert();
  390: 	}
  391:     } elsif ($target eq 'answer' || $target eq 'grade') {
  392: 	&Apache::response::reset_params();
  393:     } elsif ($target eq 'meta') {
  394: 	$result .= &Apache::response::meta_package_write('customresponse');
  395:     }
  396:     return $result;
  397: }
  398: 
  399: sub end_customresponse {
  400:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  401:     my $result;
  402:     my $part=$Apache::inputtags::part;
  403:     my $id=$Apache::inputtags::response[-1];
  404:     if ( $target eq 'grade' && &Apache::response::submitted() ) {
  405: 	my $response = &Apache::response::getresponse();
  406: 	if ($Apache::lonhomework::type eq 'exam' ||
  407: 	    &Apache::response::submitted('scantron')) {
  408: 	    &Apache::response::scored_response($part,$id);
  409: 	} elsif ( $response =~ /[^\s]/ && 
  410: 		  $Apache::response::custom_answer_type eq 'loncapa/perl') {
  411: 	    if (!$Apache::lonxml::default_homework_loaded) {
  412: 		&Apache::lonxml::default_homework_load($safeeval);
  413: 	    }
  414: 	    my %previous = &Apache::response::check_for_previous($response,
  415: 								 $part,$id);
  416: 	    $Apache::lonhomework::results{"resource.$part.$id.submission"}=
  417: 		$response;
  418: 	    my $error;
  419: 	    ${$safeeval->varglob('LONCAPA::customresponse_submission')}=
  420: 		$response;
  421: 	    
  422: 	    my $award = &Apache::run::run('{ my $submission=$LONCAPA::customresponse_submission;'.$Apache::response::custom_answer.'}',$safeeval);
  423: 	    if (!&Apache::inputtags::valid_award($award)) {
  424: 		$error = $award;
  425: 		$award = 'ERROR';
  426: 	    }
  427: 	    &Apache::response::handle_previous(\%previous,$award);
  428: 	    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
  429: 		$award;
  430: 	    if ($error) {
  431: 		$Apache::lonhomework::results{"resource.$part.$id.awardmsg"}=
  432: 		    $error;
  433: 	    }
  434: 	}
  435:     } elsif ( $target eq 'answer') {
  436: 	$result  = &Apache::response::answer_header('customresponse');
  437: 	my $answer = &Apache::lonxml::get_param('answerdisplay',$parstack,
  438: 						$safeeval);
  439: 	if ($env{'form.answer_output_mode'} ne 'tex') {
  440: 	    $answer = '<b>'.$answer.'</b>';
  441: 	}
  442: 	$result .= &Apache::response::answer_part('customresponse',$answer);
  443: 	$result .= &Apache::response::answer_footer('customresponse');
  444:     }
  445:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || 
  446: 	$target eq 'tex' || $target eq 'analyze') {
  447: 	&Apache::lonxml::increment_counter(&Apache::response::repetition());
  448:     }
  449:     pop(@Apache::lonxml::namespace);
  450:     &Apache::lonxml::deregister('Apache::response',('answer'));
  451:     &Apache::response::end_response();
  452:     return $result;
  453: }
  454: 
  455: 
  456: sub start_mathresponse {
  457:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  458:     my $id = &Apache::response::start_response($parstack,$safeeval);
  459:     push(@Apache::lonxml::namespace,'mathresponse');
  460:     my $result;
  461:     undef($Apache::response::custom_answer);
  462:     &Apache::lonxml::register('Apache::response',('answer'));
  463:     if ($target eq 'web') {
  464:   	if (  &Apache::response::show_answer() ) {
  465: 	    my $answer = &Apache::lonxml::get_param('answerdisplay',$parstack,
  466: 						   $safeeval);
  467: 	    $Apache::inputtags::answertxt{$id}=[$answer];
  468: 	}
  469:     } elsif ($target eq 'edit') {
  470: 	$result.=&Apache::edit::tag_start($target,$token);
  471: 	$result.=&Apache::edit::text_arg('String to display for answer:',
  472: 					 'answerdisplay',$token);
  473: 	$result.=&Apache::edit::select_arg('Algebra System:',
  474: 					   'cas',
  475: 					   ['maxima'],
  476: 					   $token);
  477: 	$result.=&Apache::edit::text_arg('Algebra System:',
  478: 					 'cas',$token);
  479: 	$result.=&Apache::edit::text_arg('Argument Array:',
  480: 					 'args',$token);
  481: 	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  482:     } elsif ($target eq 'modified') {
  483: 	my $constructtag;
  484: 	$constructtag=&Apache::edit::get_new_args($token,$parstack,
  485: 						  $safeeval,'answerdisplay');
  486: 	if ($constructtag) {
  487: 	    $result = &Apache::edit::rebuild_tag($token);
  488: 	    $result.=&Apache::edit::handle_insert();
  489: 	}
  490:     } elsif ($target eq 'answer' || $target eq 'grade') {
  491: 	&Apache::response::reset_params();
  492:     } elsif ($target eq 'meta') {
  493: 	$result .= &Apache::response::meta_package_write('mathresponse');
  494:     }
  495:     return $result;
  496: }
  497: 
  498: sub end_mathresponse {
  499:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  500:     my $result;
  501:     my $part=$Apache::inputtags::part;
  502:     my $id=$Apache::inputtags::response[-1];
  503:     if ( $target eq 'grade' && &Apache::response::submitted() ) {
  504: 	my $response = &Apache::response::getresponse();
  505: 	if ( $response =~ /[^\s]/ ) {
  506: 	    if (!$Apache::lonxml::default_homework_loaded) {
  507: 		&Apache::lonxml::default_homework_load($safeeval);
  508: 	    }
  509: 	    my %previous = &Apache::response::check_for_previous($response,
  510: 								 $part,$id);
  511: 	    $Apache::lonhomework::results{"resource.$part.$id.submission"}=
  512: 		$response;
  513: 	    my $error;
  514: 	    ${$safeeval->varglob('LONCAPA::mathresponse_submission')}=
  515: 		$response;
  516: 	    
  517: 	    my $award = &Apache::run::run('{ my $submission=$LONCAPA::mathresponse_submission;'.$Apache::response::custom_answer.'}',$safeeval);
  518: 	    if (!&Apache::inputtags::valid_award($award)) {
  519: 		$error = $award;
  520: 		$award = 'ERROR';
  521: 	    }
  522: 	    &Apache::response::handle_previous(\%previous,$award);
  523: 	    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
  524: 		$award;
  525: 	    if ($error) {
  526: 		$Apache::lonhomework::results{"resource.$part.$id.awardmsg"}=
  527: 		    $error;
  528: 	    }
  529: 	}
  530:     }
  531:     pop(@Apache::lonxml::namespace);
  532:     &Apache::lonxml::deregister('Apache::response',('answer'));
  533:     &Apache::response::end_response();
  534:     return $result;
  535: }
  536: 
  537: 
  538: sub start_answer {
  539:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  540:     my $result;
  541:     $Apache::response::custom_answer=
  542: 	&Apache::lonxml::get_all_text_unbalanced("/answer",$parser);
  543:     $Apache::response::custom_answer_type=
  544: 	lc(&Apache::lonxml::get_param('type',$parstack,$safeeval));
  545:     $Apache::response::custom_answer_type =~ s/\s+//g;
  546:     if ($target eq "edit" ) {
  547: 	$result=&Apache::edit::tag_start($target,$token,'Answer algorithm');
  548: 	$result.=&Apache::edit::editfield($token->[1],
  549: 					  $Apache::response::custom_answer,
  550: 					  '',80,4);
  551:     } elsif ( $target eq "modified" ) {
  552: 	$result=$token->[4].&Apache::edit::modifiedfield('/answer',$parser);
  553:     }
  554:     return $result;
  555: }
  556: 
  557: sub end_answer {
  558:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  559:     if ($target eq 'edit' ) {
  560: 	return &Apache::edit::end_table();
  561:     }
  562: }
  563: 
  564: sub decide_package {
  565:     my ($tagstack)=@_;
  566:     my $package;
  567:     if ($$tagstack[-1] eq 'parameter') {
  568: 	$package='part';
  569:     } else {
  570: 	my $i=-1;
  571: 	while (defined($$tagstack[$i])) {
  572: 	    if ($$tagstack[$i] =~ /(response|hint)$/) {
  573: 		$package=$$tagstack[$i];
  574: 		last;
  575: 	    }
  576: 	    $i--;
  577: 	}
  578:     }
  579:     return $package;
  580: }
  581: 
  582: sub start_responseparam {
  583:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  584:     my $result='';
  585:     if ($target eq 'meta') {
  586: 	$result = &meta_parameter_write($token->[2]->{'name'},
  587: 					$token->[2]->{'type'},
  588: 					$token->[2]->{'default'},
  589: 					$token->[2]->{'description'});
  590:     } elsif ($target eq 'edit') {
  591: 	$result.=&Apache::edit::tag_start($target,$token);
  592: 	my $optionlist;
  593: 	my $package=&decide_package($tagstack);
  594: 	foreach my $key (sort(keys(%Apache::lonnet::packagetab))) {
  595: 	    if ($key =~ /^\Q$package\E&(.*)&display$/) {
  596: 		$optionlist.='<option value="'.$1.'">'.
  597: 		    $Apache::lonnet::packagetab{$key}.'</option>';
  598: 	    }
  599: 	}
  600: 	if (defined($optionlist)) {
  601: 	    $result.='Use template: <select name="'.
  602: 		&Apache::edit::html_element_name('parameter_package').'">'.
  603: 		    '<option value=""></option>'.$optionlist.'</select><br />';
  604: 	}
  605: 	$result.=&Apache::edit::text_arg('Name:','name',$token).
  606: 	    &Apache::edit::text_arg('Type:','type',$token).
  607: 		&Apache::edit::text_arg('Description:','description',$token).
  608: 		    &Apache::edit::text_arg('Default:','default',$token).
  609: 			"</td></tr>";
  610: 	$result.=&Apache::edit::end_table;
  611:     } elsif ($target eq 'modified') {
  612: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  613: 						     $safeeval,'name','type',
  614: 						     'description','default');
  615: 	my $element=&Apache::edit::html_element_name('parameter_package');
  616: 	if (defined($env{"form.$element"}) && $env{"form.$element"} ne '') {
  617: 	    my $name=$env{"form.$element"};
  618: 	    my $tag=&decide_package($tagstack);
  619: 	    $token->[2]->{'name'}=$name;
  620: 	    $token->[2]->{'type'}=
  621: 		$Apache::lonnet::packagetab{"$tag&$name&type"};
  622: 	    $token->[2]->{'description'}=
  623: 		$Apache::lonnet::packagetab{"$tag&$name&display"};
  624: 	    $token->[2]->{'default'}=
  625: 		$Apache::lonnet::packagetab{"$tag&$name&default"};
  626: 	    $constructtag=1;
  627: 	}
  628: 	if ($constructtag) {
  629: 	    $result = &Apache::edit::rebuild_tag($token);
  630: 	    $result.=&Apache::edit::handle_insert();
  631: 	}
  632:     } elsif ($target eq 'grade' || $target eq 'answer' || $target eq 'web' ||
  633: 	     $target eq 'tex' || $target eq 'analyze' ) {
  634: 	if ($env{'request.state'} eq 'construct') {
  635: 	    my $name   =&Apache::lonxml::get_param('name',$parstack,$safeeval);
  636: 	    my $default=&Apache::lonxml::get_param('default',$parstack,
  637: 						     $safeeval);
  638: 	    if ($name) {$Apache::inputtags::params{$name}=$default;}
  639: 	}
  640:     }
  641:     return $result;
  642: }
  643: 
  644: sub end_responseparam {
  645:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  646:     if ($target eq 'edit') { return ('','no'); }
  647:     return '';
  648: }
  649: 
  650: sub start_parameter {
  651:     return &start_responseparam(@_);
  652: }
  653: 
  654: sub end_parameter {
  655:     return &end_responseparam(@_);
  656: }
  657: 
  658: sub reset_params {
  659:     %Apache::inputtags::params=();
  660: }
  661: 
  662: sub setup_params {
  663:     my ($tag,$safeeval) = @_;
  664: 
  665:     if ($env{'request.state'} eq 'construct') { return; }
  666:     my %paramlist=();
  667:     foreach my $key (keys(%Apache::lonnet::packagetab)) {
  668: 	if ($key =~ /^$tag/) {
  669: 	    my ($package,$name) = split(/&/,$key);
  670: 	    $paramlist{$name}=1;
  671: 	}
  672:     }
  673:     foreach my $key (keys(%paramlist)) {
  674: 	my $entry= 'resource.'.$Apache::inputtags::part;
  675: 	if (defined($Apache::inputtags::response[-1])) {
  676: 	    $entry.='_'.$Apache::inputtags::response[-1];
  677: 	}
  678: 	$entry.='.'.$key;
  679: 	&Apache::lonxml::debug("looking for $entry");
  680: 	my $value = &Apache::lonnet::EXT("$entry");
  681: 	&Apache::lonxml::debug("$key has value :$value:");
  682: 	if ($value eq 'con_lost' || $value =~ /^error:/) {
  683: 	    &Apache::lonxml::debug("using nothing");
  684: 	    $Apache::inputtags::params{$key}='';
  685: 	} else {
  686: 	    my $string="{return qq\0".$value."\0}";
  687: 	    my $newvalue=&Apache::run::run($string,$safeeval,1);
  688: 	    if (defined($newvalue)) { $value=$newvalue; }
  689: 	    $Apache::inputtags::params{$key}=$value;
  690: 	}
  691:     }
  692: }
  693: 
  694: {
  695:     my @answer_bits;
  696:     my $need_row_start;
  697: 
  698: sub answer_header {
  699:     my ($type,$increment,$rows) = @_;
  700:     my $result;
  701:     if ($env{'form.answer_output_mode'} eq 'tex') {
  702: 	undef(@answer_bits);
  703: 	my $bit;
  704: 	if ($Apache::lonhomework::type eq 'exam') {
  705: 	    $bit = ($Apache::lonxml::counter+$increment).') ';
  706: 	} else {
  707: 	    $bit .= ' Answer for Part: \verb|'.
  708: 		$Apache::inputtags::part.'| ';
  709: 	}
  710: 	push(@answer_bits,$bit);
  711:     } else {
  712: 	my $td = '<td '.(defined($rows)?'rowspan="'.$rows.'"':'').'>';
  713: 	$result  = '<table border="1"><tr>';
  714: 	if ($Apache::lonhomework::type eq 'exam') {
  715: 	    $result .= $td.($Apache::lonxml::counter+$increment). ')</td>';
  716: 	} else {
  717: 	    $result .= $td.&mt('Answer for Part: [_1]',
  718: 			       $Apache::inputtags::part).'</td>';
  719: 	}
  720: 	$result .= "\n";
  721: 	$need_row_start = 0;
  722:     }
  723:     return $result;
  724: }
  725: 
  726: sub next_answer {
  727:     my ($type) = @_;
  728:     my $result;
  729:     if ($env{'form.answer_output_mode'} eq 'tex') {
  730: 	# FIXME ... need to do something with tex mode
  731:     } else {
  732: 	$result .= "</tr>";
  733: 	$need_row_start = 1;
  734:     }
  735:     return $result;
  736: }
  737: 
  738: sub answer_part {
  739:     my ($type,$answer,$args) = @_;
  740:     my $result;
  741:     if ($env{'form.answer_output_mode'} eq 'tex') {
  742: 	if (!$args->{'no_verbatim'}) {
  743: 	    my $to_use='|';
  744: 	    foreach my $value (32..126) {
  745: 		my $char=pack('c',$value);
  746: 		if ($answer !~ /\Q$char\E/) {
  747: 		    $to_use=$char;
  748: 		    last;
  749: 		}
  750: 	    }
  751: 	    if ($answer ne '') {
  752: 		$answer = '\verb'.$to_use.$answer.$to_use;
  753: 	    }
  754: 	}
  755: 	if ($answer ne '') {
  756: 	    push(@answer_bits,$answer);
  757: 	}
  758:     } else {
  759: 	if ($need_row_start) {
  760: 	    $result .= '<tr>';
  761: 	    $need_row_start = 0;
  762: 	}
  763: 	$result .= '<td>'.$answer.'</td>';
  764:     }
  765:     return $result;
  766: }
  767: 
  768: sub answer_footer {
  769:     my ($type) = @_;
  770:     my $result;
  771:     if ($env{'form.answer_output_mode'} eq 'tex') {
  772: 	my $columns = scalar(@answer_bits);
  773: 	$result  = ' \vskip 0 mm \noindent \begin{tabular}{|'.'c|'x$columns.'}\hline ';
  774: 	$result .= join(' & ',@answer_bits);
  775: 	$result .= ' \\\\ \\hline \end{tabular} \vskip 0 mm ';
  776:     } else {
  777: 	$result = '</tr></table>';
  778:     }
  779:     return $result;
  780: }
  781: 
  782: }
  783: 
  784: sub showallfoils {
  785:     if (defined($env{'form.showallfoils'})) {
  786: 	my ($symb)=&Apache::lonnet::whichuser();
  787: 	if (($env{'request.state'} eq 'construct') || 
  788: 	    ($env{'user.adv'} && $symb eq '')      ||
  789:             ($Apache::lonhomework::viewgrades) ) {
  790: 	    return 1;
  791: 	}
  792:     }
  793:     if ($Apache::lonhomework::type eq 'survey') { return 1; }
  794:     return 0;
  795: }
  796: 
  797: sub getresponse {
  798:     my ($temp,$resulttype)=@_;
  799:     my $formparm='form.HWVAL_'.$Apache::inputtags::response['-1'];
  800:     my $response;
  801:     if (!defined($temp)) {
  802: 	$temp=1;
  803:     } else {
  804: 	$formparm.=":$temp";
  805:     }
  806:     my %let_to_num=('A'=>0,'B'=>1,'C'=>2,'D'=>3,'E'=>4,'F'=>5,'G'=>6,'H'=>7,
  807: 		    'I'=>8,'J'=>9,'K'=>10,'L'=>11,'M'=>12,'N'=>13,'O'=>14,
  808: 		    'P'=>15,'Q'=>16,'R'=>17,'S'=>18,'T'=>19,'U'=>20,'V'=>21,
  809: 		    'W'=>22,'X'=>23,'Y'=>24,'Z'=>25);
  810:     if ($env{'form.submitted'} eq 'scantron') {
  811: 	my $part  = $Apache::inputtags::part;
  812: 	my $id    = $Apache::inputtags::response[-1];
  813: 	$response = $env{'scantron.'.($Apache::lonxml::counter+$temp-1).
  814: 			 '.answer'};
  815: 	# save bubbled letter for later
  816: 	$Apache::lonhomework::results{"resource.$part.$id.scantron"}.=
  817: 	    $response;
  818: 	if ($resulttype ne 'letter') {
  819: 	    if ($resulttype eq 'A is 1') {
  820: 		$response = $let_to_num{$response}+1;
  821: 	    } else {
  822: 		$response = $let_to_num{$response};
  823: 	    }
  824: 	}
  825:     } else {
  826: 	$response = $env{$formparm};
  827:     }
  828:     return $response;
  829: }
  830: 
  831: sub repetition {
  832:     my $id = $Apache::inputtags::part;
  833:     my $weight = &Apache::lonnet::EXT("resource.$id.weight");
  834:     if (!defined($weight) || ($weight eq '')) { $weight=1; }
  835:     my $repetition = int($weight/10);
  836:     if ($weight % 10 != 0) { $repetition++; } 
  837:     return $repetition;
  838: }
  839: 
  840: sub scored_response {
  841:     my ($part,$id)=@_;
  842:     my $repetition=&repetition();
  843:     my $score=0;
  844:     for (my $i=0;$i<$repetition;$i++) {
  845: 	# A is 1, B is 2, etc. (get response return 0-9 and then we add 1)
  846: 	my $increase=&Apache::response::getresponse($i+1);
  847: 	if ($increase ne '') { $score+=$increase+1; }
  848:     }
  849:     my $weight = &Apache::lonnet::EXT("resource.$part.weight");
  850:     if (!defined($weight) || $weight eq '' || $weight eq 0) { $weight = 1; }
  851:     my $pcr=$score/$weight;
  852:     $Apache::lonhomework::results{"resource.$part.$id.awarded"}=$pcr;
  853:     $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
  854: 	'ASSIGNED_SCORE';
  855:     return $repetition;
  856: }
  857: 
  858: sub whichorder {
  859:     my ($max,$randomize,$showall,$hash)=@_;
  860:     #&Apache::lonxml::debug("man $max randomize $randomize");
  861:     if (!defined(@{ $$hash{'names'} })) { return; }
  862:     my @names = @{ $$hash{'names'} };
  863:     my @whichopt =();
  864:     my (%top,@toplist,%bottom,@bottomlist);
  865:     if (!($showall || ($randomize eq 'no'))) {
  866: 	my $current=0;
  867: 	foreach my $name (@names) {
  868: 	    $current++;
  869: 	    if ($$hash{"$name.location"} eq 'top') {
  870: 		$top{$name}=$current;
  871: 	    } elsif ($$hash{"$name.location"} eq 'bottom') {
  872: 		$bottom{$name}=$current;
  873: 	    }
  874: 	}
  875:     }
  876:     my $topcount=0;
  877:     my $bottomcount=0;
  878:     while (((scalar(@whichopt)+$topcount+$bottomcount) < $max || $showall)
  879: 	   && ($#names > -1)) {
  880: 	#&Apache::lonxml::debug("Have $#whichopt max is $max");
  881: 	my $aopt;
  882: 	if ($showall || ($randomize eq 'no')) {
  883: 	    $aopt=0;
  884: 	} else {
  885: 	    $aopt=int(&Math::Random::random_uniform() * ($#names+1));
  886: 	}
  887: 	#&Apache::lonxml::debug("From $#whichopt $max $#names elms, picking $aopt");
  888: 	$aopt=splice(@names,$aopt,1);
  889: 	#&Apache::lonxml::debug("Picked $aopt");
  890: 	if ($top{$aopt}) {
  891: 	    $toplist[$top{$aopt}]=$aopt;
  892: 	    $topcount++;
  893: 	} elsif ($bottom{$aopt}) {
  894: 	    $bottomlist[$bottom{$aopt}]=$aopt;
  895: 	    $bottomcount++;
  896: 	} else {
  897: 	    push (@whichopt,$aopt);
  898: 	}
  899:     }
  900:     for (my $i=0;$i<=$#toplist;$i++) {
  901: 	if ($toplist[$i]) { unshift(@whichopt,$toplist[$i]) }
  902:     }
  903:     for (my $i=0;$i<=$#bottomlist;$i++) {
  904: 	if ($bottomlist[$i]) { push(@whichopt,$bottomlist[$i]) }
  905:     }
  906:     return @whichopt;
  907: }
  908: 
  909: sub show_answer {
  910:     my $part   = $Apache::inputtags::part;
  911:     my $award  = $Apache::lonhomework::history{"resource.$part.solved"};
  912:     my $status = $Apache::inputtags::status[-1];
  913:     return  ( ($award =~ /^correct/
  914: 	       && lc($Apache::lonhomework::problemstatus) ne 'no')
  915: 	      || $status eq "SHOW_ANSWER");
  916: }
  917: 
  918: sub analyze_store_foilgroup {
  919:     my ($shown,$attrs)=@_;
  920:     my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
  921:     foreach my $name (@{ $Apache::response::foilgroup{'names'} }) {
  922: 	if (defined($Apache::lonhomework::analyze{"$part_id.foil.value.$name"})) { next; }
  923: 	push (@{ $Apache::lonhomework::analyze{"$part_id.foils"} },$name);
  924: 	foreach my $attr (@$attrs) {
  925: 	    $Apache::lonhomework::analyze{"$part_id.foil.".$attr.".$name"} =
  926: 		$Apache::response::foilgroup{"$name.".$attr};
  927: 	}
  928:     }
  929:     push (@{ $Apache::lonhomework::analyze{"$part_id.shown"} }, @{ $shown });
  930: }
  931: 
  932: sub check_if_computed {
  933:     my ($token,$parstack,$safeeval,$name)=@_;
  934:     my $value = &Apache::lonxml::get_param($name,$parstack,$safeeval);
  935:     if (ref($token->[2]) eq 'HASH' && $value ne $token->[2]{$name}) {
  936: 	my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
  937: 	$Apache::lonhomework::analyze{"$part_id.answercomputed"} = 1;
  938:     }
  939: }
  940: 
  941: sub pick_foil_for_concept {
  942:     my ($target,$attrs,$hinthash,$parstack,$safeeval)=@_;
  943:     if (not defined(@{ $Apache::response::conceptgroup{'names'} })) { return; }
  944:     my @names = @{ $Apache::response::conceptgroup{'names'} };
  945:     my $pick=int(&Math::Random::random_uniform() * ($#names+1));
  946:     my $name=$names[$pick];
  947:     push @{ $Apache::response::foilgroup{'names'} }, $name;
  948:     foreach my $attr (@$attrs) {
  949: 	$Apache::response::foilgroup{"$name.".$attr} =
  950: 	    $Apache::response::conceptgroup{"$name.".$attr};
  951:     }
  952:     my $concept = &Apache::lonxml::get_param('concept',$parstack,$safeeval);
  953:     $Apache::response::foilgroup{"$name.concept"} = $concept;
  954:     &Apache::lonxml::debug("Selecting $name in $concept");
  955:     my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
  956:     if ($target eq 'analyze') {
  957: 	push (@{ $Apache::lonhomework::analyze{"$part_id.concepts"} },
  958: 	      $concept);
  959: 	$Apache::lonhomework::analyze{"$part_id.concept.$concept"}=
  960: 	    $Apache::response::conceptgroup{'names'};
  961: 	foreach my $name (@{ $Apache::response::conceptgroup{'names'} }) {
  962: 	    push (@{ $Apache::lonhomework::analyze{"$part_id.foils"} },
  963: 		  $name);
  964: 	    foreach my $attr (@$attrs) {
  965: 		$Apache::lonhomework::analyze{"$part_id.foil.$attr.$name"}=
  966: 		    $Apache::response::conceptgroup{"$name.$attr"};
  967: 	    }
  968: 	}
  969:     }
  970:     push(@{ $hinthash->{"$part_id.concepts"} },$concept);
  971:     $hinthash->{"$part_id.concept.$concept"}=
  972: 	$Apache::response::conceptgroup{'names'};
  973: 
  974: }
  975: 
  976: sub get_response_param {
  977:     my ($id,$name,$default)=@_;
  978:     my $parameter;
  979:     if ($env{'request.state'} eq 'construct' &&
  980: 	defined($Apache::inputtags::params{$name})) {
  981: 	$parameter=$Apache::inputtags::params{$name};
  982:     } else {
  983: 	$parameter=&Apache::lonnet::EXT("resource.$id.$name");
  984:     }
  985:     if (!defined($parameter) ||	$parameter eq '') {
  986: 	$parameter = $default;
  987:     }
  988:     return $parameter;
  989: }
  990: 
  991: sub submitted {
  992:     my ($who)=@_;
  993:     
  994:     # when scatron grading any submission is a submission
  995:     if ($env{'form.submitted'} eq 'scantron') { return 1; }
  996:     # if the caller only cared if this was a scantron submission
  997:     if ($who eq 'scantron') { return 0; }
  998:     # if the Submit Answer button for this particular part was pressed
  999:     my $partid=$Apache::inputtags::part;
 1000:     if (defined($env{'form.submit_'.$partid})) { return 1; }
 1001:     # Submit All button on a .page was pressed
 1002:     if (defined($env{'form.all_submit'})) { return 1; }
 1003:     # otherwise no submission occured
 1004:     return 0;
 1005: }
 1006: 
 1007: sub add_to_gradingqueue {
 1008:     my ($symb,$courseid,$domain,$name) = &Apache::lonnet::whichuser();
 1009:     if (   $courseid eq ''
 1010: 	|| $symb eq ''
 1011: 	|| $env{'request.state'} eq 'construct'
 1012: 	|| $Apache::lonhomework::type ne 'problem') {
 1013: 	return;
 1014:     }
 1015: 
 1016:     my %queue_info = ( 'type' => 'problem',
 1017: 		       'time' => time);
 1018: 
 1019:     if (exists($Apache::lonhomework::history{"resource.0.checkedin.slot"})) {
 1020: 	$queue_info{'slot'}=
 1021: 	     $Apache::lonhomework::history{"resource.0.checkedin.slot"};
 1022:     }
 1023: 
 1024:     my $result=&Apache::bridgetask::add_to_queue('gradingqueue',\%queue_info);
 1025:     if ($result ne 'ok') {
 1026: 	&Apache::lonxml::error("add_to_queue said $result");
 1027:     }
 1028: }
 1029: 
 1030: # basically undef and 0 (both false) mean that they still have work to do
 1031: # and all true values mean that they can't do any more work
 1032: #
 1033: # a return of undef means it is unattempted
 1034: # a return of 0 means it is attmpted and wrong but still has tries
 1035: # a return of 1 means it is marked correct
 1036: # a return of 2 means they have exceed maximum number of tries
 1037: # a return of 3 means it after the answer date
 1038: sub check_status {
 1039:     my ($id)=@_;
 1040:     if (!defined($id)) { $id=$Apache::inputtags::part; }
 1041:     my $curtime=&Apache::lonnet::EXT('system.time');
 1042:     my $opendate=&Apache::lonnet::EXT("resource.$id.opendate");
 1043:     my $duedate=&Apache::lonnet::EXT("resource.$id.duedate");
 1044:     my $answerdate=&Apache::lonnet::EXT("resource.$id.answerdate");
 1045:     if ( $opendate && $curtime > $opendate &&
 1046:          $duedate && $curtime > $duedate &&
 1047:          $answerdate && $curtime > $answerdate) {
 1048:         return 3;
 1049:     }
 1050:     my $status=&Apache::lonnet::EXT("user.resource.resource.$id.solved");
 1051:     if ($status =~ /^correct/) { return 1; }
 1052:     if (!$status) { return undef; }
 1053:     my $maxtries=&Apache::lonnet::EXT("resource.$id.maxtries");
 1054:     if ($maxtries eq '') { $maxtries=2; }
 1055:     my $curtries=&Apache::lonnet::EXT("user.resource.resource.$id.tries");
 1056:     if ($curtries < $maxtries) { return 0; }
 1057:     return 2;
 1058: }
 1059: 
 1060: 1;
 1061: __END__
 1062:  

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>