--- loncom/publisher/lonpubdir.pm 2014/01/21 18:23:35 1.149
+++ loncom/publisher/lonpubdir.pm 2014/07/31 19:25:39 1.159
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Authoring Space Directory Lister
#
-# $Id: lonpubdir.pm,v 1.149 2014/01/21 18:23:35 musolffc Exp $
+# $Id: lonpubdir.pm,v 1.159 2014/07/31 19:25:39 musolffc Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,89 +40,243 @@ use Apache::lonlocal;
use Apache::lonmsg;
use Apache::lonmenu;
use Apache::lonnet;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
sub handler {
- my $r=shift;
+ my $r=shift;
- # Validate access to the construction space and get username:domain.
+ # Validate access to the construction space and get username:domain.
- my $uname;
- my $udom;
-
- ($uname,$udom)=&Apache::lonnet::constructaccess($r->uri);
- unless (($uname) && ($udom)) {
- return HTTP_NOT_ACCEPTABLE;
- }
+ my ($uname,$udom)=&Apache::lonnet::constructaccess($r->uri);
+ unless (($uname) && ($udom)) {
+ return HTTP_NOT_ACCEPTABLE;
+ }
# ----------------------------------------------------------- Start page output
- my $fn=$r->filename;
- $fn=~s/\/$//;
+ my $fn=$r->filename;
+ $fn=~s/\/$//;
+ my $thisdisfn=$fn;
+
+ my $docroot=$r->dir_config('lonDocRoot'); # Apache londocument root.
+ if ($thisdisfn eq "$docroot/priv/$udom") {
+ if ((-d "/home/$uname/public_html/") && (!-e "$docroot/priv/$udom/$uname")) {
+ my ($version) = ($r->dir_config('lonVersion') =~ /^\'?(\d+\.\d+)\./);
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->send_http_header;
+
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ $r->print(&Apache::loncommon::start_page('Authoring Space').
+ '
'
@@ -516,51 +670,71 @@ sub putdirectory {
}
$r->print($Apache::lonpublisher::metadatafields{'keywords'}.''.
'
'.&Apache::lonlocal::locallocaltime($modtime).' | '.
+ '
| '.
"\n");
}
- return OK;
+ return;
}
-#
-# Put a table row for a file resource.
-#
-sub putresource {
- my ($r, $udom, $uname, $filename, $thisdisfn,
- $resdir, $targetdir, $linkdir,
- $cmtime,$bombs,$numres) = @_;
- &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
- my $pubstatus = 'unpublished';
- my $status=&mt('Unpublished');
- my $css_class='LC_browser_file';
+
+sub getTitle {
+ my ($resdir, $targetdir, $filename, $linkfilename, $meta_same, $bombs) = @_;
my $title='';
- my $publish_button=&mt('Publish');
- my $cstr_dir = $r->dir_config('lonDocRoot').'/priv'.$thisdisfn;
- my $linkfilename=&HTML::Entities::encode('/priv'.$thisdisfn.'/'.$filename,'<>&"');
+ my $titleString = &getTitleString($targetdir.'/'.$filename);
+ if (-e $resdir.'/'.$filename) {
+ $title = '
'.$titleString.'';
+ if (!$meta_same) {
+ $title = &mt('Metadata Modified').'
'.$title.
+ '
'.
+ &Apache::loncommon::modal_link(
+ '/adm/diff?filename='.$linkfilename.'.meta'.'&versiontwo=priv',
+ &mt('Metadata Diffs'),600,500);
+ $title.="\n".'
'.
+ &Apache::loncommon::modal_link(
+ '/adm/retrieve?filename='.$linkfilename.'.meta&inhibitmenu=yes&add_modal=yes',
+ &mt('Retrieve Metadata'),600,500);
+ }
+ }
+ # Allow editing metadata of published and unpublished resources
+ $title .= "\n".'
' if ($title);
+ $title .= '
'.
+ ($$bombs{&Apache::lonnet::declutter($targetdir.'/'.$filename)}?
+ '':
+ &mt('Edit Metadata')).
+ '';
+
+ return ($title, $titleString);
+}
+
+
+sub isMetaSame {
+ my ($cstr_dir, $resdir, $filename) = @_;
+ my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
+ my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
+ return (&Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
+ $cstr_dir.'/'.$filename.'.meta') && $meta_rmtime < $meta_cmtime)
+ ? 0 : 1;
+}
+
+
+sub getStatus {
+ my ($resdir, $targetdir, $cstr_dir, $filename,
+ $linkfilename, $cmtime, $meta_same) = @_;
+ my $pubstatus = 'unpublished';
+ my $status = &mt('Unpublished');
if (-e $resdir.'/'.$filename) {
- my $same=0;
- my ($rdev,$rino,$rmode,$rnlink,
- $ruid,$rgid,$rrdev,$rsize,
- $ratime,$rmtime,$rctime,
- $rblksize,$rblocks)=stat($resdir.'/'.$filename);
- if ($rmtime>=$cmtime) {
- $same=1;
+ my $same = 0;
+ if ((stat($resdir.'/'.$filename))[9] >= $cmtime) {
+ $same = 1;
} else {
if (&Apache::londiff::are_different_files($resdir.'/'.$filename,
$cstr_dir.'/'.$filename)) {
- $same=0;
+ $same = 0;
} else {
- $same=1;
+ $same = 1;
}
}
- my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
- my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
- my $meta_same = 1;
- if ($meta_rmtime < $meta_cmtime
- && &Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
- $cstr_dir.'/'.$filename.'.meta')) {
- $meta_same = 0;
- }
- $publish_button=&mt('Re-publish');
my $rights_status =
&mt(&getCopyRightString($targetdir.'/'.$filename)).', ';
@@ -572,9 +746,6 @@ sub putresource {
$rights_status .=
$lt_SourceRight{&getSourceRightString($targetdir.'/'.$filename)};
- $title = '
'.
- &getTitleString($targetdir.'/'.$filename).'';
if ($same) {
if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
$pubstatus = 'obsolete';
@@ -599,28 +770,24 @@ sub putresource {
&mt('Diffs'),600,500);
}
}
- if (!$meta_same) {
- $title = &mt('Metadata Modified').'
'.$title.
- '
'.
- &Apache::loncommon::modal_link(
- '/adm/diff?filename='.$linkfilename.'.meta'.'&versiontwo=priv',
- &mt('Metadata Diffs'),600,500);
- $title.="\n".'
'.
- &Apache::loncommon::modal_link(
- '/adm/retrieve?filename='.$linkfilename.'.meta&inhibitmenu=yes&add_modal=yes',
- &mt('Retrieve Metadata'),600,500);
- }
+
$status.="\n".'
'.
&Apache::loncommon::modal_link(
'/adm/retrieve?filename='.$linkfilename.'&inhibitmenu=yes&add_modal=yes',&mt('Retrieve'),600,500);
}
- # Allow editing metadata of published and unpublished resources
- $title .= "\n".'
' if ($title);
- $title .= '
'.
- ($$bombs{&Apache::lonnet::declutter($targetdir.'/'.$filename)}?
- '':
- &mt('Edit Metadata')).
- '';
+
+ return ($status, $pubstatus);
+}
+
+
+#
+# Put a table row for a file resource.
+#
+sub putresource {
+ my ($r, $udom, $uname, $filename, $thisdisfn, $resdir, $targetdir,
+ $linkdir, $cmtime, $size, $numres, $linkfilename, $title,
+ $status, $pubstatus) = @_;
+ &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
my $editlink='';
my $editlink2='';
@@ -637,6 +804,7 @@ sub putresource {
if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
$editlink=' (
'.&mt('Decompress').')';
}
+ my $publish_button = (-e $resdir.'/'.$filename) ? &mt('Re-publish') : &mt('Publish');
my $pub_select = '';
&create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
$r->print(&Apache::loncommon::start_data_table_row().
@@ -651,9 +819,10 @@ sub putresource {
'
| '. # Display publication status
'
'.$status.' | '.
'
'.&Apache::lonlocal::locallocaltime($cmtime).' | '.
+ '
'.sprintf("%.1f",$size).' | '.
&Apache::loncommon::end_data_table_row()
);
- return OK;
+ return;
}
sub create_pubselect {
@@ -706,6 +875,7 @@ sub check_for_versions {
$versions ++;
}
}
+ closedir(DIR);
return $versions;
}
@@ -812,4 +982,3 @@ Output the header of the page. This inc
=back
=cut
-