--- loncom/homework/structuretags.pm 2024/01/13 17:48:57 1.512.2.24.2.9 +++ loncom/homework/structuretags.pm 2024/02/27 19:46:23 1.512.2.24.2.10 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.512.2.24.2.9 2024/01/13 17:48:57 raeburn Exp $ +# $Id: structuretags.pm,v 1.512.2.24.2.10 2024/02/27 19:46:23 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1533,6 +1533,96 @@ sub store_aggregates { } } +sub access_status_msg { + my ($mode,$status,$symb,$target,$ipused,$accessmsg) = @_; + my $msg; + if ($target eq 'web') { + if ($status eq 'UNAVAILABLE') { + $msg.='

'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'

'; + } elsif ($status eq 'NOT_IN_A_SLOT') { + $msg.='

'.&mt('You are not currently signed up to work at this time and/or place.').'

'; + } elsif (($status eq 'RESERVABLE') || ($status eq 'RESERVABLE_LATER') || + ($status eq 'NOTRESERVABLE')) { + $msg.='

'.&mt('Access requires reservation to work at specific time/place.').'

'; + } elsif ($status ne 'NOT_YET_VIEWED') { + $msg.='

'.&mt('Not open to be viewed').'

'; + } + if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') { + $msg.=&mt('The problem ').$accessmsg; + } elsif ($status eq 'UNCHECKEDOUT') { + $msg.=&checkout_msg(); + } elsif ($status eq 'NOT_YET_VIEWED') { + $msg.=&firstaccess_msg($accessmsg,$symb); + } elsif ($status eq 'NOT_IN_A_SLOT') { + $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work"); + } elsif ($status eq 'RESERVABLE') { + $msg.=&mt('Available to make a reservation.').' '.&mt('Reservation window closes [_1].', + &Apache::lonnavmaps::timeToHumanString($accessmsg,'end')). + '
'. + &Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work"); + } elsif ($status eq 'RESERVABLE_LATER') { + $msg.=&mt('Window to make a reservation will open [_1].', + &Apache::lonnavmaps::timeToHumanString($accessmsg,'start')); + } elsif ($status eq 'NOTRESERVABLE') { + $msg.=&mt('Not available to make a reservation.'); + } + $msg.='
'; + } elsif ($target eq 'tex') { + my $startminipage = ($env{'form.problem_split'}=~/yes/i)? '' + : '\begin{minipage}{\textwidth}'; + + $msg ='\noindent \vskip 1 mm '. + $startminipage.'\vskip 0 mm'; + if ($status eq 'UNAVAILABLE') { + $msg.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm '; + } else { + $msg.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm "; + } + } + return $msg; +} + +sub checkin_prompt { + my ($target,$slot_name,$slot,$type) = @_; + my $result; + if ($target eq 'web') { + $result = &Apache::bridgetask::proctor_validation_screen($slot); + } elsif ($target eq 'grade') { + if (!&Apache::bridgetask::proctor_check_auth($slot_name,$slot,$type)) { + $result = &mt('An error occurred during check-in'); + } + } + return $result; +} + +sub selfcheckin_resource { + my ($resource_due,$slot_name,$slot,$symb) = @_; + if ($slot_name ne '') { + my $checked_in = + $Apache::lonhomework::history{'resource.0.checkedin'}; + if ($checked_in eq '') { + # unproctored slot access, self checkin + my $check = &Apache::bridgetask::check_in('problem',undef,undef, + $slot_name); + if ($check =~ /^error: /) { + &Apache::lonnet::logthis("Error during self-checkin of problem (symb: $symb) using slot: $slot_name"); + } else { + $checked_in = $Apache::lonhomework::results{"resource.0.checkedin"}; + } + } + if ((ref($slot) eq 'HASH') && ($checked_in ne '')) { + if ($slot->{'starttime'} < time()) { + if (!$resource_due) { + $resource_due = $slot->{'endtime'}; + } elsif ($slot->{'endtime'} < $resource_due) { + $resource_due = $slot->{'endtime'}; + } + } + } + } + return $resource_due; +} + sub checkout_msg { my %lt=&Apache::lonlocal::texthash( 'resource'=>'The resource needs to be checked out', @@ -1879,85 +1969,21 @@ sub start_problem { ( $status eq 'INVALID_ACCESS')) { my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser, $style); - if ( $target eq "web" ) { - my $msg; - if ($status eq 'UNAVAILABLE') { - $msg.='

'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'

'; - } elsif ($status eq 'NOT_IN_A_SLOT') { - $msg.='

'.&mt('You are not currently signed up to work at this time and/or place.').'

'; - } elsif (($status eq 'RESERVABLE') || ($status eq 'RESERVABLE_LATER') || - ($status eq 'NOTRESERVABLE')) { - $msg.='

'.&mt('Access requires reservation to work at specific time/place.').'

'; - } elsif ($status ne 'NOT_YET_VIEWED') { - $msg.='

'.&mt('Not open to be viewed').'

'; - } - if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') { - $msg.=&mt('The problem ').$accessmsg; - } elsif ($status eq 'UNCHECKEDOUT') { - $msg.=&checkout_msg(); - } elsif ($status eq 'NOT_YET_VIEWED') { - if ($firstaccres) { - $msg .= '

'. - &mt('A problem occurred when trying to start the timer.').'

'; - } - $msg.=&firstaccess_msg($accessmsg,$symb); - } elsif ($status eq 'NOT_IN_A_SLOT') { - $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work"); - } elsif ($status eq 'RESERVABLE') { - $msg.=&mt('Available to make a reservation.').' '.&mt('Reservation window closes [_1].', - &Apache::lonnavmaps::timeToHumanString($accessmsg,'end')). - '
'. - &Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work"); - } elsif ($status eq 'RESERVABLE_LATER') { - $msg.=&mt('Window to make a reservation will open [_1].', - &Apache::lonnavmaps::timeToHumanString($accessmsg,'start')); - } elsif ($status eq 'NOTRESERVABLE') { - $msg.=&mt('Not available to make a reservation.'); - } - $result.=$msg.'
'; - } elsif ($target eq 'tex') { - my $startminipage = ($env{'form.problem_split'}=~/yes/i)? '' - : '\begin{minipage}{\textwidth}'; - $result.='\noindent \vskip 1 mm '. - $startminipage.'\vskip 0 mm'; - if ($status eq 'UNAVAILABLE') { - $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm '; - } else { - $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm "; - } - } + if (($status eq 'NOT_YET_VIEWED') && ($firstaccres)) { + $result .= '

'. + &mt('A problem occurred when trying to start the timer.').'

'; + } + $result .= &access_status_msg('problem',$status,$symb,$target,$ipused,$accessmsg); } elsif ($status eq 'NEEDS_CHECKIN') { my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser, $style); - if ($target eq 'web') { - $result .= - &Apache::bridgetask::proctor_validation_screen($slot); - } elsif ($target eq 'grade') { - &Apache::bridgetask::proctor_check_auth($slot_name,$slot, - 'problem'); - } + $result .= &checkin_prompt($target,$slot_name,$slot,'problem'); } elsif ($target eq 'web') { if ($status eq 'CAN_ANSWER') { $resource_due = &Apache::lonhomework::due_date(0, $env{'request.symb'}); if ($slot_name ne '') { - my $checked_in = - $Apache::lonhomework::history{'resource.0.checkedin'}; - if ($checked_in eq '') { - # unproctored slot access, self checkin - &Apache::bridgetask::check_in('problem',undef,undef, - $slot_name); - $checked_in = - $Apache::lonhomework::results{"resource.0.checkedin"}; - } - if ((ref($slot) eq 'HASH') && ($checked_in ne '')) { - if ($slot->{'starttime'} < time()) { - if (!$resource_due) { - $resource_due = $slot->{'endtime'}; - } elsif ($slot->{'endtime'} < $resource_due) { - $resource_due = $slot->{'endtime'}; - } - } - } + $resource_due = &selfcheckin_resource($resource_due,$slot_name,$slot, + $env{'request.symb'}); } if ($resource_due) { my $time_left = $resource_due - time(); @@ -2000,8 +2026,6 @@ sub start_problem { } elsif ($target eq 'tex') { $result .= 'INSERTTEXFRONTMATTERHERE'; $result .= &select_metadata_hyphenation(); - - } } elsif ($target eq 'edit') { $result .= $form_tag_start.&problem_edit_header();