--- loncom/interface/londocs.pm 2012/11/08 20:51:40 1.503
+++ loncom/interface/londocs.pm 2013/01/09 17:22:51 1.530
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.503 2012/11/08 20:51:40 raeburn Exp $
+# $Id: londocs.pm,v 1.530 2013/01/09 17:22:51 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,7 +40,7 @@ use Apache::lonxml;
use Apache::lonclonecourse;
use Apache::lonnavmaps;
use Apache::lonnavdisplay();
-use Apache::lonuserstate();
+use Apache::lonextresedit();
use HTML::Entities;
use HTML::TokeParser;
use GDBM_File;
@@ -270,7 +270,9 @@ sub dumpcourse {
sub group_import {
my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
-
+ my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
+ %removeparam,$importuploaded,$fixuperrors);
+ $allmaps = {};
while (@files) {
my ($name, $url, $residx) = @{ shift(@files) };
if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
@@ -296,6 +298,24 @@ sub group_import {
}
}
if ($url) {
+ if (($caller eq 'londocs') &&
+ ($folder =~ /^default/)) {
+ unless ($donechk) {
+ my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
+ my $cid = $coursedom.'_'.$coursenum;
+ $allmaps =
+ &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
+ $chome,$cid);
+ $donechk = 1;
+ }
+ if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
+ &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
+ \%addedmaps,\%hierarchy,\%titles,$allmaps);
+ $importuploaded = 1;
+ } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
+ next if ($allmaps->{$url});
+ }
+ }
if (!$residx
|| defined($LONCAPA::map::zombies[$residx])) {
$residx = &LONCAPA::map::getresidx($url,$residx);
@@ -309,62 +329,27 @@ sub group_import {
join(':', ($name, $url, $ext, 'normal', 'res'));
}
}
- return &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
-}
-
-sub breadcrumbs {
- my ($allowed,$crstype)=@_;
- &Apache::lonhtmlcommon::clear_breadcrumbs();
- my (@folders);
- if ($env{'form.pagepath'}) {
- @folders = split('&',$env{'form.pagepath'});
- } else {
- @folders=split('&',$env{'form.folderpath'});
- }
- my $folderpath;
- my $plain='';
- my $randompick=-1;
- my $isencrypted=0;
- my $ishidden=0;
- my $is_random_order=0;
- while (@folders) {
- my $folder=shift(@folders);
- my $foldername=shift(@folders);
- if ($folderpath) {$folderpath.='&';}
- $folderpath.=$folder.'&'.$foldername;
- my $url;
- if ($allowed) {
- $url = '/adm/coursedocs?folderpath=';
- } else {
- $url = '/adm/supplemental?folderpath=';
- }
- $url .= &escape($folderpath);
- my $name=&unescape($foldername);
-# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
- $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
- if ($1 ne '') {
- $randompick=$1;
- } else {
- $randompick=-1;
- }
- if ($2) { $ishidden=1; }
- if ($3) { $isencrypted=1; }
- if ($4 ne '') { $is_random_order = 1; }
- if ($folder eq 'supplemental') {
- $name = &mt('Supplemental '.$crstype.' Content');
- }
- &Apache::lonhtmlcommon::add_breadcrumb(
- {'href'=>$url,
- 'title'=>$name,
- 'text'=>$name,
- 'no_mt'=>1,
- });
- $plain.=$name.' > ';
- }
- $plain=~s/\>\;\s*$//;
- return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
- undef, undef, 1 ),$randompick,$ishidden,
- $isencrypted,$plain,$is_random_order);
+ if ($importuploaded) {
+ my %import_errors;
+ my %updated = (
+ removefrommap => \%removefrommap,
+ removeparam => \%removeparam,
+ );
+ &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
+ if (keys(%import_errors) > 0) {
+ $fixuperrors =
+ '
'."\n".
+ &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
+ '
'."\n";
+ foreach my $key (sort(keys(%import_errors))) {
+ $fixuperrors .= ''.$key.' '."\n";
+ }
+ $fixuperrors .= ' '."\n";
+ }
+ }
+ my ($errtext,$fatal) =
+ &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
+ return ($errtext,$fatal,$fixuperrors);
}
sub log_docs {
@@ -445,17 +430,15 @@ sub docs_change_log {
my %orderhash;
my $container='sequence';
my $pathitem;
- if ($env{'form.pagepath'}) {
+ if ($env{'form.folderpath'} =~ /\:1$/) {
$container='page';
- $pathitem = ' ';
- } else {
- my $folderpath=$env{'form.folderpath'};
- if ($folderpath eq '') {
- $folderpath = 'default&'.&escape(&mt('Main '.$crstype.' Documents'));
- }
- $pathitem = ' ';
}
+ my $folderpath=$env{'form.folderpath'};
+ if ($folderpath eq '') {
+ $folderpath = 'default&'.&escape(&mt('Main '.$crstype.' Documents').':::::');
+ }
+ $pathitem = ' ';
my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
my $jumpto = $readfile;
$jumpto =~ s{^/}{};
@@ -463,7 +446,8 @@ sub docs_change_log {
if ($supplementalflag) {
$tid = 2;
}
- my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype);
+ my ($breadcrumbtrail) =
+ &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
$r->print($breadcrumbtrail.
&generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
$readfile));
@@ -706,7 +690,7 @@ sub print_paste_buffer {
$is_external = 1;
}
- my ($canpaste,$nopaste,$othercrs,$areachange,$is_uploaded_map);
+ my ($canpaste,$nopaste,$othercrs,$areachange);
if ($folder =~ /^supplemental/) {
$canpaste = &supp_pasteable($env{'docs.markedcopy_url'});
unless ($canpaste) {
@@ -813,16 +797,9 @@ sub print_paste_buffer {
}
}
$r->print(' '.$othercrs);
- if ($container eq 'page') {
- $r->print('
-
-
-');
- } else {
- $r->print('
+ $r->print('
');
- }
$r->print('');
} else {
$r->print(&mt('Paste buffer contains:').' '.$buffer.
@@ -957,30 +934,23 @@ sub do_paste_from_buffer {
%dbcopies,%zombies,%params,%docmoves,%mapmoves,%newsubdir,%newurls);
$oldurl = $url;
if ($is_map) {
- if ($folder =~ /^default/) {
- my $lastchange = &Apache::lonnet::get_coursechange($coursedom,$coursenum);
- if ($lastchange > $env{'request.course.tied'}) {
- &reinit_role($coursedom,$coursenum,$env{"course.$env{'request.course.id'}.home"});
- }
- }
# If pasting a map, check if map contains other maps
- my (%allmaps,%hierarchy,%titles);
+ my ($allmaps,%hierarchy,%titles);
+ $allmaps = {};
if ($folder =~ /^default/) {
- my $navmap = Apache::lonnavmaps::navmap->new();
- if (defined($navmap)) {
- foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
- $allmaps{$res->src()} = 1;
- }
- }
+ $allmaps =
+ &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
+ $env{"course.$env{'request.course.id'}.home"},
+ $env{'request.course.id'});
}
&contained_map_check($url,$folder,\%removefrommap,\%removeparam,
- \%addedmaps,\%hierarchy,\%titles,\%allmaps);
+ \%addedmaps,\%hierarchy,\%titles,$allmaps);
if ($url=~ m{^/uploaded/}) {
my $newurl;
unless ($env{'form.docs.markedcopy_options'} eq 'move') {
($newurl,my $error) =
&get_newmap_url($url,$folder,$prefixchg,$coursedom,$coursenum,
- $srcdom,$srcnum,\$title,\%allmaps,\%newurls);
+ $srcdom,$srcnum,\$title,$allmaps,\%newurls);
if ($error) {
return ($error);
}
@@ -996,14 +966,14 @@ sub do_paste_from_buffer {
if (($srcdom ne $coursedom) || ($srcnum ne $coursenum) || ($prefixchg) ||
(($newurl ne '') && ($newurl ne $url))) {
unless (&url_paste_fixups($url,$folder,$prefixchg,$coursedom,$coursenum,
- \%allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
+ $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
\%zombies,\%params,\%mapmoves,\%mapchanges,\%tomove,
\%newsubdir,\%newurls)) {
$mapmoves{$url} = 1;
}
$url = $newurl;
} elsif ($env{'docs.markedcopy_nested'}) {
- &url_paste_fixups($url,$folder,$prefixchg,$coursedom,$coursenum,\%allmaps,\%rewrites,
+ &url_paste_fixups($url,$folder,$prefixchg,$coursedom,$coursenum,$allmaps,\%rewrites,
\%retitles,\%copies,\%dbcopies,\%zombies,\%params,\%mapmoves,
\%mapchanges,\%tomove,\%newsubdir,\%newurls);
}
@@ -1012,7 +982,7 @@ sub do_paste_from_buffer {
&Apache::lonnet::delenv('docs.markedcopy');
# if pasting published map (main content are only) check map is not already in course
if ($folder =~ /^default/) {
- if ($allmaps{$url}) {
+ if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
return (&mt('Paste failed: only one instance of a particular published sequence or page is allowed within each course.'));
}
}
@@ -1078,11 +1048,28 @@ sub do_paste_from_buffer {
}
# Apply any changes to maps, or copy dependencies for uploaded HTML pages
my ($result,$save_err);
+ my %updated = (
+ rewrites => \%rewrites,
+ zombies => \%zombies,
+ removefrommap => \%removefrommap,
+ removeparam => \%removeparam,
+ dbcopies => \%dbcopies,
+ retitles => \%retitles,
+ );
+ my %info = (
+ newsubdir => \%newsubdir,
+ params => \%params,
+ before => \%before,
+ after => \%after,
+ );
+ my %moves = (
+ copies => \%copies,
+ docmoves => \%docmoves,
+ mapmoves => \%mapmoves,
+ );
$result =
- &apply_fixups($folder,$is_map,$prefixchg,$coursedom,$coursenum,$oldurl,
- $url,\%removefrommap,\%removeparam,\%rewrites,\%retitles,
- \%copies,\%dbcopies,\%zombies,\%params,\%docmoves,
- \%mapmoves,\%newsubdir,$errors,\%before,\%after);
+ &apply_fixups($folder,$is_map,$coursedom,$coursenum,$errors,
+ \%updated,\%info,\%moves,$prefixchg,$oldurl,$url,'paste');
if ($result eq 'ok') {
if ($is_map) {
my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
@@ -1242,7 +1229,7 @@ sub contained_map_check {
$titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
} else {
if ($allmaps->{$ressrc}) {
- $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
+ $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
} elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
$removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
} else {
@@ -1266,15 +1253,6 @@ sub contained_map_check {
return;
}
-sub reinit_role {
- my ($cdom,$cnum,$chome) = @_;
- my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
- unless ($ferr) {
- &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
- }
- return;
-}
-
sub url_paste_fixups {
my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$allmaps,$rewrites,$retitles,$copies,
$dbcopies,$zombies,$params,$mapmoves,$mapchanges,$tomove,$newsubdir,$newurls) = @_;
@@ -1393,23 +1371,71 @@ sub url_paste_fixups {
}
sub apply_fixups {
- my ($folder,$is_map,$prefixchg,$cdom,$cnum,$oldurl,$url,$removefrommap,
- $removeparam,$rewrites,$retitles,$copies,$dbcopies,$zombies,$params,
- $docmoves,$mapmoves,$newsubdir,$errors,$before,$after) = @_;
- foreach my $key (keys(%{$copies}),keys(%{$docmoves})) {
+ my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
+ $oldurl,$url,$caller) = @_;
+ my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
+ %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves);
+ if (ref($updated) eq 'HASH') {
+ if (ref($updated->{'rewrites'}) eq 'HASH') {
+ %rewrites = %{$updated->{'rewrites'}};
+ }
+ if (ref($updated->{'zombies'}) eq 'HASH') {
+ %zombies = %{$updated->{'zombies'}};
+ }
+ if (ref($updated->{'removefrommap'}) eq 'HASH') {
+ %removefrommap = %{$updated->{'removefrommap'}};
+ }
+ if (ref($updated->{'removeparam'}) eq 'HASH') {
+ %removeparam = %{$updated->{'removeparam'}};
+ }
+ if (ref($updated->{'dbcopies'}) eq 'HASH') {
+ %dbcopies = %{$updated->{'dbcopies'}};
+ }
+ if (ref($updated->{'retitles'}) eq 'HASH') {
+ %retitles = %{$updated->{'retitles'}};
+ }
+ }
+ if (ref($info) eq 'HASH') {
+ if (ref($info->{'newsubdir'}) eq 'HASH') {
+ %newsubdir = %{$info->{'newsubdir'}};
+ }
+ if (ref($info->{'params'}) eq 'HASH') {
+ %params = %{$info->{'params'}};
+ }
+ if (ref($info->{'before'}) eq 'HASH') {
+ %before = %{$info->{'before'}};
+ }
+ if (ref($info->{'after'}) eq 'HASH') {
+ %after = %{$info->{'after'}};
+ }
+ }
+ if (ref($moves) eq 'HASH') {
+ if (ref($moves->{'copies'}) eq 'HASH') {
+ %copies = %{$moves->{'copies'}};
+ }
+ if (ref($moves->{'docmoves'}) eq 'HASH') {
+ %docmoves = %{$moves->{'docmoves'}};
+ }
+ if (ref($moves->{'mapmoves'}) eq 'HASH') {
+ %mapmoves = %{$moves->{'mapmoves'}};
+ }
+ }
+ foreach my $key (keys(%copies),keys(%docmoves)) {
my @allcopies;
- if (ref($copies->{$key}) eq 'HASH') {
- my %added;
- foreach my $innerkey (keys(%{$copies->{$key}})) {
- if (($innerkey ne '') && (!$added{$innerkey})) {
- push(@allcopies,$innerkey);
- $added{$innerkey} = 1;
+ if (exists($copies{$key})) {
+ if (ref($copies{$key}) eq 'HASH') {
+ my %added;
+ foreach my $innerkey (keys(%{$copies{$key}})) {
+ if (($innerkey ne '') && (!$added{$innerkey})) {
+ push(@allcopies,$innerkey);
+ $added{$innerkey} = 1;
+ }
}
+ undef(%added);
}
- undef(%added);
}
if ($key eq $oldurl) {
- if ((exists($docmoves->{$key}))) {
+ if ((exists($docmoves{$key}))) {
unless (grep(/^\Q$oldurl\E/,@allcopies)) {
push(@allcopies,$oldurl);
}
@@ -1423,16 +1449,16 @@ sub apply_fixups {
my $content = &Apache::lonnet::getfile($item);
unless ($content eq '-1') {
my $storefn;
- if (($key eq $oldurl) && (ref($docmoves) eq 'HASH') && (exists($docmoves->{$key}))) {
- $storefn = $docmoves->{$key};
+ if (($key eq $oldurl) && (exists($docmoves{$key}))) {
+ $storefn = $docmoves{$key};
} else {
$storefn = $relpath;
$storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
- if ($prefixchg) {
- $storefn =~ s/^\Q$before->{'doc'}\E/$after->{'doc'}/;
+ if ($prefixchg && $before{'doc'} && $after{'doc'}) {
+ $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
}
- if ($newsubdir->{$key}) {
- $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir->{$key}#;
+ if ($newsubdir{$key}) {
+ $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}#;
}
}
©_dependencies($item,$storefn,$relpath,$errors,\$content);
@@ -1440,7 +1466,7 @@ sub apply_fixups {
&Apache::lonclonecourse::writefile($env{'request.course.id'},
$storefn.$fname,$content);
if ($copyurl eq '/adm/notfound.html') {
- if ((ref($docmoves) eq 'HASH') && (exists($docmoves->{$oldurl}))) {
+ if (exists($docmoves{$oldurl})) {
return &mt('Paste failed: an error occurred copying the file.');
} elsif (ref($errors) eq 'HASH') {
$errors->{$item} = 1;
@@ -1451,14 +1477,14 @@ sub apply_fixups {
}
}
}
- foreach my $key (keys(%{$mapmoves})) {
+ foreach my $key (keys(%mapmoves)) {
my $storefn=$key;
$storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
- if ($prefixchg) {
- $storefn =~ s/^\Q$before->{'map'}\E/$after->{'map'}/;
+ if ($prefixchg && $before{'map'} && $after{'map'}) {
+ $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
}
- if ($newsubdir->{$key}) {
- $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir->{$key}/;
+ if ($newsubdir{$key}) {
+ $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
}
my $mapcontent = &Apache::lonnet::getfile($key);
if ($mapcontent eq '-1') {
@@ -1478,48 +1504,39 @@ sub apply_fixups {
}
my %updates;
if ($is_map) {
- foreach my $key (keys(%{$rewrites})) {
- $updates{$key} = 1;
- }
- foreach my $key (keys(%{$zombies})) {
- $updates{$key} = 1;
- }
- foreach my $key (keys(%{$removefrommap})) {
- $updates{$key} = 1;
- }
- foreach my $key (keys(%{$removeparam})) {
- $updates{$key} = 1;
- }
- foreach my $key (keys(%{$dbcopies})) {
- $updates{$key} = 1;
- }
- foreach my $key (keys(%{$retitles})) {
- $updates{$key} = 1;
+ if (ref($updated) eq 'HASH') {
+ foreach my $type (keys(%{$updated})) {
+ if (ref($updated->{$type}) eq 'HASH') {
+ foreach my $key (keys(%{$updated->{$type}})) {
+ $updates{$key} = 1;
+ }
+ }
+ }
}
foreach my $key (keys(%updates)) {
my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
- if (ref($rewrites->{$key}) eq 'HASH') {
- %torewrite = %{$rewrites->{$key}};
+ if (ref($rewrites{$key}) eq 'HASH') {
+ %torewrite = %{$rewrites{$key}};
}
- if (ref($retitles->{$key}) eq 'HASH') {
- %toretitle = %{$retitles->{$key}};
+ if (ref($retitles{$key}) eq 'HASH') {
+ %toretitle = %{$retitles{$key}};
}
- if (ref($removefrommap->{$key}) eq 'HASH') {
- %toremove = %{$removefrommap->{$key}};
+ if (ref($removefrommap{$key}) eq 'HASH') {
+ %toremove = %{$removefrommap{$key}};
}
- if (ref($removeparam->{$key}) eq 'HASH') {
- %remparam = %{$removeparam->{$key}};
+ if (ref($removeparam{$key}) eq 'HASH') {
+ %remparam = %{$removeparam{$key}};
}
- if (ref($zombies->{$key}) eq 'HASH') {
- %zombie = %{$zombies->{$key}};
+ if (ref($zombies{$key}) eq 'HASH') {
+ %zombie = %{$zombies{$key}};
}
- if (ref($dbcopies->{$key}) eq 'HASH') {
- foreach my $item (keys(%{$dbcopies->{$key}})) {
+ if (ref($dbcopies{$key}) eq 'HASH') {
+ foreach my $item (keys(%{$dbcopies{$key}})) {
$newdb{$item} = &dbcopy($item);
}
}
- if (ref($params->{$key}) eq 'HASH') {
- %currparam = %{$params->{$key}};
+ if (ref($params{$key}) eq 'HASH') {
+ %currparam = %{$params{$key}};
}
my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
if ($fatal) {
@@ -1533,40 +1550,41 @@ sub apply_fixups {
}
}
}
- for (my $i=0; $i<@LONCAPA::map::resources; $i++) {
- if (defined($LONCAPA::map::resources[$i])) {
+ for (my $i=0; $i<@LONCAPA::map::order; $i++) {
+ my $idx = $LONCAPA::map::order[$i];
+ if (defined($LONCAPA::map::resources[$idx])) {
my $changed;
- my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$i]);
- if ($toremove{$src} eq $i) {
+ my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
+ if ((exists($toremove{$idx})) && ($toremove{$idx} eq $src)) {
splice(@LONCAPA::map::order,$i,1);
- if (ref($currparam{$i}) eq 'ARRAY') {
- foreach my $name (@{$currparam{$i}}) {
- &LONCAPA::map::delparameter($i,'parameter_'.$name);
+ if (ref($currparam{$idx}) eq 'ARRAY') {
+ foreach my $name (@{$currparam{$idx}}) {
+ &LONCAPA::map::delparameter($idx,'parameter_'.$name);
}
}
next;
}
my $origsrc = $src;
- if ((exists($toretitle{$src})) && ($toretitle{$src} eq $i)) {
+ if ((exists($toretitle{$src})) && ($toretitle{$src} eq $idx)) {
if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
$changed = 1;
}
}
- if ((exists($torewrite{$src})) && ($torewrite{$src} eq $i)) {
+ if ((exists($torewrite{$src})) && ($torewrite{$src} eq $idx)) {
$src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
if ($origsrc =~ m{^/uploaded/}) {
- if ($prefixchg) {
+ if ($prefixchg && $before{'map'} && $after{'map'}) {
if ($src =~ /\.(page|sequence)$/) {
- $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before->{'map'}\E#$1$after->{'map'}#;
+ $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
} else {
- $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before->{'doc'}\E#$1$after->{'doc'}#;
+ $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
}
}
- if ($newsubdir->{$origsrc}) {
+ if ($newsubdir{$origsrc}) {
if ($src =~ /\.(page|sequence)$/) {
- $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir->{$origsrc}#;
+ $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
} else {
- $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir->{$origsrc}#;
+ $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$origsrc}#;
}
}
}
@@ -1576,7 +1594,7 @@ sub apply_fixups {
$changed = 1;
}
if ($changed) {
- $LONCAPA::map::resources[$i] = join(':',($title,$src,$ext,$type));
+ $LONCAPA::map::resources[$idx] = join(':',($title,$src,$ext,$type));
}
}
}
@@ -1594,21 +1612,23 @@ sub apply_fixups {
} else {
$storefn = $key;
$storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
- if ($prefixchg) {
- $storefn =~ s/^\Q$before->{'map'}\E/$after->{'map'}/;
+ if ($prefixchg && $before{'map'} && $after{'map'}) {
+ $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
}
- if ($newsubdir->{$key}) {
- $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir->{$key}/;
+ if ($newsubdir{$key}) {
+ $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
}
}
my $report;
if ($folder !~ /^supplemental/) {
$report = 1;
}
- my ($outtext,$errtext) =
+ (my $outtext,$errtext) =
&LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
if ($errtext) {
- return &mt('Paste failed: an error occurred saving the folder or page.');
+ if ($caller eq 'paste') {
+ return &mt('Paste failed: an error occurred saving the folder or page.');
+ }
}
}
}
@@ -1743,15 +1763,24 @@ sub handle_edit_cmd {
sub editor {
my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
- $supplementalflag,$orderhash,$iconpath,$uploadtag)=@_;
- my $container= ($env{'form.pagepath'}) ? 'page'
- : 'sequence';
-
- my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
- &breadcrumbs($allowed,$crstype);
- $r->print($breadcrumbtrail);
+ $supplementalflag,$orderhash,$iconpath,$pathitem)=@_;
+ my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
+ if ($allowed) {
+ (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
+ $is_random_order,$container) =
+ &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
+ $r->print($breadcrumbtrail);
+ } elsif ($env{'form.folderpath'} =~ /\:1$/) {
+ $container = 'page';
+ } else {
+ $container = 'sequence';
+ }
- my $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
+ my $jumpto;
+
+ unless ($supplementalflag) {
+ $jumpto = "'uploaded/$coursedom/$coursenum/$folder.$container'";
+ }
unless ($allowed) {
$randompick = -1;
@@ -1828,12 +1857,28 @@ sub editor {
if (defined($item)) {
my ($name,$url,$residx)=
map {&unescape($_)} split(/\=/,$item);
+ if ($url=~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
+ my ($suffix,$errortxt,$locknotfreed) =
+ &newmap_suffix($1,$2,$coursedom,$coursenum);
+ if ($locknotfreed) {
+ $r->print($locknotfreed);
+ }
+ if ($suffix) {
+ $url =~ s/_new\./_$suffix./;
+ } else {
+ return $errortxt;
+ }
+ }
push(@imports, [$name, $url, $residx]);
}
}
- ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
- $container,'londocs',@imports);
+ ($errtext,$fatal,my $fixuperrors) =
+ &group_import($coursenum, $coursedom, $folder,$container,
+ 'londocs',@imports);
return $errtext if ($fatal);
+ if ($fixuperrors) {
+ $r->print($fixuperrors);
+ }
}
# Loading a complete map
if ($env{'form.loadmap'}) {
@@ -1900,35 +1945,67 @@ sub editor {
unless ($name) { $idx++; next; }
$output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
$coursenum,$coursedom,$crstype,
- $uploadtag,$supplementalflag);
+ $pathitem,$supplementalflag,$container);
$idx++;
$shown++;
}
&Apache::loncommon::end_data_table_count();
-
- if ($shown) {
- $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
- .&Apache::loncommon::start_data_table(undef,'contentlist');
- if ($allowed) {
- $to_show .= &Apache::loncommon::start_data_table_header_row()
- .''.&mt('Move').' '
- .''.&mt('Actions').' '
- .''.&mt('Document').' ';
- if ($folder !~ /^supplemental/) {
- $to_show .= ''.&mt('Settings').' ';
+
+ if (($allowed) || ($supplementalflag && $folder eq 'supplemental')) {
+ my $toolslink = ''
+ .&Apache::loncommon::help_open_menu('Navigation Screen',
+ 'Navigation_Screen',undef,'RAT')
+ .' '.&mt('Tools:').' '
+ .'
';
+ if ($shown) {
+ if ($allowed) {
+ $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
+ .&Apache::loncommon::start_data_table(undef,'contentlist')
+ .&Apache::loncommon::start_data_table_header_row()
+ .''.&mt('Move').' '
+ .''.&mt('Actions').' '
+ .''.&mt('Document').' ';
+ if ($folder !~ /^supplemental/) {
+ $to_show .= ''.&mt('Settings').' ';
+ }
+ $to_show .= &Apache::loncommon::end_data_table_header_row()
+ .$output.' '
+ .&Apache::loncommon::end_data_table()
+ .' '
+ .&Apache::loncommon::end_scrollbox();
+ } else {
+ $to_show .= $toolslink
+ .&Apache::loncommon::start_data_table('LC_tableOfContent')
+ .$output.' '
+ .&Apache::loncommon::end_data_table();
+ }
+ } else {
+ if (!$allowed) {
+ $to_show .= $toolslink;
}
- $to_show .= &Apache::loncommon::end_data_table_header_row();
+ $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
+ .''
+ .&mt('Currently no documents.')
+ .'
'
+ .&Apache::loncommon::end_scrollbox();
}
- $to_show .= $output.' '
- .&Apache::loncommon::end_data_table()
- .' '
- .&Apache::loncommon::end_scrollbox();
} else {
- $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
- .''
- .&mt('Currently no documents.')
- .'
'
- .&Apache::loncommon::end_scrollbox();
+ if ($shown) {
+ $to_show = ''
+ .&Apache::loncommon::start_data_table('LC_tableOfContent')
+ .$output
+ .&Apache::loncommon::end_data_table()
+ .'
';
+ } else {
+ $to_show = ''
+ .&mt('Currently no documents.')
+ .'
'
+ }
}
my $tid = 1;
if ($supplementalflag) {
@@ -1940,19 +2017,6 @@ sub editor {
$readfile));
&print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
} else {
- if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
- #Function Box for Supplemental Content for users with mdc priv.
- my $funcname = &mt('Folder Editor');
- $r->print(
- &Apache::loncommon::head_subbox(
- &Apache::lonhtmlcommon::start_funclist().
- &Apache::lonhtmlcommon::add_item_funclist(
- ''.
- ' '.
- ' ').
- &Apache::lonhtmlcommon::end_funclist()));
- }
$r->print($to_show);
}
return;
@@ -1973,7 +2037,7 @@ sub process_file_upload {
my $errtext='';
my $fatal=0;
my $container='sequence';
- if ($env{'form.pagepath'}) {
+ if ($env{'form.folderpath'} =~ /:1$/) {
$container='page';
}
($errtext,$fatal)=
@@ -2063,7 +2127,6 @@ sub process_file_upload {
my $archiveurl = &HTML::Entities::encode($url,'<>&"');
my %archiveitems = (
folderpath => $env{'form.folderpath'},
- pagepath => $env{'form.pagepath'},
cmd => $nextphase,
newidx => $newidx,
position => $position,
@@ -2118,16 +2181,14 @@ sub is_supplemental_title {
sub entryline {
my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
- $crstype,$uploadtag,$supplementalflag)=@_;
- my ($foldertitle,$pagetitle,$renametitle);
+ $crstype,$pathitem,$supplementalflag,$container)=@_;
+ my ($foldertitle,$renametitle);
if (&is_supplemental_title($title)) {
($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
- $pagetitle = $foldertitle;
} else {
$title=&HTML::Entities::encode($title,'"<>&\'');
$renametitle=$title;
$foldertitle=$title;
- $pagetitle=$title;
}
my $orderidx=$LONCAPA::map::order[$index];
@@ -2138,30 +2199,34 @@ sub entryline {
my $line=&Apache::loncommon::start_data_table_row();
my ($form_start,$form_end,$form_common);
# Edit commands
- my ($container, $type, $esc_path, $path, $symb);
+ my ($type, $esc_path, $path, $symb);
+ if ($container eq 'page') {
+ $type = 'page';
+ } else {
+ $type = 'folder';
+ }
if ($env{'form.folderpath'}) {
- $type = 'folder';
- $container = 'sequence';
$esc_path=&escape($env{'form.folderpath'});
$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
}
- if ($env{'form.pagepath'}) {
- $type = $container = 'page';
- $esc_path=&escape($env{'form.pagepath'});
- $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
- }
- if (!$supplementalflag && $residx) {
+ my $isexternal;
+ if ($residx) {
my $currurl = $url;
$currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
- my $path = 'uploaded/'.
- $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
- $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
- $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
- $residx,
- &Apache::lonnet::declutter($currurl));
+ if ($currurl =~ m{^/adm/wrapper/ext/}) {
+ $isexternal = 1;
+ }
+ if (!$supplementalflag) {
+ my $path = 'uploaded/'.
+ $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
+ $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
+ $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
+ $residx,
+ &Apache::lonnet::declutter($currurl));
+ }
}
- my %lt;
+ my ($renamelink,%lt);
if ($allowed) {
my $incindex=$index+1;
my $selectbox='';
@@ -2258,10 +2323,7 @@ sub entryline {
$nocopy=1;
}
}
- my $copylink=' ';
- my $cutlink=' ';
- my $removelink=' ';
-
+ my ($copylink,$cutlink,$removelink);
my $skip_confirm = 0;
if ( $folder =~ /^supplemental/
|| ($url =~ m{( /smppg$
@@ -2269,26 +2331,43 @@ sub entryline {
|/aboutme$
|/navmaps$
|/bulletinboard$
- |\.html$
- |^/adm/wrapper/ext)}x)) {
+ |\.html$)}x)
+ || $isexternal) {
$skip_confirm = 1;
}
- if (!$nocopy) {
+ if ($nocopy) {
+ $copylink=(<$lt{'cp'}
+ENDCOPY
+ } else {
$copylink=(<$lt{'cp'}
+$lt{'cp'}
ENDCOPY
}
- if (!$nocut) {
+ if ($nocut) {
+ $cutlink=(<$lt{'ct'}
+ENDCUT
+ } else {
$cutlink=(<$lt{'ct'}
+$lt{'ct'}
ENDCUT
}
- if (!$noremove) {
+ if ($noremove) {
+ $removelink=(<$lt{'rm'}
+ENDREM
+ } else {
$removelink=(<$lt{'rm'}
+$lt{'rm'}
ENDREM
}
+ unless ($isexternal) {
+ $renamelink=(<$lt{'rn'}
+ENDREN
+ }
$form_start = '
';
- my $ro_set=
- ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
- $rand_order_text =
+ if ($rpicknum ne '') {
+ $rand_pick_text .= ': '.$rpicknum.' ';
+ }
+ $rand_pick_text .= '';
+ my $ro_set=
+ ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
+ $rand_order_text =
$form_start.
$form_common.'
'.&mt('Random Order').' ';
+ }
+ } elsif ($supplementalflag && !$allowed) {
+ $url .= ($url =~ /\?/) ? '&':'?';
+ $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
+ if ($title) {
+ $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
+ }
+ if ($isexternal && $orderidx) {
+ $url .= '&idx='.$orderidx;
+ }
}
- if ($ispage) {
- my $pagename=&escape($pagetitle);
- my $pagepath;
- my $folderpath=$env{'form.folderpath'};
- if ($folderpath) { $pagepath = $folderpath.'&' };
- $pagepath.=$pagearg.'&'.$pagename;
- $url.='pagepath='.&escape($pagepath).
- '&pagesymb='.&escape($symb);
- }
+ my ($tdalign,$tdwidth);
if ($allowed) {
my $fileloc =
&Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
-
- if ($external) {
- $editlink = <<"EXTLNK";
-
-
- $lt{'ed'}
-
-EXTLNK
- } else {
+ if ($isexternal) {
+ ($editlink,$extresform) =
+ &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
+ } elsif (!$isfolder && !$ispage) {
my ($cfile,$home,$switchserver,$forceedit,$forceview) =
&Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
- if (($cfile ne '') && ($symb ne '')) {
+ if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
my $jscall =
&Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
$switchserver,
$forceedit,
- undef,$symb);
+ undef,$symb,
+ &escape($env{'form.folderpath'}),
+ $renametitle,'','',1);
if ($jscall) {
- $editlink = ' '.&mt('Edit').' ';
+ $editlink = ''.&mt('Edit').' '."\n";
}
}
}
+ $tdalign = ' align="right" valign="top"';
+ $tdwidth = ' width="80%"';
}
my $reinit;
if ($crstype eq 'Community') {
$reinit = &mt('(re-initialize community to access)');
} else {
$reinit = &mt('(re-initialize course to access)');
- }
- $line.='';
+ }
+ $line.=' '.$editlink.$renamelink;
if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
$line.=' ';
} elsif ($url) {
@@ -2497,7 +2558,7 @@ EXTLNK
} else {
$line.=' ';
}
- $line.=' ';
+ $line.=' ';
if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
$line.=''.$title.' ';
} elsif ($url) {
@@ -2506,7 +2567,7 @@ EXTLNK
} else {
$line.=$title.' '.$reinit.' ';
}
- $line.=$editlink." ";
+ $line.="$extresform";
$rand_pick_text = ' ' if ($rand_pick_text eq '');
$rand_order_text = ' ' if ($rand_order_text eq '');
if (($allowed) && ($folder!~/^supplemental/)) {
@@ -2537,6 +2598,30 @@ ENDPARMS
return $line;
}
+sub newmap_suffix {
+ my ($area,$container,$coursedom,$coursenum) = @_;
+ my ($prefix,$idtype,$errtext,$locknotfreed);
+ $prefix = 'docs';
+ if ($area eq 'supplemental') {
+ $prefix = 'supp';
+ }
+ $prefix .= $container;
+ $idtype = 'concat';
+ my ($suffix,$freedlock,$error) =
+ &Apache::lonnet::get_timebased_id($prefix,'num','uploadedmaps',
+ $coursedom,$coursenum);
+ if (!$suffix) {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
+ if ($error) {
+ $errtext .= ' '.$error;
+ }
+ }
+ if ($freedlock ne 'ok') {
+ $locknotfreed = ''.&mt('There was a problem removing a lockfile. This will prevent creation of additional folders or composite pages in this course. Please contact the domain coordinator for your LON-CAPA domain.').'
';
+ }
+ return ($suffix,$errtext,$locknotfreed);
+}
+
=pod
=item tiehash()
@@ -2632,7 +2717,7 @@ sub checkonthis {
$r->print(''.&mt('connection down').' ');
} elsif ($result eq 'not_found') {
unless ($url=~/\$/) {
- $r->print(''.&mt('not found').' ');
+ $r->print(''.&mt('not found').' ');
} else {
$r->print(''.&mt('unable to verify variable URL').' ');
}
@@ -2678,7 +2763,7 @@ sub list_symbs {
$r->print(&Apache::loncommon::start_data_table_row().
''.$res->compTitle().' '.
''.$res->symb().' '.
- &Apache::loncommon::start_data_table_row());
+ &Apache::loncommon::end_data_table_row());
$count ++;
}
if (!$count) {
@@ -2688,6 +2773,7 @@ sub list_symbs {
}
$r->print(&Apache::loncommon::end_data_table());
}
+ $r->print(&endContentScreen());
}
@@ -2718,6 +2804,7 @@ sub verifycontent {
}
&untiehash();
$r->print(''.&mt('Done').'
');
+ $r->print(&endContentScreen());
}
@@ -2797,7 +2884,7 @@ sub checkversions {
if ($env{'form.timerange'} eq 'all') {
# show all documents
$header=&mt('All Documents in '.$crstype);
- $allsel=1;
+ $allsel=' selected="selected"';
foreach my $key (keys(%hash)) {
if ($key=~/^ids\_(\/res\/.+)$/) {
my $src=$1;
@@ -2818,19 +2905,19 @@ sub checkversions {
.&mt('seconds');
if ($env{'form.timerange'}==-1) {
$seltext='since start of course';
- $startsel='selected';
+ $startsel=' selected="selected"';
$env{'form.timerange'}=time;
}
$starttime=time-$env{'form.timerange'};
if ($env{'form.timerange'}==2592000) {
$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
- $monthsel='selected';
+ $monthsel=' selected="selected"';
} elsif ($env{'form.timerange'}==604800) {
$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
- $weeksel='selected';
+ $weeksel=' selected="selected"';
} elsif ($env{'form.timerange'}==86400) {
$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
- $daysel='selected';
+ $daysel=' selected="selected"';
}
$header=&mt('Content changed').' '.$seltext;
} else {
@@ -2868,11 +2955,11 @@ sub checkversions {
$lt{'cd'}
-$lt{'al'}
-$lt{'st'}
-$lt{'lm'}
-$lt{'lw'}
-$lt{'sy'}
+$lt{'al'}
+$lt{'st'}
+$lt{'lm'}
+$lt{'lw'}
+$lt{'sy'}
@@ -2888,111 +2975,93 @@ $lt{'sc'}:
-
ENDHEADERS
#number of columns for version history
- my $num_ver_col = 1;
$r->print(
- &Apache::loncommon::start_data_table().
- &Apache::loncommon::start_data_table_header_row().
- ''.&mt('Resources').' '.
- "$lt{'mr'} ".
- "$lt{'ve'} ".
- "$lt{'vu'} ".
- ''.&mt('History').' '.
- '');
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ ''.&mt('Resources').' '.
+ "$lt{'mr'} ".
+ "$lt{'ve'} ".
+ "$lt{'vu'} ".
+ ''.&mt('History').' '.
+ &Apache::loncommon::end_data_table_header_row()
+ );
foreach my $key (sort(keys(%changes))) {
#excludes not versionable problems from resource version history:
- if ($changes{$key}>$starttime && $key !~ /^\/res\/lib\/templates/) {
- my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
- my $currentversion=&Apache::lonnet::getversion($key);
- if ($currentversion<0) {
- $currentversion=''.&mt('Could not be determined.').' ';
- }
- my $linkurl=&Apache::lonnet::clutter($key);
+ next unless ($changes{$key}>$starttime && $key !~ /^\/res\/lib\/templates/);
+ my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
+ my $currentversion=&Apache::lonnet::getversion($key);
+ if ($currentversion<0) {
+ $currentversion=''.&mt('Could not be determined.').' ';
+ }
+ my $linkurl=&Apache::lonnet::clutter($key);
$r->print(
- &Apache::loncommon::end_data_table_header_row().
&Apache::loncommon::start_data_table_row().
- ''.&Apache::lonnet::gettitle($linkurl).' '.
+ ''.&Apache::lonnet::gettitle($linkurl).' '.
''.$linkurl.' '.
- ''.$currentversion.' ('.
+ ' '.$currentversion.' ('.
&Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).') '.
- '');
-# Used in course
- my $usedversion=$hash{'version_'.$linkurl};
- if (($usedversion) && ($usedversion ne 'mostrecent')) {
- if($usedversion != $currentversion){
+ ' '
+ );
+ # Used in course
+ my $usedversion=$hash{'version_'.$linkurl};
+ if (($usedversion) && ($usedversion ne 'mostrecent')) {
+ if ($usedversion != $currentversion) {
$r->print(''.$usedversion.' ');
- }else{
+ } else {
$r->print($usedversion);
}
- } else {
- $r->print($currentversion);
- }
- $r->print(' ');
-# Set version
- $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
- 'set_version_'.$linkurl,
- {'select_form_order' =>
- ['',1..$currentversion,'mostrecent'],
- '' => '',
- 'mostrecent' => &mt('most recent'),
- map {$_,$_} (1..$currentversion)}));
- my $lastold=1;
- for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
- my $url=$root.'.'.$prevvers.'.'.$extension;
- if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
- $starttime) {
- $lastold=$prevvers;
- }
- }
- #
- # Code to figure out how many version entries should go in
- # each of the four columns
- my $entries_per_col = 0;
- my $num_entries = ($currentversion-$lastold);
- if ($num_entries % $num_ver_col == 0) {
- $entries_per_col = $num_entries/$num_ver_col;
} else {
- $entries_per_col = $num_entries/$num_ver_col + 1;
+ $r->print($currentversion);
}
- my $entries_count = 0;
- $r->print(' ');
- my $cols_output = 1;
- for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
- my $url=$root.'.'.$prevvers.'.'.$extension;
- $r->print(''.&mt('Version').' '.$prevvers.' ('.
- &Apache::lonlocal::locallocaltime(
- &Apache::lonnet::metadata($url,
- 'lastrevisiondate')
- ).
- ')');
- if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
- $r->print(' '.&mt('Diffs').' ');
- }
- $r->print(' ');
- if (++$entries_count % $entries_per_col == 0) {
- $r->print(' ');
- if ($cols_output != $num_ver_col) {
- $r->print('');
- $cols_output++;
- }
- }
- }
- while($cols_output++ < $num_ver_col) {
- $r->print(' ');
+ $r->print(' ');
+ # Set version
+ $r->print(&Apache::loncommon::select_form(
+ $setversions{$linkurl},
+ 'set_version_'.$linkurl,
+ {'select_form_order' => ['',1..$currentversion,'mostrecent'],
+ '' => '',
+ 'mostrecent' => &mt('most recent'),
+ map {$_,$_} (1..$currentversion)}));
+ my $lastold=1;
+ for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
+ my $url=$root.'.'.$prevvers.'.'.$extension;
+ if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
+ $lastold=$prevvers;
+ }
+ }
+ $r->print(' ');
+ # List all available versions
+ $r->print('');
+ for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
+ my $url=$root.'.'.$prevvers.'.'.$extension;
+ $r->print(
+ ''
+ .''
+ .&mt('Version [_1]',$prevvers).' '
+ .' ('.&Apache::lonlocal::locallocaltime(
+ &Apache::lonnet::metadata($url,'lastrevisiondate'))
+ .')');
+ if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
+ $r->print(
+ ' &').
+ '" target="diffs">'.&mt('Diffs').' ');
}
- }
+ $r->print(' ');
+ }
+ $r->print(' '.&Apache::loncommon::end_data_table_row());
}
- $r->print(''.&Apache::loncommon::end_data_table_row().
- &Apache::loncommon::end_data_table().
- ' ');
+ $r->print(
+ &Apache::loncommon::end_data_table().
+ ' '.
+ ''
+ );
&untiehash();
+ $r->print(&endContentScreen());
}
sub mark_hash_old {
@@ -3024,11 +3093,6 @@ sub changewarning {
my $pathvar='folderpath';
my $path=&escape($env{'form.folderpath'});
if (!defined($url)) {
- if (defined($env{'form.pagepath'})) {
- $pathvar='pagepath';
- $path=&escape($env{'form.pagepath'});
- $path.='&pagesymb='.&escape($env{'form.pagesymb'});
- }
$url='/adm/coursedocs?'.$pathvar.'='.$path;
}
my $course_type = &Apache::loncommon::course_type();
@@ -3202,9 +3266,9 @@ sub handler {
# Get the parameters that may be needed
#
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['folderpath','pagepath',
- 'pagesymb','forcesupplement','forcestandard',
- 'tools','symb','command']);
+ ['folderpath',
+ 'forcesupplement','forcestandard',
+ 'tools','symb','command','supppath']);
# standard=1: this is a "new-style" course with an uploaded map as top level
# standard=2: this is a "old-style" course, and there is nothing we can do
@@ -3218,7 +3282,7 @@ sub handler {
my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
- if (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'} eq "" || ($env{'form.pagepath'})) {
+ if (($env{'form.folderpath'}=~/^default/) || ($env{'form.folderpath'} eq "")) {
$supplementalflag=0;
}
if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
@@ -3233,106 +3297,58 @@ sub handler {
my $addentries = {};
my $container;
my $containertag;
- my $uploadtag;
+ my $pathitem;
# Do we directly jump somewhere?
- if ($env{'form.command'} eq 'direct') {
- my ($mapurl,$id,$resurl);
+ if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
if ($env{'form.symb'} ne '') {
- ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
- if ($resurl=~/\.(sequence|page)$/) {
- $mapurl=$resurl;
- } elsif ($resurl eq 'adm/navmaps') {
- $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
- }
- my $mapresobj;
- my $navmap = Apache::lonnavmaps::navmap->new();
- if (ref($navmap)) {
- $mapresobj = $navmap->getResourceByUrl($mapurl);
- }
- $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
- my $type=$2;
- my $path;
- if (ref($mapresobj)) {
- my $pcslist = $mapresobj->map_hierarchy();
- if ($pcslist ne '') {
- foreach my $pc (split(/,/,$pcslist)) {
- next if ($pc <= 1);
- my $res = $navmap->getByMapPc($pc);
- if (ref($res)) {
- my $thisurl = $res->src();
- $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
- my $thistitle = $res->title();
- $path .= '&'.
- &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($thistitle).
- ':'.$res->randompick().
- ':'.$res->randomout().
- ':'.$res->encrypted().
- ':'.$res->randomorder();
- }
- }
- }
- $path .= '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($mapresobj->title()).
- ':'.$mapresobj->randompick().
- ':'.$mapresobj->randomout().
- ':'.$mapresobj->encrypted().
- ':'.$mapresobj->randomorder();
- } else {
- my $maptitle = &Apache::lonnet::gettitle($mapurl);
- $path = '&default&...::::'.
- '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
- }
- $path = 'default&'.
- &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
- $path;
- if ($type eq 'sequence') {
- $env{'form.folderpath'}=$path;
- $env{'form.pagepath'}='';
- } else {
- $env{'form.pagepath'}=$path;
- $env{'form.folderpath'}='';
- }
+ $env{'form.folderpath'}=
+ &Apache::loncommon::symb_to_docspath($env{'form.symb'});
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
+ $env{'form.command'}.'_'.$env{'form.symb'}});
} elsif ($env{'form.supppath'} ne '') {
$env{'form.folderpath'}=$env{'form.supppath'};
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
+ $env{'form.command'}.'_'.$env{'form.supppath'}});
}
} elsif ($env{'form.command'} eq 'editdocs') {
- $env{'form.folderpath'} = 'default&'.
- &Apache::lonhtmlcommon::entity_encode('Main Course Content');
- $env{'form.pagepath'}='';
+ $env{'form.folderpath'} = 'default&'.
+ &Apache::lonhtmlcommon::entity_encode('Main Course Content').
+ ':::::';
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
} elsif ($env{'form.command'} eq 'editsupp') {
- $env{'form.folderpath'} = 'default&'.
+ $env{'form.folderpath'} = 'supplemental&'.
&Apache::lonhtmlcommon::entity_encode('Supplemental Content');
- $env{'form.pagepath'}='';
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
+ } elsif ($env{'form.command'} eq 'contents') {
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
+ } elsif ($env{'form.command'} eq 'home') {
+ &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
}
+
# Where do we store these for when we come back?
my $stored_folderpath='docs_folderpath';
if ($supplementalflag) {
$stored_folderpath='docs_sup_folderpath';
}
-# No folderpath, no pagepath, see if we have something stored
- if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
+# No folderpath, and in edit mode, see if we have something stored
+ if ((!$env{'form.folderpath'}) && $allowed) {
&Apache::loncommon::restore_course_settings($stored_folderpath,
- {'folderpath' => 'scalar'});
+ {'folderpath' => 'scalar'});
+ unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
+ undef($env{'form.folderpath'});
+ }
}
# If we are not allowed to make changes, all we can see are supplemental docs
if (!$allowed) {
- $env{'form.pagepath'}='';
unless ($env{'form.folderpath'} =~ /^supplemental/) {
$env{'form.folderpath'} = &supplemental_base();
}
}
-# If we still not have a folderpath, see if we can resurrect at pagepath
- if (!$env{'form.folderpath'} && $allowed) {
- &Apache::loncommon::restore_course_settings($stored_folderpath,
- {'pagepath' => 'scalar'});
- }
# Make the zeroth entry in supplemental docs page paths, so we can get to top level
if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
$env{'form.folderpath'} = &supplemental_base()
@@ -3340,48 +3356,42 @@ sub handler {
$env{'form.folderpath'};
}
# If after all of this, we still don't have any paths, make them
- unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
+ unless ($env{'form.folderpath'}) {
if ($supplementalflag) {
$env{'form.folderpath'}=&supplemental_base();
} else {
- $env{'form.folderpath'}='default';
+ $env{'form.folderpath'}='default'.&escape(&mt('Main '.$crstype.' Documents')).
+ ':::::';
}
}
# Store this
unless ($toolsflag) {
- &Apache::loncommon::store_course_settings($stored_folderpath,
- {'pagepath' => 'scalar',
- 'folderpath' => 'scalar'});
+ if ($allowed) {
+ &Apache::loncommon::store_course_settings($stored_folderpath,
+ {'folderpath' => 'scalar'});
+ }
+ my $folderpath;
if ($env{'form.folderpath'}) {
- my (@folderpath)=split('&',$env{'form.folderpath'});
- $env{'form.foldername'}=&unescape(pop(@folderpath));
- $env{'form.folder'}=pop(@folderpath);
- $container='sequence';
- }
- if ($env{'form.pagepath'}) {
- my (@pagepath)=split('&',$env{'form.pagepath'});
- $env{'form.pagename'}=&unescape(pop(@pagepath));
- $env{'form.folder'}=pop(@pagepath);
- $container='page';
- $containertag = ' '.
- ' ';
- $uploadtag =
- ' '.
- ' '.
- ' ';
+ $folderpath = $env{'form.folderpath'};
+ my (@folders)=split('&',$env{'form.folderpath'});
+ $env{'form.foldername'}=&unescape(pop(@folders));
+ if ($env{'form.foldername'} =~ /\:1$/) {
+ $container = 'page';
+ } else {
+ $container = 'sequence';
+ }
+ $env{'form.folder'}=pop(@folders);
} else {
- my $folderpath=$env{'form.folderpath'};
- if (!$folderpath) {
- if ($env{'form.folder'} eq '' ||
- $env{'form.folder'} eq 'supplemental') {
- $folderpath='default&'.
- &escape(&mt('Main '.$crstype.' Documents'));
- }
+ if ($env{'form.folder'} eq '' ||
+ $env{'form.folder'} eq 'supplemental') {
+ $folderpath='default&'.
+ &escape(&mt('Main '.$crstype.' Documents')).
+ ':::::';
}
- $containertag = ' ';
- $uploadtag = ' ';
}
+ $containertag = ' ';
+ $pathitem = ' ';
if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
$showdoc='/'.$1;
}
@@ -3419,7 +3429,7 @@ sub handler {
@tabids = ('002','ee2','ff2');
} else {
@tabids = ('aa1','bb1','cc1','ff1');
- unless ($env{'form.pagepath'}) {
+ unless ($env{'form.folderpath'} =~ /\:1$/) {
unshift(@tabids,'001');
push(@tabids,('dd1','ee1'));
}
@@ -3428,7 +3438,8 @@ sub handler {
$script .= &editing_js($udom,$uname,$supplementalflag).
&history_tab_js().
&inject_data_js().
- &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr);
+ &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr).
+ &Apache::lonextresedit::extedit_javascript();
$addentries = {
onload => "javascript:resize_scrollbox('contentscroll','1','1');",
};
@@ -3450,22 +3461,26 @@ sub handler {
# Breadcrumbs
&Apache::lonhtmlcommon::clear_breadcrumbs();
- unless ($showdoc) {
+
+ if ($showdoc) {
+ $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
+ {'force_register' => $showdoc,}));
+ } elsif ($r->uri eq '/adm/supplemental') {
+ my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
+ $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
+ {'bread_crumbs' => $brcrum,}));
+ } else {
&Apache::lonhtmlcommon::add_breadcrumb({
href=>"/adm/coursedocs",text=>"$crstype Contents"});
$r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
- {'force_register' => $showdoc,
- 'add_entries' => $addentries,
- })
+ {'add_entries' => $addentries}
+ )
.&Apache::loncommon::help_open_menu('','',273,'RAT')
.&Apache::lonhtmlcommon::breadcrumbs(
'Editing '.$crstype.' Contents',
'Docs_Adding_Course_Doc')
);
- } else {
- $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
- {'force_register' => $showdoc,}));
}
my %allfiles = ();
@@ -3528,9 +3543,6 @@ sub handler {
} elsif ((!$showdoc) && (!$uploadphase)) {
# -----------------------------------------------------------------------------
my %lt=&Apache::lonlocal::texthash(
- 'uplm' => 'Upload a new main '.lc($crstype).' document',
- 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
- 'impp' => 'Import a document',
'copm' => 'All documents out of a published map into this folder',
'upfi' => 'Upload File',
'upld' => 'Import Content',
@@ -3540,10 +3552,8 @@ sub handler {
'impm' => 'Import from Assembled Map',
'selm' => 'Select Map',
'load' => 'Load Map',
- 'reco' => 'Recover Deleted Documents',
'newf' => 'New Folder',
'newp' => 'New Composite Page',
- 'extr' => 'External Resource',
'syll' => 'Syllabus',
'navc' => 'Table of Contents',
'sipa' => 'Simple Course Page',
@@ -3554,7 +3564,7 @@ sub handler {
'mypi' => 'My Personal Information Page',
'grpo' => 'Group Portfolio',
'rost' => 'Course Roster',
- 'abou' => 'Personal Information Page for a User',
+ 'abou' => 'Personal Information Page for a User',
'imsf' => 'IMS Import',
'imsl' => 'Import IMS package',
'cms' => 'Origin of IMS package',
@@ -3562,14 +3572,7 @@ sub handler {
'file' => 'File',
'title' => 'Title',
'comment' => 'Comment',
- 'url' => 'URL',
- 'prev' => 'Preview',
- 'lnk' => 'Add Link',
'parse' => 'Upload embedded images/multimedia files if HTML file',
- 'nd' => 'Upload Document',
- 'pm' => 'Published Map',
- 'sd' => 'Special Document',
- 'mo' => 'More Options',
);
# -----------------------------------------------------------------------------
my $fileupload=(<