version 1.4, 2007/04/25 00:32:49
|
version 1.12, 2007/04/26 21:50:27
|
Line 33 use File::Path;
|
Line 33 use File::Path;
|
use File::Basename; |
use File::Basename; |
use File::Copy; |
use File::Copy; |
use IO::File; |
use IO::File; |
use Image::Magick; |
|
use Apache::lonhtmlcommon(); |
use Apache::lonhtmlcommon(); |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::grades; |
use Apache::grades; |
Line 44 use Apache::lonnet;
|
Line 43 use Apache::lonnet;
|
use LONCAPA::Enrollment; |
use LONCAPA::Enrollment; |
use strict; |
use strict; |
|
|
sub is_student { |
|
return ($env{'request.role'}=~/^st\./); |
|
} |
|
|
|
$|=1; |
$|=1; |
if (! &LONCAPA::loncgi::check_cookie_and_load_env()) { |
if (! &LONCAPA::loncgi::check_cookie_and_load_env()) { |
print <<END; |
print <<END; |
Line 65 END
|
Line 60 END
|
&Apache::lonlocal::get_language_handle(); |
&Apache::lonlocal::get_language_handle(); |
&Apache::loncommon::content_type(undef,'text/html'); |
&Apache::loncommon::content_type(undef,'text/html'); |
my $identifier = $ENV{'QUERY_STRING'}; |
my $identifier = $ENV{'QUERY_STRING'}; |
|
my $unique_path = $identifier.time(); |
print(&Apache::loncommon::start_page('Multiple Downloads')); |
print(&Apache::loncommon::start_page('Multiple Downloads')); |
$env{'request.role'} =~ m/^(.+)\./; |
|
my $role = $1; |
my $scope = $env{'request.course.id'}; |
if ($role eq 'cc') { |
if ($env{'request.course.sec'}) { |
|
$scope .= '/'.$env{'request.course.sec'}; |
|
} |
|
if (&Apache::lonnet::allowed('vgr',$scope) eq 'F') { |
my $symb = $env{'cgi.'.$identifier.'.symb'}; |
my $symb = $env{'cgi.'.$identifier.'.symb'}; |
|
$symb =~ /^.*\/(.+)\.problem$/; |
|
my $zipout = $1.".zip"; |
|
$zipout =~ s/\s/_/g; |
my $courseid = $env{'request.course.id'}; |
my $courseid = $env{'request.course.id'}; |
my @stuchecked = split(/\n/,$env{'cgi.'.$identifier.'.students'}); |
my @stuchecked = split(/\n/,$env{'cgi.'.$identifier.'.students'}); |
my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'}); |
my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'}); |
Line 77 if ($role eq 'cc') {
|
Line 79 if ($role eq 'cc') {
|
my @part_response_id = &Apache::grades::flatten_responseType($responseType); |
my @part_response_id = &Apache::grades::flatten_responseType($responseType); |
my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'}; |
my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'}; |
my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb); |
my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($symb); |
mkdir($doc_zip_root."/zipdir",0777); |
my $uname = $env{'user.name'}; |
|
my $udom = $env{'user.domain'}; |
|
&mkpath($doc_zip_root."/zipdir/$uname$udom/$unique_path",0,0700); |
foreach my $stu (@stuchecked) { |
foreach my $stu (@stuchecked) { |
my ($uname,$udom,$fullname) = split(/:/,$stu); |
my ($stuname,$studom,$fullname) = split(/:/,$stu); |
mkdir($doc_zip_root."/zipdir/$uname",0777); |
my %record = &Apache::lonnet::restore($symb,$courseid,$studom,$stuname); |
my %record = &Apache::lonnet::restore($symb,$courseid,$udom,$uname); |
|
foreach my $part (@part_response_id) { |
foreach my $part (@part_response_id) { |
my ($partid,$respid) = @{$part}; |
my ($partid,$respid) = @{$part}; |
mkdir($doc_zip_root."/zipdir/$uname/part$partid",0777); |
&mkpath($doc_zip_root."/zipdir/$uname$udom/$unique_path/$stuname/part$partid/resp$respid",0,0700); |
mkdir($doc_zip_root."/zipdir/$uname/part$partid/resp$respid",0777); |
my $files = &Apache::grades::get_submitted_files($studom,$stuname,$partid,$respid,\%record); |
my $files = &Apache::grades::get_submitted_files($udom,$uname,$partid,$respid,\%record); |
|
foreach my $file (@$files) { |
foreach my $file (@$files) { |
$file =~ /(^.*\/)(.+$)/; |
$file =~ /(^.*\/)(.+$)/; |
my $file_name_only = $2; |
my $file_name_only = $2; |
my $file_content = &Apache::lonnet::getfile($file); |
&Apache::lonnet::repcopy($file); |
if (open(my $fh,">$doc_zip_root/zipdir/$uname/part$partid/resp$respid/$file_name_only")) { |
my $source = &Apache::lonnet::filelocation("",$file); |
print($fh $file_content); |
©($source,"$doc_zip_root/zipdir/$uname$udom/$unique_path/$stuname/part$partid/resp$respid/$file_name_only"); |
close($fh); |
|
} else { |
|
print("problem creating file <br />"); |
|
} |
|
} |
} |
} |
} |
} |
} |
mkdir($doc_zip_root."/zipout",0777); |
&mkpath($doc_zip_root."/zipout/$uname$udom",0,0700); |
my $statement = "zip -r $doc_zip_root/zipout/output.zip $doc_zip_root/zipdir/* > /dev/null"; |
my $statement = "cd $doc_zip_root/zipdir/$uname$udom/$unique_path\n"; |
|
$statement .= "zip -r $doc_zip_root/zipout/$uname$udom/$zipout * > /dev/null"; |
system($statement); |
system($statement); |
$statement = "rm -rf $doc_zip_root/zipdir"; |
$statement = "rm -rf $doc_zip_root/zipdir/$uname$udom/$unique_path"; |
system($statement); |
system($statement); |
print('<a href="../zipout/output.zip">Click to download</a><br />'); |
print('<a href="/zipspool/zipout/'.$uname.$udom.'/'.$zipout.'">Click to download</a><br />'); |
} else { |
} else { |
print('You are not authorized to download student submissions.'); |
print('You are not authorized to download student submissions.'); |
} |
} |
# print($env{'request.role'}.' == roles <br />'); |
1; |
return 1; |
__END__; |