--- loncom/publisher/lonpubdir.pm 2004/08/20 16:29:15 1.63 +++ loncom/publisher/lonpubdir.pm 2014/04/06 19:39:04 1.151 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA -# Construction Space Directory Lister +# Authoring Space Directory Lister # -# $Id: lonpubdir.pm,v 1.63 2004/08/20 16:29:15 www Exp $ +# $Id: lonpubdir.pm,v 1.151 2014/04/06 19:39:04 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,133 +33,129 @@ use strict; use Apache::File; use File::Copy; use Apache::Constants qw(:common :http :methods); -use Apache::loncacc; use Apache::loncommon(); use Apache::lonhtmlcommon(); +use Apache::londiff(); use Apache::lonlocal; use Apache::lonmsg; +use Apache::lonmenu; +use Apache::lonnet; +use LONCAPA; sub handler { my $r=shift; - my $fn; - - - - $fn = getEffectiveUrl($r); - - # Validate access to the construction space and get username@domain. + # Validate access to the construction space and get username:domain. my $uname; my $udom; - ($uname,$udom)= - &Apache::loncacc::constructaccess( - $fn,$r->dir_config('lonDefDomain')); + ($uname,$udom)=&Apache::lonnet::constructaccess($r->uri); unless (($uname) && ($udom)) { - $r->log_reason($uname.' at '.$udom. - ' trying to list directory '.$ENV{'form.filename'}. - ' ('.$fn.') - not authorized', - $r->filename); return HTTP_NOT_ACCEPTABLE; } - # Remove trailing / from directory name. +# ----------------------------------------------------------- Start page output + my $fn=$r->filename; $fn=~s/\/$//; - unless ($fn) { - $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. - ' trying to list empty directory', $r->filename); - return HTTP_NOT_FOUND; - } - -# ----------------------------------------------------------- Start page output - my $thisdisfn=$fn; - $thisdisfn=~s/^\/home\/$uname\/public_html//; # subdirectory part of - # construction space. my $docroot=$r->dir_config('lonDocRoot'); # Apache londocument root. + $thisdisfn=~s/^\Q$docroot\E\/priv//; - my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn; # Resource directory - my $targetdir=$udom.'/'.$uname.$thisdisfn; # Publiction target directory. - my $linkdir='/priv/'.$uname.$thisdisfn; # Full URL name of constr space. + my $resdir=$docroot.'/res'.$thisdisfn; # Resource directory + my $targetdir='/res'.$thisdisfn; # Publication target directory. + my $linkdir='/priv'.$thisdisfn; # Full URL name of constr space. my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom); &startpage($r, $uname, $udom, $thisdisfn); # Put out the start of page. + &dircontrols($r,$uname,$udom,$thisdisfn); # Put out actions for directory, + # browse/upload + new file page. + &resourceactions($r,$uname,$udom,$thisdisfn); #Put out form used for printing/deletion etc. + + my $numdir = 0; + my $numres = 0; - # Start off the directory table. + # Retrieving value for sortby from QUERY_STRING + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sortby']); - $r->print('
'.&mt('Actions').' | '.&mt('Name').' | '. - &mt('Title').' | '. - ''.&mt('Status').' | '.&mt('Last Modified'). - ' | '.&mt('Type').' | ' + .''.&mt('Actions').' | ' + .''.&mt('Name').' ▼ | ' + .''.&mt('Title').' | ' + .''.&mt('Status').' | ' + .''.&mt('Last Modified').' ▼ | ' + .&Apache::loncommon::end_data_table_header_row() + ); my $filename; my $dirptr=16384; # Mask indicating a directory in stat.cmode. opendir(DIR,$fn); + my $filehash = {}; + my $sortby = $env{'form.sortby'}; my @files=sort {uc($a) cmp uc($b)} (readdir(DIR)); foreach my $filename (@files) { - my ($cdev,$cino,$cmode,$cnlink, - $cuid,$cgid,$crdev,$csize, - $catime,$cmtime,$cctime, - $cblksize,$cblocks)=stat($fn.'/'.$filename); - - my $extension=''; - if ($filename=~/\.(\w+)$/) { $extension=$1; } - if ($cmode&$dirptr) { - putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime,$targetdir,\%bombs); - } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') { - putresource($r, $uname, $filename, $thisdisfn, $resdir, - $targetdir, $linkdir, $cmtime,\%bombs); - } else { - # "hidden" extension and not a directory, so hide it away. + next if ($filename eq '.DS_Store'); + my ($cmode,$cmtime)=(stat($fn.'/'.$filename))[2,9]; + # If you want to sort by "last modified", we need to make this hash. + if ($sortby eq 'cmtime') { + $filehash->{ $filename } = {"cmtime" => $cmtime,}; } - } + # Otherwise sort by name. Don't bother with filehash. Continue printing contents. + else { + my $extension=''; + if ($filename=~/\.(\w+)$/) { $extension=$1; } + if ($cmode&$dirptr) { + &putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime,$targetdir,\%bombs,\$numdir); + } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') { + &putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir, + $targetdir, $linkdir, $cmtime,\%bombs,\$numres); + } else { + # "hidden" extension and not a directory, so hide it away. + } + } + }; + + # Sorting files by "last modified" if that's what you selected + if ($sortby eq 'cmtime') { + my @sorted_files = sort { + $filehash->{$b}->{$sortby} <=> $filehash->{$a}->{$sortby} + } (keys(%{$filehash})); + foreach my $filename (@sorted_files) { + my ($cmode,$cmtime)=(stat($fn.'/'.$filename))[2,9]; + my $extension=''; + if ($filename=~/\.(\w+)$/) { $extension=$1; } + if ($cmode&$dirptr) { + &putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime,$targetdir,\%bombs,\$numdir); + } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') { + &putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir, + $targetdir, $linkdir, $cmtime,\%bombs,\$numres); + } else { + # "hidden" extension and not a directory, so hide it away. + }; + }; + }; + closedir(DIR); - $r->print('
---|