--- loncom/publisher/lonpubdir.pm 2016/09/14 16:48:02 1.160.2.2 +++ 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.2 2016/09/14 16:48:02 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; } @@ -80,41 +81,85 @@ 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,$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); - &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); + 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; + } } - &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 +218,7 @@ sub handler { order => 'ascending', text => &mt('Size').' (kB)', }, - ); + ); # Print column headers my $output = ''; @@ -187,12 +232,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}.''); } - $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() ); @@ -210,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) = ('',''); @@ -240,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 @@ -274,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 { @@ -283,74 +341,103 @@ sub handler { } # Print the sorted resources + 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"}, - $filehash->{$filename}->{"pubstatus"}); + $filehash->{$filename}->{"pubstatus"}, + \%editors); } } - $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); +# startpage($r, $uame, $udom, $thisdisfn, $current_disk_usage, $disk_quota); # $r - The apache request object. # $uname - User name. # $udom - Domain name the user is logged in under. # $thisdisfn - Displayable version of the filename. +# $current_disk_usage - User's current disk usage (in kB). +# $disk_quota - Disk quota for user's authoring space (in MB). +# $crstype - Course type, if this is for "course author" sub startpage { - my ($r, $uname, $udom, $thisdisfn) = @_; + 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 $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 = 1000 * $disk_quota; # convert from MB to kB - + my $js = ''; + $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('Authoring Space'); + my $doctitle = 'LON-CAPA '.&mt($title); my $newname = &mt('New Name'); my $pubdirscript=(< @@ -361,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) { @@ -463,19 +531,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', @@ -492,51 +557,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', - 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 - $r->print(<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'} @@ -551,60 +645,58 @@ sub dircontrols { } } -    -
- Quickactions: + $selectbox   +
+ $lt{'shcu'}: - - - - - - - + file icon + + problem icon + + web page icon + + folder icon
-
+
END } @@ -612,26 +704,26 @@ END sub resourceactions { my ($r,$uname,$udom,$thisdisfn) = @_; $r->print(< +
-
+
-
+
-
+
-
+
-
+
END @@ -682,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 '.')) { @@ -707,9 +799,9 @@ sub putdirectory { $actionitem = &mt('Go to ...'); $disfilename = ''.&mt('Parent Directory').''; } else { - $actionitem = + $actionitem = '
'. + '" action="/adm/publish">'. '