--- loncom/interface/portfolio.pm 2010/10/27 01:02:29 1.226 +++ loncom/interface/portfolio.pm 2012/04/16 19:31:57 1.234 @@ -1,7 +1,7 @@ # The LearningOnline Network # portfolio browser # -# $Id: portfolio.pm,v 1.226 2010/10/27 01:02:29 raeburn Exp $ +# $Id: portfolio.pm,v 1.234 2012/04/16 19:31:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -303,7 +303,7 @@ sub display_directory { my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group); my $now = time; if ($env{"form.mode"} eq 'selectfile') { - &select_files($r); + &select_files($r,$dir_list); $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'}); $select_mode = 'true'; } @@ -379,23 +379,26 @@ sub display_directory { my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path; my @dir_lines; my %versioned; - foreach my $dir_line (sort - { - my ($afile)=split('&',$a,2); - my ($bfile)=split('&',$b,2); - return (lc($afile) cmp lc($bfile)); - } (@$dir_list)) { - my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16); - $filename =~ s/\s+$//; - my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename); - if ($version) { - my $fullpath = &prepend_group($current_path.$fname.'.'.$extension); - push(@{ $versioned{$fullpath} }, - [$filename,$dom,$testdir,$size,$mtime,$obs,]); - } else { - push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]); - } + if (ref($dir_list) eq 'ARRAY') { + foreach my $dir_line (sort + { + my ($afile)=split('&',$a,2); + my ($bfile)=split('&',$b,2); + return (lc($afile) cmp lc($bfile)); + } (@{$dir_list})) { + my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16); + $filename =~ s/\s+$//; + my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename); + if ($version) { + my $fullpath = &prepend_group($current_path.$fname.'.'.$extension); + push(@{ $versioned{$fullpath} }, + [$filename,$dom,$testdir,$size,$mtime,$obs,]); + } else { + push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]); + } + } } + my $zerobyte; foreach my $dir_line (@dir_lines) { my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line; my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename); @@ -455,11 +458,16 @@ sub display_directory { my $css_class = 'LC_browser_file'; my $line; if ($select_mode eq 'true') { - $line='
'.&mt('[quant,_1,file] in list not selectable as file size is 0 bytes.',$zerobyte).'
'); + } + $r->print(' @@ -1854,13 +1866,24 @@ END_SCRIPT } sub select_files { - my ($r) = @_; + my ($r,$dir_list) = @_; if ($env{'form.continue'} eq 'true') { # here we update the selections for the currentpath # eventually, have to handle removing those not checked, but . . . my @items=&Apache::loncommon::get_env_multiple('form.checkfile'); if (scalar(@items)){ - &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items); + my @ok_items; + if (ref($dir_list) eq 'ARRAY') { + foreach my $dir_line (@{$dir_list}) { + my ($filename,undef,undef,undef,undef,undef,undef,undef,$size)=split(/\&/,$dir_line,10); + if (grep(/^\Q$filename\E$/,@items)) { + if ($size) { + push(@ok_items,$filename); + } + } + } + } + &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @ok_items); } } else { #empty the file for a fresh start @@ -1937,12 +1960,13 @@ sub upload { $port_path,$disk_quota, $current_disk_usage,$uname,$udom); if ($state eq 'will_exceed_quota' - || $state eq 'file_locked') { + || $state eq 'file_locked' + || $state eq 'zero_bytes') { $r->print($msg.&done('Back',$url)); return; } - my (%allfiles,%codebase,$mode); + my (%allfiles,%codebase,$mode,$mimetype); if ($env{'form.'.$formname.'.filename'} =~ m/(\.htm|\.html|\.shtml)$/i) { if ($env{'form.parserflag'}) { $mode = 'parse'; @@ -1952,10 +1976,12 @@ sub upload { if ($state eq 'existingfile') { $context = $state; } + my $subdir = $port_path.$env{'form.currentpath'}; + $subdir =~ s{(/)$}{}; my ($result,$timestamp) = - &Apache::lonnet::userfileupload($formname,$context, - $port_path.$env{'form.currentpath'}, - $mode,\%allfiles,\%codebase); + &Apache::lonnet::userfileupload($formname,$context,$subdir, + $mode,\%allfiles,\%codebase,undef,undef, + undef,undef,undef,undef,\$mimetype); if ($state eq 'existingfile') { my $group_elem; my $rootdir = $r->dir_config('lonDaemons').'/tmp/overwrites'; @@ -1976,44 +2002,56 @@ sub upload { conf => 'Are you sure you want to overwrite an existing file?', cont => 'Continue', ); + my $parserflag; + my $hidden = &hidden_elems(); + if ($mode eq 'parse') { + $parserflag = ''; + } $r->print(<<"END"); $msg -