--- loncom/publisher/lonpubdir.pm 2024/08/22 18:32:56 1.160.2.5.2.5 +++ 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.160.2.5.2.5 2024/08/22 18:32:56 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; } @@ -85,43 +86,80 @@ sub handler { 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; } - $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.').'

'); @@ -180,7 +218,7 @@ sub handler { order => 'ascending', text => &mt('Size').' (kB)', }, - ); + ); # Print column headers my $output = ''; @@ -199,7 +237,15 @@ sub handler { .$columns{$key}{text}.$arrows[$idx].'' : ''.$columns{$key}{text}.''); } - $r->print(&Apache::loncommon::start_data_table() + +my $result = ""; + $r->print($result); + + $r->print('
'.&Apache::loncommon::start_data_table() + .'' .&Apache::loncommon::start_data_table_header_row() . $output .&Apache::loncommon::end_data_table_header_row() ); @@ -217,18 +263,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) = ('',''); @@ -247,7 +298,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 @@ -281,7 +332,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 { @@ -293,13 +344,14 @@ sub handler { 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"}, @@ -308,16 +360,29 @@ sub handler { } } - $r->print( &Apache::loncommon::end_data_table() - .&Apache::loncommon::end_page() ); - - return OK; + $r->print(&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, $current_disk_usage, $disk_quota); @@ -330,32 +395,40 @@ sub handler { # $crstype - Course type, if this is for "course author" sub startpage { - my ($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota) = @_; + 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 $js = ''; + $r->print(&Apache::loncommon::start_page($title, $js)); - 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 = 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( '
' .&Apache::lonhtmlcommon::display_usage($current_disk_usage, @@ -364,7 +437,7 @@ sub startpage { .&Apache::loncommon::CSTR_pageheader('','',$headertext))); my $esc_thisdisfn = &Apache::loncommon::escape_single($thisdisfn); - my $doctitle = 'LON-CAPA '.&mt('Authoring Space'); + my $doctitle = 'LON-CAPA '.&mt($title); my $newname = &mt('New Name'); my $pubdirscript=(< @@ -378,9 +451,9 @@ parent.lastknownpriv='/priv$esc_thisdisf function checkUpload(theform) { if (theform.file == '') { alert("Please use 'Browse..' to choose a file first, before uploading") - return + return } - theform.submit() + theform.submit() } function SetPubDir(theform,printForm) { @@ -458,7 +531,7 @@ ENDPUBDIRSCRIPT } sub dircontrols { - my ($r,$uname,$udom,$thisdisfn,$current_disk_usage,$disk_quota) = @_; + my ($r,$uname,$udom,$thisdisfn,$current_disk_usage,$disk_quota,$crsauthor) = @_; my %lt=&Apache::lonlocal::texthash( cnpd => 'Cannot publish directory', cnrd => 'Cannot retrieve directory', @@ -466,7 +539,7 @@ sub dircontrols { pubr => 'Publish this Resource', rtrv => 'Retrieve Old Version', list => 'List Directory', - uplo => 'Upload file', + uplo => 'Upload file', dele => 'Delete', sela => 'Select Action', nfil => 'New file', @@ -485,6 +558,9 @@ sub dircontrols { type => 'Type Name Here', go => 'Go', crea => 'Create a new subdirectory or document', + qs => 'Quick name search', + cs => 'Case Sensitive', + re => 'Regular Expression', updc => 'Upload a new document', pick => 'Please select an action to perform using the new filename', shcu => 'Shortcuts', @@ -499,23 +575,46 @@ sub dircontrols { # 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".'
'."\n"); + $r->printf(< +
+
+ $lt{'qs'} + + + + %s +
+ + +
+
+END my %fileoptions = ( none => "$lt{'sela'}:", newfile => "$lt{'nfil'}:", newhtmlfile => "$lt{'nhtm'}:", newproblemfile => "$lt{'nprb'}:", newdir => "$lt{'nsub'}:", - newpagefile => "$lt{'npag'}:", - newsequencefile => "$lt{'nseq'}:", - newrightsfile => "$lt{'ncrf'}:", - newstyfile => "$lt{'nsty'}:", - newtaskfile => "$lt{'nbt'}:", - newlibraryfile => "$lt{'nlib'}:", ); - $fileoptions{'select_form_order'} = ['none','newfile','newhtmlfile','newproblemfile', - 'newpagefile','newsequencefile','newrightsfile', - 'newstyfile','newtaskfile','newlibraryfile','newdir']; + $fileoptions{'select_form_order'} = ['none','newfile','newhtmlfile','newproblemfile']; + if ($crsauthor) { + push(@{$fileoptions{'select_form_order'}},'newdir'); + } else { + my %extraoptions = ( + newpagefile => "$lt{'npag'}:", + newsequencefile => "$lt{'nseq'}:", + newrightsfile => "$lt{'ncrf'}:", + newstyfile => "$lt{'nsty'}:", + newtaskfile => "$lt{'nbt'}:", + newlibraryfile => "$lt{'nlib'}:", + ); + %fileoptions = (%fileoptions,%extraoptions); + push(@{$fileoptions{'select_form_order'}},('newpagefile','newsequencefile', + 'newrightsfile','newstyfile', + 'newtaskfile','newlibraryfile', + 'newdir')); + } my $selectbox = &Apache::loncommon::select_form('none','action',\%fileoptions); $r->print(< @@ -534,8 +633,8 @@ sub dircontrols {
$lt{'crea'} - - + + - $selectbox   -
+ $selectbox   +
$lt{'shcu'}: - file icon - + file icon + problem icon - + web page icon - - folder icon + + folder icon -
+
@@ -675,9 +774,9 @@ sub putdirectory { my ($r, $reqfile, $here, $dirname, $modtime, $targetdir, $bombs, $numdir) = @_; # construct the display filename: the directory name unless ..: - + my $actionitem; - + my $disfilename = $dirname; # Don't display directory itself, and there is no way up from root directory unless ((($dirname eq '..') && ($reqfile=~/^\/[^\/]+\/[^\/]+$/)) || ($dirname eq '.')) { @@ -700,7 +799,7 @@ sub putdirectory { $actionitem = &mt('Go to ...'); $disfilename = ''.&mt('Parent Directory').''; } else { - $actionitem = + $actionitem = '
'. '