[LON-CAPA-cvs] cvs: loncom /interface multidownload.pl

raeburn raeburn at source.lon-capa.org
Fri Nov 3 14:08:54 EDT 2017


raeburn		Fri Nov  3 18:08:54 2017 EDT

  Modified files:              
    /loncom/interface	multidownload.pl 
  Log:
  - xhtml validation.
  - sanity checking.
  
  
Index: loncom/interface/multidownload.pl
diff -u loncom/interface/multidownload.pl:1.39 loncom/interface/multidownload.pl:1.40
--- loncom/interface/multidownload.pl:1.39	Wed Dec 21 21:25:40 2011
+++ loncom/interface/multidownload.pl	Fri Nov  3 18:08:54 2017
@@ -2,7 +2,7 @@
 # CGI-script to allow download of all essay submissions of 
 # multiple students.
 #
-# $Id: multidownload.pl,v 1.39 2011/12/21 21:25:40 www Exp $
+# $Id: multidownload.pl,v 1.40 2017/11/03 18:08:54 raeburn Exp $
 # Copyright Michigan State University Board of Trustees
 #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -74,21 +74,34 @@
 $|=1;
 &Apache::lonlocal::get_language_handle();
 &Apache::loncommon::content_type(undef,'text/html');
+my ($nocookie,$identifier,$unique_path,$scope);
 if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
     print(&LONCAPA::loncgi::missing_cookie_msg());
-    return;
+    $nocookie = 1;
 }
 
-my $identifier = $ENV{'QUERY_STRING'};
-my $unique_path = $identifier.time();
-print(&Apache::loncommon::start_page('Multiple Downloads'));
-    
-
-my $scope = $env{'request.course.id'};
-if ($env{'request.course.sec'}) {
-    $scope .= '/'.$env{'request.course.sec'};
+unless ($nocookie) {
+    $scope = $env{'request.course.id'};
+    if ($env{'request.course.sec'}) {
+        $scope .= '/'.$env{'request.course.sec'};
+    }
+    if ($ENV{'QUERY_STRING'} =~ /^\d+_\d+_\d+$/) {
+        $identifier = $ENV{'QUERY_STRING'};
+        $unique_path = $identifier.time();
+    }
+    print(&Apache::loncommon::start_page('Multiple Downloads'));
 }
-if (&Apache::lonnet::allowed('vgr',$scope) eq 'F') {
+if ($scope eq '') {
+    print(&mt('Invalid course context: you need to reselect your course role.'));
+} elsif ($identifier eq '') {
+    unless ($nocookie) {
+        if (&Apache::lonnet::allowed('vgr',$scope) eq 'F') {
+            print(&mt('Invalid query string; unable to download submissions.'));
+        } else {
+            print(&mt('You are not authorized to download student submissions.'));
+        }
+    }
+} elsif (&Apache::lonnet::allowed('vgr',$scope) eq 'F') {
     my $symb = $env{'cgi.'.$identifier.'.symb'};
     my $navmap = Apache::lonnavmaps::navmap->new();
     my $res = $navmap->getBySymb($symb);
@@ -106,14 +119,17 @@
     my $uname = $env{'user.name'};
     my $udom = $env{'user.domain'};
     my $unique_user = $uname.":".$udom;
+    my $manifest;
     &mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path",0,0700);
-    if (!open(MANIFEST, ">$doc_zip_root/zipdir/$unique_user/$unique_path/manifest.txt")) {
+    if (open(MANIFEST, ">$doc_zip_root/zipdir/$unique_user/$unique_path/manifest.txt")) {
+        $manifest = 1;
+        print MANIFEST (&mt("Zip file generated on [_1]",&Apache::lonlocal::locallocaltime(time()))."\n");
+        print MANIFEST (&mt("Course: [_1]",$env{"course.$courseid.description"})."\n");
+        print MANIFEST (&mt("Problem: [_1]",$res->compTitle)."\n");
+        print MANIFEST (&mt("Files contained in this zip:")."\n");
+    } else {
         &Apache::lonnet::logthis("Problem making manifest");
     }
-    print MANIFEST (&mt("Zip file generated on [_1]",&Apache::lonlocal::locallocaltime(time()))."\n");
-    print MANIFEST (&mt("Course: [_1]",$env{"course.$courseid.description"})."\n");
-    print MANIFEST (&mt("Problem: [_1]",$res->compTitle)."\n");
-    print MANIFEST (&mt("Files contained in this zip:")."\n");
     my $file_problem = 0;
     my $current_student = 0;
     foreach my $stu (@stuchecked) {
@@ -123,7 +139,9 @@
         my ($stuname,$studom,$fullname) = split(/:/,$stu);
         my %record = &Apache::lonnet::restore($symb,$courseid,$studom,$stuname);
         my $port_url = '/uploaded/'.$studom.'/'.$stuname.'/portfolio';
-        print MANIFEST ($fullname."\n");
+        if ($manifest) {
+            print MANIFEST ($fullname."\n");
+        }
          
         my $submission_count = 0;
         foreach my $partid (@$partlist) {
@@ -145,8 +163,10 @@
                             $file = $port_url.$file;
                         }
                         my ($file_name_only) = ($file =~ m{.*/([^/]+)$});
-                        print MANIFEST ("\t$file_name_only (".&mt("Part [_1]",$partid).
-                                        ") (".&mt("Response [_1]",$respid).")"."\n");
+                        if ($manifest) {
+                            print MANIFEST ("\t$file_name_only (".&mt("Part [_1]",$partid).
+                                            ") (".&mt("Response [_1]",$respid).")"."\n");
+                        }
                         $submission_count ++;
                         &Apache::lonnet::repcopy($file);
                         my $source = &Apache::lonnet::filelocation("",$file);
@@ -170,7 +190,7 @@
                 }
             }
         }
-        if (!$submission_count) {
+        if ((!$submission_count) && ($manifest)) {
             print MANIFEST ("\t".&mt("No Files Submitted")."\n");
         }
     }
@@ -190,9 +210,14 @@
     &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state);
     print('<p><a href="/zipspool/zipout/'.$unique_user.'/'.$zipout.'">'.
             &mt("Click to download").'</a></p><br />');
-    close(MANIFEST);
+    if ($manifest) {
+        close(MANIFEST);
+    }
 } else {
     print(&mt('You are not authorized to download student submissions.'));
 }
+unless ($nocookie) {
+    print(&Apache::loncommon::end_page());
+}
 1;
 __END__;




More information about the LON-CAPA-cvs mailing list