--- loncom/publisher/lonpubdir.pm 2015/12/03 20:40:46 1.165
+++ loncom/publisher/lonpubdir.pm 2024/01/10 20:07:37 1.183
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Authoring Space Directory Lister
#
-# $Id: lonpubdir.pm,v 1.165 2015/12/03 20:40:46 damieng Exp $
+# $Id: lonpubdir.pm,v 1.183 2024/01/10 20:07:37 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,6 +36,7 @@ use Apache::Constants qw(:common :http :
use Apache::loncommon();
use Apache::lonhtmlcommon();
use Apache::londiff();
+use Apache::lonpublisher();
use Apache::lonlocal;
use Apache::lonmsg;
use Apache::lonmenu;
@@ -48,7 +49,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;
}
@@ -67,9 +68,7 @@ sub handler {
$r->send_http_header;
&Apache::lonhtmlcommon::clear_breadcrumbs();
- my $js = '';
- $r->print(&Apache::loncommon::start_page('Authoring Space', $js).
+ $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).'
'.
@@ -82,48 +81,85 @@ 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,$crstoplevel,$cdom,$cnum);
+ if ($env{'request.course.id'}) {
+ $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ if ($thisdisfn =~ m{^/\Q$cdom/$cnum\E}) {
+ $crsauthor = 1;
+ $cstr = 'course';
+ $crstype = &Apache::loncommon::course_type();
+ $crstoplevel = "$docroot/priv/$cdom/$cnum";
+ }
+ }
+
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
-
+ $cstr,$crstype); # expressed in MB
# Put out the start of page.
- &startpage($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota);
+ &startpage($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota, $crsauthor);
+
+ my @files;
if (!-d $fn) {
- if (-e $fn) {
- $r->print('
'.&mt('Requested item is a file not a directory.').'
');
+ if (($crsauthor) && ($fn eq $crstoplevel)) {
+ my $path = "$docroot/priv/$cdom/$cnum";
+ my $rightsfile = 'default.rights';
+ my $sourcerights = "$path/$rightsfile";
+ &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$cnum,$cdom);
+ my $targetrights = $docroot."/res/$cdom/$cnum/$rightsfile";
+ if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
+ if (!-e "$docroot/res/$cdom") {
+ mkdir("$docroot/res/$cdom",0755);
+ }
+ if (!-e "$docroot/res/$cdom/$cnum") {
+ mkdir("$docroot/res/$cdom/$cnum",0755);
+ }
+ if ((-e "$docroot/res/$cdom/$cnum") && (!-e $targetrights)) {
+ my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
+ my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
+ }
+ } else {
+ $r->print('
'.&mt('The requested subdirectory does not exist.').'
');
+ return OK;
+ }
} else {
- $r->print('
'.&mt('The requested subdirectory does not exist.').'
');
+ 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);
+ &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.').'
');
@@ -182,7 +218,7 @@ sub handler {
order => 'ascending',
text => &mt('Size').' (kB)',
},
- );
+ );
# Print column headers
my $output = '';
@@ -227,18 +263,23 @@ my $result = "';
- $r->print(&Apache::loncommon::start_page('Authoring Space', $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(
'