version 1.42, 2018/05/02 16:59:44
|
version 1.43, 2020/09/02 14:52:08
|
Line 130 if ($scope eq '') {
|
Line 130 if ($scope eq '') {
|
my $number_of_students = scalar(@stuchecked); |
my $number_of_students = scalar(@stuchecked); |
my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('',$number_of_students); |
my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('',$number_of_students); |
my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'}); |
my @parts = split(/\n/,$env{'cgi.'.$identifier.'.parts'}); |
my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'}; |
my @getparts; |
my $manifest; |
if (ref($partlist) eq 'ARRAY') { |
unless (-d "$doc_zip_root/zipdir/$unique_user/$unique_path") { |
if (@parts) { |
&File::Path::mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path",0,0700); |
foreach my $posspart (@{$partlist}) { |
|
if (grep(/^\Q$posspart\E$/,@parts)) { |
|
unless (grep(/^\Q$posspart\E$/,@getparts)) { |
|
push(@getparts,$posspart); |
|
} |
|
} |
|
} |
|
} else { |
|
@getparts = @{$partlist}; |
|
} |
} |
} |
if (open(MANIFEST,'>',"$doc_zip_root/zipdir/$unique_user/$unique_path/manifest.txt")) { |
if (!@getparts) { |
$manifest = 1; |
print(&mt('No problem parts specified for retrieval of submissions.')); |
print MANIFEST (&mt("Zip file generated on [_1]",&Apache::lonlocal::locallocaltime(time()))."\n"); |
} elsif (!$number_of_students) { |
print MANIFEST (&mt("Course: [_1]",$env{"course.$courseid.description"})."\n"); |
print(&mt('No students selected for retrieval of submissions.')); |
print MANIFEST (&mt("Problem: [_1]",$res->compTitle)."\n"); |
|
print MANIFEST (&mt("Files contained in this zip:")."\n"); |
|
} else { |
} else { |
&Apache::lonnet::logthis("Problem making manifest"); |
my $doc_zip_root = $Apache::lonnet::perlvar{'lonZipDir'}; |
} |
my $manifest; |
my $file_problem = 0; |
unless (-d "$doc_zip_root/zipdir/$unique_user/$unique_path") { |
my $current_student = 0; |
&File::Path::mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path",0,0700); |
foreach my $stu (@stuchecked) { |
|
$current_student ++; |
|
&Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,&mt("Processing student [_1] of [_2]",$current_student,$number_of_students)); |
|
my %files_saved; |
|
my ($stuname,$studom,$fullname) = split(/:/,$stu); |
|
my %record = &Apache::lonnet::restore($symb,$courseid,$studom,$stuname); |
|
my $port_url = '/uploaded/'.$studom.'/'.$stuname.'/portfolio'; |
|
if ($manifest) { |
|
print MANIFEST ($fullname."\n"); |
|
} |
} |
|
if (open(MANIFEST,'>',"$doc_zip_root/zipdir/$unique_user/$unique_path/manifest.txt")) { |
my $submission_count = 0; |
$manifest = 1; |
foreach my $partid (@$partlist) { |
print MANIFEST (&mt("Zip file generated on [_1]",&Apache::lonlocal::locallocaltime(time()))."\n"); |
my @ids = $res->responseIds($partid); |
print MANIFEST (&mt("Course: [_1]",$env{"course.$courseid.description"})."\n"); |
foreach my $respid (@ids) { |
print MANIFEST (&mt("Problem: [_1]",$res->compTitle)."\n"); |
my $part_resp_path = &get_part_resp_path($flat_part,$flat_resp, $partid, $respid); |
print MANIFEST (&mt("Files contained in this zip:")."\n"); |
&File::Path::mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path/$stuname/$part_resp_path",0,0700); |
} else { |
foreach my $origin ('portfiles','uploadedurl') { |
&Apache::lonnet::logthis("Problem making manifest"); |
my @files; |
} |
if ($record{"resource.$partid.$respid.$origin"} ne '') { |
my $file_problem = 0; |
if ($origin eq 'portfiles') { |
my $current_student = 0; |
@files = (split(',',$record{"resource.$partid.$respid.$origin"})); |
foreach my $stu (@stuchecked) { |
} else { |
$current_student ++; |
@files = ($record{"resource.$partid.$respid.$origin"}); |
&Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,&mt("Processing student [_1] of [_2]",$current_student,$number_of_students)); |
} |
my %files_saved; |
} |
my ($stuname,$studom,$fullname) = split(/:/,$stu); |
foreach my $file (@files) { |
my %record = &Apache::lonnet::restore($symb,$courseid,$studom,$stuname); |
if ($origin eq 'portfiles') { |
my $port_url = '/uploaded/'.$studom.'/'.$stuname.'/portfolio'; |
$file = $port_url.$file; |
if ($manifest) { |
} |
print MANIFEST ($fullname."\n"); |
my ($file_name_only) = ($file =~ m{.*/([^/]+)$}); |
} |
if ($manifest) { |
|
print MANIFEST ("\t$file_name_only (".&mt("Part [_1]",$partid). |
my $submission_count = 0; |
") (".&mt("Response [_1]",$respid).")"."\n"); |
foreach my $partid (@getparts) { |
|
my @ids = $res->responseIds($partid); |
|
foreach my $respid (@ids) { |
|
my $part_resp_path = &get_part_resp_path($flat_part,$flat_resp, $partid, $respid); |
|
&File::Path::mkpath($doc_zip_root."/zipdir/$unique_user/$unique_path/$stuname/$part_resp_path",0,0700); |
|
foreach my $origin ('portfiles','uploadedurl') { |
|
my @files; |
|
if ($record{"resource.$partid.$respid.$origin"} ne '') { |
|
if ($origin eq 'portfiles') { |
|
@files = (split(',',$record{"resource.$partid.$respid.$origin"})); |
|
} else { |
|
@files = ($record{"resource.$partid.$respid.$origin"}); |
|
} |
} |
} |
$submission_count ++; |
foreach my $file (@files) { |
&Apache::lonnet::repcopy($file); |
if ($origin eq 'portfiles') { |
my $source = &Apache::lonnet::filelocation("",$file); |
$file = $port_url.$file; |
my $destination = "$doc_zip_root/zipdir/$unique_user/$unique_path/$stuname$part_resp_path/$file_name_only"; |
} |
if (exists($files_saved{$destination})) { |
my ($file_name_only) = ($file =~ m{.*/([^/]+)$}); |
# file has already been saved once |
if ($manifest) { |
my ($file_name,$file_ext) = |
print MANIFEST ("\t$file_name_only (".&mt("Part [_1]",$partid). |
($destination =~ /(^.*)(\..+$)/); |
") (".&mt("Response [_1]",$respid).")"."\n"); |
$destination = $file_name.$files_saved{$destination}.$file_ext; |
} |
|
$submission_count ++; |
|
&Apache::lonnet::repcopy($file); |
|
my $source = &Apache::lonnet::filelocation("",$file); |
|
my $destination = "$doc_zip_root/zipdir/$unique_user/$unique_path/$stuname$part_resp_path/$file_name_only"; |
|
if (exists($files_saved{$destination})) { |
|
# file has already been saved once |
|
my ($file_name,$file_ext) = |
|
($destination =~ /(^.*)(\..+$)/); |
|
$destination = $file_name.$files_saved{$destination}.$file_ext; |
|
$files_saved{$destination}++; |
|
} |
$files_saved{$destination}++; |
$files_saved{$destination}++; |
} |
if (!©($source,$destination)) { |
$files_saved{$destination}++; |
if (!$file_problem) { |
if (!©($source,$destination)) { |
print('<br /><span class="LC_error">'.&mt("Unable to create: ")."</span><br />"); |
if (!$file_problem) { |
$file_problem = 1; |
print('<br /><span class="LC_error">'.&mt("Unable to create: ")."</span><br />"); |
} |
$file_problem = 1; |
print('<span class="LC_filename">'."$stuname/part$partid/resp$respid/$file_name_only".'</span><br />'); |
} |
} |
print('<span class="LC_filename">'."$stuname/part$partid/resp$respid/$file_name_only".'</span><br />'); |
|
} |
} |
} |
} |
} |
} |
} |
} |
|
if ((!$submission_count) && ($manifest)) { |
|
print MANIFEST ("\t".&mt("No Files Submitted")."\n"); |
|
} |
} |
} |
if ((!$submission_count) && ($manifest)) { |
if ($manifest) { |
print MANIFEST ("\t".&mt("No Files Submitted")."\n"); |
close(MANIFEST); |
} |
} |
} |
my $madezip; |
if ($manifest) { |
unless (-d "$doc_zip_root/zipout/$unique_user") { |
close(MANIFEST); |
&File::Path::mkpath($doc_zip_root."/zipout/$unique_user",0,0700); |
} |
} |
my $madezip; |
if ((-d "$doc_zip_root/zipout/$unique_user") && |
unless (-d "$doc_zip_root/zipout/$unique_user") { |
(-d "$doc_zip_root/zipdir/$unique_user/$unique_path")) { |
&File::Path::mkpath($doc_zip_root."/zipout/$unique_user",0,0700); |
if (!-e "$doc_zip_root/zipout/$unique_user/$zipout") { |
} |
my $zip = Archive::Zip->new(); |
if ((-d "$doc_zip_root/zipout/$unique_user") && |
$zip->addTree("$doc_zip_root/zipdir/$unique_user/$unique_path"); |
(-d "$doc_zip_root/zipdir/$unique_user/$unique_path")) { |
if ($zip->writeToFileNamed("$doc_zip_root/zipout/$unique_user/$zipout") == AZ_OK) { |
if (!-e "$doc_zip_root/zipout/$unique_user/$zipout") { |
$madezip = 1; |
my $zip = Archive::Zip->new(); |
} |
$zip->addTree("$doc_zip_root/zipdir/$unique_user/$unique_path"); |
} else { |
if ($zip->writeToFileNamed("$doc_zip_root/zipout/$unique_user/$zipout") == AZ_OK) { |
$madezip = 1; |
$madezip = 1; |
# should happen only if user reloads page |
} |
&Apache::lonnet::logthis("$zipout is already there"); |
|
} |
|
&File::Path::remove_tree("$doc_zip_root/zipdir/$unique_user/$unique_path",{ safe => 1, }); |
|
} |
|
&Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); |
|
if ($madezip) { |
|
print('<p><a href="/zipspool/zipout/'.$unique_user.'/'.$zipout.'">'. |
|
&mt("Click to download").'</a></p><br />'); |
} else { |
} else { |
$madezip = 1; |
print('<p class="LC_error">'. |
# should happen only if user reloads page |
&mt('Failed to create zip archive of student submissions'). |
&Apache::lonnet::logthis("$zipout is already there"); |
'</p>'); |
} |
} |
&File::Path::remove_tree("$doc_zip_root/zipdir/$unique_user/$unique_path",{ safe => 1, }); |
|
} |
|
&Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); |
|
if ($madezip) { |
|
print('<p><a href="/zipspool/zipout/'.$unique_user.'/'.$zipout.'">'. |
|
&mt("Click to download").'</a></p><br />'); |
|
} else { |
|
print('<p class="LC_error">'. |
|
&mt('Failed to create zip archive of student submissions'). |
|
'</p>'); |
|
} |
} |
} else { |
} else { |
print('<p class="LC_error">'. |
print('<p class="LC_error">'. |