--- loncom/homework/lonhomework.pm 2002/12/11 15:33:55 1.105 +++ loncom/homework/lonhomework.pm 2003/02/25 18:49:05 1.109 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.105 2002/12/11 15:33:55 www Exp $ +# $Id: lonhomework.pm,v 1.109 2003/02/25 18:49:05 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -48,6 +48,8 @@ use Apache::optionresponse(); use Apache::imageresponse(); use Apache::essayresponse(); use Apache::externalresponse(); +use Apache::rankresponse(); +use Apache::matchresponse(); use Apache::Constants qw(:common); use HTML::Entities(); use Apache::loncommon(); @@ -150,6 +152,14 @@ sub check_access { my $temp; my $type; my $passed; + + if ($ENV{'request.state'} eq "construct") { + &Apache::lonxml::debug("in construction ignoring dates"); + $status='CAN_ANSWER'; + $datemsg='is in under construction'; + return ($status,$datemsg); + } + &Apache::lonxml::debug("checking for part :$id:"); &Apache::lonxml::debug("time:".time); foreach $temp ("opendate","duedate","answerdate") { @@ -216,11 +226,7 @@ sub check_access { $status='CAN_ANSWER'; $datemsg='is closed but you are allowed to view it'; } - if ($ENV{'request.state'} eq "construct") { - &Apache::lonxml::debug("in construction ignoring dates"); - $status='CAN_ANSWER'; - $datemsg='is in under construction'; - } + return ($status,$datemsg); } @@ -230,6 +236,23 @@ sub showhash { return ''; } +sub showarray { + my ($array)=@_; + my $string="("; + foreach my $elm (@{ $array }) { + if (ref($elm)) { + if ($elm =~ /ARRAY/ ) { + $string.=&showarray($elm); + } + } else { + $string.="$elm," + } + } + chop($string); + $string.=")"; + return $string; +} + sub showhashsubset { my ($hash,$keyre) = @_; my $resultkey; @@ -237,14 +260,13 @@ sub showhashsubset { if ($resultkey =~ /$keyre/) { if (ref($$hash{$resultkey})) { if ($$hash{$resultkey} =~ /ARRAY/ ) { - my $string="$resultkey ---- ("; - foreach my $elm (@{ $$hash{$resultkey} }) { - $string.="$elm,"; - } - chop($string); - &Apache::lonxml::debug("$string)"); + &Apache::lonxml::debug("$resultkey ---- ". + &showarray($$hash{$resultkey})); + } elsif ($$hash{$resultkey} =~ /HASH/ ) { + &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}"); + &showhashsubset($$hash{$resultkey},'.'); } else { - &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}"); + &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}"); } } else { &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}"); @@ -317,7 +339,9 @@ sub handle_save_or_undo { sub analyze_header { my ($request) = @_; - my $result.=' + my $result.=' + Analyzing a problem +
@@ -331,6 +355,13 @@ sub analyze_header { $request->rflush(); } +sub analyze_footer { + my ($request) = @_; + my $result=''; + $request->print($result); + $request->rflush(); +} + sub analyze { my ($request,$file) = @_; &Apache::lonxml::debug("Analyze"); @@ -346,23 +377,34 @@ sub analyze { &Apache::lonxml::debug(":$subresult:"); (my $garbage,$subresult)=split(/_HASH_REF__/,$subresult,2); my %analyze=&Apache::lonnet::str2hash($subresult); + $Apache::lonxml::debug=1; &Apache::lonhomework::showhash(%analyze); + $Apache::lonxml::debug=0; my @parts = @{ $analyze{'parts'} }; foreach my $part (@parts) { if (!exists($allparts{$part})) {$allparts{$part}=1;}; - if ($analyze{$part.'.type'} eq 'numericalresponse') { + if ($analyze{$part.'.type'} eq 'numericalresponse' || + $analyze{$part.'.type'} eq 'stringresponse' || + $analyze{$part.'.type'} eq 'formularesponse' ) { push( @{ $overall{$part.'.answer'} }, [@{ $analyze{$part.'.answer'} }]); } } } foreach my $part (keys(%allparts)) { - $request->print(''); - foreach my $answer (sort {$a->[0] <=> $b->[0]} (@{ $overall{$part.'.answer'} })) { - $request->print(''); + if (defined(@{ $overall{$part.'.answer'} })) { + $request->print('
Part '.$part.'
'.join('',@{ $answer }). - '
'); + foreach my $answer (sort {$a->[0] <=> $b->[0]} (@{ $overall{$part.'.answer'} })) { + $request->print(''); + } + $request->print('
Part '.$part.'
'.join('',@{ $answer }). + '
'); + } else { + $request->print('

Part '.$part. + ' is not analyzabale at this time

'); } } + &analyze_footer($request); &Apache::lonhomework::showhash(%overall); return $result; } @@ -426,10 +468,7 @@ sub renderpage { my %mystyle; my $result = ''; - &Apache::inputtags::initialize_inputtags(); - &Apache::outputtags::initialize_outputtags(); - &Apache::edit::initialize_edit(); - if ($target eq 'analyze') { %Apache::lonhomework::anaylze=(); } + if ($target eq 'analyze') { %Apache::lonhomework::analyze=(); } if ($target eq 'answer') { &showhash(%Apache::lonhomework::history); } if ($target eq 'web') {&Apache::lonhomework::showhashsubset(\%ENV,'^form');}