--- loncom/homework/response.pm	2009/04/17 01:00:15	1.214
+++ loncom/homework/response.pm	2010/10/14 19:54:56	1.219
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.214 2009/04/17 01:00:15 www Exp $
+# $Id: response.pm,v 1.219 2010/10/14 19:54:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -30,7 +30,7 @@
 
 =head1 NAME
 
-Apache::resonse.pm
+Apache::response.pm
 
 =head1 SYNOPSIS
 
@@ -280,7 +280,7 @@ sub meta_response_order {
 }
 
 sub check_for_previous {
-    my ($curresponse,$partid,$id,$last) = @_;
+    my ($curresponse,$partid,$id,$last,$type) = @_;
     my %previous;
     $previous{'used'} = 0;
     foreach my $key (sort(keys(%Apache::lonhomework::history))) {
@@ -305,7 +305,15 @@ sub check_for_previous {
 		if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN';	}
                 if ($previous{'award'} eq 'INTERNAL_ERROR') { $previous{'used'}=0; }
 		&Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:");
-	    }
+            } elsif ($type eq 'ci') {
+                if (lc($pastresponse) eq lc($curresponse)) {
+                    if ($key =~ /^(\d+):/) {
+                        push (@{$previous{'versionci'}},$1);
+                        $previous{'awardci'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"};
+                        $previous{'usedci'} = 1;
+                    }
+                }
+            }
 	}
     }
     &Apache::lonhomework::showhash(%previous);
@@ -318,7 +326,10 @@ sub handle_previous {
 	if ($$previous{'last'}) {
 	    push(@Apache::inputtags::previous,'PREVIOUSLY_LAST');
 	    push(@Apache::inputtags::previous_version,$$previous{'version'});
-	} elsif ($Apache::lonhomework::type ne 'survey') {
+	} elsif (($Apache::lonhomework::type ne 'survey') &&
+                 ($Apache::lonhomework::type ne 'surveycred') &&
+                 ($Apache::lonhomework::type ne 'anonsurvey') &&
+                 ($Apache::lonhomework::type ne 'anonsurveycred')) { 
 	    push(@Apache::inputtags::previous,'PREVIOUSLY_USED');
 	    push(@Apache::inputtags::previous_version,$$previous{'version'});
 	}
@@ -439,7 +450,7 @@ sub end_customresponse {
 	    ${$safeeval->varglob('LONCAPA::customresponse_submission')}=
 		$response;
 	    
-	    my $award = &Apache::run::run('{ my $submission=$LONCAPA::customresponse_submission;'.$Apache::response::custom_answer[-1].'}',$safeeval);
+	    my ($award,$score) = &Apache::run::run('{ my $submission=$LONCAPA::customresponse_submission;'.$Apache::response::custom_answer[-1].'}',$safeeval);
 	    if (!&Apache::inputtags::valid_award($award)) {
 		$error = $award;
 		$award = 'ERROR';
@@ -447,6 +458,9 @@ sub end_customresponse {
 	    &Apache::response::handle_previous(\%previous,$award);
 	    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
 		$award;
+            if ($award eq 'ASSIGNED_SCORE') {
+                $Apache::lonhomework::results{"resource.$part.$id.awarded"}=1.0*$score;
+            }
 	    if ($error) {
 		$Apache::lonhomework::results{"resource.$part.$id.awardmsg"}=
 		    $error;
@@ -546,7 +560,7 @@ function edit_${id}_${field} (textarea)
     newwin = window.open("/adm/dragmath/applet/MaximaPopup.html","","width=565,height=400,resizable");
 }
 </script>
-<a href="javascript:edit_${id}_${field}('${field}');void(0);"><img class="stift" src='$iconpath/stift.gif' alt='$button' title='$button'/></a>
+<a href="javascript:edit_${id}_${field}('${field}');void(0);"><img class="stift" src="$iconpath/stift.gif" alt="$button" title="$button" /></a>
 ENDFORMULABUTTON
 }
 
@@ -904,6 +918,10 @@ sub showallfoils {
 	}
     }
     if ($Apache::lonhomework::type eq 'survey') { return 1; }
+    if ($Apache::lonhomework::type eq 'surveycred') { return 1; }
+    if ($Apache::lonhomework::type eq 'anonsurvey') { return 1; }
+    if ($Apache::lonhomework::type eq 'anonsurveycred') { return 1; }
+
     return 0;
 }