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

banghart lon-capa-cvs-allow@mail.lon-capa.org
Wed, 25 Apr 2007 00:16:53 -0000


banghart		Tue Apr 24 20:16:53 2007 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  	Offer multidownload link only if files are available to be
  	downloaded.
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.395 loncom/homework/grades.pm:1.396
--- loncom/homework/grades.pm:1.395	Mon Apr 16 15:00:38 2007
+++ loncom/homework/grades.pm	Tue Apr 24 20:16:51 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.395 2007/04/16 19:00:38 albertel Exp $
+# $Id: grades.pm,v 1.396 2007/04/25 00:16:51 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -953,8 +953,8 @@
     my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
     my $total      = scalar(@stuchecked)-1;
 
-    foreach (@stuchecked) {
-	my ($uname,$udom,$fullname) = split(/:/);
+    foreach my $student (@stuchecked) {
+	my ($uname,$udom,$fullname) = split(/:/,$student);
 	$env{'form.student'}        = $uname;
 	$env{'form.userdom'}        = $udom;
 	$env{'form.fullname'}       = $fullname;
@@ -1626,7 +1626,25 @@
     $result.='</td></tr></table><br />';
     return $result;
 }
-
+sub files_exist {
+    my ($r, $symb) = @_;
+    my $files_exist = 0;
+    my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
+    foreach my $student (@students) {
+        my ($uname,$udom,$fullname) = split(/:/,$student);
+        my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
+        my ($string,$timestamp)= &get_last_submission(\%record);
+        foreach (@$string) {
+            my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
+            my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
+            if (@$files) {
+                $files_exist = 1;
+                return $files_exist;
+            }
+        }
+    }
+    return $files_exist;
+}
 sub download_all_link {
     my ($r,$symb) = @_;
     my $all_students = 
@@ -1678,7 +1696,9 @@
 	&sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
 	$env{'form.probTitle'} = $env{'form.probTitle'} eq '' ? 
 	    &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
-	&download_all_link($request,$symb);
+	if (&files_exist($request, $symb)) {
+	    &download_all_link($request, $symb);
+	}
 	$request->print('<h3>&nbsp;<font color="#339933">Submission Record</font></h3>'."\n".
 			'<font size=+1>&nbsp;<b>Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n");