--- loncom/interface/londocs.pm 2016/11/30 18:05:43 1.484.2.68 +++ loncom/interface/londocs.pm 2020/01/20 20:09:37 1.484.2.86 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.484.2.68 2016/11/30 18:05:43 raeburn Exp $ +# $Id: londocs.pm,v 1.484.2.86 2020/01/20 20:09:37 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -834,7 +834,7 @@ sub docs_change_log { '// '."\n". @@ -1061,27 +1061,33 @@ sub update_paste_buffer { foreach my $suffix (@currpaste) { my $cid = $env{'docs.markedcopy_crs_'.$suffix}; my $url = $env{'docs.markedcopy_url_'.$suffix}; + my $mapidx = $env{'docs.markedcopy_map_'.$suffix}; if (($cid =~ /^$match_domain(?:_)$match_courseid$/) && ($url ne '')) { - $pasteurls{$cid.'_'.$url} = 1; + $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1; } } } # Mark items for copying (skip any items already in user's paste buffer) my %addtoenv; - + + my @pathitems = split(/\&/,$env{'form.folderpath'}); + my @folderconf = split(/\:/,$pathitems[-1]); + my $ispage = $folderconf[4]; + 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 $mapidx = $folder.':'.$orderidx.':'.$ispage; 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})); + next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx})); my ($suffix,$errortxt,$locknotfreed) = &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste'); if ($suffix ne '') { @@ -1100,7 +1106,7 @@ sub update_paste_buffer { $addtoenv{'docs.markedcopy_url_'.$suffix} = $url, $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd, $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'}; - + $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx; if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) { my $prefix = $1; my $subdir =$2; @@ -1178,6 +1184,7 @@ sub print_paste_buffer { next if ($suffix =~ /\D/); my $cid = $env{'docs.markedcopy_crs_'.$suffix}; my $url = $env{'docs.markedcopy_url_'.$suffix}; + my $mapidx = $env{'docs.markedcopy_map_'.$suffix}; if (($cid =~ /^$match_domain\_$match_courseid$/) && ($url ne '')) { $clipboardcount ++; @@ -1203,9 +1210,7 @@ sub print_paste_buffer { 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)'); - } + $othercrs = '
'.&mt('(from another course)'); } else { $canpaste = 0; $nopaste = &mt('Paste from another course unavailable.'); @@ -1219,10 +1224,21 @@ sub print_paste_buffer { } $is_uploaded_map = 1; } + } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) || + ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) { + if ($cid ne $env{'request.course.id'}) { + my ($srcdom,$srcnum) = split(/_/,$cid); + if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) { + $othercrs = '
'.&mt('(from another course)'); + } else { + $canpaste = 0; + $nopaste = &mt('Paste from another course unavailable.'); + } + } + } + if ($canpaste) { + push(@pasteable,$suffix); } - } - if ($canpaste) { - push(@pasteable,$suffix); } my $buffer; if ($is_external) { @@ -1508,10 +1524,12 @@ sub do_paste_from_buffer { } my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate, - %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult); + %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult); foreach my $suffix (@topaste) { my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix}); + my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); + my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix}); # Supplemental content may only include certain types of content # Early out if pasted content is not supported in Supplemental area if ($folder =~ /^supplemental/) { @@ -1533,8 +1551,21 @@ sub do_paste_from_buffer { } $srcdom{$suffix} = $srcd; $srcnum{$suffix} = $srcn; + } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) || + ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) { + my ($srcd,$srcn) = split(/_/,$cid); +# 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 (($srcd ne $coursedom) || ($srcn ne $coursenum)) { + unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) { + $notincrs{$suffix} = 1; + next; + } + } + $srcdom{$suffix} = $srcd; + $srcnum{$suffix} = $srcn; } - + $srcmapidx{$suffix} = $mapidx; push(@dopaste,$suffix); if ($url=~/\.(page|sequence)$/) { $is_map{$suffix} = 1; @@ -1544,7 +1575,7 @@ sub do_paste_from_buffer { my $oldprefix = $1; # 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. +# a folder/page or a document). if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) { $prefixchg{$suffix} = 'docstosupp'; } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) { @@ -1612,30 +1643,31 @@ sub do_paste_from_buffer { # Retrieve information about all course maps in main content area my $allmaps = {}; - if ($folder =~ /^default/) { - $allmaps = - &Apache::loncommon::allmaps_incourse($coursedom,$coursenum, - $env{"course.$env{'request.course.id'}.home"}, - $env{'request.course.id'}); - } - - my (@toclear,%mapurls,%lockerrs,%msgerrs,%results); + my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk); # Loop over the items to paste foreach my $suffix (@dopaste) { # Maps need to be copied first my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies, %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir, - %newurls,%tomove); + %newurls,%tomove,%resdatacopy); if (ref($marktomove{$suffix}) eq 'ARRAY') { map { $tomove{$_} = 1; } @{$marktomove{$suffix}}; } my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix}); my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}); + my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); my $oldurl = $url; if ($is_map{$suffix}) { # If pasting a map, check if map contains other maps my (%hierarchy,%titles); + if (($folder =~ /^default/) && (!$donechk)) { + $allmaps = + &Apache::loncommon::allmaps_incourse($coursedom,$coursenum, + $env{"course.$env{'request.course.id'}.home"}, + $env{'request.course.id'}); + $donechk = 1; + } &contained_map_check($url,$folder,\%removefrommap,\%removeparam, \%addedmaps,\%hierarchy,\%titles,$allmaps); if ($url=~ m{^/uploaded/}) { @@ -1667,7 +1699,7 @@ sub do_paste_from_buffer { \%retitles,\%copies,\%dbcopies, \%zombies,\%params,\%mapmoves, \%mapchanges,\%tomove,\%newsubdir, - \%newurls)) { + \%newurls,\%resdatacopy)) { $mapmoves{$url} = 1; } $url = $newurl; @@ -1676,10 +1708,10 @@ sub do_paste_from_buffer { $coursenum,$srcdom{$suffix},$srcnum{$suffix}, $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies, \%zombies,\%params,\%mapmoves,\%mapchanges, - \%tomove,\%newsubdir,\%newurls); + \%tomove,\%newsubdir,\%newurls,\%resdatacopy); } } elsif ($url=~m {^/res/}) { -# published map can only exists once, so remove from paste buffer when done +# published map can only exist once, so remove from paste buffer when done push(@toclear,$suffix); # if pasting published map (main content area only) check map not already in course if ($folder =~ /^default/) { @@ -1692,13 +1724,21 @@ sub do_paste_from_buffer { } if ($url=~ m{/(bulletinboard|smppg)$}) { my $prefix = $1; + my $fromothercrs; #need to copy the db contents to a new one, unless this is a move. my %info = ( src => $url, cdom => $coursedom, cnum => $coursenum, - ); - unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') { + ); + if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) { + unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) { + $fromothercrs = 1; + $info{'cdom'} = $srcdom{$suffix}; + $info{'cnum'} = $srcnum{$suffix}; + } + } + unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) { my (%lockerr,$msg); my ($newurl,$result,$errtext) = &dbcopy(\%info,$coursedom,$coursenum,\%lockerr); @@ -1774,6 +1814,12 @@ sub do_paste_from_buffer { } } } + } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) { + my $template = $1; + if ($newidx) { + ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix}, + $coursedom,$coursenum,$template,$newidx,"$folder.$container"); + } } $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url). ':'.$ext.':normal:res'; @@ -1787,7 +1833,8 @@ sub do_paste_from_buffer { } } -# Apply any changes to maps, or copy dependencies for uploaded HTML pages +# Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update +# resourcedata for simpleproblems copied from another course unless ($allresult eq 'fail') { my %updated = ( rewrites => \%rewrites, @@ -1795,6 +1842,7 @@ sub do_paste_from_buffer { removefrommap => \%removefrommap, removeparam => \%removeparam, dbcopies => \%dbcopies, + resdatacopy => \%resdatacopy, retitles => \%retitles, ); my %info = ( @@ -1959,8 +2007,8 @@ sub get_newmap_url { sub dbcopy { my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_; my ($url,$result,$errtext); - $url = $dbref->{'src'}; if (ref($dbref) eq 'HASH') { + $url = $dbref->{'src'}; if ($url =~ m{/(smppg|bulletinboard)$}) { my $prefix = $1; if (($dbref->{'cdom'} =~ /^$match_domain$/) && @@ -2051,6 +2099,97 @@ sub dbcopy { return ($url,$result,$errtext); } +sub copy_templated_files { + my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_; + my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo); + my $srccontainer = 'sequence'; + if ($srcwaspage) { + $srccontainer = 'page'; + } + my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer". + '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl); + my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb; + my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix); + my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'. + $template.'.problem'; + my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb; + if ($template eq 'simpleproblem') { + $srcprefix .= '.0.'; + my $weightprefix = $newprefix; + $newprefix .= '.0.'; + my @simpleprobqtypes = qw(radio option string essay numerical); + my $qtype=$srcparms{$srcprefix.'questiontype'}; + if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) { + my %newdata = ( + $newprefix.'questiontype' => $qtype, + ); + foreach my $type (@simpleprobqtypes) { + if ($type eq $qtype) { + $newdata{"$weightprefix.$type.weight"}=1; + } else { + $newdata{"$weightprefix.$type.weight"}=0; + } + } + $newdata{$newprefix.'hiddenparts'} = '!'.$qtype; + $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'}; + $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'}; + if ($qtype eq 'numerical') { + $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'}; + $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'}; + $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'}; + $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'}; + } elsif (($qtype eq 'option') || ($qtype eq 'radio')) { + my $maxfoils=$srcparms{$srcprefix.'maxfoils'}; + unless (defined($maxfoils)) { $maxfoils=10; } + unless ($maxfoils=~/^\d+$/) { $maxfoils=10; } + if ($maxfoils<=0) { $maxfoils=10; } + my $randomize=$srcparms{$srcprefix.'randomize'}; + unless (defined($randomize)) { $randomize='yes'; } + unless ($randomize eq 'no') { $randomize='yes'; } + $newdata{$newprefix.'maxfoils'} = $maxfoils; + $newdata{$newprefix.'randomize'} = $randomize; + if ($qtype eq 'option') { + $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'}; + } + for (my $i=1; $i<=10; $i++) { + $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i}; + $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i}; + $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i}; + } + + } elsif (($qtype eq 'option') || ($qtype eq 'radio')) { + my $maxfoils=$srcparms{$srcprefix.'maxfoils'}; + unless (defined($maxfoils)) { $maxfoils=10; } + unless ($maxfoils=~/^\d+$/) { $maxfoils=10; } + if ($maxfoils<=0) { $maxfoils=10; } + my $randomize=$srcparms{$srcprefix.'randomize'}; + unless (defined($randomize)) { $randomize='yes'; } + unless ($randomize eq 'no') { $randomize='yes'; } + $newdata{$newprefix.'maxfoils'} = $maxfoils; + $newdata{$newprefix.'randomize'} = $randomize; + if ($qtype eq 'option') { + $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'}; + } + for (my $i=1; $i<=10; $i++) { + $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i}; + $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i}; + $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i}; + } + } elsif ($qtype eq 'string') { + $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'}; + $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'}; + } + if (keys(%newdata)) { + my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom, + $coursenum); + if ($putres eq 'ok') { + &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom); + } + } + } + } +} + sub uniqueness_check { my ($newurl) = @_; my $unique = 1; @@ -2116,7 +2255,7 @@ sub contained_map_check { sub url_paste_fixups { my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps, $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves, - $mapchanges,$tomove,$newsubdir,$newurls) = @_; + $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_; my $checktitle; if (($prefixchg) && ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) { @@ -2165,7 +2304,7 @@ sub url_paste_fixups { $srcdom,$srcnum,$allmaps,$rewrites, $retitles,$copies,$dbcopies,$zombies, $params,$mapmoves,$mapchanges,$tomove, - $newsubdir,$newurls); + $newsubdir,$newurls,$resdatacopy); next; } else { ($newurl,my $error) = @@ -2189,7 +2328,7 @@ sub url_paste_fixups { $cnum,$srcdom,$srcnum,$allmaps, $rewrites,$retitles,$copies,$dbcopies, $zombies,$params,$mapmoves,$mapchanges, - $tomove,$newsubdir,$newurls)) { + $tomove,$newsubdir,$newurls,$resdatacopy)) { $mapmoves->{$ressrc} = 1; } $changed = 1; @@ -2218,6 +2357,12 @@ sub url_paste_fixups { $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum; $changed = 1; } + } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') { + if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) { + $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc; + $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom; + $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum; + } } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) { next if ($skip); my $srcdom = $1; @@ -2249,7 +2394,7 @@ sub apply_fixups { $oldurl,$url,$caller) = @_; my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles, %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs, - %lockerrors,$lockmsg); + %resdatacopy,%lockerrors,$lockmsg); if (ref($updated) eq 'HASH') { if (ref($updated->{'rewrites'}) eq 'HASH') { %rewrites = %{$updated->{'rewrites'}}; @@ -2269,6 +2414,9 @@ sub apply_fixups { if (ref($updated->{'retitles'}) eq 'HASH') { %retitles = %{$updated->{'retitles'}}; } + if (ref($updated->{'resdatacopy'}) eq 'HASH') { + %resdatacopy = %{$updated->{'resdatacopy'}}; + } } if (ref($info) eq 'HASH') { if (ref($info->{'newsubdir'}) eq 'HASH') { @@ -2419,6 +2567,36 @@ sub apply_fixups { } } } + if (ref($resdatacopy{$key}) eq 'HASH') { + my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer); + foreach my $idx (keys(%{$resdatacopy{$key}})) { + if (ref($resdatacopy{$key}{$idx}) eq 'HASH') { + my $srcurl = $resdatacopy{$key}{$idx}{'src'}; + if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) { + my $template = $1; + if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) && + ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) { + my $srcdom = $resdatacopy{$key}{$idx}{'cdom'}; + my $srcnum = $resdatacopy{$key}{$idx}{'cnum'}; + unless ($gotnewmapname) { + ($newmapname) = ($key =~ m{/([^/]+)$}); + ($srcfolder,$srccontainer) = split(/\./,$newmapname); + if ($newsubdir{$key}) { + $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/; + } + $gotnewmapname = 1; + } + my $srcmapinfo = $srcfolder.':'.$idx; + if ($srccontainer eq 'page') { + $srcmapinfo .= ':1'; + } + ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom, + $cnum,$template,$idx,$newmapname); + } + } + } + } + } if (ref($params{$key}) eq 'HASH') { %currparam = %{$params{$key}}; } @@ -2434,7 +2612,8 @@ sub apply_fixups { } } } - for (my $i=0; $i<@LONCAPA::map::order; $i++) { + my $total = scalar(@LONCAPA::map::order) - 1; + for (my $i=$total; $i>=0; $i--) { my $idx = $LONCAPA::map::order[$i]; if (defined($LONCAPA::map::resources[$idx])) { my $changed; @@ -2444,7 +2623,7 @@ sub apply_fixups { splice(@LONCAPA::map::order,$i,1); if (ref($currparam{$idx}) eq 'ARRAY') { foreach my $name (@{$currparam{$idx}}) { - &LONCAPA::map::delparameter($idx,'parameter_'.$name); + &LONCAPA::map::delparameter($idx,$name); } } next; @@ -2486,7 +2665,7 @@ sub apply_fixups { foreach my $idx (keys(%remparam)) { if (ref($remparam{$idx}) eq 'ARRAY') { foreach my $name (@{$remparam{$idx}}) { - &LONCAPA::map::delparameter($idx,'parameter_'.$name); + &LONCAPA::map::delparameter($idx,$name); } } } @@ -2745,8 +2924,8 @@ sub handle_edit_cmd { sub editor { my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype, - $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,$navmapref, - $hiddentop)=@_; + $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit, + $hostname,$navmapref,$hiddentop)=@_; my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container); if ($allowed) { (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain, @@ -3065,7 +3244,8 @@ sub editor { $output .= &entryline($idx,$name,$url,$folder,$allowed,$res, $coursenum,$coursedom,$crstype, $pathitem,$supplementalflag,$container, - \%filters,\%curr_groups,$canedit,$isencrypted,$navmapref); + \%filters,\%curr_groups,$canedit, + $isencrypted,$navmapref,$hostname); $idx++; $shown++; } @@ -3444,7 +3624,7 @@ sub is_supplemental_title { sub entryline { my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom, $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups, - $canedit,$isencrypted,$navmapref)=@_; + $canedit,$isencrypted,$navmapref,$hostname)=@_; my ($foldertitle,$renametitle,$oldtitle); if (&is_supplemental_title($title)) { ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title); @@ -3691,7 +3871,7 @@ END } } - my ($editlink,$extresform,$anchor,$hiddenres); + my ($editlink,$extresform,$anchor,$hiddenres,$nomodal); my $orig_url = $url; $orig_url=~s{http(:|:)//https(:|:)//}{https$2//}; $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/}; @@ -3709,8 +3889,23 @@ END } elsif ($url!~/\.(sequence|page)$/) { $url='/adm/coursedocs/showdoc'.$url; } - } elsif ($url=~m|^/ext/|) { - $url='/adm/wrapper'.$url; + } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) { + my $wrapped = $1; + my $exturl = $2; + if ($wrapped eq '') { + $url='/adm/wrapper'.$url; + } + if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) { + $nomodal = 1; + } + } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") { + if (($ENV{'SERVER_PORT'} == 443) && + ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { + unless (&Apache::lonnet::uses_sts()) { + $url .= '?usehttp=1'; + } + $nomodal = 1; + } } if (&Apache::lonnet::symbverify($symb,$url)) { my $shownsymb = $symb; @@ -3718,9 +3913,8 @@ END if ($url =~ /^([^#]+)#([^#]+)$/) { $url = $1; $anchor = $2; - if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) { - $shownsymb = $1.&escape('#').$anchor; - } + my $escan = &escape('#'); + $shownsymb =~ s/^([^\#]+)#([^\#]+)$/$1$escan$2/; } } unless ($env{'request.role.adv'}) { @@ -3733,14 +3927,14 @@ END } } if ($url ne '') { - $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&'); + $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb); } } elsif (!$env{'request.role.adv'}) { my $checkencrypt; if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) || $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) { $checkencrypt = 1; - } else { + } elsif (ref($navmapref)) { unless (ref($$navmapref)) { $$navmapref = Apache::lonnavmaps::navmap->new(); } @@ -3754,7 +3948,7 @@ END my $shownsymb = &Apache::lonenc::encrypted($symb); my $shownurl = &Apache::lonenc::encrypted($url); if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) { - $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&'); + $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb); if ($env{'request.enc'} ne '') { delete($env{'request.enc'}); } @@ -3773,6 +3967,26 @@ END if ($url =~ /^([^#]+)#([^#]+)$/) { $url = $1; $anchor = $2; + if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) { + unless (&Apache::lonnet::uses_sts()) { + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; + } + $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; + } + $nomodal = 1; + } + } + } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { + if (($ENV{'SERVER_PORT'} == 443) && + ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { + unless (&Apache::lonnet::uses_sts()) { + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; + } + $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; + } + $nomodal = 1; } } } @@ -3795,25 +4009,29 @@ END my $encryptmap = ((&LONCAPA::map::getparameter($orderidx, 'parameter_encrypturl'))[0]=~/^yes$/i); unless ($hiddenmap) { - unless (ref($$navmapref)) { - $$navmapref = Apache::lonnavmaps::navmap->new(); - } - if (ref($$navmapref)) { - if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') { - my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1); - unless (@resources) { - $hiddenmap = 1; - unless ($env{'request.role.adv'}) { - $url = ''; - $hiddenfolder = 1; + if (ref($navmapref)) { + unless (ref($$navmapref)) { + $$navmapref = Apache::lonnavmaps::navmap->new(); + } + if (ref($$navmapref)) { + if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') { + my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1); + unless (@resources) { + $hiddenmap = 1; + unless ($env{'request.role.adv'}) { + $url = ''; + $hiddenfolder = 1; + } } } } } } unless ($encryptmap) { - if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') { - $encryptmap = 1; + if ((ref($navmapref)) && (ref($$navmapref))) { + if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') { + $encryptmap = 1; + } } } @@ -3892,7 +4110,8 @@ $form_end; $forceedit, undef,$symb, &escape($env{'form.folderpath'}), - $renametitle,'','',1,$suppanchor); + $renametitle,$hostname, + '','',1,$suppanchor); if ($jscall) { $editlink = ''.&mt('Edit').' '."\n"; @@ -3909,6 +4128,7 @@ $form_end; $reinit = &mt('(re-initialize course to access)'); } $line.=''.$editlink.$renamelink; + my $link; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { $line.=''; } elsif ($url) { @@ -3919,9 +4139,20 @@ $form_end; $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&'); } } - $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. - (($anchor ne '')?$anchor:'')), - '',600,500); + + if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) { + $link = 'http://'.$hostname.$url; + } else { + $link = $url; + } + $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor); + if ($nomodal) { + $line.=''. + ''; + } else { + $line.=&Apache::loncommon::modal_link($link, + '',600,500); + } } else { $line.=''; } @@ -3929,11 +4160,14 @@ $form_end; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { $line.=''.$title.''; } elsif ($url) { - $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. - (($anchor ne '')?$anchor:'')), - $title,600,500); + if ($nomodal) { + $line.=''. + $title.''; + } else { + $line.=&Apache::loncommon::modal_link($link,$title,600,500); + } } elsif (($hiddenfolder) || ($hiddenres)) { - $line.=$title.' '.&mt('(Hidden)').''; + $line.=$title.' ('.&mt('Hidden').')'; } else { $line.=$title.' '.$reinit.''; } @@ -3991,9 +4225,11 @@ sub action_restrictions { if ($url=~ m{^/res/.+\.(page|sequence)$}) { # no copy for published maps $denied{'copy'} = 1; - } elsif ($url=~m{^/res/lib/templates/}) { - $denied{'copy'} = 1; - $denied{'cut'} = 1; + } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) { + unless ($1 eq 'simpleproblem') { + $denied{'copy'} = 1; + } + $denied{'cut'} = 1; } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") { if ($folderpath =~ /^default&[^\&]+$/) { if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) { @@ -4148,7 +4384,7 @@ sub untiehash { sub checkonthis { - my ($r,$url,$level,$title)=@_; + my ($r,$url,$level,$title,$checkstale)=@_; $url=&unescape($url); $alreadyseen{$url}=1; $r->rflush(); @@ -4163,10 +4399,22 @@ sub checkonthis { $r->print(''. ($title?$title:$url).' '); if ($url=~/^\/res\//) { + my $updated; + if (($checkstale) && ($url !~ m{^/res/lib/templates/}) && + ($url !~ /\.\d+\.\w+$/)) { + $updated = &Apache::lonnet::remove_stale_resfile($url); + } my $result=&Apache::lonnet::repcopy( &Apache::lonnet::filelocation('',$url)); if ($result eq 'ok') { $r->print(''.&mt('ok').''); + if ($updated) { + $r->print('
'); + for (my $i=0;$i<=$level*5;$i++) { + $r->print(' '); + } + $r->print('- '.&mt('Outdated copy removed')); + } $r->rflush(); &Apache::lonnet::countacc($url); $url=~/\.(\w+)$/; @@ -4200,7 +4448,7 @@ sub checkonthis { &Apache::lonnet::metadata($url,'dependencies'); foreach my $dep (split(/\,/,$dependencies)) { if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) { - &checkonthis($r,$dep,$level+1); + &checkonthis($r,$dep,$level+1,'',$checkstale); } } } elsif ($result eq 'unavailable') { @@ -4214,6 +4462,9 @@ sub checkonthis { } else { $r->print(''.&mt('access denied').''); } + if (($updated) && ($result ne 'ok')) { + $r->print('
'.&mt('Outdated copy removed')); + } } } } @@ -4266,9 +4517,29 @@ sub list_symbs { $r->print(&endContentScreen()); } +sub contentverifyform { + my ($r) = @_; + my $crstype = &Apache::loncommon::course_type(); + $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content')); + $r->print(&startContentScreen('tools')); + $r->print('

'.&mt($crstype.' content verification').'

'); + $r->print('

'. + &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?'). + ' '. + ''.(' 'x2). + '

'. + ''. + ''. + '

'); + $r->print(&endContentScreen()); + return; +} sub verifycontent { - my ($r) = @_; + my ($r,$checkstale) = @_; my $crstype = &Apache::loncommon::course_type(); $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content')); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content')); @@ -4289,7 +4560,7 @@ sub verifycontent { } } if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) { - &checkonthis($r,$hash{$key},0,$hash{'title_'.$1}); + &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale); } } &untiehash(); @@ -4756,9 +5027,25 @@ sub handler { $disabled = ' disabled="disabled"'; } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']); + if ($env{'form.inhibitmenu'}) { + unless ($env{'form.inhibitmenu'} eq 'yes') { + delete($env{'form.inhibitmenu'}); + } + } + if ($allowed && $env{'form.verify'}) { &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content'); - &verifycontent($r); + if (!$canedit) { + &verifycontent($r); + } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) { + &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}", + text=>'Results', + faq=>273, + bug=>'Instructor Interface'}); + &verifycontent($r,$env{'form.checkstale'}); + } else { + &contentverifyform($r); + } } elsif ($allowed && $env{'form.listsymbs'}) { &init_breadcrumbs('listsymbs','List Content IDs'); &list_symbs($r); @@ -4789,6 +5076,26 @@ sub handler { 'forcesupplement','forcestandard', 'tools','symb','command','supppath']); + foreach my $item ('forcesupplement','forcestandard','tools') { + next if ($env{'form.'.$item} eq ''); + unless ($env{'form.'.$item} eq '1') { + delete($env{'form.'.$item}); + } + } + + if ($env{'form.command'}) { + unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) { + delete($env{'form.command'}); + } + } + + if ($env{'form.symb'}) { + my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'}); + unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { + delete($env{'form.symb'}); + } + } + # standard=1: this is a "new-style" course with an uploaded map as top level # standard=2: this is a "old-style" course, and there is nothing we can do @@ -4811,6 +5118,38 @@ sub handler { my $toolsflag=0; if ($env{'form.tools'}) { $toolsflag=1; } + 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'}); + } + } + + if ($env{'form.supppath'} ne '') { + my @items = split(/\&/,$env{'form.supppath'}); + my $badpath; + for (my $i=0; $i<@items; $i++) { + my $odd = $i%2; + if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) { + $badpath = 1; + } + last if ($badpath); + } + if ($badpath) { + delete($env{'form.supppath'}); + } + } + my $script=''; my $showdoc=0; my $addentries = {}; @@ -4994,8 +5333,9 @@ sub handler { } } my $tabidstr = join("','",@tabids); + my $hostname = $r->hostname(); $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum, - $canedit,\$navmap). + $canedit,$hostname,\$navmap). &history_tab_js(). &inject_data_js(). &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid). @@ -5015,7 +5355,8 @@ sub handler { .'// '."\n" - .''."\n"; + .''."\n" + .''."\n"; # Breadcrumbs &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -5077,6 +5418,7 @@ sub handler { undef($hadchanges); $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom, \%allfiles,\%codebase,$context,$crstype); + undef($navmap); if ($hadchanges) { &mark_hash_old(); } @@ -5164,7 +5506,8 @@ sub handler { 'er' => 'Editing rights unavailable for your current role.', ); # ----------------------------------------------------------------------------- - # Calculate free quota space for a user or course. + # Calculate free quota space for a user or course. A javascript function checks + # file size to determine if upload should be allowed. my $quotatype = 'unofficial'; if ($crstype eq 'Community') { $quotatype = 'community'; @@ -5187,7 +5530,7 @@ sub handler { if ($disk_quota == 0) { $percent = 100.0; } else { - $percent = 100*($current_disk_usage/$disk_quota); + $percent = 100*($usage/$disk_quota); } $usage = sprintf("%.2f",$usage); $quota = sprintf("%.2f",$quota); @@ -5198,7 +5541,8 @@ sub handler { my $fileupload=(< - + + FIUP my $checkbox=(<hostname(); if ($allowed) { my $folder=$env{'form.folder'}; @@ -5592,13 +5937,15 @@ unless ($container eq 'page') { unless (($supplementalflag || $toolsflag)) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, $supplementalflag,\%orderhash,$iconpath,$pathitem, - $canedit,\$navmap,$hiddentop); + $canedit,$hostname,\$navmap,$hiddentop); undef($navmap); if ($error) { $r->print('

'.$error.'

'); } if ($hadchanges) { - &mark_hash_old(); + unless (&is_hash_old()) { + &mark_hash_old(); + } } &changewarning($r,''); @@ -5728,7 +6075,7 @@ my %suporderhash = ( if ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, $supplementalflag,\%suporderhash,$iconpath,$pathitem, - $canedit); + $canedit,$hostname); if ($error) { $r->print('

'.$error.'

'); } else { @@ -5748,7 +6095,7 @@ my %suporderhash = ( } } elsif ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,'',$iconpath,$pathitem); + $supplementalflag,'',$iconpath,$pathitem,'',$hostname); if ($error) { $r->print('

'.$error.'

'); } @@ -5782,6 +6129,7 @@ my %suporderhash = ( sub embedded_form_elems { my ($phase,$primaryurl,$newidx) = @_; my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); + $newidx =~s /\D+//g; return < @@ -5802,7 +6150,11 @@ sub embedded_destination { } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) { $destination .= $2.'/'; } - $destination .= $env{'form.newidx'}; + my $newidx = $env{'form.newidx'}; + $newidx =~s /\D+//g; + if ($newidx) { + $destination .= $newidx; + } my $dir_root = '/userfiles'; return ($destination,$dir_root); } @@ -5828,6 +6180,9 @@ sub decompression_info { } unshift(@hiddens,$pathitem); foreach my $item (@hiddens) { + if ($item eq 'newidx') { + next if ($env{'form.'.$item} =~ /\D/); + } if ($env{'form.'.$item}) { $hiddenelem .= ''."\n"; @@ -6120,7 +6475,8 @@ END } sub editing_js { - my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$canedit,$navmapref) = @_; + my ($udom,$uname,$supplementalflag,$coursedom,$coursenum, + $canedit,$hostname,$navmapref) = @_; my %js_lt = &Apache::lonlocal::texthash( p_mnf => 'Name of New Folder', t_mnf => 'New Folder', @@ -6192,8 +6548,33 @@ sub editing_js { } else { $url = $res; } - $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='. - &HTML::Entities::encode($caller,'<>&"'); + $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"'); + if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) { + $backtourl .= '?navmap=1'; + } else { + $backtourl .= '?symb='. + &HTML::Entities::encode($caller,'<>&"'); + } + if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { + if (($ENV{'SERVER_PORT'} == 443) && + ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { + unless (&Apache::lonnet::uses_sts()) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; + } + } + } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) { + if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) { + unless (&Apache::lonnet::uses_sts()) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; + } + } + } if ($anchor ne '') { $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"'); } @@ -7389,7 +7770,9 @@ check on this Verify Content -=item devalidateversioncache() & checkversions() +=item devalidateversioncache() + +=item checkversions() Check Versions