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.4 2007/04/25 00:32:49 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: sub is_student {
48: return ($env{'request.role'}=~/^st\./);
49: }
50:
51: $|=1;
52: if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
53: print <<END;
54: Content-type: text/html
55:
56: <html>
57: <head><title>Bad Cookie</title></head>
58: <body>
59: Your cookie information is incorrect.
60: </body>
61: </html>
62: END
63: return;
64: }
65: &Apache::lonlocal::get_language_handle();
66: &Apache::loncommon::content_type(undef,'text/html');
67: my $identifier = $ENV{'QUERY_STRING'};
68: print(&Apache::loncommon::start_page('Multiple Downloads'));
69: $env{'request.role'} =~ m/^(.+)\./;
70: my $role = $1;
71: if ($role eq 'cc') {
72: my $symb = $env{'cgi.'.$identifier.'.symb'};
73: my $courseid = $env{'request.course.id'};
74: my @stuchecked = split(/\n/,$env{'cgi.'.$identifier.'.students'});
75: my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'});
76: my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
77: my @part_response_id = &Apache::grades::flatten_responseType($responseType);
78: my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'};
79: my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
80: mkdir($doc_zip_root."/zipdir",0777);
81: foreach my $stu (@stuchecked) {
82: my ($uname,$udom,$fullname) = split(/:/,$stu);
83: mkdir($doc_zip_root."/zipdir/$uname",0777);
84: my %record = &Apache::lonnet::restore($symb,$courseid,$udom,$uname);
85: foreach my $part (@part_response_id) {
86: my ($partid,$respid) = @{$part};
87: mkdir($doc_zip_root."/zipdir/$uname/part$partid",0777);
88: mkdir($doc_zip_root."/zipdir/$uname/part$partid/resp$respid",0777);
89: my $files = &Apache::grades::get_submitted_files($udom,$uname,$partid,$respid,\%record);
90: foreach my $file (@$files) {
91: $file =~ /(^.*\/)(.+$)/;
92: my $file_name_only = $2;
93: my $file_content = &Apache::lonnet::getfile($file);
94: if (open(my $fh,">$doc_zip_root/zipdir/$uname/part$partid/resp$respid/$file_name_only")) {
95: print($fh $file_content);
96: close($fh);
97: } else {
98: print("problem creating file <br />");
99: }
100: }
101: }
102: }
103: mkdir($doc_zip_root."/zipout",0777);
104: my $statement = "zip -r $doc_zip_root/zipout/output.zip $doc_zip_root/zipdir/* > /dev/null";
105: system($statement);
106: $statement = "rm -rf $doc_zip_root/zipdir";
107: system($statement);
108: print('<a href="../zipout/output.zip">Click to download</a><br />');
109: } else {
110: print('You are not authorized to download student submissions.');
111: }
112: # print($env{'request.role'}.' == roles <br />');
113: return 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>