[LON-CAPA-cvs] cvs: loncom /homework inputtags.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 01 Mar 2007 02:30:05 -0000


This is a MIME encoded message

--albertel1172716205
Content-Type: text/plain

albertel		Wed Feb 28 21:30:05 2007 EDT

  Modified files:              
    /loncom/homework	inputtags.pm 
  Log:
  - add in a previous tries display BUG#2622
  
  
--albertel1172716205
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20070228213005.txt"

Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.216 loncom/homework/inputtags.pm:1.217
--- loncom/homework/inputtags.pm:1.216	Tue Feb 27 14:43:16 2007
+++ loncom/homework/inputtags.pm	Wed Feb 28 21:30:03 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # input  definitons
 #
-# $Id: inputtags.pm,v 1.216 2007/02/27 19:43:16 banghart Exp $
+# $Id: inputtags.pm,v 1.217 2007/03/01 02:30:03 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -70,6 +70,10 @@
 #  %Apache::inputtags::answertxt    - <*response> tags store correct
 #                                     answer strings for display by <textline/>
 #                                     in this hash.
+#  %Apache::inputtags::submission_display
+#                                   - <*response> tags store improved display
+#                                     of submission strings for display by part
+#                                     end.
 
 sub initialize_inputtags {
     @Apache::inputtags::input=();
@@ -88,6 +92,7 @@
     @Apache::inputtags::importlist=();
     $Apache::inputtags::response_with_no_part=0;
     %Apache::inputtags::answertxt=();
+    %Apache::inputtags::submission_display=();
 }
 
 sub check_for_duplicate_ids {
@@ -994,10 +999,82 @@
     return '';
 }
 
+sub get_grade_messages {
+    my ($id,$prefix,$target,$status) = @_;
+
+    my ($message,$latemessage,$trystr,$previousmsg);
+    my $showbutton = 1;
+
+    my $award = $Apache::lonhomework::history{"$prefix.award"};
+    my $awarded = $Apache::lonhomework::history{"$prefix.awarded"};
+    my $solved = $Apache::lonhomework::history{"$prefix.solved"};
+    my $previous = $Apache::lonhomework::history{"$prefix.previous"};
+    my $awardmsg = $Apache::lonhomework::history{"$prefix.awardmsg"};
+    &Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
+    if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
+	&Apache::lonxml::debug('Getting message');
+	($showbutton,my $bgcolor,$message,$previousmsg) =
+	    &decideoutput($award,$awarded,$awardmsg,$solved,$previous,
+			  $target);
+	if ($target eq 'tex') {
+	    $message='\vskip 2 mm '.$message.' ';
+	} else {
+	    $message="<td bgcolor=\"$bgcolor\">$message</td>";
+	    if ($previousmsg) {
+		$previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
+	    }
+	}
+    }
+    my $tries = $Apache::lonhomework::history{"$prefix.tries"};
+    my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
+    &Apache::lonxml::debug("got maxtries of :$maxtries:");
+    #if tries are set to negative turn off the Tries/Button and messages
+    if (defined($maxtries) && $maxtries < 0) { return ''; }
+    if ( $tries eq '' ) { $tries = '0'; }
+    if ( $maxtries eq '' ) { $maxtries = '2'; } 
+    if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } 
+    my $tries_text=&mt('Tries');
+    if ( $Apache::lonhomework::type eq 'survey' ||
+	 $Apache::lonhomework::parsing_a_task) {
+	$tries_text=&mt('Submissions');
+    }
+
+    if ($showbutton) {
+	if ($target eq 'tex') {
+	    if ($env{'request.state'} ne "construct"
+		&& $Apache::lonhomework::type ne 'exam'
+		&& $env{'form.suppress_tries'} ne 'yes') {
+		$trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.
+		    $tries.'/'.$maxtries.'} \vskip 2 mm ';
+	    } else {
+		$trystr = '\vskip 0 mm ';
+	    }
+	} else {
+	    $trystr = "<td><nobr>".$tries_text." $tries";
+	    if ($Apache::lonhomework::parsing_a_task) {
+	    } elsif($env{'request.state'} ne 'construct') {
+		$trystr.="/$maxtries";
+	    } else {
+		if (defined($Apache::inputtags::params{'maxtries'})) {
+		    $trystr.="/".$Apache::inputtags::params{'maxtries'};
+		}
+	    }
+	    $trystr.="</nobr></td>";
+	}
+    }
+    if ($Apache::lonhomework::history{"$prefix.afterduedate"}) {
+	#last submissions was after due date
+	$latemessage=&mt(' The last submission was after the Due Date ');;
+	if ($target eq 'web') {
+	    $latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
+	}
+    }
+    return ($previousmsg,$latemessage,$message,$trystr,$showbutton);
+}
+
 sub gradestatus {
     my ($id,$target) = @_;
     my $showbutton = 1;
-    my $bgcolor = '';
     my $message = '';
     my $latemessage = '';
     my $trystr='';
@@ -1011,72 +1088,19 @@
 	 && $status ne 'INVALID_ACCESS' 
 	 && $status ne 'NEEDS_CHECKIN' 
 	 && $status ne 'NOT_IN_A_SLOT') {  
-	my $award = $Apache::lonhomework::history{"resource.$id.award"};
-	my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
-	my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
-	my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
-	my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
-	&Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
-	if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
-	    &Apache::lonxml::debug('Getting message');
-	    ($showbutton,$bgcolor,$message,$previousmsg) =
-		&decideoutput($award,$awarded,$awardmsg,$solved,$previous,
-			      $target);
-	    if ($target eq 'tex') {
-		$message='\vskip 2 mm '.$message.' ';
-	    } else {
-		$message="<td bgcolor=\"$bgcolor\">$message</td>";
-		if ($previousmsg) {
-		    $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
-		}
-	    }
-	}
-	my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
-	my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
-	&Apache::lonxml::debug("got maxtries of :$maxtries:");
-	#if tries are set to negative turn off the Tries/Button and messages
-	if (defined($maxtries) && $maxtries < 0) { return ''; }
-	if ( $tries eq '' ) { $tries = '0'; }
-	if ( $maxtries eq '' ) { $maxtries = '2'; } 
-	if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } 
-	my $tries_text=&mt('Tries');
-	if ( $Apache::lonhomework::type eq 'survey' ||
-	     $Apache::lonhomework::parsing_a_task) {
-	    $tries_text=&mt('Submissions');
-	}
-	if ( $showbutton ) {
-	    if ($target eq 'tex') {
-		if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {
-		    $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
-		} else {
-		    $trystr = '\vskip 0 mm ';
-		}
-	    } else {
-		$trystr = "<td><nobr>".$tries_text." $tries";
-		if ($Apache::lonhomework::parsing_a_task) {
-		} elsif($env{'request.state'} ne 'construct') {
-		    $trystr.="/$maxtries";
-		} else {
-		    if (defined($Apache::inputtags::params{'maxtries'})) {
-			$trystr.="/".$Apache::inputtags::params{'maxtries'};
-		    }
-		}
-		$trystr.="</nobr></td>";
-	    }
+
+	($previousmsg,$latemessage,$message,$trystr) =
+	    &get_grade_messages($id,"resource.$id",$target,$status,
+				$showbutton);
+	if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {
+	    $showbutton = 0;
 	}
-	if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
 	if ( $showbutton ) { 
 	    if ($target ne 'tex') {
 		$button = '<input onsubmit="javascript:setSubmittedPart(\''.$id.'\')" type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
 	    }
 	}
-	if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
-	    #last submissions was after due date
-	    $latemessage=&mt(' The last submission was after the Due Date ');;
-	    if ($target eq 'web') {
-		$latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
-	    }
-	}
+
     }
     my $output= $previousmsg.$latemessage.$message.$trystr;
     if ($output =~ /^\s*$/) {
@@ -1085,10 +1109,76 @@
 	if ($target eq 'tex') {
 	    return $button.' \vskip 0 mm '.$output.' ';
 	} else {
-	    return '<table><tr><td>'.$button.'</td>'.$output.'</tr></table>';
+	    return '<table><tr><td>'.$button.'</td>'.$output.'<td>'.&previous_tries($id,$target).'</td></tr></table>';
 	}
     }
 }
+
+sub previous_tries {
+    my ($id,$target) = @_;
+    my $output;
+    my $status = $Apache::inputtags::status['-1'];
+    
+    foreach my $i (1..$Apache::lonhomework::history{'version'}) {
+	my $prefix = $i.":resource.$id";
+
+	next if (!exists($Apache::lonhomework::history{"$prefix.award"}));
+	my ($previousmsg,$latemessage,$message,$trystr);
+
+	($previousmsg,$latemessage,$message,$trystr) =
+	    &get_grade_messages($id,"$prefix",$target,$status);
+	if (!exists($Apache::lonhomework::history{"$prefix.tries"})) {
+	    undef($trystr);
+	}
+
+	if ($previousmsg eq '') { $previousmsg='<td></td>'; }
+	if ($trystr eq '') { $trystr = '<td></td>'; }
+
+	$output.='<tr>';
+	$output.=$message.$previousmsg.$trystr;
+
+	foreach my $resid (@Apache::inputtags::response) {
+	    my $prefix = $prefix.".$resid";
+	    if (exists($Apache::lonhomework::history{"$prefix.submission"})) {
+		my $submission =
+		    $Apache::inputtags::submission_display{"$prefix.submission"};
+		if (!defined($submission)) {
+		    $submission = 
+			$Apache::lonhomework::history{"$prefix.submission"};
+		}
+		$output.='<td>'.$submission.'</td>';
+	    } else {
+		$output.='<td></td>';
+	    }
+	}
+	$output.='</tr>';
+    }
+    return if ($output eq '');
+
+    $output ='<table class="LC_prior_tries">'.$output.'</table>';
+    #return $output;
+    $output=~s/\\/\\\\/g;
+    $output=~s/\'/\\\'/g;
+    $output=~s/\s+/ /g;
+    my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
+    my $start_page =
+	&Apache::loncommon::start_page('Previous Tries', undef,
+				       {'only_body' => 1,
+					'bgcolor'   => '#FFFFFF',
+					'js_ready'  => 1,});
+    my $end_page =
+	&Apache::loncommon::end_page({'js_ready' => 1,});
+    
+    my $result ="<script type=\"text/javascript\">
+// <![CDATA[
+    function LONCAPA_previous_tries_$Apache::lonxml::curdepth() {newWindow=open('','new_W','width=500,height=500,scrollbars=1,resizable=yes');newWindow.$windowopen;newWindow.document.writeln('$start_page $output $end_page');newWindow.document.close();newWindow.focus()}
+// ]]>
+</script><a href=\"javascript:LONCAPA_previous_tries_$Apache::lonxml::curdepth();void(0);\">".&mt("Previous Tries")."</a><br />";
+    #use Data::Dumper;
+    #&Apache::lonnet::logthis(&Dumper(\%Apache::inputtags::submission_display));
+    return $result;
+}
+
 1;
 __END__
  

--albertel1172716205--