--- loncom/homework/bridgetask.pm	2006/11/27 23:33:01	1.210
+++ loncom/homework/bridgetask.pm	2007/01/24 19:24:33	1.223
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.210 2006/11/27 23:33:01 albertel Exp $
+# $Id: bridgetask.pm,v 1.223 2007/01/24 19:24:33 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -98,6 +98,7 @@ sub check_in {
 	&check_in_sequence($user,$domain,$slot_name);
     } else {
 	&create_new_version($type,$user,$domain,$slot_name);
+	&Apache::structuretags::finalize_storage();
     }
     return 1;
 }
@@ -590,7 +591,6 @@ sub start_Task {
 	    &Apache::structuretags::page_start($target,$token,$tagstack,
 					       $parstack,$parser,$safeeval,
 					       $name,&style($target));
-	$result .= '<div class="LC_task">'."\n";
     }
 
     if ($target eq 'web' && $env{'request.state'} ne 'construct') {
@@ -639,6 +639,11 @@ sub start_Task {
 					  'slot' => $slot_name});
 	    ($version,$previous)=&get_version();
 	}
+	
+	my $status_id = 
+	    ($previous || $status eq 'SHOW_ANSWER') ? 'LC_task_feedback'
+	                                            : 'LC_task_take';
+	$result .= '<div class="LC_task" id="'.$status_id.'">'."\n";
 
 	push(@Apache::inputtags::status,$status);
 	$Apache::inputtags::slot_name=$slot_name;
@@ -706,6 +711,7 @@ sub start_Task {
 	      $target eq 'webgrade') {
 	my $webgrade='yes';
 	if ($target eq 'webgrade') {
+	    $result .= '<div class="LC_task">'."\n";
 	    $result.= "\n".'<div class="LC_GRADING_task">'."\n".
 		'<script type="text/javascript" 
                          src="/res/adm/includes/task_grading.js"></script>';
@@ -862,8 +868,8 @@ sub get_key_todo {
 	my ($symb,$cid)=&Apache::lonnet::whichuser();
 	my $cnum  = $env{'course.'.$cid.'.num'};
 	my $cdom  = $env{'course.'.$cid.'.domain'};
-	my $uname = $env{'form.gradinguser'};
-	my $udom  = $env{'form.gradingdomain'};
+	my $uname = &clean_username($env{'form.gradinguser'});
+	my $udom  = &clean_domain($env{'form.gradingdomain'});
 
 	my $gradingkey=&encode_queue_key($symb,$udom,$uname);
 
@@ -1061,27 +1067,30 @@ DONEBUTTON
 		    $start_time=&Apache::lonlocal::locallocaltime($start_time);
 
 		    my $status = 
-			"\n<div class='LC_$bt_status LC_criteria'>\n\t";
+			"\n<div class='LC_$bt_status LC_criteria LC_task_overall_status'>\n\t";
 		    
+		    my $dim = $top;
+		    my %counts = &get_counts($dim,undef,$parstack,
+					     $safeeval);
+		    my $question_status ="\n\t<p>".
+			&question_status_message(\%counts,-1).
+			"</p>\n";
+
 		    if ($bt_status eq 'pass')  {
 			$status.='<h2>You passed the '.$title.' given on '.
 			    $start_time.'</h2>';
+			$status.=$question_status;
 		    }
 		    if ($bt_status eq 'fail')  {
 			$status.='<h2>You did not pass the '.$title.' given on '.
 			    $start_time.'</h2>';
+			$status.=$question_status;
 			if (!$previous) {
 			    $status.=&add_request_another_attempt_button();
 			}
 		    }
-		    $status.="\n".'</div>'."\n";
-		    my $dim = $top;
-		    my %counts = &get_counts($dim,undef,$parstack,
-					     $safeeval);
-		    $status.="\n<div class='LC_$bt_status LC_criteria LC_task_overall_status'>\n\t<p>".
-			&question_status_message(\%counts,-1).
-			"</p>\n</div>\n";
 		    
+		    $status.="\n".'</div>'."\n";
 
 		    foreach my $id (@{$dimension{$dim}{'criterias'}}) {
 			my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
@@ -1113,7 +1122,8 @@ DONEBUTTON
 	}
 	
 
-	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
+	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous
+	    && $status eq 'CAN_ANSWER') {
 	    my $award='SUBMITTED';
 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
 						    'portfiles',\$award);
@@ -1574,9 +1584,16 @@ sub show_queue {
 		my $ekey=&escape($key);
 		my ($action,$description,$status)=('select',&mt('Select'));
 		if (exists($queue{"$key\0locked"})) {
+		    my ($locker,$time) = 
+			&get_lock_info($queue{"$key\0locked"});
+		    if ($time) {
+			$time = 
+			    &Apache::lonnavmaps::timeToHumanString($time,
+								   'start');
+		    }
 		    my $me=$env{'user.name'}.':'.$env{'user.domain'};
-		    $status=&mt('Locked by <tt>[_1]</tt>',$queue{"$key\0locked"});
-		    if ($me eq $queue{"$key\0locked"}) {
+		    $status=&mt('Locked by <tt>[_1]</tt> [_2]',$locker,$time);
+		    if ($me eq $locker) {
 			($action,$description)=('resume',&mt('Resume'));
 		    } else {
 			($action,$description)=('unlock',&mt('Unlock'));
@@ -1686,7 +1703,7 @@ sub queue_key_locked {
     my ($key_locked,$value)=
 	&Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
     if ($key_locked eq "$key\0locked") {
-	return $value;
+	return &get_lock_info($value);
     }
     return undef;
 }
@@ -1767,6 +1784,24 @@ sub pick_from_queue_data {
     return undef;
 }
 
+sub get_lock_info {
+    my ($lock_info) = @_;
+    if (wantarray) {
+	if (ref($lock_info) eq 'ARRAY') {
+	    return @{$lock_info};
+	} else {
+	    return ($lock_info);
+	}
+    } else {
+	if (ref($lock_info) eq 'ARRAY') {
+	    return $lock_info->[0];
+	} else {
+	    return $lock_info;
+	}
+    }
+    return;
+}
+
 sub find_mid_grade {
     my ($queue,$symb,$cdom,$cnum)=@_;
     my $todo=&unescape($env{'form.gradingkey'});
@@ -1778,7 +1813,7 @@ sub find_mid_grade {
     my $regexp="^$symb\0.*\0locked\$";
     my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
     foreach my $key (keys(%locks)) {
-	my $who=$locks{$key};
+	my $who= &get_lock_info($locks{$key});
 	if ($who eq $me) {
 	    $todo=$key;
 	    $todo=~s/\0locked$//;
@@ -1794,7 +1829,7 @@ sub lock_key {
     my (undef,$cid)=&Apache::lonnet::whichuser();
     my $cnum=$env{'course.'.$cid.'.num'};
     my $cdom=$env{'course.'.$cid.'.domain'};
-    my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
+    my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> [$me,time]},
 					$cdom,$cnum);
     &Apache::lonxml::debug("success $success $todo");
     if ($success eq 'ok') {
@@ -2210,7 +2245,6 @@ sub end_Dimension {
     my $result=&Apache::lonxml::endredirection();
     my $dim=&get_id($parstack,$safeeval);
     if (&skip_dimension_parsing($dim)) {
-	&disable_dimension_parsing($dim);
 	pop(@Apache::bridgetask::dimension);
 	return;
     }
@@ -2250,13 +2284,15 @@ sub end_Dimension {
 		}
 		my $dim_info=
 		    "\n<div class='LC_$dim_status LC_question_grade'>\n\t";
-		my $question = ('sub' x $dimension{$dim}{'depth'}).'question';
-		$question =~ s/^(.)/uc($1)/e;
+		my $ucquestion = 
+		    my $question = 
+		    ('sub' x $dimension{$dim}{'depth'}).'question';
+		$ucquestion =~ s/^(.)/uc($1)/e;
 		if ($dim_status eq 'pass') {
-		    $dim_info.='<h3>'.$question.' : you passed the above '.$mandatory.' question</h3>';
+		    $dim_info.='<h3>'.$ucquestion.' : you passed this '.$mandatory.' '.$question.'</h3>';
 		}
 		if ($dim_status eq 'fail') {
-		    $dim_info.='<h3>'.$question.' : you did not pass the above '.$mandatory.' question</h3>';
+		    $dim_info.='<h3>'.$ucquestion.' : you did not pass this '.$mandatory.' '.$question.'</h3>';
 		}
 		my %counts = &get_counts($dim,$instance,$parstack,
 					 $safeeval);
@@ -2300,8 +2336,8 @@ sub end_Dimension {
 	    # those old ones will continue to work.  # It puts the
 	    # LC_question div to come after any starting closie div
 	    # that the dimension produces
-	    if ($result =~ m{\s*</div>}) {
-		$result =~ s{(\s*</div>)}
+	    if ($result =~ m{^\s*</div>}) {
+		$result =~ s{^(\s*</div>)}
 		            {$1\n<div id="$dim" class="LC_question">};
 	    } else {
 		$result = "\n".'<div id="'.$dim.'" class="LC_question">'.
@@ -2429,7 +2465,7 @@ sub question_status_message {
 	foreach my $type ('cri','dim') {
 	    if ($counts->{$req.'_'.$type}) {
 		push(@sections,
-		     $counts->{$req.'_'.$type.'_passed'}.' of '.
+		     $counts->{$req.'_'.$type.'_passed'}.' of the '.
 		     $counts->{$req.'_'.$type}.' '.
 		     $req{$req}.' '.$type{$type});
 	    }
@@ -2449,7 +2485,15 @@ sub question_status_message {
     $status .= '.';
     if ($counts->{'opt'}) {
 	$status .= ' You were required to pass '.$counts->{'opt_req'}.
-	    ' optional component'.($counts->{'opt_req'} == 1?'':'s');
+	    ' optional ';
+	if ($counts->{'opt_dim'} + $counts->{'man_dim'} < 1) {
+	    $status .=
+		($counts->{'opt_req'} == 1?'criterion':'criteria');
+	} else {
+	    $status .=
+		'component'.($counts->{'opt_req'} == 1?'':'s');
+	}
+	$status .= '.';
     }
     return $status;
 }