--- loncom/homework/lonhomework.pm 2003/04/30 21:27:57 1.120 +++ loncom/homework/lonhomework.pm 2003/05/16 19:01:27 1.129 @@ -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.129 2003/05/16 19:01:27 albertel 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,12 +209,20 @@ 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') && @@ -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 '' } @@ -534,7 +551,7 @@ sub get_template_list { } if (@allnames && !$result) { $result="\n'; + join(''; } return $result; } @@ -545,33 +562,29 @@ sub newproblem { $extension=~s:^.*\.([\w]+)$:$1:; &Apache::lonxml::debug("Looking for :$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'}) { - # 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; + 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