--- loncom/interface/londocs.pm 2003/09/22 03:02:05 1.83
+++ loncom/interface/londocs.pm 2004/12/23 14:00:58 1.158
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.83 2003/09/22 03:02:05 www Exp $
+# $Id: londocs.pm,v 1.158 2004/12/23 14:00:58 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,15 +30,18 @@ package Apache::londocs;
use strict;
use Apache::Constants qw(:common :http);
+use Apache::imsexport;
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonratedt;
use Apache::lonratsrv;
use Apache::lonxml;
use Apache::loncreatecourse;
+use Apache::lonnavmaps;
use HTML::Entities;
use GDBM_File;
use Apache::lonlocal;
+use Cwd;
my $iconpath;
@@ -68,10 +71,13 @@ sub mapread {
sub storemap {
my ($coursenum,$coursedom,$map)=@_;
- $hadchanges=1;
- return
+ my ($outtext,$errtext)=
&Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
$map,1);
+ if ($errtext) { return ($errtext,2); }
+
+ $hadchanges=1;
+ return ($errtext,0);
}
# ----------------------------------------- Return hash with valid author names
@@ -94,13 +100,15 @@ sub authorhosts {
} else {
($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
}
- if (&Apache::lonnet::homeserver($ca,$cd) eq
- $Apache::lonnet::perlvar{'lonHostID'}) {
+ my $allowed=0;
+ my $myhome=&Apache::lonnet::homeserver($ca,$cd);
+ my @ids=&Apache::lonnet::current_machine_ids();
+ foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
+ if ($allowed) {
$home++;
$outhash{'home_'.$ca.'@'.$cd}=1;
} else {
- $outhash{'otherhome_'.$ca.'@'.$cd}=
- &Apache::lonnet::homeserver($ca,$cd);
+ $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
$other++;
}
}
@@ -116,7 +124,8 @@ sub dumpbutton {
if ($home) {
return '
'.
'';
+ &mt('Dump Course DOCS to Construction Space').'" />'.
+ &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
} else {
return'
'.
&mt('Dump Course DOCS to Construction Space: available on other servers');
@@ -138,7 +147,7 @@ sub dumpcourse {
# Do the dumping
unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
- $r->print('
Copying Files
');
+ $r->print('
'.&mt('Copying Files').'
');
my $title=$ENV{'form.authorfolder'};
$title=~s/[^\w\/]+/\_/g;
my %replacehash=();
@@ -151,7 +160,7 @@ sub dumpcourse {
$crs=~s/\_/\//g;
foreach (keys %replacehash) {
my $newfilename=$title.'/'.$replacehash{$_};
- $newfilename=~s/[^\w\/\.]+/\_/g;
+ $newfilename=~s/[^\w\/\.\/]+/\_/g;
my @dirs=split(/\//,$newfilename);
my $path='/home/'.$ca.'/public_html';
my $makepath=$path;
@@ -195,7 +204,8 @@ sub dumpcourse {
$r->print(
'');
} else {
- $r->print('');
+ $r->print('');
}
}
}
@@ -218,7 +228,7 @@ sub dumpcourse {
$title=$_;
}
$title=~s/\.(\w+)$//;
- $title=~s/\W+/\_/gs;
+ $title=~s/[^\w\/]+/\_/gs;
$title.='.'.$ext;
$r->print("\n
'.
+ ''.
+ &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
+}
+
+sub exportcourse {
+ my $r=shift;
+ my %discussiontime = &Apache::lonnet::dump('discussiontimes',
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ my $numdisc = keys %discussiontime;
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
+ my $curRes;
+ my $outcome;
+
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['finishexport']);
+ if ($ENV{'form.finishexport'}) {
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['archive','discussion']);
+
+ my @exportitems = ();
+ if (defined($ENV{'form.archive'})) {
+ if (ref($ENV{'form.archive'}) eq 'ARRAY') {
+ @exportitems = @{$ENV{'form.archive'}};
+ } else {
+ $exportitems[0] = $ENV{'form.archive'};
+ }
+ }
+ my @discussions = ();
+ if (defined($ENV{'form.discussion'})) {
+ if (ref($ENV{'form.discussion'}) eq 'ARRAY') {
+ @discussions = $ENV{'form.discussion'};
+ } else {
+ $discussions[0] = $ENV{'form.discussion'};
+ }
+ }
+ if (@exportitems == 0 && @discussions == 0) {
+ $outcome = ' As you did not select any content items or discussions for export, an IMS package has not been created. Please go back to select either content items or discussions for export';
+ } else {
+ my $now = time;
+ my %symbs;
+ my $manifestok = 0;
+ my $imsresources;
+ my $tempexport;
+ my $copyresult;
+ my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
+ if ($manifestok) {
+ &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
+ close($ims_manifest);
+
+#Create zip file in prtspool
+ my $imszipfile = '/prtspool/'.
+ $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
+ time.'_'.rand(1000000000).'.zip';
+# zip can cause an sh launch which can pass along all of %ENV
+# which can be too large for /bin/sh to handle
+ my %oldENV=%ENV;
+ undef(%ENV);
+ my $cwd = &Cwd::getcwd();
+ my $imszip = '/home/httpd/'.$imszipfile;
+ chdir $tempexport;
+ open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
+ close(OUTPUT);
+ chdir $cwd;
+ %ENV=%oldENV;
+ undef(%oldENV);
+ $outcome .= 'Download the zip file from IMS course archive ';
+ if ($copyresult) {
+ $outcome .= 'The following errors occurred during export - '.$copyresult;
+ }
+ } else {
+ $outcome = ' Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file. ';
+ }
+ }
+
+ $r->print('Export Course'.
+ &Apache::loncommon::bodytag('Export course to IMS content package'));
+ $r->print($outcome);
+ $r->print('