--- loncom/homework/bridgetask.pm	2009/03/20 10:05:00	1.245
+++ loncom/homework/bridgetask.pm	2010/04/01 00:37:15	1.251
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.245 2009/03/20 10:05:00 bisitz Exp $
+# $Id: bridgetask.pm,v 1.251 2010/04/01 00:37:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -82,7 +82,10 @@ sub proctor_check_auth {
 		}
 	    }
 	    if ($authenticated) {
-		&check_in($type,$user,$domain,$slot_name);
+		my $check = &check_in($type,$user,$domain,$slot_name);
+                if ($check =~ /^error:/) {
+                    return 0;
+                }
 		return 1;
 	    }
 	}
@@ -94,7 +97,10 @@ sub check_in {
     my ($type,$user,$domain,$slot_name) = @_;
     my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
     if ( $useslots eq 'map_map') {
-	&check_in_sequence($user,$domain,$slot_name);
+	my $result = &check_in_sequence($user,$domain,$slot_name);
+        if ($result =~ /^error: /) {
+            return $result;
+        }
     } else {
 	&create_new_version($type,$user,$domain,$slot_name);
 	&Apache::structuretags::finalize_storage();
@@ -105,6 +111,9 @@ sub check_in {
 sub check_in_sequence {
     my ($user,$domain,$slot_name) = @_;
     my $navmap = Apache::lonnavmaps::navmap->new();
+    if (!defined($navmap)) {
+        return 'error: ';
+    }
     my ($symb) = &Apache::lonnet::whichuser();
     my ($map)  = &Apache::lonnet::decode_symb($symb);
     my @resources = 
@@ -306,7 +315,7 @@ sub add_request_another_attempt_button {
     my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
     my $action='get_reservation';
     if ($slot_name) {
-	$text=&mt('Change reservation.');
+	$text=&mt('Change reservation');
 	$action='change_reservation';
 	my $description=&Apache::slotrequest::get_description($slot_name,
 							      $slot);
@@ -655,7 +664,11 @@ sub start_Task {
 	if ($status eq 'CAN_ANSWER' && $version eq '') {
 	    # CAN_ANSWER mode, and no current version, unproctored access
 	    # thus self-checkedin
-	    &check_in('Task',undef,undef,$slot_name);
+	    my $check = &check_in('Task',undef,undef,$slot_name);
+            if ($check =~ /^error: /) {
+                my $symb=&Apache::lonnet::symbread();
+                &Apache::lonnet::logthis("Error during self-checkin of version $version of Task (symb: $symb) using slot: $slot_name");   
+            }
 	    &add_to_queue('gradingqueue',{'type' => 'Task',
 					  'time' => time,
 					  'slot' => $slot_name});
@@ -685,7 +698,7 @@ sub start_Task {
 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
 		} elsif ($status eq 'NOT_IN_A_SLOT') {
 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
-		    $msg.=&add_request_another_attempt_button("Sign up for time to work.");
+		    $msg.=&add_request_another_attempt_button("Sign up for time to work");
 		} elsif ($status eq 'NEEDS_CHECKIN') {
 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
 			'</h1>'.&proctor_validation_screen($slot);
@@ -701,7 +714,7 @@ sub start_Task {
 		}
 		$result.=$msg.'<br />';
 	    } elsif ($target eq 'tex') {
-		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
+		$result.='\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\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 {
@@ -1295,8 +1308,25 @@ DONEBUTTON
 		    $Apache::lonhomework::results{"resource.$version.0.solved"};
 	    }
 	    &minimize_storage();
-	    &Apache::structuretags::finalize_storage();
-	    
+            my $canstore;
+            if ($env{'form.gradingkey'}) {
+                my ($symb,$courseid,$domain,$name) =
+                    &Apache::lonnet::whichuser();
+                my $todo=&unescape($env{'form.gradingkey'});
+                my ($keysymb,$uname,$udom)=&decode_queue_key($todo);
+                if ($symb eq $keysymb) {
+                    if (($domain eq $udom) && ($name eq $uname)) {
+                        $canstore = 1;           
+                    }
+                }
+            }
+            if ($canstore) {
+	        &Apache::structuretags::finalize_storage();
+            } else {
+                $result .= '<br /><div class="LC_error">'.
+                           &mt('Information extracted from the current gradingkey was for a different BT or user from those for which grading data are to be stored.').' '.&mt('No grading changes stored.').'</div><br />';  
+            }
+
 	    # data stored, now handle queue
 	    if ($review) {
 		if ($env{'form.queue'} eq 'reviewqueue') {
@@ -1382,6 +1412,13 @@ DONEBUTTON
     }
     &Apache::structuretags::reset_problem_globals('Task');
     undef($Apache::lonhomework::parsing_a_task);
+    if ( ($target eq 'grade' && $env{'form.webgrade'}) ||
+          $target eq 'webgrade') {
+        delete($env{'form.grade_symb'});
+        delete($env{'form.grade_domain'});
+        delete($env{'form.grade_username'});
+        delete($env{'form.grade_courseid'});
+    }
     return $result;
 }
 
@@ -2994,14 +3031,14 @@ sub layout_webgrade_Criteria {
     $comment = &HTML::Entities::encode($comment,'<>"&');
     my %checked;
     foreach my $which ('ungraded','fail','pass','review') {
-	if ($status eq $which) { $checked{$which} = 'checked="checked"'; }
+	if ($status eq $which) { $checked{$which} = ' checked="checked"'; }
     }
-    if (!%checked) { $checked{'ungraded'} = 'checked="checked"'; }
+    if (!%checked) { $checked{'ungraded'} = ' checked="checked"'; }
     my $buttons;
     foreach my $which  ('ungraded','fail','pass','review') {
 	$buttons .= <<END_BUTTON;
 		<label class="LC_GRADING_$which">
-			<input type="radio" name="HWVAL_$link" value="$which" $checked{$which} />
+			<input type="radio" name="HWVAL_$link" value="$which"$checked{$which} />
 			$lt{$which}
 		</label>
 END_BUTTON
@@ -3144,7 +3181,7 @@ sub proctor_validation_screen {
                             'vali'  => 'Validate',
                             'stui'  => "Student who should be logged in is:",
                             'name'  => "Name:",
-                            'sid'   => "Student/Employee ID:",
+                            'sid'   => "Student/Employee ID",
                             'unam'  => "Username:",
                            );
     my $result= (<<ENDCHECKOUT);