--- loncom/interface/londocs.pm 2025/01/17 14:10:05 1.484.2.93.2.18 +++ loncom/interface/londocs.pm 2022/10/22 17:24:54 1.684 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.484.2.93.2.18 2025/01/17 14:10:05 raeburn Exp $ +# $Id: londocs.pm,v 1.684 2022/10/22 17:24:54 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,11 +43,15 @@ use Apache::lonnavdisplay(); use Apache::lonextresedit(); use Apache::lontemplate(); use Apache::lonsimplepage(); +use Apache::lonhomework(); +use Apache::lonpublisher(); +use Apache::lonparmset(); use Apache::loncourserespicker(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; use File::MMagic; +use File::Copy; use Apache::lonlocal; use Cwd; use UUID::Tiny ':std'; @@ -179,62 +183,43 @@ sub default_folderpath { } } -sub validate_supppath { - my ($coursenum,$coursedom) = @_; - my $backto; +sub validate_folderpath { + my ($supplementalflag) = @_; + if ($env{'form.folderpath'} ne '') { + my @items = split(/\&/,$env{'form.folderpath'}); + my $badpath; + for (my $i=0; $i<@items; $i++) { + my $odd = $i%2; + if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) { + $badpath = 1; + } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) { + $badpath = 1; + } + last if ($badpath); + } + if ($badpath) { + delete($env{'form.folderpath'}); + } + } + return; +} + +sub validate_suppath { if ($env{'form.supppath'} ne '') { my @items = split(/\&/,$env{'form.supppath'}); - my ($badpath,$got_supp,$supppath,%supphidden,%suppids); + my $badpath; for (my $i=0; $i<@items; $i++) { my $odd = $i%2; if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) { $badpath = 1; - last; - } elsif ($odd) { - my $suffix; - my $idx = $i-1; - if ($items[$i] =~ /^([^:]*)::(|1):::$/) { - $backto .= '&'.$1; - } elsif ($items[$idx] eq 'supplemental') { - $backto .= '&'.$items[$i]; - } else { - $backto .= '&'.$items[$i]; - my $is_hidden; - unless ($got_supp) { - my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom); - if (ref($supplemental) eq 'HASH') { - if (ref($supplemental->{'hidden'}) eq 'HASH') { - %supphidden = %{$supplemental->{'hidden'}}; - } - if (ref($supplemental->{'ids'}) eq 'HASH') { - %suppids = %{$supplemental->{'ids'}}; - } - } - $got_supp = 1; - } - if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') { - my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0]; - if ($supphidden{$mapid}) { - $is_hidden = 1; - } - } - $suffix = '::'.$is_hidden.':::'; - } - $supppath .= '&'.$items[$i].$suffix; - } else { - $supppath .= '&'.$items[$i]; - $backto .= '&'.$items[$i]; } + last if ($badpath); } if ($badpath) { delete($env{'form.supppath'}); - } else { - $supppath =~ s/^\&//; - $backto =~ s/^\&//; - $env{'form.supppath'} = $supppath; } } - return $backto; + return; } sub dumpcourse { @@ -292,7 +277,7 @@ ENDJS } else { &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles, 'dumpdocs',$cdom,$cnum); - } + } my @todump = &Apache::loncommon::get_env_multiple('form.archive'); my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages, %newcontent,%has_simpleprobs); @@ -303,7 +288,7 @@ ENDJS if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) { $tocopy{$1} = $name; $display{$item} = $1; - $lookup{$1} = $item; + $lookup{$1} = $item; } elsif ($res eq 'lib/templates/simpleproblem.problem') { $simpleproblems{$item} = { symb => $resources{$item}, @@ -403,7 +388,7 @@ $contents{content}.' '; } if ($contents{webreferences}) { - $content .= ' + $content .= '