--- loncom/interface/londocs.pm 2003/09/15 15:24:18 1.78
+++ loncom/interface/londocs.pm 2004/08/29 06:35:41 1.139
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.78 2003/09/15 15:24:18 www Exp $
+# $Id: londocs.pm,v 1.139 2004/08/29 06:35:41 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,8 +36,10 @@ use Apache::lonratedt;
use Apache::lonratsrv;
use Apache::lonxml;
use Apache::loncreatecourse;
+use Apache::lonnavmaps;
use HTML::Entities;
use GDBM_File;
+use Apache::lonlocal;
my $iconpath;
@@ -67,10 +69,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
@@ -93,13 +98,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++;
}
}
@@ -114,10 +121,12 @@ sub dumpbutton {
my $output='
';
if ($home) {
return ' '.
- ' ';
+ ' '.
+ &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
} else {
return' '.
- 'Dump Course DOCS to Construction Space: available on other servers';
+ &mt('Dump Course DOCS to Construction Space: available on other servers');
}
}
@@ -136,13 +145,56 @@ sub dumpcourse {
# Do the dumping
unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
+ $r->print(''.&mt('Copying Files').' ');
my $title=$ENV{'form.authorfolder'};
-
+ $title=~s/[^\w\/]+/\_/g;
+ my %replacehash=();
+ foreach (keys %ENV) {
+ if ($_=~/^form\.namefor\_(.+)/) {
+ $replacehash{$1}=$ENV{$_};
+ }
+ }
+ my $crs='/uploaded/'.$ENV{'request.course.id'}.'/';
+ $crs=~s/\_/\//g;
+ foreach (keys %replacehash) {
+ my $newfilename=$title.'/'.$replacehash{$_};
+ $newfilename=~s/[^\w\/\.\/]+/\_/g;
+ my @dirs=split(/\//,$newfilename);
+ my $path='/home/'.$ca.'/public_html';
+ my $makepath=$path;
+ my $fail=0;
+ for (my $i=0;$i<$#dirs;$i++) {
+ $makepath.='/'.$dirs[$i];
+ unless (-e $makepath) {
+ unless(mkdir($makepath,0777)) { $fail=1; }
+ }
+ }
+ $r->print(''.$_.' => '.$newfilename.' : ');
+ if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
+ if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
+ print $fh &Apache::loncreatecourse::rewritefile(
+ &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_),
+ (%replacehash,$crs => '')
+ );
+ } else {
+ print $fh
+ &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_);
+ }
+ $fh->close();
+ } else {
+ $fail=1;
+ }
+ if ($fail) {
+ $r->print('fail ');
+ } else {
+ $r->print('ok ');
+ }
+ }
} else {
# Input form
unless ($home==1) {
$r->print(
- 'Select the Construction Space ');
+ ''.&mt('Select the Construction Space').' ');
}
foreach (sort keys %outhash) {
if ($_=~/^home_(.+)$/) {
@@ -150,7 +202,8 @@ sub dumpcourse {
$r->print(
' ');
} else {
- $r->print(''.$_.' ');
+ $r->print(''.$1.' - '.
+ &Apache::loncommon::plainname(split(/\@/,$1)).' ');
}
}
}
@@ -160,9 +213,9 @@ sub dumpcourse {
my $title=$origcrsdata{'description'};
$title=~s/\s+/\_/gs;
$title=~s/\W//gs;
- $r->print('Folder in Construction Space ');
+ $r->print(''.&mt('Folder in Construction Space').' ');
&tiehash();
- $r->print('Filenames in Construction Space Internal Filename Title Save as ... ');
+ $r->print(''.&mt('Filenames in Construction Space').' \n");
&untiehash();
$r->print(
- '
');
+ '
');
+ }
+}
+
+# ------------------------------------------------------ Generate "export" button
+
+sub exportbutton {
+ return ''.
+ ' '.
+ &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;
+
+ &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'};
+ }
+ }
+ my $curRes;
+ my $count;
+ my %symbs;
+ my $display;
+ while ($curRes = $it->next()) {
+ if (ref($curRes)) {
+ $count ++;
+ $symbs{$count} = $curRes->symb();
+ if (grep/^$count$/,@exportitems) {
+ $display.= 'Export content item '.$curRes->title()." \n";
+ }
+ if (grep/^$count$/,@discussions) {
+ $display.= 'Export discussion posts '.$curRes->title()." \n";
+ }
+ }
+ }
+
+ $r->print('Export Course '.
+ &Apache::loncommon::bodytag('Export course to IMS or SCORM content package'
+));
+
+ my $exportfile;
+ $r->print($display);
+ $r->print('