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

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 20 May 2005 21:23:43 -0000


albertel		Fri May 20 17:23:43 2005 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm 
  Log:
  - show previous version works
  
  
Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.28 loncom/homework/bridgetask.pm:1.29
--- loncom/homework/bridgetask.pm:1.28	Fri May 20 14:53:53 2005
+++ loncom/homework/bridgetask.pm	Fri May 20 17:23:42 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.28 2005/05/20 18:53:53 albertel Exp $
+# $Id: bridgetask.pm,v 1.29 2005/05/20 21:23:42 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -89,33 +89,59 @@
 }
 
 sub get_version {
+    my ($version,$previous);
     if ($env{'form.previousversion'} && 
 	defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
-	return $env{'form.previousversion'};
+	$version=$env{'form.previousversion'};
+	$previous=1;
+    } else {
+	$version=$Apache::lonhomework::history{'resource.version'};
+	$previous=0;
+    }
+    if (wantarray) {
+	return ($version,$previous);
     }
-    return $Apache::lonhomework::history{'resource.version'};
+    return $version;
 }
 
 sub add_previous_version_button {
     my ($status)=@_;
     my $result;
-    if ($Apache::lonhomework::history{'resource.version'} eq '0') {
+    if ($Apache::lonhomework::history{'resource.version'} eq '') {
 	return '';
     }
-    my $version=&get_version();
-    if ($version ne $Apache::lonhomework::history{'resource.version'}) {
+    if ($Apache::lonhomework::history{'resource.version'} < 2 &&
+	$status ne 'NEEDS_CHECKIN') {
 	return '';
     }
-
-    $result.=&mt(' Show a previously done version: [_1]','<select name="previousversion">
-<option>Pick one</option>
-</select>');
+    my $version=&get_version();
+    if ($env{'form.previousversion'} ne '' &&
+	$env{'form.previousversion'} eq $version) {
+	$result.="<h3>".&mt("Showing previous version [_1]",$version).
+	    "</h3>\n";
+    }
+    my @to_show;
+    foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) {
+	if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) {
+	    push(@to_show,$test_version);
+	}
+    }
+    my $list='<option>'.
+	join("</option>\n<option>",@to_show).
+	     "</option>\n";
+    $result.='<form name="getprevious" method="POST" action="';
+    my $uri=$env{'request.uri'};
+    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
+    $result.=$uri.'">'.
+	&mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
+<option>'.&mt('Pick one').'</option>
+'.$list.'
+</select>')."</form>";
     return $result;
 }
 
 sub add_grading_button {
-    my $result;
-    $result.=' <input type="submit" name="gradeasubmission" value="'.
+    my $result=' <input type="submit" name="gradeasubmission" value="'.
 	&mt("Get a submission to grade").'" />';
     $result.='<input type="hidden" name="grade_target" value="webgrade" />';
     return $result;
@@ -152,7 +178,7 @@
     }
     if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
 	$target eq 'tex') {
-	my $version=&get_version();
+	my ($version,$previous)=&get_version();
 	($status,$accessmsg,my $slot_name,$slot) = 
 	    &Apache::lonhomework::check_task_access('0');
 	push(@Apache::inputtags::status,$status);
@@ -162,13 +188,14 @@
 	&Apache::run::run($expression,$safeeval);
 	&Apache::lonxml::debug("Got $status");
 	$body_tag_start.=&add_previous_version_button($status);
-	if (( $status eq 'CLOSED' ) ||
-	    ( $status eq 'BANNED') ||
-	    ( $status eq 'UNAVAILABLE') ||
-	    ( $status eq 'NOT_IN_A_SLOT') ||
-	    ( $status eq 'NEEDS_CHECKIN') ||
-	    ( $status eq 'WAITING_FOR_GRADE') ||
-	    ( $status eq 'INVALID_ACCESS')) {
+	if (!$previous && (
+			   ( $status eq 'CLOSED' ) ||
+			   ( $status eq 'BANNED') ||
+			   ( $status eq 'UNAVAILABLE') ||
+			   ( $status eq 'NOT_IN_A_SLOT') ||
+			   ( $status eq 'NEEDS_CHECKIN') ||
+			   ( $status eq 'WAITING_FOR_GRADE') ||
+			   ( $status eq 'INVALID_ACCESS') )) {
 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
 	    if ( $target eq "web" ) {
 		$result.= $head_tag_start.'</head>'.$body_tag_start;
@@ -220,10 +247,12 @@
 			'" value="'.$env{"form.grade_$field"}.'" />'."\n";
 		}
 	    }
-	    my $version=&get_version();
+	    my ($version,$previous)=&get_version();
 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
 		$result.='<h1><font color="red">'.&mt('Did not pass').'</font></h1>';
-		$result.=&add_request_another_attempt_button();
+		if (!$previous) {
+		    $result.=&add_request_another_attempt_button();
+		}
 	    }
 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
 		$result.='<h1><font color="green">'.&mt('Passed').'</font></h1>';
@@ -266,7 +295,7 @@
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result='';
     my $status=$Apache::inputtags::status['-1'];
-    my $version=&get_version();
+    my ($version,$previous)=&get_version();
     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
 	$target eq 'tex') {
 	if (
@@ -274,7 +303,7 @@
 	    ($target eq 'answer') || ($target eq 'tex')
 	   ) {
 	    if ($target eq 'web') {
-		if ($status eq 'CAN_ANSWER') {
+		if ($status eq 'CAN_ANSWER' && !$previous) {
 		    $result.="\n".'<table border="1">'.
 			&Apache::inputtags::file_selector("$version.0",
 							  "bridgetask","*",
@@ -287,7 +316,7 @@
 		$result.=&Apache::lonxml::xmlend().'</html>';
 	    }
 	}
-	if ($target eq 'grade' && !$env{'form.webgrade'}) {
+	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
 	    my $award='SUBMITTED';
 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
 						    'portfiles',\$award);
@@ -639,7 +668,10 @@
     #then start repicking
     &Apache::response::pushrandomnumber();
     my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
-    return $order[0];
+    my $num=@order;
+    my $version=&get_version();
+    my $which=($version-1)%$num;
+    return $order[$which];
 }
 
 {