--- loncom/homework/essayresponse.pm	2004/10/26 21:27:10	1.43
+++ loncom/homework/essayresponse.pm	2005/01/31 22:00:40	1.58
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # essay (ungraded) style responses
 #
-# $Id: essayresponse.pm,v 1.43 2004/10/26 21:27:10 banghart Exp $
+# $Id: essayresponse.pm,v 1.58 2005/01/31 22:00:40 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -51,9 +51,9 @@ sub start_essayresponse {
 	my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
 	$result='<br /><table border="1">';
 	$result.='<tr><td>'.
-	    '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked> '.
+	    '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked="checked" /> '.
 	    &mt('Submit entries below as answer to receive credit').' <br />'.
-	    '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no"> '.
+	    '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no" /> '.
 	    &mt('Save entries below as a draft answer (not submitting them for credit yet)').
 	    ' </td></tr>';
 	if ($ncol > 0) {
@@ -65,18 +65,16 @@ sub start_essayresponse {
 	    $result .='</td></tr>';
 	}
         if ($uploadedfiletypes) {
-	    $result.='<tr><td>'.&mt('Submit a file:').
+	    $result.='<tr><td>'.&mt('Submit a file: (only one file can be uploaded)').
 		' <br /><input type="file" size="50" name="HWFILE'.
-		$part.'_'.$id.'" onFocus="this.form.enctype='.
-		"'multipart/form-data'".';" /><br />'.
+		$part.'_'.$id.'" /><br />'.
 		&mt('Allowed filetypes: <b>[_1]</b>',$uploadedfiletypes).'<br />'.
-                '<strong>OR:</strong><br /><a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&fieldname=HWPORT'.$part.'_'.$id.'","cat","height=400,'.
-                'width=500,scrollbars=1,resizable=1,menubar=0,location=1"))'."'".'>Select Portfolio Files</a>'.
+                '<strong>OR:</strong><br /><a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&amp;fieldname=HWPORT'.$part.'_'.$id.'","cat","height=600,width=800,scrollbars=1,resizable=1,menubar=2,location=1"))'."'".'>Select Portfolio Files</a>'.
                 '<br />'.
                 '<input type="text" size="50" name="HWPORT'.$part.'_'.$id.'" value="" />'.
 		'<br />';
-	    if ($portfile=~/[^\s]/){
-	        $result.="Portfolio files previously selected: <strong>".$Apache::lonhomework::history{"resource.$part.$id.portfiles"}."</strong><br />";
+	    if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){
+	        $result.="Portfolio files previously selected: <strong>".&Apache::lonnet::unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"})."</strong><br />";
 	    }
 
             if ($uploadedfile) {
@@ -110,10 +108,9 @@ sub end_essayresponse {
 	    $Apache::lonhomework::results{"resource.$part.$id.collaborators"}=$collaborators
 		if ($collaborators ne $previous_list);
 	}
-	if ( defined($ENV{'form.submitted'}) &&
-	     $ENV{'form.submitted'} eq 'scantron' ) {
+	if (  &Apache::response::submitted('scantron') ) {
 	    $increment=&Apache::response::scored_response($part,$id);
-	} elsif ( defined($ENV{'form.submitted'}) ) {
+	} elsif ( &Apache::response::submitted() ) {
 	    my $response      = $ENV{'form.HWVAL_'.$id};
             my $filename= $ENV{'form.HWFILE'.$part.'_'.$id.'.filename'};
             my $portfiles = $ENV{'form.HWPORT'.$part.'_'.$id};
@@ -126,23 +123,35 @@ sub end_essayresponse {
 		}
                 my $uploadedflag=0;
                 if ($filename =~ /[^\s]/) {
- 	           my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
-                   $uploadedfiletypes=~s/[^\w\,]//g;
-                   $uploadedfiletypes=','.$uploadedfiletypes.',';
-                   my ($extension)=($filename=~/\.(\w+)$/);
-	           if ($uploadedfiletypes=~/\,$extension\,/i) {
-	              $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"}=$filename;
-                      $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"}=
-                         &Apache::lonnet::userfileupload('HWFILE'.$part.'_'.$id,undef,'essayresponse');
-                      $uploadedflag=1;
-		   } else {
-		      $award='INVALID_FILETYPE';
-                   }
+ 	            my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
+                    $uploadedfiletypes=~s/[^\w\,]//g;
+                    $uploadedfiletypes=','.$uploadedfiletypes.',';
+                    my ($extension)=($filename=~/\.(\w+)$/);
+	            if ($uploadedfiletypes=~/\,$extension\,/i) {
+	                $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"}=$filename;
+                        $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"}=
+                        &Apache::lonnet::userfileupload('HWFILE'.$part.'_'.$id,undef,'essayresponse');
+                        $uploadedflag=1;
+		    } else {
+		        $award='INVALID_FILETYPE';
+                    }
+	        } else {
+	           $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"}="";
+                   $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"}="";
 	        }
                 if ($portfiles =~ /[^\s]/) {
+                    $portfiles =~s/,$//;
                     $Apache::lonhomework::results{"resource.$part.$id.portfiles"}=$portfiles;
-                    $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"}=$portfiles;
+                    my @submitted_files = split /,/,$portfiles;
+		    my ($dsymb,$crsid,$domain,$name)=&Apache::lonxml::whichuser();
+		    &Apache::lonnet::unmark_as_readonly($domain,$name,$dsymb.$crsid);
+                    &Apache::lonnet::mark_as_readonly($domain,$name,\@submitted_files,$dsymb.$crsid);
+                    &Apache::lonnet::clear_selected_files($name);
                     $uploadedflag=1;
+    	        } else {
+		    my ($dsymb,$crsid,$domain,$name)=&Apache::lonxml::whichuser();
+    	            &Apache::lonnet::unmark_as_readonly($domain,$name,$dsymb.$crsid);
+    	            $Apache::lonhomework::results{"resource.$part.$id.portfiles"}="";
     	        }
 		$Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
 		$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;