--- loncom/homework/bridgetask.pm	2006/03/30 16:50:18	1.128.2.4
+++ loncom/homework/bridgetask.pm	2006/06/24 01:32:25	1.128.2.12
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.128.2.4 2006/03/30 16:50:18 albertel Exp $
+# $Id: bridgetask.pm,v 1.128.2.12 2006/06/24 01:32:25 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -349,12 +349,15 @@ sub webgrade_standard_info {
 
     my %lt=&Apache::lonlocal::texthash('done' => 'Next Item',
 				       'stop' => 'Quit Grading',
+				       'fail' => 'Fail Rest',
 				       );
 				       
     my $result=<<INFO;
   <div class="LC_GRADING_maincontrols">
     <input type="submit" name="next" value="$lt{'done'}" />
     <input type="submit" name="stop" value="$lt{'stop'}" />
+    <input type="button" name="fail" value="$lt{'fail'}" 
+           onclick="javascript:onFailRest()" />
   </div>
   $file_list
 INFO
@@ -365,8 +368,8 @@ sub start_Task {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 
     my ($status,$accessmsg,$slot);
+    &Apache::structuretags::init_problem_globals('Task');
     if ($target ne 'webgrade') {
-	&Apache::structuretags::init_problem_globals('Task');
 	&Apache::structuretags::initialize_storage();
 	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
 	if ($env{'request.state'} eq 'construct') {
@@ -453,12 +456,33 @@ sub start_Task {
 		    my (undef,undef,$domain,$user)=
 			&Apache::lonxml::whichuser();
 		    my $files = '<ul>';
+		    my $msg;
 		    foreach my $file (@files) {
 			my $url="/uploaded/$domain/$user/portfolio$file";
 			$file = '<tt>'.$file.'</tt>';
 			$files .= '<li>'.$file.'</li>';
+			$msg .= "<p>Submitted file $file</p>\n";
 		    }
 		    $files.='</ul>';
+		    my $subject = "Submission message for $title";
+		    my ($message_status,$comment_status);
+		    my $setting = $env{'course.'.$env{'request.course.id'}.'.task_messages'};
+		    $setting =~ s/^\s*(\S*)\s*$/$1/;
+		    $setting = lc($setting);
+		    if ($setting eq 'only_student'
+			|| $setting eq 'student_and_user_notes_screen') {
+			$message_status =
+			    &Apache::lonmsg::user_normal_msg($user,$domain,$subject,$msg);
+			$message_status = '<p>'.&mt('Message sent to user: [_1]',
+						    $message_status).' </p>';
+		    }
+		    if ($setting eq 'student_and_user_notes_screen') {
+			$comment_status =
+			    &Apache::lonmsg::store_instructor_comment($subject.'<br />'.
+								      $msg,$user,$domain);
+			$comment_status = '<p>'.&mt('Message sent to instructor: [_1]',
+						    $comment_status).' </p>';
+		    }
 
 		    $result.=<<DONESCREEN;
 <h2>$title</h2>
@@ -467,6 +491,8 @@ sub start_Task {
 <hr />
 <p> <a href="/adm/logout">Logout</a> </p>
 <p> <a href="/adm/roles">Change to a different course</a> </p>
+$message_status
+$comment_status
 DONESCREEN
 		} elsif ($status ne 'NOT_YET_VIEWED') {
 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
@@ -992,6 +1018,7 @@ DONEBUTTON
 	$result.=&Apache::response::meta_stores_write('status','string',
 						      'Bridge Task Status');
     }
+    &Apache::structuretags::reset_problem_globals('Task');
     undef($Apache::lonhomework::parsing_a_task);
     return $result;
 }
@@ -1315,9 +1342,15 @@ sub pick_from_queue_data {
     if (@possible) {
         # sort entries in order by slot end time
 	@possible = sort { $a->[1] <=> $b->[1] } @possible;
-	# pick one of the first ten entries
-	my $max=($#possible < 10) ? $#possible : 10;
-	return $possible[int(rand($max))][0];
+	# pick one of the entries in the top 10% in small queues and one
+	# of the first ten entries in large queues
+	#my $ten_percent = int($#possible * 0.1);
+	#if ($ten_percent < 1 ) { $ten_percent = 1;  }
+	#if ($ten_percent > 10) { $ten_percent = 10; }
+	#my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
+	
+	#return $possible[int(rand($max))][0];
+	return $possible[0][0];
     }
     return undef;
 }
@@ -1760,9 +1793,7 @@ sub get_instance {
 		my $link=&link($instance,$id);
 		my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"};
 		$result.='<div class="LC_GRADING_criteria" id="'.$link.'">'."\n".
-		    '<a name="'.$link.'" />'."\n".
-		    '<a name="next_'.$last_link.'" />'."\n".
-		    '<div class="LC_GRADING_criteriatext">'."\n";
+		    '<div class="LC_GRADING_criteriatext" id="next_'.$last_link.'">'."\n";
 		@Apache::scripttag::parser_env = @_;
 		$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
 		$result.='</div>'."\n".
@@ -1789,7 +1820,13 @@ sub get_instance {
 	    my $mandatory_failed=0;
 	    my $ungraded=0;
 	    my $review=0;
+
+	    @Apache::scripttag::parser_env = @_;
+	    $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
+		@Apache::scripttag::parser_env = @_;
+		$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.tex
+t'});
 		my $link=&link($instance,$id);
 		my $status=$Apache::lonhomework::results{"resource.$version.0.$dim.$instance.$id.status"}=$env{'form.HWVAL_'.$link};
 		$Apache::lonhomework::results{"resource.$version.0.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
@@ -1866,7 +1903,7 @@ sub grading_history {
 sub start_IntroParagraph {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;
-    if ($target eq 'web' || $target eq 'webgrade') {
+    if ($target eq 'web' || $target eq 'web' || $target eq 'webgrade') {
 	if ($tagstack->[-2] eq 'Dimension') {
 	    $dimension{'intro'}=&Apache::lonxml::get_all_text('/introparagraph',$parser,$style);
 	
@@ -1907,7 +1944,7 @@ sub start_InstanceText {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $instance_id=$Apache::bridgetask::instance[-1];
     my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
-    if ($target eq 'web' || $target eq 'webgrade') {
+    if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
 	$dimension{$instance_id.'.text'}=$text;
     }
     return '';