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

raeburn raeburn@source.lon-capa.org
Thu, 17 Jun 2010 00:13:20 -0000


This is a MIME encoded message

--raeburn1276733600
Content-Type: text/plain

raeburn		Thu Jun 17 00:13:20 2010 EDT

  Modified files:              
    /loncom/homework	essayresponse.pm inputtags.pm 
  Log:
  - bug 5933.
    Files submitted to essayresponse items directly from user's desktop
    instead of selecting from portfolio now stored in user's portfolio.
    Instructors can now return files to student for this type of upload.
    
    Work in progress.
  
  
--raeburn1276733600
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100617001320.txt"

Index: loncom/homework/essayresponse.pm
diff -u loncom/homework/essayresponse.pm:1.106 loncom/homework/essayresponse.pm:1.107
--- loncom/homework/essayresponse.pm:1.106	Thu Apr 22 13:00:24 2010
+++ loncom/homework/essayresponse.pm	Thu Jun 17 00:13:20 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # essay (ungraded) style responses
 #
-# $Id: essayresponse.pm,v 1.106 2010/04/22 13:00:24 www Exp $
+# $Id: essayresponse.pm,v 1.107 2010/06/17 00:13:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -171,7 +171,13 @@
 		$Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
 		$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;
 		my %previous=&Apache::response::check_for_previous($response,$part,$id);
-		unless ($uploadedflag) { &Apache::response::handle_previous(\%previous,$award); }
+		if ($uploadedflag) {
+                    if ($award eq 'FILENAME_INUSE') {
+                        delete($Apache::lonhomework::results{"resource.$id.tries"});
+                    }
+                } else {
+                    &Apache::response::handle_previous(\%previous,$award);
+                }
 #
 # Store with resource author for similarity testing
 #
@@ -273,6 +279,7 @@
             $files = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'};
         }
     }
+    my ($symb,$crsid,$udom,$uname)=&Apache::lonnet::whichuser();
     if ($files =~ /[^\s]/) {
 	$files =~s/,$//;
         my (@submitted_files,@acceptable_files,@accepted_files);
@@ -311,7 +318,6 @@
                     $$totalsize += $env{'form.HWFILESIZE'.$jspart.'_'.$id};
                 }
             } else {
-                my ($symb,$crsid,$udom,$uname) = &Apache::lonnet::whichuser();
                 my ($path,$filename) = ($file =~ m{^(.*/)([^/]+)$});
                 my $fullpath = '/userfiles/portfolio'.$path;
                 if (!exists($dirlist{$fullpath})) {
@@ -347,62 +353,119 @@
                 push(@accepted_files,$file);
             }
         }
-        $Apache::lonhomework::results{"resource.$part.$id.$which"}=join(',',@accepted_files);
+        if ($which eq 'portfiles') {
+            my @to_mark;
+            if ($Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
+                @to_mark = ($Apache::lonhomework::results{"resource.$part.$id.portfiles"});
+            }
+            if (@accepted_files) {
+                if ($Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
+                    $Apache::lonhomework::results{"resource.$part.$id.$which"} .= ',';
+                }
+                $Apache::lonhomework::results{"resource.$part.$id.$which"}.=join(',',@accepted_files);
+                push(@to_mark,@accepted_files);
+            }
+            &Apache::lonnet::unmark_as_readonly($udom,$uname,[$symb,$crsid]);
+            &Apache::lonnet::mark_as_readonly($udom,$uname,\@to_mark,[$symb,$crsid]);
+            &Apache::lonnet::clear_selected_files($uname);
+        }
         if (($$award eq 'INVALID_FILETYPE') || ($$award eq 'EXCESS_FILESIZE')) {
+            if ($which eq 'filename') {
+                delete($env{'form.HWFILE'.$jspart.'_'.$id});
+            }
             return;
         }
 	if (ref($uploadedflag)) {
 	    $$uploadedflag=1;
 	}
-        my ($symb,$crsid,$domain,$name)=&Apache::lonnet::whichuser();
-	if ($which eq 'portfiles') {
-	    &Apache::lonnet::unmark_as_readonly($domain,$name,[$symb,$crsid]);
-	    &Apache::lonnet::mark_as_readonly($domain,$name,\@submitted_files,[$symb,$crsid]);
-	    &Apache::lonnet::clear_selected_files($name);
-	}
 	if ($which eq 'filename') {
-	    $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"}=
-		$files;
             my $cleanpart = $part;
             $cleanpart =~ s/\W/_/g;
             my $cleanid = $id;
             $cleanid =~ s/\W/_/g;
-            my ($map,$resid,$res)=&Apache::lonnet::decode_symb($symb);
-            my $container;
-            if ($map =~ /^uploaded/) {
-                (my $prefix,$container) = ($map =~ m{^uploaded/[^/]+/[^/]+/(default|supplemental)_?([^.]*)\.(?:sequence|page)$});
-                if (length($container) > 10) {
-                    $container = substr($container,-10,10);
+            my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
+            my %crsdesc = &Apache::lonnet::coursedescription($crsid);
+            my $turnindir;
+            my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
+            $turnindir = $userhash{'turnindir'};
+            if ($turnindir eq '') {
+                $turnindir = &mt('turned in');
+                $turnindir =~ s/\W+/_/g;
+                my %newhash = (
+                                'turnindir' => $turnindir,
+                              );
+                &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
+            }
+            my $prefix = 'portfolio';
+            my $path = '/'.$turnindir.'/';
+            my $crsname = $crsdesc{'description'};
+            my $restitle=&Apache::lonnet::gettitle($symb);
+            foreach my $item ($crsname,$restitle) {
+                $item =~ s/\W+/_/g;
+            }
+            if ($crsname eq '') {
+                $crsname = $crsid;
+            }
+            if ($restitle eq '') {
+                $restitle = ($resurl =~ m{/[^/]+$});
+                if ($restitle eq '') {
+                    $restitle = time;
                 }
-                if ($container ne '') {
-                    $container = $prefix.'_'.$container;
+            }
+            my @pathitems;
+            my $navmap = Apache::lonnavmaps::navmap->new();
+            if (defined($navmap)) {
+                my $mapres = $navmap->getResourceByUrl($map);
+                if (ref($mapres)) {
+                    my $pcslist = $mapres->map_hierarchy();
+                    if ($pcslist ne '') {
+                        foreach my $pc (split(/,/,$pcslist)) {
+                            my $res = $navmap->getByMapPc($pc);
+                            if (ref($res)) {
+                                my $title = $res->compTitle();
+                                $title =~ s/\W+/_/g;
+                                if ($title ne '') {
+                                    push(@pathitems,$title);
+                                }
+                            }
+                        }
+                    }
+                    my $maptitle = $mapres->compTitle();
+                    $maptitle =~ s/\W+/_/g;
+                    if ($maptitle ne '') {
+                        push(@pathitems,$maptitle);
+                    }
                 } else {
-                    $container = $prefix;
-                } 
-            } else {
-                ($container) = ($map =~ m{(.+)\.(?:sequence|page)$});
-                $container =~ s/\W/_/g;
-                if (length($container) > 255) {
-                    $container = substr($container,0,254);
+                    $$award = 'INTERNAL_ERROR';
                 }
+            } else {
+                $$award = 'INTERNAL_ERROR';
             }
-            my $subdir = 'essayresponse';
-            my %crsdesc = &Apache::lonnet::coursedescription($crsid);
-            foreach my $item ($crsdesc{'domain'},$crsdesc{'num'},$container,$resid,$cleanpart,$cleanid) {
-                if ($item ne '') {
-                    $subdir .= '/'.$item;
+            push(@pathitems,$restitle);
+            unshift(@pathitems,$crsname);
+            $path .= join('/',@pathitems);
+            my $formelement = 'HWFILE'.$jspart.'_'.$id;
+            my $fname = $env{'form.'.$formelement.'.filename'};
+            &Apache::lonnet::clean_filename($fname);
+            my $url = '/uploaded/'.$udom.'/'.$uname.'/'.$prefix.$path.'/'.$fname;
+            my @stat = &Apache::lonnet::stat_file($url);
+            if (@stat && $stat[0] ne 'no_such_dir') {
+                $$award = 'FILENAME_INUSE';
+            } else {
+                my ($mode,%allfiles,%codebase);
+                my $result = &Apache::lonnet::userfileupload($formelement,'',
+                                 $prefix.$path,$mode,\%allfiles,\%codebase);
+                if ($result =~ m{^/uploaded/}) {
+                    $Apache::lonhomework::results{"resource.$part.$id.portfiles"} .= $path.'/'.$fname;
+                    &Apache::lonnet::unmark_as_readonly($udom,$uname,[$symb,$crsid]);
+     
+                    &Apache::lonnet::mark_as_readonly($udom,$uname,[$path.'/'.$fname],[$symb,$crsid]);
+                } else {
+                    $$award = 'INTERNAL_ERROR';
                 }
             }
-	    $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"}=
-		&Apache::lonnet::userfileupload('HWFILE'.$jspart.'_'.$id,undef,
-						$subdir);
             delete($env{'form.HWFILE'.$jspart.'_'.$id});
 	}
-    } elsif ($which eq 'portfiles' &&
-	     $Apache::lonhomework::history{"resource.$part.$id.$which"}) {
-	my ($symb,$crsid,$domain,$name)=&Apache::lonnet::whichuser();
-	&Apache::lonnet::unmark_as_readonly($domain,$name,[$symb,$crsid]);
-	$Apache::lonhomework::results{"resource.$part.$id.$which"}="";
     }
 }
 
@@ -413,7 +476,6 @@
     delete($env{'form.HWFILE'.$jspart.'_'.$id});
 }
 
-
 sub check_collaborators {
     my ($ncol,$coll) = @_;
     my %classlist=&Apache::lonnet::dump('classlist',
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.263 loncom/homework/inputtags.pm:1.264
--- loncom/homework/inputtags.pm:1.263	Sun Jun  6 21:42:04 2010
+++ loncom/homework/inputtags.pm	Thu Jun 17 00:13:20 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # input  definitons
 #
-# $Id: inputtags.pm,v 1.263 2010/06/06 21:42:04 raeburn Exp $
+# $Id: inputtags.pm,v 1.264 2010/06/17 00:13:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -572,8 +572,8 @@
 			       'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
 			       'BAD_FORMULA', 'INTERNAL_ERROR', 'SIG_FAIL', 'INCORRECT', 
 			       'MISORDERED_RANK', 'INVALID_FILETYPE',
-                               'EXCESS_FILESIZE', 'DRAFT',
-			       'SUBMITTED', 'SUBMITTED_CREDIT', 
+                               'EXCESS_FILESIZE', 'FILENAME_INUSE', 
+			       'DRAFT', 'SUBMITTED', 'SUBMITTED_CREDIT', 
                                'ANONYMOUS', 'ANONYMOUS_CREDIT',
                                'ASSIGNED_SCORE', 'APPROX_ANS',
 			       'EXACT_ANS','COMMA_FAIL') {
@@ -589,7 +589,8 @@
 		  'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
 		  'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', 'INTERNAL_ERROR',
 		  'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
-		  'INVALID_FILETYPE', 'EXCESS_FILESIZE', 'DRAFT', 'SUBMITTED',
+		  'INVALID_FILETYPE', 'EXCESS_FILESIZE', 'FILENAME_INUSE', 
+                  'DRAFT', 'SUBMITTED',
                   'SUBMITTED_CREDIT', 'ANONYMOUS', 'ANONYMOUS_CREDIT',
                   'ASSIGNED_SCORE', 'APPROX_ANS', 'EXACT_ANS');
     my $i=0;
@@ -820,6 +821,16 @@
         $message = &mt('Submission won\'t be graded. The combined size of submitted files exceeded the amount allowed.');
         $css_class=$possible_class{'not_charged_try'};
         $button=1;
+    } elsif ($award eq 'FILENAME_INUSE') {
+        $message = &mt('You have already uploaded a file with that filename.');
+        if ($target eq 'tex') {
+            $message.= "\\\\\n";
+        } else {
+            $message .= '<br />';
+        }
+        $message .= &mt('Please use a different file name.');
+        $css_class=$possible_class{'not_charged_try'};
+        $button=1;
     } elsif ($award eq 'INVALID_FILETYPE') {
 	$message = &mt("Submission won't be graded. The type of file submitted is not allowed.");
 	$css_class=$possible_class{'not_charged_try'};

--raeburn1276733600--