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

1.1       banghart    1: #!/usr/bin/perl
                      2: # CGI-script to allow download of all essay submissions of 
                      3: # multiple students.
                      4: #
1.12    ! banghart    5: # $Id: multidownload.pl,v 1.11 2007/04/26 20:26:36 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 Apache::lonhtmlcommon();
                     37: use Apache::lonnet;
                     38: use Apache::grades;
                     39: use Apache::loncommon();
                     40: use Apache::lonlocal;
                     41: use Apache::lonmsg();
1.2       banghart   42: use Apache::lonnet;
1.1       banghart   43: use LONCAPA::Enrollment;
                     44: use strict;
                     45: 
                     46: $|=1;
                     47: if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
                     48:     print <<END;
                     49: Content-type: text/html
                     50: 
                     51: <html>
                     52: <head><title>Bad Cookie</title></head>
                     53: <body>
                     54: Your cookie information is incorrect.
                     55: </body>
                     56: </html>
                     57: END
                     58:     return;
                     59: }
                     60: &Apache::lonlocal::get_language_handle();
                     61: &Apache::loncommon::content_type(undef,'text/html');
                     62: my $identifier = $ENV{'QUERY_STRING'};
1.8       banghart   63: my $unique_path = $identifier.time();
1.1       banghart   64: print(&Apache::loncommon::start_page('Multiple Downloads'));
1.6       banghart   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') {
1.4       banghart   71:     my $symb = $env{'cgi.'.$identifier.'.symb'};
1.10      banghart   72:     $symb =~ /^.*\/(.+)\.problem$/;
                     73:     my $zipout = $1.".zip";
                     74:     $zipout =~ s/\s/_/g;
1.4       banghart   75:     my $courseid = $env{'request.course.id'};
                     76:     my @stuchecked = split(/\n/,$env{'cgi.'.$identifier.'.students'});
                     77:     my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'});
                     78:     my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
                     79:     my @part_response_id = &Apache::grades::flatten_responseType($responseType);
                     80:     my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'};
                     81:     my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
1.5       banghart   82:     my $uname = $env{'user.name'};
                     83:     my $udom = $env{'user.domain'};
1.11      banghart   84:     &mkpath($doc_zip_root."/zipdir/$uname$udom/$unique_path",0,0700);
1.4       banghart   85:     foreach my $stu (@stuchecked) {
1.5       banghart   86:         my ($stuname,$studom,$fullname) = split(/:/,$stu);
                     87:         my %record = &Apache::lonnet::restore($symb,$courseid,$studom,$stuname);
1.4       banghart   88:         foreach my $part (@part_response_id) {
                     89:             my ($partid,$respid) = @{$part};
1.11      banghart   90:             &mkpath($doc_zip_root."/zipdir/$uname$udom/$unique_path/$stuname/part$partid/resp$respid",0,0700);
1.5       banghart   91:             my $files = &Apache::grades::get_submitted_files($studom,$stuname,$partid,$respid,\%record);
1.4       banghart   92:             foreach my $file (@$files) {
                     93:                 $file =~ /(^.*\/)(.+$)/;
                     94:                 my $file_name_only = $2;
1.12    ! banghart   95:                 &Apache::lonnet::repcopy($file);
        !            96:                 my $source = &Apache::lonnet::filelocation("",$file);
        !            97:                 &copy($source,"$doc_zip_root/zipdir/$uname$udom/$unique_path/$stuname/part$partid/resp$respid/$file_name_only");
1.2       banghart   98:             }
1.1       banghart   99:         }
                    100:     }
1.11      banghart  101:     &mkpath($doc_zip_root."/zipout/$uname$udom",0,0700);
1.9       banghart  102:     my $statement = "cd $doc_zip_root/zipdir/$uname$udom/$unique_path\n";
1.10      banghart  103:     $statement .= "zip -r $doc_zip_root/zipout/$uname$udom/$zipout * > /dev/null";
1.4       banghart  104:     system($statement);
1.9       banghart  105:     $statement = "rm -rf $doc_zip_root/zipdir/$uname$udom/$unique_path";
1.4       banghart  106:     system($statement);
1.10      banghart  107:     print('<a href="/zipspool/zipout/'.$uname.$udom.'/'.$zipout.'">Click to download</a><br />');
1.4       banghart  108: } else {
                    109:     print('You are not authorized to download student submissions.');
1.1       banghart  110: }
1.6       banghart  111: 1;
                    112: __END__;

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