--- loncom/homework/lonhomework.pm 2006/06/20 03:33:55 1.251 +++ loncom/homework/lonhomework.pm 2006/09/25 19:41:56 1.258 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.251 2006/06/20 03:33:55 albertel Exp $ +# $Id: lonhomework.pm,v 1.258 2006/09/25 19:41:56 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -244,7 +244,7 @@ sub check_slot_access { # does it pass normal muster my ($status,$datemsg)=&check_access($id); - my $useslots = &Apache::lonnet::EXT("resource.$id.useslots"); + my $useslots = &Apache::lonnet::EXT("resource.0.useslots"); if ($useslots ne 'resource' && $useslots ne 'map' && $useslots ne 'map_map') { return ($status,$datemsg); @@ -269,8 +269,8 @@ sub check_slot_access { } my @slots= - (split(':',&Apache::lonnet::EXT("resource.$id.availablestudent")), - split(':',&Apache::lonnet::EXT("resource.$id.available"))); + (split(':',&Apache::lonnet::EXT("resource.0.availablestudent")), + split(':',&Apache::lonnet::EXT("resource.0.available"))); # if (!@slots) { # return ($status,$datemsg); @@ -310,8 +310,10 @@ sub check_slot_access { $checkedin = $Apache::lonhomework::history{"resource.$version.0.checkedin"}; } elsif ($type eq 'problem') { - $got_grade = 1; - $checkedin = $Apache::lonhomework::history{"resource.0.checkedin"}; + $got_grade = 1; + $checkedin = $Apache::lonhomework::history{"resource.0.checkedin"}; + $is_correct = + ($Apache::lonhomework::history{"resource.0.solved"} =~/^correct_/); } &Apache::lonxml::debug(" slot is $slotstatus checkedin ($checkedin) got_grade ($got_grade) is_correct ($is_correct)"); @@ -324,6 +326,14 @@ sub check_slot_access { return ('WAITING_FOR_GRADE'); } + # no slot is currently open, and has been checked in for this version + # previous slot is therefore CLOSED, so therefore the problem is + if (!defined($slot_name) + && $checkedin + && $type eq 'problem') { + return ('CLOSED',$datemsg); + } + if ($slotstatus eq 'NOT_IN_A_SLOT' && $checkedin ) { @@ -334,9 +344,14 @@ sub check_slot_access { } } + if ( $is_correct) { + if ($type eq 'problem') { + return ($status); + } return ('SHOW_ANSWER'); } + if ( $status eq 'CANNOT_ANSWER' && ($slotstatus ne 'NEEDS_CHECKIN' && $slotstatus ne 'NOT_IN_A_SLOT')) { return ($status,$datemsg); @@ -465,7 +480,11 @@ sub check_access { if (!$first_access) { $status='NOT_YET_VIEWED'; my $due_date = &due_date($id); - $datemsg=&seconds_to_human_length($due_date-time); + my $seconds_left = $due_date - time; + if ($seconds_left > $interval || $due_date eq '') { + $seconds_left = $interval; + } + $datemsg=&seconds_to_human_length($seconds_left); } } } @@ -495,8 +514,9 @@ sub due_date { my $due_date= &Apache::lonnet::EXT("resource.$part_id.duedate",$symb, $udom,$uname); &Apache::lonxml::debug("looking for due_date $part_id $symb $due_date"); - if (defined($interval)) { + if ($interval =~ /\d+/) { my $first_access=&Apache::lonnet::get_first_access('map',$symb); + &Apache::lonxml::debug("looking for first_access $first_access"); if (defined($first_access)) { $interval = $first_access+$interval; $date = ($interval < $due_date)? $interval : $due_date; @@ -611,6 +631,13 @@ sub setuppermissions { return ''; } +sub unset_permissions { + undef($Apache::lonhomework::queuegrade); + undef($Apache::lonhomework::modifygrades); + undef($Apache::lonhomework::viewgrades); + undef($Apache::lonhomework::browse); +} + sub setupheader { my $request=$_[0]; &Apache::loncommon::content_type($request,'text/html'); @@ -797,7 +824,7 @@ sub editxmlmode { &Apache::loncommon::helpLatexCheatsheet("Problem_Editor_XML_Index", "Problem Editing Help"). ''. - &Apache::loncommon::help_open_menu('',undef,undef,undef,5,'Authoring'). + &Apache::loncommon::help_open_menu(undef,undef,5,'Authoring'). ''; if ($cols > 80) { $cols = 80; } if ($cols < 70) { $cols = 70; } @@ -942,7 +969,7 @@ sub newproblem { # 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'; + $request->dir_config('lonIncludes').'/templates/blank.'.$extension; &Apache::lonxml::debug("$templatefilename"); my $dest = &Apache::lonnet::filelocation("",$request->uri); copy($templatefilename,$dest); @@ -968,16 +995,19 @@ sub newproblem { 'click' => 'click on the', 'Create' => 'Create', 'button' => 'button'); - $request->print(<print(" $start_page -

$lt{'create'} $extension $lt{'resource'}

+

".&mt("Creating a new $extension resource.")."

$errormsg -$lt{'requested'} $shownurl $lt{'not exist'}. +".&mt("The requested file [_1] currently does not exist.", + "$shownurl")."

-$lt{'createnew'} $extension$instructions $lt{'click'} "$lt{'Create'} $extension" $lt{'button'}. -

-

-ENDNEWPROBLEM + +".&mt("To create a new $extension, select a template from the". + "pull-down menu below. Then click on the \"Create $extension\" button.")." +

"); + if (defined($templatelist)) { $request->print(""); } @@ -1010,10 +1040,15 @@ sub handler { if ($Apache::lonhomework::browse ne 'F' && $env{'request.state'} ne "construct") { #should know where we are, so ask - $request->internal_redirect('/adm/ambiguous'); return OK; + &unset_permissions(); + $request->internal_redirect('/adm/ambiguous'); + return OK; } } - if (&setupheader($request)) { return OK; } + if (&setupheader($request)) { + &unset_permissions(); + return OK; + } &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:$Apache::lonhomework::modifygrades:$Apache::lonhomework::queuegrade"); &Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'}); my ($symb) = &Apache::lonxml::whichuser(); @@ -1047,6 +1082,7 @@ sub handler { #&Apache::lonxml::debug("Spent $td seconds processing"); # always turn off debug messages $Apache::lonxml::debug=0; + &unset_permissions(); return OK; }