--- loncom/interface/londocs.pm 2013/04/03 02:41:22 1.484.2.30 +++ loncom/interface/londocs.pm 2012/11/16 23:37:15 1.509 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.484.2.30 2013/04/03 02:41:22 raeburn Exp $ +# $Id: londocs.pm,v 1.509 2012/11/16 23:37:15 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,7 +40,7 @@ use Apache::lonxml; use Apache::lonclonecourse; use Apache::lonnavmaps; use Apache::lonnavdisplay(); -use Apache::lonextresedit(); +use Apache::lonuserstate(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; @@ -152,7 +152,7 @@ sub dumpcourse { $r->print(&endContentScreen()); return ''; } - my ($ca,$cd)=split(/\:/,$env{'form.authorspace'}); + my ($ca,$cd)=split(/\@/,$env{'form.authorspace'}); $r->print('
'."\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". - '
'.
- join('
',@{$msgsarray}).
- '
'. - $lockerror. - '
'; - } - } - my ($errtext,$fatal) = - &storemap($coursenum, $coursedom, $folder.'.'.$container,1); - return ($errtext,$fatal,$fixuperrors); + return &storemap($coursenum, $coursedom, $folder.'.'.$container,1); } sub log_docs { @@ -485,15 +390,18 @@ sub docs_change_log { my %orderhash; my $container='sequence'; my $pathitem; - if ($env{'form.folderpath'} =~ /\:1$/) { + if ($env{'form.pagepath'}) { $container='page'; + $pathitem = ''; + } else { + my $folderpath=$env{'form.folderpath'}; + if ($folderpath eq '') { + $folderpath = 'default&'.&escape(&mt('Main '.$crstype.' Documents')); + } + $pathitem = ''; } - my $folderpath=$env{'form.folderpath'}; - if ($folderpath eq '') { - $folderpath = 'default&'.&escape(&mt('Main '.$crstype.' Content').':::::'); - } - $pathitem = ''; my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container"; my $jumpto = $readfile; $jumpto =~ s{^/}{}; @@ -655,115 +563,57 @@ sub docs_change_log { sub update_paste_buffer { my ($coursenum,$coursedom,$folder) = @_; - my (@possibles,%removals,%cuts); - if ($env{'form.multiremove'}) { - $env{'form.multiremove'} =~ s/,$//; - map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'}); - } - if (($env{'form.multicopy'}) || ($env{'form.multicut'})) { - if ($env{'form.multicut'}) { - $env{'form.multicut'} =~ s/,$//; - foreach my $item (split(/,/,$env{'form.multicut'})) { - unless ($removals{$item}) { - $cuts{$item} = 1; - push(@possibles,$item.':cut'); - } - } - } - if ($env{'form.multicopy'}) { - $env{'form.multicopy'} =~ s/,$//; - foreach my $item (split(/,/,$env{'form.multicopy'})) { - unless ($removals{$item} || $cuts{$item}) { - push(@possibles,$item.':copy'); - } - } - } - } elsif ($env{'form.markcopy'}) { - @possibles = split(/,/,$env{'form.markcopy'}); - } - return if (@possibles == 0); + return if (!defined($env{'form.markcopy'})); return if (!defined($env{'form.copyfolder'})); + return if ($env{'form.markcopy'} < 0); my ($errtext,$fatal) = &mapread($coursenum,$coursedom, $env{'form.copyfolder'}); - return if ($fatal); - - my %curr_groups = &Apache::longroup::coursegroups(); -# Retrieve current paste buffer suffixes. - my @currpaste = split(/,/,$env{'docs.markedcopies'}); - my (%pasteurls,@newpaste); - -# Construct identifiers for current contents of user's paste buffer - if (@currpaste) { - foreach my $suffix (@currpaste) { - my $cid = $env{'docs.markedcopy_crs_'.$suffix}; - my $url = $env{'docs.markedcopy_url_'.$suffix}; - if (($cid =~ /^$match_domain(?:_)$match_courseid$/) && - ($url ne '')) { - $pasteurls{$cid.'_'.$url}; - } - } - } + return if ($fatal); -# Mark items for copying (skip any items already in user's paste buffer) - my %addtoenv; - - foreach my $item (@possibles) { - my ($orderidx,$cmd) = split(/:/,$item); - next if ($orderidx =~ /\D/); - next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove')); - my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]); - my %denied = &action_restrictions($coursenum,$coursedom, - &LONCAPA::map::qtescape($url), - $env{'form.folderpath'},\%curr_groups); - next if ($denied{'copy'}); - $url=~s{http(:|:)//https(:|:)//}{https$2//}; - next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url})); - my ($suffix,$errortxt,$locknotfreed) = - &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste'); - push(@newpaste,$suffix); - if ($locknotfreed) { - return $locknotfreed; - last; - } - if (&is_supplemental_title($title)) { - &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title}); - ($title) = &Apache::loncommon::parse_supplemental_title($title); - } - - $addtoenv{'docs.markedcopy_title_'.$suffix} = $title, - $addtoenv{'docs.markedcopy_url_'.$suffix} = $url, - $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd, - $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'}; - - 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_'.$suffix} = $nested; - } - if ($nestednames ne '') { - $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames; - } +# Mark for copying + my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]); + if (&is_supplemental_title($title)) { + &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title}); + ($title) = &Apache::loncommon::parse_supplemental_title($title); + } elsif ($env{'docs.markedcopy_supplemental'}) { + &Apache::lonnet::delenv('docs.markedcopy_supplemental'); + } + $url=~s{http(:|:)//https(:|:)//}{https$2//}; + + (my $cmd,undef)=split('_',$env{'form.cmd'}); + + my %addtoenv = ( + 'docs.markedcopy_title' => $title, + 'docs.markedcopy_url' => $url, + 'docs.markedcopy_cmd' => $cmd, + ); + &Apache::lonnet::delenv('docs.markedcopy_nested'); + &Apache::lonnet::delenv('docs.markedcopy_nestednames'); + if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) { + my $prefix = $1; + my $subdir =$2; + if ($subdir eq '') { + $subdir = $prefix; + } + my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps); + &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps, + \%hierarchy,\%titles,\%allmaps); + if (ref($hierarchy{$url}) eq 'HASH') { + my ($nested,$nestednames); + &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames); + $nested =~ s/\&$//; + $nestednames =~ s/\Q___&&&___\E$//; + if ($nested ne '') { + $addtoenv{'docs.markedcopy_nested'} = $nested; + } + if ($nestednames ne '') { + $addtoenv{'docs.markedcopy_nestednames'} = $nestednames; } } } - if (@newpaste) { - $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste)); - } &Apache::lonnet::appenv(\%addtoenv); delete($env{'form.markcopy'}); } @@ -795,200 +645,145 @@ sub recurse_uploaded_maps { sub print_paste_buffer { my ($r,$container,$folder,$coursedom,$coursenum) = @_; - return if (!defined($env{'docs.markedcopies'})); + return if (!defined($env{'docs.markedcopy_url'})); - unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) { - return if ($env{'docs.markedcopies'} eq ''); + 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 @currpaste = split(/,/,$env{'docs.markedcopies'}); - my ($pasteitems,@pasteable); + my ($canpaste,$nopaste,$othercrs,$areachange,$is_uploaded_map); + if ($folder =~ /^supplemental/) { + $canpaste = &supp_pasteable($env{'docs.markedcopy_url'}); + unless ($canpaste) { + $nopaste = &mt('Paste into Supplemental Content unavailable for this type of content.'); + } + } else { + $canpaste = 1; + } -# Construct identifiers for current contents of user's paste buffer - foreach my $suffix (@currpaste) { - next if ($suffix =~ /\D/); - my $cid = $env{'docs.markedcopy_crs_'.$suffix}; - my $url = $env{'docs.markedcopy_url_'.$suffix}; - if (($cid =~ /^$match_domain\_$match_courseid$/) && - ($url ne '')) { - my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent, - $canpaste,$nopaste,$othercrs,$areachange); - my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1]; - if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) { - $is_external = 1; - } - if ($folder =~ /^supplemental/) { - $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix}); - unless ($canpaste) { - $nopaste = &mt('Paste into Supplemental Content unavailable.'); + 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 = ''.
- join('
',@{$pastemsgarray}).
- '
'. - $lockerror. - '
'); - } - if ($save_error ne '') { - return $save_error; - } - if ($paste_res) { - my %errortext = &Apache::lonlocal::texthash ( - fail => 'Storage of folder contents failed', - failread => 'Reading folder contents failed', - failstore => 'Storage of folder contents failed', - ); - if ($errortext{$paste_res}) { - $r->print(''.$errortext{$paste_res}.'
'); + if ($save_error ne '') { + return $save_error; } + if ($paste_res ne 'ok') { + $r->print(''.$paste_res.'
'); } if (keys(%paste_errors) > 0) { - $r->print(''."\n". + $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". '
'.$output.'
'); - } - } + } $r->print($upload_output); -# Rename, cut, copy or remove a single resource if (&handle_edit_cmd()) { my $contentchg; - if ($env{'form.cmd'} =~ m{^(del|cut)_}) { + if ($env{'form.cmd'} =~ /^(del|cut)_/) { $contentchg = 1; } ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg); return $errtext if ($fatal); } - -# Cut, copy and/or remove multiple resources - if ($env{'form.multichange'}) { - my %allchecked = ( - cut => {}, - remove => {}, - ); - my $needsupdate; - foreach my $which (keys(%allchecked)) { - $env{'form.multi'.$which} =~ s/,$//; - if ($env{'form.multi'.$which}) { - map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which}); - if (ref($allchecked{$which}) eq 'HASH') { - $needsupdate += scalar(keys(%{$allchecked{$which}})); - } - } - } - if ($needsupdate) { - my $haschanges = 0; - my %curr_groups = &Apache::longroup::coursegroups(); - my $total = scalar(@LONCAPA::map::order) - 1; - for (my $i=$total; $i>=0; $i--) { - my $res = $LONCAPA::map::order[$i]; - my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]); - $name=&LONCAPA::map::qtescape($name); - $url=&LONCAPA::map::qtescape($url); - next unless ($name && $url); - my %denied = - &action_restrictions($coursenum,$coursedom,$url, - $env{'form.folderpath'},\%curr_groups); - foreach my $which (keys(%allchecked)) { - next if ($denied{$which}); - next unless ($allchecked{$which}{$res}); - if ($which eq 'remove') { - if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) && - ($url!~/$LONCAPA::assess_page_seq_re/)) { - &Apache::lonnet::removeuploadedurl($url); - } else { - &LONCAPA::map::makezombie($res); - } - splice(@LONCAPA::map::order,$i,1); - $haschanges ++; - } elsif ($which eq 'cut') { - &LONCAPA::map::makezombie($res); - splice(@LONCAPA::map::order,$i,1); - $haschanges ++; - } - } - } - if ($haschanges) { - ($errtext,$fatal) = - &storemap($coursenum,$coursedom,$folder.'.'.$container,1); - return $errtext if ($fatal); - } - } - } - # Group import/search if ($env{'form.importdetail'}) { my @imports; foreach my $item (split(/\&/,$env{'form.importdetail'})) { if (defined($item)) { my ($name,$url,$residx)= - map { &unescape($_); } split(/\=/,$item); - if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) { - my ($suffix,$errortxt,$locknotfreed) = - &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2); + map {&unescape($_)} split(/\=/,$item); + if ($url=~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) { + my ($suffix,$errortxt,$locknotfreed) = + &newmap_suffix($1,$2,$coursedom,$coursenum); if ($locknotfreed) { $r->print($locknotfreed); } @@ -2503,45 +1786,13 @@ sub editor { } else { return $errortxt; } - } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) { - my $type = $1; - my ($suffix,$errortxt,$locknotfreed) = - &new_timebased_suffix($coursedom,$coursenum,$type); - if ($locknotfreed) { - $r->print($locknotfreed); - } - if ($suffix) { - $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix}; - } else { - return $errortxt; - } - } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) { - if ($supplementalflag) { - next unless ($1 eq 'supplemental'); - if ($folder eq 'supplemental') { - next unless ($2 eq 'default'); - } else { - next unless ($folder eq 'supplemental_'.$2); - } - } else { - next unless ($1 eq 'docs'); - if ($folder eq 'default') { - next unless ($2 eq 'default'); - } else { - next unless ($folder eq 'default_'.$2); - } - } } push(@imports, [$name, $url, $residx]); } } - ($errtext,$fatal,my $fixuperrors) = - &group_import($coursenum, $coursedom, $folder,$container, - 'londocs',@imports); + ($errtext,$fatal)=&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'}) { @@ -2597,17 +1848,8 @@ sub editor { $r->print(''); } - my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups); - %filters = ( - canremove => [], - cancut => [], - cancopy => [], - hiddenresource => [], - encrypturl => [], - randomorder => [], - randompick => [], - ); - %curr_groups = &Apache::longroup::coursegroups(); + my ($to_show,$output); + &Apache::loncommon::start_data_table_count(); #setup a row counter foreach my $res (@LONCAPA::map::order) { my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]); @@ -2615,110 +1857,37 @@ sub editor { $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, - \%filters,\%curr_groups); + $pathitem,$supplementalflag); $idx++; $shown++; } &Apache::loncommon::end_data_table_count(); - - my $need_save; - if (($allowed) || ($supplementalflag && $folder eq 'supplemental')) { - my $toolslink = '' - .&Apache::loncommon::help_open_menu('Navigation Screen', - 'Navigation_Screen',undef,'RAT') - .' | '.&mt('Tools:').' | ' - .'
|