--- loncom/interface/londocs.pm 2002/09/02 15:27:08 1.15 +++ loncom/interface/londocs.pm 2013/09/01 03:21:46 1.484.2.40 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.15 2002/09/02 15:27:08 www Exp $ +# $Id: londocs.pm,v 1.484.2.40 2013/09/01 03:21:46 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,310 +29,6522 @@ package Apache::londocs; use strict; -use Apache::Constants qw(:common); +use Apache::Constants qw(:common :http); +use Apache::imsexport; use Apache::lonnet; use Apache::loncommon; -use Apache::lonratedt; -use Apache::lonratsrv; +use Apache::lonhtmlcommon; +use LONCAPA::map(); +use Apache::lonratedt(); use Apache::lonxml; +use Apache::lonclonecourse; +use Apache::lonnavmaps; +use Apache::lonnavdisplay(); +use Apache::lonextresedit(); +use HTML::Entities; +use HTML::TokeParser; +use GDBM_File; +use Apache::lonlocal; +use Cwd; +use LONCAPA qw(:DEFAULT :match); my $iconpath; -# Mapread read maps into lonratedt::global arrays -# @order and @resources, determines status -# sets @order - pointer to resources in right order -# sets @resources - array with the resources with correct idx -# +my %hash; + +my $hashtied; +my %alreadyseen=(); + +my $hadchanges; +my $suppchanges; + + +my %help=(); + sub mapread { my ($coursenum,$coursedom,$map)=@_; return - &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'. - $map); + &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'. + $map); } sub storemap { - my ($coursenum,$coursedom,$map)=@_; - return - &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'. - $map,1); + my ($coursenum,$coursedom,$map,$contentchg)=@_; + my $report; + if (($contentchg) && ($map =~ /^default/)) { + $report = 1; + } + my ($outtext,$errtext)= + &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'. + $map,1,$report); + if ($errtext) { return ($errtext,2); } + + if ($map =~ /^default/) { + $hadchanges=1; + } else { + $suppchanges=1; + } + return ($errtext,0); +} + + + +sub authorhosts { + my %outhash=(); + my $home=0; + my $other=0; + foreach my $key (keys(%env)) { + if ($key=~/^user\.role\.(au|ca)\.(.+)$/) { + my $role=$1; + my $realm=$2; + my ($start,$end)=split(/\./,$env{$key}); + if (($start) && ($start>time)) { next; } + if (($end) && (time>$end)) { next; } + my ($ca,$cd); + if ($1 eq 'au') { + $ca=$env{'user.name'}; + $cd=$env{'user.domain'}; + } else { + ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/); + } + 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; + last; + } + } + if ($allowed) { + $home++; + $outhash{'home_'.$ca.':'.$cd}=1; + } else { + $outhash{'otherhome_'.$ca.':'.$cd}=$myhome; + $other++; + } + } + } + return ($home,$other,%outhash); +} + + +sub clean { + my ($title)=@_; + $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs; + return $title; +} + + + +sub dumpcourse { + my ($r) = @_; + my $crstype = &Apache::loncommon::course_type(); + $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space')."\n". + &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n"); + $r->print(&startContentScreen('tools')); + my ($home,$other,%outhash)=&authorhosts(); + unless ($home) { + $r->print(&endContentScreen()); + return ''; + } + my $origcrsid=$env{'request.course.id'}; + my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid); + if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) { +# Do the dumping + unless ($outhash{'home_'.$env{'form.authorspace'}}) { + $r->print(&endContentScreen()); + return ''; + } + my ($ca,$cd)=split(/\:/,$env{'form.authorspace'}); + $r->print('