--- loncom/interface/londocs.pm 2004/12/14 21:10:58 1.156
+++ loncom/interface/londocs.pm 2005/06/08 19:36:54 1.180
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.156 2004/12/14 21:10:58 albertel Exp $
+# $Id: londocs.pm,v 1.180 2005/06/08 19:36:54 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,6 +30,7 @@ package Apache::londocs;
use strict;
use Apache::Constants qw(:common :http);
+use Apache::imsexport;
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonratedt;
@@ -85,17 +86,17 @@ sub authorhosts {
my %outhash=();
my $home=0;
my $other=0;
- foreach (keys %ENV) {
+ foreach (keys %env) {
if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
my $role=$1;
my $realm=$2;
- my ($start,$end)=split(/\./,$ENV{$_});
+ 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'};
+ $ca=$env{'user.name'};
+ $cd=$env{'user.domain'};
} else {
($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
}
@@ -131,35 +132,41 @@ sub dumpbutton {
}
}
+sub clean {
+ my ($title)=@_;
+ $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
+ return $title;
+}
# -------------------------------------------------------- Actually dump course
sub dumpcourse {
my $r=shift;
- $r->print('
Dump DOCS'.
+ my $html=&Apache::lonxml::xmlbegin();
+ $r->print($html.'Dump DOCS'.
&Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
'";
@@ -1226,14 +1455,14 @@ ENDPARMS
sub tiehash {
my ($mode)=@_;
$hashtied=0;
- if ($ENV{'request.course.fn'}) {
+ if ($env{'request.course.fn'}) {
if ($mode eq 'write') {
- if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
+ if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
&GDBM_WRCREAT(),0640)) {
$hashtied=2;
}
} else {
- if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
+ if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
&GDBM_READER(),0640)) {
$hashtied=1;
}
@@ -1263,7 +1492,7 @@ sub checkonthis {
if ($url=~/^\/res\//) {
my $result=&Apache::lonnet::repcopy(
&Apache::lonnet::filelocation('',$url));
- if ($result==OK) {
+ if ($result eq 'ok') {
$r->print(''.&mt('ok').'');
$r->rflush();
&Apache::lonnet::countacc($url);
@@ -1275,23 +1504,20 @@ sub checkonthis {
$r->print(' ');
}
$r->print('- '.&mt('Rendering').': ');
- my $oldpath=$ENV{'request.filename'};
- $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
- &Apache::lonxml::xmlparse($r,'web',
- &Apache::lonnet::getfile(
- &Apache::lonnet::filelocation('',$url)));
- undef($Apache::lonhomework::parsing_a_problem);
- $ENV{'request.filename'}=$oldpath;
- if (($Apache::lonxml::errorcount) ||
- ($Apache::lonxml::warningcount)) {
- if ($Apache::lonxml::errorcount) {
+ my ($errorcount,$warningcount)=split(/:/,
+ &Apache::lonnet::ssi_body($url,
+ ('grade_target'=>'web',
+ 'return_only_error_and_warning_counts' => 1)));
+ if (($errorcount) ||
+ ($warningcount)) {
+ if ($errorcount) {
$r->print(''.
- $Apache::lonxml::errorcount.' '.
+ $errorcount.' '.
&mt('error(s)').' ');
}
- if ($Apache::lonxml::warningcount) {
+ if ($warningcount) {
$r->print(''.
- $Apache::lonxml::warningcount.' '.
+ $warningcount.' '.
&mt('warning(s)').'');
}
} else {
@@ -1306,9 +1532,9 @@ sub checkonthis {
&checkonthis($r,$_,$level+1);
}
}
- } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
+ } elsif ($result eq 'unavailable') {
$r->print(''.&mt('connection down').'');
- } elsif ($result==HTTP_NOT_FOUND) {
+ } elsif ($result eq 'not_found') {
unless ($url=~/\$/) {
$r->print(''.&mt('not found').'');
} else {
@@ -1329,8 +1555,8 @@ sub verifycontent {
my $r=shift;
my $loaderror=&Apache::lonnet::overloaderror($r);
if ($loaderror) { return $loaderror; }
-
- $r->print('Verify Content'.
+ my $html=&Apache::lonxml::xmlbegin();
+ $r->print($html.'Verify Content'.
&Apache::loncommon::bodytag('Verify Course Documents'));
$hashtied=0;
undef %alreadyseen;
@@ -1358,7 +1584,8 @@ sub verifycontent {
sub checkversions {
my $r=shift;
- $r->print('Check Versions'.
+ my $html=&Apache::lonxml::xmlbegin();
+ $r->print($html.'Check Versions'.
&Apache::loncommon::bodytag('Check Course Document Versions'));
my $header='';
my $startsel='';
@@ -1370,20 +1597,20 @@ sub checkversions {
my $starttime=0;
my $haschanged=0;
my %setversions=&Apache::lonnet::dump('resourceversions',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
$hashtied=0;
&tiehash();
my %newsetversions=();
- if ($ENV{'form.setmostrecent'}) {
+ if ($env{'form.setmostrecent'}) {
$haschanged=1;
foreach (keys %hash) {
if ($_=~/^ids\_(\/res\/.+)$/) {
$newsetversions{$1}='mostrecent';
}
}
- } elsif ($ENV{'form.setcurrent'}) {
+ } elsif ($env{'form.setcurrent'}) {
$haschanged=1;
foreach (keys %hash) {
if ($_=~/^ids\_(\/res\/.+)$/) {
@@ -1393,21 +1620,21 @@ sub checkversions {
}
}
}
- } elsif ($ENV{'form.setversions'}) {
+ } elsif ($env{'form.setversions'}) {
$haschanged=1;
- foreach (keys %ENV) {
+ foreach (keys %env) {
if ($_=~/^form\.set_version_(.+)$/) {
my $src=$1;
- if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
- $newsetversions{$src}=$ENV{$_};
+ if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
+ $newsetversions{$src}=$env{$_};
}
}
}
}
if ($haschanged) {
if (&Apache::lonnet::put('resourceversions',\%newsetversions,
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
$r->print('
'.&mt('Your Version Settings have been Stored').'
');
} else {
$r->print('
'.&mt('An Error Occured while Attempting to Store your Version Settings').'
');
@@ -1415,7 +1642,7 @@ sub checkversions {
&mark_hash_old();
}
&changewarning($r,'');
- if ($ENV{'form.timerange'} eq 'all') {
+ if ($env{'form.timerange'} eq 'all') {
# show all documents
$header=&mt('All Documents in Course');
$allsel=1;
@@ -1428,28 +1655,28 @@ sub checkversions {
} else {
# show documents which changed
%changes=&Apache::lonnet::dump
- ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
my $firstkey=(keys %changes)[0];
unless ($firstkey=~/^error\:/) {
- unless ($ENV{'form.timerange'}) {
- $ENV{'form.timerange'}=604800;
+ unless ($env{'form.timerange'}) {
+ $env{'form.timerange'}=604800;
}
- my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
+ my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
.&mt('seconds');
- if ($ENV{'form.timerange'}==-1) {
+ if ($env{'form.timerange'}==-1) {
$seltext='since start of course';
$startsel='selected';
- $ENV{'form.timerange'}=time;
+ $env{'form.timerange'}=time;
}
- $starttime=time-$ENV{'form.timerange'};
- if ($ENV{'form.timerange'}==2592000) {
+ $starttime=time-$env{'form.timerange'};
+ if ($env{'form.timerange'}==2592000) {
$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
$monthsel='selected';
- } elsif ($ENV{'form.timerange'}==604800) {
+ } elsif ($env{'form.timerange'}==604800) {
$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
$weeksel='selected';
- } elsif ($ENV{'form.timerange'}==86400) {
+ } elsif ($env{'form.timerange'}==86400) {
$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
$daysel='selected';
}
@@ -1459,8 +1686,8 @@ sub checkversions {
}
}
%setversions=&Apache::lonnet::dump('resourceversions',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
my %lt=&Apache::lonlocal::texthash
('st' => 'Version changes since start of Course',
'lm' => 'Version changes since last Month',
@@ -1621,25 +1848,29 @@ sub is_hash_old {
}
sub changewarning {
- my ($r,$postexec)=@_;
+ my ($r,$postexec,$message,$url)=@_;
if (!&is_hash_old()) { return; }
my $pathvar='folderpath';
- my $path=&Apache::lonnet::escape($ENV{'form.folderpath'});
- if (defined($ENV{'form.pagepath'})) {
- $pathvar='pagepath';
- $path=&Apache::lonnet::escape($ENV{'form.pagepath'});
- $path.='&symb='.&Apache::lonnet::escape($ENV{'form.pagesymb'});
+ my $path=&Apache::lonnet::escape($env{'form.folderpath'});
+ if (!defined($url)) {
+ if (defined($env{'form.pagepath'})) {
+ $pathvar='pagepath';
+ $path=&Apache::lonnet::escape($env{'form.pagepath'});
+ $path.='&symb='.&Apache::lonnet::escape($env{'form.pagesymb'});
+ }
+ $url='/adm/coursedocs?'.$pathvar.'='.$path;
+ }
+ if (!defined($message)) {
+ $message='Changes will become active for your current session after [_1], or the next time you log in.';
}
$r->print(
''.
'
'.
-'
'.
-&mt('Changes will become active for your current session after').
-' '.&mt(', or the next time you log in.').
+&mt($message,' ').
$help{'Caching'}.'
');
}
@@ -1672,18 +1903,18 @@ sub handler {
'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
$help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
- if ($ENV{'form.verify'}) {
+ if ($env{'form.verify'}) {
&verifycontent($r);
- } elsif ($ENV{'form.versions'}) {
+ } elsif ($env{'form.versions'}) {
&checkversions($r);
- } elsif ($ENV{'form.dumpcourse'}) {
+ } elsif ($env{'form.dumpcourse'}) {
&dumpcourse($r);
- } elsif ($ENV{'form.exportcourse'}) {
+ } elsif ($env{'form.exportcourse'}) {
&exportcourse($r);
} else {
# is this a standard course?
- my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
+ my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
my $forcestandard = 0;
my $forcesupplement;
my $script='';
@@ -1693,33 +1924,33 @@ sub handler {
my $containertag;
my $uploadtag;
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['folderpath','pagepath','pagesymb']);
- if ($ENV{'form.folderpath'}) {
- my (@folderpath)=split('&',$ENV{'form.folderpath'});
- $ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
- $ENV{'form.folder'}=pop(@folderpath);
- }
- if ($ENV{'form.pagepath'}) {
- my (@pagepath)=split('&',$ENV{'form.pagepath'});
- $ENV{'form.pagename'}=&Apache::lonnet::unescape(pop(@pagepath));
- $ENV{'form.folder'}=pop(@pagepath);
+ ['folderpath','pagepath','pagesymb','markedcopy_url','markedcopy_title']);
+ if ($env{'form.folderpath'}) {
+ my (@folderpath)=split('&',$env{'form.folderpath'});
+ $env{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
+ $env{'form.folder'}=pop(@folderpath);
+ }
+ if ($env{'form.pagepath'}) {
+ my (@pagepath)=split('&',$env{'form.pagepath'});
+ $env{'form.pagename'}=&Apache::lonnet::unescape(pop(@pagepath));
+ $env{'form.folder'}=pop(@pagepath);
$containertag = ''.
'';
- $uploadtag = ''.
- '';
+ $uploadtag = ''.
+ '';
}
if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
$showdoc='/'.$1;
}
unless ($showdoc) { # got called from remote
- if (($ENV{'form.folder'}=~/^default_/) ||
- ($ENV{'form.folder'} =~ m#^\d+/(pages|sequences)/#)) {
+ if (($env{'form.folder'}=~/^default_/) ||
+ ($env{'form.folder'} =~ m#^\d+/(pages|sequences)/#)) {
$forcestandard = 1;
}
- $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
+ $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
# does this user have privileges to post, etc?
- $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
+ $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
if ($allowed) {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
$script=&Apache::lonratedt::editscript('simple');
@@ -1732,25 +1963,26 @@ sub handler {
}
# get course data
- my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
- my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
# get personal data
- my $uname=$ENV{'user.name'};
- my $udom=$ENV{'user.domain'};
+ my $uname=$env{'user.name'};
+ my $udom=$env{'user.domain'};
my $plainname=&Apache::lonnet::escape(
&Apache::loncommon::plainname($uname,$udom));
# graphics settings
- $iconpath = $r->dir_config('lonIconsURL') . "/";
+ $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
my $now=time;
# print screen
+ my $html=&Apache::lonxml::xmlbegin();
$r->print(<
+$html
The LearningOnline Network with CAPA
ENDNEWSCRIPT
@@ -1893,7 +2156,9 @@ ENDNEWSCRIPT
my %lt=&Apache::lonlocal::texthash(
'uplm' => 'Upload a new main course document',
'upls' => 'Upload a new supplemental course document',
- 'impp' => 'Import a published document',
+ 'impp' => 'Import a document',
+ 'pubd' => 'Published documents',
+ 'copm' => 'All documents out of a published map',
'spec' => 'Special documents',
'upld' => 'Upload Document',
'srch' => 'Search',
@@ -1925,15 +2190,15 @@ ENDNEWSCRIPT
'cv' => 'Check/Set Resource Versions',
);
- my $folderpath=$ENV{'form.folderpath'};
+ my $folderpath=$env{'form.folderpath'};
if (!$folderpath) {
- if ($ENV{'form.folder'} eq '' ||
- $ENV{'form.folder'} eq 'supplemental') {
+ if ($env{'form.folder'} eq '' ||
+ $env{'form.folder'} eq 'supplemental') {
$folderpath='default&'.
&Apache::lonnet::escape(&mt('Main Course Documents'));
}
}
- unless ($ENV{'form.pagepath'}) {
+ unless ($env{'form.pagepath'}) {
$containertag = '';
$uploadtag = '';
}
@@ -1942,6 +2207,7 @@ ENDNEWSCRIPT