Diff for /loncom/interface/londocs.pm between versions 1.484.2.71 and 1.484.2.84

version 1.484.2.71, 2017/05/10 21:24:23 version 1.484.2.84, 2019/08/17 12:45:34
Line 834  sub docs_change_log { Line 834  sub docs_change_log {
              '// <![CDATA['."\n".               '// <![CDATA['."\n".
              &Apache::loncommon::display_filter_js('docslog')."\n".               &Apache::loncommon::display_filter_js('docslog')."\n".
              &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,               &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
                          $coursedom,$coursenum,$canedit,\$navmap)."\n".                           $coursedom,$coursenum,$canedit,'',\$navmap)."\n".
              &history_tab_js()."\n".               &history_tab_js()."\n".
              &Apache::lonratedt::editscript('simple')."\n".               &Apache::lonratedt::editscript('simple')."\n".
              '// ]]>'."\n".               '// ]]>'."\n".
Line 1061  sub update_paste_buffer { Line 1061  sub update_paste_buffer {
         foreach my $suffix (@currpaste) {          foreach my $suffix (@currpaste) {
              my $cid = $env{'docs.markedcopy_crs_'.$suffix};               my $cid = $env{'docs.markedcopy_crs_'.$suffix};
              my $url = $env{'docs.markedcopy_url_'.$suffix};               my $url = $env{'docs.markedcopy_url_'.$suffix};
                my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
              if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&               if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
                  ($url ne '')) {                   ($url ne '')) {
                  $pasteurls{$cid.'_'.$url} = 1;                   $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
              }               }
         }          }
     }      }
   
 # Mark items for copying (skip any items already in user's paste buffer)  # Mark items for copying (skip any items already in user's paste buffer)
     my %addtoenv;      my %addtoenv;
                     
       my @pathitems = split(/\&/,$env{'form.folderpath'});
       my @folderconf = split(/\:/,$pathitems[-1]);
       my $ispage = $folderconf[4];
   
     foreach my $item (@possibles) {      foreach my $item (@possibles) {
         my ($orderidx,$cmd) = split(/:/,$item);          my ($orderidx,$cmd) = split(/:/,$item);
         next if ($orderidx =~ /\D/);          next if ($orderidx =~ /\D/);
         next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));          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 ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
         my %denied = &action_restrictions($coursenum,$coursedom,          my %denied = &action_restrictions($coursenum,$coursedom,
                                           &LONCAPA::map::qtescape($url),                                            &LONCAPA::map::qtescape($url),
                                           $env{'form.folderpath'},\%curr_groups);                                            $env{'form.folderpath'},\%curr_groups);
         next if ($denied{'copy'});          next if ($denied{'copy'});
         $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};          $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
         next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));          next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
         my ($suffix,$errortxt,$locknotfreed) =          my ($suffix,$errortxt,$locknotfreed) =
             &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');              &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
         if ($suffix ne '') {          if ($suffix ne '') {
Line 1100  sub update_paste_buffer { Line 1106  sub update_paste_buffer {
         $addtoenv{'docs.markedcopy_url_'.$suffix}   = $url,          $addtoenv{'docs.markedcopy_url_'.$suffix}   = $url,
         $addtoenv{'docs.markedcopy_cmd_'.$suffix}   = $cmd,          $addtoenv{'docs.markedcopy_cmd_'.$suffix}   = $cmd,
         $addtoenv{'docs.markedcopy_crs_'.$suffix}   = $env{'request.course.id'};          $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)$}) {          if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
             my $prefix = $1;              my $prefix = $1;
             my $subdir =$2;              my $subdir =$2;
Line 1178  sub print_paste_buffer { Line 1184  sub print_paste_buffer {
         next if ($suffix =~ /\D/);          next if ($suffix =~ /\D/);
         my $cid = $env{'docs.markedcopy_crs_'.$suffix};          my $cid = $env{'docs.markedcopy_crs_'.$suffix};
         my $url = $env{'docs.markedcopy_url_'.$suffix};          my $url = $env{'docs.markedcopy_url_'.$suffix};
           my $mapidx = $env{'docs.markedcopy_map_'.$suffix}; 
         if (($cid =~ /^$match_domain\_$match_courseid$/) &&          if (($cid =~ /^$match_domain\_$match_courseid$/) &&
             ($url ne '')) {              ($url ne '')) {
             $clipboardcount ++;              $clipboardcount ++;
Line 1203  sub print_paste_buffer { Line 1210  sub print_paste_buffer {
                     if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {                      if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
                         $othercourse = 1;                          $othercourse = 1;
                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {                          if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
                             if ($canpaste) {                              $othercrs = '<br />'.&mt('(from another course)');
                                 $othercrs = '<br />'.&mt('(from another course)');  
                             }  
                         } else {                          } else {
                             $canpaste = 0;                              $canpaste = 0;
                             $nopaste = &mt('Paste from another course unavailable.');                               $nopaste = &mt('Paste from another course unavailable.'); 
Line 1219  sub print_paste_buffer { Line 1224  sub print_paste_buffer {
                         }                          }
                         $is_uploaded_map = 1;                          $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 = '<br />'.&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;              my $buffer;
             if ($is_external) {              if ($is_external) {
Line 1508  sub do_paste_from_buffer { Line 1524  sub do_paste_from_buffer {
     }      }
   
     my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,      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) {      foreach my $suffix (@topaste) {
         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});          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  # Supplemental content may only include certain types of content
 # Early out if pasted content is not supported in Supplemental area  # Early out if pasted content is not supported in Supplemental area
         if ($folder =~ /^supplemental/) {          if ($folder =~ /^supplemental/) {
Line 1533  sub do_paste_from_buffer { Line 1551  sub do_paste_from_buffer {
             }              }
             $srcdom{$suffix} = $srcd;              $srcdom{$suffix} = $srcd;
             $srcnum{$suffix} = $srcn;              $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);          push(@dopaste,$suffix);
         if ($url=~/\.(page|sequence)$/) {          if ($url=~/\.(page|sequence)$/) {
             $is_map{$suffix} = 1;               $is_map{$suffix} = 1; 
Line 1544  sub do_paste_from_buffer { Line 1575  sub do_paste_from_buffer {
             my $oldprefix = $1;              my $oldprefix = $1;
 # When pasting content from Main Content to Supplemental Content and vice versa   # When pasting content from Main Content to Supplemental Content and vice versa 
 # URLs will contain different paths (which depend on whether pasted item is  # 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'))) {              if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
                 $prefixchg{$suffix} = 'docstosupp';                  $prefixchg{$suffix} = 'docstosupp';
             } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {              } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
Line 1612  sub do_paste_from_buffer { Line 1643  sub do_paste_from_buffer {
 # Retrieve information about all course maps in main content area   # Retrieve information about all course maps in main content area 
   
     my $allmaps = {};      my $allmaps = {};
     if ($folder =~ /^default/) {      my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
         $allmaps =  
             &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,  
                                                  $env{"course.$env{'request.course.id'}.home"},  
                                                  $env{'request.course.id'});  
     }  
   
     my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);  
   
 # Loop over the items to paste  # Loop over the items to paste
     foreach my $suffix (@dopaste) {      foreach my $suffix (@dopaste) {
 # Maps need to be copied first  # Maps need to be copied first
         my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,          my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
             %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,              %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
             %newurls,%tomove);              %newurls,%tomove,%resdatacopy);
         if (ref($marktomove{$suffix}) eq 'ARRAY') {          if (ref($marktomove{$suffix}) eq 'ARRAY') {
             map { $tomove{$_} = 1; } @{$marktomove{$suffix}};              map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
         }          }
         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});          my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
         my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});          my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
           my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
         my $oldurl = $url;          my $oldurl = $url;
         if ($is_map{$suffix}) {          if ($is_map{$suffix}) {
 # If pasting a map, check if map contains other maps  # If pasting a map, check if map contains other maps
             my (%hierarchy,%titles);              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,              &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
                                  \%addedmaps,\%hierarchy,\%titles,$allmaps);                                   \%addedmaps,\%hierarchy,\%titles,$allmaps);
             if ($url=~ m{^/uploaded/}) {              if ($url=~ m{^/uploaded/}) {
Line 1667  sub do_paste_from_buffer { Line 1699  sub do_paste_from_buffer {
                                               \%retitles,\%copies,\%dbcopies,                                                \%retitles,\%copies,\%dbcopies,
                                               \%zombies,\%params,\%mapmoves,                                                \%zombies,\%params,\%mapmoves,
                                               \%mapchanges,\%tomove,\%newsubdir,                                                \%mapchanges,\%tomove,\%newsubdir,
                                               \%newurls)) {                                                \%newurls,\%resdatacopy)) {
                         $mapmoves{$url} = 1;                          $mapmoves{$url} = 1;
                     }                      }
                     $url = $newurl;                      $url = $newurl;
Line 1676  sub do_paste_from_buffer { Line 1708  sub do_paste_from_buffer {
                                       $coursenum,$srcdom{$suffix},$srcnum{$suffix},                                        $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                                       $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,                                        $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
                                       \%zombies,\%params,\%mapmoves,\%mapchanges,                                        \%zombies,\%params,\%mapmoves,\%mapchanges,
                                       \%tomove,\%newsubdir,\%newurls);                                         \%tomove,\%newsubdir,\%newurls,\%resdatacopy); 
                 }                  }
             } elsif ($url=~m {^/res/}) {              } 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);                  push(@toclear,$suffix);
 # if pasting published map (main content area only) check map not already in course  # if pasting published map (main content area only) check map not already in course
                 if ($folder =~ /^default/) {                  if ($folder =~ /^default/) {
Line 1692  sub do_paste_from_buffer { Line 1724  sub do_paste_from_buffer {
         }          }
         if ($url=~ m{/(bulletinboard|smppg)$}) {          if ($url=~ m{/(bulletinboard|smppg)$}) {
             my $prefix = $1;              my $prefix = $1;
               my $fromothercrs;
             #need to copy the db contents to a new one, unless this is a move.              #need to copy the db contents to a new one, unless this is a move.
             my %info = (              my %info = (
                          src  => $url,                           src  => $url,
                          cdom => $coursedom,                           cdom => $coursedom,
                          cnum => $coursenum,                           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 (%lockerr,$msg); 
                 my ($newurl,$result,$errtext) =                  my ($newurl,$result,$errtext) =
                     &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);                      &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
Line 1774  sub do_paste_from_buffer { Line 1814  sub do_paste_from_buffer {
                         }                          }
                     }                      }
                 }                  }
               } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   my $template = $1;
                   if ($newidx) {
                       &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                                             $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                   }
             }              }
             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).              $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                                               ':'.$ext.':normal:res';                                                ':'.$ext.':normal:res';
Line 1787  sub do_paste_from_buffer { Line 1833  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') {          unless ($allresult eq 'fail') {
             my %updated = (              my %updated = (
                             rewrites      => \%rewrites,                              rewrites      => \%rewrites,
Line 1795  sub do_paste_from_buffer { Line 1842  sub do_paste_from_buffer {
                             removefrommap => \%removefrommap,                              removefrommap => \%removefrommap,
                             removeparam   => \%removeparam,                              removeparam   => \%removeparam,
                             dbcopies      => \%dbcopies,                              dbcopies      => \%dbcopies,
                               resdatacopy   => \%resdatacopy,
                             retitles      => \%retitles,                              retitles      => \%retitles,
                           );                            );
             my %info = (              my %info = (
Line 2051  sub dbcopy { Line 2099  sub dbcopy {
     return ($url,$result,$errtext);      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 {  sub uniqueness_check {
     my ($newurl) = @_;      my ($newurl) = @_;
     my $unique = 1;      my $unique = 1;
Line 2116  sub contained_map_check { Line 2255  sub contained_map_check {
 sub url_paste_fixups {  sub url_paste_fixups {
     my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,      my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
         $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,          $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
         $mapchanges,$tomove,$newsubdir,$newurls) = @_;          $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
     my $checktitle;      my $checktitle;
     if (($prefixchg) &&      if (($prefixchg) &&
         ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {          ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
Line 2165  sub url_paste_fixups { Line 2304  sub url_paste_fixups {
                                           $srcdom,$srcnum,$allmaps,$rewrites,                                            $srcdom,$srcnum,$allmaps,$rewrites,
                                           $retitles,$copies,$dbcopies,$zombies,                                            $retitles,$copies,$dbcopies,$zombies,
                                           $params,$mapmoves,$mapchanges,$tomove,                                            $params,$mapmoves,$mapchanges,$tomove,
                                           $newsubdir,$newurls);                                            $newsubdir,$newurls,$resdatacopy);
                         next;                          next;
                     } else {                      } else {
                         ($newurl,my $error) =                          ($newurl,my $error) =
Line 2189  sub url_paste_fixups { Line 2328  sub url_paste_fixups {
                                                   $cnum,$srcdom,$srcnum,$allmaps,                                                    $cnum,$srcdom,$srcnum,$allmaps,
                                                   $rewrites,$retitles,$copies,$dbcopies,                                                    $rewrites,$retitles,$copies,$dbcopies,
                                                   $zombies,$params,$mapmoves,$mapchanges,                                                    $zombies,$params,$mapmoves,$mapchanges,
                                                   $tomove,$newsubdir,$newurls)) {                                                    $tomove,$newsubdir,$newurls,$resdatacopy)) {
                             $mapmoves->{$ressrc} = 1;                              $mapmoves->{$ressrc} = 1;
                         }                          }
                         $changed = 1;                          $changed = 1;
Line 2218  sub url_paste_fixups { Line 2357  sub url_paste_fixups {
                     $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;                      $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
                     $changed = 1;                      $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)/(.+)$}) {              } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
                 next if ($skip);                  next if ($skip);
                 my $srcdom = $1;                  my $srcdom = $1;
Line 2249  sub apply_fixups { Line 2394  sub apply_fixups {
         $oldurl,$url,$caller) = @_;          $oldurl,$url,$caller) = @_;
     my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,      my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
         %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,          %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
         %lockerrors,$lockmsg);          %resdatacopy,%lockerrors,$lockmsg);
     if (ref($updated) eq 'HASH') {      if (ref($updated) eq 'HASH') {
         if (ref($updated->{'rewrites'}) eq 'HASH') {          if (ref($updated->{'rewrites'}) eq 'HASH') {
             %rewrites = %{$updated->{'rewrites'}};              %rewrites = %{$updated->{'rewrites'}};
Line 2269  sub apply_fixups { Line 2414  sub apply_fixups {
         if (ref($updated->{'retitles'}) eq 'HASH') {          if (ref($updated->{'retitles'}) eq 'HASH') {
             %retitles = %{$updated->{'retitles'}};              %retitles = %{$updated->{'retitles'}};
         }          }
           if (ref($updated->{'resdatacopy'}) eq 'HASH') {
               %resdatacopy = %{$updated->{'resdatacopy'}};
           }
     }      }
     if (ref($info) eq 'HASH') {      if (ref($info) eq 'HASH') {
         if (ref($info->{'newsubdir'}) eq 'HASH') {          if (ref($info->{'newsubdir'}) eq 'HASH') {
Line 2419  sub apply_fixups { Line 2567  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';
                                   }
                                   &copy_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
                                                         $cnum,$template,$idx,$newmapname);
                               }
                           }
                       }
                   }
               }
             if (ref($params{$key}) eq 'HASH') {              if (ref($params{$key}) eq 'HASH') {
                 %currparam = %{$params{$key}};                  %currparam = %{$params{$key}};
             }              }
Line 2434  sub apply_fixups { Line 2612  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];                  my $idx = $LONCAPA::map::order[$i];
                 if (defined($LONCAPA::map::resources[$idx])) {                  if (defined($LONCAPA::map::resources[$idx])) {
                     my $changed;                      my $changed;
Line 2444  sub apply_fixups { Line 2623  sub apply_fixups {
                         splice(@LONCAPA::map::order,$i,1);                          splice(@LONCAPA::map::order,$i,1);
                         if (ref($currparam{$idx}) eq 'ARRAY') {                          if (ref($currparam{$idx}) eq 'ARRAY') {
                             foreach my $name (@{$currparam{$idx}}) {                              foreach my $name (@{$currparam{$idx}}) {
                                 &LONCAPA::map::delparameter($idx,'parameter_'.$name);                                  &LONCAPA::map::delparameter($idx,$name);
                             }                              }
                         }                          }
                         next;                          next;
Line 2486  sub apply_fixups { Line 2665  sub apply_fixups {
             foreach my $idx (keys(%remparam)) {              foreach my $idx (keys(%remparam)) {
                 if (ref($remparam{$idx}) eq 'ARRAY') {                  if (ref($remparam{$idx}) eq 'ARRAY') {
                     foreach my $name (@{$remparam{$idx}}) {                         foreach my $name (@{$remparam{$idx}}) {   
                         &LONCAPA::map::delparameter($idx,'parameter_'.$name);                          &LONCAPA::map::delparameter($idx,$name);
                     }                      }
                 }                  }
             }              }
Line 2745  sub handle_edit_cmd { Line 2924  sub handle_edit_cmd {
   
 sub editor {  sub editor {
     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,      my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
         $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,$navmapref,          $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,
         $hiddentop)=@_;          $hostname,$navmapref,$hiddentop)=@_;
     my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);      my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
     if ($allowed) {      if ($allowed) {
         (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,          (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
Line 3066  sub editor { Line 3245  sub editor {
                               $coursenum,$coursedom,$crstype,                                $coursenum,$coursedom,$crstype,
                               $pathitem,$supplementalflag,$container,                                $pathitem,$supplementalflag,$container,
                               \%filters,\%curr_groups,$canedit,                                \%filters,\%curr_groups,$canedit,
                               $isencrypted,$navmapref);                                $isencrypted,$navmapref,$hostname);
         $idx++;          $idx++;
         $shown++;          $shown++;
     }      }
Line 3445  sub is_supplemental_title { Line 3624  sub is_supplemental_title {
 sub entryline {  sub entryline {
     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,      my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
         $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,          $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
         $canedit,$isencrypted,$navmapref)=@_;          $canedit,$isencrypted,$navmapref,$hostname)=@_;
     my ($foldertitle,$renametitle,$oldtitle);      my ($foldertitle,$renametitle,$oldtitle);
     if (&is_supplemental_title($title)) {      if (&is_supplemental_title($title)) {
  ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);   ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
Line 3722  END Line 3901  END
             } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {              } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
                 if (($ENV{'SERVER_PORT'} == 443) &&                  if (($ENV{'SERVER_PORT'} == 443) &&
                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {                      ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
                       unless (&Apache::lonnet::uses_sts()) {
                           $url .= '?usehttp=1';
                       }
                     $nomodal = 1;                      $nomodal = 1;
                 }                  }
     }      }
Line 3731  END Line 3913  END
                     if ($url =~ /^([^#]+)#([^#]+)$/) {                      if ($url =~ /^([^#]+)#([^#]+)$/) {
                         $url = $1;                          $url = $1;
                         $anchor = $2;                          $anchor = $2;
                         if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {                          my $escan = &escape('#');
                             $shownsymb = $1.&escape('#').$anchor;                          $shownsymb =~ s/^([^\#]+)#([^\#]+)$/$1$escan$2/;
                         }  
                     }                      }
                 }                  }
                 unless ($env{'request.role.adv'}) {                  unless ($env{'request.role.adv'}) {
Line 3746  END Line 3927  END
                     }                      }
                 }                  }
                 if ($url ne '') {                  if ($url ne '') {
                     $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');                      $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
                 }                  }
             } elsif (!$env{'request.role.adv'}) {              } elsif (!$env{'request.role.adv'}) {
                 my $checkencrypt;                  my $checkencrypt;
Line 3767  END Line 3948  END
                     my $shownsymb = &Apache::lonenc::encrypted($symb);                      my $shownsymb = &Apache::lonenc::encrypted($symb);
                     my $shownurl = &Apache::lonenc::encrypted($url);                      my $shownurl = &Apache::lonenc::encrypted($url);
                     if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {                      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 '') {                          if ($env{'request.enc'} ne '') {
                             delete($env{'request.enc'});                              delete($env{'request.enc'});
                         }                          }
Line 3787  END Line 3968  END
                 $url = $1;                  $url = $1;
                 $anchor = $2;                  $anchor = $2;
                 if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {                  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 =~ /\?/) ? '&amp;':'?').'usehttp=1';
                       }
                     $nomodal = 1;                      $nomodal = 1;
                 }                  }
             }              }
         } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {          } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
             if (($ENV{'SERVER_PORT'} == 443) &&              if (($ENV{'SERVER_PORT'} == 443) &&
                 ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {                  ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
                   unless (&Apache::lonnet::uses_sts()) {
                       if ($hostname ne '') {
                           $url = 'http://'.$hostname.$url;
                       }
                       $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
                   }
                 $nomodal = 1;                  $nomodal = 1;
             }              }
         }          }
Line 3917  $form_end; Line 4110  $form_end;
                                                             $forceedit,                                                              $forceedit,
                                                             undef,$symb,                                                              undef,$symb,
                                                             &escape($env{'form.folderpath'}),                                                              &escape($env{'form.folderpath'}),
                                                             $renametitle,'','',1,$suppanchor);                                                              $renametitle,$hostname,
                                                               '','',1,$suppanchor);
                 if ($jscall) {                  if ($jscall) {
                     $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.                      $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
                                 $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";                                  $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";
Line 3945  $form_end; Line 4139  $form_end;
                $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');                 $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
            }             }
        }         }
        $link = &js_escape($url.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.  
                                                (($anchor ne '')?$anchor:''));         if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
              $link = 'http://'.$hostname.$url;
          } else {
              $link = $url;
          }
          $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.$anchor);
        if ($nomodal) {         if ($nomodal) {
            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.             $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';                    '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
Line 3968  $form_end; Line 4167  $form_end;
            $line.=&Apache::loncommon::modal_link($link,$title,600,500);             $line.=&Apache::loncommon::modal_link($link,$title,600,500);
        }         }
     } elsif (($hiddenfolder) || ($hiddenres)) {      } elsif (($hiddenfolder) || ($hiddenres)) {
        $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';         $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
     } else {      } else {
        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';         $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
     }      }
Line 4026  sub action_restrictions { Line 4225  sub action_restrictions {
     if ($url=~ m{^/res/.+\.(page|sequence)$}) {      if ($url=~ m{^/res/.+\.(page|sequence)$}) {
         # no copy for published maps          # no copy for published maps
         $denied{'copy'} = 1;          $denied{'copy'} = 1;
     } elsif ($url=~m{^/res/lib/templates/}) {      } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
        $denied{'copy'} = 1;          unless ($1 eq 'simpleproblem') {
        $denied{'cut'} = 1;              $denied{'copy'} = 1;
           }
           $denied{'cut'} = 1;
     } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {      } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
         if ($folderpath =~ /^default&[^\&]+$/) {          if ($folderpath =~ /^default&[^\&]+$/) {
             if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {              if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
Line 4183  sub untiehash { Line 4384  sub untiehash {
   
   
 sub checkonthis {  sub checkonthis {
     my ($r,$url,$level,$title)=@_;      my ($r,$url,$level,$title,$checkstale)=@_;
     $url=&unescape($url);      $url=&unescape($url);
     $alreadyseen{$url}=1;      $alreadyseen{$url}=1;
     $r->rflush();      $r->rflush();
Line 4198  sub checkonthis { Line 4399  sub checkonthis {
        $r->print('<a href="'.$url.'" target="cat">'.         $r->print('<a href="'.$url.'" target="cat">'.
  ($title?$title:$url).'</a> ');   ($title?$title:$url).'</a> ');
        if ($url=~/^\/res\//) {         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(    my $result=&Apache::lonnet::repcopy(
                               &Apache::lonnet::filelocation('',$url));                                &Apache::lonnet::filelocation('',$url));
           if ($result eq 'ok') {            if ($result eq 'ok') {
              $r->print('<span class="LC_success">'.&mt('ok').'</span>');               $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                if ($updated) {
                    $r->print('<br />');
                    for (my $i=0;$i<=$level*5;$i++) {
                        $r->print('&nbsp;');
                    }
                    $r->print('- '.&mt('Outdated copy removed'));
                }
              $r->rflush();               $r->rflush();
              &Apache::lonnet::countacc($url);               &Apache::lonnet::countacc($url);
              $url=~/\.(\w+)$/;               $url=~/\.(\w+)$/;
Line 4235  sub checkonthis { Line 4448  sub checkonthis {
                 &Apache::lonnet::metadata($url,'dependencies');                  &Apache::lonnet::metadata($url,'dependencies');
              foreach my $dep (split(/\,/,$dependencies)) {               foreach my $dep (split(/\,/,$dependencies)) {
  if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {   if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
                     &checkonthis($r,$dep,$level+1);                      &checkonthis($r,$dep,$level+1,'',$checkstale);
                  }                   }
              }               }
           } elsif ($result eq 'unavailable') {            } elsif ($result eq 'unavailable') {
Line 4249  sub checkonthis { Line 4462  sub checkonthis {
           } else {            } else {
              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');               $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
           }            }
             if (($updated) && ($result ne 'ok')) {
                 $r->print('<br />'.&mt('Outdated copy removed'));
             }
        }         }
     }      }
 }  }
Line 4301  sub list_symbs { Line 4517  sub list_symbs {
     $r->print(&endContentScreen());      $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('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
       $r->print('<form method="post" action="/adm/coursedocs"><p>'.
                 &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
                 '&nbsp;<span class="LC_nobreak">'.
                 '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
                 &mt('No').'</label>'.('&nbsp;'x2).
                 '<label><input type="radio" name="checkstale" value="1" />'.
                 &mt('Yes').'</label></span></p><p>'.
                 '<input type="submit" value="'.&mt('Verify content').' "/>'.
                 '<input type="hidden" value="1" name="tools" />'.
                 '<input type="hidden" value="1" name="verify" /></p></form>');
       $r->print(&endContentScreen());
       return;
   }
   
 sub verifycontent {  sub verifycontent {
     my ($r) = @_;      my ($r,$checkstale) = @_;
     my $crstype = &Apache::loncommon::course_type();      my $crstype = &Apache::loncommon::course_type();
     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));      $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));      $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
Line 4324  sub verifycontent { Line 4560  sub verifycontent {
    }     }
        }         }
        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {         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();     &untiehash();
Line 4791  sub handler { Line 5027  sub handler {
         $disabled = ' disabled="disabled"';          $disabled = ' disabled="disabled"';
     }      }
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);      &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'}) {    if ($allowed && $env{'form.verify'}) {
       &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');        &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'}) {    } elsif ($allowed && $env{'form.listsymbs'}) {
       &init_breadcrumbs('listsymbs','List Content IDs');        &init_breadcrumbs('listsymbs','List Content IDs');
       &list_symbs($r);        &list_symbs($r);
Line 4824  sub handler { Line 5076  sub handler {
                                              'forcesupplement','forcestandard',                                               'forcesupplement','forcestandard',
                                              'tools','symb','command','supppath']);                                               '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=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  # standard=2: this is a "old-style" course, and there is nothing we can do
   
Line 4846  sub handler { Line 5118  sub handler {
     my $toolsflag=0;      my $toolsflag=0;
     if ($env{'form.tools'}) { $toolsflag=1; }      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 $script='';
     my $showdoc=0;      my $showdoc=0;
     my $addentries = {};      my $addentries = {};
Line 5029  sub handler { Line 5333  sub handler {
                 }                  }
             }              }
             my $tabidstr = join("','",@tabids);              my $tabidstr = join("','",@tabids);
               my $hostname = $r->hostname();
     $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,      $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
                                    $canedit,\$navmap).                                     $canedit,$hostname,\$navmap).
                        &history_tab_js().                         &history_tab_js().
                        &inject_data_js().                         &inject_data_js().
                        &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).                         &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
Line 5050  sub handler { Line 5355  sub handler {
               .'// <![CDATA['."\n"                .'// <![CDATA['."\n"
               .$script."\n"                .$script."\n"
               .'// ]]>'."\n"                .'// ]]>'."\n"
               .'</script>'."\n";                .'</script>'."\n"
                 .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
   
     # Breadcrumbs      # Breadcrumbs
     &Apache::lonhtmlcommon::clear_breadcrumbs();      &Apache::lonhtmlcommon::clear_breadcrumbs();
Line 5112  sub handler { Line 5418  sub handler {
   undef($hadchanges);    undef($hadchanges);
           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,            $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
                                               \%allfiles,\%codebase,$context,$crstype);                                                \%allfiles,\%codebase,$context,$crstype);
             undef($navmap);
   if ($hadchanges) {    if ($hadchanges) {
       &mark_hash_old();        &mark_hash_old();
   }    }
Line 5199  sub handler { Line 5506  sub handler {
                 'er' => 'Editing rights unavailable for your current role.',                  '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';      my $quotatype = 'unofficial';
     if ($crstype eq 'Community') {      if ($crstype eq 'Community') {
         $quotatype = 'community';          $quotatype = 'community';
Line 5233  sub handler { Line 5541  sub handler {
  my $fileupload=(<<FIUP);   my $fileupload=(<<FIUP);
         $quotainfo          $quotainfo
  $lt{'file'}:<br />   $lt{'file'}:<br />
  <input type="file" name="uploaddoc" size="40" $disabled />   <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
           <input type="hidden" id="LC_free_space" value="$free_space" />
 FIUP  FIUP
   
  my $checkbox=(<<CHBO);   my $checkbox=(<<CHBO);
Line 5633  unless ($container eq 'page') { Line 5942  unless ($container eq 'page') {
              $r->print('<p><span class="LC_error">'.$error.'</span></p>');               $r->print('<p><span class="LC_error">'.$error.'</span></p>');
           }            }
           if ($hadchanges) {            if ($hadchanges) {
              &mark_hash_old();               unless (&is_hash_old()) {
                    &mark_hash_old();
                }
           }            }
   
           &changewarning($r,'');            &changewarning($r,'');
Line 5817  my %suporderhash = ( Line 6128  my %suporderhash = (
 sub embedded_form_elems {  sub embedded_form_elems {
     my ($phase,$primaryurl,$newidx) = @_;      my ($phase,$primaryurl,$newidx) = @_;
     my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');      my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
       $newidx =~s /\D+//g;
     return <<STATE;      return <<STATE;
     <input type="hidden" name="folderpath" value="$folderpath" />      <input type="hidden" name="folderpath" value="$folderpath" />
     <input type="hidden" name="cmd" value="upload_embedded" />      <input type="hidden" name="cmd" value="upload_embedded" />
Line 5837  sub embedded_destination { Line 6149  sub embedded_destination {
     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {      } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
         $destination .=  $2.'/';          $destination .=  $2.'/';
     }      }
     $destination .= $env{'form.newidx'};      my $newidx = $env{'form.newidx'};
       $newidx =~s /\D+//g;
       if ($newidx) {
           $destination .= $newidx;
       }
     my $dir_root = '/userfiles';      my $dir_root = '/userfiles';
     return ($destination,$dir_root);      return ($destination,$dir_root);
 }  }
Line 5863  sub decompression_info { Line 6179  sub decompression_info {
     }      }
     unshift(@hiddens,$pathitem);      unshift(@hiddens,$pathitem);
     foreach my $item (@hiddens) {      foreach my $item (@hiddens) {
           if ($item eq 'newidx') {
               next if ($env{'form.'.$item} =~ /\D/);
           }
         if ($env{'form.'.$item}) {          if ($env{'form.'.$item}) {
             $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.              $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
                            &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";                             &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
Line 6155  END Line 6474  END
 }  }
   
 sub editing_js {  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(      my %js_lt = &Apache::lonlocal::texthash(
                                           p_mnf => 'Name of New Folder',                                            p_mnf => 'Name of New Folder',
                                           t_mnf => 'New Folder',                                            t_mnf => 'New Folder',
Line 6227  sub editing_js { Line 6547  sub editing_js {
                 } else {                  } else {
                     $url = $res;                      $url = $res;
                 }                  }
                 $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.                  $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
                              &HTML::Entities::encode($caller,'<>&"');                  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 =~ /\?/) ? '&amp;':'?').'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 =~ /\?/) ? '&amp;':'?').'usehttp=1';
                           }
                       }
                   }
                 if ($anchor ne '') {                  if ($anchor ne '') {
                     $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');                      $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
                 }                  }
Line 7424  check on this Line 7769  check on this
   
 Verify Content  Verify Content
   
 =item devalidateversioncache() & checkversions()  =item devalidateversioncache()
   
   =item checkversions()
   
 Check Versions  Check Versions
   

Removed from v.1.484.2.71  
changed lines
  Added in v.1.484.2.84


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>