+
+
+
+$name
+
+
+$initialtext
+
+
+END
+ $env{'form.output'}=$newhtml;
+ my $result =
+ &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
+ 'output',
+ "$filepath/$residx/$fname.html");
+ if ($result =~ m{^/uploaded/}) {
+ $url = $result;
+ if ($filepath =~ /^supplemental/) {
+ $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
+ $env{'user.domain'}.'___&&&___'.$name;
+ }
+ } else {
+ return (&mt('Failed to save new web page.'),1);
+ }
+ }
+ $LONCAPA::map::resources[$residx] =
join(':', ($name, $url, $ext, 'normal', 'res'));
}
}
- return &storemap($coursenum, $coursedom, $folder.'.'.$container);
-}
-
-sub breadcrumbs {
- my ($where,$allowed,$type)=@_;
- &Apache::lonhtmlcommon::clear_breadcrumbs();
- my (@folders);
- if ($env{'form.pagepath'}) {
- @folders = split('&',$env{'form.pagepath'});
- } else {
- @folders=split('&',$env{'form.folderpath'});
- }
- my $folderpath;
- my $cpinfo='';
- 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='/adm/coursedocs?folderpath='.
- &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 ($importuploaded) {
+ my %import_errors;
+ my %updated = (
+ removefrommap => \%removefrommap,
+ removeparam => \%removeparam,
+ );
+ my ($result,$msgsarray,$lockerror) =
+ &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";
}
- if ($2) { $ishidden=1; }
- if ($3) { $isencrypted=1; }
- if ($4 ne '') { $is_random_order = 1; }
- if ($folder eq 'supplemental') {
- if ($allowed) {
- $name = &mt('Supplemental '.$type.' Documents');
- } else {
- $name = &mt($type.' Documents');
- }
+ $fixuperrors .= '
'."\n";
+ }
+ if (ref($msgsarray) eq 'ARRAY') {
+ if (@{$msgsarray} > 0) {
+ $fixuperrors .= ''.
+ join('
',@{$msgsarray}).
+ '
';
}
- &Apache::lonhtmlcommon::add_breadcrumb(
- {'href'=>$url.$cpinfo,
- 'title'=>$name,
- 'text'=>''.
- $name.'',
- 'no_mt'=>1,
- });
- $plain.=$name.' > ';
- }
- $plain=~s/\>\;\s*$//;
- return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
- 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
+ }
+ if ($lockerror) {
+ $fixuperrors .= ''.
+ $lockerror.
+ '
';
+ }
+ }
+ my ($errtext,$fatal) =
+ &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
+ return ($errtext,$fatal,$fixuperrors);
}
sub log_docs {
- return &Apache::lonnet::instructor_log('docslog',@_);
+ return &Apache::lonnet::write_log('course','docslog',@_);
}
{
@@ -1081,39 +468,71 @@ sub log_docs {
}
}
-
-
-
-
sub docs_change_log {
- my ($r)=@_;
- my $folder=$env{'form.folder'};
- $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
+ my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
+ my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
+ my $js = ''."\n";
+ $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
+ $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
+ my %orderhash;
+ my $container='sequence';
+ my $pathitem;
+ if ($env{'form.folderpath'} =~ /\:1$/) {
+ $container='page';
+ }
+ 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{^/}{};
+ my $tid = 1;
+ if ($supplementalflag) {
+ $tid = 2;
+ }
+ my ($breadcrumbtrail) =
+ &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
+ $r->print($breadcrumbtrail.
+ &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
+ $readfile));
my %docslog=&Apache::lonnet::dump('nohist_docslog',
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
- $r->print('');
+ my $filter = &Apache::loncommon::display_filter('docslog')."\n".
+ $pathitem."\n".
+ ''.
+ (' 'x2).'';
+ $r->print(''.
+ '
');
$r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
''.&mt('Time').' | '.&mt('User').' | '.&mt('Folder').' | '.&mt('Before').' | '.
&mt('After').' | '.
@@ -1130,7 +549,7 @@ sub docs_change_log {
foreach my $key (@changes) {
$wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
}
- if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
+ if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
}
my $count = 0;
my $time =
@@ -1157,18 +576,30 @@ sub docs_change_log {
':'.$docslog{$id}{'exe_udom'}.''.
$send_msg_link.''.
$docslog{$id}{'logentry'}{'folder'}.' | ');
+ my $is_supp = 0;
+ if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
+ $is_supp = 1;
+ }
# Before
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
if ($oldname ne $newname) {
- $r->print(&LONCAPA::map::qtescape($oldname));
+ my $shown = &LONCAPA::map::qtescape($oldname);
+ if ($is_supp) {
+ $shown = &Apache::loncommon::parse_supplemental_title($shown);
+ }
+ $r->print($shown);
}
}
$r->print('');
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
- $r->print('- '.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'
');
+ my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
+ if ($is_supp) {
+ $shown = &Apache::loncommon::parse_supplemental_title($shown);
+ }
+ $r->print('- '.$shown.'
');
}
}
$r->print(' ');
@@ -1179,13 +610,21 @@ sub docs_change_log {
my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
if ($oldname ne '' && $oldname ne $newname) {
- $r->print(&LONCAPA::map::qtescape($newname));
+ my $shown = &LONCAPA::map::qtescape($newname);
+ if ($is_supp) {
+ $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
+ }
+ $r->print($shown);
}
- }
+ }
$r->print('');
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
- $r->print('- '.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'
');
+ 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(' ');
@@ -1193,6 +632,7 @@ sub docs_change_log {
$r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':');
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})
@@ -1207,11 +647,14 @@ 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_data_table()."\n".
+ &makesimpleeditform($pathitem)."\n".
+ '');
+ $r->print(&endContentScreen());
}
sub update_paste_buffer {
- my ($coursenum,$coursedom) = @_;
+ my ($coursenum,$coursedom,$folder) = @_;
return if (!defined($env{'form.markcopy'}));
return if (!defined($env{'form.copyfolder'}));
@@ -1219,158 +662,698 @@ sub update_paste_buffer {
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) = &parse_supplemental_title($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//};
- &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
- 'docs.markedcopy_url' => $url});
+ (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) = @_;
+ my ($r,$container,$folder,$coursedom,$coursenum) = @_;
return if (!defined($env{'docs.markedcopy_url'}));
- $r->print(<
-ENDPASTE
- $r->print(' ');
-
- my $type;
+ 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)(?::|:))//} ) {
- $type = &mt('External Resource');
- $r->print($type.': '.
- &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
- &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
- } else {
- my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
- my $icon = &Apache::loncommon::icon($extension);
- if ($extension eq 'sequence' &&
- $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
- $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
- $icon .= '/folder_closed.gif';
- }
- $icon = '';
- $r->print($icon.$type.': '. &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
+ $is_external = 1;
}
- if ($container eq 'page') {
- $r->print('
-
-
-');
+
+ 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 {
- $r->print('
+ $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 =' ';
+ return;
+}
+
+function hidePasteOptions() {
+ document.getElementById('pasteoptions').style.display='none';
+ document.getElementById('pasteoptionstext').innerHTML ='';
+ return;
+}
+
+END
+
+}
+
+
sub do_paste_from_buffer {
- my ($coursenum,$coursedom,$folder) = @_;
+ my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
+# Early out if paste buffer is empty
if (!$env{'form.pastemarked'}) {
- return;
+ 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'));
+ }
}
-# paste resource to end of list
+# 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'});
-# Maps need to be copied first
- if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
- $title=&mt('Copy of').' '.$title;
- my $newid=$$.int(rand(100)).time;
- my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
- if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
- my $path = $1;
- my $prefix = $2;
- my $ancestor = $3;
- if (length($ancestor) > 10) {
- $ancestor = substr($ancestor,-10,10);
+
+ 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.'));
}
- $oldid = $path.$prefix.$ancestor;
}
- my $counter = 0;
- my $newurl=$oldid.$newid.'.'.$ext;
- my $is_unique = &uniqueness_check($newurl);
- while (!$is_unique && $counter < 100) {
- $counter ++;
- $newid ++;
- $newurl = $oldid.$newid;
- $is_unique = &uniqueness_check($newurl);
- }
- if (!$is_unique) {
- if ($url=~/\.page$/) {
- return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
- } else {
- return &mt('Paste failed: an error occurred creating a unique URL for the folder');
+# 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);
+ }
}
- }
- my $storefn=$newurl;
- $storefn=~s{^/\w+/$match_domain/$match_username/}{};
- my $paste_map_result =
- &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
- &Apache::lonnet::getfile($url));
- if ($paste_map_result eq '/adm/notfound.html') {
- if ($url=~/\.page$/) {
- return &mt('Paste failed: an error occurred saving the composite page');
- } else {
- return &mt('Paste failed: an error occurred saving the folder');
+ foreach my $item (@nested) {
+ if ($env{'form.docs.markedcopy_'.$item} eq 'move') {
+ $tomove{$type.'_'.$item} = 1;
+ }
}
}
- $url = $newurl;
}
+
+# 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
- if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
- &Apache::lonnet::delenv('docs.markedcopy');
+ &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.'));
+ }
+ }
+ }
}
- if ($url=~ m{/smppg$}) {
- my $db_name = &Apache::lonsimplepage::get_db_name($url);
- if ($db_name =~ /^smppage_/) {
- #simple pages, need to copy the db contents to a new one.
- my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
- my $now = time();
- $db_name =~ s{_\d*$ }{_$now}x;
- my $result=&Apache::lonnet::put($db_name,\%contents,
- $coursedom,$coursenum);
- $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
- $title=&mt('Copy of').' '.$title;
- }
+ 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
- my $newidx = &LONCAPA::map::getresidx($url);
- if ($env{'docs.markedcopy_supplemental'}) {
- if ($folder =~ /^supplemental/) {
- $title = $env{'docs.markedcopy_supplemental'};
+ $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 {
- (undef,undef,$title) =
- &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
+ if ($folder=~/^supplemental/) {
+ $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
+ $env{'user.domain'}.'___&&&___'.$title;
+ }
}
- } 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;
}
}
- $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
- push(@LONCAPA::map::order, $newidx);
- return 'ok';
-# Store the result
+ 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.').' ';
+ }
+ }
+ } elsif ($url =~ m{/syllabus$}) {
+ if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
+ ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
+ if (($dbref->{'cdom'} ne $coursedom) ||
+ ($dbref->{'cnum'} ne $coursenum)) {
+ my %contents=&Apache::lonnet::dump('syllabus',
+ $dbref->{'cdom'},
+ $dbref->{'cnum'});
+ $result=&Apache::lonnet::put('syllabus',\%contents,
+ $coursedom,$coursenum);
+ }
+ }
+ }
+ }
+ return ($url,$result,$errtext);
}
sub uniqueness_check {
@@ -1381,12 +1364,524 @@ sub uniqueness_check {
$url=&LONCAPA::map::qtescape($url);
if ($newurl eq $url) {
$unique = 0;
- last;
+ last;
}
}
return $unique;
}
+sub contained_map_check {
+ my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
+ $allmaps) = @_;
+ my $content = &Apache::lonnet::getfile($url);
+ unless ($content eq '-1') {
+ my $parser = HTML::TokeParser->new(\$content);
+ $parser->attr_encoded(1);
+ while (my $token = $parser->get_token) {
+ next if ($token->[0] ne 'S');
+ if ($token->[1] eq 'resource') {
+ next if ($token->[2]->{'type'} eq 'zombie');
+ my $ressrc = $token->[2]->{'src'};
+ if ($folder =~ /^supplemental/) {
+ unless (&supp_pasteable($ressrc)) {
+ $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
+ next;
+ }
+ }
+ if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
+ if ($1 eq 'uploaded') {
+ $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
+ $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
+ } else {
+ if ($allmaps->{$ressrc}) {
+ $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
+ } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
+ $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
+ } else {
+ $addedmaps->{$ressrc} = [$url];
+ }
+ }
+ &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
+ $addedmaps,$hierarchy,$titles,$allmaps);
+ }
+ } elsif ($token->[1] eq 'param') {
+ if ($folder =~ /^supplemental/) {
+ if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
+ push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
+ } else {
+ $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
+ }
+ }
+ }
+ }
+ }
+ return;
+}
+
+sub url_paste_fixups {
+ my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
+ $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
+ $mapchanges,$tomove,$newsubdir,$newurls) = @_;
+ my $checktitle;
+ if (($prefixchg) &&
+ ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
+ $checktitle = 1;
+ }
+ my $skip;
+ if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
+ my $mapid = $1.$2;
+ if ($tomove->{$mapid}) {
+ $skip = 1;
+ }
+ }
+ my $file = &Apache::lonnet::getfile($oldurl);
+ return if ($file eq '-1');
+ my $parser = HTML::TokeParser->new(\$file);
+ $parser->attr_encoded(1);
+ my $changed = 0;
+ while (my $token = $parser->get_token) {
+ next if ($token->[0] ne 'S');
+ if ($token->[1] eq 'resource') {
+ my $ressrc = $token->[2]->{'src'};
+ next if ($ressrc eq '');
+ my $id = $token->[2]->{'id'};
+ my $title = $token->[2]->{'title'};
+ if ($checktitle) {
+ if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
+ $retitles->{$oldurl}{$id} = $ressrc;
+ }
+ }
+ next if ($token->[2]->{'type'} eq 'external');
+ if ($token->[2]->{'type'} eq 'zombie') {
+ next if ($skip);
+ $zombies->{$oldurl}{$id} = $ressrc;
+ $changed = 1;
+ } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
+ my $srcdom = $1;
+ my $srcnum = $2;
+ my $rem = $3;
+ my $newurl;
+ my $mapname;
+ if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
+ my $prefix = $1;
+ $mapname = $prefix.$2;
+ if ($tomove->{$mapname}) {
+ &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
+ $srcdom,$srcnum,$allmaps,$rewrites,
+ $retitles,$copies,$dbcopies,$zombies,
+ $params,$mapmoves,$mapchanges,$tomove,
+ $newsubdir,$newurls);
+ next;
+ } else {
+ ($newurl,my $error) =
+ &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
+ $srcdom,$srcnum,\$title,$allmaps,$newurls);
+ if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
+ $newsubdir->{$ressrc} = $1;
+ }
+ if ($error) {
+ next;
+ }
+ }
+ }
+ if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
+ ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
+
+ if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
+ $rewrites->{$oldurl}{$id} = $ressrc;
+ $mapchanges->{$ressrc} = 1;
+ unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
+ $cnum,$srcdom,$srcnum,$allmaps,
+ $rewrites,$retitles,$copies,$dbcopies,
+ $zombies,$params,$mapmoves,$mapchanges,
+ $tomove,$newsubdir,$newurls)) {
+ $mapmoves->{$ressrc} = 1;
+ }
+ $changed = 1;
+ } else {
+ $rewrites->{$oldurl}{$id} = $ressrc;
+ $copies->{$oldurl}{$ressrc} = $id;
+ $changed = 1;
+ }
+ }
+ } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
+ next if ($skip);
+ my $srcdom = $1;
+ my $srcnum = $2;
+ if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
+ $rewrites->{$oldurl}{$id} = $ressrc;
+ $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
+ $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
+ $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
+ $changed = 1;
+ }
+ } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
+ if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
+ ($env{'form.docs.markedcopy_options'} ne 'move')) {
+ $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
+ $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
+ $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
+ $changed = 1;
+ }
+ } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
+ next if ($skip);
+ my $srcdom = $1;
+ my $srcnum = $2;
+ if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
+ $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
+ $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
+ $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
+ $changed = 1;
+ }
+ }
+ } elsif ($token->[1] eq 'param') {
+ next if ($skip);
+ my $to = $token->[2]->{'to'};
+ if ($to ne '') {
+ if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
+ push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
+ } else {
+ @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
+ }
+ }
+ }
+ }
+ return $changed;
+}
+
+sub apply_fixups {
+ 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,@msgs,
+ %lockerrors,$lockmsg);
+ 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 (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);
+ }
+ }
+ if ($key eq $oldurl) {
+ if ((exists($docmoves{$key}))) {
+ unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
+ push(@allcopies,$oldurl);
+ }
+ }
+ }
+ if (@allcopies > 0) {
+ foreach my $item (@allcopies) {
+ my ($relpath,$oldsubdir,$fname) =
+ ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
+ if ($fname ne '') {
+ my $content = &Apache::lonnet::getfile($item);
+ unless ($content eq '-1') {
+ my $storefn;
+ if (($key eq $oldurl) && (exists($docmoves{$key}))) {
+ $storefn = $docmoves{$key};
+ } else {
+ $storefn = $relpath;
+ $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
+ 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}/#;
+ }
+ }
+ ©_dependencies($item,$storefn,$relpath,$errors,\$content);
+ my $copyurl =
+ &Apache::lonclonecourse::writefile($env{'request.course.id'},
+ $storefn.$fname,$content);
+ if ($copyurl eq '/adm/notfound.html') {
+ if (exists($docmoves{$oldurl})) {
+ return &mt('Paste failed: an error occurred copying the file.');
+ } elsif (ref($errors) eq 'HASH') {
+ $errors->{$item} = 1;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ foreach my $key (keys(%mapmoves)) {
+ my $storefn=$key;
+ $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
+ 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}/;
+ }
+ my $mapcontent = &Apache::lonnet::getfile($key);
+ if ($mapcontent eq '-1') {
+ if (ref($errors) eq 'HASH') {
+ $errors->{$key} = 1;
+ }
+ } else {
+ my $newmap =
+ &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
+ $mapcontent);
+ if ($newmap eq '/adm/notfound.html') {
+ if (ref($errors) eq 'HASH') {
+ $errors->{$key} = 1;
+ }
+ }
+ }
+ }
+ my %updates;
+ if ($is_map) {
+ 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($retitles{$key}) eq 'HASH') {
+ %toretitle = %{$retitles{$key}};
+ }
+ if (ref($removefrommap{$key}) eq 'HASH') {
+ %toremove = %{$removefrommap{$key}};
+ }
+ if (ref($removeparam{$key}) eq 'HASH') {
+ %remparam = %{$removeparam{$key}};
+ }
+ if (ref($zombies{$key}) eq 'HASH') {
+ %zombie = %{$zombies{$key}};
+ }
+ if (ref($dbcopies{$key}) eq 'HASH') {
+ foreach my $idx (keys(%{$dbcopies{$key}})) {
+ if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
+ my ($newurl,$result,$errtext) =
+ &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
+ if ($result eq 'ok') {
+ $newdb{$idx} = $newurl;
+ } elsif (ref($errors) eq 'HASH') {
+ $errors->{$key} = 1;
+ }
+ push(@msgs,$errtext);
+ }
+ }
+ }
+ if (ref($params{$key}) eq 'HASH') {
+ %currparam = %{$params{$key}};
+ }
+ my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
+ if ($fatal) {
+ return ($errtext);
+ }
+ for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
+ if (defined($LONCAPA::map::zombies[$i])) {
+ my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
+ if ($zombie{$i} eq $src) {
+ undef($LONCAPA::map::zombies[$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[$idx]);
+ if ((exists($toremove{$idx})) && ($toremove{$idx} eq $src)) {
+ splice(@LONCAPA::map::order,$i,1);
+ if (ref($currparam{$idx}) eq 'ARRAY') {
+ foreach my $name (@{$currparam{$idx}}) {
+ &LONCAPA::map::delparameter($idx,'parameter_'.$name);
+ }
+ }
+ next;
+ }
+ my $origsrc = $src;
+ if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
+ if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
+ $changed = 1;
+ }
+ }
+ if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
+ $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
+ if ($origsrc =~ m{^/uploaded/}) {
+ if ($prefixchg && $before{'map'} && $after{'map'}) {
+ if ($src =~ /\.(page|sequence)$/) {
+ $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'}#;
+ }
+ }
+ if ($origsrc =~ /\.(page|sequence)$/) {
+ if ($newsubdir{$origsrc}) {
+ $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
+ }
+ } elsif ($newsubdir{$key}) {
+ $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
+ }
+ }
+ $changed = 1;
+ } elsif ($newdb{$idx} ne '') {
+ $src = $newdb{$idx};
+ $changed = 1;
+ }
+ if ($changed) {
+ $LONCAPA::map::resources[$idx] = join(':',($title,$src,$ext,$type));
+ }
+ }
+ }
+ foreach my $idx (keys(%remparam)) {
+ if (ref($remparam{$idx}) eq 'ARRAY') {
+ foreach my $name (@{$remparam{$idx}}) {
+ &LONCAPA::map::delparameter($idx,'parameter_'.$name);
+ }
+ }
+ }
+ if (values(%lockerrors) > 0) {
+ $lockmsg = join(' ',values(%lockerrors));
+ }
+ my $storefn;
+ if ($key eq $oldurl) {
+ $storefn = $url;
+ $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
+ } else {
+ $storefn = $key;
+ $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
+ 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}/;
+ }
+ }
+ my $report;
+ if ($folder !~ /^supplemental/) {
+ $report = 1;
+ }
+ (my $outtext,$errtext) =
+ &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
+ if ($errtext) {
+ if ($caller eq 'paste') {
+ return (&mt('Paste failed: an error occurred saving the folder or page.'));
+ }
+ }
+ }
+ }
+ return ('ok',\@msgs,$lockmsg);
+}
+
+sub copy_dependencies {
+ my ($item,$storefn,$relpath,$errors,$contentref) = @_;
+ my $content;
+ if (ref($contentref)) {
+ $content = $$contentref;
+ } else {
+ $content = &Apache::lonnet::getfile($item);
+ }
+ unless ($content eq '-1') {
+ my $mm = new File::MMagic;
+ my $mimetype = $mm->checktype_contents($content);
+ if ($mimetype eq 'text/html') {
+ my (%allfiles,%codebase,$state);
+ my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
+ if ($res eq 'ok') {
+ my ($numexisting,$numpathchanges,$existing);
+ (undef,$numexisting,$numpathchanges,$existing) =
+ &Apache::loncommon::ask_for_embedded_content(
+ '/adm/coursedocs',$state,\%allfiles,\%codebase,
+ {'error_on_invalid_names' => 1,
+ 'ignore_remote_references' => 1,
+ 'docs_url' => $item,
+ 'context' => 'paste'});
+ if ($numexisting > 0) {
+ if (ref($existing) eq 'HASH') {
+ foreach my $dep (keys(%{$existing})) {
+ my $depfile = $dep;
+ unless ($depfile =~ m{^\Q$relpath\E}) {
+ $depfile = $relpath.$dep;
+ }
+ my $depcontent = &Apache::lonnet::getfile($depfile);
+ unless ($depcontent eq '-1') {
+ my $storedep = $dep;
+ $storedep =~ s{^\Q$relpath\E}{};
+ my $dep_url =
+ &Apache::lonclonecourse::writefile(
+ $env{'request.course.id'},
+ $storefn.$storedep,$depcontent);
+ if ($dep_url eq '/adm/notfound.html') {
+ if (ref($errors) eq 'HASH') {
+ $errors->{$depfile} = 1;
+ }
+ } else {
+ ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return;
+}
+
my %parameter_type = ( 'randompick' => 'int_pos',
'hiddenresource' => 'string_yesno',
'encrypturl' => 'string_yesno',
@@ -1394,29 +1889,98 @@ my %parameter_type = ( 'randompick'
my $valid_parameters_re = join('|',keys(%parameter_type));
# set parameters
sub update_parameter {
+ if ($env{'form.changeparms'} eq 'all') {
+ my (@allidx,@allmapidx,%allchecked,%currchecked);
+ %allchecked = (
+ 'hiddenresource' => {},
+ 'encrypturl' => {},
+ 'randompick' => {},
+ 'randomorder' => {},
+ );
+ foreach my $which (keys(%allchecked)) {
+ $env{'form.all'.$which} =~ s/,$//;
+ if ($which eq 'randompick') {
+ foreach my $item (split(/,/,$env{'form.all'.$which})) {
+ my ($res,$value) = split(/:/,$item);
+ if ($value =~ /^\d+$/) {
+ $allchecked{$which}{$res} = $value;
+ }
+ }
+ } else {
+ map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
+ }
+ }
+ my $haschanges = 0;
+ foreach my $res (@LONCAPA::map::order) {
+ my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
+ $name=&LONCAPA::map::qtescape($name);
+ $url=&LONCAPA::map::qtescape($url);
+ next unless ($name && $url);
+ my $is_map;
+ if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
+ $is_map = 1;
+ }
+ foreach my $which (keys(%allchecked)) {
+ if (($which eq 'randompick' || $which eq 'randomorder')) {
+ next if (!$is_map);
+ }
+ my $oldvalue = 0;
+ my $newvalue = 0;
+ if ($allchecked{$which}{$res}) {
+ $newvalue = $allchecked{$which}{$res};
+ }
+ my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
+ if ($which eq 'randompick') {
+ if ($current =~ /^(\d+)$/) {
+ $oldvalue = $1;
+ }
+ } else {
+ if ($current =~ /^yes$/i) {
+ $oldvalue = 1;
+ }
+ }
+ if ($oldvalue ne $newvalue) {
+ $haschanges = 1;
+ if ($newvalue) {
+ my $storeval = 'yes';
+ if ($which eq 'randompick') {
+ $storeval = $newvalue;
+ }
+ &LONCAPA::map::storeparameter($res,'parameter_'.$which,
+ $storeval,
+ $parameter_type{$which});
+ &remember_parms($res,$which,'set',$storeval);
+ } elsif ($oldvalue) {
+ &LONCAPA::map::delparameter($res,'parameter_'.$which);
+ &remember_parms($res,$which,'del');
+ }
+ }
+ }
+ }
+ return $haschanges;
+ } else {
+ return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
- return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
+ my $which = $env{'form.changeparms'};
+ my $idx = $env{'form.setparms'};
+ if ($env{'form.'.$which.'_'.$idx}) {
+ my $value = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
+ : 'yes';
+ &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
+ $parameter_type{$which});
+ &remember_parms($idx,$which,'set',$value);
+ } else {
+ &LONCAPA::map::delparameter($idx,'parameter_'.$which);
- my $which = $env{'form.changeparms'};
- my $idx = $env{'form.setparms'};
- if ($env{'form.'.$which.'_'.$idx}) {
- my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
- : 'yes';
- &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
- $parameter_type{$which});
- &remember_parms($idx,$which,'set',$value);
- } else {
- &LONCAPA::map::delparameter($idx,'parameter_'.$which);
-
- &remember_parms($idx,$which,'del');
+ &remember_parms($idx,$which,'del');
+ }
+ return 1;
}
- return 1;
}
sub handle_edit_cmd {
my ($coursenum,$coursedom) =@_;
-
my ($cmd,$idx)=split('_',$env{'form.cmd'});
my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
@@ -1424,7 +1988,7 @@ sub handle_edit_cmd {
if ($cmd eq 'del') {
if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
- ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
+ ($url!~/$LONCAPA::assess_page_seq_re/)) {
&Apache::lonnet::removeuploadedurl($url);
} else {
&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
@@ -1435,7 +1999,7 @@ sub handle_edit_cmd {
&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
splice(@LONCAPA::map::order, $idx, 1);
- } elsif ($cmd eq 'up'
+ } elsif ($cmd eq 'up'
&& ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
@LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
@@ -1460,10 +2024,29 @@ sub handle_edit_cmd {
}
sub editor {
- my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$type)=@_;
+ my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
+ $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;
+
+ unless ($supplementalflag) {
+ $jumpto = "'uploaded/$coursedom/$coursenum/$folder.$container'";
+ }
- my $container= ($env{'form.pagepath'}) ? 'page'
- : 'sequence';
+ unless ($allowed) {
+ $randompick = -1;
+ }
my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
$folder.'.'.$container);
@@ -1475,11 +2058,7 @@ sub editor {
$LONCAPA::map::order[0]=$idx;
$LONCAPA::map::resources[$idx]='';
}
-
- my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)=
- &breadcrumbs($folder,$allowed,$type);
- $r->print($breadcrumbtrail);
-
+
# ------------------------------------------------------------ Process commands
# ---------------- if they are for this folder and user allowed to make changes
@@ -1500,22 +2079,50 @@ sub editor {
($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
return $errtext if ($fatal);
}
-
+
if ($env{'form.pastemarked'}) {
- my $paste_res =
- &do_paste_from_buffer($coursenum,$coursedom,$folder);
- if ($paste_res eq 'ok') {
- ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
- return $errtext if ($fatal);
- } elsif ($paste_res ne '') {
+ 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}).
+ ' ');
+ }
+ }
+ if ($lockerror) {
+ $r->print(''.
+ $lockerror.
+ ' ');
+ }
+ 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()) {
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ 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
@@ -1524,13 +2131,57 @@ sub editor {
foreach my $item (split(/\&/,$env{'form.importdetail'})) {
if (defined($item)) {
my ($name,$url,$residx)=
- map {&unescape($_)} split(/\=/,$item);
+ 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)=&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'}) {
@@ -1542,11 +2193,11 @@ sub editor {
$LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
}
($errtext,$fatal)=&storemap($coursenum,$coursedom,
- $folder.'.'.$container);
+ $folder.'.'.$container,1);
return $errtext if ($fatal);
} else {
$r->print(''.&mt('No map selected.').' ');
-
+
}
}
&log_differences($plain);
@@ -1556,36 +2207,164 @@ sub editor {
my $idx=0;
my $shown=0;
if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
- $r->print(''.&mt('Parameters').': '.
- ($randompick>=0?'- '.&mt('randomly pick [_1] resources',$randompick).'
':'').
+ $r->print(''.
+ ' - '.&mt('Parameters:').'
'.
+ ($randompick>=0?'- '.&mt('randomly pick [quant,_1,resource]',$randompick).'
':'').
($ishidden?'- '.&mt('contents hidden').'
':'').
($isencrypted?'- '.&mt('URLs hidden').'
':'').
- '');
- }
- if ($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.').' ');
- }
- if ($is_random_order) {
- $r->print(''.&mt('Caution: this folder is set to randomly order its contents. Adding or removing resources from this folder will change the order of resources shown.').' ');
+ ($is_random_order?'- '.&mt('random order').'
':'').
+ '
');
+ if ($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.')
+ .' '
+ );
+ }
+ if ($is_random_order) {
+ $r->print(' '
+ .&mt('Caution: this folder is set to randomly order its'
+ .' contents. Adding or removing resources from this folder'
+ .' will change the order of resources shown.')
+ .' '
+ );
+ }
+ $r->print(' ');
}
- $r->print('');
+
+ my ($to_show,$output,@allidx,@allmapidx);
+
+ &Apache::loncommon::start_data_table_count(); #setup a row counter
foreach my $res (@LONCAPA::map::order) {
- my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
- $name=&LONCAPA::map::qtescape($name);
- $url=&LONCAPA::map::qtescape($url);
- unless ($name) { $name=(split(/\//,$url))[-1]; }
- unless ($name) { $idx++; next; }
- $r->print(&entryline($idx,$name,$url,$folder,$allowed,$res,
- $coursenum));
- $idx++;
- $shown++;
+ my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
+ $name=&LONCAPA::map::qtescape($name);
+ $url=&LONCAPA::map::qtescape($url);
+ unless ($name) { $name=(split(/\//,$url))[-1]; }
+ unless ($name) { $idx++; next; }
+ push(@allidx,$res);
+ if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
+ push(@allmapidx,$res);
+ }
+ $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
+ $coursenum,$coursedom,$crstype,
+ $pathitem,$supplementalflag,$container);
+ $idx++;
+ $shown++;
}
- unless ($shown) {
- $r->print(''.&mt('Currently no documents.').' | ');
+ &Apache::loncommon::end_data_table_count();
+
+ 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();
+ if ($folder !~ /^supplemental/) {
+ my $idxlist = join(',',@allidx);
+ my $mapidxlist = join(',',@allmapidx);
+ if (@allidx > 0) {
+ my $path;
+ if ($env{'form.folderpath'}) {
+ $path =
+ &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
+ }
+ $to_show .=
+ &Apache::loncommon::continue_data_table_row().
+ ' | '.
+ ''.
+ ''.
+ ''.
+
+ ' | '.
+ &Apache::loncommon::end_data_table_row();
+ }
+ }
+ $to_show .= $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::start_scrollbox('400px','380px','200px','contentscroll')
+ .''
+ .&mt('Currently no documents.')
+ .' '
+ .&Apache::loncommon::end_scrollbox();
+ }
+ } else {
+ 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) {
+ $tid = 2;
}
- $r->print("\n \n");
if ($allowed) {
- &print_paste_buffer($r,$container);
+ 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;
}
@@ -1593,11 +2372,10 @@ sub editor {
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';
@@ -1606,18 +2384,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/';
@@ -1627,13 +2402,27 @@ 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 = ''.&mt('Uploaded [_1]',''.
+ $stored.'').' ';
+ } else {
+ my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
+
+ $$upload_output = ''.&mt('Unable to save file [_1].',''.$filename.'').' ';
+ return;
+ }
my $ext='false';
if ($url=~m{^http://}) { $ext='true'; }
$url = &LONCAPA::map::qtunescape($url);
@@ -1648,53 +2437,86 @@ sub process_file_upload {
$comment.':'.$url.':'.$ext.':normal:res';
$LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
($errtext,$fatal)=&storemap($coursenum,$coursedom,
- $folder.'.'.$container);
+ $folder.'.'.$container,1);
if ($fatal) {
- $$upload_output .= ''.$errtext.' ';
- return 'failed';
+ $$upload_output = ''.$errtext.' ';
+ return;
} else {
- if ($parseaction eq 'parse') {
- my $total_embedded = keys(%{$allfiles});
+ if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
+ $$upload_output = $showupload;
+ my $total_embedded = scalar(keys(%{$allfiles}));
if ($total_embedded > 0) {
- my $num = 0;
- my $state = '
-
-
-
-
- ';
- $phase_status = 'phasetwo';
-
- $$upload_output .=
- 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA. '.
- &Apache::loncommon::ask_for_embedded_content(
- '/adm/coursedocs',$state,$allfiles,$codebase);
+ my $uploadphase = 'upload_embedded';
+ my $primaryurl = &HTML::Entities::encode($url,'<>&"');
+ my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
+ my ($embedded,$num) =
+ &Apache::loncommon::ask_for_embedded_content(
+ '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
+ if ($embedded) {
+ if ($num) {
+ $$upload_output .=
+ ''.&mt('This file contains embedded multimedia objects, which need to be uploaded.').' '.$embedded;
+ $nextphase = $uploadphase;
+ } else {
+ $$upload_output .= $embedded;
+ }
+ } else {
+ $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').' ';
+ }
} else {
- $$upload_output .= 'No embedded items identified ';
+ $$upload_output .= &mt('No embedded items identified').' ';
}
+ $$upload_output = ''.$$upload_output.' ';
+ } 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 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.'/';
+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]);
+ }
}
- $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;
+ return @dir_lines;
}
sub is_supplemental_title {
@@ -1702,82 +2524,64 @@ sub is_supplemental_title {
return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
}
-sub parse_supplemental_title {
- my ($title) = @_;
-
- my ($foldertitle,$renametitle);
- if ($title =~ /&&&/) {
- $title = &HTML::Entites::decode($title);
- }
- if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
- $renametitle=$4;
- my ($time,$uname,$udom) = ($1,$2,$3);
- $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
- my $name = &Apache::loncommon::plainname($uname,$udom);
- $name = &HTML::Entities::encode($name,'"<>&\'');
- $title=''.&Apache::lonlocal::locallocaltime($time).' '.
- $name.': '.$foldertitle;
- }
- if (wantarray) {
- return ($title,$foldertitle,$renametitle);
- }
- return $title;
-}
-
# --------------------------------------------------------------- An entry line
sub entryline {
- my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
-
- my ($foldertitle,$pagetitle,$renametitle);
+ my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
+ $crstype,$pathitem,$supplementalflag,$container)=@_;
+ my ($foldertitle,$renametitle);
if (&is_supplemental_title($title)) {
- ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
- $pagetitle = $foldertitle;
+ ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
} else {
$title=&HTML::Entities::encode($title,'"<>&\'');
$renametitle=$title;
$foldertitle=$title;
- $pagetitle=$title;
}
my $orderidx=$LONCAPA::map::order[$index];
-
$renametitle=~s/\\/\\\\/g;
$renametitle=~s/\"\;/\\\"/g;
$renametitle=~s/ /%20/g;
- my $line='';
- my ($form_start,$form_end);
+ 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 ($esc_path, $path, $symb);
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($path = $env{'form.pagepath'});
- $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
- $symb=&escape($env{'form.pagesymb'});
+ 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 $cpinfo='';
+ 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;
}
+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()
@@ -2050,7 +3018,7 @@ sub tiehash {
$hashtied=1;
}
}
- }
+ }
}
sub untiehash {
@@ -2099,7 +3067,7 @@ sub checkonthis {
if (($errorcount) ||
($warningcount)) {
if ($errorcount) {
- $r->print(''.
+ $r->print(''.
&mt('[quant,_1,error]',$errorcount).'');
}
if ($warningcount) {
@@ -2122,7 +3090,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').'');
}
@@ -2139,52 +3107,68 @@ sub checkonthis {
=item list_symbs()
-List Symbs
+List Content Identifiers
=cut
sub list_symbs {
my ($r) = @_;
- my $type = &Apache::loncommon::course_type();
- $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();
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($type).':'.$env{'request.course.id'});
+ &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("$crstype Content Identifiers").''.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ ''.&mt('Title').' | '.&mt('Identifier').' | '.
+ &Apache::loncommon::end_data_table_header_row()."\n");
+ my $count;
foreach my $res ($navmap->retrieveResources()) {
- $r->print($res->compTitle()."\t".$res->symb()."\n");
+ $r->print(&Apache::loncommon::start_data_table_row().
+ ''.$res->compTitle().' | '.
+ ''.$res->symb().' | '.
+ &Apache::loncommon::end_data_table_row());
+ $count ++;
+ }
+ if (!$count) {
+ $r->print(&Apache::loncommon::start_data_table_row().
+ ''.&mt("$crstype is empty").' | '.
+ &Apache::loncommon::end_data_table_row());
}
- $r->print("\n \n");
+ $r->print(&Apache::loncommon::end_data_table());
}
- $r->print(''.&mt('Return to DOCS').'');
+ $r->print(&endContentScreen());
}
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 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 '.$type.': ').
+ &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. '));
+ &mt('Note that grading records for problems included in this sequence or folder will overlap.').' ');
}
}
if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
@@ -2192,8 +3176,8 @@ sub verifycontent {
}
}
&untiehash();
- $r->print(''.&mt('Done').'.'.''.
- &mt('Return to DOCS').'');
+ $r->print(''.&mt('Done').' ');
+ $r->print(&endContentScreen());
}
@@ -2205,9 +3189,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='';
@@ -2258,18 +3244,20 @@ 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 Saved').'');
+ $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 Save 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;
+ $header=&mt('All Documents in '.$crstype);
+ $allsel=' selected="selected"';
foreach my $key (keys(%hash)) {
if ($key=~/^ids\_(\/res\/.+)$/) {
my $src=$1;
@@ -2290,19 +3278,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 {
@@ -2313,139 +3301,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
| ');
- }
-# ----------------------------------------------------- Supplemental documents
- if (!$forcestandard) {
- $r->print('');
-# ''.&mt('Supplemental Course Documents').
-# ($allowed?' '.$help{'Supplemental'}:'').'');
+
+ my $newnavform=(<
+
+ $pathitem
+
+
+ $help{'Navigate_Content'}
+
+NNFORM
+ my $newsmppageform=(<
+
+ $pathitem
+
+
+ $help{'Simple Page'}
+
+NSPFORM
+
+ my $newsmpproblemform=(<
+
+ $pathitem
+
+
+ $help{'Simple Problem'}
+
+
+NSPROBFORM
+
+ my $newdropboxform=(<
+
+ $pathitem
+
+
+
+NDBFORM
+
+ my $newexuploadform=(<
+
+ $pathitem
+
+
+ $help{'Score_Upload_Form'}
+
+NEXUFORM
+
+ my $newbulform=(<
+
+ $pathitem
+
+
+ $help{'Bulletin Board'}
+
+NBFORM
+
+ my $newaboutmeform=(<
+
+ $pathitem
+
+
+ $help{'My Personal Information Page'}
+
+NAMFORM
+
+ my $newaboutsomeoneform=(<
+
+ $pathitem
+
+
+
+NASOFORM
+
+ my $newrosterform=(<
+
+ $pathitem
+
+
+ $help{'Course Roster'}
+
+NROSTFORM
+
+ my $newwebpage;
+ if ($folder =~ /^default_?(\d*)$/) {
+ $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
+ if ($1) {
+ $newwebpage .= $1;
+ } else {
+ $newwebpage .= 'default';
+ }
+ $newwebpage .= '/new.html';
+ }
+ my $newwebpageform =(<
+
+ $pathitem
+
+
+ $help{'Web Page'}
+
+NWEBFORM
+
+
+my $specialdocumentsform;
+my @specialdocumentsforma;
+my $gradingform;
+my @gradingforma;
+my $communityform;
+my @communityforma;
+my $newfolderform;
+my $newfolderb;
+
+ my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
+
+ my $newpageform=(<
+
+
+
+
+ $help{'Adding_Pages'}
+
+NPFORM
+
+
+ $newfolderform=(<
+ $pathitem
+
+
+ $lt{'newf'}$help{'Adding_Folders'}
+
+NFFORM
+
+ my $newsylform=(<
+
+ $pathitem
+
+
+ $help{'Syllabus'}
+
+
+NSYLFORM
+
+ my $newgroupfileform=(<
+
+ $pathitem
+
+
+ $help{'Group Portfolio'}
+
+NGFFORM
+ @specialdocumentsforma=(
+ {''=>$newpageform},
+ {''=>$newsylform},
+ {''=>$newnavform},
+ {''=>$newsmppageform},
+ {''=>$newwebpageform},
+ );
+ $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
+
+
+ my @importdoc = (
+ {''=>$extresourcesform}
+ );
+ unless ($container eq 'page') {
+ push(@importdoc,
+ {''=>$imspform}
+ );
+ }
+ push(@importdoc,
+ {''=>$fileuploadform}
+ );
+ $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
+
+ @gradingforma=(
+ {''=>$newsmpproblemform},
+ {''=>$newdropboxform},
+ {''=>$newexuploadform},
+
+ );
+ $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
+
+ @communityforma=(
+ {''=>$newbulform},
+ {''=>$newaboutmeform},
+ {''=>$newaboutsomeoneform},
+ {''=>$newrosterform},
+ {''=>$newgroupfileform},
+ );
+ $communityform = &create_form_ul(&create_list_elements(@communityforma));
+
+my %orderhash = (
+ 'aa' => ['Import Content',$fileuploadform],
+ 'bb' => ['Published Content',$importpubform],
+ 'cc' => ['Grading Resources',$gradingform],
+ );
+unless ($container eq 'page') {
+ $orderhash{'00'} = ['Newfolder',$newfolderform];
+ $orderhash{'dd'} = ['Collaboration',$communityform];
+ $orderhash{'ee'} = ['Special Pages',$specialdocumentsform];
+}
+
+ $hadchanges=0;
+ unless (($supplementalflag || $toolsflag)) {
+ my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
+ $supplementalflag,\%orderhash,$iconpath,$pathitem);
+ if ($error) {
+ $r->print(''.$error.' ');
+ }
+ if ($hadchanges) {
+ &mark_hash_old();
+ }
+
+ &changewarning($r,'');
+ }
+ }
+
+# Supplemental documents start here
+
my $folder=$env{'form.folder'};
- unless ($folder=~/^supplemental/) {
+ unless ($supplementalflag) {
$folder='supplemental';
}
if ($folder =~ /^supplemental$/ &&
(($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
- $env{'form.folderpath'} = 'supplemental&'.
- &escape(&mt('Supplemental '.$type.' Documents'));
- }
- my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
- if ($error) {
- $r->print(''.$error.' ');
+ $env{'form.folderpath'} = &supplemental_base();
+ } elsif ($allowed) {
+ $env{'form.folderpath'} = $savefolderpath;
}
+ $pathitem = '';
if ($allowed) {
my $folderseq=
- '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
- '.sequence';
+ '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
- my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
- $r->print(<
-$lt{'upls'} |
-$lt{'spec'} |
-
-
-
-
-
-
-
-
-
-
-$lt{'comment'}:
-
-
-
-
-
-
- $help{'Uploading_From_Harddrive'}
-
-
- |
-
-
-
-
-
- $help{'Adding_Folders'}
-
-
-
-
-
-
- $help{'Adding_External_Resource'}
-
-
-
-
-
-
-
-$help{'Syllabus'}
-
-
-
-
-
-
-
-$help{'My Personal Info'}
-
-
- |
- |
-ENDSUPFORM
- }
+ my $supupdocform=(<