[LON-CAPA-cvs] cvs: loncom /interface multidownload.pl
banghart
lon-capa-cvs-allow@mail.lon-capa.org
Thu, 05 Apr 2007 00:50:32 -0000
banghart Wed Apr 4 20:50:32 2007 EDT
Modified files:
/loncom/interface multidownload.pl
Log:
Saving work in progress. Doesn't work yet.
Index: loncom/interface/multidownload.pl
diff -u loncom/interface/multidownload.pl:1.1 loncom/interface/multidownload.pl:1.2
--- loncom/interface/multidownload.pl:1.1 Fri Mar 30 18:57:39 2007
+++ loncom/interface/multidownload.pl Wed Apr 4 20:50:32 2007
@@ -2,7 +2,7 @@
# CGI-script to allow download of all essay submissions of
# multiple students.
#
-# $Id: multidownload.pl,v 1.1 2007/03/30 22:57:39 banghart Exp $
+# $Id: multidownload.pl,v 1.2 2007/04/05 00:50:32 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,6 +40,7 @@
use Apache::loncommon();
use Apache::lonlocal;
use Apache::lonmsg();
+use Apache::lonnet;
use LONCAPA::Enrollment;
use strict;
@@ -64,26 +65,35 @@
my $identifier = $ENV{'QUERY_STRING'};
print(&Apache::loncommon::start_page('Multiple Downloads'));
my $symb = $env{'cgi.'.$identifier.'.symb'};
-my $courseid = $env{'cgi.'.$identifier.'.courseid'};
+my $courseid = $env{'request.course.id'};
my @stuchecked = split /\n/,$env{'cgi.'.$identifier.'.students'};
my @parts = split /\n/,$env{'cgi.'.$identifier.'.parts'};
my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
my @part_response_id = &Apache::grades::flatten_responseType($responseType);
-print "number of parts is: ".@parts."<br />";
+my $doc_root = $Apache::lonnet::perlvar{'lonDocRoot'};
my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb);
-print "in the CGI script <br />";
-foreach (@stuchecked) {
- my ($uname,$udom,$fullname) = split(/:/);
+mkdir($doc_root."/zipdir",0777);
+foreach my $stu (@stuchecked) {
+ my ($uname,$udom,$fullname) = split(/:/,$stu);
+ mkdir($doc_root."/zipdir/$uname",0777);
my %record = &Apache::lonnet::restore($symb,$courseid,$udom,$uname);
- print $uname."<br />";
- foreach my $part(@part_response_id) {
- print $part."<br />";
- my ($partid,$respid) = @{ $part };
+ foreach my $part (@part_response_id) {
+ my ($partid,$respid) = @{$part};
+ mkdir($doc_root."/zipdir/$uname/part$partid",0777);
+ mkdir($doc_root."/zipdir/$uname/part$partid/resp$respid",0777);
my $files = &Apache::grades::get_submitted_files($udom,$uname,$partid,$respid,\%record);
- foreach my $file(@$files) {
- print $file."<br />";
+ foreach my $file (@$files) {
+ $file =~ /(^.*\/)(.+$)/;
+ my $file_name_only = $2;
+ my $file_content = &Apache::lonnet::getfile($file);
+ if (open(my $fh,">$doc_root/zipdir/$uname/part$partid/resp$respid/$file_name_only")) {
+ print $fh $file_content;
+ close $fh;
+ } else {
+ print "problem creating file <br />";
+ }
}
}
}
-
-die;
+print '<a href="../zipout/output.zip">Click to download</a>';
+return 1;