--- loncom/publisher/lonpubdir.pm 2009/05/19 10:16:02 1.120
+++ loncom/publisher/lonpubdir.pm 2024/08/22 18:32:56 1.160.2.5.2.5
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
-# Construction Space Directory Lister
+# Authoring Space Directory Lister
#
-# $Id: lonpubdir.pm,v 1.120 2009/05/19 10:16:02 bisitz Exp $
+# $Id: lonpubdir.pm,v 1.160.2.5.2.5 2024/08/22 18:32:56 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,7 +33,6 @@ 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();
@@ -41,215 +40,341 @@ use Apache::lonlocal;
use Apache::lonmsg;
use Apache::lonmenu;
use Apache::lonnet;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
sub handler {
- my $r=shift;
-
- my $fn;
+ my $r=shift;
+ # Validate access to the construction space and get username:domain.
+ my ($uname,$udom)=&Apache::lonnet::constructaccess($r->uri);
+ unless (($uname) && ($udom)) {
+ return HTTP_NOT_ACCEPTABLE;
+ }
- $fn = getEffectiveUrl($r);
+# ----------------------------------------------------------- Start page output
- # Validate access to the construction space and get username@domain.
+ 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 $uname;
- my $udom;
+ 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);
+
+ 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,
+ 'author'); # expressed in MB
+
+ # Put out the start of page.
+ &startpage($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota);
+
+ 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.').'
'
+ .&Apache::loncommon::CSTR_pageheader('','',$headertext)));
my $esc_thisdisfn = &Apache::loncommon::escape_single($thisdisfn);
- my $doctitle = 'LON-CAPA '.&mt('Construction Space');
+ my $doctitle = 'LON-CAPA '.&mt('Authoring Space');
my $newname = &mt('New Name');
my $pubdirscript=(<
top.document.title = '$esc_thisdisfn/ - $doctitle';
// Store directory location for menu bar to find
-parent.lastknownpriv='/~$uname$esc_thisdisfn/';
+parent.lastknownpriv='/priv$esc_thisdisfn/';
// Confirmation dialogues
- function currdiract(theform) {
- if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
- document.publishdir.filename.value = theform.filename.value;
- document.publishdir.submit();
- }
- if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editmeta') {
- top.location=theform.filename.value+'default.meta'
- }
- if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
- document.printdir.postdata.value=theform.filename.value
- document.printdir.submit();
- }
- if (theform.dirtask.options[theform.dirtask.selectedIndex].value == "delete") {
- var delform = document.delresource
- delform.filename.value = theform.filename.value
- delform.submit()
- }
- }
-
function checkUpload(theform) {
if (theform.file == '') {
alert("Please use 'Browse..' to choose a file first, before uploading")
@@ -330,27 +455,19 @@ parent.lastknownpriv='/~$uname$esc_thisd
ENDPUBDIRSCRIPT
$r->print($pubdirscript);
-
- if ((($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) &&
- $env{'environment.remote'} ne 'off') {
- $r->print('
'.&mt('Co-Author [_1]',$uname.':'.$udom).'
');
- }
}
sub dircontrols {
- my ($r,$uname,$udom,$thisdisfn) = @_;
+ my ($r,$uname,$udom,$thisdisfn,$current_disk_usage,$disk_quota) = @_;
my %lt=&Apache::lonlocal::texthash(
cnpd => 'Cannot publish directory',
cnrd => 'Cannot retrieve directory',
mcdi => 'Must create new subdirectory inside a directory',
pubr => 'Publish this Resource',
- pubd => 'Publish this Directory',
- dedr => 'Delete Directory',
rtrv => 'Retrieve Old Version',
list => 'List Directory',
uplo => 'Upload file',
dele => 'Delete',
- edit => 'Edit Metadata',
sela => 'Select Action',
nfil => 'New file',
nhtm => 'New HTML file',
@@ -367,55 +484,58 @@ sub dircontrols {
copy => 'Copy current file to',
type => 'Type Name Here',
go => 'Go',
- prnt => 'Print contents of directory',
- crea => 'Create a new directory or LON-CAPA document',
- acti => 'Actions for current directory',
+ crea => 'Create a new subdirectory or document',
updc => 'Upload a new document',
pick => 'Please select an action to perform using the new filename',
+ shcu => 'Shortcuts',
);
+ my %js_lt = &Apache::lonlocal::texthash(
+ nanf => 'Name of New File',
+ nans => 'Name of New Subdirectory',
+ psfn => 'Please specify file name',
+ );
+ &js_escape(\%js_lt);
my $mytype = $lt{'type'}; # avoid conflict with " and ' in javascript
+ # Calculate free space in bytes.
+ # $disk_quota is in MB and $current_disk_usage is in kB
+ my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
+ $r->print("\n".'
END
}
-sub pubbuttons {
- my ($r,$uname,$thisdisfn) = @_;
- $r->print('
'.
- '
'.
- '
'.
-'
');
-}
-
sub resourceactions {
my ($r,$uname,$udom,$thisdisfn) = @_;
$r->print(<
+
-
+
-
+
-
+
-
+
-
+
END
@@ -516,42 +660,49 @@ sub getSourceRightString {
}
#
# Put out a directory table row:
-# putdirectory(r, base, here, dirname, modtime)
-# r - Apache request object.
-# reqfile - File in request.
-# here - Where we are in directory tree.
-# dirname - Name of directory special file.
-# modtime - Encoded modification time.
-#
+# putdirectory(r, base, here, dirname, modtime, targetdir, bombs, numdir)
+# r - Apache request object.
+# reqfile - File in request.
+# here - Where we are in directory tree.
+# dirname - Name of directory special file.
+# modtime - Encoded modification time.
+# targetdir - Publication target directory.
+# bombs - Reference to hash of URLs with runtime error messages.
+# numdir - Reference to scalar used to track number of sub-directories
+# in directory (used in form name for each "actions" dropdown).
+#
sub putdirectory {
- my ($r, $reqfile, $here, $dirname, $modtime, $resdir, $bombs, $numdir) = @_;
- # construct the display filename: the directory name unless ..:
-
+ my ($r, $reqfile, $here, $dirname, $modtime, $targetdir, $bombs, $numdir) = @_;
+
+# construct the display filename: the directory name unless ..:
+
+ my $actionitem;
+
my $disfilename = $dirname;
- if ($dirname eq '..') {
- $disfilename = ''.&mt('Parent Directory').'';
- }
- unless ( (($dirname eq '..') && ($reqfile eq '')) || ($dirname eq '.')) {
- my $kaputt=0;
- foreach (keys %{$bombs}) {
- if ($_=~m:^\Q$resdir\E/\Q$disfilename\E/:) { $kaputt=1; last; }
- }
+# Don't display directory itself, and there is no way up from root directory
+ unless ((($dirname eq '..') && ($reqfile=~/^\/[^\/]+\/[^\/]+$/)) || ($dirname eq '.')) {
+ my $kaputt=0;
+ if (ref($bombs) eq 'HASH') {
+ foreach my $key (keys(%{$bombs})) {
+ my $currentdir = &Apache::lonnet::declutter("$targetdir/$disfilename");
+ if (($key) =~ m{^\Q$currentdir\E/}) { $kaputt=1; last; }
+ }
+ }
+#
+# Get the metadata from that directory's default.meta to display titles
+#
%Apache::lonpublisher::metadatafields=();
%Apache::lonpublisher::metadatakeys=();
- my $construct=$here;
- $construct=~s{^/priv/($LONCAPA::username_re)$}{/home/$1/public_html};
- my $dirpath = $here;
- $dirpath=~s{^/priv/}{/~};
- &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile(
- $construct.'/'.$dirname.'/default.meta'
- ));
- my $actionitem = '';
+ &Apache::lonpublisher::metaeval(
+ &Apache::lonnet::getfile($r->dir_config('lonDocRoot').$here.'/'.$dirname.'/default.meta')
+ );
if ($dirname eq '..') {
$actionitem = &mt('Go to ...');
+ $disfilename = ''.&mt('Parent Directory').'';
} else {
$actionitem =
'
'.
&Apache::loncommon::end_data_table_row()
);
- return OK;
+ return;
}
sub create_pubselect {
@@ -738,8 +924,8 @@ sub create_pubselect {
''.
''.
'
-
+
';
$$numres ++;
@@ -761,48 +947,23 @@ sub check_for_versions {
$versions ++;
}
}
+ closedir(DIR);
return $versions;
}
-#
-# Categorize files in the directory.
-# For each file in a list of files in a file directory,
-# the file categorized as one of:
-# - directory
-# - sequence
-# - problem
-# - Other resource.
-#
-# For each file the modification date is determined as well.
-# Returned is a list of sublists:
-# (directories, sequences, problems, other)
-# each of the sublists contains entries of the following form (sorted by
-# filename):
-# (filename, typecode, lastmodtime)
-#
-# $list = CategorizeFiles($location, $files)
-# $location - Directory in which the files live (relative to our
-# execution.
-# $files - list of files.
-#
-sub CategorizeFiles {
- my $location = shift;
- my $files = shift;
-}
-
1;
__END__
=head1 NAME
-Apache::lonpubdir - Construction space directory lister
+Apache::lonpubdir - Authoring space directory lister
=head1 SYNOPSIS
Invoked (for various locations) by /etc/httpd/conf/srm.conf:
-
+
PerlAccessHandler Apache::loncacc
SetHandler perl-script
PerlHandler Apache::lonpubdir
@@ -875,38 +1036,21 @@ Output the header of the page. This inc
$str = getTitleString($fullname);
$fullname - Fully qualified filename to check.
-=item putdirectory(r, base, here, dirname, modtime)
+=item putdirectory($r, $base, $here, $dirname, $modtime, $targetdir, $bombs,
+ $numdir)
Put out a directory table row:
- putdirectory($r, $base, $here, $dirname, $modtime)
- $r - Apache request object.
- $reqfile - File in request.
- $here - Where we are in directory tree.
- $dirname - Name of directory special file.
- $modtime - Encoded modification time.
-
-=item CategorizeFiles($location, $files)
-
- Categorize files in the directory.
- For each file in a list of files in a file directory,
- the file categorized as one of:
- - directory
- - sequence
- - problem
- - Other resource.
-
- For each file the modification date is determined as well.
- Returned is a list of sublists:
- (directories, sequences, problems, other)
- each of the sublists contains entries of the following form (sorted by filename):
- (filename, typecode, lastmodtime)
-
- $list = CategorizeFiles($location, $files)
- $location - Directory in which the files live (relative to our execution)
- $files - list of files.
+ $r - Apache request object.
+ $reqfile - File in request.
+ $here - Where we are in directory tree.
+ $dirname - Name of directory special file.
+ $modtime - Encoded modification time.
+ targetdir - Publication target directory.
+ bombs - Reference to hash of URLs with runtime error messages.
+ numdir - Reference to scalar used to track number of sub-directories
+ in directory (used in form name for each "actions" dropdown).
=back
=cut
-