--- loncom/publisher/lonpubdir.pm 2014/10/13 14:50:42 1.161 +++ 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.161 2014/10/13 14:50:42 goltermann 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; } @@ -80,14 +80,33 @@ 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); + 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); - &startpage($r, $uname, $udom, $thisdisfn); # Put out the start of page. + 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, + $cstr,$crstype); # expressed in MB + # Put out the start of page. + + &startpage($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota, $crsauthor); if (!-d $fn) { if (-e $fn) { @@ -108,13 +127,13 @@ sub handler { return OK; } - &dircontrols($r,$uname,$udom,$thisdisfn); # Put out actions for directory, - # browse/upload + new file page. + # Put out actions for directory, browse/upload + new file page. + &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.').'

'); @@ -173,7 +192,7 @@ sub handler { order => 'ascending', text => &mt('Size').' (kB)', }, - ); + ); # Print column headers my $output = ''; @@ -187,20 +206,20 @@ sub handler { } else { $idx = 2; } # No arrow if column is not sorted $output .= (($columns{$key}{order}) ? '' .$columns{$key}{text}.$arrows[$idx].'' : ''.$columns{$key}{text}.''); } -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() ); @@ -218,18 +237,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( '
' - .&Apache::lonhtmlcommon::display_usage($current_disk_usage,$disk_quota) + .&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=(< @@ -380,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) { @@ -482,19 +503,16 @@ ENDPUBDIRSCRIPT } sub dircontrols { - my ($r,$uname,$udom,$thisdisfn) = @_; + 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', @@ -511,54 +529,80 @@ 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', - qs => 'Quick Search', + crea => 'Create a new subdirectory or document', + qs => 'Quick name search', cs => 'Case Sensitive', re => 'Regular Expression', - acti => 'Actions for current directory', 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->printf(< -
-
-
- $lt{'acti'} - - -
-
-
- - -
-
- -
+
+
+ $lt{'qs'} + + + + %s +
+ + +
- -
-
+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(< +
$lt{'updc'} - + +
-
+
$lt{'crea'} @@ -573,37 +617,58 @@ sub dircontrols { } } -    + $selectbox   +
+ $lt{'shcu'}: + + + file icon + + problem icon + + web page icon + + folder icon + +
-
-
-
- $lt{'qs'} - - - - %s -
- - -
-
-
END } @@ -611,26 +676,26 @@ END sub resourceactions { my ($r,$uname,$udom,$thisdisfn) = @_; $r->print(< +
-
+
-
+
-
+
-
+
-
+
END @@ -681,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 '.')) { @@ -706,9 +771,9 @@ sub putdirectory { $actionitem = &mt('Go to ...'); $disfilename = ''.&mt('Parent Directory').''; } else { - $actionitem = + $actionitem = '
'. + '" action="/adm/publish">'. '