Diff for /loncom/interface/londocs.pm between versions 1.484.2.72.2.2 and 1.484.2.93.2.15

version 1.484.2.72.2.2, 2017/09/15 23:15:55 version 1.484.2.93.2.15, 2023/09/06 13:35:14
Line 43  use Apache::lonnavdisplay(); Line 43  use Apache::lonnavdisplay();
 use Apache::lonextresedit();  use Apache::lonextresedit();
 use Apache::lontemplate();  use Apache::lontemplate();
 use Apache::lonsimplepage();  use Apache::lonsimplepage();
   use Apache::loncourserespicker();
 use HTML::Entities;  use HTML::Entities;
 use HTML::TokeParser;  use HTML::TokeParser;
 use GDBM_File;  use GDBM_File;
 use File::MMagic;  use File::MMagic;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Cwd;  use Cwd;
   use UUID::Tiny ':std';
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
   
 my $iconpath;  my $iconpath;
Line 85  sub storemap { Line 87  sub storemap {
   
     if ($map =~ /^default/) {      if ($map =~ /^default/) {
         $hadchanges=1;          $hadchanges=1;
     } else {      } elsif ($contentchg) {
         $suppchanges=1;          $suppchanges=1;
     }      }
     return ($errtext,0);      return ($errtext,0);
Line 177  sub default_folderpath { Line 179  sub default_folderpath {
     }      }
 }  }
   
   sub validate_supppath {
       my ($coursenum,$coursedom) = @_;
       my $backto;
       if ($env{'form.supppath'} ne '') {
           my @items = split(/\&/,$env{'form.supppath'});
           my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
           for (my $i=0; $i<@items; $i++) {
               my $odd = $i%2;
               if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
                   $badpath = 1;
                   last;
               } elsif ($odd) {
                   my $suffix;
                   my $idx = $i-1;
                   if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
                       $backto .= '&'.$1;
                   } elsif ($items[$idx] eq 'supplemental') {
                       $backto .= '&'.$items[$i];
                   } else {
                       $backto .= '&'.$items[$i];
                       my $is_hidden;
                       unless ($got_supp) {
                           my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
                           if (ref($supplemental) eq 'HASH') {
                               if (ref($supplemental->{'hidden'}) eq 'HASH') {
                                   %supphidden = %{$supplemental->{'hidden'}};
                               }
                               if (ref($supplemental->{'ids'}) eq 'HASH') {
                                   %suppids = %{$supplemental->{'ids'}};
                               }
                           }
                           $got_supp = 1;
                       }
                       if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
                           my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
                           if ($supphidden{$mapid}) {
                               $is_hidden = 1;
                           }
                       }
                       $suffix = '::'.$is_hidden.':::';
                   }
                   $supppath .= '&'.$items[$i].$suffix;
               } else {
                   $supppath .= '&'.$items[$i];
                   $backto .= '&'.$items[$i];
               }
           }
           if ($badpath) {
               delete($env{'form.supppath'});
           } else {
               $supppath =~ s/^\&//;
               $backto =~ s/^\&//;
               $env{'form.supppath'} = $supppath;
           }
       }
       return $backto;
   }
   
 sub dumpcourse {  sub dumpcourse {
     my ($r) = @_;      my ($r) = @_;
     my $crstype = &Apache::loncommon::course_type();      my $crstype = &Apache::loncommon::course_type();
Line 655  sub group_import { Line 715  sub group_import {
                 $url = $1;                  $url = $1;
                 my $marker = $2;                  my $marker = $2;
                 my $info = $3;                  my $info = $3;
                 my ($toolid,%toolhash,%toolsettings);                  my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
                 my @extras = ('linktext','explanation','crslabel','crstitle');                   my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
                 my @toolinfo = split(/:/,$info);                  my @toolinfo = split(/:/,$info);
                 if ($residx) {                  if ($residx) {
                     %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);                      %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
Line 664  sub group_import { Line 724  sub group_import {
                 } else {                  } else {
                     $toolid = shift(@toolinfo);                      $toolid = shift(@toolinfo);
                 }                  }
                   if ($toolid =~ /^c/) {
                       $tooltype = 'crs';
                       $toolprefix = 'c';
                   } else {
                       $tooltype = 'dom';
                   }
                 $toolid =~ s/\D//g;                  $toolid =~ s/\D//g;
                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},                  ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
                  $toolhash{'linktext'},$toolhash{'explanation'},                   $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
                  $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;                   $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
                 foreach my $item (@extras) {                  foreach my $item (@extras) {
                     $toolhash{$item} = &unescape($toolhash{$item});                      $toolhash{$item} = &unescape($toolhash{$item});
                 }                  }
                   if ($folder =~ /^supplemental/) {
                       delete($toolhash{'gradable'});
                   } else {
                       $toolhash{'gradable'} =~ s/\D+//g;
                   }
                 if (ref($ltitoolsref) eq 'HASH') {                  if (ref($ltitoolsref) eq 'HASH') {
                     my @deleted;                      if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
                     if (ref($ltitoolsref->{$toolid}) eq 'HASH') {                          if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
                         $toolhash{'id'} = $toolid;                              my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
                         if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||                              my @deleted;
                             ($toolhash{'target'} eq 'window')) {                              $toolhash{'id'} = $toolprefix.$toolid;
                             if ($toolhash{'target'} eq 'window') {                              if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
                                 foreach my $item ('width','height') {                                  ($toolhash{'target'} eq 'window')) {
                                     $toolhash{$item} =~ s/^\s+//;                                  if ($toolhash{'target'} eq 'window') {
                                     $toolhash{$item} =~ s/\s+$//;                                      foreach my $item ('width','height') {
                                     if ($toolhash{$item} =~ /\D/) {                                          $toolhash{$item} =~ s/^\s+//;
                                         delete($toolhash{$item});                                          $toolhash{$item} =~ s/\s+$//;
                                         if ($residx) {                                          if ($toolhash{$item} =~ /\D/) {
                                             if ($toolsettings{$item}) {                                              delete($toolhash{$item});
                                                 push(@deleted,$item);                                              if ($residx) {
                                                   if ($toolsettings{$item}) {
                                                       push(@deleted,$item);
                                                   }
                                             }                                              }
                                         }                                          }
                                     }                                      }
                                 }                                  }
                             }                              } elsif ($residx) {
                         } elsif ($residx) {                                  $toolhash{'target'} = $toolsettings{'target'};
                             $toolhash{'target'} = $toolsettings{'target'};                                  if ($toolhash{'target'} eq 'window') {
                             if ($toolhash{'target'} eq 'window') {                                      foreach my $item ('width','height') {
                                 foreach my $item ('width','height') {                                          $toolhash{$item} = $toolsettings{$item};
                                     $toolhash{$item} = $toolsettings{$item};                                      }
                                   }
                               } elsif (ref($tools{'display'}) eq 'HASH') {
                                   $toolhash{'target'} = $tools{'display'}{'target'};
                                   if ($toolhash{'target'} eq 'window') {
                                       $toolhash{'width'} = $tools{'display'}{'width'};
                                       $toolhash{'height'} = $tools{'display'}{'height'};
                                 }                                  }
                             }                              }
                         } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {                              if ($toolhash{'target'} eq 'iframe') {
                             $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};                                  foreach my $item ('width','height','linktext','explanation') {
                             if ($toolhash{'target'} eq 'window') {                                      delete($toolhash{$item});
                                 $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};                                      if ($residx) {
                                 $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};                                          if ($toolsettings{$item}) {
                             }                                              push(@deleted,$item);
                         }                                          }
                         if ($toolhash{'target'} eq 'iframe') {  
                             foreach my $item ('width','height','linktext','explanation') {  
                                 delete($toolhash{$item});  
                                 if ($residx) {  
                                     if ($toolsettings{$item}) {  
                                         push(@deleted,$item);  
                                     }                                      }
                                 }                                  }
                             }                              } elsif ($toolhash{'target'} eq 'tab') {
                         } elsif ($toolhash{'target'} eq 'tab') {                                  foreach my $item ('width','height') {
                             foreach my $item ('width','height') {                                      delete($toolhash{$item});
                                 delete($toolhash{$item});                                      if ($residx) {
                                 if ($residx) {                                          if ($toolsettings{$item}) {
                                     if ($toolsettings{$item}) {                                              push(@deleted,$item);
                                         push(@deleted,$item);                                          }
                                     }                                      }
                                 }                                  }
                             }                              }
                         }                              if (ref($tools{'crsconf'}) eq 'HASH') {
                         if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {                                  foreach my $item ('label','title','linktext','explanation') {
                             foreach my $item ('label','title','linktext','explanation') {                                      my $crsitem;
                                 my $crsitem;                                      if (($item eq 'label') || ($item eq 'title')) {
                                 if (($item eq 'label') || ($item eq 'title')) {                                          $crsitem = 'crs'.$item;
                                     $crsitem = 'crs'.$item;                                      } else {
                                 } else {                                          $crsitem = $item;
                                     $crsitem = $item;                                      }
                                 }                                      if ($tools{'crsconf'}{$item}) {
                                 if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {                                          $toolhash{$crsitem} =~ s/^\s+//;
                                     $toolhash{$crsitem} =~ s/^\s+//;                                          $toolhash{$crsitem} =~ s/\s+$//;
                                     $toolhash{$crsitem} =~ s/\s+$//;                                          if ($toolhash{$crsitem} eq '') {
                                     if ($toolhash{$crsitem} eq '') {                                              delete($toolhash{$crsitem});
                                           }
                                       } else {
                                         delete($toolhash{$crsitem});                                          delete($toolhash{$crsitem});
                                     }                                      }
                                 } else {                                      if (($residx) && (exists($toolsettings{$crsitem}))) {
                                     delete($toolhash{$crsitem});                                          unless (exists($toolhash{$crsitem})) {
                                               push(@deleted,$crsitem);
                                           }
                                       }
                                 }                                  }
                                 if (($residx) && (exists($toolsettings{$crsitem}))) {                              }
                                     unless (exists($toolhash{$crsitem})) {                              if ($toolhash{'passback'}) {
                                         push(@deleted,$crsitem);                                  my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                                   $toolhash{'gradesecret'} = $gradesecret;
                                   $toolhash{'gradesecretdate'} = time;
                               }
                               if ($toolhash{'roster'}) {
                                   my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                                   $toolhash{'rostersecret'} = $rostersecret;
                                   $toolhash{'rostersecretdate'} = time;
                               }
                               my $changegradable;
                               if (($residx) && ($folder =~ /^default/)) {
                                   if ($toolsettings{'gradable'}) {
                                       unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
                                           push(@deleted,'gradable');
                                           $changegradable = 1;
                                       }
                                   } elsif ($toolhash{'gradable'}) {
                                       $changegradable = 1;
                                   }
                                   if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
                                       $changegradable = 1;
                                       if ($toolsettings{'gradable'}) {
                                           $toolhash{'gradable'} = 1;
                                     }                                      }
                                 }                                  }
                             }                              }
                         }                              my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
                         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);                              if ($putres eq 'ok') {
                         if ($putres eq 'ok') {                                  if (@deleted) {
                             if (@deleted) {                                      &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
                                 &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);                                  }
                                   if (($changegradable) && ($folder =~ /^default/)) {
                                       my $val;
                                       if ($toolhash{'gradable'}) {
                                           $val = 'yes';
                                       } else {
                                           $val = 'no';
                                       }
                                       &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
                                                                     'string_yesno');
                                       &remember_parms($residx,'gradable','set',$val);
                                   }
                               } else {
                                   return (&mt('Failed to save update to external tool.'),1);
                             }                              }
                         }                          }
                     }                      }
Line 782  sub group_import { Line 896  sub group_import {
     }      }
     my $ext = 'false';      my $ext = 'false';
     if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }      if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
     $name = &LONCAPA::map::qtunescape($name);  
             if ($name eq '') {  
                 $name = &LONCAPA::map::qtunescape(&mt('Web Page'));  
             }  
             if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {              if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
                 my $filepath = $1;                  my $filepath = $1;
                 my $fname = $name;                  my $fname;
                 if ($fname =~ /^\W+$/) {                  if ($name eq '') {
                       $name = &mt('Web Page');
                     $fname = 'web';                      $fname = 'web';
                 } else {                  } else {
                     $fname =~ s/\W/_/g;                      $fname = $name;
                 }                      $fname=&Apache::lonnet::clean_filename($fname);
                 if (length($fname) > 15) {                      if ($fname eq '') {
                     $fname = substr($fname,0,14);                          $fname = 'web';
                       } elsif (length($fname) > 15) {
                           $fname = substr($fname,0,14);
                       }
                 }                  }
                   my $title = &Apache::loncommon::cleanup_html($name);
                 my $initialtext = &mt('Replace with your own content.');                  my $initialtext = &mt('Replace with your own content.');
                 my $newhtml = <<END;                  my $newhtml = <<END;
 <html>  <html>
 <head>  <head>
 <title>$name</title>  <title>$title</title>
 </head>  </head>
 <body bgcolor="#ffffff">  <body bgcolor="#ffffff">
 $initialtext  $initialtext
Line 823  END Line 938  END
                     return (&mt('Failed to save new web page.'),1);                      return (&mt('Failed to save new web page.'),1);
                 }                  }
             }              }
               $name = &LONCAPA::map::qtunescape($name);
             $url  = &LONCAPA::map::qtunescape($url);              $url  = &LONCAPA::map::qtunescape($url);
     $LONCAPA::map::resources[$residx] =      $LONCAPA::map::resources[$residx] =
  join(':', ($name, $url, $ext, 'normal', 'res'));   join(':', ($name, $url, $ext, 'normal', 'res'));
Line 863  END Line 979  END
         &storemap($coursenum, $coursedom, $folder.'.'.$container,1);          &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
     unless ($fatal) {      unless ($fatal) {
         if ($folder =~ /^supplemental/) {          if ($folder =~ /^supplemental/) {
             &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);  
             my ($errtext,$fatal) = &mapread($coursenum,$coursedom,              my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                                             $folder.'.'.$container);                                              $folder.'.'.$container);
         }          }
Line 940  sub docs_change_log { Line 1055  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 990  sub docs_change_log { Line 1105  sub docs_change_log {
     'encrypturl'     => 'URL hidden',      'encrypturl'     => 'URL hidden',
     'randompick'     => 'Randomly pick',      'randompick'     => 'Randomly pick',
     'randomorder'    => 'Randomly ordered',      'randomorder'    => 'Randomly ordered',
               'gradable'       => 'Grade can be assigned to External Tool',
     'set'            => 'set to',      'set'            => 'set to',
     'del'            => 'deleted');      'del'            => 'deleted');
     my $filter = &Apache::loncommon::display_filter('docslog')."\n".      my $filter = &Apache::loncommon::display_filter('docslog')."\n".
Line 1096  sub docs_change_log { Line 1212  sub docs_change_log {
  }   }
  $r->print('</ul>');   $r->print('</ul>');
  if ($docslog{$id}{'logentry'}{'parameter_res'}) {   if ($docslog{$id}{'logentry'}{'parameter_res'}) {
     $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');              my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
     foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {              if ($title eq '') {
                   ($title) = ($url =~ m{/([^/]+)$});
               } elsif ($is_supp) {
                   $title = &Apache::loncommon::parse_supplemental_title($title);
               }
               $r->print(&LONCAPA::map::qtescape($title).':<ul>');
       foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
  if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {   if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
 # FIXME: internationalization seems wrong here  # FIXME: internationalization seems wrong here
     $r->print('<li>'.      $r->print('<li>'.
Line 1165  sub update_paste_buffer { Line 1287  sub update_paste_buffer {
 # Construct identifiers for current contents of user's paste buffer  # Construct identifiers for current contents of user's paste buffer
     if (@currpaste) {      if (@currpaste) {
         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};
              if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&              my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
                  ($url ne '')) {              if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
                  $pasteurls{$cid.'_'.$url} = 1;                  ($url ne '')) {
              }                  if ($url eq '/res/lib/templates/simpleproblem.problem') {
                       $pasteurls{$cid.'_'.$mapidx} = 1;
                   } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                       $pasteurls{$url} = 1;
                   } else {
                       $pasteurls{$cid.'_'.$url} = 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[5];
   
     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}));          if ($url eq '/res/lib/templates/simpleproblem.problem') {
               next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
           } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
               next if (exists($pasteurls{$url}));
           } else {
               next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
           }
         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 1206  sub update_paste_buffer { Line 1346  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 1276  sub print_paste_buffer { Line 1416  sub print_paste_buffer {
     }      }
   
     my @currpaste = split(/,/,$env{'docs.markedcopies'});      my @currpaste = split(/,/,$env{'docs.markedcopies'});
     my ($pasteitems,@pasteable);      my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
     my $clipboardcount = 0;      my $clipboardcount = 0;
   
 # Construct identifiers for current contents of user's paste buffer  # Construct identifiers for current contents of user's paste buffer
Line 1284  sub print_paste_buffer { Line 1424  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 ++;
             my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,              my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
                 $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);                  $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
                   $toolcnum,$marker);
             my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];              my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
             if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {              if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
                 $is_external = 1;                  $is_external = 1;
             } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {              } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                   ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
                 $is_exttool = 1;                  $is_exttool = 1;
             }              }
             if ($folder =~ /^supplemental/) {              if ($folder =~ /^supplemental/) {
Line 1330  sub print_paste_buffer { Line 1473  sub print_paste_buffer {
                     if ($cid ne $env{'request.course.id'}) {                      if ($cid ne $env{'request.course.id'}) {
                         my ($srcdom,$srcnum) = split(/_/,$cid);                          my ($srcdom,$srcnum) = split(/_/,$cid);
                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {                          if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
                             if (($is_exttool) && ($srcdom ne $coursedom)) {                              if ($is_exttool) {
                                 $canpaste = 0;                                  if ($toolcdom ne $coursedom) {
                                 $nopaste = &mt('Paste from another domain unavailable.');                                      $canpaste = 0;
                             } else {                                      $nopaste = &mt('Paste from another domain unavailable.');
                                 $othercrs = '<br />'.&mt('(from another course)');                                  } elsif ($toolcnum ne $coursenum) {
                                       my %toolsettings =
                                           &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
                                       my %tooltypes = &Apache::loncommon::usable_exttools();
                                       if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                                           (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                                           $canpaste = 0;
                                           $nopaste = &mt('Paste from another course unavailable.');
                                       } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
                                           unless ($checkedsameinst) {
                                               my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
                                               my $intdom = &Apache::lonnet::internet_dom($primary_id);
                                               if ($intdom ne '') {
                                                   my $internet_names =
                                                       &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                                                   if (ref($internet_names) eq 'ARRAY') {
                                                       if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                                                           $same_institution = 1;
                                                       }
                                                   }
                                               }
                                               $checkedsameinst = 1;
                                           }
                                           if ($same_institution) {
                                               $othercrs = '<br />'.&mt('(from another course)');
                                           } else {
                                               $nopaste = &mt('Paste from another course unavailable.');
                                           }
                                       } else {
                                           $othercrs = '<br />'.&mt('(from another course)');
                                       }
                                   }
                             }                              }
                         } else {                          } else {
                             $canpaste = 0;                              $canpaste = 0;
Line 1342  sub print_paste_buffer { Line 1516  sub print_paste_buffer {
                         }                          }
                     }                      }
                 }                  }
             }                  if ($canpaste) {
             if ($canpaste) {                      push(@pasteable,$suffix);
                push(@pasteable,$suffix);                  }
             }              }
             my $buffer;              my $buffer;
             if ($is_external) {               if ($is_external) {
                 $buffer = &mt('External Resource').': '.                  $buffer = &mt('External Resource').': '.
                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.                      &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
                     &LONCAPA::map::qtescape($url).')';                      &LONCAPA::map::qtescape($url).')';
Line 1383  sub print_paste_buffer { Line 1557  sub print_paste_buffer {
             }              }
             $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';              $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
             if ($nopaste) {              if ($nopaste) {
                  $pasteitems .= $nopaste;                      $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';   
             } else {              } else {
                 if ($othercrs) {                  if ($othercrs) {
                     $pasteitems .= $othercrs;                      $pasteitems .= $othercrs;
Line 1633  sub do_paste_from_buffer { Line 1807  sub do_paste_from_buffer {
         return();          return();
     }      }
   
     my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,      my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
         %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult);          %othcrstool,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
           %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
           %currltititles,$currltimax,$gotcrsltitools);
       $currltimax = 0;
       $gotcrsltitools = 0;
     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 $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 1660  sub do_paste_from_buffer { Line 1838  sub do_paste_from_buffer {
             }              }
             $srcdom{$suffix} = $srcd;              $srcdom{$suffix} = $srcd;
             $srcnum{$suffix} = $srcn;              $srcnum{$suffix} = $srcn;
         } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {          } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
                    ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
                    ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
             my ($srcd,$srcn) = split(/_/,$cid);              my ($srcd,$srcn) = split(/_/,$cid);
 # When paste buffer was populated using an active role in a different course  # 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  # check for mdc privilege in the course from which the resource was pasted
Line 1671  sub do_paste_from_buffer { Line 1851  sub do_paste_from_buffer {
                 }                  }
             }              }
 # When buffer was populated using an active role in a different course  # When buffer was populated using an active role in a different course
 # disallow pasting of External Tool if course is in a different domain.  # disallow pasting of External Tool if course is in a different domain,
             if ($srcd ne $coursedom) {  # or if External Tool use is not permitted in this course.
                 $notindom{$suffix} = 1;              if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                 next;                  my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
                   if ($toolcdom ne $coursedom) {
                       $notindom{$suffix} = 1;
                       next;
                   } elsif ($toolcnum ne $coursenum) {
                       my %toolsettings =
                           &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
                       my %tooltypes = &Apache::loncommon::usable_exttools();
                       if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                           (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                           $othcrstool{$suffix} = 1;
                           next;
                       }
                       if ($toolsettings{'id'} =~ /^c\d+$/) {
                           unless ($gotcrsltitools) {
                               %currcrsltitools =
                                   &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
                               foreach my $item (sort(keys(%currcrsltitools))) {
                                   if (ref($currcrsltitools{$item}) eq 'HASH') {
                                       $currltimax ++;
                                       if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
                                           push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
                                       } else {
                                           $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
                                       }
                                   }
                               }
                               $gotcrsltitools = 1;
                           }
                       }
                   }
             }              }
             $srcdom{$suffix} = $srcd;              $srcdom{$suffix} = $srcd;
             $srcnum{$suffix} = $srcn;              $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; 
         }          }
   
         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {          if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
             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 
Line 1728  sub do_paste_from_buffer { Line 1938  sub do_paste_from_buffer {
     %msgs = &Apache::lonlocal::texthash (      %msgs = &Apache::lonlocal::texthash (
                 notinsupp => 'Paste failed: content type is not supported within Supplemental Content',                  notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
                 notincrs  => 'Paste failed: Item is from a different course which you do not have rights to edit.',                  notincrs  => 'Paste failed: Item is from a different course which you do not have rights to edit.',
                 notindom  => 'Paste failed: Item is an external tool from a course in a different donain.',                   notindom  => 'Paste failed: Item is an external tool from a course in a different domain.',
                   othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
                 duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',                  duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
             );              );
   
Line 1757  sub do_paste_from_buffer { Line 1968  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 =          @updatetoolsenc,$updatetoolscache,$checkedsameinst,
             &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,          $same_institution);
                                                  $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}};
         }          }
Line 1782  sub do_paste_from_buffer { Line 1988  sub do_paste_from_buffer {
         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,$coursenum,$coursedom,              &contained_map_check($url,$folder,$coursenum,$coursedom,
                                  \%removefrommap,\%removeparam,\%addedmaps,                                   \%removefrommap,\%removeparam,\%addedmaps,
                                  \%hierarchy,\%titles,$allmaps);                                   \%hierarchy,\%titles,$allmaps);
Line 1814  sub do_paste_from_buffer { Line 2027  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 1823  sub do_paste_from_buffer { Line 2036  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 exist once, so remove from paste buffer when done  # published map can only exist once, so remove from paste buffer when done
Line 1837  sub do_paste_from_buffer { Line 2050  sub do_paste_from_buffer {
                 }                  }
             }              }
         }          }
         if ($url=~ m{/(ext\.tool)$}) {          if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
             my $prefix = $1;              my $prefix = $1;
             my $fromothercrs;              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.
Line 1845  sub do_paste_from_buffer { Line 2058  sub do_paste_from_buffer {
                          src  => $url,                           src  => $url,
                          cdom => $coursedom,                           cdom => $coursedom,
                          cnum => $coursenum,                           cnum => $coursenum,
             );                         );
               if ($prefix eq 'ext.tool') {
                   if ($prefixchg{$suffix} eq 'docstosupp') {
                       $info{'delgradable'} = 1;
                   }
               }
             if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {              if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
                 unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {                  unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
                     $fromothercrs = 1;                      $fromothercrs = 1;
                     $info{'cdom'} = $srcdom{$suffix};                      $info{'cdom'} = $srcdom{$suffix};
                     $info{'cnum'} = $srcnum{$suffix};                      $info{'cnum'} = $srcnum{$suffix};
                       unless ($checkedsameinst) {
                           my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
                           my $intdom = &Apache::lonnet::internet_dom($primary_id);
                           if ($intdom ne '') {
                               my $internet_names =
                                   &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                               if (ref($internet_names) eq 'ARRAY') {
                                   if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                                       $same_institution = 1;
                                   }
                               }
                           }
                           $checkedsameinst = 1;
                       }
                 }                  }
             }              }
             unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {              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,\%currltititles,
                               \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
                 if ($result eq 'ok') {                  if ($result eq 'ok') {
                     $url = $newurl;                      $url = $newurl;
                     $title=&mt('Copy of').' '.$title;                      $title=&mt('Copy of').' '.$title;
                 } else {                  } else {
                     if ($prefix eq 'ext.tool') {                      if ($prefix eq 'smppg') {
                           $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
                       } elsif ($prefix eq 'bulletinboard') {
                           $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
                       } elsif ($prefix eq 'ext.tool') {
                         $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;                          $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
                     }                      }
                     $results{$suffix} = $result;                      $results{$suffix} = $result;
Line 1927  sub do_paste_from_buffer { Line 2164  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");
                   }
               } elsif ($url =~ /ext\.tool$/) {
                   if (($newidx) && ($folder=~/^default/)) {
                       my $marker = (split(m{/},$url))[4];
                       my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
                       my $val = 'no';
                       if ($toolsettings{'gradable'}) {
                           $val = 'yes';
                       }
                       &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
                                                     'string_yesno');
                       &remember_parms($newidx,'gradable','set',$val);
                   }
             }              }
             $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 1940  sub do_paste_from_buffer { Line 2195  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 1948  sub do_paste_from_buffer { Line 2204  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 2001  sub do_paste_from_buffer { Line 2258  sub do_paste_from_buffer {
             }              }
         }          }
     }      }
       if (($updatetoolscache) || (@updatetoolsenc)) {
           &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
                                   \@updatetoolsenc);
       }
     &clear_from_buffer(\@toclear,\@currpaste);      &clear_from_buffer(\@toclear,\@currpaste);
     my $msgsarray;      my $msgsarray;
     foreach my $suffix (keys(%msgs)) {      foreach my $suffix (keys(%msgs)) {
Line 2049  sub clear_from_buffer { Line 2310  sub clear_from_buffer {
     return $numdel;      return $numdel;
 }  }
   
   sub update_ltitools_caches {
       my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
       my $hashid=$coursedom.'_'.$coursenum;
       if ($updatetoolscache) {
           &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
       }
       if ((ref($updatetoolsenc) eq 'ARRAY') &&
           (@{$updatetoolsenc})) {
           my @ids=&Apache::lonnet::current_machine_ids();
           my $updatedone;
           foreach my $lonhost (@{$updatetoolsenc}) {
               if (grep(/^\Q$lonhost\E$/,@ids)) {
                   unless ($updatedone) {
                       &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
                   }
                   $updatedone = 1;
               } else {
                   &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
               }
           }
       }
       return;
   }
   
 sub get_newmap_url {  sub get_newmap_url {
     my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,      my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
         $titleref,$allmaps,$newurls) = @_;          $titleref,$allmaps,$newurls) = @_;
Line 2110  sub get_newmap_url { Line 2395  sub get_newmap_url {
 }  }
   
 sub dbcopy {  sub dbcopy {
     my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;      my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
           $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
     my ($url,$result,$errtext);      my ($url,$result,$errtext);
     if (ref($dbref) eq 'HASH') {      if (ref($dbref) eq 'HASH') {
         $url = $dbref->{'src'};          $url = $dbref->{'src'};
Line 2154  sub dbcopy { Line 2440  sub dbcopy {
                     my %contents=&Apache::lonnet::dump($db_name,                      my %contents=&Apache::lonnet::dump($db_name,
                                                        $dbref->{'cdom'},                                                         $dbref->{'cdom'},
                                                        $dbref->{'cnum'});                                                         $dbref->{'cnum'});
                       my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
                       if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
                           if ($contents{'id'} =~ /^(|c)(\d+)$/) {
                               $oldtoolid = $2;
                               if ($1 eq 'c') {
                                   $defincrs = 1;
                                   %toolinfo =
                                       &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
                               } else {
                                   %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
                               }
                               if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
                                   if ($toolinfo{$oldtoolid}{'passback'}) {
                                       $toolpassback = 1;
                                   }
                                   if ($toolinfo{$oldtoolid}{'roster'}) {
                                       $toolroster = 1;
                                   }
                               } else {
                                   $toolcopyerror = 1;
                                   $errtext = &mt('Could not retrieve original settings for pasted external tool.');
                               }
                           }
                           unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
                               $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
                               if ($contents{'crstitle'} ne '') {
                                   $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
                               }
                               if (($defincrs) && (!$toolcopyerror)) {
                                   my %newtool;
                                   my $oldcdom = $dbref->{'cdom'};
                                   my $oldcnum = $dbref->{'cnum'};
                                   my $title = $toolinfo{$oldtoolid}{'title'};
                                   if (ref($currltititles) eq 'HASH') {
                                       if (exists($currltititles->{$title})) {
                                           $title .= ' (copied from another course)';
                                       }
                                   }
                                   my ($newid,$iderror) =
                                       &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
                                   if ($newid =~ /^\d+$/) {
                                       %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
                                       $newtool{$newid}{'title'} = $title;
                                       if (ref($currltimax)) {
                                           $newtool{$newid}{'order'} = $$currltimax;
                                       }
                                       if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
                                           my $fname = $1;
                                           my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
                                           if ($content eq '-1') {
                                               delete($newtool{$newid}{'image'});
                                           } else {
                                               $env{'form.'.$suffix.'.image'} = $content;
                                               my $newlogo =
                                                   &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
                                               delete($env{'form.'.$suffix.'.image'});
                                               if ($newlogo =~ m{^/uploaded/}) {
                                                   $newtool{$newid}{'image'} = $newlogo;
                                               } else {
                                                   delete($newtool{$newid}{'image'});
                                               }
                                           }
                                       }
                                       my $newusable;
                                       if ($same_institution) {
                                           my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
                                           if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
                                               my %newtoolsenc;
                                               %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
                                               my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
                                               if ($putres eq 'ok') {
                                                   if (ref($updatetoolsenc) eq 'ARRAY') {
                                                       my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
                                                       unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
                                                           push(@{$updatetoolsenc},$newhome);
                                                       }
                                                   }
                                                   $newusable = 1;
                                               }
                                           }
                                       }
                                       if ($newtool{$newid}{'usable'}) {
                                           unless ($newusable) {
                                               delete($newtool{$newid}{'usable'});
                                           }
                                       }
                                       my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
                                       if ($putres eq 'ok') {
                                           $contents{'id'} = "c$newid";
                                           if (ref($updatetoolscache)) {
                                               $$updatetoolscache ++;
                                           }
                                           if (ref($currltititles->{$title}) eq 'ARRAY') {
                                               push(@{$currltititles->{$title}},$newid);
                                           } else {
                                               $currltititles->{$title} = [$newid];
                                           }
                                           if (ref($currltimax)) {
                                               $$currltimax ++;
                                           }
                                       } else {
                                           $toolcopyerror = 1;
                                           $errtext = &mt('Unable to save external tool definition in Course Settings.');
                                       }
                                   } else {
                                       $toolcopyerror = 1;
                                       $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
                                   }
                               }
                           }
                       }
                     if (exists($contents{'uploaded.photourl'})) {                      if (exists($contents{'uploaded.photourl'})) {
                         my $photo = $contents{'uploaded.photourl'};                          my $photo = $contents{'uploaded.photourl'};
                         my ($subdir,$fname) =                          my ($subdir,$fname) =
Line 2173  sub dbcopy { Line 2570  sub dbcopy {
                         }                          }
                     }                      }
                     $db_name =~ s{_\d*$ }{_$suffix}x;                      $db_name =~ s{_\d*$ }{_$suffix}x;
                     $result=&Apache::lonnet::put($db_name,\%contents,                      if ($prefix eq 'exttool') {
                                                  $coursedom,$coursenum);                          unless ($toolcopyerror) {
                     if ($result eq 'ok') {                              foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
                         $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;                                  if (exists($contents{$key})) {
                                       delete($contents{$key});
                                   }
                               }
                               if ($dbref->{'delgradable'}) {
                                   if (exists($contents{'gradable'})) {
                                       delete($contents{'gradable'});
                                   }
                               }
                               if ($toolpassback) {
                                   if ($contents{'gradable'}) {
                                       my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                                       $contents{'gradesecret'} = $gradesecret;
                                       $contents{'gradesecretdate'} = time;
                                   }
                               }
                               if ($toolroster) {
                                   my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                                   $contents{'rostersecret'} = $rostersecret;
                                   $contents{'rostersecretdate'} = time;
                               }
                           }
                       }
                       if (($prefix eq 'exttool') && ($toolcopyerror)) {
                           $result = 'error';
                       } else {
                           $result=&Apache::lonnet::put($db_name,\%contents,
                                                        $coursedom,$coursenum);
                           if ($result eq 'ok') {
                               $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
                           }
                     }                      }
                 }                  }
                 if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {                  if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
Line 2214  sub dbcopy { Line 2641  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 2240  sub contained_map_check { Line 2758  sub contained_map_check {
             if ($token->[1] eq 'resource') {              if ($token->[1] eq 'resource') {
                 next if ($token->[2]->{'type'} eq 'zombie');                  next if ($token->[2]->{'type'} eq 'zombie');
                 my $ressrc = $token->[2]->{'src'};                  my $ressrc = $token->[2]->{'src'};
                 if ($folder =~ /^supplemental/) {                  if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                       my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
                       unless ($srcdom eq $coursedom) {
                           $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                           next;
                       }
                       unless ($srcnum eq $coursenum) {
                           my %toolsettings =
                               &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
                           my %tooltypes = &Apache::loncommon::usable_exttools();
                           if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                               (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                               $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                               next;
                           }
                       }
                   } elsif ($folder =~ /^supplemental/) {
                     unless (&supp_pasteable($ressrc)) {                      unless (&supp_pasteable($ressrc)) {
                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;                          $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                         next;                          next;
Line 2280  sub contained_map_check { Line 2814  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 2329  sub url_paste_fixups { Line 2863  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 2353  sub url_paste_fixups { Line 2887  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 2363  sub url_paste_fixups { Line 2897  sub url_paste_fixups {
                         $changed = 1;                          $changed = 1;
                     }                      }
                 }                  }
             } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {              } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
                 next if ($skip);                  next if ($skip);
                 my $srcdom = $1;                  my $srcdom = $1;
                 my $srcnum = $2;                  my $srcnum = $2;
                   my $rem = $3;
                   my ($is_exttool,$exttoolchg);
                   if ($rem =~ m{\d+/ext\.tool$}) {
                       $is_exttool = 1;
                   }
                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {                  if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
                     $rewrites->{$oldurl}{$id} = $ressrc;                      $rewrites->{$oldurl}{$id} = $ressrc;
                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;                      $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;                      $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;                      $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                     $changed = 1;                      $changed = 1;
                       if ($is_exttool) {
                           $exttoolchg = 1;
                       }
                   } elsif (($is_exttool) &&
                            ($env{'form.docs.markedcopy_options'} ne 'move')) {
                       $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                       $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                       $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                       $changed = 1;
                       $exttoolchg = 1;
                   }
                   if (($is_exttool) && ($prefixchg)) {
                       if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
                           if ($exttoolchg) {
                               $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
                           }
                       }
                 }                  }
             } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {              } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||                  if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
Line 2382  sub url_paste_fixups { Line 2938  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 2413  sub apply_fixups { Line 2975  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,%currcrsltitools,$gotcrsltitools,
           %currltititles,$currltimax);
       $currltimax = 0;
     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 2433  sub apply_fixups { Line 2997  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 2526  sub apply_fixups { Line 3093  sub apply_fixups {
             $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;              $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
         }          }
         my $mapcontent = &Apache::lonnet::getfile($key);          my $mapcontent = &Apache::lonnet::getfile($key);
           if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
               ($after{'map'} eq 'default') &&
               ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
               $mapcontent = '<map>'."\n".
                             '<resource id="1" src="" type="start" />'."\n".
                             '<link from="1" to="2" index="1" />'."\n".
                             '<resource id="2" src="" type="finish" />'."\n".
                             '</map>';
           }
         if ($mapcontent eq '-1') {          if ($mapcontent eq '-1') {
             if (ref($errors) eq 'HASH') {              if (ref($errors) eq 'HASH') {
                 $errors->{$key} = 1;                  $errors->{$key} = 1;
Line 2552  sub apply_fixups { Line 3128  sub apply_fixups {
                 }                  }
             }              }
         }          }
           my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
         foreach my $key (keys(%updates)) {          foreach my $key (keys(%updates)) {
             my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);              my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
             if (ref($rewrites{$key}) eq 'HASH') {              if (ref($rewrites{$key}) eq 'HASH') {
Line 2572  sub apply_fixups { Line 3149  sub apply_fixups {
             if (ref($dbcopies{$key}) eq 'HASH') {              if (ref($dbcopies{$key}) eq 'HASH') {
                 foreach my $idx (keys(%{$dbcopies{$key}})) {                  foreach my $idx (keys(%{$dbcopies{$key}})) {
                     if (ref($dbcopies{$key}{$idx}) eq 'HASH') {                      if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
                           my $oldurl = $dbcopies{$key}{$idx}{'src'};
                           my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
                           my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
                           my $oldmarker;
                           if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
                               $oldmarker = $1;
                               unless (($gotcrsltitools) ||
                                       (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
                                   my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
                                   if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
                                       unless ($gotcrsltitools) {
                                           %currcrsltitools =
                                               &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
                                           foreach my $item (sort(keys(%currcrsltitools))) {
                                               if (ref($currcrsltitools{$item}) eq 'HASH') {
                                                   $currltimax ++;
                                                   if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
                                                       push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
                                                   } else {
                                                       $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
                                                   }
                                               }
                                           }
                                           $gotcrsltitools = 1;
                                       }
                                       unless ($checkedsameinst) {
                                           my $primary_id = &Apache::lonnet::domain($cdom,'primary');
                                           my $intdom = &Apache::lonnet::internet_dom($primary_id);
                                           if ($intdom ne '') {
                                               my $internet_names =
                                                   &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                                               if (ref($internet_names) eq 'ARRAY') {
                                                   if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                                                       $same_institution = 1;
                                                   }
                                               }
                                           }
                                           $checkedsameinst = 1;
                                       }
                                   }
                               }
                           }
                         my ($newurl,$result,$errtext) =                          my ($newurl,$result,$errtext) =
                             &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);                              &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
                                       \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
                         if ($result eq 'ok') {                          if ($result eq 'ok') {
                             $newdb{$idx} = $newurl;                              $newdb{$idx} = $newurl;
                               if ($newurl =~ /ext\.tool$/) {
                                   if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
                                       if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
                                           my $newmarker = $1;
                                           unless ($oldmarker eq $newmarker) {
                                               $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
                                           }
                                       }
                                   }
                               }
                         } elsif (ref($errors) eq 'HASH') {                          } elsif (ref($errors) eq 'HASH') {
                             $errors->{$key} = 1;                              $errors->{$key} = 1;
                         }                          }
Line 2583  sub apply_fixups { Line 3213  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 2598  sub apply_fixups { Line 3258  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 2608  sub apply_fixups { Line 3269  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 2650  sub apply_fixups { Line 3311  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 2683  sub apply_fixups { Line 3344  sub apply_fixups {
                 }                  }
             }              }
         }          }
           if (($updatetoolscache) || (@updatetoolsenc)) {
               &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
                                       \@updatetoolsenc);
           }
     }      }
     return ('ok',\@msgs,$lockmsg);      return ('ok',\@msgs,$lockmsg);
 }  }
Line 2777  sub update_parameter { Line 3442  sub update_parameter {
             my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);              my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
             $name=&LONCAPA::map::qtescape($name);              $name=&LONCAPA::map::qtescape($name);
             $url=&LONCAPA::map::qtescape($url);              $url=&LONCAPA::map::qtescape($url);
             next unless ($name && $url);              next unless $url;
             my $is_map;              my $is_map;
             if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {              if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                 $is_map = 1;                  $is_map = 1;
Line 2862  sub update_parameter { Line 3527  sub update_parameter {
   
 sub handle_edit_cmd {  sub handle_edit_cmd {
     my ($coursenum,$coursedom) =@_;      my ($coursenum,$coursedom) =@_;
       my $haschanges = 0;
     if ($env{'form.cmd'} eq '') {      if ($env{'form.cmd'} eq '') {
         return 0;          return $haschanges;
     }      }
     my ($cmd,$idx)=split('_',$env{'form.cmd'});      my ($cmd,$idx)=split('_',$env{'form.cmd'});
   
Line 2878  sub handle_edit_cmd { Line 3544  sub handle_edit_cmd {
     &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);      &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
  }   }
  splice(@LONCAPA::map::order, $idx, 1);   splice(@LONCAPA::map::order, $idx, 1);
           $haschanges = 1;
     } elsif ($cmd eq 'cut') {      } elsif ($cmd eq 'cut') {
  &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);   &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
  splice(@LONCAPA::map::order, $idx, 1);   splice(@LONCAPA::map::order, $idx, 1);
           $haschanges = 1;
     } elsif ($cmd eq 'up'      } elsif ($cmd eq 'up'
      && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {       && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
  @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];   @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
           $haschanges = 1;
     } elsif ($cmd eq 'down'      } elsif ($cmd eq 'down'
      && defined($LONCAPA::map::order[$idx+1])) {       && defined($LONCAPA::map::order[$idx+1])) {
  @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];   @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
           $haschanges = 1;
     } elsif ($cmd eq 'rename') {      } elsif ($cmd eq 'rename') {
  my $comment = &LONCAPA::map::qtunescape($env{'form.title'});   my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
  if ($comment=~/\S/) {   if ($comment=~/\S/) {
Line 2900  sub handle_edit_cmd { Line 3566  sub handle_edit_cmd {
 # Devalidate title cache  # Devalidate title cache
  my $renamed_url=&LONCAPA::map::qtescape($url);   my $renamed_url=&LONCAPA::map::qtescape($url);
  &Apache::lonnet::devalidate_title_cache($renamed_url);   &Apache::lonnet::devalidate_title_cache($renamed_url);
           $haschanges = 1;
     } else {  
  return 0;  
     }      }
     return 1;      return $haschanges;
 }  }
   
 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,$ltitoolsref,          $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
         $canedit,$navmapref,$hiddentop)=@_;          $canedit,$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 3214  sub editor { Line 3878  sub editor {
         $r->print('</div>');          $r->print('</div>');
     }      }
   
       if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
           my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
           if (ref($supplemental) eq 'HASH') {
               if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
                   (ref($supplemental->{'ids'}) eq 'HASH')) {
                   if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
                       my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
                       if ($supplemental->{'hidden'}->{$mapnum}) {
                           $ishidden = 1;
                       }
                   }
               }
           }
       }
   
     my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);      my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
     %filters =  (      %filters =  (
                   canremove      => [],                    canremove      => [],
Line 3237  sub editor { Line 3916  sub editor {
             push(@allmapidx,$res);              push(@allmapidx,$res);
         }          }
   
           if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
               if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
                   $idx++;
                   next;
               }
           }
         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,          $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
                               $coursenum,$coursedom,$crstype,                                $coursenum,$coursedom,$crstype,
                               $pathitem,$supplementalflag,$container,                                $pathitem,$supplementalflag,$container,
                               \%filters,\%curr_groups,$ltitoolsref,$canedit,                                \%filters,\%curr_groups,$ltitoolsref,$canedit,
                               $isencrypted,$navmapref);                                $isencrypted,$ishidden,$navmapref,$hostname);
         $idx++;          $idx++;
         $shown++;          $shown++;
     }      }
Line 3250  sub editor { Line 3935  sub editor {
     my $need_save;      my $need_save;
     if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {      if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
         my $toolslink;          my $toolslink;
         if ($allowed) {          if ($allowed || $canedit) {
               my $helpitem = 'Navigation_Screen';
               if (!$allowed) {
                   $helpitem = 'Supplemental_Navigation';
               }
             $toolslink = '<table><tr><td>'              $toolslink = '<table><tr><td>'
                        .&Apache::loncommon::help_open_menu('Navigation Screen',                         .&Apache::loncommon::help_open_menu('Navigation Screen',
                                                            'Navigation_Screen',undef,'RAT')                                                             $helpitem,undef,'RAT')
                        .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'                         .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
                        .'<td align="left"><ul id="LC_toolbar">'                         .'<td align="left"><ul id="LC_toolbar">'
                        .'<li><a href="/adm/coursedocs?forcesupplement=1&amp;command=editsupp" '                         .'<li><a href="/adm/coursedocs?forcesupplement=1&amp;command=editsupp" '
Line 3269  sub editor { Line 3958  sub editor {
                           .&Apache::loncommon::start_data_table_header_row()                            .&Apache::loncommon::start_data_table_header_row()
                           .'<th colspan="2">'.&mt('Move').'</th>'                            .'<th colspan="2">'.&mt('Move').'</th>'
                           .'<th colspan="2">'.&mt('Actions').'</th>'                            .'<th colspan="2">'.&mt('Actions').'</th>'
                           .'<th>'.&mt('Document').'</th>';                            .'<th>'.&mt('Document').'</th>'
                 if ($folder !~ /^supplemental/) {                            .'<th colspan="2">'.&mt('Settings').'</th>'
                     $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';                            .&Apache::loncommon::end_data_table_header_row();
                 }  
                 $to_show .= &Apache::loncommon::end_data_table_header_row();  
                 if ($folder !~ /^supplemental/) {                  if ($folder !~ /^supplemental/) {
                     $lists{'canhide'} = join(',',@allidx);                      $lists{'canhide'} = join(',',@allidx);
                     $lists{'canrandomlyorder'} = join(',',@allmapidx);                      $lists{'canrandomlyorder'} = join(',',@allmapidx);
Line 3301  sub editor { Line 3988  sub editor {
                                 '</td>'.                                  '</td>'.
                                 '<td>&nbsp;</td>'.                                  '<td>&nbsp;</td>'.
                                 '<td>&nbsp;</td>'.                                  '<td>&nbsp;</td>'.
                                 '<td colspan="4">'.                                  '<td colspan="2">'.
                                 &multiple_check_form('settings',\%lists,$canedit).                                  &multiple_check_form('settings',\%lists,$canedit).
                                 '</td>'.                                  '</td>'.
                                 &Apache::loncommon::end_data_table_row();                                  &Apache::loncommon::end_data_table_row();
Line 3370  sub multiple_check_form { Line 4057  sub multiple_check_form {
     return unless (ref($listsref) eq 'HASH');      return unless (ref($listsref) eq 'HASH');
     my $disabled;      my $disabled;
     unless ($canedit) {      unless ($canedit) {
         $disabled = 'disabled="disabled"';          $disabled = ' disabled="disabled"';
     }      }
     my $output =      my $output =
     '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.      '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
Line 3620  sub is_supplemental_title { Line 4307  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,
         $ltitoolsref,$canedit,$isencrypted,$navmapref)=@_;          $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
     my ($foldertitle,$renametitle,$oldtitle);      my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
     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);
           $encodedtitle=$title;
     } else {      } else {
  $title=&HTML::Entities::encode($title,'"<>&\'');   $title=&HTML::Entities::encode($title,'"<>&\'');
           $encodedtitle=$title;
  $renametitle=$title;   $renametitle=$title;
  $foldertitle=$title;   $foldertitle=$title;
     }      }
Line 3647  sub entryline { Line 4336  sub entryline {
     my $line=&Apache::loncommon::start_data_table_row();      my $line=&Apache::loncommon::start_data_table_row();
     my ($form_start,$form_end,$form_common,$form_param);      my ($form_start,$form_end,$form_common,$form_param);
 # Edit commands  # Edit commands
     my ($esc_path, $path, $symb);      my ($esc_path, $path, $symb, $shownsymb);
     if ($env{'form.folderpath'}) {      if ($env{'form.folderpath'}) {
  $esc_path=&escape($env{'form.folderpath'});   $esc_path=&escape($env{'form.folderpath'});
  $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');   $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
Line 3847  END Line 4536  END
     my $ispage;      my $ispage;
     my $containerarg;      my $containerarg;
     my $folderurl;      my $folderurl;
       my $plainurl;
     if ($uploaded) {      if ($uploaded) {
         if (($extension eq 'sequence') || ($extension eq 'page')) {          if (($extension eq 'sequence') || ($extension eq 'page')) {
             $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;              $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
Line 3865  END Line 4555  END
                 $url='/adm/supplemental?';                  $url='/adm/supplemental?';
             }              }
  } else {   } else {
     &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);              $plainurl = $url;
  }   }
     }      }
   
     my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);      my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
     my $orig_url = $url;      my $orig_url = $url;
     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};      $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
     $url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};      if ($container eq 'page') {
           $url=~s{^http(|s)(&colon;|:)//}{/ext/};
       } else {
           $url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
       }
     if (!$supplementalflag && $residx && $symb) {      if (!$supplementalflag && $residx && $symb) {
         if ((!$isfolder) && (!$ispage)) {          if ((!$isfolder) && (!$ispage)) {
     (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);      (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
     $url=&Apache::lonnet::clutter($url);              if (($url =~ m{^ext/}) && ($container eq 'page')) {
                   $url=&Apache::lonnet::clutter_with_no_wrapper($url);
               } else {
                   $url=&Apache::lonnet::clutter($url);
               }
     if ($url=~/^\/*uploaded\//) {      if ($url=~/^\/*uploaded\//) {
         $url=~/\.(\w+)$/;          $url=~/\.(\w+)$/;
         my $embstyle=&Apache::loncommon::fileembstyle($1);          my $embstyle=&Apache::loncommon::fileembstyle($1);
Line 3890  END Line 4588  END
             } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {              } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
                 my $wrapped = $1;                  my $wrapped = $1;
                 my $exturl = $2;                  my $exturl = $2;
                 if ($wrapped eq '') {                  if (($wrapped eq '') && ($container ne 'page')) {
                     $url='/adm/wrapper'.$url;                      $url='/adm/wrapper'.$url;
                 }                  }
                 if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {                  if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
Line 3901  END Line 4599  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()) || (&Apache::lonnet::waf_allssl($hostname))) {
                           $url .= '?usehttp=1';
                       }
                     $nomodal = 1;                      $nomodal = 1;
                 }                  }
     }      }
             if (&Apache::lonnet::symbverify($symb,$url)) {              my ($checkencrypt,$shownurl);
                 my $shownsymb = $symb;              if (!$env{'request.role.adv'}) {
                 if ($isexternal) {  
                     if ($url =~ /^([^#]+)#([^#]+)$/) {  
                         $url = $1;  
                         $anchor = $2;  
                         if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {  
                             $shownsymb = $1.&escape('#').$anchor;  
                         }  
                     }  
                 }  
                 unless ($env{'request.role.adv'}) {  
                     if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {  
                         $url = '';  
                     }  
                     if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {  
                         $url = '';  
                         $hiddenres = 1;  
                     }  
                 }  
                 if ($url ne '') {  
                     $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');  
                 }  
             } elsif (!$env{'request.role.adv'}) {  
                 my $checkencrypt;  
                 if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||                  if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
                       $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {                      ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
                     $checkencrypt = 1;                      $checkencrypt = 1;
                 } elsif (ref($navmapref)) {                  } elsif (ref($navmapref)) {
                     unless (ref($$navmapref)) {                      unless (ref($$navmapref)) {
Line 3942  END Line 4620  END
                         }                          }
                     }                      }
                 }                  }
                 if ($checkencrypt) {              }
                     my $shownsymb = &Apache::lonenc::encrypted($symb);              if ($checkencrypt) {
                     my $shownurl = &Apache::lonenc::encrypted($url);                  my $currenc = $env{'request.enc'};
                     if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {                  $env{'request.enc'} = 1;
                         $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');                  $shownsymb = &Apache::lonenc::encrypted($symb);
                         if ($env{'request.enc'} ne '') {                  $shownurl = &Apache::lonenc::encrypted($url);
                             delete($env{'request.enc'});                  if (&Apache::lonnet::symbverify($symb,$url)) {
                         }                      $url = $shownurl;
                     } else {  
                         $url='';  
                     }  
                 } else {                  } else {
                     $url='';                      $url = '';
                 }                  }
             } else {                  $env{'request.enc'} = $currenc;
                 $url='';              } elsif (&Apache::lonnet::symbverify($symb,$url)) {
                   $shownsymb = $symb;
                   if ($isexternal) {
                       $url =~ s/\#[^#]+$//;
                       if ($container eq 'page') {
                           $url = &Apache::lonnet::clutter($url);
                       }
                   }
                   $shownurl = $url;
               }
               unless ($env{'request.role.adv'}) {
                   if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                       $url = '';
                   }
                   if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
                       $url = '';
                       $hiddenres = 1;
                   }
               }
               if ($url ne '') {
                   $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
             }              }
  }   }
     } elsif ($supplementalflag) {      } elsif ($supplementalflag) {
Line 3966  END Line 4661  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()) || (&Apache::lonnet::waf_allssl($hostname))) {
                           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()) || (&Apache::lonnet::waf_allssl($hostname))) {
                       if ($hostname ne '') {
                           $url = 'http://'.$hostname.$url;
                       }
                       $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
                   }
                 $nomodal = 1;                  $nomodal = 1;
             }              }
           } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
               my $embstyle=&Apache::loncommon::fileembstyle($extension);
               unless ($embstyle eq 'ssi') {
                   if (($embstyle eq 'img')
                    || ($embstyle eq 'emb')
                    || ($embstyle eq 'wrp')) {
                       $url='/adm/wrapper'.$url;
                   } elsif ($url !~ /\.(sequence|page)$/) {
                       $url='/adm/coursedocs/showdoc'.$url;
                   }
               }
           }
           unless ($allowed && $env{'request.role.adv'}) {
               if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   $hiddenres = 1;
               }
         }          }
     }      }
     my ($rand_pick_text,$rand_order_text,$hiddenfolder);      my ($rand_pick_text,$rand_order_text,$hiddenfolder);
Line 3985  END Line 4708  END
         if (!$allowed && $supplementalflag) {          if (!$allowed && $supplementalflag) {
             $folderpath.=$containerarg.'&'.$foldername;              $folderpath.=$containerarg.'&'.$foldername;
             $url.='folderpath='.&escape($folderpath);              $url.='folderpath='.&escape($folderpath);
               if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   $hiddenfolder = 1;
               }
         } else {          } else {
             my $rpicknum = (&LONCAPA::map::getparameter($orderidx,              my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
                                                         'parameter_randompick'))[0];                                                          'parameter_randompick'))[0];
Line 4070  $form_end; Line 4796  $form_end;
         $url .= ($url =~ /\?/) ? '&amp;':'?';          $url .= ($url =~ /\?/) ? '&amp;':'?';
         $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');          $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
         if ($title) {          if ($title) {
             $url .= '&amp;title='.&HTML::Entities::encode($renametitle,'<>&"');              $url .= '&amp;title='.$encodedtitle;
         }          }
         if ((($isexternal) || ($isexttool)) && $orderidx) {          if ((($isexternal) || ($isexttool)) && $orderidx) {
             $url .= '&amp;idx='.$orderidx;              $url .= '&amp;idx='.$orderidx;
Line 4086  $form_end; Line 4812  $form_end;
         if ($isexternal) {          if ($isexternal) {
             ($editlink,$extresform) =               ($editlink,$extresform) = 
                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,                  &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                                                      undef,undef,undef,$disabled);                                                       undef,undef,undef,undef,undef,undef,
                                                        undef,$disabled);
         } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {          } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
             ($editlink,$extresform) =              ($editlink,$extresform) =
                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,                  &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
Line 4104  $form_end; Line 4831  $form_end;
                     &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,                      &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
                                                             $switchserver,                                                              $switchserver,
                                                             $forceedit,                                                              $forceedit,
                                                             undef,$symb,                                                              undef,$symb,$shownsymb,
                                                             &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 4123  $form_end; Line 4851  $form_end;
         $reinit = &mt('(re-initialize course to access)');          $reinit = &mt('(re-initialize course to access)');
     }      }
     $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;      $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
     my $link;      my ($link,$nolink);
     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {      if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
        $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';          if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
               if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   $nolink = 1;
               }
           }
           if ($nolink) {
               $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
           } else {
               $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
           }
     } elsif ($url) {      } elsif ($url) {
        if ($anchor ne '') {         if ($anchor ne '') {
            if ($supplementalflag) {             if ($supplementalflag) {
Line 4134  $form_end; Line 4871  $form_end;
                $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');                 $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
            }             }
        }         }
        $link = &js_escape($url.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.         if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
                                                (($anchor ne '')?$anchor:''));             $link = 'http://'.$hostname.$url;
        if ($nomodal) {         } else {
              $link = $url;
          }
          $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.$anchor);
          if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
              if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                  $nolink = 1;
              }
          }
          if ($nolink) {
              $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
          } elsif ($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>';
        } else {         } else {
Line 4148  $form_end; Line 4896  $form_end;
     }      }
     $line.='</span></td><td'.$tdwidth.'>';      $line.='</span></td><td'.$tdwidth.'>';
     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {      if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
        $line.='<a href="'.$url.'">'.$title.'</a>';         if ($nolink) {
              $line.=$title;
          } else {
              $line.='<a href="'.$url.'">'.$title.'</a>';
          }
          if (!$allowed && $supplementalflag && $canedit && $isfolder) {
              my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
              my $editurl = $url;
              $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;};
              $line .= '&nbsp;'.'<a href="'.$editurl.'">'.
                       '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
                       '</a>';
          }
          if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag))  {
              $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
          }
     } elsif ($url) {      } elsif ($url) {
        if ($nomodal) {         if ($nolink) {
              $line.=$title;
          } elsif ($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;" />'.
                   $title.'</a>';                    $title.'</a>';
        } else {         } else {
Line 4164  $form_end; Line 4929  $form_end;
     $line.="$extresform</td>";      $line.="$extresform</td>";
     $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');      $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');
     $rand_order_text = '&nbsp;' if ($rand_order_text eq '');      $rand_order_text = '&nbsp;' if ($rand_order_text eq '');
     if (($allowed) && ($folder!~/^supplemental/)) {      if ($uploaded && $url && !$isfolder && !$ispage) {
   my %lt=&Apache::lonlocal::texthash(          if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
        'hd' => 'Hidden',              &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
        'ec' => 'URL hidden');  
         my ($enctext,$hidtext);  
         if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {  
             $enctext = ' checked="checked"';  
             if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {  
                 push(@{$filtersref->{'encrypturl'}},$orderidx);  
             }  
         }          }
       }
       if ($allowed) {
           my %lt=&Apache::lonlocal::texthash(
                                 'hd' => 'Hidden',
                                 'ec' => 'URL hidden');
           my ($enctext,$hidtext,$formhidden,$formurlhidden);
         if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {          if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
             $hidtext = ' checked="checked"';              $hidtext = ' checked="checked"';
             if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {              if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
                 push(@{$filtersref->{'hiddenresource'}},$orderidx);                  push(@{$filtersref->{'hiddenresource'}},$orderidx);
             }              }
         }          }
         my $formhidden = 'edit_hiddenresource_'.$orderidx;          $formhidden = 'edit_hiddenresource_'.$orderidx;
         my $formurlhidden = 'edit_encrypturl_'.$orderidx;          $line.=(<<ENDPARMS);
  $line.=(<<ENDPARMS);  
   <td class="LC_docs_entry_parameter">    <td class="LC_docs_entry_parameter">
     <form action="/adm/coursedocs" method="post" name="$formhidden">      <form action="/adm/coursedocs" method="post" name="$formhidden">
     $form_param      $form_param
     $form_common      $form_common
     <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>      <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
     $form_end      $form_end
   ENDPARMS
           if ($folder =~/^supplemental/) {
               $line.= "\n    <td>";
           } else {
               if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
                   $enctext = ' checked="checked"';
                   if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
                       push(@{$filtersref->{'encrypturl'}},$orderidx);
                   }
               }
               $formurlhidden = 'edit_encrypturl_'.$orderidx;
       $line.=(<<ENDPARMS);
     <br />      <br />
     <form action="/adm/coursedocs" method="post" name="$formurlhidden">      <form action="/adm/coursedocs" method="post" name="$formurlhidden">
     $form_param      $form_param
Line 4200  $form_end; Line 4975  $form_end;
   <td class="LC_docs_entry_parameter">$rand_pick_text<br />    <td class="LC_docs_entry_parameter">$rand_pick_text<br />
                                       $rand_order_text</td>                                        $rand_order_text</td>
 ENDPARMS  ENDPARMS
           }
     }      }
     $line.=&Apache::loncommon::end_data_table_row();      $line.=&Apache::loncommon::end_data_table_row();
     return $line;      return $line;
Line 4215  sub action_restrictions { Line 4991  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 4377  sub untiehash { Line 5155  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 4392  sub checkonthis { Line 5170  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 4429  sub checkonthis { Line 5219  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 4443  sub checkonthis { Line 5233  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 4495  sub list_symbs { Line 5288  sub list_symbs {
     $r->print(&endContentScreen());      $r->print(&endContentScreen());
 }  }
   
   sub short_urls {
       my ($r,$canedit) = @_;
       my $crstype = &Apache::loncommon::course_type();
       my $formname = 'shortenurl';
       $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
       $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
       $r->print(&startContentScreen('tools'));
       my ($navmap,$errormsg) =
           &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
       my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
       my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
       my (%maps,%resources,%titles);
       if (!ref($navmap)) {
           $r->print($errormsg.
                     &endContentScreen());
           return '';
       } else {
           $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
           $r->rflush();
           my $readonly;
           if ($canedit) {
               my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
               if ($numnew) {
                   $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
               }
               if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
                   $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
                   foreach my $error (@{$errors}) {
                       $r->print('<li>'.$error.'</li>');
                   }
                   $r->print('</ul><br />');
               }
           } else {
               $readonly = 1;
           }
           my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
           $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
                                                                undef,undef,undef,undef,undef,\%currtiny,$readonly));
       }
       $r->print(&endContentScreen());
   }
   
 sub verifycontent {  sub contentverifyform {
     my ($r) = @_;      my ($r) = @_;
     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'));
     $r->print(&startContentScreen('tools'));      $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 {
       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'));
       $r->print(&startContentScreen('tools'));
     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');       $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>'); 
    $hashtied=0;     $hashtied=0;
    undef %alreadyseen;     undef %alreadyseen;
Line 4518  sub verifycontent { Line 5373  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 4846  sub changewarning { Line 5701  sub changewarning {
     if (!defined($message)) {      if (!defined($message)) {
  $message='Changes will become active for your current session after [_1], or the next time you log in.';   $message='Changes will become active for your current session after [_1], or the next time you log in.';
     }      }
       my $windowname = 'loncapaclient';
       if ($env{'request.lti.login'}) {
           $windowname .= 'lti';
       }
     $r->print("\n\n".      $r->print("\n\n".
 '<script type="text/javascript">'."\n".  '<script type="text/javascript">'."\n".
 '// <![CDATA['."\n".  '// <![CDATA['."\n".
 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".  'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
 '// ]]>'."\n".  '// ]]>'."\n".
 '</script>'."\n".  '</script>'."\n".
 '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.  '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
 '<input type="hidden" name="orgurl" value="'.$url.  '<input type="hidden" name="orgurl" value="'.$url.
 '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.  '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
 &mt($message,' <input type="hidden" name="'.  &mt($message,' <input type="hidden" name="'.
Line 4950  sub handler { Line 5809  sub handler {
     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',      foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
                'Adding_External_Resource','Adding_External_Tool',                 'Adding_External_Resource','Adding_External_Tool',
                        'Navigate_Content','Adding_Folders','Docs_Overview',                         'Navigate_Content','Adding_Folders','Docs_Overview',
                'Load_Map','Supplemental','Score_Upload_Form',                 'Load_Map','Supplemental','Score_Upload_Form', 
                        'Adding_Pages','Importing_LON-CAPA_Resource',                 'Adding_Pages','Importing_LON-CAPA_Resource',
                        'Importing_IMS_Course','Uploading_From_Harddrive',                 'Importing_IMS_Course','Uploading_From_Harddrive',
                        'Course_Roster','Web_Page','Dropbox','Simple_Problem') {                         'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
  $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);   $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
     }      }
Line 4969  sub handler { Line 5828  sub handler {
     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');      $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
     
     my ($allowed,$canedit,$canview,$disabled);      my ($allowed,$canedit,$canview,$disabled);
   # does this user have privileges to modify content.
       if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
 # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.  # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
     unless ($r->uri eq '/adm/supplemental') {          unless ($r->uri eq '/adm/supplemental') {
         # does this user have privileges to modify content.    
         if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {  
             $allowed = 1;              $allowed = 1;
             $canedit = 1;          }
             $canview = 1;          $canedit = 1;
         } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {          $canview = 1;
       } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
   # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
           unless ($r->uri eq '/adm/supplemental') {
             $allowed = 1;              $allowed = 1;
             $canview = 1;  
         }          }
           $canview = 1;
     }      }
     unless ($canedit) {      unless ($canedit) {
         $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);
     } elsif ($allowed && $env{'form.shorturls'}) {
         &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
         &short_urls($r,$canedit);
   } elsif ($allowed && $env{'form.docslog'}) {    } elsif ($allowed && $env{'form.docslog'}) {
       &init_breadcrumbs('docslog','Show Log');        &init_breadcrumbs('docslog','Show Log');
       my $folder = $env{'form.folder'};        my $folder = $env{'form.folder'};
Line 5014  sub handler { Line 5895  sub handler {
 # Get the parameters that may be needed  # Get the parameters that may be needed
 #  #
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['folderpath',                                              ['folderpath','title',
                                              '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 5040  sub handler { Line 5941  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 '') {
           &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
       }
   
       my $backto_supppath;
       if ($env{'form.supppath'} ne '') {
           if ($supplementalflag && $allowed) {
               $backto_supppath = &validate_supppath($coursenum,$coursedom);
           }
       }
   
     my $script='';      my $script='';
     my $showdoc=0;      my $showdoc=0;
     my $addentries = {};      my $addentries = {};
Line 5047  sub handler { Line 5959  sub handler {
     my $containertag;      my $containertag;
     my $pathitem;      my $pathitem;
     my %ltitools;      my %ltitools;
       my $posslti;
     my $hiddentop;      my $hiddentop;
     my $navmap;      my $navmap;
     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };      my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
Line 5058  sub handler { Line 5971  sub handler {
                &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);                 &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>             &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
                $env{'form.command'}.'_'.$env{'form.symb'}});                 $env{'form.command'}.'_'.$env{'form.symb'}});
        } elsif ($env{'form.supppath'} ne '') {         } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
            $env{'form.folderpath'}=$env{'form.supppath'};             $env{'form.folderpath'}=$env{'form.supppath'};
            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>             &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
                $env{'form.command'}.'_'.$env{'form.supppath'}});                 $env{'form.command'}.'_'.$backto_supppath});
        }         }
    } elsif ($env{'form.command'} eq 'editdocs') {     } elsif ($env{'form.command'} eq 'editdocs') {
        $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);         $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
Line 5096  sub handler { Line 6009  sub handler {
         } else {          } else {
             undef($env{'form.folderpath'});              undef($env{'form.folderpath'});
         }          }
           if ($env{'form.folderpath'} ne '') {
               &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
           }
     }      }
         
 # If we are not allowed to make changes, all we can see are supplemental docs  # If we are not allowed to make changes, all we can see are supplemental docs
Line 5111  sub handler { Line 6027  sub handler {
                                   $env{'form.folderpath'};                                    $env{'form.folderpath'};
     }      }
 # If allowed and user's role is not advanced check folderpath is not hidden  # If allowed and user's role is not advanced check folderpath is not hidden
     if (($allowed) && (!$env{'request.role.adv'}) &&      my $hidden_and_empty;
         ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {      if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
         my $folderurl;          my ($folderurl,$foldername,$hiddenfolder);
         my @pathitems = split(/\&/,$env{'form.folderpath'});          my @pathitems = split(/\&/,$env{'form.folderpath'});
         my $folder = $pathitems[-2];          my $folder = $pathitems[-2];
         if ($folder eq '') {          if ($folder eq '') {
             undef($env{'form.folderpath'});              undef($env{'form.folderpath'});
         } else {          } else {
             $folderurl = "uploaded/$coursedom/$coursenum/$folder";              $folderurl = "uploaded/$coursedom/$coursenum/$folder";
             if ((split(/\:/,$pathitems[-1]))[4]) {              if ((split(/\:/,$pathitems[-1]))[5]) {
                 $folderurl .= '.page';                  $folderurl .= '.page';
             } else {              } else {
                 $folderurl .= '.sequence';                  $folderurl .= '.sequence';
             }              }
             unless (ref($navmap)) {              if ($supplementalflag) {
                 $navmap = Apache::lonnavmaps::navmap->new();                  ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
             }                  $foldername = &HTML::Entities::decode(&unescape($foldername));
             if (ref($navmap)) {                  my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
                 if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {                  if (ref($supplemental) eq 'HASH') {
                     my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);                      my ($suppmap,$suppmapnum);
                     unless (@resources) {                      if ($folder eq 'supplemental') {
                         undef($env{'form.folderpath'});                          $suppmap = 'default';
                           $suppmapnum = 0;
                       } elsif ($folder =~ /^supplemental_(\d+)$/) {
                           $suppmap = $1;
                           $suppmapnum = $suppmap;
                       }
                       if ($hiddenfolder) {
                           my $hascontent;
                           foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
                               if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
                                   $hascontent = 1;
                               } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
                                   foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
                                       if ($id =~ /^$suppmapnum\:/) {
                                           $hascontent = 1;
                                           last;
                                       }
                                   }
                               }
                               last if ($hascontent);
                           }
                           unless ($hascontent) {
                               if ($foldername ne '') {
                                   $hidden_and_empty = $foldername;
                               } else {
                                   $hidden_and_empty = $folder;
                               }
                           }
                       }
                   }
               } else {
                   unless (ref($navmap)) {
                       $navmap = Apache::lonnavmaps::navmap->new();
                   }
                   ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
                   $foldername = &HTML::Entities::decode(&unescape($foldername));
                   if (ref($navmap)) {
                       if ($hiddenfolder ||
                           (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
                           my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
                           unless (@resources) {
                               if ($foldername ne '') {
                                   $hidden_and_empty = $foldername;
                               } else {
                                   $hidden_and_empty = $folder;
                               }
                           }
                     }                      }
                 }                  }
             }              }
               if ($hidden_and_empty ne '') {
                   splice(@pathitems,-2);
                   if (@pathitems) {
                       $env{'form.folderpath'} = join('&',@pathitems);
                   } else {
                       undef($env{'form.folderpath'});
                   }
               }
         }          }
     }      }
   
   
 # If after all of this, we still don't have any paths, make them  # If after all of this, we still don't have any paths, make them
     unless ($env{'form.folderpath'}) {      unless ($env{'form.folderpath'}) {
        if ($supplementalflag) {         if ($supplementalflag) {
Line 5224  sub handler { Line 6193  sub handler {
                 }                  }
             }              }
             my $tabidstr = join("','",@tabids);              my $tabidstr = join("','",@tabids);
             %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);              my (%domtools,%crstools);
             my $posslti = keys(%ltitools);              my %tooltypes = &Apache::loncommon::usable_exttools();
     $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,              if ($tooltypes{'dom'}) {
                                    $canedit,\$navmap).                  %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
               }
               if ($tooltypes{'crs'}) {
                   %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
               }
               %ltitools = (
                             dom => \%domtools,
                             crs => \%crstools,
                           );
               $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
               my $hostname = $r->hostname();
               $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
                                      $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).
                        &Apache::lonextresedit::extedit_javascript(\%ltitools);                         &Apache::lonextresedit::extedit_javascript(\%ltitools);
               my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
               if ($hidden_and_empty ne '') {
                   my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
                                   $hidden_and_empty);
                   $onload .= "javascript:alert('".&js_escape($alert)."');";
               }
             $addentries = {              $addentries = {
                             onload   => "javascript:resize_scrollbox('contentscroll','1','1');",                              onload => $onload,
                           };                            };
         }          }
         $script .= &paste_popup_js();           $script .= &paste_popup_js(); 
Line 5247  sub handler { Line 6234  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();
   
     if ($showdoc) {      if ($showdoc) {
         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,          my $args;
                                                 {'force_register' => $showdoc,}));          if ($supplementalflag) {
               my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
               my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
               $args = {'bread_crumbs' => $brcrum};
           } else {
               $args = {'force_register' => $showdoc};
           }
           $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
     } elsif ($toolsflag) {      } elsif ($toolsflag) {
         my ($breadtext,$breadtitle);          my ($breadtext,$breadtitle);
         $breadtext = "$crstype Editor";          $breadtext = "$crstype Editor";
Line 5272  sub handler { Line 6267  sub handler {
                      $breadtitle)                       $breadtitle)
                  );                   );
     } elsif ($r->uri eq '/adm/supplemental') {      } elsif ($r->uri eq '/adm/supplemental') {
           unless ($env{'request.role.adv'}) {
               unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
                   $r->internal_redirect('/adm/navmaps');
                   return OK;
               }
           }
         my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);          my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
         $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,          $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
                                                 {'bread_crumbs' => $brcrum,}));                                                  {'bread_crumbs' => $brcrum,}));
Line 5302  sub handler { Line 6303  sub handler {
   my %codebase = ();    my %codebase = ();
   my ($upload_result,$upload_output,$uploadphase);    my ($upload_result,$upload_output,$uploadphase);
   if ($canedit) {    if ($canedit) {
         undef($suppchanges);
       if (($env{'form.uploaddoc.filename'}) &&        if (($env{'form.uploaddoc.filename'}) &&
   ($env{'form.cmd'}=~/^upload_(\w+)/)) {    ($env{'form.cmd'}=~/^upload_(\w+)/)) {
           my $context = $1;             my $context = $1; 
Line 5313  sub handler { Line 6315  sub handler {
   if ($hadchanges) {    if ($hadchanges) {
       &mark_hash_old();        &mark_hash_old();
   }    }
             if ($suppchanges) {
                 &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
                 undef($suppchanges);
             }
           $r->print($upload_output);            $r->print($upload_output);
       } elsif ($env{'form.phase'} eq 'upload_embedded') {        } elsif ($env{'form.phase'} eq 'upload_embedded') {
           # Process file upload - phase two - upload embedded objects             # Process file upload - phase two - upload embedded objects 
Line 5399  sub handler { Line 6405  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 5433  sub handler { Line 6440  sub handler {
  my $fileupload=(<<FIUP);   my $fileupload=(<<FIUP);
         $quotainfo          $quotainfo
  $lt{'file'}:<br />   $lt{'file'}:<br />
  <input type="file" name="uploaddoc" size="40" $disabled />  
 FIUP  FIUP
   
  my $checkbox=(<<CHBO);   my $checkbox=(<<CHBO);
  <!-- <label>$lt{'parse'}?   <!-- <label>$lt{'parse'}?
  <input type="checkbox" name="parserflag" />   <input type="checkbox" name="parserflag" />
Line 5455  CHBO Line 6460  CHBO
         <fieldset id="uploadimsform" style="display: none;">          <fieldset id="uploadimsform" style="display: none;">
         <legend>$lt{'imsf'}</legend>          <legend>$lt{'imsf'}</legend>
         $fileupload          $fileupload
           <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
           <input type="hidden" id="LC_free_space_ims" value="$free_space" />
         <br />          <br />
         <p>          <p>
         $lt{'cms'}:&nbsp;           $lt{'cms'}:&nbsp; 
Line 5481  IMSFORM Line 6488  IMSFORM
         <legend>$lt{'upfi'}</legend>          <legend>$lt{'upfi'}</legend>
  <input type="hidden" name="active" value="aa" />   <input type="hidden" name="active" value="aa" />
  $fileupload   $fileupload
           <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
           <input type="hidden" id="LC_free_space" value="$free_space" />
  <br />   <br />
  $lt{'title'}:<br />   $lt{'title'}:<br />
  <input type="text" size="60" name="comment" $disabled />   <input type="text" size="60" name="comment" $disabled />
Line 5537  SEDFFORM Line 6546  SEDFFORM
         my $extresourcesform =          my $extresourcesform =
             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,              &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
                                                  $help{'Adding_External_Resource'},                                                   $help{'Adding_External_Resource'},
                                                  undef,undef,$disabled);                                                   undef,undef,undef,undef,undef,undef,$disabled);
         my $exttoolform =          my $exttoolform =
             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,              &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
                                                  $help{'Adding_External_Tool'},undef,                                                   $help{'Adding_External_Tool'},undef,
Line 5586  HIDDENFORM Line 6595  HIDDENFORM
 #  #
   
     my $savefolderpath;      my $savefolderpath;
       my $hostname = $r->hostname();
   
     if ($allowed) {      if ($allowed) {
        my $folder=$env{'form.folder'};         my $folder=$env{'form.folder'};
Line 5598  HIDDENFORM Line 6608  HIDDENFORM
        }         }
        my $postexec='';         my $postexec='';
        if ($folder eq 'default') {         if ($folder eq 'default') {
              my $windowname = 'loncapaclient';
              if ($env{'request.lti.login'}) {
                  $windowname .= 'lti';
              }
            $r->print('<script type="text/javascript">'."\n"             $r->print('<script type="text/javascript">'."\n"
                     .'// <![CDATA['."\n"                      .'// <![CDATA['."\n"
                     .'this.window.name="loncapaclient";'."\n"                      .'this.window.name="$windowname";'."\n"
                     .'// ]]>'."\n"                      .'// ]]>'."\n"
                     .'</script>'."\n"                      .'</script>'."\n"
        );         );
Line 5777  NSYLFORM Line 6791  NSYLFORM
  $help{'Group Portfolio'}   $help{'Group Portfolio'}
  </form>   </form>
 NGFFORM  NGFFORM
  @specialdocumentsforma=(          if ($container eq 'page') {
               @specialdocumentsforma=(
           {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
               );
           } else {
       @specialdocumentsforma=(
  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'"  onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'"  onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
         );              );
           }
         $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));          $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
   
   
         my @importdoc = (          my @importdoc = (
         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
         );          );
         if (keys(%ltitools)) {          if ($posslti) {
             push(@importdoc,              push(@importdoc,
                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
         );          );
Line 5826  my %orderhash = ( Line 6846  my %orderhash = (
                 'aa' => ['Upload',$fileuploadform],                  'aa' => ['Upload',$fileuploadform],
                 'bb' => ['Import',$importpubform],                  'bb' => ['Import',$importpubform],
                 'cc' => ['Grading',$gradingform],                  'cc' => ['Grading',$gradingform],
                   'ee' => ['Other',$specialdocumentsform],
                 );                  );
 unless ($container eq 'page') {  unless ($container eq 'page') {
     $orderhash{'00'} = ['Newfolder',$newfolderform];      $orderhash{'00'} = ['Newfolder',$newfolderform];
     $orderhash{'dd'} = ['Collaboration',$communityform];      $orderhash{'dd'} = ['Collaboration',$communityform];
     $orderhash{'ee'} = ['Other',$specialdocumentsform];  
 }  }
   
  $hadchanges=0;   $hadchanges=0;
        unless (($supplementalflag || $toolsflag)) {         unless (($supplementalflag || $toolsflag)) {
           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,            my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                               $supplementalflag,\%orderhash,$iconpath,$pathitem,                                $supplementalflag,\%orderhash,$iconpath,$pathitem,
                               \%ltitools,$canedit,\$navmap,$hiddentop);                                \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
           undef($navmap);            undef($navmap);
           if ($error) {            if ($error) {
              $r->print('<p><span class="LC_error">'.$error.'</span></p>');               $r->print('<p><span class="LC_error">'.$error.'</span></p>');
Line 5847  unless ($container eq 'page') { Line 6867  unless ($container eq 'page') {
                  &mark_hash_old();                   &mark_hash_old();
              }               }
           }            }
   
           &changewarning($r,'');            &changewarning($r,'');
         }          }
     }      }
Line 5857  unless ($container eq 'page') { Line 6878  unless ($container eq 'page') {
        unless ($supplementalflag) {         unless ($supplementalflag) {
    $folder='supplemental';     $folder='supplemental';
        }         }
        if ($folder =~ /^supplemental$/ &&         if (($folder eq 'supplemental') &&
    (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {     (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
           $env{'form.folderpath'} = &supplemental_base();            $env{'form.folderpath'} = &supplemental_base();
        } elsif ($allowed) {         } elsif ($allowed) {
Line 5877  unless ($container eq 'page') { Line 6898  unless ($container eq 'page') {
         <legend>$lt{'upfi'}</legend>          <legend>$lt{'upfi'}</legend>
  <input type="hidden" name="active" value="ee" />   <input type="hidden" name="active" value="ee" />
  $fileupload   $fileupload
           <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
           <input type="hidden" id="LC_free_space_supp" value="$free_space" />
  <br />   <br />
  <br />   <br />
  <span class="LC_nobreak">   <span class="LC_nobreak">
Line 5889  unless ($container eq 'page') { Line 6912  unless ($container eq 'page') {
  $pathitem   $pathitem
  <input type="hidden" name="cmd" value="upload_supplemental" />   <input type="hidden" name="cmd" value="upload_supplemental" />
         <input type='submit' value="$lt{'upld'}" />          <input type='submit' value="$lt{'upld'}" />
           </fieldset>
         </form>          </form>
 SUPDOCFORM  SUPDOCFORM
   
Line 5906  SNFFORM Line 6930  SNFFORM
             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,              &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
                                                  $help{'Adding_External_Resource'},                                                   $help{'Adding_External_Resource'},
                                                  undef,undef,$disabled);                                                   undef,undef,$disabled);
   
         my $supexttoolform =          my $supexttoolform =
             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,              &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
                                                  $help{'Adding_External_Tool'},                                                   $help{'Adding_External_Tool'},
                                                  undef,undef,'tool',$coursedom,                                                   undef,undef,'tool',$coursedom,
                                                  $coursenum,\%ltitools,$disabled);                                                   $coursenum,\%ltitools,$disabled);
   
  my $supnewsylform=(<<SNSFORM);   my $supnewsylform=(<<SNSFORM);
  <form action="/adm/coursedocs" method="post" name="supnewsyl">   <form action="/adm/coursedocs" method="post" name="supnewsyl">
  <input type="hidden" name="active" value="ff" />   <input type="hidden" name="active" value="ff" />
Line 5983  my %suporderhash = ( Line 7007  my %suporderhash = (
                 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]                  'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
                 );                  );
         if ($supplementalflag) {          if ($supplementalflag) {
            my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,              $suppchanges = 0;
                                $supplementalflag,\%suporderhash,$iconpath,$pathitem,              my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                                \%ltitools,$canedit);                                  $supplementalflag,\%suporderhash,$iconpath,$pathitem,
            if ($error) {                                  \%ltitools,$canedit,$hostname);
               $r->print('<p><span class="LC_error">'.$error.'</span></p>');              if ($error) {
            } else {                  $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                if ($suppchanges) {              }
                    my %servers = &Apache::lonnet::internet_dom_servers($coursedom);              if ($suppchanges) {
                    my @ids=&Apache::lonnet::current_machine_ids();                  &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
                    foreach my $server (keys(%servers)) {                  undef($suppchanges);
                        next if (grep(/^\Q$server\E$/,@ids));              }
                        my $hashid=$coursenum.':'.$coursedom;  
                        my $cachekey = &escape('suppcount').':'.&escape($hashid);  
                        &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);  
                    }  
                    &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);  
                    undef($suppchanges);  
                }  
            }  
         }          }
     } elsif ($supplementalflag) {      } elsif ($supplementalflag) {
         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,          my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                             $supplementalflag,'',$iconpath,$pathitem);                              $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
                               $hostname);
         if ($error) {          if ($error) {
             $r->print('<p><span class="LC_error">'.$error.'</span></p>');              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
         }          }
Line 6039  my %suporderhash = ( Line 7056  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 6059  sub embedded_destination { Line 7077  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 6085  sub decompression_info { Line 7107  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 6159  sub remove_archive { Line 7184  sub remove_archive {
             if ($url eq $env{'form.archiveurl'}) {              if ($url eq $env{'form.archiveurl'}) {
                 if (&handle_edit_cmd($docuname,$docudom)) {                  if (&handle_edit_cmd($docuname,$docudom)) {
                     ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);                      ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
                       if ($suppchanges) {
                           &Apache::lonnet::update_supp_caches($docudom,$docuname);
                           undef($suppchanges);
                       }
                     if ($fatal) {                      if ($fatal) {
                         if ($container eq 'page') {                          if ($container eq 'page') {
                             $delwarning = &mt('An error occurred updating the contents of the current page.');                              $delwarning = &mt('An error occurred updating the contents of the current page.');
Line 6197  sub generate_admin_menu { Line 7226  sub generate_admin_menu {
                                          'vc'   => 'Verify Content',                                           'vc'   => 'Verify Content',
                                          'cv'   => 'Check/Set Resource Versions',                                           'cv'   => 'Check/Set Resource Versions',
                                          'ls'   => 'List Resource Identifiers',                                           'ls'   => 'List Resource Identifiers',
                                            'ct'   => 'Display/Set Shortened URLs for Deep-linking',
                                          'imse' => 'Export contents to IMS Archive',                                           'imse' => 'Export contents to IMS Archive',
                                          'dcd'  => "Copy $crstype Content to Authoring Space",                                           'dcd'  => "Copy $crstype Content to Authoring Space",
             );              );
Line 6247  sub generate_admin_menu { Line 7277  sub generate_admin_menu {
                     icon       => 'symbs.png',                      icon       => 'symbs.png',
                     linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"                      linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"
                 },                  },
                   {   linktext   => $lt{'ct'},
                       url        => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
                       permission => 'F',
                       help       => 'Docs_Short_URLs',
                       icon       => 'shorturls.png',
                       linktitle  => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
                   },
                 ]                  ]
         });          });
     if ($canedit) {      if ($canedit) {
Line 6377  END Line 7414  END
 }  }
   
 sub editing_js {  sub editing_js {
     my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$canedit,$navmapref) = @_;      my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
           $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 6456  sub editing_js { Line 7494  sub editing_js {
                     $backtourl .= '?symb='.                      $backtourl .= '?symb='.
                                   &HTML::Entities::encode($caller,'<>&"');                                    &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()) || (&Apache::lonnet::waf_allssl($hostname))) {
                               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()) || (&Apache::lonnet::waf_allssl($hostname))) {
                               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 6467  sub editing_js { Line 7525  sub editing_js {
     } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {      } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
         $backtourl = '/adm/menu';          $backtourl = '/adm/menu';
     } elsif ($supplementalflag) {      } elsif ($supplementalflag) {
         $backtourl = '/adm/supplemental';          if (($env{'request.role.adv'}) ||
               (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
               $backtourl = '/adm/supplemental';
           } else {
               $backtourl = '/adm/navmaps';
           }
     } else {      } else {
         $backtourl = '/adm/navmaps';          $backtourl = '/adm/navmaps';
     }      }
Line 6492  sub editing_js { Line 7555  sub editing_js {
 function makenewfolder(targetform,folderseq) {  function makenewfolder(targetform,folderseq) {
     var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');      var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
     if (foldername) {      if (foldername) {
        targetform.importdetail.value=escape(foldername)+"="+folderseq;         targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
         targetform.submit();          targetform.submit();
     }      }
 }  }
Line 6500  function makenewfolder(targetform,folder Line 7563  function makenewfolder(targetform,folder
 function makenewpage(targetform,folderseq) {  function makenewpage(targetform,folderseq) {
     var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');      var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
     if (pagename) {      if (pagename) {
         targetform.importdetail.value=escape(pagename)+"="+folderseq;          targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
         targetform.submit();          targetform.submit();
     }      }
 }  }
Line 6509  function makeexamupload() { Line 7572  function makeexamupload() {
    var title=prompt('$js_lt{"p_mxu"}');     var title=prompt('$js_lt{"p_mxu"}');
    if (title) {     if (title) {
     this.document.forms.newexamupload.importdetail.value=      this.document.forms.newexamupload.importdetail.value=
  escape(title)+'=/res/lib/templates/examupload.problem';   encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
     this.document.forms.newexamupload.submit();      this.document.forms.newexamupload.submit();
    }     }
 }  }
Line 6518  function makesmppage() { Line 7581  function makesmppage() {
    var title=prompt('$js_lt{"p_msp"}');     var title=prompt('$js_lt{"p_msp"}');
    if (title) {     if (title) {
     this.document.forms.newsmppg.importdetail.value=      this.document.forms.newsmppg.importdetail.value=
  escape(title)+'=/adm/$udom/$uname/new/smppg';   encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
     this.document.forms.newsmppg.submit();      this.document.forms.newsmppg.submit();
    }     }
 }  }
Line 6533  function makewebpage(type) { Line 7596  function makewebpage(type) {
    }     }
    if (title) {     if (title) {
        var webpage = formname.importdetail.value;         var webpage = formname.importdetail.value;
        formname.importdetail.value = escape(title)+'='+webpage;         formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
        formname.submit();         formname.submit();
    }     }
 }  }
Line 6542  function makesmpproblem() { Line 7605  function makesmpproblem() {
    var title=prompt('$js_lt{"p_msb"}');     var title=prompt('$js_lt{"p_msb"}');
    if (title) {     if (title) {
     this.document.forms.newsmpproblem.importdetail.value=      this.document.forms.newsmpproblem.importdetail.value=
  escape(title)+'=/res/lib/templates/simpleproblem.problem';   encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
     this.document.forms.newsmpproblem.submit();      this.document.forms.newsmpproblem.submit();
    }     }
 }  }
Line 6551  function makedropbox() { Line 7614  function makedropbox() {
    var title=prompt('$js_lt{"p_mdb"}');     var title=prompt('$js_lt{"p_mdb"}');
    if (title) {     if (title) {
     this.document.forms.newdropbox.importdetail.value=      this.document.forms.newdropbox.importdetail.value=
         escape(title)+'=/res/lib/templates/DropBox.problem';          encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
     this.document.forms.newdropbox.submit();      this.document.forms.newdropbox.submit();
    }     }
 }  }
Line 6560  function makebulboard() { Line 7623  function makebulboard() {
    var title=prompt('$js_lt{"p_mbb"}');     var title=prompt('$js_lt{"p_mbb"}');
    if (title) {     if (title) {
     this.document.forms.newbul.importdetail.value=      this.document.forms.newbul.importdetail.value=
  escape(title)+'=/adm/$udom/$uname/new/bulletinboard';   encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
     this.document.forms.newbul.submit();      this.document.forms.newbul.submit();
    }     }
 }  }
Line 7670  check on this Line 8733  check on this
   
 Verify Content  Verify Content
   
 =item devalidateversioncache()   =item devalidateversioncache()
   
 =item checkversions()  =item checkversions()
   

Removed from v.1.484.2.72.2.2  
changed lines
  Added in v.1.484.2.93.2.15


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