Diff for /loncom/interface/multidownload.pl between versions 1.1 and 1.19

version 1.1, 2007/03/30 22:57:39 version 1.19, 2007/04/27 22:43:11
Line 33  use File::Path; Line 33  use File::Path;
 use File::Basename;  use File::Basename;
 use File::Copy;  use File::Copy;
 use IO::File;  use IO::File;
 use Image::Magick;  
 use Apache::lonhtmlcommon();  use Apache::lonhtmlcommon();
 use Apache::lonnet;  
 use Apache::grades;  use Apache::grades;
   use Apache::lonnavmaps;
   use Apache::lonnet;
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonmsg();  use Apache::lonmsg();
   use Apache::lonnet;
 use LONCAPA::Enrollment;  use LONCAPA::Enrollment;
   
 use strict;  use strict;
   
   
 $|=1;  $|=1;
 if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {  if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
     print <<END;      print <<END;
Line 62  END Line 61  END
 &Apache::lonlocal::get_language_handle();  &Apache::lonlocal::get_language_handle();
 &Apache::loncommon::content_type(undef,'text/html');  &Apache::loncommon::content_type(undef,'text/html');
 my $identifier = $ENV{'QUERY_STRING'};  my $identifier = $ENV{'QUERY_STRING'};
   my $unique_path = $identifier.time();
 print(&Apache::loncommon::start_page('Multiple Downloads'));  print(&Apache::loncommon::start_page('Multiple Downloads'));
 my $symb = $env{'cgi.'.$identifier.'.symb'};  
 my $courseid = $env{'cgi.'.$identifier.'.courseid'};  my $scope = $env{'request.course.id'};
 my @stuchecked = split /\n/,$env{'cgi.'.$identifier.'.students'};  if ($env{'request.course.sec'}) {
 my @parts = split /\n/,$env{'cgi.'.$identifier.'.parts'};      $scope .= '/'.$env{'request.course.sec'};
 my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);  }
 my @part_response_id = &Apache::grades::flatten_responseType($responseType);  if (&Apache::lonnet::allowed('vgr',$scope) eq 'F') {
 print "number of parts is: ".@parts."<br />";      my $symb = $env{'cgi.'.$identifier.'.symb'};
 my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);      my $navmap = Apache::lonnavmaps::navmap->new();
 print "in the CGI script <br />";      my $res = $navmap->getBySymb($symb);
 foreach (@stuchecked) {      my $partlist = $res->parts();
     my ($uname,$udom,$fullname) = split(/:/);      foreach my $part(@$partlist) {
     my %record = &Apache::lonnet::restore($symb,$courseid,$udom,$uname);          &Apache::lonnet::logthis("partlist is $part");
     print $uname."<br />";      }
     foreach my $part(@part_response_id) {      my ($zipout) = ($symb =~ /^.*\/(.+)\.problem$/);
         print $part."<br />";      $zipout =~ s/\s/_/g;
         my ($partid,$respid) = @{ $part };      $zipout .= ".zip";
         my $files = &Apache::grades::get_submitted_files($udom,$uname,$partid,$respid,\%record);      my $courseid = $env{'request.course.id'};
         foreach my $file(@$files) {      my @stuchecked = split(/\n/,$env{'cgi.'.$identifier.'.students'});
             print $file."<br />";      my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'});
       my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'};
       my $uname = $env{'user.name'};
       my $udom = $env{'user.domain'};
       my $unique_user = $uname.":".$udom;
       &mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path",0,0700);
       my $file_problem = 0;
       foreach my $stu (@stuchecked) {
           my %files_saved;
           my ($stuname,$studom,$fullname) = split(/:/,$stu);
           my %record = &Apache::lonnet::restore($symb,$courseid,$studom,$stuname);
           foreach my $partid (@$partlist) {
               my @ids = $res->responseIds($partid);
               foreach my $respid(@ids) {
                   &mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path/$stuname/part$partid/resp$respid",0,0700);
                   my $files = &Apache::grades::get_submitted_files($studom,$stuname,$partid,$respid,\%record);
                   foreach my $file (@$files) {
                       my ($file_name_only) = ($file =~ /^.*\/(.+$)/);
                       &Apache::lonnet::repcopy($file);
                       my $source = &Apache::lonnet::filelocation("",$file);
                       my $destination = "$doc_zip_root/zipdir/$unique_user/$unique_path/$stuname/part$partid/resp$respid/$file_name_only";
                       if (exists($files_saved{$destination})) {
                           # file has already been saved once
                           my ($file_name,$file_ext) = ($destination =~ /(^.*)(\..+$)/);
                           $destination = $file_name.$files_saved{$destination}.$file_ext;
                           $files_saved{$destination} ++;
                       }
                       $files_saved{$destination}++;
                       if (!&copy($source,$destination)) {
                           if (!$file_problem) {
                               print &mt("Unable to create: <br />");
                               $file_problem = 1;
                           }
                           print ("$stuname/part$partid/resp$respid/$file_name_only <br />");
                       }
                   }
               }
         }          }
     }      }
       &mkpath($doc_zip_root."/zipout/$unique_user",0,0700);
       my $statement = "cd $doc_zip_root/zipdir/$unique_user/$unique_path\n";
       $statement .= "zip -r $doc_zip_root/zipout/$unique_user/$zipout * > /dev/null";
       system($statement);
       $statement = "rm -rf $doc_zip_root/zipdir/$unique_user/$unique_path";
       system($statement);
       print('<a href="/zipspool/zipout/'.$unique_user.'/'.$zipout.'">'.
               &mt("Click to download").'</a><br />');
   } else {
       print(&mt('You are not authorized to download student submissions.'));
 }  }
   1;
 die;  __END__;

Removed from v.1.1  
changed lines
  Added in v.1.19


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>