File:
[LON-CAPA] /
loncom /
interface /
multidownload.pl
Revision
1.38:
download - view:
text,
annotated -
select for diffs
Tue Dec 30 23:18:24 2008 UTC (15 years, 8 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_99_1,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
bz6209-base,
bz6209,
bz5969,
bz2851,
PRINT_INCOMPLETE_base,
PRINT_INCOMPLETE,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ5971-printing-apage,
BZ5434-fox
- Missing cookie message generated from &LONCAPA::loncgi::missing_cookie_msg().
- zip file can contain directly uploaded files as well as files submitted from a portfolio.
- CSS: LC_error and LC_filename
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.38 2008/12/30 23:18:24 raeburn Exp $
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: use lib '/home/httpd/lib/perl';
30: use LONCAPA::loncgi;
31: use File::Path;
32: use File::Basename;
33: use File::Copy;
34: use Apache::lonhtmlcommon();
35: use Apache::lonnavmaps();
36: use Apache::loncommon();
37: use Apache::lonlocal;
38: use Apache::lonmsg();
39: use Apache::lonnet;
40: use LONCAPA::Enrollment;
41: use strict;
42:
43: sub is_flat {
44: my ($partlist, $res) = @_;
45: my $flat_part = 1;
46: my $flat_resp = 1;
47: if (scalar(@$partlist) > 1) {
48: $flat_part = 0;
49: }
50: foreach my $partid (@$partlist) {
51: my @ids = $res->responseIds($partid);
52: if (scalar(@ids) > 1 ) {
53: $flat_resp = 0;
54: }
55: }
56: return ($flat_part, $flat_resp);
57: }
58:
59:
60: sub get_part_resp_path {
61: my ($flat_part, $flat_resp, $part_id, $resp_id) = @_;
62: my $part_resp_path = "";
63: if (!$flat_part) {
64: $part_resp_path = "part$part_id/";
65: }
66: if (!$flat_resp) {
67: $part_resp_path .= "resp$resp_id/";
68: }
69: $part_resp_path =~ s/\/^//;
70: return('/'.$part_resp_path);
71: }
72:
73:
74: $|=1;
75: &Apache::lonlocal::get_language_handle();
76: &Apache::loncommon::content_type(undef,'text/html');
77: if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
78: print(&LONCAPA::loncgi::missing_cookie_msg());
79: return;
80: }
81:
82: my $identifier = $ENV{'QUERY_STRING'};
83: my $unique_path = $identifier.time();
84: print(&Apache::loncommon::start_page('Multiple Downloads'));
85:
86:
87: my $scope = $env{'request.course.id'};
88: if ($env{'request.course.sec'}) {
89: $scope .= '/'.$env{'request.course.sec'};
90: }
91: if (&Apache::lonnet::allowed('vgr',$scope) eq 'F') {
92: my $symb = $env{'cgi.'.$identifier.'.symb'};
93: my $navmap = Apache::lonnavmaps::navmap->new();
94: my $res = $navmap->getBySymb($symb);
95: my $partlist = $res->parts();
96: my ($flat_part, $flat_resp) = &is_flat($partlist, $res);
97: my ($zipout) = ($symb =~ /^.*\/(.+)\.problem$/);
98: $zipout =~ s/\s/_/g;
99: $zipout .= "$identifier.zip";
100: my $courseid = $env{'request.course.id'};
101: my @stuchecked = split(/\n/,$env{'cgi.'.$identifier.'.students'});
102: my $number_of_students = scalar(@stuchecked);
103: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Processing Status',
104: 'Preparing Zip File',$number_of_students,'inline','80');
105: my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'});
106: my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'};
107: my $uname = $env{'user.name'};
108: my $udom = $env{'user.domain'};
109: my $unique_user = $uname.":".$udom;
110: &mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path",0,0700);
111: if (!open(MANIFEST, ">$doc_zip_root/zipdir/$unique_user/$unique_path/manifest.txt")) {
112: &Apache::lonnet::logthis("Problem making manifest");
113: }
114: print MANIFEST (&mt("Zip file generated on [_1]",&Apache::lonlocal::locallocaltime(time()))."\n");
115: print MANIFEST (&mt("Course: [_1]",$env{"course.$courseid.description"})."\n");
116: print MANIFEST (&mt("Problem: [_1]",$res->compTitle)."\n");
117: print MANIFEST (&mt("Files contained in this zip:")."\n");
118: my $file_problem = 0;
119: my $current_student = 0;
120: foreach my $stu (@stuchecked) {
121: $current_student ++;
122: &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,"Processing student $current_student of $number_of_students");
123: my %files_saved;
124: my ($stuname,$studom,$fullname) = split(/:/,$stu);
125: my %record = &Apache::lonnet::restore($symb,$courseid,$studom,$stuname);
126: my $port_url = '/uploaded/'.$studom.'/'.$stuname.'/portfolio';
127: print MANIFEST ($fullname."\n");
128:
129: my $submission_count = 0;
130: foreach my $partid (@$partlist) {
131: my @ids = $res->responseIds($partid);
132: foreach my $respid (@ids) {
133: my $part_resp_path = &get_part_resp_path($flat_part,$flat_resp, $partid, $respid);
134: &mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path/$stuname/$part_resp_path",0,0700);
135: foreach my $origin ('portfiles','uploadedurl') {
136: my @files;
137: if ($record{"resource.$partid.$respid.$origin"} ne '') {
138: if ($origin eq 'portfiles') {
139: @files = (split(',',$record{"resource.$partid.$respid.$origin"}));
140: } else {
141: @files = ($record{"resource.$partid.$respid.$origin"});
142: }
143: }
144: foreach my $file (@files) {
145: if ($origin eq 'portfiles') {
146: $file = $port_url.$file;
147: }
148: my ($file_name_only) = ($file =~ m{.*/([^/]+)$});
149: print MANIFEST ("\t$file_name_only (".&mt("Part [_1]",$partid).
150: ") (".&mt("Response [_1]",$respid).")"."\n");
151: $submission_count ++;
152: &Apache::lonnet::repcopy($file);
153: my $source = &Apache::lonnet::filelocation("",$file);
154: my $destination = "$doc_zip_root/zipdir/$unique_user/$unique_path/$stuname$part_resp_path/$file_name_only";
155: if (exists($files_saved{$destination})) {
156: # file has already been saved once
157: my ($file_name,$file_ext) =
158: ($destination =~ /(^.*)(\..+$)/);
159: $destination = $file_name.$files_saved{$destination}.$file_ext;
160: $files_saved{$destination}++;
161: }
162: $files_saved{$destination}++;
163: if (!©($source,$destination)) {
164: if (!$file_problem) {
165: print('<br /><span class="LC_error">'.&mt("Unable to create: ")."</span><br />");
166: $file_problem = 1;
167: }
168: print('<span class="LC_filename">'."$stuname/part$partid/resp$respid/$file_name_only".'</span><br />');
169: }
170: }
171: }
172: }
173: }
174: if (!$submission_count) {
175: print MANIFEST ("\t".&mt("No Files Submitted")."\n");
176: }
177: }
178:
179: &mkpath($doc_zip_root."/zipout/$unique_user",0,0700);
180: my $statement;
181: if (! -e "$doc_zip_root/zipout/$unique_user/$zipout") {
182: $statement = "cd $doc_zip_root/zipdir/$unique_user/$unique_path\n";
183: $statement .= "zip -r $doc_zip_root/zipout/$unique_user/$zipout * > /dev/null";
184: system($statement);
185: } else {
186: # should happen only if user reloads page
187: &Apache::lonnet::logthis("$zipout is already there");
188: }
189: $statement = "rm -rf $doc_zip_root/zipdir/$unique_user/$unique_path";
190: system($statement);
191: &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state);
192: print('<p><a href="/zipspool/zipout/'.$unique_user.'/'.$zipout.'">'.
193: &mt("Click to download").'</a></p><br />');
194: close(MANIFEST);
195: } else {
196: print(&mt('You are not authorized to download student submissions.'));
197: }
198: 1;
199: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>