File:  [LON-CAPA] / loncom / interface / multidownload.pl
Revision 1.7: download - view: text, annotated - select for diffs
Thu Apr 26 17:43:24 2007 UTC (17 years ago) by banghart
Branches: MAIN
CVS tags: HEAD
	Make directory root for workspace unique.

    1: #!/usr/bin/perl
    2: # CGI-script to allow download of all essay submissions of 
    3: # multiple students.
    4: #
    5: # $Id: multidownload.pl,v 1.7 2007/04/26 17:43:24 banghart Exp $
    6: #
    7: # Copyright Michigan State University Board of Trustees
    8: #
    9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   10: #
   11: # LON-CAPA is free software; you can redistribute it and/or modify
   12: # it under the terms of the GNU General Public License as published by
   13: # the Free Software Foundation; either version 2 of the License, or
   14: # (at your option) any later version.
   15: #
   16: # LON-CAPA is distributed in the hope that it will be useful,
   17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19: # GNU General Public License for more details.
   20: #
   21: # You should have received a copy of the GNU General Public License
   22: # along with LON-CAPA; if not, write to the Free Software
   23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24: #
   25: # /home/httpd/html/adm/gpl.txt
   26: #
   27: # http://www.lon-capa.org/
   28: #
   29: 
   30: use lib '/home/httpd/lib/perl';
   31: use LONCAPA::loncgi;
   32: use File::Path;
   33: use File::Basename;
   34: use File::Copy;
   35: use IO::File;
   36: use Image::Magick;
   37: use Apache::lonhtmlcommon();
   38: use Apache::lonnet;
   39: use Apache::grades;
   40: use Apache::loncommon();
   41: use Apache::lonlocal;
   42: use Apache::lonmsg();
   43: use Apache::lonnet;
   44: use LONCAPA::Enrollment;
   45: use strict;
   46: 
   47: $|=1;
   48: if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
   49:     print <<END;
   50: Content-type: text/html
   51: 
   52: <html>
   53: <head><title>Bad Cookie</title></head>
   54: <body>
   55: Your cookie information is incorrect.
   56: </body>
   57: </html>
   58: END
   59:     return;
   60: }
   61: &Apache::lonlocal::get_language_handle();
   62: &Apache::loncommon::content_type(undef,'text/html');
   63: my $identifier = $ENV{'QUERY_STRING'};
   64: print(&Apache::loncommon::start_page('Multiple Downloads'));
   65: 
   66: my $scope = $env{'request.course.id'};
   67: if ($env{'request.course.sec'}) {
   68:     $scope .= '/'.$env{'request.course.sec'};
   69: }
   70: if (&Apache::lonnet::allowed('vgr',$scope) eq 'F') {
   71:     my $symb = $env{'cgi.'.$identifier.'.symb'};
   72:     my $courseid = $env{'request.course.id'};
   73:     my @stuchecked = split(/\n/,$env{'cgi.'.$identifier.'.students'});
   74:     my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'});
   75:     my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
   76:     my @part_response_id = &Apache::grades::flatten_responseType($responseType);
   77:     my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'};
   78:     my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
   79:     my $uname = $env{'user.name'};
   80:     my $udom = $env{'user.domain'};
   81:     mkdir($doc_zip_root."/zipdir",0700);
   82:     mkdir($doc_zip_root."/zipdir/$identifier",0700);
   83:     foreach my $stu (@stuchecked) {
   84:         my ($stuname,$studom,$fullname) = split(/:/,$stu);
   85:         mkdir($doc_zip_root."/zipdir/$identifier/$stuname",0700);
   86:         my %record = &Apache::lonnet::restore($symb,$courseid,$studom,$stuname);
   87:         foreach my $part (@part_response_id) {
   88:             my ($partid,$respid) = @{$part};
   89:             mkdir($doc_zip_root."/zipdir/$identifier/$stuname/part$partid",0700);
   90:             mkdir($doc_zip_root."/zipdir/$identifier/$stuname/part$partid/resp$respid",0700);
   91:             my $files = &Apache::grades::get_submitted_files($studom,$stuname,$partid,$respid,\%record);
   92:             foreach my $file (@$files) {
   93:                 $file =~ /(^.*\/)(.+$)/;
   94:                 my $file_name_only = $2;
   95:                 my $file_content = &Apache::lonnet::getfile($file);
   96:                 if (open(my $fh,">$doc_zip_root/zipdir/$identifier/$stuname/part$partid/resp$respid/$file_name_only")) {
   97:                     print($fh $file_content);
   98:                     close($fh);
   99:                 } else {
  100:                     print("problem creating file <br />");
  101:                 }
  102:             }
  103:         }
  104:     }
  105:     mkdir($doc_zip_root."/zipout",0777);
  106:     my $statement = "zip -r $doc_zip_root/zipout/output.zip $doc_zip_root/zipdir/$identifier/* > /dev/null";
  107:     system($statement);
  108:     $statement = "rm -rf $doc_zip_root/zipdir/$identifier";
  109:     system($statement);
  110:     print('<a href="/zipspool/zipout/output.zip">Click to download</a><br />');
  111: } else {
  112:     print('You are not authorized to download student submissions.');
  113: }
  114: 1;
  115: __END__;

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