Annotation of loncom/interface/multidownload.pl, revision 1.5

1.1       banghart    1: #!/usr/bin/perl
                      2: # CGI-script to allow download of all essay submissions of 
                      3: # multiple students.
                      4: #
1.5     ! banghart    5: # $Id: multidownload.pl,v 1.4 2007/04/25 00:32:49 banghart Exp $
1.1       banghart    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();
1.2       banghart   43: use Apache::lonnet;
1.1       banghart   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'));
1.5     ! banghart   65: my $scope .= '/'.$env{'request.course.sec'};
        !            66: if (&Apache::lonnet::allowed('vgr',$scope)) {
1.4       banghart   67:     my $symb = $env{'cgi.'.$identifier.'.symb'};
                     68:     my $courseid = $env{'request.course.id'};
                     69:     my @stuchecked = split(/\n/,$env{'cgi.'.$identifier.'.students'});
                     70:     my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'});
                     71:     my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
                     72:     my @part_response_id = &Apache::grades::flatten_responseType($responseType);
                     73:     my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'};
                     74:     my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
1.5     ! banghart   75:     my $uname = $env{'user.name'};
        !            76:     my $udom = $env{'user.domain'};
        !            77:     mkdir($doc_zip_root."/zipdir",0700);
        !            78:     mkdir($doc_zip_root."/zipdir/$uname$udom",0700);
1.4       banghart   79:     foreach my $stu (@stuchecked) {
1.5     ! banghart   80:         my ($stuname,$studom,$fullname) = split(/:/,$stu);
        !            81:         mkdir($doc_zip_root."/zipdir/$uname$udom/$stuname",0700);
        !            82:         my %record = &Apache::lonnet::restore($symb,$courseid,$studom,$stuname);
1.4       banghart   83:         foreach my $part (@part_response_id) {
                     84:             my ($partid,$respid) = @{$part};
1.5     ! banghart   85:             mkdir($doc_zip_root."/zipdir/$uname$udom/$stuname/part$partid",0700);
        !            86:             mkdir($doc_zip_root."/zipdir/$uname$udom/$stuname/part$partid/resp$respid",0700);
        !            87:             my $files = &Apache::grades::get_submitted_files($studom,$stuname,$partid,$respid,\%record);
1.4       banghart   88:             foreach my $file (@$files) {
                     89:                 $file =~ /(^.*\/)(.+$)/;
                     90:                 my $file_name_only = $2;
                     91:                 my $file_content = &Apache::lonnet::getfile($file);
1.5     ! banghart   92:                 if (open(my $fh,">$doc_zip_root/zipdir/$uname$udom/$stuname/part$partid/resp$respid/$file_name_only")) {
1.4       banghart   93:                     print($fh $file_content);
                     94:                     close($fh);
                     95:                 } else {
                     96:                     print("problem creating file <br />");
                     97:                 }
1.2       banghart   98:             }
1.1       banghart   99:         }
                    100:     }
1.4       banghart  101:     mkdir($doc_zip_root."/zipout",0777);
1.5     ! banghart  102:     my $statement = "zip -r $doc_zip_root/zipout/output.zip $doc_zip_root/zipdir/$uname$udom/* > /dev/null";
1.4       banghart  103:     system($statement);
1.5     ! banghart  104:     $statement = "rm -rf $doc_zip_root/zipdir/$uname$udom";
1.4       banghart  105:     system($statement);
1.5     ! banghart  106:     print('<a href="/zipspool/zipout/output.zip">Click to download</a><br />');
1.4       banghart  107: } else {
                    108:     print('You are not authorized to download student submissions.');
1.1       banghart  109: }
1.5     ! banghart  110: 

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