--- loncom/interface/londocs.pm 2007/01/26 23:37:53 1.270
+++ loncom/interface/londocs.pm 2013/03/13 00:29:09 1.536
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.270 2007/01/26 23:37:53 albertel Exp $
+# $Id: londocs.pm,v 1.536 2013/03/13 00:29:09 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,12 +33,16 @@ 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;
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;
@@ -53,15 +57,9 @@ my %alreadyseen=();
my $hadchanges;
-# Available help topics
my %help=();
-# 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
-#
sub mapread {
my ($coursenum,$coursedom,$map)=@_;
@@ -71,30 +69,34 @@ sub mapread {
}
sub storemap {
- my ($coursenum,$coursedom,$map)=@_;
+ my ($coursenum,$coursedom,$map,$contentchg)=@_;
+ my $report;
+ if (($contentchg) && ($map =~ /^default/)) {
+ $report = 1;
+ }
my ($outtext,$errtext)=
&LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map,1);
+ $map,1,$report);
if ($errtext) { return ($errtext,2); }
-
+
$hadchanges=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'};
@@ -104,815 +106,179 @@ sub authorhosts {
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();
- my $type = &Apache::loncommon::course_type();
- if ($home+$other==0) { return ''; }
- my $output='
');
+ my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
+ if ($is_supp) {
+ $shown = &Apache::loncommon::parse_supplemental_title($shown);
+ }
+ $r->print('
'.$shown.'
');
}
}
$r->print('
');
if ($docslog{$id}{'logentry'}{'parameter_res'}) {
$r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':
');
- foreach my $parameter ('randompick','hiddenresource','encrypturl') {
+ foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
+# FIXME: internationalization seems wrong here
$r->print('
'.
&mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
$docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
@@ -1183,316 +647,1621 @@ sub docs_change_log {
if (!($env{'form.show'} eq &mt('all')
|| $shown<=$env{'form.show'})) { last; }
}
- $r->print(&Apache::loncommon::end_data_table());
- $r->print(&Apache::loncommon::end_page());
+ $r->print(&Apache::loncommon::end_data_table()."\n".
+ &makesimpleeditform($pathitem)."\n".
+ '');
+ $r->print(&endContentScreen());
+}
+
+sub update_paste_buffer {
+ my ($coursenum,$coursedom,$folder) = @_;
+
+ return if (!defined($env{'form.markcopy'}));
+ return if (!defined($env{'form.copyfolder'}));
+ return if ($env{'form.markcopy'} < 0);
+
+ my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
+ $env{'form.copyfolder'});
+
+ return if ($fatal);
+
+# Mark for copying
+ my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
+ if (&is_supplemental_title($title)) {
+ &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
+ ($title) = &Apache::loncommon::parse_supplemental_title($title);
+ } elsif ($env{'docs.markedcopy_supplemental'}) {
+ &Apache::lonnet::delenv('docs.markedcopy_supplemental');
+ }
+ $url=~s{http(:|:)//https(:|:)//}{https$2//};
+
+ (my $cmd,undef)=split('_',$env{'form.cmd'});
+
+ my %addtoenv = (
+ 'docs.markedcopy_title' => $title,
+ 'docs.markedcopy_url' => $url,
+ 'docs.markedcopy_cmd' => $cmd,
+ );
+ &Apache::lonnet::delenv('docs.markedcopy_nested');
+ &Apache::lonnet::delenv('docs.markedcopy_nestednames');
+ if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
+ my $prefix = $1;
+ my $subdir =$2;
+ if ($subdir eq '') {
+ $subdir = $prefix;
+ }
+ my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
+ &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
+ \%hierarchy,\%titles,\%allmaps);
+ if (ref($hierarchy{$url}) eq 'HASH') {
+ my ($nested,$nestednames);
+ &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
+ $nested =~ s/\&$//;
+ $nestednames =~ s/\Q___&&&___\E$//;
+ if ($nested ne '') {
+ $addtoenv{'docs.markedcopy_nested'} = $nested;
+ }
+ if ($nestednames ne '') {
+ $addtoenv{'docs.markedcopy_nestednames'} = $nestednames;
+ }
+ }
+ }
+ &Apache::lonnet::appenv(\%addtoenv);
+ delete($env{'form.markcopy'});
+}
+
+sub recurse_uploaded_maps {
+ my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
+ if (ref($hierarchy->{$url}) eq 'HASH') {
+ my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
+ my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
+ my (@uploaded,@names,%shorter);
+ for (my $i=0; $i<@maps; $i++) {
+ my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
+ if ($inner ne '') {
+ push(@uploaded,$inner);
+ push(@names,&escape($titles[$i]));
+ $shorter{$maps[$i]} = $inner;
+ }
+ }
+ $$nestref .= "$dir:".join(',',@uploaded).'&';
+ $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
+ foreach my $map (@maps) {
+ if ($shorter{$map} ne '') {
+ &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
+ }
+ }
+ }
+ return;
+}
+
+sub print_paste_buffer {
+ my ($r,$container,$folder,$coursedom,$coursenum) = @_;
+ return if (!defined($env{'docs.markedcopy_url'}));
+
+ my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent);
+ my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
+ if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
+ $is_external = 1;
+ }
+
+ my ($canpaste,$nopaste,$othercrs,$areachange);
+ if ($folder =~ /^supplemental/) {
+ $canpaste = &supp_pasteable($env{'docs.markedcopy_url'});
+ unless ($canpaste) {
+ $nopaste = &mt('Paste into Supplemental Content unavailable for this type of content.');
+ }
+ } else {
+ $canpaste = 1;
+ }
+
+ if ($canpaste) {
+ if ($env{'docs.markedcopy_url'} =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
+ my $srcdom = $1;
+ my $srcnum = $2;
+ my $rem = $3;
+ if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
+ $othercourse = 1;
+ if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
+ if ($canpaste) {
+ $othercrs = ' '.&mt('(from another course).');
+ }
+ } else {
+ $canpaste = 0;
+ $nopaste = &mt('Paste from another course unavailable.')
+ }
+ }
+ if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
+ my $prefix = $1;
+ $parent = $2;
+ if ($folder !~ /^\Q$prefix\E/) {
+ $areachange = 1;
+ }
+ $is_uploaded_map = 1;
+ }
+ }
+ }
+
+ $r->print('');
+}
+
+sub recurse_print {
+ my ($r,$dir,$deps,$display) = @_;
+ $r->print($display->{$dir}."\n");
+ if (ref($deps->{$dir}) eq 'ARRAY') {
+ foreach my $subdir (@{$deps->{$dir}}) {
+ &recurse_print($r,$subdir,$deps,$display);
+ }
+ }
+}
+
+sub supp_pasteable {
+ my ($url) = @_;
+ if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
+ (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
+ ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
+ ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
+ ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
+ return 1;
+ }
+ return;
+}
+
+sub paste_popup_js {
+ my %lt = &Apache::lonlocal::texthash(
+ show => 'Show Paste Options',
+ hide => 'Hide Paste Options',
+ );
+ return <<"END";
+
+function showPasteOptions() {
+ document.getElementById('pasteoptions').style.display='block';
+ document.getElementById('pasteoptions').style.textAlign='left';
+ document.getElementById('pasteoptions').style.textFace='normal';
+ document.getElementById('pasteoptionstext').innerHTML ='$lt{'hide'} ';
+ return;
+}
+
+function hidePasteOptions() {
+ document.getElementById('pasteoptions').style.display='none';
+ document.getElementById('pasteoptionstext').innerHTML ='$lt{'show'}';
+ return;
+}
+
+END
+
+}
+
+
+sub do_paste_from_buffer {
+ my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
+
+# Early out if paste buffer is empty
+ if (!$env{'form.pastemarked'}) {
+ return ();
+ }
+
+# Supplemental content may only include certain types of content
+# Early out if pasted content is not supported in Supplemental area
+ if ($folder =~ /^supplemental/) {
+ unless (&supp_pasteable($env{'docs.markedcopy_url'})) {
+ return (&mt('Paste failed: content type is not supported within Supplemental Content'));
+ }
+ }
+
+# Prepare to paste resource at end of list
+ my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
+ my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
+
+ my ($is_map,$srcdom,$srcnum,$prefixchg,%before,%after,%mapchanges,%tomove);
+ if ($url=~/\.(page|sequence)$/) {
+ $is_map = 1;
+ }
+ if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/([^/]+)}) {
+ $srcdom = $1;
+ $srcnum = $2;
+ my $oldprefix = $3;
+# When paste buffer was populated using an active role in a different course
+# check for mdc privilege in the course from which the resource was pasted
+ if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
+ unless ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
+ return (&mt('Paste failed: Item is from a different course which you do not have rights to edit.'));
+ }
+ }
+# When pasting content from Main Content to Supplemental Content and vice versa
+# URLs will contain different paths (which depend on whether pasted item is
+# a folder/page or a document.
+ if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
+ $prefixchg = 1;
+ %before = ( map => 'default',
+ doc => 'docs');
+ %after = ( map => 'supplemental',
+ doc => 'supplemental' );
+ } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
+ $prefixchg = 1;
+ %before = ( map => 'supplemental',
+ doc => 'supplemental');
+ %after = ( map => 'default',
+ doc => 'docs');
+ }
+
+# If pasting an uploaded map, get list of contained uploaded maps.
+ my @nested;
+ if ($env{'docs.markedcopy_nested'}) {
+ my ($type) = ($oldprefix =~ /^(default|supplemental)/);
+ my @items = split(/\&/,$env{'docs.markedcopy_nested'});
+ my @deps = map { /\d+:([\d,]+$)/ } @items;
+ foreach my $dep (@deps) {
+ if ($dep =~ /,/) {
+ push(@nested,split(/,/,$dep));
+ } else {
+ push(@nested,$dep);
+ }
+ }
+ foreach my $item (@nested) {
+ if ($env{'form.docs.markedcopy_'.$item} eq 'move') {
+ $tomove{$type.'_'.$item} = 1;
+ }
+ }
+ }
+ }
+
+# Maps need to be copied first
+ my ($oldurl,%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
+ %dbcopies,%zombies,%params,%docmoves,%mapmoves,%newsubdir,%newurls);
+ $oldurl = $url;
+ if ($is_map) {
+# If pasting a map, check if map contains other maps
+ my ($allmaps,%hierarchy,%titles);
+ $allmaps = {};
+ if ($folder =~ /^default/) {
+ $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);
+ 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);
+ if ($error) {
+ return ($error);
+ }
+ if ($newurl ne '') {
+ if ($newurl ne $url) {
+ if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
+ $newsubdir{$url} = $1;
+ }
+ $mapchanges{$url} = 1;
+ }
+ }
+ }
+ if (($srcdom ne $coursedom) || ($srcnum ne $coursenum) || ($prefixchg) ||
+ (($newurl ne '') && ($newurl ne $url))) {
+ unless (&url_paste_fixups($url,$folder,$prefixchg,$coursedom,
+ $coursenum,$srcdom,$srcnum,$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,
+ $srcdom,$srcnum,$allmaps,\%rewrites,
+ \%retitles,\%copies,\%dbcopies,\%zombies,\%params,\%mapmoves,
+ \%mapchanges,\%tomove,\%newsubdir,\%newurls);
+ }
+ } elsif ($url=~m {^/res/}) {
+# published maps can only exists once, so remove it from paste buffer when done
+ &Apache::lonnet::delenv('docs.markedcopy');
+# if pasting published map (main content are only) check map is not already in course
+ if ($folder =~ /^default/) {
+ 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.'));
+ }
+ }
+ }
+ }
+ my $lockerrors;
+ if ($url=~ m{/(bulletinboard|smppg)$}) {
+ my $prefix = $1;
+ #need to copy the db contents to a new one, unless this is a move.
+ my %info = (
+ src => $url,
+ cdom => $coursedom,
+ cnum => $coursenum,
+ );
+ my (%lockerr,$msg);
+ unless ($env{'form.docs.markedcopy_options'} eq 'move') {
+ my ($newurl,$result,$errtext) =
+ &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
+ if ($result eq 'ok') {
+ $url = $newurl;
+ $title=&mt('Copy of').' '.$title;
+ } else {
+ if ($prefix eq 'smppg') {
+ $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
+ } elsif ($prefix eq 'bulletinboard') {
+ $msg = &mt('Paste failed: An error occurred when copying the bulletin board.').' '.$errtext;
+ }
+ return ($result,undef,[$msg],$lockerr{$prefix});
+ }
+ if ($lockerr{$prefix}) {
+ $lockerrors = $lockerr{$prefix};
+ }
+ }
+ }
+ $title = &LONCAPA::map::qtunescape($title);
+ my $ext='false';
+ if ($url=~m{^http(|s)://}) { $ext='true'; }
+ $url = &LONCAPA::map::qtunescape($url);
+
+# For uploaded files (excluding pages/sequences) path in copied file is changed
+# if paste is from Main to Supplemental (or vice versa), or if pasting between
+# courses.
+
+ my $newidx;
+ unless ($is_map) {
+# Now insert the URL at the bottom
+ $newidx = &LONCAPA::map::getresidx($url);
+ if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
+ my $relpath = $1;
+ if ($relpath ne '') {
+ my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
+ my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
+ my $newprefix = $newloc;
+ if ($newloc eq 'default') {
+ $newprefix = 'docs';
+ }
+ if ($newdocsdir eq '') {
+ $newdocsdir = 'default';
+ }
+ if (($prefixchg) ||
+ ($srcdom ne $coursedom) || ($srcnum ne $coursenum) ||
+ ($env{'form.docs.markedcopy_options'} ne 'move')) {
+ my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
+ $url =
+ &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
+ &Apache::lonnet::getfile($oldurl));
+ if ($url eq '/adm/notfound.html') {
+ return (&mt('Paste failed: an error occurred saving the file.'));
+ } else {
+ my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
+ $newsubpath =~ s{/+$}{/};
+ $docmoves{$oldurl} = $newsubpath;
+ }
+ }
+ }
+ }
+ }
+# 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,my $msgsarray,my $lockerror) =
+ &apply_fixups($folder,$is_map,$coursedom,$coursenum,$errors,
+ \%updated,\%info,\%moves,$prefixchg,$oldurl,$url,'paste');
+ $lockerrors .= $lockerror;
+ if ($result eq 'ok') {
+ if ($is_map) {
+ my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
+ $folder.'.'.$container);
+ return ($errtext,$save_err,$msgsarray,$lockerrors) if ($fatal);
+
+ if ($#LONCAPA::map::order<1) {
+ my $idx=&LONCAPA::map::getresidx();
+ if ($idx<=0) { $idx=1; }
+ $LONCAPA::map::order[0]=$idx;
+ $LONCAPA::map::resources[$idx]='';
+ }
+ $newidx = &LONCAPA::map::getresidx($url);
+ }
+ if ($env{'docs.markedcopy_supplemental'}) {
+ if ($folder !~ /^supplemental/) {
+ (undef,undef,$title) =
+ &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental'});
+ }
+ } else {
+ if ($folder=~/^supplemental/) {
+ $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
+ $env{'user.domain'}.'___&&&___'.$title;
+ }
+ }
+ $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
+ push(@LONCAPA::map::order, $newidx);
+
+# Store the result
+ my ($errtext,$fatal) =
+ &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
+ if ($fatal) {
+ $save_err = $errtext;
+ }
+ }
+
+ if ($env{'form.docs.markedcopy_options'} eq 'move') {
+ &Apache::lonnet::delenv('docs.markedcopy');
+ &Apache::lonnet::delenv('docs.markedcopy_nested');
+ &Apache::lonnet::delenv('docs.markedcopy_nestednames');
+ }
+ return ($result,$save_err,$msgsarray,$lockerrors);
+}
+
+sub get_newmap_url {
+ my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
+ $titleref,$allmaps,$newurls) = @_;
+ my $newurl;
+ if ($url=~ m{^/uploaded/}) {
+ $$titleref=&mt('Copy of').' '.$$titleref;
+ }
+ my $now = time;
+ my $suffix=$$.int(rand(100)).$now;
+ my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
+ if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
+ my $path = $1;
+ my $prefix = $2;
+ my $ancestor = $3;
+ if (length($ancestor) > 10) {
+ $ancestor = substr($ancestor,-10,10);
+ }
+ my $newid;
+ if ($prefixchg) {
+ if ($folder =~ /^supplemental/) {
+ $prefix =~ s/^default/supplemental/;
+ } else {
+ $prefix =~ s/^supplemental/default/;
+ }
+ }
+ if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
+ $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
+ } else {
+ $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
+ }
+ my $counter = 0;
+ my $is_unique = &uniqueness_check($newurl);
+ if ($folder =~ /^default/) {
+ if ($allmaps->{$newurl}) {
+ $is_unique = 0;
+ }
+ }
+ while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
+ $counter ++;
+ $suffix ++;
+ if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
+ $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
+ } else {
+ $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
+ }
+ $is_unique = &uniqueness_check($newurl);
+ }
+ if ($is_unique) {
+ $newurls->{$newurl} = 1;
+ } else {
+ if ($url=~/\.page$/) {
+ return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
+ } else {
+ return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
+ }
+ }
+ }
+ return ($newurl);
+}
+
+sub dbcopy {
+ my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
+ my ($url,$result,$errtext);
+ my $url = $dbref->{'src'};
+ if (ref($dbref) eq 'HASH') {
+ if ($url =~ m{/(smppg|bulletinboard)$}) {
+ my $prefix = $1;
+ if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
+ ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
+ my $db_name;
+ my $marker = (split(m{/},$url))[4];
+ $marker=~s/\D//g;
+ if ($dbref->{'src'} =~ m{/smppg$}) {
+ $db_name =
+ &Apache::lonsimplepage::get_db_name($url,$marker,
+ $dbref->{'cdom'},
+ $dbref->{'cnum'});
+ } else {
+ $db_name = 'bulletinpage_'.$marker;
+ }
+ my ($suffix,$freedlock,$error) =
+ &Apache::lonnet::get_timebased_id($prefix,'num','templated',
+ $coursedom,$coursenum,
+ 'concat');
+ if (!$suffix) {
+ if ($prefix eq 'smppg') {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
+ } else {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a bulletin board [_1].',$url);
+ }
+ if ($error) {
+ $errtext .= ' '.$error;
+ }
+ } else {
+ #need to copy the db contents to a new one.
+ my %contents=&Apache::lonnet::dump($db_name,
+ $dbref->{'cdom'},
+ $dbref->{'cnum'});
+ if (exists($contents{'uploaded.photourl'})) {
+ my $photo = $contents{'uploaded.photourl'};
+ my ($subdir,$fname) =
+ ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
+ my $newphoto;
+ if ($fname ne '') {
+ my $content = &Apache::lonnet::getfile($photo);
+ unless ($content eq '-1') {
+ $env{'form.'.$suffix.'.photourl'} = $content;
+ $newphoto =
+ &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
+ delete($env{'form.'.$suffix.'.photourl'});
+ }
+ }
+ if ($newphoto =~ m{^/uploaded/}) {
+ $contents{'uploaded.photourl'} = $newphoto;
+ }
+ }
+ $db_name =~ s{_\d*$ }{_$suffix}x;
+ $result=&Apache::lonnet::put($db_name,\%contents,
+ $coursedom,$coursenum);
+ if ($result eq 'ok') {
+ $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
+ }
+ }
+ if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
+ $lockerrorsref->{$prefix} =
+ '
'.
+ &mt('There was a problem removing a lockfile.');
+ if ($prefix eq 'smppg') {
+ $lockerrorsref->{$prefix} .=
+ &mt('This will prevent creation of additional simple pages in this course.');
+ } else {
+ $lockerrorsref->{$prefix} .= &mt('This will prevent creation of additional bulletin boards in this course.');
+ }
+ $lockerrorsref->{$prefix} .= &mt('Please contact the domain coordinator for your LON-CAPA domain.').'
');
- } else {
+
# ------------------------------------------------------------ Process commands
# ---------------- if they are for this folder and user allowed to make changes
- if (($allowed) && ($env{'form.folder'} eq $folder)) {
+ if (($allowed) && ($env{'form.folder'} eq $folder)) {
# set parameters and change order
- &snapshotbefore();
- if ($env{'form.changeparms'}) {
- my $idx=$env{'form.setparms'};
-# set parameters
- if ($env{'form.changeparms'} eq 'randompick') {
- if ($env{'form.randpick_'.$idx}) {
- &LONCAPA::map::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos');
- &remember_parms($idx,'randompick','set',$env{'form.randpick_'.$idx});
- } else {
- &LONCAPA::map::delparameter($idx,'parameter_randompick');
- &remember_parms($idx,'randompick','del');
- }
- }
- if ($env{'form.changeparms'} eq 'hiddenresource') {
- if ($env{'form.hidprs_'.$idx}) {
- &LONCAPA::map::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
- &remember_parms($idx,'hiddenresource','set',$env{'form.hidprs_'.$idx});
- } else {
- &LONCAPA::map::delparameter($idx,'parameter_hiddenresource');
- &remember_parms($idx,'hiddenresource','del');
- }
- }
- if ($env{'form.changeparms'} eq 'encrypturl') {
- if ($env{'form.encprs_'.$idx}) {
- &LONCAPA::map::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
- &remember_parms($idx,'encrypturl','set',$env{'form.encprs_'.$idx});
- } else {
- &LONCAPA::map::delparameter($idx,'parameter_encrypturl');
- &remember_parms($idx,'encrypturl','del');
- }
- }
-# store the changed version
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
- if ($fatal) {
- $r->print('
'.$errtext.'
');
- return;
- }
- }
+ &snapshotbefore();
- if ($env{'form.newpos'}) {
+ if (&update_parameter()) {
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ return $errtext if ($fatal);
+ }
+
+ if ($env{'form.newpos'} && $env{'form.currentpos'}) {
# change order
- my $newpos=$env{'form.newpos'}-1;
- my $currentpos=$env{'form.currentpos'}-1;
- my $i;
- my @neworder=();
- if ($newpos>$currentpos) {
-# moving stuff up
- for ($i=0;$i<$currentpos;$i++) {
- $neworder[$i]=$LONCAPA::map::order[$i];
- }
- for ($i=$currentpos;$i<$newpos;$i++) {
- $neworder[$i]=$LONCAPA::map::order[$i+1];
- }
- $neworder[$newpos]=$LONCAPA::map::order[$currentpos];
- for ($i=$newpos+1;$i<=$#LONCAPA::map::order;$i++) {
- $neworder[$i]=$LONCAPA::map::order[$i];
- }
- } else {
-# moving stuff down
- for ($i=0;$i<$newpos;$i++) {
- $neworder[$i]=$LONCAPA::map::order[$i];
- }
- $neworder[$newpos]=$LONCAPA::map::order[$currentpos];
- for ($i=$newpos+1;$i<$currentpos+1;$i++) {
- $neworder[$i]=$LONCAPA::map::order[$i-1];
- }
- for ($i=$currentpos+1;$i<=$#LONCAPA::map::order;$i++) {
- $neworder[$i]=$LONCAPA::map::order[$i];
- }
- }
- @LONCAPA::map::order=@neworder;
-# store the changed version
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
- if ($fatal) {
- $r->print('
'.$errtext.'
');
- return;
- }
- }
-
- if ($env{'form.pastemarked'}) {
-# paste resource to end of list
- my $url=$env{'form.markedcopy_url'};
- my $title=$env{'form.markedcopy_title'};
-# Maps need to be copied first
- if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
- $title=&mt('Copy of').' '.$title;
- my $newid=$$.time;
- $url=~/^(.+)\.(\w+)$/;
- my $newurl=$1.$newid.'.'.$2;
- my $storefn=$newurl;
- $storefn=~s{^/\w+/$match_domain/$match_username/}{};
- &Apache::lonclonecourse::writefile
- ($env{'request.course.id'},$storefn,
- &Apache::lonnet::getfile($url));
- $url=$newurl;
- }
- $title = &LONCAPA::map::qtunescape($title);
- my $ext='false';
- if ($url=~/^http\:\/\//) { $ext='true'; }
- $url = &LONCAPA::map::qtunescape($url);
-# Now insert the URL at the bottom
- my $newidx=&LONCAPA::map::getresidx($url);
- $LONCAPA::map::resources[$newidx]=
- $title.':'.$url.':'.$ext.':normal:res';
- $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
-# Store the result
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
- if ($fatal) {
- $r->print('
'.$errtext.'
');
- return;
- }
+ my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
+ splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
- }
- $r->print($upload_output);
- if ($env{'form.cmd'}) {
- my ($cmd,$idx)=split(/\_/,$env{'form.cmd'});
- if ($cmd eq 'del') {
- my (undef,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
- if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
- ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
- &Apache::lonnet::removeuploadedurl($url);
- } else {
- &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
- }
- for (my $i=$idx;$i<$#LONCAPA::map::order;$i++) {
- $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
- }
- $#LONCAPA::map::order--;
- } elsif ($cmd eq 'cut') {
- my (undef,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
- &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
- for (my $i=$idx;$i<$#LONCAPA::map::order;$i++) {
- $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
- }
- $#LONCAPA::map::order--;
- } elsif ($cmd eq 'up') {
- if (($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
- my $i=$LONCAPA::map::order[$idx-1];
- $LONCAPA::map::order[$idx-1] = $LONCAPA::map::order[$idx];
- $LONCAPA::map::order[$idx] = $i;
- }
- } elsif ($cmd eq 'down') {
- if (defined($LONCAPA::map::order[$idx+1])) {
- my $i=$LONCAPA::map::order[$idx+1];
- $LONCAPA::map::order[$idx+1] = $LONCAPA::map::order[$idx];
- $LONCAPA::map::order[$idx] = $i;
- }
- } elsif ($cmd eq 'rename') {
- my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
- my ($rtitle,@rrest)=split(/\:/,
- $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
- my $comment=$env{'form.title'};
- $comment = &LONCAPA::map::qtunescape($comment);
- if ($comment=~/\S/) {
- $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
- $comment.':'.join(':',@rrest);
- }
-# Devalidate title cache
- my $renamed_url=&LONCAPA::map::qtescape($rrest[0]);
- &Apache::lonnet::devalidate_title_cache($renamed_url);
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ return $errtext if ($fatal);
+ }
+
+ if ($env{'form.pastemarked'}) {
+ my %paste_errors;
+ my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
+ &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
+ \%paste_errors);
+ if (ref($pastemsgarray) eq 'ARRAY') {
+ if (@{$pastemsgarray} > 0) {
+
+ $r->print('
'.
+ join(' ',@{$pastemsgarray}).
+ '
');
+ }
}
-# Store the changed version
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,
- $folder.'.'.$container);
- if ($fatal) {
- $r->print('
');
+ }
+ if ($save_error ne '') {
+ return $save_error;
+ }
+ if ($paste_res ne 'ok') {
+ $r->print('
'.$paste_res.'
');
}
+ if (keys(%paste_errors) > 0) {
+ $r->print('
'."\n".
+ &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
+ '
'."\n");
+ foreach my $key (sort(keys(%paste_errors))) {
+ $r->print('
'.$key.'
'."\n");
+ }
+ $r->print('
'."\n");
+ }
+ }
+
+ $r->print($upload_output);
+
+ if (&handle_edit_cmd()) {
+ my $contentchg;
+ if ($env{'form.cmd'} =~ /^(del|cut)_/) {
+ $contentchg = 1;
+ }
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
+ return $errtext if ($fatal);
+ }
# Group import/search
- if ($env{'form.importdetail'}) {
- my @imports;
-# &Apache::lonnet::logthis("imp detail ".$env{'form.importdetail'});
- foreach (split(/\&/,$env{'form.importdetail'})) {
- if (defined($_)) {
- my ($name,$url)=split(/\=/,$_);
- $name=&unescape($name);
- $url=&unescape($url);
- push @imports, $name, $url;
- }
- }
-# Store the changed version
- ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
- $container,'londocs',@imports);
- if ($fatal) {
- $r->print('
'.$errtext.'
');
- return;
+ if ($env{'form.importdetail'}) {
+ my @imports;
+ foreach my $item (split(/\&/,$env{'form.importdetail'})) {
+ 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) =
+ &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
+ if ($locknotfreed) {
+ $r->print($locknotfreed);
+ }
+ if ($suffix) {
+ $url =~ s/_new\./_$suffix./;
+ } else {
+ return $errortxt;
+ }
+ } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
+ my $type = $1;
+ my ($suffix,$errortxt,$locknotfreed) =
+ &new_timebased_suffix($coursedom,$coursenum,$type);
+ if ($locknotfreed) {
+ $r->print($locknotfreed);
+ }
+ if ($suffix) {
+ $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
+ } else {
+ return $errortxt;
+ }
+ } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
+ if ($supplementalflag) {
+ next unless ($1 eq 'supplemental');
+ if ($folder eq 'supplemental') {
+ next unless ($2 eq 'default');
+ } else {
+ next unless ($folder eq 'supplemental_'.$2);
+ }
+ } else {
+ next unless ($1 eq 'docs');
+ if ($folder eq 'default') {
+ next unless ($2 eq 'default');
+ } else {
+ next unless ($folder eq 'default_'.$2);
+ }
+ }
+ }
+ push(@imports, [$name, $url, $residx]);
}
+ }
+ ($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'}) {
- if ($env{'form.importmap'}=~/\w/) {
- foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
- my ($title,$url,$ext,$type)=split(/\:/,$_);
- my $idx=&LONCAPA::map::getresidx($url);
- $LONCAPA::map::resources[$idx]=$_;
- $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
- }
-# Store the changed version
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,
- $folder.'.'.$container);
- if ($fatal) {
- $r->print('
'.$errtext.'
');
- return;
- }
- } else {
- $r->print('
'.&mt('No map selected.').'
');
- }
- }
- &log_differences($plain);
- }
+ if ($env{'form.loadmap'}) {
+ if ($env{'form.importmap'}=~/\w/) {
+ foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
+ my ($title,$url,$ext,$type)=split(/\:/,$res);
+ my $idx=&LONCAPA::map::getresidx($url);
+ $LONCAPA::map::resources[$idx]=$res;
+ $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
+ }
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,
+ $folder.'.'.$container,1);
+ return $errtext if ($fatal);
+ } else {
+ $r->print('
'.&mt('No map selected.').'
');
+
+ }
+ }
+ &log_differences($plain);
+ }
# ---------------------------------------------------------------- End commands
# ---------------------------------------------------------------- Print screen
- my $idx=0;
- my $shown=0;
- if (($ishidden) || ($isencrypted) || ($randompick>=0)) {
- $r->print('
'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'
'
+ }
+ }
+ my $tid = 1;
+ if ($supplementalflag) {
+ $tid = 2;
+ }
+ if ($allowed) {
+ my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
+ $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,$jumpto,
+ $readfile));
+ &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
+ } else {
+ $r->print($to_show);
}
+ return;
}
sub process_file_upload {
my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
# upload a file, if present
- my $parseaction;
- if ($env{'form.parserflag'}) {
+ my ($parseaction,$showupload,$nextphase,$mimetype);
+ if ($env{'form.parserflag'}) {
$parseaction = 'parse';
}
- my $phase_status;
my $folder=$env{'form.folder'};
if ($folder eq '') {
$folder='default';
@@ -1501,18 +2270,15 @@ 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)=
- &mapread($coursenum,$coursedom,$folder.'.'.$container);
+ &mapread($coursenum,$coursedom,$folder.'.'.$container);
if ($#LONCAPA::map::order<1) {
$LONCAPA::map::order[0]=1;
$LONCAPA::map::resources[1]='';
}
- if ($fatal) {
- return 'failed';
- }
my $destination = 'docs/';
if ($folder =~ /^supplemental/) {
$destination = 'supplemental/';
@@ -1522,15 +2288,29 @@ sub process_file_upload {
} elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
$destination .= $2.'/';
}
-# this is for a course, not a user, so set coursedoc flag
-# probably the only place in the system where this should be "1"
+ if ($fatal) {
+ $$upload_output = '
'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'
';
+ return;
+ }
+# this is for a course, not a user, so set context to coursedoc.
my $newidx=&LONCAPA::map::getresidx();
$destination .= $newidx;
- my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
+ my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
$parseaction,$allfiles,
- $codebase);
+ $codebase,undef,undef,undef,undef,
+ undef,undef,\$mimetype);
+ if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
+ my $stored = $1;
+ $showupload = '
';
+ } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
+ $nextphase = 'decompress_uploaded';
+ my $position = scalar(@LONCAPA::map::order)-1;
+ my $noextract = &return_to_editor();
+ my $archiveurl = &HTML::Entities::encode($url,'<>&"');
+ my %archiveitems = (
+ folderpath => $env{'form.folderpath'},
+ cmd => $nextphase,
+ newidx => $newidx,
+ position => $position,
+ phase => $nextphase,
+ comment => $comment,
+ );
+ my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
+ my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
+ $$upload_output = $showupload.
+ &Apache::loncommon::decompress_form($mimetype,
+ $archiveurl,'/adm/coursedocs',$noextract,
+ \%archiveitems,\@current);
}
}
}
- return $phase_status;
+ return $nextphase;
}
-sub ask_for_embedded_content {
- my ($actionurl,$state,$allfiles,$codebase)=@_;
- my $upload_output = '
- ';
- return $upload_output;
+sub get_dir_list {
+ my ($url,$coursenum,$coursedom,$newidx) = @_;
+ my ($destination,$dir_root) = &embedded_destination();
+ my ($dirlistref,$listerror) =
+ &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
+ my @dir_lines;
+ my $dirptr=16384;
+ if (ref($dirlistref) eq 'ARRAY') {
+ foreach my $dir_line (sort
+ {
+ my ($afile)=split('&',$a,2);
+ my ($bfile)=split('&',$b,2);
+ return (lc($afile) cmp lc($bfile));
+ } (@{$dirlistref})) {
+ my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
+ $filename =~ s/\s+$//;
+ next if ($filename =~ /^\.\.?$/);
+ my $isdir = 0;
+ if ($dirptr&$testdir) {
+ $isdir = 1;
+ }
+ push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
+ }
+ }
+ return @dir_lines;
}
-sub process_secondary_uploads {
- my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
- my $folder=$env{'form.folder'};
- my $destination = 'docs/';
- if ($folder =~ /^supplemental/) {
- $destination = 'supplemental/';
- }
- if (($folder eq 'default') || ($folder eq 'supplemental')) {
- $destination .= 'default/';
- } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
- $destination .= $2.'/';
- }
- $destination .= $newidx;
- my ($url,$filename);
- $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
- ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
- return $filename;
+sub is_supplemental_title {
+ my ($title) = @_;
+ return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
}
# --------------------------------------------------------------- An entry line
sub entryline {
- my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
- $title=&HTML::Entities::encode($title,'"<>&\'');
- my $renametitle=$title;
- my $foldertitle=$title;
- my $pagetitle=$title;
- my $orderidx=$LONCAPA::map::order[$index];
- if ($title=~ /^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/ ) {
- $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
- $renametitle=$4;
- $title=''.&Apache::lonlocal::locallocaltime($1).' '.
- &Apache::loncommon::plainname($2,$3).': '.
- $foldertitle;
+ my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
+ $crstype,$pathitem,$supplementalflag,$container)=@_;
+ my ($foldertitle,$renametitle);
+ if (&is_supplemental_title($title)) {
+ ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
+ } else {
+ $title=&HTML::Entities::encode($title,'"<>&\'');
+ $renametitle=$title;
+ $foldertitle=$title;
}
+
+ my $orderidx=$LONCAPA::map::order[$index];
+
$renametitle=~s/\\/\\\\/g;
$renametitle=~s/\"\;/\\\"/g;
- my $line='
';
+ $renametitle=~s/ /%20/g;
+ my $line=&Apache::loncommon::start_data_table_row();
+ my ($form_start,$form_end,$form_common);
# Edit commands
- my $container;
- my $folderpath;
+ my ($esc_path, $path, $symb);
if ($env{'form.folderpath'}) {
- $container = 'sequence';
- $folderpath=&escape($env{'form.folderpath'});
+ $esc_path=&escape($env{'form.folderpath'});
+ $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
}
- my ($pagepath,$pagesymb);
- if ($env{'form.pagepath'}) {
- $container = 'page';
- $pagepath=&escape($env{'form.pagepath'});
- $pagesymb=&escape($env{'form.pagesymb'});
- }
- my $cpinfo='';
- if ($env{'form.markedcopy_url'}) {
- $cpinfo='&markedcopy_url='.
- &escape($env{'form.markedcopy_url'}).
- '&markedcopy_title='.
- &escape($env{'form.markedcopy_title'});
+ my $isexternal;
+ if ($residx) {
+ my $currurl = $url;
+ $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
+ 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 ($renamelink,%lt);
if ($allowed) {
my $incindex=$index+1;
my $selectbox='';
- if (($folder!~/^supplemental/) &&
- ($#LONCAPA::map::order>0) &&
+ if (($#LONCAPA::map::order>0) &&
((split(/\:/,
- $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
- ne '') &&
+ $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
+ ne '') &&
((split(/\:/,
- $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
+ $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
ne '')) {
$selectbox=
''.
- '
";
+ $line.=&Apache::loncommon::end_data_table_row();
return $line;
}
-# ---------------------------------------------------------------- tie the hash
+sub new_timebased_suffix {
+ my ($coursedom,$coursenum,$type,$area,$container) = @_;
+ my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
+ if ($type eq 'map') {
+ $prefix = 'docs';
+ if ($area eq 'supplemental') {
+ $prefix = 'supp';
+ }
+ $prefix .= $container;
+ $namespace = 'uploadedmaps';
+ } else {
+ $prefix = $type;
+ $namespace = 'templated';
+ }
+ $idtype = 'concat';
+ my ($suffix,$freedlock,$error) =
+ &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,
+ $coursedom,$coursenum);
+ if (!$suffix) {
+ if ($type eq 'map') {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
+ } elsif ($type eq 'smppg') {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
+ } else {
+ $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new bulletin board.');
+ }
+ if ($error) {
+ $errtext .= ' '.$error;
+ }
+ }
+ if ($freedlock ne 'ok') {
+ $locknotfreed =
+ '
'.
+ &mt('There was a problem removing a lockfile.').' ';
+ if ($type eq 'map') {
+ &mt('This will prevent creation of additional folders or composite pages in this course.');
+ } elsif ($type eq 'smppg') {
+ $locknotfreed .=
+ &mt('This will prevent creation of additional simple pages in this course.');
+ } else {
+ $locknotfreed .=
+ &mt('This will prevent creation of additional bulletin boards in this course.');
+ }
+ $locknotfreed .=
+ ' '.&mt('Please contact the domain coordinator for your LON-CAPA domain.').
+ '
';
+ }
+ return ($suffix,$errtext,$locknotfreed);
+}
+
+=pod
+
+=item tiehash()
+
+tie the hash
+
+=cut
sub tiehash {
my ($mode)=@_;
@@ -1934,7 +2899,7 @@ sub tiehash {
$hashtied=1;
}
}
- }
+ }
}
sub untiehash {
@@ -1943,7 +2908,8 @@ sub untiehash {
return OK;
}
-# --------------------------------------------------------------- check on this
+
+
sub checkonthis {
my ($r,$url,$level,$title)=@_;
@@ -1952,6 +2918,9 @@ sub checkonthis {
$r->rflush();
if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
$r->print("\n ");
+ if ($level==0) {
+ $r->print(" ");
+ }
for (my $i=0;$i<=$level*5;$i++) {
$r->print(' ');
}
@@ -1961,7 +2930,7 @@ sub checkonthis {
my $result=&Apache::lonnet::repcopy(
&Apache::lonnet::filelocation('',$url));
if ($result eq 'ok') {
- $r->print(''.&mt('ok').'');
+ $r->print(''.&mt('ok').'');
$r->rflush();
&Apache::lonnet::countacc($url);
$url=~/\.(\w+)$/;
@@ -1971,7 +2940,7 @@ sub checkonthis {
for (my $i=0;$i<=$level*5;$i++) {
$r->print(' ');
}
- $r->print('- '.&mt('Rendering').': ');
+ $r->print('- '.&mt('Rendering:').' ');
my ($errorcount,$warningcount)=split(/:/,
&Apache::lonnet::ssi_body($url,
('grade_target'=>'web',
@@ -1979,96 +2948,120 @@ sub checkonthis {
if (($errorcount) ||
($warningcount)) {
if ($errorcount) {
- $r->print(''.
- $errorcount.' '.
- &mt('error(s)').' ');
+ $r->print(''.
+ &mt('[quant,_1,error]',$errorcount).'');
}
if ($warningcount) {
- $r->print(''.
- $warningcount.' '.
- &mt('warning(s)').'');
+ $r->print(''.
+ &mt('[quant,_1,warning]',$warningcount).'');
}
} else {
- $r->print(''.&mt('ok').'');
+ $r->print(''.&mt('ok').'');
}
$r->rflush();
}
my $dependencies=
&Apache::lonnet::metadata($url,'dependencies');
- foreach (split(/\,/,$dependencies)) {
- if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
- &checkonthis($r,$_,$level+1);
+ foreach my $dep (split(/\,/,$dependencies)) {
+ if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
+ &checkonthis($r,$dep,$level+1);
}
}
} elsif ($result eq 'unavailable') {
- $r->print(''.&mt('connection down').'');
+ $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').'');
+ $r->print(''.&mt('unable to verify variable URL').'');
}
} else {
- $r->print(''.&mt('access denied').'');
+ $r->print(''.&mt('access denied').'');
}
- }
- }
+ }
+ }
}
-#
-# ----------------------------------------------------------------- List Symbs
-#
+
+=pod
+
+=item list_symbs()
+
+List Content Identifiers
+
+=cut
+
sub list_symbs {
my ($r) = @_;
- $r->print(&Apache::loncommon::start_page('Symb List'));
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
+ my $crstype = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
+ $r->print(&startContentScreen('tools'));
my $navmap = Apache::lonnavmaps::navmap->new();
- $r->print("
\n");
- foreach my $res ($navmap->retrieveResources()) {
- $r->print($res->compTitle()."\t".$res->symb()."\n");
+ if (!defined($navmap)) {
+ $r->print('
'.&mt('Retrieval of List Failed').'
'.
+ '
'.
+ &mt('Unable to retrieve information about course contents').
+ '
');
+ &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
+ } else {
+ $r->print('
\n");
- $r->print(''.&mt('Return to DOCS').'');
+ $r->print(&endContentScreen());
}
-#
-# -------------------------------------------------------------- Verify Content
-#
sub verifycontent {
my ($r) = @_;
- my $type = &Apache::loncommon::course_type();
- my $loaderror=&Apache::lonnet::overloaderror($r);
- if ($loaderror) { return $loaderror; }
- $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
+ my $crstype = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
+ $r->print(&startContentScreen('tools'));
+ $r->print('
'.&mt($crstype.' content verification').'
');
$hashtied=0;
undef %alreadyseen;
%alreadyseen=();
&tiehash();
- foreach (keys %hash) {
- if ($hash{$_}=~/\.(page|sequence)$/) {
- if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) {
- $r->print(''.
- &mt('The following sequence or page is included more than once in your '.$type.': ').
- &unescape($hash{$_}).' '.
- &mt('Note that grading records for problems included in this sequence or folder will overlap.'));
+
+ foreach my $key (keys(%hash)) {
+ if ($hash{$key}=~/\.(page|sequence)$/) {
+ if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
+ $r->print(''.
+ &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
+ &unescape($hash{$key}).' '.
+ &mt('Note that grading records for problems included in this sequence or folder will overlap.').'');
}
}
- if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$_})})) {
- &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
+ if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
+ &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
}
}
&untiehash();
- $r->print('
');
+ $r->print(&endContentScreen());
}
-# -------------------------------------------------------------- Check Versions
-
sub devalidateversioncache {
my $src=shift;
&Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
@@ -2077,9 +3070,11 @@ sub devalidateversioncache {
sub checkversions {
my ($r) = @_;
- my $type = &Apache::loncommon::course_type();
- $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
- $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));
+ my $crstype = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
+ $r->print(&startContentScreen('tools'));
+
my $header='';
my $startsel='';
my $monthsel='';
@@ -2098,16 +3093,16 @@ sub checkversions {
my %newsetversions=();
if ($env{'form.setmostrecent'}) {
$haschanged=1;
- foreach (keys %hash) {
- if ($_=~/^ids\_(\/res\/.+)$/) {
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
$newsetversions{$1}='mostrecent';
&devalidateversioncache($1);
}
}
} elsif ($env{'form.setcurrent'}) {
$haschanged=1;
- foreach (keys %hash) {
- if ($_=~/^ids\_(\/res\/.+)$/) {
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
my $getvers=&Apache::lonnet::getversion($1);
if ($getvers>0) {
$newsetversions{$1}=$getvers;
@@ -2117,11 +3112,11 @@ sub checkversions {
}
} elsif ($env{'form.setversions'}) {
$haschanged=1;
- foreach (keys %env) {
- if ($_=~/^form\.set_version_(.+)$/) {
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.set_version_(.+)$/) {
my $src=$1;
- if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
- $newsetversions{$src}=$env{$_};
+ if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
+ $newsetversions{$src}=$env{$key};
&devalidateversioncache($src);
}
}
@@ -2130,20 +3125,22 @@ sub checkversions {
if ($haschanged) {
if (&Apache::lonnet::put('resourceversions',\%newsetversions,
$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').'
');
+ $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
+ $r->print(&Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
} else {
- $r->print('
'.&mt('An Error Occured while Attempting to Store your Version Settings').'
');
+ $r->print(&Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
}
&mark_hash_old();
}
&changewarning($r,'');
if ($env{'form.timerange'} eq 'all') {
# show all documents
- $header=&mt('All Documents in '.$type);
- $allsel=1;
- foreach (keys %hash) {
- if ($_=~/^ids\_(\/res\/.+)$/) {
+ $header=&mt('All Documents in '.$crstype);
+ $allsel=' selected="selected"';
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
my $src=$1;
$changes{$src}=1;
}
@@ -2153,7 +3150,7 @@ sub checkversions {
%changes=&Apache::lonnet::dump
('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
- my $firstkey=(keys %changes)[0];
+ my $firstkey=(keys(%changes))[0];
unless ($firstkey=~/^error\:/) {
unless ($env{'form.timerange'}) {
$env{'form.timerange'}=604800;
@@ -2162,19 +3159,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 {
@@ -2185,139 +3182,140 @@ sub checkversions {
$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 '.$type,
+ ('st' => 'Version changes since start of '.$crstype,
'lm' => 'Version changes since last Month',
'lw' => 'Version changes since last Week',
'sy' => 'Version changes since Yesterday',
'al' => 'All Resources (possibly large output)',
+ 'cd' => 'Change display',
'sd' => 'Display',
'fi' => 'File',
'md' => 'Modification Date',
'mr' => 'Most recently published Version',
- 've' => 'Version used in '.$type,
- 'vu' => 'Set Version to be used in '.$type,
-'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
+ 've' => 'Version used in '.$crstype,
+ 'vu' => 'Set Version to be used in '.$crstype,
+'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
- 'di' => 'Differences');
+ 'di' => 'Differences',
+ 'save' => 'Save changes',
+ 'vers' => 'Version choice(s) for specific resources',
+ 'act' => 'Actions');
$r->print(<$header