--- loncom/publisher/lonpubdir.pm 2014/08/05 19:32:23 1.160
+++ loncom/publisher/lonpubdir.pm 2023/11/17 17:02:22 1.181
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Authoring Space Directory Lister
#
-# $Id: lonpubdir.pm,v 1.160 2014/08/05 19:32:23 musolffc Exp $
+# $Id: lonpubdir.pm,v 1.181 2023/11/17 17:02:22 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -48,7 +48,7 @@ sub handler {
# Validate access to the construction space and get username:domain.
- my ($uname,$udom)=&Apache::lonnet::constructaccess($r->uri);
+ my ($uname,$udom)=&Apache::lonnet::constructaccess($r->uri);
unless (($uname) && ($udom)) {
return HTTP_NOT_ACCEPTABLE;
}
@@ -80,14 +80,33 @@ sub handler {
}
}
$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);
- &startpage($r, $uname, $udom, $thisdisfn); # Put out the start of page.
+ 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
+ # Put out the start of page.
+
+ &startpage($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota, $crsauthor);
if (!-d $fn) {
if (-e $fn) {
@@ -108,13 +127,13 @@ sub handler {
return OK;
}
- &dircontrols($r,$uname,$udom,$thisdisfn); # Put out actions for directory,
- # browse/upload + new file page.
+ # Put out actions for directory, browse/upload + new file page.
+ &dircontrols($r,$uname,$udom,$thisdisfn,$current_disk_usage,$disk_quota,$crsauthor);
&resourceactions($r,$uname,$udom,$thisdisfn); # Put out form used for printing/deletion etc.
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.').'
');
@@ -173,7 +192,7 @@ sub handler {
order => 'ascending',
text => &mt('Size').' (kB)',
},
- );
+ );
# Print column headers
my $output = '';
@@ -187,12 +206,20 @@ sub handler {
} else { $idx = 2; } # No arrow if column is not sorted
$output .= (($columns{$key}{order}) ?
'
'
.&Apache::loncommon::start_data_table_header_row() . $output
.&Apache::loncommon::end_data_table_header_row()
);
@@ -210,18 +237,23 @@ sub handler {
my ($cmode,$csize,$cmtime)=(stat($fn.'/'.$filename))[2,7,9];
my $linkfilename = &HTML::Entities::encode('/priv'.$thisdisfn.'/'.$filename,'<>&"');
# Identify type of file according to icon used
- my ($filetype) = (&Apache::loncommon::icon($filename) =~ m{/(\w+).gif$});
+ my ($filetype) = (&Apache::loncommon::icon($filename) =~ m{/(\w+).gif$});
my $cstr_dir = $r->dir_config('lonDocRoot').'/priv'.$thisdisfn;
my $meta_same = &isMetaSame($cstr_dir, $resdir, $filename);
-
+
# Store size, title, and status for files but not directories
my $size = (!($cmode&$dirptr)) ? $csize/1024. : 0;
my ($status, $pubstatus, $title, $fulltitle);
if (!($cmode&$dirptr)) {
- ($status, $pubstatus) = &getStatus($resdir, $targetdir, $cstr_dir,
+ ($status, $pubstatus) = &getStatus($resdir, $targetdir, $cstr_dir,
$filename, $linkfilename, $cmtime, $meta_same);
- ($fulltitle, $title) = &getTitle($resdir, $targetdir, $filename,
- $linkfilename, $meta_same, \%bombs);
+ if (($crsauthor) && ($extension eq 'rights')) {
+ $title = &getTitleString($targetdir.'/'.$filename);
+ $fulltitle = $title;
+ } else {
+ ($fulltitle, $title) = &getTitle($resdir, $targetdir, $filename,
+ $linkfilename, $meta_same, \%bombs);
+ }
} else {
($status, $pubstatus) = ('','');
($fulltitle, $title) = ('','');
@@ -240,7 +272,7 @@ sub handler {
"linkfilename" => $linkfilename,
}
}
-
+
my @sorted_files;
# Sorting by something other than "Name". Name is the secondary key.
if ($sortby =~ m{cmtime|size}) { # Numeric fields
@@ -274,7 +306,7 @@ sub handler {
}
# Sort by "Name" is the default
- } else {
+ } else {
if ($sortorder eq "rev") {
@sorted_files = sort {uc($b) cmp uc($a)} (keys(%{$filehash}));
} else {
@@ -283,73 +315,103 @@ sub handler {
}
# Print the sorted resources
+ my %editors = &Apache::loncommon::permitted_editors();
foreach my $filename (@sorted_files) {
if ($filehash->{$filename}->{"cmode"}&$dirptr) { # Directories
- &putdirectory($r, $thisdisfn, $linkdir, $filename,
- $filehash->{$filename}->{"cmtime"},
+ &putdirectory($r, $thisdisfn, $linkdir, $filename,
+ $filehash->{$filename}->{"cmtime"},
$targetdir, \%bombs, \$numdir);
} else { # Files
&putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir,
- $targetdir, $linkdir, $filehash->{$filename}->{"cmtime"},
- $filehash->{$filename}->{"size"}, \$numres,
+ $targetdir, $linkdir, $crsauthor,
+ $filehash->{$filename}->{"cmtime"},
+ $filehash->{$filename}->{"size"}, \$numres,
$filehash->{$filename}->{"linkfilename"},
$filehash->{$filename}->{"fulltitle"},
$filehash->{$filename}->{"status"},
- $filehash->{$filename}->{"pubstatus"});
+ $filehash->{$filename}->{"pubstatus"},
+ \%editors);
}
}
- $r->print( &Apache::loncommon::end_data_table()
- .&Apache::loncommon::end_page() );
-
- return OK;
+ $r->print(&Apache::loncommon::end_data_table()
+ .'
'
+ .&Apache::loncommon::start_data_table()
+ .'
'.&mt('Results in other directories:').'
'
+ .'
'
+ .'
'.&mt('Type').'
'
+ .'
'.&mt('Directory').'
'
+ .'
'.&mt('Name').'
'
+ .'
'.&mt('Title').'
'
+ .'
'.&mt('Status').'
'
+ .'
'.&mt('Last Modified').'
'
+ .'
'
+ .&Apache::loncommon::end_data_table()
+ .'
'
+ .&Apache::loncommon::end_page()
+ );
+ return OK;
}
# Output the header of the page. This includes:
-# - The HTML header
+# - The HTML header
# - The H1/H3 stuff which includes the directory.
#
-# startpage($r, $uame, $udom, $thisdisfn);
+# 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) = @_;
+ my ($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota, $crsauthor) = @_;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
my $formaction='/priv'.$thisdisfn.'/';
$formaction=~s|/+|/|g;
- &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
+
+ 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' => 'Authoring Space',
+ 'text' => $title,
'href' => &Apache::loncommon::authorspace($formaction),
});
- # breadcrumbs (and tools) will be created
+ # breadcrumbs (and tools) will be created
# in start_page->bodytag->innerregister
$env{'request.noversionuri'}=$formaction;
- $r->print(&Apache::loncommon::start_page('Authoring Space'));
-
- my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
- my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
- my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); #expressed in MB
- $disk_quota = 1000 * $disk_quota; # convert from MB to kB
-
+ my $js = '';
+ $r->print(&Apache::loncommon::start_page($title, $js));
+
+ $disk_quota = 1024 * $disk_quota; # convert from MB to kB
+
+ my $headertext = &mt('Directory');
+ if ($crsauthor) {
+ $headertext = &mt('Course Authoring Directory');
+ }
$r->print(&Apache::loncommon::head_subbox(
'