--- loncom/publisher/lonpubdir.pm 2001/08/20 20:13:40 1.14
+++ loncom/publisher/lonpubdir.pm 2023/06/11 19:46:01 1.177
@@ -1,16 +1,31 @@
# The LearningOnline Network with CAPA
+# Authoring Space Directory Lister
#
-# (Publication Handler
-#
-# (TeX Content Handler
+# $Id: lonpubdir.pm,v 1.177 2023/06/11 19:46:01 raeburn Exp $
#
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
+# Copyright Michigan State University Board of Trustees
#
-# 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
-# 03/23 Guy Albertelli
-# 03/24,03/29 Gerd Kortemeyer)
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
-# 03/31,04/03,05/09,06/23,08/18,08/20 Gerd Kortemeyer
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
+###
package Apache::lonpubdir;
@@ -18,142 +33,1254 @@ 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 qw(:DEFAULT :match);
sub handler {
- my $r=shift;
+ my $r=shift;
- my $fn;
+ # Validate access to the construction space and get username:domain.
- if ($ENV{'form.filename'}) {
- $fn=$ENV{'form.filename'};
- $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
- $fn=~s/\/[^\/]+$//;
- } else {
- $fn=$r->filename();
- }
-
- my $uname;
- my $udom;
-
- ($uname,$udom)=
- &Apache::loncacc::constructaccess(
- $fn,$r->dir_config('lonDefDomain'));
- unless (($uname) && ($udom)) {
- $r->log_reason($uname.' at '.$udom.
- ' trying to publish file '.$ENV{'form.filename'}.
- ' ('.$fn.') - not authorized',
- $r->filename);
- return HTTP_NOT_ACCEPTABLE;
- }
-
- $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;
- }
+ my ($uname,$udom)=&Apache::lonnet::constructaccess($r->uri);
+ unless (($uname) && ($udom)) {
+ return HTTP_NOT_ACCEPTABLE;
+ }
# ----------------------------------------------------------- Start page output
+ my $fn=$r->filename;
+ $fn=~s/\/$//;
+ my $thisdisfn=$fn;
+
+ my $docroot=$r->dir_config('lonDocRoot'); # Apache londocument root.
+ if ($thisdisfn eq "$docroot/priv/$udom") {
+ if ((-d "/home/$uname/public_html/") && (!-e "$docroot/priv/$udom/$uname")) {
+ my ($version) = ($r->dir_config('lonVersion') =~ /^\'?(\d+\.\d+)\./);
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->send_http_header;
+
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ $r->print(&Apache::loncommon::start_page('Authoring Space').
+ '
'.
+ '
'.
+ &mt('Your Authoring Space is currently in the location used by LON-CAPA version 2.10 and older, but your domain is using a newer LON-CAPA version ([_1]).',$version).'
'.
+ '
'.
+ &mt('Please ask your Domain Coordinator to move your Authoring Space to the new location.').
+ '
'.
+ '
'.
+ &Apache::loncommon::end_page());
+ return OK;
+ }
+ }
+ $thisdisfn=~s/^\Q$docroot\E\/priv//;
+
+ 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 $cstr = 'author';
+ my ($crsauthor,$crstype);
+ if ($env{'request.course.id'}) {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ if ($thisdisfn =~ m{^/\Q$cdom/$cnum\E}) {
+ $crsauthor = 1;
+ $cstr = 'course';
+ $crstype = &Apache::loncommon::course_type();
+ }
+ }
+
+ my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
+
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,
+ "$londocroot/priv/$udom/$uname"); # expressed in kB
+ my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,
+ $cstr,$crstype); # expressed in MB
+ my $diraction;
+ if (-d $fn) {
+ $diraction = &diractions($thisdisfn);
+ }
+
+ # Put out the start of page.
+
+ &startpage($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota, $crsauthor, $diraction);
+
+ if (!-d $fn) {
+ if (-e $fn) {
+ $r->print('
'.&mt('Requested item is a file not a directory.').'
');
+ } else {
+ $r->print('
'.&mt('The requested subdirectory does not exist.').'
');
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
+ }
+
+ # Put out actions for directory, browse/upload + new file page.
+ &dircontrols($r,$uname,$udom,$thisdisfn, $current_disk_usage, $disk_quota);
+ &resourceactions($r,$uname,$udom,$thisdisfn); # Put out form used for printing/deletion etc.
- $r->content_type('text/html');
- $r->send_http_header;
+ my $numdir = 0;
+ my $numres = 0;
+
+ if ((@files == 0) && ($thisdisfn =~ m{^/$match_domain/$match_username})) {
+ if ($thisdisfn =~ m{^/$match_domain/$match_username$}) {
+ $r->print('
'.&mt('This Authoring Space is currently empty.').'
');
+ } else {
+ $r->print('
'.&mt('This subdirectory is currently empty.').'
');
+ }
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
+ }
+
+ # Retrieving value for "sortby" and "sortorder" from QUERY_STRING
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['sortby','sortorder']);
+
+ # Sort by name as default, not reversed
+ if (! exists($env{'form.sortby'})) { $env{'form.sortby'} = 'filename' }
+ if (! exists($env{'form.sortorder'})) { $env{'form.sortorder'} = '' }
+ my $sortby = $env{'form.sortby'};
+ my $sortorder = $env{'form.sortorder'};
+
+ # Order in which columns are displayed from left to right
+ my @order = ('filetype','actions','filename','title',
+ 'pubstatus','cmtime','size');
+
+ # Up and down arrows to indicate sort order
+ my @arrows = (' ▲',' ▼','');
+
+ # Default sort order and column title
+ my %columns = (
+ filetype => {
+ order => 'ascending',
+ text => &mt('Type'),
+ },
+ actions => {
+ # Not sortable
+ text => &mt('Actions'),
+ },
+ filename => {
+ order => 'ascending',
+ text => &mt('Name'),
+ },
+ title => {
+ order => 'ascending',
+ text => &mt('Title'),
+ },
+ pubstatus => {
+ order => 'ascending',
+ text => &mt('Status'),
+ colspan => '2',
+ },
+ cmtime => {
+ order => 'descending',
+ text => &mt('Last Modified'),
+ },
+ size => {
+ order => 'ascending',
+ text => &mt('Size').' (kB)',
+ },
+ );
+
+ # Print column headers
+ my $output = '';
+ foreach my $key (@order) {
+ my $idx;
+ # Append an up or down arrow to sorted column
+ if ($sortby eq $key) {
+ $idx = ($columns{$key}{order} eq 'ascending') ? 0:1;
+ if ($sortorder eq 'rev') { $idx ++; }
+ $idx = $idx%2;
+ } else { $idx = 2; } # No arrow if column is not sorted
+ $output .= (($columns{$key}{order}) ?
+ '
');
+# Output the header of the page. This includes:
+# - The HTML header
+# - The H1/H3 stuff which includes the directory.
+#
+# startpage($r, $uame, $udom, $thisdisfn, $current_disk_usage, $disk_quota);
+# $r - The apache request object.
+# $uname - User name.
+# $udom - Domain name the user is logged in under.
+# $thisdisfn - Displayable version of the filename.
+# $current_disk_usage - User's current disk usage (in kB).
+# $disk_quota - Disk quota for user's authoring space (in MB).
+# $crstype - Course type, if this is for "course author"
+
+sub startpage {
+ my ($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota, $crsauthor, $diraction) = @_;
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->send_http_header;
+
+ my $formaction='/priv'.$thisdisfn.'/';
+ $formaction=~s|/+|/|g;
+
+ my $title;
+ if ($crsauthor) {
+ $title = 'Course Authoring';
+ } else {
+ $title = 'Authoring Space';
+ &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
+ }
+
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb({
+ 'text' => $title,
+ 'href' => &Apache::loncommon::authorspace($formaction),
+ });
+ # breadcrumbs (and tools) will be created
+ # in start_page->bodytag->innerregister
+
+ $env{'request.noversionuri'}=$formaction;
+ my $js = '';
+ $r->print(&Apache::loncommon::start_page($title, $js));
+
+ $disk_quota = 1024 * $disk_quota; # convert from MB to kB
+
+ my $heading = &mt('Directory');
+ $r->print(&Apache::loncommon::head_subbox(
+ '