--- loncom/publisher/lonpubdir.pm 2022/05/27 18:04:26 1.160.2.5.2.1
+++ loncom/publisher/lonpubdir.pm 2023/07/14 18:01:23 1.180
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Authoring Space Directory Lister
#
-# $Id: lonpubdir.pm,v 1.160.2.5.2.1 2022/05/27 18:04:26 raeburn Exp $
+# $Id: lonpubdir.pm,v 1.180 2023/07/14 18:01:23 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;
}
@@ -85,16 +85,28 @@ 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);
+ 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);
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);
if (!-d $fn) {
if (-e $fn) {
@@ -116,12 +128,12 @@ sub handler {
}
# 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 +192,7 @@ sub handler {
order => 'ascending',
text => &mt('Size').' (kB)',
},
- );
+ );
# Print column headers
my $output = '';
@@ -199,7 +211,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 +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) = ('','');
@@ -247,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
@@ -281,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 {
@@ -292,13 +317,14 @@ sub handler {
# Print the sorted resources
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"},
@@ -306,16 +332,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::start_data_table()
+ .'
'.&mt('Results in other directories:').' '
+ .''
+ .&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);
@@ -328,39 +367,49 @@ 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,
$disk_quota,'authoring')
.'
'
- .&Apache::loncommon::CSTR_pageheader()));
+ .&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=(<
@@ -371,31 +420,12 @@ parent.lastknownpriv='/priv$esc_thisdisf
// Confirmation dialogues
- function currdiract(theform) {
- if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
- document.publishdir.filename.value = theform.filename.value;
- document.publishdir.submit();
- }
- if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editmeta') {
- top.location=theform.filename.value+'default.meta'
- }
- if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
- document.printdir.postdata.value=theform.filename.value
- document.printdir.submit();
- }
- if (theform.dirtask.options[theform.dirtask.selectedIndex].value == "delete") {
- var delform = document.delresource
- delform.filename.value = theform.filename.value
- delform.submit()
- }
- }
-
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) {
@@ -473,19 +503,16 @@ 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',
mcdi => 'Must create new subdirectory inside a directory',
pubr => 'Publish this Resource',
- pubd => 'Publish this Directory',
- dedr => 'Delete Directory',
rtrv => 'Retrieve Old Version',
list => 'List Directory',
- uplo => 'Upload file',
+ uplo => 'Upload file',
dele => 'Delete',
- edit => 'Edit Metadata',
sela => 'Select Action',
nfil => 'New file',
nhtm => 'New HTML file',
@@ -502,47 +529,72 @@ sub dircontrols {
copy => 'Copy current file to',
type => 'Type Name Here',
go => 'Go',
- prnt => 'Print contents of directory',
- crea => 'Create a new directory or LON-CAPA document',
- acti => 'Actions for current directory',
+ 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',
);
+ my %js_lt = &Apache::lonlocal::texthash(
+ nanf => 'Name of New File',
+ nans => 'Name of New Subdirectory',
+ psfn => 'Please specify file name',
+ );
+ &js_escape(\%js_lt);
my $mytype = $lt{'type'}; # avoid conflict with " and ' in javascript
# 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(<printf(<
-
-
-
-
+
+
+ $lt{'qs'}
+
+
+
+ %s
+
+ $lt{'cs'}
+ $lt{'re'}
+
-
+END
+ my %fileoptions = (
+ none => "$lt{'sela'}:",
+ newfile => "$lt{'nfil'}:",
+ newhtmlfile => "$lt{'nhtm'}:",
+ newproblemfile => "$lt{'nprb'}:",
+ newdir => "$lt{'nsub'}:",
+ );
+ $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(<
-
+
END
}
@@ -696,9 +746,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 '.')) {
@@ -721,7 +771,7 @@ sub putdirectory {
$actionitem = &mt('Go to ...');
$disfilename = ''.&mt('Parent Directory').' ';
} else {
- $actionitem =
+ $actionitem =
'