--- loncom/homework/lonhomework.pm 2003/02/13 21:14:35 1.108 +++ 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.108 2003/02/13 21:14:35 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,16 +61,18 @@ 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'}); } elsif ( defined($ENV{'form.grade_target'} ) - && ($Apache::lonhomework::viewgrades == 'F' )) { + && ($Apache::lonhomework::viewgrades eq 'F' )) { return ($ENV{'form.grade_target'}); } - if ( defined($ENV{'form.submitted'})) { + if ( defined($ENV{'form.submitted'}) && + ( !defined($ENV{'form.resetdata'}))) { return ('grade', 'web'); } else { return ('web'); @@ -206,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') && @@ -279,23 +290,31 @@ 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 '' } sub setupheader { - my $request=$_[0]; - if ($ENV{'browser.mathml'}) { - $request->content_type('text/xml'); - } else { - $request->content_type('text/html'); - } - if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) { - &Apache::loncommon::no_cache($request); - } - $request->send_http_header; - return OK if $request->header_only; - return '' + my $request=$_[0]; + if ($ENV{'browser.mathml'}) { + $request->content_type('text/xml'); + } else { + $request->content_type('text/html'); + } + $request->content_encoding('UTF-8'); + if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) { + &Apache::loncommon::no_cache($request); + } + $request->send_http_header; + return OK if $request->header_only; + return '' } sub handle_save_or_undo { @@ -339,7 +358,9 @@ sub handle_save_or_undo { sub analyze_header { my ($request) = @_; - my $result.=' + my $result.=' + Analyzing a problem +
@@ -353,6 +374,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"); @@ -361,30 +389,50 @@ sub analyze { my %allparts; my $rndseed=$ENV{'form.rndseed'}; &analyze_header($request); + my %prog_state= + &Apache::lonhtmlcommon::Create_PrgWin($request,'Analyze Progress', + 'Getting Problem Variants', + $ENV{'form.numtoanalyze'}); for(my $i=1;$i<$ENV{'form.numtoanalyze'}+1;$i++) { + &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state, + 'last problem'); my $subresult=&Apache::lonnet::ssi($request->uri, ('grade_target' => 'analyze'), ('rndseed' => $i)); &Apache::lonxml::debug(":$subresult:"); (my $garbage,$subresult)=split(/_HASH_REF__/,$subresult,2); my %analyze=&Apache::lonnet::str2hash($subresult); - &Apache::lonhomework::showhash(%analyze); - my @parts = @{ $analyze{'parts'} }; + my @parts; + if (defined(@{ $analyze{'parts'} })) { + @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'} }]); } } } + &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state, + 'Analyzing Results'); 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

'); } } + &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state); + &analyze_footer($request); &Apache::lonhomework::showhash(%overall); return $result; } @@ -393,7 +441,7 @@ sub editxmlmode { my ($request,$file) = @_; my $result; my $problem=&Apache::lonnet::getfile($file); - if ($problem == -1) { + if ($problem eq -1) { &Apache::lonxml::error(" Unable to find $file"); $problem=''; } @@ -409,7 +457,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; } @@ -424,7 +480,7 @@ sub editxmlmode {
- ' . $xml_help . ' Problem Help
+ ' . $xml_help . '
'; @@ -441,21 +497,21 @@ sub renderpage { foreach my $target (@targets) { #my $t0 = [&gettimeofday()]; my $problem=&Apache::lonnet::getfile($file); - if ($problem == -1) { + if ($problem eq -1) { &Apache::lonxml::error(" Unable to find $file"); $problem=''; } my %mystyle; my $result = ''; - 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); @@ -470,6 +526,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); @@ -493,8 +550,8 @@ sub get_template_list { } } if (@allnames && !$result) { - $result="\n'; + $result="\n'; } return $result; } @@ -505,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 @@ -561,7 +614,6 @@ sub handler { #my $t0 = [&gettimeofday()]; my $request=$_[0]; -# if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} $Apache::lonxml::debug=$ENV{'user.debug'}; if (&setupheader($request)) { return OK; } @@ -593,11 +645,16 @@ sub handler { } } + my ($symb) = &Apache::lonxml::whichuser(); + &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' ) { + my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); + &Apache::lonnet::tmpreset($symb,'',$domain,$name); + } + } if ($ENV{'request.state'} eq "construct") { - if ($ENV{'form.resetdata'} eq 'Reset Submissions') { - my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); - &Apache::lonnet::tmpreset($symb,'',$domain,$name); - } if ( -e $file ) { if (!(defined $ENV{'form.problemmode'})) { #first visit to problem in construction space