--- loncom/homework/lonhomework.pm 2002/12/11 14:44:24 1.104 +++ loncom/homework/lonhomework.pm 2003/03/07 23:43:21 1.113 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.104 2002/12/11 14:44:24 www Exp $ +# $Id: lonhomework.pm,v 1.113 2003/03/07 23:43:21 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; } @@ -387,7 +429,15 @@ sub editxmlmode { &renderpage($request,$file); } else { my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem); - my $xml_help = Apache::loncommon::help_open_topic("Problem_Editor_XML_Index"); + my $xml_help = '
'. + &Apache::loncommon::help_open_topic("Problem_Editor_XML_Index",'Problem Editing Help') + .''. + &Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols', + undef,undef,600) + .''. + &Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols', + undef,undef,600) + .'
'; if ($cols > 80) { $cols = 80; } if ($cols < 70) { $cols = 70; } if ($rows < 20) { $rows = 20; } @@ -402,7 +452,7 @@ sub editxmlmode {
- ' . $xml_help . ' Problem Help
+ ' . $xml_help . '
'; @@ -426,17 +476,14 @@ 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');} &Apache::lonxml::debug("Should be parsing now"); $result = &Apache::lonxml::xmlparse($request, $target, $problem, &setup_vars($target),%mystyle); - + undef($Apache::lonhomework::parsing_a_problem); #$request->print("Result follows:"); if ($target eq 'modified') { &handle_save_or_undo($request,\$problem,\$result); @@ -451,6 +498,7 @@ sub renderpage { #$result.="
Spent $td seconds processing target $target\n"; #} $request->print($result); + $request->rflush(); } #$request->print(":Result ends"); #my $td=&tv_interval($t0); @@ -506,18 +554,21 @@ sub newproblem { my $url=$request->uri; my $dest = &Apache::lonnet::filelocation("",$request->uri); my $instructions; - if ($templatelist) { $instructions=", select a template from the pull-down menu below. Then";} + if ($templatelist) { $instructions=", select a template from the pull-down menu below.
Then";} $request->print(< -The requested file $url doesn\'t exist.
-To create a new $extension$instructions click on the Create $extension button. -
+

Creating a new $extension resource

+The requested file $url currently does not exist. +

+To create a new $extension$instructions click on the "Create $extension" button. +

+

ENDNEWPROBLEM if (defined($templatelist)) { $request->print(""); } $request->print("
"); - $request->print("

"); + $request->print("

"); } return ''; }