--- loncom/interface/londocs.pm 2003/09/02 18:31:08 1.69.2.1.2.3
+++ loncom/interface/londocs.pm 2004/08/22 18:15:54 1.138
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.69.2.1.2.3 2003/09/02 18:31:08 albertel Exp $
+# $Id: londocs.pm,v 1.138 2004/08/22 18:15:54 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,8 +35,11 @@ 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;
my $iconpath;
@@ -66,17 +69,423 @@ 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
+
+sub authorhosts {
+ my %outhash=();
+ my $home=0;
+ my $other=0;
+ foreach (keys %ENV) {
+ if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
+ my $role=$1;
+ my $realm=$2;
+ my ($start,$end)=split(/\./,$ENV{$_});
+ if (($start) && ($start>time)) { next; }
+ if (($end) && (time>$end)) { next; }
+ my $ca; my $cd;
+ if ($1 eq 'au') {
+ $ca=$ENV{'user.name'};
+ $cd=$ENV{'user.domain'};
+ } else {
+ ($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
+ }
+ 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}=$myhome;
+ $other++;
+ }
+ }
+ }
+ return ($home,$other,%outhash);
+}
+# ------------------------------------------------------ Generate "dump" button
+
+sub dumpbutton {
+ my ($home,$other,%outhash)=&authorhosts();
+ if ($home+$other==0) { return ''; }
+ my $output='
';
+ if ($home) {
+ return ' | '.
+ ''.
+ &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
+ } else {
+ return' | '.
+ &mt('Dump Course DOCS to Construction Space: available on other servers');
+ }
+}
+
+# -------------------------------------------------------- Actually dump course
+
+sub dumpcourse {
+ my $r=shift;
+ $r->print('Dump DOCS'.
+ &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
+ '');
+ }
+}
+
+# ------------------------------------------------------ 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('');
+ } else {
+ my $display;
+ $display = ' |