--- loncom/publisher/lonpubdir.pm 2019/08/13 16:59:12 1.173 +++ 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.173 2019/08/13 16:59:12 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( '
' .&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($title); @@ -410,31 +448,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) { @@ -512,19 +531,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', @@ -541,50 +557,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', - 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'} - +
@@ -592,7 +630,7 @@ sub dircontrols {
- +
$lt{'crea'} @@ -607,53 +645,51 @@ sub dircontrols { } } -    + $selectbox  
- Quickactions: + $lt{'shcu'}: - + file icon - + problem icon - + web page icon - + folder icon @@ -661,18 +697,6 @@ sub dircontrols {
-
-
- $lt{'qs'} - - - - %s -
- - -
-
END } @@ -680,26 +704,26 @@ END sub resourceactions { my ($r,$uname,$udom,$thisdisfn) = @_; $r->print(< +
-
+
-
+
-
+
-
+
-
+
END @@ -750,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 '.')) { @@ -775,9 +799,9 @@ sub putdirectory { $actionitem = &mt('Go to ...'); $disfilename = ''.&mt('Parent Directory').''; } else { - $actionitem = + $actionitem = '
'. + '" action="/adm/publish">'. '