--- loncom/interface/londocs.pm 2012/07/06 22:46:06 1.490 +++ loncom/interface/londocs.pm 2012/11/30 14:46:21 1.512 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.490 2012/07/06 22:46:06 raeburn Exp $ +# $Id: londocs.pm,v 1.512 2012/11/30 14:46:21 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,6 +41,7 @@ use Apache::lonclonecourse; use Apache::lonnavmaps; use Apache::lonnavdisplay(); use Apache::lonuserstate(); +use Apache::lonextresedit(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; @@ -69,10 +70,14 @@ 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; @@ -305,67 +310,11 @@ sub group_import { join(':', ($name, $url, $ext, 'normal', 'res')); } } - return &storemap($coursenum, $coursedom, $folder.'.'.$container); -} - -sub breadcrumbs { - my ($allowed,$crstype)=@_; - &Apache::lonhtmlcommon::clear_breadcrumbs(); - my (@folders); - if ($env{'form.pagepath'}) { - @folders = split('&',$env{'form.pagepath'}); - } else { - @folders=split('&',$env{'form.folderpath'}); - } - my $folderpath; - my $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; - if ($allowed) { - $url = '/adm/coursedocs?folderpath='; - } else { - $url = '/adm/supplemental?folderpath='; - } - $url .= &escape($folderpath); - my $name=&unescape($foldername); -# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername - $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//; - if ($1 ne '') { - $randompick=$1; - } else { - $randompick=-1; - } - if ($2) { $ishidden=1; } - if ($3) { $isencrypted=1; } - if ($4 ne '') { $is_random_order = 1; } - if ($folder eq 'supplemental') { - $name = &mt('Supplemental '.$crstype.' Content'); - } - &Apache::lonhtmlcommon::add_breadcrumb( - {'href'=>$url.$cpinfo, - 'title'=>$name, - 'text'=>$name, - 'no_mt'=>1, - }); - $plain.=$name.' > '; - } - $plain=~s/\>\;\s*$//; - return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp', - undef, undef, 1 ),$randompick,$ishidden, - $isencrypted,$plain,$is_random_order); + return &storemap($coursenum, $coursedom, $folder.'.'.$container,1); } sub log_docs { - return &Apache::lonnet::instructor_log('docslog',@_); + return &Apache::lonnet::write_log('course','docslog',@_); } { @@ -451,7 +400,8 @@ sub docs_change_log { if ($folderpath eq '') { $folderpath = 'default&'.&escape(&mt('Main '.$crstype.' Documents')); } - $pathitem = ''; + $pathitem = ''; } my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container"; my $jumpto = $readfile; @@ -460,7 +410,8 @@ sub docs_change_log { if ($supplementalflag) { $tid = 2; } - my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype); + my ($breadcrumbtrail) = + &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1); $r->print($breadcrumbtrail. &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto, $readfile)); @@ -612,7 +563,7 @@ sub docs_change_log { } sub update_paste_buffer { - my ($coursenum,$coursedom) = @_; + my ($coursenum,$coursedom,$folder) = @_; return if (!defined($env{'form.markcopy'})); return if (!defined($env{'form.copyfolder'})); @@ -633,75 +584,211 @@ sub update_paste_buffer { } $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,$folder) = @_; + my ($r,$container,$folder,$coursedom,$coursenum) = @_; return if (!defined($env{'docs.markedcopy_url'})); - my $is_external; + 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; + my ($canpaste,$nopaste,$othercrs,$areachange,$is_uploaded_map); if ($folder =~ /^supplemental/) { - $canpaste = &supp_pasteable($env{'docs.markedcopy_url'}); + $canpaste = &supp_pasteable($env{'docs.markedcopy_url'}); + unless ($canpaste) { + $nopaste = &mt('Paste into Supplemental Content unavailable for this type of content.'); + } } else { $canpaste = 1; } - my $pasteinfo; if ($canpaste) { - $pasteinfo = '
'; + } + } elsif ($supplementalflag && !$allowed) { + $url .= ($url =~ /\?/) ? '&':'?'; + $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"'); + if ($title) { + $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"'); + } + if ($isexternal && $orderidx) { + $url .= '&idx='.$orderidx; + } } if ($ispage) { my $pagename=&escape($pagetitle); @@ -1841,23 +2444,32 @@ $form_common.' my $folderpath=$env{'form.folderpath'}; if ($folderpath) { $pagepath = $folderpath.'&' }; $pagepath.=$pagearg.'&'.$pagename; - my $symb=$env{'form.pagesymb'}; - if (!$symb) { - my $path='uploaded/'. - $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'. - $env{'course.'.$env{'request.course.id'}.'.num'}.'/'; - $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence', - $residx, - $path.$pagearg.'.page'); - } $url.='pagepath='.&escape($pagepath). - '&pagesymb='.&escape($symb).$cpinfo; + '&pagesymb='.&escape($symb); } - if (($external) && ($allowed)) { - my $form = ($folder =~ /^default/)? 'newext' : 'supnewext'; - $external = ' '.&mt('Edit').''; - } else { - undef($external); + if ($allowed) { + my $fileloc = + &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url)); + if ($isexternal) { + $editlink = ' '. + &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem); + } elsif (!$isfolder && !$ispage) { + my ($cfile,$home,$switchserver,$forceedit,$forceview) = + &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url); + if (($cfile ne '') && ($symb ne '' || $supplementalflag)) { + my $jscall = + &Apache::lonhtmlcommon::jump_to_editres($cfile,$home, + $switchserver, + $forceedit, + undef,$symb, + &escape($env{'form.folderpath'}), + $renametitle); + if ($jscall) { + $editlink = ' '.&mt('Edit').''; + } + } + } } my $reinit; if ($crstype eq 'Community') { @@ -1883,7 +2495,7 @@ $form_common.' } else { $line.=$title.' '.$reinit.''; } - $line.=$external.""; + $line.=$editlink.""; $rand_pick_text = ' ' if ($rand_pick_text eq ''); $rand_order_text = ' ' if ($rand_order_text eq ''); if (($allowed) && ($folder!~/^supplemental/)) { @@ -1914,6 +2526,30 @@ ENDPARMS return $line; } +sub newmap_suffix { + my ($area,$container,$coursedom,$coursenum) = @_; + my ($prefix,$idtype,$errtext,$locknotfreed); + $prefix = 'docs'; + if ($area eq 'supplemental') { + $prefix = 'supp'; + } + $prefix .= $container; + $idtype = 'concat'; + my ($suffix,$freedlock,$error) = + &Apache::lonnet::get_timebased_id($prefix,'num','uploadedmaps', + $coursedom,$coursenum); + if (!$suffix) { + $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.'); + if ($error) { + $errtext .= '