--- loncom/publisher/lonpubdir.pm 2023/11/28 22:28:05 1.182 +++ 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.182 2023/11/28 22:28:05 raeburn 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; @@ -86,14 +87,15 @@ sub handler { my $linkdir='/priv'.$thisdisfn; # Full URL name of constr space. my $cstr = 'author'; - my ($crsauthor,$crstype); + my ($crsauthor,$crstype,$crstoplevel,$cdom,$cnum); if ($env{'request.course.id'}) { - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + $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"; } } @@ -108,23 +110,47 @@ sub handler { &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; } - $r->print(&Apache::loncommon::end_page()); - return OK; - } - my @files; - if (opendir(DIR,$fn)) { - @files = grep(!/^\.+$/,readdir(DIR)); - closedir(DIR); } else { - $r->print('

'.&mt('Could not open directory.').'

'); - $r->print(&Apache::loncommon::end_page()); - return OK; + if (opendir(DIR,$fn)) { + @files = grep(!/^\.+$/,readdir(DIR)); + closedir(DIR); + } else { + $r->print('

'.&mt('Could not open directory.').'

'); + $r->print(&Apache::loncommon::end_page()); + return OK; + } } # Put out actions for directory, browse/upload + new file page.