--- loncom/interface/londocs.pm 2004/08/17 19:02:57 1.137
+++ loncom/interface/londocs.pm 2016/06/19 04:27:49 1.606
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.137 2004/08/17 19:02:57 albertel Exp $
+# $Id: londocs.pm,v 1.606 2016/06/19 04:27:49 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,15 +30,29 @@ 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::lonhtmlcommon;
+use LONCAPA::map();
+use Apache::lonratedt();
use Apache::lonxml;
-use Apache::loncreatecourse;
+use Apache::lonclonecourse;
+use Apache::lonnavmaps;
+use Apache::lonnavdisplay();
+use Apache::lonextresedit();
+use Apache::lontemplate();
+use Apache::lonsimplepage();
+use Apache::lonhomework();
+use Apache::lonpublisher();
use HTML::Entities;
+use HTML::TokeParser;
use GDBM_File;
+use File::MMagic;
+use File::Copy;
use Apache::lonlocal;
+use Cwd;
+use LONCAPA qw(:DEFAULT :match);
my $iconpath;
@@ -48,639 +62,4212 @@ my $hashtied;
my %alreadyseen=();
my $hadchanges;
+my $suppchanges;
-# Available help topics
my %help=();
-# 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
-#
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)=@_;
+ my ($coursenum,$coursedom,$map,$contentchg)=@_;
+ my $report;
+ if (($contentchg) && ($map =~ /^default/)) {
+ $report = 1;
+ }
my ($outtext,$errtext)=
- &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map,1);
+ &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
+ $map,1,$report);
if ($errtext) { return ($errtext,2); }
-
- $hadchanges=1;
+
+ if ($map =~ /^default/) {
+ $hadchanges=1;
+ } else {
+ $suppchanges=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)\.(.+)$/) {
+ foreach my $key (keys(%env)) {
+ if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
my $role=$1;
my $realm=$2;
- my ($start,$end)=split(/\./,$ENV{$_});
+ my ($start,$end)=split(/\./,$env{$key});
if (($start) && ($start>time)) { next; }
if (($end) && (time>$end)) { next; }
- my $ca; my $cd;
+ my ($ca,$cd);
if ($1 eq 'au') {
- $ca=$ENV{'user.name'};
- $cd=$ENV{'user.domain'};
+ $ca=$env{'user.name'};
+ $cd=$env{'user.domain'};
} else {
- ($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
+ ($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; } }
+ foreach my $id (@ids) {
+ if ($id eq $myhome) {
+ $allowed=1;
+ last;
+ }
+ }
if ($allowed) {
$home++;
- $outhash{'home_'.$ca.'@'.$cd}=1;
+ $outhash{'home_'.$ca.':'.$cd}=1;
} else {
- $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
+ $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');
- }
+
+sub clean {
+ my ($title)=@_;
+ $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
+ return $title;
}
-# -------------------------------------------------------- Actually dump course
+
sub dumpcourse {
- my $r=shift;
- $r->print('Dump DOCS'.
- &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
- ' | ');
- }
-# ----------------------------------------------------- Supplemental documents
- if (!$forcestandard) {
- $r->print('');
-# ''.&mt('Supplemental Course Documents').
-# ($allowed?' '.$help{'Supplemental'}:'').'');
- my $folder=$ENV{'form.folder'};
- unless ($folder=~/^supplemental/) {
- $folder='supplemental';
- }
- if ($folder =~ /^supplemental$/ &&
- $ENV{'form.folderpath'} =~ /^default\&/) {
- $ENV{'form.folderpath'}='supplemental&'.
- &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
- }
- &editor($r,$coursenum,$coursedom,$folder,$allowed);
- if ($allowed) {
- my $folderseq=
- '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
- '.sequence';
-
- $r->print(<
-$lt{'upls'} |
-$lt{'spec'} |
-
-
-
- |
-
-
-
-
-
- |
- |
-ENDSUPFORM
+}
+
+sub history_tab_js {
+ return <<"ENDHIST";
+function toggleHistoryDisp(choice) {
+ document.docslogform.docslog.value = choice;
+ document.docslogform.submit();
+ return;
+}
+
+ENDHIST
+}
+
+sub inject_data_js {
+ return < 'Copying content to Authoring Space requires switching server.',
+ swit => 'Switch server?',
+ );
+ my %html_js_lt = &Apache::lonlocal::texthash(
+ swit => 'Switch server?',
+ duco => 'Copying Content to Authoring Space',
+ yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
+ chos => 'Choose server',
+ );
+ &js_escape(\%js_lt);
+ &html_escape(\%html_js_lt);
+ &js_escape(\%html_js_lt);
+ my $role = $env{'request.role'};
+ my $js = <<"ENDSWJS";
+
+
+ENDSWJS
+
+ my $startpage = &Apache::loncommon::start_page('Choose server',$js,
+ {'only_body' => 1,
+ 'js_ready' => 1,});
+ my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
+
+ my $hostpicker;
+ my $count = 0;
+ foreach my $host (sort(@hosts)) {
+ my $checked;
+ if ($count == 0) {
+ $checked = ' checked="checked"';
+ }
+ $hostpicker .= ' ';
+ $count++;
}
- $r->print('');
- } else {
-# -------------------------------------------------------- This is showdoc mode
- $r->print("".&mt('Uploaded Document').'
'.
-&mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."
".
- &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'
');
- }
- }
- $r->print('');
- return OK;
-}
+
+ return <<"ENDSWITCHJS";
+
+function dump_needs_switchserver(url) {
+ if (url!='' && url!= null) {
+ if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
+ go(url);
+ }
+ }
+ return;
+}
+
+function choose_switchserver_window() {
+ newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
+ newWindow.document.open();
+ newWindow.document.writeln('$startpage');
+ newWindow.document.write('$html_js_lt{'duco'}<\\/h3>\\n'+
+ '
$html_js_lt{'yone'}<\\/p>\\n'+
+ '