--- loncom/homework/lonhomework.pm 2011/02/06 18:43:10 1.323 +++ loncom/homework/lonhomework.pm 2012/12/18 16:48:19 1.336 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.323 2011/02/06 18:43:10 www Exp $ +# $Id: lonhomework.pm,v 1.336 2012/12/18 16:48:19 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -147,6 +147,8 @@ sub get_target { } else { if ($env{'form.problemstate'} eq 'WEB_GRADE') { return ('grade','webgrade','answer'); + } elsif ($env{'form.problemmode'} eq 'view') { + return ('grade','web','answer'); } elsif ($env{'form.problemmode'} eq 'saveview') { return ('modified','web','answer'); } elsif ($env{'form.problemmode'} eq 'discard') { @@ -244,20 +246,24 @@ sub check_slot_access { # } my $slotstatus='NOT_IN_A_SLOT'; my ($returned_slot,$slot_name); + my $now = time; + my $num_usable_slots = 0; foreach my $slot (@slots) { $slot =~ s/(^\s*|\s*$)//g; &Apache::lonxml::debug("getting $slot"); my %slot=&Apache::lonnet::get_slot($slot); &Apache::lonhomework::showhash(%slot); - if ($slot{'starttime'} < time && - $slot{'endtime'} > time && + next if ($slot{'endtime'} < $now); + $num_usable_slots ++; + if ($slot{'starttime'} < $now && + $slot{'endtime'} > $now && &Apache::loncommon::check_ip_acc($slot{'ip'})) { &Apache::lonxml::debug("$slot is good"); $slotstatus='NEEDS_CHECKIN'; $returned_slot=\%slot; $slot_name=$slot; last; - } + } } if ($slotstatus eq 'NEEDS_CHECKIN' && &proctor_checked_in($slot_name,$returned_slot,$type)) { @@ -297,11 +303,36 @@ sub check_slot_access { # However, the problem is not closed, and potentially, another slot might be # used to gain access to it to work on it, until the due date is reached, and the # problem then becomes CLOSED. Therefore return the slotstatus - - # (which will be NOT_IN_SLOT). - if (!defined($slot_name) - && $checkedin - && $type eq 'problem') { - return ($slotstatus); + # (which will be one of: NOT_IN_A_SLOT, RESERVABLE, RESERVABLE_LATER, or NOTRESERVABLE. + if (!defined($slot_name) && $type eq 'problem') { + if ($slotstatus eq 'NOT_IN_A_SLOT') { + if (!$num_usable_slots) { + if ($env{'request.course.id'}) { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my ($symb)=&Apache::lonnet::whichuser(); + $slotstatus = 'NOTRESERVABLE'; + my ($reservable_now_order,$reservable_now,$reservable_future_order, + $reservable_future) = + &Apache::loncommon::get_future_slots($cnum,$cdom,$now,$symb); + if ((ref($reservable_now_order) eq 'ARRAY') && (ref($reservable_now) eq 'HASH')) { + if (@{$reservable_now_order} > 0) { + $slotstatus = 'RESERVABLE'; + $datemsg = $reservable_now->{$reservable_now_order->[-1]}{'endreserve'}; + } + } + unless ($slotstatus eq 'RESERVABLE') { + if ((ref($reservable_future_order) eq 'ARRAY') && (ref($reservable_future) eq 'HASH')) { + if (@{$reservable_future_order} > 0) { + $slotstatus = 'RESERVABLE_LATER'; + $datemsg = $reservable_future->{$reservable_future_order->[0]}{'startreserve'}; + } + } + } + } + } + } + return ($slotstatus,$datemsg); } if ($slotstatus eq 'NOT_IN_A_SLOT' @@ -374,7 +405,12 @@ sub check_access { $date=&mt("can not be accessed from your location."); return($status,$date); } - + if ($env{'form.grade_imsexport'}) { + if (($env{'request.course.id'}) && + (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) { + return ('SHOW_ANSWER'); + } + } foreach my $temp ("opendate","duedate","answerdate") { $lastdate = $date; if ($temp eq 'duedate') { @@ -432,13 +468,16 @@ sub check_access { if ( $tries eq '' ) { $tries = '0'; } if ( $maxtries eq '' && $env{'request.state'} ne 'construct') { $maxtries = '2'; } + $Apache::lonhomework::results{'resource.'.$id.'.maxtries'}=$maxtries; if ($maxtries && $tries >= $maxtries) { $status = 'CANNOT_ANSWER'; } # if (correct and show prob status) or excused then CANNOT_ANSWER - if(($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/ - && - &show_problem_status()) - || - $Apache::lonhomework::history{"resource.$id.solved"}=~/^excused/) { + if ( ($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/) + && (&show_problem_status()) ) { + if (($Apache::lonhomework::history{"resource.$id.awarded"} >= 1) || + (&Apache::lonnet::EXT("resource.$id.retrypartial") !~/^1|on|yes$/i)) { + $status = 'CANNOT_ANSWER'; + } + } elsif ($Apache::lonhomework::history{"resource.$id.solved"}=~/^excused/) { $status = 'CANNOT_ANSWER'; } if ($status eq 'CANNOT_ANSWER' @@ -688,7 +727,7 @@ sub analyze_header { my $js = &Apache::structuretags::setmode_javascript(); # Breadcrumbs - my $brcrum = [{'href' => &Apache::loncommon::authorspace(), + my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri), 'text' => 'Construction Space'}, {'href' => '', 'text' => 'Problem Testing'}, @@ -740,13 +779,9 @@ sub analyze { my $rndseed=$env{'form.rndseed'}; &analyze_header($request); my %prog_state= - &Apache::lonhtmlcommon::Create_PrgWin($request,&mt('Analyze Progress'), - &mt('Getting Problem Variants'), - $env{'form.numtoanalyze'}, - 'inline',undef); + &Apache::lonhtmlcommon::Create_PrgWin($request,$env{'form.numtoanalyze'}); for(my $i=1;$i<$env{'form.numtoanalyze'}+1;$i++) { - &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state, - &mt('last problem')); + &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state,'last problem'); if (&Apache::loncommon::connection_aborted($request)) { return; } my $thisseed=$i+$rndseed; my $subresult=&Apache::lonnet::ssi($request->uri, @@ -755,7 +790,7 @@ sub analyze { (my $garbage,$subresult)=split(/_HASH_REF__/,$subresult,2); my %analyze=&Apache::lonnet::str2hash($subresult); my @parts; - if (defined(@{ $analyze{'parts'} })) { + if (ref($analyze{'parts'}) eq 'ARRAY') { @parts=@{ $analyze{'parts'} }; } foreach my $part (@parts) { @@ -788,15 +823,15 @@ sub analyze { } } } - &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state, - &mt('Analyzing Results')); + &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state,&mt('Analyzing Results')); $request->print('
' .'

' .&mt('List of possible answers') .'

' ); foreach my $part (sort(keys(%allparts))) { - if (defined(@{ $overall{$part.'.answer'} })) { + if ((ref($overall{$part.'.answer'}) eq 'ARRAY') && + (@{$overall{$part.'.answer'}} > 0)) { for (my $i=0;$iprint(&Apache::loncommon::start_data_table() @@ -894,10 +929,10 @@ sub editxmlmode { my $problem=&Apache::lonnet::getfile($file); if ($problem eq -1) { &Apache::lonxml::error( - ' ' + '

' .&mt('Unable to find [_1]', ''.$file.'') - .''); + .'

'); $problem=''; } @@ -926,7 +961,7 @@ sub editxmlmode { &Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); # Breadcrumbs - my $brcrum = [{'href' => &Apache::loncommon::authorspace(), + my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri), 'text' => 'Construction Space'}, {'href' => '', 'text' => 'Problem Editing'}]; @@ -1004,9 +1039,10 @@ sub renderpage { $problem=''; my $filename=(split('/',$file))[-1]; my $error = - " ".&mt('Unable to find [_1]', + '

' + .&mt('Unable to find [_1]', ''.$filename.'') - .""; + ."

"; $result.= &Apache::loncommon::simple_error_page($request,'Not available', $error); @@ -1088,6 +1124,7 @@ sub get_template_list { my $count = 0; my $currentcategory=''; my $first = 1; + my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; foreach my $file (@files) { next if ($file->[1] !~ /\S/); if ($file->[2] ne $currentcategory) { @@ -1111,9 +1148,9 @@ sub get_template_list { $result.=&Apache::loncommon::help_open_topic($file->[3]); } my $filename=$file->[0]; - $filename=~s/^\/home\/httpd\/html//; + $filename=~s{^\Q$londocroot\E}{}; $result.=' ' - .''.&mt('Example').'' + .&Apache::loncommon::modal_link($filename.'?inhibitmenu=yes',&mt('Example'),600,420,'sample') .'
'."\n"; $count ++; } @@ -1147,12 +1184,10 @@ sub newproblem { &renderpage($request,$dest); } else { my $url=&HTML::Entities::encode($request->uri,'<>&"'); - my $shownurl=$url; - $shownurl=~s-^/~-/priv/-; my $dest = &Apache::lonnet::filelocation("",$request->uri); my $errormsg; my $instructions; - my $brcrum = [{'href' => &Apache::loncommon::authorspace(), + my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri), 'text' => 'Construction Space'}, {'href' => '', 'text' => "Create New $extension"}]; @@ -1167,7 +1202,7 @@ sub newproblem { .'

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

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

'.&mt("To create a new $extension, select a template from the". " list below. Then click on the \"Create $extension\" button.").'