--- loncom/publisher/lonpubdir.pm 2023/06/10 23:01:15 1.175 +++ 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.175 2023/06/10 23:01:15 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; @@ -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; } @@ -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"; } } @@ -104,36 +106,60 @@ sub handler { "$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); + 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. - &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.').'
'); @@ -192,7 +218,7 @@ sub handler { order => 'ascending', text => &mt('Size').' (kB)', }, - ); + ); # Print column headers my $output = ''; @@ -237,18 +263,23 @@ my $result = "'; $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( '