Annotation of loncom/interface/multidownload.pl, revision 1.2
1.1 banghart 1: #!/usr/bin/perl
2: # CGI-script to allow download of all essay submissions of
3: # multiple students.
4: #
1.2 ! banghart 5: # $Id: multidownload.pl,v 1.1 2007/03/30 22:57:39 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:
46: use strict;
47:
48:
49: $|=1;
50: if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
51: print <<END;
52: Content-type: text/html
53:
54: <html>
55: <head><title>Bad Cookie</title></head>
56: <body>
57: Your cookie information is incorrect.
58: </body>
59: </html>
60: END
61: return;
62: }
63: &Apache::lonlocal::get_language_handle();
64: &Apache::loncommon::content_type(undef,'text/html');
65: my $identifier = $ENV{'QUERY_STRING'};
66: print(&Apache::loncommon::start_page('Multiple Downloads'));
67: my $symb = $env{'cgi.'.$identifier.'.symb'};
1.2 ! banghart 68: my $courseid = $env{'request.course.id'};
1.1 banghart 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);
1.2 ! banghart 73: my $doc_root = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1 banghart 74: my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
1.2 ! banghart 75: mkdir($doc_root."/zipdir",0777);
! 76: foreach my $stu (@stuchecked) {
! 77: my ($uname,$udom,$fullname) = split(/:/,$stu);
! 78: mkdir($doc_root."/zipdir/$uname",0777);
1.1 banghart 79: my %record = &Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.2 ! banghart 80: foreach my $part (@part_response_id) {
! 81: my ($partid,$respid) = @{$part};
! 82: mkdir($doc_root."/zipdir/$uname/part$partid",0777);
! 83: mkdir($doc_root."/zipdir/$uname/part$partid/resp$respid",0777);
1.1 banghart 84: my $files = &Apache::grades::get_submitted_files($udom,$uname,$partid,$respid,\%record);
1.2 ! banghart 85: foreach my $file (@$files) {
! 86: $file =~ /(^.*\/)(.+$)/;
! 87: my $file_name_only = $2;
! 88: my $file_content = &Apache::lonnet::getfile($file);
! 89: if (open(my $fh,">$doc_root/zipdir/$uname/part$partid/resp$respid/$file_name_only")) {
! 90: print $fh $file_content;
! 91: close $fh;
! 92: } else {
! 93: print "problem creating file <br />";
! 94: }
1.1 banghart 95: }
96: }
97: }
1.2 ! banghart 98: print '<a href="../zipout/output.zip">Click to download</a>';
! 99: return 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>