--- loncom/homework/lonhomework.pm 2003/05/16 19:01:27 1.129 +++ loncom/homework/lonhomework.pm 2003/09/15 21:50:49 1.142 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.129 2003/05/16 19:01:27 albertel Exp $ +# $Id: lonhomework.pm,v 1.142 2003/09/15 21:50:49 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,7 +50,7 @@ use Apache::essayresponse(); use Apache::externalresponse(); use Apache::rankresponse(); use Apache::matchresponse(); -#use Apache::chemresponse(); +use Apache::chemresponse(); use Apache::Constants qw(:common); use HTML::Entities(); use Apache::loncommon(); @@ -69,10 +69,14 @@ sub get_target { } elsif ( defined($ENV{'form.grade_target'} ) && ($Apache::lonhomework::viewgrades eq 'F' )) { return ($ENV{'form.grade_target'}); + } elsif (defined($ENV{'form.grade_target'} ) + && ($ENV{'form.grade_target'} eq 'answer')) { + return ($ENV{'form.grade_target'}); } if ( defined($ENV{'form.submitted'}) && - ( !defined($ENV{'form.resetdata'}))) { + ( !defined($ENV{'form.resetdata'})) && + ( !defined($ENV{'form.newrandomization'}))) { return ('grade', 'web'); } else { return ('web'); @@ -91,7 +95,8 @@ sub get_target { if ( $ENV{'form.problemmode'} eq 'View' || $ENV{'form.problemmode'} eq 'Discard Edits and View') { if ( defined($ENV{'form.submitted'}) && - (!defined($ENV{'form.resetdata'})) ) { + (!defined($ENV{'form.resetdata'})) && + (!defined($ENV{'form.newrandomization'}))) { return ('grade', 'web','answer'); } else { return ('web','answer'); @@ -225,10 +230,10 @@ sub check_access { } } - if (($status ne 'CLOSED') && ($Apache::lonhomework::type eq 'exam') && - (!$Apache::lonhomework::history{"resource.0.outtoken"})) { - return ('UNCHECKEDOUT','needs to be checked out'); - } + #if (($status ne 'CLOSED') && ($Apache::lonhomework::type eq 'exam') && + # (!$Apache::lonhomework::history{"resource.0.outtoken"})) { + # return ('UNCHECKEDOUT','needs to be checked out'); + #} &Apache::lonxml::debug("sending back :$status:$datemsg:"); @@ -398,8 +403,7 @@ sub analyze { 'last problem'); my $subresult=&Apache::lonnet::ssi($request->uri, ('grade_target' => 'analyze'), - ('rndseed' => $i)); - &Apache::lonxml::debug(":$subresult:"); + ('rndseed' => $i+$rndseed)); (my $garbage,$subresult)=split(/_HASH_REF__/,$subresult,2); my %analyze=&Apache::lonnet::str2hash($subresult); my @parts; @@ -418,19 +422,32 @@ sub analyze { } &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state, 'Analyzing Results'); - foreach my $part (keys(%allparts)) { + foreach my $part (sort(keys(%allparts))) { if (defined(@{ $overall{$part.'.answer'} })) { - $request->print(''); + my $num_cols=scalar(@{ $overall{$part.'.answer'}->[0] }); + $request->print('
Part '.$part.'
'); + my %frequency; foreach my $answer (sort {$a->[0] <=> $b->[0]} (@{ $overall{$part.'.answer'} })) { - $request->print(''); + $frequency{join("\0",@{ $answer })}++; + } + $request->print(''); + foreach my $answer (sort {(split("\0",$a))[0] <=> (split("\0",$b))[0]} (keys(%frequency))) { + $request->print(''); } $request->print('
Part '.$part.'
'.join('',@{ $answer }). - '
AnswerFrequency
'. + join('',split("\0",$answer)). + '('.$frequency{$answer}. + ')
'); } else { $request->print('

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

'); + ' is not analyzable at this time

'); } } + if (scalar(keys(%allparts)) == 0 ) { + $request->print('

Found no analyzable parts in this problem, + currently only Numerical, Formula and String response + styles are supported.

'); + } &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state); &analyze_footer($request); &Apache::lonhomework::showhash(%overall); @@ -457,15 +474,8 @@ 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",'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) - .'
'; + my $xml_help = Apache::loncommon::helpLatexCheatsheet("Problem_Editor_XML_Index", + "Problem Editing Help"); if ($cols > 80) { $cols = 80; } if ($cols < 70) { $cols = 70; } if ($rows < 20) { $rows = 20; } @@ -561,6 +571,7 @@ sub newproblem { my $extension=$request->uri; $extension=~s:^.*\.([\w]+)$:$1:; &Apache::lonxml::debug("Looking for :$extension:"); + my $templatelist=&get_template_list('',$extension); if ($ENV{'form.template'} && $ENV{'form.template'} ne "Select a $extension template") { use File::Copy; @@ -568,8 +579,16 @@ sub newproblem { my $dest = &Apache::lonnet::filelocation("",$request->uri); copy($file,$dest); &renderpage($request,$dest); + } elsif($ENV{'form.newfile'} && !$templatelist) { + # I don't like hard-coded filenames but for now, this will work. + use File::Copy; + my $templatefilename = + $request->dir_config('lonIncludes').'/templates/blank.problem'; + &Apache::lonxml::debug("$templatefilename"); + my $dest = &Apache::lonnet::filelocation("",$request->uri); + copy($templatefilename,$dest); + &renderpage($request,$dest); } else { - my $templatelist=&get_template_list('',$extension); my $url=$request->uri; my $dest = &Apache::lonnet::filelocation("",$request->uri); my $errormsg; @@ -641,7 +660,10 @@ sub handler { # if we are browsing we might not be able to know where we are if ($Apache::lonhomework::browse ne 'F') { #should know where we are, so ask - $request->internal_redirect('/adm/ambiguous'); return; + if ( $Apache::lonnet::perlvar{'MODPERL2'} ) { + &Apache::lonnet::cleanenv(); + } + $request->internal_redirect('/adm/ambiguous'); return; } } @@ -649,13 +671,17 @@ sub handler { &Apache::lonxml::debug('symb is '.$symb); if ($ENV{'request.state'} eq "construct" || $symb eq '') { if ($ENV{'form.resetdata'} eq 'Reset Submissions' || - $ENV{'form.resetdata'} eq 'New Problem Variation' ) { + $ENV{'form.resetdata'} eq 'New Problem Variation' || + $ENV{'form.newrandomization'} eq 'New Randomization') { my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); &Apache::lonnet::tmpreset($symb,'',$domain,$name); +&Apache::lonxml::debug("Attempt reset"); } } if ($ENV{'request.state'} eq "construct") { if ( -e $file ) { + &Apache::loncommon::get_unprocessed_cgi + ($ENV{'QUERY_STRING'},['problemmode']); if (!(defined $ENV{'form.problemmode'})) { #first visit to problem in construction space #&view_or_edit_menu($request); @@ -663,7 +689,7 @@ sub handler { &renderpage($request,$file); } elsif ($ENV{'form.problemmode'} eq 'EditXML') { &editxmlmode($request,$file); - } elsif ($ENV{'form.problemmode'} eq 'Answer Distribution') { + } elsif ($ENV{'form.problemmode'} eq 'Calculate answers') { &analyze($request,$file); } else { &renderpage($request,$file);