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

1.1       banghart    1: #!/usr/bin/perl
                      2: # CGI-script to allow download of all essay submissions of 
                      3: # multiple students.
                      4: #
1.20    ! banghart    5: # $Id: multidownload.pl,v 1.19 2007/04/27 22:43:11 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();
1.16      banghart   37: use Apache::grades;
                     38: use Apache::lonnavmaps;
1.1       banghart   39: use Apache::lonnet;
                     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'};
1.8       banghart   64: my $unique_path = $identifier.time();
1.1       banghart   65: print(&Apache::loncommon::start_page('Multiple Downloads'));
1.6       banghart   66: 
                     67: my $scope = $env{'request.course.id'};
                     68: if ($env{'request.course.sec'}) {
                     69:     $scope .= '/'.$env{'request.course.sec'};
                     70: }
                     71: if (&Apache::lonnet::allowed('vgr',$scope) eq 'F') {
1.4       banghart   72:     my $symb = $env{'cgi.'.$identifier.'.symb'};
1.16      banghart   73:     my $navmap = Apache::lonnavmaps::navmap->new();
                     74:     my $res = $navmap->getBySymb($symb);
1.19      banghart   75:     my $partlist = $res->parts();
1.16      banghart   76:     my ($zipout) = ($symb =~ /^.*\/(.+)\.problem$/);
1.10      banghart   77:     $zipout =~ s/\s/_/g;
1.16      banghart   78:     $zipout .= ".zip";
1.4       banghart   79:     my $courseid = $env{'request.course.id'};
                     80:     my @stuchecked = split(/\n/,$env{'cgi.'.$identifier.'.students'});
                     81:     my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'});
                     82:     my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'};
1.5       banghart   83:     my $uname = $env{'user.name'};
                     84:     my $udom = $env{'user.domain'};
1.16      banghart   85:     my $unique_user = $uname.":".$udom;
                     86:     &mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path",0,0700);
1.15      banghart   87:     my $file_problem = 0;
1.4       banghart   88:     foreach my $stu (@stuchecked) {
1.15      banghart   89:         my %files_saved;
1.5       banghart   90:         my ($stuname,$studom,$fullname) = split(/:/,$stu);
                     91:         my %record = &Apache::lonnet::restore($symb,$courseid,$studom,$stuname);
1.20    ! banghart   92:         my $file_url = '/uploaded/'.$studom.'/'.$stuname.'/portfolio';
1.19      banghart   93:         foreach my $partid (@$partlist) {
                     94:             my @ids = $res->responseIds($partid);
                     95:             foreach my $respid(@ids) {
                     96:                 &mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path/$stuname/part$partid/resp$respid",0,0700);
1.20    ! banghart   97:                 foreach my $file (split(',',$record{"resource.$partid.$respid.portfiles"})) {
        !            98:                     $file = $file_url.$file;
1.19      banghart   99:                     my ($file_name_only) = ($file =~ /^.*\/(.+$)/);
                    100:                     &Apache::lonnet::repcopy($file);
                    101:                     my $source = &Apache::lonnet::filelocation("",$file);
                    102:                     my $destination = "$doc_zip_root/zipdir/$unique_user/$unique_path/$stuname/part$partid/resp$respid/$file_name_only";
                    103:                     if (exists($files_saved{$destination})) {
                    104:                         # file has already been saved once
                    105:                         my ($file_name,$file_ext) = ($destination =~ /(^.*)(\..+$)/);
                    106:                         $destination = $file_name.$files_saved{$destination}.$file_ext;
                    107:                         $files_saved{$destination} ++;
                    108:                     }
                    109:                     $files_saved{$destination}++;
                    110:                     if (!&copy($source,$destination)) {
                    111:                         if (!$file_problem) {
                    112:                             print &mt("Unable to create: <br />");
                    113:                             $file_problem = 1;
                    114:                         }
                    115:                         print ("$stuname/part$partid/resp$respid/$file_name_only <br />");
1.14      banghart  116:                     }
                    117:                 }
1.2       banghart  118:             }
1.1       banghart  119:         }
                    120:     }
1.16      banghart  121:     &mkpath($doc_zip_root."/zipout/$unique_user",0,0700);
                    122:     my $statement = "cd $doc_zip_root/zipdir/$unique_user/$unique_path\n";
                    123:     $statement .= "zip -r $doc_zip_root/zipout/$unique_user/$zipout * > /dev/null";
1.4       banghart  124:     system($statement);
1.16      banghart  125:     $statement = "rm -rf $doc_zip_root/zipdir/$unique_user/$unique_path";
1.4       banghart  126:     system($statement);
1.16      banghart  127:     print('<a href="/zipspool/zipout/'.$unique_user.'/'.$zipout.'">'.
1.13      banghart  128:             &mt("Click to download").'</a><br />');
1.4       banghart  129: } else {
1.13      banghart  130:     print(&mt('You are not authorized to download student submissions.'));
1.1       banghart  131: }
1.6       banghart  132: 1;
                    133: __END__;

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