[LON-CAPA-cvs] cvs: loncom /homework essayresponse.pm inputtags.pm
raeburn
raeburn@source.lon-capa.org
Mon, 21 Jun 2010 02:15:38 -0000
This is a MIME encoded message
--raeburn1277086538
Content-Type: text/plain
raeburn Mon Jun 21 02:15:38 2010 EDT
Modified files:
/loncom/homework essayresponse.pm inputtags.pm
Log:
- Improved student interface for managing files submitted to dropbox
over multiple tries.
--raeburn1277086538
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100621021538.txt"
Index: loncom/homework/essayresponse.pm
diff -u loncom/homework/essayresponse.pm:1.107 loncom/homework/essayresponse.pm:1.108
--- loncom/homework/essayresponse.pm:1.107 Thu Jun 17 00:13:20 2010
+++ loncom/homework/essayresponse.pm Mon Jun 21 02:15:37 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# essay (ungraded) style responses
#
-# $Id: essayresponse.pm,v 1.107 2010/06/17 00:13:20 raeburn Exp $
+# $Id: essayresponse.pm,v 1.108 2010/06/21 02:15:37 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -29,7 +29,10 @@
package Apache::essayresponse;
use strict;
use Apache::lonxml();
+use Apache::lonhtmlcommon;
+use Apache::loncommon;
use Apache::lonnet;
+use Apache::lonnavmaps;
use Apache::lonlocal;
use LONCAPA qw(:DEFAULT :match);
@@ -59,27 +62,37 @@
($Apache::lonhomework::type eq 'surveycred') ||
($Apache::lonhomework::type eq 'anonsurvey') ||
($Apache::lonhomework::type eq 'anonsurveycred')) {
- $result.= '<input type="hidden" name="HWDRAFT'.$part.'_'.$id.'" value="yes" /> ';
+ $result.= '<input type="hidden" name="HWDRAFT'.$part.'_'.$id.'" value="yes" />';
}
- $result.='<br /><table border="1">';
+ my $status_text = &mt('Submission type');
+ if ($Apache::lonhomework::history{"resource.$part.award"} eq 'DRAFT') {
+ $status_text .= '<br />'.&mt('(Currently -- draft)');
+ }
+ $result.= '<p>'.&Apache::lonhtmlcommon::start_pick_box().
+ &Apache::lonhtmlcommon::row_title($status_text);
if (($Apache::lonhomework::type ne 'survey') &&
($Apache::lonhomework::type ne 'surveycred') &&
($Apache::lonhomework::type ne 'anonsurvey') &&
($Apache::lonhomework::type ne 'anonsurveycred')) {
- $result.= '<tr><td>'.
+ my $closure;
+ unless ($ncol || $uploadedfiletypes) {
+ $closure = 1;
+ }
+ $result.=
'<label>'.
- '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked="checked" /> '.
+ '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked="checked" /> '.
&mt('Submit entries below as answer to receive credit').
'</label> <br />'.
'<label>'.
- '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no" /> '.
+ '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no" /> '.
&mt('Save entries below (not submitted for credit yet)').
'</label>'.
- '</td></tr>';
+ &Apache::lonhtmlcommon::row_closure($closure);
}
if ($ncol > 0) {
- $result .='<tr><td>'.'<label>'.
+ $result.= &Apache::lonhtmlcommon::row_title(&mt('Collaborators')).
+ '<label>'.
&mt('Collaborators:').' <input type="text" size="70" max="80" name="HWCOL'.
$part.'_'.$id.'" value="'.$coll.'" /><br />'.
&mt('(Enter a maximum of [quant,_1,collaborator] using username or username:domain, e.g. smithje or smithje:[_2].)',$ncol,$env{'user.domain'});
@@ -88,7 +101,7 @@
}
$result .= '</label><br />';
$result .= &check_collaborators($ncol,$coll) if ($coll =~ /\w+/);
- $result .='</td></tr>';
+ $result .= &Apache::lonhtmlcommon::row_closure();
}
my $filesfrom = 'both';
my $stuname = &Apache::lonnet::EXT('user.name');
@@ -98,7 +111,7 @@
}
$result.=&Apache::inputtags::file_selector($part,$id,$uploadedfiletypes,
$filesfrom,undef,$maxfilesize);
- $result.='</table>';
+ $result.=&Apache::lonhtmlcommon::end_pick_box().'</p>';
} elsif ($target eq 'web' &&
$Apache::inputtags::status[-1] ne 'CAN_ANSWER') {
my $part= $Apache::inputtags::part;
@@ -108,17 +121,11 @@
$result .= '<td><i>'.&mt('Collaborated with [_1]',$coll).'</i></td>';
}
- my $file_submission =
- &Apache::inputtags::show_past_file_submission($part,$id);
- if ($file_submission) {
- $result .= '<td>'.$file_submission.'</td>';
- }
-
- my $port_submission =
- &Apache::inputtags::show_past_portfile_submission($part,$id);
- if ($port_submission) {
- $result .= '<td>'.$port_submission.'</td>';
- }
+ my $current_files_display = ¤t_file_submissions($part,$id);
+ if ($current_files_display) {
+ $result .= '<td><b>'.&mt('Submitted files:').'</b><br />'.
+ $current_files_display.'</td>';
+ }
if ($result ne '') {
$result =
@@ -151,7 +158,16 @@
my $filename = $env{'form.HWFILE'.$part.'_'.$id.'.filename'} ||
$env{'form.HWFILETOOBIG'.$part.'_'.$id};
my $portfiles = $env{'form.HWPORT'.$part.'_'.$id};
- if (( $response =~ /[^\s]/) || ($filename =~ /[^\s]/) || ($portfiles =~ /[^\s]/)) {
+ my @deletions = &Apache::loncommon::get_env_multiple('form.HWFILE'.$part.'_'.$id.'_delete');
+ my ($is_submit,$was_draft);
+ if ($env{'form.HWDRAFT'.$part.'_'.$id} eq 'yes') {
+ $is_submit = 1;
+ }
+ if ($Apache::lonhomework::history{"resource.$part.award"} eq 'DRAFT') {
+ $was_draft = 1;
+ }
+ if (($response =~ /[^\s]/) || ($filename =~ /[^\s]/) || ($portfiles =~ /[^\s]/) ||
+ (@deletions > 0) || ($was_draft && $is_submit)) {
my $award='DRAFT';
if ($env{'form.HWDRAFT'.$part.'_'.$id} eq 'yes') {
if ($Apache::lonhomework::type eq 'anonsurvey') {
@@ -166,8 +182,7 @@
}
my $uploadedflag=0;
my $totalsize=0;
- &file_submission($part,$id,'filename',\$award,\$uploadedflag,\$totalsize);
- &file_submission($part,$id,'portfiles',\$award,\$uploadedflag,\$totalsize);
+ &file_submission($part,$id,\$award,\$uploadedflag,\$totalsize,\@deletions);
$Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;
my %previous=&Apache::response::check_for_previous($response,$part,$id);
@@ -197,7 +212,7 @@
{ $akey => $response },$adom,$aname);
}
}
- }
+ }
}
} elsif ($target eq 'edit') {
$result.=&Apache::edit::end_table();
@@ -265,59 +280,108 @@
}
sub file_submission {
- my ($part,$id,$which,$award,$uploadedflag,$totalsize)=@_;
+ my ($part,$id,$award,$uploadedflag,$totalsize,$deletions)=@_;
my $files;
my $jspart=$part;
$jspart=~s/\./_/g;
- if ($which eq 'portfiles') {
- $files= $env{'form.HWPORT'.$jspart.'_'.$id};
- } elsif ($which eq 'filename') {
- if ($env{'form.HWFILETOOBIG'.$jspart.'_'.$id} ne '') {
- $$award = 'EXCESS_FILESIZE';
- return;
- } else {
- $files = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'};
+ my ($symb,$crsid,$udom,$uname) = &Apache::lonnet::whichuser();
+ my %crsinfo = &Apache::lonnet::coursedescription($crsid);
+ my $cdom = $crsinfo{'domain'};
+ my $cnum = $crsinfo{'num'};
+ my (@portfiles,$uploadedurl,@submitted_portfiles,$submitted_upload,
+ @acceptable_portfiles,$acceptable_upload,@accepted_portfiles,
+ $accepted_upload,@savedportfiles,$stored_upload,@tolock,
+ %port_delete,$uploaded_delete);
+ if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"} ||
+ $Apache::lonhomework::history{"resource.$part.$id.uploadedurl"}) {
+ if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}) {
+ @portfiles = split(/,/,$Apache::lonhomework::history{"resource.$part.$id.portfiles"});
+ }
+ $uploadedurl = $Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
+ if (ref($deletions) eq 'ARRAY') {
+ if (@{$deletions} > 0) {
+ foreach my $file (@{$deletions}) {
+ $file = &HTML::Entities::decode($file);
+ if (grep(/^\Q$file\E$/,@portfiles)) {
+ $port_delete{$file} = 1;
+ } elsif ($file =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/essayresponse/\Q$cdom\E/\Q$cnum\E/}) {
+ $uploaded_delete = $file;
+ }
+ }
+ }
+ }
+ foreach my $current (@portfiles) {
+ unless ($port_delete{$current}) {
+ push(@savedportfiles,$current);
+ }
+ }
+ if ($uploaded_delete) {
+ $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"} = "";
+ $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"} = "";
}
}
- my ($symb,$crsid,$udom,$uname)=&Apache::lonnet::whichuser();
- if ($files =~ /[^\s]/) {
- $files =~s/,$//;
- my (@submitted_files,@acceptable_files,@accepted_files);
- if ($which eq 'portfiles') {
- @submitted_files = split(/\s*,\s*/,$files);
- } else {
- @submitted_files = ($files);
+ if ($env{'form.HWPORT'.$jspart.'_'.$id} ne '') {
+ my $newfiles= $env{'form.HWPORT'.$jspart.'_'.$id};
+ $newfiles =~s/,$//;
+ if ($newfiles =~ /[^\s]/) {
+ foreach my $file (split(/\s*,\s*/,$newfiles)) {
+ if ($file =~ /[^\s]/) {
+ push(@submitted_portfiles,$file);
+ }
+ }
+ }
+ }
+ if ($env{'form.HWFILETOOBIG'.$jspart.'_'.$id} ne '') {
+ $$award = 'EXCESS_FILESIZE';
+ } elsif ($env{'form.HWFILE'.$jspart.'_'.$id.'.filename'} ne '') {
+ my $newfile = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'};
+ if ($newfile =~ /[^\s]/) {
+ $submitted_upload = $newfile;
}
- my $uploadedfiletypes=
+ }
+ if (@savedportfiles) {
+ foreach my $file (reverse(@savedportfiles)) {
+ unless(grep(/^\Q$file\E$/,@submitted_portfiles)) {
+ unshift(@submitted_portfiles,$file);
+ }
+ }
+ }
+ if (@submitted_portfiles || $submitted_upload) {
+ my $uploadedfiletypes=
&Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
if ($uploadedfiletypes ne '') {
$uploadedfiletypes=~s/[^\w\,]//g;
$uploadedfiletypes=','.$uploadedfiletypes.',';
- foreach my $file (@submitted_files) {
- my ($extension)=($file=~/\.(\w+)$/);
- if ($uploadedfiletypes=~/\,\s*\Q$extension\E\s*\,/i) {
- push(@acceptable_files,$file);
+ if (@submitted_portfiles) {
+ foreach my $file (@submitted_portfiles) {
+ my ($extension)=($file=~/\.(\w+)$/);
+ if ($uploadedfiletypes=~/\,\s*\Q$extension\E\s*\,/i) {
+ push(@acceptable_portfiles,$file);
+ }
+ }
+ }
+ if ($submitted_upload) {
+ my ($upload_ext)=($submitted_upload=~/\.(\w+)$/);
+ if ($uploadedfiletypes=~/\,\s*\Q$upload_ext\E\s*\,/i) {
+ $acceptable_upload = $submitted_upload;
} else {
$$award='INVALID_FILETYPE';
- if ($which eq 'filename') {
- &delete_form_items($jspart,$id);
- }
+ &delete_form_items($jspart,$id);
}
}
} else {
- @acceptable_files = @submitted_files;
+ @acceptable_portfiles = @submitted_portfiles;
+ $acceptable_upload = $submitted_upload;
}
+ }
+ if ((@acceptable_portfiles) || ($acceptable_upload ne '')) {
my $maxfilesize=&Apache::lonnet::EXT("resource.$part".'_'."$id.maxfilesize");
if (!$maxfilesize) {
$maxfilesize = 10.0; #FIXME This should become a domain configuration
}
my %dirlist;
- foreach my $file (@acceptable_files) {
- if ($which eq 'filename') {
- if (ref($totalsize)) {
- $$totalsize += $env{'form.HWFILESIZE'.$jspart.'_'.$id};
- }
- } else {
+ if (@acceptable_portfiles) {
+ foreach my $file (@acceptable_portfiles) {
my ($path,$filename) = ($file =~ m{^(.*/)([^/]+)$});
my $fullpath = '/userfiles/portfolio'.$path;
if (!exists($dirlist{$fullpath})) {
@@ -327,7 +391,7 @@
if (ref($dirlist{$fullpath}) eq 'ARRAY') {
foreach my $dir_line (@{$dirlist{$fullpath}}) {
my ($fname,$dom,undef,$testdir,undef,undef,undef,undef,
- $size,undef,$mtime,undef,undef,undef,$obs,undef) =
+ $size,undef,$mtime,undef,undef,undef,$obs,undef) =
split(/\&/,$dir_line,16);
if ($filename eq $fname) {
my $mbsize = $size/(1024.0*1024.0);
@@ -338,135 +402,128 @@
}
}
}
- }
- if (ref($totalsize)) {
- if ($$totalsize > $maxfilesize) {
- $$award='EXCESS_FILESIZE';
- if ($which eq 'filename') {
+ if (ref($totalsize)) {
+ if ($$totalsize > $maxfilesize) {
+ $$award='EXCESS_FILESIZE';
&delete_form_items($jspart,$id);
+ } else {
+ push(@accepted_portfiles,$file);
}
- last;
} else {
- push(@accepted_files,$file);
+ push(@accepted_portfiles,$file);
}
- } else {
- push(@accepted_files,$file);
}
}
- if ($which eq 'portfiles') {
- my @to_mark;
- if ($Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
- @to_mark = ($Apache::lonhomework::results{"resource.$part.$id.portfiles"});
- }
- if (@accepted_files) {
- if ($Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
- $Apache::lonhomework::results{"resource.$part.$id.$which"} .= ',';
+ if ($acceptable_upload ne '') {
+ if (ref($totalsize)) {
+ $$totalsize += $env{'form.HWFILESIZE'.$jspart.'_'.$id};
+ if ($$totalsize > $maxfilesize) {
+ $$award='EXCESS_FILESIZE';
+ delete($env{'form.HWFILE'.$jspart.'_'.$id});
+ } else {
+ $accepted_upload = $acceptable_upload;
}
- $Apache::lonhomework::results{"resource.$part.$id.$which"}.=join(',',@accepted_files);
- push(@to_mark,@accepted_files);
+ } else {
+ $accepted_upload = $acceptable_upload;
}
- &Apache::lonnet::unmark_as_readonly($udom,$uname,[$symb,$crsid]);
- &Apache::lonnet::mark_as_readonly($udom,$uname,\@to_mark,[$symb,$crsid]);
- &Apache::lonnet::clear_selected_files($uname);
}
- if (($$award eq 'INVALID_FILETYPE') || ($$award eq 'EXCESS_FILESIZE')) {
- if ($which eq 'filename') {
- delete($env{'form.HWFILE'.$jspart.'_'.$id});
+ }
+ if ($accepted_upload ne '') {
+ my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
+ my $turnindir;
+ my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
+ $turnindir = $userhash{'turnindir'};
+ if ($turnindir eq '') {
+ $turnindir = &mt('turned in');
+ $turnindir =~ s/\W+/_/g;
+ my %newhash = (
+ 'turnindir' => $turnindir,
+ );
+ &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
+ }
+ my $prefix = 'portfolio';
+ my $path = '/'.$turnindir.'/';
+ my $restitle=&Apache::lonnet::gettitle($symb);
+ $restitle =~ s/\W+/_/g;
+ if ($restitle eq '') {
+ $restitle = ($resurl =~ m{/[^/]+$});
+ if ($restitle eq '') {
+ $restitle = time;
}
- return;
}
- if (ref($uploadedflag)) {
- $$uploadedflag=1;
- }
- if ($which eq 'filename') {
- my $cleanpart = $part;
- $cleanpart =~ s/\W/_/g;
- my $cleanid = $id;
- $cleanid =~ s/\W/_/g;
- my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
- my %crsdesc = &Apache::lonnet::coursedescription($crsid);
- my $turnindir;
- my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
- $turnindir = $userhash{'turnindir'};
- if ($turnindir eq '') {
- $turnindir = &mt('turned in');
- $turnindir =~ s/\W+/_/g;
- my %newhash = (
- 'turnindir' => $turnindir,
- );
- &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
- }
- my $prefix = 'portfolio';
- my $path = '/'.$turnindir.'/';
- my $crsname = $crsdesc{'description'};
- my $restitle=&Apache::lonnet::gettitle($symb);
- foreach my $item ($crsname,$restitle) {
- $item =~ s/\W+/_/g;
- }
- if ($crsname eq '') {
- $crsname = $crsid;
- }
- if ($restitle eq '') {
- $restitle = ($resurl =~ m{/[^/]+$});
- if ($restitle eq '') {
- $restitle = time;
- }
- }
- my @pathitems;
- my $navmap = Apache::lonnavmaps::navmap->new();
- if (defined($navmap)) {
- my $mapres = $navmap->getResourceByUrl($map);
- if (ref($mapres)) {
- my $pcslist = $mapres->map_hierarchy();
- if ($pcslist ne '') {
- foreach my $pc (split(/,/,$pcslist)) {
- my $res = $navmap->getByMapPc($pc);
- if (ref($res)) {
- my $title = $res->compTitle();
- $title =~ s/\W+/_/g;
- if ($title ne '') {
- push(@pathitems,$title);
- }
+ my @pathitems;
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (defined($navmap)) {
+ my $mapres = $navmap->getResourceByUrl($map);
+ if (ref($mapres)) {
+ my $pcslist = $mapres->map_hierarchy();
+ if ($pcslist ne '') {
+ foreach my $pc (split(/,/,$pcslist)) {
+ my $res = $navmap->getByMapPc($pc);
+ if (ref($res)) {
+ my $title = $res->compTitle();
+ $title =~ s/\W+/_/g;
+ if ($title ne '') {
+ push(@pathitems,$title);
}
}
}
- my $maptitle = $mapres->compTitle();
- $maptitle =~ s/\W+/_/g;
- if ($maptitle ne '') {
- push(@pathitems,$maptitle);
- }
- } else {
- $$award = 'INTERNAL_ERROR';
+ }
+ my $maptitle = $mapres->compTitle();
+ $maptitle =~ s/\W+/_/g;
+ if ($maptitle ne '') {
+ push(@pathitems,$maptitle);
}
} else {
$$award = 'INTERNAL_ERROR';
}
- push(@pathitems,$restitle);
- unshift(@pathitems,$crsname);
- $path .= join('/',@pathitems);
- my $formelement = 'HWFILE'.$jspart.'_'.$id;
- my $fname = $env{'form.'.$formelement.'.filename'};
- &Apache::lonnet::clean_filename($fname);
- my $url = '/uploaded/'.$udom.'/'.$uname.'/'.$prefix.$path.'/'.$fname;
- my @stat = &Apache::lonnet::stat_file($url);
- if (@stat && $stat[0] ne 'no_such_dir') {
- $$award = 'FILENAME_INUSE';
+ } else {
+ $$award = 'INTERNAL_ERROR';
+ }
+ push(@pathitems,$restitle);
+ $path .= join('/',@pathitems);
+ my $formelement = 'HWFILE'.$jspart.'_'.$id;
+ my $fname = $env{'form.'.$formelement.'.filename'};
+ &Apache::lonnet::clean_filename($fname);
+ my $url = '/uploaded/'.$udom.'/'.$uname.'/'.$prefix.$path.'/'.$fname;
+ my @stat = &Apache::lonnet::stat_file($url);
+ if (@stat && $stat[0] ne 'no_such_dir') {
+ $$award = 'FILENAME_INUSE';
+ } else {
+ my ($mode,%allfiles,%codebase);
+ my $result = &Apache::lonnet::userfileupload($formelement,'',
+ $prefix.$path,$mode,\%allfiles,\%codebase);
+ if ($result =~ m{^/uploaded/}) {
+ $stored_upload = $path.'/'.$fname;
+ $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = $stored_upload;
+ push(@tolock,$stored_upload);
} else {
- my ($mode,%allfiles,%codebase);
- my $result = &Apache::lonnet::userfileupload($formelement,'',
- $prefix.$path,$mode,\%allfiles,\%codebase);
- if ($result =~ m{^/uploaded/}) {
- $Apache::lonhomework::results{"resource.$part.$id.portfiles"} .= $path.'/'.$fname;
- &Apache::lonnet::unmark_as_readonly($udom,$uname,[$symb,$crsid]);
-
- &Apache::lonnet::mark_as_readonly($udom,$uname,[$path.'/'.$fname],[$symb,$crsid]);
- } else {
- $$award = 'INTERNAL_ERROR';
- }
+ $$award = 'INTERNAL_ERROR';
}
- delete($env{'form.HWFILE'.$jspart.'_'.$id});
- }
+ }
+ delete($env{'form.HWFILE'.$jspart.'_'.$id});
+ }
+ if (@accepted_portfiles) {
+ if ($stored_upload) {
+ $Apache::lonhomework::results{"resource.$part.$id.portfiles"} .= ',';
+ }
+ $Apache::lonhomework::results{"resource.$part.$id.portfiles"}.=join(',',@accepted_portfiles);
+ push(@tolock,@accepted_portfiles);
+ }
+ if (!defined($Apache::lonhomework::results{"resource.$part.$id.portfiles"})) {
+ if (keys(%port_delete) > 0) {
+ $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = "";
+ }
+ }
+ if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"} ne $Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
+ if (ref($uploadedflag)) {
+ $$uploadedflag=1;
+ }
}
+ &Apache::lonnet::unmark_as_readonly($udom,$uname,[$symb,$crsid]);
+ &Apache::lonnet::mark_as_readonly($udom,$uname,[@tolock],[$symb,$crsid]);
+ &Apache::lonnet::clear_selected_files($uname);
+ return;
}
sub delete_form_items {
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.264 loncom/homework/inputtags.pm:1.265
--- loncom/homework/inputtags.pm:1.264 Thu Jun 17 00:13:20 2010
+++ loncom/homework/inputtags.pm Mon Jun 21 02:15:37 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.264 2010/06/17 00:13:20 raeburn Exp $
+# $Id: inputtags.pm,v 1.265 2010/06/21 02:15:37 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -53,6 +53,7 @@
use HTML::Entities();
use strict;
use Apache::loncommon;
+use Apache::lonhtmlcommon;
use Apache::lonlocal;
use Apache::lonnet;
use LONCAPA;
@@ -479,87 +480,162 @@
$jspart=~s/\./_/g;
my $result;
-
- $result.='<tr><td>';
- if (($uploadedfiletypes ne '*') || ($maxfilesize)) {
- if ($uploadedfiletypes ne '*') {
- $result.=
- &mt('Allowed filetypes: [_1]','<b>'.$uploadedfiletypes.'</b>').'<br />';
- }
- if ($maxfilesize) {
- $result.=&mt('Combined size of files not to exceed: [_1] MB[_2].',
- '<b>'.$maxfilesize.'</b>').'<br />';
- }
- $result .= '<br />';
+ my $current_files_display = ¤t_file_submissions($part,$id);
+ my $addfiles;
+ if ($current_files_display) {
+ $result .= &Apache::lonhtmlcommon::row_title(&mt('Currently submitted files:')).
+ $current_files_display.
+ &Apache::lonhtmlcommon::row_closure();
+ $addfiles = &mt('Submit other file(s)');
+ } else {
+ $addfiles = &mt('Choose file(s) to submit');
+ }
+ $result .= &Apache::lonhtmlcommon::row_title($addfiles);
+ my $constraints;
+ if ($uploadedfiletypes ne '*') {
+ $constraints =
+ &mt('Allowed filetypes: [_1]','<b>'.$uploadedfiletypes.'</b>').'<br />';
+ }
+ if ($maxfilesize) {
+ $constraints .= &mt('Combined size of all files not to exceed: [_1] MB[_2].',
+ '<b>'.$maxfilesize.'</b>').'<br />';
+ }
+ if ($constraints) {
+ $result .= $constraints.'<br />';
}
if ($which eq 'uploadonly' || $which eq 'both') {
- $result.=&mt('Submit a file: (only one file can be uploaded)').
+ $result.=&mt('Submit a file: (only one file per submission)').
' <br /><input type="file" size="50" name="HWFILE'.
$jspart.'_'.$id.'" /><br />';
- $result .= &show_past_file_submission($part,$id);
}
- if ( $which eq 'both') {
+ if ( $which eq 'both') {
$result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';
}
if ($which eq 'portfolioonly' || $which eq 'both') {
$result.=$extratext.'<a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&fieldname='.$env{'form.request.prefix'}.'HWPORT'.$jspart.'_'.$id.'","cat","height=600,width=800,scrollbars=1,resizable=1,menubar=2,location=1"))'."'".'>'.
- &mt('Select Portfolio Files').'</a><br />'.
+ &mt('Select Portfolio Files: (one or more files per submission)').'</a><br />'.
'<input type="text" size="50" name="HWPORT'.$jspart.'_'.$id.'" value="" />'.
'<br />';
- $result .= &show_past_portfile_submission($part,$id);
+
}
- $result.='</td></tr>';
+ $result.=&Apache::lonhtmlcommon::row_closure(1);
return $result;
}
-sub show_past_file_submission {
+sub current_file_submissions {
my ($part,$id) = @_;
- my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
-
- return if (!$uploadedfile);
-
- my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
- &Apache::lonxml::extlink($url);
- &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
- my $icon=&Apache::loncommon::icon($url);
- my $curfile='<a href="'.$url.'"><img src="'.$icon.
- '" border="0" />'.$uploadedfile.'</a>';
- return &mt('Currently submitted: [_1]','<tt>'.$curfile.'</tt>');
-
-}
-
-sub show_past_portfile_submission {
- my ($part,$id) = @_;
- if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}!~/[^\s]/){
- return;
+ my $jspart=$part;
+ $jspart=~s/\./_/g;
+ my $uploadedfile=&HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
+ my $portfiles=$Apache::lonhomework::history{"resource.$part.$id.portfiles"};
+ return if (($uploadedfile eq '') && ($portfiles !~/[^\s]/));
+ my $header = &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '<th>'.&mt('Delete?').'</th>'.
+ '<th>'.&mt('Name').'</th>'.
+ '<th>'.&mt('Size (MB)').'</th>'.
+ '<th>'.&mt('Last Modified').'</th>'.
+ &Apache::loncommon::end_data_table_header_row();
+ my (undef,$crsid,$udom,$uname)=&Apache::lonnet::whichuser();
+ my ($cdom,$cnum) = ($crsid =~ /^($LONCAPA::match_domain)_($LONCAPA::match_courseid)$/);
+ my ($result,$header_shown,%okfiles,%rows,@bad_file_list);
+ if ($uploadedfile) {
+ my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
+ my ($path,$name) = ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E/(essayresponse/.+/)([^/]+))});
+ my ($status,$hashref,$error) =
+ ¤t_file_info($url,$uploadedfile,$name,$path);
+ if ($status eq 'ok') {
+ push(@{$okfiles{$name}},$url);
+ $rows{$url} = $hashref;
+ &Apache::lonxml::extlink($url);
+ &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
+ } else {
+ push(@bad_file_list,$error);
+ }
+ }
+ if ($portfiles =~ /[^\s]/) {
+ my $prefix = "/uploaded/$udom/$uname/portfolio";
+ foreach my $file (split(/\s*,\s*/,&unescape($portfiles))) {
+ my ($path,$name) = ($file =~ m{^(.*/)([^/]+)$});
+ my $url = $prefix.$path.$name;
+ my $uploadedfile = &HTML::Entities::encode($url,'<>&"');
+ my ($status,$hashref,$error) =
+ ¤t_file_info($url,$uploadedfile,$name,$path);
+ if ($status eq 'ok') {
+ push(@{$okfiles{$name}},$url);
+ $rows{$url} = $hashref;
+ } else {
+ push(@bad_file_list,$error);
+ }
+ }
+ }
+ foreach my $name (sort(keys(%okfiles))) {
+ if (ref($okfiles{$name}) eq 'ARRAY') {
+ foreach my $url (@{$okfiles{$name}}) {
+ if (ref($rows{$url}) eq 'HASH') {
+ my $link = $rows{$url}{link};
+ my $portfile = $rows{$url}{path}.$rows{$url}{name};
+ $portfile = &HTML::Entities::encode($portfile,'<>&"');
+ if ($link) {
+ my $icon=&Apache::loncommon::icon($url);
+ unless ($header_shown) {
+ $result .= $header;
+ $header_shown = 1;
+ }
+ $result.=
+ &Apache::loncommon::start_data_table_row()."\n".
+ '<td valign="bottom"><input type="checkbox" name="HWFILE'.$jspart.'_'.$id.'_delete" value="'.
+ $portfile.'" /></td>'."\n".
+ '<td><a href="'.$link.'"><img src="'.$icon.
+ '" border="0" />'.$name.'</a></td>'."\n".
+ '<td align="right" valign="bottom">'.$rows{$url}{size}.'</td>'."\n".
+ '<td align="right" valign="bottom">'.$rows{$url}{lastmodified}.'</td>'."\n".
+ &Apache::loncommon::end_data_table_row();
+ }
+ }
+ }
+ }
+ }
+ if ($header_shown) {
+ $result .= &Apache::loncommon::end_data_table();
}
- my (@file_list,@bad_file_list);
- foreach my $file (split(/\s*,\s*/,&unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) {
- my (undef,undef,$domain,$user)=&Apache::lonnet::whichuser();
- my $url="/uploaded/$domain/$user/portfolio$file";
- my $icon=&Apache::loncommon::icon($url);
- push(@file_list,'<a href="'.$url.'"><img src="'.$icon.
- '" border="0" />'.$file.'</a>');
- if (! &Apache::lonnet::stat_file($url)) {
- &Apache::lonnet::logthis("bad file is $url");
- push(@bad_file_list,'<a href="'.$url.'"><img src="'.$icon.
- '" border="0" />'.$file.'</a>');
- }
- }
- my $files = '<span class="LC_filename">'.
- join('</span>, <span class="LC_filename">',@file_list).
- '</span>';
- my $result = &mt("Portfolio files previously selected: [_1]",$files);
if (@bad_file_list) {
- my $bad_files = '<span class="LC_filename">'.
- join('</span>, <span class="LC_filename">',@bad_file_list).
- '</span>';
- $result.='<p><span class="LC_error">'
- .&mt("These file(s) don't exist: [_1]",$bad_files)
- .'</span></p>';
+ my $bad_files = '<span class="LC_filename">'.
+ join('</span>, <span class="LC_filename">',@bad_file_list).
+ '</span>';
+ $result.='<p class="LC_error">'.
+ &mt("These file(s) don't exist: [_1]",$bad_files).
+ '</p>';
}
return $result;
+}
+sub current_file_info {
+ my ($url,$uploadedfile,$name,$path) = @_;
+ my ($status,$error,%info);
+ my @stat = &Apache::lonnet::stat_file($url);
+ if ((@stat) && ($stat[0] ne 'no_such_dir')) {
+ my ($lastmod,$size);
+ if ($stat[9] =~ /^\d+$/) {
+ $lastmod = &Apache::lonlocal::locallocaltime($stat[9]);
+ }
+ $size = $stat[7]/(1024*1024);
+ $size = sprintf("%.3f",$size);
+ %info = (
+ link => $uploadedfile,
+ name => $name,
+ path => $path,
+ size => $size,
+ lastmodified => $lastmod,
+ );
+ $status = 'ok';
+ } else {
+ &Apache::lonnet::logthis("bad file is $url");
+ my $icon=&Apache::loncommon::icon($url);
+ $error = '<a href="'.$url.'"><img src="'.$icon.
+ '" border="0" />'.$uploadedfile.'</a>';
+ }
+ return ($status,\%info,$error);
}
sub valid_award {
--raeburn1277086538--