--- loncom/homework/lonhomework.pm 2003/04/30 21:27:57 1.120 +++ loncom/homework/lonhomework.pm 2003/06/16 21:32:43 1.135 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.120 2003/04/30 21:27:57 albertel Exp $ +# $Id: lonhomework.pm,v 1.135 2003/06/16 21:32:43 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,6 +50,7 @@ use Apache::essayresponse(); use Apache::externalresponse(); use Apache::rankresponse(); use Apache::matchresponse(); +#use Apache::chemresponse(); use Apache::Constants qw(:common); use HTML::Entities(); use Apache::loncommon(); @@ -60,7 +61,8 @@ BEGIN { } sub get_target { - if ( $ENV{'request.state'} eq "published") { + if (($ENV{'request.state'} eq "published") || + ($ENV{'request.state'} eq "uploaded")) { if ( defined($ENV{'form.grade_target'} ) && ($ENV{'form.grade_target'} eq 'tex')) { return ($ENV{'form.grade_target'}); @@ -207,18 +209,26 @@ sub check_access { $datemsg = "was due on $lastdate, and answers will be available on $date"; } if ($status eq 'CAN_ANSWER') { - #check #tries + #check #tries, and if correct. my $tries = $Apache::lonhomework::history{"resource.$id.tries"}; my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries"); if ( $tries eq '' ) { $tries = '0'; } if ( $maxtries eq '' ) { $maxtries = '2'; } - if ($tries >= $maxtries) { $status = 'CANNOT_ANSWER'; } + if ($tries >= $maxtries) { $status = 'CANNOT_ANSWER'; } + # if (correct and show prob status) or excused then CANNOT_ANSWER + if(($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/ + && + lc($Apache::lonhomework::problemstatus) ne 'no') + || + $Apache::lonhomework::history{"resource.$id.solved"}=~/^excused/) { + $status = 'CANNOT_ANSWER'; + } } - 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:"); @@ -280,7 +290,14 @@ sub showhashsubset { sub setuppermissions { $Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'}); - $Apache::lonhomework::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); + my $viewgrades = &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); + if (! $viewgrades && + exists($ENV{'request.course.sec'}) && + $ENV{'request.course.sec'} !~ /^\s*$/) { + $viewgrades = &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}. + '/'.$ENV{'request.course.sec'}); + } + $Apache::lonhomework::viewgrades = $viewgrades; return '' } @@ -381,8 +398,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; @@ -401,19 +417,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); @@ -534,7 +563,7 @@ sub get_template_list { } if (@allnames && !$result) { $result="\n'; + join(''; } return $result; } @@ -544,34 +573,39 @@ 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 type") { + $ENV{'form.template'} ne "Select a $extension template") { use File::Copy; my $file = &get_template_list($ENV{'form.template'},$extension); my $dest = &Apache::lonnet::filelocation("",$request->uri); copy($file,$dest); &renderpage($request,$dest); - } elsif($ENV{'form.newfile'}) { + } elsif($ENV{'form.newfile'} && !$templatelist) { # I don't like hard-coded filenames but for now, this will work. use File::Copy; - my $templatefilename = + 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; + if ($ENV{'form.newfile'}) { + $errormsg='

You did not select a template.

'."\n"; + } my $instructions; if ($templatelist) { $instructions=", select a template from the pull-down menu below.
Then";} $request->print(<

Creating a new $extension resource

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

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

ENDNEWPROBLEM @@ -643,6 +677,8 @@ sub handler { } 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); @@ -650,7 +686,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);