--- loncom/interface/londocs.pm 2008/11/18 19:14:22 1.316
+++ loncom/interface/londocs.pm 2010/12/11 14:28:12 1.447
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.316 2008/11/18 19:14:22 jms Exp $
+# $Id: londocs.pm,v 1.447 2010/12/11 14:28:12 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,20 +27,6 @@
#
-=head1 NAME
-
-Apache::londocs.pm
-
-=head1 SYNOPSIS
-
-This is part of the LearningOnline Network with CAPA project
-described at http://www.lon-capa.org.
-
-=head1 SUBROUTINES
-
-=over
-
-=cut
package Apache::londocs;
@@ -49,6 +35,7 @@ use Apache::Constants qw(:common :http);
use Apache::imsexport;
use Apache::lonnet;
use Apache::loncommon;
+use Apache::lonhtmlcommon;
use LONCAPA::map();
use Apache::lonratedt();
use Apache::lonxml;
@@ -70,26 +57,8 @@ my %alreadyseen=();
my $hadchanges;
-=pod
-
-=item %help=()
-
- Available help topics
-
-=cut
-
my %help=();
-=pod
-
-=item mapread()
-
-Mapread read maps into LONCAPA::map:: global arrays
-@order and @resources, determines status
-sets @order - pointer to resources in right order
-sets @resources - array with the resources with correct idx
-
-=cut
sub mapread {
my ($coursenum,$coursedom,$map)=@_;
@@ -104,32 +73,25 @@ sub storemap {
&LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
$map,1);
if ($errtext) { return ($errtext,2); }
-
+
$hadchanges=1;
return ($errtext,0);
}
-=pod
-
-=item authorhosts()
-
- Return hash with valid author names
-
-=cut
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'};
@@ -151,52 +113,43 @@ sub authorhosts {
}
return ($home,$other,%outhash);
}
-=pod
-
-=item dumpbutton()
- Generate "dump" button
-
-=cut
sub dumpbutton {
my ($home,$other,%outhash)=&authorhosts();
- my $type = &Apache::loncommon::course_type();
+ my $crstype = &Apache::loncommon::course_type();
if ($home+$other==0) { return ''; }
if ($home) {
- return '
'.
- ' '.
- &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').
- '
';
- } else {
- return ''.
- &mt('Dump '.$type.
- ' DOCS to Construction Space: available on other servers').
- '
';
+ my $link =
+ "';
+ return
+ $link.' '
+ .&Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs')
+ .' ';
+ } else {
+ return
+ &mt('Dump '.$crstype.' Documents to Construction Space: available on other servers');
}
}
sub clean {
my ($title)=@_;
$title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
- return $title;
+ return $title;
}
-=pod
-
-=item dumpcourse()
- Actually dump course
-
-=cut
sub dumpcourse {
my ($r) = @_;
- my $type = &Apache::loncommon::course_type();
- $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').
- '');
+ '
');
}
}
-=pod
-
-=item exportbutton()
- Generate "export" button
-
-=cut
sub exportbutton {
- my $type = &Apache::loncommon::course_type();
- return ''.
- ' '.
- &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'
';
+ my $crstype = &Apache::loncommon::course_type();
+ return "".
+ &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').' ';
}
-=pod
-
-=item exportcourse()
-=cut
sub exportcourse {
my $r=shift;
- my $type = &Apache::loncommon::course_type();
+ my $crstype = &Apache::loncommon::course_type();
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 $numdisc = keys(%discussiontime);
my $navmap = Apache::lonnavmaps::navmap->new();
+ if (!defined($navmap)) {
+ $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package').
+ ''.&mt('IMS Export Failed').' '.
+ '');
+ if ($crstype eq 'Community') {
+ $r->print(&mt('Unable to retrieve information about community contents'));
+ } else {
+ $r->print(&mt('Unable to retrieve information about course contents'));
+ }
+ $r->print('
');
+ if ($crstype eq 'Community') {
+ $r->print(&mt('Return to Community Editor'));
+ } else {
+ $r->print(&mt('Return to Course Editor'));
+ }
+ $r->print(' ');
+ &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
+ return;
+ }
my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
my $curRes;
my $outcome;
@@ -353,7 +313,17 @@ sub exportcourse {
my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
if (@exportitems == 0 && @discussions == 0) {
- $outcome = ' As you did not select any content items or discussions for export, an IMS package has not been created. Please go back to select either content items or discussions for export';
+ $outcome =
+ ''
+ .&mt('As you did not select any content items or discussions'
+ .' for export, an IMS package has not been created.')
+ .'
'
+ .''
+ .&mt('Please [_1]go back[_2] to select either content items'
+ .' or discussions for export.'
+ ,''
+ ,' ')
+ .'
';
} else {
my $now = time;
my %symbs;
@@ -376,35 +346,53 @@ sub exportcourse {
open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
close(OUTPUT);
chdir $cwd;
- $outcome .= &mt('Download the zip file from IMS '.lc($type).' archive ',$imszipfile,);
+ $outcome .= ''
+ .&mt('[_1]Your IMS package[_2] is ready for download.'
+ ,'',' ')
+ .'
';
if ($copyresult) {
- $outcome .= &mt('The following errors occurred during export - [_1]',$copyresult);
+ $outcome .= ''
+ .&mt('The following errors occurred during export - [_1]'
+ ,$copyresult)
+ .'
';
}
} else {
- $outcome = ' '.&mt('Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.').' ';
+ $outcome = ''
+ .&mt('Unfortunately you will not be able to retrieve'
+ .' an IMS archive of your course at this time,'
+ .' because there was a problem creating a'
+ .' manifest file.')
+ .'
'
+ .''
+ .&mt('Go Back')
+ .'
';
}
}
- $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package'));
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));
+ $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));
$r->print($outcome);
$r->print(&Apache::loncommon::end_page());
} else {
- my $display;
- $display = ''.
- &Apache::loncommon::end_page());
+ &mt('Export').'" />');
}
}
@@ -617,7 +607,7 @@ sub build_package {
if ($curRes->is_sequence() || $curRes->is_page()) {
$lastcontainer = $count;
}
- if (grep/^$count$/,@$exportitems) {
+ if (grep(/^$count$/,@$exportitems)) {
&get_dependencies($exportitems,\%parent,$depth,\@dependencies);
}
}
@@ -641,7 +631,7 @@ sub build_package {
if (ref($curRes)) {
$count ++;
- if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
+ if ((grep(/^$count$/,@$exportitems)) || (grep(/^$count$/,@dependencies))) {
my $symb = $curRes->symb();
my $isvisible = 'true';
my $resourceref;
@@ -675,11 +665,11 @@ sub build_package {
' '."\n".
' '."\n";
- foreach (@hrefs) {
+ foreach my $item (@hrefs) {
$imsresources .=
- ' '."\n";
+ ' '."\n";
}
- if (grep/^$count$/,@$discussions) {
+ if (grep(/^$count$/,@$discussions)) {
my $ressymb = $symb;
my $mode;
if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
@@ -720,8 +710,8 @@ sub build_package {
sub get_dependencies {
my ($exportitems,$parent,$depth,$dependencies) = @_;
if ($depth > 1) {
- if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
- push @$dependencies, $$parent{$depth};
+ if ((!grep(/^$$parent{$depth}$/,@$exportitems)) && (!grep(/^$$parent{$depth}$/,@$dependencies))) {
+ push(@{$dependencies},$$parent{$depth});
if ($depth > 2) {
&get_dependencies($exportitems,$parent,$depth-1,$dependencies);
}
@@ -815,7 +805,7 @@ sub replicate_content {
if ($caller eq 'templateupload') {
$url = $symb;
$url =~ s#//#/#g;
- } else {
+ } else {
($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
}
my $content;
@@ -855,9 +845,9 @@ sub replicate_content {
$$message = 'Could not render '.$url.' server message - '.$rtncode." \n";
}
} elsif ($caller eq 'noedit') {
-# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
+# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
$repstatus = 'ok';
- $content = 'Not the owner of this resource';
+ $content = 'Not the owner of this resource';
}
if ($repstatus eq 'ok') {
print $copiedfile $content;
@@ -908,14 +898,14 @@ sub extract_media {
}
}
if ($caller eq 'resource') {
- my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
- my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
+ my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
+ my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
$embed_content = &Apache::lonnet::getfile($embed_path);
unless ($embed_content eq -1) {
$repstatus = 'ok';
}
} elsif ($caller eq 'uploaded') {
-
+
$repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
}
if ($repstatus eq 'ok') {
@@ -927,7 +917,7 @@ sub extract_media {
my $copiedfile;
if ($copiedfile = Apache::File->new('>'.$destination)) {
print $copiedfile $embed_content;
- push @{$href}, 'resources/'.$count.'/res/'.$filename;
+ push(@{$href},'resources/'.$count.'/res/'.$filename);
my $attrib_regexp = '';
if (@{$allfiles{$embed_file}} > 1) {
$attrib_regexp = join('|',@{$allfiles{$embed_file}});
@@ -971,24 +961,16 @@ sub store_template {
}
}
-=pod
-
-=item group_import()
-
- Imports the given (name, url) resources into the course
- coursenum, coursedom, and folder must precede the list
-
-=cut
sub group_import {
my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
while (@files) {
my ($name, $url, $residx) = @{ shift(@files) };
- if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
+ if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
&& ($caller eq 'londocs')
&& (!&Apache::lonnet::stat_file($url))) {
-
+
my $errtext = '';
my $fatal = 0;
my $newmapstr = ''."\n".
@@ -1008,7 +990,7 @@ sub group_import {
}
}
if ($url) {
- if (!$residx
+ if (!$residx
|| defined($LONCAPA::map::zombies[$residx])) {
$residx = &LONCAPA::map::getresidx($url,$residx);
push(@LONCAPA::map::order, $residx);
@@ -1017,7 +999,7 @@ sub group_import {
if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
$url = &LONCAPA::map::qtunescape($url);
$name = &LONCAPA::map::qtunescape($name);
- $LONCAPA::map::resources[$residx] =
+ $LONCAPA::map::resources[$residx] =
join(':', ($name, $url, $ext, 'normal', 'res'));
}
}
@@ -1025,7 +1007,7 @@ sub group_import {
}
sub breadcrumbs {
- my ($where,$allowed,$type)=@_;
+ my ($allowed,$crstype)=@_;
&Apache::lonhtmlcommon::clear_breadcrumbs();
my (@folders);
if ($env{'form.pagepath'}) {
@@ -1040,6 +1022,15 @@ sub breadcrumbs {
my $isencrypted=0;
my $ishidden=0;
my $is_random_order=0;
+ if (!$allowed) {
+ my $description = $env{'course.'.$env{'request.course.id'}.'.description'};
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ {'href' => '/adm/menu',
+ 'title'=> 'Go to main menu',
+ 'text' => $description,
+ });
+ $plain .= $description.' >';
+ }
while (@folders) {
my $folder=shift(@folders);
my $foldername=shift(@folders);
@@ -1048,9 +1039,9 @@ sub breadcrumbs {
my $url='/adm/coursedocs?folderpath='.
&escape($folderpath);
my $name=&unescape($foldername);
-# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
+# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
$name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
- if ($1 ne '') {
+ if ($1 ne '') {
$randompick=$1;
} else {
$randompick=-1;
@@ -1059,24 +1050,19 @@ sub breadcrumbs {
if ($3) { $isencrypted=1; }
if ($4 ne '') { $is_random_order = 1; }
if ($folder eq 'supplemental') {
- if ($allowed) {
- $name = &mt('Supplemental '.$type.' Documents');
- } else {
- $name = &mt($type.' Documents');
- }
+ $name = &mt('Supplemental '.$crstype.' Documents');
}
&Apache::lonhtmlcommon::add_breadcrumb(
{'href'=>$url.$cpinfo,
'title'=>$name,
- 'text'=>''.
- $name.' ',
+ 'text'=>$name,
'no_mt'=>1,
});
$plain.=$name.' > ';
}
$plain=~s/\>\;\s*$//;
return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
- 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
+ undef, undef, 1 ),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
}
sub log_docs {
@@ -1114,7 +1100,7 @@ sub log_docs {
'currentfolder' => $env{'form.folder'});
if ($parmidx) {
$storehash{'parameter_res'}=$oldresources[$parmidx];
- foreach my $parm (keys %parmaction) {
+ foreach my $parm (keys(%parmaction)) {
$storehash{'parameter_action_'.$parm}=$parmaction{$parm};
$storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
}
@@ -1140,11 +1126,9 @@ sub log_docs {
}
}
-=pod
-=item docs_change_log()
-=cut
+
sub docs_change_log {
my ($r)=@_;
@@ -1191,7 +1175,7 @@ sub docs_change_log {
foreach my $key (@changes) {
$wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
}
- if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
+ if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
}
my $count = 0;
my $time =
@@ -1242,7 +1226,7 @@ sub docs_change_log {
if ($oldname ne '' && $oldname ne $newname) {
$r->print(&LONCAPA::map::qtescape($newname));
}
- }
+ }
$r->print('